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
 
@@ -17,160 +17,131 @@
 
#include "core/alloc_func.hpp"
 
#include "date_func.h"
 
#include "settings_type.h"
 
#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
 
 * - true: full-report, print out every state and choice with string-names
 
 * OR
 
 * - 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,
 
		_airport_entries_dummy,
 
		AirportFTAClass::ALL,
 
		_airport_fta_dummy,
 
		0
 
	);
 

	
 
	_country_airport = new AirportFTAClass(
 
static AirportFTAClass _airportfta_country(
 
		_airport_moving_data_country,
 
		_airport_terminal_country,
 
		NULL,
 
		_airport_entries_country,
 
		AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
 
		_airport_fta_country,
 
		0
 
	);
 

	
 
	_city_airport = new AirportFTAClass(
 
static AirportFTAClass _airportfta_city(
 
		_airport_moving_data_town,
 
		_airport_terminal_city,
 
		NULL,
 
		_airport_entries_city,
 
		AirportFTAClass::ALL,
 
		_airport_fta_city,
 
		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,
 
		_airport_entries_metropolitan,
 
		AirportFTAClass::ALL,
 
		_airport_fta_metropolitan,
 
		0
 
	);
 

	
 
	_international_airport = new AirportFTAClass(
 
static AirportFTAClass _airportfta_international(
 
		_airport_moving_data_international,
 
		_airport_terminal_international,
 
		_airport_helipad_international,
 
		_airport_entries_international,
 
		AirportFTAClass::ALL,
 
		_airport_fta_international,
 
		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,
 
		_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(
 
		_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,
 
		_airport_entries_helistation,
 
		AirportFTAClass::HELICOPTERS,
 
		_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);
 
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA);
 
static byte AirportGetTerminalCount(const byte *terminals, byte *groups);
 
static byte AirportTestFTA(uint nofelements, const AirportFTA *layout, const byte *terminals);
 
@@ -404,23 +375,8 @@ static void AirportPrintOut(uint nofelem
 
	}
 
}
 
#endif
 

	
 
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
 
@@ -182,13 +182,11 @@ struct AirportFTA {
 
	uint64 block;            ///< 64 bit blocks (st->airport_flags), should be enough for the most complex airports
 
	byte position;           ///< the position that an airplane is at
 
	byte next_position;      ///< next position from this position
 
	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[];
 

	
 
#endif /* AIRPORT_H */
src/newgrf_airport.cpp
Show inline comments
 
@@ -17,13 +17,13 @@
 
#include "core/alloc_type.hpp"
 
#include "newgrf.h"
 
#include "table/strings.h"
 

	
 
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];
 

	
 
/**
 
 * Retrieve airport spec for the given airport. If an override is available
 
 *  it is returned.
src/newgrf_airport.h
Show inline comments
 
@@ -46,12 +46,13 @@ 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
 
	byte size_x;                           ///< size of airport in x direction
 
	byte size_y;                           ///< size of airport in y direction
 
	byte noise_level;                      ///< noise that this airport generates
src/openttd.cpp
Show inline comments
 
@@ -330,15 +330,12 @@ static void ShutdownGame()
 

	
 
	UnInitWindowSystem();
 

	
 
	/* stop the AI */
 
	AI::Uninitialize(false);
 

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

	
 
	/* Uninitialize variables that are allocated dynamically */
 
	GamelogReset();
 
	_town_pool.CleanPool();
 
	_industry_pool.CleanPool();
 
	_station_pool.CleanPool();
 
	_roadstop_pool.CleanPool();
 
@@ -602,15 +599,12 @@ int ttd_main(int argc, char *argv[])
 
	/* enumerate language files */
 
	InitializeLanguagePacks();
 

	
 
	/* initialize screenshot formats */
 
	InitializeScreenshotFormats();
 

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

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

	
 
	/* Initialize FreeType */
 
	InitFreeType();
 

	
src/table/airport_defaults.h
Show inline comments
 
@@ -374,35 +374,35 @@ static AirportTileTable *_tile_table_hel
 
};
 

	
 
#undef MK
 
#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[] = {
 
	AS(country, 4, 3, 0, 1959, 4, 3, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_SMALL),
 
	AS(city, 6, 6, 1955, MAX_YEAR, 5, 5, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_CITY),
 
	AS_ND(heliport, 1, 1, 1963, MAX_YEAR, 4, 1, ATP_TTDP_HELIPORT, APC_HELIPORT, STR_AIRPORT_HELIPORT),
 
	AS(metropolitan, 6, 6, 1980, MAX_YEAR, 6, 8, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_METRO),
 
	AS(international, 7, 7, 1990, MAX_YEAR, 8, 17, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERNATIONAL),
 
	AS(commuter, 5, 4, 1983, MAX_YEAR, 4, 4, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_COMMUTER),
 
	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));
 

	
 
#undef AS
 
#undef AS_ND
0 comments (0 inline, 0 general)