[Scummvm-git-logs] scummvm master -> 67013713a79c359bddc49f482cc1a7b451c4f465

scemino noreply at scummvm.org
Fri May 31 07:18:39 UTC 2024


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5f03ea2b13 DIRECTOR: Remove unuseful code in function list
67013713a7 DIRECTOR: Add lingo stepping


Commit: 5f03ea2b133997bdf4907f96313d6271a0089013
    https://github.com/scummvm/scummvm/commit/5f03ea2b133997bdf4907f96313d6271a0089013
Author: scemino (scemino74 at gmail.com)
Date: 2024-05-31T09:12:47+02:00

Commit Message:
DIRECTOR: Remove unuseful code in function list

Changed paths:
    engines/director/debugtools.cpp


diff --git a/engines/director/debugtools.cpp b/engines/director/debugtools.cpp
index e37bfa62994..f1c63253ba1 100644
--- a/engines/director/debugtools.cpp
+++ b/engines/director/debugtools.cpp
@@ -2687,10 +2687,6 @@ static void showFuncList() {
 	ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
 	ImGui::SetNextWindowSize(ImVec2(480, 240), ImGuiCond_FirstUseEver);
 	if (ImGui::Begin("Functions", &_state->_w.funcList)) {
-		Lingo *lingo = g_director->getLingo();
-		Movie *movie = g_director->getCurrentMovie();
-		ScriptContext *csc = lingo->_state->context;
-
 		_state->_functions._nameFilter.Draw();
 		ImGui::Separator();
 		const ImVec2 childSize = ImGui::GetContentRegionAvail();
@@ -2703,27 +2699,7 @@ static void showFuncList() {
 			ImGui::TableSetupColumn("Type", 0, 80.f);
 			ImGui::TableHeadersRow();
 
-			if (csc) {
-				Common::String scriptType(scriptType2str(csc->_scriptType));
-				for (auto &functionHandler : csc->_functionHandlers) {
-					Common::String function(g_lingo->formatFunctionName(functionHandler._value));
-					if (!_state->_functions._nameFilter.PassFilter(function.c_str()))
-						continue;
-
-					ImGui::TableNextRow();
-					ImGui::TableNextColumn();
-					if (ImGui::Selectable(function.c_str())) {
-						// TODO:
-					}
-					ImGui::TableNextColumn();
-					ImGui::Text("%s", movie->getArchive()->getPathName().toString().c_str());
-					ImGui::TableNextColumn();
-					ImGui::Text("-");
-					ImGui::TableNextColumn();
-					ImGui::Text("%s", scriptType.c_str());
-				}
-			}
-
+			Movie *movie = g_director->getCurrentMovie();
 			for (auto &cast : *movie->getCasts()) {
 				for (int i = 0; i <= kMaxScriptType; i++) {
 					if (cast._value->_lingoArchive->scriptContexts[i].empty())


Commit: 67013713a79c359bddc49f482cc1a7b451c4f465
    https://github.com/scummvm/scummvm/commit/67013713a79c359bddc49f482cc1a7b451c4f465
Author: scemino (scemino74 at gmail.com)
Date: 2024-05-31T09:12:47+02:00

Commit Message:
DIRECTOR: Add lingo stepping

Changed paths:
    engines/director/debugtools.cpp
    engines/director/lingo/lingo.cpp
    engines/director/lingo/lingo.h


diff --git a/engines/director/debugtools.cpp b/engines/director/debugtools.cpp
index f1c63253ba1..010cb891697 100644
--- a/engines/director/debugtools.cpp
+++ b/engines/director/debugtools.cpp
@@ -89,6 +89,8 @@ typedef struct ImGuiScript {
 	Common::StringArray globalNames;
 	Common::SharedPtr<LingoDec::HandlerNode> root;
 	Common::Array<LingoDec::Bytecode> bytecodeArray;
+	Common::Array<uint> startOffsets;
+
 
 	bool operator==(const ImGuiScript &c) const {
 		return moviePath == c.moviePath && score == c.score && id == c.id && handlerId == c.handlerId;
@@ -374,6 +376,10 @@ typedef struct ImGuiState {
 		bool _showByteCode = false;
 		bool _showScript = false;
 	} _functions;
+	struct {
+		uint _lastLinePC = 0;
+		uint _callstackSize = 0;
+	} _dbg;
 
 	struct {
 		ImVec4 _bp_color_disabled = ImVec4(0.9f, 0.08f, 0.0f, 0.0f);
@@ -504,6 +510,7 @@ public:
 			CFrame *head = callstack[callstack.size() - 1];
 			_isScriptInDebug = (head->sp.ctx->_id == script.id.member) && (*head->sp.name == script.handlerId);
 		}
+		_script.startOffsets.clear();
 	}
 
 	virtual void visit(const LingoDec::HandlerNode &node) override {
@@ -1565,6 +1572,7 @@ private:
 		bool showCurrentStatement = false;
 		p = MIN(p, _script.byteOffsets.size() - 1);
 		uint pc = _script.byteOffsets[p];
+		_script.startOffsets.push_back(pc);
 
 		if (_isScriptInDebug && g_lingo->_exec._state == kPause) {
 			// check current statement
@@ -1667,6 +1675,58 @@ private:
 	bool _isScriptInDebug = false;
 };
 
+static uint32 getLineFromPC() {
+	const uint pc = g_lingo->_state->pc;
+	const Common::Array<uint> &offsets = _state->_functions._scripts[_state->_functions._current].startOffsets;
+	for (uint i = 0; i < offsets.size(); i++) {
+		if (pc <= offsets[i])
+			return i;
+	}
+	return 0;
+}
+
+static bool stepOverShouldPauseDebugger() {
+	const uint32 line = getLineFromPC();
+
+	// we stop when we are :
+	// - in the same callstack level and the statement line is different
+	// - OR we go up in the callstack
+	if (((g_lingo->_state->callstack.size() == _state->_dbg._callstackSize) && (line != _state->_dbg._lastLinePC)) ||
+		 (g_lingo->_state->callstack.size() < _state->_dbg._callstackSize)) {
+		_state->_dbg._lastLinePC = line;
+		return true;
+	}
+
+	return false;
+}
+
+static bool stepInShouldPauseDebugger() {
+	const uint32 line = getLineFromPC();
+
+	// we stop when:
+	// - the statement line is different
+	// - OR when the callstack level change
+	if ((g_lingo->_state->callstack.size() != _state->_dbg._callstackSize) || (_state->_dbg._lastLinePC != line)) {
+		_state->_dbg._lastLinePC = line;
+		return true;
+	}
+	return false;
+}
+
+static bool stepOutShouldPause() {
+	const uint32 line = getLineFromPC();
+
+	// we stop when:
+	// - the statement line is different
+	// - OR we go up in the callstack
+	if (g_lingo->_state->callstack.size() < _state->_dbg._callstackSize) {
+		_state->_dbg._lastLinePC = line;
+		return true;
+	}
+
+	return false;
+}
+
 static void showControlPanel() {
 	if (!_state->_w.controlPanel)
 		return;
@@ -1741,6 +1801,7 @@ static void showControlPanel() {
 			if (ImGui::IsItemClicked(0)) {
 				score->_playState = kPlayPaused;
 				g_lingo->_exec._state = kPause;
+				g_lingo->_exec._shouldPause = nullptr;
 			}
 
 			if (ImGui::IsItemHovered())
@@ -1780,8 +1841,8 @@ static void showControlPanel() {
 
 			if (ImGui::IsItemClicked(0)) {
 				score->_playState = kPlayStarted;
-				g_lingo->_exec._step = -1;
 				g_lingo->_exec._state = kRunning;
+				g_lingo->_exec._shouldPause = nullptr;
 			}
 
 			if (ImGui::IsItemHovered())
@@ -1818,9 +1879,9 @@ static void showControlPanel() {
 			if (ImGui::IsItemClicked(0)) {
 				score->_playState = kPlayStarted;
 				g_lingo->_exec._state = kRunning;
-				g_lingo->_exec._step = -1;
-				g_lingo->_exec._next._enabled = true;
-				g_lingo->_exec._next._stackSize = g_lingo->_state->callstack.size();
+				_state->_dbg._lastLinePC = getLineFromPC();
+				_state->_dbg._callstackSize = g_lingo->_state->callstack.size();
+				g_lingo->_exec._shouldPause = stepOverShouldPauseDebugger;
 			}
 
 			if (ImGui::IsItemHovered())
@@ -1842,8 +1903,10 @@ static void showControlPanel() {
 
 			if (ImGui::IsItemClicked(0)) {
 				score->_playState = kPlayStarted;
-				g_lingo->_exec._step = 1;
 				g_lingo->_exec._state = kRunning;
+				_state->_dbg._lastLinePC = getLineFromPC();
+				_state->_dbg._callstackSize = g_lingo->_state->callstack.size();
+				g_lingo->_exec._shouldPause = stepInShouldPauseDebugger;
 			}
 
 			if (ImGui::IsItemHovered())
@@ -1865,9 +1928,9 @@ static void showControlPanel() {
 			if (ImGui::IsItemClicked(0)) {
 				score->_playState = kPlayStarted;
 				g_lingo->_exec._state = kRunning;
-				g_lingo->_exec._step = -1;
-				g_lingo->_exec._next._enabled = true;
-				g_lingo->_exec._next._stackSize = g_lingo->_state->callstack.size() - 1;
+				_state->_dbg._lastLinePC = getLineFromPC();
+				_state->_dbg._callstackSize = g_lingo->_state->callstack.size();
+				g_lingo->_exec._shouldPause = stepOutShouldPause;
 			}
 
 			if (ImGui::IsItemHovered())
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index 0ba30669b72..b8ba3456b85 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -617,12 +617,7 @@ bool Lingo::execute() {
 	uint localCounter = 0;
 
 	while (!_abort && !_freezeState && _state->script && (*_state->script)[_state->pc] != STOP) {
-		if (_exec._next._enabled && _state->callstack.size() == _exec._next._stackSize) {
-			// we reach the next statement -> pause the execution
-			_exec._state = kPause;
-			_exec._next._enabled = false;
-		}
-		if (!_exec._step || _exec._state == kPause) {
+		if ((_exec._state == kPause) || (_exec._shouldPause && _exec._shouldPause())) {
 			// if execution is in pause -> poll event + update screen
 			_exec._state = kPause;
 			Common::EventManager *eventMan = g_system->getEventManager();
@@ -674,8 +669,6 @@ bool Lingo::execute() {
 		}
 
 		g_debugger->stepHook();
-		if (_exec._step > 0)
-			_exec._step--;
 
 		_state->pc++;
 		(*((*_state->script)[_state->pc - 1]))();
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index 663e498c8fb..4f787f97041 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -558,11 +558,7 @@ public:
 
 	struct {
 		LingoExecState _state = kRunning;
-		int _step = -1;
-		struct {
-			uint _stackSize = 0;
-			bool _enabled = false;
-		} _next;
+		bool (*_shouldPause)() = nullptr;
 	} _exec;
 
 public:




More information about the Scummvm-git-logs mailing list