(svn r4483) - NewGRF: Dynamically allocate memory for 'real' spritegroups. This removes the limit of 16 loading/unloading states, although will result in less memory usage as most of the time the full fixed allocation wasn't used.
authorpeter1138
Thu, 20 Apr 2006 13:33:40 +0000
changeset 3593 7ec7431c7a94
parent 3592 f4f185314df8
child 3594 3c4e4feea80a
(svn r4483) - NewGRF: Dynamically allocate memory for 'real' spritegroups. This removes the limit of 16 loading/unloading states, although will result in less memory usage as most of the time the full fixed allocation wasn't used.
newgrf.c
sprite.c
sprite.h
--- a/newgrf.c	Thu Apr 20 08:33:42 2006 +0000
+++ b/newgrf.c	Thu Apr 20 13:33:40 2006 +0000
@@ -1480,15 +1480,6 @@
 	if (_cur_grffile->first_spriteset == 0)
 		_cur_grffile->first_spriteset = _cur_grffile->spriteset_start;
 
-	if (numloaded > 16) {
-		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
-		numloaded = 16;
-	}
-	if (numloading > 16) {
-		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
-		numloading = 16;
-	}
-
 	group = calloc(1, sizeof(*group));
 	group->type = SGT_REAL;
 	rg = &group->g.real;
@@ -1497,6 +1488,9 @@
 	rg->loaded_count  = numloaded;
 	rg->loading_count = numloading;
 
+	rg->loaded  = calloc(rg->loaded_count,  sizeof(*rg->loaded));
+	rg->loading = calloc(rg->loading_count, sizeof(*rg->loading));
+
 	DEBUG(grf, 6) ("NewSpriteGroup: New SpriteGroup 0x%02hhx, %u views, %u loaded, %u loading, sprites %u - %u",
 			setid, rg->sprites_per_set, rg->loaded_count, rg->loading_count,
 			_cur_grffile->spriteset_start - _cur_grffile->sprite_offset,
--- a/sprite.c	Thu Apr 20 08:33:42 2006 +0000
+++ b/sprite.c	Thu Apr 20 13:33:40 2006 +0000
@@ -132,6 +132,8 @@
 			for (i = 0; i < rsg->loaded_count; i++) {
 				if (rsg->loaded[i] != NULL) UnloadSpriteGroup(&rsg->loaded[i]);
 			}
+			free(group->g.real.loaded);
+			free(group->g.real.loading);
 			free(group);
 			return;
 		}
--- a/sprite.h	Thu Apr 20 08:33:42 2006 +0000
+++ b/sprite.h	Thu Apr 20 13:33:40 2006 +0000
@@ -32,8 +32,6 @@
 typedef struct SpriteGroup SpriteGroup;
 
 typedef struct RealSpriteGroup {
-	// XXX: Would anyone ever need more than 16 spritesets? Maybe we should
-	// use even less, now we take whole 8kb for custom sprites table, oh my!
 	byte sprites_per_set; // means number of directions - 4 or 8
 
 	// Loaded = in motion, loading = not moving
@@ -43,10 +41,10 @@
 	// with small amount of cargo whilst loading is for stations with a lot
 	// of da stuff.
 
-	byte loaded_count;
-	SpriteGroup *loaded[16]; // sprite ids
-	byte loading_count;
-	SpriteGroup *loading[16]; // sprite ids
+	byte loaded_count;     ///< Number of loaded groups
+	SpriteGroup **loaded;  ///< List of loaded groups (can be SpriteIDs or Callback results)
+	byte loading_count;    ///< Number of loading groups
+	SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
 } RealSpriteGroup;
 
 /* Shared by deterministic and random groups. */