AKB Forums

Go Back   AKB Forums > Technical sections > Algorithms
Home Register Blogs FAQ Members List Calendar Downloads Arcade Mark Forums Read

Algorithms The source of algorithms for your project

Troubles when posting message? Click here! :: Проблемы с отправлением сообщения? Нажмите сюда!

Reply
 
LinkBack Thread Tools Display Modes
Old Mar 1, 2006, 02:16   #1
Easy rider
 
Silver's Avatar
 
Join Date: Nov 2005
Location: tristeza
Posts: 1,087
Rep Power: 3
Reputation: 10
Send a message via ICQ to Silver
Lightbulb A Singleton Discussion

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;
}
This is the main.cpp of the project I'm currently working on, with the error handling removed. Basically, my CGame is a class that is accessible to everyone from everywhere - ****y, but flexible. It is also the top container of all data in my application. It contains pointers to all different subsystems like the graphics subsystem, the game logic subsystem, the sound subsystem, the window subsystem etc. Through CGame::Instance()->get***(), each class can aquire a pointer to the subsystem it wants and work with it. That way, all objects on my world can 'see' each other and interact with each other the way they are programmed to. And I really do not see a possible 'abstracted' alternative - maybe someone can point me out!

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);
}
Which really does look natural to me. I have only one game, only one graphical subsystem, only one memory manager etc running during the entire application lifetime. So I really (and I mean really, please) want to see a bulletproof reply of a better alternative for the design, provided with arguments and all. Anyone?
__________________




You must spread before giving to Silver again.
Silver is offline   Reply With Quote Quote selected
Old Mar 1, 2006, 06:50   #2
Грустно...
 
Agregat's Avatar
 
Join Date: Aug 2002
Location: Там, где всегда идут дожди
Posts: 21,343
Rep Power: 10
Reputation: 109
Send a message via ICQ to Agregat Send a message via MSN to Agregat
Re: A Singleton Discussion

Зайцу не надо знать о том, что такое игра. Более того, он не должен знать, как и зачем его рисуют. Он должен экспортировать mesh, а дальше RenderManager должен заниматься тем, что по очереди рисовать все объекты. Более того, только рендерер может знать что рисовать, а что нет - так как только у него есть правильный З-порядок. А заяц, о своем порядке знать не долже. Ну и т.д.
__________________
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!
В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте.
Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2.
Agregat is offline   Reply With Quote Quote selected
Old Mar 1, 2006, 19:49   #3
Easy rider
 
Silver's Avatar
 
Join Date: Nov 2005
Location: tristeza
Posts: 1,087
Rep Power: 3
Reputation: 10
Send a message via ICQ to Silver
Lightbulb Re: A Singleton Discussion

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.
__________________




You must spread before giving to Silver again.
Silver is offline   Reply With Quote Quote selected
Old Mar 2, 2006, 06:41   #4
Грустно...
 
Agregat's Avatar
 
Join Date: Aug 2002
Location: Там, где всегда идут дожди
Posts: 21,343
Rep Power: 10
Reputation: 109
Send a message via ICQ to Agregat Send a message via MSN to Agregat
Re: A Singleton Discussion

Заяц не есть контейнер - заяц есть заяц. Так как у тебя может быть миллион зайцев.
Заяц должен уметь Есть, Срать и Трахаться. У него должны быть соответствующие методы. Он должен уметь есть траву и не есть мясо. Но он не должен уметь себя рисовать. Так как заяц сквозь сеточные глаза пчелы и в моих глазах выглят по разному. Рендерер должен определять как выглятит тот или иной заяц в разных контекстах, а вот форма у зайца есть - поэтому меш он должен экспортировать.
__________________
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!
В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте.
Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2.
Agregat is offline   Reply With Quote Quote selected
Old Mar 2, 2006, 06:50   #5
hex god
 
Griffon2-7's Avatar
 
Join Date: Mar 2002
Location: Yerevan, AM
Posts: 3,173
Rep Power: 7
Reputation: 19
Send a message via ICQ to Griffon2-7
Re: A Singleton Discussion

Quote:
Originally Posted by Agregat
Так как заяц сквозь сеточные глаза пчелы и в моих глазах выглят по разному.
Держите себя в руках, Виктор! Держите себя в руках!
__________________
Ленинградское время 0 часов 0 минут
Griffon2-7 is offline   Reply With Quote Quote selected
Old Mar 2, 2006, 07:56   #6
Грустно...
 
Agregat's Avatar
 
Join Date: Aug 2002
Location: Там, где всегда идут дожди
Posts: 21,343
Rep Power: 10
Reputation: 109
Send a message via ICQ to Agregat Send a message via MSN to Agregat
Re: A Singleton Discussion

Держу. Стараюсь, по крайней мере!
__________________
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!
В сумасшедшем доме каждый мог говорить все, что взбредет ему в голову, словно в парламенте.
Я. Гашек. "Приключения Бравого Солдата Швейка". Часть 1. Глава IV. Абзац 2.
Agregat is offline   Reply With Quote Quote selected
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT. The time now is 12:21.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
This board was founded on September 29, 2001
Powered by Viper Internet

Affordable Web Hosting | ParevNet

Buy text link