Added Screen space reflections and Editor UI refactoring
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user