mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-10-11 03:40:06 +00:00
fix: Chunks are now goroutine safe
- added Chunk.ForEachEntity() - refactored SendPacketExclude() to use it - Chunk.Entities is now Chunk.entities, which is private. - Chunk.AddEntity() && RemoveEntity() now lock the chunk mutex
This commit is contained in:
@@ -58,9 +58,9 @@ func (server *ShardServer) sendAllPacket(plr *entity.Player, typeID uint32, pkt
|
||||
|
||||
func (server *ShardServer) removeEntityFromChunks(this entity.Entity, chunks []*entity.Chunk) {
|
||||
for _, chunk := range chunks {
|
||||
for e := range chunk.Entities {
|
||||
chunk.ForEachEntity(func(e entity.Entity) bool {
|
||||
if e == this {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
|
||||
// notify other players we're leaving
|
||||
@@ -74,15 +74,17 @@ func (server *ShardServer) removeEntityFromChunks(this entity.Entity, chunks []*
|
||||
thisPlr := this.(*entity.Player)
|
||||
e.DisappearFromViewOf(thisPlr.Peer)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (server *ShardServer) addEntityToChunks(this entity.Entity, chunks []*entity.Chunk) {
|
||||
for _, chunk := range chunks {
|
||||
for e := range chunk.Entities {
|
||||
chunk.ForEachEntity(func(e entity.Entity) bool {
|
||||
if e == this {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
|
||||
// notify other players we're entering
|
||||
@@ -96,7 +98,9 @@ func (server *ShardServer) addEntityToChunks(this entity.Entity, chunks []*entit
|
||||
thisPlr := this.(*entity.Player)
|
||||
e.EnterIntoViewOf(thisPlr.Peer)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user