Player property not visibly to MasterClient

Hi, I'm adding 2D tile swapping to a game and need some help.

Here's a scenario to best explain my approach: When a client performs a digging action it calls an RPC function with the MasterClient as its target.
The MasterClient then calls an RPC function with all the connected clients who have the area where tile is located loaded, as its target. In that function the tile becomes swapped and all is right with the world.

The issue I'm facing, and I feel it's a small one, is; the player component that that loads chunks doesn't appear to load them from the MasterClient's point of view. I'm not sure what to do.

This is the code for it.
foreach (Rectangle unloadedChunk in World.instance.UnloadedChunks)
{
if (chunkLoader.rectangle.Overlaps( unloadedChunk.rectangle, true))
{
if (photonView.isMine)
{
if (EnteredChunk != null)
{ // x0, y1 example
LoadedChunks.Add(new Point(unloadedChunk.x
, unloadedChunk.y
));
EnteredChunk(unloadedChunk.x
, unloadedChunk.y
, ClientData.instance.m_playerName
);
break;
}
}
else
{
// do stuff for people that aren't me?
}
}
}

Answers

  • Hi @VenetianBears,

    The issue I'm facing, and I feel it's a small one, is; the player component that that loads chunks doesn't appear to load them from the MasterClient's point of view.


    I'm not sure if I got the problem correctly, so please let me know if I'm right: this is a synchronization problem, isn't it?

    With the information from the other thread you opened, I'm basically not sure, if using RPCs is the best option for this scenario, so I would like to share another approach with you. Since you already have separated the world into multiple chunks, you could add some kind of a ChunkManager to each of them. The manager's task is to receive custom events (happens on all clients) and update the chunk's state accordingly. To use custom events, the client can use the RaiseEvent function with a certain Event Code. This calls also includes the unique ID of the chunk (in order to identify), the tile (either ID or position data) and maybe what happens to it (if this is not clear by using a special Event Code). Having sent this custom event, it is received on all clients and each client can update the world accordingly.
  • That's a very good idea and has given me a lot to think about. I hadn't heard of custom events until now.

    I got my method working but am shamed to say I didn't really learn anything by doing it. I couldn't figure out how to serialize loaded chunks, which are really just a list of points, made up of 2 integers,

    I tried serializing them like
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    stream.SendNext(LoadedChunks.Count);

    //a point is a class object with 2 public integers x and y
    foreach (Point item in LoadedChunks)
    {
    stream.SendNext(item.x);
    stream.SendNext(item.y);
    }
    }
    else
    {
    int count = (int)stream.ReceiveNext();

    LoadedChunks.Clear();

    for (int i = 0; i < count; i++)
    {
    int x = (int)stream.ReceiveNext();
    int y = (int)stream.ReceiveNext();

    LoadedChunks.Add(new Point(x, y));
    }
    }
    }