Init
Some checks failed
Quality Check / Static Analysis (push) Failing after 12s
Quality Check / Linting (push) Failing after 15s

This commit is contained in:
Snoweuph 2024-09-16 19:47:12 +02:00
commit e19048569f
Signed by: Snoweuph
GPG key ID: 4014606F050AEF63
10 changed files with 155 additions and 0 deletions

25
.forgejo/workflows/qs.yml Normal file
View 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
View file

@ -0,0 +1 @@
game

21
Justfile Normal file
View 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
View 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
View 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
View 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()
}
}

View file

@ -0,0 +1,6 @@
package engine
type Package interface {
Load() error
Terminate()
}

View file

@ -0,0 +1,7 @@
package engine
type Window interface {
Destroy()
SwapBuffers()
ShouldClose() bool
}

View 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()
}

View 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()
}