1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
/* 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/archive.h"
#include "director/debugger.h"
#include "director/debugger/dt-internal.h"
#include "director/lingo/lingo-object.h"
namespace Director {
namespace DT {
void showCallStack() {
if (!_state->_w.callStack)
return;
Director::Lingo *lingo = g_director->getLingo();
ImGui::SetNextWindowPos(ImVec2(20, 160), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(120, 120), ImGuiCond_FirstUseEver);
if (ImGui::Begin("CallStack", &_state->_w.callStack)) {
ImGui::Text("%s", lingo->formatCallStack(lingo->_state->pc).c_str());
}
ImGui::End();
}
static void cacheVars() {
// take a snapshot of the variables every 500 ms
if ((g_director->getTotalPlayTime() - _state->_vars._lastTimeRefreshed) > 500) {
_state->_vars._prevLocals = _state->_vars._locals;
if (g_lingo->_state->localVars) {
_state->_vars._locals = *g_lingo->_state->localVars;
} else {
_state->_vars._locals.clear();
}
_state->_vars._prevGlobals = _state->_vars._globals;
_state->_vars._globals = g_lingo->_globalvars;
_state->_vars._lastTimeRefreshed = g_director->getTotalPlayTime();
}
}
void showVars() {
if (!_state->_w.vars)
return;
cacheVars();
Director::Lingo *lingo = g_director->getLingo();
ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(300, 250), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Vars", &_state->_w.vars)) {
Common::Array<Common::String> keyBuffer;
if (ImGui::CollapsingHeader("Global vars:", ImGuiTreeNodeFlags_DefaultOpen)) {
for (auto &it : _state->_vars._globals) {
keyBuffer.push_back(it._key);
}
Common::sort(keyBuffer.begin(), keyBuffer.end());
for (auto &i : keyBuffer) {
Datum &val = _state->_vars._globals.getVal(i);
bool changed = !_state->_vars._prevGlobals.contains(i) || !(_state->_vars._globals.getVal(i) == _state->_vars._prevGlobals.getVal(i));
displayVariable(i, changed);
ImGui::SameLine();
ImGui::Text(" - [%s] %s", val.type2str(), formatStringForDump(val.asString(true)).c_str());
}
keyBuffer.clear();
}
if (ImGui::CollapsingHeader("Local vars:", ImGuiTreeNodeFlags_None)) {
if (!_state->_vars._locals.empty()) {
for (auto &it : _state->_vars._locals) {
keyBuffer.push_back(it._key);
}
Common::sort(keyBuffer.begin(), keyBuffer.end());
for (auto &i : keyBuffer) {
Datum &val = _state->_vars._locals.getVal(i);
bool changed = !_state->_vars._prevLocals.contains(i) || !(_state->_vars._locals.getVal(i) == _state->_vars._prevLocals.getVal(i));
displayVariable(i, changed);
ImGui::SameLine();
ImGui::Text(" - [%s] %s", val.type2str(), formatStringForDump(val.asString(true)).c_str());
}
keyBuffer.clear();
} else {
ImGui::Text(" (no local vars)");
}
}
if (ImGui::CollapsingHeader("Instance/property vars:", ImGuiTreeNodeFlags_None)) {
if (lingo->_state->me.type == OBJECT && lingo->_state->me.u.obj->getObjType() & (kFactoryObj | kScriptObj)) {
ScriptContext *script = static_cast<ScriptContext *>(lingo->_state->me.u.obj);
for (uint32 i = 1; i <= script->getPropCount(); i++) {
keyBuffer.push_back(script->getPropAt(i));
}
Common::sort(keyBuffer.begin(), keyBuffer.end());
for (auto &i : keyBuffer) {
Datum val = script->getProp(i);
displayVariable(i, false);
ImGui::SameLine();
ImGui::Text(" - [%s] %s", val.type2str(), formatStringForDump(val.asString(true)).c_str());
}
keyBuffer.clear();
} else {
ImGui::Text(" (no instance or property)");
}
}
}
ImGui::End();
}
void showWatchedVars() {
if (!_state->_w.watchedVars)
return;
cacheVars();
ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(300, 250), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Watched Vars", &_state->_w.watchedVars)) {
for (auto &v : _state->_variables) {
Datum name(v._key);
name.type = VARREF;
Datum val = g_lingo->varFetch(name, true);
displayVariable(v._key, false);
ImGui::SameLine();
ImGui::Text(" - [%s] %s", val.type2str(), formatStringForDump(val.asString(true)).c_str());
}
if (_state->_variables.empty())
ImGui::Text("(no watched variables)");
}
ImGui::End();
}
// Make the UI compact because there are so many fields
static void PushStyleCompact() {
ImGuiStyle &style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(style.FramePadding.x, (float)(int)(style.FramePadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x, (float)(int)(style.ItemSpacing.y * 0.60f)));
}
static void PopStyleCompact() {
ImGui::PopStyleVar(2);
}
void showBreakpointList() {
if (!_state->_w.bpList)
return;
ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(480, 240), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Breakpoints", &_state->_w.bpList)) {
auto &bps = g_lingo->getBreakpoints();
if (ImGui::BeginTable("BreakpointsTable", 5, ImGuiTableFlags_SizingFixedFit)) {
for (uint i = 0; i < 5; i++)
ImGui::TableSetupColumn(NULL, i == 2 ? ImGuiTableColumnFlags_WidthStretch : ImGuiTableColumnFlags_NoHeaderWidth);
for (uint i = 0; i < bps.size(); i++) {
if (bps[i].type != kBreakpointFunction)
continue;
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImDrawList *dl = ImGui::GetWindowDrawList();
ImVec2 pos = ImGui::GetCursorScreenPos();
const ImVec2 mid(pos.x + 7, pos.y + 7);
ImVec4 color = bps[i].enabled ? _state->_colors._bp_color_enabled : _state->_colors._bp_color_disabled;
ImGui::InvisibleButton("Line", ImVec2(16, ImGui::GetFontSize()));
if (ImGui::IsItemClicked(0)) {
if (bps[i].enabled) {
bps[i].enabled = false;
color = _state->_colors._bp_color_disabled;
} else {
bps[i].enabled = true;
color = _state->_colors._bp_color_enabled;
}
}
if (!bps[i].enabled && ImGui::IsItemHovered()) {
color = _state->_colors._bp_color_hover;
}
if (bps[i].enabled)
dl->AddCircleFilled(mid, 4.0f, ImColor(color));
else
dl->AddCircle(mid, 4.0f, ImColor(_state->_colors._line_color));
// enabled column
ImGui::TableNextColumn();
PushStyleCompact();
ImGui::PushID(i);
ImGui::Checkbox("", &bps[i].enabled);
PopStyleCompact();
// description
ImGui::TableNextColumn();
Common::String desc;
if (bps[i].scriptId)
desc = Common::String::format("%d: %s", bps[i].scriptId, bps[i].funcName.c_str());
else
desc = bps[i].funcName;
ImGui::Text("%s", desc.c_str());
// remove bp
ImGui::TableNextColumn();
pos = ImGui::GetCursorScreenPos();
const bool del = ImGui::InvisibleButton("DelBp", ImVec2(16, ImGui::GetFontSize()));
const bool hovered = ImGui::IsItemHovered();
const float fontSize = ImGui::GetFontSize();
const float cross_extent = ImGui::GetFontSize() * 0.5f * 0.7071f - 1.0f;
const ImU32 cross_col = ImGui::GetColorU32(ImGuiCol_Text);
const ImVec2 center = pos + ImVec2(0.5f + fontSize * 0.5f, 1.0f + fontSize * 0.5f);
if (hovered)
dl->AddCircleFilled(center, MAX(2.0f, fontSize * 0.5f + 1.0f), ImGui::GetColorU32(ImGuiCol_ButtonActive));
dl->AddLine(center + ImVec2(+cross_extent, +cross_extent), center + ImVec2(-cross_extent, -cross_extent), cross_col, 1.0f);
dl->AddLine(center + ImVec2(+cross_extent, -cross_extent), center + ImVec2(-cross_extent, +cross_extent), cross_col, 1.0f);
// offset
ImGui::TableNextColumn();
ImGui::Text("%d", bps[i].funcOffset);
ImGui::PopID();
if (del) {
g_lingo->delBreakpoint(bps[i].id);
break;
}
}
ImGui::EndTable();
}
}
ImGui::End();
}
void showArchive() {
if (!_state->_w.archive)
return;
ImVec2 pos(40, 40);
ImGui::SetNextWindowPos(pos, ImGuiCond_FirstUseEver);
ImVec2 windowSize = ImGui::GetMainViewport()->Size * 0.8f;
ImGui::SetNextWindowSize(windowSize, ImGuiCond_FirstUseEver);
if (ImGui::Begin("Archive", &_state->_w.archive)) {
{ // Left pane
ImGui::BeginChild("ChildL", ImVec2(ImGui::GetContentRegionAvail().x * 0.3f, ImGui::GetContentRegionAvail().y), ImGuiChildFlags_None);
for (auto &it : g_director->_allSeenResFiles) {
Archive *archive = it._value;
if (ImGui::TreeNode(archive->getPathName().toString().c_str())) {
Common::Array<uint32> typeList = archive->getResourceTypeList();
Common::sort(typeList.begin(), typeList.end());
for (auto tag : typeList) {
if (ImGui::TreeNode((void*)(intptr_t)tag, "%s", tag2str(tag))) {
Common::Array<uint16> resList = archive->getResourceIDList(tag);
Common::sort(resList.begin(), resList.end());
for (auto id : resList) {
if (ImGui::Selectable(Common::String::format("%d", id).c_str())) {
_state->_archive.path = it._key;
_state->_archive.resType = tag;
_state->_archive.resId = id;
free(_state->_archive.data);
Common::SeekableReadStreamEndian *res = archive->getResource(tag, id);
_state->_archive.data = (byte *)malloc(res->size());
res->read(_state->_archive.data, res->size());
_state->_archive.dataSize = res->size();
delete res;
}
}
ImGui::TreePop();
}
}
ImGui::TreePop();
}
}
ImGui::EndChild();
}
ImGui::SameLine();
{ // Right pane
ImGui::BeginChild("ChildR", ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y), ImGuiChildFlags_Borders);
ImGui::Text("Resource %s %d (%d bytes)", tag2str(_state->_archive.resType), _state->_archive.resId, _state->_archive.dataSize);
ImGui::Separator();
if (!_state->_archive.path.empty())
_state->_archive.memEdit.DrawContents(_state->_archive.data, _state->_archive.dataSize);
ImGui::EndChild();
}
}
ImGui::End();
}
} // namespace DT
} // namespace Director
|