v8::Handle<v8::Function> CreateDebugDrawManager(Handle<Context> context)
   {
      v8::HandleScope handle_scope;

      Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_debugDrawWrapper);
      if(templt.IsEmpty())
      {

        templt = FunctionTemplate::New();
        templt->SetClassName(String::New("DebugDrawManager"));
        templt->InstanceTemplate()->SetInternalFieldCount(1);

        Handle<ObjectTemplate> proto = templt->PrototypeTemplate();

        proto->Set("addAABB", FunctionTemplate::New(DebugDrawManagerAddAABB));
        proto->Set("addCircle", FunctionTemplate::New(DebugDrawManagerAddCircle));
        proto->Set("addCross", FunctionTemplate::New(DebugDrawManagerAddCross));
        proto->Set("addLine", FunctionTemplate::New(DebugDrawManagerAddLine));
        proto->Set("addLines", FunctionTemplate::New(DebugDrawManagerAddLines));
        proto->Set("addSphere", FunctionTemplate::New(DebugDrawManagerAddSphere));
		  proto->Set("addString", FunctionTemplate::New(DebugDrawManagerAddString));
        proto->Set("addTriangle", FunctionTemplate::New(DebugDrawManagerAddTriangle));
        proto->Set("clear", FunctionTemplate::New(DebugDrawManagerClear));
        proto->Set("isEnabled", FunctionTemplate::New(DebugDrawManagerIsEnabled));
        proto->Set("setEnabled", FunctionTemplate::New(DebugDrawManagerSetEnabled));
        proto->Set("toString", FunctionTemplate::New(DebugDrawManagerToString));
        
        GetScriptSystem()->SetTemplateBySID(s_debugDrawWrapper, templt);
      }
      return handle_scope.Close(templt->GetFunction());
   }
 bool IsComponent(v8::Handle<v8::Value> val)
 {
   HandleScope scope;
   Handle<FunctionTemplate> tmplt = GetScriptSystem()->GetTemplateBySID(s_componentWrapper);
   if(tmplt.IsEmpty())
   {
      return false;
   }
   return tmplt->HasInstance(val);
 }
Beispiel #3
0
void CScriptSystem::Update(float currTime, float frameTime, int aiTicks)
{
    // garbage-collect script-variables
    int gcCount = GetScriptSystem()->GetGCCount();

    if ((gcCount - m_lastGarbageCollectCount) > LUA_MAX_GARBAGE_PERIOD)
    {
        ForceGarbageCollection();
        m_lastGarbageCollectCount = GetGCCount();
    }
}
Beispiel #4
0
   v8::Handle<v8::Object> WrapLogger(Handle<Context> context)
   {
      v8::HandleScope handle_scope;
      Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_loggerWrapper);
      if(templt.IsEmpty())
      {
        templt = FunctionTemplate::New();
        templt->SetClassName(String::New("Log"));

        Handle<ObjectTemplate> proto = templt->PrototypeTemplate();

        proto->Set("always", FunctionTemplate::New(LogAlways));
        proto->Set("debug", FunctionTemplate::New(LogDebug));
        proto->Set("error", FunctionTemplate::New(LogError));
        proto->Set("info", FunctionTemplate::New(LogInfo));
        proto->Set("warning", FunctionTemplate::New(LogWarning));
        proto->Set("addLogListener", FunctionTemplate::New(LogAddListener));
        proto->Set("processLogListeners", FunctionTemplate::New(LogProcessListeners));
        GetScriptSystem()->SetTemplateBySID(s_loggerWrapper, templt);
      }
      Local<Object> instance = templt->GetFunction()->NewInstance();
      return handle_scope.Close(instance);
   }
   v8::Handle<v8::Object> WrapElementDocument(v8::Handle<v8::Context> context, Rocket::Core::ElementDocument* v)
   {
      
      v8::HandleScope handle_scope;

      Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_elementDocumentWrapper);
      if(templt.IsEmpty())
      {

        templt = FunctionTemplate::New();
        templt->Inherit(GetElementTemplate());
        templt->SetClassName(String::New("ElementDocument"));
        templt->InstanceTemplate()->SetInternalFieldCount(1);
		  templt->InstanceTemplate()->SetNamedPropertyHandler(
           ELNamedPropertyGetter,
           ELNamedPropertySetter,
           ELNamedPropertyQuery,
           ELNamedPropertyDeleter,
           ELNamedPropertyEnumerator
        );

        Handle<ObjectTemplate> proto = templt->PrototypeTemplate();

		  proto->Set("hide", FunctionTemplate::New(EDHide));
        proto->Set("toString", FunctionTemplate::New(EDToString));
        proto->Set("show", FunctionTemplate::New(EDShow));
        proto->Set("hide", FunctionTemplate::New(EDHide));
        proto->Set("close", FunctionTemplate::New(EDClose));

        GetScriptSystem()->SetTemplateBySID(s_elementDocumentWrapper, templt);

      }
      Local<Object> instance = templt->GetFunction()->NewInstance();
      instance->SetInternalField(0, External::New(v));
      return handle_scope.Close(instance);

   }
