public void DebugReturn(DebugLevel level, string message)
{
if (this.listener.IsDebugLogEnabled)
{
this.listener.LogDebug(this, string.Concat(this.avatar.Id, ": ", debug));
}
}
public void EventAction(byte eventCode, Hashtable photonEvent)
{
stateStrategy.OnEventReceive(this, (EventCode)eventCode, photonEvent);
}
public void OperationResult(byte operationCode, int returnCode, Hashtable returnValues, short invocId)
{
try
{
stateStrategy.OnOperationReturn(this, (OperationCode)operationCode, returnCode, returnValues);
}
catch (Exception e)
{
listener.LogError(this, e);
}
}
public void PeerStatusCallback(StatusCode statusCode)
{
try
{
stateStrategy.OnPeerStatusCallback(this, returnCode);
}
catch (Exception e)
{
listener.LogError(this, e);
}
}
public void Update()
{
stateStrategy.OnUpdate(this);
}
public void SendOp(OperationCode operationCode, Hashtable parameter, bool sendReliable, byte channelId)
{
stateStrategy.SendOperation(this, operationCode, parameter, sendReliable, channelId);
}
As you can see, each place we normally would have done something because we received a message through the peer, we now pass on to the state. The state will then determine if we need to process the message and if so, how.
Now to create our Disconnect state. It is a very simple state, it does nothing when asked to send an operation or to update. The other functions all call the error logs we created earlier.
using AegisBornCommon;
public class Disconnected : IGameState
{
public static readonly IGameState Instance = new Disconnected();
public GameState State
{
get { return GameState.Disconnected; }
}
public void OnEventReceive(Game gameLogic, AegisBornCommon.EventCode eventCode, System.Collections.Hashtable eventData)
{
gameLogic.OnUnexpectedEventReceive(eventCode, eventData);
}
public void OnOperationReturn(Game gameLogic, AegisBornCommon.OperationCode operationCode, int returnCode, System.Collections.Hashtable returnValues)
{
gameLogic.OnUnexpectedPhotonReturn(returnCode, operationCode, returnValues);
}
public void OnPeerStatusCallback(Game gameLogic, ExitGames.Client.Photon.StatusCode returnCode)
{
gameLogic.OnUnexpectedPhotonReturn((int)returnCode, OperationCode.Nil, null);
}
public void OnUpdate(Game gameLogic)
{
// Do nothing on updates because we are disconnected.
}
public void SendOperation(Game gameLogic, AegisBornCommon.OperationCode operationCode, System.Collections.Hashtable parameter, bool sendReliable, byte channelId)
{
// Do not send operations because we are disconnected.
}
}
So now we have our disconnected state and we are almost back to where we were. It feels like a ton of work just to be right back where we started, but this is a very good setup. The time we take setting up this project the first time, means less time will be spent when we need to add new states or messages.
Next up we will get WaitingForConnect and CharacterSelect states up and running!
No comments:
Post a Comment