added simple scene manager and classes Scene and SceneNode

This commit is contained in:
Lendemor 2015-07-28 21:46:25 +02:00
parent 1adae53287
commit 7fd5fbde46
8 changed files with 115 additions and 18 deletions

View File

@ -7,7 +7,7 @@ else(WIN32)
set(SYSTEM_LIB_PATH "linux") set(SYSTEM_LIB_PATH "linux")
endif(WIN32) endif(WIN32)
set(LIB_SRC_LIST engine.cpp) set(LIB_SRC_LIST engine.cpp scenemanager.cpp scene.cpp)
set(LIBRARY_NAME ${PROJECT_NAME}) set(LIBRARY_NAME ${PROJECT_NAME})
set(EXECUTABLE_NAME "test${PROJECT_NAME}") set(EXECUTABLE_NAME "test${PROJECT_NAME}")

View File

@ -1,41 +1,41 @@
#include "engine.h" #include "engine.h"
#include "scenemanager.h"
//#include "bullet/btBulletCollisionCommon.h" //#include "bullet/btBulletCollisionCommon.h"
//#include "bullet/btBulletDynamicsCommon.h" //#include "bullet/btBulletDynamicsCommon.h"
Engine::Engine(Input* _input): input(_input) Engine::Engine(Input* input): m_input(input)
{ {
m_clock.restart();
} }
void Engine::update() void Engine::update()
{ {
//update time variable //update time variable
lastTimeStamp = timeStamp; m_lastTimeStamp = m_timeStamp;
timeStamp = (unsigned int) clock.getElapsedTime().asMilliseconds(); m_timeStamp = (unsigned int) m_clock.getElapsedTime().asMilliseconds();
//update Events //update Events
input->updateEvents(); m_input->updateEvents();
render();
updatePhysics();
} }
void Engine::render() void Engine::render()
{ {
//call to SparrowRenderer // work for SparrowRenderer
} }
void Engine::updatePhysics() void Engine::updatePhysics()
{ {
//update world // work for Bullet
} }
unsigned int Engine::getTime() unsigned int Engine::getTime()
{ {
return timeStamp; return m_timeStamp;
} }
unsigned int Engine::getDeltaTime() unsigned int Engine::getDeltaTime()
{ {
return timeStamp - lastTimeStamp; return m_timeStamp - m_lastTimeStamp;
} }

View File

@ -5,7 +5,7 @@
class Engine{ class Engine{
public: public:
Engine(Input* _input); Engine(Input* input);
//main function //main function
void update(); void update();
void render(); void render();
@ -16,10 +16,10 @@ public:
unsigned int getDeltaTime(); unsigned int getDeltaTime();
private: private:
Input* input; Input* m_input;
sf::Clock clock; sf::Clock m_clock;
unsigned int timeStamp = 0; unsigned int m_timeStamp = 0;
unsigned int lastTimeStamp = 0; unsigned int m_lastTimeStamp = 0;
}; };
#endif #endif

View File

@ -6,5 +6,8 @@ int main(){
Engine engine = Engine(input); Engine engine = Engine(input);
while(!input->isCloseRequested()){ while(!input->isCloseRequested()){
engine.update(); engine.update();
// game content
engine.updatePhysics();
engine.render();
} }
} }

16
scene.cpp Normal file
View File

@ -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
}

26
scene.h Normal file
View File

@ -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

27
scenemanager.cpp Normal file
View File

@ -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();
}

25
scenemanager.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef SCENEMANAGER_H
#define SCENEMANAGER_H
#include <string>
#include <unordered_map>
//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<std::string, Scene*> scenes;
};
#endif // SCENEMANAGER_H