My custom Operation

zoultrexzoultrex
edited July 2010 in Photon Server
Ive made an Operation for the player to shoot.
When looking at the MmoActor.cs file I found out I would copy the operation related to the movement and adapt it to my needs. So far so good.
One question I have is, why exactly there are 2 operations related to movement

public OperationResponse OperationMove(Peer peer, OperationRequest request)
and
private OperationResponse ItemOperationMove(MmoItem item, Move operation)

Is it just to be more organized or thats how it has to be done for some reason?
It seems to me that the funcion ItemOperationMove could be integrated inside OperationMove.

Comments

  • BorisBoris ✭✭
    You are right, this is true for OperationMove.

    However, if you compare it to OperationRaiseGenericEvent you will notice a slight difference:
    return this.ItemOperationMove(item, operation);
    
    vs
    if (actorItem)
    {
       // we are already in the item thread, invoke directly
       return ItemOperationRaiseGenericEvent(item, operation);
    }
    
    // second parameter (peer) allows us to send an 
    // error event to the client (in case of an error)
    item.OperationQueue.EnqueueOperation(() => ItemOperationRaiseGenericEvent(item, operation), this.Peer, request);
    
    // operation continued later
    return null;
    

    RaiseEvent is allowed for everyone to call, Move only for the Item owner.
    If you wanted to allow to move items of others you would have to add a similar call to OperationMove.
    So splitting Move into two methods is more for the convenience of making it easier to change it.

    If you are wondering why RaiseEvent is doing this:
    Items run on the owner's fiber. Operation requests arrive on the peer fiber. If the current request does not belong to the same peer that the item does you need to enqueue the operation on the item fiber to make it thread safe.

    So make sure that your operation is just for your own items if you access the item right away, otherwise do it like RaiseEvent.
Sign In or Register to comment.