2
\$\begingroup\$

In my game, I keep a list of all clients currently connected to the server and a list of all actors in the game. Each actor is "relevant" ( currently replicating ) to 0 or many clients, and each client has has 0 or many actors that are relevant to it.

In some situations, I want to do something like this:

NetworkSystem.AddMulticastRPC( rpcCall, actor.AllRelevantClients );

This would send an RPC to all clients who have this actor as relevant.

Sometimes I need to do things like this:

foreach( var actor in client.RelevantActors )
{
    ...
}

Looping through all relevant actors.

Storing a collection on both the client and actor objects would be a duplication of data. Storing a collection on only one of these leads to some complex searches.

Is there an approach to dealing with data like this that avoids both of those problems?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I didn't understand the second problem, only the duplication part. Can you make it clear, please? \$\endgroup\$
    – MVCDS
    Jul 14, 2015 at 15:36
  • \$\begingroup\$ The space/time tradeoff is inevitable, so there's no way around it unless you tell us more about your use case. For example, what determines if an actor is "relevant" for a client, or vice versa? \$\endgroup\$ Aug 14, 2015 at 7:42

1 Answer 1

-2
\$\begingroup\$

Plese don't consider it as an anwser yet, for good or bad, I just need some place to tell about half of the problem (duplication)

I think you need to choose one of them to be the central point, either actor or client (I don't know how to use RPC to tell you how the API would work).

Suppose you choose that an Actors have many clients

foreach(var client in actor.AllRelevantClients)
{
    actor.doRPC(client);//work out with true RPC inside a function
}

and

forech(var client in actor.AllRelevantClients)
{
    actor.foo(client);//or client.foo(actor);
}

Invert the types to invert which class is the central point.

What is being referenced could only points to the central point when added

class Actor
{    
    List<Client> _clients = new List<Client>;
    public void Add(Client client)
    {
        _clients.add(client);
        _clients.actor = this;
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .