Ejemplo n.º 1
0
        public RTSRenderer(GraphicsDeviceManager gdm, ContentManager cm, RendererInitArgs ria, GameWindow w)
        {
            window = w;
            gManager = gdm;
            cManager = cm;
            args = ria;
            toDispose = new ConcurrentBag<IDisposable>();

            NonFriendlyUnitModels = new List<RTSUnitModel>();
            FriendlyUnitModels = new List<RTSUnitModel>();
            NonFriendlyBuildingModels = new List<RTSBuildingModel>();
            FriendlyBuildingModels = new List<RTSBuildingModel>();
            IconLibrary = new Dictionary<string, Texture2D>();
            for(int i = 0; i < ria.Icons.Length; i += 2) {
                IconLibrary.Add(ria.Icons[i], LoadTexture2D(ria.Icons[i + 1]));
            }

                tPixel = CreateTexture2D(1, 1);
            tPixel.SetData(new Color[] { Color.White });
            IconLibrary.Add("None", tPixel);

            fxMap = new RTSFXMap(LoadEffect(ria.FXMap));

            fxSimple = CreateEffect();
            fxSimple.LightingEnabled = false;
            fxSimple.FogEnabled = false;
            fxSimple.TextureEnabled = false;
            fxSimple.VertexColorEnabled = true;
            fxSimple.World = Matrix.Identity;
            fxSimple.Texture = tPixel;

            fxAnim = new RTSFXEntity(LoadEffect(ria.FXEntity));
            fxAnim.World = Matrix.Identity;
            fxAnim.CPrimary = Vector3.UnitX;
            fxAnim.CSecondary = Vector3.UnitY;
            fxAnim.CTertiary = Vector3.UnitZ;
            tNoise = LoadTexture2D(ria.FXBuildNoise);
            healthView = new HealthViewer();
            healthView.Build(this, fxAnim, ria.FXHealthTechnique, ria.FXHealthPass, ria.FXHealthTexture);
            UseFOW = true;

            pRenderer = new ParticleRenderer(LoadEffect(ria.FXParticle), ria.ParticleConfig);
            Minimap = new Minimap();

            CamPointer = new CameraPointer();
            CamPointer.Build(this, ria.CamPointerTexture, ria.CamPointerRadii, ria.CamPointerHeights);

            drawBox = false;
            MouseEventDispatcher.OnMousePress += OnMousePress;
            MouseEventDispatcher.OnMouseRelease += OnMouseRelease;
            MouseEventDispatcher.OnMouseMotion += OnMouseMove;
        }
Ejemplo n.º 2
0
        //public SpriteFont CreateFont(string fontName, int size, int spacing = 0, bool useKerning = true, string style = "Regular", char defaultChar = '*', int cStart = 32, int cEnd = 126) {
        //    IDisposable disp;
        //    SpriteFont f = XNASpriteFont.Compile(G, fontName, size, out disp, spacing, useKerning, style, defaultChar, cStart, cEnd);
        //    toDispose.Add(disp);
        //    return f;
        //}
        //public SpriteFont CreateFont(string fontName, int size, out IDisposable disp, int spacing = 0, bool useKerning = true, string style = "Regular", char defaultChar = '*', int cStart = 32, int cEnd = 126) {
        //    SpriteFont f = XNASpriteFont.Compile(G, fontName, size, out disp, spacing, useKerning, style, defaultChar, cStart, cEnd);
        //    toDispose.Add(disp);
        //    return f;
        //}
        #endregion

        public void HookToGame(GameState state, int ti, Camera camera)
        {
            // Get The Team To Be Visualized
            teamIndex = ti;
            teamInput = state.teams[teamIndex].Input;
            SelectionCircleTexture = LoadTexture2D(@"Content\Textures\SelectionCircle.png");

            // Get The Camera
            Camera = camera;

            // Create The Map
            CreateVoxGeos(state.VoxState.World.Atlas);
            Map = new VoxMap(this, state.CGrid.numCells.X, state.CGrid.numCells.Y);
            // TODO: Parse This In
            VoxMapConfig vmc = new VoxMapConfig();

            vmc.VoxState  = state.VoxState;
            vmc.TexVoxMap = @"voxmap.png";
            vmc.RootPath  = state.LevelGrid.Directory.FullName;
            vmc.FXFile    = @"FX\Voxel";
            Map.Build(gManager, cManager, vmc);

            Camera.MoveTo(state.CGrid.size.X * 0.5f, state.CGrid.size.Y * 0.5f);
            fxMap.MapSize     = state.CGrid.size;
            pRenderer.MapSize = state.CGrid.size;

            // Hook FOW
            state.CGrid.OnFOWChange += OnFOWChange;
            Minimap.Hook(this, state, ti);


            // Load Particles
            // TODO: Config
            ParticleOptions pOpt = ZXParser.ParseFile(@"Content\FX\Particles\Particle.conf", typeof(ParticleOptions)) as ParticleOptions;

            pRenderer.Load(this, pOpt);

            // Load Team Visuals
            for (int i = 0; i < state.teams.Length; i++)
            {
                if (state.teams[i] == null)
                {
                    continue;
                }
                LoadTeamVisuals(state, i);
            }

            // Set FOW
            for (int y = 0; y < Map.FogOfWarTexture.Height; y++)
            {
                for (int x = 0; x < Map.FogOfWarTexture.Width; x++)
                {
                    switch (state.CGrid.GetFogOfWar(x, y, teamIndex))
                    {
                    case FogOfWar.Active:
                        Map.SetFOW(x, y, 1f);
                        break;

                    case FogOfWar.Passive:
                        Map.SetFOW(x, y, 0.5f);
                        break;

                    case FogOfWar.Nothing:
                        Map.SetFOW(x, y, 0f);
                        break;
                    }
                }
            }
        }