Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 529e51009c | |||
| 2e958fa1ec |
Vendored
+2
-1
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.h": "c",
|
||||
"xstring": "cpp"
|
||||
"xstring": "cpp",
|
||||
"iostream": "cpp"
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -25,8 +25,18 @@ target_include_directories(scriptstdstring
|
||||
PUBLIC external/angelscript/sdk/angelscript/include
|
||||
)
|
||||
|
||||
# ------------------------
|
||||
# debugger add-on
|
||||
# ------------------------
|
||||
add_library(debugger STATIC
|
||||
external/angelscript/sdk/add_on/debugger/debugger.cpp
|
||||
)
|
||||
|
||||
target_include_directories(debugger PUBLIC
|
||||
external/angelscript/sdk/angelscript/include
|
||||
)
|
||||
# -------------------------
|
||||
# 3️⃣.1️⃣ scriptbuilder add-on
|
||||
# scriptbuilder add-on
|
||||
# -------------------------
|
||||
add_library(scriptbuilder STATIC
|
||||
external/angelscript/sdk/add_on/scriptbuilder/scriptbuilder.cpp
|
||||
@@ -37,7 +47,7 @@ target_include_directories(scriptbuilder
|
||||
)
|
||||
|
||||
# -------------------------
|
||||
# 4️⃣ Main executable
|
||||
# Main executable
|
||||
# -------------------------
|
||||
add_executable(simian
|
||||
main.cpp
|
||||
@@ -55,6 +65,7 @@ target_include_directories(simian PUBLIC
|
||||
external/angelscript/sdk/angelscript/include
|
||||
external/angelscript/sdk/add_on/scriptstdstring
|
||||
external/angelscript/sdk/add_on/scriptbuilder
|
||||
external/angelscript/sdk/add_on/debugger
|
||||
)
|
||||
|
||||
target_link_libraries(simian
|
||||
@@ -62,6 +73,7 @@ target_link_libraries(simian
|
||||
angelscript
|
||||
scriptstdstring
|
||||
scriptbuilder
|
||||
debugger
|
||||
)
|
||||
|
||||
# -------------------------
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "angelscript.h"
|
||||
#include "scriptbuilder.h"
|
||||
#include <string>
|
||||
#include "debugger.h"
|
||||
|
||||
class ScriptEngine {
|
||||
public:
|
||||
@@ -17,6 +18,8 @@ public:
|
||||
asIScriptEngine* GetEngine() const { return engine; }
|
||||
asIScriptFunction* GetUpdateFunction() const { return updateFunc; }
|
||||
asIScriptFunction* GetDrawFunction() const { return drawFunc; }
|
||||
void AddFileBreakPoint(const std::string& file, int line);
|
||||
void AddFuncBreakPoint(const std::string& func);
|
||||
|
||||
private:
|
||||
asIScriptEngine* engine;
|
||||
@@ -24,6 +27,7 @@ private:
|
||||
asIScriptFunction* drawFunc;
|
||||
asIScriptModule* currentModule;
|
||||
bool hasValidScript;
|
||||
CDebugger* debugger = nullptr;
|
||||
|
||||
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
||||
static int IncludeCallback(const char* include, const char* from, CScriptBuilder* builder, void* userParam);
|
||||
|
||||
@@ -22,6 +22,9 @@ bool ScriptEngine::Initialize() {
|
||||
return false;
|
||||
}
|
||||
|
||||
debugger = new CDebugger();
|
||||
debugger->SetEngine(engine);
|
||||
|
||||
// Register std::string
|
||||
RegisterStdString(engine);
|
||||
|
||||
@@ -40,6 +43,11 @@ bool ScriptEngine::Initialize() {
|
||||
|
||||
void ScriptEngine::Shutdown() {
|
||||
ClearCachedFunctions();
|
||||
if (debugger) {
|
||||
debugger->SetEngine(nullptr);
|
||||
delete debugger;
|
||||
debugger = nullptr;
|
||||
}
|
||||
if (engine) {
|
||||
engine->ShutDownAndRelease();
|
||||
engine = nullptr;
|
||||
@@ -110,6 +118,11 @@ bool ScriptEngine::CompileScript(const std::string& filename) {
|
||||
updateFunc = currentModule->GetFunctionByName("Update");
|
||||
drawFunc = currentModule->GetFunctionByName("Draw");
|
||||
hasValidScript = true;
|
||||
// If debugger is present, add a function breakpoint on Update to stop when Update is entered
|
||||
// The debugger will transform function breakpoints into file breakpoints when the function is entered
|
||||
if (debugger && updateFunc) {
|
||||
debugger->AddFuncBreakPoint("Update");
|
||||
}
|
||||
log_info("Script compiled and cached: %s", filename.c_str());
|
||||
return true;
|
||||
}
|
||||
@@ -120,6 +133,10 @@ void ScriptEngine::CallScriptFunction(asIScriptFunction* func, float dt) {
|
||||
asIScriptContext* ctx = engine->CreateContext();
|
||||
if (!ctx) return;
|
||||
|
||||
if (debugger) {
|
||||
ctx->SetLineCallback(asMETHOD(CDebugger, LineCallback), debugger, asCALL_THISCALL);
|
||||
}
|
||||
|
||||
int r = ctx->Prepare(func);
|
||||
if (r < 0) {
|
||||
ctx->Release();
|
||||
@@ -152,6 +169,13 @@ void ScriptEngine::GarbageCollect() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptEngine::AddFileBreakPoint(const std::string &file, int line) {
|
||||
if (debugger) debugger->AddFileBreakPoint(file, line);
|
||||
}
|
||||
void ScriptEngine::AddFuncBreakPoint(const std::string &func) {
|
||||
if (debugger) debugger->AddFuncBreakPoint(func);
|
||||
}
|
||||
void ScriptEngine::MessageCallback(const asSMessageInfo* msg, void*) {
|
||||
// Map AngelScript message types to log levels
|
||||
if (msg->type == asMSGTYPE_ERROR) {
|
||||
|
||||
Reference in New Issue
Block a user