public PoolClient(PoolInstance poolInstance, ICoinHandlerPool pool, ICoinHandlerMiner miner) { this.poolHandler = pool; this.coinHandler = miner; this.poolInstance = poolInstance; //Create a new instance of the MinerServer, which creates an instance of Network.Sockets.Server minerServer = new MinerServer(poolInstance.localListenPort, this, minerManager, coinHandler); //Create a new instance of the Network.Sockets.Client poolClient = new Client(poolInstance.GetCurrentPool().poolAddress, poolInstance.GetCurrentPool().poolPort); //define pool events poolClient.OnServerConnected += PoolClient_OnServerConnected; poolClient.OnServerDataReceived += PoolClient_OnServerDataReceived; poolClient.OnServerDisconnected += PoolClient_OnServerDisconnected; poolClient.OnServerError += PoolClient_OnServerError; //setup coin miner handler coinHandler.SetMinerServer(minerServer); coinHandler.SetPoolClient(this); coinHandler.SetMinerManager(minerManager); //setup coin Pool handler poolHandler.SetMinerServer(minerServer); poolHandler.SetPoolClient(this); poolHandler.SetMinerManager(minerManager); //this.Start(); minerServer.ListenForMiners(); Log.Information("[{0}] waiting for miners before connecting to pool..", poolWorkerName); }
/// <summary> /// Resizes the instance list for a given pool (in case we need more instances that we expected) /// </summary> /// <param name="poolId">The id of the pool we want to resize.</param> private void resizePoolInstanceList(PoolIds poolId) { //Get the pool data and the prefab to instantiate PoolData poolData = poolList[poolId]; GameObject prefab = poolData.instanceList[0].gameObject; //Calculate the new size and create the new array int newSize = Mathf.FloorToInt(poolData.numInstances * 1.20f); PoolInstance[] newInstanceList = new PoolInstance[newSize]; //Move the references for (int i = 0; i < poolData.numInstances; i++) { newInstanceList[i] = poolData.instanceList[i]; } //Create the new instances for (int i = poolData.numInstances; i < newSize; i++) { newInstanceList[i] = instantiatePoolInstance(prefab); } poolData.numInstances = newSize; poolData.instanceList = newInstanceList; }
public PoolRef(GameObject src) { cachedObj = src; cachedPool = Pool.Instance; if(src != null) ptr = cachedPool.GetPoolInstance(src); }
/// <summary> /// Creates multiple pools of GameObjects in selected amount for each /// </summary> /// <param name="newPools">Dictionary containing GameObject as key and number of instances as value</param> public void AddNewPool(Dictionary <GameObject, int> newPools) { foreach (KeyValuePair <GameObject, int> newPool in newPools) { PoolInstance pool = new PoolInstance(newPool.Key, newPool.Value, transform); _pools.Add(newPool.Key, pool); } }
private GameObject InternalSpawn(GameObject prefab, Vector3 position, Quaternion rotation) { PoolTable table = GetOrCreateTable(prefab); GameObject obj = table.Spawn(position, rotation); poolInstances[obj] = new PoolInstance(obj, true, table); return(obj); }
public PoolRef(GameObject src) { cachedObj = src; cachedPool = Pool.Instance; if (src != null) { ptr = cachedPool.GetPoolInstance(src); } }
/// <summary> /// Instantiates a new pool instance /// </summary> /// <returns>The pool instance.</returns> /// <param name="prefab">The prefab for the instance.</param> private PoolInstance instantiatePoolInstance(GameObject prefab) { //The pool only operates with PoolInstance objects PoolInstance instance = (GameObject.Instantiate(prefab) as GameObject).GetComponent <PoolInstance>(); instance.init(); instance.transform.parent = transform; return(instance); }
public GameObject ReuseObject(int key, Vector3 pos, Quaternion rot) { if (pools.ContainsKey(key)) { PoolInstance reused = pools[key].Dequeue(); pools[key].Enqueue(reused); reused.Reuse(pos, rot); return(reused.GameObject()); } throw new KeyNotFoundException(); }
private void DoDespawnAll() { foreach (var pair in poolInstances) { PoolInstance inst = pair.Value; if (inst.Table != null) { inst.InUse = false; inst.Table.Despawn(pair.Key); } } enabled = true; }
public static bool WritePoolToFile(string filename, PoolInstance pool) { try { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"pools\", filename); Log.Debug("Writing {0} to {1}..", pool.mainPool.poolWorkerName, Path.GetRelativePath(AppDomain.CurrentDomain.BaseDirectory, path)); File.WriteAllText(path, JsonConvert.SerializeObject(pool, Formatting.Indented)); return(true); } catch (Exception ex) { Log.Warning(string.Format("Save settings error: {0}", ex.Message)); return(false); } }
public static List <PoolInstance> LoadPoolDirectory() { List <PoolInstance> pools = new List <PoolInstance>(); PoolInstance temp; string dirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"pools\"); Log.Information("Loading pools.. {0}", @"\pools\"); if (!Directory.Exists(dirPath)) { Log.Information("Pool directory doesn't exist; creating.."); Directory.CreateDirectory(dirPath); } List <string> dir = new List <string>(Directory.EnumerateFiles(dirPath, "*.json")); if (dir.Count == 0) { Log.Information("No pools found; creating default.."); PoolInstance etcPool = new PoolInstance("us1-etc.ethermine.org", 4444, 9000, "MProxyETC", "0x83D557A1E88C9E3BbAe51DFA7Bd12CF523B28b84", "ETC", 0); etcPool.AddFailoverPool(etcPool.mainPool.poolAddress, etcPool.mainPool.poolPort); etcPool.AddAllowedIPAddress("0.0.0.0"); WritePoolToFile("Ethermine ETC.json", etcPool); } dir = new List <string>(Directory.EnumerateFiles(dirPath, "*.json")); foreach (var item in dir) { Log.Verbose("Attempting to load {0}..", Path.GetRelativePath(AppDomain.CurrentDomain.BaseDirectory, item)); temp = LoadPoolFromFile(item); if (temp == null) { Log.Debug("Skipping {0}", item); continue; } Log.Information("Loaded {0} for {1} on port {2}", temp.mainPool.poolWorkerName, temp.mainPool.poolEndPoint, temp.localListenPort); pools.Add(temp); } return(pools); }
public void CreatePool(GameObject prefab, int size) { int key = prefab.GetInstanceID(); GameObject pool = new GameObject(prefab.name + "_pool"); pool.transform.parent = transform; if (!pools.ContainsKey(key)) { pools.Add(key, new Queue <PoolInstance> ()); for (int i = 0; i < size; i++) { PoolInstance instance = new PoolInstance(Instantiate(prefab) as GameObject); pools[key].Enqueue(instance); instance.SetParent(pool.transform); } } }
public static PoolInstance LoadPoolFromFile(string filename) { if (!File.Exists(filename)) { Log.Warning("Unable to load {0}!", Path.GetRelativePath(AppDomain.CurrentDomain.BaseDirectory, filename)); return(null); } Log.Debug("Loading {0}..", Path.GetRelativePath(AppDomain.CurrentDomain.BaseDirectory, filename)); try { PoolInstance pool = JsonConvert.DeserializeObject <PoolInstance>(File.ReadAllText(filename)); return(pool); } catch (Exception ex) { Log.Error("Unable to load {0}: {1}", filename, ex.Message); return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="RMQPoolContainer{T}"/> class. /// </summary> /// <param name="container">The container.</param> public RMQPoolContainer(PoolInstance <RMQObjectPoolData, object> container) { Guard.AgainstNull(() => container); _container = container; }
public PoolRef(PoolRef other) { ptr = other.ptr; cachedPool = Pool.Instance; cachedObj = other.cachedObj; }
public void destroyInstance(PoolInstance instance) { instance.kill(); }
/// <summary> /// 发送事件信息 /// </summary> /// <param name="actionName">事件名</param> /// <param name="args">事件参数</param> public void Send(string actionName, Hashtable args) { PoolInstance.Deal(this, actionName, args); }
/// <summary> /// 向实体池反注册此实体 /// </summary> public void UnRegister() { PoolInstance.UnRegister(this); OnRemove(); }
/// <summary> /// 向实体池注册此实体 /// </summary> public void Register() { PoolInstance.Register(this); }
public void Remove(PoolInstance instance) { instance.gameObject.SetActive(false); objPool.Push(instance); }
/// <summary> /// Creates a pool for selected GameObject in selected amount, under selected parent /// </summary> /// <param name="objectToPool">Preefab of an object to pool</param> /// <param name="amountToPool">How many instances should be creeated</param> public void AddNewPool(GameObject objectToPool, int amountToPool) { PoolInstance newPool = new PoolInstance(objectToPool, amountToPool, transform); _pools.Add(objectToPool, newPool); }