Example #1
0
   ScriptSystem::ScriptSystem(dtEntity::EntityManager& em)
      : dtEntity::EntitySystem(em)
      , mDebugPortOpened(false)
   {      

      V8::Initialize();
      Register(ScriptsId, &mScripts);
      Register(DebugPortId, &mDebugPort);
      Register(DebugEnabledId, &mDebugEnabled);
      mDebugPort.Set(9222);
      
      //V8::AddGCPrologueCallback(GCStartCallback);
      //V8::AddGCEpilogueCallback(GCEndCallback);

      mSceneLoadedFunctor = dtEntity::MessageFunctor(this, &ScriptSystem::OnSceneLoaded);
      GetEntityManager().RegisterForMessages(dtEntity::SceneLoadedMessage::TYPE, mSceneLoadedFunctor, "ScriptSystem::OnSceneLoaded");

      mTickFunctor = dtEntity::MessageFunctor(this, &ScriptSystem::Tick);
      em.RegisterForMessages(dtEntity::TickMessage::TYPE, mTickFunctor, "ScriptSystem::Tick");

      mLoadScriptFunctor = dtEntity::MessageFunctor(this, &ScriptSystem::OnLoadScript);
      em.RegisterForMessages(ExecuteScriptMessage::TYPE, mLoadScriptFunctor, "ScriptSystem::OnLoadScript");

      HandleScope scope;
      mEntityIdString = Persistent<String>::New(String::New("__entityid__"));
      mPropertyNamesString = Persistent<String>::New(String::New("__propertynames__"));
   }  
Example #2
0
   void MapSystem::OnAddedToEntityManager(dtEntity::EntityManager& em)
   {
      em.AddEntitySystemRequestCallback(this);
#if PROTOBUF_FOUND
      AddMapEncoder(new ProtoBufMapEncoder(em));
#endif
      AddMapEncoder(new RapidXMLMapEncoder(em));

   }
Example #3
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

   }
Example #4
0
 void ScriptSystem::OnRemoveFromEntityManager(dtEntity::EntityManager& em)
 {
    em.RemoveDeletedCallback(this);
 }
Example #5
0
 void ScriptSystem::OnAddedToEntityManager(dtEntity::EntityManager& em)
 {
    SetupContext();      
    em.AddDeletedCallback(this);
 }
   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);
   }
Example #7
0
 WheelSystem(dtEntity::EntityManager& em)
    : DefaultEntitySystem<WheelComponent>(em)
 {
    mTickFunctor = dtEntity::MessageFunctor(this, &WheelSystem::Tick);
    em.RegisterForMessages(dtEntity::TickMessage::TYPE, mTickFunctor);
 }