diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 649e3e84832e46e250ff742c8012f0633db20ca5..95b3ba1d76d72dc37caa5f0a3ae8dfc298cbe687 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,45 +2,33 @@ # 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/Getting-Started.gitlab-ci.yml +# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/C++.gitlab-ci.yml -# This is a sample GitLab CI/CD configuration file that should run without any modifications. -# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, -# it uses echo commands to simulate the pipeline execution. -# -# A pipeline is composed of independent jobs that run scripts, grouped into stages. -# Stages run in sequential order, but jobs within stages run in parallel. -# -# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages +# use the official gcc image, based on debian +# can use versions as well, like gcc:5.2 +# see https://hub.docker.com/_/gcc/ -stages: # List of stages for jobs, and their order of execution - - build - - test - - deploy +image: gcc -build-job: # This job runs in the build stage, which runs first. +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 script: - - echo "Compiling the code..." - - echo "Compile complete." - make + 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" -unit-test-job: # This job runs in the test stage. - stage: test # It only starts when the job in the build stage completes successfully. +# run tests using the binary built before +test: + stage: test script: - - echo "Running unit tests... This will take about 60 seconds." - - sleep 60 - - echo "Code coverage is 90%" - -lint-test-job: # This job also runs in the test stage. - stage: test # It can run at the same time as unit-test-job (in parallel). - script: - - echo "Linting code... This will take about 10 seconds." - - sleep 10 - - echo "No lint issues found." - -deploy-job: # This job runs in the deploy stage. - stage: deploy # It only runs when *both* jobs in the test stage complete successfully. - script: - - echo "Deploying application..." - - echo "Application successfully deployed." + - echo "Dummy Testing" diff --git a/config/settings.cfg b/config/settings.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f5194b45e584bcb17e35f1d7d511f8d005e0f9d9 --- /dev/null +++ b/config/settings.cfg @@ -0,0 +1,7 @@ +# comment test +test1: test +test2: tedfh +duplicate: test1 +duplicate: test2 +duplicate: test3 +comment: Example comment # this should not render diff --git a/include/components/components-generic.h b/include/components/components-generic.h new file mode 100644 index 0000000000000000000000000000000000000000..f070a6d0291e1546db35fe4e43366737d7b9eb5f --- /dev/null +++ b/include/components/components-generic.h @@ -0,0 +1,11 @@ +#ifndef __COMPONENTS__COMPONENT_GENERIC_H__ +#define __COMPONENTS__COMPONENT_GENERIC_H__ + +class CComponentGeneric +{ + public: + CComponentGeneric(); + ~CComponentGeneric(); +}; + +#endif // __COMPONENTS__COMPONENT_GENERIC_H__ diff --git a/include/config-parser.h b/include/config-parser.h new file mode 100644 index 0000000000000000000000000000000000000000..3f0b9d923db8915665283cab306a75ddf18477ce --- /dev/null +++ b/include/config-parser.h @@ -0,0 +1,48 @@ +#ifndef __CONFIG_PARSER_H__ +#define __CONFIG_PARSER_H__ + +#include <string> +#include <iostream> +#include <filesystem> +#include <map> + +#include "logger.h" + +typedef std::pair<std::string,std::string> keyPair; +typedef std::map<std::string,std::string> ConfigMap; + +class ConfigParser +{ + friend std::ostream& operator<<( std::ostream& os, const ConfigParser& obj ); + + public: + static ConfigParser UserSettings(); + + ~ConfigParser(); + + ConfigMap userSettings(){ return this->readFile( "settings.cfg" ); } + + void set( std::string key, std::string value ); + std::string get( std::string key ); + + std::string toString() const; + + private: + std::string _path; + ConfigParser( std::string path ); + const std::string CONFIG_DIRECTORY = "config"; + const char DELIMINATOR = ':'; + const char COMMENT_CHAR = '#'; + Logger& _logger; + + ConfigMap _config; + + ConfigMap readFile( std::string path ); + // void writeConfigFile( std::map settings ); + + std::string getKey( std::string line ); + std::string getValue( std::string line ); +}; + +#endif // __CONFIG_PARSER_H__ + diff --git a/include/entities/entity-generic.h b/include/entities/entity-generic.h new file mode 100644 index 0000000000000000000000000000000000000000..aef3d46522b24e45c1c45ffe4bd9619b28aa41ff --- /dev/null +++ b/include/entities/entity-generic.h @@ -0,0 +1,33 @@ + +#ifndef __ENTITIES__ENTITY_GENERIC_H +#define __ENTITIES__ENTITY_GENERIC_H + +// #include "entity-manager.h" +#include "logger.h" + +class EntityGeneric +{ + // friend class EntityManager; + public: + EntityGeneric( const std::string& tag, size_t id ); /** @todo make this private */ + ~EntityGeneric(); + + bool isAlive() { return this->_alive; } + bool isDead() { return ! this->_alive; } + void kill() { this->_alive = false; } + + // Component Variables + const std::string& tag() { return this->_tag; } + + private: + Logger& _logger; + + const size_t _id = 0; + const std::string _tag = "Default"; + bool _alive = true; + +}; + +typedef EntityGeneric Entity; + +#endif // __ENTITIES__ENTITY_GENERIC_H diff --git a/include/entity-manager.h b/include/entity-manager.h new file mode 100644 index 0000000000000000000000000000000000000000..c554c52240fa7da8dcee6de851cadd0e8aca6a3b --- /dev/null +++ b/include/entity-manager.h @@ -0,0 +1,37 @@ +#ifndef __ENTITY_MANAGER_H__ +#define __ENTITY_MANAGER_H__ + +#include <string> +#include <vector> +#include <memory> +#include <map> + +#include "logger.h" +#include "entities/entity-generic.h" + +typedef EntityGeneric Entity; +typedef std::vector<std::shared_ptr<EntityGeneric>> EntityVector; +typedef std::map< std::string, EntityVector > EntityMap; + +class EntityManager +{ + public: + EntityManager(); + ~EntityManager(); + std::shared_ptr<EntityGeneric> addEntity( const std::string& tag ); + void removeEntity(); + void update(); + + EntityVector& getEntities(); + EntityVector& getEntities( const std::string& tag ); + private: + Logger& _logger; + EntityVector _entities; + EntityVector _entitiesToAdd; + EntityMap _entityMap; + size_t _totalEntities = 0; + + size_t nextId() { return this->_totalEntities++; } +}; + +#endif // __ENTITY_MANAGER_H__ diff --git a/include/game-engine.h b/include/game-engine.h new file mode 100644 index 0000000000000000000000000000000000000000..4f92753c5626595e9dd54380754d710edaf696d0 --- /dev/null +++ b/include/game-engine.h @@ -0,0 +1,41 @@ +#ifndef __GAME_H__ +#define __GAME_H__ + +#include <map> +#include <string> +#include <vector> + +#include "logger.h" +#include "entity-manager.h" +#include "scene.h" + +class GameEngine +{ + public: + GameEngine(); + ~GameEngine(); + void init(); + void run(); + void update(); + void close(); + Scene* currentScene(); + void changeScene( Scene scene ); + // std::vector< Asset& > getAssets(); + // Window& getWindow(); + + bool isRunning; + private: + EntityManager _entityManager; + Logger& _logger; + + std::string _currScene; + + // Window* _window; + // std::vector<Asset> _assets; + std::map< std::string, Scene > _scenes; + + /* Systems */ + // sUserInput +}; + +#endif // __GAME_H__ diff --git a/include/main.h b/include/main.h index d402445bd0929ad316e5786de22327021465c581..2073f875790e074cc12c06de431360290940c494 100644 --- a/include/main.h +++ b/include/main.h @@ -4,12 +4,11 @@ #include <iostream> #include <cstdint> -#define SDL_MAIN_HANDLED -#include <SDL.h> enum GenerationMethod { - Random + Random, + Cave }; #include "save-manager.h" @@ -17,6 +16,11 @@ enum GenerationMethod #include "world-hex-2d.h" #include "world-map-3d.h" #include "chunk.h" +#include "config-parser.h" +#include "game-engine.h" #include "logger.h" +#include "entities/entity-generic.h" +#include "maths/maths.h" +#include "entity-manager.h" #endif // MAIN_H diff --git a/include/maths/maths.h b/include/maths/maths.h new file mode 100644 index 0000000000000000000000000000000000000000..048083693f92000b84d23b2b5eb9415a68e4edd1 --- /dev/null +++ b/include/maths/maths.h @@ -0,0 +1,7 @@ +#ifndef __MATHEMATICS_INCLUDE_H__ +#define __MATHEMATICS_INCLUDE_H__ + +#include "maths/vec2.h" +#include "maths/rect.h" + +#endif // __MATHEMATICS_INCLUDE_H__ diff --git a/include/maths/rect.h b/include/maths/rect.h new file mode 100644 index 0000000000000000000000000000000000000000..fc836ea2b7d7732c0cd9af64c7b2a3dcebdb04f2 --- /dev/null +++ b/include/maths/rect.h @@ -0,0 +1,26 @@ +#ifndef __MATHS_RECT_H__ +#define __MATHS_RECT_H__ + +#include "maths/vec2.h" + +class Rect +{ + public: + Rect( float x, float y, float w, float h ); + Rect( Vec2 pt, float w, float h ); + ~Rect(){} + + bool isOverlap( Vec2 pt ); + bool isOverlap( Rect rect ); + + bool overlap_horizontal( Rect rect ); + bool overlap_vertical( Rect rect ); + + private: + Vec2 _pt; + float _halfWidth; + float _halfHeight; +}; + + +#endif // __MATHS_RECT_H__ diff --git a/include/maths/vec2.h b/include/maths/vec2.h new file mode 100644 index 0000000000000000000000000000000000000000..e01f0f7b9c4172905bb6e0e114b2530983b771cd --- /dev/null +++ b/include/maths/vec2.h @@ -0,0 +1,27 @@ +#ifndef __MATHS__VEC2_H__ +#define __MATHS__VEC2_H__ + +#include <cmath> + +class Vec2 +{ + public: + float x = 0, y = 0; + Vec2(); + Vec2( float xIn, float yIn ); + + bool operator == ( const Vec2 rhs ) const; + Vec2 operator + ( const Vec2 rhs ) const; + Vec2 operator * ( const Vec2 rhs ) const; + Vec2 operator - ( const Vec2 rhs ) const; + Vec2 operator * ( const float scale ) const; + void operator += ( const Vec2 & rhs ); + void operator -= ( const Vec2 & rhs ); + void operator *= ( const Vec2 & rhs ); + void operator *= ( const float rhs ); + + float length(); + void normalise(); +}; + +#endif // __MATHS__VEC2_H__ diff --git a/include/scene.h b/include/scene.h new file mode 100644 index 0000000000000000000000000000000000000000..149f98d55d7c0700570d500b4a18273afef7155c --- /dev/null +++ b/include/scene.h @@ -0,0 +1,14 @@ +#ifndef __SCENE_H__ +#define __SCENE_H__ + +#include "logger.h" + +class Scene{ + public: + Scene(); + ~Scene(); + private: + Logger& _logger; +}; + +#endif // __SCENE_H__ diff --git a/include/systems/system-core.h b/include/systems/system-core.h new file mode 100644 index 0000000000000000000000000000000000000000..ab735f82d851c31c2e7e05661a1a28c0f3981943 --- /dev/null +++ b/include/systems/system-core.h @@ -0,0 +1,16 @@ +#ifndef __SYSTEMS__SYSTEM_CORE_H_ +#define __SYSTEMS__SYSTEM_CORE_H_ + +#include "logger.h" + +class SystemsGeneric +{ + + public: + SystemsGeneric(); + ~SystemsGeneric(); + private: + Logger& _logger; +}; + +#endif // __SYSTEMS__SYSTEM_CORE_H_ diff --git a/makefile b/makefile index aef12b9e1fa5d81b44558cb423b0da76225725bd..ff9d6bf6cff15dbededc3a09adea9934f32a03b3 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,24 @@ -# Makefile for Simple Game - -# Compiler +ifeq ($(OS),Windows_NT) +CXX = g++ # or your Windows compiler +CXXFLAGS = -std=c++17 -Wall -Wreorder +RM = del /Q +else +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) CXX = g++ +CXXFLAGS = -std=c++17 -Wall -Wreorder +RM = rm -f +endif +# Add more conditions for other platforms as needed +endif # Compiler flags -CXXFLAGS = -std=c++17 -Wall -Wreorder -g + +# DEBUG BUILD +CXXFLAGS += -g + +# Linker Flags +LDFLAGS = # Source directory SRC_DIR = src @@ -29,7 +43,7 @@ SDL_OPTIONS = -lSDL2main -lSDL2 # Source files SRC_FILES = $(wildcard $(SRC_DIR)/**/*.cpp $(SRC_DIR)/*.cpp ) -SRC_FILES_ = $(wildcard $(SRC_DIR)/*.cpp) + # Test Files TEST_FILES = $(wildcard $(TEST_DIR)/**/*.test.cpp $(TEST_DIR)/*.test.cpp) @@ -39,30 +53,30 @@ TEST_OBJ_FILES = $(patsubst $(TEST_DIR)/%.test.cpp,$(BUILD_DIR)/%.o,$(TEST_FILES # Output executable TARGET = $(BIN_DIR)/game +TEST_TARGET = $(BIN_DIR)/test_runner all: $(TARGET) $(TARGET): $(OBJ_FILES) $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ_FILES) $(SDL_LIBRARY) $(SDL_OPTIONS) -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp ${INC_DIR}/*.h @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) ${SDL_INCLUDE} -I$(INC_DIR) -c -o $@ $< -# $(CXX) $(CXXFLAGS) -I$(INC_DIR) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -I$(INC_DIR) -c -o $@ $< clean: rm -rf $(BIN_DIR)/* $(BUILD_DIR)/* test_runnr rm -rf ./*~ ./*.swp + rm -rf *~ run_tests: $(TEST_OBJ_FILES) - $(CC) $(CFLAGS) $(INC_DIRS) -o test_runner $^ - ./test_runner + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INC_DIRS) -o ${TEST_TARGET} $^ + ./${TEST_TARGET} $(BUILD_DIR)/%.o: $(TEST_DIR)/%.test.cpp @mkdir -p $(@D) - $(CC) $(CFLAGS) $(INC_DIRS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INC_DIRS) -c -o $@ $< run: $(TARGET) ./$(TARGET) - diff --git a/readme.md b/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..b7df97f9533f7bd3d4e98a3279692c58411a90f9 --- /dev/null +++ b/readme.md @@ -0,0 +1,138 @@ +# SpaceOK + +## Overview + +I'm just having fun making a game in my spare time. + +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) +- [Features](#features) +- [Contributing](#contributing) +- [FAQ](#faq) +- [Community Support](#community-support) +- [License](#license) +- [Acknowledgements](#acknowledgements) +- [License](#license) + +## Installation + +Provide instructions on how to install and set up your project. Include any dependencies and steps needed to run the project. + +```bash +# Example installation command or steps +git clone https://gitlab.ucc.asn.au/aburgess/spaceok.git +cd spaceok +make run +``` + +## Usage + +### Controls + +### Config + +## Features + +### Core Gameplay + +1. **Turn-Based Gameplay:** + - Implement a turn-based system where players take turns to make decisions and actions. + +2. **Hexagon Grid World:** + - Design and render the game world using a hexagon grid system. + +3. **Procedural World Generation:** + - Generate the game world dynamically with procedural algorithms. + +4. **Resource Management:** + - Include a system for collecting, managing, and utilizing in-game resources. + +5. **Player and NPC Interaction:** + - Implement interactions between the player and non-player characters (NPCs). + +### Game Mechanics + +6. **Combat System:** + - Develop a combat system with attacks, defenses, and damage calculations. + +7. **Quest and Mission System:** + - Create a system for assigning quests or missions to players. + +8. **Character Progression:** + - Design a system for character development and progression, including leveling up and skill acquisition. + +9. **Inventory System:** + - Implement an inventory system for storing and managing items. + +10. **Day-Night Cycle:** + - Include a dynamic day-night cycle that affects gameplay and visuals. + +## User Interface (UI) + +11. **Main Menu:** + - Design an intuitive main menu for starting, loading, and exiting the game. + +12. **In-Game HUD:** + - Create a heads-up display (HUD) to show essential information during gameplay. + +13. **Dialog System:** + - Implement a dialogue system for in-game conversations. + +14. **Map and Navigation:** + - Provide a map and navigation system to help players navigate the game world. + +### Graphics and Sound + +15. **2D Art and Animation:** + - Integrate 2D art and animations for characters, objects, and visual effects. + +16. **Sound Effects and Music:** + - Include sound effects and background music to enhance the gaming experience. + +### Additional Features + +17. **Save and Load System:** + - Develop a system for saving and loading game progress. + +18. **Achievements and Rewards:** + - Implement achievements and reward systems for completing specific tasks or milestones. + +19. **Multiplayer Functionality:** + - Optionally, add multiplayer features such as co-op or competitive gameplay. + +20. **Modding Support:** + - Provide support for modding, allowing players to create and share custom content. + +### Future Enhancements + +21. **Additional Game Modes:** + - Consider future game modes or expansions to extend the replay value. + +22. **Accessibility Features:** + - Explore options for making the game accessible to a broader audience. + +23. **Cross-Platform Compatibility:** + - Investigate the possibility of making the game compatible with multiple platforms. + +24. **Community and Social Integration:** + - Integrate features that encourage community interaction and social sharing. + +## Contributing + +If you would like others to contribute to your project, provide guidelines on how to do so. + +1. Fork the project +2. Create a new branch (`git checkout -b feature/new-feature`) +3. Commit your changes (`git commit -am 'Add new feature'`) +4. Push to the branch (`git push origin feature/new-feature`) +5. Open a pull request + +## FAQ + +## Community Support + +## License + +## Acknowledgements diff --git a/src/Scene.cpp b/src/Scene.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d38a18b8bb40f780f5b1b9ea39cc3b99c80e406 --- /dev/null +++ b/src/Scene.cpp @@ -0,0 +1,8 @@ +#include "scene.h" + + +Scene::Scene() + : _logger( Logger::instance() ) +{ this->_logger.info( "Creating new Scene" ); } +Scene::~Scene() + { this->_logger.info( "Deleting Scene" ); } diff --git a/src/chunk.cpp b/src/chunk.cpp index 1d335fb198f08aa744910d4690bf425a7db306e8..ec60f2ea3da6b7e9b653262b65833e8e9aaa628d 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -46,7 +46,7 @@ std::string Chunk::getRadiationString() const { return std::to_string(this->radi std::string Chunk::getAgeString() const { return std::to_string(this->age); } std::string Chunk::getString( ChunkQuery format ) const - {return "rest";} + { return "rest"; } void Chunk::visualise() const { std::cout << this->getString() << std::endl; } std::string Chunk::getString() const diff --git a/src/components/components-generic.cpp b/src/components/components-generic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca920c9abbe2914e6fc45ed4fe4d346892fb06dc --- /dev/null +++ b/src/components/components-generic.cpp @@ -0,0 +1,4 @@ +#include "components/components-generic.h" + +CComponentGeneric::CComponentGeneric(){} +CComponentGeneric::~CComponentGeneric(){} diff --git a/src/config-parser.cpp b/src/config-parser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e6266e06911a94b4928f19c9080ffbf6ee373345 --- /dev/null +++ b/src/config-parser.cpp @@ -0,0 +1,99 @@ +#include "config-parser.h" + +ConfigParser ConfigParser::UserSettings() +{ + ConfigParser parser("settings.cfg"); + return parser; +} + +void ConfigParser::set( std::string key, std::string value ) + { this->_config[key] = value; } + +std::string ConfigParser::get( std::string key ) + { return this->_config[key]; } + +std::string ConfigParser::toString() const +{ + std::string str = "Config File: "+this->_path+"\n"; + for( const auto [key, value] : this->_config ) + { str += "["+key+"] "+value+"\n"; } + return str; +} + + +ConfigParser::ConfigParser( std::string path ) + : _path(path), _logger( Logger::instance() ) +{ + this->_logger.info( "Creating config parser" ); + this->readFile( path ); +} + +ConfigParser::~ConfigParser() + { this->_logger.info( "Closing config parser" ); } + + +ConfigMap ConfigParser::readFile( std::string path ) +{ + ConfigMap confMap; + if( ! std::filesystem::is_directory( CONFIG_DIRECTORY ) ) + { + this->_logger.warning( "Unable to read config directory" ); + return confMap; + } + + std::ifstream file( CONFIG_DIRECTORY+"/"+path ); + if( file.is_open() ) + { + std::string line; + while( std::getline(file, line) ) + { + if( ! line.empty() ) + { + if( line.at(0) == COMMENT_CHAR ) + { continue; } + std::string key = this->getKey( line ); + std::string value = this->getKey( line ); + if( ! key.empty() && ! value.empty() ) + { confMap[key] = value; } + std::cout << key << "," << value << std::endl; + // { confMap.insert( keyPair(key, value) ); } + } + } + } else + { this->_logger.error( "Unable to load specified configuration file:\n"+path ); } + + this->_config = confMap; + return confMap; +} + +std::string ConfigParser::getKey( std::string line ) +{ + std::string key = ""; + for( char ch : line ) + { + if( ch == DELIMINATOR + || ch == COMMENT_CHAR + ) { break; } + else if ( ! std::isspace(ch) ) { key.push_back( ch ) ; } + } + return key; +} + +std::string ConfigParser::getValue( std::string line ) +{ + std::string value = ""; + bool hasFound = false; + for( char ch : line ) + { + if( ch == DELIMINATOR + || COMMENT_CHAR == ch + ) { break; } + else if ( hasFound ) { value.push_back( ch ) ; } + } + return value; +} + +std::ostream& operator<<( std::ostream& os, const ConfigParser& obj ) +{ + return os << obj.toString(); +} diff --git a/src/entities/entity-generic.cpp b/src/entities/entity-generic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a56b644e2f6ed8101df4e4fcf7ac9434ef5b091 --- /dev/null +++ b/src/entities/entity-generic.cpp @@ -0,0 +1,8 @@ +#include "entities/entity-generic.h" + +EntityGeneric::EntityGeneric( + const std::string& tag, size_t id +) : _tag( tag ), _id( id ), + _logger( Logger::instance() ) +{ this->_logger.info( "Generic Entity Created" ); } +EntityGeneric::~EntityGeneric(){} diff --git a/src/entity-manager.cpp b/src/entity-manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fb1e62a9b43f5fa225d80086bf5a2289866cda8 --- /dev/null +++ b/src/entity-manager.cpp @@ -0,0 +1,45 @@ +#include "entity-manager.h" + +EntityManager::EntityManager() + : _logger( Logger::instance() ) +{ this->_logger.info( "Creating entity manager" ); } +EntityManager::~EntityManager() +{ + // while( auto entity = ) + // { delete entity; } + + this->_logger.info( "Deleting entity manager" ); +} +std::shared_ptr<Entity> EntityManager::addEntity( const std::string& tag ) +{ + auto entity = std::shared_ptr< Entity >( new EntityGeneric( tag, this->nextId() ) ); + this->_entitiesToAdd.push_back( entity ); + return entity; +} + +EntityVector& EntityManager::getEntities(){ return this->_entities; } +EntityVector& EntityManager::getEntities( const std::string& tag ){ + return this->_entities; +} + +void EntityManager::update() +{ + for( auto entity : this->_entities ) + { + if( entity->isDead() ) + { + /** @todo Implement this with a clean deletion taking into account iterator invalidation + */ + // Remove from this->entities; + // Remove from this->entitiesMap; + } + } + for( auto entity : this->_entitiesToAdd ) + { + this->_entities.push_back( entity ); + this->_entityMap[entity->tag()].push_back( entity ); + } + this->_entitiesToAdd.clear(); +} + +void EntityManager::removeEntity(){} diff --git a/src/game-engine.cpp b/src/game-engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea8cbdcb7f94b39c6400b8e5260f8b90af310c7d --- /dev/null +++ b/src/game-engine.cpp @@ -0,0 +1,31 @@ +#include "game-engine.h" + + +GameEngine::GameEngine() + : _logger( Logger::instance() ) +{ + this->_logger.info( "Creating GameEngine Object" ); +} +GameEngine::~GameEngine() +{ + this->_logger.info( "Cleaning GameEngine Object" ); +} +void GameEngine::close(){} +void GameEngine::init() +{ + this->isRunning = false; + this->_currScene = ""; +} +void GameEngine::changeScene( Scene scene ){} +Scene* GameEngine::currentScene() +{ + return nullptr; +} +void GameEngine::run() +{ + this->isRunning = true; +} +void GameEngine::update() +{ + this->_entityManager.update(); +} diff --git a/src/logger.cpp b/src/logger.cpp index 43da8d80e3e9bf398cd2b0f60a3c9e502bc5cc14..bcff28df1129589bd4b6660e61388cc03f585753 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -17,7 +17,7 @@ void Logger::fatal( const std::string& message ) { this->log( LogLevel::FATAL, m Logger::Logger() : currentLogLevel( LogLevel::INFO ) { this->info("New Logger instance created"); } -Logger::~Logger(){} +Logger::~Logger(){ this->info( "Closing Logger System" ); } void Logger::log(LogLevel level, const std::string& message) { diff --git a/src/main.cpp b/src/main.cpp index 3193ad1d10f6893c38f6f119dc0ef24cb700ab24..242a827ea462a60618bf7f86fab54c20ccf7cae8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,38 +10,17 @@ int main( int argc, char* argv[] ) { // Initialise Logger& logger = Logger::instance(); int tickCount = 0; + int _frame = 0; SaveManager saveManager; state = Initialise; - // Seed the random number generator - srand(static_cast<unsigned int>(time(nullptr))); - - SDL_Window* window = NULL; - SDL_Surface* screenSurface = NULL; - - //Initialize SDL - if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) - { - // printf( "SDL could not initialize! SDL_Error: \n%s\n", SDL_GetError() ); - logger.error( "Failed to initialise SDL" ); - return 1; - } - window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); - if( window == NULL ) - { - printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); - } else { - //Get window surface - screenSurface = SDL_GetWindowSurface( window ); - //Fill the surface white - SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) ); + ConfigParser userSettings = ConfigParser::UserSettings(); - //Update the surface - SDL_UpdateWindowSurface( window ); + EntityManager entityManager; - //Hack to get window to stay up - SDL_Event e; bool quit = false; while( quit == false ){ while( SDL_PollEvent( &e ) ){ if( e.type == SDL_QUIT ) quit = true; } } - } + // Seed the random number generator + srand(static_cast<unsigned int>(time(nullptr))); + std::vector< EntityGeneric* > entities; // Genrate a Random chunk WorldHex2D map( 5 ); //Chunk* chunk = new Chunk( 0, 0, 0); @@ -59,6 +38,9 @@ int main( int argc, char* argv[] ) { // List Saves saveManager.list(); + + GameEngine* game = new GameEngine(); + // Main Loop while( state != Exit ) { @@ -68,19 +50,29 @@ int main( int argc, char* argv[] ) { state = Exit; } - + // Update Entities + game->update(); // Process Input + // Movement Updates + // Collision Updates // Update Game State // Render Game - } - // Clean-up - //Destroy window - SDL_DestroyWindow( window ); + _frame++; + } - //Quit SDL subsystems - SDL_Quit(); + userSettings.set( "exit", "teset" ); + std::cout << userSettings; + // Clean-up + while( entities.size() > 0 ) + { + EntityGeneric* entity = entities.back(); + entities.pop_back(); + delete entity; + } + delete game; + // Return logger.info( "Process Ending" ); return 0; diff --git a/src/maths/rect.cpp b/src/maths/rect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..855294e429d5a5a50f77a975b556667188ab5b87 --- /dev/null +++ b/src/maths/rect.cpp @@ -0,0 +1,33 @@ +#include "maths/rect.h" + +Rect::Rect( float x, float y, float w, float h ) + : Rect( Vec2(x, y), w, h ) +{} +Rect::Rect( Vec2 pt, float w, float h ) + : _pt( pt ), + _halfWidth( w / 2 ), + _halfHeight( h / 2 ) +{} + +bool Rect::isOverlap( Vec2 pt ) +{ + return pt.x > ( pt.x - _halfWidth ) + && pt.x < ( pt.x + _halfWidth ) + && pt.y > ( pt.y - _halfHeight ) + && pt.y < ( pt.y + _halfHeight ); +} +bool Rect::isOverlap( Rect rect ) + { return this->overlap_horizontal( rect ) && this->overlap_vertical( rect ); } + + +bool Rect::overlap_horizontal( Rect rect ) +{ + return abs( this->_pt.x - rect._pt.x ) + < this->_halfWidth + rect._halfWidth; +} +bool Rect::overlap_vertical( Rect rect ) +{ + return abs( this->_pt.y - rect._pt.y ) + < this->_halfHeight + rect._halfHeight; +} + diff --git a/src/maths/vec2.cpp b/src/maths/vec2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aee6719eca9998cfe71c7094beeecd8925494870 --- /dev/null +++ b/src/maths/vec2.cpp @@ -0,0 +1,32 @@ +#include "maths/vec2.h" + +Vec2::Vec2() + : Vec2( 0.0, 0.0 ) {} +Vec2::Vec2( float xIn, float yIn ) + : x( xIn ), y( yIn ) +{}; + +bool Vec2::operator == ( const Vec2 rhs ) const { + return ( + abs( this->x - rhs.x ) < 0.01 + ) && ( + abs( this->y - rhs.y ) < 0.01 + ); +} +Vec2 Vec2::operator + ( const Vec2 rhs ) const { return Vec2( this->x + rhs.x, this->y + rhs.y ); } +Vec2 Vec2::operator - ( const Vec2 rhs ) const { return Vec2( this->x - rhs.x, this->y - rhs.y ); } +Vec2 Vec2::operator * ( const Vec2 rhs ) const { return Vec2( this->x * rhs.x, this->y * rhs.y ); } +Vec2 Vec2::operator * ( const float scale ) const { return Vec2( this->x * scale, this->y * scale ); } +void Vec2::operator += ( const Vec2 & rhs ) { this->x += rhs.x; this->y += rhs.y; } +void Vec2::operator -= ( const Vec2 & rhs ) { this->x -= rhs.x; this->y -= rhs.y; } +void Vec2::operator *= ( const Vec2 & rhs ) { this->x *= rhs.x; this->y *= rhs.y; } +void Vec2::operator *= ( const float scale ) { this->x *= scale; this->y *= scale; } + +float Vec2::length() + { return sqrtf( this->x*this->x + this->y*this->y ); } +void Vec2::normalise() +{ + float mag = this->length(); + this->x /= mag; + this->y /= mag; +} diff --git a/src/maths/vec2.cpp.back b/src/maths/vec2.cpp.back new file mode 100644 index 0000000000000000000000000000000000000000..aee6719eca9998cfe71c7094beeecd8925494870 --- /dev/null +++ b/src/maths/vec2.cpp.back @@ -0,0 +1,32 @@ +#include "maths/vec2.h" + +Vec2::Vec2() + : Vec2( 0.0, 0.0 ) {} +Vec2::Vec2( float xIn, float yIn ) + : x( xIn ), y( yIn ) +{}; + +bool Vec2::operator == ( const Vec2 rhs ) const { + return ( + abs( this->x - rhs.x ) < 0.01 + ) && ( + abs( this->y - rhs.y ) < 0.01 + ); +} +Vec2 Vec2::operator + ( const Vec2 rhs ) const { return Vec2( this->x + rhs.x, this->y + rhs.y ); } +Vec2 Vec2::operator - ( const Vec2 rhs ) const { return Vec2( this->x - rhs.x, this->y - rhs.y ); } +Vec2 Vec2::operator * ( const Vec2 rhs ) const { return Vec2( this->x * rhs.x, this->y * rhs.y ); } +Vec2 Vec2::operator * ( const float scale ) const { return Vec2( this->x * scale, this->y * scale ); } +void Vec2::operator += ( const Vec2 & rhs ) { this->x += rhs.x; this->y += rhs.y; } +void Vec2::operator -= ( const Vec2 & rhs ) { this->x -= rhs.x; this->y -= rhs.y; } +void Vec2::operator *= ( const Vec2 & rhs ) { this->x *= rhs.x; this->y *= rhs.y; } +void Vec2::operator *= ( const float scale ) { this->x *= scale; this->y *= scale; } + +float Vec2::length() + { return sqrtf( this->x*this->x + this->y*this->y ); } +void Vec2::normalise() +{ + float mag = this->length(); + this->x /= mag; + this->y /= mag; +} diff --git a/src/systems/system-core.cpp b/src/systems/system-core.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38775d1d48ab7d13181e0bcbf465432b25816dc9 --- /dev/null +++ b/src/systems/system-core.cpp @@ -0,0 +1,8 @@ +#include "systems/system-core.h" + + +SystemsGeneric::SystemsGeneric() + : _logger( Logger::instance() ) +{ this->_logger.info( "Generic System Created" ); } +SystemsGeneric::~SystemsGeneric() +{ this->_logger.info( "Generic System Deleted" ); }