Пример #1
0
    public static void Main(string[] args)
    {
        Gk3Main.Settings.Renderer = DefaultRenderer;
        Gk3Main.Settings.Load("settings.txt");

        _window = init(args);
        if (_window == null)
        {
            return;                  // something bad happened
        }
        // int dummy1, dummy2;
        //Sdl.SDL_GetMouseState(out dummy1, out dummy2);

        _clock.Start();

        while (MainLoop())
        {
            refreshInput();

            update();

            Gk3Main.Graphics.Camera camera = Gk3Main.SceneManager.CurrentCamera;

            render(camera, Game.Input.MouseX, Game.Input.MouseY);

            _window.Present();
        }

        shutdown();
    }
Пример #2
0
    private static void onMouseMove(int mx, int my)
    {
        Gk3Main.Graphics.Camera camera = Gk3Main.SceneManager.CurrentCamera;
        if (camera != null)
        {
            if (Game.Input.LeftMousePressed)
            {
                if (Game.Input.RightMousePressed)
                {
                    camera.AddRelativePositionOffset(Gk3Main.Math.Vector3.Right * Game.Input.RelMouseX);
                    camera.AddPositionOffset(0, -Game.Input.RelMouseY, 0);
                }
                else
                {
                    if (Game.VerbPickerManager.VerbButtonsVisible == false)
                    {
                        if (Game.Input.CurrentKeys.IsKeyDown(Game.Keys.LeftShift) ||
                            Game.Input.CurrentKeys.IsKeyDown(Game.Keys.RightShift))
                        {
                            camera.AdjustYaw(Game.Input.RelMouseX * 0.01f);
                            camera.AdjustPitch(Game.Input.RelMouseY * 0.01f);
                        }
                        else
                        {
                            camera.AdjustYaw(Game.Input.RelMouseX * 0.01f);
                            camera.AddRelativePositionOffset(Gk3Main.Math.Vector3.Forward * -Game.Input.RelMouseY);
                        }
                    }
                }
            }
        }

        Gk3Main.Gui.GuiMaster.OnMouseMove(Gk3Main.Game.GameManager.TickCount, mx, my);
    }
Пример #3
0
        public static void renderRadiosityCallback(Radiosity.HemicubeRenderType type,
                                                   int viewportX, int viewportY, int viewportWidth, int viewportHeight,
                                                   float eyeX, float eyeY, float eyeZ,
                                                   float directionX, float directionY, float directionZ,
                                                   float upX, float upY, float upZ)
        {
            Graphics.RendererManager.CurrentRenderer.Viewport = new Graphics.Viewport(viewportX, viewportY, viewportWidth, viewportHeight);

            Graphics.Camera c       = null;
            bool            zNegOne = (Graphics.RendererManager.CurrentRenderer.ZClipMode == Gk3Main.Graphics.ZClipMode.NegativeOne);

            const float near = 2.0f;

            Math.Vector3 position  = new Math.Vector3(eyeX, eyeY, eyeZ);
            Math.Vector3 direction = new Math.Vector3(directionX, directionY, directionZ);

            if (type == Radiosity.HemicubeRenderType.Front)
            {
                c = new Graphics.Camera(90.0f * 0.0174532925f, 1.0f, near, 1000.0f, zNegOne);
            }
            else if (type == Radiosity.HemicubeRenderType.Top)
            {
                Math.Matrix projection = Math.Matrix.PerspectiveOffCenter(-near, near, -near, 0, near, 1000.0f, zNegOne);
                c = new Graphics.Camera(projection);
            }
            else if (type == Radiosity.HemicubeRenderType.Bottom)
            {
                Math.Matrix projection = Math.Matrix.PerspectiveOffCenter(-near, near, 0, near, near, 1000.0f, zNegOne);
                c = new Graphics.Camera(projection);
            }
            else if (type == Radiosity.HemicubeRenderType.Left)
            {
                Math.Matrix projection = Math.Matrix.PerspectiveOffCenter(0, near, -near, near, near, 1000.0f, zNegOne);
                c = new Graphics.Camera(projection);
            }
            else if (type == Radiosity.HemicubeRenderType.Right)
            {
                Math.Matrix projection = Math.Matrix.PerspectiveOffCenter(-near, 0, -near, near, near, 1000.0f, zNegOne);
                c = new Graphics.Camera(projection);
            }

            c.LookAt(new Math.Vector3(eyeX, eyeY, eyeZ), new Math.Vector3(directionX, directionY, directionZ), new Math.Vector3(upX, upY, upZ));

            if (_currentSkybox != null)
            {
                _currentSkybox.Render(c);
            }
            _currentRoom.Render(c, _currentLightmaps, true);

            // add any omni lights
            foreach (OmniInfo omni in _omniLightInfo)
            {
                Graphics.BillboardManager.AddBillboard(omni.Info.Position, omni.Info.Radius, omni.Info.Radius, omni.MemTex, omni.AlphaMask);
            }

            // render any billboards
            Graphics.BillboardManager.RenderBillboardsWithAlpha(c);
        }
