From: Sam S. <sam...@gm...> - 2005-12-04 16:21:47
|
On Nov 27, 2005, at 3:52 PM, Dan Potter wrote: > - And about Drawables in lists...: > R.I.P 2001 - 2005 entity.h, callback.h / callback.cc, collide.h / collide.cc, and a host of other files related to AOE, the core of DreamZZT and DCBlap (and the misc 3D demos that use the DCBlap engine). I took the plunge and practically rewrote DCBlap using Tiki Drawables! To be honest, it wasn't as difficult as I thought, though it requires changing your mindset around going from C-style programming to C++ OOP (load_world() doesn't load the objects anymore, it creates an object and the object loads itself from the file, etc.). Now the entire game world is packed neatly into a genmenu scene, using Tiki selectors for messaging. > If we turn on RTTI (I think it might work on the DC now, and might > be a good thing to have overall) then you can also use dynamic_cast > to check to make sure that a particular pointer is the class you > think it is, if you need to do that. > Right now I'm keeping my own std::list<Entity *> of Entity pointers so I don't lose them when they turn into Drawables in the list, but I'm guessing RTTI would let me enumerate genmenu's m_scene to find Entity-derived objects, and cast them from a Drawable pointer to an Entity pointer to use the Entity-specific functions? > The type switch on creation is pretty ugly but there's no really > good way around that in C++ > Yeah, I opted for the giant if/else function for now. I figure I can just generate it with a shell script, like the old object-template creation function was. I actually have two of them, because of what I assume is another C++ "feature": create_object("Paddle") returns an Entity* which is pointing to a Paddle*. If I then call ent->loadFromFile(), then Entity::loadFromFile() gets called, but not Paddle::loadFromFile(). I think that's what the virtual keyword is for? Anyway, for now I just have a second giant if/else called load_object() that calls loadFromFile before the object gets cast to an Entity*. As for the menus, I went and recreated them as a bunch of drawables -- the help text is now a few labels and banners for the controller icons. It looks much better, and it's easier to swap the icons out for PC keyboard images on the PC (though, drawing a D-Pad was a lot easier than drawing the arrow keys on a PC.. grr). I've still got a long way to go with writing the new object classes, so nothing playable this week -- right now it's been reduced to a paddle that kind-of responds to the keyboard, and a ball that makes drawables turn red with setTint when it collides with them. -Sam |