Inheritance: GUIElement
Exemple #1
0
        public void MainLoop(GUISkin skin, Color skincolor)
        {
            // Main Render Loop
            int minFrameTime = (int) (1000/((float) m_maximumFramesPerSecond));

            m_lastScreenSize = Renderer.Driver.ScreenSize;

            while (Running)
            {
                try
                {
                    NetworkInterface.Process();
                }
                catch (Exception e)
                {
                    m_log.Error("Error processing network messages: " + e);
                }

                try
                {

                    // If you close the gui window, device.Run returns false.
                    Running = Renderer.Device.Run();
                }
                catch (AccessViolationException e)
                {
                    m_log.Error("[VIDEO]: Error in device" + e.ToString());
                }
                catch (OutOfMemoryException e)
                {
                    m_log.Error("[VIDEO]: Error in device" + e.ToString());
                    continue;
                }
                if (!Running)
                    break;
                try
                {
                    //  SceneGraph.WaterNode.Update();
                }
                catch ( /*AccessViolation*/ Exception)
                {
                    m_log.Warn("[water]: Unable to update this round");
                }

                Renderer.Driver.BeginScene(true, true, new Color(0, 255, 255, 255));
                try
                {
                    Renderer.SceneManager.DrawAll();
                }
                catch (Exception e)
                {

                    System.Console.WriteLine("" + e);
                }
                try
                {
                    Renderer.GuiEnvironment.DrawAll();
                }
                catch (Exception e)
                {

                    System.Console.WriteLine("" + e);
                }
                Renderer.Driver.EndScene();

                m_timeSinceLastSceneUpdate += System.Environment.TickCount - m_lastTickCount;
                int frameTime = System.Environment.TickCount - m_lastTickCount;
                m_lastTickCount = System.Environment.TickCount;

                // Update Interpolation targets
                SceneGraph.UpdateMovingObjects();
                // Update camera position and rotation.
                CameraController.CheckTarget();

                if (m_timeSinceLastSceneUpdate > m_baseSceneUpdateTimePeriod)
                {
                    // Repeat any held keys
                    UpdatePressedKeys();

                    m_timeSinceLastSceneUpdate = 0;
                    m_sceneUpdateCounter++;

                    if (m_sceneUpdateCounter == int.MaxValue)
                        m_sceneUpdateCounter = 0;
                }

                if ((m_sceneUpdateCounter%m_avatarModificationProcessingRate) == 0)
                {
                    AvatarController.UpdateRemote();
                    NetworkInterface.SendCameraViewMatrix(CameraController.GetCameraViewMatrix());
                    // process avatar animation changes
                    SceneGraph.ProcessAnimations();
                    // Process Avatar Mod Queue
                    SceneGraph.ProcessObjectModifications(20, ref SceneGraph.AvatarModifications);
                }

                try
                {
                    TerrainManager.Process();
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("" + e);
                }

                if ((m_sceneUpdateCounter%m_objectModificationProcessingRate) == 0)
                {
                    // Process Object Mod Queue.  Parameter is 'Items'
                    try
                    {
                        SceneGraph.ProcessObjectModifications(20, ref SceneGraph.ObjectModifications);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessObjectModifications" + ex);
                    }
                    // Process Mesh Queue.  Parameter is 'Items'
                    try
                    {
                        SceneGraph.ProcessMeshModifications(20);
                    }
                    catch (System.Exception ex)
                    {

                        System.Console.WriteLine("MAINLOOP: ProcessMeshModifications" + ex);
                    }
                    // Check the UnAssigned Child Queue for parents that have since rezed
                    try
                    {
                        SceneGraph.ProcessParentWaitingObjects(5);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessParentWaitingObjects" + ex);
                    }
                    // Apply textures
                    try
                    {
                        SceneGraph.ProcessTextureModifications(10);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessTextureModifications" + ex);
                    }
                    // Update foliage.
                    try
                    {
                        SceneGraph.ProcessFoliageMeshModifications(3);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessFoliageMeshModifications" + ex);
                    }
                    // Set the FPS in the window title.
                    Renderer.Device.WindowCaption = "IdealistViewer 0.001, FPS:" + Renderer.Driver.FPS.ToString();

                }

                // process chat
                if (UserInterface.OutboundChatMessages.Count > 0)
                    lock (UserInterface.OutboundChatMessages)
                        for (int i = 0; i < UserInterface.OutboundChatMessages.Count; i++)
                            NetworkInterface.Say(UserInterface.OutboundChatMessages.Dequeue());

                UserInterface.UpdateChatWindow();

                // Sleep until full frame time has been used.                
                if (m_limitFramesPerSecond && frameTime < minFrameTime)
                    Thread.Sleep(minFrameTime - frameTime);

            }
            //In the end, delete the Irrlicht device.
            Shutdown();
        }
