Blizzard / s2client-api

StarCraft II Client - C++ library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
1.66k stars 282 forks source link

In nonmultithreaded, multi-player game, the call of OnGameEnd() is missing. #325

Open monarchBacilluscoli opened 4 years ago

monarchBacilluscoli commented 4 years ago

I guess the problem comes from here Just see the comments

void CoordinatorImp::StepAgents() {
    auto step_agent = [this](Agent* a) {
        ControlInterface* control = a->Control();

        if (control->GetAppState() != AppState::normal) {
            return;
        }

        if (control->PollLeaveGame()) {
            return;
        }

        if (control->IsFinishedGame()) {
            return;
        }

        control->Step(process_settings_.step_size);
        control->WaitStep();                        //1. from here we know the game has been end.
        if (process_settings_.multi_threaded) {
            CallOnStep(a);                          //2. The first chance to call the CallOnStep() is missing (This function will call OnGameEnd() based on whether the Agent is in game or not) since it is not a multi_threaded game according to my settings.
        }
    };

    if (agents_.size() == 1) {
        step_agent(agents_.front()); 
    }
    else {
        RunParallel(step_agent, agents_);           // 0. Normal opeartion as usual
    }

    if (!process_settings_.multi_threaded) {
        for (auto a : agents_) {
            if (a->Control()->GetAppState() != AppState::normal) {
                continue;
            }

            // It is possible to have a pending leave game request here.
            if (a->Control()->PollLeaveGame()) {    // 3. In PollLeaveGame() it checks if the Agent is in game, is not, return true and continue
                continue;
            }

            CallOnStep(a);                          // 4. Because of step 3, the last precious call of CallOnStep (that is, the call of OnGameEnd() as I have mentioned in step 2) is missing again
        }
    }

}