]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_timer.c
Merge branch 'master' of github.com:sparky4/16
[16.git] / src / lib / 16_timer.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/16_timer.h"\r
24 \r
25 clock_t start_timer(global_game_variables_t *gv)\r
26 {\r
27         gv->kurokku.t = clock();\r
28         gv->kurokku.tiku = 0;\r
29         gv->kurokku.clock_start = *clockw;\r
30         gv->kurokku.clock = clockw;\r
31         gv->kurokku.frames_per_second = 60;\r
32         gv->pee = _nmalloc(sizeof(byte)*16);\r
33         //turn this off if XT\r
34         switch(detectcpu())\r
35         {\r
36                 case 0:\r
37                         gv->kurokku.fpscap=0;\r
38                 break;\r
39                 default:\r
40                         gv->kurokku.fpscap=1;\r
41                 break;\r
42         }\r
43         return gv->kurokku.t;\r
44 }\r
45 \r
46 double elapsed_timer(global_game_variables_t *gv)\r
47 {\r
48         return (clock() - gv->kurokku.t) / CLOCKS_PER_SEC;\r
49 }\r
50 \r
51 double ticktock(global_game_variables_t *gv)\r
52 {\r
53         double clocku;\r
54         clocku = (clock() - gv->kurokku.t) / CLOCKS_PER_SEC;\r
55         gv->kurokku.t = clock();\r
56         return clocku;\r
57 }\r
58 \r
59 double time_in_seconds(global_game_variables_t *gv)\r
60 {\r
61         return (gv->kurokku.t) / CLOCKS_PER_SEC;\r
62 }\r
63 \r
64 /*double time_in_seconds(time_t in_t)\r
65 {\r
66         return (in_t) / CLOCKS_PER_SEC;\r
67 }*/\r
68 \r
69 /*      sync    */\r
70 void shinkutxt(global_game_variables_t *gv)\r
71 {\r
72         //float t;\r
73         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))\r
74         {\r
75                 //t=(((*(gv->clock))-gv->clock_start) /18.2);\r
76                 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));\r
77                 fprintf(stderr, "%s\n", gv->pee);\r
78                 //(gv->clock_start)=*(gv->clock);\r
79                 gv->kurokku.tiku=0;\r
80         }\r
81         gv->kurokku.tiku++;\r
82         switch(gv->kurokku.fpscap)\r
83         {\r
84                 case 0:\r
85                         gv->kurokku.frames_per_second=1;\r
86                 break;\r
87                 case 1:\r
88                         //turn this off if XT\r
89                         WaitPee();\r
90                         gv->kurokku.frames_per_second=60;\r
91                 break;\r
92         }\r
93 }\r
94 \r
95 void WaitPee()\r
96 {\r
97     while(inp(INPUT_STATUS_1)  & 8)  {\r
98         /* spin */\r
99     }\r
100 \r
101     while(!(inp(INPUT_STATUS_1)  & 8))  {\r
102         /* spin */\r
103     }\r
104 }\r