updating scenetree for the new renderer structure

This commit is contained in:
Anselme 2016-03-29 07:20:39 +02:00
parent f648b81ee3
commit 5fd9e791de
5 changed files with 39 additions and 25 deletions

View File

@ -99,7 +99,7 @@ unsigned int Engine::getDeltaTime()
return m_timeStamp - m_lastTimeStamp; return m_timeStamp - m_lastTimeStamp;
} }
void Engine::setScene(std::string sceneName) void Engine::setScene(SceneTree *scene)
{ {
m_scene = RESOURCE_GET(SceneTree, sceneName); m_scene = scene;
} }

View File

@ -23,7 +23,7 @@ public:
unsigned int w = 800, unsigned int w = 800,
unsigned int h = 600, unsigned int h = 600,
bool isWindowed = true); bool isWindowed = true);
void setScene(std::string sceneName); void setScene(SceneTree *scene);
void initPhysics(); void initPhysics();
void start(); void start();

View File

@ -9,11 +9,10 @@
#include "tools/pathfinder.h" #include "tools/pathfinder.h"
int main(){ int main(){
SceneTree scene("testScene");
Engine engine; Engine engine;
engine.createWindow("test"); engine.createWindow("test");
engine.setScene("testScene"); SceneTree scene; // the opengl context must exist before the scene is created
engine.setScene(&scene);
engine.start(); engine.start();
GraphNode n1 = GraphNode(); GraphNode n1 = GraphNode();

View File

@ -1,27 +1,36 @@
#include "scenetree.h" #include "scenetree.h"
#include "resourcemanager.h" #include "resourcemanager.h"
#include <pipeline.h>
// Scene // Scene
SceneTree::SceneTree(std::string name) : SceneTree::SceneTree() :
m_name(name), Scene(),
m_skybox(NULL) m_skybox(NULL)
{ {
RESOURCE_ADD(this, SceneTree, m_name); m_simplepipeline = new SimplePipeline();
m_simplepipeline->setClearColor(glm::vec3(0.1f, 0.4f, 0.25f));
} }
SceneTree::~SceneTree() SceneTree::~SceneTree()
{ {
RESOURCE_ADD(NULL, SceneTree, m_name);
}
void SceneTree::setMainCamera(CameraNode *camera)
{
m_simplepipeline->setCamera(camera);
} }
SceneIterator<Light*>* SceneTree::getLights() SceneIterator<Light*>* SceneTree::getLights()
{ {
// TODO
return NULL; return NULL;
} }
SceneIterator<GeometryNode*>* SceneTree::getGeometry() SceneIterator<GeometryNode*>* SceneTree::getGeometry()
{ {
// TODO
return NULL; return NULL;
} }
@ -38,9 +47,8 @@ void ContainerNode::update()
sn->update(); sn->update();
} }
void ContainerNode::addChild(const std::string &childName) void ContainerNode::addChild(SceneNode* node)
{ {
SceneNode* node = RESOURCE_GET(SceneNode, childName);
if(node != NULL) if(node != NULL)
{ {
m_children.push_back(node); m_children.push_back(node);
@ -48,18 +56,15 @@ void ContainerNode::addChild(const std::string &childName)
} }
} }
void ContainerNode::removeChild(const std::string &childName) void ContainerNode::removeChild(SceneNode* node)
{ {
SceneNode* node = RESOURCE_GET(SceneNode, childName);
if(node != NULL) if(node != NULL)
{ {
for(unsigned int i=0; i<m_children.size(); ++i) for(auto it = m_children.begin(); it != m_children.end(); ++it)
{ {
if(m_children[i] == node) if(*it == node)
{ {
m_children[i]->m_parent = NULL; m_children.erase(it);
m_children[i] == m_children.back();
m_children.pop_back();
break; break;
} }
} }

View File

@ -7,6 +7,8 @@
#include "light.h" #include "light.h"
#include "resourcemanager.h" #include "resourcemanager.h"
class SimplePipeline;
/** /**
* @brief The SceneNode class represents a class of the game * @brief The SceneNode class represents a class of the game
* that will be updated or used for rendering every frame * that will be updated or used for rendering every frame
@ -25,8 +27,16 @@ class ContainerNode : public SceneNode
{ {
public: public:
virtual void update(); virtual void update();
void addChild(const std::string &childName);
void removeChild(const std::string &childName); /**
* @brief addChild adds node in the ContainerNode's children list
*/
void addChild(SceneNode* node);
/**
* @brief removeChild removes the first iteration of node of the children list
*/
void removeChild(SceneNode* node);
protected: protected:
std::vector<SceneNode*> m_children; std::vector<SceneNode*> m_children;
}; };
@ -42,7 +52,7 @@ class CameraNode : public Camera, SceneNode
class SceneTree : public Scene class SceneTree : public Scene
{ {
public: public:
SceneTree(std::string name); SceneTree();
~SceneTree(); ~SceneTree();
virtual SceneIterator<Light*>* getLights(); virtual SceneIterator<Light*>* getLights();
@ -53,13 +63,13 @@ public:
Texture* getSkybox() {return m_skybox;} Texture* getSkybox() {return m_skybox;}
void setSkybox(Texture* skybox) {m_skybox = skybox;} void setSkybox(Texture* skybox) {m_skybox = skybox;}
void setMainCamera(const std::string &name) {m_camera = RESOURCE_GET(CameraNode, name);} void setMainCamera(CameraNode *camera);
void addRootObject(const std::string &name) {m_root.addChild(name);} void addRootObject(SceneNode *node) {m_root.addChild(node);}
private: private:
std::string m_name;
ContainerNode m_root; ContainerNode m_root;
Texture* m_skybox; Texture* m_skybox;
SimplePipeline* m_simplepipeline;
}; };
// Additionnal Nodes : // Additionnal Nodes :