Packages

Ecspanse is an Entity Component System (ECS) library for Elixir, offering a suite of features including: flexible queries with multiple filters, dynamic bidirectional relationships, versatile tagging capabilities, system event subscriptions, or asynchronous system execution.

Current section

Files

Jump to
ecspanse lib ecspanse system track_fps.ex
Raw

lib/ecspanse/system/track_fps.ex

defmodule Ecspanse.System.TrackFPS do
@moduledoc """
A special system provided by the framework to track the FPS.
The value is stored in the `Ecspanse.Resource.FPS` resource.
"""
use Ecspanse.System
@impl true
def run(frame) do
{:ok, fps_resource} = Ecspanse.Query.fetch_resource(Ecspanse.Resource.FPS)
new_time = fps_resource.millisecond + frame.delta
updated_resource =
if new_time >= 1000 do
[value: fps_resource.current + 1, current: 0, millisecond: new_time - 1000]
else
[current: fps_resource.current + 1, millisecond: new_time]
end
Ecspanse.Command.update_resource!(fps_resource, updated_resource)
end
end