game: sort spawn functions

This commit is contained in:
Denis Pauk 2024-10-30 01:09:17 +02:00
parent f5eb462fc1
commit 1f147f2fa8
4 changed files with 78 additions and 13 deletions

View file

@ -72,6 +72,7 @@ typedef struct
static dynamicentity_t *dynamicentities;
static int ndynamicentities;
static int nstaticentities;
static void
DynamicSpawnUpdate(edict_t *self, dynamicentity_t *data)
@ -220,6 +221,39 @@ Spawn_CheckCoop_MapHacks(edict_t *ent)
return false;
}
static const spawn_t *
StaticSpawnSearch(const char *classname)
{
int start, end;
start = 0;
end = nstaticentities - 1;
while (start <= end)
{
int i, res;
i = start + (end - start) / 2;
res = Q_stricmp(spawns[i].name, classname);
if (res == 0)
{
return &spawns[i];
}
else if (res < 0)
{
start = i + 1;
}
else
{
end = i - 1;
}
}
return NULL;
}
/*
* Finds the spawn function for
* the entity and calls it
@ -227,7 +261,7 @@ Spawn_CheckCoop_MapHacks(edict_t *ent)
void
ED_CallSpawn(edict_t *ent)
{
spawn_t *s;
const spawn_t *s;
gitem_t *item;
int i, dyn_id;
@ -291,14 +325,12 @@ ED_CallSpawn(edict_t *ent)
}
/* check normal spawn functions */
for (s = spawns; s->name; s++)
s = StaticSpawnSearch(ent->classname);
if (s)
{
if (!strcmp(s->name, ent->classname))
{
/* found it */
s->spawn(ent);
return;
}
/* found it */
s->spawn(ent);
return;
}
if (dyn_id >= 0 && dynamicentities[dyn_id].model_path[0])
@ -1940,7 +1972,7 @@ DynamicSort(const void *p1, const void *p2)
return Q_stricmp(ent1->classname, ent2->classname);
}
void
static void
DynamicSpawnInit(void)
{
char *buf_ent, *buf_ai, *raw;
@ -2226,3 +2258,38 @@ DynamicSpawnInit(void)
/* sort definitions */
qsort(dynamicentities, ndynamicentities, sizeof(dynamicentity_t), DynamicSort);
}
static int
StaticSort(const void *p1, const void *p2)
{
spawn_t *ent1, *ent2;
ent1 = (spawn_t*)p1;
ent2 = (spawn_t*)p2;
return Q_stricmp(ent1->name, ent2->name);
}
static void
StaticSpawnInit(void)
{
const spawn_t *s;
/* check count of spawn functions */
for (s = spawns; s->name; s++)
{
}
nstaticentities = s - spawns;
gi.dprintf("Found %d static definitions\n", nstaticentities);
/* sort definitions */
qsort(spawns, nstaticentities, sizeof(spawn_t), StaticSort);
}
void
SpawnInit(void)
{
StaticSpawnInit();
DynamicSpawnInit();
}

View file

@ -1084,7 +1084,7 @@ void fire_doppleganger(edict_t *ent, vec3_t start, vec3_t aimdir);
/* g_spawn.c */
void ED_CallSpawn(edict_t *ent);
char *ED_NewString(const char *string, qboolean raw);
void DynamicSpawnInit(void);
void SpawnInit(void);
edict_t *CreateFlyMonster(vec3_t origin, vec3_t angles, vec3_t mins,
vec3_t maxs, char *classname);
edict_t *CreateGroundMonster(vec3_t origin, vec3_t angles, vec3_t mins,

View file

@ -268,7 +268,7 @@ InitGame(void)
LocalizationInit();
/* initilize dynamic object spawn */
DynamicSpawnInit();
SpawnInit();
/* items */
InitItems();

View file

@ -887,12 +887,10 @@ trigger_endgame||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|
trigger_farclip||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Changes the console variable r_farclipdist.|0.5|0.5|0.5
trigger_fogdensity||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Sets r_fog_density and fog color|.5|.5|.5
trigger_goto_buoy||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Send monster to buoy|.5|.5|.5
trigger_Gravity||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none||.5|.5|.5
trigger_lightning||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Triggers lightning bolt|0.5|0.5|0.5
trigger_mappercentage||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Map percentage|0.3|0.1|0.6
trigger_mission_give||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Gives mission objectives|0.5|0.5|0.5
trigger_mission_take||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Removes mission objectives|0.5|0.5|0.5
trigger_MonsterJump||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Makes monsters jump|0.5|0.5|0.5
trigger_playerpushbutton||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Player push button|.5|.5|.5
trigger_playerpushlever||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Player Push lever|.5|.5|.5
trigger_playerusepuzzle||1.0|1.0|1.0|general|0.0|0.0|0.0|0.0|0.0|0.0|shadow|0|0.0|0.0|0|0|0|0:0|0|0|none|Player can use puzzle items within this entity|.5|.5|.5