[Scummvm-git-logs] scummvm master -> 738def31a099b3b9d1da89acb63f5684f5b270c6
rvanlaar
noreply at scummvm.org
Tue Mar 22 22:40:04 UTC 2022
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:
40627f0caf GUI: Debugger: Implement defaultCommandProcessor
738def31a0 DIRECTOR: Implement lingo repl in debugger
Commit: 40627f0cafa8474a2a34fa94caf101ab84bcddaf
https://github.com/scummvm/scummvm/commit/40627f0cafa8474a2a34fa94caf101ab84bcddaf
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2022-03-22T23:39:54+01:00
Commit Message:
GUI: Debugger: Implement defaultCommandProcessor
A defaultCommandProcessor let's an engine take over the processing of
commands in the debugger. The Director Engine uses the functionality to
implement a repl for the Lingo language.
Example Usage:
registerDefaultCmd(WRAP_DEFAULTCOMMAND(Debugger, lingoCommandProcessor));
The input will now be handled by lingoCommandProcessor. Other commands
will not work untill control is given back to the debugger.
It's up to the engine to return control to the debugger when done.
To return control, call it with a nullptr:
registerDefaultCmd(nullptr);
Changed paths:
gui/debugger.cpp
gui/debugger.h
diff --git a/gui/debugger.cpp b/gui/debugger.cpp
index ed87caeb382..166d529b647 100644
--- a/gui/debugger.cpp
+++ b/gui/debugger.cpp
@@ -52,6 +52,7 @@ Debugger::Debugger() {
_frameCountdown = 0;
_isActive = false;
_firstTime = true;
+ _defaultCommandProcessor = nullptr;
#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
_debuggerDialog = new GUI::ConsoleDialog(1.0f, 0.67f);
_debuggerDialog->setInputCallback(debuggerInputCallback, this);
@@ -295,6 +296,9 @@ bool Debugger::parseCommand(const char *inputOrig) {
int num_params = 0;
const char *param[256];
+ if (_defaultCommandProcessor)
+ return (*_defaultCommandProcessor)(inputOrig);
+
// Parse out any params
Common::String input(inputOrig);
splitCommand(input, num_params, ¶m[0]);
diff --git a/gui/debugger.h b/gui/debugger.h
index 49758703b45..31200bcd08f 100644
--- a/gui/debugger.h
+++ b/gui/debugger.h
@@ -75,6 +75,7 @@ public:
bool isActive() const { return _isActive; }
protected:
+ typedef Common::Functor1<const char *, bool> defaultCommand;
typedef Common::Functor2<int, const char **, bool> Debuglet;
/**
@@ -88,6 +89,14 @@ protected:
#define WRAP_METHOD(cls, method) \
new Common::Functor2Mem<int, const char **, bool, cls>(this, &cls::method)
+ /**
+ * Convenience macro that makes it easier to register a defaultCommandProcessor
+ * Usage example:
+ * registerDefaultCmd(WRAP_DEFAULTCOMMAND(MyDebugger, myCmd));
+ */
+ #define WRAP_DEFAULTCOMMAND(cls, command) \
+ new Common::Functor1Mem<const char *, bool, cls>(this, &cls::command)
+
enum VarType {
DVAR_BYTE,
DVAR_INT,
@@ -142,6 +151,18 @@ protected:
void registerCmd(const Common::String &cmdname, Debuglet *debuglet);
+ /**
+ * Register a default command processor with the debugger. This
+ * allows an engine to receive all user input in the debugger.
+ *
+ * A defaultCommandProcessor has the following signature:
+ * bool func(const char **inputOrig)
+ *
+ * To deactivate call with a nullptr.
+ */
+ void registerDefaultCmd(defaultCommand *defaultCommandProcessor) {
+ _defaultCommandProcessor = defaultCommandProcessor; }
+
/**
* Remove all vars except default "debug_countdown"
*/
@@ -182,6 +203,11 @@ private:
*/
bool _firstTime;
+ /**
+ * A nullptr till set by via registerDefaultCommand.
+ */
+ defaultCommand *_defaultCommandProcessor;
+
protected:
PauseToken _debugPauseToken;
Commit: 738def31a099b3b9d1da89acb63f5684f5b270c6
https://github.com/scummvm/scummvm/commit/738def31a099b3b9d1da89acb63f5684f5b270c6
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2022-03-22T23:39:54+01:00
Commit Message:
DIRECTOR: Implement lingo repl in debugger
When in debug mode enter: lingo on
The prompt will start with lingo) to indicate the repl is active.
To stop enter: lingo off
This will allow developers to interactively inspect the current state of
the program.
Only statements that fit on one line are supported.
Changed paths:
A engines/director/debugger.cpp
A engines/director/debugger.h
engines/director/director.cpp
engines/director/director.h
engines/director/lingo/lingo-builtins.cpp
engines/director/module.mk
diff --git a/engines/director/debugger.cpp b/engines/director/debugger.cpp
new file mode 100644
index 00000000000..b5db569f439
--- /dev/null
+++ b/engines/director/debugger.cpp
@@ -0,0 +1,64 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "director/director.h"
+#include "director/lingo/lingo.h"
+#include "director/lingo/lingo-code.h"
+#include "director/lingo/lingo-object.h"
+#include "director/lingo/lingo-codegen.h"
+#include "director/debugger.h"
+
+namespace Director {
+
+#define PROMPT "lingo"
+
+Debugger *g_debugger;
+
+Debugger::Debugger(): GUI::Debugger() {
+ g_debugger = this;
+ registerCmd("lingo", WRAP_METHOD(Debugger, cmd_lingo));
+}
+
+bool Debugger::cmd_lingo(int argc, const char **argv) {
+ if (argc == 2 && !strcmp(argv[1], "on")) {
+ registerDefaultCmd(WRAP_DEFAULTCOMMAND(Debugger, lingoCommandProcessor));
+ debugPrintf(PROMPT);
+ }
+ return true;
+}
+
+bool Debugger::lingoCommandProcessor(const char *inputOrig) {
+ if (!strcmp(inputOrig, "lingo off")) {
+ registerDefaultCmd(nullptr);
+ return true;
+ }
+
+ Common::String expr = Common::String(inputOrig);
+ // Compile the code to an anonymous function and call it
+ ScriptContext *sc = g_lingo->_compiler->compileAnonymous(expr);
+ Symbol sym = sc->_eventHandlers[kEventGeneric];
+ LC::call(sym, 0, false);
+ g_lingo->execute();
+ debugPrintf(PROMPT);
+ return true;
+}
+
+} // Enf of namespace Director
\ No newline at end of file
diff --git a/engines/director/debugger.h b/engines/director/debugger.h
new file mode 100644
index 00000000000..629e5534fe9
--- /dev/null
+++ b/engines/director/debugger.h
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef DIRECTOR_DEBUGGER_H
+#define DIRECTOR_DEBUGGER_H
+
+#include "gui/debugger.h"
+#include "director/director.h"
+
+namespace Director {
+
+class Debugger : public GUI::Debugger {
+public:
+ Debugger();
+
+private:
+ bool cmd_lingo(int argc, const char **argv);
+
+ bool lingoCommandProcessor(const char *inputOrig);
+};
+
+
+} // End of namespace Director
+
+#endif
\ No newline at end of file
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index d7b80731ecc..da9a9691cdb 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -29,6 +29,7 @@
#include "graphics/wincursor.h"
#include "director/director.h"
+#include "director/debugger.h"
#include "director/archive.h"
#include "director/cast.h"
#include "director/movie.h"
@@ -57,7 +58,9 @@ DirectorEngine *g_director;
DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
g_director = this;
-
+ g_debugger = new Debugger();
+ setDebugger(g_debugger);
+
_dirSeparator = ':';
parseOptions();
diff --git a/engines/director/director.h b/engines/director/director.h
index e27ebf9025e..333f562680f 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -35,6 +35,7 @@
#include "director/types.h"
#include "director/util.h"
+#include "director/debugger.h"
#include "director/detection.h"
namespace Common {
@@ -297,6 +298,7 @@ private:
};
extern DirectorEngine *g_director;
+extern Debugger *g_debugger;
extern uint32 wmMode;
} // End of namespace Director
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index e27ba8dd59b..5892e6226fb 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1673,7 +1673,11 @@ void LB::b_put(int nargs) {
if (i > 0)
output += " ";
}
- debug("-- %s", output.c_str());
+ if (g_debugger->isActive()) {
+ g_debugger->debugPrintf("-- %s\n", output.c_str());
+ } else {
+ debug("-- %s", output.c_str());
+ }
g_lingo->dropStack(nargs);
}
diff --git a/engines/director/module.mk b/engines/director/module.mk
index b4eb6a8d0eb..c3bd4c28600 100644
--- a/engines/director/module.mk
+++ b/engines/director/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS = \
channel.o \
cursor.o \
director.o \
+ debugger.o \
events.o \
fonts.o \
frame.o \
More information about the Scummvm-git-logs
mailing list