79 class AdvanceAct :
public Action
82 AdvanceAct(
float dt,
float t,
bool bTiming =
false) {
88 void start(
Node* node)
override {
92 node->stateTimeStep()->setValue(mDt);
96 void process(
Node* node)
override {
114 std::stringstream name;
115 std::stringstream ss;
116 name << std::setw(40) << node->getClassInfo()->getClassName();
119 std::string info =
"Node: \t" + name.str() +
": \t " + ss.str() +
"ms \n";
127 bool mTiming =
false;
137 class AsyncAdvanceAct :
public Action
140 AsyncAdvanceAct(
bool bTiming =
false) {
144 void start(
Node* node)
override {
148 auto dt = node->
getDt();
149 node->stateTimeStep()->setValue(dt);
152 void process(
Node* node)
override {
170 std::stringstream name;
171 std::stringstream ss;
172 name << std::setw(40) << node->getClassInfo()->getClassName();
175 std::string info =
"Node: \t" + name.str() +
": \t " + ss.str() +
"ms \n";
180 void end(
Node* node)
override {
184 auto dt = node->stateTimeStep()->getValue();
185 auto time = node->stateElapsedTime()->getValue();
186 node->stateElapsedTime()->setValue(time + dt);
189 bool mTiming =
false;
197 std::cout <<
"**************** Frame " <<
mFrameNumber <<
" Started ****************" << std::endl;
211 class QueryTimeStep :
public Action
214 void process(
Node* node)
override {
215 if (node !=
nullptr && node->
isActive())
234 while (t + dt < interval)
254 std::cout <<
"---------------- Frame " <<
mFrameNumber <<
" Ended! ( " << timer.
getElapsedTime() <<
" ms in Total) ----------------" << std::endl << std::endl;
263 class UpdateGrpahicsContextAct :
public Action
266 void process(
Node* node)
override {
286 for (
auto it = this->
begin(); it != this->
end(); it++)
288 box.
join(it->boundingBox());
296 class ResetNodeAct :
public Action
299 void process(
Node* node)
override {
381 class MouseEventAct :
public Action
384 MouseEventAct(
PMouseEvent event) { mMouseEvent = event; }
385 ~MouseEventAct()
override {}
388 void process(
Node* node)
override
398 m->enqueueEvent(mMouseEvent);
407 m->enqueueEvent(mMouseEvent);
415 MouseEventAct eventAct(event);
422 if (node ==
nullptr || !node->isVisible())
425 for (
auto iter : node->animationPipeline()->activeModules())
430 m->enqueueEvent(event);
434 for (
auto iter : node->graphicsPipeline()->activeModules())
439 m->enqueueEvent(event);
446 class KeyboardEventAct :
public Action
449 KeyboardEventAct(
PKeyboardEvent event) { mKeyboardEvent = event; }
450 ~KeyboardEventAct()
override {}
453 void process(
Node* node)
override
463 m->enqueueEvent(mKeyboardEvent);
472 m->enqueueEvent(mKeyboardEvent);
480 KeyboardEventAct eventAct(event);
540 std::queue<Node*> queue;
543 while (!queue.empty())
545 auto fn = queue.front();
550 auto exports = fn->getExportNodes();
551 for (
auto port : exports) {
552 auto next = port->getParent();
553 if (next !=
nullptr && !visited[next->objectId()]) {
558 auto outFields = fn->getOutputFields();
559 for (
auto f : outFields) {
560 auto& sinks = f->getSinks();
561 for (
auto sink : sinks) {
562 if (sink !=
nullptr) {
563 auto next =
dynamic_cast<Node*
>(sink->parent());
564 if (next !=
nullptr && !visited[next->objectId()]) {
606 Node* node = n.second.get();
610 bool hasAncestor =
false;
614 for (
auto port : imports) {
615 auto& inNodes = port->getNodes();
616 for (
auto inNode : inNodes) {
617 if (inNode !=
nullptr) {
618 dag.
addEdge(inNode->objectId(), outId);
627 for (
auto f : inFields) {
628 auto* src = f->getSource();
629 if (src !=
nullptr) {
630 auto* inNode =
dynamic_cast<Node*
>(src->parent());
631 if (inNode !=
nullptr) {
632 dag.
addEdge(inNode->objectId(), outId);
648 for (
auto id : sortedIds)
687 std::map<ObjectId, bool> visited;
689 visited[nm.first] =
false;
693 BFS(node.get(), list, visited);
695 for (
auto it = list.begin(); it != list.end(); ++it)
713 std::queue<Node*> queue;
716 while (!queue.empty())
718 auto fn = queue.front();
723 auto exports = fn->getExportNodes();
724 for (
auto port : exports) {
725 auto next = port->getParent();
726 if (next !=
nullptr && next->isAutoSync() && !visited[next->objectId()]) {
731 auto outFields = fn->getOutputFields();
732 for (
auto f : outFields) {
733 auto& sinks = f->getSinks();
734 for (
auto sink : sinks) {
735 if (sink !=
nullptr) {
736 auto next =
dynamic_cast<Node*
>(sink->parent());
737 if (next !=
nullptr && next->isAutoSync() && !visited[next->objectId()]) {
748 std::map<ObjectId, bool> visited;
750 visited[nm.first] =
false;
756 for (
auto it = list.begin(); it != list.end(); ++it)
771 if (node ==
nullptr ||
781 std::map<ObjectId, bool> visited;
784 visited[(*it)->objectId()] =
false;
virtual void end(Node *node)
virtual void process(Node *node)
virtual void start(Node *node)
AssignFrameNumberAct(uint num)
void process(Node *node) override
double getElapsedTime()
return the elapsed time in (ms)
Graph class represents a directed graph.
void addEdge(ObjectId v, ObjectId w)
std::vector< ObjectId > & topologicalSort(ObjectId v)
@ Info
Information to user.
@ Error
Error information while executing something.
static void sendMessage(MessageType type, const std::string &text)
Add a new message to log.
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
virtual bool isActive()
Check the state of dynamics.
virtual Real getDt()
Simulation timestep.
void update()
Called every time interval.
std::shared_ptr< AnimationPipeline > animationPipeline()
virtual bool isVisible()
Check the visibility of context.
std::vector< NodePort * > & getImportNodes()
std::vector< FBase * > & getInputFields()
static ObjectId baseId()
Base Id.
bool mAsynchronousSimulation
void deleteNode(std::shared_ptr< Node > node)
void markQueueUpdateRequired()
An interface to tell SceneGraph to update the execuation queue.
void setLowerBound(Vec3f lowerBound)
virtual void takeOneFrame()
bool isIntervalAdaptive()
void updateExecutionQueue()
NBoundingBox boundingBox()
void onMouseEvent(PMouseEvent event)
void printValidationInfo(bool enabled)
virtual void advanceInAsync()
void traverseBackward(Action *act)
Depth-first tree traversal.
void traverseForward(Action *act)
Breadth-first tree traversal.
void propagateNode(std::shared_ptr< Node > node)
void printNodeInfo(bool enabled)
void setAsynchronousSimulation(bool b)
void onKeyboardEvent(PKeyboardEvent event)
void setAdaptiveInterval(bool adaptive)
void traverseForwardWithAutoSync(std::shared_ptr< Node > node, Action *act)
Breadth-first tree traversal starting from a specific node, only those whose mAutoSync turned-on will...
void printRenderingInfo(bool enabled)
void setUpperBound(Vec3f upperBound)
virtual bool load(std::string name)
void printSimulationInfo(bool enabled)
virtual void advance(float dt)
virtual void updateGraphicsContext()
bool mQueueUpdateRequired
static SceneGraph & getInstance()
static SceneLoaderFactory & getInstance()
Get the ObjectFactory singleton instance.
SceneLoader * getEntryByFileName(std::string filename)
Get an entry given a file name.
This is an implementation of AdditiveCCD based on peridyno.
void BFS(Node *node, NodeList &list, std::map< ObjectId, bool > &visited)
void BFSWithAutoSync(Node *node, NodeList &list, std::map< ObjectId, bool > &visited)
std::list< Node * > NodeList
NBoundingBox & join(const NBoundingBox box)