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-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/*

View File

@ -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

View File

@ -15,6 +15,7 @@
#include <unistd.h>
#endif
#ifdef MACOSX
#include <mach-o/dyld.h>
#include <ApplicationServices/ApplicationServices.h>
#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());

View File

@ -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;

View File

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

View File

@ -198,10 +198,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * 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<std::string> * 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<std::string> * 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<std::string> * 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<std::string> * words)
if(sim->parts[j].type == type)
{
returnValue++;
*((float*)(((void*)&sim->parts[j])+propertyOffset)) = tempNumber;
*((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = tempNumber;
}
}
break;

View File

@ -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;

View File

@ -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)

View File

@ -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
{

View File

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

View File

@ -1,5 +1,5 @@
//#include <cstdlib>
#include <math.h>
#include <cmath>
#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();