Пример #4
0
    private static void onMouseRightUp(int mx, int my)
    {
        Gk3Main.Gui.GuiMaster.OnMouseUp(1, mx, my);

        if (Game.VerbPickerManager.VerbButtonsVisible)
        {
            Game.VerbPickerManager.Dismiss();
        }
        else if (_leftDownWhileRightDown == false && Game.Input.LeftMousePressed == false)
        {
            Gk3Main.Graphics.Camera camera = Gk3Main.SceneManager.CurrentCamera;
            if (camera != null)
            {
                Gk3Main.Gui.GuiMaster.ToggleOptionsMenu(Gk3Main.Resource.ResourceManager.Global, mx, my);
            }
        }

        _leftDownWhileRightDown = false;
    }
Пример #5
0
    private static void render(Gk3Main.Graphics.Camera camera, int mouseX, int mouseY)
    {
        Gk3Main.Graphics.RendererManager.CurrentRenderer.Clear();
        Gk3Main.Graphics.RendererManager.CurrentRenderer.BeginScene();

        Gk3Main.SceneManager.Render();

        _spriteBatch.Begin();

        if (_state == GameState.TimeBlockSplash)
        {
        }
        else if (_state == GameState.MainMenu)
        {
        }

        bool mouseIntercepted = Gk3Main.Gui.GuiMaster.Render(_spriteBatch, Gk3Main.Game.GameManager.TickCount);

        if (mouseIntercepted)
        {
            _pointCursor.Render(_spriteBatch, mouseX, mouseY);
        }
        else
        {
            Game.VerbPickerManager.RenderProperCursor(_spriteBatch, camera, mouseX, mouseY, _pointCursor, _zoom1Cursor);
        }



        _spriteBatch.End();

        //if (Gk3Main.DebugFlagManager.GetDebugFlag(Gk3Main.DebugFlag.ShowStats))
        renderStats();

        Game.Console.Render(_spriteBatch);

        Gk3Main.Graphics.RendererManager.CurrentRenderer.EndScene();
    }
