• Advertisement

Archived

This topic is now archived and is closed to further replies.

is it effective to use OOP in game programming?

This topic is 5710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to use OOP (classes constructors destructors etc) in game programming but I''m anxcious that it could slow down the game. What do you think about it? I don''t see any OOP in game programming examples so I wish to know if anyone''s using it.

Share this post


Link to post
Share on other sites
Advertisement
If done right, it''s no slower than C. Just learn good OOP practices and you''ll be fine.

For small games it doesn''t make much difference at all.

Share this post


Link to post
Share on other sites
The consensus seems to be that the most vital part of a game engine is what happens at the lowest levels (efficiency of parsing for collision detection, primitive submittal to the rendering pipeline, etc.)

Programming in C++ at its worst involves some extra memory references, which aren''t enough in today''s machines to make that much of a difference. You can go overboard with OOP and overdo the necessity for extra memory references, and there are ways to optimize, but on its own it doesn''t make enough of an impact to be a concern.

That''s my 2 cents.

Share this post


Link to post
Share on other sites
Why would using OOP slow down your program? I'm using Classes (well, just one :D ), and it helps that all the code I need have been packed away in a bunch of functions, which have been in turn been packed away in a Class.

Though that said, I am experiencing some slow down probs myself right now - I think it's something to do with how my main loop/getmessage code is done (thread on this coming soon). I cannot believe it's summat to do with my using a class.

Of course I might be wrong.





"Sweetie! Get Mommy's bazooka!"

[edited by - Mister Stewart on September 1, 2002 2:09:52 PM]

Share this post


Link to post
Share on other sites
quote:


Why would using OOP slow down your program?




Generally you will be doing:

CGame *MyGame=new CGame;

to access any of the methods/properties will require the CPU to traverse a pointer to get to the class.

Also

CGame *MyGame=new CDerivedGame;

you also have the overhead of using the VMT (virtual method table) to make use of polymorphism, which is slower as it''s another pointer traversal.

Also

You might come unstuck with multiple inheritance (less of an efficiency problem but one which may slow down your coding if you are unaware of the consequences).

I like OO techniques in game coding. Understanding OO is essential to doing it well. OO does not slow down a program (if it did do you think Microsoft would have based DirectX on COM - a OO technology) by a lot but there IS an overhead (generally n-noticeable on todays machines)

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites
*g* Perhaps Half-Life with its unstable & ugly engine isn''t the best example to show the benefits of OOP ;-)

_________________________
"Reality is merely an illusion, albeit a very persistent one." (Albert Einstein)
My Homepage

Share this post


Link to post
Share on other sites
Unreal Tournament''s code is highly object oriented. Actually, I believe OOP has been used for the majority of the games released in the last 4 years.

You don''t have to traverse more pointers with C++ than you would do with C. And if you do, there''s a very very very high probability that it wont impact the performance of your program at all.

Regarding virtual methods for polymorphism... It''s a feature like any other, and you choose whether you use it or not. However, if you need a C equivalent for polymorphism you''ll have to write it on your own, and again there''s a very high probability that your code will be less efficient than the C++ compiler''s.

Share this post


Link to post
Share on other sites
Games are ideal for OOP! I wrote one myself with Tile,Unit and GameEvent classes.

''Your theory of a donut shaped universe is intriguing Homer'' - Stephen Hawking

Share this post


Link to post
Share on other sites

  • Advertisement