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
+8
View File
@@ -2,6 +2,7 @@ package game
import (
"fmt"
"sync"
"time"
"gitea.boner.be/bdnugget/goonscape/types"
@@ -25,6 +26,7 @@ type Chat struct {
cursorPos int
scrollOffset int
userData interface{}
mutex sync.RWMutex
}
func NewChat() *Chat {
@@ -49,6 +51,9 @@ func (c *Chat) AddMessage(playerID int32, content string) {
}
func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
c.mutex.Lock()
defer c.mutex.Unlock()
// Convert protobuf messages to our local type
for _, msg := range messages {
localMsg := types.ChatMessage{
@@ -94,6 +99,9 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
}
func (c *Chat) Draw(screenWidth, screenHeight int32) {
c.mutex.RLock()
defer c.mutex.RUnlock()
// Calculate chat window width based on screen width
chatWindowWidth := screenWidth - (chatMargin * 2)