2d engine design issue
I know this may be just a small detail but I would like to do it right the first time
Okey, I have an Engine class and a Texture class. Should the engine handle the loading and drawing of textures or should the texture be allowed to load and draw itself.
Example:
Texture tex = engine->loadTexture("texture.bmp");
engine->drawTexture(tex);
or
Texture tex;
tex.load("texture.bmp");
tex.draw();
Whats the most correct way OO wise?
By the way its a 2D engine using SDL.
Thanks.
na, have a texture manager. you need to be able to manage resources yourself, else it''s gonna be a nightmare to manage. You can then prioritise them, organise them in groups (menus, sprites, fonts, particles, backgrounds, ...), not downloading the same texture twice, being able to release the textures without tracking down each of the textures separately (you can count the references, if the reference count reaches zero, free the texture, if the reference count goes from zero to one, reload the texture, but watchout for memory fragmentation if you are that bothered), reusing the textures for different things (skybox and environment mapping?).
so it should really be dealt with by a global engine, that will do the dirty work for you (once you get the texture manager sorted ). Like all the other resources of the game (audio files, models, materials, animations, ect...). A resource is supposed to be shared by various things, so it''s good to keep it global and easily accessible.
well, that''s what I''d do anyway.
so it should really be dealt with by a global engine, that will do the dirty work for you (once you get the texture manager sorted ). Like all the other resources of the game (audio files, models, materials, animations, ect...). A resource is supposed to be shared by various things, so it''s good to keep it global and easily accessible.
well, that''s what I''d do anyway.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement