summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-17 20:38:05 +0000
committerrubidium <rubidium@openttd.org>2009-05-17 20:38:05 +0000
commit10406e8ad668e230eaeac4a969dca367da1d9bd8 (patch)
tree7a4b64aeaf764e69e1360db47b1d42bd5db3c0a7 /src/saveload
parent543cc6b75eac3dc8864c21ed65707e1affa2e78f (diff)
downloadopenttd-10406e8ad668e230eaeac4a969dca367da1d9bd8.tar.xz
(svn r16346) -Codechange: don't exploit the pool system in the way done for the saveload pool; it makes writing replacements unnecessarily difficult. And now we've got SmallVector that does more than enough for saving with less lines of 'interface' code.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/saveload.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index c0b6561c2..9389bdab2 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1266,34 +1266,34 @@ struct ThreadedSave {
CursorID cursor;
};
-/* A maximum size of of 128K * 500 = 64.000KB savegames */
-STATIC_OLD_POOL(Savegame, byte, 17, 500, NULL, NULL)
+/** Save in chunks of 128 KiB. */
+static const int MEMORY_CHUNK_SIZE = 128 * 1024;
+/** Memory allocation for storing savegames in memory. */
+static AutoFreeSmallVector<byte *, 16> _memory_savegame;
+
static ThreadedSave _ts;
-static bool InitMem()
+static void WriteMem(size_t size)
{
- _ts.count = 0;
-
- _Savegame_pool.CleanPool();
- _Savegame_pool.AddBlockToPool();
+ _ts.count += (uint)size;
- /* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */
- _sl.bufsize = GetSavegamePoolSize();
- _sl.buf = GetSavegame(_ts.count);
- return true;
+ _sl.buf = CallocT<byte>(MEMORY_CHUNK_SIZE);
+ *_memory_savegame.Append() = _sl.buf;
}
static void UnInitMem()
{
- _Savegame_pool.CleanPool();
+ _memory_savegame.Clear();
}
-static void WriteMem(size_t size)
+static bool InitMem()
{
- _ts.count += (uint)size;
- /* Allocate new block and new buffer-pointer */
- _Savegame_pool.AddBlockIfNeeded(_ts.count);
- _sl.buf = GetSavegame(_ts.count);
+ _ts.count = 0;
+ _sl.bufsize = MEMORY_CHUNK_SIZE;
+
+ UnInitMem();
+ WriteMem(0);
+ return true;
}
/********************************************
@@ -1675,7 +1675,7 @@ static void SaveFileError()
SaveFileDone();
}
-/** We have written the whole game into memory, _Savegame_pool, now find
+/** We have written the whole game into memory, _memory_savegame, now find
* and appropiate compressor and start writing to file.
*/
static SaveOrLoadResult SaveFileToDisk(bool threaded)
@@ -1696,18 +1696,17 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
{
uint i;
- uint count = 1 << Savegame_POOL_BLOCK_SIZE_BITS;
if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk");
- for (i = 0; i != _Savegame_pool.GetBlockCount() - 1; i++) {
- _sl.buf = _Savegame_pool.blocks[i];
- fmt->writer(count);
+ for (i = 0; i != _memory_savegame.Length() - 1; i++) {
+ _sl.buf = _memory_savegame[i];
+ fmt->writer(MEMORY_CHUNK_SIZE);
}
/* The last block is (almost) always not fully filled, so only write away
* as much data as it is in there */
- _sl.buf = _Savegame_pool.blocks[i];
- fmt->writer(_ts.count - (i * count));
+ _sl.buf = _memory_savegame[i];
+ fmt->writer(_ts.count % MEMORY_CHUNK_SIZE);
}
fmt->uninit_write();