Finished refactoring angelscript internal api
This commit is contained in:
parent
47871fa1dc
commit
54f8156b6b
@ -8,7 +8,7 @@ namespace Deer {
|
|||||||
|
|
||||||
void Log::init() {
|
void Log::init() {
|
||||||
// spdlog::set_pattern("%^[%T] %n: %v%$");
|
// spdlog::set_pattern("%^[%T] %n: %v%$");
|
||||||
spdlog::set_pattern("%n: %v%$");
|
spdlog::set_pattern("%v%$");
|
||||||
|
|
||||||
coreLogger = spdlog::stdout_color_mt("Core");
|
coreLogger = spdlog::stdout_color_mt("Core");
|
||||||
clientLogger = spdlog::stdout_color_mt("Client");
|
clientLogger = spdlog::stdout_color_mt("Client");
|
||||||
|
|||||||
2591
Deer/vendor/angelScript/include/angelscript.h
vendored
2591
Deer/vendor/angelScript/include/angelscript.h
vendored
File diff suppressed because it is too large
Load Diff
802
Deer/vendor/angelScript/src/scriptbuilder.cpp
vendored
802
Deer/vendor/angelScript/src/scriptbuilder.cpp
vendored
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "DeerRender/Tools/Memory.h"
|
||||||
#include "DeerRender/Tools/Path.h"
|
#include "DeerRender/Tools/Path.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -9,8 +10,10 @@ class asIScriptModule;
|
|||||||
class asIScriptContext;
|
class asIScriptContext;
|
||||||
class asIScriptObject;
|
class asIScriptObject;
|
||||||
class asIScriptFunction;
|
class asIScriptFunction;
|
||||||
|
class asIScriptFunction;
|
||||||
class asITypeInfo;
|
class asITypeInfo;
|
||||||
class CScriptBuilder;
|
class CScriptBuilder;
|
||||||
|
class asIScriptGeneric;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace AngelScriptEngine {
|
||||||
@ -20,6 +23,12 @@ namespace Deer {
|
|||||||
void render();
|
void render();
|
||||||
void deinitialize();
|
void deinitialize();
|
||||||
|
|
||||||
|
struct ServiceExposedFunctionData {
|
||||||
|
asIScriptFunction* exposedFunction = nullptr;
|
||||||
|
asIScriptObject* exposedObject = nullptr;
|
||||||
|
std::string exposedFunctionName;
|
||||||
|
};
|
||||||
|
|
||||||
struct Service {
|
struct Service {
|
||||||
public:
|
public:
|
||||||
Service(asITypeInfo*);
|
Service(asITypeInfo*);
|
||||||
@ -34,14 +43,25 @@ namespace Deer {
|
|||||||
void update();
|
void update();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
|
void updateTypes(asIScriptModule*);
|
||||||
|
void registerApiExpose();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
asITypeInfo* type = nullptr;
|
asITypeInfo* type = nullptr;
|
||||||
asIScriptObject* object = nullptr;
|
asIScriptObject* object = nullptr;
|
||||||
asIScriptFunction* updateFunction = nullptr;
|
asIScriptFunction* updateFunction = nullptr;
|
||||||
asIScriptFunction* initFunction = nullptr;
|
asIScriptFunction* initFunction = nullptr;
|
||||||
asIScriptFunction* shutdownFunction = nullptr;
|
asIScriptFunction* shutdownFunction = nullptr;
|
||||||
|
std::vector<Scope<ServiceExposedFunctionData>> exposedFunctions;
|
||||||
|
|
||||||
|
std::string typeName;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void registerExposedFunction(asIScriptFunction*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void service_exposed_generic_call(asIScriptGeneric*);
|
||||||
|
|
||||||
struct Panel : public Service {
|
struct Panel : public Service {
|
||||||
public:
|
public:
|
||||||
Panel(asITypeInfo*);
|
Panel(asITypeInfo*);
|
||||||
@ -52,6 +72,7 @@ namespace Deer {
|
|||||||
Panel& operator=(Panel&&) = default;
|
Panel& operator=(Panel&&) = default;
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
void updateTypes(asIScriptModule*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
asIScriptFunction* renderFunction;
|
asIScriptFunction* renderFunction;
|
||||||
@ -93,7 +114,8 @@ namespace Deer {
|
|||||||
void render();
|
void render();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
void extractTypes();
|
void extract(asIScriptModule*);
|
||||||
|
void updateTypes();
|
||||||
|
|
||||||
inline void invalidate() { state = ModuleState::ExecutionError; }
|
inline void invalidate() { state = ModuleState::ExecutionError; }
|
||||||
|
|
||||||
|
|||||||
@ -7,27 +7,45 @@ namespace Deer {
|
|||||||
namespace AngelScriptEngine {
|
namespace AngelScriptEngine {
|
||||||
Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {}
|
Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {}
|
||||||
|
|
||||||
void Module::extractTypes() {
|
void Module::extract(asIScriptModule* _module) {
|
||||||
if (state != ModuleState::Built)
|
if (state != ModuleState::Built)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
angelscriptModule = AngelScriptEngine::scriptEngine->GetModule(moduleInfo.moduleName.c_str());
|
angelscriptModule = _module;
|
||||||
uint32_t typeCount = angelscriptModule->GetObjectTypeCount();
|
|
||||||
|
|
||||||
|
scriptEngine->SetDefaultNamespace(moduleInfo.moduleName.c_str());
|
||||||
|
uint32_t typeCount = angelscriptModule->GetObjectTypeCount();
|
||||||
for (uint32_t typeId = 0; typeId < typeCount; typeId++) {
|
for (uint32_t typeId = 0; typeId < typeCount; typeId++) {
|
||||||
asITypeInfo* typeInfo = angelscriptModule->GetObjectTypeByIndex(typeId);
|
asITypeInfo* typeInfo = angelscriptModule->GetObjectTypeByIndex(typeId);
|
||||||
|
|
||||||
if (ImplementsInterface(typeInfo, serviceBaseType)) {
|
if (ImplementsInterface(typeInfo, serviceBaseType)) {
|
||||||
services.push_back({typeInfo});
|
services.push_back({typeInfo});
|
||||||
|
services.back().registerApiExpose();
|
||||||
} else if (ImplementsInterface(typeInfo, panelBaseType)) {
|
} else if (ImplementsInterface(typeInfo, panelBaseType)) {
|
||||||
panels.push_back({typeInfo});
|
panels.push_back({typeInfo});
|
||||||
|
panels.back().registerApiExpose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scriptEngine->SetDefaultNamespace("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::updateTypes() {
|
||||||
|
if (state != ModuleState::Built)
|
||||||
|
return;
|
||||||
|
|
||||||
|
angelscriptModule = AngelScriptEngine::scriptEngine->GetModule(moduleInfo.moduleName.c_str());
|
||||||
|
|
||||||
|
for (Service& service : services)
|
||||||
|
service.updateTypes(angelscriptModule);
|
||||||
|
|
||||||
|
for (Panel& panel : panels)
|
||||||
|
panel.updateTypes(angelscriptModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::init() {
|
void Module::init() {
|
||||||
if (state != ModuleState::Built)
|
if (state != ModuleState::Built)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
angelscriptModule->BindAllImportedFunctions();
|
angelscriptModule->BindAllImportedFunctions();
|
||||||
|
|
||||||
for (Service& service : services)
|
for (Service& service : services)
|
||||||
|
|||||||
@ -44,10 +44,12 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AngelScriptEngine::loadModule(Module& module) {
|
bool AngelScriptEngine::loadModule(Module& module) {
|
||||||
|
if (module.state != ModuleState::NotBuilt)
|
||||||
|
return false;
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
module.state = ModuleState::Building;
|
module.state = ModuleState::Building;
|
||||||
|
|
||||||
DEER_CORE_TRACE("Loading module {}", module.moduleInfo.moduleName);
|
|
||||||
for (const std::string& dependency : module.moduleInfo.module_requires) {
|
for (const std::string& dependency : module.moduleInfo.module_requires) {
|
||||||
if (!module_id.contains(dependency)) {
|
if (!module_id.contains(dependency)) {
|
||||||
DEER_CORE_ERROR("Failed to find dependency {} for module {}",
|
DEER_CORE_ERROR("Failed to find dependency {} for module {}",
|
||||||
@ -79,6 +81,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DEER_CORE_TRACE("Loading module {}", module.moduleInfo.moduleName);
|
||||||
|
|
||||||
scriptBuilder.StartNewModule(scriptEngine, module.moduleInfo.moduleName.c_str());
|
scriptBuilder.StartNewModule(scriptEngine, module.moduleInfo.moduleName.c_str());
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
@ -109,6 +112,8 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.state = ModuleState::Built;
|
module.state = ModuleState::Built;
|
||||||
|
module.extract(as_module);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +156,16 @@ namespace Deer {
|
|||||||
|
|
||||||
desc.modulePath = path.string();
|
desc.modulePath = path.string();
|
||||||
|
|
||||||
|
if (module_id.contains(desc.moduleName)) {
|
||||||
|
DEER_CORE_ERROR("Module name duplicated {}", path.string().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
module_id[desc.moduleName] = modules.size();
|
module_id[desc.moduleName] = modules.size();
|
||||||
modules.push_back({desc});
|
modules.push_back({desc});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::loadModules() {
|
void AngelScriptEngine::loadModules() {
|
||||||
generateAngelscriptPredefined();
|
|
||||||
const Path path = Path("Editor") / Path("Modules");
|
const Path path = Path("Editor") / Path("Modules");
|
||||||
|
|
||||||
if (!fs::exists(path) || !fs::is_directory(path)) {
|
if (!fs::exists(path) || !fs::is_directory(path)) {
|
||||||
@ -173,14 +182,15 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
saveAngelscriptPredefined(module.moduleInfo.modulePath);
|
|
||||||
if (module.state == ModuleState::NotBuilt) {
|
if (module.state == ModuleState::NotBuilt) {
|
||||||
loadModule(module);
|
loadModule(module);
|
||||||
|
generateAngelscriptPredefined();
|
||||||
}
|
}
|
||||||
|
saveAngelscriptPredefined(module.moduleInfo.modulePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
module.extractTypes();
|
module.updateTypes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -12,6 +12,13 @@ namespace Deer {
|
|||||||
menuBarFunction = type->GetMethodByDecl("void menuBar()");
|
menuBarFunction = type->GetMethodByDecl("void menuBar()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::updateTypes(asIScriptModule* typeInfo) {
|
||||||
|
Service::updateTypes(typeInfo);
|
||||||
|
|
||||||
|
renderFunction = type->GetMethodByDecl("void render()");
|
||||||
|
menuBarFunction = type->GetMethodByDecl("void menuBar()");
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::render() {
|
void Panel::render() {
|
||||||
// IMPLEMENT REMOVE PADDING
|
// IMPLEMENT REMOVE PADDING
|
||||||
if (menuBarFunction) {
|
if (menuBarFunction) {
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
// https://github.com/sashi0034/angel-lsp/blob/main/examples/OpenSiv3D/make_predefined.cpp
|
// https://github.com/sashi0034/angel-lsp/blob/main/examples/OpenSiv3D/make_predefined.cpp
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "DeerRender/Log.h"
|
||||||
#include "DeerStudio/AngelScriptEngine.h"
|
#include "DeerStudio/AngelScriptEngine.h"
|
||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
|
||||||
@ -71,6 +72,43 @@ void printEnumList(const asIScriptEngine& engine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeParameters(asIScriptFunction* function) {
|
||||||
|
for (int n = 0; n < function->GetParamCount(); n++) {
|
||||||
|
int typeId;
|
||||||
|
asDWORD flags;
|
||||||
|
const char* name;
|
||||||
|
const char* defaultArgument;
|
||||||
|
|
||||||
|
function->GetParam(n, &typeId, &flags, &name, &defaultArgument);
|
||||||
|
|
||||||
|
if (typeId == -1) {
|
||||||
|
stream << "?";
|
||||||
|
} else {
|
||||||
|
asITypeInfo* ti = function->GetEngine()->GetTypeInfoById(typeId);
|
||||||
|
if (ti && (ti->GetFlags() & asOBJ_FUNCDEF)) {
|
||||||
|
stream << ti->GetName();
|
||||||
|
} else {
|
||||||
|
const char* typeName = function->GetEngine()->GetTypeDeclaration(typeId, false);
|
||||||
|
stream << typeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & asTM_INREF)
|
||||||
|
stream << " &in ";
|
||||||
|
else if (flags & asTM_OUTREF)
|
||||||
|
stream << " &out ";
|
||||||
|
else if (flags & asTM_INOUTREF)
|
||||||
|
stream << " &inout ";
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
stream << " " << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n != function->GetParamCount() - 1)
|
||||||
|
stream << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void printClassTypeList(const asIScriptEngine& engine) {
|
void printClassTypeList(const asIScriptEngine& engine) {
|
||||||
for (int i = 0; i < engine.GetObjectTypeCount(); ++i) {
|
for (int i = 0; i < engine.GetObjectTypeCount(); ++i) {
|
||||||
asITypeInfo* t = engine.GetObjectTypeByIndex(i);
|
asITypeInfo* t = engine.GetObjectTypeByIndex(i);
|
||||||
@ -109,7 +147,9 @@ void printClassTypeList(const asIScriptEngine& engine) {
|
|||||||
for (int j = 0; j < t->GetFactoryCount(); ++j) {
|
for (int j = 0; j < t->GetFactoryCount(); ++j) {
|
||||||
asIScriptFunction* f = t->GetFactoryByIndex(j);
|
asIScriptFunction* f = t->GetFactoryByIndex(j);
|
||||||
|
|
||||||
stream << "\t" << f->GetDeclaration(false, false, true) << ";\n";
|
stream << "\t" << t->GetName() << "(";
|
||||||
|
writeParameters(f);
|
||||||
|
stream << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < t->GetBehaviourCount(); ++j) {
|
for (int j = 0; j < t->GetBehaviourCount(); ++j) {
|
||||||
@ -125,7 +165,21 @@ void printClassTypeList(const asIScriptEngine& engine) {
|
|||||||
|
|
||||||
for (int j = 0; j < t->GetMethodCount(); ++j) {
|
for (int j = 0; j < t->GetMethodCount(); ++j) {
|
||||||
const auto m = t->GetMethodByIndex(j);
|
const auto m = t->GetMethodByIndex(j);
|
||||||
stream << "\t" << m->GetDeclaration(false, false, true);
|
|
||||||
|
stream << "\t";
|
||||||
|
int methodReturnId = m->GetReturnTypeId();
|
||||||
|
if (methodReturnId == -1) {
|
||||||
|
stream << "? ";
|
||||||
|
} else {
|
||||||
|
stream << t->GetEngine()->GetTypeDeclaration(methodReturnId) << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << m->GetName() << "(";
|
||||||
|
|
||||||
|
writeParameters(m);
|
||||||
|
stream << ")";
|
||||||
|
|
||||||
|
// stream << "\t" << m->GetDeclaration(false, false, true);
|
||||||
|
|
||||||
if (m->IsProperty())
|
if (m->IsProperty())
|
||||||
stream << " property";
|
stream << " property";
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine.h"
|
#include "DeerStudio/AngelScriptEngine.h"
|
||||||
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
||||||
|
|
||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
#include "scriptbuilder.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace AngelScriptEngine {
|
||||||
@ -27,6 +30,11 @@ namespace Deer {
|
|||||||
object->AddRef();
|
object->AddRef();
|
||||||
AS_CHECK(scriptContext->Unprepare());
|
AS_CHECK(scriptContext->Unprepare());
|
||||||
|
|
||||||
|
for (Scope<ServiceExposedFunctionData>& exposedFunction : exposedFunctions) {
|
||||||
|
exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str());
|
||||||
|
exposedFunction->exposedObject = object;
|
||||||
|
}
|
||||||
|
|
||||||
if (!initFunction)
|
if (!initFunction)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -37,6 +45,214 @@ namespace Deer {
|
|||||||
AS_CHECK(scriptContext->Unprepare());
|
AS_CHECK(scriptContext->Unprepare());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Service::registerApiExpose() {
|
||||||
|
int functionCount = type->GetMethodCount();
|
||||||
|
|
||||||
|
for (int i = 0; i < functionCount; i++) {
|
||||||
|
asIScriptFunction* function = type->GetMethodByIndex(i);
|
||||||
|
|
||||||
|
bool containsExposeMetadata = false;
|
||||||
|
std::vector<std::string> metadata = scriptBuilder.GetMetadataForTypeMethod(type->GetTypeId(), function);
|
||||||
|
|
||||||
|
for (std::string& meta : metadata) {
|
||||||
|
if (meta == "Expose") {
|
||||||
|
containsExposeMetadata = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!containsExposeMetadata)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
registerExposedFunction(function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Service::registerExposedFunction(asIScriptFunction* function) {
|
||||||
|
asITypeInfo* returnType = scriptEngine->GetTypeInfoById(function->GetReturnTypeId());
|
||||||
|
if (returnType && returnType->GetModule()) {
|
||||||
|
DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type for return type", function->GetDeclaration());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string declaration;
|
||||||
|
declaration = scriptEngine->GetTypeDeclaration(function->GetReturnTypeId(), false);
|
||||||
|
|
||||||
|
declaration += " ";
|
||||||
|
declaration += function->GetName();
|
||||||
|
declaration += "(";
|
||||||
|
|
||||||
|
int paramCount = function->GetParamCount();
|
||||||
|
for (int n = 0; n < paramCount; n++) {
|
||||||
|
int typeId;
|
||||||
|
asDWORD flags;
|
||||||
|
const char* name;
|
||||||
|
const char* defaultArgument;
|
||||||
|
|
||||||
|
function->GetParam(n, &typeId, &flags, &name, &defaultArgument);
|
||||||
|
asITypeInfo* paramType = scriptEngine->GetTypeInfoById(typeId);
|
||||||
|
if (paramType && paramType->GetModule()) {
|
||||||
|
DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type in parameter", function->GetDeclaration());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* typeName = scriptEngine->GetTypeDeclaration(typeId, false);
|
||||||
|
declaration += typeName;
|
||||||
|
|
||||||
|
if (flags & asTM_INREF)
|
||||||
|
declaration += " in ";
|
||||||
|
else if (flags & asTM_OUTREF)
|
||||||
|
declaration += " out ";
|
||||||
|
else if (flags & asTM_INOUTREF)
|
||||||
|
declaration += " inout ";
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
declaration += " ";
|
||||||
|
declaration += name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaultArgument) {
|
||||||
|
declaration += "= ";
|
||||||
|
declaration += defaultArgument;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n != paramCount - 1)
|
||||||
|
declaration += ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
declaration += ")";
|
||||||
|
|
||||||
|
exposedFunctions.push_back(MakeScope<ServiceExposedFunctionData>());
|
||||||
|
ServiceExposedFunctionData* exposedFunctionData = exposedFunctions.back().get();
|
||||||
|
|
||||||
|
exposedFunctionData->exposedFunction = function;
|
||||||
|
exposedFunctionData->exposedFunctionName = function->GetName();
|
||||||
|
exposedFunctionData->exposedObject = object;
|
||||||
|
|
||||||
|
DEER_CORE_TRACE("Registering {}", declaration.c_str());
|
||||||
|
scriptEngine->RegisterGlobalFunction(declaration.c_str(), asFUNCTION(service_exposed_generic_call), asCALL_GENERIC, exposedFunctionData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void service_exposed_generic_call(asIScriptGeneric* genericFun) {
|
||||||
|
AS_CHECK(scriptContext->PushState());
|
||||||
|
|
||||||
|
ServiceExposedFunctionData* data = (ServiceExposedFunctionData*)genericFun->GetAuxiliary();
|
||||||
|
|
||||||
|
AS_CHECK(scriptContext->Prepare(data->exposedFunction));
|
||||||
|
AS_CHECK(scriptContext->SetObject(data->exposedObject));
|
||||||
|
|
||||||
|
int argCount = genericFun->GetArgCount();
|
||||||
|
for (int i = 0; i < argCount; ++i) {
|
||||||
|
int typeId = genericFun->GetArgTypeId(i);
|
||||||
|
|
||||||
|
if (typeId & asTYPEID_OBJHANDLE) {
|
||||||
|
void* obj = genericFun->GetAddressOfArg(i);
|
||||||
|
AS_CHECK(scriptContext->SetArgAddress(i, obj));
|
||||||
|
} else if (typeId & asTYPEID_MASK_OBJECT) {
|
||||||
|
void* obj = genericFun->GetArgObject(i);
|
||||||
|
AS_CHECK(scriptContext->SetArgObject(i, obj));
|
||||||
|
} else {
|
||||||
|
switch (typeId) {
|
||||||
|
case asTYPEID_BOOL:
|
||||||
|
case asTYPEID_INT8:
|
||||||
|
case asTYPEID_UINT8:
|
||||||
|
AS_CHECK(scriptContext->SetArgByte(i, genericFun->GetArgByte(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT16:
|
||||||
|
case asTYPEID_UINT16:
|
||||||
|
AS_CHECK(scriptContext->SetArgWord(i, genericFun->GetArgWord(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT32:
|
||||||
|
case asTYPEID_UINT32:
|
||||||
|
AS_CHECK(scriptContext->SetArgDWord(i, genericFun->GetArgDWord(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT64:
|
||||||
|
case asTYPEID_UINT64:
|
||||||
|
AS_CHECK(scriptContext->SetArgQWord(i, genericFun->GetArgQWord(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_FLOAT:
|
||||||
|
AS_CHECK(scriptContext->SetArgFloat(i, genericFun->GetArgFloat(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_DOUBLE:
|
||||||
|
AS_CHECK(scriptContext->SetArgDouble(i, genericFun->GetArgDouble(i)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
AS_CHECK(scriptContext->SetArgObject(i, genericFun->GetArgObject(i)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AS_CHECK(scriptContext->Execute());
|
||||||
|
int retTypeId = genericFun->GetReturnTypeId();
|
||||||
|
|
||||||
|
if (retTypeId == asTYPEID_VOID) {
|
||||||
|
} else if (retTypeId & asTYPEID_OBJHANDLE) {
|
||||||
|
void* obj = scriptContext->GetReturnObject();
|
||||||
|
genericFun->SetReturnObject(obj);
|
||||||
|
} else if (retTypeId & asTYPEID_MASK_OBJECT) {
|
||||||
|
void* obj = scriptContext->GetReturnObject();
|
||||||
|
genericFun->SetReturnObject(obj);
|
||||||
|
} else {
|
||||||
|
switch (retTypeId) {
|
||||||
|
case asTYPEID_BOOL:
|
||||||
|
case asTYPEID_INT8:
|
||||||
|
case asTYPEID_UINT8:
|
||||||
|
genericFun->SetReturnByte(scriptContext->GetReturnByte());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT16:
|
||||||
|
case asTYPEID_UINT16:
|
||||||
|
genericFun->SetReturnWord(scriptContext->GetReturnWord());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT32:
|
||||||
|
case asTYPEID_UINT32:
|
||||||
|
genericFun->SetReturnDWord(scriptContext->GetReturnDWord());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_INT64:
|
||||||
|
case asTYPEID_UINT64:
|
||||||
|
genericFun->SetReturnQWord(scriptContext->GetReturnQWord());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_FLOAT:
|
||||||
|
genericFun->SetReturnFloat(scriptContext->GetReturnFloat());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case asTYPEID_DOUBLE:
|
||||||
|
genericFun->SetReturnDouble(scriptContext->GetReturnDouble());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// value types returned by value
|
||||||
|
genericFun->SetReturnObject(scriptContext->GetReturnObject());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AS_CHECK(scriptContext->PopState());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Service::updateTypes(asIScriptModule* module) {
|
||||||
|
type = module->GetTypeInfoByName(typeName.c_str());
|
||||||
|
|
||||||
|
updateFunction = type->GetMethodByDecl("void update()");
|
||||||
|
initFunction = type->GetMethodByDecl("void init()");
|
||||||
|
shutdownFunction = type->GetMethodByDecl("void shutdown()");
|
||||||
|
|
||||||
|
for (Scope<ServiceExposedFunctionData>& exposedFunction : exposedFunctions) {
|
||||||
|
exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str());
|
||||||
|
exposedFunction->exposedObject = object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Service::update() {
|
void Service::update() {
|
||||||
if (!updateFunction)
|
if (!updateFunction)
|
||||||
return;
|
return;
|
||||||
@ -70,6 +286,8 @@ namespace Deer {
|
|||||||
Service::Service(asITypeInfo* _type)
|
Service::Service(asITypeInfo* _type)
|
||||||
: type(_type) {
|
: type(_type) {
|
||||||
|
|
||||||
|
typeName = _type->GetName();
|
||||||
|
|
||||||
updateFunction = type->GetMethodByDecl("void update()");
|
updateFunction = type->GetMethodByDecl("void update()");
|
||||||
initFunction = type->GetMethodByDecl("void init()");
|
initFunction = type->GetMethodByDecl("void init()");
|
||||||
shutdownFunction = type->GetMethodByDecl("void shutdown()");
|
shutdownFunction = type->GetMethodByDecl("void shutdown()");
|
||||||
|
|||||||
@ -1,8 +1,21 @@
|
|||||||
Entity entity = Resource::getMainEnvironment().getRootEntity();
|
class ActiveEntity : Service {
|
||||||
Entity getActiveEntity() {
|
Entity entity;
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setActiveEntity(Entity ent) {
|
[Expose]
|
||||||
entity = ent;
|
Entity getActiveEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
[Expose]
|
||||||
|
void setActiveEntity(Entity ent) {
|
||||||
|
entity = ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
entity = Resource::getMainEnvironment().getRootEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Expose]
|
||||||
|
void wtf() {
|
||||||
|
Engine::print("Exposed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,4 +57,8 @@ class MeshComponentRender {
|
|||||||
entity.removeMeshComponent();
|
entity.removeMeshComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
ActiveEntity::wtf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
import Entity getActiveEntity() from "ActiveEntity";
|
|
||||||
import void setActiveEntity(Entity) from "ActiveEntity";
|
|
||||||
|
|
||||||
class PropertiesPanel : Panel {
|
class PropertiesPanel : Panel {
|
||||||
float slider = 0;
|
float slider = 0;
|
||||||
vec3 slid;
|
vec3 slid;
|
||||||
vec3 slid2;
|
vec3 slid2;
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
Entity entity = getActiveEntity();
|
Entity entity = ActiveEntity::getActiveEntity();
|
||||||
|
|
||||||
// NAME
|
// NAME
|
||||||
// Id:0 [+ add component]
|
// Id:0 [+ add component]
|
||||||
@ -60,7 +57,7 @@ class PropertiesPanel : Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void renameEntityMenu() {
|
void renameEntityMenu() {
|
||||||
Entity entity = getActiveEntity();
|
Entity entity = ActiveEntity::getActiveEntity();
|
||||||
|
|
||||||
if (!entity.isRoot) {
|
if (!entity.isRoot) {
|
||||||
if (UI::menuItem("Rename")) {
|
if (UI::menuItem("Rename")) {
|
||||||
|
|||||||
@ -1,19 +1,10 @@
|
|||||||
RenderService@ mainRenderService;
|
|
||||||
|
|
||||||
FrameBuffer renderMeshPreview(GPUMesh mesh) {
|
|
||||||
return mainRenderService.renderMeshPreview(mesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) {
|
|
||||||
return mainRenderService.renderMeshPreview(mesh, fase);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSceneCamera(SceneCamera sc) {
|
|
||||||
}
|
|
||||||
|
|
||||||
class RenderService : Service {
|
class RenderService : Service {
|
||||||
|
Environment env;
|
||||||
|
SceneCamera sceneCamera;
|
||||||
|
MeshComponent meshC;
|
||||||
|
Entity child;
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
@mainRenderService = this;
|
|
||||||
env = Resource::createLoadEnvironment("PreviewerEnv");
|
env = Resource::createLoadEnvironment("PreviewerEnv");
|
||||||
|
|
||||||
child = env.getRootEntity().createChild("Render");
|
child = env.getRootEntity().createChild("Render");
|
||||||
@ -27,30 +18,27 @@ class RenderService : Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Expose]
|
||||||
FrameBuffer renderMeshPreview(GPUMesh mesh) {
|
FrameBuffer renderMeshPreview(GPUMesh mesh) {
|
||||||
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
|
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
|
||||||
|
|
||||||
buffer.clearRGBA(0, 0, 0, 0);
|
buffer.clearRGBA(0, 0, 0, 0);
|
||||||
meshC.meshResource = mesh;
|
meshC.meshResource = mesh;
|
||||||
child.transform.rotation = vec3(0, 0, 0);
|
child.transform.rotation = vec3(0, 0, 0);
|
||||||
mainRenderService.env.render(buffer, mainRenderService.sceneCamera);
|
env.render(buffer, sceneCamera);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) {
|
[Expose]
|
||||||
|
FrameBuffer renderMeshPreview_fase(GPUMesh mesh, float fase) {
|
||||||
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
|
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
|
||||||
|
|
||||||
buffer.clearRGBA(0, 0, 0, 0);
|
buffer.clearRGBA(0, 0, 0, 0);
|
||||||
meshC.meshResource = mesh;
|
meshC.meshResource = mesh;
|
||||||
child.transform.rotation = vec3(0, (1-(1/(1+fase * fase)))*45, 0);
|
child.transform.rotation = vec3(0, (1-(1/(1+fase * fase)))*45, 0);
|
||||||
mainRenderService.env.render(buffer, mainRenderService.sceneCamera);
|
env.render(buffer, sceneCamera);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment env;
|
|
||||||
SceneCamera sceneCamera;
|
|
||||||
MeshComponent meshC;
|
|
||||||
Entity child;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import FrameBuffer renderMeshPreview(GPUMesh mesh) from "Previewer";
|
|
||||||
import FrameBuffer renderMeshPreview(GPUMesh mesh, float fase) from "Previewer";
|
|
||||||
string selectedResource = "";
|
string selectedResource = "";
|
||||||
|
|
||||||
class ResourceExplorer : Panel {
|
class ResourceExplorer : Panel {
|
||||||
@ -62,7 +60,7 @@ class ResourceExplorer : Panel {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
GPUMesh mesh = Resource::loadGPUMesh(filename);
|
GPUMesh mesh = Resource::loadGPUMesh(filename);
|
||||||
frameBuffer = renderMeshPreview(mesh, fase);
|
frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase);
|
||||||
meshFrameBuffer[filename] = frameBuffer;
|
meshFrameBuffer[filename] = frameBuffer;
|
||||||
alreadyRendered = true;
|
alreadyRendered = true;
|
||||||
|
|
||||||
|
|||||||
8
Editor/Modules/Test/ActiveEntity.as
Normal file
8
Editor/Modules/Test/ActiveEntity.as
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Test : Service {
|
||||||
|
void init() {
|
||||||
|
Engine::print("Initing");
|
||||||
|
Entity entity = ActiveEntity::getActiveEntity();
|
||||||
|
Engine::print(entity.name);
|
||||||
|
Engine::print("Ending");
|
||||||
|
}
|
||||||
|
}
|
||||||
5
Editor/Modules/Test/module.json
Normal file
5
Editor/Modules/Test/module.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"patch": 1,
|
||||||
|
"name": "Test",
|
||||||
|
"requires": ["ActiveEntity"]
|
||||||
|
}
|
||||||
@ -1,6 +1,3 @@
|
|||||||
import Entity getActiveEntity() from "ActiveEntity";
|
|
||||||
import void setActiveEntity(Entity) from "ActiveEntity";
|
|
||||||
|
|
||||||
class EntityTreeRender {
|
class EntityTreeRender {
|
||||||
EntityTreeRender(Entity _entity) {
|
EntityTreeRender(Entity _entity) {
|
||||||
entity = _entity;
|
entity = _entity;
|
||||||
@ -8,7 +5,7 @@ class EntityTreeRender {
|
|||||||
|
|
||||||
Entity entity;
|
Entity entity;
|
||||||
bool isActiveEntity() {
|
bool isActiveEntity() {
|
||||||
return entity == getActiveEntity();
|
return entity == ActiveEntity::getActiveEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderEntity() {
|
void renderEntity() {
|
||||||
@ -47,7 +44,7 @@ class EntityTreeRender {
|
|||||||
UI::contextItemPopup("POP_ENTITY_" + entity.id, Callback(this.renderContextMenu));
|
UI::contextItemPopup("POP_ENTITY_" + entity.id, Callback(this.renderContextMenu));
|
||||||
|
|
||||||
if (UI::isItemClicked(0)) {
|
if (UI::isItemClicked(0)) {
|
||||||
setActiveEntity(entity);
|
ActiveEntity::setActiveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import void setSceneCamera (SceneCamera sc) from "Previewer";
|
|
||||||
|
|
||||||
class ViewportPanel : Panel {
|
class ViewportPanel : Panel {
|
||||||
FrameBuffer frameBuffer;
|
FrameBuffer frameBuffer;
|
||||||
SceneCamera sceneCamera;
|
SceneCamera sceneCamera;
|
||||||
@ -68,7 +66,6 @@ class ViewportPanel : Panel {
|
|||||||
vertically--;
|
vertically--;
|
||||||
|
|
||||||
sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0);
|
sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0);
|
||||||
setSceneCamera(sceneCamera);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user