big ol refactor

This commit is contained in:
2025-04-16 12:13:29 +02:00
parent b866ac879e
commit 9d60d5e9cd
10 changed files with 747 additions and 382 deletions

View File

@ -1,9 +1,36 @@
package game
import (
"fmt"
"log"
"runtime/debug"
rl "github.com/gen2brain/raylib-go/raylib"
)
// SafeExecute runs a function and recovers from panics
func SafeExecute(action func() error) (err error) {
defer func() {
if r := recover(); r != nil {
stack := debug.Stack()
log.Printf("Recovered from panic: %v\nStack trace:\n%s", r, stack)
err = fmt.Errorf("recovered from panic: %v", r)
}
}()
return action()
}
// SafeExecuteVoid runs a void function and recovers from panics
func SafeExecuteVoid(action func()) {
defer func() {
if r := recover(); r != nil {
stack := debug.Stack()
log.Printf("Recovered from panic: %v\nStack trace:\n%s", r, stack)
}
}()
action()
}
func RayIntersectsBox(ray rl.Ray, boxMin, boxMax rl.Vector3) bool {
tmin := (boxMin.X - ray.Position.X) / ray.Direction.X
tmax := (boxMax.X - ray.Position.X) / ray.Direction.X