コード例 #1
0
    public override void SendInitialState(BSONObject bsonObj, INetObjectViewer viewer)
    {
        base.SendInitialState(bsonObj, viewer);

        // if we have trunk pieces, send those
        if (this.trunkPieces.Count > 0)
        {
            BSONArray trunkInfo = BSONArray.New;
            foreach (var trunkPiece in this.trunkPieces)
            {
                trunkInfo.Add(trunkPiece.ToInitialBson());
            }
            bsonObj["trunks"] = trunkInfo;
        }

        if (this.Controller != null && this.Controller is INetObject)
        {
            bsonObj["controller"] = ((INetObject)this.Controller).ID;
        }

        if (this.stumpHealth <= 0f) // trunk pieces have their own grounders
        {
            bsonObj["noGround"] = true;
        }

        bsonObj["mult"] = this.resourceMultiplier;
    }
コード例 #2
0
    public override void ReceiveUpdate(BSONObject bsonObj)
    {
        bool changed = false;

        if (!bsonObj.ContainsKey("trunks"))
        {
            return;
        }
        BSONArray trunks = bsonObj["trunks"].ArrayValue;

        foreach (BSONObject obj in trunks)
        {
            Guid       id    = obj["id"];
            TrunkPiece piece = this.trunkPieces.FirstOrDefault(p => p.ID == id);

            if (piece != null && (piece.Position != obj["pos"] || piece.Rotation != obj["rot"]))
            {
                piece.Position       = obj["pos"];
                piece.Rotation       = obj["rot"];
                piece.Velocity       = obj["v"];
                piece.LastUpdateTime = TimeUtil.Seconds;
                changed = true;
            }
        }

        if (changed)
        {
            if (this.UpRooted)
            {
                this.Position = this.trunkPieces.First().Position;
            }
            this.lastKeyframeTime = bsonObj["time"];
            this.LastUpdateTime   = TimeUtil.Seconds;
        }
    }
コード例 #3
0
        void Awake()
        {
            // Set up BSON objects before script Start()
            bsonRoot    = new BSONObject();
            bsonGlobals = new BSONObject();

            bsonChildren["load"]     = new BSONArray();
            bsonChildren["play"]     = new BSONArray();
            bsonChildren["move"]     = new BSONArray();
            bsonChildren["volume"]   = new BSONArray();
            bsonChildren["playrate"] = new BSONArray();
            bsonChildren["time"]     = new BSONArray();
        }
コード例 #4
0
        public void WriteArray()
        {
            byte[] data = MiscellaneousUtils.HexToBytes("31-00-00-00-04-42-53-4f-4e-00-26-00-00-00-02-30-00-08-00-00-00-61-77-65-73-6f-6d-65-00-01-31-00-33-33-33-33-33-33-14-40-10-32-00-c2-07-00-00-00-00");

            BSONObject obj = new BSONObject();

            obj ["BSON"] = new BSONArray();
            obj ["BSON"].Add("awesome");
            obj ["BSON"].Add(5.05);
            obj ["BSON"].Add(1986);

            byte[] target = SimpleBSON.Dump(obj);
            Assert.IsTrue(MiscellaneousUtils.ByteArrayCompare(target, data) == 0);
        }
コード例 #5
0
        /// Transforms a position in world space to Bellows polar coordinates
        public BSONArray WorldToBellowsPosition(Vector3 vec)
        {
            // Transform point to be relative to whatever this Sound Master is attached to
            // (usually the camera)
            vec = transform.InverseTransformPoint(vec);

            // X value in bellows is simply polar direction
            float bellowsX = Mathf.Atan2(vec.z, vec.x) / (Mathf.PI * 2);

            // Y value in bellows is just the height
            float bellowsY = vec.y;

            // Z value in bellows is the distance to the sound, ignoring height
            float bellowsZ = Mathf.Sqrt((vec.x * vec.x) + (vec.z * vec.z));

            BSONArray a = new BSONArray();

            a.Add(bellowsX);
            a.Add(bellowsY);
            a.Add(bellowsZ);

            return(a);
        }
コード例 #6
0
    public override void SendUpdate(BSONObject bsonObj, INetObjectViewer viewer)
    {
        base.SendUpdate(bsonObj, viewer);

        if (this.Fallen && this.Controller != viewer)
        {
            BSONArray trunkInfo = BSONArray.New;
            foreach (var trunkPiece in this.trunkPieces)
            {
                if (trunkPiece.Position == Vector3.Zero)
                {
                    continue;
                }
                if (trunkPiece.LastUpdateTime < viewer.LastSentUpdateTime)
                {
                    continue;
                }

                trunkInfo.Add(trunkPiece.ToUpdateBson());
            }
            bsonObj["trunks"] = trunkInfo;
            bsonObj["time"]   = this.lastKeyframeTime;
        }
    }
コード例 #7
0
        static void Main()
        {
            var httpWReq = (HttpWebRequest)WebRequest.Create("http://www.slamby.com/test/json/get/basic.json");
            var response = (HttpWebResponse)httpWReq.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var jsonContent = new StreamReader(stream: response.GetResponseStream()).ReadToEnd();

                #region WithJSON2BSON

                var dbtest = new EJDB("dbb")
                {
                    ThrowExceptionOnFail = true
                };
                dbtest.Save("doctest", dbtest.Json2Bson(jsonContent));
                var queryTest = dbtest.CreateQuery(new
                {
                    sex = "male"
                }, "doctest");
                using (var cursor = queryTest.Find())
                {
                    Console.WriteLine("Found" + cursor.Length + "names");
                }
                #endregion



                var dictionary = JSON.Instance.Parse(jsonContent) as Dictionary <string, object>;
                if (dictionary != null)
                {
                    var dict = new Dictionary <string, object>(dictionary);

                    var db = new EJDB("db")
                    {
                        ThrowExceptionOnFail = true
                    };
                    var bsonDocument = new BSONDocument();
                    foreach (var keyValuePair in dict)
                    {
                        if (keyValuePair.Value.GetType() != dict["dogs"].GetType())
                        {
                            bsonDocument.SetString(keyValuePair.Key, keyValuePair.Value.ToString());
                        }
                        else
                        {
                            if (dict["dogs"] as IEnumerable == null)
                            {
                                continue;
                            }
                            var dogsIndex     = 0;
                            var dogsBsonArray = new BSONArray();
                            foreach (var dog in dict["dogs"] as IEnumerable)
                            {
                                var dogsAttributes = JSON.Instance.Parse(dog as string) as Dictionary <string, string>;
                                if (dogsAttributes != null)
                                {
                                    var dogBsonValue = new BSONDocument();
                                    foreach (var dogAttribute in dogsAttributes)
                                    {
                                        dogBsonValue.SetString(dogAttribute.Key, dogAttribute.Value);
                                    }
                                    dogsBsonArray.SetObject(dogsIndex, dogBsonValue);
                                    dogsIndex++;
                                }
                            }
                            bsonDocument.SetArray("dogs", dogsBsonArray);
                        }
                    }

                    db.Save("doc", bsonDocument);

                    var query = db.CreateQuery(new {
                        sex = "male"
                    }, "doc");

                    /*using (var cursor = query.Find())
                     * {
                     *  Console.WriteLine("Found" + cursor.Length + "names");
                     * }*/

                    Console.ReadKey();
                    query.Dispose();
                    db.Dispose();
                }
            }
        }