| 171 | } |
| 172 | |
| 173 | void CommandOptimizer::flush() |
| 174 | { |
| 175 | // TODO Only process on the frame before commands are sent |
| 176 | |
| 177 | // Iterate the command types |
| 178 | for (int i = 0; i < UnitCommandTypes::Enum::None; ++i) |
| 179 | { |
| 180 | // Declare our temporary variables |
| 181 | std::vector<Unit> groupOf12; |
| 182 | |
| 183 | Position pos = Positions::None; |
| 184 | int e = 0; |
| 185 | Unit t = nullptr; |
| 186 | UnitType ut; |
| 187 | bool o = false; |
| 188 | |
| 189 | // Iterate the list |
| 190 | auto cmd = optimizerQueue[i].begin(); |
| 191 | |
| 192 | // Re-Iterate all remaining commands |
| 193 | while (cmd != optimizerQueue[i].end()) |
| 194 | { |
| 195 | // Iterate all commands, and only process those that are equal |
| 196 | while (cmd != optimizerQueue[i].end()) |
| 197 | { |
| 198 | // Ignore anything but the command that the unit last processed |
| 199 | /*if ( //static_cast<UnitImpl*>(cmd->unit)->lastImmediateCommandFrame == this->getFrameCount() && |
| 200 | static_cast<UnitImpl*>(cmd->unit)->lastImmediateCommand != *cmd ) |
| 201 | { |
| 202 | cmd = commandOptimizer[i].erase(cmd); |
| 203 | continue; |
| 204 | }*/ |
| 205 | |
| 206 | // If we are starting a new command grouping |
| 207 | if (groupOf12.empty()) |
| 208 | { |
| 209 | // Assign our comparison variables to determine which commands should be grouped |
| 210 | // Note: Using individual variables instead of comparing UnitCommand operator== because |
| 211 | // it will also compare the type which is not necessary, and we may create a new |
| 212 | // optimization type that does a fuzzy position comparison |
| 213 | e = cmd->extra; |
| 214 | t = cmd->target; |
| 215 | pos = cmd->getTargetPosition(); |
| 216 | if (i == UnitCommandTypes::Attack_Unit || |
| 217 | i == UnitCommandTypes::Unload_All || |
| 218 | i == UnitCommandTypes::Load || |
| 219 | i == UnitCommandTypes::Cancel_Morph) |
| 220 | o = cmd->unit->getType().isBuilding(); |
| 221 | else if (i == UnitCommandTypes::Use_Tech) |
| 222 | o = cmd->unit->isSieged() || cmd->unit->isCloaked() || cmd->unit->isBurrowed(); |
| 223 | else |
| 224 | o = false; |
| 225 | groupOf12.push_back(cmd->unit); |
| 226 | cmd = optimizerQueue[i].erase(cmd); |
| 227 | } // otherwise if this command is the same as the first, the units can be grouped |
| 228 | else if (e == cmd->extra && t == cmd->target && pos == cmd->getTargetPosition()) |
| 229 | { |
| 230 | bool oTmp; |
no test coverage detected