From 9f9355c24601d4bd8451398975eaecfa185057fe Mon Sep 17 00:00:00 2001 From: Alfred Burgess <aburgess@ucc.gu.uwa.edu.au> Date: Mon, 18 Dec 2023 15:18:53 +0800 Subject: [PATCH] Working on scenes --- .gitlab-ci.yml | 22 +++++----------------- include/asset.h | 4 ++++ include/game-engine.h | 22 ++++++++++++++-------- include/scene.h | 5 +++-- include/scenes/scene_play.h | 24 ++++++++++++++++++++++++ makefile | 8 ++++++-- src/asset.cpp | 2 ++ src/chunk.cpp | 8 +++----- src/entities/entity.cpp | 4 ++-- src/game-engine.cpp | 16 +++++++++++----- src/scenes/scene_play.cpp | 7 +++++++ src/world-hex-2d.cpp | 4 ++-- src/world-map3d.cpp | 5 +++-- 13 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 include/scenes/scene_play.h create mode 100644 src/scenes/scene_play.cpp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a9c7a2f..bf72a0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,34 +1,22 @@ -# This file is a template, and might need editing before it works on your project. -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/ee/development/cicd/templates.html -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/C++.gitlab-ci.yml - -# use the official gcc image, based on debian -# can use versions as well, like gcc:5.2 -# see https://hub.docker.com/_/gcc/ - image: gcc build: stage: build - # instead of calling g++ directly you can also use some build toolkit like make - # install the necessary build tools when needed before_script: - mkdir bin - mkdir saves + - mkdir logs script: - make console artifacts: paths: - bin/ - # depending on your build setup it's most likely a good idea to cache outputs to reduce the build time - # cache: - # paths: - # - "*.o" + cache: + paths: + - "build/*.o" # run tests using the binary built before test: stage: test script: - - echo "Dummy Testing" + - make test diff --git a/include/asset.h b/include/asset.h index a2e1cd7..abf0a6a 100644 --- a/include/asset.h +++ b/include/asset.h @@ -1,6 +1,8 @@ #ifndef __ASSET_H__ #define __ASSET_H__ +#include <string> + #include "logger.h" class Asset @@ -8,6 +10,8 @@ class Asset public: Asset(); ~Asset(); + + void loadMedia( std::string path ); private: Logger& _logger; }; diff --git a/include/game-engine.h b/include/game-engine.h index 1b376bb..e3d7fbc 100644 --- a/include/game-engine.h +++ b/include/game-engine.h @@ -1,6 +1,7 @@ #ifndef __GAME_H__ #define __GAME_H__ +#include <memory> #include <map> #include <string> #include <vector> @@ -12,10 +13,14 @@ #include "logger.h" #include "entity-manager.h" #include "scene.h" +#include "asset.h" +// #include "window.h" #ifdef console #endif +class Window {}; + class GameEngine { public: @@ -26,11 +31,11 @@ class GameEngine void update(); void close(); Scene* currentScene(); - // void changeScene( Scene scene ); - // std::vector< Asset& > getAssets(); - // Window& getWindow(); + void changeScene( std::string label, Scene *scene ); + void changeScene( std::string label ); + std::vector< Asset& > getAssets(); + Window& getWindow(); - std::vector<Asset> getAssets(); void sUserInput(); bool isRunning; @@ -41,11 +46,12 @@ class GameEngine EntityManager _entityManager; Logger& _logger; - std::string _currScene; - // Window* _window; - // std::vector<Asset> _assets; - // std::map< std::string, Scene > _scenes; + Window* _window; + std::vector<Asset> _assets; /** @todo : move this to scene */ + + std::string _currScene; + std::map< std::string, Scene* > _scenes; /* Systems */ // sUserInput diff --git a/include/scene.h b/include/scene.h index 20d4568..92ce89a 100644 --- a/include/scene.h +++ b/include/scene.h @@ -12,14 +12,15 @@ class Scene{ public: - Scene(); + Scene();// : _logger( Logger::instance() ) {} ~Scene(); virtual void update() = 0; virtual void simulate() = 0; virtual void doAction() = 0; + virtual void render() = 0; virtual void registerAction() = 0; - private: + protected: std::vector<Asset> _assets; Logger& _logger; diff --git a/include/scenes/scene_play.h b/include/scenes/scene_play.h new file mode 100644 index 0000000..16483a5 --- /dev/null +++ b/include/scenes/scene_play.h @@ -0,0 +1,24 @@ +#ifndef __SCENES__PLAY_H__ +#define __SCENES__PLAY_H__ + +#include "scene.h" +#include "entities/entity.h" + +class ScenePlay : public Scene +{ + public: + void update(); + void simulate(); + void doAction(); + void render(); + void registerAction(); + + private: + std::string _levelPath; + Entity* _player; + + // Systems + // sAnimation(); +}; + +#endif // __SCENES__PLAY_H__ diff --git a/makefile b/makefile index a27274b..d4a020e 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,7 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_PATCH = 0 + ifeq ($(OS),Windows_NT) CXX = g++ # or your Windows compiler CXXFLAGS = -std=c++17 -Wall -Wreorder @@ -72,8 +76,8 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp ${INC_DIR}/*.h clean: rm -rf $(BIN_DIR)/* $(BUILD_DIR)/* test_runnr - rm -rf ./*~ ./*.swp - rm -rf *~ + rm -r ./*~ + rm -r $(SRC_DIR)/*~ ${INC_DIR}/*~ run_tests: $(TEST_OBJ_FILES) $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INC_DIRS) -o ${TEST_TARGET} $^ diff --git a/src/asset.cpp b/src/asset.cpp index b3b506f..ab192b5 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -4,3 +4,5 @@ Asset::Asset() : _logger( Logger::instance() ) { this->_logger.info( "New asset created" ); } Asset::~Asset(){} + +void Asset::loadMedia( std::string path ) {} diff --git a/src/chunk.cpp b/src/chunk.cpp index ec60f2e..33f8a13 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -2,11 +2,9 @@ Chunk::Chunk( int x, int y, int z ) - : _x(x), _y(y), _z(z), - _logger( Logger::instance() ) -{ - this->generate(); -} + : _logger( Logger::instance() ), + _x(x), _y(y), _z(z) +{ this->generate(); } Chunk::~Chunk() { // this->_logger.info( "Deleting Chunk" ); diff --git a/src/entities/entity.cpp b/src/entities/entity.cpp index 2c0f0e9..b493de0 100644 --- a/src/entities/entity.cpp +++ b/src/entities/entity.cpp @@ -2,7 +2,7 @@ Entity::Entity( const std::string& tag, size_t id -) : _tag( tag ), _id( id ), - _logger( Logger::instance() ) +) : _logger( Logger::instance() ), + _id(id), _tag( tag ) { this->_logger.info( "Generic Entity Created" ); } Entity::~Entity(){} diff --git a/src/game-engine.cpp b/src/game-engine.cpp index 1219df9..8c51eb8 100644 --- a/src/game-engine.cpp +++ b/src/game-engine.cpp @@ -16,11 +16,17 @@ void GameEngine::init() this->isRunning = false; this->_currScene = ""; } -// void GameEngine::changeScene( Scene scene ){} -Scene* GameEngine::currentScene() +void GameEngine::changeScene( std::string label, Scene* scene ) { - return nullptr; + this->_scenes[ label ] = scene; + this->_currScene = label; } +void GameEngine::changeScene( std::string label ) + { this->_currScene = label; } + +Scene* GameEngine::currentScene() + { return this->_scenes[this->_currScene]; } + void GameEngine::run() { this->isRunning = true; @@ -38,9 +44,9 @@ void GameEngine::update() if( ++this->_frame > 10000 ) { this->close(); } else if ( this->_frame % 1000 == 0 ) { std::time_t cTime = std::chrono::system_clock::to_time_t(now); - size_t delTime = cTime - this->_frametime; + // size_t delTime = cTime - this->_frametime; this->_frametime = cTime; - printf( "Frame: %i at %.2f fps\n", this->_frame / 1000, delTime == 0 ? 0.0 : 1.0 / delTime ); + // printf( "Frame: %i at %.2f fps\n", this->_frame / 1000, delTime == 0 ? 0.0 : 1.0 / delTime ); } } void GameEngine::handleInput() { } diff --git a/src/scenes/scene_play.cpp b/src/scenes/scene_play.cpp new file mode 100644 index 0000000..9572ee8 --- /dev/null +++ b/src/scenes/scene_play.cpp @@ -0,0 +1,7 @@ +#include "scenes/scene_play.h" + +void ScenePlay::update(){} +void ScenePlay::simulate(){} +void ScenePlay::doAction(){} +void ScenePlay::render(){} +void ScenePlay::registerAction(){} diff --git a/src/world-hex-2d.cpp b/src/world-hex-2d.cpp index 2e7ced3..6892f4e 100644 --- a/src/world-hex-2d.cpp +++ b/src/world-hex-2d.cpp @@ -8,8 +8,8 @@ WorldHex2D::WorldHex2D( uint8_t radius ) ) {} WorldHex2D::WorldHex2D( uint8_t width, uint8_t height, uint8_t depth) - : _width( width ), _height( height ), _depth( depth ), - _logger( Logger::instance() ) + : _logger( Logger::instance() ), + _width( width ), _height( height ), _depth( depth ) { this->_logger.info( "Creating Hex Map" ); this->generateWorld(); diff --git a/src/world-map3d.cpp b/src/world-map3d.cpp index c34b95a..010bef0 100644 --- a/src/world-map3d.cpp +++ b/src/world-map3d.cpp @@ -7,8 +7,9 @@ WorldMap3D::WorldMap3D( uint8_t width, uint8_t height, uint8_t depth -) : _width(width), _height(height), _depth(depth), - _logger( Logger::instance() ) +) : + _logger( Logger::instance() ), + _width(width), _height(height), _depth(depth) { this->_logger.info( "Creating new world" ); this->generateWorld(); -- GitLab