holy refactor

started out as me making a service abstraction..

- db.Player exists again, and entity.Player uses it as an embedded struct
- chunk.ForEachEntity() lets you add/remove entities during iteration now
- removed account related fields from CNPeer
- protocol/pool has been merged with protocol.
use protocol.GetBuffer() and protocol.PutBuffer().
- new protocol/internal/service!
service.Service is an abstraction layer to handle multiple CNPeer*
connections and allows you to associate each with an interface{} uData.
In the future it might also handle a task queue for jobs that
modify/interact with the player's uData, called from service.handleEvents()
- PacketHandler callback type has a new param! uData is passed as well now
- much of loginserver/shardserver is now handled by the shared service
abstraction
- SHARD: NPC_ENTER packets are now sent on player loading complete
rather than on enter.
This commit is contained in:
2023-11-27 21:23:28 -06:00
parent d8277ea89c
commit 1f66acfd25
12 changed files with 378 additions and 358 deletions

View File

@@ -38,11 +38,17 @@ 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()
defer c.lock.Unlock()
for entity := range c.entities {
entities[entity] = struct{}{}
}
c.lock.Unlock()
for entity := range entities {
if f(entity) {
break
}