![]() |
| |||||||
| Home | Register | Blogs | FAQ | Members List | Calendar | Downloads | Arcade | Mark Forums Read |
| Algorithms The source of algorithms for your project |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Easy rider | Howdy, We all know that using global variables eliminates all abstraction and basically means a bad design. Code: int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
CGame::Instance()->Init(hInstance); // Initialize the subsystems
while (CGame::Instance()->getGameWnd()->HandleMessages())
{
CGame::Instance()->Run();
}
CGame::Instance()->Shutdown();
return 0;
} Here is an example situation in my project. The CRabbit class implements the functionality of a bunny and is inherited from ICreature. Each ICreature must implement a Draw() routine. Since the graphical output in my app is quite complicated, it's wrapped with the CGraphics class. So my shrinked code for CBunny::Draw() looks as follows: Code: void CBunny::Draw()
{
CGame::Instance()->getGraphics()->DrawMesh(this->mesh);
} |
| | |
| | #2 |
| Грустно... | Re: A Singleton Discussion Зайцу не надо знать о том, что такое игра. Более того, он не должен знать, как и зачем его рисуют. Он должен экспортировать mesh, а дальше RenderManager должен заниматься тем, что по очереди рисовать все объекты. Более того, только рендерер может знать что рисовать, а что нет - так как только у него есть правильный З-порядок. А заяц, о своем порядке знать не долже. Ну и т.д.
__________________ Хотели, как лучше, а получилось даже хуже... Лозунг шахматиста: На каждый шах - ответим матом! В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте. Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2. |
| | |
| | #3 |
| Easy rider | So am I getting you right that a better design would be splitting all entities existing within the scope of the task into 'Data Containers' (CMesh, CHuman, CRabbit...) and 'Action Performers' (CRenderer, CWalker, CDLLManager, CLogger...). But then again (if that's what you mean), aren't all 'Action Performers' singletons by their nature? Also another question, if a bunny lives in a specific world, I assume he knows how to live in it. I assume he knows how to handle other animals on the same world, how to eat the grass growing on that world, how to draw itself and how to have sex with any other creature, that's at least how it seems natural to me. I want to think of a bunny as of something more than just a bunch of parameters, something that makes use of the world it lives in for the survival of its own, the way its programmed to use it. Isn't that how the real world is constructed? I am too unexperienced and the opinions I express could seem too immature, though. Why not give all the objects all the knowledge about the entire world (like in the real life) and limit their ability to modify it merely by the implementation of the specific creature (like in real life)? If the universe logics solely exists within some CUniverseLogic(), we can't hope to expand it later by adding revolutionary creatures to the world - can we? We'll have to modify the universe logics core. Go deeper with this, please. Also, if anyone could advise some good reading, that'd be fantastic. Thanks a lot. |
| | |
| | #4 |
| Грустно... | Re: A Singleton Discussion Заяц не есть контейнер - заяц есть заяц. Так как у тебя может быть миллион зайцев. Заяц должен уметь Есть, Срать и Трахаться. У него должны быть соответствующие методы. Он должен уметь есть траву и не есть мясо. Но он не должен уметь себя рисовать. Так как заяц сквозь сеточные глаза пчелы и в моих глазах выглят по разному. Рендерер должен определять как выглятит тот или иной заяц в разных контекстах, а вот форма у зайца есть - поэтому меш он должен экспортировать.
__________________ Хотели, как лучше, а получилось даже хуже... Лозунг шахматиста: На каждый шах - ответим матом! В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте. Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2. |
| | |
| | #5 | |
| hex god | Re: A Singleton Discussion Quote:
__________________ Ленинградское время 0 часов 0 минут | |
| | |
| | #6 |
| Грустно... | Re: A Singleton Discussion Держу. Стараюсь, по крайней мере!
__________________ Хотели, как лучше, а получилось даже хуже... Лозунг шахматиста: На каждый шах - ответим матом! В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте. Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2. |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Peace Building & Conflict Resolution Resource Center's Lecture & Discussion Series | PsilocybeLarvae | Science and Education | 2 | Feb 15, 2006 06:43 |
| Panel Discussion: What's Better for Use - GUI or Command Line | Hrach_Techie | Software | 17 | Jul 13, 2005 18:30 |
| Discussion: Why is UNIX so Sexy? | Hrach_Techie | Operating Systems | 270 | Jan 20, 2005 15:17 |
| Discussion: Планета Нибиру - Что это? | Hrach_Techie | Science and Education | 24 | Jan 12, 2005 09:32 |
| Panel Discussion: Current Issues in Armenian Nursing | PsilocybeLarvae | Science and Education | 0 | Oct 6, 2004 20:30 |