From 20e05f878cc9110d5a7540b6042a04cf2b2d5d5e Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 6 Mar 2010 15:38:13 +0000 Subject: (svn r19353) -Codechange: use static objects for the airport statemachines instead of new/delete at the start/end of the game -Codechange: store the fta in AirportSpec --- src/airport.cpp | 124 ++++++++++++++++++-------------------------------------- 1 file changed, 40 insertions(+), 84 deletions(-) (limited to 'src/airport.cpp') diff --git a/src/airport.cpp b/src/airport.cpp index a699cea20..00ef18137 100644 --- a/src/airport.cpp +++ b/src/airport.cpp @@ -20,7 +20,6 @@ #include "newgrf_airport.h" #include "table/strings.h" #include "table/airporttile_ids.h" -#include "table/airport_defaults.h" /* Uncomment this to print out a full report of the airport-structure * You should either use @@ -29,22 +28,7 @@ * - false: give a summarized report which only shows current and next position */ //#define DEBUG_AIRPORT false -static AirportFTAClass *_dummy_airport; -static AirportFTAClass *_country_airport; -static AirportFTAClass *_city_airport; -static AirportFTAClass *_oilrig; -static AirportFTAClass *_heliport; -static AirportFTAClass *_metropolitan_airport; -static AirportFTAClass *_international_airport; -static AirportFTAClass *_commuter_airport; -static AirportFTAClass *_heli_depot; -static AirportFTAClass *_intercontinental_airport; -static AirportFTAClass *_heli_station; - - -void InitializeAirports() -{ - _dummy_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_dummy( _airport_moving_data_dummy, NULL, NULL, @@ -54,7 +38,7 @@ void InitializeAirports() 0 ); - _country_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_country( _airport_moving_data_country, _airport_terminal_country, NULL, @@ -64,7 +48,7 @@ void InitializeAirports() 0 ); - _city_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_city( _airport_moving_data_town, _airport_terminal_city, NULL, @@ -74,7 +58,27 @@ void InitializeAirports() 0 ); - _metropolitan_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_oilrig( + _airport_moving_data_oilrig, + NULL, + _airport_helipad_heliport_oilrig, + _airport_entries_heliport_oilrig, + AirportFTAClass::HELICOPTERS, + _airport_fta_heliport_oilrig, + 54 + ); + +static AirportFTAClass _airportfta_heliport( + _airport_moving_data_heliport, + NULL, + _airport_helipad_heliport_oilrig, + _airport_entries_heliport_oilrig, + AirportFTAClass::HELICOPTERS, + _airport_fta_heliport_oilrig, + 60 + ); + +static AirportFTAClass _airportfta_metropolitan( _airport_moving_data_metropolitan, _airport_terminal_metropolitan, NULL, @@ -84,7 +88,7 @@ void InitializeAirports() 0 ); - _international_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_international( _airport_moving_data_international, _airport_terminal_international, _airport_helipad_international, @@ -94,37 +98,7 @@ void InitializeAirports() 0 ); - _intercontinental_airport = new AirportFTAClass( - _airport_moving_data_intercontinental, - _airport_terminal_intercontinental, - _airport_helipad_intercontinental, - _airport_entries_intercontinental, - AirportFTAClass::ALL, - _airport_fta_intercontinental, - 0 - ); - - _heliport = new AirportFTAClass( - _airport_moving_data_heliport, - NULL, - _airport_helipad_heliport_oilrig, - _airport_entries_heliport_oilrig, - AirportFTAClass::HELICOPTERS, - _airport_fta_heliport_oilrig, - 60 - ); - - _oilrig = new AirportFTAClass( - _airport_moving_data_oilrig, - NULL, - _airport_helipad_heliport_oilrig, - _airport_entries_heliport_oilrig, - AirportFTAClass::HELICOPTERS, - _airport_fta_heliport_oilrig, - 54 - ); - - _commuter_airport = new AirportFTAClass( +static AirportFTAClass _airportfta_commuter( _airport_moving_data_commuter, _airport_terminal_commuter, _airport_helipad_commuter, @@ -134,7 +108,7 @@ void InitializeAirports() 0 ); - _heli_depot = new AirportFTAClass( +static AirportFTAClass _airportfta_helidepot( _airport_moving_data_helidepot, NULL, _airport_helipad_helidepot, @@ -144,7 +118,17 @@ void InitializeAirports() 0 ); - _heli_station = new AirportFTAClass( +static AirportFTAClass _airportfta_intercontinental( + _airport_moving_data_intercontinental, + _airport_terminal_intercontinental, + _airport_helipad_intercontinental, + _airport_entries_intercontinental, + AirportFTAClass::ALL, + _airport_fta_intercontinental, + 0 + ); + +static AirportFTAClass _airportfta_helistation( _airport_moving_data_helistation, NULL, _airport_helipad_helistation, @@ -153,21 +137,8 @@ void InitializeAirports() _airport_fta_helistation, 0 ); -} -void UnInitializeAirports() -{ - delete _dummy_airport; - delete _country_airport; - delete _city_airport; - delete _heliport; - delete _metropolitan_airport; - delete _international_airport; - delete _commuter_airport; - delete _heli_depot; - delete _intercontinental_airport; - delete _heli_station; -} +#include "table/airport_defaults.h" static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA); @@ -407,20 +378,5 @@ static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool ful const AirportFTAClass *GetAirport(const byte airport_type) { - /* FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code - * needs constant change if more airports are added */ - switch (airport_type) { - default: NOT_REACHED(); - case AT_SMALL: return _country_airport; - case AT_LARGE: return _city_airport; - case AT_METROPOLITAN: return _metropolitan_airport; - case AT_HELIPORT: return _heliport; - case AT_OILRIG: return _oilrig; - case AT_INTERNATIONAL: return _international_airport; - case AT_COMMUTER: return _commuter_airport; - case AT_HELIDEPOT: return _heli_depot; - case AT_INTERCON: return _intercontinental_airport; - case AT_HELISTATION: return _heli_station; - case AT_DUMMY: return _dummy_airport; - } + return AirportSpec::Get(airport_type)->fsm; } -- cgit v1.2.3-54-g00ecf