From e0809c02b0520e480908b80e664bc4c56b866346 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Tue, 31 Mar 2015 13:02:09 -0400 Subject: [PATCH] Fixed a potential compatibility problem. The plain int type is only guaranteed to be at least 16 bits, and yet the flags variable was expecting at least 22 bits. This turns out to be true for x86 and x86-64 systems, but to ensure compatibility, the variable has been changed to an unsigned long int. Also added the "L" suffix to flags that were more than 16 bits. --- src/bullet.cpp | 6 +++--- src/defs.h | 16 ++++++++-------- src/graphics.cpp | 2 +- src/resources.cpp | 6 ++++++ src/structs.h | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/bullet.cpp b/src/bullet.cpp index 922bc25..74922d0 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -146,7 +146,7 @@ one attempt per call (one call per frame) to find a suitable target. If the targ it picks is dead or outside the screen range, then it returns NULL. A suitable target will be returned as the object address. */ -static object *getRandomEnemy(object *bullet) +static object *bullet_getTarget(object *bullet) { int i; @@ -240,8 +240,8 @@ void doBullets() { if (bullet->flags & WF_HOMING) { - if (bullet->target == NULL) - bullet->target = getRandomEnemy(bullet); + if (bullet->target == NULL) + bullet->target = bullet_getTarget(bullet); if (bullet->owner->flags & FL_FRIEND) homingMissileSpeed = 0.25; diff --git a/src/defs.h b/src/defs.h index c372f76..91d4022 100644 --- a/src/defs.h +++ b/src/defs.h @@ -36,7 +36,7 @@ along with this program. If not, see . // Compile-time options #ifndef VERSION -#define VERSION "devbuild" +#define VERSION "???" #endif #ifndef DATADIR @@ -64,13 +64,13 @@ along with this program. If not, see . #define FL_RUNSAWAY 8192 #define FL_ALWAYSFACE 16384 // Kline doesn't turn his back on you! ;) #define FL_CIRCLES 32768 // Kline can circle around -#define FL_CONTINUOUS_FIRE 65536 // Go absolutely nutts(!) -#define FL_DEPLOYDRONES 131072 // Deploys small drone - Used by Boss 2 -#define FL_CANCLOAK 262144 -#define FL_ISCLOAKED 524288 -#define FL_ACTIVATE 1048576 -#define FL_HASMINIMUMSPEED 2097152 -#define FL_FIRELASER 4194304 +#define FL_CONTINUOUS_FIRE 65536L // Go absolutely nutts(!) +#define FL_DEPLOYDRONES 131072L // Deploys small drone - Used by Boss 2 +#define FL_CANCLOAK 262144L +#define FL_ISCLOAKED 524288L +#define FL_ACTIVATE 1048576L +#define FL_HASMINIMUMSPEED 2097152L +#define FL_FIRELASER 4194304L // Explosions #define E_SMALL_EXPLOSION 4 diff --git a/src/graphics.cpp b/src/graphics.cpp index 5391e01..2b6b0a1 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -173,7 +173,7 @@ void blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) showErrorAndExit(2, ""); } - // Only ff it is to the screen, mark the region as damaged + // Only if it is to the screen, mark the region as damaged if (dest == screen) addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h); } diff --git a/src/resources.cpp b/src/resources.cpp index ac156da..deb644b 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -86,7 +86,9 @@ void loadGameGraphics() switch (shipShape[i]->format->BitsPerPixel) { case 32: + SDL_LockSurface(shipShape[i]); p32 = (Uint32 *)shipShape[i]->pixels; + SDL_UnlockSurface(shipShape[i]); for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++) { if (p32[j]) @@ -95,7 +97,9 @@ void loadGameGraphics() break; case 16: + SDL_LockSurface(shipShape[i]); p16 = (Uint16 *)shipShape[i]->pixels; + SDL_UnlockSurface(shipShape[i]); for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++) { if (p16[j]) @@ -104,7 +108,9 @@ void loadGameGraphics() break; case 8: + SDL_LockSurface(shipShape[i]); p8 = (Uint8 *)shipShape[i]->pixels; + SDL_UnlockSurface(shipShape[i]); for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++) { if (p8[j]) diff --git a/src/structs.h b/src/structs.h index 6df7b22..113c53b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -60,7 +60,7 @@ struct object { int collectType; // What the object is carrying int collectValue; // What it is worth - int flags; // Various flags for an object + unsigned long int flags; // Various flags for an object float x, y, dx, dy;