- [NEW] system.fps()
This commit is contained in:
6
lua.cpp
6
lua.cpp
@@ -670,6 +670,11 @@ extern "C" {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpp_sys_fps(lua_State *L) {
|
||||
lua_pushnumber(L, getfps());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// win
|
||||
// ===============================================
|
||||
@@ -922,6 +927,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_sys_updateTimeout); lua_setfield(L, -2, "updateOnEventsAndTimeout");
|
||||
lua_pushcfunction(L,cpp_sys_dir); lua_setfield(L, -2, "getFilesInDataDirectory");
|
||||
lua_pushcfunction(L,cpp_sys_exit); lua_setfield(L, -2, "quit");
|
||||
lua_pushcfunction(L,cpp_sys_fps); lua_setfield(L, -2, "fps");
|
||||
lua_setglobal(L, "system");
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
14
mini.cpp
14
mini.cpp
@@ -23,7 +23,9 @@ struct surface_t {
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
|
||||
int fps=0;
|
||||
int fps_counter=0;
|
||||
uint32_t fps_timer=0;
|
||||
char window_title[256];
|
||||
char config_folder[256];
|
||||
uint16_t screen_width = 160;
|
||||
@@ -475,6 +477,12 @@ int main(int argc,char*argv[]){
|
||||
SDL_UnlockTexture(mini_bak);
|
||||
SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
||||
SDL_RenderPresent(mini_ren);
|
||||
fps_counter++;
|
||||
if (SDL_GetTicks()>=(fps_timer+1000)) {
|
||||
fps = fps_counter;
|
||||
fps_counter=0;
|
||||
fps_timer = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
@@ -1146,6 +1154,10 @@ int rnd(int x) {
|
||||
return rand()%x;
|
||||
}
|
||||
|
||||
int getfps() {
|
||||
return fps;
|
||||
}
|
||||
|
||||
void playmusic(const char *filename, const int loop) {
|
||||
int size;
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
|
||||
Reference in New Issue
Block a user