switched from uclock() to PCTIMER in love.timer
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ LOVE/
|
|||||||
rel/
|
rel/
|
||||||
test/
|
test/
|
||||||
test2/
|
test2/
|
||||||
|
pi/
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "vgm.h"
|
#include "vgm.h"
|
||||||
#include "lib/pctimer/gccint8.h"
|
#include "lib/pctimer/gccint8.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
static lua_State *L;
|
static lua_State *L;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ int main(int argc, char **argv) {
|
|||||||
palette_init();
|
palette_init();
|
||||||
keyboard_init();
|
keyboard_init();
|
||||||
mouse_init();
|
mouse_init();
|
||||||
pctimer_init(1000);
|
pctimer_init(TICKS_PER_SEC);
|
||||||
init_vgm();
|
init_vgm();
|
||||||
|
|
||||||
/* Init lua */
|
/* Init lua */
|
||||||
|
|||||||
6
src/main.h
Normal file
6
src/main.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef MAIN_H
|
||||||
|
#define MAIN_H
|
||||||
|
|
||||||
|
#define TICKS_PER_SEC 1000
|
||||||
|
|
||||||
|
#endif // MAIN_H
|
||||||
@@ -6,10 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#include <time.h>
|
|
||||||
#include "luaobj.h"
|
#include "luaobj.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
|
#include "lib/pctimer/gccint8.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
long long timer_lastStep;
|
long long timer_lastStep;
|
||||||
double timer_lastDt;
|
double timer_lastDt;
|
||||||
@@ -21,13 +22,13 @@ double timer_avgTimer;
|
|||||||
|
|
||||||
int l_timer_step(lua_State *L) {
|
int l_timer_step(lua_State *L) {
|
||||||
/* Do delta */
|
/* Do delta */
|
||||||
long long now;
|
unsigned long now;
|
||||||
/* Sometimes a call to uclock() will return a slightly earlier time than the
|
/* Sometimes a call to uclock() will return a slightly earlier time than the
|
||||||
* previous call, resulting in a negative delta time. The below loop keeps
|
* previous call, resulting in a negative delta time. The below loop keeps
|
||||||
* trying for a proper value if this occurs. */
|
* trying for a proper value if this occurs. */
|
||||||
do {
|
do {
|
||||||
now = uclock();
|
now = pctimer_get_ticks();
|
||||||
timer_lastDt = (now - timer_lastStep) / (double)UCLOCKS_PER_SEC;
|
timer_lastDt = (now - timer_lastStep) / (double)TICKS_PER_SEC;
|
||||||
} while (timer_lastDt < 0);
|
} while (timer_lastDt < 0);
|
||||||
timer_lastStep = now;
|
timer_lastStep = now;
|
||||||
/* Do average */
|
/* Do average */
|
||||||
@@ -64,7 +65,7 @@ int l_timer_getFPS(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int l_timer_getTime(lua_State *L) {
|
int l_timer_getTime(lua_State *L) {
|
||||||
lua_pushnumber(L, uclock() / (double)UCLOCKS_PER_SEC);
|
lua_pushnumber(L, pctimer_get_ticks() / (double)TICKS_PER_SEC);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ VGM specs are at https://vgmrips.net/wiki/VGM_Specification
|
|||||||
#include "vgm.h"
|
#include "vgm.h"
|
||||||
#include "lib/pctimer/gccint8.h"
|
#include "lib/pctimer/gccint8.h"
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#define VGM_RESOLUTION 44100
|
#define VGM_RESOLUTION 44100
|
||||||
#define VGM_FACTOR 44
|
#define VGM_FACTOR (VGM_RESOLUTION / TICKS_PER_SEC)
|
||||||
#define VGM_OPL_ADDR 0x388
|
#define VGM_OPL_ADDR 0x388
|
||||||
#define VGM_OPL_DATA 0x389
|
#define VGM_OPL_DATA 0x389
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user