summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-07-31 12:05:41 +0000
committerrubidium <rubidium@openttd.org>2010-07-31 12:05:41 +0000
commit9c241135f2d035c9e02b72c433517eb77d58c502 (patch)
tree43613cf536b4a88717971ca9fd7922ff9261e561
parentd9bc65cdd873f2ea438a0d91d243766a72ba5ff7 (diff)
downloadopenttd-9c241135f2d035c9e02b72c433517eb77d58c502.tar.xz
(svn r20257) -Codechange: unify some node handling code and don't require a single root node
-rw-r--r--src/newgrf.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 9a6fe39a8..bb5f63660 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6108,7 +6108,7 @@ struct AllowedSubtags {
};
static bool SkipUnknownInfo(ByteReader *buf, byte type);
-static bool HandleNode(byte type, uint32 id, ByteReader *buf, AllowedSubtags *tags);
+static bool HandleNodes(ByteReader *buf, AllowedSubtags *tags);
/**
* Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names
@@ -6179,12 +6179,7 @@ static bool HandleParameterInfo(ByteReader *buf)
}
_cur_parameter = _cur_grfconfig->param_info[id];
/* Read all parameter-data and process each node. */
- byte sub_type = buf->ReadByte();
- while (sub_type != 0) {
- uint32 sub_id = buf->ReadDWord();
- if (!HandleNode(sub_type, sub_id, buf, _tags_parameters)) return false;
- sub_type = buf->ReadByte();
- }
+ if (!HandleNodes(buf, _tags_parameters)) return false;
type = buf->ReadByte();
}
return true;
@@ -6265,13 +6260,7 @@ static bool HandleNode(byte type, uint32 id, ByteReader *buf, AllowedSubtags sub
if (tag->handler.call_handler) {
return tag->handler.u.branch(buf);
}
- byte new_type = buf->ReadByte();
- while (new_type != 0) {
- uint32 new_id = buf->ReadDWord();
- if (!HandleNode(new_type, new_id, buf, tag->handler.u.subtags)) return false;
- new_type = buf->ReadByte();
- }
- return true;
+ return HandleNodes(buf, tag->handler.u.subtags);
}
}
}
@@ -6279,14 +6268,22 @@ static bool HandleNode(byte type, uint32 id, ByteReader *buf, AllowedSubtags sub
return SkipUnknownInfo(buf, type);
}
+static bool HandleNodes(ByteReader *buf, AllowedSubtags subtags[])
+{
+ byte type = buf->ReadByte();
+ while (type != 0) {
+ uint32 id = buf->ReadDWord();
+ if (!HandleNode(type, id, buf, subtags)) return false;
+ type = buf->ReadByte();
+ }
+ return true;
+}
+
/* Action 0x14 */
static void StaticGRFInfo(ByteReader *buf)
{
/* <14> <type> <id> <text/data...> */
-
- byte type = buf->ReadByte();
- uint32 id = buf->ReadDWord();
- HandleNode(type, id, buf, _tags_root);
+ HandleNodes(buf, _tags_root);
}
/* 'Action 0xFF' */