UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_view.cpp
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/client/cl_view.c
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27*/
28
29#include "../client.h"
30#include "../cl_screen.h"
31#include "../cgame/cl_game.h"
32#include "cl_particle.h"
33#include "cl_localentity.h"
34#include "cl_actor.h"
35#include "cl_hud.h"
36#include "cl_spawn.h"
37#include "cl_view.h"
38#include "../renderer/r_main.h"
40
44
49{
51
52 if (CL_GetConfigString(CS_TILES)[0] == '\0')
53 return; /* no map loaded */
54
56
57 float loadingPercent = 0;
58
59 /* register models, pics, and skins */
60 SCR_DrawLoading(loadingPercent);
64
65 loadingPercent += 10.0f;
66 SCR_DrawLoading(loadingPercent);
67
70
71 int max = 0;
72 for (int i = 1; i < MAX_MODELS && CL_GetConfigString(CS_MODELS + i)[0] != '\0'; i++)
73 max++;
74
75 max += csi.numODs;
76
77 for (int i = 1; i < MAX_MODELS; i++) {
78 const char* name = CL_GetConfigString(CS_MODELS + i);
79 if (name[0] == '\0')
80 break;
81 SCR_DrawLoading(loadingPercent);
82 cl.model_draw[i] = R_FindModel(name);
83 if (!cl.model_draw[i]) {
84 Cmd_ExecuteString("fs_info");
85 Com_Error(ERR_DROP, "Could not load model '%s'\n", name);
86 }
87
88 /* initialize clipping for bmodels */
89 if (name[0] == '*')
90 cl.model_clip[i] = CM_InlineModel(cl.mapTiles, name);
91 else
92 cl.model_clip[i] = nullptr;
93
94 loadingPercent += 100.0f / (float)max;
95 }
96
97 /* update le model references */
98 le_t* le = nullptr;
99 while ((le = LE_GetNextInUse(le))) {
100 if (le->modelnum1 > 0)
102 if (le->modelnum2 > 0)
104 }
105
106 refdef.ready = true;
107
108 /* waiting for EV_START */
110}
111
117static float CL_PrecacheCharacterModels (float alreadyLoadedPercent)
118{
119 if (!cl_precache->integer)
120 return 0;
121
122 const float percent = 40.0f;
123 /* search the name */
124 for (int i = 0; i < csi.numTeamDefs; i++) {
125 teamDef_t* td = &csi.teamDef[i];
126 for (int j = NAME_NEUTRAL; j < NAME_LAST; j++) {
127 /* search one of the model definitions */
128 for (linkedList_t const* list = td->models[j]; list; list = list->next) {
129 teamDef_t::model_t const& m = *static_cast<teamDef_t::model_t const*>(list->data);
130 /* register body */
131 char model[MAX_QPATH];
132 Com_sprintf(model, sizeof(model), "%s/%s", m.path, m.body);
133 if (!R_FindModel(model))
134 Com_Printf("Com_PrecacheCharacterModels: Could not register model %s\n", model);
135 /* register head */
136 Com_sprintf(model, sizeof(model), "%s/%s", m.path, m.head);
137 if (!R_FindModel(model))
138 Com_Printf("Com_PrecacheCharacterModels: Could not register model %s\n", model);
139
140 alreadyLoadedPercent += percent / (td->numModels[j] * csi.numTeamDefs * NAME_LAST);
141 SCR_DrawLoadingScreen(true, alreadyLoadedPercent);
142 }
143 }
144 }
145 /* some genders may not have models - ensure that we do the wanted percent step */
146 return percent;
147}
148
153{
154 float percent = 30.0f;
155 float alreadyLoadedPercent = 30.0f;
156
157 const float loaded = CL_PrecacheCharacterModels(alreadyLoadedPercent);
158 alreadyLoadedPercent += loaded;
159 if (loaded == 0)
160 percent = 100 - alreadyLoadedPercent;
161
162 for (int i = 0; i < csi.numODs; i++) {
163 const objDef_t* od = INVSH_GetItemByIDX(i);
164
165 alreadyLoadedPercent += percent / csi.numODs;
166 SCR_DrawLoadingScreen(true, alreadyLoadedPercent);
167
168 if (od->type[0] == '\0' || od->isDummy)
169 continue;
170
171 if (od->model[0] != '\0') {
172 cls.modelPool[i] = R_FindModel(od->model);
173 if (cls.modelPool[i])
174 Com_DPrintf(DEBUG_CLIENT, "CL_PrecacheModels: Registered object model: '%s' (%i)\n", od->model, i);
175 }
176 }
177
178 /* now make sure that all the precached models are stored until we quit the game
179 * otherwise they would be freed with every map change */
181
182 SCR_DrawLoadingScreen(false, 100.f);
183}
184
190{
191 if (cl_isometric->integer) {
192 const float zoom = 3.6 * (cl.cam.zoom - cl_camzoommin->value) + 0.3 * cl_camzoommin->value;
193 refdef.fieldOfViewX = std::max(std::min(FOV / zoom, 140.0), 1.0);
194 } else {
195 refdef.fieldOfViewX = std::max(std::min(FOV / cl.cam.zoom, 95.0), 55.0);
196 }
197}
198
202static inline void CL_ViewCalcFieldOfViewY (const float width, const float height)
203{
204 refdef.fieldOfViewY = atan(tan(refdef.fieldOfViewX * (M_PI / 360.0)) * (height / width)) * (360.0 / M_PI);
205}
206
211{
212 VectorCopy(cl.cam.camorg, refdef.viewOrigin);
213 VectorCopy(cl.cam.angles, refdef.viewAngles);
214
215 CL_ViewCalcFieldOfViewY(viddef.viewWidth, viddef.viewHeight);
216
217 /* setup refdef */
218 refdef.time = cl.time * 0.001;
219 refdef.worldlevel = cl_worldlevel->integer;
220}
221
225void CL_ViewRender (void)
226{
227 refdef.brushCount = 0;
228 refdef.aliasCount = 0;
229 refdef.batchCount = 0;
230 refdef.FFPToShaderCount = 0;
231 refdef.shaderToShaderCount = 0;
232 refdef.shaderToFFPCount = 0;
233
234 if (cls.state != ca_active)
235 return;
236
237 if (!viddef.viewWidth || !viddef.viewHeight)
238 return;
239
240 /* still loading */
241 if (!refdef.ready)
242 return;
243
244 refdef.numEntities = 0;
245 refdef.mapTiles = cl.mapTiles;
246
247 /* tell the bsp thread to start */
249 /* make sure we are really rendering the world */
250 refdef.rendererFlags &= ~RDF_NOWORLDMODEL;
251 /* add local models to the renderer chain */
253 /* add local entities to the renderer chain */
255
256 /* adds pathing data */
257 if (cl_map_displayavailablecells->integer) {
259 }
260
261 if (cl_map_debug->integer) {
262 if (cl_map_debug->integer & MAPDEBUG_PATHING)
264 /* adds floor arrows */
265 if (cl_map_debug->integer & MAPDEBUG_CELLS)
267 /* adds wall arrows */
268 if (cl_map_debug->integer & MAPDEBUG_WALLS)
270 }
271
272
273 /* adds target cursor */
275
276 /* update ref def */
278
279 /* render the world */
281}
282
290{
291 vec3_t vec;
292
293 PosToVec(pos, vec);
294 VectorCopy(vec, cl.cam.origin);
295 Cvar_SetValue("cl_worldlevel", pos[2]);
296}
297
298void CL_ViewInit (void)
299{
300 cl_precache = Cvar_Get("cl_precache", "0", CVAR_ARCHIVE, "Precache character models at startup - more memory usage but smaller loading times in the game");
301 cl_map_displayavailablecells = Cvar_Get("cl_map_displayavailablecells", "0", 0, "Display cells where a soldier can move");
302 cl_map_draw_rescue_zone = Cvar_Get("cl_map_draw_rescue_zone", "2", 0, "Draw rescue zone: 1 - draw perimeter, 2 - draw circles on the ground, 3 - draw both");
303}
@ NAME_LAST
Definition chr_shared.h:237
@ NAME_NEUTRAL
Definition chr_shared.h:233
void CL_DisplayObstructionArrows(void)
Useful for debugging pathfinding.
void CL_AddTargeting(void)
Adds a target cursor when we render the world.
void CL_AddActorPathing(void)
Adds an actor pathing marker to the current floor when we render the world.
void CL_AddPathing(void)
Adds a pathing marker to the current floor when we render the world.
void CL_DisplayFloorArrows(void)
Useful for debugging pathfinding.
char * CL_GetConfigString(int index)
int CL_GetConfigStringInteger(int index)
clientBattleScape_t cl
cvar_t * cl_camzoommin
Definition cl_camera.cpp:68
#define FOV
Definition cl_camera.h:42
void GAME_InitMissionBriefing(const char *title)
Definition cl_game.cpp:1311
Shared game type headers.
cvar_t * cl_worldlevel
Definition cl_hud.cpp:46
HUD related routines.
le_t * LE_GetNextInUse(le_t *lastLE)
Iterate through the entities that are in use.
void LM_AddToScene(void)
Add the local models to the scene.
void LM_Register(void)
Register misc_models.
model_t * LE_GetDrawModel(unsigned int index)
cvar_t * cl_map_draw_rescue_zone
void LE_AddToScene(void)
client_static_t cls
Definition cl_main.cpp:83
void CL_ParticleRegisterArt(void)
@ THREAD_BSP
void R_SwitchModelMemPoolTag(void)
After all static models are loaded, switch the pool tag for these models to not free them everytime R...
Definition r_model.cpp:299
renderer_threadstate_t r_threadstate
Definition r_thread.cpp:34
#define RDF_NOWORLDMODEL
Definition cl_renderer.h:34
void R_ModBeginLoading(const char *tiles, bool day, const char *pos, const char *mapName, const char *mapZone)
Specifies the model that will be used as the world.
rendererData_t refdef
Definition r_main.cpp:45
void SCR_DrawLoading(int percent)
Draws the current loading pic of the map from base/pics/maps/loading.
void SCR_DrawLoadingScreen(bool string, int percent)
Precache and loading screen at startup.
void SCR_EndLoadingPlaque(void)
Header for certain screen operations.
#define _(String)
Definition cl_shared.h:44
@ ca_active
Definition cl_shared.h:80
void CL_SpawnParseEntitystring(void)
Parse the map entity string and spawns those entities that are client-side only.
Definition cl_spawn.cpp:308
viddef_t viddef
Definition cl_video.cpp:34
void CL_ViewLoadMedia(void)
Call before entering a new level, or after vid_restart.
Definition cl_view.cpp:48
void CL_ViewCenterAtGridPosition(const pos3_t pos)
Centers the camera on a given grid field.
Definition cl_view.cpp:289
void CL_ViewUpdateRenderData(void)
Updates the refdef.
Definition cl_view.cpp:210
void CL_ViewCalcFieldOfViewX(void)
Calculates refdef's FOV_X. Should generally be called after any changes are made to the zoom level (v...
Definition cl_view.cpp:189
void CL_ViewRender(void)
Definition cl_view.cpp:225
cvar_t * cl_map_debug
Definition cl_view.cpp:41
static float CL_PrecacheCharacterModels(float alreadyLoadedPercent)
Precache all menu models for faster access.
Definition cl_view.cpp:117
static cvar_t * cl_precache
Definition cl_view.cpp:42
void CL_ViewPrecacheModels(void)
Precaches all models at game startup - for faster access.
Definition cl_view.cpp:152
void CL_ViewInit(void)
Definition cl_view.cpp:298
static void CL_ViewCalcFieldOfViewY(const float width, const float height)
Definition cl_view.cpp:202
static cvar_t * cl_map_displayavailablecells
Definition cl_view.cpp:43
#define MAPDEBUG_PATHING
Definition cl_view.h:64
#define MAPDEBUG_WALLS
Definition cl_view.h:66
#define MAPDEBUG_CELLS
Definition cl_view.h:65
cvar_t * cl_isometric
Definition cl_input.cpp:73
Primary header for client.
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
cBspModel_t * CM_InlineModel(const mapTiles_t *mapTiles, const char *name)
Searches all inline models and return the cBspModel_t pointer for the given modelnumber or -name.
Definition bsp.cpp:929
csi_t csi
Definition common.cpp:39
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition common.cpp:440
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define ERR_DROP
Definition common.h:211
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition cvar.cpp:671
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 CVAR_ARCHIVE
Definition cvar.h:40
#define DEBUG_CLIENT
Definition defines.h:59
#define MAX_MODELS
Definition defines.h:100
#define MAX_QPATH
Definition filesys.h:40
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
#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 M_PI
Definition mathlib.h:34
static struct mdfour * m
Definition md4.cpp:35
#define CS_TILES
Definition q_shared.h:325
#define CS_LIGHTMAP
Definition q_shared.h:321
#define CS_POSITIONS
Definition q_shared.h:326
#define CS_NAME
Definition q_shared.h:309
#define CS_MAPZONE
Definition q_shared.h:322
#define CS_MODELS
Definition q_shared.h:327
#define CS_MAPTITLE
Definition q_shared.h:310
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
void R_RenderFrame(void)
Definition r_main.cpp:298
model_t * R_FindModel(const char *name)
Tries to load a model.
Definition r_model.cpp:203
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
a local entity
unsigned int modelnum1
model_t * model1
model_t * model2
unsigned int modelnum2
linkedList_t * next
Definition list.h:32
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
const char * type
Definition inv_shared.h:271
bool isDummy
Definition inv_shared.h:290
const char * model
Definition inv_shared.h:269
int numModels[NAME_LAST]
Definition chr_shared.h:326
linkedList_t * models[NAME_LAST]
Definition chr_shared.h:325
pos_t pos3_t[3]
Definition ufotypes.h:58
vec_t vec3_t[3]
Definition ufotypes.h:39
#define VectorCopy(src, dest)
Definition vector.h:51