fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / ComplexSceneManager / OSGComplexSceneManager.cpp
blob750f5fb60a82baf2adbf3e3ad4acca432d3c630d
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include <boost/bind.hpp>
48 #include "OSGConfig.h"
50 #include "OSGComplexSceneManager.h"
51 #include "OSGOSGSceneFileType.h"
52 #include "OSGContainerCollection.h"
53 #include "OSGSceneFileHandler.h"
54 #include "OSGImageFileHandler.h"
55 #include "OSGNameAttachment.h"
56 #include "OSGAction.h"
57 #include "OSGCSMResetInterface.h"
58 #include "OSGFrameHandler.h"
59 #include "OSGGeoProperty.h"
61 #include "OSGGeoFunctions.h"
62 #include "OSGGraphOpFactory.h"
64 #include "OSGCSMDrawManager.h"
66 //#include "OSGFieldContainerFactory.h"
67 //#include "OSGTypeFactory.h"
69 OSG_BEGIN_NAMESPACE
71 // Documentation for this class is emitted in the
72 // OSGComplexSceneManagerBase.cpp file.
73 // To modify it, please change the .fcd file (OSGComplexSceneManager.fcd) and
74 // regenerate the base file.
76 struct NodeFinder
78 std::string _szRefName;
79 Node *_pResult;
81 NodeFinder(void) :
82 _szRefName( ),
83 _pResult (NULL)
87 Action::ResultE enter(Node * const pNode)
89 Action::ResultE returnValue = Action::Continue;
91 const Char8 *szName = OSG::getName(pNode);
93 if(szName != NULL)
95 if(osgStringCmp(_szRefName.c_str(), szName) == 0)
97 _pResult = pNode;
99 returnValue = Action::Quit;
103 return returnValue;
106 private:
108 NodeFinder(const NodeFinder &other);
109 void operator=(const NodeFinder &rhs);
112 struct ElementFinder
114 std::string _szRefName;
115 FieldContainer *_pResult;
117 ElementFinder(void) :
118 _szRefName( ),
119 _pResult (NULL)
123 Action::ResultE enter(Node * const pNode)
125 Action::ResultE returnValue = Action::Continue;
127 const Char8 *szName = OSG::getName(pNode);
129 if(szName != NULL)
131 if(osgStringCmp(_szRefName.c_str(), szName) == 0)
133 _pResult = pNode;
135 returnValue = Action::Quit;
138 else if(pNode->getCore() != NULL)
140 szName = OSG::getName(pNode->getCore());
142 if(szName != NULL)
144 if(osgStringCmp(_szRefName.c_str(), szName) == 0)
146 _pResult = pNode;
148 returnValue = Action::Quit;
153 return returnValue;
156 private:
158 ElementFinder(const ElementFinder &other);
159 void operator=(const ElementFinder &rhs);
163 /***************************************************************************\
164 * Class variables *
165 \***************************************************************************/
167 Time ComplexSceneManager::SystemTime = 0.0;
169 ComplexSceneManagerUnrecPtr ComplexSceneManager::_the = NULL;
170 PathHandler ComplexSceneManager::_oPathHandler;
171 std::vector<FieldContainerUnrecPtr > ComplexSceneManager::_vStaticGlobals;
172 std::vector<
173 ComplexSceneManager::DeferredFCUse> ComplexSceneManager::_vStaticUnresolvedFCs;
175 /***************************************************************************\
176 * Class methods *
177 \***************************************************************************/
179 void ComplexSceneManager::initMethod(InitPhase ePhase)
181 Inherited::initMethod(ePhase);
183 if(ePhase == TypeObject::SystemPost)
189 ComplexSceneManager *ComplexSceneManager::the(void)
191 return _the;
194 FieldContainer *ComplexSceneManager::resolveStatic(
195 const Char8 *szName,
196 FieldContainer *pDestContainer,
197 Int32 iDestFieldId)
199 std::vector<FieldContainerUnrecPtr>::const_iterator gIt =
200 _vStaticGlobals.begin();
202 std::vector<FieldContainerUnrecPtr>::const_iterator gEnd =
203 _vStaticGlobals.end ();
205 AttachmentContainer *pAttCnt = NULL;
206 Node *pNode = NULL;
207 const Char8 *szTmpName = NULL;
209 while(gIt != gEnd)
211 pNode = dynamic_cast<Node *>((*gIt).get());
213 if(pNode != NULL)
215 ElementFinder oFinder;
217 oFinder._szRefName = szName;
219 traverse(pNode, boost::bind(&ElementFinder::enter, &oFinder, _1));
221 if(oFinder._pResult != NULL)
223 return oFinder._pResult;
227 pAttCnt = dynamic_cast<AttachmentContainer *>((*gIt).get());
229 if(pAttCnt != NULL)
231 szTmpName = OSG::getName(pAttCnt);
233 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
235 return pAttCnt;
237 else
239 #if 0
240 FieldContainer *tmpVal = pAttCnt->findNamedComponent(szName);
242 if(tmpVal != NULL)
243 return tmpVal;
244 #endif
248 ++gIt;
251 if(pDestContainer != NULL && iDestFieldId >= 0)
253 DeferredFCUse tmpBlock;
255 tmpBlock._szName = szName;
256 tmpBlock._pDstCnt = pDestContainer;
257 tmpBlock._uiDstFieldId = UInt32(iDestFieldId);
259 _vStaticUnresolvedFCs.push_back(tmpBlock);
262 return NULL;
265 void ComplexSceneManager::addStaticGlobals(const Char8 *szFilename)
267 std::string szFilenameResolved = _oPathHandler.findFile(szFilename);
269 if(szFilenameResolved.empty() == true)
271 fprintf(stderr, "Could not find static global file %s\n",
272 szFilename);
274 return;
277 FieldContainerUnrecPtr pRes =
278 readOSGFile(szFilenameResolved,
279 boost::bind(&ComplexSceneManager::resolveStatic,
280 _1, _2, _3));
282 if(pRes == NULL)
283 return;
285 ContainerCollectionUnrecPtr pColl =
286 dynamic_pointer_cast<ContainerCollection>(pRes);
288 if(pColl == NULL)
289 return;
291 MFUnrecFieldContainerPtr::const_iterator fIt =
292 pColl->getMFContainers()->begin();
294 MFUnrecFieldContainerPtr::const_iterator fEnd =
295 pColl->getMFContainers()->end();
297 while(fIt != fEnd)
299 _vStaticGlobals.push_back(*fIt);
301 ++fIt;
305 void ComplexSceneManager::scanParamFile(
306 const Char8 *szFilename,
307 std::vector<std::string> &vParams )
309 FILE *pIn = fopen(szFilename, "r");
311 Char8 szRow[1024];
313 std::string szBuffer;
314 const Char8 *szDelim = " \t\n ";
316 vParams.clear();
318 while(!feof(pIn))
320 fgets(szRow, 1024, pIn);
322 szBuffer = szRow;
324 if(feof(pIn) ||
325 szBuffer.empty() == true ||
326 szBuffer[0] == '\n' ||
327 szBuffer[0] == '#' )
329 continue;
332 string_token_iterator cIt (szBuffer, szDelim);
333 string_token_iterator cEnd;
335 while(cIt != cEnd)
337 vParams.push_back(*cIt);
338 ++cIt;
342 fclose(pIn);
345 void ComplexSceneManager::scanPreSystem(std::vector<std::string> &vParams)
347 static const UInt32 ScanSystem = 0;
348 static const UInt32 ScanData = 1;
349 static const UInt32 ScanGlobals = 2;
351 UInt32 uiState = ScanSystem;
353 std::vector<std::string>::iterator pIt = vParams.begin();
354 std::vector<std::string>::const_iterator pEnd = vParams.end ();
356 while(pIt != pEnd)
358 if((*pIt)[0] == '-' && (*pIt)[1] == '-')
360 if((*pIt)[2] == 'd' && (*pIt)[3] == 'a' &&
361 (*pIt)[4] == 't' && (*pIt)[5] == 'a')
363 uiState = ScanData;
365 else if((*pIt)[2] == 'g' && (*pIt)[3] == 'l' &&
366 (*pIt)[4] == 'o' && (*pIt)[5] == 'b' &&
367 (*pIt)[6] == 'a' && (*pIt)[7] == 'l')
369 uiState = ScanGlobals;
371 else if((*pIt)[2] == 's' && (*pIt)[3] == 'y' &&
372 (*pIt)[4] == 's' && (*pIt)[5] == 't' &&
373 (*pIt)[6] == 'e' && (*pIt)[7] == 'm')
375 uiState = ScanSystem;
377 else
379 fprintf(stderr, "Unknow option %s\n", (*pIt).c_str());
380 break;
383 else
385 if(uiState == ScanSystem)
387 break;
389 else if(uiState == ScanGlobals)
391 addStaticGlobals((*pIt).c_str());
393 else if(uiState == ScanData)
395 FWARNING(("Error data not allowed at this point, "
396 "ignoring %s\n", (*pIt).c_str()));
400 ++pIt;
403 if(pIt != vParams.begin())
405 vParams.erase(vParams.begin(), pIt);
409 void ComplexSceneManager::startFrom(const std::string &szParamFilename)
411 _oPathHandler.clearPathList();
412 _oPathHandler.clearBaseFile();
414 _oPathHandler.push_frontCurrentDir();
416 std::string szParamFileResolved =
417 _oPathHandler.findFile(szParamFilename.c_str());
419 if(szParamFileResolved.empty() == true)
421 fprintf(stderr, "Could not find param file %s\n",
422 szParamFilename.c_str());
424 return;
427 _oPathHandler.setBaseFile(szParamFileResolved.c_str());
429 OSG::SceneFileHandler::the()->setPathHandler(&_oPathHandler);
431 std::vector<std::string> vParams;
433 scanParamFile(szParamFileResolved.c_str(), vParams);
435 Self::startUp(vParams);
438 /***************************************************************************\
439 * Instance methods *
440 \***************************************************************************/
442 /*-------------------------------------------------------------------------*\
443 - private -
444 \*-------------------------------------------------------------------------*/
446 /*----------------------- constructors & destructors ----------------------*/
448 ComplexSceneManager::ComplexSceneManager(void) :
449 Inherited ( ),
450 _fMainloop ( ),
451 _oKeyHelper ( ),
452 _vUnresolvedFCs( )
453 #ifdef OSG_WITH_WEBSERVICE
454 ,_pWebInterface (NULL)
455 #endif
459 ComplexSceneManager::ComplexSceneManager(const ComplexSceneManager &source) :
460 Inherited (source),
461 _fMainloop ( ),
462 _oKeyHelper ( ),
463 _vUnresolvedFCs( )
464 #ifdef OSG_WITH_WEBSERVICE
465 ,_pWebInterface (NULL )
466 #endif
470 ComplexSceneManager::~ComplexSceneManager(void)
474 FieldContainer *ComplexSceneManager::resolve(
475 const Char8 *szName,
476 FieldContainer *pDestContainer,
477 Int32 iDestFieldId)
479 FieldContainer *returnValue = this->findNamedComponent(szName);
481 if(returnValue == NULL && pDestContainer != NULL && iDestFieldId >= 0)
483 DeferredFCUse tmpBlock;
485 tmpBlock._szName = szName;
486 tmpBlock._pDstCnt = pDestContainer;
487 tmpBlock._uiDstFieldId = UInt32(iDestFieldId);
489 _vUnresolvedFCs.push_back(tmpBlock);
492 return returnValue;
495 void ComplexSceneManager::addGlobals(const std::string &filename)
497 if(_sfDrawManager.getValue() == NULL)
499 return;
502 std::string szFilenameResolved = _oPathHandler.findFile(filename.c_str());
504 if(szFilenameResolved.empty() == true)
506 return;
509 FieldContainerUnrecPtr pRes =
510 readOSGFile(szFilenameResolved,
511 boost::bind(&ComplexSceneManager::resolve, this,
512 _1, _2, _3));
514 fprintf(stderr, "addGlobals::pres %p\n", static_cast<void *>(pRes.get()));
516 if(pRes == NULL)
517 return;
519 ContainerCollectionUnrecPtr pColl =
520 dynamic_pointer_cast<ContainerCollection>(pRes);
522 if(pColl != NULL)
524 MFUnrecFieldContainerPtr::const_iterator fIt =
525 pColl->getMFContainers()->begin();
527 MFUnrecFieldContainerPtr::const_iterator fEnd =
528 pColl->getMFContainers()->end();
530 while(fIt != fEnd)
532 this->pushToGlobals(*fIt);
533 ++fIt;
536 else
538 this->pushToGlobals(pRes);
541 return;
544 void ComplexSceneManager::addData(const std::string &filename)
546 Node *pModelRoot = findNode("ModelRoot");
548 if(pModelRoot == NULL)
550 return;
553 std::string szFilenameResolved = _oPathHandler.findFile(filename.c_str());
555 if(szFilenameResolved.empty() == true)
557 fprintf(stderr, "Could not find data file %s\n",
558 filename.c_str());
560 return;
563 _oPathHandler.pushState();
565 _oPathHandler.setBaseFile(szFilenameResolved.c_str());
567 fprintf(stderr, "loading data %s ...\n",
568 filename.c_str());
570 NodeUnrecPtr pFile =
571 OSG::SceneFileHandler::the()->read(
572 szFilenameResolved.c_str(),
573 NULL,
574 boost::bind(&ComplexSceneManager::resolve, this, _1, _2, _3),
575 true);
577 _oPathHandler.popState();
579 if(pFile != NULL)
581 #if defined(OSG_OGL_ES2)
582 OSG::GraphOpRefPtr op =
583 OSG::GraphOpFactory::the()->create("PrepareES");
585 fprintf(stderr, "do es prep %p\n", static_cast<void *>(op.get()));
587 op->traverse(pFile);
588 #endif
590 pModelRoot->addChild(pFile);
594 Node *ComplexSceneManager::findNode(const std::string &filename) const
596 MFGlobalsType::const_iterator gIt = _mfGlobals.begin();
597 MFGlobalsType::const_iterator gEnd = _mfGlobals.end ();
599 Node *pNode = NULL;
600 Node *returnValue = NULL;
602 while(gIt != gEnd)
604 pNode = dynamic_cast<Node *>(*gIt);
606 if(pNode != NULL)
608 NodeFinder oFinder;
610 oFinder._szRefName = filename;
612 traverse(pNode, boost::bind(&NodeFinder::enter, &oFinder, _1));
614 if(oFinder._pResult != NULL)
616 returnValue = oFinder._pResult;
617 break;
621 ++gIt;
624 return returnValue;
627 void ComplexSceneManager::processUnresolved(void)
629 std::vector<DeferredFCUse>::const_iterator uIt = _vUnresolvedFCs.begin();
630 std::vector<DeferredFCUse>::const_iterator uEnd = _vUnresolvedFCs.end ();
632 for(; uIt != uEnd; ++uIt)
634 if(uIt->_pDstCnt == NULL)
635 continue;
637 FieldContainer *pTmpFC = this->findNamedComponent(uIt->_szName.c_str());
639 if(pTmpFC == NULL)
641 continue;
644 EditFieldHandlePtr pDstField =
645 uIt->_pDstCnt->editField(uIt->_uiDstFieldId);
647 FieldContainerPtrSFieldBase::EditHandlePtr pSFHandle =
648 boost::dynamic_pointer_cast<
649 FieldContainerPtrSFieldBase::EditHandle>(
650 pDstField);
652 FieldContainerPtrMFieldBase::EditHandlePtr pMFHandle =
653 boost::dynamic_pointer_cast<
654 FieldContainerPtrMFieldBase::EditHandle>(
655 pDstField);
657 EditMapFieldHandlePtr pMapHandle =
658 boost::dynamic_pointer_cast<
659 EditMapFieldHandle>(pDstField);
661 if(pSFHandle != NULL && pSFHandle->isValid())
663 pSFHandle->set(pTmpFC);
665 else if(pMFHandle != NULL && pMFHandle->isValid())
667 pMFHandle->add(pTmpFC);
669 else if(pMapHandle != NULL && pMapHandle->isValid())
671 pMapHandle->add(pTmpFC, "0");
676 _vUnresolvedFCs.clear();
679 FieldContainerTransitPtr ComplexSceneManager::readOSGFile(
680 const std::string &filename,
681 Resolver resolver)
683 FieldContainerTransitPtr returnValue(NULL);
685 _oPathHandler.pushState();
687 _oPathHandler.setBaseFile(filename.c_str());
689 ImageFileHandler::the()->setPathHandler(&_oPathHandler);
691 fprintf(stderr, "loading osg file %s ...\n",
692 filename.c_str());
694 returnValue = OSG::OSGSceneFileType::the().readContainer(
695 filename.c_str(),
696 resolver);
698 ImageFileHandler::the()->setPathHandler(NULL);
700 _oPathHandler.popState();
702 return returnValue;
705 FieldContainer *ComplexSceneManager::findNamedComponent(
706 const Char8 *szName)
708 MFGlobalsType::const_iterator gIt = _mfGlobals.begin();
709 MFGlobalsType::const_iterator gEnd = _mfGlobals.end ();
711 AttachmentContainer *pAttCnt = NULL;
712 Node *pNode = NULL;
713 const Char8 *szTmpName = NULL;
715 if(_sfDrawManager.getValue() != NULL)
717 szTmpName = OSG::getName(_sfDrawManager.getValue());
719 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
721 return _sfDrawManager.getValue();
724 FieldContainer *tmpVal =
725 _sfDrawManager.getValue()->findNamedComponent(szName);
727 if(tmpVal != NULL)
728 return tmpVal;
731 while(gIt != gEnd)
733 pNode = dynamic_cast<Node *>(*gIt);
735 if(pNode != NULL)
737 ElementFinder oFinder;
739 oFinder._szRefName = szName;
741 traverse(pNode, boost::bind(&ElementFinder::enter, &oFinder, _1));
743 if(oFinder._pResult != NULL)
745 return oFinder._pResult;
749 pAttCnt = dynamic_cast<AttachmentContainer *>(*gIt);
751 if(pAttCnt != NULL)
753 szTmpName = OSG::getName(pAttCnt);
755 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
757 return pAttCnt;
759 else
761 FieldContainer *tmpVal = pAttCnt->findNamedComponent(szName);
763 if(tmpVal != NULL)
764 return tmpVal;
768 ++gIt;
771 return NULL;
774 void ComplexSceneManager::addFrameProducer(
775 FrameProducerInterface *pProducer)
777 if(_sfDrawManager.getValue() != NULL)
779 _sfDrawManager.getValue()->addProducer(pProducer);
783 void ComplexSceneManager::removeFrameProducer(
784 FrameProducerInterface *pProducer)
786 if(_sfDrawManager.getValue() != NULL)
788 _sfDrawManager.getValue()->removeProducer(pProducer);
792 /*----------------------------- class specific ----------------------------*/
794 void ComplexSceneManager::changed(ConstFieldMaskArg whichField,
795 UInt32 origin,
796 BitVector details)
798 Inherited::changed(whichField, origin, details);
801 void ComplexSceneManager::dump( UInt32 ,
802 const BitVector ) const
804 SLOG << "Dump ComplexSceneManager NI" << std::endl;
807 void ComplexSceneManager::onCreate(const ComplexSceneManager *source)
809 Inherited::onCreate(source);
811 // Don't add the prototype instances to the list
812 if(GlobalSystemState != Running)
813 return;
815 if(_the != NULL)
817 fprintf(stderr, "WARNING ADDING SECOND COMPLEX SCENE MANAGER,"
818 " WILL SELF DESTRUCT IN 45 SECONDS");
821 _the = this;
823 std::vector<FieldContainerUnrecPtr>::const_iterator gIt =
824 _vStaticGlobals.begin();
826 std::vector<FieldContainerUnrecPtr>::const_iterator gEnd =
827 _vStaticGlobals.end ();
829 while(gIt != gEnd)
831 this->pushToGlobals(*gIt);
832 ++gIt;
835 #if 0
836 SensorTaskUnrecPtr pSensorTask = SensorTask::create();
838 setSensorTask(pSensorTask);
839 #endif
842 bool ComplexSceneManager::startFrom(int argc, char **argv)
844 _oPathHandler.clearPathList();
845 _oPathHandler.clearBaseFile();
847 _oPathHandler.push_frontCurrentDir();
849 std::vector<std::string> vParams;
850 std::string szTmp;
852 for(Int32 i = 1; i < argc; ++i)
854 szTmp = argv[i];
856 vParams.push_back(szTmp);
859 Self::startUp(vParams);
861 return true;
864 bool ComplexSceneManager::startUp(std::vector<std::string> &vParams)
866 setVBOUsageOnPropertyProtos(true);
868 scanPreSystem(vParams);
870 std::string szSystemFile = vParams[0];
872 std::string szSystemFileResolved =
873 _oPathHandler.findFile(szSystemFile.c_str());
875 if(szSystemFileResolved.empty() == true)
877 fprintf(stderr, "Could not find system file %s\n",
878 szSystemFile.c_str());
880 return false;
883 readOSGFile(szSystemFileResolved,
884 boost::bind(&ComplexSceneManager::resolveStatic,
885 _1, _2, _3));
887 _vStaticGlobals.clear();
889 if(OSG::ComplexSceneManager::the() == NULL)
891 fprintf(stderr, "Error could not find any complex scenemanager\n");
892 return false;
895 OSG::SceneFileHandler::the()->setGlobalResolver(
896 boost::bind(&ComplexSceneManager::resolve, _the.get(), _1, _2, _3));
898 OSG::ComplexSceneManager::the()->init(vParams);
900 OSG::ComplexSceneManager::the()->run();
902 return true;
905 bool ComplexSceneManager::init(const std::vector<std::string> &vParams)
907 bool returnValue = true;
909 bool bDoData = false;
911 _vUnresolvedFCs.insert(_vUnresolvedFCs.begin(),
912 _vStaticUnresolvedFCs.begin(),
913 _vStaticUnresolvedFCs.end ());
915 _vStaticUnresolvedFCs.clear();
917 for(UInt32 i = 1; i < vParams.size(); ++i)
919 if(vParams[i][0] == '-' && vParams[i][1] == '-')
921 if(vParams[i][2] == 'd' && vParams[i][3] == 'a' &&
922 vParams[i][4] == 't' && vParams[i][5] == 'a')
924 bDoData = true;
926 else if(vParams[i][2] == 'g' && vParams[i][3] == 'l' &&
927 vParams[i][4] == 'o' && vParams[i][5] == 'b' &&
928 vParams[i][6] == 'a' && vParams[i][7] == 'l')
930 bDoData = false;
932 else
934 fprintf(stderr, "Unknow option %s\n", vParams[i].c_str());
935 return false;
939 else
941 if(bDoData == true)
943 addData(vParams[i]);
945 else
947 addGlobals(vParams[i]);
952 this->processUnresolved();
954 if(_sfDrawManager.getValue() == NULL)
956 return false;
959 commitChanges();
961 returnValue = _sfDrawManager.getValue()->init();
963 if(returnValue == true && FrameHandler::the() != NULL)
965 returnValue &= FrameHandler::the()->init();
968 return returnValue;
971 void ComplexSceneManager::terminate(void)
973 _vStaticGlobals.clear();
975 _the->shutdown();
977 _the = NULL;
980 void ComplexSceneManager::shutdown(void)
982 #ifdef OSG_WITH_WEBSERVICE
983 _pWebInterface = NULL;
984 #endif
986 if(FrameHandler::the() != NULL)
988 FrameHandler::the()->shutdown();
991 this->clearGlobals();
993 if(_sfDrawManager.getValue() != NULL)
995 _sfDrawManager.getValue()->shutdown();
999 this->setDrawManager(NULL);
1000 // this->setSensorTask (NULL);
1003 void ComplexSceneManager::setMainloop(MainLoopFuncF fMainloop)
1005 _fMainloop = fMainloop;
1008 void ComplexSceneManager::run(void)
1010 #ifdef OSG_WITH_WEBSERVICE
1011 if(this->getEnableWebService() == true)
1013 _pWebInterface = WebInterface::create(this->getWebServicePort());
1015 FieldContainer *pRoot =
1016 this->resolve(this->getWebServiceRoot().c_str(), NULL, 0);
1018 Node *pRootNode = dynamic_cast<Node *>(pRoot);
1020 if(pRootNode != NULL)
1022 fprintf(stderr, "WebService using : %p\n",
1023 static_cast<void *>(pRootNode) );
1025 _pWebInterface->setRoot (pRootNode);
1026 _pWebInterface->setSystemContainer(this );
1029 #endif
1031 if(_fMainloop)
1033 _fMainloop();
1035 else
1037 FWARNING(("ComplexSceneManager: no mainloop exiting\n"));
1040 osgExit();
1043 void ComplexSceneManager::frame(void)
1045 #if 0
1046 setCurrTime(getSystemTime());
1048 if(osgAbs(_sfStartTime.getValue()) < 0.00001)
1050 setStartTime(_sfCurrTime.getValue());
1052 setLastTime(0.f);
1055 _sfCurrTime.getValue() -= _sfStartTime.getValue();
1057 if(_sfPaused.getValue() == false)
1059 SFTime *pSFTimeStamp = editSFTimeStamp();
1061 if(_sfConstantTime.getValue() == true)
1063 pSFTimeStamp->getValue() += _sfConstantTimeStep.getValue();
1065 if(pSFTimeStamp->getValue() < 0.)
1066 pSFTimeStamp->setValue(0.0);
1068 else
1070 pSFTimeStamp->getValue() +=
1071 (_sfCurrTime.getValue() - _sfLastTime.getValue()) *
1072 _sfTimeScale.getValue();
1074 if(pSFTimeStamp->getValue() < 0.)
1075 pSFTimeStamp->setValue(0.0);
1079 setLastTime(_sfCurrTime.getValue());
1081 SystemTime = _sfTimeStamp.getValue();
1083 ++(editSFFrameCount()->getValue());
1085 if(_sfSensorTask.getValue() != NULL)
1087 _sfSensorTask.getValue()->frame(_sfTimeStamp.getValue (),
1088 _sfFrameCount.getValue());
1090 #endif
1092 if(_sfDumpFrameStart.getValue() == true)
1094 fprintf(stderr, "=================================================\n");
1095 fprintf(stderr, "Render Frame\n");
1096 fprintf(stderr, "=================================================\n");
1099 FrameHandler::the()->frame();
1101 SystemTime = FrameHandler::the()->getTimeStamp();
1103 commitChanges();
1105 #ifdef OSG_WITH_WEBSERVICE
1106 if(_pWebInterface != NULL)
1108 _pWebInterface->waitRequest(0.01);
1109 _pWebInterface->handleRequests();
1111 #endif
1113 if(_sfDrawManager.getValue() != NULL)
1115 _sfDrawManager.getValue()->frame(FrameHandler::the()->getTimeStamp(),
1116 FrameHandler::the()->getFrameCount());
1119 if(this->getWaitKeyAfterFrame() == true)
1121 getchar();
1125 void ComplexSceneManager::resetScene(void)
1127 MFGlobalsType::const_iterator gIt = _mfGlobals.begin();
1128 MFGlobalsType::const_iterator gEnd = _mfGlobals.end ();
1130 CSMResetInterface *pIf = NULL;
1132 for(; gIt != gEnd; ++gIt)
1134 pIf = dynamic_cast<CSMResetInterface *>(*gIt);
1136 if(pIf != NULL)
1138 fprintf(stderr, "found if %p\n", static_cast<void *>(pIf));
1140 pIf->reset();
1145 void ComplexSceneManager::key(Int32 x,
1146 Int32 y,
1147 Int32 iState,
1148 Char8 cKey )
1150 _oKeyHelper.update(x, y, iState, cKey);
1153 void ComplexSceneManager::updateKeySensor(KeySensor *pSensor)
1155 _oKeyHelper.updateSensors(pSensor);
1158 void ComplexSceneManager::removeKeySensor(KeySensor *pSensor)
1160 _oKeyHelper.removeSensor(pSensor);
1163 OSG_END_NAMESPACE