Beispiel #1
0
/**
**  Draw a map viewport.
*/
void CViewport::Draw() const
{
	PushClipping();
	this->SetClipping();

	/* this may take while */
	this->DrawMapBackgroundInViewport();

	CurrentViewport = this;
	{
		// Now we need to sort units, missiles, particles by draw level and draw them
		std::vector<CUnit *> unittable;
		std::vector<Missile *> missiletable;
		std::vector<CParticle *> particletable;

		FindAndSortUnits(*this, unittable);
		const size_t nunits = unittable.size();
		FindAndSortMissiles(*this, missiletable);
		const size_t nmissiles = missiletable.size();
		ParticleManager.prepareToDraw(*this, particletable);
		const size_t nparticles = particletable.size();

		size_t i = 0;
		size_t j = 0;
		size_t k = 0;


		while ((i < nunits && j < nmissiles) || (i < nunits && k < nparticles)
			   || (j < nmissiles && k < nparticles)) {
			if (i == nunits) {
				if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					missiletable[j]->DrawMissile(*this);
					++j;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (j == nmissiles) {
				if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					particletable[k]->draw();
					++k;
				}
			} else if (k == nparticles) {
				if (unittable[i]->Type->DrawLevel < missiletable[j]->Type->DrawLevel) {
					unittable[i]->Draw(*this);
					++i;
				} else {
					missiletable[j]->DrawMissile(*this);
					++j;
				}
			} else {
				if (unittable[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
					if (unittable[i]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						unittable[i]->Draw(*this);
						++i;
					} else {
						particletable[k]->draw();
						++k;
					}
				} else {
					if (missiletable[j]->Type->DrawLevel < particletable[k]->getDrawLevel()) {
						missiletable[j]->DrawMissile(*this);
						++j;
					} else {
						particletable[k]->draw();
						++k;
					}
				}
			}
		}
		for (; i < nunits; ++i) {
			unittable[i]->Draw(*this);
		}
		for (; j < nmissiles; ++j) {
			missiletable[j]->DrawMissile(*this);
		}
		for (; k < nparticles; ++k) {
			particletable[k]->draw();
		}
		ParticleManager.endDraw();
	}

	this->DrawMapFogOfWar();

	//
	// Draw orders of selected units.
	// Drawn here so that they are shown even when the unit is out of the screen.
	//
	if (!Preference.ShowOrders) {
	} else if (Preference.ShowOrders < 0
			   || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
		for (int i = 0; i < NumSelected; ++i) {
			ShowOrder(*Selected[i]);
		}
	}

	//
	// Draw unit's name popup
	//
	if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
		const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
		const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);

		if (UI.MouseViewport->IsInsideMapArea(CursorScreenPos) && UnitUnderCursor
			&& ((isMapFieldVisile && !UnitUnderCursor->Type->BoolFlag[ISNOTSELECTABLE_INDEX].value) || ReplayRevealMap)) {
			ShowUnitName(*this, CursorScreenPos, UnitUnderCursor);
		} else if (!isMapFieldVisile) {
			ShowUnitName(*this, CursorScreenPos, NULL, true);
		}
	}

	DrawBorder();
	PopClipping();
}
Beispiel #2
0
/**
**  Draw a map viewport.
*/
void CViewport::Draw() const
{
    PushClipping();
    this->SetClipping();

    /* this may take while */
    this->DrawMapBackgroundInViewport();

    CurrentViewport = this;
    {
        std::vector<CUnit *> unittable;
        std::vector<Missile *> missiletable;

        // We find and sort units after draw level.
        FindAndSortUnits(*this, unittable);
        const size_t nunits = unittable.size();
        FindAndSortMissiles(*this, missiletable);
        const size_t nmissiles = missiletable.size();
        size_t i = 0;
        size_t j = 0;

        while (i < nunits && j < nmissiles) {
            if (unittable[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
                unittable[i]->Draw(*this);
                ++i;
            } else {
                missiletable[j]->DrawMissile(*this);
                ++j;
            }
        }
        for (; i < nunits; ++i) {
            unittable[i]->Draw(*this);
        }
        for (; j < nmissiles; ++j) {
            missiletable[j]->DrawMissile(*this);
        }
    }

    ParticleManager.draw(*this);

    this->DrawMapFogOfWar();

    //
    // Draw orders of selected units.
    // Drawn here so that they are shown even when the unit is out of the screen.
    //
    if (!Preference.ShowOrders) {
    } else if (Preference.ShowOrders < 0
               || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
        for (int i = 0; i < NumSelected; ++i) {
            ShowOrder(*Selected[i]);
        }
    }

    //
    // Draw unit's name popup
    //
    if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
        const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
        const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);

        if (UI.MouseViewport->IsInsideMapArea(CursorScreenPos)
                && (isMapFieldVisile || ReplayRevealMap)) {
            ShowUnitName(*this, CursorScreenPos, UnitUnderCursor);
        } else if (!isMapFieldVisile) {
            ShowUnitName(*this, CursorScreenPos, NULL, true);
        }
    }

    DrawBorder();
    PopClipping();
}