Fix chat and other players not showing up

This commit is contained in:
2025-04-16 11:13:52 +02:00
parent 5bf962a18d
commit 555b8118f2
6 changed files with 80 additions and 33 deletions

View File

@ -9,7 +9,7 @@ import (
)
type Player struct {
sync.RWMutex
sync.RWMutex // Keep this for network operations
Model rl.Model
Texture rl.Texture2D
PosActual rl.Vector3
@ -31,9 +31,7 @@ type Player struct {
}
func (p *Player) MoveTowards(target Tile, deltaTime float32, mapGrid [][]Tile) {
p.Lock()
defer p.Unlock()
// No need for lock here as this is called from a single thread (game loop)
targetPos := rl.Vector3{
X: float32(target.X * TileSize),
Y: mapGrid[target.X][target.Y].Height * TileHeight,
@ -53,7 +51,7 @@ func (p *Player) MoveTowards(target Tile, deltaTime float32, mapGrid [][]Tile) {
oldFrame := p.AnimationFrame
p.AnimationFrame += int32(deltaTime * 60)
rl.TraceLog(rl.LogInfo, "Walk frame update: %d -> %d (delta: %f)",
rl.TraceLog(rl.LogDebug, "Walk frame update: %d -> %d (delta: %f)",
oldFrame, p.AnimationFrame, deltaTime)
} else {
wasMoving := p.IsMoving
@ -65,7 +63,7 @@ func (p *Player) MoveTowards(target Tile, deltaTime float32, mapGrid [][]Tile) {
oldFrame := p.AnimationFrame
p.AnimationFrame += int32(deltaTime * 60)
rl.TraceLog(rl.LogInfo, "Idle frame update: %d -> %d (delta: %f)",
rl.TraceLog(rl.LogDebug, "Idle frame update: %d -> %d (delta: %f)",
oldFrame, p.AnimationFrame, deltaTime)
}
@ -116,6 +114,7 @@ func (p *Player) UpdatePosition(state *pb.PlayerState, tickRate time.Duration) {
}
func (p *Player) ForceResync(state *pb.PlayerState) {
// Keep this lock since it's called from the network goroutine
p.Lock()
defer p.Unlock()