public AtlasTests() { Stream tmxStream = FileStreams.SmallPickupTmx(); StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream()); TmxSerializer serializer = new TmxSerializer(); Map map = serializer.Deserialize(tmxStream); ToyWorld world = new ToyWorld(map, tilesetTableStreamReader); m_atlas = world.Atlas; }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if ((Settings.EnabledOverlays ^ RenderRequestOverlay.InventoryTool) == RenderRequestOverlay.None) { return; } Owner.FrontFbo.Bind(); // some stuffs }
public LuaConsole(ToyWorld toyWorld, IAtlas atlas) { InitializeComponent(); toyWorld.ToyWorldDisposed += CloseConsole; outputListBox.DataSource = m_inputOutputList; m_lex = new LuaExecutor(atlas, this); m_inputOutputList.Add(INVITATION_MESSAGE); ResetBox(); }
public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, GameObjectSettings settings) { Settings = settings; GL.DepthFunc(DepthFunction.Lequal); //GL.DepthFunc(DepthFunction.Always); // Ignores stored depth values, but still writes them // Tileset textures { // Set up tileset textures IEnumerable <Tileset> tilesets = world.TilesetTable.GetTilesetImages(); TilesetImage[] tilesetImages = tilesets.Select( t => new TilesetImage( t.Image.Source, new Vector2I(t.Tilewidth, t.Tileheight), new Vector2I(t.Spacing), world.TilesetTable.TileBorder)) .ToArray(); TilesetTexture = renderer.TextureManager.Get <TilesetTexture>(tilesetImages); } // Set up tile grid shader { Effect = renderer.EffectManager.Get <NoEffectOffset>(); renderer.EffectManager.Use(Effect); // Need to use the effect to set uniforms // Set up static uniforms Vector2I fullTileSize = world.TilesetTable.TileSize + world.TilesetTable.TileMargins + world.TilesetTable.TileBorder * 2; // twice the border, on each side once Vector2 tileCount = (Vector2)TilesetTexture.Size / (Vector2)fullTileSize; Effect.TexSizeCountUniform(new Vector3I(TilesetTexture.Size.X, TilesetTexture.Size.Y, (int)tileCount.X)); Effect.TileSizeMarginUniform(new Vector4I(world.TilesetTable.TileSize, world.TilesetTable.TileMargins)); Effect.TileBorderUniform(world.TilesetTable.TileBorder); Effect.AmbientUniform(new Vector4(1, 1, 1, EffectPainter.AmbientTerm)); } // Set up geometry if (settings.Use3D) { Cube = renderer.GeometryManager.Get <DuplicatedCube>(); } else { Cube = renderer.GeometryManager.Get <Quad>(); } IgnoredGameObjects.Clear(); }
public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, PostprocessingSettings settings) { Settings = settings; if (Settings.EnabledPostprocessing.HasFlag(RenderRequestPostprocessing.Noise)) { if (m_noiseEffect == null) { m_noiseEffect = renderer.EffectManager.Get <NoiseEffect>(); } renderer.EffectManager.Use(m_noiseEffect); // Need to use the effect to set uniforms m_noiseEffect.ViewportSizeUniform((Vector2I)Owner.Resolution); m_noiseEffect.SceneTextureUniform((int)RenderRequestBase.TextureBindPosition.PostEffectTextureBindPosition); } }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if (Settings.CopyMode == RenderRequestImageCopyingMode.None) { return; } // Gather data to host mem Owner.FrontFbo.Bind(); switch (Settings.CopyMode) { case RenderRequestImageCopyingMode.DefaultFbo: GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); GL.BlitFramebuffer( 0, 0, Owner.FrontFbo.Size.X, Owner.FrontFbo.Size.Y, 0, 0, renderer.Width, renderer.Height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest); break; case RenderRequestImageCopyingMode.OpenglPbo: Pbo.Bind(); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); // Works for fbo bound to Framebuffer (not DrawFramebuffer) //Owner.FrontFbo[FramebufferAttachment.ColorAttachment0].Copy2D(PixelType.UnsignedByte); // This is half as fast as ReadPixels for color data GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.Bgra, PixelType.UnsignedByte, default(IntPtr)); if (Settings.CopyDepth) { DepthPbo.Bind(); Owner.FrontFbo[FramebufferAttachment.DepthAttachment].Copy2D(PixelType.Float); // This is twice as fast as ReadPixels for depth texture //GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.DepthComponent, PixelType.UnsignedInt, default(IntPtr)); } break; case RenderRequestImageCopyingMode.Cpu: GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); // Works for fbo bound to Framebuffer (not DrawFramebuffer) GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.Bgra, PixelType.UnsignedByte, RenderedScene); if (Settings.CopyDepth) { Owner.FrontFbo[FramebufferAttachment.DepthAttachment].Copy2D(PixelType.Float, RenderedSceneDepth); } break; } }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if (Settings.EnabledOverlays == RenderRequestOverlay.None) { return; } base.Draw(renderer, world); if (Settings.EnabledOverlays.HasFlag(RenderRequestOverlay.InventoryTool)) { DrawAvatarTool( renderer, world.GetAvatar(Owner.AvatarID), (Vector2)Settings.ToolSize, (Vector2)Settings.ToolPosition, Settings.ToolBackground); } }
public void CheckDirtyParams(RendererBase <ToyWorld> renderer, ToyWorld world) { var gridView = GridView; // Get currently rendered layers m_toRender = GetTileLayersToRender().ToArray(); if (Owner.DirtyParams.HasFlag(RenderRequestBase.DirtyParam.Size)) { if (Settings.Use3D) { Grid = renderer.GeometryManager.Get <DuplicatedCubeGrid>(gridView.Size); } else { Grid = renderer.GeometryManager.Get <DuplicatedGrid>(gridView.Size); } // Reallocate stuff if needed -- texture holds tileTypes for all the layers int totalTileCount = gridView.Size.Size() * m_toRender.Length; Debug.Assert(totalTileCount < 1 << 14, "TileTypesTexture will overflow!"); if (TileTypesTexure == null || totalTileCount > TileTypesTexure.Size.Size()) { // Init buffer if (m_tileTypesBuffer != null) { m_tileTypesBuffer.Dispose(); } m_tileTypesBuffer = new Pbo <ushort>(1); m_tileTypesBuffer.Init(totalTileCount, hint: BufferUsageHint.StreamDraw); // Init texture if (TileTypesTexure != null) { TileTypesTexure.Dispose(); } TileTypesTexure = renderer.TextureManager.Get <BasicTexture1D>(new Vector2I(totalTileCount, 1)); TileTypesTexure.DefaultInit(); } } }
public void AvatarLoosingEnergy() { Stream tmxStream = FileStreams.SmallPickupTmx(); StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream()); TmxSerializer serializer = new TmxSerializer(); Map map = serializer.Deserialize(tmxStream); m_worldPickupWorld = new ToyWorld(map, tilesetTableStreamReader); m_eater = m_worldPickupWorld.GetAvatar(m_worldPickupWorld.GetAvatarsIds()[0]); // Act for (int i = 0; i < 100; i++) { m_eater.Update(m_worldPickupWorld.Atlas, It.IsAny <TilesetTable>()); } // Assert Assert.True(m_eater.Energy < 1); }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if (Settings.EnabledGameObjects == RenderRequestGameObject.None) { return; } if (!Settings.Use3D) { GL.Enable(EnableCap.Blend); Owner.SetDefaultBlending(); } else { GL.Disable(EnableCap.Blend); } GL.Enable(EnableCap.DepthTest); GL.DepthMask(true); // Bind stuff to GL renderer.TextureManager.Bind(TilesetTexture[0], Owner.GetTextureUnit(RenderRequestBase.TextureBindPosition.SummerTileset)); renderer.TextureManager.Bind(TilesetTexture[1], Owner.GetTextureUnit(RenderRequestBase.TextureBindPosition.WinterTileset)); renderer.TextureManager.Bind(TileTypesTexure, Owner.GetTextureUnit(RenderRequestBase.TextureBindPosition.TileTypes)); renderer.EffectManager.Use(Effect); Effect.TextureUniform((int)RenderRequestBase.TextureBindPosition.SummerTileset); Effect.TextureWinterUniform((int)RenderRequestBase.TextureBindPosition.WinterTileset); Effect.TileTypesTextureUniform((int)RenderRequestBase.TextureBindPosition.TileTypes); Effect.DiffuseUniform(new Vector4(1, 1, 1, Owner.EffectPainter.GetGlobalDiffuseComponent(world))); Effect.TileVertexCountUniform(Settings.Use3D ? DuplicatedCubeGrid.FaceCount * 4 : 4); if (Settings.EnabledGameObjects.HasFlag(RenderRequestGameObject.TileLayers)) { DrawTileLayers(renderer, world); } if (Settings.EnabledGameObjects.HasFlag(RenderRequestGameObject.ObjectLayers)) { DrawObjectLayers(renderer, world); } }
public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, EffectSettings settings) { Settings = settings; if (Settings.EnabledEffects.HasFlag(RenderRequestEffect.Lights)) { if (m_pointLightEffect == null) { m_pointLightEffect = new PointLightEffect(); } } if (Settings.EnabledEffects.HasFlag(RenderRequestEffect.Smoke)) { if (m_smokeEffect == null) { m_smokeEffect = renderer.EffectManager.Get <SmokeEffect>(); } renderer.EffectManager.Use(m_smokeEffect); // Need to use the effect to set uniforms m_smokeEffect.SmokeColorUniform(new Vector4(Settings.SmokeColor.R, Settings.SmokeColor.G, Settings.SmokeColor.B, Settings.SmokeColor.A) / 255f); } }
protected virtual void DrawObjectLayers(RendererBase <ToyWorld> renderer, ToyWorld world) { var gridView = GridView; Effect.TileTypesIdxOffsetUniform(0); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); // Draw objects foreach (var objectLayer in world.Atlas.ObjectLayers) { foreach (var gameObject in objectLayer.GetGameObjects(new RectangleF(gridView))) { if (IgnoredGameObjects.Contains(gameObject) || gameObject.Invisible) { continue; } // Set up transformation to screen space for the gameObject Matrix transform = Matrix.Identity; // Model transform IRotatable rotatableObject = gameObject as IRotatable; if (rotatableObject != null) { transform *= Matrix.CreateRotationZ(rotatableObject.Rotation); } transform *= Matrix.CreateScale(new Vector3(gameObject.Size, objectLayer.Thickness) * 0.5f); // from (-1,1) to (-size,size)/2 // World transform transform *= Matrix.CreateTranslation(new Vector3(gameObject.Position, objectLayer.SpanIntervalFrom + objectLayer.Thickness / 2)); // View and projection transforms transform *= Owner.ViewProjectionMatrix; Effect.ModelViewProjectionUniform(ref transform); // Setup dynamic data LocalTileTypesBuffer[0] = (ushort)gameObject.TilesetId; TileTypesTexure.Update1D(1, dataType: PixelType.UnsignedShort, data: LocalTileTypesBuffer); Cube.Draw(); } } }
public void AvatarCanPickUp() { Stream tmxStream = FileStreams.SmallPickupTmx(); StreamReader tilesetTableStreamReader = new StreamReader(FileStreams.TilesetTableStream()); TmxSerializer serializer = new TmxSerializer(); Map map = serializer.Deserialize(tmxStream); m_worldPickupWorld = new ToyWorld(map, tilesetTableStreamReader); m_avatarPickuper = m_worldPickupWorld.GetAvatar(m_worldPickupWorld.GetAvatarsIds()[0]); m_avatarPickuper.PickUp = true; Assert.Equal(null, m_avatarPickuper.Tool); // Act m_avatarPickuper.Update(m_worldPickupWorld.Atlas, It.IsAny <TilesetTable>()); // Assert Assert.IsType <Apple>(m_avatarPickuper.Tool); Assert.False(m_avatarPickuper.PickUp); }
public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, OverlaySettings settings) { Settings = settings; // Set up overlay textures IEnumerable <Tileset> tilesets = world.TilesetTable.GetOverlayImages(); TilesetImage[] tilesetImages = tilesets.Select(t => new TilesetImage( t.Image.Source, new Vector2I(t.Tilewidth, t.Tileheight), new Vector2I(t.Spacing), world.TilesetTable.TileBorder)) .ToArray(); m_overlayTexture = renderer.TextureManager.Get <TilesetTexture>(tilesetImages); // Set up overlay shader m_overlayEffect = renderer.EffectManager.Get <NoEffectOffset>(); renderer.EffectManager.Use(m_overlayEffect); // Need to use the effect to set uniforms // Set up static uniforms Vector2I tileSize = tilesetImages[0].TileSize; Vector2I tileMargins = tilesetImages[0].TileMargin; Vector2I tileBorder = tilesetImages[0].TileBorder; Vector2I fullTileSize = tileSize + tileMargins + tileBorder * 2; // twice the border, on each side once Vector2 tileCount = (Vector2)m_overlayTexture.Size / (Vector2)fullTileSize; m_overlayEffect.TexSizeCountUniform(new Vector3I(m_overlayTexture.Size.X, m_overlayTexture.Size.Y, (int)tileCount.X)); m_overlayEffect.TileSizeMarginUniform(new Vector4I(tileSize, tileMargins)); m_overlayEffect.TileBorderUniform(tileBorder); m_overlayEffect.AmbientUniform(new Vector4(1, 1, 1, 1)); QuadOffset = renderer.GeometryManager.Get <Quad>(); }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if (Settings.EnabledEffects == RenderRequestEffect.None) { return; } GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.DepthTest); GL.DepthMask(false); Owner.FrontFbo.Bind(); const float effectHeight = 1.5f; if (Settings.EnabledEffects.HasFlag(RenderRequestEffect.Lights)) { //GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.SrcAlpha); // Fades non-lit stuff to black GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.DstAlpha); renderer.EffectManager.Use(m_pointLightEffect); foreach (var character in world.Atlas.Characters) { m_pointLightEffect.ColorUniform(new Vector4(0.85f)); float lightDecay = character.ForwardSpeed; m_pointLightEffect.IntensityDecayUniform(new Vector2(1, lightDecay)); m_pointLightEffect.LightPosUniform(new Vector3(character.Position, effectHeight)); // Set up transformation to world and screen space for noise effect Matrix mw = Matrix.Identity; // Model transform -- scale from (-1,1) to viewSize/2, center on origin const float minIntensity = 0.01f; const float intensityScale = (1 / minIntensity - 1) / 30; mw *= Matrix.CreateScale(intensityScale / lightDecay / 2); // World transform -- move center to view center mw *= Matrix.CreateTranslation(new Vector3(character.Position, effectHeight)); m_pointLightEffect.ModelWorldUniform(ref mw); Matrix mvp = mw * Owner.ViewProjectionMatrix; m_pointLightEffect.ModelViewProjectionUniform(ref mvp); Owner.Quad.Draw(); } Owner.SetDefaultBlending(); } if (Settings.EnabledEffects.HasFlag(RenderRequestEffect.Smoke)) { renderer.EffectManager.Use(m_smokeEffect); // Set up transformation to world and screen space for noise effect Matrix mw = Matrix.Identity; // Model transform -- scale from (-1,1) to viewSize/2, center on origin mw *= Matrix.CreateScale(Owner.ViewV.Size / 2); // World transform -- move center to view center mw *= Matrix.CreateTranslation(new Vector3(Owner.ViewV.Center, effectHeight + 0.05f)); // View and projection transforms Matrix mvp = mw * Owner.ViewProjectionMatrix; m_smokeEffect.ModelWorldUniform(ref mw); m_smokeEffect.ModelViewProjectionUniform(ref mvp); m_smokeEffect.AmbientDiffuseTermsUniform(new Vector2(AmbientTerm, GetGlobalDiffuseComponent(world))); // Advance noise time by a visually pleasing step; wrap around if we run for waaaaay too long. double step = 0.005d * Settings.SmokeTransformationSpeedCoefficient; double seed = renderer.SimTime * step % 3e6d; m_smokeEffect.TimeStepUniform(new Vector2((float)seed, (float)step)); m_smokeEffect.MeanScaleUniform(new Vector2(Settings.SmokeIntensityCoefficient, Settings.SmokeScaleCoefficient)); Owner.Quad.Draw(); } // more stufffs }
public abstract void Draw(RendererBase <ToyWorld> renderer, ToyWorld world);
public abstract void Init(RendererBase <ToyWorld> renderer, ToyWorld world, TSettings settings);
public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, OverlaySettings settings) { base.Init(renderer, world, settings); }