light: c++ify remaining files

This commit is contained in:
Eric Wasylishen 2016-07-05 22:27:41 -06:00
parent 34bc864616
commit d225891ef5
5 changed files with 25 additions and 25 deletions

View File

@ -7,10 +7,10 @@ set(LIGHT_INCLUDES
${CMAKE_SOURCE_DIR}/include/light/litfile.h) ${CMAKE_SOURCE_DIR}/include/light/litfile.h)
set(LIGHT_SOURCES set(LIGHT_SOURCES
entities.c entities.cc
litfile.c litfile.cc
ltface.c ltface.cc
trace.c trace.cc
light.cc light.cc
${CMAKE_SOURCE_DIR}/common/bspfile.c ${CMAKE_SOURCE_DIR}/common/bspfile.c
${CMAKE_SOURCE_DIR}/common/cmdlib.c ${CMAKE_SOURCE_DIR}/common/cmdlib.c

View File

@ -73,7 +73,7 @@ SetKeyValue(entity_t *ent, const char *key, const char *value)
strcpy(ep->value, value); strcpy(ep->value, value);
return; return;
} }
ep = malloc(sizeof(*ep)); ep = (epair_t *) malloc(sizeof(*ep));
ep->next = ent->epairs; ep->next = ent->epairs;
ent->epairs = ep; ent->epairs = ep;
strcpy(ep->key, key); strcpy(ep->key, key);
@ -306,7 +306,7 @@ Dirt_ResolveFlag(int dirtInt)
static void static void
AddSun(vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt) AddSun(vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt)
{ {
sun_t *sun = malloc(sizeof(sun_t)); sun_t *sun = (sun_t *) malloc(sizeof(sun_t));
memset(sun, 0, sizeof(*sun)); memset(sun, 0, sizeof(*sun));
VectorCopy(sunvec, sun->sunvec); VectorCopy(sunvec, sun->sunvec);
VectorNormalize(sun->sunvec); VectorNormalize(sun->sunvec);
@ -938,7 +938,7 @@ LoadEntities(const bsp2_t *bsp)
logprint("lightmap_scale should be _lightmap_scale\n"); logprint("lightmap_scale should be _lightmap_scale\n");
} }
epair = malloc(sizeof(epair_t)); epair = (epair_t *) malloc(sizeof(epair_t));
memset(epair, 0, sizeof(epair_t)); memset(epair, 0, sizeof(epair_t));
strcpy(epair->key, key); strcpy(epair->key, key);
strcpy(epair->value, com_token); strcpy(epair->value, com_token);
@ -966,7 +966,7 @@ LoadEntities(const bsp2_t *bsp)
else if (!strcmp(key, "wait")) else if (!strcmp(key, "wait"))
entity->atten = atof(com_token); entity->atten = atof(com_token);
else if (!strcmp(key, "delay")) else if (!strcmp(key, "delay"))
entity->formula = atoi(com_token); entity->formula = static_cast<light_formula_t>(atoi(com_token));
else if (!strcmp(key, "mangle")) { else if (!strcmp(key, "mangle")) {
if (!projangleknown) if (!projangleknown)
scan_vec3(projangle, com_token, key); scan_vec3(projangle, com_token, key);
@ -1443,7 +1443,7 @@ WriteEntitiesToString(bsp2_t *bsp)
logprint("%i switchable light styles\n", numlighttargets); logprint("%i switchable light styles\n", numlighttargets);
bsp->entdatasize = Get_EntityStringSize(entities); bsp->entdatasize = Get_EntityStringSize(entities);
bsp->dentdata = malloc(bsp->entdatasize); bsp->dentdata = (char *) malloc(bsp->entdatasize);
if (!bsp->dentdata) if (!bsp->dentdata)
Error("%s: allocation of %d bytes failed\n", __func__, Error("%s: allocation of %d bytes failed\n", __func__,
bsp->entdatasize); bsp->entdatasize);

View File

@ -46,10 +46,10 @@ WriteLitFile(const bsp2_t *bsp, facesup_t *facesup, const char *filename, int ve
if (version == 2) if (version == 2)
{ {
unsigned int i, j; unsigned int i, j;
unsigned int *offsets = malloc(bsp->numfaces * sizeof(*offsets)); unsigned int *offsets = (unsigned int *) malloc(bsp->numfaces * sizeof(*offsets));
unsigned short *extents = malloc(2*bsp->numfaces * sizeof(*extents)); unsigned short *extents = (unsigned short *) malloc(2*bsp->numfaces * sizeof(*extents));
unsigned char *styles = malloc(4*bsp->numfaces * sizeof(*styles)); unsigned char *styles = (unsigned char *) malloc(4*bsp->numfaces * sizeof(*styles));
unsigned char *shifts = malloc(bsp->numfaces * sizeof(*shifts)); unsigned char *shifts = (unsigned char *) malloc(bsp->numfaces * sizeof(*shifts));
for (i = 0; i < bsp->numfaces; i++) for (i = 0; i < bsp->numfaces; i++)
{ {
offsets[i] = LittleLong(facesup[i].lightofs); offsets[i] = LittleLong(facesup[i].lightofs);

View File

@ -679,8 +679,8 @@ CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, lightsurf_t *surf,
/* Allocate surf->points */ /* Allocate surf->points */
surf->numpoints = surf->width * surf->height; surf->numpoints = surf->width * surf->height;
surf->points = calloc(surf->numpoints, sizeof(vec3_t)); surf->points = (vec3_t *) calloc(surf->numpoints, sizeof(vec3_t));
surf->normals = calloc(surf->numpoints, sizeof(vec3_t)); surf->normals = (vec3_t *) calloc(surf->numpoints, sizeof(vec3_t));
surf->occluded = (bool *)calloc(surf->numpoints, sizeof(bool)); surf->occluded = (bool *)calloc(surf->numpoints, sizeof(bool));
for (int t = 0; t < surf->height; t++) { for (int t = 0; t < surf->height; t++) {
@ -812,8 +812,8 @@ CalcPvs(const bsp2_t *bsp, lightsurf_t *lightsurf)
if (!bsp->visdatasize) return; if (!bsp->visdatasize) return;
// set lightsurf->pvs // set lightsurf->pvs
byte *pointpvs = calloc(pvssize, 1); byte *pointpvs = (byte *) calloc(pvssize, 1);
lightsurf->pvs = calloc(pvssize, 1); lightsurf->pvs = (byte *) calloc(pvssize, 1);
for (int i = 0; i < lightsurf->numpoints; i++) { for (int i = 0; i < lightsurf->numpoints; i++) {
const bsp2_dleaf_t *leaf = Light_PointInLeaf (bsp, lightsurf->points[i]); const bsp2_dleaf_t *leaf = Light_PointInLeaf (bsp, lightsurf->points[i]);
@ -912,7 +912,7 @@ Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face,
VectorAdd(lightsurf->origin, modelinfo->offset, lightsurf->origin); VectorAdd(lightsurf->origin, modelinfo->offset, lightsurf->origin);
/* Allocate occlusion array */ /* Allocate occlusion array */
lightsurf->occlusion = calloc(lightsurf->numpoints, sizeof(float)); lightsurf->occlusion = (float *) calloc(lightsurf->numpoints, sizeof(float));
/* Setup vis data */ /* Setup vis data */
CalcPvs(bsp, lightsurf); CalcPvs(bsp, lightsurf);
@ -955,7 +955,7 @@ Lightmap_ForStyle(lightmap_t *lightmaps, const int style, const lightsurf_t *lig
if (lightmap->samples == NULL) { if (lightmap->samples == NULL) {
/* first use of this lightmap, allocate the storage for it. */ /* first use of this lightmap, allocate the storage for it. */
lightmap->samples = calloc(lightsurf->numpoints, sizeof(lightsample_t)); lightmap->samples = (lightsample_t *) calloc(lightsurf->numpoints, sizeof(lightsample_t));
} else { } else {
/* clear only the data that is going to be merged to it. there's no point clearing more */ /* clear only the data that is going to be merged to it. there's no point clearing more */
memset(lightmap->samples, 0, sizeof(*lightmap->samples)*lightsurf->numpoints); memset(lightmap->samples, 0, sizeof(*lightmap->samples)*lightsurf->numpoints);
@ -1015,7 +1015,7 @@ Lightmap_Soften(lightmap_t *lightmap, const lightsurf_t *lightsurf)
const int height = (lightsurf->texsize[1] + 1) * oversample; const int height = (lightsurf->texsize[1] + 1) * oversample;
const int fullsamples = (2 * softsamples + 1) * (2 * softsamples + 1); const int fullsamples = (2 * softsamples + 1) * (2 * softsamples + 1);
softmap = calloc(lightsurf->numpoints, sizeof(lightsample_t)); softmap = (lightsample_t *) calloc(lightsurf->numpoints, sizeof(lightsample_t));
dst = softmap; dst = softmap;
for (i = 0; i < lightsurf->numpoints; i++, dst++) { for (i = 0; i < lightsurf->numpoints; i++, dst++) {
@ -2254,7 +2254,7 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo,
for (j = 0; j < lightsurf->numpoints; j++) { for (j = 0; j < lightsurf->numpoints; j++) {
int palidx = SampleTexture(face, bsp, lightsurf->points[j]); int palidx = SampleTexture(face, bsp, lightsurf->points[j]);
if (palidx >= 0) { if (palidx >= 0) {
vec3_t texcolor = {thepalette[3*palidx], thepalette[3*palidx + 1], thepalette[3*palidx + 2]}; vec3_t texcolor = {static_cast<float>(thepalette[3*palidx]), static_cast<float>(thepalette[3*palidx + 1]), static_cast<float>(thepalette[3*palidx + 2])};
VectorAdd(lightsurf->texturecolor, texcolor, lightsurf->texturecolor); VectorAdd(lightsurf->texturecolor, texcolor, lightsurf->texturecolor);
} }
} }

View File

@ -248,7 +248,7 @@ void
MakeFaceInfo(const bsp2_t *bsp, const bsp2_dface_t *face, faceinfo_t *info) MakeFaceInfo(const bsp2_t *bsp, const bsp2_dface_t *face, faceinfo_t *info)
{ {
info->numedges = face->numedges; info->numedges = face->numedges;
info->edgeplanes = calloc(face->numedges, sizeof(plane_t)); info->edgeplanes = (plane_t *) calloc(face->numedges, sizeof(plane_t));
GetFaceNormal(bsp, face, &info->plane); GetFaceNormal(bsp, face, &info->plane);
@ -319,7 +319,7 @@ Model_HasFence(const bsp2_t *bsp, const dmodel_t *model)
static void static void
MakeFenceInfo(const bsp2_t *bsp) MakeFenceInfo(const bsp2_t *bsp)
{ {
fence_dmodels = calloc(bsp->nummodels, sizeof(bool)); fence_dmodels = (bool *) calloc(bsp->nummodels, sizeof(bool));
for (int i = 0; i < bsp->nummodels; i++) { for (int i = 0; i < bsp->nummodels; i++) {
fence_dmodels[i] = Model_HasFence(bsp, &bsp->dmodels[i]); fence_dmodels[i] = Model_HasFence(bsp, &bsp->dmodels[i]);
} }
@ -329,11 +329,11 @@ void
BSP_MakeTnodes(const bsp2_t *bsp) BSP_MakeTnodes(const bsp2_t *bsp)
{ {
bsp_static = bsp; bsp_static = bsp;
tnode_p = tnodes = malloc(bsp->numnodes * sizeof(tnode_t)); tnode_p = tnodes = (tnode_t *) malloc(bsp->numnodes * sizeof(tnode_t));
for (int i = 0; i < bsp->nummodels; i++) for (int i = 0; i < bsp->nummodels; i++)
MakeTnodes_r(bsp->dmodels[i].headnode[0], bsp); MakeTnodes_r(bsp->dmodels[i].headnode[0], bsp);
faceinfos = malloc(bsp->numfaces * sizeof(faceinfo_t)); faceinfos = (faceinfo_t *) malloc(bsp->numfaces * sizeof(faceinfo_t));
for (int i = 0; i < bsp->numfaces; i++) for (int i = 0; i < bsp->numfaces; i++)
MakeFaceInfo(bsp, &bsp->dfaces[i], &faceinfos[i]); MakeFaceInfo(bsp, &bsp->dfaces[i], &faceinfos[i]);