public void Serialization()
        {
            ProgramDefinition pd = new ProgramDefinition();

            pd.Commands = new Dictionary <string, CommandDefinition>();
            pd.Commands.Add("stepname", new CommandDefinition()
            {
                Action = "xxd",
                Args   = new Dictionary <string, object>()
                {
                    { "sss", 22 }
                }
            });;


            pd.State = new Dictionary <string, object>()
            {
                { "key", "value" }
            };

            var dese = new YamlDotNet.Serialization.Serializer();
            var sttr = dese.Serialize(pd);

            Assert.NotNull(sttr);
        }
Beispiel #2
0
        private unsafe Boolean ParseGlobalPair(ProgramDefinition key, String value)
        {
            Int32 offset;

            if (IsGlobalStruct(key.ofs, out offset))
            {
                return(ParsePair(( Single * )_GlobalStructAddr + offset, key, value));
            }
            return(ParsePair(( Single * )_GlobalsAddr + offset, key, value));
        }
Beispiel #3
0
        /// <summary>
        /// ED_ParseEpair
        /// Can parse either fields or globals returns false if error
        /// Uze: Warning! value pointer is already with correct offset (value = base + key.ofs)!
        /// </summary>
        private unsafe Boolean ParsePair(void *value, ProgramDefinition key, String s)
        {
            var d = value;// (void *)((int *)base + key->ofs);

            switch (( EdictType )(key.type & ~ProgramDef.DEF_SAVEGLOBAL))
            {
            case EdictType.ev_string:
                *( Int32 * )d = NewString(s);      // - pr_strings;
                break;

            case EdictType.ev_float:
                *( Single * )d = MathLib.atof(s);
                break;

            case EdictType.ev_vector:
                var vs = s.Split(' ');
                (( Single * )d)[0] = MathLib.atof(vs[0]);
                (( Single * )d)[1] = (vs.Length > 1 ? MathLib.atof(vs[1]) : 0);
                (( Single * )d)[2] = (vs.Length > 2 ? MathLib.atof(vs[2]) : 0);
                break;

            case EdictType.ev_entity:
                *( Int32 * )d = Host.Server.EdictToProg(Host.Server.EdictNum(MathLib.atoi(s)));
                break;

            case EdictType.ev_field:
                var f = IndexOfField(s);
                if (f == -1)
                {
                    Host.Console.Print("Can't find field {0}\n", s);
                    return(false);
                }
                *( Int32 * )d = GetInt32(_FieldDefs[f].ofs);
                break;

            case EdictType.ev_function:
                var func = IndexOfFunction(s);
                if (func == -1)
                {
                    Host.Console.Print("Can't find function {0}\n", s);
                    return(false);
                }
                *( Int32 * )d = func;    // - pr_functions;
                break;

            default:
                break;
            }
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Since memory block containing original edict_t plus additional data
        /// is split into two fiels - edict_t.v and edict_t.fields we must check key.ofs
        /// to choose between thistwo parts.
        /// Warning: Key offset is in integers not bytes!
        /// </summary>
        private unsafe Boolean ParsePair(MemoryEdict ent, ProgramDefinition key, String s)
        {
            Int32 offset1;

            if (ent.IsV(key.ofs, out offset1))
            {
                fixed(EntVars *ptr = &ent.v)
                {
                    return(ParsePair(( Int32 * )ptr + offset1, key, s));
                }
            }
            else
                fixed(Single *ptr = ent.fields)
                {
                    return(ParsePair(ptr + offset1, key, s));
                }
        }
Beispiel #5
0
        private ProgramDefinition CachedSearch(MemoryEdict ed, String field)
        {
            ProgramDefinition def = null;

            for (var i = 0; i < GEFV_CACHESIZE; i++)
            {
                if (field == _gefvCache[i].field)
                {
                    def = _gefvCache[i].pcache;
                    return(def);
                }
            }

            def = FindField(field);

            _gefvCache[_gefvPos].pcache = def;
            _gefvCache[_gefvPos].field  = field;
            _gefvPos ^= 1;

            return(def);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // we need to connect to cloud
            // the cloud shall act as a router

            const int AtAdministration = 800;
            const int AtIdentityIndex  = 1000;
            const int AtJoin           = 1001;



            // if the router is not up we ought to create one

            var port = 33333;

            var RouterClients = new
            {
                Index  = default(int),
                Reader = default(BinaryReader),
                Writer = default(BinaryWriter),

                AtIdentityIndex = default(Action <int>),
                AtJoin          = default(Action <int>),

                AtUserInput = default(Action <int, int>),
                AtMove      = default(Action <int, int, int>),
            }.ToListFromType();

            RouterClients.Add(null);

            port.ToListener(
                s =>
            {
                //Console.WriteLine("router: client connected to router");

                var Writer = new BinaryWriter(s);



                var RouterClient = new
                {
                    Index  = RouterClients.Count,
                    Reader = new BinaryReader(s),
                    Writer = Writer,

                    AtIdentityIndex =
                        Writer.AsBuilder()
                        .Int32(AtAdministration)
                        .Int32(AtIdentityIndex)
                        .Int32()
                        .ToAction(),

                    AtJoin =
                        Writer.AsBuilder()
                        .Int32(AtAdministration)
                        .Int32(AtJoin)
                        .Int32()
                        .ToAction(),

                    AtUserInput =
                        Writer.AsBuilder()
                        .Int32(ProgramDefinition.TokenAtUserInput)
                        .Int32()
                        .Int32()
                        .ToAction(),


                    AtMove =
                        Writer.AsBuilder()
                        .Int32(ProgramDefinition.TokenAtMove)
                        .Int32()
                        .Int32()
                        .Int32()
                        .ToAction()
                };

                var Others = RouterClients.Except(new[] { RouterClient, null });

                // 0 means server to client communication

                RouterClient.AtIdentityIndex(RouterClient.Index);

                lock (RouterClient)
                {
                    RouterClients.Add(RouterClient);

                    foreach (var other in Others)
                    {
                        other.AtJoin(RouterClient.Index);
                        RouterClient.AtJoin(other.Index);
                    }
                }

                while (true)
                {
                    var Token = RouterClient.Reader.ReadInt32();

                    Thread.Sleep(500);

                    #region AtUserInput
                    if (Token == ProgramDefinition.TokenAtUserInput)
                    {
                        var Parameter = RouterClient.Reader.ReadInt32();

                        foreach (var other in Others)
                        {
                            other.AtUserInput(RouterClient.Index, Parameter);
                        }
                    }
                    #endregion
                    #region AtMove
                    else if (Token == ProgramDefinition.TokenAtMove)
                    {
                        var Parameter_x = RouterClient.Reader.ReadInt32();
                        var Parameter_y = RouterClient.Reader.ReadInt32();

                        foreach (var other in Others)
                        {
                            other.AtMove(RouterClient.Index, Parameter_x, Parameter_y);
                        }
                    }
                    #endregion
                    else
                    {
                        Console.WriteLine("router: unknown token: " + Token);
                    }
                }
            }
                );

            var c = new TcpClient();

            c.Connect(IPAddress.Loopback, port);


            var a = new ProgramDefinition
            {
                Identity = new ProgramDefinition.EndPointIdentity()
            };

            Console.Title = "frame 1";

            {
                var Reader = new BinaryReader(c.GetStream());
                var Writer = new BinaryWriter(c.GetStream());

                #region AtUserInput
                var AtUserInput = a.AtUserInput;

                a.AtUserInput =
                    (sender, data) =>
                {
                    Writer.Write((int)ProgramDefinition.TokenAtUserInput);
                    Writer.Write((int)data);

                    AtUserInput(sender, data);
                };
                #endregion

                #region AtMove
                var AtMove = a.AtMove;

                a.AtMove =
                    (sender, x, y) =>
                {
                    Writer.Write((int)ProgramDefinition.TokenAtMove);
                    Writer.Write((int)x);
                    Writer.Write((int)y);

                    AtMove(sender, x, y);
                };
                #endregion

                var Peers = new List <ProgramDefinition.EndPointIdentity>();

                0.AtDelay(
                    delegate
                {
                    while (c.Connected)
                    {
                        var Token = Reader.ReadInt32();

                        if (Token == AtAdministration)
                        {
                            var Operation = Reader.ReadInt32();

                            #region AtIdentityIndex
                            if (Operation == AtIdentityIndex)
                            {
                                var Parameter = Reader.ReadInt32();

                                a.Identity.Index = Parameter;

                                Console.WriteLine("identity " + Parameter);
                            }
                            #endregion
                            #region AtJoin
                            else if (Operation == AtJoin)
                            {
                                var Parameter = Reader.ReadInt32();

                                Console.WriteLine("join " + Parameter);

                                Peers.Add(new ProgramDefinition.EndPointIdentity {
                                    Index = Parameter
                                });
                            }
                            #endregion
                        }
                        #region AtUserInput
                        else if (Token == ProgramDefinition.TokenAtUserInput)
                        {
                            var sender = Reader.ReadInt32();
                            var data   = Reader.ReadInt32();


                            AtUserInput(Peers.Single(k => k.Index == sender), (char)data);
                        }
                        #endregion
                        #region AtUserInput
                        else if (Token == ProgramDefinition.TokenAtMove)
                        {
                            var sender = Reader.ReadInt32();
                            var x      = Reader.ReadInt32();
                            var y      = Reader.ReadInt32();


                            AtMove(Peers.Single(k => k.Index == sender), x, y);
                        }
                        #endregion
                        else
                        {
                            // some user token
                            Console.WriteLine("client: unknown token: " + Token);
                        }
                    }
                }
                    );

                1000.AtInterval(
                    delegate
                {
                    a.Identity.Frame++;
                    Console.Title = "frame " + a.Identity.Frame;
                }
                    );
            }

            a.GatherUserInput();

            c.Close();
        }