From 63e97754fbf907cfefd277087bfbac5e0d4434e8 Mon Sep 17 00:00:00 2001 From: truelight Date: Thu, 6 Jan 2005 22:31:58 +0000 Subject: (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries (in prepare of dynamic arrays): - DEREF_XXX is changed into GetXXX - All direct call are directed via GetXXX - struct Industry has now an index-field - ENUM'd some stuff - Replaced home built loops with FOR_ALL_XXX - Added _stations_size, _vehicles_size, ... which gives the length of the array (which will be dynamic in the near future) - Changed lengtof(XXX) to _XXX_size (e.g. _stations_size) - Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX) - Made the sort-functions of all 4 dynamic - Made all 4 Initialize functions more of the same - Some minor tab-fixing and stuff (tnx to Tron for proof-reading my 100kb patch ;)) Note for all: please do NOT directly call _stations, _vehicles, _towns and _industries, but use the right wrapper to access them. Thank you. Ps: please also do not use 'v++', where v is of type Vehicle *. --- ttd.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'ttd.c') diff --git a/ttd.c b/ttd.c index 8d3955a90..61680c112 100644 --- a/ttd.c +++ b/ttd.c @@ -482,6 +482,35 @@ void ParseResolution(int res[2], char *s) res[1] = strtoul(t + 1, NULL, 0); } +static void InitializeDynamicVariables(void) +{ + /* Dynamic stuff needs to be initialized somewhere... */ + _stations_size = lengthof(_stations); + _station_sort = NULL; + + _vehicles_size = lengthof(_vehicles); + _vehicle_sort = NULL; + + _towns_size = lengthof(_towns); + _town_sort = NULL; + + _industries_size = lengthof(_industries); + _industry_sort = NULL; +} + +static void UnInitializeDynamicVariables(void) +{ + /* Dynamic stuff needs to be free'd somewhere... */ + free(_station_sort); + + free(_vehicle_sort); + + free(_town_sort); + + free(_industry_sort); +} + + void LoadIntroGame() { char filename[256]; @@ -640,6 +669,9 @@ int ttd_main(int argc, char* argv[]) // initialize airport state machines InitializeAirports(); + /* initialize all variables that are allocated dynamically */ + InitializeDynamicVariables(); + // Sample catalogue DEBUG(misc, 1) ("Loading sound effects..."); _os_version = GetOSVersion(); @@ -721,6 +753,9 @@ int ttd_main(int argc, char* argv[]) // uninitialize airport state machines UnInitializeAirports(); + /* uninitialize variables that are allocated dynamic */ + UnInitializeDynamicVariables(); + return 0; } -- cgit v1.2.3-54-g00ecf