Ejemplo n.º 1
0
void SMTController::reportProgress(uint32 id, uint64 ammount)
{
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);
	assert(m_pUPThread);

	m_pUPThread->reportProg(id, worker->ammountDone + ammount);
}
Ejemplo n.º 2
0
void SMTController::reportError(uint32 id, gcException &e)
{
#ifdef WIN32
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);
#endif
	Warning(gcString("SMTControler {0} Error: {1}.\n", id, e));
	onErrorEvent(e);
}
Ejemplo n.º 3
0
void WGTController::reportNegProgress(uint32 id, uint64 ammount)
{
	WGTWorkerInfo* worker = findWorker(id);
	assert(worker);
	assert(m_pUPThread);

	worker->ammountDone -= ammount;
	m_pUPThread->reportProg(id, worker->ammountDone);
}
Ejemplo n.º 4
0
void SMTController::endTask(uint32 id)
{
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);

	worker->status = SF_STATUS_NULL;

	worker->ammountDone += worker->curFile->getSize();
}
Ejemplo n.º 5
0
uint32 SMTController::getStatus(uint32 id)
{
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);

	if (isPaused())
		return SF_STATUS_PAUSE;

	if (isStopped())
		return SF_STATUS_STOP;

	return worker->status;
}
Ejemplo n.º 6
0
bool
IOProcess::removeWorkerFromWorkerList(int id)
{
	Worker* worker = findWorker(id);
	if( worker ) {
		m_workers_list.remove(id);

		delete worker;
		return true;
	}

	return false;
}
Ejemplo n.º 7
0
// Find 64k id's that all point to the specified worker
void runTestsWithPrefix(char* prefix, char* serverIp) {
	printf("Running tests against prefix %s\n", prefix);
	int clientNum=0;
	char clientIdStr[20];
	for (clientNum=0; clientNum < TEST_CONNS; clientNum++) {
		snprintf(clientIdStr, 20, "%s%d", prefix, clientNum);
		int worker = findWorker(clientIdStr);
		openSocket(worker, clientIdStr, serverIp);
		if (!(clientNum%1000)) {
			printf("%s\n", clientIdStr);
		}
	}
	printf ("Opened all\n");
}
Ejemplo n.º 8
0
void WGTController::reportError(uint32 id, gcException &e)
{
	WGTWorkerInfo* worker = findWorker(id);
	assert(worker);

	Warning(gcString("WebGet: {0} Error: {1}.\n", id, e));

	m_pUPThread->stopThread(id);
	worker->status = SF_STATUS_STOP;

	m_iRunningWorkers--;

	//get thread running again.
	m_WaitCondition.notify();
}
Ejemplo n.º 9
0
void WGTController::workerFinishedBlock(uint32 id, Misc::WGTBlock* block)
{
	WGTWorkerInfo* worker = findWorker(id);
	assert(worker);

	if (!block || !worker)
		return;

	worker->mutex.lock();
	worker->vBuffer.push_back(block);
	worker->mutex.unlock();

	//get thread running again.
	m_WaitCondition.notify();
}
Ejemplo n.º 10
0
TilePosition CoverMap::findClosestGasWithoutRefinery(UnitType toBuild, TilePosition start)
{
	TilePosition bestSpot = TilePosition(-1,-1);
	double bestDist = -1;
	TilePosition home = Broodwar->self()->getStartLocation();
	Unit* worker = findWorker();

	for(int i = 0 ; i < w ; i++)
	{
		for (int j = 0; j < h; j++)
		{
			if (cover_map[i][j] == GAS)
			{
				TilePosition cPos = TilePosition(i,j);

				bool ok = true;
				vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
				for (int i = 0; i < (int)agents.size(); i++)
				{
					Unit* unit = agents.at(i)->getUnit();
					if (unit->getType().isRefinery())
					{
						double dist = unit->getTilePosition().getDistance(cPos);
						if (dist <= 2)
						{
							ok = false;
						}
					}
				}
				if (ok)
				{
					if (ExplorationManager::canReach(home, cPos))
					{
						BaseAgent* agent = AgentManager::getInstance()->getClosestBase(cPos);
						double dist = agent->getUnit()->getTilePosition().getDistance(cPos);
						if (bestDist == -1 || dist < bestDist)
						{
							bestDist = dist;
							bestSpot = cPos;
						}
					}
				}
			}
		}
	}

	return bestSpot;
}
Ejemplo n.º 11
0
Misc::WGTSuperBlock* WGTController::newTask(uint32 id, uint32 &status)
{
	WGTWorkerInfo* worker = findWorker(id);
	assert(worker);

	status = worker->status;

	if (worker->status != SF_STATUS_CONTINUE)
		return NULL;

	if (worker->curBlock)
		return worker->curBlock;

	m_pFileMutex.lock();
	size_t listSize = m_vSuperBlockList.size();
	m_pFileMutex.unlock();

	if (listSize == 0 && !stealBlocks())
	{
		m_pUPThread->stopThread(id);
		worker->status = SF_STATUS_STOP;
		status = SF_STATUS_STOP;

		m_iRunningWorkers--;
		//get thread running again.
		m_WaitCondition.notify();

		return NULL;
	}

	m_pFileMutex.lock();
	Misc::WGTSuperBlock* temp = m_vSuperBlockList.front();
	m_vSuperBlockList.pop_front();
	m_pFileMutex.unlock();

	if (!temp)
		return newTask(id, status);

	worker->curBlock = temp;
	worker->status = SF_STATUS_CONTINUE;
	status = SF_STATUS_CONTINUE;

	return temp;
}
Ejemplo n.º 12
0
void WGTController::workerFinishedSuperBlock(uint32 id)
{
	WGTWorkerInfo* worker = findWorker(id);
	assert(worker);

	Misc::WGTSuperBlock* block = NULL;

	worker->mutex.lock();
	block = worker->curBlock;
	worker->curBlock = NULL;
	worker->status = SF_STATUS_CONTINUE;
	worker->mutex.unlock();

	if (!block)
	{
		m_WaitCondition.notify();
		return;
	}

	if (block->vBlockList.size() == 0)
	{
		if (block->size != 0)
			Warning("WGControler: Block still has data to download but all blocks consumed. Expect trouble ahead\n");

		safe_delete(block);

		m_pFileMutex.lock();
		m_iAvailbleWork--;
		m_pFileMutex.unlock();
	}
	else
	{
		m_pFileMutex.lock();
		m_vSuperBlockList.push_back(block);
		m_pFileMutex.unlock();
	}

	//get thread running again.
	m_WaitCondition.notify();
}
Ejemplo n.º 13
0
MCFCore::MCFFile* SMTController::newTask(uint32 id)
{
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);

	if (worker->status != SF_STATUS_NULL)
		return NULL;

	m_pFileMutex.lock();
	size_t listSize = m_vFileList.size();
	m_pFileMutex.unlock();

	if (listSize == 0)
	{
		m_pUPThread->stopThread(id);
		worker->status = SF_STATUS_STOP;

		m_iRunningWorkers--;
		//wake thread up
		m_WaitCond.notify();
		return NULL;
	}

	m_pFileMutex.lock();
	int index = m_vFileList.back();
	m_vFileList.pop_back();
	m_pFileMutex.unlock();

	MCFCore::MCFFile *temp = m_rvFileList[index];

	if (!temp)
		return newTask(id);

	worker->vFileList.push_back(index);
	worker->curFile = temp;
	worker->status = SF_STATUS_CONTINUE;
	return temp;
}
Ejemplo n.º 14
0
bool CoverMap::canBuild(UnitType toBuild, TilePosition buildSpot)
{
	Corners c = getCorners(toBuild, buildSpot);

	//Step 1: Check covermap.
	for (int x = c.x1; x <= c.x2; x++)
	{
		for (int y = c.y1; y <= c.y2; y++)
		{
			if (x >= 0 && x < w && y >= 0 && y < h)
			{
				if (cover_map[x][y] != BUILDABLE)
				{
					//Cant build here.
					return false;
				}
			}
			else
			{
				//Out of bounds
				return false;
			}
		}
	}

	//Step 2: Check if path is available
	if (!ExplorationManager::canReach(Broodwar->self()->getStartLocation(), buildSpot))
	{
		return false;
	}

	//Step 3: Check canBuild
	Unit* worker = findWorker();
	if (worker == NULL)
	{
		//No worker available
		return false;
	}

	//Step 4: Check any units on tile
	if (AgentManager::getInstance()->unitsInArea(buildSpot, toBuild.tileWidth(), toBuild.tileHeight(), worker->getID()))
	{
		return false;
	}

	//Step 5: If Protoss, check PSI coverage
	if (BuildPlanner::isProtoss())
	{
		if (toBuild.requiresPsi())
		{
			if (!Broodwar->hasPower(buildSpot, toBuild.tileWidth(), toBuild.tileHeight()))
			{
				return false;
			}
		}
	}

	//Step 6: If Zerg, check creep
	if (BuildPlanner::isZerg())
	{
		if (UnitAgent::isOfType(toBuild, UnitTypes::Zerg_Hatchery))
		{
			//Do not build if we have creep (to spread creep out)
			if (Broodwar->hasCreep(buildSpot))
			{
				return false;
			}
		}
		else if (toBuild.requiresCreep())
		{
			if (!Broodwar->hasCreep(buildSpot))
			{
				return false;
			}
		}
	}

	//Step 7: If detector, check if spot is already covered by a detector
	/*if (toBuild.isDetector())
	{
		if (!suitableForDetector(buildSpot))
		{
			return false;
		}
	}*/

	//All passed. It is possible to build here.
	return true;
}
Ejemplo n.º 15
0
CoverMap::CoverMap()
{
	w = Broodwar->mapWidth();
	h = Broodwar->mapHeight();
	range = 30;

	Unit* worker = findWorker();

	cover_map = new int*[w];
	for(int i = 0 ; i < w ; i++)
	{
		cover_map[i] = new int[h];

		//Fill from static map and Region connectability
		for (int j = 0; j < h; j++)
		{
			int ok = BUILDABLE;
			if (!Broodwar->isBuildable(i, j))
			{
				ok = BLOCKED;
			}

			cover_map[i][j] = ok;
		}
	}

	//Fill from current agents
	vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
	for (int i = 0; i < (int)agents.size(); i++)
	{
		BaseAgent* agent = agents.at(i);
		if (agent->isBuilding())
		{
			Corners c = getCorners(agent->getUnit());
			fill(c);
		}
	}

	//Fill from minerals
	for(set<Unit*>::iterator m = Broodwar->getMinerals().begin(); m != Broodwar->getMinerals().end(); m++)
	{
		Corners c;
		c.x1 = (*m)->getTilePosition().x() - 1;
		c.y1 = (*m)->getTilePosition().y() - 1;
		c.x2 = (*m)->getTilePosition().x() + 2;
		c.y2 = (*m)->getTilePosition().y() + 1;
		fill(c);

		cover_map[c.x1+2][c.y1+2] = MINERAL;
	}

	//Fill from gas
	for(set<Unit*>::iterator m = Broodwar->getGeysers().begin(); m != Broodwar->getGeysers().end(); m++)
	{
		Corners c;
		c.x1 = (*m)->getTilePosition().x() - 2;
		c.y1 = (*m)->getTilePosition().y() - 2;
		c.x2 = (*m)->getTilePosition().x() + 5;
		c.y2 = (*m)->getTilePosition().y() + 3;
		fill(c);

		cover_map[c.x1+2][c.y1+2] = GAS;
	}

	//Fill from narrow chokepoints
	if (analyzed)
	{
		for(set<Region*>::const_iterator i=getRegions().begin();i!=getRegions().end();i++)
		{
			for(set<Chokepoint*>::const_iterator c=(*i)->getChokepoints().begin();c!=(*i)->getChokepoints().end();c++)
			{
				if ((*c)->getWidth() <= 4 * 32)
				{
					TilePosition center = TilePosition((*c)->getCenter());
					Corners c;
					c.x1 = center.x() - 1;
					c.x2 = center.x() + 1;
					c.y1 = center.y() - 1;
					c.y2 = center.y() + 1;
					fill(c);
				}
			}
		}
	}

	mapData = MapDataReader();
	mapData.readMap();
}