(svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
authorpeter1138
Sat, 05 May 2007 10:47:35 +0000
changeset 7072 973b998c5cfe
parent 7071 80d45870637a
child 7073 72dc5a55e16b
(svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
src/newgrf.cpp
--- a/src/newgrf.cpp	Sat May 05 09:51:26 2007 +0000
+++ b/src/newgrf.cpp	Sat May 05 10:47:35 2007 +0000
@@ -1791,11 +1791,6 @@
 
 	EngineInfo *ei = NULL;
 
-	if (len == 1) {
-		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
-		return;
-	}
-
 	if (!check_length(len, 6, "FeatureChangeInfo")) return;
 	buf++;
 	uint8 feature  = grf_load_byte(&buf);
@@ -1879,11 +1874,6 @@
 /* Action 0x00 (GLS_SAFETYSCAN) */
 static void SafeChangeInfo(byte *buf, int len)
 {
-	if (len == 1) {
-		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
-		return;
-	}
-
 	if (!check_length(len, 6, "SafeChangeInfo")) return;
 	buf++;
 	uint8 feature  = grf_load_byte(&buf);
@@ -1909,11 +1899,6 @@
 {
 	byte *bufend = buf + len;
 
-	if (len == 1) {
-		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
-		return;
-	}
-
 	if (!check_length(len, 6, "InitChangeInfo")) return;
 	buf++;
 	uint8 feature  = grf_load_byte(&buf);
@@ -1954,11 +1939,6 @@
 {
 	byte *bufend = buf + len;
 
-	if (len == 1) {
-		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
-		return;
-	}
-
 	if (!check_length(len, 6, "InitChangeInfo")) return;
 	buf++;
 	uint8 feature  = grf_load_byte(&buf);
@@ -2055,6 +2035,20 @@
 	}
 }
 
+/* Action 0x01 (SKIP) */
+static void SkipAct1(byte *buf, int len)
+{
+	if (!check_length(len, 4, "SkipAct1")) return;
+	buf++;
+	grf_load_byte(&buf);
+	uint8 num_sets  = grf_load_byte(&buf);
+	uint16 num_ents = grf_load_extended(&buf);
+
+	_skip_sprites = num_sets * num_ents;
+
+	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
+}
+
 /* Helper function to either create a callback or link to a previously
  * defined spritegroup. */
 static const SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
@@ -4614,8 +4608,8 @@
 	 * In other stages we skip action 0x10 since it's already dealt with. */
 	static const SpecialSpriteHandler handlers[][GLS_END] = {
 		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       InitChangeInfo, ReserveChangeInfo, FeatureChangeInfo, },
-		/* 0x01 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              NewSpriteSet, },
-		/* 0x02 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              NewSpriteGroup, },
+		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
+		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
 		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
 		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
 		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },