Merge branch 'master' into improved_breakdowns

This commit is contained in:
Jonathan G Rennison
2015-08-15 23:34:48 +01:00
200 changed files with 10552 additions and 3678 deletions

View File

@@ -16,6 +16,7 @@
#include "../fios.h"
#include "../gamelog_internal.h"
#include "../network/network.h"
#include "../network/network_func.h"
#include "../gfxinit.h"
#include "../viewport_func.h"
#include "../industry.h"
@@ -2983,18 +2984,20 @@ bool AfterLoadGame()
}
/*
* Only keep order-backups for network clients.
* Only keep order-backups for network clients (and when replaying).
* If we are a network server or not networking, then we just loaded a previously
* saved-by-server savegame. There are no clients with a backup, so clear it.
* Furthermore before savegame version 192 the actual content was always corrupt.
*/
if (!_networking || _network_server || IsSavegameVersionBefore(192)) {
#ifndef DEBUG_DUMP_COMMANDS
/* Note: We cannot use CleanPool since that skips part of the destructor
* and then leaks un-reachable Orders in the order pool. */
OrderBackup *ob;
FOR_ALL_ORDER_BACKUPS(ob) {
delete ob;
}
#endif
}

View File

@@ -48,21 +48,39 @@ static const SaveLoad _engine_desc[] = {
SLE_END()
};
static std::vector<Engine> _temp_engine;
static std::vector<Engine*> _temp_engine;
/**
* Allocate an Engine structure, but not using the pools.
* The allocated Engine must be freed using FreeEngine;
* @return Allocated engine.
*/
static Engine* CallocEngine()
{
uint8 *zero = CallocT<uint8>(sizeof(Engine));
Engine *engine = new (zero) Engine();
return engine;
}
/**
* Deallocate an Engine constructed by CallocEngine.
* @param e Engine to free.
*/
static void FreeEngine(Engine *e)
{
if (e != NULL) {
e->~Engine();
free(e);
}
}
Engine *GetTempDataEngine(EngineID index)
{
if (index < _temp_engine.size()) {
return &_temp_engine[index];
return _temp_engine[index];
} else if (index == _temp_engine.size()) {
uint8 zero[sizeof(Engine)];
memset(zero, 0, sizeof(zero));
Engine *engine = new (zero) Engine();
/* Adding 'engine' to the vector makes a shallow copy, so we do not want to destruct 'engine' */
_temp_engine.push_back(*engine);
return &_temp_engine[index];
_temp_engine.push_back(CallocEngine());
return _temp_engine[index];
} else {
NOT_REACHED();
}
@@ -127,6 +145,9 @@ void CopyTempEngineData()
}
/* Get rid of temporary data */
for (std::vector<Engine*>::iterator it = _temp_engine.begin(); it != _temp_engine.end(); ++it) {
FreeEngine(*it);
}
_temp_engine.clear();
}

View File

@@ -160,14 +160,14 @@ static void Save_ITBL()
/** Load industry-type build data. */
static void Load_ITBL()
{
int index;
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
index = SlIterateArray();
assert(index == i);
SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
_industry_builder.builddata[it].Reset();
}
int index;
while ((index = SlIterateArray()) != -1) {
if ((uint)index >= NUM_INDUSTRYTYPES) SlErrorCorrupt("Too many industry builder datas");
SlObject(_industry_builder.builddata + index, _industrytype_builder_desc);
}
index = SlIterateArray();
assert(index == -1);
}
extern const ChunkHandler _industry_chunk_handlers[] = {

View File

@@ -51,7 +51,7 @@ void Load_NewGRFMapping(OverrideManagerBase &mapping)
int index;
while ((index = SlIterateArray()) != -1) {
if ((uint)index >= max_id) break;
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
}
}

View File

@@ -1669,9 +1669,11 @@ static void SlLoadChunk(const ChunkHandler *ch)
case CH_ARRAY:
_sl.array_index = 0;
ch->load_proc();
if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
break;
case CH_SPARSE_ARRAY:
ch->load_proc();
if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
break;
default:
if ((m & 0xF) == CH_RIFF) {