/// <see cref="IComponent.Start"/> public void Start() { /// Collect the heap types defined in the heap type containers List <HeapType> heapTypes = new List <HeapType>(); foreach (Assembly container in this.heapTypeContainers) { foreach (Type type in container.GetTypes()) { if (type.IsSubclassOf(typeof(HeapedObject))) { HeapType heapType = this.CreateHeapType(type); this.inheritenceTree.Add(type.Name, null); heapTypes.Add(heapType); } } } /// Register the found heap types. this.RegisterNonBuiltInTypes(heapTypes); /// Create the inheritence tree. foreach (IHeapType heapType in heapTypes) { List <IHeapType> inheritencePath = new List <IHeapType>(); IHeapType currHeapType = heapType; inheritencePath.Add(currHeapType); while (currHeapType.HasField(Constants.NAME_OF_BASE_TYPE_FIELD)) { currHeapType = this.GetHeapType(currHeapType.GetFieldTypeID(Constants.NAME_OF_BASE_TYPE_FIELD)); inheritencePath.Add(currHeapType); } inheritencePath.Reverse(); this.inheritenceTree[heapType.Name] = inheritencePath.ToArray(); } }
static void TestSimulationHeap() { List <HeapType> testMetadata = new List <HeapType>() { new HeapType("Unit", new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("HitPoints", "short"), new KeyValuePair <string, string>("TestArray", "int*"), new KeyValuePair <string, string>("TestPtrArray", "Building**"), new KeyValuePair <string, string>("TestPtr", "Building*"), }), new HeapType("Building", new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("HitPoints", "short"), new KeyValuePair <string, string>("BuildStatus", "short"), }), }; IHeapManagerInternals heapMgr = new HeapManager(testMetadata); IHeapType unitType = heapMgr.GetHeapType("Unit"); int UNIT_HP_IDX = unitType.GetFieldIdx("HitPoints"); short UNIT_HP_TID = unitType.GetFieldTypeID("HitPoints"); int UNIT_TESTARRAY_IDX = unitType.GetFieldIdx("TestArray"); short UNIT_TESTARRAY_TID = unitType.GetFieldTypeID("TestArray"); int UNIT_TESTPTRARRAY_IDX = unitType.GetFieldIdx("TestPtrArray"); short UNIT_TESTPTRARRAY_TID = unitType.GetFieldTypeID("TestPtrArray"); int UNIT_TESTPTR_IDX = unitType.GetFieldIdx("TestPtr"); short UNIT_TESTPTR_TID = unitType.GetFieldTypeID("TestPtr"); IHeapType buildingType = heapMgr.GetHeapType("Building"); int BUILDING_HP_IDX = buildingType.GetFieldIdx("HitPoints"); short BUILDING_HP_TID = buildingType.GetFieldTypeID("HitPoints"); int BUILDING_BUILDSTATUS_IDX = buildingType.GetFieldIdx("BuildStatus"); short BUILDING_BUILDSTATUS_TID = buildingType.GetFieldTypeID("BuildStatus"); Stopwatch watch = new Stopwatch(); watch.Start(); for (int j = 0; j < 100000; j++) { IHeapConnector unit = heapMgr.New(unitType.ID); IHeapConnector building0 = heapMgr.New(buildingType.ID); IHeapConnector building1 = heapMgr.New(buildingType.ID); ((IValueWrite <short>)building0.AccessField(BUILDING_HP_IDX)).Write(100); ((IValueWrite <short>)building0.AccessField(BUILDING_BUILDSTATUS_IDX)).Write(50); ((IValueWrite <short>)building1.AccessField(BUILDING_HP_IDX)).Write(50); ((IValueWrite <short>)building1.AccessField(BUILDING_BUILDSTATUS_IDX)).Write(100); ((IValueWrite <short>)unit.AccessField(UNIT_HP_IDX)).Write(88); unit.AccessField(UNIT_TESTPTR_IDX).PointTo(building0); unit.AccessField(UNIT_TESTARRAY_IDX).PointTo(heapMgr.NewArray(heapMgr.GetHeapType("int").ID, 5)); for (int i = 0; i < 5; ++i) { ((IValueWrite <int>)unit.AccessField(UNIT_TESTARRAY_IDX).Dereference().AccessArrayItem(i)).Write(i); } unit.AccessField(UNIT_TESTPTRARRAY_IDX).PointTo(heapMgr.NewArray(heapMgr.GetHeapType("Building*").ID, 5)); unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().AccessArrayItem(0).PointTo(building0); unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().AccessArrayItem(1).PointTo(building1); unit.AccessField(UNIT_TESTARRAY_IDX).Dereference().DeleteArray(); unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().DeleteArray(); unit.Delete(); building0.Delete(); building1.Delete(); } watch.Stop(); // TODO: test heap saving/loading }