示例#1
0
 public MultiLevelVoxelMap2D(int sizeX, int sizeY, int numLayers)
 {
     _sizeX  = sizeX;
     _sizeY  = sizeY;
     _sizeZ  = numLayers;
     _layers = new VoxelMap2DLayer[_sizeZ];
     for (int i = 0; i < _sizeZ; ++i)
     {
         _layers [i] = new VoxelMap2DLayer(_sizeX, _sizeY);
     }
 }
示例#2
0
    //TODO maybe replace this with an arbitrary query instead of searching just by position
    //for example we might search for a list of all sources of danger within some distance
    public List <IPlaceable> GetContent(Position position)
    {
        Position3D position3D = GetPosition3D(position);

        if (position3D == null)
        {
            Debug.Log("not a position3d");
            return(null);
        }
        VoxelMap2DLayer layer = _layers[position3D.GetZ()];

        return(layer == null ? new List <IPlaceable> () : layer.GetContent(position));
    }
示例#3
0
    public bool Place(IPlaceable placeable, Position position)
    {
        Position3D position3D = position.AsPosition3D();

        if (!CanPlace(placeable, position, position3D))
        {
            return(false);
        }
        bool            addedSuccessfully = true;
        VoxelMap2DLayer layer             = _layers [position3D.GetZ()];

        if (layer == null)
        {
            layer = new VoxelMap2DLayer(_sizeX, _sizeY);
        }
        addedSuccessfully = addedSuccessfully && layer.Place(placeable, (Position)position3D);     //TODO this is sligthly inefficient because the check happens at both the 3D map and the 2D slice...
        System.Diagnostics.Debug.Assert(addedSuccessfully, "3D map and 2D slice should match in terms of whether or not this can be added");
        return(addedSuccessfully);
    }