Changeset - r14755:86b8e81d785d
[Not reviewed]
master
0 6 0
yexo - 14 years ago 2010-03-06 15:38:13
yexo@openttd.org
(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
6 files changed with 56 insertions and 107 deletions:
0 comments (0 inline, 0 general)
src/airport.cpp
Show inline comments
 
@@ -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,7 +98,27 @@ void InitializeAirports()
 
		0
 
	);
 

	
 
	_intercontinental_airport = new AirportFTAClass(
 
static AirportFTAClass _airportfta_commuter(
 
		_airport_moving_data_commuter,
 
		_airport_terminal_commuter,
 
		_airport_helipad_commuter,
 
		_airport_entries_commuter,
 
		AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
 
		_airport_fta_commuter,
 
		0
 
	);
 

	
 
static AirportFTAClass _airportfta_helidepot(
 
		_airport_moving_data_helidepot,
 
		NULL,
 
		_airport_helipad_helidepot,
 
		_airport_entries_helidepot,
 
		AirportFTAClass::HELICOPTERS,
 
		_airport_fta_helidepot,
 
		0
 
	);
 

	
 
static AirportFTAClass _airportfta_intercontinental(
 
		_airport_moving_data_intercontinental,
 
		_airport_terminal_intercontinental,
 
		_airport_helipad_intercontinental,
 
@@ -104,47 +128,7 @@ void InitializeAirports()
 
		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(
 
		_airport_moving_data_commuter,
 
		_airport_terminal_commuter,
 
		_airport_helipad_commuter,
 
		_airport_entries_commuter,
 
		AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
 
		_airport_fta_commuter,
 
		0
 
	);
 

	
 
	_heli_depot = new AirportFTAClass(
 
		_airport_moving_data_helidepot,
 
		NULL,
 
		_airport_helipad_helidepot,
 
		_airport_entries_helidepot,
 
		AirportFTAClass::HELICOPTERS,
 
		_airport_fta_helidepot,
 
		0
 
	);
 

	
 
	_heli_station = new AirportFTAClass(
 
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 nofelem
 

	
 
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;
 
}
src/airport.h
Show inline comments
 
@@ -185,8 +185,6 @@ struct AirportFTA {
 
	byte heading;            ///< heading (current orders), guiding an airplane to its target on an airport
 
};
 

	
 
void InitializeAirports();
 
void UnInitializeAirports();
 
const AirportFTAClass *GetAirport(const byte airport_type);
 

	
 
extern const byte * const _airport_sections[];
src/newgrf_airport.cpp
Show inline comments
 
@@ -20,7 +20,7 @@
 

	
 
static AirportClass _airport_classes[APC_MAX];
 

	
 
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false};
 
AirportSpec AirportSpec::dummy = {NULL, NULL, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false};
 

	
 
AirportSpec AirportSpec::specs[NUM_AIRPORTS];
 

	
src/newgrf_airport.h
Show inline comments
 
@@ -49,6 +49,7 @@ enum TTDPAirportType {
 
 * Defines the data structure for an airport.
 
 */
 
struct AirportSpec {
 
	const struct AirportFTAClass *fsm;     ///< the finite statemachine for the default airports
 
	const AirportTileTable * const *table; ///< list of the tiles composing the airport
 
	const TileIndexDiffC *depot_table;     ///< gives the position of the depots on the airports
 
	byte nof_depots;                       ///< the number of depots in this airport
src/openttd.cpp
Show inline comments
 
@@ -333,9 +333,6 @@ static void ShutdownGame()
 
	/* stop the AI */
 
	AI::Uninitialize(false);
 

	
 
	/* Uninitialize airport state machines */
 
	UnInitializeAirports();
 

	
 
	/* Uninitialize variables that are allocated dynamically */
 
	GamelogReset();
 
	_town_pool.CleanPool();
 
@@ -605,9 +602,6 @@ int ttd_main(int argc, char *argv[])
 
	/* initialize screenshot formats */
 
	InitializeScreenshotFormats();
 

	
 
	/* initialize airport state machines */
 
	InitializeAirports();
 

	
 
	/* initialize all variables that are allocated dynamically */
 
	InitializeDynamicVariables();
 

	
src/table/airport_defaults.h
Show inline comments
 
@@ -377,16 +377,16 @@ static AirportTileTable *_tile_table_hel
 
#undef MKEND
 

	
 
/** General AirportSpec definition. */
 
#define AS_GENERIC(att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, enabled) \
 
	{att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled}
 
#define AS_GENERIC(fsm, att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, enabled) \
 
	{fsm, att, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled}
 

	
 
/** AirportSpec definition for airports without any depot. */
 
#define AS_ND(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id, name) \
 
	AS_GENERIC(_tile_table_##ap_name, NULL, 0, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, true)
 
	AS_GENERIC(&_airportfta_##ap_name, _tile_table_##ap_name, NULL, 0, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, true)
 

	
 
/** AirportSpec definition for airports with at least one depot. */
 
#define AS(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id, name) \
 
	AS_GENERIC(_tile_table_##ap_name, _airport_depots_##ap_name, lengthof(_airport_depots_##ap_name), size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, true)
 
	AS_GENERIC(&_airportfta_##ap_name, _tile_table_##ap_name, _airport_depots_##ap_name, lengthof(_airport_depots_##ap_name), size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, true)
 

	
 
/* The helidepot and helistation have ATP_TTDP_SMALL because they are at ground level */
 
extern const AirportSpec _origin_airport_specs[] = {
 
@@ -399,7 +399,7 @@ extern const AirportSpec _origin_airport
 
	AS(helidepot, 2, 2, 1976, MAX_YEAR, 4, 2, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELIDEPOT),
 
	AS(intercontinental, 9, 11, 2002, MAX_YEAR, 10, 25, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERCONTINENTAL),
 
	AS(helistation, 4, 2, 1980, MAX_YEAR, 4, 3, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELISTATION),
 
	AS_GENERIC(NULL, NULL, 0, 1, 1, 0, 4, 0, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, false),
 
	AS_GENERIC(&_airportfta_oilrig, NULL, NULL, 0, 1, 1, 0, 4, 0, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, false),
 
};
 

	
 
assert_compile(NUM_AIRPORTS == lengthof(_origin_airport_specs));
0 comments (0 inline, 0 general)