summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-04-11 10:05:52 +0000
committerpeter1138 <peter1138@openttd.org>2006-04-11 10:05:52 +0000
commit5e345e0e7f49b17a56b7538bffcd6aa982d0f06d (patch)
tree8c858faf9fc6315a46b67866d8e2ad36afb77dfa
parentd38964e49ab78612bbf44b876c7da6dee789b377 (diff)
downloadopenttd-5e345e0e7f49b17a56b7538bffcd6aa982d0f06d.tar.xz
(svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
-rw-r--r--newgrf.c20
-rw-r--r--newgrf.h3
2 files changed, 18 insertions, 5 deletions
diff --git a/newgrf.c b/newgrf.c
index cffb88c9c..8b6ff2c58 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -762,10 +762,17 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
int i;
int ret = 0;
- /* This is one single huge TODO. It doesn't handle anything more than
- * just waypoints for now. */
+ /* Allocate station specs if necessary */
+ if (_cur_grffile->num_stations < stid + numinfo) {
+ _cur_grffile->stations = realloc(_cur_grffile->stations, (stid + numinfo) * sizeof(*_cur_grffile->stations))
+;
+
+ while (_cur_grffile->num_stations < stid + numinfo) {
+ memset(&_cur_grffile->stations[_cur_grffile->num_stations], 0, sizeof(*_cur_grffile->stations));
+ _cur_grffile->num_stations++;
+ }
+ }
- //printf("sci %d %d [0x%02x]\n", stid, numinfo, prop);
switch (prop) {
case 0x08:
{ /* Class ID */
@@ -2357,7 +2364,7 @@ static void ResetCustomStations(void)
CargoID c;
for (file = _first_grffile; file != NULL; file = file->next) {
- for (i = 0; i < lengthof(file->stations); i++) {
+ for (i = 0; i < file->num_stations; i++) {
if (file->stations[i].grfid != file->grfid) continue;
// TODO: Release renderdata, platforms and layouts
@@ -2368,6 +2375,11 @@ static void ResetCustomStations(void)
UnloadSpriteGroup(&file->stations[i].spritegroup[c]);
}
}
+
+ /* Free and reset the station data */
+ free(file->stations);
+ file->stations = NULL;
+ file->num_stations = 0;
}
}
diff --git a/newgrf.h b/newgrf.h
index a5aeb49e6..6739d23d8 100644
--- a/newgrf.h
+++ b/newgrf.h
@@ -34,7 +34,8 @@ struct GRFFile {
int spritegroups_count;
SpriteGroup **spritegroups;
- StationSpec stations[256];
+ uint num_stations;
+ StationSpec *stations;
uint32 param[0x80];
uint param_end; /// one more than the highest set parameter