Skip to content

Instantly share code, notes, and snippets.

@Rusketh
Created June 12, 2017 19:13
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 Rusketh/70586ddc400471fb6f050e61d16a5cbf to your computer and use it in GitHub Desktop.
Save Rusketh/70586ddc400471fb6f050e61d16a5cbf to your computer and use it in GitHub Desktop.
ENGINE_TICK_RATE = 1/10; -- 0.1
ENGINE_THINK_RATE = 1/20; -- 0.05
ENGINE_FRAME_RATE = 1/30; -- 0.03
---------------------------------
includeSafely("lua/core/game.lua");
---------------------------------
local event_pump = love.event.pump;
local event_poll = love.event.poll;
local timer_step = love.timer.step;
local timer_getDelta = love.timer.getDelta;
local timer_sleep = love.timer.sleep;
local clear_frame = love.graphics.clear;
local origin = love.graphics.origin;
local present = love.graphics.present;
local canDraw = love.graphics.isActive;
local time = os.time;
---------------------------------
---------------------------------
love.physics.setMeter(GAME_WORLD_SCALE);
love.math.setRandomSeed(os.time());
love.timer.step();
---------------------------------
local ok, err = pcall(function()
local loop = true;
local tick_delta = 0;
local next_tick = 0;
local think_delta = 0;
local next_think = 0;
while loop do
-- Check for an event.
event_pump();
for name, a, b, c, d, e, f in event_poll() do
if name ~= "quit" then
Hook.call(name, GAME, a, b, c, d, e, f);
else
loop = false;
break;
end
end
-- Measure the time for this frame.
timer_step();
local dlt = timer_getDelta();
current_time = current_time + dlt;
-- Run a game tick.
tick_delta = tick_delta + dlt;
if current_time >= next_tick then
GAME:GameTick(tick_delta, current_time);
next_tick = current_time + ENGINE_TICK_RATE;
tick_delta = 0;
end
-- Run a game think.
think_delta = think_delta + dlt;
if current_time >= next_think then
GAME:GameThink(think_delta, current_time);
next_think = current_time + ENGINE_THINK_RATE;
think_delta = 0;
end
-- Draw the frame.
if canDraw() then
love.graphics.clear(100, 100, 100, 255);
love.graphics.origin();
GAME:DrawFrame(dt, current_time);
love.graphics.present();
print("Rendered: ", current_time)
end
-- Update the uptime counter.
total_up_time = time() - current_time;
-- Sleep til the enxt frame.
timer_sleep(ENGINE_FRAME_RATE);
end
end)
---------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment