View Single Post
  #3   (View Single Post)  
Old 19th December 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

Most of the things that people tout as the advantages of OOP, are exactly the things you should be doing with or without it.

Programming in C with a more `object oriented` nature generally applies to making wiser use of data structures and pointers then the newbie will often first consider. You might consider a look at LibWWW or GTK+ (C bindings, not C++).



On a side note:

Typical game implementations that I've seen, either build their control handling as a massive switch over key events (I believe even vi did this), or create a input management class that invokes a method on a registered objects descended from abstract base class XYZ after looking up the binding. Registering callbacks some times even saves a pointer to some special object rather then a function pointer. This generally sucks up costs for (several) vtable operations, numerous method resolutions, will likely incur dynamic memory allocations in the data structures, and some people will even process the controls in a O(n) like fashion every frame.

The system I've been piecing together for Stargella, polls input events and uses the key that was pressed to index into a table of function pointers: which is effectively a sniper shot compared to using std::map or related bits of C++ voodoo. Making my system more of a simple matter of pointer arithmetic to trigger the call backs, then would be the cost of hunting it down through an STL map, vector, or list (etc).


That is a fair difference between `typical C++` and `typical C` was of implementing the same thing.


A more objectual change, will be making the game register structures instead of funcptrs with the input system, allowing one to more easily change the concept of a keybinding without complicating the input system. The main reason for the change, being to bundle the question of whether input handling for control XYZ is supposed to be buffered or unbuffered, etc.


and without having to deal with the hell they call C++ OOP :-P.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote