mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 23:10:06 +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"
|
"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 {
|
func (server *ShardServer) getChunk(pos entity.ChunkPosition) *entity.Chunk {
|
||||||
chunk, ok := server.chunks[pos]
|
chunk, ok := server.chunks[pos]
|
||||||
if !ok {
|
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) {
|
func (server *ShardServer) removeEntityFromChunks(chunks []*entity.Chunk, this entity.Entity) {
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
for e, _ := range chunk.Entities {
|
for e := range chunk.Entities {
|
||||||
if e == this {
|
if e == this {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -57,7 +69,7 @@ func (server *ShardServer) removeEntityFromChunks(chunks []*entity.Chunk, this e
|
|||||||
|
|
||||||
func (server *ShardServer) addEntityToChunks(chunks []*entity.Chunk, this entity.Entity) {
|
func (server *ShardServer) addEntityToChunks(chunks []*entity.Chunk, this entity.Entity) {
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
for e, _ := range chunk.Entities {
|
for e := range chunk.Entities {
|
||||||
if e == this {
|
if e == this {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,7 @@ func (server *ShardServer) disconnect(peer *protocol.CNPeer) {
|
|||||||
plr, ok := server.peers[peer]
|
plr, ok := server.peers[peer]
|
||||||
if ok {
|
if ok {
|
||||||
log.Printf("Player %d (AccountID %d) disconnected\n", plr.PlayerID, plr.AccountID)
|
log.Printf("Player %d (AccountID %d) disconnected\n", plr.PlayerID, plr.AccountID)
|
||||||
server.removeEntityFromChunks(server.getViewableChunks(plr.Chunk), plr)
|
server.removeEntity(plr)
|
||||||
server.getChunk(plr.Chunk).RemoveEntity(plr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Peer %p disconnected from SHARD\n", peer)
|
log.Printf("Peer %p disconnected from SHARD\n", peer)
|
||||||
|
Loading…
Reference in New Issue
Block a user