13 #ifndef hifi_render_Scene_h
14 #define hifi_render_Scene_h
17 #include "SpatialTree.h"
19 #include "Selection.h"
20 #include "Transition.h"
21 #include "HighlightStyle.h"
44 typedef std::function<void(ItemID,
const Transition*)> TransitionQueryFunc;
45 typedef std::function<void()> TransitionFinishedFunc;
46 typedef std::function<void(HighlightStyle
const*)> SelectionHighlightQueryFunc;
58 void resetItem(ItemID
id,
const PayloadPointer& payload);
79 template <
class T>
void updateItem(ItemID
id, std::function<
void(T&)> func) {
80 updateItem(
id, std::make_shared<UpdateFunctor<T>>(func));
102 void resetTransitionOnItem(ItemID
id, TransitionType transition, ItemID boundId = render::Item::INVALID_ITEM_ID);
145 void resetSelectionHighlight(
const std::string& selectionName,
const HighlightStyle& style = HighlightStyle());
171 void reserve(
const std::vector<Transaction>& transactionContainer);
180 void mergeByCopying(
const std::vector<Transaction>& transactionContainer);
189 void mergeByMoving(std::vector<Transaction>&& transactionContainer);
219 void updateItem(ItemID
id,
const UpdateFunctorPointer& functor);
221 using Reset = std::tuple<ItemID, PayloadPointer>;
222 using Remove = ItemID;
223 using Update = std::tuple<ItemID, UpdateFunctorPointer>;
225 using TransitionReset = std::tuple<ItemID, TransitionType, ItemID>;
226 using TransitionRemove = ItemID;
227 using TransitionFinishedOperator = std::tuple<ItemID, TransitionFinishedFunc>;
228 using TransitionQuery = std::tuple<ItemID, TransitionQueryFunc>;
230 using SelectionReset = Selection;
232 using HighlightReset = std::tuple<std::string, HighlightStyle>;
233 using HighlightRemove = std::string;
234 using HighlightQuery = std::tuple<std::string, SelectionHighlightQueryFunc>;
236 using Resets = std::vector<Reset>;
237 using Removes = std::vector<Remove>;
238 using Updates = std::vector<Update>;
240 using TransitionResets = std::vector<TransitionReset>;
241 using TransitionRemoves = std::vector<TransitionRemove>;
242 using TransitionFinishedOperators = std::vector<TransitionFinishedOperator>;
243 using TransitionQueries = std::vector<TransitionQuery>;
245 using SelectionResets = std::vector<SelectionReset>;
247 using HighlightResets = std::vector<HighlightReset>;
248 using HighlightRemoves = std::vector<HighlightRemove>;
249 using HighlightQueries = std::vector<HighlightQuery>;
252 Removes _removedItems;
253 Updates _updatedItems;
255 TransitionResets _resetTransitions;
256 TransitionRemoves _removeTransitions;
257 TransitionFinishedOperators _transitionFinishedOperators;
258 TransitionQueries _queriedTransitions;
260 SelectionResets _resetSelections;
262 HighlightResets _highlightResets;
263 HighlightRemoves _highlightRemoves;
264 HighlightQueries _highlightQueries;
266 typedef std::vector<Transaction> TransactionQueue;
280 Scene(glm::vec3 origin,
float size);
344 Selection
getSelection(
const Selection::Name& name)
const;
382 const Item&
getItem(
const ItemID&
id)
const {
return _items[id]; }
416 StagePointer
getStage(
const Stage::Name& name)
const;
427 std::shared_ptr<T>
getStage(
const Stage::Name& name = T::getName())
const {
429 return (stage ? std::static_pointer_cast<T>(stage) : std::shared_ptr<T>());
439 void resetStage(
const Stage::Name& name,
const StagePointer& stage);
460 HighlightStyle
getOutlineStyle(ItemID
id,
const ViewFrustum& viewFrustum, uint16_t height) {
return _items[id].getOutlineStyle(viewFrustum, height); }
470 void setItemTransition(ItemID
id, Index transitionId);
478 void removeItemTransition(ItemID
id);
482 std::atomic<unsigned int> _IDAllocator{ 1 };
483 std::atomic<unsigned int> _numAllocatedItems{ 1 };
486 std::mutex _transactionQueueMutex;
490 TransactionQueue _transactionQueue;
493 std::mutex _transactionFramesMutex;
495 using TransactionFrames = std::vector<Transaction>;
498 TransactionFrames _transactionFrames;
501 uint32_t _transactionFrameNumber{ 0 };
508 void processTransactionFrame(
const Transaction& transaction);
513 std::mutex _itemsMutex;
519 ItemSpatialTree _primarySpatialTree;
522 ItemIDSet _primaryNonspatialSet;
528 void resetItems(
const Transaction::Resets& transactions);
534 void resetTransitionFinishedOperator(
const Transaction::TransitionFinishedOperators& transactions);
540 void removeItems(
const Transaction::Removes& transactions);
548 void updateItems(
const Transaction::Updates& transactions);
554 void resetTransitionItems(
const Transaction::TransitionResets& transactions);
560 void removeTransitionItems(
const Transaction::TransitionRemoves& transactions);
566 void queryTransitionItems(
const Transaction::TransitionQueries& transactions);
572 void resetHighlights(
const Transaction::HighlightResets& transactions);
578 void removeHighlights(
const Transaction::HighlightRemoves& transactions);
584 void queryHighlights(
const Transaction::HighlightQueries& transactions);
591 void collectSubItems(ItemID parentId, ItemIDs& subItems)
const;
594 mutable std::mutex _selectionsMutex;
595 SelectionMap _selections;
598 std::unordered_map<int32_t, std::vector<Transaction::TransitionFinishedFunc>> _transitionFinishedOperatorMap;
604 void resetSelections(
const Transaction::SelectionResets& transactions);
613 mutable std::mutex _stagesMutex;
619 friend class RenderEngine;
622 typedef std::shared_ptr<Scene> ScenePointer;
623 typedef std::vector<ScenePointer> Scenes;
Scene is a container for Items. Items are introduced, modified or erased in the scene through Transac...
Definition: Scene.h:274
const Item getItemSafe(const ItemID &id) const
Same as getItem, checking if the id is valid.
Definition: Scene.h:391
void addItemToSelection(const std::string &selectionName, ItemID itemID)
Add a single item to a selection by name.
Definition: Scene.cpp:612
StagePointer getStage(const Stage::Name &name) const
Access a particular Stage (empty pointer if it doesn't exist).
Definition: Scene.cpp:630
ItemID allocateID()
Get a new, unique item ID.
Definition: Scene.cpp:195
size_t getNumItems() const
Get the total number of allocated items, this a threadsafe call.
Definition: Scene.h:303
void simulate(ItemID id, RenderArgs *args)
Perform renderer-side simulation of a given item.
Definition: Scene.h:449
void enqueueTransaction(const Transaction &transaction)
Enqueue transaction to the scene.
Definition: Scene.cpp:205
bool isAllocatedID(const ItemID &id) const
Check that the ID is valid and allocated for this scene, this a threadsafe call.
Definition: Scene.cpp:200
const ItemSpatialTree & getSpatialTree() const
Access the spatialized items.
Definition: Scene.h:399
void removeSelection(const std::string &selectionName)
Remove a selection by name.
Definition: Scene.cpp:623
Scene(glm::vec3 origin, float size)
Definition: Scene.cpp:185
void resetStage(const Stage::Name &name, const StagePointer &stage)
Assign a given instance of a stage object to a given name.
Definition: Scene.cpp:641
Selection getSelection(const Selection::Name &name) const
Access a particular selection (empty if doesn't exist)
Definition: Scene.cpp:580
uint32_t enqueueFrame()
Enqueue end of frame transactions boundary.
Definition: Scene.cpp:215
bool isSelectionEmpty(const Selection::Name &name) const
Check if a particular selection is empty (returns ).
Definition: Scene.cpp:590
HighlightStyle getOutlineStyle(ItemID id, const ViewFrustum &viewFrustum, uint16_t height)
Returns outline style properties for a given item.
Definition: Scene.h:460
void enqueueTransactionMove(Transaction &&transaction)
Enqueue transaction to the scene by moving it.
Definition: Scene.cpp:210
const Item & getItem(const ItemID &id) const
Access a particular item from its ID.
Definition: Scene.h:382
std::shared_ptr< T > getStage(const Stage::Name &name=T::getName()) const
Access stage of a given type.
Definition: Scene.h:427
const ItemIDSet & getNonspatialSet() const
Access non-spatialized items (layered objects, backgrounds).
Definition: Scene.h:407
void processTransactionQueue()
Process the pending transactions queued.
Definition: Scene.cpp:234
Transaction is the mechanism to make any change to the scene. Whenever a new item need to be reset,...
Definition: Scene.h:40
void setTransitionFinishedOperator(ItemID id, TransitionFinishedFunc func)
The transaction will add a function to be called when fade effect finishes for a given item.
Definition: Scene.cpp:47
void removeHighlightFromSelection(const std::string &selectionName)
The transaction will remove highlight from a selection with specified name.
Definition: Scene.cpp:63
void resetItem(ItemID id, const PayloadPointer &payload)
The transaction will replace item's payload with new one.
Definition: Scene.cpp:22
void mergeByMoving(std::vector< Transaction > &&transactionContainer)
Moves content of given transactions to the current one and then clears input vector.
Definition: Scene.cpp:119
void mergeByCopying(const std::vector< Transaction > &transactionContainer)
Adds content of given transactions to the current one.
Definition: Scene.cpp:111
void removeItem(ItemID id)
The transaction will remove given item.
Definition: Scene.cpp:31
void querySelectionHighlight(const std::string &selectionName, const SelectionHighlightQueryFunc &func)
The transaction will add a function to be called on the render thread that will be provided with curr...
Definition: Scene.cpp:67
void updateItem(ItemID id)
The transaction will update an item without running a function.
Definition: Scene.h:90
bool hasRemovedItems() const
Definition: Scene.h:69
void updateItem(ItemID id, std::function< void(T &)> func)
The transaction will execute a function on the render thread to update the given render item.
Definition: Scene.h:79
void removeTransitionFromItem(ItemID id)
The transaction will remove fade effect for a given item.
Definition: Scene.cpp:39
void resetSelectionHighlight(const std::string &selectionName, const HighlightStyle &style=HighlightStyle())
The transaction will set a highlight style for a selection with a given name.
Definition: Scene.cpp:59
void queryTransitionOnItem(ItemID id, TransitionQueryFunc func)
The transaction will add a function to be called on the render thread that will be provided with curr...
Definition: Scene.cpp:43
void reserve(const std::vector< Transaction > &transactionContainer)
Reserves space needed to fit content of provided transactions.
Definition: Scene.cpp:71
void clear()
Clears the content of this transaction.
Definition: Scene.cpp:170
void resetTransitionOnItem(ItemID id, TransitionType transition, ItemID boundId=render::Item::INVALID_ITEM_ID)
The transaction will start a new fade effect on a given item.
Definition: Scene.cpp:35
void resetSelection(const Selection &selection)
The transaction will replace selection with a given name with the new one.
Definition: Scene.cpp:55