Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Make d click optional, #4 #5

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ build

# IDE - VSCode
.vscode/

# Clangd cache
.cache/
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ set(BUILD_API_TESTS OFF CACHE INTERNAL "" FORCE)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

if (MSVC)
# Setup MSVC parallelized builds.
add_compile_options(/MP)

# Use statically linked runtime.
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
endif ()

add_subdirectory("cpp-sc2")
add_subdirectory("src")
add_subdirectory("test")
2 changes: 1 addition & 1 deletion cpp-sc2
24 changes: 15 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class Replay : public sc2::ReplayObserver
CameraModuleObserver m_cameraModule;
float m_speed;
long m_delay;
bool m_toggle_production_tab;
std::map < sc2::Tag, bool> alreadySeen;

Replay(float speed, long delay):
sc2::ReplayObserver(), m_cameraModule(this), m_speed(speed), m_delay(delay)
Replay(float speed, long delay, bool toggle_production_tab):
sc2::ReplayObserver(), m_cameraModule(this),
m_speed(speed), m_delay(delay),
m_toggle_production_tab(toggle_production_tab)
{
}

Expand All @@ -33,6 +36,9 @@ class Replay : public sc2::ReplayObserver
}
*/
m_cameraModule.onStart();

if (m_toggle_production_tab)
pressDKey();
}

void OnUnitCreated(const sc2::Unit* unit) final
Expand All @@ -47,13 +53,9 @@ class Replay : public sc2::ReplayObserver

void OnStep() final
{
if (Observation()->GetGameLoop() == 10)
{
pressDKey();
}
Timer t;
t.start();
Observation()->GetChatMessages();
Observation()->GetChatMessages();
for (const auto & unit : Observation()->GetUnits())
{
if (!alreadySeen[unit->tag])
Expand Down Expand Up @@ -91,7 +93,8 @@ int main(int argc, char* argv[])
arg_parser.AddOptions({
{ "-p", "--Path", "Path to a single SC2 replay or directory with replay files", true },
{ "-s", "--Speed", "Replay speed", false},
{ "-d", "--Delay", "Delay after game in ms.", false}
{ "-d", "--Delay", "Delay after game in ms.", false},
{ "-t", "--Toggle", "Toggle the Production tab on game start (Windows only).", false},
});
arg_parser.Parse(static_cast<int>(observer_options.size()), &observer_options[0]);

Expand Down Expand Up @@ -125,13 +128,16 @@ int main(int argc, char* argv[])
std::cout << "Using default delay: 3000ms" << std::endl;
}

std::string dummy;
bool toggle_production_tab = arg_parser.Get("Toggle", dummy);

std::vector<std::string> replayFiles;
unsigned long replayIndex = 0;
sc2::Coordinator coordinator;
if (!coordinator.LoadSettings(static_cast<int>(sc2_options.size()), &sc2_options[0])) {
return 1;
}
Replay replayObserver(speed, delay);
Replay replayObserver(speed, delay, toggle_production_tab);
coordinator.AddReplayObserver(&replayObserver);
coordinator.SetReplayPerspective(0);
//coordinator.SetRealtime(true);
Expand Down