commit 7489c466e6e44a36dca8af1d772dc9a3cd949640 Author: Snoweuph Date: Mon Sep 16 19:47:12 2024 +0200 Init diff --git a/.forgejo/workflows/qs.yml b/.forgejo/workflows/qs.yml new file mode 100644 index 0000000..027ef1e --- /dev/null +++ b/.forgejo/workflows/qs.yml @@ -0,0 +1,28 @@ +name: "Quality Check" +on: + - push + +jobs: + qs-lint: + name: "Linting" + runs-on: "ubuntu-latest" + container: + image: "git.euph.dev/actions/runner-go:latest" + steps: + - name: "Checkout" + uses: "https://git.euph.dev/actions/checkout@v3" + - name: "Lint" + run: | + echo $PATH + ls + tree + qs-static: + name: "Static Analysis" + runs-on: "ubuntu-latest" + container: + image: "git.euph.dev/actions/runner-go:latest" + steps: + - name: "Checkout" + uses: "https://git.euph.dev/actions/checkout@v3" + - name: "Lint" + run: staticcheck ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc22e61 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +game diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..c77e5a7 --- /dev/null +++ b/Justfile @@ -0,0 +1,21 @@ +_default: + just --choose + +clean: + go mod vendor + +build: + #!/bin/sh + if [ -n "$WAYLAND_DISPLAY" ]; then + tags="wayland" + else + tags="" + fi + go build -tags "$tags" -o ./game ./cmd/game/main.go + +run: build + ./game + +check: + @golangci-lint run + @staticcheck ./... diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..64ef339 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module dev.euph.git/snoweuph/game-engine + +go 1.22.6 + +require github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..14e0e73 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= diff --git a/pkg/engine/game.go b/pkg/engine/game.go new file mode 100644 index 0000000..c276c1c --- /dev/null +++ b/pkg/engine/game.go @@ -0,0 +1,29 @@ +package engine + +import ( + engine "dev.euph.git/snoweuph/game-engine/pkg/engine/ports" +) + +type Game struct { + packages []engine.Package +} + +func NewGame(packages ...engine.Package) (*Game, error) { + for _, p := range packages{ + err := p.Load() + if err != nil{ + return nil, err + } + } + return &Game{ + packages: packages, + }, nil +} + +func (g *Game) Terminate(){ + for _, p := range g.packages{ + p.Terminate() + } +} + + diff --git a/pkg/engine/ports/package.go b/pkg/engine/ports/package.go new file mode 100644 index 0000000..b1e885c --- /dev/null +++ b/pkg/engine/ports/package.go @@ -0,0 +1,6 @@ +package engine + +type Package interface { + Load() error + Terminate() +} diff --git a/pkg/engine/ports/window.go b/pkg/engine/ports/window.go new file mode 100644 index 0000000..b2c7a98 --- /dev/null +++ b/pkg/engine/ports/window.go @@ -0,0 +1,7 @@ +package engine + +type Window interface { + Destroy() + SwapBuffers() + ShouldClose() bool +} diff --git a/pkg/glfw/adapters/package.go b/pkg/glfw/adapters/package.go new file mode 100644 index 0000000..e4c24d1 --- /dev/null +++ b/pkg/glfw/adapters/package.go @@ -0,0 +1,24 @@ +package glfw + +import ( + engine "dev.euph.git/snoweuph/game-engine/pkg/engine/ports" + _glfw "github.com/go-gl/glfw/v3.3/glfw" +) + +type GLFWPackage struct{} + +func NewGLFWPackage() engine.Package { + return &GLFWPackage{} +} + + +func (pkg *GLFWPackage) Load() error { + return _glfw.Init() +} + +func (pkg *GLFWPackage) Terminate() { + _glfw.Terminate() +} + + + diff --git a/pkg/glfw/adapters/window.go b/pkg/glfw/adapters/window.go new file mode 100644 index 0000000..9f46104 --- /dev/null +++ b/pkg/glfw/adapters/window.go @@ -0,0 +1,35 @@ +package glfw + +import ( + engine "dev.euph.git/snoweuph/game-engine/pkg/engine/ports" + _glfw "github.com/go-gl/glfw/v3.3/glfw" +) + +type GLFWWindow struct { + window *_glfw.Window +} + +func NewGLFWWindow(w int, h int, title string) (engine.Window, error) { + window, err := _glfw.CreateWindow(w, h, title, nil, nil) + if err != nil { + return nil, err + } + + window.MakeContextCurrent() + + return &GLFWWindow{ + window: window, + }, nil +} + +func (w GLFWWindow) Destroy(){ + w.window.Destroy() +} + +func (w GLFWWindow) SwapBuffers() { + w.window.SwapBuffers() +} + +func (w GLFWWindow) ShouldClose() bool { + return w.window.ShouldClose() +}