UFO: Alien Invasion
Loading...
Searching...
No Matches
tracing.h
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Copyright (C) 1997-2001 Id Software, Inc.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26*/
27
28#pragma once
29
30#include "../shared/typedefs.h"
31
32/*
33 * ufo2map and ufo have a different view on the data in the bsp tree,
34 * so they use different structs and classes.
35 */
36#if defined(COMPILE_MAP)
37 #define TR_TILE_TYPE dMapTile_t
38 #define TR_PLANE_TYPE dBspPlane_t
39#elif defined(COMPILE_UFO)
40 #define TR_TILE_TYPE MapTile
41 #define TR_PLANE_TYPE cBspPlane_t
42#else
43 #error Either COMPILE_MAP or COMPILE_UFO must be defined in order for tracing.c to work.
44#endif
46
50#define TRACE_VISIBLE_LEVELS 0x0FF
51#define TRACE_CLIP_LEVELS 0x100
52#define TRACE_ALL_LEVELS 0x1FF
53
55typedef struct trace_s {
56 bool allsolid;
58 float fraction;
60 TR_PLANE_TYPE plane;
63 uint32_t contentFlags;
64 int32_t leafnum;
65 int mapTile;
66 struct le_s* le;
67 int entNum;
68
69 inline trace_s () {
70 init();
71 }
72 inline void init() {
73 OBJZERO(*this);
74 }
75} trace_t;
76
77typedef struct mapTiles_s {
79 TR_TILE_TYPE mapTiles[MAX_MAPTILES];
80
83
84 void getTilesAt(int x ,int y, byte& fromTile1, byte& fromTile2, byte& fromTile3);
85 void getTileOverlap(const byte tile1, const byte tile2, int& minZ, int& maxZ);
86 void printTilesAt(int x ,int y);
88
89/*==============================================================
90BOX AND LINE TRACING
91==============================================================*/
92
93/* This attempts to make the box tracing code thread safe. */
94typedef struct boxtrace_s {
100
102 uint32_t contents;
103 uint32_t rejects;
104 bool ispoint; /* optimized case */
105
106 TR_TILE_TYPE* tile;
107
108 void init (TR_TILE_TYPE* _tile, const int contentmask, const int brushreject, const float fraction);
109 void setLineAndBox(const Line& line, const AABB& box);
110} boxtrace_t;
111
112int TR_BoxOnPlaneSide(const vec3_t mins, const vec3_t maxs, const TR_PLANE_TYPE* plane);
113
114void TR_BuildTracingNode_r(TR_TILE_TYPE* tile, tnode_t** tnode, int32_t nodenum, int level);
115
116#ifdef COMPILE_MAP
117trace_t TR_SingleTileBoxTrace(mapTiles_t* mapTiles, const Line& traceLine, const AABB* traceBox, const int levelmask, const int brushmask, const int brushreject);
118#endif
119int TR_TestLine_r(TR_TILE_TYPE* tile, int32_t nodenum, const vec3_t start, const vec3_t end);
120trace_t TR_BoxTrace(boxtrace_t& traceData, const Line& traceLine, const AABB& traceBox, const int headnode, const float fraction);
121
122bool TR_TestLine(mapTiles_t* mapTiles, const vec3_t start, const vec3_t end, const int levelmask);
123bool TR_TestLineDM(mapTiles_t* mapTiles, const vec3_t start, const vec3_t end, vec3_t hit, const int levelmask);
124trace_t TR_TileBoxTrace(TR_TILE_TYPE* myTile, const Line& traceLine, const AABB& aabb, const int levelmask, const int brushmask, const int brushreject);
Definition aabb.h:42
Definition line.h:31
level_locals_t level
Definition g_main.cpp:38
#define OBJZERO(obj)
Definition shared.h:178
vec3_t absmaxs
Definition tracing.h:97
uint32_t contents
Definition tracing.h:102
bool ispoint
Definition tracing.h:104
TR_TILE_TYPE * tile
Definition tracing.h:106
vec3_t offset
Definition tracing.h:99
vec3_t end
Definition tracing.h:95
vec3_t maxs
Definition tracing.h:96
trace_t trace
Definition tracing.h:101
vec3_t start
Definition tracing.h:95
void setLineAndBox(const Line &line, const AABB &box)
void init(TR_TILE_TYPE *_tile, const int contentmask, const int brushreject, const float fraction)
vec3_t extents
Definition tracing.h:98
vec3_t absmins
Definition tracing.h:97
vec3_t mins
Definition tracing.h:96
uint32_t rejects
Definition tracing.h:103
TR_TILE_TYPE mapTiles[MAX_MAPTILES]
Definition tracing.h:79
int numTiles
Definition tracing.h:82
void getTileOverlap(const byte tile1, const byte tile2, int &minZ, int &maxZ)
void getTilesAt(int x, int y, byte &fromTile1, byte &fromTile2, byte &fromTile3)
void printTilesAt(int x, int y)
Data for line tracing (?).
Definition typedefs.h:69
vec3_t endpos
Definition tracing.h:59
void init()
Definition tracing.h:72
cBspSurface_t * surface
Definition tracing.h:61
int planenum
Definition tracing.h:62
float fraction
Definition tracing.h:58
uint32_t contentFlags
Definition tracing.h:63
TR_PLANE_TYPE plane
Definition tracing.h:60
trace_s()
Definition tracing.h:69
bool startsolid
Definition tracing.h:57
int mapTile
Definition tracing.h:65
int32_t leafnum
Definition tracing.h:64
struct le_s * le
Definition tracing.h:66
bool allsolid
Definition tracing.h:56
int entNum
Definition tracing.h:67
static mapTiles_t mapTiles
bool TR_TestLine(mapTiles_t *mapTiles, const vec3_t start, const vec3_t end, const int levelmask)
Checks traces against the world.
Definition tracing.cpp:310
void TR_BuildTracingNode_r(TR_TILE_TYPE *tile, tnode_t **tnode, int32_t nodenum, int level)
Definition tracing.cpp:122
trace_t TR_BoxTrace(boxtrace_t &traceData, const Line &traceLine, const AABB &traceBox, const int headnode, const float fraction)
This function traces a line from start to end. It returns a trace_t indicating what portion of the li...
Definition tracing.cpp:1003
trace_t TR_TileBoxTrace(TR_TILE_TYPE *myTile, const Line &traceLine, const AABB &aabb, const int levelmask, const int brushmask, const int brushreject)
Traces all submodels in the specified tile. Provides for a short circuit if the trace tries to move p...
Definition tracing.cpp:1067
bool TR_TestLineDM(mapTiles_t *mapTiles, const vec3_t start, const vec3_t end, vec3_t hit, const int levelmask)
Checks traces against the world, gives hit position back.
Definition tracing.cpp:458
int TR_TestLine_r(TR_TILE_TYPE *tile, int32_t nodenum, const vec3_t start, const vec3_t end)
Definition tracing.cpp:209
int TR_BoxOnPlaneSide(const vec3_t mins, const vec3_t maxs, const TR_PLANE_TYPE *plane)
Returns PSIDE_FRONT, PSIDE_BACK, or PSIDE_BOTH.
Definition tracing.cpp:542
vec_t vec3_t[3]
Definition ufotypes.h:39