more performance
This commit is contained in:
@@ -212,6 +212,11 @@ func (l *Loop) ContextDoneListener() (chSending <-chan any) {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Loop) IsTypeRegistered(t reflect.Type) bool {
|
||||||
|
_, ok := l.HandlerFunctions[t]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Loop) StartLoop() (err error) {
|
func (l *Loop) StartLoop() (err error) {
|
||||||
_ = *l // exit early on nil loop
|
_ = *l // exit early on nil loop
|
||||||
l.RegisterEventSource(l.ContextDoneListener())
|
l.RegisterEventSource(l.ContextDoneListener())
|
||||||
|
|||||||
+11
-5
@@ -27,6 +27,7 @@ var (
|
|||||||
WrongDirectionErr = errors.New("wrong direction")
|
WrongDirectionErr = errors.New("wrong direction")
|
||||||
CantTranslateErr = errors.New("cant translate packet")
|
CantTranslateErr = errors.New("cant translate packet")
|
||||||
PacketDoesntExistInFutureVersionErr = errors.New("packet doesnt exist in future version")
|
PacketDoesntExistInFutureVersionErr = errors.New("packet doesnt exist in future version")
|
||||||
|
NoHandlerRegisteredErr = errors.New("no handler registered")
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoginTick is used as a subsite for the old event system because it is very useful in login contexts
|
// LoginTick is used as a subsite for the old event system because it is very useful in login contexts
|
||||||
@@ -54,11 +55,12 @@ func (u *UnCodablePacket) Decode(r io.Reader) (err error) {
|
|||||||
type Conn struct {
|
type Conn struct {
|
||||||
RawConn
|
RawConn
|
||||||
*event.Loop
|
*event.Loop
|
||||||
state proto_base.State
|
state proto_base.State
|
||||||
stateMutex sync.RWMutex
|
stateMutex sync.RWMutex
|
||||||
Actor proto_base.Actor
|
Actor proto_base.Actor
|
||||||
Version string
|
Version string
|
||||||
ProtocolVersion int32
|
ProtocolVersion int32
|
||||||
|
DecodeEvenIfUnused bool
|
||||||
|
|
||||||
sendTickAlways bool
|
sendTickAlways bool
|
||||||
}
|
}
|
||||||
@@ -219,6 +221,10 @@ func (c *Conn) Receive() (packet proto_base.EncodeDecodeAble, err error) {
|
|||||||
packet = &UnCodablePacket{Err: BadPacketIdErr, Data: packetBytes, Direction: c.Actor.ReceiveDirection()}
|
packet = &UnCodablePacket{Err: BadPacketIdErr, Data: packetBytes, Direction: c.Actor.ReceiveDirection()}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !c.DecodeEvenIfUnused && !c.IsTypeRegistered(reflect.TypeOf(packet)) {
|
||||||
|
packet = &UnCodablePacket{Err: NoHandlerRegisteredErr, Data: packetBytes, Direction: c.Actor.ReceiveDirection()}
|
||||||
|
return
|
||||||
|
}
|
||||||
err = packet.Decode(b)
|
err = packet.Decode(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
packet = &UnCodablePacket{Err: err, Data: packetBytes, Direction: c.Actor.ReceiveDirection()}
|
packet = &UnCodablePacket{Err: err, Data: packetBytes, Direction: c.Actor.ReceiveDirection()}
|
||||||
|
|||||||
+18
-6
@@ -7,15 +7,27 @@ import (
|
|||||||
"github.com/admin-else/strom/proto_generated"
|
"github.com/admin-else/strom/proto_generated"
|
||||||
)
|
)
|
||||||
|
|
||||||
// I know this is in-performant and i dont care until it becomes a problem for somebody it will stay like this and it is pretty easy to make caches or similar to speed this up so yeah
|
type PidEtc struct {
|
||||||
|
Direction proto_base.Direction
|
||||||
|
State proto_base.State
|
||||||
|
PacketId int32
|
||||||
|
ProtocolVersion int32
|
||||||
|
}
|
||||||
|
|
||||||
|
var pidMap = make(map[PidEtc]*proto_base.PacketInfo)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for _, pin := range proto_generated.Packets {
|
||||||
|
pidMap[PidEtc{pin.Direction, pin.State, pin.PacketId, pin.ProtocolVersion}] = &pin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func LookUpTypeByPacketInfo(direction proto_base.Direction, state proto_base.State, pid, version int32) (p proto_base.PacketInfo, ok bool) {
|
func LookUpTypeByPacketInfo(direction proto_base.Direction, state proto_base.State, pid, version int32) (p proto_base.PacketInfo, ok bool) {
|
||||||
for _, pin := range proto_generated.Packets {
|
pP, ok := pidMap[PidEtc{direction, state, pid, version}]
|
||||||
if pin.Direction != direction || pin.State != state || pin.ProtocolVersion != version || pin.PacketId != pid {
|
if !ok {
|
||||||
continue
|
return
|
||||||
}
|
|
||||||
return pin, true
|
|
||||||
}
|
}
|
||||||
|
p = *pP
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user