コード例 #1
0
ファイル: gml_base.cpp プロジェクト: AMDmi3/spring
	void PrintStartupMessage(int showMTInfo) {
		if (showMTInfo == -1)
			return;
		if (showMTInfo != MT_LUA_NONE) {
			if (showMTInfo == MT_LUA_SINGLE || showMTInfo == MT_LUA_SINGLE_BATCH || showMTInfo == MT_LUA_DUAL_EXPORT) {
				LOG("[Threading] Multithreading is enabled but currently running in compatibility mode %d", showMTInfo);
			} else {
				LOG("[Threading] Multithreading is enabled and currently running in mode %d", showMTInfo);
			}
			if (showMTInfo == MT_LUA_SINGLE) {
				CKeyBindings::HotkeyList lslist = keyBindings->GetHotkeys("luaui selector");
				std::string lskey = lslist.empty() ? "" : " (press " + lslist.front() + ")";
				LOG("[Threading] Games that use lua based rendering may run very slow in this mode, "
					"indicated by a high LUA-SYNC-CPU(MT) value displayed in the upper right corner");
				LOG("[Threading] Consider MultiThreadLua = %d in the settings to improve performance, "
					"or try to disable LuaShaders and all rendering widgets%s", (int)MT_LUA_SINGLE_BATCH, lskey.c_str());
			} else if (showMTInfo == MT_LUA_SINGLE_BATCH) {
				LOG("[Threading] Games that use lua gadget based rendering may run very slow in this mode, "
					"indicated by a high LUA-SYNC-CPU(MT) value displayed in the upper right corner");
			} else if (showMTInfo == MT_LUA_DUAL_EXPORT) {
				LOG("[Threading] Games that use lua gadgets which export data may run very slow in this mode, "
					"indicated by a high LUA-EXP-SIZE(MT) value displayed in the upper right corner");
			}
		}  else if (configHandler->GetBool("EnableUnsafeAndBrokenMT"))  {
			LOG("[Threading] Multithreading is disabled because the game or system appears incompatible");
			LOG("[Threading] MultiThreadCount > 1 in the settings will forcefully enable multithreading");
		}
	}
