adding the render engine

This commit is contained in:
Sam Gateau 2015-03-04 09:54:07 -08:00
parent 66894a8fda
commit 0c9c60dd65
4 changed files with 133 additions and 27 deletions

View file

@ -0,0 +1,17 @@
//
// Engine.cpp
// render/src/render
//
// Created by Sam Gateau on 3/3/15.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Engine.h"
using namespace render;

View file

@ -0,0 +1,32 @@
//
// Engine.h
// render/src/render
//
// Created by Sam Gateau on 3/3/15.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_render_Engine_h
#define hifi_render_Engine_h
#include "Scene.h"
namespace render {
class Engine {
public:
Engine() {}
~Engine() {}
protected:
};
}
#endif // hifi_render_Engine_h

View file

@ -12,11 +12,48 @@
using namespace render;
void Scene::ChangeBatch::resetItem(ID id, ItemDataPointer& itemData) {
_resetItems.push_back(id);
_resetItemDatas.push_back(itemData);
}
Item::ID Scene::addItem(ItemDataPointer& itemData) {
ID id = _items.size();
void Scene::ChangeBatch::removeItem(ID id) {
_removedItems.push_back(id);
}
void Scene::ChangeBatch::moveItem(ID id) {
_movedItems.push_back(id);
}
Scene::Scene() :
_IDAllocator(0)
{
}
Item::ID Scene::allocateID() {
// Just increment and return the proevious value initialized at 0
return _IDAllocator.fetch_add(1);
}
/// Enqueue change batch to the scene
void Scene::enqueueChangeBatch(const ChangeBatch& changeBatch) {
_changeQueueMutex.lock();
_changeQueue.push_back(changeBatch);
_changeQueueMutex.unlock();
}
void Scene::processChangeBatchQueue() {
_itemsMutex.lock();
for (auto changeBatch : _changeQueue) {
for (auto reset :
}
_itemsMutex.unlock();
}
void Scene::resetItem(ID id, ItemDataPointer& itemData) {
/*ID id = _items.size();
_items.push_back(Item(itemData));
return id;
*/
}
void Scene::removeItem(ID id) {

View file

@ -17,6 +17,8 @@
#include <vector>
#include <map>
#include <AABox.h>
#include <atomic>
#include <mutex>
namespace render {
@ -35,7 +37,7 @@ public:
VIEW_SPACE, // Transformed in view space, and not in world space
DYNAMIC, // Dynamic and bound will change unlike static item
DEFORMED, // Deformed within bound, not solid
UNVISIBLE, // Visible or not? could be just here to cast shadow
INVISIBLE, // Visible or not? could be just here to cast shadow
SHADOW_CASTER, // Item cast shadows
PICKABLE, // Item can be picked/selected
@ -92,8 +94,8 @@ public:
bool isDynamic() const { return _state[DYNAMIC]; }
bool isDeformed() const { return _state[DEFORMED]; }
bool isVisible() const { return !_state[UNVISIBLE]; }
bool isUnvisible() const { return _state[UNVISIBLE]; }
bool isVisible() const { return !_state[INVISIBLE]; }
bool isUnvisible() const { return _state[INVISIBLE]; }
bool isShadowCaster() const { return _state[SHADOW_CASTER]; }
@ -112,6 +114,9 @@ protected:
typedef Item::PayloadInterface ItemData;
typedef Item::PayloadPointer ItemDataPointer;
typedef std::vector< ItemDataPointer > ItemDataVector;
class Engine;
class Scene {
public:
@ -120,40 +125,55 @@ public:
typedef std::vector<Item::ID> ItemList;
typedef std::map<Item::State, ItemList> ItemLists;
enum ChangeType {
ADD = 0,
REMOVE,
MOVE,
RESET,
NUM_CHANGE_TYPES,
};
typedef ItemList ChangeLists[NUM_CHANGE_TYPES];
class ChangePacket {
class ChangeBatch {
public:
ChangePacket(int frame) :
_frame(frame) {}
~ChangePacket();
ChangeBatch() {}
~ChangeBatch();
void resetItem(ID id, ItemDataPointer& itemData);
void removeItem(ID id);
void moveItem(ID id);
ItemDataVector _resetItemDatas;
ItemList _resetItems;
ItemList _removedItems;
ItemList _movedItems;
int _frame;
ChangeLists _changeLists;
protected:
};
typedef std::vector<ChangeBatch> ChangeBatchQueue;
Scene() {}
Scene();
~Scene() {}
/// This call is thread safe, can be called from anywhere to allocate a new ID
ID allocateID();
ID addItem(ItemDataPointer& itemData);
/// Enqueue change batch to the scene
void enqueueChangeBatch(const ChangeBatch& changeBatch);
protected:
// Thread safe elements that can be accessed from anywhere
std::atomic<unsigned int> _IDAllocator;
std::mutex _changeBatchQueueMutex;
ChangeBatchQueue _changeBatchQueue;
// The actual database
std::mutex _itemsMutex;
Items _items;
ItemLists _buckets;
void processChangeBatchQueue();
void resetItem(ID id, ItemDataPointer& itemData);
void removeItem(ID id);
void moveItem(ID id);
protected:
Items _items;
ItemLists _buckets;
friend class Engine;
};
typedef std::shared_ptr<Scene> ScenePointer;
typedef std::vector<ScenePointer> Scenes;
}
#endif // hifi_render_Scene_h