Exemple #2
0
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected override void StartupComponents()
        {
            m_log.Info("[STARTUP]: Beginning startup processing");

            Version = Util.EnhanceVersionInformation();

            m_log.Info("[STARTUP]: Version: " + Version + "\n");

            Console = new Console(this,"Region", this);
            IConfig cnf = m_configSource.Source.Configs["Startup"];
            string loginURI = "http://127.0.0.1:9000/";
            string firstName = string.Empty;
            string lastName = string.Empty;
            string password = string.Empty;
            string startlocation = "";
            bool loadtextures = true;
            bool multipleSims = false;

            if (cnf != null)
            {
                loginURI = cnf.GetString("login_uri", "");
                firstName = cnf.GetString("first_name", "test");
                lastName = cnf.GetString("last_name", "user");
                password = cnf.GetString("pass_word", "nopassword");
                loadtextures = cnf.GetBoolean("load_textures", true);
                MeshSculpties = cnf.GetBoolean("mesh_sculpties", MeshSculpties);
                BackFaceCulling = cnf.GetBoolean("backface_culling", BackFaceCulling);
                AvatarMesh = cnf.GetString("avatar_mesh", AvatarMesh);
                AvatarMaterial = cnf.GetString("avatar_material", AvatarMaterial);
                AvatarScale = cnf.GetFloat("avatar_scale", AvatarScale);
                startlocation = cnf.GetString("start_location", "");
                multipleSims = cnf.GetBoolean("multiple_sims", multipleSims);
                ProcessFoliage = cnf.GetBoolean("process_foliage", ProcessFoliage);
                m_limitFramesPerSecond = cnf.GetBoolean("limitfps", m_limitFramesPerSecond);
            }
            LoadTextures = loadtextures;
            MainConsole.Instance = Console;

            // Initialize LibOMV
            if (NetworkInterface == null) NetworkInterface = new RadegastNetworkModule(RInstance);
            NetworkInterface.MultipleSims = multipleSims;
            NetworkInterface.OnLandUpdate += OnNetworkLandUpdate;
            NetworkInterface.OnConnected += OnNetworkConnected;
            NetworkInterface.OnObjectAdd += OnNetworkObjectAdd;
            NetworkInterface.OnSimulatorConnected += OnNetworkSimulatorConnected;
            NetworkInterface.OnObjectUpdate += OnNetworkObjectUpdate;
            NetworkInterface.OnObjectRemove += OnNetworkObjectRemove;
            NetworkInterface.OnAvatarAdd += OnNetworkAvatarAdd;
            //NetworkInterface.OnChat +=new NetworkChatDelegate(OnNetworkChat);
            //NetworkInterface.OnFriendsListUpdate +=new NetworkFriendsListUpdateDelegate(OnNetworkFriendsListChange);

            //NetworkInterface.Login(loginURI, firstName + " " + lastName, password, startlocation);

            // Startup the GUI
            Renderer = new RaegastRenderer(this,Device);
            Renderer.Startup();

            GUIFont defaultFont = Renderer.GuiEnvironment.GetFont("defaultfont.png");

            skin = Renderer.GuiEnvironment.Skin;
            skin.Font = defaultFont;
            skincolor = skin.GetColor(GuiDefaultColor.Face3D);
            skincolor.A = 255;
            skin.SetColor(GuiDefaultColor.Face3D, skincolor);
            skincolor = skin.GetColor(GuiDefaultColor.Shadow3D);
            skincolor.A = 255;
            skin.SetColor(GuiDefaultColor.Shadow3D, skincolor);
            // Set up event handler for the GUI window events.
            Renderer.Device.OnEvent += new OnEventDelegate(OnDeviceEvent);

            Renderer.Device.Resizeable = true;

            MeshManager = new MeshManager(Renderer.SceneManager.MeshManipulator, Renderer.Device);

            SceneGraph = new VSceneGraph(this);

            // Set up the picker.
            SceneGraph.TrianglePicker = new TrianglePickerMapper(Renderer.SceneManager.CollisionManager);
            SceneGraph.TriangleSelector = Renderer.SceneManager.CreateMetaTriangleSelector();

            // Only create a texture manager if the user configuration option is enabled for downloading textures
            if (LoadTextures)
            {
                TextureManager = new TextureManager(this,Renderer.Device, Renderer.Driver, SceneGraph.TrianglePicker, SceneGraph.TriangleSelector, "IdealistCache", NetworkInterface);
                TextureManager.OnTextureLoaded += OnNetworkTextureDownloaded;
            }

            AvatarController = new AvatarController(NetworkInterface, null);

            TerrainManager = ModuleManager.GetTerrainManager(this, m_configSource);

            Renderer.SceneManager.SetAmbientLight(new Colorf(1f, 0.2f, 0.2f, 0.2f));

            // This light simulates the sun
            //SceneNode light2 = Renderer.SceneManager.AddLightSceneNode(Renderer.SceneManager.RootSceneNode, new Vector3D(0, 255, 0), new Colorf(0f, 0.5f, 0.5f, 0.5f), 250, -1);
            SceneNode light2 = Renderer.SceneManager.AddLightSceneNode(Renderer.SceneManager.RootSceneNode, new Vector3D(0, 255, 0), new Colorf(0f, 0.6f, 0.6f, 0.6f), 512, -1);

            // Fog is on by default, this line disables it.
            //Renderer.SceneManager.VideoDriver.SetFog(new Color(0, 255, 255, 255), false, 9999, 9999, 0, false, false);
            float fogBrightness = 0.8f;
            Renderer.SceneManager.VideoDriver.SetFog(new Color(0, (int)(0.5f * 255 * fogBrightness), (int)(0.5f * 255 * fogBrightness), (int)(1.0f * 255 * fogBrightness)), true, 50, 100, 0, true, true);

            //ATMOSkySceneNode skynode = new ATMOSkySceneNode(Renderer.Driver.GetTexture("irrlicht2_up.jpg"), null, Renderer.SceneManager, 100, -1);
            
            //ATMOSphere atmosphere = new ATMOSphere(Renderer.Device.Timer, null, Renderer.SceneManager, -1);
            //atmosphere.SkyTexture = Renderer.Driver.GetTexture("irrlicht2_up.jpg");

            
            Renderer.Driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);
            bool Broken = false;
            if (!Broken) Renderer.SceneManager.AddSkyBoxSceneNode(null, new Texture[] {
                Renderer.Driver.GetTexture("topax2.jpg"),
                Renderer.Driver.GetTexture("irrlicht2_dn.jpg"),
                Renderer.Driver.GetTexture("rightax2.jpg"),
				Renderer.Driver.GetTexture("leftax2.jpg"),
                Renderer.Driver.GetTexture("frontax2.jpg"),
                Renderer.Driver.GetTexture("backax2.jpg")}, 
0);

            Renderer.Driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, true);
            

            CameraController = new CameraController(this,Renderer.SceneManager);

            SceneGraph.WaterNode = new WaterSceneNode(null, Renderer.SceneManager, new Dimension2Df(180, 180), new Dimension2D(100, 100), new Dimension2D(512, 512));
            SceneGraph.WaterNode.Position = new Vector3D(0, 30, 0);
            //SceneGraph.WaterNode.WaveHeight *= .4f;
            SceneGraph.WaterNode.RefractionFactor = 0.3f;
            SceneGraph.WaterNode.WaveDisplacement = 2f;
            SceneGraph.WaterNode.WaveHeight = 2f;
            SceneGraph.WaterNode.WaveLength = 2f;
            SceneGraph.WaterNode.WaveSpeed = 5f;
            SceneGraph.WaterNode.WaveRepetition = 20f;
            SceneGraph.WaterNode.Scale = new Vector3D(0.2f,0.2f,0.2f);
            SceneGraph.WaterNode.MultiColor = new Colorf(0.9f, 0.7f, 0.7f, 1.0f);

            UserInterface = new UserInterfaceManager(this, Renderer.Driver, Renderer.SceneManager, Renderer.GuiEnvironment, CameraController, AvatarController);
            UserInterface.DefaultFont = defaultFont;
             
            XmlReader xml = Broken? null: XmlReader.Create(new StreamReader("../../../media/About.xml"));
            while (xml != null && xml.Read())
            {
                switch (xml.NodeType)
                {
                    case XmlNodeType.Text:
                        UserInterface.AboutText = xml.ReadContentAsString();
                        break;
                    case XmlNodeType.Element:
                        if (xml.Name.Equals("startUpModel"))
                        {
                        }
                        else if (xml.Name.Equals("messageText"))
                            UserInterface.AboutCaption = xml.GetAttribute("caption");
                        break;
                }
            }

            string formsUiConfigurationOption = m_configSource.Source.Configs["Startup"].GetString("forms", "true");
            if (formsUiConfigurationOption == "true")
            {
                frmCommunications f = new frmCommunications(NetworkInterface);
                f.Visible = true;
                this.m_formsThread = new Thread(delegate() { Application.DoEvents(); Thread.Sleep(50); });
                m_formsThread.Start();
            }

            AnimationManager = new AnimationManager(this);

            TimeSpan timeTaken = DateTime.UtcNow - StartupTime;

            m_log.InfoFormat("[STARTUP]: Startup took {0}m {1}s", timeTaken.Minutes, timeTaken.Seconds);

        }