コード例 #2
0
ファイル: GameSetupDrawer.cpp プロジェクト: Tsuful/spring
void GameSetupDrawer::Draw()
{
    if (readyCountdown > 0) {
        readyCountdown -= (SDL_GetTicks() - lastTick);
        lastTick = SDL_GetTicks();

        if (readyCountdown <= 0) {
            GameSetupDrawer::Disable();
            return; // *this is deleted!
        }
    }

    std::string state = "Unknown state.";
    if (readyCountdown > 0) {
        char buf[64];
        sprintf(buf, "Starting in %i", readyCountdown / 1000);
        state = buf;
    } else if (!playerHandler->Player(gu->myPlayerNum)->spectator && !playerHandler->Player(gu->myPlayerNum)->readyToStart) {
        state = "Choose start pos";
    } else if (gameServer) {
        CKeyBindings::HotkeyList list = keyBindings->GetHotkeys("forcestart");
        std::string primary = "<none>";
        if (!list.empty())
            primary = list.front();
        state = std::string("Waiting for players, press ")+primary + " to force start";
    } else {
        state = "Waiting for players";
    }

    int numPlayers = (int)playerHandler->ActivePlayers();
    //! not the most efficent way to do this, but who cares?
    std::map<int, std::string> playerStates;
    for (int a = 0; a < numPlayers; a++) {
        const CPlayer* player = playerHandler->Player(a);

        if (!player->active) {
            // player does not become active until we receive NETMSG_PLAYERNAME
            playerStates[a] = "missing";
        } else if (!player->spectator && !player->readyToStart) {
            playerStates[a] = "notready";
        } else {
            playerStates[a] = "ready";
        }
    }

    CStartPosSelecter* selector = CStartPosSelecter::selector;
    bool ready = (selector == NULL);

    if (eventHandler.GameSetup(state, ready, playerStates)) {
        if (selector) {
            selector->ShowReady(false);
            if (ready) {
                selector->Ready();
            }
        }
        return; //! LuaUI says it will do the rendering
    }

    if (selector) {
        selector->ShowReady(true);
    }

    font->Begin();
    font->SetColors(); //! default
    font->glPrint(0.3f, 0.7f, 1.0f, FONT_OUTLINE | FONT_SCALE | FONT_NORM, state);

    for (int a = 0; a <= numPlayers; a++) {
        const float4* color;
        static const float4      red(1.0f, 0.2f, 0.2f, 1.0f);
        static const float4    green(0.2f, 1.0f, 0.2f, 1.0f);
        static const float4   yellow(0.8f, 0.8f, 0.2f, 1.0f);
        static const float4    white(1.0f, 1.0f, 1.0f, 1.0f);
        static const float4     cyan(0.0f, 0.9f, 0.9f, 1.0f);
        static const float4 lightred(1.0f, 0.5f, 0.5f, 1.0f);
        if (a == numPlayers) {
            color = &white;
        } else if (playerHandler->Player(a)->spectator) {
            if (!playerHandler->Player(a)->active) {
                color = &lightred;
            } else {
                color = &cyan;
            }
        } else if (!playerHandler->Player(a)->active) {
            color = &red;
        } else if (!playerHandler->Player(a)->readyToStart) {
            color = &yellow;
        } else {
            color = &green;
        }

        std::string name = "Players:";
        if (a != numPlayers) {
            name = playerHandler->Player(a)->name;
        }
        const float fontScale = 1.0f;
        const float fontSize  = fontScale * font->GetSize();
        const float yScale = fontSize * font->GetLineHeight() * globalRendering->pixelY;
        const float yPos = 0.5f - (0.5f * yScale * numPlayers) + (yScale * (float)a);
        const float xPos = 10.0f * globalRendering->pixelX;
        font->SetColors(color, NULL);
        font->glPrint(xPos, yPos, fontSize, FONT_OUTLINE | FONT_NORM, name);
    }
    font->End();
}
コード例 #3
0
ファイル: GameSetupDrawer.cpp プロジェクト: AMDmi3/spring
void GameSetupDrawer::Draw()
{
    if (readyCountdown > spring_nulltime) {
        readyCountdown -= (spring_gettime() - lastTick);
        lastTick = spring_gettime();

        if (readyCountdown <= spring_nulltime) {
            GameSetupDrawer::Disable();
            return; // *this is deleted!
        }
    }

    std::map<int, std::string> playerStates;
    std::string startState = "Unknown state.";

    if (readyCountdown > spring_nulltime) {
        startState = "Starting in " + IntToString(readyCountdown.toSecsi(), "%i");
    } else if (!playerHandler->Player(gu->myPlayerNum)->spectator && !playerHandler->Player(gu->myPlayerNum)->IsReadyToStart()) {
        startState = "Choose start pos";
    } else if (gameServer) {
        // we are the host and can get the show on the road by force
        const CKeyBindings::HotkeyList fsKeys = keyBindings->GetHotkeys("forcestart");
        const std::string& fsKey = fsKeys.empty() ? "<none>" : fsKeys.front();
        startState = std::string("Waiting for players, press ") + fsKey + " to force start";
    } else {
        startState = "Waiting for players";
    }

    const unsigned int numPlayers = playerHandler->ActivePlayers();

    // not the most efficent way to do this, but who cares?
    for (unsigned int a = 0; a < numPlayers; a++) {
        const CPlayer* player = playerHandler->Player(a);

        if (!player->active) {
            // player does not become active until we receive NETMSG_PLAYERNAME
            playerStates[a] = "missing";
        } else if (!player->spectator && !player->IsReadyToStart()) {
            playerStates[a] = "notready";
        } else {
            playerStates[a] = "ready";
        }
    }

    // if choosing in-game, selector remains non-NULL
    // so long as a position has not been picked yet
    // and deletes itself afterwards
    bool playerHasReadied = (CStartPosSelecter::GetSelector() == NULL);

    if (eventHandler.GameSetup(startState, playerHasReadied, playerStates)) {
        if (CStartPosSelecter::GetSelector() != NULL) {
            CStartPosSelecter::GetSelector()->ShowReadyBox(false);

            if (playerHasReadied) {
                // either we were ready before or a client
                // listening to the GameSetup event forced
                // us to be
                CStartPosSelecter::GetSelector()->Ready(true);
            }
        }

        // LuaUI says it will do the rendering
        return;
    }

    // LuaUI doesn't want to draw, keep showing the box
    if (CStartPosSelecter::GetSelector() != NULL) {
        CStartPosSelecter::GetSelector()->ShowReadyBox(true);
    }

    font->Begin();
    font->SetColors(); // default
    font->glPrint(0.3f, 0.7f, 1.0f, FONT_OUTLINE | FONT_SCALE | FONT_NORM, startState);

    for (unsigned int a = 0; a <= numPlayers; a++) {
        static const float4      red(1.0f, 0.2f, 0.2f, 1.0f);
        static const float4    green(0.2f, 1.0f, 0.2f, 1.0f);
        static const float4   yellow(0.8f, 0.8f, 0.2f, 1.0f);
        static const float4    white(1.0f, 1.0f, 1.0f, 1.0f);
        static const float4     cyan(0.0f, 0.9f, 0.9f, 1.0f);
        static const float4 lightred(1.0f, 0.5f, 0.5f, 1.0f);

        const float fontScale = 1.0f;
        const float fontSize  = fontScale * font->GetSize();
        const float yScale = fontSize * font->GetLineHeight() * globalRendering->pixelY;
        // note: list is drawn in reverse order, last player first
        const float yPos = 0.5f - (0.5f * yScale * numPlayers) + (yScale * a);
        const float xPos = 10.0f * globalRendering->pixelX;

        const CPlayer* player = NULL;
        const float4* color = NULL;

        std::string name;

        if (a == numPlayers) {
            color = &white;
            name = "Players:";
        } else {
            player = playerHandler->Player(a);
            name = player->name;

            if (player->spectator) {
                if (!player->active) {
                    color = &lightred;
                } else {
                    color = &cyan;
                }
            } else if (!player->active) {
                color = &red;
            } else if (!player->IsReadyToStart()) {
                color = &yellow;
            } else {
                color = &green;
            }
        }

        font->SetColors(color, NULL);
        font->glPrint(xPos, yPos, fontSize, FONT_OUTLINE | FONT_NORM, name);
    }
    font->End();
}