Skip to content

Commit

Permalink
Merged pull request "Sync with Q2PRO: BSP loading": NVIDIA#336
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Oct 6, 2023
2 parents 3e4802f + 9c03893 commit d73d6d8
Show file tree
Hide file tree
Showing 25 changed files with 777 additions and 1,191 deletions.
25 changes: 15 additions & 10 deletions doc/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,18 +537,23 @@ if found, is replaced with a single character representing message type
### Miscellaneous

#### `map_override_path`
Specifies the prefix used to construct path to the entity string override
file. Override file will be loaded from `$\{map_override_path}$\{mapname}.ent`.
Usually this variable is set to `maps/` (notice the trailing slash), and
`.ent` files are placed together with `.bsp` files. Default value is empty
(don't try to override entity strings).
Specifies the directory from which override files with extensions `.ent` or
`.bsp.override` are loaded. Default value is empty (don't try to override
entity strings). Typical value for this is `maps`, but can be customized
per server port.

#### Entity overrides
Override files allow the entity string of a map being loaded to be replaced by
a custom data supplied by server operator. This makes it possible to change the
layout of entities on the map (thus creating a new version of the map) without
requiring clients to download anything. Entity string can be dumped from the current
map using `dumpents` server command and later changed with a text editor.
Override files with `.ent` extension allow the entity string of the map being
loaded to be replaced by a custom data supplied by server operator. This makes
it possible to change the layout of entities on the map (thus creating a new
version of the map) without requiring clients to download anything. Entity
string can be dumped from the current map using `dumpents` server command and
later changed with a text editor.

Override files with `.bsp.override` extension are more complex: they are binary
files that can replace map entity string or checksum. They can also create an
alias for the map. How to create such files is out of scope of this manual
(search the internet for ‘r1q2 map override file generator’).

#### `map_visibility_patch`
Attempt to patch miscalculated visibility data for some well-known maps
Expand Down
43 changes: 23 additions & 20 deletions inc/common/bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "format/bsp.h"

// maximum size of a PVS row, in bytes
#define VIS_MAX_BYTES (MAX_MAP_LEAFS >> 3)
#define VIS_MAX_BYTES (MAX_MAP_CLUSTERS >> 3)

// take advantage of 64-bit systems
#define VIS_FAST_LONGS(bsp) \
Expand Down Expand Up @@ -75,14 +75,10 @@ typedef struct {

#define SURF_TRANS_MASK (SURF_TRANS33 | SURF_TRANS66)
#define SURF_COLOR_MASK (SURF_TRANS_MASK | SURF_WARP)
#define SURF_NOLM_MASK (SURF_COLOR_MASK | SURF_FLOWING | SURF_SKY)
#define SURF_NOLM_MASK (SURF_COLOR_MASK | SURF_FLOWING | SURF_SKY | SURF_NODRAW)

#define DSURF_PLANEBACK 1

// for lightmap block calculation
#define S_MAX(surf) (((surf)->extents[0] >> 4) + 1)
#define T_MAX(surf) (((surf)->extents[1] >> 4) + 1)

typedef struct mface_s {
msurfedge_t *firstsurfedge;
int numsurfedges;
Expand All @@ -95,8 +91,11 @@ typedef struct mface_s {
int numstyles;

mtexinfo_t *texinfo;
int texturemins[2];
int extents[2];
vec3_t lm_axis[2];
vec2_t lm_offset;
vec2_t lm_scale;
int lm_width;
int lm_height;

#if USE_REF == REF_GL
int texnum[2];
Expand All @@ -110,11 +109,13 @@ typedef struct mface_s {

int firstbasis;

int drawframe;
unsigned drawframe;

unsigned dlightframe;
unsigned dlightbits;

int dlightframe;
int dlightbits;
struct mface_s *next;
struct entity_s *entity;
struct mface_s *next;
} mface_t;
#endif

Expand All @@ -125,7 +126,7 @@ typedef struct mnode_s {
vec3_t mins;
vec3_t maxs;

int visframe;
unsigned visframe;
#endif
struct mnode_s *parent;
/* <====== */
Expand All @@ -147,7 +148,7 @@ typedef struct {
int contents;
int numsides;
mbrushside_t *firstbrushside;
int checkcount; // to avoid repeated testings
unsigned checkcount; // to avoid repeated testings
} mbrush_t;

typedef struct {
Expand All @@ -157,7 +158,7 @@ typedef struct {
vec3_t mins;
vec3_t maxs;

int visframe;
unsigned visframe;
#endif
struct mnode_s *parent;
/* <====== */
Expand All @@ -181,7 +182,7 @@ typedef struct {
typedef struct {
int numareaportals;
mareaportal_t *firstareaportal;
int floodvalid;
unsigned floodvalid;
} marea_t;

typedef struct mmodel_s {
Expand All @@ -201,7 +202,7 @@ typedef struct mmodel_s {
mface_t *firstface;

#if USE_REF == REF_GL
int drawframe;
unsigned drawframe;
#endif
#endif
} mmodel_t;
Expand Down Expand Up @@ -248,7 +249,7 @@ typedef struct bsp_s {
int numareas;
marea_t *areas;

int lastareaportal; // largest portal number used
int numportals; // largest portal number used plus one
int numareaportals; // size of the array below
mareaportal_t *areaportals;

Expand Down Expand Up @@ -276,6 +277,8 @@ typedef struct bsp_s {

int numbases;
mbasis_t *bases;

bool lm_decoupled;
#endif

byte *pvs_matrix;
Expand All @@ -290,13 +293,13 @@ typedef struct bsp_s {

int BSP_Load(const char *name, bsp_t **bsp_p);
void BSP_Free(bsp_t *bsp);
const char *BSP_GetError(void);
const char *BSP_ErrorString(int err);

#if USE_REF
typedef struct {
mface_t *surf;
cplane_t plane;
int s, t;
float s, t;
float fraction;
} lightpoint_t;

Expand Down
4 changes: 4 additions & 0 deletions inc/common/cmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ typedef struct {
int *floodnums; // if two areas have equal floodnums,
// they are connected
bool *portalopen;
int override_bits;
int checksum;
char *entitystring;
} cm_t;

void CM_Init(void);

void CM_FreeMap(cm_t *cm);
int CM_LoadMap(cm_t *cm, const char *name);
void CM_LoadOverrides(cm_t *cm, char *server, size_t server_size);

int CM_NumClusters(cm_t *cm);
int CM_NumInlineModels(cm_t *cm);
Expand Down
2 changes: 2 additions & 0 deletions inc/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bool Com_ParseTimespec(const char *s, int *frames);

void Com_PlayerToEntityState(const player_state_t *ps, entity_state_t *es);

bool Com_ParseMapName(char *out, const char *in, size_t size);

unsigned Com_HashString(const char *s, unsigned size);
unsigned Com_HashStringLen(const char *s, size_t len, unsigned size);

Expand Down
Loading

0 comments on commit d73d6d8

Please sign in to comment.