Permalink
Browse files

reached state of pre-alpha-tech-demo

state of loop showing „Hello world“ and current FPS, to be exact
  • Loading branch information...
1 parent e1094b7 commit 19a76ae6d4d0190c6ad63f8e6a955c6b29b26c0a @niksaak committed Feb 1, 2013
Showing with 73 additions and 7 deletions.
  1. +1 −1 README.md
  2. +68 −6 src/main.c
  3. +4 −0 src/main.h
View
@@ -1,6 +1,6 @@
# DAME
*distance and modular entities*
-Current version: **0.01+0.09i**
+Current version: **0.02+0.09i**
Working on: **Game.** All of it.
View
@@ -1,25 +1,87 @@
#include <stdio.h>
#include <stdbool.h>
-#include <SDL.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_gfxPrimitives.h>
#include "engine/system.h"
#include "engine/util.h"
#include "engine/stateman.h"
#include "states.h"
#include "main.h"
+bool running = true;
+Uint32 run_counter = 9001;
+
+int timcount = 0;
+int phycount = 0;
+int gfxcount = 0;
+
+void benchprint()
+{
+ SDL_Surface* win = NULL;
+ static char phstr[64] = {0};
+ static char gxstr[64] = {0};
+
+ if((win = get_screen()) == NULL)
+ CRASH(SDL_GetError());
+ if(timcount > 1000) {
+ snprintf(phstr, 64, "PHY FPS: %i", phycount);
+ snprintf(gxstr, 64, "GFX FPS: %i", gfxcount);
+ timcount = 0;
+ phycount = 0;
+ gfxcount = 0;
+ }
+ stringColor(win, 10, win->h - 20, phstr, 0xffffffff);
+ stringColor(win, 10, win->h - 10, gxstr, 0xffffffff);
+ SDL_UpdateRect(win, 0, 0, 0, 0);
+}
+
int main(int argc, char** argv)
{
- printf("Hello World!\n");
state_t state;
+ Uint32 t = 0;
+ Uint32 dt = 10;
+ Uint32 curtime = 0;
+ Sint32 accum = 0;
state = state_main();
+
start_screen("TEST", 512, 512, false);
- state.wake();
- state.do_world();
- state.do_render();
- state.sleep();
+ state.init();
+ switch_state(&state);
+ curtime = SDL_GetTicks();
+
+ while(run_counter) {
+ Uint32 newtime;
+ Uint32 frametime;
+ state_t* st;
+
+ st = CurrentState;
+ newtime = SDL_GetTicks();
+ frametime = newtime - curtime;
+ curtime = newtime;
+
+ accum += frametime;
+
+ while(accum >= dt) {
+ st->do_world(dt / 1000.0);
+ accum -= dt;
+ t += dt;
+ ++phycount;
+ }
+ st->do_render();
+
+ if(st != CurrentState) {
+ st->sleep();
+ CurrentState->wake();
+ }
+ ++gfxcount;
+ benchprint();
+ --run_counter;
+ timcount += frametime;
+ }
state.deinit();
+
stop_screen();
return 0;
View
@@ -0,0 +1,4 @@
+#pragma once
+#include <stdbool.h>
+
+extern bool running;

0 comments on commit 19a76ae

Please sign in to comment.