修改底层渲染为OpenGL
This commit is contained in:
@@ -78,7 +78,9 @@ bool SquirrelEx::Compilebuffer(std::string Path, std::string Code)
|
||||
|
||||
void SquirrelEx::Init()
|
||||
{
|
||||
v = sq_open(1024); // 栈大小1024
|
||||
// 初始化虚拟机
|
||||
if (v == nullptr)
|
||||
v = sq_open(1024); // 栈大小1024
|
||||
sqstd_seterrorhandlers(v);
|
||||
sq_pushroottable(v);
|
||||
sqstd_register_bloblib(v);
|
||||
@@ -89,6 +91,20 @@ void SquirrelEx::Init()
|
||||
|
||||
sq_setprintfunc(v, printfunc, errorfunc);
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#else
|
||||
// 获取工作目录 (switch 不允许)
|
||||
WorkPath = SDL_GetBasePath();
|
||||
FILE *file1 = fopen("DevMode.ini", "rb");
|
||||
if (file1)
|
||||
{
|
||||
sq_enabledebuginfo(v, true);
|
||||
|
||||
dbg = sqdbg_attach_debugger(v);
|
||||
sqdbg_listen_socket(dbg, 2222);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 加载脚本
|
||||
LoadLocalScript();
|
||||
}
|
||||
@@ -151,6 +167,14 @@ void SquirrelEx::LoadLocalScript()
|
||||
continue;
|
||||
|
||||
std::string RegistPath = "sqr/" + clean_line;
|
||||
|
||||
#ifndef __SWITCH__
|
||||
std::replace(RegistPath.begin(), RegistPath.end(), '/', '\\');
|
||||
RegistPath = WorkPath + RegistPath;
|
||||
|
||||
_scriptmap[RegistPath] = Tool_get_file_size(RegistPath);
|
||||
#endif
|
||||
|
||||
if (!SQ_SUCCEEDED(sqstd_dofile(v, (SQChar *)(RegistPath.c_str()), SQFalse, SQTrue)))
|
||||
{
|
||||
SDL_LogError(0, "脚本文件未找到,请检查项目目录 %s 文件是否存在", RegistPath.c_str());
|
||||
@@ -198,6 +222,37 @@ void SquirrelEx::Run()
|
||||
sq_settop(v, top); // restores the original stack size
|
||||
}
|
||||
|
||||
void SquirrelEx::Update(float Dt)
|
||||
{
|
||||
#ifdef __SWITCH__
|
||||
#else
|
||||
sqdbg_frame(dbg);
|
||||
|
||||
// 热重载
|
||||
if (HotReload)
|
||||
{
|
||||
for (auto &script : _scriptmap)
|
||||
{
|
||||
std::string path = script.first;
|
||||
int value = script.second;
|
||||
int newvalue = Tool_get_file_size(path);
|
||||
if (value != newvalue)
|
||||
{
|
||||
if (SQ_SUCCEEDED(sqstd_dofile(v, (SQChar *)(path.c_str()), SQFalse, SQTrue)))
|
||||
{
|
||||
SDL_Log("脚本文件热重载成功 %s", path.c_str());
|
||||
_scriptmap[path] = newvalue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Log("脚本文件热重载失败 %s", path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SquirrelEx::Clean()
|
||||
{
|
||||
sq_close(v);
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
|
||||
#include "Tool/Tool_Network.h"
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#else
|
||||
#include "sqdbg.h"
|
||||
#endif
|
||||
|
||||
#ifdef SQUNICODE
|
||||
|
||||
#define scvprintf vfwprintf
|
||||
@@ -50,6 +55,7 @@ public:
|
||||
void LoadLocalScript();
|
||||
// 运行
|
||||
void Run();
|
||||
void Update(float Dt);
|
||||
// 清理
|
||||
void Clean();
|
||||
|
||||
@@ -60,5 +66,16 @@ private:
|
||||
SquirrelEx(/* args */);
|
||||
~SquirrelEx();
|
||||
HSQUIRRELVM v = nullptr;
|
||||
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#else
|
||||
// 虚拟机调试对象
|
||||
HSQDEBUGSERVER dbg;
|
||||
#endif
|
||||
|
||||
//工作目录
|
||||
std::string WorkPath;
|
||||
//热重载
|
||||
bool HotReload = true;
|
||||
std::map<std::string, int> _scriptmap;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user