Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move cameras to per-map files #169

Merged
merged 2 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions baseq2/cameras.txt

This file was deleted.

3 changes: 3 additions & 0 deletions baseq2/maps/cameras/base3.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions baseq2/maps/cameras/fact2.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions baseq2/maps/cameras/jail1.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions baseq2/maps/cameras/jail2.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions baseq2/maps/cameras/jail3.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions baseq2/maps/cameras/jail5.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions baseq2/maps/cameras/lab.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(-2008.9, 678.2, 206.1) (0.001, -0.810, -0.586)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the to original cameras.txt had a comment for the "lab" map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
58 changes: 2 additions & 56 deletions src/refresh/vkpt/bsp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
#include <float.h>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
Expand Down
86 changes: 86 additions & 0 deletions src/refresh/vkpt/cameras.c
Original file line number Diff line number Diff line change
@@ -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 <string.h>

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++;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be helpful for map authors to print a message if MAX_CAMERAS is exceeded.

}
}

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");
}
28 changes: 28 additions & 0 deletions src/refresh/vkpt/cameras.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/refresh/vkpt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -3657,6 +3659,7 @@ R_Shutdown_RTX(qboolean total)
#endif

vkpt_fog_shutdown();
vkpt_cameras_shutdown();
MAT_Shutdown();
IMG_FreeAll();
vkpt_textures_destroy_unused();
Expand Down