// Pushes the VillageObject to the VillageObjectPool where it will // be reused when Village.FromJson is called. internal void PushToPool() { // Don't wait for ResetVillageObject to be called to set the _village to null, // so the _village can get picked up by the GC. _village = null; // Push the object back to the pool. VillageObjectPool.Push(this); _pushCount++; }
// Tries to return an instance of the Building class from the VillageObjectPool. // Used by ReadBuildingArray. internal static Building GetInstance(Village village) { var obj = (VillageObject)null; if (!VillageObjectPool.TryPop(Kind, out obj)) { obj = new Building(); } obj.SetVillageInternal(village); return((Building)obj); }
// Tries to return an instance of the Building class from the VillageObjectPool. internal static Trap GetInstance(Village village) { var obj = (VillageObject)null; if (!VillageObjectPool.TryPop(Kind, out obj)) { obj = new Trap(); } obj.SetVillageInternal(village); return((Trap)obj); }
internal static Decoration GetInstance(Village village) { var obj = (VillageObject)null; if (!VillageObjectPool.TryPop(Kind, out obj)) { obj = new Decoration(); } obj.SetVillageInternal(village); return((Decoration)obj); }
internal static Obstacle GetInstance(Village village) { var obj = (VillageObject)null; if (!VillageObjectPool.TryPop(Kind, out obj)) { obj = new Obstacle(); } obj.SetVillageInternal(village); return((Obstacle)obj); }