<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace Game.Model
{
	public class World
	{
		private readonly VoxelArray voxels;

		private readonly MaterialMap materialMap;

		private List<VertexBuffer> vbs;

		private int voxelVersion = -1;

		public World(VoxelArray voxels,MaterialMap materialMap)
		{
			this.voxels = voxels;
			this.materialMap = materialMap;
		}

		public int SizeX
		{
			get
			{
				return voxels.SizeX;
			}
		}

		public int SizeY
		{
			get
			{
				return voxels.SizeY;
			}
		}
		public int SizeZ
		{
			get
			{
				return voxels.SizeZ;
			}
		}

		public WorldMaterial GetMaterialAt(int x, int y, int z)
		{
			return materialMap[voxels[x, y, z]];
		}

		public void Render(float opacity)
		{
			EnsureVertexBuffers();
			foreach (var vertexBuffer in vbs)
			{
				var worldMaterial = materialMap[vertexBuffer.material];
				if (opacity > 0)
				{
					GL.Disable(EnableCap.Texture2D);
				}
				else
				{
					if (worldMaterial.Texture != null)
					{
						worldMaterial.Texture.Set(0);
					}
					else
					{
						GL.Disable(EnableCap.Texture2D);
					}
				}
				GL.CullFace(CullFaceMode.Back);
				GL.Enable(EnableCap.CullFace);
				GL.Enable(EnableCap.DepthTest);
				vertexBuffer.Enable();
				GL.DrawArrays(BeginMode.Quads, 0, vertexBuffer.Count);
				vertexBuffer.Disable();
			}
			//for (int i = 0; i < 256; i++)
			//{

			//	var vertexBufferItems = vblist[i];
			//	if (vertexBufferItems != null)
			//	{
			//		//GL.CullFace(CullFaceMode.Front);
			//		//GL.Enable(EnableCap.CullFace);
			//		var worldMaterial = materialMap[i];
			//		if (worldMaterial.Texture != null)
			//		{
			//			worldMaterial.Texture.Set(0);
			//		}
			//		else
			//		{
			//			GL.Disable(EnableCap.Texture2D);
			//		}
			//		//GL.Begin(BeginMode.Quads);
			//		//foreach (var vertexBufferItem in vertexBufferItems)
			//		//{
			//		//	GL.Color4(vertexBufferItem.Color4);
			//		//	GL.TexCoord2(vertexBufferItem.UV);
			//		//	GL.Vertex3(vertexBufferItem.Pos);
			//		//}
			//		//GL.End();
			//	}
			//}
		}

		private void EnsureVertexBuffers()
		{
			if (voxelVersion == voxels.Version && vbs != null)
				return;
			if (vbs != null)
			{
				foreach (var vertexBuffer in vbs)
				{
					vertexBuffer.Dispose();
				}
				vbs = null;
			}
			voxelVersion = voxels.Version;
			Vector2[] quadUv = new Vector2[]
				{
					new Vector2(0, 0),<commit_msg>no message<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace Game.Model
{
	public class World
	{
		private readonly VoxelArray voxels;

		private readonly MaterialMap materialMap;

		private List<VertexBuffer> vbs;

		private int voxelVersion = -1;

		public World(VoxelArray voxels,MaterialMap materialMap)
		{
			this.voxels = voxels;
			this.materialMap = materialMap;
		}

		public int SizeX
		{
			get
			{
				return voxels.SizeX;
			}
		}

		public int SizeY
		{
			get
			{
				return voxels.SizeY;
			}
		}
		public int SizeZ
		{
			get
			{
				return voxels.SizeZ;
			}
		}

		public WorldMaterial GetMaterialAt(int x, int y, int z)
		{
			return materialMap[voxels[x, y, z]];
		}

		public void Render(float opacity)
		{
			EnsureVertexBuffers();
			foreach (var vertexBuffer in vbs)
			{
				var worldMaterial = materialMap[vertexBuffer.material];
				if (opacity > 0)
				{
					GL.Disable(EnableCap.Texture2D);
				}
				else
				{
					if (worldMaterial.Texture != null)
					{
						worldMaterial.Texture.Set(0);
					}
					else
					{
						GL.Disable(EnableCap.Texture2D);
					}
				}
				GL.CullFace(CullFaceMode.Back);
				GL.Enable(EnableCap.CullFace);
				GL.Enable(EnableCap.DepthTest);
				vertexBuffer.Enable();
				GL.DrawArrays(BeginMode.Quads, 0, vertexBuffer.Count);
				vertexBuffer.Disable();
			}

		}

		private void EnsureVertexBuffers()
		{
			if (voxelVersion == voxels.Version && vbs != null)
				return;
			if (vbs != null)
			{
				foreach (var vertexBuffer in vbs)
				{
					vertexBuffer.Dispose();
				}
				vbs = null;
			}
			voxelVersion = voxels.Version;
			Vector2[] quadUv = new Vector2[]
				{
					new Vector2(0, 0),
{'fraction_non_alphanumeric': 0.12343143965320556, 'fraction_numerical': 0.00730093543235227, 'mean_word_length': 2.4932270916334662, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5960491', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1567, 'n_words': 304}