diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a7eed..3d841d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ else(WIN32) set(SYSTEM_LIB_PATH "linux") endif(WIN32) -set(LIB_SRC_LIST engine.cpp) +set(LIB_SRC_LIST engine.cpp scenemanager.cpp scene.cpp) set(LIBRARY_NAME ${PROJECT_NAME}) set(EXECUTABLE_NAME "test${PROJECT_NAME}") diff --git a/engine.cpp b/engine.cpp index 85f8a4b..54266a0 100644 --- a/engine.cpp +++ b/engine.cpp @@ -1,41 +1,41 @@ #include "engine.h" + +#include "scenemanager.h" + //#include "bullet/btBulletCollisionCommon.h" //#include "bullet/btBulletDynamicsCommon.h" -Engine::Engine(Input* _input): input(_input) +Engine::Engine(Input* input): m_input(input) { - + m_clock.restart(); } void Engine::update() { //update time variable - lastTimeStamp = timeStamp; - timeStamp = (unsigned int) clock.getElapsedTime().asMilliseconds(); + m_lastTimeStamp = m_timeStamp; + m_timeStamp = (unsigned int) m_clock.getElapsedTime().asMilliseconds(); //update Events - input->updateEvents(); - - render(); - updatePhysics(); + m_input->updateEvents(); } void Engine::render() { - //call to SparrowRenderer + // work for SparrowRenderer } void Engine::updatePhysics() { - //update world + // work for Bullet } unsigned int Engine::getTime() { - return timeStamp; + return m_timeStamp; } unsigned int Engine::getDeltaTime() { - return timeStamp - lastTimeStamp; + return m_timeStamp - m_lastTimeStamp; } diff --git a/engine.h b/engine.h index 02a23ef..d92adf4 100644 --- a/engine.h +++ b/engine.h @@ -5,7 +5,7 @@ class Engine{ public: - Engine(Input* _input); + Engine(Input* input); //main function void update(); void render(); @@ -16,10 +16,10 @@ public: unsigned int getDeltaTime(); private: - Input* input; - sf::Clock clock; - unsigned int timeStamp = 0; - unsigned int lastTimeStamp = 0; + Input* m_input; + sf::Clock m_clock; + unsigned int m_timeStamp = 0; + unsigned int m_lastTimeStamp = 0; }; #endif diff --git a/main.cpp b/main.cpp index 6e14273..2ecdf27 100644 --- a/main.cpp +++ b/main.cpp @@ -6,5 +6,8 @@ int main(){ Engine engine = Engine(input); while(!input->isCloseRequested()){ engine.update(); + // game content + engine.updatePhysics(); + engine.render(); } } diff --git a/scene.cpp b/scene.cpp new file mode 100644 index 0000000..01fed41 --- /dev/null +++ b/scene.cpp @@ -0,0 +1,16 @@ +#include "scene.h" + +Scene::Scene() +{ + +} + +void Scene::update() +{ + //update call for all nodes +} + +void Scene::render() +{ + //render call for all nodes +} diff --git a/scene.h b/scene.h new file mode 100644 index 0000000..169f89b --- /dev/null +++ b/scene.h @@ -0,0 +1,26 @@ +#ifndef SCENE_H +#define SCENE_H + +class SceneNode; + +class Scene +{ +public: + Scene(); + void update(); + void render(); +private: + SceneNode* m_sceneNodeTree; +}; + + +class SceneNode +{ +public: + SceneNode(); + virtual void update(); +private: + SceneNode* m_parentNode; +}; + +#endif // SCENE_H diff --git a/scenemanager.cpp b/scenemanager.cpp new file mode 100644 index 0000000..3a8b761 --- /dev/null +++ b/scenemanager.cpp @@ -0,0 +1,27 @@ +#include "scenemanager.h" +#include "scene.h" + +SceneManager::SceneManager() +{ + +} + +void SceneManager::addScene(std::string scene_name, Scene *p_scene) +{ + scenes[scene_name] = p_scene; +} + +void SceneManager::setCurrentScene(std::string scene) +{ + if(scenes.count(scene)) p_currentScene = scenes[scene]; +} + +void SceneManager::update() +{ + p_currentScene->update(); +} + +void SceneManager::render() +{ + p_currentScene->render(); +} diff --git a/scenemanager.h b/scenemanager.h new file mode 100644 index 0000000..1fb8070 --- /dev/null +++ b/scenemanager.h @@ -0,0 +1,25 @@ +#ifndef SCENEMANAGER_H +#define SCENEMANAGER_H + +#include +#include + +//define macro similar to the one in SparrowResource ? + +class Scene; + +class SceneManager +{ +public: + SceneManager(); + void addScene(std::string scene_name, Scene* p_scene); + void setCurrentScene(std::string scene); + void update(); + void render(); + +private: + Scene* p_currentScene; + std::unordered_map scenes; +}; + +#endif // SCENEMANAGER_H