diff --git a/src/game/memory.h b/src/game/memory.h index 48cd703c..a1eba8a7 100644 --- a/src/game/memory.h +++ b/src/game/memory.h @@ -9,6 +9,7 @@ #define MEMORY_POOL_RIGHT 1 #define GFX_POOL_SIZE (512 * 1024) +#define DEFAULT_POOL_SIZE (0x165000 * 8) struct AllocOnlyPool { diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index b9e9ee77..54dbb5c7 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -34,6 +34,12 @@ static inline int arg_string(const char *name, const char *value, char *target) return 1; } +static inline int arg_uint(const char *name, const char *value, unsigned int *target) { + const unsigned long int v = strtoul(value, NULL, 0); + *target = v; + return 1; +} + void parse_cli_opts(int argc, char* argv[]) { // Initialize options with false values. memset(&gCLIOpts, 0, sizeof(gCLIOpts)); @@ -51,6 +57,9 @@ void parse_cli_opts(int argc, char* argv[]) { else if (strcmp(argv[i], "--cheats") == 0) // Enable cheats menu Cheats.EnableCheats = true; + else if (strcmp(argv[i], "--poolsize") == 0) // Main pool size + arg_uint("--poolsize", argv[++i], &gCLIOpts.PoolSize); + else if (strcmp(argv[i], "--configfile") == 0 && (i + 1) < argc) arg_string("--configfile", argv[++i], gCLIOpts.ConfigFile); diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index f9a45e18..a0281e22 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -6,6 +6,7 @@ struct PCCLIOptions { unsigned int SkipIntro; unsigned int FullScreen; + unsigned int PoolSize; char ConfigFile[SYS_MAX_PATH]; char SavePath[SYS_MAX_PATH]; char GameDir[SYS_MAX_PATH]; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index ada661f1..923e7ea8 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -172,10 +172,6 @@ static void on_anim_frame(double time) { #endif void main_func(void) { - static u64 pool[0x165000/8 / 4 * sizeof(void *)]; - main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0])); - gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); - const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR; const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path(); fs_init(sys_ropaths, gamedir, userpath); @@ -187,6 +183,12 @@ void main_func(void) { else if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; + const size_t poolsize = gCLIOpts.PoolSize ? gCLIOpts.PoolSize : DEFAULT_POOL_SIZE; + u64 *pool = malloc(poolsize); + if (!pool) sys_fatal("Could not alloc %u bytes for main pool.\n", poolsize); + main_pool_init(pool, pool + poolsize / sizeof(pool[0])); + gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); + #if defined(WAPI_SDL1) || defined(WAPI_SDL2) wm_api = &gfx_sdl; #elif defined(WAPI_DXGI)