Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

second part of function renaming

  • Loading branch information...
commit f793a31089de907682354d2a8cc2249d16ba2053 1 parent 6a99cea
@niksaak authored
Showing with 34 additions and 50 deletions.
  1. +17 −19 src/main.c
  2. +17 −31 src/state_main.c
View
36 src/main.c
@@ -22,7 +22,7 @@ void benchprint()
static char phstr[64] = {0};
static char gxstr[64] = {0};
- if((win = get_screen()) == NULL)
+ if((win = scrget()) == NULL)
CRASH(SDL_GetError());
if(timcount > 1000) {
snprintf(phstr, 64, "PHY FPS: %i", phycount);
@@ -37,46 +37,44 @@ void benchprint()
int main(int argc, char** argv)
{
- state_t state;
- Uint32 t = 0;
- Uint32 dt = 10;
+ state_t state; // main state IGNOT
+ Uint32 dt = 10; // gameloop vars
Uint32 curtime = 0;
Sint32 accum = 0;
- state = state_main();
+ state = state_main(); // TODO: move this to init_states() or something
- start_screen("TEST", 512, 512, false);
- state.init();
- switch_state(&state);
- curtime = SDL_GetTicks();
+ scrstart("TEST", 512, 512, false); // window appearifies here
+ state.init(); // init our main-and-only (MANLY) gamestate
+ swstate(&state);
+ curtime = SDL_GetTicks(); // initial timerset
while(run_counter) {
- Uint32 newtime;
+ Uint32 newtime; // local gameloop vars
Uint32 frametime;
state_t* st;
- st = CurrentState;
- newtime = SDL_GetTicks();
+ st = curstate();
+ newtime = SDL_GetTicks(); // getting time for frame
frametime = newtime - curtime;
curtime = newtime;
accum += frametime;
- while(accum >= dt) {
+ while(accum >= dt) { // physics loop
st->do_world(dt / 1000.0);
accum -= dt;
- t += dt;
++phycount;
}
- SDL_FillRect(get_screen(), NULL, 0);
+ SDL_FillRect(scrget(), NULL, 0); // rendering
st->do_render();
benchprint();
- SDL_UpdateRect(get_screen(), 0, 0, 0, 0);
+ SDL_UpdateRect(scrget(), 0, 0, 0, 0);
- if(st != CurrentState) {
+ if(st != curstate()) { // put state to sleep if it in not current anymore
st->sleep();
- CurrentState->wake();
+ curstate()->wake();
}
++gfxcount;
--run_counter;
@@ -84,7 +82,7 @@ int main(int argc, char** argv)
}
state.deinit();
- stop_screen();
+ scrstop();
return 0;
}
View
48 src/state_main.c
@@ -3,13 +3,9 @@
#include <SDL/SDL_gfxPrimitives.h>
#include "engine/system.h"
+#include "engine/util.h"
#include "states.h"
-typedef struct SDL_Point {
- int x;
- int y;
-} SDL_Point;
-
struct {
cpShape* shape;
} ground;
@@ -22,58 +18,48 @@ struct {
cpVect gravity;
cpSpace* space = NULL;
-SDL_Point cpv_to_SDL(cpVect vector, SDL_Surface* screen, cpVect offset)
-{
- int w = screen->w;
- int h = screen->h;
- int x = vector.x;
- int y = vector.y;
- SDL_Point xy;
-
- xy.x = (w / 2) + x;
- xy.y = (h / 2) - y;
-
- return xy;
-}
-
-void init()
+static void init()
{
space = cpSpaceNew();
cpSpaceSetGravity(space, cpv(0, -100));
ground.shape = cpSegmentShapeNew(space->staticBody,
cpv(-20,5), cpv(20, -5), 0);
- cpShapeSetFriction(ground.shape, 1);
cpSpaceAddShape(space, ground.shape);
+ cpShapeSetFriction(ground.shape, 1);
+ cpShapeSetElasticity(ground.shape, 0.3);
ball.body = cpSpaceAddBody(
space,
cpBodyNew(1, cpMomentForCircle(1, 0, 5, cpvzero)));
- cpBodySetPos(ball.body, cpv(0, 15));
+ cpBodySetPos(ball.body, cpv(0, 150));
ball.shape = cpSpaceAddShape(
space,
cpCircleShapeNew(ball.body, 5, cpvzero));
cpShapeSetFriction(ball.shape, 0.7);
+ cpShapeSetElasticity(ball.shape, 0.7);
}
-void wake()
+static void wake()
{ }
-void do_world(cpFloat step)
+static void do_world(cpFloat step)
{
cpSpaceStep(space, step);
}
-void do_render()
+static void do_render()
{
- SDL_Surface* screen = get_screen();
+ SDL_Surface* screen = scrget();
+ if(nullp(screen))
+ CRASH(SDL_GetError());
void draw_ground()
{
- SDL_Point pta = cpv_to_SDL(
+ SDL_Point pta = cpvSDL(
cpSegmentShapeGetA(ground.shape), screen, cpvzero);
- SDL_Point ptb = cpv_to_SDL(
+ SDL_Point ptb = cpvSDL(
cpSegmentShapeGetB(ground.shape), screen, cpvzero);
aalineColor(screen, pta.x, pta.y, ptb.x, ptb.y, 0xffffffff);
@@ -82,7 +68,7 @@ void do_render()
void draw_ball()
{
Sint16 radius = cpCircleShapeGetRadius(ball.shape);
- SDL_Point pos = cpv_to_SDL(
+ SDL_Point pos = cpvSDL(
cpBodyGetPos(ball.body), screen, cpvzero);
aacircleColor(screen, pos.x, pos.y, radius, 0xffffffff);
}
@@ -91,10 +77,10 @@ void do_render()
draw_ball();
}
-void sleep()
+static void sleep()
{ }
-void deinit()
+static void deinit()
{
cpShapeFree(ball.shape);
cpBodyFree(ball.body);

0 comments on commit f793a31

Please sign in to comment.
Something went wrong with that request. Please try again.