ULTIMA8: Fix compilation of DEBUG code

This commit is contained in:
Paul Gilbert 2020-02-22 11:15:22 -08:00
parent 67a5d0d7e3
commit 844a26e34b
9 changed files with 79 additions and 58 deletions

View File

@ -113,6 +113,9 @@ inline void u6debug(bool no_header, const DebugLevelType level, const char *form
extern void u6debug(bool no_header, const DebugLevelType level, const char *format, ...); extern void u6debug(bool no_header, const DebugLevelType level, const char *format, ...);
#endif #endif
#ifdef DEBUG
#undef DEBUG
#endif
#define DEBUG u6debug #define DEBUG u6debug
#define U6PATH_DELIMITER '/' #define U6PATH_DELIMITER '/'

View File

@ -107,7 +107,7 @@ template<class T>
class set { class set {
struct Comparitor { struct Comparitor {
bool operator()(const T &a, const T &b) const { bool operator()(const T &a, const T &b) const {
return a.Compare(b); return a == b;
} }
}; };
@ -129,6 +129,13 @@ public:
iterator begin() { return _items.begin(); } iterator begin() { return _items.begin(); }
iterator end() { return _items.end(); } iterator end() { return _items.end(); }
/**
* Clear the set
*/
void clear() {
_items.clear();
}
/** /**
* Inserts a new item * Inserts a new item
*/ */
@ -152,6 +159,15 @@ public:
void swap(set<T> &arr) { void swap(set<T> &arr) {
_items.swap(arr); _items.swap(arr);
} }
/**
* Find an item
*/
iterator find(T item) {
iterator it = begin();
for (; it != end() && *it != item; ++it) {}
return it;
}
}; };
template<class Key, class Val, class HashFunc = Common::Hash<Key>, template<class Key, class Val, class HashFunc = Common::Hash<Key>,

View File

@ -48,6 +48,7 @@
#include "ultima/ultima8/world/item_factory.h" #include "ultima/ultima8/world/item_factory.h"
#include "ultima/ultima8/world/actors/quick_avatar_mover_process.h" #include "ultima/ultima8/world/actors/quick_avatar_mover_process.h"
#include "ultima/ultima8/world/actors/main_actor.h" #include "ultima/ultima8/world/actors/main_actor.h"
#include "ultima/ultima8/world/actors/pathfinder.h"
namespace Ultima { namespace Ultima {
namespace Ultima8 { namespace Ultima8 {
@ -153,7 +154,7 @@ Debugger::Debugger() : Shared::Debugger() {
registerCmd("ShapeViewerGump::U8ShapeViewer", WRAP_METHOD(Debugger, cmdU8ShapeViewer)); registerCmd("ShapeViewerGump::U8ShapeViewer", WRAP_METHOD(Debugger, cmdU8ShapeViewer));
#ifdef DEBUG #ifdef DEBUG
registerCmd("Pathfinder::visualDebug", Pathfinder::cmdVisualDebugPathfinder); registerCmd("Pathfinder::visualDebug", WRAP_METHOD(Debugger, cmdVisualDebugPathfinder));
#endif #endif
} }
@ -1145,7 +1146,7 @@ bool Debugger::cmdMemInfo(int argc, const char **argv) {
} }
#ifdef DEBUG #ifdef DEBUG
bool Debugger::cmdTest(int argc, const char **argv) { bool Debugger::cmdTestMemory(int argc, const char **argv) {
return true; return true;
} }
#endif #endif
@ -1331,11 +1332,11 @@ bool Debugger::cmdTracePID(int argc, const char **argv) {
return true; return true;
} }
uint16 _pid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0)); uint16 pid = static_cast<uint16>(strtol(argv[1], 0, 0));
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true; uc->_tracingEnabled = true;
uc->trace_PIDs.insert(_pid); uc->_tracePIDs.insert(pid);
debugPrintf("UCMachine: tracing process %d\n", pid); debugPrintf("UCMachine: tracing process %d\n", pid);
return true; return true;
@ -1347,11 +1348,11 @@ bool Debugger::cmdTraceObjID(int argc, const char **argv) {
return true; return true;
} }
uint16 objid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0)); uint16 objid = static_cast<uint16>(strtol(argv[1], 0, 0));
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true; uc->_tracingEnabled = true;
uc->trace_ObjIDs.insert(objid); uc->_traceObjIDs.insert(objid);
debugPrintf("UCMachine: tracing object %d\n", objid); debugPrintf("UCMachine: tracing object %d\n", objid);
return true; return true;
@ -1363,11 +1364,11 @@ bool Debugger::cmdTraceClass(int argc, const char **argv) {
return true; return true;
} }
uint16 ucclass = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0)); uint16 ucclass = static_cast<uint16>(strtol(argv[1], 0, 0));
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true; uc->_tracingEnabled = true;
uc->trace_classes.insert(ucclass); uc->_traceClasses.insert(ucclass);
debugPrintf("UCMachine: tracing class %d\n", ucclass); debugPrintf("UCMachine: tracing class %d\n", ucclass);
return true; return true;
@ -1375,8 +1376,8 @@ bool Debugger::cmdTraceClass(int argc, const char **argv) {
bool Debugger::cmdTraceAll(int argc, const char **argv) { bool Debugger::cmdTraceAll(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true; uc->_tracingEnabled = true;
uc->trace_all = true; uc->_traceAll = true;
debugPrintf("UCMachine: tracing all usecode\n"); debugPrintf("UCMachine: tracing all usecode\n");
return true; return true;
@ -1384,21 +1385,21 @@ bool Debugger::cmdTraceAll(int argc, const char **argv) {
bool Debugger::cmdTraceEvents(int argc, const char **argv) { bool Debugger::cmdTraceEvents(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true; uc->_tracingEnabled = true;
uc->trace_events = true; uc->_traceEvents = true;
debugPrintf("UCMachine: tracing usecode events\n"); debugPrintf("UCMachine: tracing usecode events\n");
return true; return true;
} }
bool Debugger::cmdStopTrace(const Console::ArgvType &/*argv*/) { bool Debugger::cmdStopTrace(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance(); UCMachine *uc = UCMachine::get_instance();
uc->trace_ObjIDs.clear(); uc->_traceObjIDs.clear();
uc->trace_PIDs.clear(); uc->_tracePIDs.clear();
uc->trace_classes.clear(); uc->_traceClasses.clear();
uc->tracing_enabled = false; uc->_tracingEnabled = false;
uc->trace_all = false; uc->_traceAll = false;
uc->trace_events = false; uc->_traceEvents = false;
debugPrintf("Trace stopped\n"); debugPrintf("Trace stopped\n");
return true; return true;
@ -1506,16 +1507,18 @@ bool Debugger::cmdVisualDebugPathfinder(int argc, const char **argv) {
if (argc != 2) { if (argc != 2) {
debugPrintf("Usage: Pathfinder::visualDebug objid\n"); debugPrintf("Usage: Pathfinder::visualDebug objid\n");
debugPrintf("Specify objid -1 to stop tracing.\n"); debugPrintf("Specify objid -1 to stop tracing.\n");
return; return true;
} }
int p = strtol(argv[1].c_str(), 0, 0); int p = strtol(argv[1], 0, 0);
if (p == -1) { if (p == -1) {
visualdebug_actor = 0xFFFF; Pathfinder::_visualDebugActor = 0xFFFF;
debugPrintf("Pathfinder: stopped visual tracing\n"); debugPrintf("Pathfinder: stopped visual tracing\n");
} else { } else {
visualdebug_actor = (uint16)p; Pathfinder::_visualDebugActor = (uint16)p;
debugPrintf("Pathfinder: visually tracing _actor " << visualdebug_actor << Std::endl; debugPrintf("Pathfinder: visually tracing _actor %d\n", Pathfinder::_visualDebugActor);
} }
return true;
} }
#endif #endif

View File

@ -1337,9 +1337,7 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
_settingMan->get("ignore_savegame_mismatch", ignore); _settingMan->get("ignore_savegame_mismatch", ignore);
if (!ignore) { if (!ignore) {
Error(message, "Error Loading savegame " + filename); error("%s", message.c_str());
delete sg;
return false;
} }
perr << message << Std::endl; perr << message << Std::endl;
#else #else

View File

@ -97,8 +97,8 @@ UCMachine::UCMachine(Intrinsic *iset, unsigned int icount) {
_stringIDs = new idMan(1, 65534, 256); _stringIDs = new idMan(1, 65534, 256);
#ifdef DEBUG #ifdef DEBUG
tracing_enabled = false; _tracingEnabled = false;
trace_all = false; _traceAll = false;
#endif #endif
} }
@ -147,7 +147,7 @@ void UCMachine::execProcess(UCProcess *p) {
#ifdef DEBUG #ifdef DEBUG
if (trace_show(p->_pid, p->_itemNum, p->_classId)) { if (trace_show(p->_pid, p->_itemNum, p->_classId)) {
pout << Std::hex << "running process " << p->_pid pout << Std::hex << "running process " << p->_pid
<< ", item " << p->_itemNum << ", type " << p->type << ", item " << p->_itemNum << ", type " << p->_type
<< ", class " << p->_classId << ", offset " << p->_ip << ", class " << p->_classId << ", offset " << p->_ip
<< Std::dec << Std::endl; << Std::dec << Std::endl;
} }
@ -354,7 +354,7 @@ void UCMachine::execProcess(UCProcess *p) {
//! TODO //! TODO
uint16 arg_bytes = cs.read1(); uint16 arg_bytes = cs.read1();
uint16 func = cs.read2(); uint16 func = cs.read2();
LOGPF(("calli\t\t%04Xh (%02Xh arg bytes) %s \n", func, arg_bytes, _convUse->_intrinsics()[func])); debug(("calli\t\t%04Xh (%02Xh arg bytes) %s \n", func, arg_bytes, _convUse->intrinsics()[func]));
// !constants // !constants
if (func >= _intrinsicCount || _intrinsics[func] == 0) { if (func >= _intrinsicCount || _intrinsics[func] == 0) {
@ -1337,7 +1337,7 @@ void UCMachine::execProcess(UCProcess *p) {
#ifdef DEBUG #ifdef DEBUG
if (trace_show(p->_pid, p->_itemNum, p->_classId)) { if (trace_show(p->_pid, p->_itemNum, p->_classId)) {
pout << Std::hex << "(still) running process " << p->_pid pout << Std::hex << "(still) running process " << p->_pid
<< ", item " << p->_itemNum << ", type " << p->type << ", item " << p->_itemNum << ", type " << p->_type
<< ", class " << p->_classId << ", offset " << p->_ip << ", class " << p->_classId << ", offset " << p->_ip
<< Std::dec << Std::endl; << Std::dec << Std::endl;
} }
@ -1365,10 +1365,10 @@ void UCMachine::execProcess(UCProcess *p) {
uint16 offset = cs.read2(); uint16 offset = cs.read2();
uint16 delta = cs.read2(); uint16 delta = cs.read2();
int this_size = cs.read1(); int this_size = cs.read1();
(void)cs.read1(); // ?? int unknown = cs.read1(); // ??
LOGPF(("spawn inline\t%04X:%04X+%04X=%04X %02X %02X\n", debug("spawn inline\t%04X:%04X+%04X=%04X %02X %02X\n",
classid, offset, delta, offset + delta, this_size, unknown)); classid, offset, delta, offset + delta, this_size, unknown);
uint32 thisptr = 0; uint32 thisptr = 0;
if (this_size > 0) if (this_size > 0)

View File

@ -23,6 +23,7 @@
#ifndef ULTIMA8_USECODE_UCMACHINE_H #ifndef ULTIMA8_USECODE_UCMACHINE_H
#define ULTIMA8_USECODE_UCMACHINE_H #define ULTIMA8_USECODE_UCMACHINE_H
#include "ultima/ultima8/misc/common_types.h"
#include "ultima/shared/std/containers.h" #include "ultima/shared/std/containers.h"
#include "ultima/ultima8/usecode/intrinsics.h" #include "ultima/ultima8/usecode/intrinsics.h"
@ -114,25 +115,25 @@ private:
#ifdef DEBUG #ifdef DEBUG
// tracing // tracing
bool tracing_enabled; bool _tracingEnabled;
bool trace_all; bool _traceAll;
bool trace_events; bool _traceEvents;
Std::set<ObjId> trace_ObjIDs; Std::set<ObjId> _traceObjIDs;
Std::set<ProcId> trace_PIDs; Std::set<ProcId> _tracePIDs;
Std::set<uint16> trace_classes; Std::set<uint16> _traceClasses;
inline bool trace_show(ProcId pid, ObjId objid, uint16 ucclass) { inline bool trace_show(ProcId pid, ObjId objid, uint16 ucclass) {
if (!tracing_enabled) return false; if (!_tracingEnabled) return false;
if (trace_all) return true; if (_traceAll) return true;
if (trace_ObjIDs.find(objid) != trace_ObjIDs.end()) return true; if (_traceObjIDs.find(objid) != _traceObjIDs.end()) return true;
if (trace_PIDs.find(pid) != trace_PIDs.end()) return true; if (_tracePIDs.find(pid) != _tracePIDs.end()) return true;
if (trace_classes.find(ucclass) != trace_classes.end()) return true; if (_traceClasses.find(ucclass) != _traceClasses.end()) return true;
return false; return false;
} }
public: public:
bool trace_event() { bool trace_event() {
return (tracing_enabled && (trace_all || trace_events)); return (_tracingEnabled && (_traceAll || _traceEvents));
} }
#endif #endif
}; };

View File

@ -33,7 +33,7 @@ namespace Ultima {
namespace Ultima8 { namespace Ultima8 {
#ifdef DEBUG #ifdef DEBUG
ObjId Pathfinder::visualdebug_actor = 0xFFFF; ObjId Pathfinder::_visualDebugActor = 0xFFFF;
#endif #endif
struct PathNode { struct PathNode {
@ -403,12 +403,12 @@ void Pathfinder::newNode(PathNode *oldnode, PathfindingState &state,
#endif #endif
#ifdef DEBUG #ifdef DEBUG
if (_actor->getObjId() == visualdebug_actor) { if (_actor->getObjId() == _visualDebugActor) {
RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen(); RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
screen->BeginPainting(); screen->BeginPainting();
drawpath(newnode, 0xFFFFFF00, done); drawpath(newnode, 0xFFFFFF00, done);
screen->EndPainting(); screen->EndPainting();
SDL_Delay(250); g_system->delayMillis(250);
if (!done) { if (!done) {
screen->BeginPainting(); screen->BeginPainting();
drawpath(newnode, 0xFFB0B000, done); drawpath(newnode, 0xFFB0B000, done);
@ -513,7 +513,7 @@ bool Pathfinder::pathfind(Std::vector<PathfindingAction> &path) {
#endif #endif
#ifdef DEBUG #ifdef DEBUG
if (_actor->getObjId() == visualdebug_actor) { if (_actor->getObjId() == _visualDebugActor) {
RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen(); RenderSurface *screen = Ultima8Engine::get_instance()->getRenderScreen();
screen->BeginPainting(); screen->BeginPainting();
if (_targetItem) if (_targetItem)

View File

@ -76,7 +76,7 @@ public:
bool pathfind(Std::vector<PathfindingAction> &path); bool pathfind(Std::vector<PathfindingAction> &path);
#ifdef DEBUG #ifdef DEBUG
static ObjId visualdebug_actor; static ObjId _visualDebugActor;
#endif #endif

View File

@ -1035,8 +1035,8 @@ uint32 Item::callUsecodeEvent(uint32 event, const uint8 *args, int argsize) {
#ifdef DEBUG #ifdef DEBUG
if (UCMachine::get_instance()->trace_event()) { if (UCMachine::get_instance()->trace_event()) {
pout.printf("Item: %d calling usecode event %d @ %04X:%04X\n", pout.Print("Item: %d calling usecode event %d @ %04X:%04X\n",
_objId, event, class_id, offset); _objId, event, class_id, offset);
} }
#endif #endif