OS X compiling working, Make it a bit more friendly with stricter compilers

This commit is contained in:
Simon Robertshaw 2012-04-26 13:10:47 +01:00
parent 9e4cd165eb
commit bb8a3f76e3
11 changed files with 63 additions and 46 deletions

View File

@ -18,6 +18,7 @@ powder-release.exe: build/powder-release.exe
powder.exe: build/powder.exe powder.exe: build/powder.exe
powder-release: build/powder-release powder-release: build/powder-release
powder: build/powder 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: 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 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-release: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f
build/powder: CFLAGS += -DLIN32 build/powder: CFLAGS += -DLIN32
build/powder: LFLAGS := -lSDL -lm -lbz2 -llua -lfftw3f 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 CFLAGS += -DGRAVFFT -DLUACONSOLE
@ -55,6 +58,14 @@ build/obj/powder/%.o: src/%.cpp $(HEADERS)
buildpaths-powder: buildpaths-powder:
$(shell mkdir -p build/obj/powder/) $(shell mkdir -p build/obj/powder/)
$(shell mkdir -p $(sort $(dir $(patsubst build/obj/%.o,build/obj/powder/%.o,$(OBJS))))) $(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: clean:
rm -r build/obj/* rm -r build/obj/*

View File

@ -88,7 +88,7 @@
#define XCNTR 306 #define XCNTR 306
#define YCNTR 192 #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 #define GRAV_DIFF

View File

@ -15,6 +15,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef MACOSX #ifdef MACOSX
#include <mach-o/dyld.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#endif #endif
@ -28,11 +29,11 @@ char *exe_name(void)
while ((res = GetModuleFileName(NULL, name, max)) >= max) while ((res = GetModuleFileName(NULL, name, max)) >= max)
{ {
#elif defined MACOSX #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; uint32_t max=64, res;
if (_NSGetExecutablePath(fn, &max) != 0) if (_NSGetExecutablePath(fn, &max) != 0)
{ {
fn = realloc(fn, max); fn = (char*)realloc(fn, max);
_NSGetExecutablePath(fn, &max); _NSGetExecutablePath(fn, &max);
} }
if (realpath(fn, name) == NULL) if (realpath(fn, name) == NULL)
@ -368,7 +369,7 @@ void clipboard_push_text(char * text)
if (PasteboardClear(newclipboard)!=noErr) return; if (PasteboardClear(newclipboard)!=noErr) return;
PasteboardSynchronize(newclipboard); 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); PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
#elif defined WIN32 #elif defined WIN32
if (OpenClipboard(NULL)) if (OpenClipboard(NULL))
@ -654,9 +655,9 @@ void OpenURI(std::string uri) {
#ifdef WIN32 #ifdef WIN32
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0); ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
#elif MACOSX #elif MACOSX
char *cmd = malloc(7+uri.length()); char *cmd = (char*)malloc(7+uri.length());
strcpy(cmd, "open "); strcpy(cmd, "open ");
strappend(cmd, uri.c_str()); strappend(cmd, (char*)uri.c_str());
system(cmd); system(cmd);
#elif LIN32 #elif LIN32
char *cmd = (char*)malloc(11+uri.length()); char *cmd = (char*)malloc(11+uri.length());

View File

@ -326,11 +326,11 @@ int luacon_partread(lua_State* l){
switch(format) switch(format)
{ {
case 0: case 0:
tempinteger = *((int*)(((void*)&luacon_sim->parts[i])+offset)); tempinteger = *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset));
lua_pushnumber(l, tempinteger); lua_pushnumber(l, tempinteger);
break; break;
case 1: case 1:
tempfloat = *((float*)(((void*)&luacon_sim->parts[i])+offset)); tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset));
lua_pushnumber(l, tempfloat); lua_pushnumber(l, tempfloat);
break; break;
} }
@ -358,10 +358,10 @@ int luacon_partwrite(lua_State* l){
switch(format) switch(format)
{ {
case 0: 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; break;
case 1: 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; break;
} }
return 1; return 1;
@ -488,11 +488,11 @@ int luacon_transitionread(lua_State* l){
switch(format) switch(format)
{ {
case 0: case 0:
tempinteger = *((int*)(((void*)&luacon_sim->ptransitions[i])+offset)); tempinteger = *((int*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset));
lua_pushnumber(l, tempinteger); lua_pushnumber(l, tempinteger);
break; break;
case 1: case 1:
tempfloat = *((float*)(((void*)&luacon_sim->ptransitions[i])+offset)); tempfloat = *((float*)(((unsigned char*)&luacon_sim->ptransitions[i])+offset));
lua_pushnumber(l, tempfloat); lua_pushnumber(l, tempfloat);
break; break;
} }
@ -522,10 +522,10 @@ int luacon_transitionwrite(lua_State* l){
switch(format) switch(format)
{ {
case 0: 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; break;
case 1: 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; break;
} }
return 0; return 0;
@ -675,19 +675,19 @@ int luacon_elementread(lua_State* l){
switch(format) switch(format)
{ {
case 0: case 0:
tempinteger = *((int*)(((void*)&luacon_sim->ptypes[i])+offset)); tempinteger = *((int*)(((unsigned char*)&luacon_sim->ptypes[i])+offset));
lua_pushnumber(l, tempinteger); lua_pushnumber(l, tempinteger);
break; break;
case 1: case 1:
tempfloat = *((float*)(((void*)&luacon_sim->ptypes[i])+offset)); tempfloat = *((float*)(((unsigned char*)&luacon_sim->ptypes[i])+offset));
lua_pushnumber(l, tempfloat); lua_pushnumber(l, tempfloat);
break; break;
case 2: case 2:
tempstring = *((char**)(((void*)&luacon_sim->ptypes[i])+offset)); tempstring = *((char**)(((unsigned char*)&luacon_sim->ptypes[i])+offset));
lua_pushstring(l, tempstring); lua_pushstring(l, tempstring);
break; break;
case 3: 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); lua_pushnumber(l, tempinteger);
break; break;
} }
@ -719,10 +719,10 @@ int luacon_elementwrite(lua_State* l){
switch(format) switch(format)
{ {
case 0: 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; break;
case 1: 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; break;
case 2: case 2:
tempstring = mystrdup((char*)luaL_optstring(l, 3, "")); tempstring = mystrdup((char*)luaL_optstring(l, 3, ""));
@ -745,11 +745,11 @@ int luacon_elementwrite(lua_State* l){
return luaL_error(l, "Name in use"); 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 //Need some way of cleaning up previous values
break; break;
case 3: 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; break;
} }
if (modified_stuff) if (modified_stuff)
@ -1212,9 +1212,9 @@ int luatpt_set_property(lua_State* l)
} }
i = r>>8; i = r>>8;
if(format == CommandInterface::FormatFloat){ if(format == CommandInterface::FormatFloat){
*((float*)(((void*)&luacon_sim->parts[i])+offset)) = f; *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f;
} else { } else {
*((int*)(((void*)&luacon_sim->parts[i])+offset)) = t; *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t;
} }
} }
} else { } else {
@ -1236,9 +1236,9 @@ int luatpt_set_property(lua_State* l)
if (partsel && partsel != luacon_sim->parts[i].type) if (partsel && partsel != luacon_sim->parts[i].type)
return 0; return 0;
if(format == CommandInterface::FormatFloat){ if(format == CommandInterface::FormatFloat){
*((float*)(((void*)&luacon_sim->parts[i])+offset)) = f; *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f;
} else { } else {
*((int*)(((void*)&luacon_sim->parts[i])+offset)) = t; *((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t;
} }
} }
return 0; return 0;

View File

@ -10,9 +10,9 @@
extern "C" extern "C"
{ {
#include <lua5.1/lua.h> #include <lua.h>
#include <lua5.1/lauxlib.h> #include <lauxlib.h>
#include <lua5.1/lualib.h> #include <lualib.h>
} }
#include "CommandInterface.h" #include "CommandInterface.h"

View File

@ -198,10 +198,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
switch(propertyFormat) switch(propertyFormat)
{ {
case FormatInt: case FormatInt:
*((int*)(((void*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); *((int*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value();
break; break;
case FormatFloat: case FormatFloat:
*((float*)(((void*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value(); *((float*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = ((NumberType)value).Value();
break; break;
} }
returnValue = 1; returnValue = 1;
@ -217,7 +217,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
if(sim->parts[j].type) if(sim->parts[j].type)
{ {
returnValue++; returnValue++;
*((int*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber;
} }
} }
break; break;
@ -228,7 +228,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
if(sim->parts[j].type) if(sim->parts[j].type)
{ {
returnValue++; returnValue++;
*((float*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber;
} }
} }
break; break;
@ -253,7 +253,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
if(sim->parts[j].type == type) if(sim->parts[j].type == type)
{ {
returnValue++; returnValue++;
*((int*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; *((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber;
} }
} }
break; break;
@ -264,7 +264,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
if(sim->parts[j].type == type) if(sim->parts[j].type == type)
{ {
returnValue++; returnValue++;
*((float*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber; *((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber;
} }
} }
break; break;

View File

@ -31,7 +31,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) {
pmap[y][x] = 0; pmap[y][x] = 0;
for (nxj=-(rad+1); nxj<=(rad+1); nxj++) for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
for (nxi=-(rad+1); nxi<=(rad+1); nxi++) 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); nb = sim->create_part(-1, x+nxi, y+nxj, PT_BOMB);
if (nb!=-1) { if (nb!=-1) {
parts[nb].tmp = 1; parts[nb].tmp = 1;
@ -43,7 +43,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) {
} }
for (nxj=-rad; nxj<=rad; nxj++) for (nxj=-rad; nxj<=rad; nxj++)
for (nxi=-rad; nxi<=rad; nxi++) 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) { 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->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; sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;

View File

@ -11,8 +11,8 @@ int update_FIGH(UPDATE_FUNC_ARGS)
//Set target cords //Set target cords
if (sim->player.spwn && sim->player2.spwn) if (sim->player.spwn && sim->player2.spwn)
{ {
if ((pow(sim->player.legs[2]-x, 2) + pow(sim->player.legs[3]-y, 2))<= if ((pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<=
(pow(sim->player2.legs[2]-x, 2) + pow(sim->player2.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]; tarx = (unsigned int)sim->player.legs[2];
tary = (unsigned int)sim->player.legs[3]; tary = (unsigned int)sim->player.legs[3];
@ -43,7 +43,7 @@ int update_FIGH(UPDATE_FUNC_ARGS)
switch (parts[i].tmp2) switch (parts[i].tmp2)
{ {
case 1: 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 if (figh->elem == PT_LIGH || figh->elem == PT_NEUT
|| sim->ptypes[figh->elem].properties&(PROP_DEADLY|PROP_RADIOACTIVE) || sim->ptypes[figh->elem].properties&(PROP_DEADLY|PROP_RADIOACTIVE)

View File

@ -11,7 +11,6 @@
#include "GameModelException.h" #include "GameModelException.h"
GameModel::GameModel(): GameModel::GameModel():
activeTools({NULL, NULL, NULL}),
sim(NULL), sim(NULL),
ren(NULL), ren(NULL),
currentBrush(0), currentBrush(0),
@ -24,6 +23,8 @@ GameModel::GameModel():
sim = new Simulation(); sim = new Simulation();
ren = new Renderer(ui::Engine::Ref().g, sim); ren = new Renderer(ui::Engine::Ref().g, sim);
memset(activeTools, 0, sizeof(activeTools));
//Load config into renderer //Load config into renderer
try try
{ {

View File

@ -2,7 +2,7 @@
#define ELEMENT_H #define ELEMENT_H
// This header should be included by all files in src/elements/ // This header should be included by all files in src/elements/
#include <math.h> #include <cmath>
#include "Simulation.h" #include "Simulation.h"
#include "Renderer.h" #include "Renderer.h"
#include "ElementFunctions.h" #include "ElementFunctions.h"

View File

@ -1,5 +1,5 @@
//#include <cstdlib> //#include <cstdlib>
#include <math.h> #include <cmath>
#include "Config.h" #include "Config.h"
#include "Simulation.h" #include "Simulation.h"
#include "Elements.h" #include "Elements.h"
@ -3570,10 +3570,14 @@ Simulation::~Simulation()
} }
Simulation::Simulation(): Simulation::Simulation():
sys_pause(0), sys_pause(0)
portal_rx({-1, 0, 1, 1, 1, 0,-1,-1}),
portal_ry({-1,-1,-1, 0, 1, 1, 1, 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 //Create and attach gravity simulation
grav = new Gravity(); grav = new Gravity();