From bb8a3f76e3b558a63eab38ab15ebb71f9b5ac762 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 26 Apr 2012 13:10:47 +0100 Subject: [PATCH] OS X compiling working, Make it a bit more friendly with stricter compilers --- Makefile | 11 ++++++++++ src/Config.h | 2 +- src/Misc.cpp | 11 +++++----- src/cat/LuaScriptInterface.cpp | 40 +++++++++++++++++----------------- src/cat/LuaScriptInterface.h | 6 ++--- src/cat/TPTScriptInterface.cpp | 12 +++++----- src/elements/bomb.cpp | 4 ++-- src/elements/figh.cpp | 6 ++--- src/game/GameModel.cpp | 3 ++- src/simulation/Element.h | 2 +- src/simulation/Simulation.cpp | 12 ++++++---- 11 files changed, 63 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 304749748..42b299d31 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ powder-release.exe: build/powder-release.exe powder.exe: build/powder.exe powder-release: build/powder-release powder: build/powder +powder-x: build/powder-x build/powder-release.exe: CFLAGS += -DWIN32 -O3 -ftree-vectorize -msse2 -funsafe-math-optimizations -ffast-math -fomit-frame-pointer -funsafe-loop-optimizations -Wunsafe-loop-optimizations build/powder-release.exe: LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 -llua -lfftw3f-3 -mwindows @@ -27,6 +28,8 @@ build/powder-release: CFLAGS += -DLIN32 -O3 -ftree-vectorize -msse2 -funsafe-ma build/powder-release: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f build/powder: CFLAGS += -DLIN32 build/powder: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f +build/powder-x: CFLAGS += -DPIX32BGRA -DMACOSX -I/Library/Frameworks/SDL.framework/Headers -I/Library/Frameworks/Lua.framework/Headers +build/powder-x: LFLAGS := -lm -lbz2 -lfftw3f -framework SDL -framework Lua -framework Cocoa CFLAGS += -DGRAVFFT -DLUACONSOLE @@ -55,6 +58,14 @@ build/obj/powder/%.o: src/%.cpp $(HEADERS) buildpaths-powder: $(shell mkdir -p build/obj/powder/) $(shell mkdir -p $(sort $(dir $(patsubst build/obj/%.o,build/obj/powder/%.o,$(OBJS))))) + +build/powder-x: buildpaths-powder-x $(patsubst build/obj/%.o,build/obj/powder-x/%.o,$(OBJS)) + $(CPPC) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(patsubst build/obj/%.o,build/obj/powder-x/%.o,$(OBJS)) SDLmain.m $(LFLAGS) -o $@ -ggdb +build/obj/powder-x/%.o: src/%.cpp $(HEADERS) + $(CPPC) -c $(CFLAGS) $(OFLAGS) -o $@ $< -ggdb +buildpaths-powder-x: + $(shell mkdir -p build/obj/powder-x/) + $(shell mkdir -p $(sort $(dir $(patsubst build/obj/%.o,build/obj/powder-x/%.o,$(OBJS))))) clean: rm -r build/obj/* diff --git a/src/Config.h b/src/Config.h index 5c2cab400..575a620fa 100644 --- a/src/Config.h +++ b/src/Config.h @@ -88,7 +88,7 @@ #define XCNTR 306 #define YCNTR 192 -#define MAX_DISTANCE sqrt(pow(XRES, 2)+pow(YRES, 2)) +#define MAX_DISTANCE sqrt(pow((float)XRES, 2)+pow((float)YRES, 2)) #define GRAV_DIFF diff --git a/src/Misc.cpp b/src/Misc.cpp index bba64a0c4..920145a24 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -15,6 +15,7 @@ #include #endif #ifdef MACOSX +#include #include #endif @@ -28,11 +29,11 @@ char *exe_name(void) while ((res = GetModuleFileName(NULL, name, max)) >= max) { #elif defined MACOSX - char *fn=malloc(64),*name=malloc(PATH_MAX); + char *fn=(char*)malloc(64),*name=(char*)malloc(PATH_MAX); uint32_t max=64, res; if (_NSGetExecutablePath(fn, &max) != 0) { - fn = realloc(fn, max); + fn = (char*)realloc(fn, max); _NSGetExecutablePath(fn, &max); } if (realpath(fn, name) == NULL) @@ -368,7 +369,7 @@ void clipboard_push_text(char * text) if (PasteboardClear(newclipboard)!=noErr) return; PasteboardSynchronize(newclipboard); - CFDataRef data = CFDataCreate(kCFAllocatorDefault, text, strlen(text)); + CFDataRef data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)text, strlen(text)); PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0); #elif defined WIN32 if (OpenClipboard(NULL)) @@ -654,9 +655,9 @@ void OpenURI(std::string uri) { #ifdef WIN32 ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0); #elif MACOSX - char *cmd = malloc(7+uri.length()); + char *cmd = (char*)malloc(7+uri.length()); strcpy(cmd, "open "); - strappend(cmd, uri.c_str()); + strappend(cmd, (char*)uri.c_str()); system(cmd); #elif LIN32 char *cmd = (char*)malloc(11+uri.length()); diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index a918ff165..6ee913210 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -326,11 +326,11 @@ int luacon_partread(lua_State* l){ switch(format) { case 0: - tempinteger = *((int*)(((void*)&luacon_sim->parts[i])+offset)); + tempinteger = *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)); lua_pushnumber(l, tempinteger); break; case 1: - tempfloat = *((float*)(((void*)&luacon_sim->parts[i])+offset)); + tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)); lua_pushnumber(l, tempfloat); break; } @@ -358,10 +358,10 @@ int luacon_partwrite(lua_State* l){ switch(format) { case 0: - *((int*)(((void*)&luacon_sim->parts[i])+offset)) = luaL_optinteger(l, 3, 0); + *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = luaL_optinteger(l, 3, 0); break; case 1: - *((float*)(((void*)&luacon_sim->parts[i])+offset)) = luaL_optnumber(l, 3, 0); + *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = luaL_optnumber(l, 3, 0); break; } return 1; @@ -488,11 +488,11 @@ int luacon_transitionread(lua_State* l){ switch(format) { case 0: - tempinteger = *((int*)(((void*)&luacon_sim->ptransitions[i])+offset)); + tempinteger = *((int*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset)); lua_pushnumber(l, tempinteger); break; case 1: - tempfloat = *((float*)(((void*)&luacon_sim->ptransitions[i])+offset)); + tempfloat = *((float*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset)); lua_pushnumber(l, tempfloat); break; } @@ -522,10 +522,10 @@ int luacon_transitionwrite(lua_State* l){ switch(format) { case 0: - *((int*)(((void*)&luacon_sim->ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0); + *((int*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0); break; case 1: - *((float*)(((void*)&luacon_sim->ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0); + *((float*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0); break; } return 0; @@ -675,19 +675,19 @@ int luacon_elementread(lua_State* l){ switch(format) { case 0: - tempinteger = *((int*)(((void*)&luacon_sim->ptypes[i])+offset)); + tempinteger = *((int*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)); lua_pushnumber(l, tempinteger); break; case 1: - tempfloat = *((float*)(((void*)&luacon_sim->ptypes[i])+offset)); + tempfloat = *((float*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)); lua_pushnumber(l, tempfloat); break; case 2: - tempstring = *((char**)(((void*)&luacon_sim->ptypes[i])+offset)); + tempstring = *((char**)(((unsigned char*)&luacon_sim->ptypes[i])+offset)); lua_pushstring(l, tempstring); break; case 3: - tempinteger = *((unsigned char*)(((void*)&luacon_sim->ptypes[i])+offset)); + tempinteger = *((unsigned char*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)); lua_pushnumber(l, tempinteger); break; } @@ -719,10 +719,10 @@ int luacon_elementwrite(lua_State* l){ switch(format) { case 0: - *((int*)(((void*)&luacon_sim->ptypes[i])+offset)) = luaL_optinteger(l, 3, 0); + *((int*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)) = luaL_optinteger(l, 3, 0); break; case 1: - *((float*)(((void*)&luacon_sim->ptypes[i])+offset)) = luaL_optnumber(l, 3, 0); + *((float*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)) = luaL_optnumber(l, 3, 0); break; case 2: tempstring = mystrdup((char*)luaL_optstring(l, 3, "")); @@ -745,11 +745,11 @@ int luacon_elementwrite(lua_State* l){ return luaL_error(l, "Name in use"); } } - *((char**)(((void*)&luacon_sim->ptypes[i])+offset)) = tempstring; + *((char**)(((unsigned char*)&luacon_sim->ptypes[i])+offset)) = tempstring; //Need some way of cleaning up previous values break; case 3: - *((unsigned char*)(((void*)&luacon_sim->ptypes[i])+offset)) = luaL_optinteger(l, 3, 0); + *((unsigned char*)(((unsigned char*)&luacon_sim->ptypes[i])+offset)) = luaL_optinteger(l, 3, 0); break; } if (modified_stuff) @@ -1212,9 +1212,9 @@ int luatpt_set_property(lua_State* l) } i = r>>8; if(format == CommandInterface::FormatFloat){ - *((float*)(((void*)&luacon_sim->parts[i])+offset)) = f; + *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f; } else { - *((int*)(((void*)&luacon_sim->parts[i])+offset)) = t; + *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t; } } } else { @@ -1236,9 +1236,9 @@ int luatpt_set_property(lua_State* l) if (partsel && partsel != luacon_sim->parts[i].type) return 0; if(format == CommandInterface::FormatFloat){ - *((float*)(((void*)&luacon_sim->parts[i])+offset)) = f; + *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f; } else { - *((int*)(((void*)&luacon_sim->parts[i])+offset)) = t; + *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t; } } return 0; diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index a346b1ada..50ec52e6d 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -10,9 +10,9 @@ extern "C" { -#include -#include -#include +#include +#include +#include } #include "CommandInterface.h" diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index a3f468cce..137ad586d 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -198,10 +198,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) switch(propertyFormat) { case FormatInt: - *((int*)(((void*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); + *((int*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); break; case FormatFloat: - *((float*)(((void*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); + *((float*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); break; } returnValue = 1; @@ -217,7 +217,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if(sim->parts[j].type) { returnValue++; - *((int*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; + *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber; } } break; @@ -228,7 +228,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if(sim->parts[j].type) { returnValue++; - *((float*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; + *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber; } } break; @@ -253,7 +253,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if(sim->parts[j].type == type) { returnValue++; - *((int*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; + *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber; } } break; @@ -264,7 +264,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if(sim->parts[j].type == type) { returnValue++; - *((float*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; + *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber; } } break; diff --git a/src/elements/bomb.cpp b/src/elements/bomb.cpp index 3b6db267c..99eb7f0bc 100644 --- a/src/elements/bomb.cpp +++ b/src/elements/bomb.cpp @@ -31,7 +31,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) { pmap[y][x] = 0; for (nxj=-(rad+1); nxj<=(rad+1); nxj++) for (nxi=-(rad+1); nxi<=(rad+1); nxi++) - if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1) { + if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1) { nb = sim->create_part(-1, x+nxi, y+nxj, PT_BOMB); if (nb!=-1) { parts[nb].tmp = 1; @@ -43,7 +43,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) { } for (nxj=-rad; nxj<=rad; nxj++) for (nxi=-rad; nxi<=rad; nxi++) - if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1) + if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1) if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) { sim->delete_part(x+nxi, y+nxj, 0);//it SHOULD kill anything but the exceptions above, doesn't seem to always work sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; diff --git a/src/elements/figh.cpp b/src/elements/figh.cpp index 6a8bb4e6a..6b67a275e 100644 --- a/src/elements/figh.cpp +++ b/src/elements/figh.cpp @@ -11,8 +11,8 @@ int update_FIGH(UPDATE_FUNC_ARGS) //Set target cords if (sim->player.spwn && sim->player2.spwn) { - if ((pow(sim->player.legs[2]-x, 2) + pow(sim->player.legs[3]-y, 2))<= - (pow(sim->player2.legs[2]-x, 2) + pow(sim->player2.legs[3]-y, 2))) + if ((pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<= + (pow((float)sim->player2.legs[2]-x, 2) + pow((float)sim->player2.legs[3]-y, 2))) { tarx = (unsigned int)sim->player.legs[2]; tary = (unsigned int)sim->player.legs[3]; @@ -43,7 +43,7 @@ int update_FIGH(UPDATE_FUNC_ARGS) switch (parts[i].tmp2) { case 1: - if ((pow(tarx-x, 2) + pow(tary-y, 2))<600) + if ((pow(float(tarx-x), 2) + pow(float(tary-y), 2))<600) { if (figh->elem == PT_LIGH || figh->elem == PT_NEUT || sim->ptypes[figh->elem].properties&(PROP_DEADLY|PROP_RADIOACTIVE) diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index f83242275..4dd14ef4b 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -11,7 +11,6 @@ #include "GameModelException.h" GameModel::GameModel(): - activeTools({NULL, NULL, NULL}), sim(NULL), ren(NULL), currentBrush(0), @@ -24,6 +23,8 @@ GameModel::GameModel(): sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); + memset(activeTools, 0, sizeof(activeTools)); + //Load config into renderer try { diff --git a/src/simulation/Element.h b/src/simulation/Element.h index 449bf51e3..f00751e7b 100644 --- a/src/simulation/Element.h +++ b/src/simulation/Element.h @@ -2,7 +2,7 @@ #define ELEMENT_H // This header should be included by all files in src/elements/ -#include +#include #include "Simulation.h" #include "Renderer.h" #include "ElementFunctions.h" diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 9f435f0b5..0a69c7b74 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1,5 +1,5 @@ //#include -#include +#include #include "Config.h" #include "Simulation.h" #include "Elements.h" @@ -3570,10 +3570,14 @@ Simulation::~Simulation() } Simulation::Simulation(): - sys_pause(0), - portal_rx({-1, 0, 1, 1, 1, 0,-1,-1}), - portal_ry({-1,-1,-1, 0, 1, 1, 1, 0}) + sys_pause(0) { + + int tportal_rx[] = {-1, 0, 1, 1, 1, 0,-1,-1}; + int tportal_ry[] = {-1,-1,-1, 0, 1, 1, 1, 0}; + + memcpy(portal_rx, tportal_rx, sizeof(tportal_rx)); + memcpy(portal_ry, tportal_ry, sizeof(tportal_ry)); //Create and attach gravity simulation grav = new Gravity();