UFO: Alien Invasion
Loading...
Searching...
No Matches
test_footsteps.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "test_shared.h"
27#include "../client/client.h"
28#include "../client/cl_shared.h"
29#include "../client/cl_lua.h"
32#include "../common/routing.h"
33#include "../server/server.h"
34#include "../server/sv_rma.h"
35
36class FootStepTest: public ::testing::Test {
37protected:
38 static void SetUpTestCase() {
39 TEST_Init();
40
41 sv_genericPool = Mem_CreatePool("mapdef-test");
43 vid_imagePool = Mem_CreatePool("Vid: Image system");
44 sv_dumpmapassembly = Cvar_Get("sv_dumpassembly", "0");
45 sv_public = Cvar_Get("sv_public", "0");
46 port = Cvar_Get("testport", "27909");
47 masterserver_url = Cvar_Get("masterserver_test", "http://localhost");
48
49 cl_genericPool = Mem_CreatePool("Client: Generic");
50
51 r_state.active_texunit = &r_state.texunits[0];
52 R_FontInit();
53 CL_InitLua();
54 UI_Init();
55
56 OBJZERO(cls);
57 Com_ParseScripts(false);
58 }
59
60 static void TearDownTestCase() {
63 }
64};
65
66#define FOOTSTEPS_FULL 0
75TEST_F(FootStepTest, DISABLED_MapDefsFootSteps)
76{
77 const char* filterId = TEST_GetStringProperty("mapdef-id");
78 const mapDef_t* md;
79 int mapCount = 0; // the number of maps read
80 int badMapCount = 0;
81 const int skipCount = 20; // to skip the first n mapDefs
82 const int badMapCountMax = 25; // # of maps with missing sounds before this test stops
83 const int mapCountMax = 150; // should of cause be higher than skip + bad
84 const int texCountMax = 30;
85 char texNames[texCountMax][MAX_QPATH];
86 bool done = false;
87
88 OBJZERO(texNames);
89 ASSERT_TRUE(csi.numMDs > 0);
90
91 MapDef_Foreach(md) {
92 if (md->mapTheme[0] == '.')
93 continue;
94 if (filterId && !Q_streq(filterId, md->id))
95 continue;
96
97 mapCount++;
98 if (mapCount <= skipCount)
99 continue;
100 /* use a known seed to reproduce an error */
101 unsigned int seed;
102 if (TEST_ExistsProperty("mapdef-seed")) {
103 seed = TEST_GetLongProperty("mapdef-seed");
104 } else {
105 seed = (unsigned int) time(nullptr);
106 }
107 srand(seed);
108
109 int count = 0;
110 Com_Printf("testMapDefsFootSteps: Mapdef %s (seed %u)\n", md->id, seed);
111
112 const char* asmName = (const char*)LIST_GetByIdx(md->params, 0);
113 SV_Map(true, md->mapTheme, asmName);
114
115 /* now that we have loaded the map, check all cells for walkable places */
116 GridBox mBox(sv->mapData.mapBox); // test ALL the cells
117#if !FOOTSTEPS_FULL
118 if (mapCount >= skipCount + 4) { // after the first 4 maps, reduce the testing area
119 const pos3_t center = {148, 128, 0};
120 mBox.set(center, center); // the box on the map we're testing
121 mBox.expandXY(10); // just test a few cells around the center of the map
122 mBox.maxs[2] = 2; // and 3 levels high
123 }
124#endif
125 mBox.clipToMaxBoundaries();
126
127 for (int x = mBox.getMinX(); x <= mBox.getMaxX() && !done; x++) {
128 for (int y = mBox.getMinY(); y <= mBox.getMaxY() && !done; y++) {
129 for (int z = mBox.getMinZ(); z <= mBox.getMaxZ(); z++) {
130 const int floor = sv->mapData.routing.getFloor(1, x, y, z);
131 if (floor < 0) // if we have a floor in that cell
132 continue;
133 const AABB noBox(vec3_origin, vec3_origin); // we're doing a point-trace
134 const pos3_t cellPos = {(pos_t)x, (pos_t)y, (pos_t)z}; // the cell in question
135 vec3_t from, to;
136 PosToVec(cellPos, from); // the center of the cell
137 VectorCopy(from, to); // also base for the endpoint of the trace
138 from[2] -= UNIT_HEIGHT / 2; // bottom of the cell
139 from[2] += (floor + 2) * QUANT; // add the height of the floor plus 2 QUANTS
140 to[2] -= 2 * UNIT_HEIGHT; // we should really hit the ground with this
141 const trace_t trace = SV_Trace(Line(from, to), noBox, nullptr, MASK_SOLID);
142 if (!trace.surface)
143 continue;
144
145 const char* snd = SV_GetFootstepSound(trace.surface->name);
146 if (snd)
147 continue;
148
149 for (int i = 0; i < texCountMax; ++i) {
150 if (!texNames[i][0]) { // found a free slot ?
151 Q_strncpyz(texNames[i], trace.surface->name, sizeof(texNames[i]));
152 count++;
153 break;
154 }
155 if (Q_streq(trace.surface->name, texNames[i])) // already there ?
156 break;
157 }
158 if (count > texCountMax) {
159 done = true;
160 break; // the z-loop
161 }
162 }
163 }
164 }
165 if (!texNames[0][0]) {
166 Com_Printf("In map %s, asm %s: Nothing detected\n", md->mapTheme, asmName);
167 } else {
168 ++badMapCount;
169 for (int i = 0; i < texCountMax; ++i) {
170 if (texNames[i][0]) {
171 Com_Printf("In map %s, asm %s: No sound for: %s\n", md->mapTheme, asmName, texNames[i]);
172 }
173 }
174 }
175 OBJZERO(texNames);
177
178 if (done || mapCount >= mapCountMax || badMapCount >= badMapCountMax)
179 break;
180 }
181}
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
Definition cl_lua.cpp:130
memPool_t * vid_imagePool
Definition cl_main.cpp:88
client_static_t cls
Definition cl_main.cpp:83
memPool_t * cl_genericPool
Definition cl_main.cpp:86
void R_FontInit(void)
Definition r_font.cpp:716
Share stuff between the different cgame implementations.
Definition aabb.h:42
static void TearDownTestCase()
static void SetUpTestCase()
pos_t getMinY() const
Definition mathlib.h:177
void set(const pos3_t mini, const pos3_t maxi)
Definition mathlib.h:148
void clipToMaxBoundaries()
Definition mathlib.h:215
pos_t getMinZ() const
Definition mathlib.h:180
pos3_t maxs
Definition mathlib.h:223
pos_t getMaxY() const
Definition mathlib.h:186
void expandXY(const int byVal)
expand the box in four directions, but clip them to the maximum boundaries
Definition mathlib.h:206
pos_t getMinX() const
Definition mathlib.h:174
pos_t getMaxX() const
Definition mathlib.h:183
pos_t getMaxZ() const
Definition mathlib.h:189
Definition line.h:31
Primary header for client.
csi_t csi
Definition common.cpp:39
cvar_t * port
Definition common.cpp:58
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
memPool_t * com_networkPool
Definition common.cpp:73
cvar_t * masterserver_url
Definition common.cpp:57
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
#define QUANT
Definition defines.h:126
#define UNIT_HEIGHT
Definition defines.h:122
#define MASK_SOLID
Definition defines.h:272
#define MAX_QPATH
Definition filesys.h:40
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void * LIST_GetByIdx(linkedList_t *list, int index)
Get an entry of a linked list by its index in the list.
Definition list.cpp:362
const vec3_t vec3_origin
Definition mathlib.cpp:35
#define PosToVec(p, v)
Pos boundary size is +/- 128 - to get into the positive area we add the possible max negative value a...
Definition mathlib.h:110
#define Mem_CreatePool(name)
Definition mem.h:32
void NET_Shutdown(void)
Definition net.cpp:337
#define MapDef_Foreach(var)
Definition q_shared.h:505
QGL_EXTERN GLuint count
Definition r_gl.h:99
QGL_EXTERN GLint i
Definition r_gl.h:113
rstate_t r_state
Definition r_main.cpp:48
grid pathfinding and routing
void Com_ParseScripts(bool onlyServer)
Definition scripts.cpp:3619
Main server include file.
memPool_t * sv_genericPool
Definition sv_main.cpp:55
const char * SV_GetFootstepSound(const char *texture)
Query the footstep sound for the given surface texture.
Definition sv_world.cpp:451
trace_t SV_Trace(const Line &traceLine, const AABB &box, const edict_t *passedict, int contentmask)
Moves the given mins/maxs volume through the world from start to end.
Definition sv_world.cpp:417
void SV_Map(bool day, const char *levelstring, const char *assembly, bool verbose=true)
Change the server to a new map, taking all connected clients along with it.
Definition sv_init.cpp:113
void SV_ShutdownGameProgs(void)
Called when either the entire server is being killed, or it is changing to a different game directory...
Definition sv_game.cpp:681
serverInstanceGame_t * sv
Definition sv_init.cpp:36
cvar_t * sv_public
Definition sv_main.cpp:52
cvar_t * sv_dumpmapassembly
Definition sv_main.cpp:47
#define Q_streq(a, b)
Definition shared.h:136
#define OBJZERO(obj)
Definition shared.h:178
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition shared.cpp:457
char name[MAX_QPATH]
Definition typedefs.h:38
char * mapTheme
Definition q_shared.h:464
char * id
Definition q_shared.h:463
linkedList_t * params
Definition q_shared.h:465
cBspSurface_t * surface
Definition tracing.h:61
TEST_F(FootStepTest, DISABLED_MapDefsFootSteps)
This test cycles through the list of map definitions found in the maps.ufo script and tries to find s...
static int mapCount
Definition test_game.cpp:37
void TEST_Shutdown(void)
bool TEST_ExistsProperty(const char *name)
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
long TEST_GetLongProperty(const char *name)
pos_t pos3_t[3]
Definition ufotypes.h:58
byte pos_t
Definition ufotypes.h:57
vec_t vec3_t[3]
Definition ufotypes.h:39
void UI_Init(void)
Definition ui_main.cpp:278
#define VectorCopy(src, dest)
Definition vector.h:51