Beispiel #6
0
struct lua_State* GetScriptState()
{
    return GetScriptSystem()->GetLuaState();
}
   Handle<Object> WrapComponent(Handle<Object> wrappedes, ScriptSystem* scriptsys, dtEntity::EntityId eid, dtEntity::Component* v)
   {

      HandleScope handle_scope;

      Handle<Object> wrapped = scriptsys->GetFromComponentMap(v->GetType(), eid);
      if(!wrapped.IsEmpty())
      {
         return wrapped;
      }

      Handle<FunctionTemplate> templt = GetScriptSystem()->GetTemplateBySID(s_componentWrapper);
      if(templt.IsEmpty())
      {

         templt = FunctionTemplate::New();

         templt->SetClassName(String::New("Component"));
         templt->InstanceTemplate()->SetInternalFieldCount(1);

         Handle<ObjectTemplate> proto = templt->PrototypeTemplate();

         proto->Set("equals", FunctionTemplate::New(COEquals));
         proto->Set("getType", FunctionTemplate::New(COGetType));
         proto->Set("properties", FunctionTemplate::New(COProperties));
         proto->Set("toString", FunctionTemplate::New(COToString));
         proto->Set("finished", FunctionTemplate::New(COFinished));
         proto->Set("copyPropertyValues", FunctionTemplate::New(COCopyPropertyValues));

         GetScriptSystem()->SetTemplateBySID(s_componentWrapper, templt);
      }


      Local<Object> instance = templt->GetFunction()->NewInstance();
      instance->SetInternalField(0, External::New(v));
      instance->SetHiddenValue(scriptsys->GetEntityIdString(), Uint32::New(eid));

      // GetStringFromSID and conversion to v8::String is costly, create a 
      // hidden value in entity system wrapper that stores
      // strings and their string ids as name=>value pairs
      Handle<Value> propnamesval = wrappedes->GetHiddenValue(scriptsys->GetPropertyNamesString());
      if(propnamesval.IsEmpty())
      {
         Handle<Object> names = Object::New();
         dtEntity::PropertyGroup::const_iterator i;
         const dtEntity::PropertyGroup& props = v->Get();
         for(i = props.begin(); i != props.end(); ++i)
         {
            dtEntity::StringId sid = i->first;
            std::string propname = dtEntity::GetStringFromSID(sid);
            names->Set(String::New(propname.c_str()), WrapSID(sid));
         }
         wrappedes->SetHiddenValue(scriptsys->GetPropertyNamesString(), names);
         propnamesval = names;
      }

      Handle<Object> propnames = Handle<Object>::Cast(propnamesval);
      Handle<Array> keys = propnames->GetPropertyNames();
      for(unsigned int i = 0; i < keys->Length(); ++i)
      {
         Handle<String> str = keys->Get(i)->ToString();
         dtEntity::StringId sid = UnwrapSID(propnames->Get(str));
         dtEntity::Property* prop = v->Get(sid);
         if(prop == NULL)
         {
            LOG_ERROR("Could not find property in component: " << ToStdString(str));
            continue;
         }
         Handle<External> ext = v8::External::New(static_cast<void*>(prop));
         instance->SetAccessor(str, COPropertyGetter, COPropertySetter, ext);
      }
      
      // store wrapped component to script system
      scriptsys->AddToComponentMap(v->GetType(), eid, instance);
      return handle_scope.Close(instance);
   }