From 6144cb7626dfdc0820a0036af83a531e8e68bae6 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Mon, 28 May 2012 21:17:46 +0200 Subject: [PATCH] Code clean-ups and makefile optimizations --- SDL_rotozoom.c | 17 +++++++++++------ archivetool.cc | 1 + game.c | 3 +++ game.h | 20 ++++++++++---------- locations.h | 2 +- makefile | 28 ++++++++++++---------------- network.c | 8 ++++---- network.h | 6 +++--- tennix.cc | 2 +- 9 files changed, 46 insertions(+), 41 deletions(-) diff --git a/SDL_rotozoom.c b/SDL_rotozoom.c index ba2c83e..baff64d 100644 --- a/SDL_rotozoom.c +++ b/SDL_rotozoom.c @@ -365,6 +365,9 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) { + (void)flipx; + (void)flipy; + Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; Uint8 *sp, *dp, *csp; int dgap; @@ -393,7 +396,7 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) */ csx = 0; csax = sax; - for (x = 0; x < dst->w; x++) { + for (x = 0; x < (Uint32)dst->w; x++) { csx += sx; *csax = (csx >> 16); csx &= 0xffff; @@ -401,7 +404,7 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) } csy = 0; csay = say; - for (y = 0; y < dst->h; y++) { + for (y = 0; y < (Uint32)dst->h; y++) { csy += sy; *csay = (csy >> 16); csy &= 0xffff; @@ -410,13 +413,13 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) csx = 0; csax = sax; - for (x = 0; x < dst->w; x++) { + for (x = 0; x < (Uint32)dst->w; x++) { csx += (*csax); csax++; } csy = 0; csay = say; - for (y = 0; y < dst->h; y++) { + for (y = 0; y < (Uint32)dst->h; y++) { csy += (*csay); csay++; } @@ -432,10 +435,10 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) * Draw */ csay = say; - for (y = 0; y < dst->h; y++) { + for (y = 0; y < (Uint32)dst->h; y++) { csax = sax; sp = csp; - for (x = 0; x < dst->w; x++) { + for (x = 0; x < (Uint32)dst->w; x++) { /* * Draw */ @@ -801,6 +804,8 @@ SDL_Surface* rotateSurface90Degrees(SDL_Surface* pSurf, int numClockwiseTurns) void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight, double *canglezoom, double *sanglezoom) { + (void)zoomy; + double x, y, cx, cy, sx, sy; double radangle; int dstwidthhalf, dstheighthalf; diff --git a/archivetool.cc b/archivetool.cc index 870889e..ad61006 100644 --- a/archivetool.cc +++ b/archivetool.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "archive.hh" diff --git a/game.c b/game.c index 967263c..11aa799 100644 --- a/game.c +++ b/game.c @@ -388,6 +388,9 @@ void step(GameState* s) { s->ball.move_x = 4.0 + 3.0*PLAYER(s, p).power/PLAYER_POWER_MAX; s->ball.move_z = 1.1*PLAYER(s, p).power/PLAYER_POWER_MAX; break; + default: + assert(false); + break; } s->ball.move_y = get_move_y( s, p); s->sound_events ^= SOUND_EVENT_RACKET; diff --git a/game.h b/game.h index 249d6e1..536672a 100644 --- a/game.h +++ b/game.h @@ -98,6 +98,13 @@ typedef struct { bool inhibit_gravity; } Ball; +enum PlayerDesire { + DESIRE_NORMAL, + DESIRE_TOPSPIN, + DESIRE_SMASH, + DESIRE_MAX +}; + typedef struct { InputDevice* input; char input_device_index; @@ -106,9 +113,9 @@ typedef struct { float power; bool use_power; unsigned char score; - unsigned char desire; + PlayerDesire desire; bool type; /* is this player ai-controlled or human? */ - char game; /* score for the current game */ + int game; /* score for the current game */ unsigned char sets[SETS_TO_WIN*2]; /* score for each set */ float accelerate; /* a value [0..1] how fast the user accelerates */ } Player; @@ -118,13 +125,6 @@ enum { PLAYER_TYPE_AI }; -enum { - DESIRE_NORMAL, - DESIRE_TOPSPIN, - DESIRE_SMASH, - DESIRE_MAX -}; - /* wait 2 seconds before we score the game */ #define SCORING_DELAY 1000 @@ -161,7 +161,7 @@ enum { typedef struct { const Location* location; - char current_location; /* index of loc. in global location table */ + int current_location; /* index of loc. in global location table */ Ball ball; Player players[MAXPLAYERS]; unsigned char serving_player; diff --git a/locations.h b/locations.h index 1786aa5..f631505 100644 --- a/locations.h +++ b/locations.h @@ -155,7 +155,7 @@ static Location locations[] = { #endif /* End marker */ - { NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, false } + { NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, false, false, 0, 0 } }; unsigned int location_count() diff --git a/makefile b/makefile index 19a25b3..fe16088 100644 --- a/makefile +++ b/makefile @@ -27,24 +27,23 @@ ifeq ($(MKCALLGRAPH),1) LD = nccld endif -RELEASE = 1.1 - -UNAME = $(shell uname) +RELEASE = 1.1.1 PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin DATAROOTDIR ?= $(PREFIX)/share DATADIR ?= $(DATAROOTDIR)/games -LIBS = -CFLAGS += -W -Wall -ansi -pedantic -Wcast-qual -Wwrite-strings -DVERSION=\"$(RELEASE)\" -O2 -DPREFIX=\"$(PREFIX)\" -g +CFLAGS += -W -Wall -DVERSION=\"$(RELEASE)\" -O2 -DPREFIX=\"$(PREFIX)\" CXXFLAGS += $(CFLAGS) USE_PYTHON ?= 1 ifeq ($(USE_PYTHON),1) - CFLAGS += `python-config --includes` -DTENNIX_PYTHON - LIBS += `python-config --libs` + PYTHON_INCLUDES := $(shell python-config --includes) + PYTHON_LIBS := $(shell python-config --libs) + CFLAGS += $(PYTHON_INCLUDES) -DTENNIX_PYTHON + LIBS += $(PYTHON_LIBS) endif ifeq ($(NONFREE_LOCATIONS),1) @@ -67,17 +66,14 @@ ifeq ($(MAEMO),1) CFLAGS += -DMAEMO endif -ifeq ($(UNAME),Darwin) - SDLLIBS=$$(sdl-config --prefix)/lib - LIBS += $$(sdl-config --static-libs) $(SDLLIBS)/libSDL_mixer.a $(SDLLIBS)/libSDL_image.a $(SDLLIBS)/libSDL_ttf.a $(SDLLIBS)/libSDL_net.a $$(freetype-config --prefix)/lib/libfreetype.a - CFLAGS += $$(sdl-config --cflags) -lz -else - LIBS += $$(sdl-config --libs) -lSDL_mixer -lSDL_image -lSDL_ttf -lSDL_net - CFLAGS += $$(sdl-config --cflags) -endif +SDL_LIBS := $(shell sdl-config --libs) +SDL_CFLAGS := $(shell sdl-config --cflags) + +LIBS += $(SDL_LIBS) -lSDL_mixer -lSDL_image -lSDL_ttf -lSDL_net +CFLAGS += $(SDL_CFLAGS) -SRC = tennix.cc game.c graphics.cc input.c util.c sound.cc animation.c network.c OBJ = tennix.o game.o graphics.o input.o util.o sound.o animation.o archive.o SDL_rotozoom.o network.o + ifeq ($(MSYSTEM),MINGW32) OBJ += tennixres.o endif diff --git a/network.c b/network.c index 7e16587..e860230 100644 --- a/network.c +++ b/network.c @@ -183,7 +183,7 @@ net_serialize_ball(const Ball* src, NetworkBall* dest) } void -net_unserialize_ball(const NetworkBall* src, Ball* dest) +net_unserialize_ball(NetworkBall* src, Ball* dest) { assert(src != NULL && dest != NULL); dest->x = unpack_float(SDLNet_Read32(&(src->x)), -WIDTH, WIDTH*2); @@ -213,7 +213,7 @@ net_serialize_player(const Player* src, NetworkPlayer* dest) } void -net_unserialize_player(const NetworkPlayer* src, Player* dest) +net_unserialize_player(NetworkPlayer* src, Player* dest) { assert(src != NULL && dest != NULL); dest->x = unpack_float(SDLNet_Read32(&(src->x)), 0, WIDTH*1.2); @@ -221,7 +221,7 @@ net_unserialize_player(const NetworkPlayer* src, Player* dest) dest->power = unpack_float(SDLNet_Read32(&(src->power)), 0, 110); dest->use_power = src->use_power; dest->score = src->score; - dest->desire = src->desire; + dest->desire = (PlayerDesire)src->desire; dest->game = src->game; memcpy(dest->sets, src->sets, sizeof(unsigned char)*(SETS_TO_WIN*2)); dest->accelerate = unpack_float(SDLNet_Read32(&(src->accelerate)), 0, 200); @@ -250,7 +250,7 @@ net_serialize_gamestate(const GameState* src, NetworkGameState* dest) } void -net_unserialize_gamestate(const NetworkGameState* src, GameState* dest) +net_unserialize_gamestate(NetworkGameState* src, GameState* dest) { int p; diff --git a/network.h b/network.h index a31ed27..6110faf 100644 --- a/network.h +++ b/network.h @@ -103,19 +103,19 @@ void net_serialize_ball(const Ball* src, NetworkBall* dest); void -net_unserialize_ball(const NetworkBall* src, Ball* dest); +net_unserialize_ball(NetworkBall* src, Ball* dest); void net_serialize_player(const Player* src, NetworkPlayer* dest); void -net_unserialize_player(const NetworkPlayer* src, Player* dest); +net_unserialize_player(NetworkPlayer* src, Player* dest); void net_serialize_gamestate(const GameState* src, NetworkGameState* dest); void -net_unserialize_gamestate(const NetworkGameState* src, GameState* dest); +net_unserialize_gamestate(NetworkGameState* src, GameState* dest); #endif diff --git a/tennix.cc b/tennix.cc index e0715f2..8f5f730 100644 --- a/tennix.cc +++ b/tennix.cc @@ -461,7 +461,7 @@ int main( int argc, char** argv) { start_fade(); gameloop(current_game, connection); SDL_Delay(150); - while(SDL_PollEvent(&e)); + while (SDL_PollEvent(&e)) {}; #ifdef ENABLE_FPS_LIMIT frames = 0; ft = SDL_GetTicks(); -- 2.11.4.GIT