Simplify the call to PR_LoadProgsFile.

I've decided that setting pr.max_edicts and pr.zone_size as part of the
local progs initialization rather than in PR_LoadProgsFile makes more
sense. For one, it is unlikely for the limits to change every time progs is
reloaded. Also, they seem to be a property of the VM rather than the progs.
However, there is nothing stopping the caller from updating max_edicts and
zone_size every call.
This commit is contained in:
Bill Currie 2018-10-11 10:06:48 +09:00
parent 4872c56e2d
commit 82809eb856
8 changed files with 32 additions and 29 deletions

View file

@ -145,27 +145,22 @@ typedef int pr_load_func_t (progs_t *pr);
\param pr pointer to ::progs_t VM struct
\param file handle of file to read progs data from
\param size bytes of \p file to read
\param max_edicts \e number of entities to allocate space for
\param zone minimum size of dynamic memory to allocate space for
dynamic memory (bytes).
\note \e All runtime strings (permanent or temporary) are allocated from
the VM's dynamic memory space, so be sure \p zone is of sufficient size.
So far, 1MB has proven more than sufficient for Quakeword, even when using
Ruamoko objects.
the VM's dynamic memory space, so be sure \p zone is of sufficient size
(by setting pr->zone_size prior to calling). So far, 1MB has proven more
than sufficient for Quakeword, even when using Ruamoko objects.
\note If entities are used, ensure pr->max_edicts is set appropriately
prior to calling.
*/
void PR_LoadProgsFile (progs_t *pr, struct QFile_s *file, int size,
int max_edicts, int zone);
void PR_LoadProgsFile (progs_t *pr, struct QFile_s *file, int size);
/** Convenience wrapper for PR_LoadProgsFile() and PR_RunLoadFuncs().
Searches for the specified file in the Quake filesystem.
\param pr pointer to ::progs_t VM struct
\param progsname name of the file to load as progs data
\param max_edicts \e number of entities to allocate space for
\param zone minimum size of dynamic memory to allocate space for
*/
void PR_LoadProgs (progs_t *pr, const char *progsname, int max_edicts,
int zone);
void PR_LoadProgs (progs_t *pr, const char *progsname);
/** Register a primary function to be called after the progs code has been
loaded. These functions are remembered across progs loads. They will be
@ -1521,7 +1516,7 @@ struct progs_s {
int denorm_found;
struct memzone_s *zone;
int zone_size;
int zone_size; ///< set by user
/// \name builtin functions
//@{
@ -1593,7 +1588,7 @@ struct progs_s {
/// \name edicts
//@{
edict_t **edicts;
int max_edicts;
int max_edicts; ///< set by user
int *num_edicts;
int *reserved_edicts; ///< alloc will start at reserved_edicts+1
void (*unlink) (edict_t *ent);

View file

@ -578,6 +578,9 @@ Menu_Init (void)
menu_pr_state.load_file = menu_load_file;
menu_pr_state.resolve = menu_resolve_globals;
menu_pr_state.max_edicts = 0;
menu_pr_state.zone_size = 1024 * 1024;
menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0);
PR_RegisterBuiltins (&menu_pr_state, builtins);
@ -617,7 +620,7 @@ Menu_Load (void)
menu_pr_state.progs = 0;
if ((file = QFS_FOpenFile (menu_pr_state.progs_name))) {
size = Qfilesize (file);
PR_LoadProgsFile (&menu_pr_state, file, size, 0, 1024 * 1024);
PR_LoadProgsFile (&menu_pr_state, file, size);
Qclose (file);
if (!PR_RunLoadFuncs (&menu_pr_state)) {

View file

@ -98,7 +98,7 @@ free_progs_mem (progs_t *pr, void *mem)
}
VISIBLE void
PR_LoadProgsFile (progs_t *pr, QFile *file, int size, int max_edicts, int zone)
PR_LoadProgsFile (progs_t *pr, QFile *file, int size)
{
size_t i;
int mem_size;
@ -166,8 +166,6 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size, int max_edicts, int zone)
pr->progs_size += sizeof (void*) - 1;
pr->progs_size &= ~(sizeof (void*) - 1);
// size of heap asked for by vm-subsystem
pr->zone_size = zone;
// round off to next highest whole word address (esp for Alpha)
// this ensures that pointers in the engine data area are always
// properly aligned
@ -183,8 +181,7 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size, int max_edicts, int zone)
// properly aligned
pr->pr_edict_size += sizeof (void*) - 1;
pr->pr_edict_size &= ~(sizeof (void*) - 1);
pr->pr_edictareasize = max_edicts * pr->pr_edict_size;
pr->max_edicts = max_edicts;
pr->pr_edictareasize = pr->max_edicts * pr->pr_edict_size;
mem_size = pr->progs_size + pr->zone_size + pr->pr_edictareasize;
pr->progs = pr->allocate_progs_mem (pr, mem_size + 1);
@ -379,14 +376,14 @@ PR_RunLoadFuncs (progs_t *pr)
PR_LoadProgs
*/
VISIBLE void
PR_LoadProgs (progs_t *pr, const char *progsname, int max_edicts, int zone)
PR_LoadProgs (progs_t *pr, const char *progsname)
{
QFile *file;
file = QFS_FOpenFile (progsname);
pr->progs_name = progsname;
if (file) {
PR_LoadProgsFile (pr, file, qfs_filesize, max_edicts, zone);
PR_LoadProgsFile (pr, file, qfs_filesize);
Qclose (file);
}
if (!pr->progs)

View file

@ -498,8 +498,9 @@ SV_LoadProgs (void)
if (*sv_progs->string)
progs_name = sv_progs->string;
PR_LoadProgs (&sv_pr_state, progs_name, sv.max_edicts,
sv_progs_zone->int_val * 1024);
sv_pr_state.max_edicts = sv.max_edicts;
sv_pr_state.zone_size = sv_progs_zone->int_val * 1024;
PR_LoadProgs (&sv_pr_state, progs_name);
if (!sv_pr_state.progs)
Host_Error ("SV_LoadProgs: couldn't load %s", progs_name);

View file

@ -521,8 +521,9 @@ SV_LoadProgs (void)
if (*sv_progs->string)
progs_name = sv_progs->string;
PR_LoadProgs (&sv_pr_state, progs_name, MAX_EDICTS,
sv_progs_zone->int_val * 1024);
sv_pr_state.max_edicts = MAX_EDICTS;
sv_pr_state.zone_size = sv_progs_zone->int_val * 1024;
PR_LoadProgs (&sv_pr_state, progs_name);
if (!sv_pr_state.progs)
Sys_Error ("SV_LoadProgs: couldn't load %s", progs_name);

View file

@ -322,7 +322,9 @@ load_progs (const char *name)
convert_qfo ();
} else {
pr.progs_name = name;
PR_LoadProgsFile (&pr, file, size, 1, 0);
pr.max_edicts = 1;
pr.zone_size = 0;
PR_LoadProgsFile (&pr, file, size);
Qclose (file);
if (!pr.progs)

View file

@ -133,7 +133,9 @@ load_progs (const char *name)
return 0;
}
pr.progs_name = name;
PR_LoadProgsFile (&pr, file, size, 1, 1024 * 1024);
pr.max_edicts = 1;
pr.zone_size = 1024*1024;
PR_LoadProgsFile (&pr, file, size);
Qclose (file);
if (!PR_RunLoadFuncs (&pr))
PR_Error (&pr, "unable to load %s", pr.progs_name);

View file

@ -144,7 +144,9 @@ load_progs (const char *name)
return 0;
}
pr.progs_name = name;
PR_LoadProgsFile (&pr, file, size, 1, 1024 * 1024);
pr.max_edicts = 1;
pr.zone_size = 1024*1024;
PR_LoadProgsFile (&pr, file, size);
Qclose (file);
if (!PR_RunLoadFuncs (&pr))
PR_Error (&pr, "unable to load %s", pr.progs_name);