----------------------------------------- APPLY LATENCY COMPENSATION
| 18 | } |
| 19 | //----------------------------------------- APPLY LATENCY COMPENSATION |
| 20 | void GameImpl::applyLatencyCompensation() |
| 21 | { |
| 22 | // Remove the current frame from the buffer and execute the current frame |
| 23 | // (only some actions execute on the current frame, like resource reserving) |
| 24 | if (!this->commandBuffer.empty()) |
| 25 | { |
| 26 | for (auto &command : this->commandBuffer.front()) |
| 27 | { |
| 28 | command.execute(true); |
| 29 | } |
| 30 | this->commandBuffer.erase(std::begin(this->commandBuffer)); |
| 31 | } |
| 32 | |
| 33 | // Apply latency compensation |
| 34 | for (auto buf = 0; buf < getRemainingLatencyFrames() |
| 35 | && buf < static_cast<int>(this->commandBuffer.size()); ++buf) |
| 36 | { |
| 37 | for (auto &command : this->commandBuffer[buf]) |
| 38 | { |
| 39 | command.execute(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Prepare buffer space for new commands |
| 44 | if (this->commandBuffer.size() < static_cast<size_t>(getRemainingLatencyFrames() + 15)) |
| 45 | { |
| 46 | this->commandBuffer.resize(getRemainingLatencyFrames() + 15); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | //--------------------------------------------- EXECUTE COMMAND -------------------------------------------- |
| 51 | void GameImpl::executeCommand(UnitCommand command) |