Example #1
0
        public void Dispose()
        {
            ChunkUpdater.Dispose();
            Atlas2D.Dispose();
            Atlas1D.Dispose();
            ModelCache.Dispose();
            Entities.Dispose();
            WorldEvents.OnNewMap       -= OnNewMapCore;
            WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;
            Events.TextureChanged      -= TextureChangedCore;

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Dispose();
            }

            Drawer2D.DisposeInstance();
            Graphics.Dispose();
            // TODO: is this needed
            //window.Dispose();

            if (!Options.HasChanged())
            {
                return;
            }
            Options.Load();
            Options.Save();
        }
Example #2
0
        public void Dispose()
        {
            MapRenderer.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Entities.Dispose();
            WorldEvents.OnNewMap       -= OnNewMapCore;
            WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;
            Events.TextureChanged      -= TextureChangedCore;

            for (int i = 0; i < Components.Count; i++)
            {
                Components[i].Dispose();
            }

            Graphics.DeleteIb(ref defaultIb);
            Drawer2D.DisposeInstance();
            Graphics.DeleteTexture(ref CloudsTex);
            Graphics.Dispose();
            if (lastAtlas != null)
            {
                lastAtlas.Dispose();
            }

            if (Options.OptionsChanged.Count == 0)
            {
                return;
            }
            Options.Load();
            Options.Save();
        }
