update to latest version of storage library.

This commit is contained in:
Enno Rehling 2014-11-03 22:29:04 +01:00
parent f623133344
commit dbf60a7ce5
5 changed files with 99 additions and 77 deletions

View file

@ -18,6 +18,8 @@ without prior permission by the authors of Eressea.
#include <kernel/version.h>
#include <storage.h>
#include <stream.h>
#include <filestream.h>
#include <binarystore.h>
#include <math.h>
@ -48,7 +50,8 @@ static int tolua_storage_create(lua_State * L)
fwrite(&data->version, sizeof(int), 1, F);
fwrite(&n, sizeof(int), 1, F);
}
binstore_init(store, F);
fstream_init(&data->strm, F);
binstore_init(store, &data->strm);
tolua_pushusertype(L, (void *)data, TOLUA_CAST "storage");
return 1;
}
@ -74,7 +77,7 @@ static int tolua_storage_read_float(lua_State * L)
gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0);
float num;
READ_FLT(data->store, &num);
tolua_pushnumber(L, (lua_Number) num);
tolua_pushnumber(L, (lua_Number)num);
return 1;
}
@ -83,7 +86,7 @@ static int tolua_storage_read_int(lua_State * L)
gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0);
int num;
READ_INT(data->store, &num);
tolua_pushnumber(L, (lua_Number) num);
tolua_pushnumber(L, (lua_Number)num);
return 1;
}
@ -95,7 +98,8 @@ static int tolua_storage_write(lua_State * L)
double n;
if (modf(num, &n) == 0.0) {
WRITE_INT(data->store, (int)num);
} else {
}
else {
WRITE_FLT(data->store, (float)num);
}
}
@ -116,6 +120,7 @@ static int tolua_storage_close(lua_State * L)
{
gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0);
binstore_done(data->store);
fstream_done(&data->strm);
return 0;
}

View file

@ -5,6 +5,8 @@
#include "faction.h"
#include "unit.h"
#include "region.h"
#include <stream.h>
#include <filestream.h>
#include <storage.h>
#include <binarystore.h>
@ -19,9 +21,11 @@ static void test_group_readwrite(CuTest * tc)
ally *al;
storage store;
FILE *F;
stream strm;
F = fopen("test.dat", "wb");
binstore_init(&store, F);
fstream_init(&strm, F);
binstore_init(&store, &strm);
test_cleanup();
test_create_world();
f = test_create_faction(0);
@ -30,13 +34,16 @@ static void test_group_readwrite(CuTest * tc)
al->status = HELP_GIVE;
write_groups(&store, f);
binstore_done(&store);
fstream_done(&strm);
F = fopen("test.dat", "rb");
binstore_init(&store, F);
fstream_init(&strm, F);
binstore_init(&store, &strm);
f->groups = 0;
free_group(g);
read_groups(&store, f);
binstore_done(&store);
fstream_done(&strm);
CuAssertPtrNotNull(tc, f->groups);
CuAssertPtrNotNull(tc, f->groups->allies);

View file

@ -70,6 +70,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/umlaut.h>
#include <util/unicode.h>
#include <stream.h>
#include <filestream.h>
#include <storage.h>
#include <binarystore.h>
@ -1457,6 +1459,7 @@ int readgame(const char *filename, int backup)
const struct building_type *bt_lighthouse = bt_find("lighthouse");
gamedata gdata = { 0 };
storage store;
stream strm;
FILE *F;
init_locales();
@ -1482,7 +1485,8 @@ int readgame(const char *filename, int backup)
assert(gdata.version <= RELEASE_VERSION || !"unsupported data format");
gdata.encoding = enc_gamedata;
binstore_init(&store, F);
fstream_init(&strm, F);
binstore_init(&store, &strm);
gdata.store = &store;
global.data_version = gdata.version; /* HACK: attribute::read does not have access to gamedata, only storage */
@ -1733,7 +1737,7 @@ int readgame(const char *filename, int backup)
read_borders(&store);
binstore_done(&store);
fstream_done(&strm);
/* Unaufgeloeste Zeiger initialisieren */
log_printf(stdout, "fixing unresolved references.\n");
resolve();
@ -1797,6 +1801,7 @@ int writegame(const char *filename)
char path[MAX_PATH];
gamedata gdata;
storage store;
stream strm;
FILE *F;
clear_monster_orders();
@ -1826,7 +1831,8 @@ int writegame(const char *filename)
fwrite(&gdata.version, sizeof(int), 1, F);
fwrite(&n, sizeof(int), 1, F);
binstore_init(&store, F);
fstream_init(&strm, F);
binstore_init(&store, &strm);
/* globale Variablen */
@ -1942,6 +1948,7 @@ int writegame(const char *filename)
WRITE_SECTION(&store);
binstore_done(&store);
fstream_done(&strm);
log_printf(stdout, "\nOk.\n");
return 0;

View file

@ -18,6 +18,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_KRNL_SAVE
#define H_KRNL_SAVE
#include <stream.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -31,6 +33,7 @@ extern "C" {
typedef struct gamedata {
struct storage *store;
stream strm;
int version;
int encoding;
} gamedata;

@ -1 +1 @@
Subproject commit c6103e59c0938b173c0e08a852ff1cbbc4e284e3
Subproject commit 5f0b7095d42209762c9eac73c866c614018b440d