From ca955e60877e0d4e14c5caed6bafe8a8b540e6b4 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 15 Dec 2021 13:48:07 -0500 Subject: [PATCH 1/2] move cameras to per-map files --- baseq2/cameras.txt | 36 --------------- baseq2/maps/cameras/base3.txt | 3 ++ baseq2/maps/cameras/fact2.txt | 5 ++ baseq2/maps/cameras/jail1.txt | 3 ++ baseq2/maps/cameras/jail2.txt | 4 ++ baseq2/maps/cameras/jail3.txt | 4 ++ baseq2/maps/cameras/jail5.txt | 2 + baseq2/maps/cameras/lab.txt | 1 + src/CMakeLists.txt | 2 + src/refresh/vkpt/bsp_mesh.c | 58 +---------------------- src/refresh/vkpt/cameras.c | 86 +++++++++++++++++++++++++++++++++++ src/refresh/vkpt/cameras.h | 28 ++++++++++++ src/refresh/vkpt/main.c | 3 ++ 13 files changed, 143 insertions(+), 92 deletions(-) delete mode 100644 baseq2/cameras.txt create mode 100644 baseq2/maps/cameras/base3.txt create mode 100644 baseq2/maps/cameras/fact2.txt create mode 100644 baseq2/maps/cameras/jail1.txt create mode 100644 baseq2/maps/cameras/jail2.txt create mode 100644 baseq2/maps/cameras/jail3.txt create mode 100644 baseq2/maps/cameras/jail5.txt create mode 100644 baseq2/maps/cameras/lab.txt create mode 100644 src/refresh/vkpt/cameras.c create mode 100644 src/refresh/vkpt/cameras.h diff --git a/baseq2/cameras.txt b/baseq2/cameras.txt deleted file mode 100644 index 8c7d0d462..000000000 --- a/baseq2/cameras.txt +++ /dev/null @@ -1,36 +0,0 @@ -base3 -(-347.3, -278.2, -90.1) (-0.489, -0.685, -0.540) -(1171.9, -1010.7, -369.2) (-0.764, 0.588, -0.266) -(1004.4, 1200.4, -694.4) (-0.713, -0.619, -0.329) - -jail1 -(-1049.7, -121.4, 115.1) (0.590, -0.539, -0.601) -(-2167.2, -573.2, 305.4) (-0.224, 0.900, -0.374) -(-1550.7, -875.6, 8.4) (-0.835, -0.441, -0.329) - -jail2 -(-1095.1, -793.7, -102.4) (0.738, 0.557, -0.380) -(-424.1, 296.2, 355.7) (0.898, 0.115, -0.424) -(-1342.3, 321.9, 280.1) (-0.700, -0.004, -0.714) -(1102.8, 173.4, 226.9) (0.626, 0.642, -0.442) - -jail3 -(-603.2, -514.6, 951.3) (0.288, 0.930, -0.228) -(691.6, -887.2, 895.8) (-0.694, 0.484, -0.533) -(1404.9, -1161.3, 513.6) (0.538, 0.843, 0.005) -(-618.4, 911.7, 352.7) (0.600, 0.656, -0.458) - -jail5 -(94.6, 128.2, 325.2) (-0.002, -0.733, -0.681) -(207.4, 1169.9, 308.3) (-0.615, -0.392, -0.684) - -lab -# the only monitor in this map has two connected faces - can only have one camera here -(-2008.9, 678.2, 206.1) (0.001, -0.810, -0.586) - -fact2 -(1302.4, -2342.9, -70.1) (-0.672, 0.635, -0.381) -(139.6, -1240.8, 262.9) (-0.532, -0.722, -0.442) -(-529.9, -1038.6, 201.4) (-0.565, 0.653, -0.504) -(-913.2, 215.9, 230.7) (-0.814, -0.457, -0.358) -(618.1, -2516.6, -11.7) (-0.692, -0.575, -0.436) \ No newline at end of file diff --git a/baseq2/maps/cameras/base3.txt b/baseq2/maps/cameras/base3.txt new file mode 100644 index 000000000..733bf52c5 --- /dev/null +++ b/baseq2/maps/cameras/base3.txt @@ -0,0 +1,3 @@ +(-347.3, -278.2, -90.1) (-0.489, -0.685, -0.540) +(1171.9, -1010.7, -369.2) (-0.764, 0.588, -0.266) +(1004.4, 1200.4, -694.4) (-0.713, -0.619, -0.329) \ No newline at end of file diff --git a/baseq2/maps/cameras/fact2.txt b/baseq2/maps/cameras/fact2.txt new file mode 100644 index 000000000..33660a620 --- /dev/null +++ b/baseq2/maps/cameras/fact2.txt @@ -0,0 +1,5 @@ +(1302.4, -2342.9, -70.1) (-0.672, 0.635, -0.381) +(139.6, -1240.8, 262.9) (-0.532, -0.722, -0.442) +(-529.9, -1038.6, 201.4) (-0.565, 0.653, -0.504) +(-913.2, 215.9, 230.7) (-0.814, -0.457, -0.358) +(618.1, -2516.6, -11.7) (-0.692, -0.575, -0.436) \ No newline at end of file diff --git a/baseq2/maps/cameras/jail1.txt b/baseq2/maps/cameras/jail1.txt new file mode 100644 index 000000000..ca75ec594 --- /dev/null +++ b/baseq2/maps/cameras/jail1.txt @@ -0,0 +1,3 @@ +(-1049.7, -121.4, 115.1) (0.590, -0.539, -0.601) +(-2167.2, -573.2, 305.4) (-0.224, 0.900, -0.374) +(-1550.7, -875.6, 8.4) (-0.835, -0.441, -0.329) \ No newline at end of file diff --git a/baseq2/maps/cameras/jail2.txt b/baseq2/maps/cameras/jail2.txt new file mode 100644 index 000000000..9f393f168 --- /dev/null +++ b/baseq2/maps/cameras/jail2.txt @@ -0,0 +1,4 @@ +(-1095.1, -793.7, -102.4) (0.738, 0.557, -0.380) +(-424.1, 296.2, 355.7) (0.898, 0.115, -0.424) +(-1342.3, 321.9, 280.1) (-0.700, -0.004, -0.714) +(1102.8, 173.4, 226.9) (0.626, 0.642, -0.442) \ No newline at end of file diff --git a/baseq2/maps/cameras/jail3.txt b/baseq2/maps/cameras/jail3.txt new file mode 100644 index 000000000..4d2a9a41f --- /dev/null +++ b/baseq2/maps/cameras/jail3.txt @@ -0,0 +1,4 @@ +(-603.2, -514.6, 951.3) (0.288, 0.930, -0.228) +(691.6, -887.2, 895.8) (-0.694, 0.484, -0.533) +(1404.9, -1161.3, 513.6) (0.538, 0.843, 0.005) +(-618.4, 911.7, 352.7) (0.600, 0.656, -0.458) \ No newline at end of file diff --git a/baseq2/maps/cameras/jail5.txt b/baseq2/maps/cameras/jail5.txt new file mode 100644 index 000000000..aa68e5d0d --- /dev/null +++ b/baseq2/maps/cameras/jail5.txt @@ -0,0 +1,2 @@ +(94.6, 128.2, 325.2) (-0.002, -0.733, -0.681) +(207.4, 1169.9, 308.3) (-0.615, -0.392, -0.684) \ No newline at end of file diff --git a/baseq2/maps/cameras/lab.txt b/baseq2/maps/cameras/lab.txt new file mode 100644 index 000000000..0a70f35d0 --- /dev/null +++ b/baseq2/maps/cameras/lab.txt @@ -0,0 +1 @@ +(-2008.9, 678.2, 206.1) (0.001, -0.810, -0.586) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7666b5a4b..5271c48ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -268,6 +268,7 @@ SET(SRC_VKPT refresh/vkpt/bsp_mesh.c refresh/vkpt/draw.c refresh/vkpt/fog.c + refresh/vkpt/cameras.c refresh/vkpt/freecam.c refresh/vkpt/fsr.c refresh/vkpt/main.c @@ -298,6 +299,7 @@ SET(HEADERS_VKPT refresh/vkpt/buddy_allocator.h refresh/vkpt/device_memory_allocator.h refresh/vkpt/fog.h + refresh/vkpt/cameras.h refresh/vkpt/material.h refresh/vkpt/physical_sky.h refresh/vkpt/precomputed_sky.h diff --git a/src/refresh/vkpt/bsp_mesh.c b/src/refresh/vkpt/bsp_mesh.c index 85e6bd15f..f2a6a8472 100644 --- a/src/refresh/vkpt/bsp_mesh.c +++ b/src/refresh/vkpt/bsp_mesh.c @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "vkpt.h" #include "shader/global_textures.h" #include "material.h" +#include "cameras.h" #include #include @@ -1524,61 +1525,6 @@ load_sky_and_lava_clusters(bsp_mesh_t* wm, const char* map_name) Z_Free(filebuf); } - -static void -load_cameras(bsp_mesh_t* wm, const char* map_name) -{ - wm->num_cameras = 0; - - char* filebuf = NULL; - FS_LoadFile("cameras.txt", (void**)&filebuf); - if (!filebuf) - { - Com_WPrintf("Couldn't read cameras.txt\n"); - return; - } - - char const * ptr = (char const *)filebuf; - char linebuf[1024]; - qboolean found_map = qfalse; - - while (sgets(linebuf, sizeof(linebuf), &ptr)) - { - { char* t = strchr(linebuf, '#'); if (t) *t = 0; } // remove comments - { char* t = strchr(linebuf, '\n'); if (t) *t = 0; } // remove newline - - - vec3_t pos, dir; - if ((linebuf[0] >= 'a' && linebuf[0] <= 'z') || (linebuf[0] >= 'A' && linebuf[0] <= 'Z')) - { - const char* delimiters = " \t\r\n"; - const char* word = strtok(linebuf, delimiters); - qboolean matches = strcmp(word, map_name) == 0; - - if (!found_map && matches) - { - found_map = qtrue; - } - else if (found_map && !matches) - { - Z_Free(filebuf); - return; - } - } - else if (found_map && sscanf(linebuf, "(%f, %f, %f) (%f, %f, %f)", &pos[0], &pos[1], &pos[2], &dir[0], &dir[1], &dir[2]) == 6) - { - if (wm->num_cameras < MAX_CAMERAS) - { - VectorCopy(pos, wm->cameras[wm->num_cameras].pos); - VectorCopy(dir, wm->cameras[wm->num_cameras].dir); - wm->num_cameras++; - } - } - } - - Z_Free(filebuf); -} - static void compute_sky_visibility(bsp_mesh_t *wm, bsp_t *bsp) { @@ -1862,7 +1808,7 @@ bsp_mesh_create_from_bsp(bsp_mesh_t *wm, bsp_t *bsp, const char* map_name) full_game_map_name = "base3"; load_sky_and_lava_clusters(wm, full_game_map_name); - load_cameras(wm, full_game_map_name); + vkpt_cameras_load(wm, full_game_map_name); wm->models = Z_Malloc(bsp->nummodels * sizeof(bsp_model_t)); memset(wm->models, 0, bsp->nummodels * sizeof(bsp_model_t)); diff --git a/src/refresh/vkpt/cameras.c b/src/refresh/vkpt/cameras.c new file mode 100644 index 000000000..adc4ca95c --- /dev/null +++ b/src/refresh/vkpt/cameras.c @@ -0,0 +1,86 @@ +/* +Copyright (C) 2021, NVIDIA CORPORATION. All rights reserved. + +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., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "cameras.h" +#include "vkpt.h" + +#include + +void +vkpt_cameras_load(bsp_mesh_t* wm, const char* map_name) +{ + wm->num_cameras = 0; + + char* filebuf = NULL; + + char filename[MAX_QPATH]; + Q_snprintf(filename, sizeof(filename), "maps/cameras/%s.txt", map_name); + FS_LoadFile(filename, (void**)&filebuf); + + if (!filebuf) + { + Com_DPrintf("Couldn't read %s\n", filename); + return; + } + + char const * ptr = (char const *)filebuf; + char linebuf[1024]; + + while (sgets(linebuf, sizeof(linebuf), &ptr)) + { + { char* t = strchr(linebuf, '#'); if (t) *t = 0; } // remove comments + { char* t = strchr(linebuf, '\n'); if (t) *t = 0; } // remove newline + + vec3_t pos, dir; + + if (sscanf(linebuf, "(%f, %f, %f) (%f, %f, %f)", &pos[0], &pos[1], &pos[2], &dir[0], &dir[1], &dir[2]) == 6) + { + if (wm->num_cameras < MAX_CAMERAS) + { + VectorCopy(pos, wm->cameras[wm->num_cameras].pos); + VectorCopy(dir, wm->cameras[wm->num_cameras].dir); + wm->num_cameras++; + } + } + } + + Z_Free(filebuf); +} + +static void Camera_Cmd_f(void) +{ + vec3_t forward; + AngleVectors(vkpt_refdef.fd->viewangles, forward, NULL, NULL); + + Com_Printf("(%f, %f, %f) (%f, %f, %f)\n", vkpt_refdef.fd->vieworg[0], vkpt_refdef.fd->vieworg[1], vkpt_refdef.fd->vieworg[2], forward[0], forward[1], forward[2]); +} + +static const cmdreg_t cmds[] = { + { "camera", &Camera_Cmd_f, NULL }, + { NULL, NULL, NULL } +}; + +void vkpt_cameras_init(void) +{ + Cmd_Register(cmds); +} + +void vkpt_cameras_shutdown(void) +{ + Cmd_RemoveCommand("camera"); +} diff --git a/src/refresh/vkpt/cameras.h b/src/refresh/vkpt/cameras.h new file mode 100644 index 000000000..7712c0b9f --- /dev/null +++ b/src/refresh/vkpt/cameras.h @@ -0,0 +1,28 @@ +/* +Copyright (C) 2021, NVIDIA CORPORATION. All rights reserved. + +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., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __CAMERAS_H_ +#define __CAMERAS_H_ + +typedef struct bsp_mesh_s bsp_mesh_t; + +void vkpt_cameras_init(void); +void vkpt_cameras_shutdown(void); +void vkpt_cameras_load(bsp_mesh_t* wm, const char* map_name); + +#endif \ No newline at end of file diff --git a/src/refresh/vkpt/main.c b/src/refresh/vkpt/main.c index 94641a44d..e2cd80275 100644 --- a/src/refresh/vkpt/main.c +++ b/src/refresh/vkpt/main.c @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "vkpt.h" #include "material.h" #include "fog.h" +#include "cameras.h" #include "physical_sky.h" #include "conversion.h" #include "../../client/client.h" @@ -3622,6 +3623,7 @@ R_Init_RTX(qboolean total) #endif vkpt_fog_init(); + vkpt_cameras_init(); for (int i = 0; i < 256; i++) { qvk.sintab[i] = sinf(i * (2 * M_PI / 255)); @@ -3657,6 +3659,7 @@ R_Shutdown_RTX(qboolean total) #endif vkpt_fog_shutdown(); + vkpt_cameras_shutdown(); MAT_Shutdown(); IMG_FreeAll(); vkpt_textures_destroy_unused(); From b9c546b7fad9c89dac7ee7d7a65a14e73837f38a Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 16 Dec 2021 12:03:04 -0500 Subject: [PATCH 2/2] Re-add missing comment from lab Break early and warn on too many cameras --- baseq2/maps/cameras/lab.txt | 1 + src/refresh/vkpt/cameras.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/baseq2/maps/cameras/lab.txt b/baseq2/maps/cameras/lab.txt index 0a70f35d0..7f2eaa89a 100644 --- a/baseq2/maps/cameras/lab.txt +++ b/baseq2/maps/cameras/lab.txt @@ -1 +1,2 @@ +# the only monitor in this map has two connected faces - can only have one camera here (-2008.9, 678.2, 206.1) (0.001, -0.810, -0.586) \ No newline at end of file diff --git a/src/refresh/vkpt/cameras.c b/src/refresh/vkpt/cameras.c index adc4ca95c..cb455e33b 100644 --- a/src/refresh/vkpt/cameras.c +++ b/src/refresh/vkpt/cameras.c @@ -56,6 +56,11 @@ vkpt_cameras_load(bsp_mesh_t* wm, const char* map_name) VectorCopy(dir, wm->cameras[wm->num_cameras].dir); wm->num_cameras++; } + else + { + Com_WPrintf("Map has too many cameras (max: %i)\n", MAX_CAMERAS); + break; + } } }