Skip to content

Instantly share code, notes, and snippets.

@hikari-no-yume
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hikari-no-yume/4f5259cde015a4d8f212 to your computer and use it in GitHub Desktop.
Save hikari-no-yume/4f5259cde015a4d8f212 to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <ctime>
#define DLLEXPORT extern "C" __declspec (dllexport)
DLLEXPORT double get_time()
{
time_t currentTime, zeroTime = {0};
time(&currentTime);
return difftime(currentTime, zeroTime);
}
global._get_time = external_define("ctime.dll", "get_time", dll_cdecl, ty_real, 0);
globalvar get_time;
get_time = "return external_call(global._get_time);"
object_event_add(PlayerControl,ev_create,0,"
lastTime = execute_string(get_time);
time = lastTime;
");
object_event_add(PlayerControl,ev_step,ev_step_begin,"
time = execute_string(get_time);
time_delta = time - lastTime;
lastTime = time;
if (time_delta != 0)
{
global.target_fps = 1/time_delta;
}
else
{
global.target_fps = 1;
}
global.delta_factor = 30/global.target_fps;
global.ticks_per_virtual = global.target_fps/30;
global.skip_delta_factor = global.delta_factor/global.frameskip;
");
//the first thing I thought of that existed through the entire game
//in case the game closes during a menu or something
object_event_add(RateController,ev_other, ev_game_end,"
external_free('ctime.dll');
");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment