From 9c88e406fd70d80d896b48a5b3d626e30f00decb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 15 Aug 2007 06:27:40 +0000 Subject: [PATCH] - .ini file ssettings for CRT debugging - quick alloc-optimization for resolve.c --- src/common/kernel/group.c | 3 ++- src/common/util/resolve.c | 51 +++++++++++++++++++++++++++------------ src/eressea/server.cpp | 23 ++++++++++++------ src/scripts/default.lua | 2 +- src/scripts/samples.lua | 6 +++-- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/common/kernel/group.c b/src/common/kernel/group.c index a9db5ab82..b6e7a85de 100644 --- a/src/common/kernel/group.c +++ b/src/common/kernel/group.c @@ -199,13 +199,14 @@ read_groups(FILE * F, faction * f) fscanf(F, "%s ", buf); aid.i = atoi36(buf); if (aid.i==0) break; - a = calloc(sizeof(ally), 1); + a = malloc(sizeof(ally)); *pa = a; pa = &a->next; fscanf(F, "%d ", &a->status); a->faction = findfaction(aid.i); if (!a->faction) ur_add(aid, (void**)&a->faction, resolve_faction); } + *pa = 0; if(global.data_version >= GROUPATTRIB_VERSION) { a_read(F, &g->attribs); } diff --git a/src/common/util/resolve.c b/src/common/util/resolve.c index 613b319ae..99509c21a 100644 --- a/src/common/util/resolve.c +++ b/src/common/util/resolve.c @@ -26,7 +26,6 @@ #include "variant.h" typedef struct unresolved { - struct unresolved * next; void ** ptrptr; /* pointer to the location where the unresolved object * should be, or NULL if special handling is required */ @@ -36,26 +35,46 @@ typedef struct unresolved { /* function to resolve the unknown object */ } unresolved; -unresolved * ur_list; +#define BLOCKSIZE 1024 +static unresolved * ur_list; +static unresolved * ur_begin; +static unresolved * ur_current; void -ur_add(variant data, void ** ptrptr, resolve_fun fun) { - unresolved * ur = malloc(sizeof(unresolved)); - ur->data = data; - ur->resolve = fun; - ur->ptrptr = ptrptr; - ur->next = ur_list; - ur_list = ur; +ur_add(variant data, void ** ptrptr, resolve_fun fun) +{ + if (ur_list==NULL) { + ur_list = malloc(BLOCKSIZE*sizeof(unresolved)); + ur_begin = ur_current = ur_list; + } + else if (ur_current-ur_begin==BLOCKSIZE-1) { + ur_begin = malloc(BLOCKSIZE*sizeof(unresolved)); + ur_current->data.v = ur_begin; + ur_current = ur_begin; + } + ur_current->data = data; + ur_current->resolve = fun; + ur_current->ptrptr = ptrptr; + + ++ur_current; + ur_current->resolve = NULL; + ur_current->data.v = NULL; } void resolve(void) { - while (ur_list) { - unresolved * ur = ur_list; - ur_list = ur->next; - if (ur->ptrptr) *ur->ptrptr = ur->resolve(ur->data); - else ur->resolve(ur->data); - free(ur); - } + unresolved * ur = ur_list; + while (ur) { + if (ur->resolve==NULL) { + ur = ur->data.v; + free(ur_list); + ur_list = ur; + continue; + } + if (ur->ptrptr) *ur->ptrptr = ur->resolve(ur->data); + else ur->resolve(ur->data); + ++ur; + } + ur_list = ur_begin = ur_current; } diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index b7ad67e71..cc81b566a 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -163,6 +163,7 @@ static boolean g_ignore_errors = false; static boolean opt_reportonly = false; static const char * luafile = NULL; static const char * script_path = "scripts"; +static int memdebug = 0; struct settings global = { "Eressea", /* gamename */ @@ -386,18 +387,22 @@ game_done(void) } #endif -#include "magic.h" - #define CRTDBG - #ifdef CRTDBG void init_crtdbg(void) { #if (defined(_MSC_VER)) int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - // flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF; - // flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */ + if (memdebug==1) { + flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */ + } else if (memdebug==2) { + flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_16_DF; + } else if (memdebug==3) { + flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_128_DF; + } else if (memdebug==4) { + flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF; + } _CrtSetDbgFlag(flags); #endif } @@ -608,6 +613,7 @@ load_inifile(const char * filename) xmlfile = iniparser_getstring(d, "common:xml", xmlfile); script_path = iniparser_getstring(d, "common:scripts", script_path); lomem = iniparser_getint(d, "common:lomem", lomem)?1:0; + memdebug = iniparser_getint(d, "common:memcheck", memdebug); str = iniparser_getstring(d, "common:gamedata_encoding", NULL); if (str) enc_gamedata = xmlParseCharEncoding(str); @@ -652,15 +658,16 @@ main(int argc, char *argv[]) return -1; } #endif -#ifdef CRTDBG - init_crtdbg(); -#endif lua_State * luaState = lua_init(); global.vm_state = luaState; load_inifile("eressea.ini"); if ((i=read_args(argc, argv, luaState))!=0) return i; +#ifdef CRTDBG + init_crtdbg(); +#endif + kernel_init(); game_init(); diff --git a/src/scripts/default.lua b/src/scripts/default.lua index 25d84aec2..715986a0e 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -25,7 +25,7 @@ function write_addresses() file = io.open(basepath .. "/adressen", "w") for faction in factions() do -- print(faction.id .. " - " .. faction.locale) - file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.banner .. "\n") + file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.info .. "\n") end file:close() diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index 0b5e37af0..acd276cd3 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -411,7 +411,7 @@ function test_moving() end end -test_movement() +-- test_movement() -- test_fail() -- test_handler() -- test_parser() @@ -425,10 +425,12 @@ test_movement() -- write_game("../testg.txt") -- read_game("../testg.txt") -if 1==1 then +if 0==1 then run_scripts() process_orders() write_reports() end -- test_moving() + +read_game("530", "ISO-8859-1")