Init
This commit is contained in:
commit
e19048569f
10 changed files with 155 additions and 0 deletions
25
.forgejo/workflows/qs.yml
Normal file
25
.forgejo/workflows/qs.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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: golangci-lint run
|
||||||
|
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 ./...
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
game
|
21
Justfile
Normal file
21
Justfile
Normal file
|
@ -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 ./...
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -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
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -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=
|
29
pkg/engine/game.go
Normal file
29
pkg/engine/game.go
Normal file
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
6
pkg/engine/ports/package.go
Normal file
6
pkg/engine/ports/package.go
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package engine
|
||||||
|
|
||||||
|
type Package interface {
|
||||||
|
Load() error
|
||||||
|
Terminate()
|
||||||
|
}
|
7
pkg/engine/ports/window.go
Normal file
7
pkg/engine/ports/window.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package engine
|
||||||
|
|
||||||
|
type Window interface {
|
||||||
|
Destroy()
|
||||||
|
SwapBuffers()
|
||||||
|
ShouldClose() bool
|
||||||
|
}
|
24
pkg/glfw/adapters/package.go
Normal file
24
pkg/glfw/adapters/package.go
Normal file
|
@ -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()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
35
pkg/glfw/adapters/window.go
Normal file
35
pkg/glfw/adapters/window.go
Normal file
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in a new issue