diff --git a/internal/game/logic.go b/internal/game/logic.go index 4289d49..bb07fa6 100644 --- a/internal/game/logic.go +++ b/internal/game/logic.go @@ -9,6 +9,7 @@ import ( "edgaru089.ink/go/gl01/internal/io" "edgaru089.ink/go/gl01/internal/util" "edgaru089.ink/go/gl01/internal/util/itype" + "edgaru089.ink/go/gl01/internal/work" "github.com/go-gl/glfw/v3.3/glfw" ) @@ -110,9 +111,9 @@ func (g *Game) Init(win *glfw.Window) { } }) -} + work.Init() -const airAccel = 0.1 +} // Update updates the game state, not necessarily in the main thread. func (g *Game) Update(win *glfw.Window, delta time.Duration) { @@ -121,6 +122,8 @@ func (g *Game) Update(win *glfw.Window, delta time.Duration) { clock := util.NewClock() + work.Update(delta) + io.Diagnostics.Times.Logic = clock.Restart() g.imgui() diff --git a/internal/util/clock.go b/internal/util/clock.go index 918a12d..e1578c3 100644 --- a/internal/util/clock.go +++ b/internal/util/clock.go @@ -17,8 +17,9 @@ func NewClock() (c *Clock) { // Restart resets the start time. // It also returns the elapsed time. func (c *Clock) Restart() (t time.Duration) { - t = time.Since(c.t) - c.t = time.Now() + now := time.Now() + t = now.Sub(c.t) + c.t = now return } diff --git a/internal/work/work.go b/internal/work/work.go new file mode 100644 index 0000000..a13f9fd --- /dev/null +++ b/internal/work/work.go @@ -0,0 +1,11 @@ +package work + +import "time" + +func Init() { + +} + +func Update(delta time.Duration) { + +} diff --git a/main.go b/main.go index a5451ab..2bf65fd 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "edgaru089.ink/go/gl01/internal/game" gio "edgaru089.ink/go/gl01/internal/io" _ "edgaru089.ink/go/gl01/internal/render/gpu_preference" + "edgaru089.ink/go/gl01/internal/util" "edgaru089.ink/go/gl01/internal/util/itype" "github.com/go-gl/gl/all-core/gl" "github.com/go-gl/glfw/v3.3/glfw" @@ -70,15 +71,14 @@ func main() { gl.ClearColor(gio.ClearColor[0], gio.ClearColor[1], gio.ClearColor[2], gio.ClearColor[3]) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) win.SwapBuffers() - winClock := time.Now() + winClock := util.NewClock() fpsClock := time.Now() fpsCounter := 0 for !win.ShouldClose() { - deltaTime := time.Since(winClock) - winClock = time.Now() + deltaTime := winClock.Restart() game.Update(win, deltaTime) gl.ClearColor(gio.ClearColor[0], gio.ClearColor[1], gio.ClearColor[2], gio.ClearColor[3])