Can I use RPC's for everything?

Options
Hi,

Is there any issues with using ONLY RPC's?

I want to control the amount of data send when sync-ing objects, so instead of having Photon send the data X times per second - can I just use my own RPC's to send data when needed?

Is there any real issues with using this everywhere? (player join, player leaves, for physics objects, to notify players of newly spawned objects, player picks up object, etc.) ?

What downsides exist?

Thanks,

James

Comments

  • One issue is buffering, if the RPC are not buffered, the state will be lost for any new players joining the room. If the RPC's are buffered, a new player will receive a whole bunch all at once when they join the room, so your code would need to be able to handle that.
  • Another way to control the amount of messages, would be to use the concept of a 'dirty flag'. Only send state over when one of the fields has been changed (dirtied). When a new player is detected to have joined, set the dirty flag to true, and the new player will get the latest state.
  • Thanks for this, I don't want to buffer as this could mean a ton of message for long lived games! (the cheat would to only allow players to join at the start..)

    I'm still a little shiny new to Photon so is this correct:

    Normally objects would send RPC "updates" to it's network copies.. but can I use OnPhotonPlayerConnected() on the master (or maybe it's owner) to notice this join of a new player and push them a "static state"?

    Is this how you notice a new player has joined you?
  • TreeFortress
    edited November 2016
    Options
    Yes that's correct, OnPhotonPlayerConnected will notify you when a new player has joined, and you can then push over current state for any object in your scene.

    Quick example of an optimized networked switch (psuedocode) that doesn't rely on RPCs:
    public class NetworkedSwitch {
    bool isDirty;
    
    private bool isOn;
    public bool IsOn {
         get {return isOn;}
         set { 
            //Don't set dirty flag if the value hasn't changed.
            if(isOn == value){return;} 
            isOn = value;
            isDirty = true; //Value has been dirtied, it will now be synced.
         }
    }
    
    void OnPhotonSerializeView(stream){
        //Only send data when it has changed, reducing the network traffic.
        if(stream.isWriting && isDirty){
              stream.SendNext(isOn);
        }
        else {   
             IsOn = (bool) stream.ReceiveNext();
        }
    
    }
    
    void OnPhotonPlayerConnected(){
        isDirty = true; //Set dirty flag to true when a user joins, forcing switch to send it's current state. 
    }
    
    }
  • Excellent.. This confirms the way I plan to do that!