diff --git a/ActiveObject.h b/ActiveObject.h new file mode 100644 index 0000000..bc3dc94 --- /dev/null +++ b/ActiveObject.h @@ -0,0 +1,17 @@ +#pragma once +#include "TextureManager.h" +#include "Math.h" +#include + +struct ActiveObject { + std::shared_ptr activeObjectTexturePtr; + ZL::VertexDataStruct activeObjectMesh; + ZL::VertexRenderStruct activeObjectMeshMutable; + + std::shared_ptr activeObjectScreenTexturePtr; + ZL::VertexDataStruct activeObjectScreenMesh; + ZL::VertexRenderStruct activeObjectScreenMeshMutable; + + ZL::Vector3f objectPos; + bool highlighted = false; +}; diff --git a/Environment.cpp b/Environment.cpp new file mode 100644 index 0000000..0bb9b23 --- /dev/null +++ b/Environment.cpp @@ -0,0 +1,14 @@ +#include "Environment.h" + +int Environment::windowHeaderHeight = 0; +int Environment::width = 0; +int Environment::height = 0; +float Environment::zoom = 10.0f; + +bool Environment::leftPressed = false; +bool Environment::rightPressed = false; +bool Environment::upPressed = false; +bool Environment::downPressed = false; + +Vector3f Environment::cameraShift = {0, 0, 0}; +Vector3f Environment::characterPos = {0, 0, 0}; diff --git a/Environment.h b/Environment.h new file mode 100644 index 0000000..f0dc366 --- /dev/null +++ b/Environment.h @@ -0,0 +1,18 @@ +#pragma once +#include "Math.h" + +class Environment { +public: + static int windowHeaderHeight; + static int width; + static int height; + static float zoom; + + static bool leftPressed; + static bool rightPressed; + static bool upPressed; + static bool downPressed; + + static ZL::Vector3f cameraShift; + static ZL::Vector3f characterPos; +}; diff --git a/Game.h b/Game.h index a76b369..66c4804 100755 --- a/Game.h +++ b/Game.h @@ -1,14 +1,35 @@ #pragma once -#include "Math.h" -#include "Physics.h" -#include "TextureManager.h" +#include +#include "GameObjectManager.h" #include "Renderer.h" -#include "AnimatedModel.h" -#include "BoneAnimatedModel.h" -#include +#include "Environment.h" -namespace ZL -{ +class Game { +public: + Game(); + ~Game(); + + void setup(); + void run(); + void update(); + void render(); + + bool shouldExit() const { return exitGameLoop; } -} \ No newline at end of file +private: + void processTickCount(); + void drawScene(); + + SDL_Window* window; + SDL_GLContext glContext; + ZL::Renderer renderer; + GameObjectManager gameObjects; + + bool exitGameLoop; + size_t newTickCount; + size_t lastTickCount; + + static const size_t CONST_TIMER_INTERVAL = 10; + static const size_t CONST_MAX_TIME_INTERVAL = 1000; +}; \ No newline at end of file diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp new file mode 100644 index 0000000..5577188 --- /dev/null +++ b/GameObjectManager.cpp @@ -0,0 +1,12 @@ +#include "GameObjectManager.h" + +const float GameObjectManager::INVENTORY_ICON_SIZE = 32.0f; +const float GameObjectManager::INVENTORY_MARGIN = 10.0f; + +void GameObjectManager::initialize() { + // Implementation coming from main.cpp setup() +} + +void GameObjectManager::update() { + // Implementation coming from main.cpp update() +} diff --git a/GameObjectManager.h b/GameObjectManager.h new file mode 100644 index 0000000..1e56e1f --- /dev/null +++ b/GameObjectManager.h @@ -0,0 +1,41 @@ +#pragma once +#include "TextureManager.h" +#include "BoneAnimatedModel.h" +#include "cmakeaudioplayer/include/AudioPlayer.hpp" +#include +#include +#include "ActiveObject.h" + +class GameObjectManager { +public: + void initialize(); + void update(); + + std::shared_ptr testObjTexturePtr; + std::shared_ptr roomTexturePtr; + std::shared_ptr coneTexturePtr; + + ZL::VertexDataStruct colorCubeMesh; + ZL::VertexRenderStruct colorCubeMeshMutable; + + ZL::VertexDataStruct testObjMesh; + ZL::VertexRenderStruct testObjMeshMutable; + + ZL::BoneSystem bx; + ZL::VertexRenderStruct bxMutable; + + ZL::VertexDataStruct textMesh; + ZL::VertexRenderStruct textMeshMutable; + + ZL::VertexDataStruct coneMesh; + ZL::VertexRenderStruct coneMeshMutable; + + std::vector activeObjects; + std::unique_ptr audioPlayer; + + ZL::VertexDataStruct inventoryIconMesh; + ZL::VertexRenderStruct inventoryIconMeshMutable; + + static const float INVENTORY_ICON_SIZE; + static const float INVENTORY_MARGIN; +}; diff --git a/main.cpp b/main.cpp index a0fb1c5..e13e50b 100755 --- a/main.cpp +++ b/main.cpp @@ -540,57 +540,26 @@ namespace ZL }; -int main(int argc, char* argv[]) -{ +#include "Game.h" - constexpr int CONST_WIDTH = 1280; - constexpr int CONST_HEIGHT = 720; +int main(int argc, char* argv[]) { + constexpr int CONST_WIDTH = 1280; + constexpr int CONST_HEIGHT = 720; - ZL::Env::width = CONST_WIDTH; - ZL::Env::height = CONST_HEIGHT; + Environment::width = CONST_WIDTH; + Environment::height = CONST_HEIGHT; + + Game game; + game.setup(); #ifdef EMSCRIPTEN - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_Renderer* renderer = NULL; - SDL_CreateWindowAndRenderer(CONST_WIDTH, CONST_HEIGHT, SDL_WINDOW_OPENGL, &ZL::window, &renderer); + emscripten_set_main_loop([]() { game.update(); }, 0, 1); #else - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { - SDL_Log("Failed to initialize SDL: %s", SDL_GetError()); - return 1; - } - - - // Use a core profile setup. - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - ZL::window = SDL_CreateWindow("Jumping Bird", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CONST_WIDTH, CONST_HEIGHT, SDL_WINDOW_OPENGL); -#endif - //todo - ZL::Env::windowHeaderHeight = 0; - - ZL::gl_context = SDL_GL_CreateContext(ZL::window); - - ZL::CheckGlError(); - - ZL::setup(); -#ifdef EMSCRIPTEN - // register update as callback - emscripten_set_main_loop(ZL::update, 0, 1); -#else - while (!ZL::ExitGameLoop) { - - ZL::update(); - SDL_Delay(2); - - } - SDL_GL_DeleteContext(ZL::gl_context); - SDL_DestroyWindow(ZL::window); - SDL_Quit(); - - exit(0); + while (!game.shouldExit()) { + game.update(); + SDL_Delay(2); + } #endif + return 0; } diff --git a/start.sh b/start.sh index 7b779b7..65dd930 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,11 @@ -g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp ObjLoader.cpp cmakeaudioplayer/src/AudioPlayer.cpp TextModel.cpp Inventory.cpp -o sdl_app -O2 -std=c++17 \ --I cmakeaudioplayer/include \ -$(pkg-config --cflags --libs sdl2 gl) \ -$(pkg-config --cflags --libs vorbis vorbisfile ogg) \ --lopenal +g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp \ + ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp \ + ObjLoader.cpp cmakeaudioplayer/src/AudioPlayer.cpp TextModel.cpp \ + Inventory.cpp Environment.cpp GameObjectManager.cpp \ + -o sdl_app -O2 -std=c++17 \ + -I cmakeaudioplayer/include \ + $(pkg-config --cflags --libs sdl2 gl) \ + $(pkg-config --cflags --libs vorbis vorbisfile ogg) \ + -lopenal ./sdl_app \ No newline at end of file