Esempio n. 1
0
	void OverlayTask::Update()
	{
		for (auto it = m_Selected.begin(), end = m_Selected.end(); it != end; ++it)
		{
			const auto& entity = *it;

			auto pos = entity->GetPosition();
			pos.x = ToRenderUnits(pos.x), pos.y = ToRenderUnits(pos.y);
			pos += m_Offset;

			clan::Rectf box(clan::Sizef(50, 50));
			box.translate(pos.x - box.get_width() * 0.5f, pos.y - box.get_height() * 0.5f);

			m_DebugDraw.DrawRectangle(box, GetColour(it));
		}

		if (m_EditCam)
		{
			clan::Colorf rangeColour(1.0f, 0.6f, 0.6f, 0.95f);
			auto center = m_EditCam->GetPosition();
			auto radius = ToRenderUnits(m_CamRange);
			clan::Rectf camRect(center.x - radius, center.y - radius, center.x + radius, center.y + radius);
			m_DebugDraw.DrawRectangle(camRect, rangeColour);
		}

		if (m_PolygonTool && m_PolygonTool->IsActive())
			m_PolygonTool->Draw();
		if (m_RectangleTool && m_RectangleTool->IsActive())
			m_RectangleTool->Draw();
		if (m_CircleTool && m_CircleTool->IsActive())
			m_CircleTool->Draw();
	}
