I'm trying to write a game in C++ using OpenGL. I've tried to separate my game logic and my rendering logic as much as possible, and up until now, this has worked for me. I haven't written a lot of code, and right now, I'm getting to the point where I have all my separate parts, and I'm trying to put them together.
In order to keep game and rendering logic separated, I've written them both in separate static libraries (So I have a libCore
and a libRendering
. There's also a third static library that contains code that is shared between the two libraries (Things like utility methods for reading files, custom exceptions, ...), this library is called libShared
. Both of my libraries (libCore
and libRendering
) are first linked against libShared
and then the game executable is linked against libCore
and libRendering
.
I've been using an entity-component-system (Which is part of libCore
) to keep track of all my entities, now I'd like to introduce a RenderingComponent
which contains all the data necessary for actually rendering an object (Things like VAO's, VBO's, Textures, Normal Maps, ...).
The problem is, that doing this would bring part of the rendering code into the game logic code. And I'm wondering what the best course of action would be here.
Should I move the ECS into libShared
?
Should I just create a single libEngine
that I can link my game against, instead of 3 different libraries?
Do you have any other solutions?
Note: I do realize that separation of game and rendering logic has been discussed before, my question is specifically about the architecture of the various libraries I have layed out in this question, and other peoples' opionions on it.
To clarify what I mean, here's what my CMakeLists.txt looks like (They're actually separate files, but I'll keep them together for simplicity's sake).
...
add_library(Shared ${SHARED_HEADER_FILES} ${SHARED_SOURCE_FILES})
...
add_library(Rendering ${RENDERING_HEADER_FILES} ${RENDERING_SOURCE_FILES})
target_link_libraries(Rendering Shared ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW_LIBRARY})
...
add_library(Core ${CORE_HEADER_FILES} ${CORE_SOURCE_FILES})
target_link_libraries(Core Shared ${LUA_LIBRARIES})
...
add_executable(Game ${GAME_HEADER_FILES} ${GAME_SOURCE_FILES} src/main.cpp)
target_link_libraries(Game Core Rendering)
Second Note: If this is better suited for Code Review or Software Engineering StackExchange, I'll happily move my question over there.