static WorldGenerator() { squaresHitboxesList = new List<Hitbox>(); squaresHitboxesPool = new ObjectPool<Hitbox>(CreateSquareHitbox, RecycleSquareHitbox, RABBIT_BOX_POOL_SIZE); getVisiblesWindowsAsSquaresHitboxes = new EnumWindowsProc(GetVisiblesWindowsAsSquaresHitboxes_EnumWindowsProc); }
public void ObjectPoolTestFactory() { var factory1 = new Disposable(); var factory2 = new Disposable(); var objectPool = new ObjectPool<Disposable, Disposable>(); objectPool.UpdateFactory(ObjectFactory.Create(factory1, d => d.Create())); var p3 = objectPool.GetOrCreate(); p3.Dispose(); objectPool.UpdateFactory(ObjectFactory.Create(factory2, d => d.Create())); Assert.IsTrue(factory1.Disposed); var p1 = objectPool.GetOrCreate(); var p2 = objectPool.GetOrCreate(); p1.Dispose(); p2.Dispose(); p1 = objectPool.GetOrCreate(); p1.Dispose(); objectPool.Dispose(); factory1.AssertChildrenDisposed(); Assert.AreEqual(1, factory1.Children.Count); factory2.AssertChildrenDisposed(); Assert.AreEqual(2, factory2.Children.Count); Assert.IsTrue(factory2.Disposed); }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); ReadIndex.Close(); ReadIndex.Dispose(); TableIndex.Close(removeFiles: false); var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 2, () => new TFChunkReader(Db, WriterCheckpoint)); var lowHasher = new XXHashUnsafe(); var highHasher = new Murmur3AUnsafe(); TableIndex = new TableIndex(GetFilePathFor("index"), lowHasher, highHasher, () => new HashListMemTable(PTableVersions.Index64Bit, maxSize: MaxEntriesInMemTable*2), () => new TFReaderLease(readers), PTableVersions.Index64Bit, maxSizeForMemory: MaxEntriesInMemTable); ReadIndex = new ReadIndex(new NoopPublisher(), readers, TableIndex, 0, additionalCommitChecks: true, metastreamMaxCount: 1, hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault); ReadIndex.Init(ChaserCheckpoint.Read()); }
public static ObjectPool<Connection> GetConnectionPool(ConnectionSetting connectionSetting) { if (connectionSetting == null) throw new ArgumentNullException("connectionSetting"); var key = connectionSetting.ConnectionString; ObjectPool<Connection> connectionPool = null; lock ((ConnectionPools as ICollection).SyncRoot) { if (ConnectionPools.ContainsKey(key)) connectionPool = ConnectionPools[key]; if (connectionPool == null) { connectionPool = new ObjectPool<Connection>( new ConnectionFactory(connectionSetting), new ObjectPool<Connection>.Configuration { MinSize = connectionSetting.MinPoolSize, MaxSize = connectionSetting.MaxPoolSize, Timeout = connectionSetting.ConnectionTimeout }); ConnectionPools[key] = connectionPool; } } return connectionPool as ObjectPool<Connection>; }
public static AsteroidWallpaper New(ObjectPool big, ObjectPool small) { var instance = CreateInstance<AsteroidWallpaper>(); instance.big = big; instance.small = small; return instance; }
public void TestAllocateAndFree() { var pool = new ObjectPool<TestElement>(); pool.Initialize(); Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 0); // allocate some instances var e1 = pool.Allocate(); var e2 = pool.Allocate(); Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0); Assert.IsTrue(e1 != e2); Assert.IsTrue(e1.value == 0); // free both and then allocate two more again - we should get both back pool.Free(e1); pool.Free(e2); Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 2); var e3 = pool.Allocate(); var e4 = pool.Allocate(); Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0); Assert.IsTrue(e3 == e2); Assert.IsTrue(e4 == e1); }
void Awake() { timeLastEnemyHitted = Time.time; trigger = GetComponentInChildren<BoxCollider>(); sprite = transform.GetComponentInChildren<SpriteRenderer>(); glitchPartPool = new ObjectPool(glitchPart); lives = 3; items = 0; //Instantiate the glitch fragments to avoid lag later in the game GameObject[] parts = new GameObject[100]; for (int i = 0; i < 100; i++) { parts[i] = glitchPartPool.getObject(); } for (int i = 0; i < 100; i++) { parts[i].SetActive(false); } boxUIActivatedRectTransform = boxUIActivated.GetComponent<RectTransform>(); exclamationSize = boxUIActivatedRectTransform.sizeDelta; boxUIActivated.SetActive(false); guiRectTrans = gui.GetComponent<RectTransform>(); slowFPSScript = transform.FindChild("Powers").GetComponentInChildren<SlowFPS>(); }
public static Poolable AddPoolableComponent(GameObject newInstance, ObjectPool pool) { scriptBuiltInstance = true; var instance = newInstance.AddComponent<Poolable>(); instance.pool = pool; return instance; }
public TemplateBinder( UrlEncoder urlEncoder, ObjectPool<UriBuildingContext> pool, RouteTemplate template, RouteValueDictionary defaults) { if (urlEncoder == null) { throw new ArgumentNullException(nameof(urlEncoder)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } if (template == null) { throw new ArgumentNullException(nameof(template)); } _urlEncoder = urlEncoder; _pool = pool; _template = template; _defaults = defaults; // Any default that doesn't have a corresponding parameter is a 'filter' and if a value // is provided for that 'filter' it must match the value in defaults. _filters = new RouteValueDictionary(_defaults); foreach (var parameter in _template.Parameters) { _filters.Remove(parameter.Name); } }
private void ReOpenDb() { Db = new TFChunkDb(new TFChunkDbConfig(PathName, new VersionedPatternFileNamingStrategy(PathName, "chunk-"), 10000, 0, WriterCheckpoint, ChaserCheckpoint, new InMemoryCheckpoint(-1), new InMemoryCheckpoint(-1))); Db.Open(); var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint)); TableIndex = new TableIndex(Path.Combine(PathName, "index"), () => new HashListMemTable(MaxEntriesInMemTable * 2), () => new TFReaderLease(readers), MaxEntriesInMemTable); ReadIndex = new ReadIndex(new NoopPublisher(), readers, TableIndex, new ByLengthHasher(), 0, additionalCommitChecks: true, metastreamMaxCount: MetastreamMaxCount); ReadIndex.Init(ChaserCheckpoint.Read()); }
private LookupResult(ObjectPool<LookupResult> pool) { _pool = pool; _kind = LookupResultKind.Empty; _symbolList = new ArrayBuilder<Symbol>(); _error = null; }
static void Main(string[] args) { CancellationTokenSource cts = new CancellationTokenSource(); // Create an opportunity for the user to cancel. Task.Run(() => { if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C') cts.Cancel(); }); ObjectPool<TestClass> pool = new ObjectPool<TestClass>(() => new TestClass()); // Create a high demand for MyClass objects. Parallel.For(0, 1000000, (i, loopState) => { using(TestClass mc = pool.GetResource()) { Console.CursorLeft = 0; // This is the bottleneck in our application. All threads in this loop // must serialize their access to the static Console class. Console.WriteLine("{0:####.####}", mc.GetValue(i)); // pool.PoolResource(mc); alternative to implementing repool in the dispose method } if (cts.Token.IsCancellationRequested) loopState.Stop(); }); Console.WriteLine("Press the Enter key to exit."); Console.ReadLine(); cts.Dispose(); }
private void ReOpenDb() { Db = new TFChunkDb(new TFChunkDbConfig(PathName, new VersionedPatternFileNamingStrategy(PathName, "chunk-"), 10000, 0, WriterCheckpoint, ChaserCheckpoint, new InMemoryCheckpoint(-1), new InMemoryCheckpoint(-1))); Db.Open(); var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint)); var lowHasher = new XXHashUnsafe(); var highHasher = new Murmur3AUnsafe(); TableIndex = new TableIndex(Path.Combine(PathName, "index"), lowHasher, highHasher, () => new HashListMemTable(PTableVersions.Index64Bit, MaxEntriesInMemTable * 2), () => new TFReaderLease(readers), PTableVersions.Index64Bit, MaxEntriesInMemTable); ReadIndex = new ReadIndex(new NoopPublisher(), readers, TableIndex, 0, additionalCommitChecks: true, metastreamMaxCount: MetastreamMaxCount, hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault); ReadIndex.Init(ChaserCheckpoint.Read()); }
// Use this for initialization public void Init () { mng.eventManager.StartListening(EventManager.EventType.PLAYER_DIED, PlayerDied); mng.eventManager.StartListening(EventManager.EventType.PLAYER_WIN, PlayerWin); mng.eventManager.StartListening(EventManager.EventType.COLOR_CHANGED, ColorChanged); aracnoBotPool = mng.poolManager.aracnoBotPool; }
private LookupResult(ObjectPool<LookupResult> pool) { this.pool = pool; this.kind = LookupResultKind.Empty; this.symbolList = new ArrayBuilder<Symbol>(); this.error = null; }
public CompilationData(Compilation comp) { _semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>(); this.SuppressMessageAttributeState = new SuppressMessageAttributeState(comp); _declarationAnalysisDataMap = new Dictionary<SyntaxReference, DeclarationAnalysisData>(); _declarationAnalysisDataPool = new ObjectPool<DeclarationAnalysisData>(() => new DeclarationAnalysisData()); }
void Start() { if(explosionPool == null && explosionRep != null) { explosionPool = PoolManager.Instance.GetPoolByRepresentative(explosionRep); } base.Start (); }
// Use this for initialization void Start () { colorObjMng = rsc.coloredObjectsMng; voxelPool = rsc.poolMng.voxelPool; voxelColliderPool = rsc.poolMng.voxelColliderPool; mat = colorObjMng.GetVoxelRandomMaterial(); if (!includeChildren) { transf = gameObject.transform; rend = gameObject.GetComponent<Renderer>(); meshFilter = gameObject.GetComponent<MeshFilter>(); sRend = gameObject.GetComponent<SkinnedMeshRenderer>(); } else { transforms = new List<Transform>(); renderers = new List<Renderer>(); isSkinedMeshRenderer = new List<bool>(); meshFilters = new List<MeshFilter>(); meshes = new List<Mesh>(); PopulateLists(gameObject); } voxelScale = new Vector3(voxelSideSize, voxelSideSize, voxelSideSize); }
public void AddInstance_UpToTheLimit_CountersCorrect() { int i = 0; var pool = new ObjectPool<PoolObject>( () => new PoolObject((i++).ToString()), null, 2, TimeSpan.MaxValue); Assert.Equal(0, pool.InstanceCount); Assert.False(pool.HasFreeInstance); //first instance PoolObject obj1 = pool.GetInstance(); Assert.Equal(1, pool.InstanceCount); Assert.False(pool.HasFreeInstance); //second instance PoolObject obj2 = pool.GetInstance(); Assert.Equal(2, pool.InstanceCount); Assert.False(pool.HasFreeInstance); //third instance new Thread(() => { pool.ReleaseInstance(obj1);}).Start(); PoolObject obj3 = pool.GetInstance(); Assert.Equal(2, pool.InstanceCount); Assert.False(pool.HasFreeInstance); Assert.True(ReferenceEquals(obj3, obj1)); pool.Dispose(); Assert.Equal(0, pool.InstanceCount); Assert.False(pool.HasFreeInstance); }
private static void Main(string[] args) { CancellationTokenSource cts = new CancellationTokenSource(); Task task = new Task(() => { if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C') { cts.Cancel(); } }); task.Start(); ObjectPool<MyClass> pool = new ObjectPool<MyClass>(() => new MyClass()); Parallel.For(0, 1000000, (i, loopstate) => { MyClass mc = pool.GetObject(); Console.CursorLeft = 0; Console.WriteLine("{0:####.####}", mc.GetValue(i)); pool.PutObject(mc); if (cts.Token.IsCancellationRequested) { loopstate.Stop(); } }); Console.WriteLine("Press the Enter key to exit."); Console.ReadLine(); }
void InitPool () { pool = new ObjectPool<DynamicBrick> (initSize, addSize); pool.NewObject = NewDynamicBrick; pool.Init (); }
void InitPool () { m_Pool_Brick = new ObjectPool<Brick> (100, 20); m_Pool_Brick.NewObject = NewBrick; m_Pool_Brick.Init (); }
public Access(string accessFileName) { var acFile = accessFileName.Replace('\\', '/').Replace("//", "/"); this.connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", acFile); this.pool = new ObjectPool<OleDbConnection>(() => new OleDbConnection(connectionString)); this.PageSize = 14; }
// Use this for initialization void Start () { //voxelPool = mng.poolManager.voxelPool; voxelScriptPool = mng.poolManager.voxelControllerPool; voxelColliderPool = mng.poolManager.voxelColliderPool; mat = redMaterial; if (!includeChildren) { transf = gameObject.transform; rend = gameObject.GetComponent<Renderer>(); meshFilter = gameObject.GetComponent<MeshFilter>(); sRend = gameObject.GetComponent<SkinnedMeshRenderer>(); } else { transforms = new List<Transform>(); renderers = new List<Renderer>(); isSkinedMeshRenderer = new List<bool>(); meshFilters = new List<MeshFilter>(); meshes = new List<Mesh>(); PopulateLists(gameObject); } voxelScale = new Vector3(voxelSideSize, voxelSideSize, voxelSideSize); }
/// <summary> /// Initializes the game board. /// </summary> /// <param name="width">The width of the board.</param> /// <param name="height">The height of the board.</param> /// <param name="initialDensity">The initial population density to use to populate the board.</param> /// <param name="pool">The pool of Bitmaps to use.</param> /// <param name="ruleSet">The rule set.</param> public GameBoard(int width, int height, double initialDensity, ObjectPool<Bitmap> pool, string ruleSet) { // Validate parameters if (width < 1) throw new ArgumentOutOfRangeException("width"); if (height < 1) throw new ArgumentOutOfRangeException("height"); if (pool == null) throw new ArgumentNullException("pool"); if (ruleSet == null) throw new ArgumentNullException("pool"); if (initialDensity < 0 || initialDensity > 1) throw new ArgumentOutOfRangeException("initialDensity"); // Store parameters _pool = pool; Width = width; Height = height; _ruleSet = ruleSet; // Create the storage arrays _scratch = new Color?[2][,] { new Color?[width, height], new Color?[width, height] }; // Populate the board randomly based on the provided initial density Random rand = new Random(); for (int i = 0; i < width; i ++) { for (int j = 0; j < height; j++) { _scratch[_currentIndex][i, j] = (rand.NextDouble() < initialDensity) ? Color.FromArgb(rand.Next()) : (Color?)null; } } }
// Use this for initialization public void Awake() { player = GameObject.FindGameObjectWithTag ("Player"); playerController = player.GetComponent<PlayerController>(); gameController = GameObject.Find("GameController").GetComponent<GameController>(); objectPool = GameObject.Find("Pool").GetComponent<ObjectPool>(); }
void OnEnable() { target = null; canFire = true; anim = GetComponent<Animator>(); projPool = PoolManager.Instance.GetPoolByRepresentative(projectile); }
/////////////////////////////////////////////// private GameObject GetObstacle(ObjectPool pool) { GameObject obstacle = pool.getNextObject (); var pos = pool.prototype.transform.position; obstacle.transform.position = new Vector3 (pos.x, pos.y, pos.z); return obstacle; }
protected override void Awake() { base.Awake(); GameObject gameController = GameObject.FindGameObjectWithTag(Tags.GAMECONTROLLER); _gameController = gameController.GetComponent<GameController>(); _objectPool = gameController.GetComponent<ObjectPool>(); }
internal RpcServerRuntime( RpcServerConfiguration configuration, SerializationContext serializationContext ) { this._configuration = configuration; this._serializationContext = serializationContext; this._applicationContextPool = configuration.ApplicationContextPoolProvider( () => new RpcApplicationContext( configuration.ExecutionTimeout, configuration.HardExecutionTimeout ), configuration.CreateApplicationContextPoolConfiguration() ); this._softTimeoutDetails = new MessagePackObject( new MessagePackObjectDictionary() { { RpcException.MessageKeyUtf8, "Execution timeout." }, { RpcException.DebugInformationKeyUtf8, String.Format( CultureInfo.InvariantCulture, "{{ \"ExecutionTimeout\" : \"{0}\", \"HardExecutionTimeout\" : \"{1}\" }}", configuration.ExecutionTimeout, configuration.HardExecutionTimeout ) } }, true ); }
private void Awake() { objectPool = ObjectPool.Instance; }
public static GameObject Spawn(this GameObject prefab, Transform parent, Vector3 position, Quaternion rotation) { return(ObjectPool.Spawn(prefab, parent, position, rotation)); }
public static void RecycleAll <T>(this T prefab) where T : Component { ObjectPool.RecycleAll(prefab); }
public static void Recycle(this GameObject obj) { ObjectPool.Recycle(obj); }
public static void Recycle <T>(this T obj) where T : Component { ObjectPool.Recycle(obj); }
public static GameObject Spawn(this GameObject prefab) { return(ObjectPool.Spawn(prefab, null, Vector3.zero, Quaternion.identity)); }
public static GameObject Spawn(this GameObject prefab, Transform parent) { return(ObjectPool.Spawn(prefab, parent, Vector3.zero, Quaternion.identity)); }
public static GameObject Spawn(this GameObject prefab, Vector3 position) { return(ObjectPool.Spawn(prefab, null, position, Quaternion.identity)); }
public static T Spawn <T>(this T prefab, Transform parent) where T : Component { return(ObjectPool.Spawn(prefab, parent, Vector3.zero, Quaternion.identity)); }
public static T Spawn <T>(this T prefab) where T : Component { return(ObjectPool.Spawn(prefab, null, Vector3.zero, Quaternion.identity)); }
public static void CreatePool(this GameObject prefab, int initialPoolSize) { ObjectPool.CreatePool(prefab, initialPoolSize); }
public static T Spawn <T>(this T prefab, Vector3 position, Quaternion rotation) where T : Component { return(ObjectPool.Spawn(prefab, null, position, rotation)); }
public static void CreatePool <T>(this T prefab, int initialPoolSize) where T : Component { ObjectPool.CreatePool(prefab, initialPoolSize); }
public static void CreatePool(this GameObject prefab) { ObjectPool.CreatePool(prefab, 0); }
void Awake() { _instance = this; }
public static void CreatePool <T>(this T prefab) where T : Component { ObjectPool.CreatePool(prefab, 0); }
void Awake() { pool = GetComponent <ObjectPool>(); }
public Rewriter(ObjectPool <IReductionRewriter> pool) : base(pool) { }
private OrderPreservingMultiDictionary(ObjectPool <OrderPreservingMultiDictionary <K, V> > pool) { _pool = pool; }
// Use this for initialization void Start() { pool = GameObject.Find("pool"); objPool = pool.GetComponent <ObjectPool>(); }
public Service(ref ObjectPool <IDbConnection> pool) { this.connectionPool = pool; }
protected void CreateCachePools() { poolStones = poolsManager.Stones; poolBonusesSpeed = poolsManager.BonusesSpeed; }
public TuioInput() { touchPool = new ObjectPool <TouchPointer>(20, () => new TouchPointer(this), null, resetPointer); objectPool = new ObjectPool <ObjectPointer>(10, () => new ObjectPointer(this), null, resetPointer); }
public void Setup(Pool.ObjectPool pool, GlobalAudioManager manager, SignalBus signalBus) { m_ClipPool = pool; m_AudioManager = manager; this._signalBus = signalBus; }
public static void RecycleAll(this GameObject prefab) { ObjectPool.RecycleAll(prefab); }
public DefaultClaimUidExtractor(ObjectPool <AntiforgerySerializationContext> pool) { _pool = pool; }
/// <summary> /// Initializes a new instance of the <see cref="TriggerCommandBuilder"/> class. /// </summary> /// <param name="objectPool">The object pool.</param> public TriggerCommandBuilder(ObjectPool <StringBuilder> objectPool) { ObjectPool = objectPool; }
public PickUpPool(ObjectPool objectpool, float poolweight) { objectPool = objectpool; poolWeight = poolweight; }
public static int CountPooled <T>(this T prefab) where T : Component { return(ObjectPool.CountPooled(prefab)); }
void Awake() { shopItemsPool = new ObjectPool <ShopItem>(ShopItemPrefab, transform); }