From 24933bce91f8a85fd8420230b05e043ed3e374d2 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 10 Sep 2023 18:00:29 +0300 Subject: [PATCH] Code path clean up --- Makefile | 6 +- src/vk/header/model.h | 55 +++++++------ src/vk/vk_light.c | 101 ++++++++++------------- src/vk/{vk_rmain.c => vk_main.c} | 0 src/vk/{vk_rmisc.c => vk_misc.c} | 0 src/vk/vk_model.c | 136 +++++++++---------------------- src/vk/{vk_rsurf.c => vk_surf.c} | 44 +++++----- src/vk/vk_warp.c | 2 +- 8 files changed, 138 insertions(+), 206 deletions(-) rename src/vk/{vk_rmain.c => vk_main.c} (100%) rename src/vk/{vk_rmisc.c => vk_misc.c} (100%) rename src/vk/{vk_rsurf.c => vk_surf.c} (97%) diff --git a/Makefile b/Makefile index 1cc3313..1f196e3 100644 --- a/Makefile +++ b/Makefile @@ -341,9 +341,9 @@ REFVK_OBJS_ := \ src/vk/vk_mesh.o \ src/vk/vk_model.o \ src/vk/vk_pipeline.o \ - src/vk/vk_rmain.o \ - src/vk/vk_rmisc.o \ - src/vk/vk_rsurf.o \ + src/vk/vk_main.o \ + src/vk/vk_misc.o \ + src/vk/vk_surf.o \ src/vk/vk_shaders.o \ src/vk/vk_swapchain.o \ src/vk/vk_validation.o \ diff --git a/src/vk/header/model.h b/src/vk/header/model.h index 9f49ea4..b24d20b 100644 --- a/src/vk/header/model.h +++ b/src/vk/header/model.h @@ -1,23 +1,29 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. -Copyright (C) 2018-2019 Krzysztof Kondrak - -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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2018-2019 Krzysztof Kondrak + * + * 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 the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Header for the model stuff. + * + * ======================================================================= + */ #ifndef __VK_MODEL_H__ #define __VK_MODEL_H__ @@ -66,7 +72,6 @@ typedef struct msurface_s short texturemins[2]; short extents[2]; - short lmshift; int light_s, light_t; // gl lightmap coordinates @@ -79,8 +84,8 @@ typedef struct msurface_s mtexinfo_t *texinfo; /* decoupled lm */ - float lmvecs[2][4]; - float lmvlen[2]; + float lmvecs[2][4]; + float lmvlen[2]; /* lighting info */ int dlightframe; @@ -92,11 +97,7 @@ typedef struct msurface_s byte *samples; // [numstyles*surfsize] } msurface_t; -//=================================================================== - -// -// Whole model -// +/* Whole model */ typedef struct model_s { diff --git a/src/vk/vk_light.c b/src/vk/vk_light.c index 390cb5c..740c4f0 100644 --- a/src/vk/vk_light.c +++ b/src/vk/vk_light.c @@ -1,37 +1,34 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. -Copyright (C) 2018-2019 Krzysztof Kondrak - -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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// vk_light.c + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2018-2019 Krzysztof Kondrak + * + * 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 the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Lightmaps and dynamic lighting + * + * ======================================================================= + */ #include "header/local.h" int r_dlightframecount; -/* -============================================================================= - -DYNAMIC LIGHTS BLEND RENDERING - -============================================================================= -*/ - static void R_RenderDlight(dlight_t *light) { @@ -119,19 +116,15 @@ DYNAMIC LIGHTS ============================================================================= */ -/* -============= -R_MarkSurfaceLights -============= -*/ void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount) { msurface_t *surf; int i; - // mark the polygons + /* mark the polygons */ surf = r_worldmodel->surfaces + node->firstsurface; + for (i=0 ; inumsurfaces ; i++, surf++) { if (surf->dlightframe != r_dlightframecount) @@ -293,11 +286,6 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor) return RecursiveLightPoint(node->children[!side], mid, end, pointcolor); } -/* -=============== -R_LightPoint -=============== -*/ void R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity) { @@ -327,22 +315,21 @@ R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity) VectorCopy(pointcolor, color); } - // - // add dynamic lights - // + /* add dynamic lights */ dl = r_newrefdef.dlights; + for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++) { float add; VectorSubtract(currententity->origin, - dl->origin, - dist); + dl->origin, dist); add = dl->intensity - VectorLength(dist); - add *= (1.0/256); + add *= (1.0 / 256); + if (add > 0) { - VectorMA (color, add, dl->color, color); + VectorMA(color, add, dl->color, color); } } @@ -620,12 +607,11 @@ store: { for (j = 0; j < smax; j++) { - r = Q_ftol(bl[0]); g = Q_ftol(bl[1]); b = Q_ftol(bl[2]); - // catch negative lights + /* catch negative lights */ if (r < 0) { r = 0; @@ -641,9 +627,7 @@ store: b = 0; } - /* - ** determine the brightest of the three color components - */ + /* determine the brightest of the three color components */ if (r > g) { max = r; @@ -658,17 +642,14 @@ store: max = b; } - /* - ** alpha is ONLY used for the mono lightmap case. For this reason - ** we set it to the brightest of the color components so that - ** things don't get too dim. - */ + /* alpha is ONLY used for the mono lightmap case. For this + reason we set it to the brightest of the color components + so that things don't get too dim. */ a = max; - /* - ** rescale all the color components if the intensity of the greatest - ** channel exceeds 1.0 - */ + /* rescale all the color components if the + intensity of the greatest channel exceeds + 1.0 */ if (max > 255) { float t = 255.0F / max; diff --git a/src/vk/vk_rmain.c b/src/vk/vk_main.c similarity index 100% rename from src/vk/vk_rmain.c rename to src/vk/vk_main.c diff --git a/src/vk/vk_rmisc.c b/src/vk/vk_misc.c similarity index 100% rename from src/vk/vk_rmisc.c rename to src/vk/vk_misc.c diff --git a/src/vk/vk_model.c b/src/vk/vk_model.c index 35d7e7c..1f8d15b 100644 --- a/src/vk/vk_model.c +++ b/src/vk/vk_model.c @@ -1,24 +1,29 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. -Copyright (C) 2018-2019 Krzysztof Kondrak - -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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -// vk_model.c -- model loading and caching + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2018-2019 Krzysztof Kondrak + * + * 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 the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Model loading and caching. Includes the .bsp file format + * + * ======================================================================= + */ #include "header/local.h" @@ -33,12 +38,6 @@ static int models_known_max = 0; int registration_sequence; - -/* -============== -Mod_ClusterPVS -============== -*/ const byte * Mod_ClusterPVS(int cluster, const model_t *model) { @@ -55,11 +54,6 @@ Mod_ClusterPVS(int cluster, const model_t *model) //=============================================================================== -/* -=============== -Mod_Reallocate -=============== -*/ static void Mod_Reallocate (void) { @@ -88,11 +82,6 @@ Mod_Reallocate (void) models_known = calloc(models_known_max, sizeof(model_t)); } -/* -=============== -Mod_Init -=============== -*/ void Mod_Init(void) { @@ -107,12 +96,8 @@ Mod_Init(void) Mod_Reallocate (); } -/* -================ -Mod_Free -================ -*/ -static void Mod_Free (model_t *mod) +static void +Mod_Free(model_t *mod) { if (!mod->extradata) { @@ -135,12 +120,8 @@ static void Mod_Free (model_t *mod) } } -/* -================ -Mod_FreeAll -================ -*/ -void Mod_FreeAll (void) +void +Mod_FreeAll (void) { int i; @@ -151,30 +132,13 @@ void Mod_FreeAll (void) } } -/* -================ -Mod_FreeModelsKnown -================ -*/ -void Mod_FreeModelsKnown (void) +void +Mod_FreeModelsKnown (void) { free(models_known); models_known = NULL; } -/* -=============================================================================== - - BRUSHMODEL LOADING - -=============================================================================== -*/ - -/* -================= -Mod_LoadSubmodels -================= -*/ static void Mod_LoadSubmodels (model_t *loadmodel, const byte *mod_base, const lump_t *l) { @@ -220,9 +184,9 @@ Mod_LoadSubmodels (model_t *loadmodel, const byte *mod_base, const lump_t *l) } out->radius = Mod_RadiusFromBounds(out->mins, out->maxs); - out->firstnode = LittleLong (in->headnode); - out->firstmodelsurface = LittleLong (in->firstface); - out->nummodelsurfaces = LittleLong (in->numfaces); + out->firstnode = LittleLong(in->headnode); + out->firstmodelsurface = LittleLong(in->firstface); + out->nummodelsurfaces = LittleLong(in->numfaces); // visleafs out->numleafs = 0; // check limits @@ -235,12 +199,8 @@ Mod_LoadSubmodels (model_t *loadmodel, const byte *mod_base, const lump_t *l) } /* -================ -CalcSurfaceExtents - -Fills in s->texturemins[] and s->extents[] -================ -*/ + * Fills in s->texturemins[] and s->extents[] + */ static void CalcSurfaceExtents(model_t *loadmodel, msurface_t *s) { @@ -489,7 +449,7 @@ Mod_LoadBSPX(int filesize, byte* mod_base) } static void -SetSurfaceLighting(model_t* loadmodel, msurface_t* out, byte* styles, int lightofs) +SetSurfaceLighting(model_t *loadmodel, msurface_t *out, byte *styles, int lightofs) { int i; @@ -703,11 +663,6 @@ Mod_LoadLeafs(model_t *loadmodel, const byte *mod_base, const lump_t *l) } } -/* -================= -Mod_LoadMarksurfaces -================= -*/ static void Mod_LoadMarksurfaces(model_t *loadmodel, const byte *mod_base, const lump_t *l) { @@ -731,8 +686,7 @@ Mod_LoadMarksurfaces(model_t *loadmodel, const byte *mod_base, const lump_t *l) for (i = 0; i < count; i++) { - int j; - + int j; j = LittleShort(in[i]); if ((j < 0) || (j >= loadmodel->numsurfaces)) @@ -1032,12 +986,6 @@ RE_BeginRegistration (char *model) r_viewcluster = -1; } -/* -===================== -RE_RegisterModel - -===================== -*/ struct model_s * RE_RegisterModel(char *name) { @@ -1098,12 +1046,8 @@ Mod_HasFreeSpace(void) return (mod_loaded + mod_max) < models_known_max; } -/* -================ -Mod_Modellist_f -================ -*/ -void Mod_Modellist_f (void) +void +Mod_Modellist_f (void) { int i, total, used; model_t *mod; diff --git a/src/vk/vk_rsurf.c b/src/vk/vk_surf.c similarity index 97% rename from src/vk/vk_rsurf.c rename to src/vk/vk_surf.c index a452788..e739457 100644 --- a/src/vk/vk_rsurf.c +++ b/src/vk/vk_surf.c @@ -1,24 +1,30 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. -Copyright (C) 2018-2019 Krzysztof Kondrak + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2018-2019 Krzysztof Kondrak + * + * 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 the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Surface generation and drawing + * + * ======================================================================= + */ -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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -// vk_rsurf.c: surface-related refresh code #include #include "header/local.h" diff --git a/src/vk/vk_warp.c b/src/vk/vk_warp.c index 8988a73..1a9f864 100644 --- a/src/vk/vk_warp.c +++ b/src/vk/vk_warp.c @@ -684,7 +684,7 @@ void R_DrawSkyBox (void) /* ============ -RE_SetSky_s +RE_SetSky ============ */ // 3dstudio environment map names