- .ini file ssettings for CRT debugging

- quick alloc-optimization for resolve.c
This commit is contained in:
Enno Rehling 2007-08-15 06:27:40 +00:00
parent 67184b0c96
commit 9c88e406fd
5 changed files with 57 additions and 28 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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()

View File

@ -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")