@freddix
Quote:
freddix wrote:
@Hans
You're not totally right.
When designing a programing language using plugin system, you're right that each plugin own its own structures and command set however, the one that handle the display (and then opengl setup) must share informations with some other ones (sprites, images, basic 3D) because they are dependant on this one and, due to the fact that adding new command to one of these sets (like for example adding primitives 3D objects) will require to modify some opengl options and refresh, I must work using this method.
Actually, you don't need to work using that method at all. I have created a small 3D engine before, and I could modularize it pretty easily in such a way that sharing internal information between .c files is unnecessary. This isn't about using plugins or not, it's about de-coupling code so that there are no complex interdependencies.
What little information you actually need to share can be done via functions defined in the .h file. For example, a sprite would have a position, size, and a texture. It doesn't need to know anything about the size of the screen, etc. A single pointer to a render function could be defined in the sprite structure that takes care of all the OpenGL rendering stuff in order to draw it to screen.
The sprite would need a texture, which is something that should be put into another .c file. However, if the texture module has the following functions (with prototypes in texture.h):
- createTexture()
- deleteTexture()
- useTexture()
- endUseTexture()
- getTextureWidth()
- getTextureHeight()
- getTextureType()
then the sprite object doesn't need anything more than a pointer to a texture object in order to use a texture.
Now if the sprite has the following functions:
- createSprite()
- deleteSprite()
- renderSprite()
- getSpritePose() // obtains the x, y and angle coordinates
- setSpritePose()
then your rendering engine requires no knowledge about a sprite's internals at all. It can do everything it has to via these few functions.
The same applies to 2D/3D objects too. If all objects to be rendered have a pointer to a render function in their structure, then your graphics engine won't even need to know what kind of object it is rendering; it just does a; object->render() call.
I could go on, but it would probably be an overload of information. Learning how to isolate code so that changes in one file hardly ever affect another will take time. However, it is possible.
Hans