Example #1
0
 public void Initialize(IRefController _reference)
 {
     __reference = _reference;
     reference = (RefController)__reference;
 }
Example #2
0
        private void StartupGUI(object target)
        {
            // Enforce the underlying Irrlicht engine to load a local D3DX9_40.dll
            // (Note: Environment.CurrentDirectory is visible to other plug-ins)
            Environment.CurrentDirectory = Util.ApplicationDataDirectory;

            SetupAddins();
            SetupLog();

            f = new RenderForm(this);
            f.Width = width;
            f.Height = height;
            f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            f.ImeMode = System.Windows.Forms.ImeMode.Inherit;
            try
            {
                SetParent(f.Handle, (IntPtr)target);

            #if MANAGED_D3D
                Microsoft.DirectX.Direct3D.PresentParameters pp = new Microsoft.DirectX.Direct3D.PresentParameters();
                pp.Windowed = true;
                pp.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;

                try
                {
                    d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                        0,
                        Microsoft.DirectX.Direct3D.DeviceType.Hardware,
                        f,
                        Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                        pp
                        );
                }
                catch
                {
                    try
                    {
                        d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                            0,
                            Microsoft.DirectX.Direct3D.DeviceType.Reference,
                            f,
                            Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                            pp
                            );
                    }
                    catch
                    {
                    }
                }

                CreateVideoObject();
            #endif
            }
            catch (System.Exception)
            {

            }
            f.Location = new System.Drawing.Point(0, 0);
            //f.FormClosed += new System.Windows.Forms.FormClosedEventHandler(f_FormClosed);
            f.Show();
            renderTarget = f.Handle;

            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string cacheFlag = m_config.Source.Configs["Startup"].Get("cache_delete", "false");
                if (cacheFlag == "true")
                {
                    CleanChache();
                }

            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            try
            {
                device = new IrrlichtDevice(DriverType.Direct3D9, new Dimension2D(width, height), 32, false, true, false, false, renderTarget);
                if (device == null)
                {
                    m_log.Error("can't create irrlicht device.");
                    System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);
                }
            }
            catch (Exception e)
            {
                m_log.Error("can't create irrlicht device.", e);
                System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);

                device = null;
            }

            if (device == null)
            {
                // release all.

                // exit application.

                return;
            }
            else
            {
                m_log.InfoFormat("AdapterVendorID: 0x{0:x8}", device.VideoDriver.AdapterVendorId);
                m_log.InfoFormat("AdapterDeviceId: 0x{0:x8}", device.VideoDriver.AdapterDeviceId);
                m_log.InfoFormat("AdapterSubSysId: 0x{0:x8}", device.VideoDriver.AdapterSubSysId);
                m_log.InfoFormat("AdapterRevision: 0x{0:x8}", device.VideoDriver.AdapterRevision);
                m_log.InfoFormat("AdapterMaxTextureHeight: {0}", device.VideoDriver.AdapterMaxTextureHeight);
                m_log.InfoFormat("AdapterMaxTextureWidth: {0}", device.VideoDriver.AdapterMaxTextureWidth);
                m_log.InfoFormat("AdapterMaxActiveLights: {0}", device.VideoDriver.AdapterMaxActiveLights);
                m_log.InfoFormat("AdapterVertexShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterVertexShaderVersion);
                m_log.InfoFormat("AdapterPixelShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterPixelShaderVersion);

                // AdapterVendorId
                // 0x1002 : ATI Technologies Inc.
                // 0x10DE : NVIDIA Corporation
                // 0x102B : Matrox Electronic Systems Ltd.
                // 0x121A : 3dfx Interactive Inc
                // 0x5333 : S3 Graphics Co., Ltd.
                // 0x8086 : Intel Corporation
                //
                if (device.VideoDriver.AdapterVendorId == 0x1002)
                {
                    string warningMessage = DialogText.WarningGraphicCardMessage;
                    string warningCaption = DialogText.WarningGraphicCardCaption;

                    System.Windows.Forms.DialogResult yesno = System.Windows.Forms.MessageBox.Show(warningMessage, warningCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
                    if (System.Windows.Forms.DialogResult.Yes != yesno)
                    {
                        return;
                    }
                }
            }

            reference = new RefController(this);

            device.OnEvent += new OnEventDelegate(device_OnEvent);

            // If enabled is true, videotexture is not correctly render.
            device.VideoDriver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            #if DEBUG
            device.Logger.LogLevel = LogLevel.Information;
            #endif
            // Create video Textrue
            videoTexture = device.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"\media\textures\videoTexture.tga");

            IrrlichtNETCP.Extensions.TTFont font = new TTFont(Device.VideoDriver);
            IrrlichtNETCP.Extensions.TTFace face = new TTFace();
            bool font_loaded = false;
            uint fontsize = 16;
            string fontface = Config.Source.Configs["Startup"].GetString("guifont_face");

            if (!string.IsNullOrEmpty(Config.Source.Configs["Startup"].GetString("guifont_size")))
            {
                fontsize = (uint)Config.Source.Configs["Startup"].GetInt("guifont_size");
            }

            if (!string.IsNullOrEmpty(fontface))
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface);
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                    font_loaded = true;
                }
                else
                {
                    m_log.Warn("[FONT]: The specified font (" + fontface + ") was not available on this system. Reverting to default.");
                }
            }
            if (!font_loaded)
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc"))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc");
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                }
                else
                {
                    JapaneseEnabled = false;
                    Locale = "en";
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                    if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf"))
                    {
                        face.Load(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf");
                        font.Attach(face, fontsize);
                        font.Antialias = true;
                        Reference.GUIEnvironment.Skin.Font = font;
                    }
                    else
                    {
                        // Use built in font--- this looks horrible and should be avoided if possible
                        Reference.GUIEnvironment.Skin.Font = Reference.GUIEnvironment.BuiltInFont;
                    }
                }
            }
            font.Drop();
            face.Drop();
            // if font and face are being used, at this point face and font should both have reference counts of 1.
            // if font and face are not being used (last else branch above, using built-in font), font and face should both be deleted at this point.

            // Zaki: Adding Japanese support end

            Reference.VideoDriver.SetFog(new Color(0, 255, 255, 255), false, 9999, 9999, 0, false, false);

            //Reference.Device.FileSystem.WorkingDirectory = Util.UserCacheDirectory;
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ApplicationDataDirectory);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ModelFolder);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.TextureFolder);

            camera = new Camera(this);

            // Create managers.
            cacheManager = new CacheManager(this, -1);
            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string s_cacheMB = m_config.Source.Configs["Startup"].Get("cache_size", DEFAULT_CACHE_MB_SIZE.ToString());

                long cacheMB = DEFAULT_CACHE_MB_SIZE;
                if (long.TryParse(s_cacheMB, out cacheMB))
                {
                    cacheMB = cacheMB * 1000 * 1000;

                    cacheManager.CacheMaxSize = cacheMB;
                    cacheManager.Clean();
                }
            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            // Locale can be used from this point on
            if (Locale == "en")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("en-US");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            }
            if (Locale == "jp")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("ja-JP");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja-JP");
            }

            stateManager = new Managers.StateManager(this);
            protocolManager = new Managers.ProtocolManager(this);
            guiManager = new GuiManager(this);
            menuManager = new MenuManager(this);
            shaderManager = new ShaderManager(this);
            entityManager = new EntityManager(this);
            irrManager = new IrrManager(this, -1);
            textureManager = new TextureManager(this);
            textureManager.OnTextureLoaded += OnTextureComplete;
            terrainManager = new Managers.TerrainManager(this);
            avatarManager = new Managers.AvatarManager(this);
            effectManager = new Managers.EffectManager(this);
            chatManager = new Managers.ChatManager(this);
            soundManager = new Managers.SoundManager(this);
            debugManager = new DebugManager(this, -1);

            // Experimental manager plugin loader
            LoadPlugins();

            // Initialize.
            Initialize();

            // Event
            stateManager.OnChanged += StateChanged;

            clearColor = Color.FromBCL(Util.FromString(BackgroundColor));
            progressBarColor = Color.FromBCL(Util.FromString(ProgressColor, System.Drawing.Color.FromArgb(63, 0, 0, 0)));

            guiManager.LoadBackgrounds();

            soundManager.InitWindowBackgroundMusicURL = InitBackgroundMusicURL;
            soundManager.LoadBackgroundMusic();

            // After all managers all initialized
            stateManager.State = State.INITIALIZED;

            adapter.Initialize(this.reference);

            adapter.CallSetWorldAmbientColor(WorldAmbientColor);
            adapter.CallSetFixDirectional(FixDirectional);
            adapter.CallSetFixDirectionalRotation(FixDirectionalRotation);
            adapter.CallSetFixDirectionalDiffuseColor(FixDirectionalDiffuseColor);
            adapter.CallSetFixDirectionalAmbientColor(FixDirectionalAmbientColor);

            SetLogFilter();

            guiManager.ShowLoginWindow(new LoginInfo(ServerURI, FirstName, LastName, Password, LoginMode, true, true));

            // Hide mouse cursor.
            ShowCursor(false);

            #if _SECOND_SURFACE_ON
            pip = Reference.VideoDriver.CreateRenderTargetTexture(new Dimension2D(256, 256));
            pipImage = Reference.GUIEnvironment.AddImage(pip, new Position2D(Width - pip.OriginalSize.Width - 10, 40), false, Reference.GUIEnvironment.RootElement, -1, "");

            CameraSceneNode oldCam = Reference.SceneManager.ActiveCamera;
            pipCamera = Reference.SceneManager.AddCameraSceneNode(Reference.SceneManager.RootSceneNode);
            material.Lighting = false;
            if (Reference.SceneManager.ActiveCamera.Raw != oldCam.Raw)
                Reference.SceneManager.ActiveCamera = oldCam;
            #endif

            System.Windows.Forms.DialogResult dialogRes = System.Windows.Forms.DialogResult.Retry;
            while (dialogRes == System.Windows.Forms.DialogResult.Retry)
            {
                dialogRes = RenderLoop();
            }

            #if MANAGED_D3D
            try
            {
                if (video != null)
                {
                    lock (video)
                    {
                        video.Stop();
                        video.Dispose();
                    }
                }

                if (d3ddevice != null)
                {
                    lock (d3ddevice)
                    {
                        d3ddevice.Dispose();
                        d3ddevice = null;
                    }
                }
            }
            catch
            {
            }
            #endif

            if (device != null)
            {
                device.Dispose();
                device = null;
            }
        }