refacored some parts of main.sh
This commit is contained in:
parent
b6684f7929
commit
dbffcf5f04
17
ActiveObject.h
Normal file
17
ActiveObject.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "TextureManager.h"
|
||||
#include "Math.h"
|
||||
#include <memory>
|
||||
|
||||
struct ActiveObject {
|
||||
std::shared_ptr<ZL::Texture> activeObjectTexturePtr;
|
||||
ZL::VertexDataStruct activeObjectMesh;
|
||||
ZL::VertexRenderStruct activeObjectMeshMutable;
|
||||
|
||||
std::shared_ptr<ZL::Texture> activeObjectScreenTexturePtr;
|
||||
ZL::VertexDataStruct activeObjectScreenMesh;
|
||||
ZL::VertexRenderStruct activeObjectScreenMeshMutable;
|
||||
|
||||
ZL::Vector3f objectPos;
|
||||
bool highlighted = false;
|
||||
};
|
||||
14
Environment.cpp
Normal file
14
Environment.cpp
Normal file
@ -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};
|
||||
18
Environment.h
Normal file
18
Environment.h
Normal file
@ -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;
|
||||
};
|
||||
39
Game.h
39
Game.h
@ -1,14 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "Math.h"
|
||||
#include "Physics.h"
|
||||
#include "TextureManager.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "GameObjectManager.h"
|
||||
#include "Renderer.h"
|
||||
#include "AnimatedModel.h"
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include <memory>
|
||||
#include "Environment.h"
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
class Game {
|
||||
public:
|
||||
Game();
|
||||
~Game();
|
||||
|
||||
void setup();
|
||||
void run();
|
||||
void update();
|
||||
void render();
|
||||
|
||||
bool shouldExit() const { return exitGameLoop; }
|
||||
|
||||
}
|
||||
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;
|
||||
};
|
||||
12
GameObjectManager.cpp
Normal file
12
GameObjectManager.cpp
Normal file
@ -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()
|
||||
}
|
||||
41
GameObjectManager.h
Normal file
41
GameObjectManager.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "TextureManager.h"
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include "cmakeaudioplayer/include/AudioPlayer.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "ActiveObject.h"
|
||||
|
||||
class GameObjectManager {
|
||||
public:
|
||||
void initialize();
|
||||
void update();
|
||||
|
||||
std::shared_ptr<ZL::Texture> testObjTexturePtr;
|
||||
std::shared_ptr<ZL::Texture> roomTexturePtr;
|
||||
std::shared_ptr<ZL::Texture> 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<ActiveObject> activeObjects;
|
||||
std::unique_ptr<AudioPlayer> audioPlayer;
|
||||
|
||||
ZL::VertexDataStruct inventoryIconMesh;
|
||||
ZL::VertexRenderStruct inventoryIconMeshMutable;
|
||||
|
||||
static const float INVENTORY_ICON_SIZE;
|
||||
static const float INVENTORY_MARGIN;
|
||||
};
|
||||
61
main.cpp
61
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;
|
||||
}
|
||||
|
||||
14
start.sh
14
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
|
||||
Loading…
Reference in New Issue
Block a user