예제 #1
0
            public void Execute(ref WorldBound worldBound, ref Translation position)
            {
                var    voxelPosition    = worldBound.voxelPosition;
                var    chunkPosition    = VoxelRaycastSystem.GetChunkPosition(voxelPosition, worldBound.voxelDimensions);
                float3 voxelPositionMax = new float3(
                    worldBound.voxelDimensions.x * 32,  // world size
                    worldBound.voxelDimensions.y * 32,
                    worldBound.voxelDimensions.z * 32);

                if (position.Value.x > voxelPositionMax.x + worldBound.voxelDimensions.x / 2f)
                {
                    position.Value = new float3(voxelPositionMax.x + worldBound.voxelDimensions.x / 2f, position.Value.y, position.Value.z);
                }
                if (position.Value.x < -voxelPositionMax.x + worldBound.voxelDimensions.x / 2f)
                {
                    position.Value = new float3(-voxelPositionMax.x + worldBound.voxelDimensions.x / 2f, position.Value.y, position.Value.z);
                }

                if (position.Value.z > voxelPositionMax.z + worldBound.voxelDimensions.z / 2f)
                {
                    position.Value = new float3(position.Value.x, position.Value.y, voxelPositionMax.z + worldBound.voxelDimensions.z / 2f);
                }
                if (position.Value.z < -voxelPositionMax.z + worldBound.voxelDimensions.z / 2f)
                {
                    position.Value = new float3(position.Value.x, position.Value.y, -voxelPositionMax.z + worldBound.voxelDimensions.z / 2f);
                }

                if (position.Value.y < 0)
                {
                    position.Value = new float3(position.Value.x, 0, position.Value.z);
                }
            }
예제 #2
0
        private byte GetVoxelType(Voxels.World world, WorldBound worldBound, int3 voxelPosition)
        {
            var   chunkPosition = VoxelRaycastSystem.GetChunkPosition(voxelPosition, worldBound.voxelDimensions);
            Chunk chunk;

            if (GetChunk(world, chunkPosition, out chunk) && chunk.Value.voxels.Length > 0)
            {
                if (chunk.isGenerating == 1)
                {
                    return(1);
                }
                int voxelIndex = VoxelRaycastSystem.GetVoxelArrayIndex(voxelPosition - chunk.GetVoxelPosition(), worldBound.voxelDimensions);
                if (voxelIndex >= chunk.Value.voxels.Length)
                {
                    return(1);
                }
                return(chunk.Value.voxels[voxelIndex]);
            }
            return(1);
        }
예제 #3
0
        private void SetPlayerCharacter(Entity entity, int id, Entity world, int metaID, float3 position)
        {
            CharacterDatam characterDatam  = meta[metaID];
            var            voxelDimensions = new int3(16, 64, 16);

            if (worldSpawnSystem != null)
            {
                voxelDimensions = World.EntityManager.GetComponentData <Voxels.World>(world).voxelDimensions;
            }

            Inventory inventory = new Inventory {
            };

            inventory.InitializeItems(9, characterDatam.items);
            World.EntityManager.SetComponentData(entity, inventory);

            QuestLog questlog = new QuestLog {
            };

            questlog.Initialize(characterDatam.quests);
            World.EntityManager.SetComponentData(entity, questlog);

            World.EntityManager.SetComponentData(entity, new ItemHitTaker {
                radius = characterDatam.itemPickupRadius
            });
            StatbarSystem.SpawnPlayerStatbar(World.EntityManager, entity);
            ActionbarSystem.SpawnUI(World.EntityManager, entity);
            CrosshairSpawnSystem.SpawnUI(World.EntityManager, entity);
            World.EntityManager.SetComponentData(entity, new ChunkStreamPoint
            {
                world           = world,
                voxelDimensions = voxelDimensions,
                didUpdate       = 1,
                chunkPosition   = VoxelRaycastSystem.GetChunkPosition(new int3(position), voxelDimensions)
            });
        }
예제 #4
0
 protected override void OnUpdate()
 {
     Entities.WithAll <WorldBound, Translation>().ForEach((Entity e, ref WorldBound worldBound, ref Translation translation) =>
     {
         Entity worldEntity = worldBound.world;
         if (World.EntityManager.Exists(worldEntity) == false)
         {
             return;
         }
         float3 positionOfMe = translation.Value;
         if (worldBound.enabled == 0)
         {
             worldBound.worldTransform = World.EntityManager.GetComponentData <LocalToWorld>(worldEntity).Value;
             float3 newPosition2       = math.transform(math.inverse(worldBound.worldTransform), positionOfMe);
             var voxelPositionIn       = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition2);
             Chunk chunk;
             var chunkPosition      = VoxelRaycastSystem.GetChunkPosition(voxelPositionIn, worldBound.voxelDimensions);
             Voxels.World thisworld = World.EntityManager.GetComponentData <Voxels.World>(worldEntity);
             if (GetChunk(thisworld, chunkPosition, out chunk))
             {
                 if (chunk.isGenerating == 0)
                 {
                     worldBound.enabled = 1;
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 return;
             }
         }
         float3 positionOffset    = -new float3(0, math.floor(worldBound.size.y), 0); // math.floor
         float3 newPosition       = math.transform(math.inverse(worldBound.worldTransform), positionOfMe) + positionOffset;
         var voxelPosition        = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition);
         worldBound.voxelPosition = voxelPosition;
         var voxelPositionLeft    = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition + new float3(-worldBound.size.x, 0, 0));
         var voxelPositionRight   = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition + new float3(worldBound.size.x, 0, 0));
         var voxelPositionForward = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition + new float3(0, 0, worldBound.size.z));
         var voxelPositionBack    = VoxelRaycastSystem.WorldPositionToVoxelPosition(newPosition + new float3(0, 0, -worldBound.size.z));
         if (worldBound.voxelPositionLeft == voxelPositionLeft &&
             worldBound.voxelPositionRight == voxelPositionRight &&
             worldBound.voxelPositionForward == voxelPositionForward &&
             worldBound.voxelPositionBack == voxelPositionBack)
         {
             return;
         }
         worldBound.voxelPositionLeft    = voxelPositionLeft;
         worldBound.voxelPositionRight   = voxelPositionRight;
         worldBound.voxelPositionForward = voxelPositionForward;
         worldBound.voxelPositionBack    = voxelPositionBack;
         Voxels.World world               = World.EntityManager.GetComponentData <Voxels.World>(worldEntity);
         worldBound.voxelTypeLeft         = GetVoxelType(world, worldBound, voxelPositionLeft);
         worldBound.voxelTypeRight        = GetVoxelType(world, worldBound, voxelPositionRight);
         worldBound.voxelTypeForward      = GetVoxelType(world, worldBound, voxelPositionForward);
         worldBound.voxelTypeBack         = GetVoxelType(world, worldBound, voxelPositionBack);
         worldBound.voxelTypeLeftBelow    = GetVoxelType(world, worldBound, voxelPositionLeft + int3.Down());    // new float3(0, -1, 0));
         worldBound.voxelTypeRightBelow   = GetVoxelType(world, worldBound, voxelPositionRight + int3.Down());   // new float3(0, -1, 0));
         worldBound.voxelTypeForwardBelow = GetVoxelType(world, worldBound, voxelPositionForward + int3.Down()); // new float3(0, -1, 0));
         worldBound.voxelTypeBackBelow    = GetVoxelType(world, worldBound, voxelPositionBack + int3.Down());    //  new float3(0, -1, 0));
     });
 }