add a bunch of mutexes and shit but still have racist conditions and panics LOL

This commit is contained in:
2025-01-22 20:14:58 +01:00
parent 417bf4ea63
commit 220a451475
7 changed files with 309 additions and 161 deletions

View File

@ -1,12 +1,34 @@
package types
import (
"sync"
"time"
pb "gitea.boner.be/bdnugget/goonserver/actions"
rl "github.com/gen2brain/raylib-go/raylib"
)
type Player struct {
sync.RWMutex
Model rl.Model
Texture rl.Texture2D
PosActual rl.Vector3
PosTile Tile
TargetPath []Tile
Speed float32
ActionQueue []*pb.Action
ID int32
QuitDone chan struct{}
CurrentTick int64
UserData interface{}
FloatingMessage *FloatingMessage
IsMoving bool
AnimationFrame int32
LastAnimUpdate time.Time
LastUpdateTime time.Time
InterpolationProgress float32
}
func (p *Player) MoveTowards(target Tile, deltaTime float32, mapGrid [][]Tile) {
p.Lock()
defer p.Unlock()
@ -68,12 +90,14 @@ func NewPlayer(state *pb.PlayerState) *Player {
Y: float32(state.Y * TileHeight),
Z: float32(state.Y * TileSize),
},
PosTile: Tile{X: int(state.X), Y: int(state.Y)},
Speed: 50.0,
ID: state.PlayerId,
IsMoving: false,
AnimationFrame: 0,
LastAnimUpdate: time.Now(),
PosTile: Tile{X: int(state.X), Y: int(state.Y)},
Speed: 50.0,
ID: state.PlayerId,
IsMoving: false,
AnimationFrame: 0,
LastAnimUpdate: time.Now(),
LastUpdateTime: time.Now(),
InterpolationProgress: 1.0,
}
}

View File

@ -1,7 +1,6 @@
package types
import (
"sync"
"time"
pb "gitea.boner.be/bdnugget/goonserver/actions"
@ -14,27 +13,6 @@ type Tile struct {
Walkable bool
}
type Player struct {
sync.Mutex
PosActual rl.Vector3
PosTile Tile
TargetPath []Tile
ActionQueue []*pb.Action
Speed float32
Model rl.Model
Texture rl.Texture2D
ID int32
CurrentTick int64
LastUpdateTime time.Time
LastAnimUpdate time.Time
InterpolationProgress float32
UserData interface{}
FloatingMessage *FloatingMessage
QuitDone chan struct{}
AnimationFrame int32
IsMoving bool
}
type AnimationSet struct {
Idle []rl.ModelAnimation
Walk []rl.ModelAnimation