MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetLinkGraphJobDesc

Function GetLinkGraphJobDesc

src/saveload/linkgraph_sl.cpp:180–213  ·  view source on GitHub ↗

* Get a SaveLoad array for a link graph job. The settings struct is derived from * the global settings saveload array. The exact entries are calculated when the function * is called the first time. * It's necessary to keep a copy of the settings for each link graph job so that you can * change the settings while in-game and still not mess with current link graph runs. * Of course the settings

Source from the content-addressed store, hash-verified

178 * @return Array of SaveLoad structs.
179 */
180SaveLoadTable GetLinkGraphJobDesc()
181{
182 static std::vector<SaveLoad> saveloads;
183
184 static const SaveLoad job_desc[] = {
185 SLE_VAR(LinkGraphJob, join_date, SLE_INT32),
186 SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
187 SLEG_STRUCT("linkgraph", SlLinkgraphJobProxy),
188 };
189
190 /* The member offset arithmetic below is only valid if the types in question
191 * are standard layout types. Otherwise, it would be undefined behaviour. */
192 static_assert(std::is_standard_layout<LinkGraphSettings>::value, "LinkGraphSettings needs to be a standard layout type");
193
194 /* We store the offset of each member of the #LinkGraphSettings in the
195 * extra data of the saveload struct. Use it together with the address
196 * of the settings struct inside the job to find the final memory address. */
197 static SaveLoadAddrProc * const proc = [](void *b, size_t extra) -> void * { return const_cast<void *>(static_cast<const void *>(reinterpret_cast<const char *>(std::addressof(static_cast<LinkGraphJob *>(b)->settings)) + extra)); };
198
199 /* Build the SaveLoad array on first call and don't touch it later on */
200 if (saveloads.empty()) {
201 GetSaveLoadFromSettingTable(_linkgraph_settings, saveloads);
202
203 for (auto &sl : saveloads) {
204 sl.address_proc = proc;
205 }
206
207 for (auto &sld : job_desc) {
208 saveloads.push_back(sld);
209 }
210 }
211
212 return saveloads;
213}
214
215/**
216 * Get a SaveLoad array for the link graph schedule.

Callers 2

SaveMethod · 0.85
LoadMethod · 0.85

Calls 3

push_backMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected