changeset 15597:df4f8bc7d432 draft

(svn r20257) -Codechange: unify some node handling code and don't require a single root node
author rubidium <rubidium@openttd.org>
date Sat, 31 Jul 2010 12:05:41 +0000
parents 87719b9a4a5b
children b5da2954ec59
files src/newgrf.cpp
diffstat 1 files changed, 15 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6108,7 +6108,7 @@
 };
 
 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 @@
 		}
 		_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 @@
 				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 @@
 	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' */