2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sv_init.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2022-05-26 07:11:50 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/crc.h"
|
2001-07-31 18:27:49 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-11-04 07:50:39 +00:00
|
|
|
#include "QF/info.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2021-07-26 02:15:51 +00:00
|
|
|
#include "QF/set.h"
|
2002-02-20 19:22:52 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-30 04:34:06 +00:00
|
|
|
#include "QF/va.h"
|
2001-07-31 18:27:49 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/include/crudefile.h"
|
|
|
|
#include "qw/include/map_cfg.h"
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "qw/pmove.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "qw/include/server.h"
|
|
|
|
#include "qw/include/sv_progs.h"
|
|
|
|
#include "qw/include/sv_gib.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "world.h"
|
|
|
|
|
2001-11-04 07:50:39 +00:00
|
|
|
info_t *localinfo; // local game info
|
2001-08-28 02:43:24 +00:00
|
|
|
char localmodels[MAX_MODELS][5]; // inline model names for precache
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
server_t sv; // local server
|
|
|
|
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
int
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_ModelIndex (const char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!name || !name[0])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODELS && sv.model_precache[i]; i++)
|
|
|
|
if (!strcmp (sv.model_precache[i], name))
|
|
|
|
return i;
|
|
|
|
if (i == MAX_MODELS || !sv.model_precache[i])
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("SV_ModelIndex: model %s not precached", name);
|
2001-02-19 21:15:25 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-07-13 06:22:53 +00:00
|
|
|
static void
|
|
|
|
SV_NextSignon (void)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!sv.max_signon_buffers
|
|
|
|
|| sv.num_signon_buffers == sv.max_signon_buffers - 1) {
|
|
|
|
sv.max_signon_buffers += MAX_SIGNON_BUFFERS;
|
|
|
|
size = sv.max_signon_buffers * sizeof (int);
|
|
|
|
sv.signon_buffer_size = realloc (sv.signon_buffer_size, size);
|
|
|
|
size = sv.max_signon_buffers * MAX_DATAGRAM;
|
|
|
|
sv.signon_buffers = realloc (sv.signon_buffers, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sv.num_signon_buffers)
|
|
|
|
sv.signon_buffer_size[sv.num_signon_buffers - 1] = sv.signon.cursize;
|
|
|
|
sv.signon.maxsize = sizeof (sv.signon_buffers[0]);
|
|
|
|
sv.signon.data = sv.signon_buffers[sv.num_signon_buffers];
|
|
|
|
sv.num_signon_buffers++;
|
|
|
|
sv.signon.cursize = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
SV_FlushSignon
|
|
|
|
|
|
|
|
Moves to the next signon buffer if needed
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_FlushSignon (void)
|
|
|
|
{
|
|
|
|
if (sv.signon.cursize < sv.signon.maxsize - 512)
|
|
|
|
return;
|
|
|
|
|
2012-07-13 06:22:53 +00:00
|
|
|
SV_NextSignon ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_CreateBaseline
|
|
|
|
|
|
|
|
Entity baselines are used to compress the update messages
|
|
|
|
to the clients -- only the fields that differ from the
|
|
|
|
baseline will be transmitted
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_CreateBaseline (void)
|
|
|
|
{
|
2022-01-16 13:15:18 +00:00
|
|
|
for (unsigned entnum = 0; entnum < sv.num_edicts; entnum++) {
|
|
|
|
edict_t *svent = EDICT_NUM (&sv_pr_state, entnum);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (svent->free)
|
|
|
|
continue;
|
|
|
|
// create baselines for all player slots,
|
|
|
|
// and any other edict that has a visible model
|
2001-08-08 20:28:53 +00:00
|
|
|
if (entnum > MAX_CLIENTS && !SVfloat (svent, modelindex))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// create entity baseline
|
2010-12-09 05:27:36 +00:00
|
|
|
VectorCopy (SVvector (svent, origin), SVdata (svent)->state.origin);
|
|
|
|
VectorCopy (SVvector (svent, angles), SVdata (svent)->state.angles);
|
|
|
|
SVdata (svent)->state.frame = SVfloat (svent, frame);
|
|
|
|
SVdata (svent)->state.skinnum = SVfloat (svent, skin);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (entnum > 0 && entnum <= MAX_CLIENTS) {
|
2010-12-09 05:27:36 +00:00
|
|
|
SVdata (svent)->state.colormap = entnum;
|
|
|
|
SVdata (svent)->state.modelindex = SV_ModelIndex
|
2001-08-28 02:43:24 +00:00
|
|
|
("progs/player.mdl");
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2010-12-09 05:27:36 +00:00
|
|
|
SVdata (svent)->state.colormap = 0;
|
|
|
|
SVdata (svent)->state.modelindex =
|
2004-01-04 07:42:43 +00:00
|
|
|
SV_ModelIndex (PR_GetString (&sv_pr_state,
|
|
|
|
SVstring (svent, model)));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// LordHavoc: setup baseline to include new effects
|
2010-12-09 05:27:36 +00:00
|
|
|
SVdata (svent)->state.alpha = 255;
|
|
|
|
SVdata (svent)->state.scale = 16;
|
|
|
|
SVdata (svent)->state.glow_size = 0;
|
|
|
|
SVdata (svent)->state.glow_color = 254;
|
|
|
|
SVdata (svent)->state.colormod = 255;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-17 16:18:34 +00:00
|
|
|
// flush the signon message out to a separate buffer if nearly full
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_FlushSignon ();
|
|
|
|
|
|
|
|
// add to the message
|
|
|
|
MSG_WriteByte (&sv.signon, svc_spawnbaseline);
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteShort (&sv.signon, entnum);
|
|
|
|
|
2010-12-09 05:27:36 +00:00
|
|
|
MSG_WriteByte (&sv.signon, SVdata (svent)->state.modelindex);
|
|
|
|
MSG_WriteByte (&sv.signon, SVdata (svent)->state.frame);
|
|
|
|
MSG_WriteByte (&sv.signon, SVdata (svent)->state.colormap);
|
|
|
|
MSG_WriteByte (&sv.signon, SVdata (svent)->state.skinnum);
|
2001-12-12 21:56:09 +00:00
|
|
|
|
2022-03-30 15:07:20 +00:00
|
|
|
MSG_WriteCoordAngleV (&sv.signon,
|
|
|
|
(vec_t*)&SVdata (svent)->state.origin,//FIXME
|
|
|
|
SVdata (svent)->state.angles);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_SaveSpawnparms
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
Grabs the current state of the progs serverinfo flags
|
2001-02-19 21:15:25 +00:00
|
|
|
and each client for saving across the
|
|
|
|
transition to another level
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_SaveSpawnparms (void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!sv.state)
|
|
|
|
return; // no progs loaded yet
|
|
|
|
|
|
|
|
// serverflags is the only game related thing maintained
|
2001-03-01 08:34:30 +00:00
|
|
|
svs.serverflags = *sv_globals.serverflags;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
for (i = 0, host_client = svs.clients; i < MAX_CLIENTS; i++, host_client++)
|
|
|
|
{
|
2003-03-04 17:38:42 +00:00
|
|
|
if (host_client->state == cs_server) {
|
|
|
|
// drop server allocated clients (FIXME for now)
|
|
|
|
if (host_client->userinfo)
|
|
|
|
Info_Destroy (host_client->userinfo);
|
|
|
|
memset (host_client, 0, sizeof (*host_client));
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
if (host_client->state != cs_spawned)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// needs to reconnect
|
|
|
|
host_client->state = cs_connected;
|
|
|
|
|
|
|
|
// call the progs to get default spawn parms for the new client
|
2001-03-01 08:34:30 +00:00
|
|
|
*sv_globals.self = EDICT_TO_PROG (&sv_pr_state, host_client->edict);
|
|
|
|
PR_ExecuteProgram (&sv_pr_state, sv_funcs.SetChangeParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
for (j = 0; j < NUM_SPAWN_PARMS; j++)
|
2001-03-01 08:34:30 +00:00
|
|
|
host_client->spawn_parms[j] = sv_globals.parms[j];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 13:36:07 +00:00
|
|
|
static set_t *
|
|
|
|
sv_alloc_vis_array (unsigned numleafs)
|
|
|
|
{
|
2021-07-27 02:34:17 +00:00
|
|
|
// the passed in numleafs is the true number of leafs in the map and thus
|
|
|
|
// does include leaf 0, but pvs bits do not include leaf 0
|
|
|
|
unsigned size = SET_SIZE (numleafs - 1);
|
2021-07-26 13:36:07 +00:00
|
|
|
|
|
|
|
if (size > SET_DEFMAP_SIZE * SET_BITS) {
|
2021-07-28 06:01:45 +00:00
|
|
|
set_t *sets = Hunk_Alloc (0,
|
|
|
|
numleafs * (sizeof (set_t) + size / 8));
|
2021-07-26 13:36:07 +00:00
|
|
|
unsigned words = size / SET_BITS;
|
2021-07-27 02:34:17 +00:00
|
|
|
set_bits_t *bits = (set_bits_t *) (&sets[numleafs]);
|
2021-07-26 13:36:07 +00:00
|
|
|
for (unsigned i = 0; i < numleafs; i++) {
|
|
|
|
sets[i].size = size;
|
|
|
|
sets[i].map = bits;
|
|
|
|
bits += words;
|
|
|
|
}
|
|
|
|
return sets;
|
|
|
|
} else {
|
2021-07-28 06:01:45 +00:00
|
|
|
set_t *sets = Hunk_Alloc (0, numleafs * sizeof (set_t));
|
2021-07-26 13:36:07 +00:00
|
|
|
for (unsigned i = 0; i < numleafs; i++) {
|
|
|
|
sets[i].size = size;
|
|
|
|
sets[i].map = sets[i].defmap;
|
|
|
|
}
|
|
|
|
return sets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
SV_CalcPHS
|
|
|
|
|
|
|
|
Expands the PVS and calculates the PHS
|
|
|
|
(Potentially Hearable Set)
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_CalcPHS (void)
|
|
|
|
{
|
2021-07-26 13:36:07 +00:00
|
|
|
int64_t count, vcount;
|
|
|
|
int num, i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("Building PHS...\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2023-06-28 12:45:41 +00:00
|
|
|
auto brush = &sv.worldmodel->brush;
|
|
|
|
num = brush->modleafs;
|
2021-07-26 13:36:07 +00:00
|
|
|
sv.pvs = sv_alloc_vis_array (num);
|
2001-02-19 21:15:25 +00:00
|
|
|
vcount = 0;
|
2021-07-26 02:15:51 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2023-06-28 12:45:41 +00:00
|
|
|
Mod_LeafPVS_set (brush->leafs + i, brush, 0xff, &sv.pvs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (i == 0)
|
|
|
|
continue;
|
2021-07-27 05:01:08 +00:00
|
|
|
vcount += set_count (&sv.pvs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 13:36:07 +00:00
|
|
|
sv.phs = sv_alloc_vis_array (num);
|
2001-02-19 21:15:25 +00:00
|
|
|
count = 0;
|
2021-07-26 02:15:51 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
set_assign (&sv.phs[i], &sv.pvs[i]);
|
|
|
|
|
|
|
|
for (set_iter_t *iter = set_first (&sv.pvs[i]); iter;
|
|
|
|
iter = set_next (iter)) {
|
|
|
|
// or this pvs row into the phs
|
|
|
|
// +1 because pvs is 1 based
|
|
|
|
set_union (&sv.phs[i], &sv.pvs[iter->element + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
continue;
|
2021-07-27 05:01:08 +00:00
|
|
|
count += set_count (&sv.phs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("Average leafs visible / hearable / total: %i / %i / %i\n",
|
2021-07-26 13:36:07 +00:00
|
|
|
(int) (vcount / num), (int) (count / num), num);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static unsigned int
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_CheckModel (const char *mdl)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
byte *buf;
|
|
|
|
unsigned short crc = 0;
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// int len;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2014-01-23 02:57:57 +00:00
|
|
|
buf = (byte *) QFS_LoadFile (QFS_FOpenFile (mdl), 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (buf) {
|
2003-02-14 19:46:07 +00:00
|
|
|
crc = CRC_Block (buf, qfs_filesize);
|
2014-01-22 23:57:54 +00:00
|
|
|
free (buf);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("WARNING: cannot generate checksum for %s\n", mdl);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_SpawnServer
|
|
|
|
|
|
|
|
Change the server to a new map, taking all connected
|
|
|
|
clients along with it.
|
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
This is called from only the SV_Map_f () function.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_SpawnServer (const char *server)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2014-01-23 02:57:57 +00:00
|
|
|
byte *buf;
|
2001-02-19 21:15:25 +00:00
|
|
|
edict_t *ent;
|
2012-07-13 06:22:53 +00:00
|
|
|
void *so_buffers;
|
|
|
|
int *so_sizes;
|
|
|
|
int max_so;
|
2010-01-13 06:44:57 +00:00
|
|
|
struct recorder_s *recorders;
|
2014-01-23 04:13:00 +00:00
|
|
|
QFile *ent_file;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "SpawnServer: %s\n", server);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
SV_SaveSpawnparms ();
|
|
|
|
|
|
|
|
svs.spawncount++; // any partially connected client
|
2001-08-28 02:43:24 +00:00
|
|
|
// will be restarted
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
sv.state = ss_dead;
|
|
|
|
sv_pr_state.null_bad = 0;
|
|
|
|
|
|
|
|
Mod_ClearAll ();
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_FreeToLowMark (0, host_hunklevel);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-01-13 06:44:57 +00:00
|
|
|
// wipe the entire per-level structure, but don't lose sv.recorders
|
2012-07-13 06:22:53 +00:00
|
|
|
// or signon buffers (good thing we're not multi-threaded FIXME?)
|
2010-01-13 06:44:57 +00:00
|
|
|
recorders = sv.recorders;
|
2012-07-13 06:22:53 +00:00
|
|
|
max_so = sv.max_signon_buffers;
|
|
|
|
so_buffers = sv.signon_buffers;
|
|
|
|
so_sizes = sv.signon_buffer_size;
|
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
if (sv.name) {
|
|
|
|
free (sv.name);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
memset (&sv, 0, sizeof (sv));
|
2012-07-13 06:22:53 +00:00
|
|
|
|
2010-01-13 06:44:57 +00:00
|
|
|
sv.recorders = recorders;
|
2012-07-13 06:22:53 +00:00
|
|
|
sv.max_signon_buffers = max_so;
|
|
|
|
sv.signon_buffers = so_buffers;
|
|
|
|
sv.signon_buffer_size = so_sizes;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
sv.datagram.maxsize = sizeof (sv.datagram_buf);
|
|
|
|
sv.datagram.data = sv.datagram_buf;
|
|
|
|
sv.datagram.allowoverflow = true;
|
|
|
|
|
|
|
|
sv.reliable_datagram.maxsize = sizeof (sv.reliable_datagram_buf);
|
|
|
|
sv.reliable_datagram.data = sv.reliable_datagram_buf;
|
|
|
|
|
|
|
|
sv.multicast.maxsize = sizeof (sv.multicast_buf);
|
|
|
|
sv.multicast.data = sv.multicast_buf;
|
|
|
|
|
|
|
|
sv.master.maxsize = sizeof (sv.master_buf);
|
|
|
|
sv.master.data = sv.master_buf;
|
|
|
|
|
2012-07-13 06:22:53 +00:00
|
|
|
SV_NextSignon ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
sv.name = strdup(server);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// load progs to get entity field count which determines how big each
|
|
|
|
// edict is
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_LoadProgs ();
|
2010-12-08 00:20:43 +00:00
|
|
|
SV_FreeAllEdictLeafs ();
|
2002-07-05 06:43:47 +00:00
|
|
|
SV_SetupUserCommands ();
|
2021-01-31 07:01:20 +00:00
|
|
|
Info_SetValueForStarKey (svs.info, "*progs", va (0, "%i", sv_pr_state.crc),
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
!sv_highchars);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
// leave slots at start for only clients
|
2001-02-19 21:15:25 +00:00
|
|
|
sv.num_edicts = MAX_CLIENTS + 1;
|
2021-08-01 12:54:05 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ent = EDICT_NUM (&sv_pr_state, i + 1);
|
|
|
|
svs.clients[i].edict = ent;
|
2001-08-28 02:43:24 +00:00
|
|
|
// ZOID - make sure we update frags right
|
2001-02-19 21:15:25 +00:00
|
|
|
svs.clients[i].old_frags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sv.time = 1.0;
|
2002-05-26 20:30:12 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
snprintf (sv.modelname, sizeof (sv.modelname), "maps/%s.bsp", server);
|
2005-06-19 06:29:50 +00:00
|
|
|
map_cfg (sv.modelname, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
sv.worldmodel = Mod_ForName (sv.modelname, true);
|
2005-06-19 06:29:50 +00:00
|
|
|
map_cfg (sv.modelname, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_CalcPHS ();
|
|
|
|
|
|
|
|
// clear physics interaction links
|
|
|
|
SV_ClearWorld ();
|
|
|
|
|
|
|
|
sv.sound_precache[0] = sv_pr_state.pr_strings;
|
|
|
|
|
|
|
|
sv.model_precache[0] = sv_pr_state.pr_strings;
|
|
|
|
sv.model_precache[1] = sv.modelname;
|
|
|
|
sv.models[1] = sv.worldmodel;
|
2021-08-01 12:54:05 +00:00
|
|
|
for (unsigned i = 1; i < sv.worldmodel->brush.numsubmodels; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
sv.model_precache[1 + i] = localmodels[i];
|
|
|
|
sv.models[i + 1] = Mod_ForName (localmodels[i], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check player/eyes models for hacks
|
|
|
|
sv.model_player_checksum = SV_CheckModel ("progs/player.mdl");
|
|
|
|
sv.eyes_player_checksum = SV_CheckModel ("progs/eyes.mdl");
|
|
|
|
|
|
|
|
// spawn the rest of the entities on the map
|
|
|
|
|
|
|
|
// precache and static commands can be issued during
|
|
|
|
// map initialization
|
|
|
|
sv.state = ss_loading;
|
|
|
|
sv_pr_state.null_bad = 0;
|
|
|
|
|
|
|
|
ent = EDICT_NUM (&sv_pr_state, 0);
|
|
|
|
ent->free = false;
|
2021-02-01 05:39:00 +00:00
|
|
|
SVstring (ent, model) = PR_SetString (&sv_pr_state, sv.worldmodel->path);
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (ent, modelindex) = 1; // world model
|
|
|
|
SVfloat (ent, solid) = SOLID_BSP;
|
|
|
|
SVfloat (ent, movetype) = MOVETYPE_PUSH;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-01 08:34:30 +00:00
|
|
|
*sv_globals.mapname = PR_SetString (&sv_pr_state, sv.name);
|
2001-02-19 21:15:25 +00:00
|
|
|
// serverflags are for cross level information (sigils)
|
2001-03-01 08:34:30 +00:00
|
|
|
*sv_globals.serverflags = svs.serverflags;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-22 19:03:26 +00:00
|
|
|
// close all CF files that progs didn't close from the last map
|
|
|
|
CF_CloseAllFiles ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// run the frame start qc function to let progs check cvars
|
|
|
|
SV_ProgStartFrame ();
|
|
|
|
|
|
|
|
// load and spawn all other entities
|
2004-11-09 22:32:00 +00:00
|
|
|
*sv_globals.time = sv.time;
|
2021-01-31 07:01:20 +00:00
|
|
|
ent_file = QFS_VOpenFile (va (0, "maps/%s.ent", server), 0,
|
2014-01-23 04:13:00 +00:00
|
|
|
sv.worldmodel->vpath);
|
|
|
|
if ((buf = QFS_LoadFile (ent_file, 0))) {
|
2014-01-23 02:57:57 +00:00
|
|
|
ED_LoadFromFile (&sv_pr_state, (char *) buf);
|
2003-03-25 17:49:27 +00:00
|
|
|
free (buf);
|
|
|
|
} else {
|
2021-02-01 10:31:11 +00:00
|
|
|
ED_LoadFromFile (&sv_pr_state, sv.worldmodel->brush.entities);
|
2003-03-25 17:49:27 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// look up some model indexes for specialized message compression
|
|
|
|
SV_FindModelNumbers ();
|
|
|
|
|
|
|
|
// all spawning is completed, any further precache statements
|
|
|
|
// or prog writes to the signon message are errors
|
|
|
|
sv.state = ss_active;
|
|
|
|
sv_pr_state.null_bad = 1;
|
|
|
|
|
|
|
|
// run two frames to allow everything to settle
|
|
|
|
sv_frametime = 0.1;
|
|
|
|
SV_Physics ();
|
|
|
|
SV_Physics ();
|
|
|
|
|
|
|
|
// save movement vars
|
|
|
|
SV_SetMoveVars ();
|
|
|
|
|
|
|
|
// create a baseline for more efficient communications
|
|
|
|
SV_CreateBaseline ();
|
|
|
|
sv.signon_buffer_size[sv.num_signon_buffers - 1] = sv.signon.cursize;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Info_SetValueForKey (svs.info, "map", sv.name, !sv_highchars);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Server spawned.\n");
|
2003-03-04 03:23:41 +00:00
|
|
|
if (sv_map_e->func)
|
|
|
|
GIB_Event_Callback (sv_map_e, 1, server);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2002-02-26 07:32:23 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SV_SetMoveVars (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
movevars.gravity = sv_gravity;
|
|
|
|
movevars.stopspeed = sv_stopspeed;
|
|
|
|
movevars.maxspeed = sv_maxspeed;
|
|
|
|
movevars.spectatormaxspeed = sv_spectatormaxspeed;
|
|
|
|
movevars.accelerate = sv_accelerate;
|
|
|
|
movevars.airaccelerate = sv_airaccelerate;
|
|
|
|
movevars.wateraccelerate = sv_wateraccelerate;
|
|
|
|
movevars.friction = sv_friction;
|
|
|
|
movevars.waterfriction = sv_waterfriction;
|
2002-02-26 07:32:23 +00:00
|
|
|
movevars.entgravity = 1.0;
|
|
|
|
}
|