Beispiel #1
0
        public void ReadData(byte[] msg)
        {
            using (var reader = new BinaryReader(new MemoryStream(msg)))
            {
                var packetId   = reader.ReadInt16();
                var headerType = (HeaderType)(packetId / 10000);
                switch (headerType)
                {
                case HeaderType.Entity:
                {
                    var worldId    = reader.ReadByte();
                    var guid       = reader.ReadInt16();
                    var dataType   = NetworkMethodCache.GetSendable(reader.ReadNullTerminatedString());
                    var dataTarget = Activator.CreateInstance(dataType);
                    var entity     = WorldManager.GetWorld(worldId).GetEntity(guid);
                    //TypeHelper.ReadProperties(reader, dataTarget);
                    var methods = NetworkMethodCache.GetEntity(packetId);
                    foreach (var method in methods)
                    {
                        method(entity, dataTarget);
                    }
                }
                break;

                case HeaderType.World:
                {
                    var worldId    = reader.ReadByte();
                    var dataType   = NetworkMethodCache.GetSendable(reader.ReadNullTerminatedString());
                    var dataTarget = Activator.CreateInstance(dataType);
                    var world      = WorldManager.GetWorld(worldId);
                    //TypeHelper.ReadProperties(reader, dataTarget);
                    var methods = NetworkMethodCache.GetWorld(packetId);
                    foreach (var method in methods)
                    {
                        method(world, dataTarget);
                    }
                }
                break;

                case HeaderType.Custom:
                {
                    var dataType   = NetworkMethodCache.GetSendable(reader.ReadNullTerminatedString());
                    var dataTarget = Activator.CreateInstance(dataType);
                    //TypeHelper.ReadProperties(reader, dataTarget);
                    var methods = NetworkMethodCache.GetCustom(packetId);
                    foreach (var method in methods)
                    {
                        method(dataTarget);
                    }
                }
                break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     LoadContent will be called once per game and is the place to load
        ///     all of your content.
        /// </summary>
        protected sealed override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (!Directory.Exists("cfg"))
            {
                Directory.CreateDirectory("cfg");
            }
            if (!Directory.Exists("addons"))
            {
                Directory.CreateDirectory("addons");
            }


            ComponentCache.RegisterComponents();
            HeaderCache.RegisterHeaders();
            NetworkMethodCache.RegisterSendables();
            TileTypeCache.RegisterTileTypes();

            ServiceLocator.RegisterService(Content);
            ServiceLocator.RegisterService(spriteBatch);
            ServiceLocator.RegisterService(graphics);

            ServiceLocator.RegisterImplementations();
            DefineImplementations();
            ServiceLocator.RegisterServices();

            GameState.RegisterStates();
            ServiceLocator.Get <IPerformanceProfiler>().StartSession(false);
            for (var i = 0; i < 1000; i++)
            {
                //var world = new ObjectFactory<ThreeTierWorld>().Make(1, 1);
            }

            var time = ServiceLocator.Get <IPerformanceProfiler>().StopSession();

            Debug.WriteLine(time.TotalTime.Milliseconds);

            ServiceLocator.Get <IPropertyService>().Load("app");
            SteamCallback.Create();
            LuaContext.LoadAddons();

            Window.TextInput += ServiceLocator.Get <ITextInputService>().Execute;

            camera          = ServiceLocator.Get <ICamera>();
            input           = ServiceLocator.Get <IInput>();
            gameTimeService = ServiceLocator.Get <IGameTimeService>();
            stateService    = ServiceLocator.Get <IStateService>();
            client          = ServiceLocator.Get <IClient>();


            LoadGameContent();
        }