Exemple #1
0
   void InitializeAllWrappers(dtEntity::EntityManager& em)
   {
      
      dtEntity::MapSystem* mapsystem;
      if(!em.GetEntitySystem(dtEntity::MapComponent::TYPE, mapsystem))
      {
        LOG_ERROR("Could not get map system!");
        return;
      }

      ScriptSystem* scriptsystem;
      if(!em.GetEntitySystem(ScriptSystem::TYPE, scriptsystem))
      {
        LOG_ERROR("Could not get script system!");
        return;
      }

      HandleScope handle_scope;
      Handle<Context> context = scriptsystem->GetGlobalContext();      
      Context::Scope context_scope(context);
      
      context->Global()->Set(String::New("DebugDrawManager"), CreateDebugDrawManager(context));
      //context->Global()->Set(String::New("Layer"), FunctionTemplate::New(CreateNewLayer)->GetFunction());

      // make entity manager accessible as a global variable
      context->Global()->Set(String::New("EntityManager"), WrapEntityManager(scriptsystem, &em));

      context->Global()->Set(String::New("NodeMasks"), WrapNodeMasks());

      context->Global()->Set(String::New("Buffer"), CreateBuffer());
      context->Global()->Set(String::New("File"), CreateFile());
      context->Global()->Set(String::New("Log"), WrapLogger(context));

      InitMapSystemWrapper(scriptsystem);
      
#if BUILD_OPENAL
      InitSoundSystemWrapper(scriptsystem);
#endif

   }
   OSGDebugDrawInterface::OSGDebugDrawInterface(dtEntity::EntityManager& em, dtEntity::StringId layerName)
   : mEnabled(false)
   , mGroupDepthTest(new osg::Group)
   , mGroupNoDepthTest(new osg::Group)
   , mCurrentTime(0)
   , mEntityManager(&em)
   , mEnableFunctor(this, &OSGDebugDrawInterface::OnEnable)
   , mTickFunctor(this, &OSGDebugDrawInterface::Tick)
   , mLayerName(layerName)
   , mContextId(0)
   , mContextIdSet(false)
   {
      if(layerName == dtEntity::StringId())
      {
         layerName = LayerAttachPointSystem::DefaultLayerId;
      }
      mGroupDepthTest->setNodeMask(dtEntity::NodeMasks::VISIBLE);
      mGroupNoDepthTest->setNodeMask(dtEntity::NodeMasks::VISIBLE);

	   {
			osg::ref_ptr<osg::StateSet> ss = mGroupDepthTest->getOrCreateStateSet();
		   ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);    
         ss->setRenderBinDetails(240000, "RenderBin");
			osg::ref_ptr<osg::LineWidth> lw = new osg::LineWidth();
		   lw->setWidth(1); 
		   ss->setAttributeAndModes(lw, osg::StateAttribute::ON); 
		   ss->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
			osg::ref_ptr<osg::PolygonMode> polyModeObj = new osg::PolygonMode;
		   polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
			ss->setAttribute(polyModeObj);
			osg::ref_ptr<osg::PolygonOffset> polyoffset = new osg::PolygonOffset;
			polyoffset->setFactor(-1.1f);
			polyoffset->setUnits(-1.1f);
			ss->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE |
				osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
	   }

	   {
			osg::ref_ptr<osg::StateSet> ss = mGroupNoDepthTest->getOrCreateStateSet();
		   ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);    
         ss->setRenderBinDetails(240001, "RenderBin");
			osg::ref_ptr<osg::LineWidth> lw = new osg::LineWidth();
		   lw->setWidth(1); 
		   ss->setAttributeAndModes(lw, osg::StateAttribute::ON); 
         ss->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
         osg::ref_ptr<osg::PolygonMode> polyModeObj = new osg::PolygonMode;
	      polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
		   ss->setAttribute(polyModeObj);  
			ss->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

	   }
      LayerAttachPointSystem* ls;
      em.GetEntitySystem(LayerAttachPointComponent::TYPE, ls);
      LayerAttachPointComponent* layer;
      bool found = ls->GetByName(layerName, layer);
      if(!found)
      {
         LOG_ERROR("Error initializing OSGDebugDrawInterface: Layer not found!");
      }
      else
      {
         layer->GetAttachmentGroup()->addChild(mGroupDepthTest);
         layer->GetAttachmentGroup()->addChild(mGroupNoDepthTest);
      }

      mEntityManager->RegisterForMessages(dtEntity::EnableDebugDrawingMessage::TYPE, mEnableFunctor);
   }