Пример #6
0
        public static void CalculateLightmaps(LightmapSpecs specs)
        {
            if (_currentRoom != null && _currentLightmaps != null)
            {
                Radiosity.Init(new Radiosity.RenderDelegate(renderRadiosityCallback));

                _calculatingRadiosity = true;
                CurrentFilterMode     = TextureFilterMode.None;
                LightmapsEnabled      = true;
                CurrentShadeMode      = ShadeMode.Flat;
                DoubleLightmapValues  = false;
                Graphics.Camera   originalCamera   = CurrentCamera;
                Graphics.Viewport originalViewport = Graphics.RendererManager.CurrentRenderer.Viewport;

                RadiosityMaps radiosityMaps = _currentRoom.GenerateMemoryTextures(specs);

                // generate the omni lights
                _omniLightInfo = new List <OmniInfo>();
                foreach (LightmapSpecs.OmniLight light in specs.OmniLights)
                {
                    OmniInfo o;
                    o.Info = light;
                    Radiosity.GenerateOmniLight((int)light.Radius, light.Color, out o.MemTex, out o.AlphaMask);

                    _omniLightInfo.Add(o);
                }

                Graphics.RendererManager.CurrentRenderer.CullMode = Graphics.CullMode.None;


                Graphics.TextureResource skyboxTop          = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxFront        = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxBack         = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxLeft         = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxRight        = Radiosity.GenerateMemoryTexture(16, 16, specs.SkyColor.X, specs.SkyColor.Y, specs.SkyColor.Z);
                Graphics.TextureResource skyboxBottom       = Radiosity.GenerateMemoryTexture(16, 16, 0, 0, 0);
                Graphics.BitmapSurface   skyboxTopPixels    = new Graphics.BitmapSurface(skyboxTop);
                Graphics.BitmapSurface   skyboxFrontPixels  = new Graphics.BitmapSurface(skyboxFront);
                Graphics.BitmapSurface   skyboxBackPixels   = new Graphics.BitmapSurface(skyboxBack);
                Graphics.BitmapSurface   skyboxLeftPixels   = new Graphics.BitmapSurface(skyboxLeft);
                Graphics.BitmapSurface   skyboxRightPixels  = new Graphics.BitmapSurface(skyboxRight);
                Graphics.BitmapSurface   skyboxBottomPixels = new Graphics.BitmapSurface(skyboxBottom);

                // Graphics.SkyBox.AddSun(specs.SunDirection, specs.SunColor, 0.125f, skyboxFrontPixels, skyboxBackPixels, skyboxLeftPixels, skyboxRightPixels, skyboxTopPixels, true);

                Graphics.SkyBox originalSkybox = _currentSkybox;
                if (_currentSkybox != null)
                {
                    _currentSkybox = new Graphics.SkyBox("box", skyboxFrontPixels, skyboxBackPixels, skyboxLeftPixels, skyboxRightPixels, skyboxTopPixels, skyboxBottomPixels, 0);

                    _currentSkybox.AddSun(specs.SunDirection, specs.SunColor, true);
                }

                Graphics.LightmapResource oldLightmaps = _currentLightmaps;
                _currentLightmaps = radiosityMaps.CreateBigMemoryTexture(_currentLightmaps.Name);
                _currentRoom.CalcRadiosityPass(_currentLightmaps, radiosityMaps);

                Radiosity.Shutdown();

                _currentRoom.FinalizeVertices(_currentLightmaps, true);
                _currentLightmaps = radiosityMaps.ConvertToLightmap(_currentLightmaps.Name, 0.02f);

                Graphics.RendererManager.CurrentRenderer.CullMode = Graphics.CullMode.CounterClockwise;
                Graphics.RendererManager.CurrentRenderer.Viewport = originalViewport;
                CurrentCamera  = originalCamera;
                _currentSkybox = originalSkybox;

                _calculatingRadiosity = false;
            }
        }
