Problem homogenizing interface for entitnes, help needed

Started by
0 comments, last by DeusFacticius 16 years, 6 months ago
Hi all, I would like to create some wrapper around entities like lights, my game movable entities, etc... I´m using ogre engine. this classes should overwrite the Init method in order to initialize depending on its type (A movable entity initializes with a mesh, etc... but a light not). An this is the problem I have found, because I can´t find a way to homogeinize the Init prototype to make it virtual. Last resort is to use a params class to pass all params in it and have something like Init(params), and every init function knows what to do with the parms, a light get the attenuation, etc... a moving entity the mesh file, etc... what do you think? A dummy example: virtual bool Init(ParamClass Params) { //do whatever initialization you need //this is a light float attenuation= Params["attenuation"]; //this is a npc Mesh* mesh=loadmesh(Params["meshfile"]; } Exceptions could be anohter chance to avoid this Init/End thing and use constructors. Thanks in advance, HexDUmp.
Advertisement
It definitely works, many games use something similar. some OOP zealots will argue that it violates the OO practice of RAII (Resource Acquisition Is Initialization) and that ALL initialization/configuration should be done by means of a constructor, but this isn't always applicable in real time environments like games.

couple recommendations though:
*) Isolate this entity creation process in a factory of some sort with a generalized interface, so that if this process needs to be changed later, you've already got that 'high risk' code isolated and can easily be adapted later without breaking other code or scouring your code base for instances of this entity creation process.

*) Generalize this string-based key-value mapping of properties so that it can be used at times other than initialization -- it might come in handy for scripting, real time editing, etc.

A good place to look into this is in OGRE itself, it uses such a string-based properties set for some of its resources (materials, particle systems, some others). You could probably use the base class they use for implementing the functionality, its called 'Dictionary' IIRC.

This topic is closed to new replies.

Advertisement