Commit 2bddc336 authored by Sam Lantinga's avatar Sam Lantinga

Fixed compilation on iPhone

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404443
parent 9467a700
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
* Figure out how to handle OpenGL context lost on Mac OS X (does it happen?) * Figure out how to handle OpenGL context lost on Mac OS X (does it happen?)
* Write automated test case for multi-draw APIs * Write automated test case for multi-draw APIs
* Make sure you can build SDL without the renderer to slim it down a bunch * Make sure you can build SDL without the renderer to slim it down a bunch
* Implement assertion code on iPhone
* Add __WINDOWS__ in addition to __WIN32__
* Check 1.2 revisions: * Check 1.2 revisions:
3554 - Need to resolve semantics for locking keys on different platforms 3554 - Need to resolve semantics for locking keys on different platforms
......
...@@ -25,7 +25,7 @@ static struct ...@@ -25,7 +25,7 @@ static struct
float x, y; /* position of ship */ float x, y; /* position of ship */
float vx, vy; /* velocity of ship (in pixels per millesecond) */ float vx, vy; /* velocity of ship (in pixels per millesecond) */
SDL_Rect rect; /* (drawn) position and size of ship */ SDL_Rect rect; /* (drawn) position and size of ship */
} ship; } shipData;
static SDL_Texture *ship = 0; /* texture for spaceship */ static SDL_Texture *ship = 0; /* texture for spaceship */
static SDL_Texture *space = 0; /* texture for space (background */ static SDL_Texture *space = 0; /* texture for space (background */
...@@ -41,9 +41,9 @@ render(void) ...@@ -41,9 +41,9 @@ render(void)
/* ship screen constraints */ /* ship screen constraints */
Uint32 minx = 0.0f; Uint32 minx = 0.0f;
Uint32 maxx = SCREEN_WIDTH - ship.rect.w; Uint32 maxx = SCREEN_WIDTH - shipData.rect.w;
Uint32 miny = 0.0f; Uint32 miny = 0.0f;
Uint32 maxy = SCREEN_HEIGHT - ship.rect.h; Uint32 maxy = SCREEN_HEIGHT - shipData.rect.h;
#define SINT16_MAX ((float)(0x7FFF)) #define SINT16_MAX ((float)(0x7FFF))
...@@ -51,59 +51,59 @@ render(void) ...@@ -51,59 +51,59 @@ render(void)
the factor SDL_IPHONE_MAX_G_FORCE / SINT16_MAX converts between the factor SDL_IPHONE_MAX_G_FORCE / SINT16_MAX converts between
SDL's units reported from the joytick, and units of g-force, as reported by the accelerometer SDL's units reported from the joytick, and units of g-force, as reported by the accelerometer
*/ */
ship.vx += shipData.vx +=
ax * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT * ax * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT *
MILLESECONDS_PER_FRAME; MILLESECONDS_PER_FRAME;
ship.vy += shipData.vy +=
ay * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT * ay * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT *
MILLESECONDS_PER_FRAME; MILLESECONDS_PER_FRAME;
float speed = sqrt(ship.vx * ship.vx + ship.vy * ship.vy); float speed = sqrt(shipData.vx * shipData.vx + shipData.vy * shipData.vy);
if (speed > 0) { if (speed > 0) {
/* compensate for friction */ /* compensate for friction */
float dirx = ship.vx / speed; /* normalized x velocity */ float dirx = shipData.vx / speed; /* normalized x velocity */
float diry = ship.vy / speed; /* normalized y velocity */ float diry = shipData.vy / speed; /* normalized y velocity */
/* update velocity due to friction */ /* update velocity due to friction */
if (speed - FRICTION * MILLESECONDS_PER_FRAME > 0) { if (speed - FRICTION * MILLESECONDS_PER_FRAME > 0) {
/* apply friction */ /* apply friction */
ship.vx -= dirx * FRICTION * MILLESECONDS_PER_FRAME; shipData.vx -= dirx * FRICTION * MILLESECONDS_PER_FRAME;
ship.vy -= diry * FRICTION * MILLESECONDS_PER_FRAME; shipData.vy -= diry * FRICTION * MILLESECONDS_PER_FRAME;
} else { } else {
/* applying friction would MORE than stop the ship, so just stop the ship */ /* applying friction would MORE than stop the ship, so just stop the ship */
ship.vx = 0.0f; shipData.vx = 0.0f;
ship.vy = 0.0f; shipData.vy = 0.0f;
} }
} }
/* update ship location */ /* update ship location */
ship.x += ship.vx * MILLESECONDS_PER_FRAME; shipData.x += shipData.vx * MILLESECONDS_PER_FRAME;
ship.y += ship.vy * MILLESECONDS_PER_FRAME; shipData.y += shipData.vy * MILLESECONDS_PER_FRAME;
if (ship.x > maxx) { if (shipData.x > maxx) {
ship.x = maxx; shipData.x = maxx;
ship.vx = -ship.vx * DAMPING; shipData.vx = -shipData.vx * DAMPING;
} else if (ship.x < minx) { } else if (shipData.x < minx) {
ship.x = minx; shipData.x = minx;
ship.vx = -ship.vx * DAMPING; shipData.vx = -shipData.vx * DAMPING;
} }
if (ship.y > maxy) { if (shipData.y > maxy) {
ship.y = maxy; shipData.y = maxy;
ship.vy = -ship.vy * DAMPING; shipData.vy = -shipData.vy * DAMPING;
} else if (ship.y < miny) { } else if (shipData.y < miny) {
ship.y = miny; shipData.y = miny;
ship.vy = -ship.vy * DAMPING; shipData.vy = -shipData.vy * DAMPING;
} }
/* draw the background */ /* draw the background */
SDL_RenderCopy(space, NULL, NULL); SDL_RenderCopy(space, NULL, NULL);
/* draw the ship */ /* draw the ship */
ship.rect.x = ship.x; shipData.rect.x = shipData.x;
ship.rect.y = ship.y; shipData.rect.y = shipData.y;
SDL_RenderCopy(ship, NULL, &ship.rect); SDL_RenderCopy(ship, NULL, &shipData.rect);
/* update screen */ /* update screen */
SDL_RenderPresent(); SDL_RenderPresent();
...@@ -148,8 +148,8 @@ initializeTextures() ...@@ -148,8 +148,8 @@ initializeTextures()
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
/* set the width and height of the ship from the surface dimensions */ /* set the width and height of the ship from the surface dimensions */
ship.rect.w = bmp_surface->w; shipData.rect.w = bmp_surface->w;
ship.rect.h = bmp_surface->h; shipData.rect.h = bmp_surface->h;
SDL_FreeSurface(bmp_surface_rgba); SDL_FreeSurface(bmp_surface_rgba);
SDL_FreeSurface(bmp_surface); SDL_FreeSurface(bmp_surface);
...@@ -211,10 +211,10 @@ main(int argc, char *argv[]) ...@@ -211,10 +211,10 @@ main(int argc, char *argv[])
initializeTextures(); initializeTextures();
/* setup ship */ /* setup ship */
ship.x = (SCREEN_WIDTH - ship.rect.w) / 2; shipData.x = (SCREEN_WIDTH - shipData.rect.w) / 2;
ship.y = (SCREEN_HEIGHT - ship.rect.h) / 2; shipData.y = (SCREEN_HEIGHT - shipData.rect.h) / 2;
ship.vx = 0.0f; shipData.vx = 0.0f;
ship.vy = 0.0f; shipData.vy = 0.0f;
done = 0; done = 0;
/* enter main loop */ /* enter main loop */
......
...@@ -312,7 +312,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata) ...@@ -312,7 +312,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
#ifdef _WINDOWS #ifdef _WINDOWS
state = SDL_PromptAssertion_windows(data); state = SDL_PromptAssertion_windows(data);
#elif __APPLE__ #elif __MACOSX__
/* This has to be done in an Objective-C (*.m) file, so we call out. */ /* This has to be done in an Objective-C (*.m) file, so we call out. */
extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *); extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *);
state = SDL_PromptAssertion_cocoa(data); state = SDL_PromptAssertion_cocoa(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment