Пример #1
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;
                        #if ANDROID
            Graphics = new OpenGLESApi();
                        #elif !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeApiInfo();
            ErrorHandler.AdditionalInfo = Graphics.ApiInfo;

            Options.Load();
            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.Load();
            LastModified.Load();

            InputHandler    = new InputHandler(this);
            defaultIb       = Graphics.MakeDefaultIb();
            ParticleManager = AddComponent(new ParticleManager());
            TabList         = AddComponent(new TabList());
            LoadOptions();
            LoadGuiOptions();
            Chat = AddComponent(new Chat());
            WorldEvents.OnNewMap       += OnNewMapCore;
            WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore;
            Events.TextureChanged      += TextureChangedCore;

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader = AddComponent(new AsyncDownloader());

                        #if ANDROID
            Drawer2D = new CanvasDrawer2D(Graphics);
                        #else
            Drawer2D = new GdiPlusDrawer2D(Graphics);
                        #endif

            Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.ArialChatFont, false);
            Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackTextShadows, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = AddComponent(new Animations());
            Inventory      = AddComponent(new Inventory());

            BlockInfo.SetDefaultBlockPerms(Inventory.CanPlace, Inventory.CanDelete);
            World         = new World(this);
            LocalPlayer   = AddComponent(new LocalPlayer(this));
            Entities[255] = LocalPlayer;
            Width         = window.Width; Height = window.Height;

            MapRenderer = new MapRenderer(this);
            string renType = Options.Get(OptionsKey.RenderType) ?? "normal";
            if (!SetRenderType(renType))
            {
                SetRenderType("normal");
            }

            if (IPAddress == null)
            {
                Server = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Server = new Network.NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Server.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this, false);
            forwardThirdPersonCam = new ThirdPersonCamera(this, true);
            Camera = firstPersonCam;
            UpdateProjection();

            Gui               = AddComponent(new GuiInterface(this));
            CommandList       = AddComponent(new CommandList());
            SelectionManager  = AddComponent(new SelectionManager());
            WeatherRenderer   = AddComponent(new WeatherRenderer());
            HeldBlockRenderer = AddComponent(new HeldBlockRenderer());

            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            Culling           = new FrustumCulling();
            Picking           = AddComponent(new PickedPosRenderer());
            AudioPlayer       = AddComponent(new AudioPlayer());
            AxisLinesRenderer = AddComponent(new AxisLinesRenderer());
            SkyboxRenderer    = AddComponent(new SkyboxRenderer());

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Init(this);
            }
            ExtractInitialTexturePack();
            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Ready(this);
            }
            InitScheduledTasks();

            window.LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Server.Connect(IPAddress, Port);
        }