Complex "input"

Hello,
I am trying to implement TrueSync into my (already lockstep ready) RTS.
To sync the useractions, I transmit them as classes (not the keys or mousemovement itself). For example I transmit the action "Place Building" with the location, orientation, buildingtype etc as content of it. In the next lockstep interation every client will validate and perform this action.

How would this be possible with TrueSync? I thought of adding a new "public static void SetByte(byte key, ActionClass value);" to TrueSyncInput, but it is a dll.

Comments

  • I did a workaround to test TrueSync more: I serialized the list of action-classes as xml-strings and put them into TrueSyncInput. Works fine, but its super stupid in the long run.
    Is it possible to get a "public static void SetObject(byte key, object value);"?
  • kristian
    kristian
    edited December 2016
    Ok, due to lack of response and try-hard attitude, I modified the TrueSync.dll.
    I added a the abstract class "LSAction", the class "SerializableDictionaryByteLSAction : SerializableDictionary", made get/set/hasLSAction functions in "TrueSyncInput" and "InputData" to support my class.

    After that I modified the class "SyncedData" to convert the LSAction object into a bytearray and back like:
    
    public List<byte> GetEncodedActions()
    [..]
    foreach (KeyValuePair<byte, LSAction> current6 in this.inputData.actionTable)
    			{
    				list.Add(current6.Key);
    				list.Add(5);
    				BinaryFormatter formatter = new BinaryFormatter();
    				byte[] bytes;
    				using (MemoryStream stream = new MemoryStream())
    				{
    					formatter.Serialize(stream, current6.Value);
    					byte[] data = stream.ToArray();
    					byte[] res = new byte[data.Length + 4];
    					Array.Copy(data, 0, res, 4, data.Length);
    					bytes = res;
    				}
    				list.AddRange(bytes);
    			}
    and
    
    
    public static SyncedData[] Decode(byte[] data)
    [..]
    case 5:
    					{
    						int valueLength = BitConverter.ToInt32(data, i);
    						i += 4;
    						byte[] bb = new byte[valueLength];
    						Array.Copy(data, i, bb, 0, valueLength);							
    						i += valueLength;
    						BinaryFormatter bf = new BinaryFormatter();
    						using (MemoryStream ms = new MemoryStream(bb))
    						{
    							LSAction aa = (LSAction)bf.Deserialize(ms);
    							syncedData.inputData.AddAction(key, aa);
    						}
    						break;
    					}
    But it does not work. What did I miss?

    (yes, using BinaryFormatter in that class is not good coding, but the easiest approach)

    Edit: Just to be sure I added a all that above again for byte[] instead of LSAction, still not working. What am I missing?
  • Ha, nevermind, I fucked it up and didnt added the new classes to TrueSyncInput in OnSyncedInput(), but just at a Button_OnClick().

    With a little edits it is a very very nice framework to use! Good work (better make it open source, though ;-))
  • Hello @kristian, sorry for the long response I was unable to check the forum before. As you noticed the TrueSyncInput it was proposed for simple types, but your need it is a good feature to be added in next releases.

    For now one idea you could use is try to split your class data into small pieces and use the TrueSyncInput for each one then you can rebuild the object in the OnSyncedUpdate method.
  • Kristian,

    I think sending the complex input might not be the easiest solution. Why not sending click positions or key presses as input, and building the complex action objects in every client?
  • kristian
    kristian
    edited December 2016
    @JeffersonHenrique I modified the TrueSync.dll and added my own type, it works like a charm! I added the class Action into the dll, and in my game I derive subclasses with the actual information/action. the de-/serialization is also done by the TrueSync.dll.

    @erickpassos Imho sending click positions or key presses is a bad idea, because not every click is important for everyone (like dismissing messages or moving the camera). I only message the important stuff like move units or place building. How its done (by mouse, by hotkey, by routine etc) is not interesting for others, only important is that it happens simultaneously. (not forgetting i cant cross-game then with android and pc or smth)
  • Hi @kristian

    You might actually be right. The best option is always the one that fits your development taste better.

    Here's what I suggest @JeffersonHenrique:

    - We chose a suitable Serialisable interface and offer a TrueSyncInput.SetObject(byte key, SerialisableInterface object) method for our queue;
    - The serialise/deserialise method should work as a get/set for a byte[] (this is what we use internally for the queue/remote send - and we'll use to add compression, etc);

    This way, any complex object can be sent/received as input, as long as the developer provide the pair of getter/setter methods for the byte[].
  • It can be very useful for new adopters of TrueSync, it will be included in our roadmap as a new feature.
  • Gekigengar
    edited July 2017

    It can be very useful for new adopters of TrueSync, it will be included in our roadmap as a new feature.

    Hello, Is the roadmap not publicly available?

    And when is the next update? I felt like TrueSync is very abandoned in comparison to other Photon products.

    I have been waiting for a feature like this for RTS, since it is the main purpose of Lockstep framework.
  • This would be great for adding 'Commands' - for things like cheats during testing.
  • Hi @Gekigengar and @Xelnath, we don't have a public roadmap and you haven't seen updates because we are working on new approach for TrueSync's core, it will be managed by an internal plugin to better handle lag, player drops and inputs. The mentioned feature is already implemented in the current repo, some early adopters are using it in alpha releases. We may start to release this TrueSync "2" later this month or next one.
  • > @JeffersonHenrique said:
    > Hi @Gekigengar and @Xelnath, we don't have a public roadmap and you haven't seen updates because we are working on new approach for TrueSync's core, it will be managed by an internal plugin to better handle lag, player drops and inputs. The mentioned feature is already implemented in the current repo, some early adopters are using it in alpha releases. We may start to release this TrueSync "2" later this month or next one.

    Or the next next one ;P
    I've been waiting since then.

    Any news?
  • Hi @Gekigengar, yep haha, we missed that launch, but it for a good reason. We want to release the plugin to better handle lag, player drops and so on, but we didn't feel a good tunning yet, we don't want to release until we see a really good improvement. Sorry for this, but it is all for the best :)