mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
Debug: Add temp store highlighting to sprite group dump window
Add tooltip
This commit is contained in:
parent
6d4da8afd4
commit
c238bd5012
@ -4207,6 +4207,7 @@ STR_NEWGRF_INSPECT_LOG_CONSOLE :{BLACK}L
|
||||
STR_NEWGRF_INSPECT_LOG_CONSOLE_TOOLTIP :{BLACK}Log text content of this window to the console
|
||||
STR_NEWGRF_INSPECT_SPRITE_DUMP :{BLACK}S
|
||||
STR_NEWGRF_INSPECT_SPRITE_DUMP_TOOLTIP :{BLACK}Display current sprite chain
|
||||
STR_NEWGRF_INSPECT_SPRITE_DUMP_PANEL_TOOLTIP :{BLACK}Click to highlight sprite group{}Ctrl+Click to highlight temporary storage register
|
||||
|
||||
STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT :{STRING1} at {HEX}
|
||||
STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT :Object
|
||||
|
@ -320,6 +320,8 @@ struct NewGRFInspectWindow : Window {
|
||||
btree::btree_map<int, uint> extra_info_click_flag_toggles;
|
||||
btree::btree_map<int, const SpriteGroup *> sprite_group_lines;
|
||||
const SpriteGroup *selected_sprite_group = nullptr;
|
||||
btree::btree_map<int, uint32> highlight_tag_lines;
|
||||
uint32 selected_highlight_tag = 0;
|
||||
|
||||
/**
|
||||
* Check whether the given variable has a parameter.
|
||||
@ -525,16 +527,18 @@ struct NewGRFInspectWindow : Window {
|
||||
};
|
||||
const_cast<NewGRFInspectWindow *>(this)->sprite_group_lines.clear();
|
||||
if (this->sprite_dump) {
|
||||
nih->SpriteDump(index, [&](const SpriteGroup *group, const char *buf) {
|
||||
nih->SpriteDump(index, [&](const SpriteGroup *group, uint32 highlight_tag, const char *buf) {
|
||||
if (this->log_console) DEBUG(misc, 0, " %s", buf);
|
||||
|
||||
int offset = i++;
|
||||
int scroll_offset = offset - this->vscroll->GetPosition();
|
||||
if (scroll_offset < 0 || scroll_offset >= this->vscroll->GetCapacity()) return;
|
||||
|
||||
const_cast<NewGRFInspectWindow *>(this)->sprite_group_lines[offset] = group;
|
||||
if (group != nullptr) const_cast<NewGRFInspectWindow *>(this)->sprite_group_lines[offset] = group;
|
||||
if (highlight_tag != 0) const_cast<NewGRFInspectWindow *>(this)->highlight_tag_lines[offset] = highlight_tag;
|
||||
|
||||
TextColour colour = (this->selected_sprite_group == group) ? TC_LIGHT_BLUE : TC_BLACK;
|
||||
if (highlight_tag != 0 && this->selected_highlight_tag == highlight_tag) colour = TC_YELLOW;
|
||||
::DrawString(r.left + LEFT_OFFSET, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (scroll_offset * this->resize.step_height), buf, colour);
|
||||
});
|
||||
return;
|
||||
@ -730,12 +734,22 @@ struct NewGRFInspectWindow : Window {
|
||||
if (line == INT_MAX) return;
|
||||
|
||||
if (this->sprite_dump) {
|
||||
const SpriteGroup *group = nullptr;
|
||||
auto iter = this->sprite_group_lines.find(line);
|
||||
if (iter != this->sprite_group_lines.end()) group = iter->second;
|
||||
if (group != nullptr || this->selected_sprite_group != nullptr) {
|
||||
this->selected_sprite_group = (group == this->selected_sprite_group) ? nullptr : group;
|
||||
this->SetWidgetDirty(WID_NGRFI_MAINPANEL);
|
||||
if (_ctrl_pressed) {
|
||||
uint32 highlight_tag = 0;
|
||||
auto iter = this->highlight_tag_lines.find(line);
|
||||
if (iter != this->highlight_tag_lines.end()) highlight_tag = iter->second;
|
||||
if (highlight_tag != 0 || this->selected_highlight_tag != 0) {
|
||||
this->selected_highlight_tag = (highlight_tag == this->selected_highlight_tag) ? 0 : highlight_tag;
|
||||
this->SetWidgetDirty(WID_NGRFI_MAINPANEL);
|
||||
}
|
||||
} else {
|
||||
const SpriteGroup *group = nullptr;
|
||||
auto iter = this->sprite_group_lines.find(line);
|
||||
if (iter != this->sprite_group_lines.end()) group = iter->second;
|
||||
if (group != nullptr || this->selected_sprite_group != nullptr) {
|
||||
this->selected_sprite_group = (group == this->selected_sprite_group) ? nullptr : group;
|
||||
this->SetWidgetDirty(WID_NGRFI_MAINPANEL);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -782,6 +796,7 @@ struct NewGRFInspectWindow : Window {
|
||||
case WID_NGRFI_SPRITE_DUMP: {
|
||||
this->sprite_dump = !this->sprite_dump;
|
||||
this->SetWidgetLoweredState(WID_NGRFI_SPRITE_DUMP, this->sprite_dump);
|
||||
this->GetWidget<NWidgetCore>(WID_NGRFI_MAINPANEL)->SetToolTip(this->sprite_dump ? STR_NEWGRF_INSPECT_SPRITE_DUMP_PANEL_TOOLTIP : STR_NULL);
|
||||
this->SetWidgetDirty(WID_NGRFI_SPRITE_DUMP);
|
||||
this->SetWidgetDirty(WID_NGRFI_MAINPANEL);
|
||||
this->SetWidgetDirty(WID_NGRFI_SCROLLBAR);
|
||||
|
@ -682,8 +682,10 @@ static const char *GetAdjustOperationName(DeterministicSpriteGroupAdjustOperatio
|
||||
|
||||
void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint flags)
|
||||
{
|
||||
uint32 highlight_tag = 0;
|
||||
auto print = [&]() {
|
||||
this->print_fn(sg, this->buffer);
|
||||
this->print_fn(sg, highlight_tag, this->buffer);
|
||||
highlight_tag = 0;
|
||||
};
|
||||
|
||||
if (sg == nullptr) {
|
||||
@ -734,11 +736,19 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint
|
||||
padding += 2;
|
||||
for (const auto &adjust : dsg->adjusts) {
|
||||
char *p = this->buffer;
|
||||
if (adjust.variable == 0x7D) {
|
||||
/* Temp storage load */
|
||||
highlight_tag = (1 << 16) | (adjust.parameter & 0xFFFF);
|
||||
}
|
||||
if (adjust.operation == DSGA_OP_TERNARY) {
|
||||
p += seprintf(p, lastof(this->buffer), "%*sTERNARY: true: %X, false: %X", padding, "", adjust.and_mask, adjust.add_val);
|
||||
print();
|
||||
continue;
|
||||
}
|
||||
if (adjust.operation == DSGA_OP_STO && adjust.type == DSGA_TYPE_NONE && adjust.variable == 0x1A && adjust.shift_num == 0) {
|
||||
/* Temp storage store */
|
||||
highlight_tag = (1 << 16) | (adjust.and_mask & 0xFFFF);
|
||||
}
|
||||
p += seprintf(p, lastof(this->buffer), "%*svar: %X", padding, "", adjust.variable);
|
||||
if (adjust.variable == A2VRI_VEHICLE_CURRENT_SPEED_SCALED) {
|
||||
p += seprintf(p, lastof(this->buffer), " (current_speed_scaled)");
|
||||
@ -815,34 +825,21 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint
|
||||
const TileLayoutRegisters *reg = registers + i;
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*ssection: %X, register flags: %X", padding, "", (uint)i, reg->flags);
|
||||
print();
|
||||
if (reg->flags & TLF_DODRAW) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_DODRAW reg: %X", padding + 2, "", reg->dodraw);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_SPRITE) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_SPRITE reg: %X", padding + 2, "", reg->sprite);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_PALETTE) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_PALETTE reg: %X", padding + 2, "", reg->palette);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_BB_XY_OFFSET) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_BB_XY_OFFSET reg: %X, %X", padding + 2, "", reg->delta.parent[0], reg->delta.parent[1]);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_BB_Z_OFFSET) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_BB_Z_OFFSET reg: %X", padding + 2, "", reg->delta.parent[2]);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_CHILD_X_OFFSET) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_CHILD_X_OFFSET reg: %X", padding + 2, "", reg->delta.child[0]);
|
||||
print();
|
||||
}
|
||||
if (reg->flags & TLF_CHILD_Y_OFFSET) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_CHILD_Y_OFFSET reg: %X", padding + 2, "", reg->delta.child[1]);
|
||||
print();
|
||||
}
|
||||
auto log_reg = [&](TileLayoutFlags flag, const char *name, uint8 flag_reg) {
|
||||
if (reg->flags & flag) {
|
||||
highlight_tag = (1 << 16) | flag_reg;
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*s%s reg: %X", padding + 2, "", name, flag_reg);
|
||||
print();
|
||||
}
|
||||
};
|
||||
log_reg(TLF_DODRAW, "TLF_DODRAW", reg->dodraw);
|
||||
log_reg(TLF_SPRITE, "TLF_SPRITE", reg->sprite);
|
||||
log_reg(TLF_PALETTE, "TLF_PALETTE", reg->palette);
|
||||
log_reg(TLF_BB_XY_OFFSET, "TLF_BB_XY_OFFSET x", reg->delta.parent[0]);
|
||||
log_reg(TLF_BB_XY_OFFSET, "TLF_BB_XY_OFFSET y", reg->delta.parent[1]);
|
||||
log_reg(TLF_BB_Z_OFFSET, "TLF_BB_Z_OFFSET", reg->delta.parent[2]);
|
||||
log_reg(TLF_CHILD_X_OFFSET, "TLF_CHILD_X_OFFSET", reg->delta.child[0]);
|
||||
log_reg(TLF_CHILD_Y_OFFSET, "TLF_CHILD_Y_OFFSET", reg->delta.child[1]);
|
||||
if (reg->flags & TLF_SPRITE_VAR10) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sTLF_SPRITE_VAR10 value: %X", padding + 2, "", reg->sprite_var10);
|
||||
print();
|
||||
@ -860,6 +857,7 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sIndustry Production (version %X) [%u]", padding, "", ipsg->version, ipsg->nfo_line);
|
||||
print();
|
||||
auto log_io = [&](const char *prefix, int i, int quantity, CargoID cargo) {
|
||||
if (ipsg->version >= 1) highlight_tag = (1 << 16) | quantity;
|
||||
if (ipsg->version >= 2) {
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*s%s %X: reg %X, cargo ID: %X", padding + 2, "", prefix, i, quantity, cargo);
|
||||
print();
|
||||
@ -875,6 +873,7 @@ void SpriteGroupDumper::DumpSpriteGroup(const SpriteGroup *sg, int padding, uint
|
||||
for (int i = 0; i < ipsg->num_output; i++) {
|
||||
log_io("Add input", i, ipsg->add_output[i], ipsg->cargo_output[i]);
|
||||
}
|
||||
if (ipsg->version >= 1) highlight_tag = (1 << 16) | ipsg->again;
|
||||
seprintf(this->buffer, lastof(this->buffer), "%*sAgain: %s %X", padding + 2, "", (ipsg->version >= 1) ? "reg" : "value", ipsg->again);
|
||||
print();
|
||||
break;
|
||||
|
@ -569,7 +569,7 @@ struct ResolverObject {
|
||||
virtual uint32 GetDebugID() const { return 0; }
|
||||
};
|
||||
|
||||
using DumpSpriteGroupPrinter = std::function<void(const SpriteGroup *, const char *)>;
|
||||
using DumpSpriteGroupPrinter = std::function<void(const SpriteGroup *, uint32, const char *)>;
|
||||
|
||||
void DumpSpriteGroup(const SpriteGroup *sg, DumpSpriteGroupPrinter print);
|
||||
uint32 EvaluateDeterministicSpriteGroupAdjust(DeterministicSpriteGroupSize size, const DeterministicSpriteGroupAdjust &adjust, ScopeResolver *scope, uint32 last_value, uint32 value);
|
||||
|
Loading…
Reference in New Issue
Block a user