Added Screen space reflections and Editor UI refactoring
This commit is contained in:
@@ -5,17 +5,18 @@
|
||||
#include "ScriptModule.h"
|
||||
#include <iostream>
|
||||
#include <wren.h>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
namespace ScriptAPI
|
||||
{
|
||||
class EngineModule : public ScriptModule
|
||||
{
|
||||
std::string ModuleName = "Engine";
|
||||
const std::string ModuleName = "Engine";
|
||||
|
||||
std::string GetModuleName() override
|
||||
{
|
||||
return "Engine";
|
||||
return ModuleName;
|
||||
}
|
||||
|
||||
void RegisterModule(WrenVM* vm) override
|
||||
|
||||
@@ -88,18 +88,18 @@ namespace Nuake {
|
||||
return result;
|
||||
}
|
||||
|
||||
Ref<WrenScript> ScriptingEngine::RegisterScript(const std::string& path, const std::string& mod)
|
||||
{
|
||||
// Check if scripts has already been loaded.
|
||||
// You can't import the same module twice, otherwise, compile error.
|
||||
if (m_Scripts.find(path) == m_Scripts.end())
|
||||
{
|
||||
std::string query = "import \"" + path + "\" for " + mod;
|
||||
wrenInterpret(m_WrenVM, "main", query.c_str());
|
||||
}
|
||||
|
||||
return CreateRef<WrenScript>(path, mod);
|
||||
}
|
||||
//Ref<WrenScript> ScriptingEngine::RegisterScript(const std::string& path, const std::string& mod)
|
||||
//{
|
||||
// //// Check if scripts has already been loaded.
|
||||
// //// You can't import the same module twice, otherwise, compile error.
|
||||
// //if (m_Scripts.find(path) == m_Scripts.end())
|
||||
// //{
|
||||
// // std::string query = "import \"" + path + "\" for " + mod;
|
||||
// // wrenInterpret(m_WrenVM, "main", query.c_str());
|
||||
// //}
|
||||
// //
|
||||
// //return CreateRef<WrenScript>(path, mod);
|
||||
//}
|
||||
|
||||
// Useful to check if a script has been imported, importing a script
|
||||
// twice gives a compile error.
|
||||
@@ -120,8 +120,6 @@ namespace Nuake {
|
||||
m_LoadedScripts.push_back(path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ScriptingEngine::RegisterModule(Ref<ScriptModule> scriptModule)
|
||||
{
|
||||
Modules[scriptModule->GetModuleName()] = scriptModule;
|
||||
|
||||
@@ -1,18 +1,57 @@
|
||||
#include "WrenScript.h"
|
||||
#include "../Core/FileSystem.h"
|
||||
#include "src/Core/String.h"
|
||||
|
||||
#include <src/Vendors/wren/src/include/wren.h>
|
||||
|
||||
namespace Nuake {
|
||||
WrenScript::WrenScript(const std::string& path, const std::string& mod, bool isEntity)
|
||||
WrenScript::WrenScript(Ref<File> file, bool isEntity)
|
||||
{
|
||||
mFile = file;
|
||||
IsEntity = isEntity;
|
||||
|
||||
ParseModules();
|
||||
}
|
||||
|
||||
void WrenScript::ParseModules()
|
||||
{
|
||||
std::ifstream MyReadFile(mFile->GetAbsolutePath());
|
||||
std::string fileContent = "";
|
||||
|
||||
while (getline(MyReadFile, fileContent))
|
||||
{
|
||||
bool hasFoundModule = false;
|
||||
|
||||
auto& splits = String::Split(fileContent, ' ');
|
||||
for (unsigned int i = 0; i < splits.size(); i++)
|
||||
{
|
||||
std::string s = splits[i];
|
||||
if (s == "class" && i + 1 < splits.size() && !hasFoundModule)
|
||||
{
|
||||
std::string moduleFound = splits[i + 1];
|
||||
mModules.push_back(moduleFound);
|
||||
hasFoundModule = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the file
|
||||
MyReadFile.close();
|
||||
}
|
||||
|
||||
std::vector<std::string> WrenScript::GetModules()
|
||||
{
|
||||
return mModules;
|
||||
}
|
||||
|
||||
void WrenScript::Build(unsigned int moduleId, bool isEntity)
|
||||
{
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
|
||||
CompiledSuccesfully = true;
|
||||
|
||||
std::string relativePath = mFile->GetRelativePath();
|
||||
// Can't import twice the same script, otherwise gives a compile error.
|
||||
if (!ScriptingEngine::IsScriptImported(path))
|
||||
if (!ScriptingEngine::IsScriptImported(relativePath))
|
||||
{
|
||||
std::string source = "import \"" + path + "\" for " + mod;
|
||||
std::string source = "import \"" + relativePath + "\" for " + GetModules()[moduleId];
|
||||
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
|
||||
|
||||
if (result != WREN_RESULT_SUCCESS)
|
||||
@@ -21,12 +60,12 @@ namespace Nuake {
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
ScriptingEngine::ImportScript(path);
|
||||
ScriptingEngine::ImportScript(relativePath);
|
||||
}
|
||||
|
||||
// Get handle to class
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "main", mod.c_str(), 0);
|
||||
wrenGetVariable(vm, "main", GetModules()[moduleId].c_str(), 0);
|
||||
WrenHandle* classHandle = wrenGetSlotHandle(vm, 0);
|
||||
|
||||
// Call the constructor
|
||||
@@ -44,10 +83,14 @@ namespace Nuake {
|
||||
|
||||
if (isEntity)
|
||||
this->m_SetEntityIDHandle = wrenMakeCallHandle(vm, "SetEntityId(_)");
|
||||
|
||||
CompiledSuccesfully = true;
|
||||
}
|
||||
|
||||
void WrenScript::CallInit()
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
WrenInterpretResult result = wrenCall(vm, this->m_OnInitHandle);
|
||||
@@ -55,6 +98,8 @@ namespace Nuake {
|
||||
|
||||
void WrenScript::CallUpdate(float timestep)
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenEnsureSlots(vm, 2);
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
@@ -64,6 +109,8 @@ namespace Nuake {
|
||||
|
||||
void WrenScript::CallFixedUpdate(float timestep)
|
||||
{
|
||||
if (!CompiledSuccesfully) return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenEnsureSlots(vm, 2);
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
@@ -84,6 +131,9 @@ namespace Nuake {
|
||||
|
||||
void WrenScript::RegisterMethod(const std::string& signature)
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
WrenHandle* handle = wrenMakeCallHandle(vm, signature.c_str());
|
||||
methods.emplace(signature, handle);
|
||||
@@ -91,8 +141,10 @@ namespace Nuake {
|
||||
|
||||
void WrenScript::CallMethod(const std::string& signature)
|
||||
{
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
|
||||
// Not found. maybe try to register it?
|
||||
if (methods.find(signature) == methods.end())
|
||||
@@ -105,6 +157,9 @@ namespace Nuake {
|
||||
|
||||
void WrenScript::SetScriptableEntityID(int id)
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
wrenSetSlotDouble(vm, 1, id);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "ScriptingEngine.h"
|
||||
|
||||
#include "src/Core/FileSystem.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@@ -8,7 +10,14 @@ class WrenHandle;
|
||||
namespace Nuake {
|
||||
class WrenScript
|
||||
{
|
||||
private:
|
||||
bool CompiledSuccesfully;
|
||||
bool IsEntity = false;
|
||||
std::vector<std::string> mModules;
|
||||
|
||||
public:
|
||||
Ref<File> mFile;
|
||||
|
||||
std::map <std::string, WrenHandle*> methods;
|
||||
WrenHandle* m_Instance;
|
||||
WrenHandle* m_OnInitHandle;
|
||||
@@ -17,10 +26,14 @@ namespace Nuake {
|
||||
WrenHandle* m_OnExitHandle;
|
||||
WrenHandle* m_SetEntityIDHandle;
|
||||
|
||||
bool CompiledSuccesfully;
|
||||
// Building
|
||||
WrenScript(Ref<File> file, bool isEntity);
|
||||
|
||||
WrenScript(const std::string& path, const std::string& mod, bool isEntity = false);
|
||||
void ParseModules();
|
||||
std::vector<std::string> GetModules();
|
||||
void Build(unsigned int moduleId, bool isEntity = false);
|
||||
|
||||
// Method calls
|
||||
void CallInit();
|
||||
void CallUpdate(float timestep);
|
||||
void CallFixedUpdate(float timestep);
|
||||
@@ -30,5 +43,7 @@ namespace Nuake {
|
||||
void CallMethod(const std::string& signature);
|
||||
|
||||
void SetScriptableEntityID(int id);
|
||||
|
||||
bool HasCompiledSuccesfully() { return CompiledSuccesfully; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user