mirror of
https://github.com/CPunch/gopenfusion.git
synced 2026-04-09 11:10:03 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user