forked from OpenLoco/OpenLoco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectManager.h
189 lines (164 loc) · 5.06 KB
/
ObjectManager.h
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
#pragma once
#include "Object.h"
#include "Ui/UiTypes.hpp"
#include <OpenLoco/Core/Span.hpp>
#include <optional>
#include <vector>
namespace OpenLoco
{
class SawyerStreamWriter;
namespace Gfx
{
struct RenderTarget;
}
struct Object;
struct ObjectEntryExtended;
struct CargoObject;
struct InterfaceSkinObject;
struct SoundObject;
struct CurrencyObject;
struct SteamObject;
struct CliffEdgeObject;
struct WaterObject;
struct LandObject;
struct TownNamesObject;
struct WallObject;
struct TrainSignalObject;
struct LevelCrossingObject;
struct StreetLightObject;
struct TunnelObject;
struct BridgeObject;
struct TrainStationObject;
struct TrackExtraObject;
struct TrackObject;
struct RoadStationObject;
struct RoadExtraObject;
struct RoadObject;
struct AirportObject;
struct DockObject;
struct VehicleObject;
struct TreeObject;
struct SnowObject;
struct ClimateObject;
struct HillShapesObject;
struct BuildingObject;
struct ScaffoldingObject;
struct IndustryObject;
struct RegionObject;
struct CompetitorObject;
struct ScenarioTextObject;
/**
* Represents an index into the entire loaded object array. Not an index for
* a specific object type. DO NOT USE
*/
using LoadedObjectIndex = size_t;
}
namespace OpenLoco::ObjectManager
{
constexpr size_t getMaxObjects(ObjectType type)
{
// 0x004FE250
constexpr size_t counts[] = {
1, // interface,
128, // sound,
1, // currency,
32, // steam,
8, // rock,
1, // water,
32, // surface,
1, // townNames,
32, // cargo,
32, // wall,
16, // train_signal,
4, // levelCrossing,
1, // streetLight,
16, // tunnel,
8, // bridge,
16, // train_station,
8, // trackExtra,
8, // track,
16, // roadStation,
4, // roadExtra,
8, // road,
8, // airport,
8, // dock,
224, // vehicle,
64, // tree,
1, // snow,
1, // climate,
1, // hillShapes,
128, // building,
1, // scaffolding,
16, // industry,
1, // region,
32, // competitor,
1 // scenarioText,
};
return counts[(size_t)type];
};
constexpr size_t maxObjects = 859;
constexpr size_t maxObjectTypes = 34;
Object* getAny(const LoadedObjectHandle& handle);
template<typename T>
T* get()
{
static_assert(getMaxObjects(T::kObjectType) == 1);
return reinterpret_cast<T*>(getAny({ T::kObjectType, 0 }));
}
template<typename T>
T* get(size_t id)
{
static_assert(getMaxObjects(T::kObjectType) != 1);
return reinterpret_cast<T*>(getAny({ T::kObjectType, static_cast<LoadedObjectId>(id) }));
}
#pragma pack(push, 1)
struct ObjectHeader2
{
uint32_t decodedFileSize;
};
struct ObjectHeader3
{
uint32_t numImages; // 0x0
uint8_t intelligence; // 0x4 competitor stats
uint8_t aggressiveness; // 0x5
uint8_t competitiveness; // 0x6
uint8_t pad_07[0x5];
};
#pragma pack(pop)
struct LoadObjectsResult
{
bool success{};
ObjectHeader problemObject;
};
struct DependentObjects
{
std::vector<ObjectHeader> required;
std::vector<ObjectHeader> willLoad;
};
void freeTemporaryObject();
bool loadTemporaryObject(ObjectHeader& header);
Object* getTemporaryObject();
bool isTemporaryObjectLoad();
std::optional<LoadedObjectHandle> findObjectHandle(const ObjectHeader& header);
// Calls findObjectHandle and if can't find performs a secondary check with slightly looser
// definitions of what a matching custom header is (no checksum, partial flags)
std::optional<LoadedObjectHandle> findObjectHandleFuzzy(const ObjectHeader& header);
void reloadAll();
ObjectHeader& getHeader(const LoadedObjectHandle& handle);
std::vector<ObjectHeader> getHeaders();
LoadObjectsResult loadAll(stdx::span<ObjectHeader> objects);
void writePackedObjects(SawyerStreamWriter& fs, const std::vector<ObjectHeader>& packedObjects);
void unloadAll();
// Only unloads the entry (clears entry for packing does not free)
void unload(const LoadedObjectHandle& handle);
// Unloads and frees the entry
void unload(const ObjectHeader& header);
bool load(const ObjectHeader& header);
bool tryInstallObject(const ObjectHeader& object, stdx::span<const uint8_t> data);
size_t getByteLength(const LoadedObjectHandle& handle);
void drawGenericDescription(Gfx::RenderTarget& rt, Ui::Point& rowPosition, const uint16_t designed, const uint16_t obsolete);
void updateYearly1();
void updateYearly2();
void sub_4748FA();
void registerHooks();
}