From 6a3b1dff365da8448ca21ed47cd79837ff0cf39c Mon Sep 17 00:00:00 2001 From: learn_more Date: Fri, 15 Feb 2013 01:12:30 +0100 Subject: [PATCH] make the thing work for msvc --- .gitignore | 8 ++ include/common.h | 34 ++++- msvc/iceball.sln | 20 +++ msvc/iceball.vcproj | 305 ++++++++++++++++++++++++++++++++++++++++++++ src/dsp.c | 2 +- src/gl/render.c | 2 +- src/img.c | 4 +- src/json.c | 4 +- src/lua_image.h | 22 ++-- src/lua_map.h | 14 +- src/lua_model.h | 24 ++-- src/lua_net.h | 2 +- src/lua_wav.h | 6 +- src/main.c | 8 +- src/map.c | 16 +-- src/model.c | 14 +- src/network.c | 46 ++++--- src/softgm/render.c | 18 +-- src/wav.c | 2 +- 19 files changed, 452 insertions(+), 99 deletions(-) create mode 100644 msvc/iceball.sln create mode 100644 msvc/iceball.vcproj diff --git a/.gitignore b/.gitignore index 650665b..2d3f476 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,11 @@ gmon.out # kate *.kate-swp +#visual studio files (personal config and whatnot) +*.suo +*.ncb +*.user + +msvc/Debug +msvc/Release +build/msvc \ No newline at end of file diff --git a/include/common.h b/include/common.h index 62dea69..5adeb8a 100644 --- a/include/common.h +++ b/include/common.h @@ -40,25 +40,44 @@ //define RENDER_FACE_COUNT 2 +#ifndef _MSC_VER +#define PACK_START +#define PACK_END #include +#include +#else +#define __attribute__(x) +#define PACK_START __pragma( pack(push, 1) ) +#define PACK_END __pragma( pack(pop) ) +typedef unsigned int uint32_t; +#define snprintf sprintf_s +#define _USE_MATH_DEFINES //M_PI and whatnot from math.h +#pragma warning( disable: 4200 4244 4996) +#endif #include #include #include -#include #include #include -#include #ifndef WIN32 +#include #include #endif #include +#ifdef __cplusplus +extern "C" { +#endif #include #include #include +#ifdef __cplusplus +}; +#endif + #ifndef DEDI #include @@ -76,7 +95,6 @@ #define _WIN32_WINNT 0x0501 #include #include -extern WSADATA windows_sucks; #else @@ -118,6 +136,7 @@ enum #ifdef __SSE__ __attribute__((aligned(16))) #endif +PACK_START typedef union vec4f { struct { float x,y,z,w; } __attribute__((__packed__)) p; @@ -135,6 +154,7 @@ typedef struct matrix //column-major! vec4f_t c[4]; } __attribute__((__packed__)) matrix_t; +PACK_END typedef struct camera { @@ -145,12 +165,14 @@ typedef struct camera float mpx,mpy,mpz,mppad; } camera_t; +PACK_START typedef struct model_point { uint16_t radius; int16_t x,y,z; uint8_t b,g,r,resv1; } __attribute__((__packed__)) model_point_t; +PACK_END typedef struct model model_t; typedef struct model_bone @@ -176,6 +198,7 @@ struct model model_bone_t *bones[]; }; +PACK_START // source: http://paulbourke.net/dataformats/tga/ typedef struct img_tgahead { @@ -192,6 +215,7 @@ typedef struct img_tgahead uint8_t bpp; uint8_t flags; } __attribute__((__packed__)) img_tgahead_t; +PACK_END typedef struct img { @@ -319,10 +343,6 @@ typedef struct client int spkt_ppos,spkt_len; } client_t; -struct netdata -{ - int sockfd; -} netdata_t; #define SOCKFD_NONE -1 #define SOCKFD_LOCAL -2 diff --git a/msvc/iceball.sln b/msvc/iceball.sln new file mode 100644 index 0000000..8127238 --- /dev/null +++ b/msvc/iceball.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iceball", "iceball.vcproj", "{CD5FA57E-F7A1-4CC0-B8B0-043E78858D90}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD5FA57E-F7A1-4CC0-B8B0-043E78858D90}.Debug|Win32.ActiveCfg = Debug|Win32 + {CD5FA57E-F7A1-4CC0-B8B0-043E78858D90}.Debug|Win32.Build.0 = Debug|Win32 + {CD5FA57E-F7A1-4CC0-B8B0-043E78858D90}.Release|Win32.ActiveCfg = Release|Win32 + {CD5FA57E-F7A1-4CC0-B8B0-043E78858D90}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/msvc/iceball.vcproj b/msvc/iceball.vcproj new file mode 100644 index 0000000..80cb6b2 --- /dev/null +++ b/msvc/iceball.vcproj @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/dsp.c b/src/dsp.c index fd17c65..dc29b9f 100644 --- a/src/dsp.c +++ b/src/dsp.c @@ -101,7 +101,7 @@ float wavelength2frequency(int rate, float wavelength) /* 12-tone scale MIDI notes are defined by this log function. 60 is "C-4", 69 is "A-4". */ float frequency2midinote(float frequency) -{ return 69 + 12*(log(frequency/440.)/log(2)); } +{ return 69 + 12*(log(frequency/440.)/log(2.)); } float midinote2frequency(float midinote) { return pow(2,(midinote-69)/12)*440; } diff --git a/src/gl/render.c b/src/gl/render.c index e45a030..69f2bff 100644 --- a/src/gl/render.c +++ b/src/gl/render.c @@ -105,7 +105,7 @@ void render_update_vbo(float **arr, int *len, int *max, int newlen) xlen = newlen + 10; } - *arr = realloc(*arr, xlen*sizeof(float)*6); + *arr = (float*)realloc(*arr, xlen*sizeof(float)*6); *max = xlen; } diff --git a/src/img.c b/src/img.c index 44c7640..0136254 100644 --- a/src/img.c +++ b/src/img.c @@ -61,7 +61,7 @@ img_t *img_parse_tga(int len, const char *data) // jump to palette // load palette if necessary - uint32_t *palette = (head.cmtype == 1 ? malloc(head.cmlen*4) : NULL); + uint32_t *palette = (head.cmtype == 1 ? (uint32_t*)malloc(head.cmlen*4) : NULL); if(palette != NULL) for(i = 0; i < head.cmlen; i++) @@ -76,7 +76,7 @@ img_t *img_parse_tga(int len, const char *data) } // allocate + stash - img_t *img = malloc(sizeof(img_t)+4*head.width*head.height); + img_t *img = (img_t*)malloc(sizeof(img_t)+4*head.width*head.height); // TODO: check if NULL img->head = head; img->udtype = UD_IMG; diff --git a/src/json.c b/src/json.c index 6b70c34..5f0a306 100644 --- a/src/json.c +++ b/src/json.c @@ -104,7 +104,7 @@ int json_parse_string(lua_State *L, const char **p) int sbuf_pos = 0; int sbuf_len = 64; - char *sbuf = malloc(sbuf_len); + char *sbuf = (char*)malloc(sbuf_len); // TODO: throughout this code, check if sbuf is NULL int uchr = 0; int lastwasr = 0; @@ -177,7 +177,7 @@ int json_parse_string(lua_State *L, const char **p) if(sbuf_pos+4 >= sbuf_len) { sbuf_len <<= 1; - sbuf = realloc(sbuf, sbuf_len); + sbuf = (char*)realloc(sbuf, sbuf_len); //printf("%i %016llX\n", sbuf_len, sbuf); } diff --git a/src/lua_image.h b/src/lua_image.h index 5ef12a8..e8746aa 100644 --- a/src/lua_image.h +++ b/src/lua_image.h @@ -22,7 +22,7 @@ int icelua_fn_client_img_blit(lua_State *L) int dx, dy, bw, bh, sx, sy; uint32_t color; - img_t *img = lua_touserdata(L, 1); + img_t *img = (img_t*)lua_touserdata(L, 1); if(img == NULL || img->udtype != UD_IMG) return luaL_error(L, "not an image"); @@ -37,7 +37,7 @@ int icelua_fn_client_img_blit(lua_State *L) #ifdef DEDI return luaL_error(L, "EDOOFUS: why the hell is this being called in the dedi version?"); #else - render_blit_img(screen->pixels, screen->w, screen->h, screen->pitch/4, + render_blit_img((uint32_t*)screen->pixels, screen->w, screen->h, screen->pitch/4, img, dx, dy, bw, bh, sx, sy, color); #endif @@ -50,10 +50,10 @@ int icelua_fn_client_img_blit_to(lua_State *L) int dx, dy, bw, bh, sx, sy; uint32_t color; - img_t *dest = lua_touserdata(L, 1); + img_t *dest = (img_t*)lua_touserdata(L, 1); if(dest == NULL || dest->udtype != UD_IMG) return luaL_error(L, "not an image"); - img_t *source = lua_touserdata(L, 2); + img_t *source = (img_t*)lua_touserdata(L, 2); if(source == NULL || source->udtype != UD_IMG) return luaL_error(L, "not an image"); @@ -88,7 +88,7 @@ int icelua_fn_common_img_load(lua_State *L) lua_pushvalue(L, 1); lua_call(L, 2, 1); - img_t *img = lua_touserdata(L, -1); + img_t *img = (img_t*)lua_touserdata(L, -1); if(img == NULL) return 0; @@ -110,7 +110,7 @@ int icelua_fn_common_img_new(lua_State *L) if(w < 1 || h < 1) return luaL_error(L, "image too small"); - img_t *img = malloc(sizeof(img_t)+(w*h*sizeof(uint32_t))); + img_t *img = (img_t*)malloc(sizeof(img_t)+(w*h*sizeof(uint32_t))); if(img == NULL) return luaL_error(L, "could not allocate memory"); @@ -138,11 +138,9 @@ int icelua_fn_common_img_new(lua_State *L) int icelua_fn_common_img_pixel_set(lua_State *L) { - int i; - int top = icelua_assert_stack(L, 4, 4); - img_t *img = lua_touserdata(L, 1); + img_t *img = (img_t*)lua_touserdata(L, 1); if(img == NULL || img->udtype != UD_IMG) return luaL_error(L, "not an image"); int x = lua_tointeger(L, 2); @@ -163,7 +161,7 @@ int icelua_fn_common_img_fill(lua_State *L) int top = icelua_assert_stack(L, 2, 2); - img_t *img = lua_touserdata(L, 1); + img_t *img = (img_t*)lua_touserdata(L, 1); if(img == NULL || img->udtype != UD_IMG) return luaL_error(L, "not an image"); uint32_t color = lua_tointeger(L, 2); @@ -178,7 +176,7 @@ int icelua_fn_common_img_free(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - img_t *img = lua_touserdata(L, 1); + img_t *img = (img_t*)lua_touserdata(L, 1); if(img == NULL || img->udtype != UD_IMG) return luaL_error(L, "not an image"); @@ -191,7 +189,7 @@ int icelua_fn_common_img_get_dims(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - img_t *img = lua_touserdata(L, 1); + img_t *img = (img_t*)lua_touserdata(L, 1); if(img == NULL || img->udtype != UD_IMG) return luaL_error(L, "not an image"); diff --git a/src/lua_map.h b/src/lua_map.h index 6920dac..23dadf1 100644 --- a/src/lua_map.h +++ b/src/lua_map.h @@ -54,7 +54,7 @@ int icelua_fn_common_map_new(lua_State *L) return luaL_error(L, "map size too small"); // XXX: shouldn't this be in map.c? - map_t *map = malloc(sizeof(map_t)); + map_t *map = (map_t*)malloc(sizeof(map_t)); if(map == NULL) { int err = errno; @@ -64,7 +64,7 @@ int icelua_fn_common_map_new(lua_State *L) map->xlen = xlen; map->ylen = ylen; map->zlen = zlen; - map->pillars = malloc(xlen*zlen*sizeof(uint8_t *)); + map->pillars = (uint8_t**)malloc(xlen*zlen*sizeof(uint8_t *)); if(map->pillars == NULL) { int err = errno; @@ -77,7 +77,7 @@ int icelua_fn_common_map_new(lua_State *L) for(z = 0, pi = 0; z < map->zlen; z++) for(x = 0; x < map->xlen; x++, pi++) { - uint8_t *p = map->pillars[pi] = malloc(16); + uint8_t *p = map->pillars[pi] = (uint8_t*)malloc(16); // TODO: check if NULL uint8_t v = (uint8_t)(x^z); *(p++) = 1; *(p++) = 0; *(p++) = 0; *(p++) = 0; @@ -97,7 +97,7 @@ int icelua_fn_common_map_new(lua_State *L) int icelua_fn_common_map_free(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - map_t *map = lua_touserdata(L, 1); + map_t *map = (map_t*)lua_touserdata(L, 1); if(map == NULL || map->udtype != UD_MAP) return luaL_error(L, "not a map"); @@ -109,7 +109,7 @@ int icelua_fn_common_map_free(lua_State *L) int icelua_fn_common_map_set(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - map_t *map = lua_touserdata(L, 1); + map_t *map = (map_t*)lua_touserdata(L, 1); if((map == NULL || map->udtype != UD_MAP) && !lua_isnil(L, 1)) return luaL_error(L, "not a map"); @@ -142,7 +142,7 @@ int icelua_fn_common_map_save(lua_State *L) { int top = icelua_assert_stack(L, 2, 3); - map_t *map = lua_touserdata(L, 1); + map_t *map = (map_t*)lua_touserdata(L, 1); if(map == NULL || map->udtype != UD_MAP) return luaL_error(L, "not a map"); const char *fname = lua_tostring(L, 2); @@ -312,7 +312,7 @@ int icelua_fn_common_map_pillar_set(lua_State *L) uint8_t *p = map->pillars[idx]; if((p[0]+1)*4 < tlen) { - p = map->pillars[idx] = realloc(p, tlen+4); + p = map->pillars[idx] = (uint8_t*)realloc(p, tlen+4); p[0] = (tlen>>2)-1; } diff --git a/src/lua_model.h b/src/lua_model.h index 9b7afb9..63c190f 100644 --- a/src/lua_model.h +++ b/src/lua_model.h @@ -53,7 +53,7 @@ int icelua_fn_common_model_save_pmf(lua_State *L) { int top = icelua_assert_stack(L, 2, 2); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL) return luaL_error(L, "not a model"); const char *fname = lua_tostring(L, 2); @@ -76,7 +76,7 @@ int icelua_fn_common_model_free(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -89,7 +89,7 @@ int icelua_fn_common_model_len(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -104,7 +104,7 @@ int icelua_fn_common_model_bone_new(lua_State *L) int top = icelua_assert_stack(L, 1, 2); int ptmax = 20; - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -138,7 +138,7 @@ int icelua_fn_common_model_bone_free(lua_State *L) int top = icelua_assert_stack(L, 1, 2); int boneidx; - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -156,7 +156,7 @@ int icelua_fn_common_model_bone_get(lua_State *L) int i; int top = icelua_assert_stack(L, 2, 2); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -205,7 +205,7 @@ int icelua_fn_common_model_bone_set(lua_State *L) int i; int top = icelua_assert_stack(L, 4, 4); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -303,7 +303,7 @@ int icelua_fn_common_model_bone_find(lua_State *L) int i; int top = icelua_assert_stack(L, 2, 2); - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -334,7 +334,7 @@ int icelua_fn_client_model_render_bone_global(lua_State *L) float ry, rx, ry2; float scale; - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -356,7 +356,7 @@ int icelua_fn_client_model_render_bone_global(lua_State *L) #ifdef DEDI return luaL_error(L, "EDOOFUS: why the hell is this being called in the dedi version?"); #else - render_pmf_bone(screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, + render_pmf_bone((uint32_t*)screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, bone, 0, px, py, pz, ry, rx, ry2, scale); #endif @@ -370,7 +370,7 @@ int icelua_fn_client_model_render_bone_local(lua_State *L) float ry, rx, ry2; float scale; - model_t *pmf = lua_touserdata(L, 1); + model_t *pmf = (model_t*)lua_touserdata(L, 1); if(pmf == NULL || pmf->udtype != UD_PMF) return luaL_error(L, "not a model"); @@ -392,7 +392,7 @@ int icelua_fn_client_model_render_bone_local(lua_State *L) #ifdef DEDI return luaL_error(L, "EDOOFUS: why the hell is this being called in the dedi version?"); #else - render_pmf_bone(screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, + render_pmf_bone((uint32_t*)screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, bone, 1, px, py, pz, ry, rx, ry2, scale); #endif diff --git a/src/lua_net.h b/src/lua_net.h index 0c56dcb..990115e 100644 --- a/src/lua_net.h +++ b/src/lua_net.h @@ -114,7 +114,7 @@ int icelua_fn_common_net_pack(lua_State *L) int slen = icelua_fnaux_net_packlen(L, fmt, top); if(slen < 0) return luaL_error(L, "invalid pack format"); - char *sbuf = malloc(slen+1); + char *sbuf = (char*)malloc(slen+1); // TODO: check if NULL char *sstop = sbuf+slen; *sstop = '\0'; diff --git a/src/lua_wav.h b/src/lua_wav.h index b9b7066..087ef15 100644 --- a/src/lua_wav.h +++ b/src/lua_wav.h @@ -46,7 +46,7 @@ int icelua_fn_client_wav_play_global(lua_State *L) { int top = icelua_assert_stack(L, 4, 7); - wav_t *wav = lua_touserdata(L, 1); + wav_t *wav = (wav_t*)lua_touserdata(L, 1); if(wav == NULL || wav->udtype != UD_WAV) return luaL_error(L, "not a wav"); float x = lua_tonumber(L, 2); @@ -77,7 +77,7 @@ int icelua_fn_client_wav_play_local(lua_State *L) { int top = icelua_assert_stack(L, 1, 7); - wav_t *wav = lua_touserdata(L, 1); + wav_t *wav = (wav_t*)lua_touserdata(L, 1); if(wav == NULL || wav->udtype != UD_WAV) return luaL_error(L, "not a wav"); float x = (top < 2 ? 0.0f : lua_tonumber(L, 2)); @@ -216,7 +216,7 @@ int icelua_fn_common_wav_free(lua_State *L) { int top = icelua_assert_stack(L, 1, 1); - wav_t *wav = lua_touserdata(L, 1); + wav_t *wav = (wav_t*)lua_touserdata(L, 1); if(wav == NULL || wav->udtype != UD_WAV) return luaL_error(L, "not a wav"); diff --git a/src/main.c b/src/main.c index c3e431a..4af964c 100644 --- a/src/main.c +++ b/src/main.c @@ -195,8 +195,9 @@ int update_client_cont1(void) //printf("%.2f",); // draw scene to cubemap SDL_LockSurface(screen); + //memset(screen->pixels, 0x51, screen->h*screen->pitch); - render_cubemap(screen->pixels, + render_cubemap((uint32_t*)screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, clmap); @@ -455,8 +456,6 @@ void run_game(void) tcam.mzy = 0.0f; tcam.mzz = 1.0f; - int i; - //render_vxl_redraw(&tcam, clmap); int quitflag = 0; @@ -521,6 +520,9 @@ int print_usage(char *rname) return 99; } +#ifdef __cplusplus +extern "C" +#endif int main(int argc, char *argv[]) { if(argc <= 1) diff --git a/src/map.c b/src/map.c index b2b166e..e34db98 100644 --- a/src/map.c +++ b/src/map.c @@ -25,7 +25,7 @@ map_t *map_parse_root(const char *dend, const char *data, int xlen, int ylen, in int taglen = (int)(dend-data); - map_t *map = malloc(sizeof(map_t)); + map_t *map = (map_t*)malloc(sizeof(map_t)); if(map == NULL) { error_perror("map_parse_root: malloc"); @@ -38,7 +38,7 @@ map_t *map_parse_root(const char *dend, const char *data, int xlen, int ylen, in map->ylen = ylen; map->zlen = zlen; - map->pillars = malloc(map->xlen*map->zlen*sizeof(uint8_t *)); + map->pillars = (uint8_t**)malloc(map->xlen*map->zlen*sizeof(uint8_t *)); if(map->pillars == NULL) { error_perror("map_parse_root: malloc(map->pillars)"); @@ -91,7 +91,7 @@ map_t *map_parse_root(const char *dend, const char *data, int xlen, int ylen, in } pillar_temp[0] = (ti>>2)-2; - map->pillars[pi] = malloc(ti); + map->pillars[pi] = (uint8_t*)malloc(ti); // TODO: check if NULL memcpy(map->pillars[pi], pillar_temp, ti); } @@ -107,8 +107,6 @@ map_t *map_parse_root(const char *dend, const char *data, int xlen, int ylen, in map_t *map_parse_aos(int len, const char *data) { - int i; - if(data == NULL) return NULL; @@ -120,8 +118,6 @@ map_t *map_parse_aos(int len, const char *data) map_t *map_parse_icemap(int len, const char *data) { - int i; - if(data == NULL) return NULL; @@ -236,8 +232,7 @@ char *map_serialise_icemap(map_t *map, int *len) { // TODO: make map_save_icemap rely on this int x,z,pi; - int i; - + if(map == NULL) { fprintf(stderr, "map_serialise_icemap: map is NULL!\n"); @@ -273,7 +268,7 @@ char *map_serialise_icemap(map_t *map, int *len) +8+4+6+maplen +8; - char *buf = malloc(buflen); + char *buf = (char*)malloc(buflen); // TODO check if NULL memcpy(buf, "IceMap\x1A\x01MapData\xFF", 16); @@ -318,7 +313,6 @@ char *map_serialise_icemap(map_t *map, int *len) int map_save_icemap(map_t *map, const char *fname) { int x,z,pi; - int i; FILE *fp = fopen(fname, "wb"); if(fp == NULL) diff --git a/src/model.c b/src/model.c index 675d0a2..bd45db0 100644 --- a/src/model.c +++ b/src/model.c @@ -19,7 +19,7 @@ model_t *model_new(int bonemax) { - model_t *pmf = malloc(sizeof(model_t)+sizeof(model_bone_t *)*bonemax); + model_t *pmf = (model_t*)malloc(sizeof(model_t)+sizeof(model_bone_t *)*bonemax); // TODO: check if NULL pmf->bonelen = 0; @@ -31,7 +31,7 @@ model_t *model_new(int bonemax) model_t *model_extend(model_t *pmf, int bonemax) { - pmf = realloc(pmf, sizeof(model_t)+sizeof(model_bone_t *)*bonemax); + pmf = (model_t*)realloc(pmf, sizeof(model_t)+sizeof(model_bone_t *)*bonemax); // TODO: check if NULL pmf->bonemax = bonemax; @@ -49,7 +49,7 @@ void model_free(model_t *pmf) model_bone_t *model_bone_new(model_t *pmf, int ptmax) { - model_bone_t *bone = malloc(sizeof(model_bone_t)+sizeof(model_point_t)*ptmax); + model_bone_t *bone = (model_bone_t*)malloc(sizeof(model_bone_t)+sizeof(model_point_t)*ptmax); // TODO: check if NULL bone->ptlen = 0; @@ -71,7 +71,7 @@ model_bone_t *model_bone_new(model_t *pmf, int ptmax) model_bone_t *model_bone_extend(model_bone_t *bone, int ptmax) { model_t *pmf = bone->parent; - bone = realloc(bone, sizeof(model_bone_t)+sizeof(model_point_t)*ptmax); + bone = (model_bone_t*)realloc(bone, sizeof(model_bone_t)+sizeof(model_point_t)*ptmax); // TODO: check if NULL pmf->bones[bone->parent_idx] = bone; @@ -101,8 +101,6 @@ model_t *model_parse_pmf(int len, const char *data) // and now we crawl through the spec. // start with the header of "PMF",0x1A,1,0,0,0 - char head[8]; - if(memcmp(p, "PMF\x1A\x01\x00\x00\x00", 8)) { fprintf(stderr, "model_load_pmf: not a valid PMF v1 file\n"); @@ -199,7 +197,7 @@ model_t *model_load_pmf(const char *fname) int model_save_pmf(model_t *pmf, const char *fname) { - int i,j; + int i; FILE *fp = fopen(fname, "wb"); @@ -210,8 +208,6 @@ int model_save_pmf(model_t *pmf, const char *fname) // and now we crawl through the spec. // start with the header of "PMF",0x1A,1,0,0,0 - char head[8]; - fwrite("PMF\x1A\x01\x00\x00\x00", 8, 1, fp); // then there's a uint32_t denoting how many body parts there are diff --git a/src/network.c b/src/network.c index 3c18f98..ca838d9 100644 --- a/src/network.c +++ b/src/network.c @@ -18,7 +18,19 @@ #include "common.h" #ifdef WIN32 -WSADATA windows_sucks; +WSADATA wsaStartup; +#define close(x) closesocket(x) +#if _MSC_VER +int bind( SOCKET s, void* name, int namelen ) +{ + return bind( s, (const sockaddr*)name, namelen ); +} +int setsockopt( SOCKET s, int level, int optname, void* optval, int optlen ) +{ + return setsockopt( s, level, optname, (const char*)optval, optlen ); +} + +#endif #endif int server_sockfd_ipv4 = -1; @@ -77,7 +89,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) if (cnt < INET_ADDRSTRLEN) return NULL; - p = src; + p = (const uint8_t*)src; snprintf(dst, cnt, "%u.%u.%u.%u", (unsigned int) (p[0] & 0xff), (unsigned int) (p[1] & 0xff), (unsigned int) (p[2] & 0xff), (unsigned int) (p[3] & 0xff)); @@ -85,7 +97,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) if (cnt < 5*8) return NULL; - p = src; + p = (const uint8_t*)src; snprintf(dst, cnt, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", (unsigned int) (p[0] & 0xff), (unsigned int) (p[1] & 0xff), (unsigned int) (p[2] & 0xff), (unsigned int) (p[3] & 0xff), @@ -119,7 +131,7 @@ int net_packet_push(int len, const char *data, int sockfd, packet_t **head, pack return 1; } - packet_t *pkt = malloc(sizeof(packet_t)+len); + packet_t *pkt = (packet_t*)malloc(sizeof(packet_t)+len); if(pkt == NULL) { error_perror("net_packet_new"); @@ -161,7 +173,7 @@ int net_packet_push_lua(int len, const char *data, int sockfd, packet_t **head, int poffs = (len >= 64 ? 3 : 1); - packet_t *pkt = malloc(sizeof(packet_t)+len+poffs); + packet_t *pkt = (packet_t*)malloc(sizeof(packet_t)+len+poffs); if(pkt == NULL) { error_perror("net_packet_new"); @@ -331,7 +343,7 @@ char *net_fetch_file(const char *fname, int *flen) int buf_len = 512; int buf_pos = 0; - char *buf = malloc(buf_len+1); + char *buf = (char*)malloc(buf_len+1); // TODO: check if NULL int buf_cpy; @@ -352,7 +364,7 @@ char *net_fetch_file(const char *fname, int *flen) break; buf_len += (buf_len>>1)+1; - buf = realloc(buf, buf_len+1); + buf = (char*)realloc(buf, buf_len+1); } fclose(fp); @@ -440,7 +452,7 @@ void net_eat_c2s(client_t *cli) use_serialised = -1; break; } - map_t *map = lua_touserdata(lstate_server, -1); + map_t *map = (map_t*)lua_touserdata(lstate_server, -1); lua_pop(lstate_server, 1); other->sfetch_ubuf = map_serialise_icemap( map, &(other->sfetch_ulen)); @@ -493,7 +505,7 @@ void net_eat_c2s(client_t *cli) other->sfetch_udtype = udtype; uLongf cbound = compressBound(other->sfetch_ulen); - other->sfetch_cbuf = malloc(cbound); + other->sfetch_cbuf = (char*)malloc(cbound); // TODO: check if NULL if(compress((Bytef *)(other->sfetch_cbuf), &cbound, (Bytef *)(other->sfetch_ubuf), other->sfetch_ulen)) @@ -621,7 +633,7 @@ void net_eat_s2c(client_t *cli) //printf("clen=%i ulen=%i\n", clen, ulen); cli->cfetch_clen = clen; cli->cfetch_ulen = ulen; - cli->cfetch_cbuf = malloc(clen); + cli->cfetch_cbuf = (char*)malloc(clen); cli->cfetch_ubuf = NULL; cli->cfetch_cpos = 0; // TODO: check if NULL @@ -632,7 +644,7 @@ void net_eat_s2c(client_t *cli) // 0x32: // file transfer end //printf("transfer END\n"); - cli->cfetch_ubuf = malloc(cli->cfetch_ulen); + cli->cfetch_ubuf = (char*)malloc(cli->cfetch_ulen); // TODO: check if NULL uLongf dlen = cli->cfetch_ulen; @@ -832,7 +844,6 @@ void net_flush_parse_s2c(client_t *cli) client_t *net_find_sockfd(int sockfd) { int i; - client_t *cli; if(sockfd == SOCKFD_LOCAL) { @@ -960,7 +971,7 @@ void net_flush_accept_one(int sockfd, struct sockaddr_storage *ss, socklen_t sle // set connection nonblocking yes = 1; #ifdef WIN32 - if(ioctlsocket(sockfd,FIONBIO,(void *)&yes) == -1) { + if(ioctlsocket(sockfd,FIONBIO,(u_long *)&yes) == -1) { #else if(fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL) | O_NONBLOCK) == -1) { @@ -1351,7 +1362,7 @@ int net_connect(void) int yes = 1; #ifdef WIN32 - if(ioctlsocket(sockfd, FIONBIO, (void *)&yes)) + if(ioctlsocket(sockfd, FIONBIO, (u_long *)&yes)) #else if(fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL) | O_NONBLOCK)) @@ -1421,7 +1432,6 @@ int net_bind(void) sa4.sin_addr.s_addr = INADDR_ANY; int yes = 1; // who the hell uses solaris anyway - int tflags; if(setsockopt(server_sockfd_ipv6, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes)) == -1) { perror("net_bind(reuseaddr.6)"); @@ -1445,7 +1455,7 @@ int net_bind(void) perror("net_bind(listen.6)"); server_sockfd_ipv6 = -1; #ifdef WIN32 - } else if(ioctlsocket(server_sockfd_ipv6,FIONBIO,(void *)&yes)) { + } else if(ioctlsocket(server_sockfd_ipv6,FIONBIO,(u_long *)&yes)) { #else } else if(fcntl(server_sockfd_ipv6, F_SETFL, fcntl(server_sockfd_ipv6, F_GETFL) | O_NONBLOCK)) { @@ -1466,7 +1476,7 @@ int net_bind(void) perror("net_bind(listen.4)"); server_sockfd_ipv4 = -1; #ifdef WIN32 - } else if(ioctlsocket(server_sockfd_ipv4,FIONBIO,(void *)&yes)) { + } else if(ioctlsocket(server_sockfd_ipv4,FIONBIO,(u_long *)&yes)) { #else } else if(fcntl(server_sockfd_ipv4, F_SETFL, fcntl(server_sockfd_ipv4, F_GETFL) | O_NONBLOCK)) { @@ -1507,7 +1517,7 @@ int net_init(void) #ifdef WIN32 // complete hackjob - if(WSAStartup(MAKEWORD(2,0), &windows_sucks) != 0) + if(WSAStartup(MAKEWORD(2,0), &wsaStartup) != 0) { fprintf(stderr, "net_init: WSAStartup failed\n"); return 1; diff --git a/src/softgm/render.c b/src/softgm/render.c index 26b436d..731aaed 100644 --- a/src/softgm/render.c +++ b/src/softgm/render.c @@ -859,7 +859,7 @@ void render_vxl_redraw(camera_t *camera, map_t *map) return; } - int i,x,y,z; + int i; // stash stuff in globals to prevent spamming the stack too much // (and in turn thrashing the cache) @@ -896,7 +896,7 @@ void render_vxl_redraw(camera_t *camera, map_t *map) if(rayc_mark_size != markbase) { rayc_mark_size = markbase; - rayc_mark = realloc(rayc_mark, rayc_mark_size*sizeof(int)); + rayc_mark = (int*)realloc(rayc_mark, rayc_mark_size*sizeof(int)); #ifdef RENDER_CUBES_MULTITHREADED rayc_stack_len = realloc(rayc_stack_len, rayc_mark_size*8*sizeof(int)); rayc_stack_ordlen = realloc(rayc_stack_ordlen, rayc_mark_size*8*sizeof(int)); @@ -906,7 +906,7 @@ void render_vxl_redraw(camera_t *camera, map_t *map) if(rayc_block_size != blockbase) { rayc_block_size = blockbase; - rayc_block = realloc(rayc_block, rayc_block_size*sizeof(rayblock_t)); + rayc_block = (rayblock_t*)realloc(rayc_block, rayc_block_size*sizeof(rayblock_t)); } } @@ -1284,7 +1284,7 @@ void render_cubemap_edge( int x1, int y1, float z1, float u1, float v1, int x2, int y2, float z2, float u2, float v2) { - int x,y; + int y; // if out of Y range, drop out early. if(y1 < 0 && y2 < 0) @@ -1577,7 +1577,7 @@ void render_cubemap_new(uint32_t *pixels, int width, int height, int pitch, came free(elist); elist_len = height; - elist = malloc(sizeof(edgebit_t)*elist_len); + elist = (edgebit_t*)malloc(sizeof(edgebit_t)*elist_len); } // do each face @@ -1593,7 +1593,7 @@ void render_cubemap_new(uint32_t *pixels, int width, int height, int pitch, came void render_cubemap(uint32_t *pixels, int width, int height, int pitch, camera_t *camera, map_t *map) { - int x,y,z; + int x,y; // stash stuff in globals to prevent spamming the stack too much // (and in turn thrashing the cache) @@ -1880,8 +1880,8 @@ int render_init(int width, int height) // allocate cubemaps for(i = 0; i < CM_MAX; i++) { - cubemap_color[i] = malloc(size*size*4); - cubemap_depth[i] = malloc(size*size*4); + cubemap_color[i] = (uint32_t*)malloc(size*size*4); + cubemap_depth[i] = (float*)malloc(size*size*4); if(cubemap_color[i] == NULL || cubemap_depth[i] == NULL) { // Can't allocate :. Can't continue @@ -1913,7 +1913,7 @@ int render_init(int width, int height) } // allocate space for depth buffer - dbuf = malloc(width*height*sizeof(float)); + dbuf = (float*)malloc(width*height*sizeof(float)); // TODO: check if NULL return 0; diff --git a/src/wav.c b/src/wav.c index ea67ba2..40a2b90 100644 --- a/src/wav.c +++ b/src/wav.c @@ -276,7 +276,7 @@ wav_t *wav_parse(char *buf, int len) int datalen_smps = datalen/fmt.blkalign; - wav_t *wav = malloc(sizeof(wav_t)*datalen_smps); + wav_t *wav = (wav_t*)malloc(sizeof(wav_t)*datalen_smps); wav->udtype = UD_WAV; wav->refcount = 1; wav->len = datalen_smps;