Example #3
0
        static void Main(string[] args)
        {
            AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string logPath = Path.Combine(AppDirectory, "client.log");

            ErrorHandler.InstallHandler(logPath);
            CleanupMainDirectory();
            Configuration.SkipPerfCountersHack();

            Utils.LogDebug("Starting " + AppName + "..");
            string path = Path.Combine(Program.AppDirectory, "texpacks");

            if (!File.Exists(Path.Combine(path, "default.zip")))
            {
                MessageDefaultZipMissing(); return;
            }

            bool nullContext = true;

                        #if !USE_DX
            nullContext = false;
                        #endif

            Options.Load();
            DisplayDevice device = DisplayDevice.Primary;
            int           width  = Options.GetInt(OptionsKey.WindowWidth, 0, device.Width, 0);
            int           height = Options.GetInt(OptionsKey.WindowHeight, 0, device.Height, 0);

            // No custom resolution has been set
            if (width == 0 || height == 0)
            {
                width = 854; height = 480;
                if (device.Width < 854)
                {
                    width = 640;
                }
            }

            if (args.Length == 0 || args.Length == 1)
            {
                const string skinServer = "http://static.classicube.net/skins/";
                string       user       = args.Length > 0 ? args[0] : "Singleplayer";
                using (Game game = new Game(user, null, skinServer, nullContext, width, height))
                    game.Run();
            }
            else if (args.Length < 4)
            {
                Utils.LogDebug("ClassicalSharp.exe is only the raw client. You must either use the launcher or"
                               + " provide command line arguments to start the client.");
            }
            else
            {
                RunMultiplayer(args, nullContext, width, height);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            CleanupMainDirectory();

            string defPath = Path.Combine("texpacks", "default.zip");

            if (!Platform.FileExists(defPath))
            {
                ErrorHandler.ShowDialog("Missing file", "default.zip not found, try running the launcher first.");
                return;
            }

            ErrorHandler.InstallHandler("client.log");
            OpenTK.Configuration.SkipPerfCountersHack();
            Utils.LogDebug("Starting " + AppName + "..");

            Options.Load();
            DisplayDevice device = DisplayDevice.Default;
            int           width  = Options.GetInt(OptionsKey.WindowWidth, 0, device.Bounds.Width, 0);
            int           height = Options.GetInt(OptionsKey.WindowHeight, 0, device.Bounds.Height, 0);

            // No custom resolution has been set
            if (width == 0 || height == 0)
            {
                width = 854; height = 480;
                if (device.Bounds.Width < 854)
                {
                    width = 640;
                }
            }

            if (args.Length == 0 || args.Length == 1)
            {
                const string skinServer = "http://static.classicube.net/skins/";
                string       user       = args.Length > 0 ? args[0] : "Singleplayer";
                using (Game game = new Game(user, null, skinServer, width, height))
                    game.Run();
            }
            else if (args.Length < 4)
            {
                Utils.LogDebug("ClassicalSharp.exe is only the raw client. You must either use the launcher or"
                               + " provide command line arguments to start the client.");
            }
            else
            {
                RunMultiplayer(args, width, height);
            }
        }
Example #5
0
        public void Dispose()
        {
            MapRenderer.Dispose();
            SetNewScreen(null);
            fpsScreen.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Entities.Dispose();
            WorldEvents.OnNewMap       -= OnNewMapCore;
            WorldEvents.OnNewMapLoaded -= OnNewMapLoadedCore;

            foreach (IGameComponent comp in Components)
            {
                comp.Dispose();
            }

            if (activeScreen != null)
            {
                activeScreen.Dispose();
            }
            Graphics.DeleteIb(defaultIb);
            Drawer2D.DisposeInstance();
            Graphics.DeleteTexture(ref CloudsTex);
            Graphics.DeleteTexture(ref GuiTex);
            Graphics.DeleteTexture(ref GuiClassicTex);
            Graphics.DeleteTexture(ref IconsTex);
            Graphics.Dispose();

            foreach (WarningScreen screen in WarningOverlays)
            {
                screen.Dispose();
            }

            if (Options.HasChanged)
            {
                Options.Load();
                Options.Save();
            }
        }
Example #6
0
        public void Dispose()
        {
            MapRenderer.Dispose();
            MapBordersRenderer.Dispose();
            EnvRenderer.Dispose();
            WeatherRenderer.Dispose();
            SetNewScreen(null);
            fpsScreen.Dispose();
            SelectionManager.Dispose();
            TerrainAtlas.Dispose();
            TerrainAtlas1D.Dispose();
            ModelCache.Dispose();
            Picking.Dispose();
            ParticleManager.Dispose();
            Players.Dispose();
            AsyncDownloader.Dispose();
            AudioPlayer.Dispose();
            AxisLinesRenderer.Dispose();

            Chat.Dispose();
            if (activeScreen != null)
            {
                activeScreen.Dispose();
            }
            Graphics.DeleteIb(defaultIb);
            Graphics.Dispose();
            Drawer2D.DisposeInstance();
            Animations.Dispose();
            Graphics.DeleteTexture(ref CloudsTexId);
            Graphics.DeleteTexture(ref RainTexId);
            Graphics.DeleteTexture(ref SnowTexId);
            Graphics.DeleteTexture(ref GuiTexId);
            Graphics.DeleteTexture(ref GuiClassicTexId);

            if (Options.HasChanged)
            {
                Options.Load();
                Options.Save();
            }
        }
Example #7
0
        protected override void OnLoad(EventArgs e)
        {
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();
            Players = new EntityList(this);

            Options.Load();
            AcceptedUrls.Load(); DeniedUrls.Load();
            ViewDistance     = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512);
            UserViewDistance = ViewDistance;
            CameraClipping   = Options.GetBool(OptionsKey.CameraClipping, true);
            InputHandler     = new InputHandler(this);
            Chat             = new ChatLog(this);
            ParticleManager  = new ParticleManager(this);
            HudScale         = Options.GetFloat(OptionsKey.HudScale, 0.25f, 5f, 1f);
            ChatScale        = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f);
            defaultIb        = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30);
            UseClassicGui    = Options.GetBool(OptionsKey.UseClassicGui, false);
            BlockInfo        = new BlockInfo();
            BlockInfo.Init();
            ChatLines     = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12);
            ClickableChat = Options.GetBool(OptionsKey.ClickableChat, true);
            ModelCache    = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = new AsyncDownloader(skinServer);
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            Drawer2D.UseBitmappedChat = !Options.GetBool(OptionsKey.ArialChatFont, false);
            ViewBobbing               = Options.GetBool(OptionsKey.ViewBobbing, false);
            ShowBlockInHand           = Options.GetBool(OptionsKey.ShowBlockInHand, true);
            InvertMouse               = Options.GetBool(OptionsKey.InvertMouse, false);
            SimpleArmsAnim            = Options.GetBool(OptionsKey.SimpleArmsAnim, false);

            TerrainAtlas1D = new TerrainAtlas1D(Graphics);
            TerrainAtlas   = new TerrainAtlas2D(Graphics, Drawer2D);
            Animations     = new Animations(this);
            defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip";
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract("default.zip", this);
            // in case the user's default texture pack doesn't have all required textures
            if (defTexturePack != "default.zip")
            {
                extractor.Extract(DefaultTexturePack, this);
            }
            Inventory = new Inventory(this);

            BlockInfo.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete);
            Map                = new Map(this);
            LocalPlayer        = new LocalPlayer(this);
            Players[255]       = LocalPlayer;
            width              = Width;
            height             = Height;
            MapRenderer        = new MapRenderer(this);
            MapBordersRenderer = new MapBordersRenderer(this);
            EnvRenderer        = new StandardEnvRenderer(this);
            if (IPAddress == null)
            {
                Network = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Network = new NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera          = firstPersonCam;
            FieldOfView     = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70);
            ZoomFieldOfView = FieldOfView;
            UpdateProjection();
            CommandManager = new CommandManager();
            CommandManager.Init(this);
            SelectionManager = new SelectionManager(this);
            WeatherRenderer  = new WeatherRenderer(this);
            WeatherRenderer.Init();
            BlockHandRenderer = new BlockHandRenderer(this);
            BlockHandRenderer.Init();

            FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync);
            SetFpsLimitMethod(method);
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc(CompareFunc.LessEqual);
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha);
            Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f);
            fpsScreen = new FpsScreen(this);
            fpsScreen.Init();
            hudScreen = new HudScreen(this);
            hudScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapBordersRenderer.Init();
            Picking           = new PickingRenderer(this);
            AudioPlayer       = new AudioPlayer(this);
            LiquidsBreakable  = Options.GetBool(OptionsKey.LiquidsBreakable, false);
            AxisLinesRenderer = new AxisLinesRenderer(this);

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            Graphics.WarnIfNecessary(Chat);
            SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Network.Connect(IPAddress, Port);
        }
