public void Build(DrawCallBatcher batcher, ref BlockData block, BlockFace face, bool backFace, ref Vector3[] vecs, LocalPools pools) { int iface = (int)face; // Randomize the color a bit Color32 color = BlockDatabase.GetBlockInfo(block.BlockType).Color; if (block.BlockType != BlockType.None) { float value = m_noise.GetValue(vecs[0] + vecs[1] + vecs[2] + vecs[3]); // -1.0f..1.0f float noise = (255.0f * value) * 0.02f; // Deviation of 0.02f points from the original int n = (int)noise; byte r = (byte)Math.Max(0, Math.Min(color.r + n, 255)); byte g = (byte)Math.Max(0, Math.Min(color.g + n, 255)); byte b = (byte)Math.Max(0, Math.Min(color.b + n, 255)); color = new Color32(r, g, b, color.a); } VertexData[] vertexData = pools.PopVertexDataArray(4); for (int i = 0; i < 4; i++) { VertexData data = vertexData[i] = pools.PopVertexData(); data.Vertex = vecs[i]; data.Color = color; data.UV = AddFaceUV(i, GetTexture(iface), backFace); data.Normal = SNormals[iface][i]; } batcher.AddFace(vertexData, backFace); pools.PushVertexDataArray(vertexData); }
public NumbersViewModel(Numbers num) { var dbNum = new BlockDatabase("PhoneNumber"); // Creates (if does not exist) a database named People dbNum.CreateTable <Numbers>(); dbNum.SaveItem <Numbers>(num); }
public MeshArchitect(int size, Block[,,] blocks, BlockDatabase blockDatabase) { this.size = size; this.blocks = blocks; this.vertices = new List <Vector3>(); this.triangles = new List <int>(); this.uv = new List <Vector2> (); this.blockDatabase = blockDatabase; //this.colliderPositions = new List<Vector3i> (); for (int x = 0; x < this.size; x++) { for (int z = 0; z < this.size; z++) { for (int y = 0; y < this.size; y++) { byte blockType = this.blocks [x, y, z].type; if (!this.blockDatabase.blockMaterials[blockType].transparent) { CreateVoxel(new Vector3i(x, y, z), blockType); } } } } }
private void Awake() { if (!instance) { instance = this; } }
Vector3 mousePos; //Where the mouse is // Start is called before the first frame update void Start() { hand = GameObject.FindGameObjectWithTag("Hand").transform; gameController = GameObject.FindGameObjectWithTag("GameController"); db = gameController.GetComponent <ElementDatabase>(); cam = GameObject.FindGameObjectWithTag("FPSCam").GetComponent <Camera>(); environment = GameObject.FindGameObjectWithTag("Environment"); blockLocations = gameController.GetComponent <BlockDatabase>(); }
public void SpawnPlayer(Vector3 positionToSpawn, BlockDatabase database, WorldGenerator world, GameManager manager) { blockDatabase = database; worldGenerator = world; gameManager = manager; Position = positionToSpawn; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
void Awake() { hand = GameObject.FindGameObjectWithTag("GodHand").transform; gameController = GameObject.FindGameObjectWithTag("GameController"); db = gameController.GetComponent <ElementDatabase>(); cam = GameObject.FindGameObjectWithTag("GodCam").GetComponent <Camera>(); environment = GameObject.FindGameObjectWithTag("Environment"); blockLocations = gameController.GetComponent <BlockDatabase>(); layerMask = layermask_to_layer(layer); }
public Chunk(ChunkCoord chunkCoord, WorldGenerator world, BlockDatabase database, EntityManager manager, GameManager GM) { Coord = chunkCoord; blockDatabase = database; entityManager = manager; worldGenerator = world; gameManager = GM; // Create the entity InstantiateChunk(new int3(Coord.x * VoxelData.ChunkSize.x, 0, Coord.z * VoxelData.ChunkSize.z)); }
private void Slot_onNumChanged(int id) { for (var i = 0; i < slots.Count; i++) { if (inventory.itemSlots[i].block == BlockDatabase.GetBlockName(id)) { slots[i].transform.Find("Number Text").GetComponent <TextMeshProUGUI>().text = inventory.itemSlots[i].num.ToString(); return; } } }
private void DragDrop_onTileDiscarded(int id) { for (var i = 0; i < itemSlots.Count; i++) { if (itemSlots[i].block == BlockDatabase.GetBlockName(id)) { itemSlots[i].UpdateNum(1); return; } } }
public static BlockDatabase LoadDatabase(string path) { BlockDatabase blockDatabase = new BlockDatabase(); foreach (BlockResourceItem resourceItem in Resources.LoadAll <BlockResourceItem>(path)) { blockDatabase.blocks.Add(resourceItem); } return(blockDatabase); }
public static List <string> GetNumberFromTable(string str) { List <string> getNumList = new List <string>(); var dbNum = new BlockDatabase(str); // Creates (if does not exist) a database named People List <Numbers> temp = dbNum.Query <Numbers>("select * from Numbers where blockType = 'blockThisNumber'"); foreach (Numbers num in temp) { getNumList.Add(num.number); } return(getNumList); }
private void Start() { if (!instance) { instance = this; DontDestroyOnLoad(this); StartCoroutine(LoadBlocks()); } else { Destroy(gameObject); } }
protected override void OnHandleIntent(Intent intent) { string blockType = intent.GetStringExtra("blockType"); List <string> getNumList; getNumList = new List <string>(); var dbNum = new BlockDatabase("PhoneNumber"); // Creates (if does not exist) a database named People List <Numbers> temp = dbNum.Query <Numbers>("select * from Numbers where blockType = '" + blockType + "'"); foreach (Numbers num in temp) { getNumList.Add(num.number); } }
private void Awake() { if (instance != null) { Debug.LogWarning("More then on instance of - BlockDatabase on (" + instance.gameObject.name + ") Gameobject"); return; } else { instance = this; } GetDatabase("Assets/Resources/BlockData.txt"); }
public static bool CastVoxel(Vector3 position, Vector3 direction, float distance, out RayVoxelOut output) { RayVoxelOut op = new RayVoxelOut(); Vector3 curPos = position; Vector3 lastPos = new Vector3(); float distTravelled = 0; World world = World.GetInstance(); while (distTravelled < distance) { var chunkPos = curPos.ToChunkPosition(); var pos = curPos.ToChunkSpaceFloored(); if (world.TryGetChunkAtPosition((int)chunkPos.X, (int)chunkPos.Z, out Chunk chunk)) { var possibleBlock = BlockDatabase.GetBlock(chunk.GetBlockID((int)(pos.X), (int)(pos.Y), (int)(pos.Z))); if (possibleBlock?.CollisionShape != null) { var blockPos = (chunkPos * Chunk.WIDTH) + pos; //var flooredCurPos = new Vector3((float)Math.Floor(curPos.X), (float)Math.Floor(curPos.Y), (float)Math.Floor(curPos.Z)); if (possibleBlock.CollisionShape.IntersectsForcedOffset(blockPos, curPos)) { op.BlockID = (short)possibleBlock.ID; op.BlockPosition = new Vector3((int)(pos.X), (int)(pos.Y), (int)(pos.Z)); op.ChunkPosition = new Vector2((int)chunkPos.X, (int)chunkPos.Z); var placeChunk = lastPos.ToChunkPosition(); var placePos = lastPos.ToChunkSpaceFloored(); op.PlacementPosition = new Vector3((int)(placePos.X), (int)(placePos.Y), (int)(placePos.Z)); op.PlacementChunk = new Vector2((int)placeChunk.X, (int)placeChunk.Z); output = op; return(true); } } } lastPos = curPos; curPos += direction * stepSize; distTravelled += stepSize; } output = default; return(false); }
public static void CheckDatabase(BlockDatabase database) { foreach (string name in Enum.GetNames(typeof(Blocks))) { Blocks block = (Blocks)Enum.Parse(typeof(Blocks), name); int count = database.blocks.FindAll(x => x.type == block).Count; if (count == 0) { Debug.LogWarning($"{name} resource hasn't found"); } else if (count > 1) { Debug.LogWarning($"Found more that one block {name}"); } } }
public void Initialize(Vector3i position, World world) { this.position = position; this.size = world.GetChunkSize(); this.blockDatabase = world.blockDatabase; this.worldPosition = position.Multiply(this.size); this.blocks = new Block[this.size, this.size, this.size]; Dictionary <Vector3i, byte> blocks; bool hasChanges = world.HasChunkChanges(this.position, out blocks); for (int x = 0; x < this.size; x++) { for (int z = 0; z < this.size; z++) { int terrainHeight = GetHeight(x + this.worldPosition.x, z + this.worldPosition.z, world.GetWorldSeed()); for (int y = 0; y < this.size; y++) { byte blockType; this.blocks [x, y, z] = new Block(); if (hasChanges && blocks.TryGetValue(new Vector3i(x, y, z), out blockType)) { //print ("OK"); } else { blockType = 0; if (y < terrainHeight) { blockType = GetType(x + this.worldPosition.x, y + this.worldPosition.y, z + this.worldPosition.z, world.GetWorldSeed()); } } this.blocks [x, y, z].type = blockType; this.blocks [x, y, z].health = this.blockDatabase.blockMaterials [blockType].hardness; } } } MeshArchitect meshArchitect = new MeshArchitect(this.size, this.blocks, this.blockDatabase); GetComponent <MeshRenderer> ().material = this.blockDatabase.materialAtlas; UpdateMesh(meshArchitect); }
void Update() { Movement(); delayTimer += Time.deltaTime; if (delayTimer >= moveDelay) { delayTimer = 0; FindNextTile(); int nextValue; GameAssets.i.tileGrid.GetComponent <TileGrid>().gridSystem.GetValue(nextTile, out nextValue); //Debug.Log(nextValue); //GameAssets.i.tileGrid.GetComponent<TileGrid>().gridSystem.SetValue(nextTile, 3); if (nextValue != BlockDatabase.GetBlockID(Blocks.Barrier) && move) { transform.position += new Vector3(vectorDirection.x, vectorDirection.y, 0); //Grid movement } if (nextValue == 0) { Respawn(); } } }
void InputDestroyBlock() { if (!controlsEnabled) { return; } if (Raycast.CastVoxel(currentWorld.WorldCamera.Position, currentWorld.WorldCamera.GetForward(), 5, out RayVoxelOut op)) { if (currentWorld.TryGetChunkAtPosition((int)op.ChunkPosition.X, (int)op.ChunkPosition.Y, out Chunk chunk)) { chunk.DestroyBlock((int)op.BlockPosition.X, (int)op.BlockPosition.Y, (int)op.BlockPosition.Z); var chunkWp = (op.ChunkPosition * Chunk.WIDTH); var wp = new Vector3(chunkWp.X, 0, chunkWp.Y) + op.BlockPosition; BlockDatabase.GetBlock(op.BlockID).OnBreak(wp, op.ChunkPosition); currentWorld.RequestChunkUpdate(chunk, true, (int)op.BlockPosition.X, (int)op.BlockPosition.Z); } } }
public void UpdateNum(int amount) { num += amount; onNumChanged?.Invoke(BlockDatabase.GetBlockID(block)); }
public override bool IntersectsWorldDirectional(Rigidbody body, Vector3 direction) { //Bottom bool BottomBackLeft() { var pos = body.Owner.Position + new Vector3(Min.X, Min.Y, Min.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool BottomBackRight() { var pos = body.Owner.Position + new Vector3(Max.X, Min.Y, Min.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool BottomFrontLeft() { var pos = body.Owner.Position + new Vector3(Min.X, Min.Y, Max.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool BottomFrontRight() { var pos = body.Owner.Position + new Vector3(Max.X, Min.Y, Max.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } //Top bool TopBackLeft() { var pos = body.Owner.Position + new Vector3(Min.X, Max.Y, Min.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool TopBackRight() { var pos = body.Owner.Position + new Vector3(Max.X, Max.Y, Min.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool TopFrontLeft() { var pos = body.Owner.Position + new Vector3(Min.X, Max.Y, Max.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool TopFrontRight() { var pos = body.Owner.Position + new Vector3(Max.X, Max.Y, Max.Z) + direction; var chunkPosition = (pos).ToChunkPosition(); var posInChunk = (pos).ToChunkSpaceFloored(); return(DoPos(chunkPosition, posInChunk)); } bool DoPos(Vector3 chunkPosition, Vector3 posInChunk) { if (World.GetInstance().TryGetChunkAtPosition((int)chunkPosition.X, (int)chunkPosition.Z, out Chunk chunk)) { short id = chunk.GetBlockID((int)(posInChunk.X), (int)(posInChunk.Y), (int)(posInChunk.Z)); if (id == 0) { return(false); } Block block = BlockDatabase.GetBlock(id); if (block == null) { return(false); } if (block.CollisionShape != null) { var blockPos = (chunkPosition * Chunk.WIDTH) + posInChunk; return(block.CollisionShape.IntersectsForcedOffset(this, body, blockPos - direction)); } return(false); } return(false); } if (!(direction.X == 0 && direction.Z == 0 && direction.Y > 0)) { if (BottomBackLeft()) { return(true); } if (BottomBackRight()) { return(true); } if (BottomFrontLeft()) { return(true); } if (BottomFrontRight()) { return(true); } } if (direction.Y >= 0) { direction.Y = -direction.Y; if (TopBackLeft()) { return(true); } if (TopBackRight()) { return(true); } if (TopFrontLeft()) { return(true); } if (TopFrontRight()) { return(true); } } return(false); }
public override void BuildMesh( Map map, DrawCallBatcher batcher, int offsetX, int offsetY, int offsetZ, int minX, int maxX, int minY, int maxY, int minZ, int maxZ, int lod, LocalPools pools ) { BlockFace face = 0; int stepSize = 1 << lod; Assert.IsTrue(lod <= EngineSettings.ChunkConfig.LogSize); // LOD can't be bigger than chunk size int width = EngineSettings.ChunkConfig.Size >> lod; int[] mins = { minX >> lod, minY >> lod, minZ >> lod }; int[] maxes = { maxX >> lod, maxY >> lod, maxZ >> lod }; int[] x = { 0, 0, 0 }; // Relative position of a block int[] xx = { 0, 0, 0 }; // Relative position of a block after applying lod int[] q = { 0, 0, 0 }; // Direction in which we compare neighbors when building mask (q[d] is our current direction) int[] du = { 0, 0, 0 }; // Width in a given dimension (du[u] is our current dimension) int[] dv = { 0, 0, 0 }; // Height in a given dimension (dv[v] is our current dimension) int[] s = { map.VoxelLogScaleX, map.VoxelLogScaleY, map.VoxelLogScaleZ }; // Scale in each dimension BlockData[] mask = pools.PopBlockDataArray(width * width); Vector3[] vecs = pools.PopVector3Array(4); // Iterate over 3 dimensions. Once for front faces, once for back faces for (int dd = 0; dd < 2 * 3; dd++) { int d = dd % 3; int u = (d + 1) % 3; int v = (d + 2) % 3; x[0] = 0; x[1] = 0; x[2] = 0; q[0] = 0; q[1] = 0; q[2] = 0; q[d] = stepSize << s[d]; // Determine which side we're meshing bool backFace = dd < 3; switch (dd) { case 0: face = BlockFace.Left; break; case 3: face = BlockFace.Right; break; case 1: face = BlockFace.Bottom; break; case 4: face = BlockFace.Top; break; case 2: face = BlockFace.Back; break; case 5: face = BlockFace.Front; break; } // Move through the dimension from front to back for (x[d] = mins[d] - 1; x[d] <= maxes[d];) { // Compute the mask int n = 0; for (x[v] = 0; x[v] < mins[v]; x[v]++) { for (x[u] = 0; x[u] < width; x[u]++) { mask[n++] = BlockData.Air; } } for (x[v] = mins[v]; x[v] <= maxes[v]; x[v]++) { for (x[u] = 0; x[u] < mins[u]; x[u]++) { mask[n++] = BlockData.Air; } for (x[u] = mins[u]; x[u] <= maxes[u]; x[u]++) { int realX = (x[0] << lod << s[0]) + offsetX; int realY = (x[1] << lod << s[1]) + offsetY; int realZ = (x[2] << lod << s[2]) + offsetZ; BlockData voxelFace0 = map.GetBlock(realX, realY, realZ); BlockData voxelFace1 = map.GetBlock(realX + q[0], realY + q[1], realZ + q[2]); mask[n++] = (voxelFace0.IsSolid() && voxelFace1.IsSolid()) ? BlockData.Air : (backFace ? voxelFace1 : voxelFace0); } for (x[u] = maxes[u] + 1; x[u] < width; x[u]++) { mask[n++] = BlockData.Air; } } for (x[v] = maxes[v] + 1; x[v] < width; x[v]++) { for (x[u] = 0; x[u] < width; x[u]++) { mask[n++] = BlockData.Air; } } x[d]++; n = 0; // Build faces from the mask if it's possible int j; for (j = 0; j < width; j++) { int i; for (i = 0; i < width;) { if (mask[n].IsEmpty()) { i++; n++; continue; } BlockType type = mask[n].BlockType; // Compute width int w; for (w = 1; i + w < width && mask[n + w].BlockType == type; w++) { } // Compute height bool done = false; int k; int h; for (h = 1; j + h < width; h++) { for (k = 0; k < w; k++) { if ( mask[n + k + h * width].IsEmpty() || mask[n + k + h * width].BlockType != type ) { done = true; break; } } if (done) { break; } } // Determine whether we really want to build this face // TODO: Skip bottom faces at the bottom of the world bool buildFace = true; if (buildFace) { // Prepare face coordinates and dimensions x[u] = i; x[v] = j; xx[0] = ((x[0] << lod) << s[0]) + offsetX; xx[1] = ((x[1] << lod) << s[1]) + offsetY; xx[2] = ((x[2] << lod) << s[2]) + offsetZ; du[0] = du[1] = du[2] = 0; dv[0] = dv[1] = dv[2] = 0; du[u] = (w << lod) << s[u]; dv[v] = (h << lod) << s[v]; // Face vertices Vector3Int v1 = new Vector3Int( xx[0], xx[1], xx[2] ); Vector3Int v2 = new Vector3Int( xx[0] + du[0], xx[1] + du[1], xx[2] + du[2] ); Vector3Int v3 = new Vector3Int( xx[0] + du[0] + dv[0], xx[1] + du[1] + dv[1], xx[2] + du[2] + dv[2] ); Vector3Int v4 = new Vector3Int( xx[0] + dv[0], xx[1] + dv[1], xx[2] + dv[2] ); // Face vertices transformed to world coordinates // 0--1 // | | // | | // 3--2 vecs[0] = new Vector3(v4.X, v4.Y, v4.Z); vecs[1] = new Vector3(v3.X, v3.Y, v3.Z); vecs[2] = new Vector3(v2.X, v2.Y, v2.Z); vecs[3] = new Vector3(v1.X, v1.Y, v1.Z); // Build the face IFaceBuilder builder = BlockDatabase.GetFaceBuilder(type); builder.Build(batcher, ref mask[n], face, backFace, ref vecs, pools); } // Zero out the mask int l; for (l = 0; l < h; ++l) { for (k = 0; k < w; ++k) { mask[n + k + l * width] = BlockData.Air; } } i += w; n += w; } } } } pools.PushBlockDataArray(mask); pools.PushVector3Array(vecs); }
private static void CheckDatabase() { BlockDatabase database = ResourceUtility.Blocks; BlockDatabase.CheckDatabase(database); }
public bool IsSolid() { return(BlockDatabase.GetBlockInfo(BlockType).IsSolid); }
public Block() { BlockDatabase.RegisterBlock(this); }
public static List <Numbers> GetDataFromTable(string str) { var dbNum = new BlockDatabase(str); // Creates (if does not exist) a database named People return(dbNum.GetItems <Numbers>()); }