MCPcopy Create free account
hub / github.com/bwapi/bwapi / insertIntoCommandBuffer

Method insertIntoCommandBuffer

bwapi/include/BWAPI/Client/CommandTemp.h:21–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 void execute(bool isCurrentFrame);
20
21 void insertIntoCommandBuffer(std::vector<std::vector<CommandTemp<UnitImpl, PlayerImpl>>> &buf) && {
22 const auto addToBuffer = [&buf](auto &&command, int frames)
23 {
24 command.execute(frames == 0);
25
26 if (static_cast<decltype(frames)>(buf.size()) < frames)
27 {
28 buf.resize(frames); // Will probably never trigger, since we resize
29 // the buffer in applyLatencyCompensation()
30 // but it's better to be safe.
31 }
32
33 if(frames > 0)
34 buf[frames - 1].push_back(std::forward<Command>(command)); // Forward rvalue ref
35 };
36
37 auto orderEvent = makeEvent(EventType::Order);
38 auto finishEvent = makeEvent(EventType::Finish);
39
40 switch (command.type) {
41 // RLF: Resource event
42 // RLF + 1: Order event
43 // RLF + 2: Finish event
44 case UnitCommandTypes::Cancel_Construction:
45 addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames());
46 addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1);
47 addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 2);
48 break;
49
50 // RLF: Resource event
51 // RLF + 1: Order event
52 case UnitCommandTypes::Build_Addon:
53 case UnitCommandTypes::Cancel_Addon:
54 case UnitCommandTypes::Cancel_Research:
55 case UnitCommandTypes::Cancel_Upgrade:
56 case UnitCommandTypes::Morph:
57 addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames());
58 addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1);
59 break;
60
61 // RLF: Resource event
62 // RLF + 1: Order event (only for building -> building morphs)
63 // RLF + 13: Finish event (only for unit -> unit morphs)
64 // RLF + 15: Finish event (only for building -> building morphs)
65 case UnitCommandTypes::Cancel_Morph:
66 addToBuffer(std::move(*this), Broodwar->getRemainingLatencyFrames());
67
68 if (auto unit = reinterpret_cast<UnitImpl*>(command.unit);
69 unit && unit->getType().isBuilding())
70 {
71 addToBuffer(std::move(orderEvent), Broodwar->getRemainingLatencyFrames() + 1);
72 addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 15);
73 }
74 else
75 {
76 addToBuffer(std::move(finishEvent), Broodwar->getRemainingLatencyFrames() + 13);
77 }
78 break;

Callers 1

addToCommandBufferMethod · 0.80

Calls 6

resizeMethod · 0.80
isBuildingMethod · 0.80
executeMethod · 0.45
sizeMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected