mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-14 03:50:05 +00:00
added shard.addEntity() and shard.removeEntity()
This commit is contained in:
parent
c09a6cfd25
commit
80dc876517
@ -4,6 +4,18 @@ import (
|
||||
"github.com/CPunch/gopenfusion/core/entity"
|
||||
)
|
||||
|
||||
func (server *ShardServer) addEntity(e entity.Entity) {
|
||||
pos := e.GetChunk()
|
||||
server.addEntityToChunks(server.getViewableChunks(pos), e)
|
||||
server.getChunk(pos).AddEntity(e)
|
||||
}
|
||||
|
||||
func (server *ShardServer) removeEntity(e entity.Entity) {
|
||||
pos := e.GetChunk()
|
||||
server.removeEntityFromChunks(server.getViewableChunks(pos), e)
|
||||
server.getChunk(pos).RemoveEntity(e)
|
||||
}
|
||||
|
||||
func (server *ShardServer) getChunk(pos entity.ChunkPosition) *entity.Chunk {
|
||||
chunk, ok := server.chunks[pos]
|
||||
if !ok {
|
||||
@ -35,7 +47,7 @@ func (server *ShardServer) sendOthersPacket(plr *entity.Player, typeID uint32, p
|
||||
|
||||
func (server *ShardServer) removeEntityFromChunks(chunks []*entity.Chunk, this entity.Entity) {
|
||||
for _, chunk := range chunks {
|
||||
for e, _ := range chunk.Entities {
|
||||
for e := range chunk.Entities {
|
||||
if e == this {
|
||||
continue
|
||||
}
|
||||
@ -57,7 +69,7 @@ func (server *ShardServer) removeEntityFromChunks(chunks []*entity.Chunk, this e
|
||||
|
||||
func (server *ShardServer) addEntityToChunks(chunks []*entity.Chunk, this entity.Entity) {
|
||||
for _, chunk := range chunks {
|
||||
for e, _ := range chunk.Entities {
|
||||
for e := range chunk.Entities {
|
||||
if e == this {
|
||||
continue
|
||||
}
|
||||
|
@ -122,8 +122,7 @@ func (server *ShardServer) disconnect(peer *protocol.CNPeer) {
|
||||
plr, ok := server.peers[peer]
|
||||
if ok {
|
||||
log.Printf("Player %d (AccountID %d) disconnected\n", plr.PlayerID, plr.AccountID)
|
||||
server.removeEntityFromChunks(server.getViewableChunks(plr.Chunk), plr)
|
||||
server.getChunk(plr.Chunk).RemoveEntity(plr)
|
||||
server.removeEntity(plr)
|
||||
}
|
||||
|
||||
log.Printf("Peer %p disconnected from SHARD\n", peer)
|
||||
|
Loading…
Reference in New Issue
Block a user