private void DrawCode(int x, int y) { var demo = (DemoReel)RB.Game; mFormatStr.Set("@C// Load infinite TMX maps chunk by chunk to create maps of any size!@N\n"); mFormatStr.Append("@Kvar@N chunkPixelSize = @Knew@N @MVector2i@N(@[email protected] * @[email protected](@L0@N).width, @[email protected] * @[email protected](@L0@N).height);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Figure out which map chunk is in the top left corner of the camera view@N\n"); mFormatStr.Append("@Kvar@N newTopLeftChunk = @Knew@N @MVector2i@N(mCameraPos.x / chunkPixelSize.width, mCameraPos.y / chunkPixelSize.height);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Check if the camera moved enough so that the top left chunk has changed, if so then we need to shift the map and load a new chunk.@N\n"); mFormatStr.Append("@Kif@N (newTopLeftChunk != mTopLeftChunk) {\n"); mFormatStr.Append(" @[email protected](@L0@N, mTopLeftChunk - newTopLeftChunk);\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @C// After shifting loop through all potentially visible chunks and load any that are now empty.@N\n"); mFormatStr.Append(" @Kfor@N (@Kint@N cx = @L0@N; cx <= @[email protected] / chunkPixelSize.width + @L1@N; cx++) {\n"); mFormatStr.Append(" @Kvar@N chunkPos = @Knew@N @MVector2i@N(cx * RB.MapChunkSize.x, cy * RB.MapChunkSize.y);\n"); mFormatStr.Append(" @Kvar@N mapPos = @Knew@N @MVector2i@N(newTopLeftChunk.x * RB.MapChunkSize.x, newTopLeftChunk.y * RB.MapChunkSize.y) + chunkPos;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kif@N (@[email protected](@L0@N, chunkPos)) {\n"); mFormatStr.Append(" @NmyMap.LoadLayerChunk(@S\"Terrain\"@N, @L0@N, mapPos, chunkPos);\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" mTopLeftChunk = newTopLeftChunk;\n"); mFormatStr.Append("}\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@Knew@N @MVector2i@N(mCameraPos.x % chunkPixelSize.width, mCameraPos.y % chunkPixelSize.height));\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
private void DrawOutput(int x, int y) { var demo = (DemoReel)RB.Game; RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), "Output:"); DrawOutputScreen(x, y + 10); }
private void DrawDesc(int x, int y) { var demo = (DemoReel)RB.Game; mFormatStr.Set(mDesc); DemoUtil.HighlightCode(mFormatStr, mFinalStr, false); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), mFinalStr); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(1)); DrawAll(4, 4); DrawCode(4, 4); }
private void DrawCode(int x, int y) { var demo = (DemoReel)RB.Game; RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), "Source code:"); RB.DrawRectFill(new Rect2i(x, y + 10, 315, 270), DemoUtil.IndexToRGB(1)); mFormatStr.Set(mMarkedUpCode); DemoUtil.HighlightCode(mFormatStr, mFinalStr); RB.Print(new Vector2i(x + 4, y + 14), DemoUtil.IndexToRGB(5), mFinalStr); }
public void TestCldDemoParserFile() { string file = "zandemo.cld"; File.Copy(Path.Combine("Resources", file), file, true); IDemoParser parser = DemoUtil.GetDemoParser(file); Assert.IsNotNull(parser); string[] files = parser.GetRequiredFiles(); Assert.AreEqual("doom2.wad", files[0]); Assert.AreEqual("pyrrhic_.wad", files[1]); }
private void DrawTilemap(int x, int y) { if (mMap == null) { RB.Print(new Vector2i(x + 2, y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapInfinite.tmx in Unity"); return; } if (mMap.status != RB.AssetStatus.Ready) { return; } var chunkPixelSize = new Vector2i(RB.MapChunkSize.width * mSpriteSheet1.grid.cellSize.width, RB.MapChunkSize.height * mSpriteSheet1.grid.cellSize.height); // Figure out which map chunk is in the top left corner of the camera view var newTopLeftChunk = new Vector2i(mCameraPos.x / chunkPixelSize.width, mCameraPos.y / chunkPixelSize.height); if (newTopLeftChunk != mTopLeftChunk) { var shift = mTopLeftChunk - newTopLeftChunk; RB.MapShiftChunks(0, shift); for (int cy = 0; cy <= (mClipRect.height / chunkPixelSize.height) + 1; cy++) { for (int cx = 0; cx <= (mClipRect.width / chunkPixelSize.width) + 1; cx++) { var chunkPos = new Vector2i(cx * RB.MapChunkSize.x, cy * RB.MapChunkSize.y); var mapPos = new Vector2i(newTopLeftChunk.x * RB.MapChunkSize.x, newTopLeftChunk.y * RB.MapChunkSize.y) + chunkPos; mapPos.x = mapPos.x % mMap.size.width; if (RB.MapChunkEmpty(0, chunkPos)) { mMap.LoadLayerChunk("Terrain", 0, mapPos, chunkPos); } } } mTopLeftChunk = newTopLeftChunk; } mChunkCameraPos = new Vector2i(mCameraPos.x % chunkPixelSize.width, mCameraPos.y % chunkPixelSize.height); RB.CameraSet(mChunkCameraPos); RB.DrawMapLayer(0, new Vector2i(x + 1, y + 1)); RB.CameraReset(); }
private void DrawOutputScreen(int x, int y) { var demo = (DemoReel)RB.Game; RB.SpriteSheetSet(mSpriteSheet1); RB.CameraSet(new Vector2i(-x, -y)); DemoUtil.DrawOutputFrame(new Rect2i(0, 0, EXAMPLE_WIDTH, EXAMPLE_HEIGHT), 4, 2, 22); int spriteIndex = ((int)RB.Ticks / 20) % 2; RB.DrawSprite(spriteIndex, new Vector2i(120, 64)); RB.Print(new Vector2i(110, 52), DemoUtil.IndexToRGB(0), "Hi there!"); RB.CameraReset(); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; RB.Clear(DemoUtil.IndexToRGB(0)); DrawDesc(4, 4); DrawCode(4, 77); DrawOutput(350, 77); int color = 3; if ((RB.Ticks % 200 > 170 && RB.Ticks % 200 < 180) || (RB.Ticks % 200) > 190) { color = 5; } RB.Print(new Vector2i(390, 300), DemoUtil.IndexToRGB(color), "LEFT CLICK or TOUCH the screen to move to\nthe next screen, RIGHT CLICK or TOUCH with\nTWO fingers to move to previous screen."); }
private void HandleDemoChange() { if (chkDemo.Checked && cmbDemo.SelectedItem != null) { var file = cmbDemo.SelectedItem as IFileData; var parser = DemoUtil.GetDemoParser(Path.Combine(m_appConfig.DemoDirectory.GetFullPath(), file.FileName)); if (parser != null) { m_handler.Reset(); SetAdditionalFiles(true); string[] requiredFiles = parser.GetRequiredFiles(); List <string> unavailable = new List <string>(); List <IGameFile> iwads = new List <IGameFile>(); List <IGameFile> gameFiles = GetGameFiles(requiredFiles, unavailable, iwads); ctrlFiles.SetDataSource(gameFiles); if (iwads.Count > 0) { SelectedIWad = iwads.First(); } if (unavailable.Count > 0) { TextBoxForm form = new TextBoxForm(true, MessageBoxButtons.OK) { StartPosition = FormStartPosition.CenterParent, Text = "Not Found", HeaderText = "The following required files were not found:", DisplayText = string.Join(Environment.NewLine, unavailable.ToArray()) }; form.ShowDialog(this); } m_demoChangedAdditionalFiles = true; ResetSpecificFilesSelections(ctrlFiles.GetFiles().Cast <IGameFile>().ToArray()); //don't use the handler in this case, we are overriding it } } else { m_demoChangedAdditionalFiles = false; } }
private void DrawAll(int x, int y) { var demo = (DemoReel)RB.Game; var gridColor = DemoUtil.IndexToRGB(14); RB.Offscreen(mSpriteSheet1); RB.SpriteSheetSet(mSpriteSheet2); mWaveOffset = (int)((RB.Ticks / 2) % 8); RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSheetGet().grid.cellSize), new Vector2i(24, 8)); RB.Onscreen(); Rect2i clipRectOverlap = mClipRect; clipRectOverlap.width += 400; if (mMap != null) { RB.DrawRectFill(mClipRect, DemoUtil.IndexToRGB(22)); } RB.ClipSet(clipRectOverlap); DrawTilemap(mClipRect.x, mClipRect.y); RB.ClipReset(); RB.CameraReset(); // Blank out right side RB.AlphaSet(196); RB.DrawRectFill(new Rect2i(mClipRect.x + mClipRect.width, mClipRect.y, 300, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.AlphaSet(255); // Blank out left side RB.DrawRectFill(new Rect2i(0, mClipRect.y, mClipRect.x - 1, mClipRect.height), DemoUtil.IndexToRGB(1)); RB.DrawRect(mClipRect, DemoUtil.IndexToRGB(7)); if (mMap == null) { return; } RB.AlphaSet(128); mFinalStr.Set("Chunk Tile Offset:"); RB.Print(new Vector2i(mClipRect.x, mClipRect.y - 16), gridColor, mFinalStr); RB.CameraSet(mChunkCameraPos - new Vector2i(mClipRect)); int gxStart = 0; int gxEnd = gxStart + (RB.DisplaySize.width * 2); for (int gx = gxStart; gx < gxEnd; gx += RB.MapChunkSize.width * RB.SpriteSheetGet().grid.cellSize.width) { RB.DrawLine(new Vector2i(gx, -8), new Vector2i(gx, mClipRect.height + 4), gridColor); mFinalStr.Set(gx / RB.SpriteSheetGet().grid.cellSize.width); RB.Print(new Vector2i(gx + 3, -8), gridColor, mFinalStr); } RB.AlphaSet(255); RB.CameraReset(); RB.SpriteSheetSet(mSpriteSheet1); }
/// <summary> /// Render /// </summary> public override void Render() { var demo = (DemoReel)RB.Game; if (mMap != null) { RB.Clear(DemoUtil.IndexToRGB(22)); RB.DrawMapLayer(0); RB.DrawMapLayer(1); } else { RB.Print(new Vector2i(2, 210), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } RB.EffectShader(mShader1); mShader1.FloatSet("Wave", RB.Ticks / 25.0f); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, 200), DemoUtil.IndexToRGB(1)); string shaderName = "PresentRippleShader"; mFormatStr.Set("@C// Custom post-processing shader\n"); mFormatStr.Append("@NmyShader.Load(@S\"Demos/DemoReel/").Append(shaderName).Append("\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](myShader);\n"); mFormatStr.Append("@[email protected](myShader, @S\"Wave\"@N, @L").Append(RB.Ticks / 25.0f, 2).Append("f@N);\n"); mFormatStr.Append("@[email protected](@MRB@N.@[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected]();\n"); DemoUtil.HighlightCode(mFormatStr, mCodeStr); mFormatStr.Set("@C// This creates a wavy effect!\n"); mFormatStr.Append("@KShader@N \"Unlit/").Append(shaderName).Append("\" {\n"); mFormatStr.Append(" @KSubShader@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @KPass@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom shader variables here ***/\n"); mFormatStr.Append(" @Kfloat@N Wave;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Nfrag_in vert(appdata v) {\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kfloat4@N frag(v2f i) : @MSV_Target@N {\n"); mFormatStr.Append(" @C/*** Insert custom fragment shader code here ***/@N\n"); mFormatStr.Append(" @Kfloat2@N centerOffset = @L-1.0@N + @L2.0@N * i.uv.xy;\n"); mFormatStr.Append(" @Kfloat@N len = @Klength@N(centerOffset);\n"); mFormatStr.Append(" i.uv.xy += (centerOffset / len) * cos(len * @L10.0@N - Wave) * @L0.005@N;\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" @Kreturn@N color;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); DemoUtil.HighlightCode(mFormatStr, mShaderStr); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(0), mCodeStr); RB.Print(new Vector2i(304, 4), DemoUtil.IndexToRGB(0), mShaderStr); }