Quote:Original post by storage
Thanks, then that's how I will do it! :)
Another thing, how should my sprites be?
1. struct/global functions
typedef struct Sprite{ int w, h;} Sprite;Sprite *mysprite;mysprite = Engine_NewSprite(w, h);Engine_DrawSprte(mysprite, x, y);
2. Class
class Sprite{ int w, h; void New(int width, int height); void Draw(int x, int y);};Sprite *mysprite;mysprite->New(w, h);mysprite->Draw(x, y);
Thanks in advance once again :)
Neither.
Approaches I might use are:
[sources]// 1. Factories: Classes are used to construct other classes. Classes are// thereby specific to their factories and cannot be arbitrarily mixed with// classes constructed by other factories.Engine * myEngine = LoadEngine("engine.dll");Sprite * mySprite = myEngine->CreateSpriteFromFile("supermonkey.sprite");Context * myContext = myEngine->CreateContext();myContext->EnableBlending();MySprite->Draw(myContext, x, y);// Classes from different factories may be incompatible.Engine * myEngine2 = Factory::LoadEngine("engine2.dll");Context * myContext2 = myEngine2->CreateContext();myContext2->EnableBlending();// This would probably not be allowed.MySprite->Draw(myContext, x, y);// 2. Wrappers: Classes are wrappers around hidden implementation classes. // Classes may be mixed and matched arbitrarily, and implementation specific// data structures are created behind-the-scenes.Engine * myEngine = LoadEngine("engine.dll");Sprite * mySprite = Sprite::CreateFromFile("supermonkey.sprite");Context * myContext = new Context;myContext->EnableBlending();// This creates internal structures which associate the engine with the context,// the sprite with the engine, and possibly the sprite with the context.// Maintaining this state is nontrivial.mySprite.Draw(myEngine, myContext, x, y);// 3. Attached wrappers: Classes are wrappers around hidden implementation // classes. Classes may not be mixed and matched arbitrarily, but must instead// be attached to particular classes in order to be used with them.Engine * myEngine = LoadEngine("engine.dll");Sprite * mySprite = Sprite::CreateFromFile("supermonkey.sprite");Context * myContext = new Context();myContext->EnableBlending();myContext->attach(myEngine);mySprite->attach(myContext);mySprite.Draw(x, y);
The factory solution is the easiest to
implement, and the more efficient. The wrapper solution is the easiest to
use, and the more flexible. The attached wrappers solution is somewhere between.