Example #8
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;

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


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

            if (Options.GetBool(OptionsKey.SurvivalMode, false))
            {
                Mode = AddComponent(new SurvivalGameMode());
            }
            else
            {
                Mode = AddComponent(new CreativeGameMode());
            }

            Input           = 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(Drawer2D));
            Lighting        = AddComponent(new BasicLighting());

            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.SetDefaultPerms(Inventory.CanPlace, Inventory.CanDelete);
            World       = new World(this);
            LocalPlayer = AddComponent(new LocalPlayer(this));
            Entities[EntityList.SelfID] = 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;

            Cameras.Add(new FirstPersonCamera(this));
            Cameras.Add(new ThirdPersonCamera(this, false));
            Cameras.Add(new ThirdPersonCamera(this, true));
            Camera = Cameras[0];
            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());

            plugins = new PluginLoader(this);
            List <string> nonLoaded = plugins.LoadAll();

            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();

            if (nonLoaded != null)
            {
                for (int i = 0; i < nonLoaded.Count; i++)
                {
                    plugins.MakeWarning(this, nonLoaded[i]);
                }
            }

            window.LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                EnvRenderer.UseLegacyMode(true);
            }
            Gui.SetNewScreen(new LoadingMapScreen(this, connectString, ""));
            Server.Connect(IPAddress, Port);
        }
