Example #1
0
        public RenderSystem(LoderGame game, SystemManager systemManager, EntityManager entityManager)
        {
            _game = game;
            _systemManager = systemManager;
            _entityManager = entityManager;
            _animationManager = game.animationManager;
            //_sortedRenderablePrimitives = new SortedDictionary<float, List<IRenderablePrimitive>>();
            _cameraSystem = _systemManager.getSystem(SystemType.Camera) as CameraSystem;
            _graphicsDevice = game.GraphicsDevice;
            _spriteBatch = game.spriteBatch;
            _backgroundRenderer = new BackgroundRenderer(_spriteBatch);
            _fluidRenderTarget = new RenderTarget2D(_graphicsDevice, _graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height);
            _renderedFluid = new RenderTarget2D(_graphicsDevice, _graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height);
            _debugFluid = new RenderTarget2D(_graphicsDevice, _graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height);
            _postSourceUnder = new RenderTarget2D(_graphicsDevice, _graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height);
            _postSourceOver = new RenderTarget2D(_graphicsDevice, _graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height);

            _contentManager = new ContentManager(game.Services);
            _contentManager.RootDirectory = "Content";
            _fluidEffect = _contentManager.Load<Effect>("fluid_effect");
            _fluidParticleTexture = _contentManager.Load<Texture2D>("fluid_particle");
            _reticle = _contentManager.Load<Texture2D>("reticle");
            _materialRenderer = new MaterialRenderer(game.GraphicsDevice, _contentManager, game.spriteBatch);
            _primitivesEffect = _contentManager.Load<Effect>("effects/primitives");
            _pixel = new Texture2D(_graphicsDevice, 1, 1);
            _pixel.SetData<Color>(new [] { Color.White });
            _circle = _contentManager.Load<Texture2D>("circle");
            _tooltipFont = _contentManager.Load<SpriteFont>("shared_ui/tooltip_font");
        }
Example #2
0
        protected override void Initialize()
        {
            _graphics.PreferredBackBufferWidth = 512;
            _graphics.PreferredBackBufferWidth = 512;
            base.Initialize();

            ResourceManager.initialize(GraphicsDevice);
            ResourceManager.rootDirectory = @"D:/StasisResources/";
            loadMaterials();

            // Initialize rectangular points
            float scaledHalfWidth = (float)(GraphicsDevice.Viewport.Width / SCALE) * 0.5f;
            float scaledHalfHeight = (float)(GraphicsDevice.Viewport.Height / SCALE) * 0.5f;
            _screenPoints = new List<Vector2>();
            _screenPoints.Add(new Vector2(-scaledHalfWidth, -scaledHalfHeight));
            _screenPoints.Add(new Vector2(scaledHalfWidth, -scaledHalfHeight));
            _screenPoints.Add(new Vector2(scaledHalfWidth, scaledHalfHeight));
            _screenPoints.Add(new Vector2(-scaledHalfWidth, scaledHalfHeight));

            // Initialize polygon points
            _polygonPoints = new List<Vector2>();
            _polygonPoints.Add(new Vector2(-3.5f, 0));
            _polygonPoints.Add(new Vector2(-1, 1));
            _polygonPoints.Add(new Vector2(0, 3));
            _polygonPoints.Add(new Vector2(2, 2.5f));
            _polygonPoints.Add(new Vector2(3, 0));
            _polygonPoints.Add(new Vector2(4, -1));
            _polygonPoints.Add(new Vector2(3.5f, -3));
            _polygonPoints.Add(new Vector2(1, -3.5f));
            _polygonPoints.Add(new Vector2(0.5f, -3));
            _polygonPoints.Add(new Vector2(-1, -4));
            _polygonPoints.Add(new Vector2(-2.5f, -2.5f));
            _polygonPoints.Add(new Vector2(-3.5f, -3));
            _polygonPoints.Add(new Vector2(-4.5f, -1.5f));

            // Initialize vertices
            _screenVertices = createVerticesFromPoints(_screenPoints, out _screenPrimitiveCount);
            _polygonVertices = createVerticesFromPoints(_polygonPoints, out _polygonPrimitiveCount);

            // Initialize primitives effect
            _primitives.CurrentTechnique = _primitives.Techniques["generic"];
            _primitives.Parameters["world"].SetValue(Matrix.Identity);
            _primitives.Parameters["view"].SetValue(Matrix.CreateScale(new Vector3(SCALE, -SCALE, 1)));
            _primitives.Parameters["projection"].SetValue(Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1));

            _materialRenderer = new MaterialRenderer(GraphicsDevice, Content, _spriteBatch);
        }