Question about needed data for schema

38 views
Skip to first unread message

MostHated

unread,
Apr 14, 2018, 10:57:31 AM4/14/18
to FlatBuffers
Hey there,
    I just found out about flatbuffers the other day and was hoping someone might be able to lend a hand. I am currently building a networked game in Unity that is primarily controlled via network messages and I am wanting to see if I can use these in my game. The question I have is, as the first test and to learn I wanted to try and send something simple.  Essentially what I need to send over the network is as follows. The method gets passed in those two items and they are what I need to send.

 public void SendOperation(ClientOperationCode operationCode, Dictionary<byte, object> parameters)
       
{
           
(Need to send the network message here)
       
}

    Where my question comes in is, am I able to send them (operationCode, parameters) separately, or do I need to combine them first into a single object? The second question is, I was looking at the schema and the example has it set up like an entire class with namespace and everything. If I only want to send over those two items (there are other methods that will send, and also responses coming back, etc, I just wanted to try this to get started) does it still require all of the items in the example, or is that only if you want to send all of the stuff in that schema? I could not find many more examples, especially not directly related to sending a simple network message. If anyone has any information or links to where I can see some more examples I would really appreciate it!

Thanks!

MostHated

unread,
Apr 14, 2018, 11:23:25 AM4/14/18
to FlatBuffers
If it helps any, here is the code that is being sent to that up there. Technically it could be changed, but there are hundreds (one for every action) that would need to be changed. The dictionary can be anywhere from a single entry with just a GameOperationCode, up to 3-4 total entries. I am not sure if that would change how it needs to be written?



public static void CastSpell(short spellId, MmoGuid? targetGuid)
{
var parameters = new Dictionary<byte, object>
{
{1, (byte) GameOperationCode.CastSpell},
{(byte) ParameterCode.SpellId, spellId},
};

if (targetGuid != null)
parameters.Add((byte) ParameterCode.ObjectId, (long) targetGuid.Value);

_engine.SendOperation(ClientOperationCode.World, parameters);
}

Wouter van Oortmerssen

unread,
Apr 16, 2018, 12:59:36 PM4/16/18
to m374...@gmail.com, FlatBuffers
First thing is to define a schema that can represent your data. So far, you handling your messages very generically, by sticking all of it in a Dictionary. But both FlatBuffers and C# are statically typed systems, so your code would be a whole lot more readable and efficient if you used something more specific.

For example, a schema could look something like:

table CastSpell { spell_id:short; target_guid:ulong }
union Action { CastSpell, SomeOtherActionEtc.. }
enum Operation { .. }
table Message { operation_code:Operation; action:Action; }

Here the union takes the place of your dictionary. It may well be that Operation is redundant, but I can't tell from your code.

Have a look at the C# tutorial in the FlatBuffer docs to see how you typically read and write such data structures.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages