Fixed some of the crashes with new coral
This commit is contained in:
@@ -9,6 +9,8 @@ project "EditorNet"
|
||||
vsprops {
|
||||
AppendTargetFrameworkToOutputPath = "false",
|
||||
Nullable = "enable",
|
||||
CopyLocalLockFileAssemblies = "true",
|
||||
EnableDynamicLoading = "true",
|
||||
}
|
||||
|
||||
files
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Nuake
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
scriptInstance->InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Nuake
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(e);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
scriptInstance->InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Nuake
|
||||
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnUpdate", ts.GetSeconds());
|
||||
scriptInstance->InvokeMethod("OnUpdate", ts.GetSeconds());
|
||||
}
|
||||
|
||||
for (auto& widget : CanvasParser::Get().GetAllCustomWidgetInstance())
|
||||
@@ -160,7 +160,7 @@ namespace Nuake
|
||||
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnFixedUpdate", ts.GetSeconds());
|
||||
scriptInstance->InvokeMethod("OnFixedUpdate", ts.GetSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace Nuake
|
||||
{
|
||||
Logger::Log(entity.GetComponent<NameComponent>().Name);
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnDestroy");
|
||||
scriptInstance->InvokeMethod("OnDestroy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,14 +226,14 @@ namespace Nuake
|
||||
if (entity1.IsValid() && scriptingEngineNet.HasEntityScriptInstance(entity1))
|
||||
{
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity1);
|
||||
scriptInstance.InvokeMethod("OnCollisionInternal", (int)col.Entity2);
|
||||
scriptInstance->InvokeMethod("OnCollisionInternal", (int)col.Entity2);
|
||||
}
|
||||
|
||||
Entity entity2 = { (entt::entity)col.Entity2, m_Scene };
|
||||
if (entity2.IsValid() && scriptingEngineNet.HasEntityScriptInstance(entity2))
|
||||
{
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity2);
|
||||
scriptInstance.InvokeMethod("OnCollisionInternal", (int)col.Entity1);
|
||||
scriptInstance->InvokeMethod("OnCollisionInternal", (int)col.Entity1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ namespace Nuake {
|
||||
return scene->GetEntity(entityName).GetHandle();
|
||||
}
|
||||
|
||||
Coral::ManagedObject GetEntityScriptFromName(Coral::String entityName)
|
||||
Coral::ManagedObject* GetEntityScriptFromName(Coral::String entityName)
|
||||
{
|
||||
auto scene = Engine::GetCurrentScene();
|
||||
if (!scene->EntityExists(entityName))
|
||||
if (!scene->EntityExists(std::string(entityName)))
|
||||
{
|
||||
return Coral::ManagedObject(); // Error code: entity not found.
|
||||
return nullptr; // Error code: entity not found.
|
||||
}
|
||||
|
||||
Entity entity = scene->GetEntity(entityName);
|
||||
@@ -62,14 +62,14 @@ namespace Nuake {
|
||||
|
||||
}
|
||||
|
||||
Coral::ManagedObject GetEntityScriptFromHandle(int entityHandle)
|
||||
Coral::ManagedObject* GetEntityScriptFromHandle(int entityHandle)
|
||||
{
|
||||
auto scene = Engine::GetCurrentScene();
|
||||
|
||||
Entity entity = { (entt::entity)(entityHandle), scene.get()};
|
||||
if (!entity.IsValid())
|
||||
{
|
||||
return Coral::ManagedObject(); // Error code: entity not found.
|
||||
return nullptr; // Error code: entity not found.
|
||||
}
|
||||
|
||||
auto& scriptingEngine = ScriptingEngineNet::Get();
|
||||
|
||||
@@ -688,8 +688,8 @@ namespace Nuake
|
||||
{
|
||||
// In the case the entity has a script & instance, we pass that.
|
||||
// This gives access to the objects scripts.
|
||||
auto scriptInstance = GetEntityScript(scriptEntity);
|
||||
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, scriptInstance);
|
||||
//Coral::ManagedObject* scriptInstance = GetEntityScript(scriptEntity);
|
||||
//classInstance->SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, scriptInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -728,17 +728,17 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
Coral::ManagedObject ScriptingEngineNet::GetEntityScript(const Entity& entity)
|
||||
Coral::ManagedObject* ScriptingEngineNet::GetEntityScript(const Entity& entity)
|
||||
{
|
||||
if (!HasEntityScriptInstance(entity))
|
||||
{
|
||||
std::string name = entity.GetComponent<NameComponent>().Name;
|
||||
Logger::Log(name);
|
||||
Logger::Log("Failed to get entity .Net script instance, doesn't exist", ".net", CRITICAL);
|
||||
return Coral::ManagedObject();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return entityToManagedObjects[entity.GetID()];
|
||||
return &entityToManagedObjects[entity.GetID()];
|
||||
}
|
||||
|
||||
bool ScriptingEngineNet::HasEntityScriptInstance(const Entity& entity)
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Nuake
|
||||
|
||||
void CreateEntityScript(const std::string& path, const std::string& entityName);
|
||||
void RegisterEntityScript(Entity& entity);
|
||||
Coral::ManagedObject GetEntityScript(const Entity& entity);
|
||||
Coral::ManagedObject* GetEntityScript(const Entity& entity);
|
||||
bool HasEntityScriptInstance(const Entity& entity);
|
||||
std::string FindClassNameInScript(const std::string& filePath);
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ project "NuakeNet"
|
||||
vsprops {
|
||||
AppendTargetFrameworkToOutputPath = "false",
|
||||
Nullable = "enable",
|
||||
CopyLocalLockFileAssemblies = "true",
|
||||
EnableDynamicLoading = "true",
|
||||
}
|
||||
|
||||
files
|
||||
|
||||
Reference in New Issue
Block a user