Move NewGRF sprite dump declarations to new header file

This commit is contained in:
Jonathan G Rennison
2024-05-30 19:05:32 +01:00
parent dc6ba9b9d8
commit 99e6b75337
16 changed files with 73 additions and 45 deletions

View File

@@ -284,6 +284,7 @@ add_files(
newgrf_config.h
newgrf_debug.h
newgrf_debug_gui.cpp
newgrf_dump.h
newgrf_engine.cpp
newgrf_engine.h
newgrf_extension.cpp

View File

@@ -38,6 +38,7 @@
#include "newgrf_airport.h"
#include "newgrf_airporttiles.h"
#include "newgrf_debug.h"
#include "newgrf_dump.h"
#include "newgrf_object.h"
#include "newgrf_spritegroup.h"
#include "newgrf_station.h"

59
src/newgrf_dump.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file newgrf_dump.h Functions/types related to NewGRF sprite group dumping. */
#ifndef NEWGRF_DUMP_H
#define NEWGRF_DUMP_H
#include "3rdparty/robin_hood/robin_hood.h"
#include <functional>
enum DumpSpriteGroupPrintOp {
DSGPO_PRINT,
DSGPO_START,
DSGPO_END,
DSGPO_NFO_LINE,
};
using DumpSpriteGroupPrinter = std::function<void(const struct SpriteGroup *, DumpSpriteGroupPrintOp, uint32_t, const char *)>;
struct SpriteGroupDumper {
bool use_shadows = false;
bool more_details = false;
private:
char buffer[1024];
DumpSpriteGroupPrinter print_fn;
const SpriteGroup *top_default_group = nullptr;
const SpriteGroup *top_graphics_group = nullptr;
robin_hood::unordered_flat_set<const struct DeterministicSpriteGroup *> seen_dsgs;
enum SpriteGroupDumperFlags {
SGDF_DEFAULT = 1 << 0,
SGDF_RANGE = 1 << 1,
};
char *DumpSpriteGroupAdjust(char *p, const char *last, const struct DeterministicSpriteGroupAdjust &adjust, const char *padding, uint32_t &highlight_tag, uint &conditional_indent);
void DumpSpriteGroup(const struct SpriteGroup *sg, const char *prefix, uint flags);
public:
SpriteGroupDumper(DumpSpriteGroupPrinter print) : print_fn(print) {}
void DumpSpriteGroup(const SpriteGroup *sg, uint flags)
{
this->DumpSpriteGroup(sg, "", flags);
}
void Print(const char *msg)
{
this->print_fn(nullptr, DSGPO_PRINT, 0, msg);
}
};
#endif /* NEWGRF_DEBUG_H */

View File

@@ -28,6 +28,7 @@
#include "scope_info.h"
#include "newgrf_extension.h"
#include "newgrf_analysis.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -17,6 +17,7 @@
#include "newgrf_extension.h"
#include "water_map.h"
#include "string_func.h"
#include "newgrf_dump.h"
#include <list>
#include "safeguards.h"

View File

@@ -18,6 +18,7 @@
#include "company_base.h"
#include "error.h"
#include "strings_func.h"
#include "newgrf_dump.h"
#include "core/random_func.hpp"
#include "table/strings.h"

View File

@@ -15,6 +15,7 @@
#include "clear_map.h"
#include "core/hash_func.hpp"
#include "string_func.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -14,6 +14,7 @@
#include "map_func.h"
#include "tracerestrict.h"
#include "string_func.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -23,6 +23,7 @@
#include "clear_func.h"
#include "newgrf_animation_base.h"
#include "newgrf_extension.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -18,6 +18,7 @@
#include "town.h"
#include "signal_func.h"
#include "road.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -25,6 +25,7 @@
#include "newgrf_animation_base.h"
#include "newgrf_sound.h"
#include "newgrf_extension.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -14,6 +14,7 @@
#include "date_func.h"
#include "depot_base.h"
#include "town.h"
#include "newgrf_dump.h"
#include "safeguards.h"

View File

@@ -20,6 +20,7 @@
#include "scope.h"
#include "debug_settings.h"
#include "newgrf_engine.h"
#include "newgrf_dump.h"
#include <bit>
#include "safeguards.h"

View File

@@ -20,8 +20,6 @@
#include "newgrf_storage.h"
#include "newgrf_commons.h"
#include "3rdparty/robin_hood/robin_hood.h"
#include <map>
#include <vector>
@@ -747,49 +745,6 @@ struct ResolverObject {
virtual uint32_t GetDebugID() const { return 0; }
};
enum DumpSpriteGroupPrintOp {
DSGPO_PRINT,
DSGPO_START,
DSGPO_END,
DSGPO_NFO_LINE,
};
using DumpSpriteGroupPrinter = std::function<void(const SpriteGroup *, DumpSpriteGroupPrintOp, uint32_t, const char *)>;
struct SpriteGroupDumper {
bool use_shadows = false;
bool more_details = false;
private:
char buffer[1024];
DumpSpriteGroupPrinter print_fn;
const SpriteGroup *top_default_group = nullptr;
const SpriteGroup *top_graphics_group = nullptr;
robin_hood::unordered_flat_set<const DeterministicSpriteGroup *> seen_dsgs;
enum SpriteGroupDumperFlags {
SGDF_DEFAULT = 1 << 0,
SGDF_RANGE = 1 << 1,
};
char *DumpSpriteGroupAdjust(char *p, const char *last, const DeterministicSpriteGroupAdjust &adjust, const char *padding, uint32_t &highlight_tag, uint &conditional_indent);
void DumpSpriteGroup(const SpriteGroup *sg, const char *prefix, uint flags);
public:
SpriteGroupDumper(DumpSpriteGroupPrinter print) : print_fn(print) {}
void DumpSpriteGroup(const SpriteGroup *sg, uint flags)
{
this->DumpSpriteGroup(sg, "", flags);
}
void Print(const char *msg)
{
this->print_fn(nullptr, DSGPO_PRINT, 0, msg);
}
};
uint32_t EvaluateDeterministicSpriteGroupAdjust(DeterministicSpriteGroupSize size, const DeterministicSpriteGroupAdjust &adjust, ScopeResolver *scope, uint32_t last_value, uint32_t value);
#endif /* NEWGRF_SPRITEGROUP_H */

View File

@@ -24,6 +24,7 @@
#include "newgrf_animation_base.h"
#include "newgrf_class_func.h"
#include "newgrf_extension.h"
#include "newgrf_dump.h"
#include "core/checksum_func.hpp"
#include "safeguards.h"

View File

@@ -27,6 +27,7 @@
#include "../tunnelbridge.h"
#include "../train_speed_adaptation.h"
#include "../tracerestrict.h"
#include "../newgrf_dump.h"
/* Helper for filling property tables */
#define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type }