oh, this is safe actually

https://stackoverflow.com/a/23230406
This commit is contained in:
CPunch 2023-11-28 21:21:24 -06:00
parent 3abba0ca3c
commit 18a6c5ab42

View File

@ -40,15 +40,7 @@ func (c *Chunk) SendPacket(typeID uint32, pkt ...interface{}) {
// calls f for each entity in this chunk, if f returns true, stop iterating
// f can safely add/remove entities from the chunk
func (c *Chunk) ForEachEntity(f func(entity Entity) bool) {
// copy entities to avoid locking for the entire iteration
entities := make(map[Entity]struct{})
c.lock.Lock()
for entity := range c.entities {
entities[entity] = struct{}{}
}
c.lock.Unlock()
for entity := range entities {
if f(entity) {
break
}