Esempio n. 2
0
bool cWorld::isChunkViable(vec2i pos)
{
	int unitId;
	float bufferArea = 500.00f;
	sf::FloatRect camRect(vec2f(camera.pos.x - bufferArea, camera.pos.y - bufferArea), vec2f(camera.res.x + bufferArea * 2, camera.res.y + bufferArea * 2));
	sf::FloatRect unitRect;
	sf::FloatRect chunkRect(vec2f(pos.x * LIMIT_CHUNKSIZE, pos.y * LIMIT_CHUNKSIZE), vec2f(LIMIT_CHUNKSIZE, LIMIT_CHUNKSIZE));
	if (client.unit != -1){
		unitId = game.getUnitId(client.unit);
		if (unitId != -1) {
			unitRect = sf::FloatRect(vec2f(game.unit[unitId].pos.x - camera.res.x / 2, game.unit[unitId].pos.y - camera.res.y / 2), vec2f(camera.res.x, camera.res.y));
		}
	}
	// Local player
	if (client.connected && (camRect.intersects(chunkRect) || unitRect.intersects(chunkRect)))
	{
		return true;
	}
	// Remote players
	if (core.localServer || core.serverMode)
	{
		for (int i = 0; i < LIMIT_SERVER_PLAYERS; i++)
		{
			if (server.player[i].connected)
			{
				camRect = sf::FloatRect(vec2f(server.player[i].camPos.x - bufferArea, server.player[i].camPos.y - bufferArea),
					vec2f(server.player[i].camRes.x + bufferArea * 2, server.player[i].camRes.y + bufferArea * 2));
				if (server.player[i].unit != -1){
					unitId = game.getUnitId(server.player[i].unit);
					if (unitId != -1)
					{
						unitRect = sf::FloatRect(vec2f(game.unit[unitId].pos.x - server.player[i].camRes.x / 2,
							game.unit[unitId].pos.y - server.player[i].camRes.y / 2), vec2f(server.player[i].camRes.x, server.player[i].camRes.y));
					}
				}
				if (camRect.intersects(chunkRect) || unitRect.intersects(chunkRect))
				{
					return true;
				}
			}
		}
	}
	return false;
}
Esempio n. 3
0
void cWindow::paintClouds()
{
	brushRect.setScale(vec2f(1.00f, 1.00f));
	brushRect.setFillColor(color(0, 0, 0));
	//brushRect.setTexture(&visual.gameTex[database.texture[TEX_CLOUD]].handle);
	sf::FloatRect camRect(camera.pos.x, camera.pos.y, camera.res.x, camera.res.y);
	mutex.renderClouds.lock();
	visual.cloudsPainted = 0;
	for (int i = 0; i < (int)weather.cloud.size(); i++)
	{
		//brushRect.setTexture(&weather.cloudTexture[i], true);
		brushRect.setTexture(&visual.gameTex[weather.cloud[i].tex].handle, true);
		brushRect.setPosition(weather.cloud[i].pos);
		brushRect.setSize(weather.cloud[i].size);
		brushRect.setOrigin(weather.cloud[i].size / 2.00f);
		if (camRect.intersects(brushRect.getGlobalBounds())) {
			window.texHandleShadow.draw(brushRect, window.matrixHandle);
			visual.cloudsPainted += 1;
		}
	}
	mutex.renderClouds.unlock();
}
Esempio n. 4
0
void cPreRender::updateUnits()
{
	game.access.lock();
	mutex.renderUnits.lock();
	preRender.units.ready = true;
	preRender.units.queue.clear();

	sf::RenderStates renderState;

	float cameraLeft = camera.pos.x;
	float cameraRight = camera.res.x + camera.pos.x;
	float cameraTop = camera.pos.y;
	float cameraBot = camera.res.y + camera.pos.y;
	// Render distance
	if (core.advancedDebug)
	{
		cameraLeft -= 5000;	cameraRight += 5000;
		cameraTop -= 5000;	cameraBot += 5000;
	}
	else
	{
		cameraLeft -= 200;	cameraRight += 200;
		cameraTop -= 300;	cameraBot += 550;
	}

	// Random initialization
	float unitLeft, unitRight, unitTop, unitBot;
	sf::FloatRect camRect(camera.pos.x, camera.pos.y, camera.res.x, camera.res.y);
	sf::FloatRect objRect;
	vector<int> miniQueue;
	vector<int> sortedQueue;

	for (int i = 0; i < game.unitCounter; i++)
	{
		unitTop = game.unit[i].pos.y - game.unit[i].center.y;
		unitBot = unitTop + game.unit[i].size.y;
		unitLeft = game.unit[i].pos.x - game.unit[i].center.x;
		unitRight = unitLeft + game.unit[i].size.x;

		if (!game.unit[i].hasRef(REF_UNIT_NORENDER)
			&& (game.unit[i].hasRef(REF_UNIT_ALWAYSVISIBLE) || (unitRight >= cameraLeft && unitLeft <= cameraRight && unitTop >= cameraTop && unitBot <= cameraBot)
			/*&& !game.unit[i].hasRef(REF_UNIT_ALWAYSVISIBLE_BOT) && !game.unit[i].hasRef(REF_UNIT_ALWAYSVISIBLE_TOP))
			|| (game.unit[i].hasRef(REF_UNIT_ALWAYSVISIBLE_BOT) && y == cameraTop)
			|| (game.unit[i].hasRef(REF_UNIT_ALWAYSVISIBLE_TOP) && y == cameraBot - step*/))
		{
			// Check if unit is already in the queue
			bool found = false;
			for (int checkVal : miniQueue)
			{
				if (checkVal == i)
				{
					found = true;
					break;
				}
			}
			// Don't allow repeating
			if (!found) { miniQueue.push_back(i); }
		}
	}
	// Sorting
	bool renderFirst = false;
	bool renderLast = false;
	int bestUnit = -1;
	float bestPos = -1.00f;
	while ((int)miniQueue.size() > 0)
	{
		// Search
		for (int i = 0; i < (int)miniQueue.size(); i++)
		{
			if (bestUnit == -1 || game.unit[miniQueue[i]].pos.y < bestPos || game.unit[miniQueue[i]].hasRef(REF_UNIT_RENDERFIRST))
			{
				bestUnit = i;
				bestPos = game.unit[miniQueue[i]].pos.y;
				if (game.unit[miniQueue[i]].hasRef(REF_UNIT_RENDERFIRST)) { break; }
			}
		}
		// Add
		preRender.units.queue.push_back(miniQueue[bestUnit]);
		// Erase
		miniQueue[bestUnit] = miniQueue[miniQueue.size() - 1];
		miniQueue.pop_back();
		// Clear
		bestUnit = -1;
		bestPos = -1.00f;
	}
	mutex.renderUnits.unlock();
	game.access.unlock();
}