Пример #7
0
        public static void Render(Graphics.Camera camera)
        {
            if (camera != null)
            {
                camera.Update();

                // render the skybox
                if (_currentSkybox != null)
                {
                    _currentSkybox.Render(camera);
                }

                // render the room
                if (camera != null && _currentRoom != null)
                {
                    _currentRoom.Render(camera, _currentLightmaps, false);
                }

                // render the models
                Graphics.ModelResource.BeginBatchRender();
                foreach (SceneModel model in _models)
                {
                    if (model.Visible)
                    {
                        model.Model.RenderBatch(camera, model.Model.TempTransform);
                    }
                }

                // render the actors
                foreach (Game.Actor actor in _actors)
                {
                    actor.RenderBatch(camera);
                }

                Graphics.ModelResource.EndBatchRender();

                // render model AABBs (if needed)
                if (Settings.ShowBoundingBoxes)
                {
                    foreach (SceneModel model in _models)
                    {
                        if (model.Visible)
                        {
                            model.Model.RenderAABB(camera);
                        }
                    }

                    foreach (Game.Actor actor in _actors)
                    {
                        actor.RenderAABB(camera);
                    }
                }


                // add helpers to the billboard list
                if (_renderHelperIcons)
                {
                    foreach (KeyValuePair <string, SifPosition> position in _roomPositions)
                    {
                        Graphics.BillboardManager.AddBillboard(new Math.Vector3(position.Value.X, position.Value.Y + 30.0f, position.Value.Z),
                                                               50.0f, 50.0f, HelperIcons.Flag);
                    }

                    foreach (KeyValuePair <string, SifRoomCamera> rcamera in _cameras)
                    {
                        Graphics.BillboardManager.AddBillboard(new Math.Vector3(rcamera.Value.X, rcamera.Value.Y + 30.0f, rcamera.Value.Z),
                                                               50.0f, 50.0f, HelperIcons.Camera);
                    }

                    foreach (KeyValuePair <string, ScnLight> light in _roomLights)
                    {
                        Graphics.BillboardManager.AddBillboard(light.Value.Position,
                                                               20.0f, 20.0f, HelperIcons.Bulb);
                    }
                }

                // render any billboards
                Graphics.BillboardManager.RenderBillboards(camera);
            }

            foreach (Sound.SoundTrackResource stk in _stks)
            {
                stk.Step(Game.GameManager.TickCount);
            }
            foreach (Sound.SoundTrackResource stk in _playingSoundTracks)
            {
                stk.Step(Game.GameManager.TickCount);
            }

            // remove stale STKs
            for (LinkedListNode <Sound.SoundTrackResource> node = _playingSoundTracks.First;
                 node != null;)
            {
                LinkedListNode <Sound.SoundTrackResource> next = node.Next;

                if (node.Value.Playing == false)
                {
                    _playingSoundTracks.Remove(node);
                }

                node = next;
            }

            // run any GASes
            for (int i = 0; i < _modelGases.Count; i++)
            {
                _modelGases[i].Continue();
            }
        }
