Isolate model submodule

Isolate model from rest of the project, minor cleanups.
This commit is contained in:
Azamat H. Hackimov 2024-07-28 02:35:22 +03:00
parent 7b31572d05
commit 9e3563de4d
13 changed files with 153 additions and 192 deletions

View File

@ -85,7 +85,6 @@ set(HEADERS
newui_core.h
object.h
object_external.h
object_external_struct.h
object_lighting.h
objinfo.h
objinit.h
@ -108,8 +107,6 @@ set(HEADERS
resource.h
robot.h
robotfire.h
robotfirestruct.h
robotfirestruct_external.h
room.h
room_external.h
scorch.h

View File

@ -438,28 +438,28 @@
*
*/
#include "viseffect.h"
#include "fireball.h"
#include "terrain.h"
#include "game.h"
#include "room.h"
#include "vclip.h"
#include "gametexture.h"
#include "object.h"
#include <algorithm>
#include <cstdlib>
#include <memory.h>
#include <stdlib.h>
#include "PHYSICS.H"
#include "weapon.h"
#include "lighting.h"
#include "dedicated_server.h"
#include "player.h"
#include "config.h"
#include "weather.h"
#include "dedicated_server.h"
#include "fireball.h"
#include "game.h"
#include "gametexture.h"
#include "lighting.h"
#include "mem.h"
#include "object.h"
#include "PHYSICS.H"
#include "player.h"
#include "polymodel.h"
#include "psrand.h"
#include "mem.h"
#include <algorithm>
#include "room.h"
#include "terrain.h"
#include "vclip.h"
#include "viseffect.h"
#include "weapon.h"
#include "weather.h"
// DAJ vis_effect VisEffects[max_vis_effects];
// DAJ uint16_t VisDeadList[max_vis_effects];

View File

@ -85,7 +85,6 @@ set(HEADERS
../descent3/newui_core.h
../descent3/object.h
../descent3/object_external.h
../descent3/object_external_struct.h
../descent3/object_lighting.h
../descent3/objinfo.h
../descent3/objinit.h
@ -108,8 +107,6 @@ set(HEADERS
../descent3/resource.h
../descent3/robot.h
../descent3/robotfire.h
../descent3/robotfirestruct.h
../descent3/robotfirestruct_external.h
../descent3/room.h
../descent3/room_external.h
../descent3/scorch.h

View File

@ -53,13 +53,15 @@
* $NoKeywords: $
*/
#ifndef __POLYMODEL_EXTERNAL_H_
#define __POLYMODEL_EXTERNAL_H_
#ifndef POLYMODEL_EXTERNAL_H_
#define POLYMODEL_EXTERNAL_H_
#include <cstdint>
#include "vecmat_external.h"
#include "pstypes.h"
#include "grdefs.h"
#include "manage_external.h"
#include "robotfirestruct.h"
#include "vecmat_external.h"
#define MAX_POLY_MODELS 1200

View File

@ -19,9 +19,10 @@
#ifndef ROBOTFIRESTRUCT_H_
#define ROBOTFIRESTRUCT_H_
#include "pstypes.h"
#include "vecmat.h"
#include <cstdint>
#include "robotfirestruct_external.h"
#include "vecmat.h"
// NOTE: CHANGE gunbattery.h (IN POFGEN PROJECT) if constants are changed
// NOTE: Robots are limited to the number of wb configurations of the player. This seem like an

View File

@ -27,6 +27,7 @@ target_link_libraries(manage PRIVATE
ddio
mem
misc
model
sndlib
stream_audio
)

View File

@ -1,11 +1,16 @@
set(HEADERS)
set(CPPS
newstyle.cpp
polymodel.cpp)
polymodel.cpp
)
add_library(model STATIC ${HEADERS} ${CPPS})
add_library(model STATIC ${CPPS})
target_link_libraries(model PRIVATE
ddio
mem
misc
)
target_include_directories(model PUBLIC
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/model
>
)

View File

@ -77,29 +77,23 @@
*
*/
#include "pserror.h"
#include "pstypes.h"
#include <cstdlib>
#include "3d.h"
#include "vecmat.h"
#include "grdefs.h"
#include "polymodel.h"
#include "gametexture.h"
#include "byteswap.h"
#include "renderer.h"
#include "lighting.h"
#include "game.h"
#include "render.h"
#include "fireball.h"
#include "lightmap_info.h"
#include "lightmap.h"
#include "lighting.h"
#include "findintersection.h"
#include <stdlib.h>
#include <string.h>
#include "fireball.h"
#include "game.h"
#include "gametexture.h"
#include "grdefs.h"
#include "lighting.h"
#include "lightmap.h"
#include "lightmap_info.h"
#include "polymodel.h"
#include "pserror.h"
#include "psrand.h"
#include "render.h"
#include "renderer.h"
#include "vecmat.h"
static float face_depth[MAX_POLYGON_VECS];
static uint8_t triangulated_faces[MAX_FACES_PER_ROOM];
@ -186,7 +180,7 @@ inline void RenderSubmodelFace(poly_model *pm, bsp_info *sm, int facenum) {
int smooth = 0;
polyface *fp = &sm->faces[facenum];
int modelnum = sm - pm->submodel;
texture *texp = NULL;
texture *texp = nullptr;
int t;
int custom = 0;
g3Codes face_cc;
@ -1320,7 +1314,7 @@ float ComputeDefaultSizeFunc(int handle, float *size_ptr, vector *offset_ptr, bo
}
float ComputeDefaultSize(int type, int handle, float *size_ptr) {
float size = ComputeDefaultSizeFunc(handle, size_ptr, NULL, true);
float size = ComputeDefaultSizeFunc(handle, size_ptr, nullptr, true);
if (type != OBJ_WEAPON && type != OBJ_DEBRIS && type != OBJ_POWERUP) {
ComputeDefaultSizeFunc(handle, &Poly_models[handle].wall_size, &Poly_models[handle].wall_size_offset, false);

View File

@ -598,25 +598,22 @@
* $NoKeywords: $
*/
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include "3d.h"
#include "bitmap.h"
#include "ddio.h"
#include "game.h"
#include "gamesequence.h"
#include "gametexture.h"
#include "mem.h"
#include "mono.h"
#include "objinfo.h"
#include "polymodel.h"
#include "pserror.h"
#include "3d.h"
#include "mono.h"
#include "bitmap.h"
#include "renderer.h"
#include "manage.h"
#include "gametexture.h"
#include "lighting.h"
#include "ddio.h"
#include "game.h"
#include <stdlib.h>
#include <string.h>
#include "robotfire.h"
#include "mem.h"
#include "gamesequence.h"
#include <algorithm>
int Num_poly_models = 0;
poly_model Poly_models[MAX_POLY_MODELS];
@ -629,7 +626,7 @@ int Instance_vec_cnt = 0;
#ifdef _DEBUG
// Flag to draw an outline around the faces
bool Polymodel_outline_mode = 0;
bool Polymodel_outline_mode = false;
#endif
#define ID_OHDR 'RDHO' // POF file header
@ -653,7 +650,6 @@ polymodel_light_type Polymodel_light_type = POLYMODEL_LIGHTING_STATIC;
float Polylighting_static_red;
float Polylighting_static_green;
float Polylighting_static_blue;
uint8_t *Polylighting_gouraud;
lightmap_object *Polylighting_lightmap_object;
vector *Polymodel_light_direction, Polymodel_fog_plane, Polymodel_specular_pos, Polymodel_fog_portal_vert,
@ -681,9 +677,6 @@ static void FreeAllModels();
static void SetModelAnglesAndPosTimed(poly_model *po, float *normalized_time, uint32_t subobj_flags);
static void BuildModelAngleMatrix(matrix *mat, angle ang, vector *axis);
int findtextbmpname = 0;
int findtextname = 0;
void WBClearInfo(poly_model *pm) { pm->num_wbs = 0; }
inline void RecursiveAssignWB(poly_model *pm, int sm_index, int wb_index) {
@ -756,91 +749,91 @@ void FreePolymodelData(int i) {
if (Poly_models[i].submodel) {
if (Poly_models[i].submodel[t].keyframe_axis) {
mem_free(Poly_models[i].submodel[t].keyframe_axis);
Poly_models[i].submodel[t].keyframe_axis = NULL;
Poly_models[i].submodel[t].keyframe_axis = nullptr;
}
if (Poly_models[i].submodel[t].tick_pos_remap) {
mem_free(Poly_models[i].submodel[t].tick_pos_remap);
Poly_models[i].submodel[t].tick_pos_remap = NULL;
Poly_models[i].submodel[t].tick_pos_remap = nullptr;
}
if (Poly_models[i].submodel[t].tick_ang_remap) {
mem_free(Poly_models[i].submodel[t].tick_ang_remap);
Poly_models[i].submodel[t].tick_ang_remap = NULL;
Poly_models[i].submodel[t].tick_ang_remap = nullptr;
}
if (Poly_models[i].submodel[t].keyframe_angles) {
mem_free(Poly_models[i].submodel[t].keyframe_angles);
Poly_models[i].submodel[t].keyframe_angles = NULL;
Poly_models[i].submodel[t].keyframe_angles = nullptr;
}
if (Poly_models[i].submodel[t].keyframe_matrix) {
mem_free(Poly_models[i].submodel[t].keyframe_matrix);
Poly_models[i].submodel[t].keyframe_matrix = NULL;
Poly_models[i].submodel[t].keyframe_matrix = nullptr;
}
if (Poly_models[i].submodel[t].keyframe_pos) {
mem_free(Poly_models[i].submodel[t].keyframe_pos);
Poly_models[i].submodel[t].keyframe_pos = NULL;
Poly_models[i].submodel[t].keyframe_pos = nullptr;
}
if (Poly_models[i].submodel[t].verts) {
mem_free(Poly_models[i].submodel[t].verts);
Poly_models[i].submodel[t].verts = NULL;
Poly_models[i].submodel[t].verts = nullptr;
}
if (Poly_models[i].submodel[t].vertnorms) {
mem_free(Poly_models[i].submodel[t].vertnorms);
Poly_models[i].submodel[t].vertnorms = NULL;
Poly_models[i].submodel[t].vertnorms = nullptr;
}
if (Poly_models[i].submodel[t].alpha) {
mem_free(Poly_models[i].submodel[t].alpha);
Poly_models[i].submodel[t].alpha = NULL;
Poly_models[i].submodel[t].alpha = nullptr;
}
if (Poly_models[i].submodel[t].vertnum_memory) {
mem_free(Poly_models[i].submodel[t].vertnum_memory);
Poly_models[i].submodel[t].vertnum_memory = NULL;
Poly_models[i].submodel[t].vertnum_memory = nullptr;
}
if (Poly_models[i].submodel[t].u_memory) {
mem_free(Poly_models[i].submodel[t].u_memory);
Poly_models[i].submodel[t].u_memory = NULL;
Poly_models[i].submodel[t].u_memory = nullptr;
}
if (Poly_models[i].submodel[t].v_memory) {
mem_free(Poly_models[i].submodel[t].v_memory);
Poly_models[i].submodel[t].v_memory = NULL;
Poly_models[i].submodel[t].v_memory = nullptr;
}
if (Poly_models[i].flags & PMF_TIMED) {
if (Poly_models[i].submodel[t].rot_start_time) {
mem_free(Poly_models[i].submodel[t].rot_start_time);
Poly_models[i].submodel[t].rot_start_time = NULL;
Poly_models[i].submodel[t].rot_start_time = nullptr;
}
if (Poly_models[i].submodel[t].pos_start_time) {
mem_free(Poly_models[i].submodel[t].pos_start_time);
Poly_models[i].submodel[t].pos_start_time = NULL;
Poly_models[i].submodel[t].pos_start_time = nullptr;
}
}
if (Poly_models[i].submodel[t].flags & (SOF_GLOW | SOF_THRUSTER)) {
mem_free(Poly_models[i].submodel[t].glow_info);
Poly_models[i].submodel[t].glow_info = NULL;
Poly_models[i].submodel[t].glow_info = nullptr;
}
if (Poly_models[i].submodel[t].faces) {
mem_free(Poly_models[i].submodel[t].faces);
Poly_models[i].submodel[t].faces = NULL;
Poly_models[i].submodel[t].faces = nullptr;
if (Poly_models[i].submodel[t].face_min) {
mem_free(Poly_models[i].submodel[t].face_min);
Poly_models[i].submodel[t].face_min = NULL;
Poly_models[i].submodel[t].face_min = nullptr;
}
if (Poly_models[i].submodel[t].face_max) {
mem_free(Poly_models[i].submodel[t].face_max);
Poly_models[i].submodel[t].face_max = NULL;
Poly_models[i].submodel[t].face_max = nullptr;
}
}
}
@ -848,28 +841,28 @@ void FreePolymodelData(int i) {
if (Poly_models[i].model_data) {
mem_free(Poly_models[i].model_data);
Poly_models[i].model_data = NULL;
Poly_models[i].model_data = nullptr;
}
if (Poly_models[i].gun_slots) {
mem_free(Poly_models[i].gun_slots);
Poly_models[i].gun_slots = NULL;
Poly_models[i].gun_slots = nullptr;
}
if (Poly_models[i].poly_wb) {
mem_free(Poly_models[i].poly_wb);
Poly_models[i].poly_wb = NULL;
Poly_models[i].poly_wb = nullptr;
}
if (Poly_models[i].attach_slots) {
mem_free(Poly_models[i].attach_slots);
Poly_models[i].attach_slots = NULL;
Poly_models[i].attach_slots = nullptr;
}
if (Poly_models[i].ground_slots) {
mem_free(Poly_models[i].ground_slots);
Poly_models[i].ground_slots = NULL;
Poly_models[i].ground_slots = nullptr;
}
if (Poly_models[i].submodel) {
mem_free(Poly_models[i].submodel);
Poly_models[i].submodel = NULL;
Poly_models[i].submodel = nullptr;
}
Poly_models[i].flags |= PMF_NOT_RESIDENT;
@ -1095,7 +1088,7 @@ void SetPolymodelProperties(bsp_info *subobj, char *props) {
subobj->flags |= SOF_GLOW;
if (subobj->glow_info == NULL) // DAJ may already exist
if (subobj->glow_info == nullptr) // DAJ may already exist
subobj->glow_info = (glowinfo *)mem_malloc(sizeof(glowinfo));
subobj->glow_info->glow_r = r;
@ -1119,7 +1112,7 @@ void SetPolymodelProperties(bsp_info *subobj, char *props) {
subobj->flags |= SOF_THRUSTER;
if (subobj->glow_info == NULL) // DAJ may already exist
if (subobj->glow_info == nullptr) // DAJ may already exist
subobj->glow_info = (glowinfo *)mem_malloc(sizeof(glowinfo));
subobj->glow_info->glow_r = r;
@ -1157,13 +1150,13 @@ void SetPolymodelProperties(bsp_info *subobj, char *props) {
if (reaction_time < 0.0f || reaction_time > 10.0f) {
// Bad data
ASSERT(0);
reaction_time = 10.0;
reaction_time = 10.0f;
}
subobj->flags |= SOF_TURRET;
subobj->fov = fov_angle / 720.0f; // 720 = 360 * 2 and we want to make fov the amount we can move in either
// direction it has a minimum value of (0.0) to [0.5]
subobj->rps = 1.0 / turret_spr; // convert spr to rps (rotations per second)
subobj->rps = 1.0f / turret_spr; // convert spr to rps (rotations per second)
subobj->think_interval = reaction_time;
return;
@ -1340,7 +1333,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->rad = cf_ReadFloat(infile);
pm->submodel = (bsp_info *)mem_malloc(sizeof(bsp_info) * pm->n_models);
ASSERT(pm->submodel != NULL);
ASSERT(pm->submodel != nullptr);
memset(pm->submodel, 0, sizeof(bsp_info) * pm->n_models);
ReadModelVector(&pm->mins, infile);
@ -1436,11 +1429,11 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
ASSERT(pm->submodel[n].alpha);
} else {
// Let me take a moment right here to say how annoying it is that I can't
// set all these pointers to NULL with one assignment on the same line due
// set all these pointers to nullptr with one assignment on the same line due
// to the stupid strong typying they've added to C.
pm->submodel[n].verts = NULL;
pm->submodel[n].vertnorms = NULL;
pm->submodel[n].alpha = NULL;
pm->submodel[n].verts = nullptr;
pm->submodel[n].vertnorms = nullptr;
pm->submodel[n].alpha = nullptr;
}
pm->submodel[n].nverts = nverts;
@ -1488,9 +1481,9 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->submodel[n].face_max = (vector *)mem_malloc(nfaces * sizeof(vector));
ASSERT(pm->submodel[n].faces);
} else {
pm->submodel[n].faces = NULL;
pm->submodel[n].face_max = NULL;
pm->submodel[n].face_min = NULL;
pm->submodel[n].faces = nullptr;
pm->submodel[n].face_max = nullptr;
pm->submodel[n].face_min = nullptr;
}
// Find out how much space we'll need
@ -1506,7 +1499,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
start_index = (int *)mem_malloc(sizeof(int) * nfaces);
ASSERT(start_index);
} else
start_index = NULL;
start_index = nullptr;
uint8_t tempbuf[2000];
@ -1542,9 +1535,9 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
sm->v_memory = (float *)mem_malloc(current_count * sizeof(float));
ASSERT(sm->v_memory);
} else {
sm->vertnum_memory = NULL;
sm->u_memory = NULL;
sm->v_memory = NULL;
sm->vertnum_memory = nullptr;
sm->u_memory = nullptr;
sm->v_memory = nullptr;
}
// Now go through and set up our fake pointers
@ -1627,7 +1620,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
case ID_GPNT:
pm->n_guns = cf_ReadInt(infile);
pm->gun_slots = (w_bank *)mem_malloc(sizeof(w_bank) * pm->n_guns);
ASSERT(pm->gun_slots != NULL);
ASSERT(pm->gun_slots != nullptr);
for (i = 0; i < pm->n_guns; i++) {
w_bank *bank = &pm->gun_slots[i];
@ -1648,7 +1641,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->n_attach = cf_ReadInt(infile);
if (pm->n_attach) {
pm->attach_slots = (a_bank *)mem_malloc(sizeof(a_bank) * pm->n_attach);
ASSERT(pm->attach_slots != NULL);
ASSERT(pm->attach_slots != nullptr);
for (i = 0; i < pm->n_attach; i++) {
a_bank *bank = &pm->attach_slots[i];
@ -1659,7 +1652,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
bank->f_uvec = false;
}
} else {
pm->attach_slots = NULL;
pm->attach_slots = nullptr;
}
break;
@ -1687,7 +1680,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
bank->f_uvec = f_uvec;
}
} else {
pm->attach_slots = NULL;
pm->attach_slots = nullptr;
}
break;
}
@ -1726,7 +1719,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->poly_wb[i].num_turrets = 8;
}
} else {
pm->poly_wb = NULL;
pm->poly_wb = nullptr;
}
break;
@ -1735,7 +1728,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
case ID_GROUND:
pm->n_ground = cf_ReadInt(infile);
pm->ground_slots = (w_bank *)mem_malloc(sizeof(w_bank) * pm->n_ground);
ASSERT(pm->ground_slots != NULL);
ASSERT(pm->ground_slots != nullptr);
for (i = 0; i < pm->n_ground; i++) {
w_bank *bank = &pm->ground_slots[i];
@ -1796,7 +1789,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->num_key_angles = nframes;
}
for (int i = 0; i < pm->n_models; i++) {
for (i = 0; i < pm->n_models; i++) {
if (timed) {
pm->submodel[i].num_key_angles = cf_ReadInt(infile);
@ -1816,7 +1809,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->submodel[i].keyframe_matrix = (matrix *)mem_malloc((pm->submodel[i].num_key_angles + 1) * sizeof(matrix));
if (timed) {
pm->submodel[i].rot_start_time = (int *)mem_malloc((pm->submodel[i].num_key_angles + 1) * sizeof(int));
ASSERT(pm->submodel[i].rot_start_time != NULL);
ASSERT(pm->submodel[i].rot_start_time != nullptr);
int num_ticks = (pm->submodel[i].rot_track_max - pm->submodel[i].rot_track_min);
@ -1824,15 +1817,15 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->submodel[i].tick_ang_remap = (uint16_t *)mem_malloc(num_ticks * 2);
ASSERT(pm->submodel[i].tick_ang_remap);
} else {
pm->submodel[i].tick_ang_remap = NULL;
pm->submodel[i].tick_ang_remap = nullptr;
}
}
ASSERT(pm->submodel[i].keyframe_axis != NULL);
ASSERT(pm->submodel[i].keyframe_angles != NULL);
ASSERT(pm->submodel[i].keyframe_matrix != NULL);
ASSERT(pm->submodel[i].keyframe_axis != nullptr);
ASSERT(pm->submodel[i].keyframe_angles != nullptr);
ASSERT(pm->submodel[i].keyframe_matrix != nullptr);
for (int t = 0; t < pm->submodel[i].num_key_angles; t++) {
for (t = 0; t < pm->submodel[i].num_key_angles; t++) {
vector *axis;
float mag;
@ -1878,7 +1871,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->num_key_pos = nframes;
}
for (int i = 0; i < pm->n_models; i++) {
for (i = 0; i < pm->n_models; i++) {
if (timed) {
pm->submodel[i].num_key_pos = cf_ReadInt(infile);
pm->submodel[i].pos_track_min = cf_ReadInt(infile);
@ -1895,21 +1888,21 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
pm->submodel[i].tick_pos_remap = (uint16_t *)mem_malloc(num_ticks * 2);
ASSERT(pm->submodel[i].tick_pos_remap);
} else {
pm->submodel[i].tick_pos_remap = NULL;
pm->submodel[i].tick_pos_remap = nullptr;
}
} else
pm->submodel[i].num_key_pos = nframes;
pm->submodel[i].keyframe_pos = (vector *)mem_malloc((pm->submodel[i].num_key_pos + 1) * sizeof(vector));
ASSERT(pm->submodel[i].keyframe_pos != NULL);
ASSERT(pm->submodel[i].keyframe_pos != nullptr);
if (timed) {
pm->submodel[i].pos_start_time = (int *)mem_malloc((pm->submodel[i].num_key_pos + 1) * sizeof(int));
ASSERT(pm->submodel[i].pos_start_time != NULL);
ASSERT(pm->submodel[i].pos_start_time != nullptr);
}
for (int t = 0; t < pm->submodel[i].num_key_pos; t++) {
for (t = 0; t < pm->submodel[i].num_key_pos; t++) {
if (timed)
pm->submodel[i].pos_start_time[t] = cf_ReadInt(infile);
@ -1940,8 +1933,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
bsp_info *sm = &pm->submodel[i];
int newt;
for (newt = 0; newt < sm->num_key_angles; newt++) {
for (int newt = 0; newt < sm->num_key_angles; newt++) {
cur_angle = sm->keyframe_angles[newt];
BuildModelAngleMatrix(&temp_matrix, cur_angle, &sm->keyframe_axis[newt]);
vm_MakeIdentity(&dest_matrix);
@ -1975,8 +1967,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) {
vector vecs[30];
vector avg;
int newt;
for (newt = 0; newt < pm->submodel[i].faces[0].nverts; newt++) {
for (int newt = 0; newt < pm->submodel[i].faces[0].nverts; newt++) {
vecs[newt] = pm->submodel[i].verts[pm->submodel[i].faces[0].vertnums[newt]];
}
@ -2068,7 +2059,7 @@ int LoadPolyModel(const char *filename, int pageable) {
char name[256];
char fname[256], pname[256], extname[256];
int i, polynum = -1;
CFILE *infile = NULL;
CFILE *infile = nullptr;
int overlay = 0;
ASSERT(Num_poly_models >= 0);
@ -2437,7 +2428,7 @@ void SetNormalizedTimeAnim(float anim_frame, float *normalized_time, poly_model
// Given a model pointer and an array of floats that go from 0..1, calculate the angles of each
// corresponding subobject
void SetModelAngles(poly_model *po, float *normalized_angles) {
void SetModelAngles(poly_model *po, const float *normalized_angles) {
int i;
ASSERT(!(po->flags & PMF_NOT_RESIDENT));
@ -2554,7 +2545,7 @@ void SetModelAngles(poly_model *po, float *normalized_angles) {
// Given a model pointer and an array of floats that go from 0..1, calculate the interpolated
// position of each corresponding subobject
void SetModelInterpPos(poly_model *po, float *normalized_pos) {
void SetModelInterpPos(poly_model *po, const float *normalized_pos) {
int i;
ASSERT(!(po->flags & PMF_NOT_RESIDENT));
@ -2893,13 +2884,10 @@ void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normali
for (i = 0; i < po->n_models; i++) {
if ((f_render_sub & (1 << i))) {
if (i != 0) {
vector ofs;
vector save_offset;
// if submodel, rotate around its center point, not pivot point
ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
save_offset = po->submodel[i].offset;
vector ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
vector save_offset = po->submodel[i].offset;
vm_MakeZero(&po->submodel[i].offset);
vm_MakeZero(&po->submodel[i].mod_pos);
memset(&po->submodel[i].angs, 0, sizeof(angvec));
@ -2973,13 +2961,10 @@ void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normali
for (i = 0; i < po->n_models; i++) {
if ((f_render_sub & (1 << i))) {
if (i != 0) {
vector ofs;
vector save_offset;
// if submodel, rotate around its center point, not pivot point
ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
save_offset = po->submodel[i].offset;
vector ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
vector save_offset = po->submodel[i].offset;
vm_MakeZero(&po->submodel[i].offset);
vm_MakeZero(&po->submodel[i].mod_pos);
memset(&po->submodel[i].angs, 0, sizeof(angvec));
@ -3045,13 +3030,10 @@ void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normali
for (i = 0; i < po->n_models; i++) {
if ((f_render_sub & (1 << i))) {
if (i != 0) {
vector ofs;
vector save_offset;
// if submodel, rotate around its center point, not pivot point
ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
save_offset = po->submodel[i].offset;
vector ofs = (po->submodel[i].min + po->submodel[i].max) / 2;
vector save_offset = po->submodel[i].offset;
vm_MakeZero(&po->submodel[i].offset);
vm_MakeZero(&po->submodel[i].mod_pos);
memset(&po->submodel[i].angs, 0, sizeof(angvec));
@ -3084,9 +3066,9 @@ void FreeAllModels() {
// Inits our models array and loads our ship pof
int InitModels() {
for (int i = 0; i < MAX_POLY_MODELS; i++) {
memset(&Poly_models[i], 0, sizeof(poly_model));
Poly_models[i].used = 0;
for (auto & Poly_model : Poly_models) {
memset(&Poly_model, 0, sizeof(poly_model));
Poly_model.used = 0;
}
atexit(FreeAllModels);
@ -3172,7 +3154,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
int mn = subnum;
vector cur_norm;
if (norm != NULL)
if (norm != nullptr)
cur_norm = *norm;
matrix m;
@ -3186,7 +3168,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
tpnt = pnt * m;
if (norm != NULL)
if (norm != nullptr)
cur_norm = cur_norm * m;
pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos;
@ -3198,7 +3180,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
m = *orient;
vm_TransposeMatrix(&m);
if (norm != NULL)
if (norm != nullptr)
*norm = (cur_norm * m);
*dest = pnt * m;
*dest += (*wpos);
@ -3219,7 +3201,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
int mn = subnum;
vector cur_norm;
if (norm != NULL)
if (norm != nullptr)
cur_norm = *norm;
matrix m;
@ -3233,7 +3215,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
tpnt = pnt * m;
if (norm != NULL)
if (norm != nullptr)
cur_norm = cur_norm * m;
pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos;
@ -3245,7 +3227,7 @@ void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix
m = *orient;
vm_TransposeMatrix(&m);
if (norm != NULL)
if (norm != nullptr)
*norm = (cur_norm * m);
*dest = pnt * m;
*dest += (*wpos);

View File

@ -294,13 +294,12 @@
#ifndef POLYMODEL_H
#define POLYMODEL_H
#include "manage.h"
#include "pstypes.h"
#include "vecmat.h"
#include <cstdint>
#include "3d.h"
#include "robotfirestruct.h"
#include "polymodel_external.h"
#include "object_external_struct.h"
#include "polymodel_external.h"
#include "vecmat.h"
#define PM_COMPATIBLE_VERSION 1807
#define PM_OBJFILE_VERSION 2300
@ -319,24 +318,16 @@ extern polymodel_light_type Polymodel_light_type;
extern float Polylighting_static_red;
extern float Polylighting_static_green;
extern float Polylighting_static_blue;
extern uint8_t *Polylighting_gouraud;
extern vector *Polymodel_light_direction, Polymodel_fog_portal_vert, Polymodel_fog_plane, Polymodel_specular_pos,
Polymodel_bump_pos;
extern lightmap_object *Polylighting_lightmap_object;
extern vector Model_eye_position;
extern vector Interp_pos_instance_vec;
extern g3Point Robot_points[];
// Flag to draw an outline around the faces
extern bool Polymodel_outline_mode;
static inline float POLY_WIDTH(int model_num) { return Poly_models[model_num].maxs.x - Poly_models[model_num].mins.x; }
static inline float POLY_HEIGHT(int model_num) { return Poly_models[model_num].maxs.y - Poly_models[model_num].mins.y; }
static inline float POLY_DEPTH(int model_num) { return Poly_models[model_num].maxs.z - Poly_models[model_num].mins.z; }
// given a filename, reads in a POF and returns an index into the Poly_models array
// returns -1 if something is wrong
int LoadPolyModel(const char *filename, int pageable);
@ -344,7 +335,7 @@ int LoadPolyModel(const char *filename, int pageable);
// gets the filename from a path, plus appends our .pof extension
void ChangePolyModelName(const char *src, char *dest);
// Searches thru all polymodels for a specific name, returns -1 if not found
// Searches through all polymodels for a specific name, returns -1 if not found
// or index of polymodel with name
int FindPolyModelName(const char *name);
@ -366,13 +357,6 @@ void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normali
void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, int flags,
lightmap_object *lm_object, uint32_t f_render_sub, uint8_t use_effect = 0, uint8_t overlay = 0);
// gives the interpreter an array of points to use
void g3_SetInterpPoints(g3Point *pointlist);
// calls the object interpreter to render an object. The object renderer
// is really a seperate pipeline. returns true if drew
int InterpPolygonModel(poly_model *pm);
// Inits our models array
int InitModels();
@ -386,17 +370,14 @@ float GetNormalizedKeyframe(int handle, float num);
// Goes through all poly models and gets all missing textures
void RemapPolyModels();
// For macintosh, we must swap the interpreted model code
void SwapPolymodelData(uint8_t *data);
// Sets a positional instance
void StartPolyModelPosInstance(vector *posvec);
// Pops a positional instance
void DonePolyModelPosInstance();
void SetModelAngles(poly_model *po, float *normalized_angles);
void SetModelInterpPos(poly_model *po, float *normalized_pos);
void SetModelAngles(poly_model *po, const float *normalized_angles);
void SetModelInterpPos(poly_model *po, const float *normalized_pos);
void SetNormalizedTimeObj(object *obj, float *normalized_time);
void SetNormalizedTimeAnim(float norm_anim_frame, float *normalized_time, poly_model *pm);
@ -415,9 +396,9 @@ void RenderSubmodel(poly_model *pm, bsp_info *sm, uint32_t f_render_sub);
// returns point within polymodel/submodel in world coordinates.
void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix *orient, int subnum, vector *pos,
vector *norm = NULL);
vector *norm = nullptr);
void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix *orient, int subnum,
float *normalized_time, vector *pos, vector *norm = NULL);
float *normalized_time, vector *pos, vector *norm = nullptr);
// Returns 1 if this submodel shouldn't be rendered
int IsNonRenderableSubmodel(poly_model *pm, int submodelnum);
@ -426,7 +407,7 @@ int IsNonRenderableSubmodel(poly_model *pm, int submodelnum);
void SetPolymodelEffect(polymodel_effect *);
// Pages in a polymodel if its not already in memory
void PageInPolymodel(int polynum, int type = -1, float *size_ptr = NULL);
void PageInPolymodel(int polynum, int type = -1, float *size_ptr = nullptr);
// Gets a pointer to a polymodel. Pages it in if neccessary
poly_model *GetPolymodelPointer(int polynum);

View File

@ -10,5 +10,6 @@ target_link_libraries(physics PRIVATE
ddio
mem
misc
model
sndlib
)