/// <summary> /// Generates chunk heightmap /// </summary> /// <param name="generator"></param> public void Generate(CsTerrainGenerator generator) { for (var i = -1; i < 17; i++) { for (var j = -1; j < 17; j++) { _heightmap[i + 1, j + 1] = (byte)generator.GetValue(X * 16 + i, Z * 16 + j); } } }
public RenderManager(CsTerrainGenerator generator) { _fgJobs = new ConcurrentQueue <IJob>(); _bgJobs = new ConcurrentQueue <IJob>(); _generator = generator; _shaderProgram = new DefaultShaderProgram(EmbeddedFiles.default_fs, EmbeddedFiles.default_vs); _shaderProgram.InitProgram(); _workerHandle = new EventWaitHandle(false, EventResetMode.ManualReset); CreateChunks(); }
private void OnLoad(object sender, EventArgs e) { Title = $"{EmbeddedFiles.AppName} | {EmbeddedFiles.Title_Unsaved}"; Icon = EmbeddedFiles.logo; // Set up lights const float diffuse = 0.9f; float[] matDiffuse = { diffuse, diffuse, diffuse }; GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, matDiffuse); GL.Light(LightName.Light0, LightParameter.Position, new[] { 0.0f, 0.0f, 0.0f, 10.0f }); GL.Light(LightName.Light0, LightParameter.Diffuse, new[] { diffuse, diffuse, diffuse, diffuse }); // Set up lighting GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); GL.ShadeModel(ShadingModel.Smooth); GL.Enable(EnableCap.ColorMaterial); // Set up caps GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.RescaleNormal); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.CullFace); // Set up blending GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); // Set background color GL.ClearColor(Color.FromArgb(255, 13, 13, 13)); // Init keyboard to ensure first frame won't NPE _keyboard = Keyboard.GetState(); _terrainGenerator = new CsTerrainGenerator(); _renderManager = new RenderManager(_terrainGenerator); _terrainLayerList = new RenderController(this); _terrainLayerList.Show(); _scriptWatcher = new ScriptWatcher(); _scriptWatcher.FileChanged += OnScriptChanged; Lumberjack.Info(EmbeddedFiles.Info_WindowLoaded); }
public RenderManager(GameWindow window, CsTerrainGenerator generator) { _window = window; _generator = generator; _fgJobs = new ConcurrentQueue <IJob>(); _bgJobs = new ConcurrentQueue <IJob>(); _nvg = GlNanoVg.CreateGl(NvgCreateFlags.StencilStrokes | NvgCreateFlags.AntiAlias); _ui = new KuatWindow(window, new KuatFont("sans", 16)); KuatButton b; KuatKnob k; KuatIndicator i; _ui.Controls.Add(b = new KuatButton("bTest") { Location = new Point(50, 50), Size = new Size(60, 23), Text = "Button" }); b.Click += (sender, args) => { Lumberjack.Info("Click!"); }; _ui.Controls.Add(new KuatCheckbox("cbTest") { Location = new Point(50, 90), Size = new Size(14, 14), Text = "Checkbox" }); _ui.Controls.Add(k = new KuatKnob("kTest") { Location = new Point(50, 130) }); _ui.Controls.Add(i = new KuatIndicator("iTest") { Location = new Point(120, 130) }); k.ValueChanged += (sender, args) => { i.Lit = k.Value > 0; }; _ui.Controls.Add(new KuatTextBox("tbTest") { Location = new Point(170, 90), Size = new Size(120, 23), ForeColor = Color.Black }); var rMono = _nvg.CreateFont("mono", EmbeddedFiles.ibmplexmono); if (rMono == -1) { throw new ApplicationException("Unable to load mono font"); } var rSans = _nvg.CreateFont("sans", EmbeddedFiles.ibmplexsans); if (rSans == -1) { throw new ApplicationException("Unable to load sans font"); } _perfGraphFps = new PerfGraph(GraphRenderStyle.Fps, null, 40); _framebuffer = new Framebuffer(8); _framebuffer.Init(window.Width, window.Height); _framebufferUi = new Framebuffer(1); _framebufferUi.Init(window.Width, window.Height); _texRandom = LoadGlTexture(EmbeddedFiles.random); _shaderModel = new ShaderProgram(EmbeddedFiles.fs_model, EmbeddedFiles.vs_model); _shaderModel.Init(); _shaderScreen = new ShaderProgram(EmbeddedFiles.fs_screen, EmbeddedFiles.vs_screen); _shaderScreen.Init(); _workerHandle = new EventWaitHandle(false, EventResetMode.ManualReset); CreateChunks(); CreateScreenVao(); }
public JobRebuildChunks(CsTerrainGenerator generator) { _generator = generator; }
public JobPregenerateChunks(CsTerrainGenerator generator) { _generator = generator; }