Changeset - r4985:3022c22ae6ea
[Not reviewed]
master
0 1 0
tron - 18 years ago 2006-10-28 12:07:32
tron@openttd.org
(svn r6988) Remove a layer of indirection when using the Savegame pool
1 file changed with 11 insertions and 14 deletions:
saveload.c
11
14
0 comments (0 inline, 0 general)
saveload.c
Show inline comments
 
@@ -1008,49 +1008,46 @@ static void UninitNoComp(void)
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "gfx.h"
 
#include "gui.h"
 

	
 
typedef struct ThreadedSave {
 
	MemoryPool *save;
 
	uint count;
 
	bool ff_state;
 
	bool saveinprogress;
 
	CursorID cursor;
 
} ThreadedSave;
 

	
 
/* A maximum size of of 128K * 500 = 64.000KB savegames */
 
STATIC_POOL(Savegame, byte, 17, 500, NULL, NULL)
 
static ThreadedSave _ts;
 

	
 
static bool InitMem(void)
 
{
 
	_ts.save = &_Savegame_pool;
 
	_ts.count = 0;
 

	
 
	CleanPool(_ts.save);
 
	AddBlockToPool(_ts.save);
 
	CleanPool(&_Savegame_pool);
 
	AddBlockToPool(&_Savegame_pool);
 

	
 
	/* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */
 
	_sl.bufsize = _ts.save->total_items;
 
	_sl.buf = (byte*)GetItemFromPool(_ts.save, _ts.count);
 
	_sl.bufsize = GetSavegamePoolSize();
 
	_sl.buf = GetSavegame(_ts.count);
 
	return true;
 
}
 

	
 
static void UnInitMem(void)
 
{
 
	CleanPool(_ts.save);
 
	_ts.save = NULL;
 
	CleanPool(&_Savegame_pool);
 
}
 

	
 
static void WriteMem(uint size)
 
{
 
	_ts.count += size;
 
	/* Allocate new block and new buffer-pointer */
 
	AddBlockIfNeeded(_ts.save, _ts.count);
 
	_sl.buf = (byte*)GetItemFromPool(_ts.save, _ts.count);
 
	AddBlockIfNeeded(&_Savegame_pool, _ts.count);
 
	_sl.buf = GetSavegame(_ts.count);
 
}
 

	
 
//********************************************
 
//********** START OF ZLIB CODE **************
 
//********************************************
 

	
 
@@ -1420,23 +1417,23 @@ static void* SaveFileToDisk(void *arg)
 
	if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError("file write failed");
 

	
 
	if (!fmt->init_write()) SlError("cannot initialize compressor");
 

	
 
	{
 
		uint i;
 
		uint count = 1 << _ts.save->block_size_bits;
 
		uint count = 1 << Savegame_POOL_BLOCK_SIZE_BITS;
 

	
 
		assert(_ts.count == _sl.offs_base);
 
		for (i = 0; i != _ts.save->current_blocks - 1; i++) {
 
			_sl.buf = _ts.save->blocks[i];
 
		for (i = 0; i != _Savegame_pool.current_blocks - 1; i++) {
 
			_sl.buf = _Savegame_pool.blocks[i];
 
			fmt->writer(count);
 
		}
 

	
 
		/* The last block is (almost) always not fully filled, so only write away
 
		 * as much data as it is in there */
 
		_sl.buf = _ts.save->blocks[i];
 
		_sl.buf = _Savegame_pool.blocks[i];
 
		fmt->writer(_ts.count - (i * count));
 
	}
 

	
 
	fmt->uninit_write();
 
	assert(_ts.count == _sl.offs_base);
 
	GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
0 comments (0 inline, 0 general)