mirror of https://github.com/OpenTTD/OpenTTD
(svn r18689) -Codechange: move the looping over chunkhandlers code to a macro
parent
58be174df2
commit
35c79d81ef
|
@ -159,27 +159,28 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate over all chunk handlers.
|
||||||
|
* @param ch the chunk handler iterator
|
||||||
|
*/
|
||||||
|
#define FOR_ALL_CHUNK_HANDLERS(ch) \
|
||||||
|
for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
|
||||||
|
for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
|
||||||
|
|
||||||
static SaveLoadParams _sl;
|
static SaveLoadParams _sl;
|
||||||
|
|
||||||
/** Null all pointers (convert index -> NULL) */
|
/** Null all pointers (convert index -> NULL) */
|
||||||
static void SlNullPointers()
|
static void SlNullPointers()
|
||||||
{
|
{
|
||||||
const ChunkHandler *ch;
|
|
||||||
const ChunkHandler * const *chsc;
|
|
||||||
|
|
||||||
_sl.action = SLA_NULL;
|
_sl.action = SLA_NULL;
|
||||||
|
|
||||||
DEBUG(sl, 1, "Nulling pointers");
|
DEBUG(sl, 1, "Nulling pointers");
|
||||||
|
|
||||||
for (chsc = _chunk_handlers; (ch = *chsc++) != NULL;) {
|
FOR_ALL_CHUNK_HANDLERS(ch) {
|
||||||
while (true) {
|
|
||||||
if (ch->ptrs_proc != NULL) {
|
if (ch->ptrs_proc != NULL) {
|
||||||
DEBUG(sl, 2, "Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
DEBUG(sl, 2, "Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
||||||
ch->ptrs_proc();
|
ch->ptrs_proc();
|
||||||
}
|
}
|
||||||
if (ch->flags & CH_LAST) break;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(sl, 1, "All pointers nulled");
|
DEBUG(sl, 1, "All pointers nulled");
|
||||||
|
@ -1187,15 +1188,8 @@ static void SlSaveChunk(const ChunkHandler *ch)
|
||||||
/** Save all chunks */
|
/** Save all chunks */
|
||||||
static void SlSaveChunks()
|
static void SlSaveChunks()
|
||||||
{
|
{
|
||||||
const ChunkHandler *ch;
|
FOR_ALL_CHUNK_HANDLERS(ch) {
|
||||||
const ChunkHandler * const *chsc;
|
|
||||||
|
|
||||||
for (chsc = _chunk_handlers; (ch = *chsc++) != NULL;) {
|
|
||||||
while (true) {
|
|
||||||
SlSaveChunk(ch);
|
SlSaveChunk(ch);
|
||||||
if (ch->flags & CH_LAST) break;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminator */
|
/* Terminator */
|
||||||
|
@ -1209,15 +1203,7 @@ static void SlSaveChunks()
|
||||||
*/
|
*/
|
||||||
static const ChunkHandler *SlFindChunkHandler(uint32 id)
|
static const ChunkHandler *SlFindChunkHandler(uint32 id)
|
||||||
{
|
{
|
||||||
const ChunkHandler *ch;
|
FOR_ALL_CHUNK_HANDLERS(ch) if (ch->id == id) return ch;
|
||||||
const ChunkHandler *const *chsc;
|
|
||||||
for (chsc = _chunk_handlers; (ch = *chsc++) != NULL;) {
|
|
||||||
for (;;) {
|
|
||||||
if (ch->id == id) return ch;
|
|
||||||
if (ch->flags & CH_LAST) break;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,23 +1225,15 @@ static void SlLoadChunks()
|
||||||
/** Fix all pointers (convert index -> pointer) */
|
/** Fix all pointers (convert index -> pointer) */
|
||||||
static void SlFixPointers()
|
static void SlFixPointers()
|
||||||
{
|
{
|
||||||
const ChunkHandler *ch;
|
|
||||||
const ChunkHandler * const *chsc;
|
|
||||||
|
|
||||||
_sl.action = SLA_PTRS;
|
_sl.action = SLA_PTRS;
|
||||||
|
|
||||||
DEBUG(sl, 1, "Fixing pointers");
|
DEBUG(sl, 1, "Fixing pointers");
|
||||||
|
|
||||||
for (chsc = _chunk_handlers; (ch = *chsc++) != NULL;) {
|
FOR_ALL_CHUNK_HANDLERS(ch) {
|
||||||
while (true) {
|
|
||||||
if (ch->ptrs_proc != NULL) {
|
if (ch->ptrs_proc != NULL) {
|
||||||
DEBUG(sl, 2, "Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
DEBUG(sl, 2, "Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
||||||
ch->ptrs_proc();
|
ch->ptrs_proc();
|
||||||
}
|
}
|
||||||
if (ch->flags & CH_LAST)
|
|
||||||
break;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(sl, 1, "All pointers fixed");
|
DEBUG(sl, 1, "All pointers fixed");
|
||||||
|
|
Loading…
Reference in New Issue