Example #1
0
        private void TestEntityState(Simulation ecs, int expectedMemoryConsumption, out MemoryResource memoryResource)
        {
            Assert.That(ecs.Entities.Count, Is.EqualTo(2), "Entity count incorrect at initialization");

            var system = ecs.Entities[1];

            Assert.That(system.HasComponent <Subsystem>(), "First entity does not have subsystem component");

            var item = ecs.Entities[2];

            Assert.That(item.HasComponent <IItemType>(), "Second entity does not have item component");

            ItemStorage itemStorage;

            Assert.That(system.TryGetComponent(out itemStorage), "System does not have ItemSTorage component");
            Assert.That(itemStorage.Items[0], Is.Not.Null, "Item storage not initialized");
            Assert.That(itemStorage.Items[0].Item.HasValue, "Item storage location 0 has not item");
            Assert.That(itemStorage.Items[0].Item.Value, Is.EqualTo(item.Id), "Item storage item id mismatch");

            ConsumeMemory consumeMemory;

            Assert.That(item.TryGetComponent(out consumeMemory), "Item does not have ConsumeMemory component");
            Assert.That(consumeMemory.Value, Is.EqualTo(SimulationConstants.ItemMemoryConsumption), "ConsumeMemory initial value incorrect");

            Assert.That(system.TryGetComponent(out memoryResource), "System does not have MemoryResource component");
            Assert.That(memoryResource.Maximum, Is.EqualTo(SimulationConstants.SubsystemMaxMemory), "System memory resource");

            Assert.That(memoryResource.Value, Is.EqualTo(expectedMemoryConsumption), "System memory resource initial value incorrect");
        }
Example #2
0
        /// <summary>
        /// Initializes a <see cref="FlatMapKeyValueStore{T}"/>. Reads and writes the store to and from the file imkvdb.arc
        /// in the specified <paramref name="rootPath"/> directory. This directory must exist when calling <see cref="Initialize"/>,
        /// but it is not required for the imkvdb.arc file to exist.
        /// </summary>
        /// <param name="fsClient">The <see cref="FileSystemClient"/> to use for reading and writing the archive.</param>
        /// <param name="rootPath">The directory path used to load and save the archive file. Directory must already exist.</param>
        /// <param name="capacity">The maximum number of entries that can be stored.</param>
        /// <param name="memoryResource"><see cref="MemoryResource"/> for allocating buffers to hold entries and values.</param>
        /// <param name="autoBufferMemoryResource"><see cref="MemoryResource"/> for allocating temporary buffers
        /// when reading and writing the store to a file.</param>
        /// <returns>The <see cref="Result"/> of the operation.</returns>
        public Result Initialize(FileSystemClient fsClient, U8Span rootPath, int capacity,
                                 MemoryResource memoryResource, MemoryResource autoBufferMemoryResource)
        {
            // The root path must be an existing directory
            Result rc = fsClient.GetEntryType(out DirectoryEntryType rootEntryType, rootPath);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (rootEntryType == DirectoryEntryType.File)
            {
                return(ResultFs.PathNotFound.Log());
            }

            var sb = new U8StringBuilder(_archivePath.Get());

            sb.Append(rootPath).Append(ArchiveFileName);

            rc = _index.Initialize(capacity, memoryResource);
            if (rc.IsFailure())
            {
                return(rc);
            }

            _fsClient       = fsClient;
            _memoryResource = memoryResource;
            _memoryResourceForAutoBuffers = autoBufferMemoryResource;

            return(Result.Success);
        }
Example #3
0
        public SaveDataIndexerManager(FileSystemClient fsClient, ulong saveDataId, MemoryResource memoryResource,
                                      IDeviceHandleManager sdCardHandleManager, bool isBisUserRedirectionEnabled)
        {
            FsClient                    = fsClient;
            SaveDataId                  = saveDataId;
            MemoryResource              = memoryResource;
            _sdCardHandleManager        = sdCardHandleManager;
            IsBisUserRedirectionEnabled = isBisUserRedirectionEnabled;

            _tempIndexer.Indexer = new SaveDataIndexerLite();
        }
Example #4
0
        public Result Initialize(long size, MemoryResource memoryResource)
        {
            MemoryResource.Buffer buffer = memoryResource.Allocate(size, Alignment);
            if (!buffer.IsValid)
            {
                return(ResultKvdb.AllocationFailed.Log());
            }

            _memoryResource = memoryResource;
            _buffer         = buffer;

            return(Result.Success);
        }
Example #5
0
        public SaveDataIndexer(FileSystemClient fsClient, U8Span mountName, SaveDataSpaceId spaceId, ulong saveDataId, MemoryResource memoryResource)
        {
            FsClient       = fsClient;
            SaveDataId     = saveDataId;
            SpaceId        = spaceId;
            MemoryResource = memoryResource;

            // note: FS uses a separate PooledBufferMemoryResource here
            BufferMemoryResource = memoryResource;

            KvDatabase = new FlatMapKeyValueStore <SaveDataAttribute>();

            IsInitialized = false;
            IsKvdbLoaded  = false;
            Handle        = 1;

            MountName = mountName.ToU8String();
        }
Example #6
0
 protected void given_remote_resource(string uri, MemoryResource resource)
 {
     Client.Resources[uri.ToUri()] = resource;
 }
Example #7
0
 protected override bool DoIsEqual(MemoryResource other)
 {
     return(ReferenceEquals(this, other));
 }