Example #9
0
        internal void OnLoad()
        {
            Mouse    = window.Mouse;
            Keyboard = window.Keyboard;
                        #if !USE_DX
            Graphics = new OpenGLApi();
                        #else
            Graphics = new Direct3D9Api(this);
                        #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            Entities = new EntityList(this);
            AcceptedUrls.Load();
            DeniedUrls.Load();
            ETags.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;

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ModelCache = new ModelCache(this);
            ModelCache.InitCache();
            AsyncDownloader           = AddComponent(new AsyncDownloader());
            Drawer2D                  = new GdiPlusDrawer2D(Graphics);
            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.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete);
            World              = new World(this);
            LocalPlayer        = AddComponent(new LocalPlayer(this));
            Entities[255]      = LocalPlayer;
            width              = Width;
            height             = Height;
            MapRenderer        = new MapRenderer(this);
            MapBordersRenderer = AddComponent(new MapBordersRenderer());
            EnvRenderer        = AddComponent(new StandardEnvRenderer());
            if (IPAddress == null)
            {
                Network = new Singleplayer.SinglePlayerServer(this);
            }
            else
            {
                Network = new Network.NetworkProcessor(this);
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam        = new FirstPersonCamera(this);
            thirdPersonCam        = new ThirdPersonCamera(this);
            forwardThirdPersonCam = new ForwardThirdPersonCamera(this);
            Camera = firstPersonCam;
            UpdateProjection();
            CommandManager    = AddComponent(new CommandManager());
            SelectionManager  = AddComponent(new SelectionManager());
            WeatherRenderer   = AddComponent(new WeatherRenderer());
            BlockHandRenderer = AddComponent(new BlockHandRenderer());

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

            foreach (IGameComponent comp in Components)
            {
                comp.Init(this);
            }
            ExtractInitialTexturePack();
            foreach (IGameComponent comp in Components)
            {
                comp.Ready(this);
            }

            LoadIcon();
            string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
            if (Graphics.WarnIfNecessary(Chat))
            {
                MapBordersRenderer.UseLegacyMode(true);
                ((StandardEnvRenderer)EnvRenderer).UseLegacyMode(true);
            }
            SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake"));
            Network.Connect(IPAddress, Port);
        }
Example #10
0
        static void Main(string[] args)
        {
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            ErrorHandler.InstallHandler("client.log");
            Utils.LogDebug("Starting " + AppName + "..");


            Utils.EnsureDirectory("maps");
            Utils.EnsureDirectory("texpacks");
            Utils.EnsureDirectory("texturecache");

            string defPath = Path.Combine("texpacks", "default.zip");

            if (!Platform.FileExists(defPath))
            {
                ErrorHandler.ShowDialog("Failed to start", "default.zip is missing, try running the launcher first.");
                return;
            }
            OpenTK.Configuration.SkipPerfCountersHack();


            IPAddress ip = null;
            int       port = 0;
            string    user = null, mppass = null;
            string    skinServer = "http://static.classicube.net/skins/";

            if (args.Length == 0 || args.Length == 1)
            {
                user = args.Length > 0 ? args[0] : "Singleplayer";
            }
            else if (args.Length < 4)
            {
                ErrorHandler.ShowDialog("Failed to start", "ClassicalSharp.exe is only the raw client\n\n." +
                                        "Use the launcher instead, or provide command line arguments");
                return;
            }
            else
            {
                user   = args[0];
                mppass = args[1];
                if (args.Length > 4)
                {
                    skinServer = args[4];
                }

                if (!IPAddress.TryParse(args[2], out ip))
                {
                    ErrorHandler.ShowDialog("Failed to start", "Invalid IP " + args[2]); return;
                }
                if (!Int32.TryParse(args[3], out port) || port <0 || port> ushort.MaxValue)
                {
                    ErrorHandler.ShowDialog("Failed to start", "Invalid port " + args[3]); return;
                }
            }

            Options.Load();
            DisplayDevice device = DisplayDevice.Default;
            int           width  = Options.GetInt(OptionsKey.WindowWidth, 0, device.Bounds.Width, 0);
            int           height = Options.GetInt(OptionsKey.WindowHeight, 0, device.Bounds.Height, 0);

            // No custom resolution has been set
            if (width == 0 || height == 0)
            {
                width = 854; height = 480;
                if (device.Bounds.Width < 854)
                {
                    width = 640;
                }
            }

            using (Game game = new Game(user, mppass, skinServer, width, height)) {
                game.IPAddress = ip;
                game.Port      = port;
                game.Run();
            }
        }