Dealing with datablocks for multiplayer game
by Marc-Andre Vachon · in Torque 3D Professional · 11/24/2014 (4:06 pm) · 4 replies
First, I have already read the most I could find about using Datablocks in a multiplyer setup but maybe my limited english made me missed important parts of the concept. Each time I enhance my game and work into getting back to multiplayer testing I'm having issues with my datablocks transmission system so maybe someone could clarify some parts I'm missing...
I will simply start by listing some basics questions that make me concerned about using the datablocks well.
1- For local only datablocks I use the prefix "new" instead of datablock. That mean that the game won't transmit those to clients, right?
2- For datablocks used during the game, should they all be sent by the server with the transmitDatablock function? Including the sounds and particles even is only used client-side?
3- Should I reload the datablocks on the server between mission? And deleteDatablocks on client before loading new mission?
4- DeleteDatablocks on client will delete all the datablocks on the client (only those with new prefix will be kept)?
Well, it's resuming my basic concern, if someone could reply with simply a yes or no to those questions it would clarify the missing links I have... Then I might ask to confirm a datablock transmission plans for my game. Thanks to anyone willing to help me a little. Also if you got some good links explaining a good use of datablocks in a multiplayer game, I'd like to have a look at it.
I will simply start by listing some basics questions that make me concerned about using the datablocks well.
1- For local only datablocks I use the prefix "new" instead of datablock. That mean that the game won't transmit those to clients, right?
2- For datablocks used during the game, should they all be sent by the server with the transmitDatablock function? Including the sounds and particles even is only used client-side?
3- Should I reload the datablocks on the server between mission? And deleteDatablocks on client before loading new mission?
4- DeleteDatablocks on client will delete all the datablocks on the client (only those with new prefix will be kept)?
Well, it's resuming my basic concern, if someone could reply with simply a yes or no to those questions it would clarify the missing links I have... Then I might ask to confirm a datablock transmission plans for my game. Thanks to anyone willing to help me a little. Also if you got some good links explaining a good use of datablocks in a multiplayer game, I'd like to have a look at it.
About the author
Silent Torque developper since 2007 (T3D/TGEA) that is trying to start his little independant studio called Nordik Lab. --"Simple is Better"--
#2
1- I'm not sure if I understand it, as I see it, all datablock should be singleton? Can you provide a basic example of what kind of datablock should be singleton on a multiplayer setup?
2- Yeah, it what I was thinking. But wasn't sure if I should load the game sounds and particles server-side. I guess it would be better to do so to avoid some kind of "hacking".
3- Just to make sure I get it right, the code will delete the transmitted datablocks on clients when to missions is ended? And I shouldn't have to reload the datablocks on the server.
4- Ok, so deleteDatablocks should be use after a client leave a server and then , in my case, I reload the single player datablocks.
So thanks, it made thing clearer for me. I'm still not sure about the singleton part but I can do a specific search about it, I'm sure there's a good explanation somewhere on forums.
11/24/2014 (6:47 pm)
Thanks for your reply. As usual the major cause of my multiplayer issue was a changes I forgot to apply on the Multiplayer script... But I still want to understand better how to deal with datablocks.1- I'm not sure if I understand it, as I see it, all datablock should be singleton? Can you provide a basic example of what kind of datablock should be singleton on a multiplayer setup?
2- Yeah, it what I was thinking. But wasn't sure if I should load the game sounds and particles server-side. I guess it would be better to do so to avoid some kind of "hacking".
3- Just to make sure I get it right, the code will delete the transmitted datablocks on clients when to missions is ended? And I shouldn't have to reload the datablocks on the server.
4- Ok, so deleteDatablocks should be use after a client leave a server and then , in my case, I reload the single player datablocks.
So thanks, it made thing clearer for me. I'm still not sure about the singleton part but I can do a specific search about it, I'm sure there's a good explanation somewhere on forums.
#3
These two operator keywords do exactly the same thing which is before actually instantiating the object check to see if said object already exists, if so skip object instantiation and continue onward in order to avoid console errors about object name collisions. Again useful for cases when you know some TorqueScripts that declare datablocks and other objects is going to be executed multiple times in the game engine's lifetime.
The datablock operator keyword has also been used as a visual aid in source code so that when you're reading the line that creates the object that you're looking at you'll know it's a datablock being created if you're not paying close attention to the "Data" postfix naming convention of most datablock class names.
Later on the singleton operator keyword was created that performs the exact same operation that datablock keyword does, however it is aptly named to what it actually does this time. In this case you see this used on objects being created that aren't generally datablocks, but you can still use this on datablocks because it doesn't matter. The result is still the same.
11/25/2014 (9:13 am)
To clear things up. The new operator instantiates an object (creates and initializes it). The alternative keywords (that replace new in their usage) are datablock and singleton.These two operator keywords do exactly the same thing which is before actually instantiating the object check to see if said object already exists, if so skip object instantiation and continue onward in order to avoid console errors about object name collisions. Again useful for cases when you know some TorqueScripts that declare datablocks and other objects is going to be executed multiple times in the game engine's lifetime.
The datablock operator keyword has also been used as a visual aid in source code so that when you're reading the line that creates the object that you're looking at you'll know it's a datablock being created if you're not paying close attention to the "Data" postfix naming convention of most datablock class names.
Later on the singleton operator keyword was created that performs the exact same operation that datablock keyword does, however it is aptly named to what it actually does this time. In this case you see this used on objects being created that aren't generally datablocks, but you can still use this on datablocks because it doesn't matter. The result is still the same.
#4
To sum it up, datablock is a regular networked datablock, singleton is a non-networked datablock and is synonymous with using the new keyword on a datablock.
Edit: bonus info, you can do
But not:
12/02/2014 (5:26 am)
Here's the truth, uncovered by unicorns and a simple search on the GG site:Quote:For this it is best to use non-networked datablocks (singleton or new) instead of networked datablocks as otherwise it can be pretty tricky to sync the material definitions with where the datablocks are actually valid. Materials are first and foremost relevant to the client so this is a natural setup.Sauce
To sum it up, datablock is a regular networked datablock, singleton is a non-networked datablock and is synonymous with using the new keyword on a datablock.
Edit: bonus info, you can do
singleton StaticShape(singletonCoin) {
dataBlock = Coin;
position = "0 0 0";
};But not:
datablock StaticShape(singletonCoin) {
dataBlock = Coin;
position = "0 0 0";
};
Torque Owner Nathan Martin
TRON 2001 Network