Sign in to follow this  
Nam Ho

What's the solution for client and server for game tower defense multiplayer like Clash of Royal?

Recommended Posts

I'm coding the game tower defense multiplayer. I try to bring all logic game to server sign and a client just play follow the data, but performance not good. I use smartfox for server sign and Unity for client sign. Please help me solve this problem. Logic game should put at client or server and how does it? P/s:sorry about my English skill. I know it's very bad.

Share this post


Link to post
Share on other sites
I haven't played that particular game, but there are many games that are "multiplayer tower defense" that work along this way:

- User builds resources slowly by a time-waiting mecahnic
- User can spend resources on either producing more resources, or defensive structures, or offensive units
- At some point the user will "send" offensive units against another user's "base"
- The attacking user cannot direct their units after sending them; they can just watch the outcome
- The defending user may be able to direct defense while the attacking units are attacking, as long as the defending user does it within a certain amount of time of the attack

To implement this, there really are two main game loops:
- The slow, time-waiting growing-and-spending loop
- The being-attacked, direct-the-defenses loop

For the growing loop, it's best to build the game to determine "the time at which this will finish," rather than "how many seconds are left before this finishes."
The reason for this is that it's very easy for the server to verify a command with no additional state calculations when the command is "harvest the resource X from point Y" -- if the command comes in after time T, it's allowed, else not. No server-side simulation is needed other than executing user commands.

For the defending loop, you will need to play this out on the client, preferably using deterministic simulation (like an RTS would.) Save all commands that the player issued, and the exactly tick counts at which the player issued them.
Then, bundle up all the attacker info, the base state info at time of attack, and the player commands, as well as the player-calculated outcome of the defense, and send that to the server. The server should then be able to run the same simulation without any rendering at a very fast pace, to verify that the outcome is the same as that reported by the client.
Optimizing what the "attack simulation engine" really does will now be your main goal. Perhaps you only really run ticks 10 times per second. Perhaps all units really only move on a 2D graph. Perhaps the physical simulation is only used on the client to make things look good, but the "important to gameplay" positions used for detecting hit/miss etc are all based on the 2D simulation.

Finally, you say that "performance is not good." It's hard to tell for us what that means.
If there is a specific measurement you are unhappy with (system load, user ping time, amount of RAM consumed per active player, ...) then posting more specific details will make it more possible for us to help.
However, if you follow all the steps above, you should be in very good shape and maybe don't need more help than that :-)

Share this post


Link to post
Share on other sites

I haven't played that particular game, but there are many games that are "multiplayer tower defense" that work along this way:

- User builds resources slowly by a time-waiting mecahnic
- User can spend resources on either producing more resources, or defensive structures, or offensive units
- At some point the user will "send" offensive units against another user's "base"
- The attacking user cannot direct their units after sending them; they can just watch the outcome
- The defending user may be able to direct defense while the attacking units are attacking, as long as the defending user does it within a certain amount of time of the attack

To implement this, there really are two main game loops:
- The slow, time-waiting growing-and-spending loop
- The being-attacked, direct-the-defenses loop

For the growing loop, it's best to build the game to determine "the time at which this will finish," rather than "how many seconds are left before this finishes."
The reason for this is that it's very easy for the server to verify a command with no additional state calculations when the command is "harvest the resource X from point Y" -- if the command comes in after time T, it's allowed, else not. No server-side simulation is needed other than executing user commands.

For the defending loop, you will need to play this out on the client, preferably using deterministic simulation (like an RTS would.) Save all commands that the player issued, and the exactly tick counts at which the player issued them.
Then, bundle up all the attacker info, the base state info at time of attack, and the player commands, as well as the player-calculated outcome of the defense, and send that to the server. The server should then be able to run the same simulation without any rendering at a very fast pace, to verify that the outcome is the same as that reported by the client.
Optimizing what the "attack simulation engine" really does will now be your main goal. Perhaps you only really run ticks 10 times per second. Perhaps all units really only move on a 2D graph. Perhaps the physical simulation is only used on the client to make things look good, but the "important to gameplay" positions used for detecting hit/miss etc are all based on the 2D simulation.

Finally, you say that "performance is not good." It's hard to tell for us what that means.
If there is a specific measurement you are unhappy with (system load, user ping time, amount of RAM consumed per active player, ...) then posting more specific details will make it more possible for us to help.
However, if you follow all the steps above, you should be in very good shape and maybe don't need more help than that :-)

Thanks for your help!

I try to simulate everything on the server to find the time attack, resume moving, dead...but it needs a long time(maybe need 1s to simulate 5s in the match). The client doesn't calculate any things and just do follow the action from the server. Ex, when the server says creep A attack creep B at 2,5s, the client counts to 2.5s and render creep A attack creep B. And now, I know server just simulate to check when client executing commands. But I don't know I must do what. Can you tell me detail about "attack simulation engine"? Objects include tower, creep, hero. Creeps will auto spawn like League of Legends. The user will spawn hero and active skills of hero.
P/s: my skype id: nam.hd

Share this post


Link to post
Share on other sites

I try to simulate everything on the server to find the time attack, resume moving, dead...but it needs a long time(maybe need 1s to simulate 5s in the match)


Then you need to figure out what is taking so long.
If, for example, you use the Unity physics engine for your base simulation (not just display) that would be one potential source.
Try applying a profiler to see where the time is going.

Share this post


Link to post
Share on other sites

In figuring out where the time is happening, divide the problem up and see where it lies.

 

Is the server taking too long to respond, or is the server responding quickly?

If the server is taking too long, is it accepting the response quickly, spending too much time processing the data, or taking to long sending the response?

If the server is responding quickly, is the client accepting the message on time? Is the client spending time processing the data, or displaying the data, or doing other work?

 

Once you know if the problem is on the client or the server, you can use a profiler to measure the timings and figure out what is taking longer than expected. If you expect something to respond in microseconds or nanoseconds but it responds in milliseconds, that would be the place to investigate.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this