|
|
@@ -27,6 +27,9 @@
|
|
|
#include "ScriptFile.h"
|
|
|
#include "ScriptInstance.h"
|
|
|
|
|
|
+static std::vector<Component*> componentResult;
|
|
|
+static std::vector<Entity*> entityResult;
|
|
|
+
|
|
|
static void ConstructComponentRef(ComponentRef* ptr)
|
|
|
{
|
|
|
new(ptr) ComponentRef();
|
|
|
@@ -87,26 +90,12 @@ static void registerComponentRef(asIScriptEngine* engine)
|
|
|
|
|
|
Component* EntityCreateComponent(const std::string& type, Entity* ptr)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- return ptr->createComponent(ShortStringHash(type));
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW_RET(e, 0);
|
|
|
- }
|
|
|
+ TRY_CONSTRUCT(ptr->createComponent(ShortStringHash(type)));
|
|
|
}
|
|
|
|
|
|
static Component* EntityCreateComponentWithName(const std::string& type, const std::string& name, Entity* ptr)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- return ptr->createComponent(ShortStringHash(type), name);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW_RET(e, 0);
|
|
|
- }
|
|
|
+ TRY_CONSTRUCT(ptr->createComponent(ShortStringHash(type), name));
|
|
|
}
|
|
|
|
|
|
static void EntityRemoveComponent(const std::string& type, Entity* ptr)
|
|
|
@@ -175,6 +164,12 @@ static CScriptArray* EntityGetComponents(Entity* ptr)
|
|
|
return sharedPtrVectorToHandleArray<Component>(components, "array<Component@>");
|
|
|
}
|
|
|
|
|
|
+static CScriptArray* EntityGetComponentsWithType(const std::string& type, Entity* ptr)
|
|
|
+{
|
|
|
+ ptr->getComponents(componentResult, ShortStringHash(type));
|
|
|
+ return vectorToHandleArray<Component>(componentResult, "array<Component@>");
|
|
|
+}
|
|
|
+
|
|
|
static asIScriptObject* EntityGetScriptObject(Entity* ptr)
|
|
|
{
|
|
|
const std::vector<SharedPtr<Component> >& components = ptr->getComponents();
|
|
|
@@ -256,6 +251,7 @@ static void registerEntity(asIScriptEngine* engine)
|
|
|
engine->RegisterObjectMethod("Entity", "ScriptObject@+ getScriptObject(const string& in) const", asFUNCTION(EntityGetScriptObjectWithClass), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Entity", "uint getNumComponents() const", asMETHOD(Entity, getNumComponents), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Entity", "array<Component@>@ getComponents() const", asFUNCTION(EntityGetComponents), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Entity", "array<Component@>@ getComponents(const string& in) const", asFUNCTION(EntityGetComponentsWithType), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Entity", "bool isAuthority() const", asMETHOD(Entity, isAuthority), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Entity", "bool isProxy() const", asMETHOD(Entity, isProxy), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Entity", "bool isOwnerPredicted() const", asMETHOD(Entity, isOwnerPredicted), asCALL_THISCALL);
|
|
|
@@ -277,21 +273,28 @@ static Scene* GetScene()
|
|
|
|
|
|
static Entity* SceneCreateEntity(Scene* ptr)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- return ptr->createEntity();
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW_RET(e, 0);
|
|
|
- }
|
|
|
+ TRY_CONSTRUCT(ptr->createEntity());
|
|
|
}
|
|
|
|
|
|
static Entity* SceneCreateEntityWithName(const std::string& name, Scene* ptr)
|
|
|
+{
|
|
|
+ TRY_CONSTRUCT(ptr->createEntity(name));
|
|
|
+}
|
|
|
+
|
|
|
+static Entity* SceneCreateEntityWithNameAndLocalFlag(const std::string& name, bool local, Scene* ptr)
|
|
|
+{
|
|
|
+ TRY_CONSTRUCT(ptr->createEntity(name, local));
|
|
|
+}
|
|
|
+
|
|
|
+static Component* SceneCreateComponent(const std::string& type, Scene* ptr)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- return ptr->createEntity(name);
|
|
|
+ SharedPtr<Component> component = ptr->createComponent(ShortStringHash(type));
|
|
|
+ // The shared pointer will go out of scope, so have to increment the reference count
|
|
|
+ // (here an auto handle can not be used)
|
|
|
+ component->addRef();
|
|
|
+ return component.getPtr();
|
|
|
}
|
|
|
catch (Exception& e)
|
|
|
{
|
|
|
@@ -299,11 +302,13 @@ static Entity* SceneCreateEntityWithName(const std::string& name, Scene* ptr)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static Entity* SceneCreateEntityWithNameAndLocalFlag(const std::string& name, bool local, Scene* ptr)
|
|
|
+static Component* SceneCreateComponentWithName(const std::string& type, const std::string& name, Scene* ptr)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- return ptr->createEntity(name, local);
|
|
|
+ SharedPtr<Component> component = ptr->createComponent(ShortStringHash(type), name);
|
|
|
+ component->addRef();
|
|
|
+ return component.getPtr();
|
|
|
}
|
|
|
catch (Exception& e)
|
|
|
{
|
|
|
@@ -315,121 +320,80 @@ static void SceneSave(File* file, Scene* ptr)
|
|
|
{
|
|
|
if (!file)
|
|
|
SAFE_EXCEPTION("Null scene destination file");
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->save(*file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+
|
|
|
+ TRY_SAFE_RETHROW(ptr->save(*file));
|
|
|
}
|
|
|
|
|
|
static void SceneLoad(File* file, Scene* ptr)
|
|
|
{
|
|
|
if (!file)
|
|
|
SAFE_EXCEPTION("Null scene source file");
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->load(*file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+
|
|
|
+ TRY_SAFE_RETHROW(ptr->load(*file));
|
|
|
}
|
|
|
|
|
|
static void SceneSaveXML(File* file, Scene* ptr)
|
|
|
{
|
|
|
if (!file)
|
|
|
SAFE_EXCEPTION("Null scene destination XML file");
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->saveXML(*file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+
|
|
|
+ TRY_SAFE_RETHROW(ptr->saveXML(*file));
|
|
|
}
|
|
|
|
|
|
static void SceneLoadXML(File* file, Scene* ptr)
|
|
|
{
|
|
|
if (!file)
|
|
|
SAFE_EXCEPTION("Null scene source XML file");
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->loadXML(*file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+
|
|
|
+ TRY_SAFE_RETHROW(ptr->loadXML(*file));
|
|
|
}
|
|
|
|
|
|
static void SceneLoadAsync(File* file, Scene* ptr)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->loadAsync(file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+ TRY_SAFE_RETHROW(ptr->loadAsync(file));
|
|
|
}
|
|
|
|
|
|
static void SceneLoadAsyncXML(File* file, Scene* ptr)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- ptr->loadAsyncXML(file);
|
|
|
- }
|
|
|
- catch (Exception& e)
|
|
|
- {
|
|
|
- SAFE_RETHROW(e);
|
|
|
- }
|
|
|
+ TRY_SAFE_RETHROW(ptr->loadAsyncXML(file));
|
|
|
}
|
|
|
|
|
|
-static void SceneRemoveAllEntitiesDefault(Scene* ptr)
|
|
|
+static CScriptArray* SceneGetAllEntities(Scene* ptr)
|
|
|
{
|
|
|
- ptr->removeAllEntities();
|
|
|
+ const std::map<EntityID, SharedPtr<Entity> >& entities = ptr->getAllEntities();
|
|
|
+ entityResult.clear();
|
|
|
+ for (std::map<EntityID, SharedPtr<Entity> >::const_iterator i = entities.begin(); i != entities.end(); ++i)
|
|
|
+ entityResult.push_back(i->second);
|
|
|
+ return vectorToHandleArray<Entity>(entityResult, "array<Entity@>");
|
|
|
}
|
|
|
|
|
|
-static CScriptArray* SceneGetEntities(Scene* ptr)
|
|
|
+static CScriptArray* SceneGetEntities(unsigned char netFlags, unsigned groupFlags, Scene* ptr)
|
|
|
{
|
|
|
- const std::map<EntityID, SharedPtr<Entity> >& entities = ptr->getEntities();
|
|
|
- std::vector<Entity*> result;
|
|
|
- for (std::map<EntityID, SharedPtr<Entity> >::const_iterator i = entities.begin(); i != entities.end(); ++i)
|
|
|
- result.push_back(i->second);
|
|
|
- return vectorToHandleArray<Entity>(result, "array<Entity@>");
|
|
|
+ ptr->getEntities(entityResult, netFlags, groupFlags);
|
|
|
+ return vectorToHandleArray<Entity>(entityResult, "array<Entity@>");
|
|
|
}
|
|
|
|
|
|
-static CScriptArray* SceneGetEntitiesWithFlags(unsigned includeFlags, unsigned excludeFlags, Scene* ptr)
|
|
|
+static CScriptArray* SceneGetEntitiesWithComponent(const std::string& type, Scene* ptr)
|
|
|
{
|
|
|
- std::vector<Entity*> result = ptr->getEntities(includeFlags, excludeFlags);
|
|
|
- return vectorToHandleArray<Entity>(result, "array<Entity@>");
|
|
|
+ ptr->getEntitiesWithComponent(entityResult, ShortStringHash(type));
|
|
|
+ return vectorToHandleArray<Entity>(entityResult, "array<Entity@>");
|
|
|
}
|
|
|
|
|
|
static CScriptArray* SceneGetScriptedEntities(Scene* ptr)
|
|
|
{
|
|
|
- const std::map<EntityID, SharedPtr<Entity> >& entities = ptr->getEntities();
|
|
|
- std::vector<Entity*> result;
|
|
|
- for (std::map<EntityID, SharedPtr<Entity> >::const_iterator i = entities.begin(); i != entities.end(); ++i)
|
|
|
- {
|
|
|
- if (i->second->hasComponent<ScriptInstance>())
|
|
|
- result.push_back(i->second);
|
|
|
- }
|
|
|
- return vectorToHandleArray<Entity>(result, "array<Entity@>");
|
|
|
+ ptr->getEntitiesWithComponent<ScriptInstance>(entityResult);
|
|
|
+ return vectorToHandleArray<Entity>(entityResult, "array<Entity@>");
|
|
|
}
|
|
|
|
|
|
static CScriptArray* SceneGetScriptedEntitiesWithClass(const std::string& className, Scene* ptr)
|
|
|
{
|
|
|
- const std::map<EntityID, SharedPtr<Entity> >& entities = ptr->getEntities();
|
|
|
- std::vector<Entity*> result;
|
|
|
- for (std::map<EntityID, SharedPtr<Entity> >::const_iterator i = entities.begin(); i != entities.end(); ++i)
|
|
|
+ static std::vector<Entity*> tempEntityResult;
|
|
|
+ entityResult.clear();
|
|
|
+
|
|
|
+ ptr->getEntitiesWithComponent<ScriptInstance>(tempEntityResult);
|
|
|
+ for (std::vector<Entity*>::const_iterator i = tempEntityResult.begin(); i != tempEntityResult.end(); ++i)
|
|
|
{
|
|
|
- const std::vector<SharedPtr<Component> >& components = i->second->getComponents();
|
|
|
+ const std::vector<SharedPtr<Component> >& components = (*i)->getComponents();
|
|
|
for (std::vector<SharedPtr<Component> >::const_iterator j = components.begin(); j != components.end(); ++j)
|
|
|
{
|
|
|
if ((*j)->getType() == ScriptInstance::getTypeStatic())
|
|
|
@@ -437,46 +401,55 @@ static CScriptArray* SceneGetScriptedEntitiesWithClass(const std::string& classN
|
|
|
ScriptInstance* instance = static_cast<ScriptInstance*>(j->getPtr());
|
|
|
if (instance->getClassName() == className)
|
|
|
{
|
|
|
- result.push_back(i->second);
|
|
|
+ entityResult.push_back(*i);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return vectorToHandleArray<Entity>(result, "array<Entity@>");
|
|
|
+ return vectorToHandleArray<Entity>(entityResult, "array<Entity@>");
|
|
|
}
|
|
|
|
|
|
static void registerScene(asIScriptEngine* engine)
|
|
|
{
|
|
|
engine->RegisterObjectBehaviour("Scene", asBEHAVE_ADDREF, "void f()", asMETHOD(Scene, addRef), asCALL_THISCALL);
|
|
|
engine->RegisterObjectBehaviour("Scene", asBEHAVE_RELEASE, "void f()", asMETHOD(Scene, releaseRef), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void update(float)", asMETHOD(Scene, update), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void save(File@+)", asFUNCTION(SceneSave), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void load(File@+)", asFUNCTION(SceneLoad), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void saveXML(File@+)", asFUNCTION(SceneSaveXML), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void loadXML(File@+)", asFUNCTION(SceneLoadXML), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void loadAsync(File@+)", asFUNCTION(SceneLoadAsync), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void loadAsyncXML(File@+)", asFUNCTION(SceneLoadAsyncXML), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void stopAsyncLoading()", asMETHOD(Scene, stopAsyncLoading), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void setName(const string& in)", asMETHOD(Scene, setName), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void setNetFlags(uint8)", asMETHOD(Scene, setNetFlags), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void setPaused(bool)", asMETHOD(Scene, setPaused), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "Entity@+ createEntity()", asFUNCTION(SceneCreateEntity), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "Entity@+ createEntity(const string& in)", asFUNCTION(SceneCreateEntityWithName), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "Entity@+ createEntity(const string& in, bool)", asFUNCTION(SceneCreateEntityWithNameAndLocalFlag), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "Component@ createComponent(const string& in)", asFUNCTION(SceneCreateComponent), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "Component@ createComponent(const string& in, const string& in)", asFUNCTION(SceneCreateComponentWithName), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "void addEntity(Entity@+)", asMETHOD(Scene, addEntity), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void removeEntity(uint)", asMETHODPR(Scene, removeEntity, (EntityID), void), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void removeEntity(Entity@+)", asMETHODPR(Scene, removeEntity, (Entity*), void), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void removeEntity(const string& in)", asMETHODPR(Scene, removeEntity, (const std::string&), void), asCALL_THISCALL);
|
|
|
- engine->RegisterObjectMethod("Scene", "void removeAllEntities()", asFUNCTION(SceneRemoveAllEntitiesDefault), asCALL_CDECL_OBJLAST);
|
|
|
- engine->RegisterObjectMethod("Scene", "void removeAllEntities(uint8)", asMETHOD(Scene, removeAllEntities), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void removeEntities(uint8, uint)", asMETHOD(Scene, removeEntities), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "void removeAllEntities()", asMETHOD(Scene, removeAllEntities), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void setTransientPredictionTime(float)", asMETHOD(Scene, setTransientPredictionTime), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void setInterpolationConstant(float)", asMETHOD(Scene, setInterpolationConstant), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "void setInterpolationSnapThreshold(float)", asMETHOD(Scene, setInterpolationSnapThreshold), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "const string& getName() const", asMETHOD(Scene, getName), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "uint8 getNetFlags() const", asMETHOD(Scene, getNetFlags), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool hasEntity(uint) const", asMETHODPR(Scene, hasEntity, (EntityID) const, bool), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool hasEntity(Entity@+) const", asMETHODPR(Scene, hasEntity, (Entity*) const, bool), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool hasEntity(const string& in) const", asMETHODPR(Scene, hasEntity, (const std::string&) const, bool), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "Entity@+ getEntity(uint) const", asMETHODPR(Scene, getEntity, (EntityID) const, Entity*), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "Entity@+ getEntity(const string& in) const", asMETHODPR(Scene, getEntity, (const std::string&) const, Entity*), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "uint getNumEntities() const", asMETHOD(Scene, getNumEntities), asCALL_THISCALL);
|
|
|
- engine->RegisterObjectMethod("Scene", "array<Entity@>@ getEntities() const", asFUNCTION(SceneGetEntities), asCALL_CDECL_OBJLAST);
|
|
|
- engine->RegisterObjectMethod("Scene", "array<Entity@>@ getEntities(uint, uint) const", asFUNCTION(SceneGetEntitiesWithFlags), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "array<Entity@>@ getAllEntities() const", asFUNCTION(SceneGetAllEntities), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "array<Entity@>@ getEntities(uint8, uint) const", asFUNCTION(SceneGetEntities), asCALL_CDECL_OBJLAST);
|
|
|
+ engine->RegisterObjectMethod("Scene", "array<Entity@>@ getEntitiesWithComponent(const string& in) const", asFUNCTION(SceneGetEntitiesWithComponent), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "array<Entity@>@ getScriptedEntities() const", asFUNCTION(SceneGetScriptedEntities), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "array<Entity@>@ getScriptedEntities(const string& in) const", asFUNCTION(SceneGetScriptedEntitiesWithClass), asCALL_CDECL_OBJLAST);
|
|
|
engine->RegisterObjectMethod("Scene", "Vector3 getEntityPosition(Entity@+) const", asMETHOD(Scene, getEntityPosition), asCALL_THISCALL);
|
|
|
@@ -488,6 +461,7 @@ static void registerScene(asIScriptEngine* engine)
|
|
|
engine->RegisterObjectMethod("Scene", "float getAsyncLoadProgress() const", asMETHOD(Scene, getAsyncLoadProgress), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool isAuthority() const", asMETHOD(Scene, isAuthority), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool isProxy() const", asMETHOD(Scene, isProxy), asCALL_THISCALL);
|
|
|
+ engine->RegisterObjectMethod("Scene", "bool isPaused() const", asMETHOD(Scene, isPaused), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool isPlayback() const", asMETHOD(Scene, isPlayback), asCALL_THISCALL);
|
|
|
engine->RegisterObjectMethod("Scene", "bool isAsyncLoading() const", asMETHOD(Scene, isAsyncLoading), asCALL_THISCALL);
|
|
|
registerRefCasts<EventListener, Scene>(engine, "EventListener", "Scene");
|