Add golangci-lint and fix errors found

main
Sean Hickey 2022-04-25 00:22:04 -07:00
parent db5a0aa6e8
commit b3c161eed2
5 changed files with 52 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# BSD 2-Clause License # BSD 2-Clause License
Copyright (c) 2021, Sean Hickey (Wisellama) Copyright (c) 2021-2022, Sean Hickey (Wisellama)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -3,12 +3,15 @@ all: release
dependencies: dependencies:
go mod tidy go mod tidy
build: dependencies build: linter dependencies
go build -x -v go build -x -v
release: dependencies release: linter dependencies
go build -x -v -ldflags "-s -w" go build -x -v -ldflags "-s -w"
linter:
golangci-lint run
cross_windows: cross_windows:
export CGO_ENABLED=1 export CGO_ENABLED=1
export CC=x86_64-w64-mingw32-gcc export CC=x86_64-w64-mingw32-gcc
@ -22,3 +25,6 @@ cross_windows_x86:
export GOOS=windows export GOOS=windows
export GOARCH=386 export GOARCH=386
go build -x -v -ldflags "-s -w" go build -x -v -ldflags "-s -w"
goimports_everything:
find . -name "*.go" -exec goimports -w {} \;

35
main.go
View File

@ -17,7 +17,6 @@ import (
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
const gameTitle = "Carpy Breakout" const gameTitle = "Carpy Breakout"
const logFile = "output.log"
func main() { func main() {
flag.Parse() flag.Parse()
@ -27,7 +26,10 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
pprof.StartCPUProfile(f) err = pprof.StartCPUProfile(f)
if err != nil {
log.Fatal(err)
}
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
@ -51,7 +53,10 @@ func runOpenGL() {
} }
defer sdl.Quit() defer sdl.Quit()
sdlSettings() err = sdlSettings()
if err != nil {
log.Fatal(err)
}
gameWindow, err := breakout.NewGameWindow(gameTitle) gameWindow, err := breakout.NewGameWindow(gameTitle)
if err != nil { if err != nil {
@ -71,7 +76,10 @@ func runOpenGL() {
log.Printf("OpenGL Version: %v\n", gl.GoStr(glVersion)) log.Printf("OpenGL Version: %v\n", gl.GoStr(glVersion))
// Then we can setup the OpenGL specific stuff in the game window // Then we can setup the OpenGL specific stuff in the game window
gameWindow.GLInitDefault() err = gameWindow.GLInitDefault()
if err != nil {
log.Printf("error in gameWindow GLInitDefault: %v", err)
}
sunLight := globjects.NewPointLight(mgl32.Vec3{-10, 10, 30}) sunLight := globjects.NewPointLight(mgl32.Vec3{-10, 10, 30})
sunLight.GLInit(gameWindow.GLProgram) sunLight.GLInit(gameWindow.GLProgram)
@ -141,6 +149,7 @@ func runOpenGL() {
} }
func setupLogging() { func setupLogging() {
// const logFile = "output.log"
// file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) // file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
// if err != nil { // if err != nil {
// log.Fatal(err) // log.Fatal(err)
@ -158,10 +167,20 @@ func glSettings() {
gl.LineWidth(2.0) gl.LineWidth(2.0)
} }
func sdlSettings() { func sdlSettings() error {
var err error
// Smooth // Smooth
sdl.GLSetAttribute(sdl.GL_MULTISAMPLEBUFFERS, 1) err = sdl.GLSetAttribute(sdl.GL_MULTISAMPLEBUFFERS, 1)
sdl.GLSetAttribute(sdl.GL_MULTISAMPLESAMPLES, 4) if err != nil {
log.Printf("error setting GL_MULTISAMPLEBUFFERS: %v", err)
return err
}
err = sdl.GLSetAttribute(sdl.GL_MULTISAMPLESAMPLES, 4)
if err != nil {
log.Printf("error setting GL_MULTISAMPLESAMPLES: %v", err)
return err
}
// Disable the Linux compositor flicker. // Disable the Linux compositor flicker.
// https://github.com/mosra/magnum/issues/184#issuecomment-425952900 // https://github.com/mosra/magnum/issues/184#issuecomment-425952900
@ -171,4 +190,6 @@ func sdlSettings() {
// Capture the mouse for movement // Capture the mouse for movement
sdl.SetRelativeMouseMode(true) sdl.SetRelativeMouseMode(true)
return nil
} }

View File

@ -90,16 +90,28 @@ func (w *GameWindow) AddObject(object globjects.GLObject) {
} }
func (w *GameWindow) Destroy() { func (w *GameWindow) Destroy() {
w.SDLWindow.Destroy() err := w.SDLWindow.Destroy()
if err != nil {
log.Println(err)
}
sdl.GLDeleteContext(*w.GLContext) sdl.GLDeleteContext(*w.GLContext)
} }
func (w *GameWindow) ToggleFullscreen() { func (w *GameWindow) ToggleFullscreen() {
var err error
if w.fullscreen { if w.fullscreen {
w.SDLWindow.SetFullscreen(defaultWindowFlags) err = w.SDLWindow.SetFullscreen(defaultWindowFlags)
if err != nil {
log.Printf("error setting defaultWindowFlags: %v", err)
}
} else { } else {
w.SDLWindow.SetFullscreen(fullscreenWindowFlags) err = w.SDLWindow.SetFullscreen(fullscreenWindowFlags)
if err != nil {
log.Printf("error setting fullscreenWindowFlags: %v", err)
}
} }
w.fullscreen = !w.fullscreen w.fullscreen = !w.fullscreen
} }

View File

@ -52,7 +52,6 @@ func (c *Camera) GLDraw() {
} }
func (c *Camera) GLInit(glProgram uint32) { func (c *Camera) GLInit(glProgram uint32) {
return
} }
func (c *Camera) Update() { func (c *Camera) Update() {
@ -61,7 +60,6 @@ func (c *Camera) Update() {
} }
func (c *Camera) ToggleWireframe() { func (c *Camera) ToggleWireframe() {
return
} }
func (c *Camera) GetAABB() *AABB { func (c *Camera) GetAABB() *AABB {