From f641e93ca2a11b48ca21f81e6d89b2d6aad2158b Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 2 Mar 2016 16:36:48 -0700 Subject: [PATCH] light: convert light.c to light.cc --- include/common/bspfile.h | 8 ++++++++ include/common/cmdlib.h | 8 ++++++++ include/common/log.h | 8 ++++++++ include/common/mathlib.h | 8 ++++++++ include/common/threads.h | 8 ++++++++ include/light/entities.h | 8 ++++++++ include/light/light.h | 8 ++++++++ include/light/litfile.h | 8 ++++++++ light/CMakeLists.txt | 4 +++- light/{light.c => light.cc} | 20 ++++++++++---------- 10 files changed, 77 insertions(+), 11 deletions(-) rename light/{light.c => light.cc} (97%) diff --git a/include/common/bspfile.h b/include/common/bspfile.h index ca1f971d..d7b632ad 100644 --- a/include/common/bspfile.h +++ b/include/common/bspfile.h @@ -25,6 +25,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* upper design bounds */ #define MAX_MAP_HULLS_Q1 4 @@ -469,4 +473,8 @@ void ConvertBSPFormat(int32_t version, bspdata_t *bspdata); void BSPX_AddLump(bspdata_t *bspdata, const char *xname, const void *xdata, size_t xsize); const void *BSPX_GetLump(bspdata_t *bspdata, const char *xname, size_t *xsize); +#ifdef __cplusplus +} +#endif + #endif /* __COMMON_BSPFILE_H__ */ diff --git a/include/common/cmdlib.h b/include/common/cmdlib.h index 50083094..76147e49 100644 --- a/include/common/cmdlib.h +++ b/include/common/cmdlib.h @@ -29,6 +29,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define stringify__(x) #x #define stringify(x) stringify__(x) @@ -141,4 +145,8 @@ void Q_CopyFile(const char *from, char *to); extern qboolean archive; extern char archivedir[1024]; +#ifdef __cplusplus +} +#endif + #endif /* __COMMON_CMDLIB_H__ */ diff --git a/include/common/log.h b/include/common/log.h index 6edf573f..3d4786bb 100644 --- a/include/common/log.h +++ b/include/common/log.h @@ -30,6 +30,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef __GNUC__ #define __attribute__(x) #endif @@ -51,4 +55,8 @@ void logprint_silent(const char *fmt, ...) void logprint_locked__(const char *fmt, ...) __attribute__((format(printf,1,2))); +#ifdef __cplusplus +} +#endif + #endif /* __COMMON_LOG_H__ */ diff --git a/include/common/mathlib.h b/include/common/mathlib.h index 39c04c68..b4428732 100644 --- a/include/common/mathlib.h +++ b/include/common/mathlib.h @@ -23,6 +23,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef DOUBLEVEC_T #define vec_t double #define VECT_MAX DBL_MAX; @@ -135,4 +139,8 @@ double VectorLength(const vec3_t v); const char *VecStr(const vec3_t vec); const char *VecStrf(const vec3_t vec); +#ifdef __cplusplus +} +#endif + #endif /* __COMMON_MATHLIB_H__ */ diff --git a/include/common/threads.h b/include/common/threads.h index b0b37908..26c3bcdf 100644 --- a/include/common/threads.h +++ b/include/common/threads.h @@ -3,6 +3,10 @@ #ifndef __COMMON_THREADS_H__ #define __COMMON_THREADS_H__ +#ifdef __cplusplus +extern "C" { +#endif + extern int numthreads; void LowerProcessPriority(void); @@ -17,4 +21,8 @@ void ThreadUnlock(void); /* Call if needing to print to stdout - should be called with lock held */ void InterruptThreadProgress__(void); +#ifdef __cplusplus +} +#endif + #endif /* __COMMON_THREADS_H__ */ diff --git a/include/light/entities.h b/include/light/entities.h index bffcec96..5811d5c6 100644 --- a/include/light/entities.h +++ b/include/light/entities.h @@ -24,6 +24,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define DEFAULTLIGHTLEVEL 300 typedef struct epair_s { @@ -128,4 +132,8 @@ void LoadEntities(const bsp2_t *bsp); void SetupLights(const bsp2_t *bsp); void WriteEntitiesToString(bsp2_t *bsp); +#ifdef __cplusplus +} +#endif + #endif /* __LIGHT_ENTITIES_H__ */ diff --git a/include/light/light.h b/include/light/light.h index 44c7456c..20a16a14 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -27,6 +27,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define ON_EPSILON 0.1 #define ANGLE_EPSILON 0.001 @@ -238,4 +242,8 @@ extern qboolean phongDebug; extern char mapfilename[1024]; +#ifdef __cplusplus +} +#endif + #endif /* __LIGHT_LIGHT_H__ */ diff --git a/include/light/litfile.h b/include/light/litfile.h index 28892a41..1974d082 100644 --- a/include/light/litfile.h +++ b/include/light/litfile.h @@ -22,6 +22,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define LIT_VERSION 1 typedef struct litheader_s { @@ -46,4 +50,8 @@ typedef struct { void WriteLitFile(const bsp2_t *bsp, facesup_t *facesup, const char *filename, int version); void WriteLuxFile(const bsp2_t *bsp, const char *filename, int version); +#ifdef __cplusplus +} +#endif + #endif /* __LIGHT_LITFILE_H__ */ diff --git a/light/CMakeLists.txt b/light/CMakeLists.txt index b776909f..224b0230 100644 --- a/light/CMakeLists.txt +++ b/light/CMakeLists.txt @@ -11,7 +11,7 @@ set(LIGHT_SOURCES litfile.c ltface.c trace.c - light.c + light.cc ${CMAKE_SOURCE_DIR}/common/bspfile.c ${CMAKE_SOURCE_DIR}/common/cmdlib.c ${CMAKE_SOURCE_DIR}/common/mathlib.c @@ -22,5 +22,7 @@ set(LIGHT_SOURCES add_executable(light ${LIGHT_SOURCES}) target_link_libraries (light ${CMAKE_THREAD_LIBS_INIT}) +set_property(TARGET light PROPERTY CXX_STANDARD 11) +set_property(TARGET light PROPERTY CXX_STANDARD_REQUIRED ON) install(TARGETS light RUNTIME DESTINATION bin) diff --git a/light/light.c b/light/light.cc similarity index 97% rename from light/light.c rename to light/light.cc index 988ccacf..67092ccc 100644 --- a/light/light.c +++ b/light/light.cc @@ -146,7 +146,7 @@ static void * LightThread(void *arg) { int facenum, i; - const bsp2_t *bsp = arg; + const bsp2_t *bsp = (const bsp2_t *)arg; const modelinfo_t *face_modelinfo; struct ltface_ctx *ctx; @@ -203,7 +203,7 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride) modelinfo_t *info; float lightmapscale; - shadowmodels = malloc(sizeof(dmodel_t *) * (bsp->nummodels + 1)); + shadowmodels = (const dmodel_t **)malloc(sizeof(dmodel_t *) * (bsp->nummodels + 1)); memset(shadowmodels, 0, sizeof(dmodel_t *) * (bsp->nummodels + 1)); /* The world always casts shadows */ @@ -335,7 +335,7 @@ CalcualateVertexNormals(const bsp2_t *bsp) bsp2_dface_t *f; vec3_t norm; - vertex_normals = malloc(sizeof(vec3_t) * bsp->numvertexes); + vertex_normals = (vec3_t *)malloc(sizeof(vec3_t) * bsp->numvertexes); memset(vertex_normals, 0, sizeof(vec3_t) * bsp->numvertexes); for (i = 0; i < bsp->numfaces; i++) @@ -384,7 +384,7 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale) /* FIXME - remove this limit */ bsp->lightdatasize = MAX_MAP_LIGHTING; - bsp->dlightdata = malloc(bsp->lightdatasize + 16); /* for alignment */ + bsp->dlightdata = (byte *)malloc(bsp->lightdatasize + 16); /* for alignment */ if (!bsp->dlightdata) Error("%s: allocation of %i bytes failed.", __func__, bsp->lightdatasize); @@ -401,7 +401,7 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale) lit_file_end = lit_filebase + 3 * (MAX_MAP_LIGHTING / 4); /* lux data stored in a separate buffer */ - lux_buffer = malloc(bsp->lightdatasize*3); + lux_buffer = (byte *)malloc(bsp->lightdatasize*3); lux_filebase = lux_buffer + 12 - ((uintptr_t)lux_buffer % 12); lux_file_p = lux_filebase; lux_file_end = lux_filebase + 3 * (MAX_MAP_LIGHTING / 4); @@ -410,12 +410,12 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale) if (forcedscale) BSPX_AddLump(bspdata, "LMSHIFT", NULL, 0); - lmshift_lump = BSPX_GetLump(bspdata, "LMSHIFT", NULL); + lmshift_lump = (const unsigned char *)BSPX_GetLump(bspdata, "LMSHIFT", NULL); if (!lmshift_lump && write_litfile != ~0) faces_sup = NULL; //no scales, no lit2 else { //we have scales or lit2 output. yay... - faces_sup = malloc(sizeof(*faces_sup) * bsp->numfaces); + faces_sup = (facesup_t *)malloc(sizeof(*faces_sup) * bsp->numfaces); memset(faces_sup, 0, sizeof(*faces_sup) * bsp->numfaces); if (lmshift_lump) { @@ -440,8 +440,8 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale) if (faces_sup) { - uint8_t *styles = malloc(sizeof(*styles)*4*bsp->numfaces); - int32_t *offsets = malloc(sizeof(*offsets)*bsp->numfaces); + uint8_t *styles = (uint8_t *)malloc(sizeof(*styles)*4*bsp->numfaces); + int32_t *offsets = (int32_t *)malloc(sizeof(*offsets)*bsp->numfaces); for (i = 0; i < bsp->numfaces; i++) { offsets[i] = faces_sup[i].lightofs; @@ -676,7 +676,7 @@ main(int argc, const char **argv) LoadEntities(bsp); - modelinfo = malloc(bsp->nummodels * sizeof(*modelinfo)); + modelinfo = (modelinfo_t *)malloc(bsp->nummodels * sizeof(*modelinfo)); FindModelInfo(bsp, lmscaleoverride); SetupLights(bsp);