Пример #8
0
    private static void update()
    {
        // TODO: this still needs cleaning up!


        if (Game.Input.LeftMousePressedFirstTime)
        {
            onMouseLeftDown(Game.Input.MouseX, Game.Input.MouseY);
        }
        else if (Game.Input.LeftMouseReleasedFirstTime)
        {
            onMouseLeftUp(Game.Input.MouseX, Game.Input.MouseY);
        }
        if (Game.Input.RightMousePressedFirstTime)
        {
            onMouseRightDown(Game.Input.MouseX, Game.Input.MouseY);
        }
        else if (Game.Input.RightMouseReleasedFirstTime)
        {
            onMouseRightUp(Game.Input.MouseX, Game.Input.MouseY);
        }

        if (Game.Input.RelMouseX != 0 || Game.Input.RelMouseY != 0)
        {
            onMouseMove(Game.Input.MouseX, Game.Input.MouseY);
        }

        if (Game.Input.KeyboardButtonPressedFirstTime(Game.Keys.OemTilde))
        {
            Game.Console.Visible = !Game.Console.Visible;
        }

        var pressed = Game.Input.CurrentKeys.GetPressedKeys();

        for (int i = 0; i < pressed.Length; i++)
        {
            if (Game.Input.PreviousKeys.IsKeyUp(pressed[i]))
            {
                onKeyPress(pressed[i]);
            }
        }


        Gk3Main.Graphics.Camera camera = Gk3Main.SceneManager.CurrentCamera;

        /*
         * if (camera != null)
         * {
         *  if (Game.Input.LeftMousePressed)
         *  {
         *      if (Game.Input.RightMousePressed)
         *      {
         *          if (Game.VerbPickerManager.VerbButtonsVisible == false)
         *          {
         *              camera.AddRelativePositionOffset(Gk3Main.Math.Vector3.Right * Game.Input.RelMouseX);
         *              camera.AddPositionOffset(0, -Game.Input.RelMouseY, 0);
         *          }
         *      }
         *      else
         *      {
         *          if (Game.VerbPickerManager.VerbButtonsVisible == false)
         *          {
         *              if (Game.Input.Keys[Sdl.SDLK_LSHIFT] != 0 ||
         *                  Game.Input.Keys[Sdl.SDLK_RSHIFT] != 0)
         *              {
         *                  camera.AdjustYaw(Game.Input.RelMouseX * 0.01f);
         *                  camera.AdjustPitch(Game.Input.RelMouseY * 0.01f);
         *              }
         *              else
         *              {
         *                  camera.AdjustYaw(Game.Input.RelMouseX * 0.01f);
         *                  camera.AddRelativePositionOffset(Gk3Main.Math.Vector3.Forward * Game.Input.RelMouseY);
         *              }
         *          }
         *
         *          if (Game.Input.LeftMousePressedFirstTime)
         *          {
         *              Game.VerbPickerManager.MouseDown(0, Game.Input.MouseX, Game.Input.MouseY);
         *              if (_optionsMenu != null)
         *                  _optionsMenu.OnMouseDown(Game.Input.MouseX, Game.Input.MouseY);
         *          }
         *      }
         *  }
         *  else if (Game.Input.LeftMouseReleasedFirstTime && camera != null)
         *  {
         *      Game.VerbPickerManager.MouseUp(camera, 0, Game.Input.MouseX, Game.Input.MouseY);
         *
         *      if (_optionsMenu != null)
         *          _optionsMenu.OnMouseUp(Game.Input.MouseX, Game.Input.MouseY);
         *  }
         *  else if (Game.Input.RightMousePressedFirstTime && camera != null)
         *  {
         *      if (_optionsMenu == null)
         *          _optionsMenu = new Gk3Main.Gui.OptionsMenu(_globalContent, Game.Input.MouseX, Game.Input.MouseY);
         *      else
         *          _optionsMenu = null;
         *  }
         *
         * }*/


        int ticks = (int)_clock.ElapsedMilliseconds;

        // int ticks = Sdl.SDL_GetTicks();
        int elapsed = Math.Min(ticks - _lastTickCount, 1000);

        _lastTickCount = ticks;
        Gk3Main.Game.GameManager.InjectTickCount(elapsed);


        Gk3Main.Sound.SoundManager.Update(camera);

        Gk3Main.Game.Animator.Advance(Gk3Main.Game.GameManager.ElapsedTickCount);
        Gk3Main.Game.DialogManager.Step();
        Gk3Main.Sheep.SheepMachine.ResumeIfNoMoreBlockingWaits();

        Gk3Main.Game.GameTimer?timer;
        while ((timer = Gk3Main.Game.GameManager.GetNextExpiredGameTimer()).HasValue)
        {
            Gk3Main.Console.CurrentConsole.WriteLine(Gk3Main.ConsoleSeverity.Debug,
                                                     "Timer expired- noun: {0} verb: {1}", timer.Value.Noun, timer.Value.Verb);

            List <Gk3Main.Game.NounVerbCase> nvcs = Gk3Main.Game.NvcManager.GetNounVerbCases(timer.Value.Noun, timer.Value.Verb, true);

            foreach (Gk3Main.Game.NounVerbCase nvc in nvcs)
            {
                Gk3Main.Console.CurrentConsole.WriteLine(Gk3Main.ConsoleSeverity.Debug,
                                                         "Executing timer NVC: {0}", nvc.Script);

                Gk3Main.Sheep.SheepMachine.RunCommand(nvc.Script);
            }
        }
    }