Clean up
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <Engine.h>
|
||||
|
||||
#include <src/Core/Maths.h>
|
||||
#include <src/Core/Input.h>
|
||||
#include <src/Scene/Scene.h>
|
||||
#include <src/Scene/Entities/Entity.h>
|
||||
@@ -28,6 +27,8 @@
|
||||
#include "src/Misc/GizmoDrawer.h"
|
||||
#include "src/Windows/FileSystemUI.h"
|
||||
|
||||
#include <src/Core/Maths.h>
|
||||
|
||||
const std::string WindowTitle = "Nuake Editor";
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
#include "src/Scripting/WrenScript.h"
|
||||
#include "src/Resource/Serializable.h"
|
||||
#include "src/Core/FileSystem.h"
|
||||
|
||||
namespace Nuake {
|
||||
namespace Nuake
|
||||
{
|
||||
class WrenScriptComponent
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Nuake {
|
||||
|
||||
if (ent.HasComponent<WrenScriptComponent>())
|
||||
{
|
||||
wrenSetSlotHandle(vm, 0, ent.GetComponent<WrenScriptComponent>().mWrenScript->m_Instance);
|
||||
wrenSetSlotHandle(vm, 0, ent.GetComponent<WrenScriptComponent>().mWrenScript->GetWrenInstanceHandle());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "WrenScript.h"
|
||||
#include "src/Core/FileSystem.h"
|
||||
|
||||
#include "src/Scripting/VM.h"
|
||||
#include "src/Scripting/Modules/ScriptModule.h"
|
||||
#include "src/Scripting/Modules/EngineModule.h"
|
||||
#include "src/Scripting/Modules/SceneModule.h"
|
||||
@@ -11,7 +10,7 @@
|
||||
#include "src/Scripting/Modules/PhysicsModule.h"
|
||||
|
||||
namespace Nuake {
|
||||
Ref<VM> ScriptingEngine::m_VM;
|
||||
WrenVM* ScriptingEngine::m_WrenVM;
|
||||
|
||||
std::map<std::string, Ref<WrenScript>> ScriptingEngine::m_Scripts;
|
||||
std::map<std::string, Ref<ScriptModule>> ScriptingEngine::Modules;
|
||||
@@ -163,8 +162,6 @@ namespace Nuake {
|
||||
config.errorFn = &errorFn;
|
||||
config.writeFn = &writeFn;
|
||||
config.bindForeignMethodFn = &bindForeignMethod;
|
||||
|
||||
m_VM = CreateRef<VM>();
|
||||
m_WrenVM = wrenNewVM(&config);
|
||||
|
||||
Logger::Log("Registing Scripting Modules");
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
WrenScript::WrenScript(Ref<File> file, bool isEntity)
|
||||
WrenScript::WrenScript(Ref<File> file, bool isEntityScript)
|
||||
{
|
||||
mFile = file;
|
||||
IsEntity = isEntity;
|
||||
m_IsEntityScript = isEntityScript;
|
||||
|
||||
ParseModules();
|
||||
}
|
||||
@@ -32,45 +32,42 @@ namespace Nuake
|
||||
if (s == "class" && i + 1 < splits.size() && !hasFoundModule)
|
||||
{
|
||||
std::string moduleFound = splits[i + 1];
|
||||
mModules.push_back(moduleFound);
|
||||
m_Modules.push_back(moduleFound);
|
||||
hasFoundModule = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the file
|
||||
MyReadFile.close();
|
||||
}
|
||||
|
||||
std::vector<std::string> WrenScript::GetModules()
|
||||
std::vector<std::string> WrenScript::GetModules() const
|
||||
{
|
||||
return mModules;
|
||||
return m_Modules;
|
||||
}
|
||||
|
||||
void WrenScript::Build(unsigned int moduleId, bool isEntity)
|
||||
{
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
|
||||
std::string relativePath = mFile->GetRelativePath();
|
||||
const std::string& relativePath = mFile->GetRelativePath();
|
||||
|
||||
// Can't import twice the same script, otherwise gives a compile error.
|
||||
if (!ScriptingEngine::IsScriptImported(relativePath))
|
||||
{
|
||||
std::string source = "import \"" + relativePath + "\" for " + GetModules()[moduleId];
|
||||
const std::string& source = "import \"" + relativePath + "\" for " + GetModules()[moduleId];
|
||||
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
|
||||
|
||||
|
||||
Logger::Log("Wren result: " + std::to_string(result));
|
||||
if (result == WREN_RESULT_SUCCESS)
|
||||
{
|
||||
Logger::Log("Wren result success: " + std::to_string(result));
|
||||
CompiledSuccesfully = true;
|
||||
Logger::Log("[ScriptingEngine] Compiled succesfully: " + std::to_string(result));
|
||||
m_HasCompiledSuccesfully = true;
|
||||
ScriptingEngine::ImportScript(relativePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Log("Wren result failed: " + std::to_string(result));
|
||||
CompiledSuccesfully = false;
|
||||
Logger::Log("[ScriptingEngine] Compiled failed: " + std::to_string(result));
|
||||
m_HasCompiledSuccesfully = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -96,12 +93,12 @@ namespace Nuake
|
||||
if (isEntity)
|
||||
this->m_SetEntityIDHandle = wrenMakeCallHandle(vm, "SetEntityId(_)");
|
||||
|
||||
CompiledSuccesfully = true;
|
||||
m_HasCompiledSuccesfully = true;
|
||||
}
|
||||
|
||||
void WrenScript::CallInit()
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
if (!m_HasCompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
@@ -110,7 +107,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::CallUpdate(float timestep)
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
if (!m_HasCompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenEnsureSlots(vm, 2);
|
||||
@@ -121,7 +118,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::CallFixedUpdate(float timestep)
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
if (!m_HasCompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenEnsureSlots(vm, 2);
|
||||
@@ -132,7 +129,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::CallExit()
|
||||
{
|
||||
if (!CompiledSuccesfully || !m_Instance)
|
||||
if (!m_HasCompiledSuccesfully || !m_Instance)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
@@ -143,7 +140,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::RegisterMethod(const std::string& signature)
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
if (!m_HasCompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
@@ -153,7 +150,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::CallMethod(const std::string& signature)
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
if (!m_HasCompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
@@ -169,7 +166,7 @@ namespace Nuake
|
||||
|
||||
void WrenScript::SetScriptableEntityID(int id)
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
if (!m_HasCompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
|
||||
@@ -12,11 +12,10 @@ namespace Nuake
|
||||
class WrenScript
|
||||
{
|
||||
private:
|
||||
bool CompiledSuccesfully;
|
||||
bool IsEntity = false;
|
||||
std::vector<std::string> mModules;
|
||||
bool m_HasCompiledSuccesfully;
|
||||
bool m_IsEntityScript = false;
|
||||
std::vector<std::string> m_Modules;
|
||||
|
||||
public:
|
||||
Ref<File> mFile;
|
||||
|
||||
std::map <std::string, WrenHandle*> methods;
|
||||
@@ -27,12 +26,11 @@ namespace Nuake
|
||||
WrenHandle* m_OnExitHandle;
|
||||
WrenHandle* m_SetEntityIDHandle;
|
||||
|
||||
// Building
|
||||
WrenScript(Ref<File> file, bool isEntity);
|
||||
|
||||
public:
|
||||
WrenScript(Ref<File> file, bool isEntityScript);
|
||||
void ParseModules();
|
||||
std::vector<std::string> GetModules();
|
||||
void Build(unsigned int moduleId, bool isEntity = false);
|
||||
|
||||
void Build(unsigned int moduleId, bool isEntityScript = false);
|
||||
|
||||
// Method calls
|
||||
void CallInit();
|
||||
@@ -44,7 +42,10 @@ namespace Nuake
|
||||
void CallMethod(const std::string& signature);
|
||||
|
||||
void SetScriptableEntityID(int id);
|
||||
bool HasCompiledSuccesfully() const { return m_HasCompiledSuccesfully; }
|
||||
|
||||
bool HasCompiledSuccesfully() { return CompiledSuccesfully; }
|
||||
std::vector<std::string> GetModules() const;
|
||||
|
||||
WrenHandle* GetWrenInstanceHandle() const { return m_Instance; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user