예제 #1
0
        public EditableMatrixImage2i(Vector2i size, IImageSampler2i sampler, IImageConstraint2i constraint)
        {
            _constraint = constraint;
            _sampler    = sampler;

            _editableMatrix = new Matrix <int>(size);
            FixImage(new Rect2i(0, 0, size.x, size.y), Direction.Unknown);
        }
예제 #2
0
        private void Initialize()
        {
            _editableImageConstraint = new TycoonTileConstraint2i();
            _sampler = new DualImageSampler2i();

            _terrainGenerator = new TerrainGenerator2i <TerrainMesher2i>();
            _meshUpdater      = new TerrainMeshUpdater();
            _groupsSelector   = new GroupsByCameraVisibilitySelector();
            _imageProvider    = new EditableMatrixImage2i(InitialTexture, InitialTextureScale, _sampler, _editableImageConstraint);
        }
예제 #3
0
        public SceneContext(
            IGroupSelector groupSelector,
            ITerrainGenerator2i terrainGenerator,
            IMeshUpdater meshUpdater,
            Vector3 cameraPosition,
            IReadOnlyList <Plane> cameraPlanes,
            IReadOnlyPooledList <Vector3> cameraFrustumCorners,
            Matrix4x4 cameraLocalToWorldMatrix,
            Matrix4x4 parentContainerWorldToLocalMatrix,
            IReadOnlySet <Vector2i> existingGroups,
            Vector2i cellInGroupCount,
            IImage2i image,
            Rect2i invalidatedArea_imageSpace,
            IImageSampler2i imageSampler,
            Func <GameObject> gameObjectFactory,
            ProfilerFactoryDelegate profilerFactory,
            LoggerFactoryDelegate loggerFactory)
        {
            GroupSelector                     = groupSelector;
            TerrainGenerator                  = terrainGenerator;
            MeshUpdater                       = meshUpdater;
            CameraPosition                    = cameraPosition;
            CameraPlanes                      = cameraPlanes;
            CameraFrustumCorners              = cameraFrustumCorners;
            CameraLocalToWorldMatrix          = cameraLocalToWorldMatrix;
            ParentContainerWorldToLocalMatrix = parentContainerWorldToLocalMatrix;
            ExistingGroups                    = existingGroups;
            CellInGroupCount                  = cellInGroupCount;
            Image             = image;
            ImageSampler      = imageSampler;
            GameObjectFactory = gameObjectFactory;
            ProfilerFactory   = profilerFactory;
            LoggerFactory     = loggerFactory;

            RangeZ      = image.RangeZ;
            GroupBounds = new Bounds(new Vector3(CellInGroupCount.x / 2.0f, CellInGroupCount.y / 2.0f, RangeZ.Center), new Vector3(CellInGroupCount.x, CellInGroupCount.y, RangeZ.Size));
            InvalidatedArea_worldSpace = ImageSampler
                                         .ImageToWorld(invalidatedArea_imageSpace)
                                         .RoundToContain();

            (Image as IInitializableImage)?.StartUsing();
        }
예제 #4
0
        private void DisposeService()
        {
            (_imageProvider as IDisposable)?.Dispose();
            _imageProvider = null;

            (_editableImageConstraint as IDisposable)?.Dispose();
            _editableImageConstraint = null;

            (_sampler as IDisposable)?.Dispose();
            _sampler = null;

            (_terrainGenerator as IDisposable)?.Dispose();
            _terrainGenerator = null;

            (_meshUpdater as IDisposable)?.Dispose();
            _meshUpdater = null;

            (_groupsSelector as IDisposable)?.Dispose();
            _groupsSelector = null;
        }
예제 #5
0
        public EditableMatrixImage2i(Texture2D texture, float scale, IImageSampler2i sampler, IImageConstraint2i constraint)
        {
            _constraint = constraint;
            _sampler    = sampler;

            int width  = texture.width;
            int height = texture.height;

            var size = new Vector2i(width, height);

            _editableMatrix = new Matrix <int>(size);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    _editableMatrix[x, y] = (int)(texture.GetPixel(x, y).grayscale *scale);
                }
            }
            FixImage(new Rect2i(0, 0, size.x, size.y), Direction.Unknown);
        }
예제 #6
0
 public static Rect ImageToWorld(this IImageSampler2i sampler, Rect2i rect)
 {
     var min = sampler.ImageToWorld(rect.min);
     var max = sampler.ImageToWorld(rect.max);
     return Rect.MinMaxRect(min.x, min.y, max.x, max.y);
 }