소스 검색

modified the update declaration, and the main function in order to be able to use a delta-time-based system

Adrien Boucaud 12 년 전
부모
커밋
dc0bac7330
3개의 변경된 파일9개의 추가작업 그리고 5개의 파일을 삭제
  1. 7 3
      hexagon.c
  2. 1 1
      wall.c
  3. 1 1
      wall.h

+ 7 - 3
hexagon.c

@@ -31,6 +31,9 @@ void drawDiagonal(int nb);
 
 int AddIn_main(int isAppli, unsigned short OptionNum)
 {
+    unsigned int start_time = RTC_GetTicks(); //1 tick == 1/128 second
+    unsigned int last_time = 0;
+    unsigned int current_time = RTC_GetTicks();
 	//variables for fps calculation
     unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks();
 	//char string to display the fps
@@ -40,9 +43,10 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
 
     //list = addWall(list, 128, 8, 1, 1);
 
-    while(KeyUp(K_EXIT)){
+    while(KeyUp(K_EXIT)){ //main loop
+    	last_time = current_time;
+	current_time = RTC_GetTicks();
         //fps
-        int current_frame_time = RTC_GetTicks();
         if(RTC_GetTicks() - tempsOrigine >= 32 )//if 1/4 seconds elapsed
         {
             fps = frame*4;
@@ -55,7 +59,7 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
         cam.angle = (int) (cam.angle + dAngle);
         if(cam.angle >= 360)cam.angle = cam.angle - 359;
         if(list != NULL){ //if the linked list is not empty
-            update(list); //update the linked list
+            update(list, current_time - last_time); //update the linked list
 
         if(isColliding(list, player_angle) == true) //if the player and a wall collide
      	{

+ 1 - 1
wall.c

@@ -59,7 +59,7 @@ Wall *removeWall(Wall *list, int d)
 	return list;
 }
 
-void update(Wall *list)
+void update(Wall *list, unsigned int delta_time)
 {
 	Wall *tmp;
 	tmp = list;

+ 1 - 1
wall.h

@@ -13,7 +13,7 @@ Wall *removeWall(Wall *list, int d); //returns a new pointer to the first elemen
 //show the ll "list"
 void show(Wall *list, Camera *cam);
 //updates the ll "list"
-void update(Wall *list);
+void update(Wall *list, unsigned int delta_time);
 //simple collision test. Returns true if a Wall from the list collides with the player
 bool isColliding(Wall *list, int player_angle);
 #endif