Compare commits

...

1 Commits

Author SHA1 Message Date
afc9904651 we're ready for tenants 2025-12-19 13:48:48 +08:00
4 changed files with 22 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import (
"edgaru089.ink/go/gl01/internal/io" "edgaru089.ink/go/gl01/internal/io"
"edgaru089.ink/go/gl01/internal/util" "edgaru089.ink/go/gl01/internal/util"
"edgaru089.ink/go/gl01/internal/util/itype" "edgaru089.ink/go/gl01/internal/util/itype"
"edgaru089.ink/go/gl01/internal/work"
"github.com/go-gl/glfw/v3.3/glfw" "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. // Update updates the game state, not necessarily in the main thread.
func (g *Game) Update(win *glfw.Window, delta time.Duration) { 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() clock := util.NewClock()
work.Update(delta)
io.Diagnostics.Times.Logic = clock.Restart() io.Diagnostics.Times.Logic = clock.Restart()
g.imgui() g.imgui()

View File

@@ -17,8 +17,9 @@ func NewClock() (c *Clock) {
// Restart resets the start time. // Restart resets the start time.
// It also returns the elapsed time. // It also returns the elapsed time.
func (c *Clock) Restart() (t time.Duration) { func (c *Clock) Restart() (t time.Duration) {
t = time.Since(c.t) now := time.Now()
c.t = time.Now() t = now.Sub(c.t)
c.t = now
return return
} }

11
internal/work/work.go Normal file
View File

@@ -0,0 +1,11 @@
package work
import "time"
func Init() {
}
func Update(delta time.Duration) {
}

View File

@@ -8,6 +8,7 @@ import (
"edgaru089.ink/go/gl01/internal/game" "edgaru089.ink/go/gl01/internal/game"
gio "edgaru089.ink/go/gl01/internal/io" gio "edgaru089.ink/go/gl01/internal/io"
_ "edgaru089.ink/go/gl01/internal/render/gpu_preference" _ "edgaru089.ink/go/gl01/internal/render/gpu_preference"
"edgaru089.ink/go/gl01/internal/util"
"edgaru089.ink/go/gl01/internal/util/itype" "edgaru089.ink/go/gl01/internal/util/itype"
"github.com/go-gl/gl/all-core/gl" "github.com/go-gl/gl/all-core/gl"
"github.com/go-gl/glfw/v3.3/glfw" "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.ClearColor(gio.ClearColor[0], gio.ClearColor[1], gio.ClearColor[2], gio.ClearColor[3])
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
win.SwapBuffers() win.SwapBuffers()
winClock := time.Now() winClock := util.NewClock()
fpsClock := time.Now() fpsClock := time.Now()
fpsCounter := 0 fpsCounter := 0
for !win.ShouldClose() { for !win.ShouldClose() {
deltaTime := time.Since(winClock) deltaTime := winClock.Restart()
winClock = time.Now()
game.Update(win, deltaTime) game.Update(win, deltaTime)
gl.ClearColor(gio.ClearColor[0], gio.ClearColor[1], gio.ClearColor[2], gio.ClearColor[3]) gl.ClearColor(gio.ClearColor[0], gio.ClearColor[1], gio.ClearColor[2], gio.ClearColor[3])