forked from github/server
- .ini file ssettings for CRT debugging
- quick alloc-optimization for resolve.c
This commit is contained in:
parent
67184b0c96
commit
9c88e406fd
5 changed files with 57 additions and 28 deletions
|
@ -199,13 +199,14 @@ read_groups(FILE * F, faction * f)
|
||||||
fscanf(F, "%s ", buf);
|
fscanf(F, "%s ", buf);
|
||||||
aid.i = atoi36(buf);
|
aid.i = atoi36(buf);
|
||||||
if (aid.i==0) break;
|
if (aid.i==0) break;
|
||||||
a = calloc(sizeof(ally), 1);
|
a = malloc(sizeof(ally));
|
||||||
*pa = a;
|
*pa = a;
|
||||||
pa = &a->next;
|
pa = &a->next;
|
||||||
fscanf(F, "%d ", &a->status);
|
fscanf(F, "%d ", &a->status);
|
||||||
a->faction = findfaction(aid.i);
|
a->faction = findfaction(aid.i);
|
||||||
if (!a->faction) ur_add(aid, (void**)&a->faction, resolve_faction);
|
if (!a->faction) ur_add(aid, (void**)&a->faction, resolve_faction);
|
||||||
}
|
}
|
||||||
|
*pa = 0;
|
||||||
if(global.data_version >= GROUPATTRIB_VERSION) {
|
if(global.data_version >= GROUPATTRIB_VERSION) {
|
||||||
a_read(F, &g->attribs);
|
a_read(F, &g->attribs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|
||||||
typedef struct unresolved {
|
typedef struct unresolved {
|
||||||
struct unresolved * next;
|
|
||||||
void ** ptrptr;
|
void ** ptrptr;
|
||||||
/* pointer to the location where the unresolved object
|
/* pointer to the location where the unresolved object
|
||||||
* should be, or NULL if special handling is required */
|
* should be, or NULL if special handling is required */
|
||||||
|
@ -36,26 +35,46 @@ typedef struct unresolved {
|
||||||
/* function to resolve the unknown object */
|
/* function to resolve the unknown object */
|
||||||
} unresolved;
|
} unresolved;
|
||||||
|
|
||||||
unresolved * ur_list;
|
#define BLOCKSIZE 1024
|
||||||
|
static unresolved * ur_list;
|
||||||
|
static unresolved * ur_begin;
|
||||||
|
static unresolved * ur_current;
|
||||||
|
|
||||||
void
|
void
|
||||||
ur_add(variant data, void ** ptrptr, resolve_fun fun) {
|
ur_add(variant data, void ** ptrptr, resolve_fun fun)
|
||||||
unresolved * ur = malloc(sizeof(unresolved));
|
{
|
||||||
ur->data = data;
|
if (ur_list==NULL) {
|
||||||
ur->resolve = fun;
|
ur_list = malloc(BLOCKSIZE*sizeof(unresolved));
|
||||||
ur->ptrptr = ptrptr;
|
ur_begin = ur_current = ur_list;
|
||||||
ur->next = ur_list;
|
}
|
||||||
ur_list = ur;
|
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
|
void
|
||||||
resolve(void)
|
resolve(void)
|
||||||
{
|
{
|
||||||
while (ur_list) {
|
unresolved * ur = ur_list;
|
||||||
unresolved * ur = ur_list;
|
while (ur) {
|
||||||
ur_list = ur->next;
|
if (ur->resolve==NULL) {
|
||||||
if (ur->ptrptr) *ur->ptrptr = ur->resolve(ur->data);
|
ur = ur->data.v;
|
||||||
else ur->resolve(ur->data);
|
free(ur_list);
|
||||||
free(ur);
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ static boolean g_ignore_errors = false;
|
||||||
static boolean opt_reportonly = false;
|
static boolean opt_reportonly = false;
|
||||||
static const char * luafile = NULL;
|
static const char * luafile = NULL;
|
||||||
static const char * script_path = "scripts";
|
static const char * script_path = "scripts";
|
||||||
|
static int memdebug = 0;
|
||||||
|
|
||||||
struct settings global = {
|
struct settings global = {
|
||||||
"Eressea", /* gamename */
|
"Eressea", /* gamename */
|
||||||
|
@ -386,18 +387,22 @@ game_done(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "magic.h"
|
|
||||||
|
|
||||||
#define CRTDBG
|
#define CRTDBG
|
||||||
|
|
||||||
#ifdef CRTDBG
|
#ifdef CRTDBG
|
||||||
void
|
void
|
||||||
init_crtdbg(void)
|
init_crtdbg(void)
|
||||||
{
|
{
|
||||||
#if (defined(_MSC_VER))
|
#if (defined(_MSC_VER))
|
||||||
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||||
// flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF;
|
if (memdebug==1) {
|
||||||
// flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */
|
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);
|
_CrtSetDbgFlag(flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -608,6 +613,7 @@ load_inifile(const char * filename)
|
||||||
xmlfile = iniparser_getstring(d, "common:xml", xmlfile);
|
xmlfile = iniparser_getstring(d, "common:xml", xmlfile);
|
||||||
script_path = iniparser_getstring(d, "common:scripts", script_path);
|
script_path = iniparser_getstring(d, "common:scripts", script_path);
|
||||||
lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
|
lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
|
||||||
|
memdebug = iniparser_getint(d, "common:memcheck", memdebug);
|
||||||
|
|
||||||
str = iniparser_getstring(d, "common:gamedata_encoding", NULL);
|
str = iniparser_getstring(d, "common:gamedata_encoding", NULL);
|
||||||
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
||||||
|
@ -652,15 +658,16 @@ main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CRTDBG
|
|
||||||
init_crtdbg();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lua_State * luaState = lua_init();
|
lua_State * luaState = lua_init();
|
||||||
global.vm_state = luaState;
|
global.vm_state = luaState;
|
||||||
load_inifile("eressea.ini");
|
load_inifile("eressea.ini");
|
||||||
if ((i=read_args(argc, argv, luaState))!=0) return i;
|
if ((i=read_args(argc, argv, luaState))!=0) return i;
|
||||||
|
|
||||||
|
#ifdef CRTDBG
|
||||||
|
init_crtdbg();
|
||||||
|
#endif
|
||||||
|
|
||||||
kernel_init();
|
kernel_init();
|
||||||
game_init();
|
game_init();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ function write_addresses()
|
||||||
file = io.open(basepath .. "/adressen", "w")
|
file = io.open(basepath .. "/adressen", "w")
|
||||||
for faction in factions() do
|
for faction in factions() do
|
||||||
-- print(faction.id .. " - " .. faction.locale)
|
-- print(faction.id .. " - " .. faction.locale)
|
||||||
file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.banner .. "\n")
|
file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.info .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
file:close()
|
file:close()
|
||||||
|
|
|
@ -411,7 +411,7 @@ function test_moving()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_movement()
|
-- test_movement()
|
||||||
-- test_fail()
|
-- test_fail()
|
||||||
-- test_handler()
|
-- test_handler()
|
||||||
-- test_parser()
|
-- test_parser()
|
||||||
|
@ -425,10 +425,12 @@ test_movement()
|
||||||
-- write_game("../testg.txt")
|
-- write_game("../testg.txt")
|
||||||
-- read_game("../testg.txt")
|
-- read_game("../testg.txt")
|
||||||
|
|
||||||
if 1==1 then
|
if 0==1 then
|
||||||
run_scripts()
|
run_scripts()
|
||||||
process_orders()
|
process_orders()
|
||||||
write_reports()
|
write_reports()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- test_moving()
|
-- test_moving()
|
||||||
|
|
||||||
|
read_game("530", "ISO-8859-1")
|
||||||
|
|
Loading…
Reference in a new issue