Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli #10

Merged
merged 11 commits into from
May 1, 2024
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Checks: '-*,readability-identifier-naming'

FormatStyle: 'file'

CheckOptions:
# Namespace
- key: readability-identifier-naming.NamespaceCase
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/cpp-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: C/C++ Linter
uses: cpp-linter/cpp-linter-action@v2
Expand All @@ -28,9 +26,5 @@ jobs:
files-changed-only: false
lines-changed-only: ${{ github.event_name == 'pull_request' }}
style: file
tidy-checks: '-*'
tidy-checks: ''
step-summary: true

- name: Fail
if: steps.linter.outputs.checks-failed > 0
run: exit 1
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_subdirectory(source/vision)
add_subdirectory(source/referee)
add_subdirectory(source/sender)
add_subdirectory(source/soccer)
add_subdirectory(source/cli)
add_subdirectory(source/gui)

set(CPACK_GENERATOR ZIP)
Expand Down
38 changes: 38 additions & 0 deletions source/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
project(${CMAKE_PROJECT_NAME}-cli)

set(HEADER_FILES
pch.h
)

set(SOURCE_FILES
main.cpp
)

add_executable(${PROJECT_NAME}
${HEADER_FILES}
${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME} PRIVATE
${CMAKE_PROJECT_NAME}-common
${CMAKE_PROJECT_NAME}-vision
${CMAKE_PROJECT_NAME}-referee
${CMAKE_PROJECT_NAME}-sender
${CMAKE_PROJECT_NAME}-soccer)

set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${USE_UNITY_BUILDS})

get_target_property(COMMON_PCHS ${CMAKE_PROJECT_NAME}-common INTERFACE_PRECOMPILE_HEADERS)
get_target_property(VISION_PCHS ${CMAKE_PROJECT_NAME}-vision INTERFACE_PRECOMPILE_HEADERS)
get_target_property(REFEREE_PCHS ${CMAKE_PROJECT_NAME}-referee INTERFACE_PRECOMPILE_HEADERS)
get_target_property(SENDER_PCHS ${CMAKE_PROJECT_NAME}-sender INTERFACE_PRECOMPILE_HEADERS)
get_target_property(SOCCER_PCHS ${CMAKE_PROJECT_NAME}-soccer INTERFACE_PRECOMPILE_HEADERS)

target_precompile_headers(${PROJECT_NAME}
PUBLIC ${COMMON_PCHS}
PUBLIC ${VISION_PCHS}
PUBLIC ${REFEREE_PCHS}
PUBLIC ${SENDER_PCHS}
PUBLIC ${SOCCER_PCHS}
PRIVATE pch.h)

install(TARGETS ${PROJECT_NAME})
150 changes: 150 additions & 0 deletions source/cli/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#define ImmortalsIsTheBest true

Check notice on line 1 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

Run clang-format on source/cli/main.cpp

File source/cli/main.cpp does not conform to Custom style guidelines. (lines 15)

Check warning on line 1 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:1:9 [readability-identifier-naming]

invalid case style for macro definition 'ImmortalsIsTheBest'

using namespace Tyr;

Check failure on line 3 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:3:17 [clang-diagnostic-error]

expected namespace name

int main()
{
Common::Services::initialize();

Check failure on line 7 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:7:5 [clang-diagnostic-error]

use of undeclared identifier 'Common'

if (!ImmortalsIsTheBest)
{
Common::logCritical("Immortals is not the best SSL team anymore.");

Check failure on line 11 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:11:9 [clang-diagnostic-error]

use of undeclared identifier 'Common'
Common::logCritical("Shutting down the system...");

Check failure on line 12 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:12:9 [clang-diagnostic-error]

use of undeclared identifier 'Common'
}

Common::WorldState *state = new Common::WorldState();

Check failure on line 15 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:15:5 [clang-diagnostic-error]

use of undeclared identifier 'Common'

Check failure on line 15 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:15:47 [clang-diagnostic-error]

use of undeclared identifier 'Common'
Common::RefereeState *referee_state = new Common::RefereeState();

Check failure on line 16 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:16:5 [clang-diagnostic-error]

use of undeclared identifier 'Common'

Check failure on line 16 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:16:47 [clang-diagnostic-error]

use of undeclared identifier 'Common'

Common::logInfo(" Connecting to RefereeBox server at {} on port : {}", Common::setting().referee_address.port,

Check failure on line 18 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:18:5 [clang-diagnostic-error]

use of undeclared identifier 'Common'

Check failure on line 18 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:18:76 [clang-diagnostic-error]

use of undeclared identifier 'Common'
Common::setting().referee_address.port);
Referee::Referee referee_2018(state, referee_state);
if (referee_2018.connectToRefBox())
{
Common::logInfo("Connected to RefBox successfully :)");
}
else
{
Common::logError("Hey you! Put the LAN cable back in its socket, or ...");
}

Common::logInfo("Connecting to Vision server at {} on port: {}", Common::setting().vision_address.ip,
Common::setting().vision_address.port);
Vision::Vision vision(state);
if (vision.isConnected())
{
Common::logInfo("Connected to Vision successfully :)");
}
else
{
Common::logError("Hey you! Put the LAN cable back in its socket, or ...");
// return 0;
}

Sender::Sender *senderBase = new Sender::Sender();

Check warning on line 43 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:43:21 [readability-identifier-naming]

invalid case style for local variable 'senderBase'

Soccer::Ai *aii = new Soccer::Ai(state, referee_state, senderBase);

auto grsim_fwd = new Sender::Grsim(Common::setting().grsim_address);

bool exited = false;
std::mutex lock;

Common::logInfo(" Now it is time, lets rock...");

auto ai_func = [&]()
{
Common::Timer timer;

while (ImmortalsIsTheBest) // Hope it lasts Forever...
{
timer.start();

vision.recieveAllCameras();

lock.lock();

// The vision process
vision.ProcessVision();
// The AI process
aii->Process(state);

// TODO #3 comment the GRsim output
// grsim_fwd->SendData((reinterpret_cast<Ai *>(aii))->OwnRobot, Setting::kMaxOnFieldTeamRobots,
// settings->our_color);

// The sending process
senderBase->sendAll();

// debugging (the visualizer written by python) :
Common::debug().broadcast();

// LordHippos GUI
// vision.SendGUIData(state,aii->AIDebug);

lock.unlock();
Common::logDebug("FPS: {}", 1.0 / timer.interval());
}
exited = true;
};

auto ref_func = [&]()
{
while ((!exited) && (ImmortalsIsTheBest)) // Hope it lasts Forever...
{
if (referee_2018.recieve())
{
// std::cout << "Referre Boz" << std::endl;
lock.lock();
referee_2018.process();
lock.unlock();
// std::cout << "Referre Boz "<< referee_2018.command_CNT << std::endl;
}
}
};

auto str_func = [&]()
{
std::shared_ptr<Common::UdpClient> strategyUDP =
std::make_shared<Common::UdpClient>(Common::setting().strategy_address);

while ((!exited) && (ImmortalsIsTheBest)) // Hope it lasts Forever...
{

auto receivedStrategy = strategyUDP->receiveRaw();

Check warning on line 113 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:113:34 [readability-identifier-naming]

invalid case style for local variable 'receivedStrategy'
const std::string strategySrcAdd = strategyUDP->getLastReceiveEndpoint().address().to_string();

Check warning on line 114 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:114:34 [readability-identifier-naming]

invalid case style for local constant 'strategySrcAdd'
const unsigned short strategySrcPort = strategyUDP->getLastReceiveEndpoint().port();

Check warning on line 115 in source/cli/main.cpp

View workflow job for this annotation

GitHub Actions / check

source/cli/main.cpp:115:34 [readability-identifier-naming]

invalid case style for local constant 'strategySrcPort'
if (receivedStrategy.size() > 11)
{
Common::logInfo("Recieved \"strategy.ims\" with size: {} KB, from {} on port {}",
float(receivedStrategy.size()) / 1000.0f, strategySrcAdd, strategySrcPort);
lock.lock();
aii->read_playBook_str(receivedStrategy.data(), receivedStrategy.size());
lock.unlock();
std::string strategy_path(DATA_DIR);
strategy_path.append("/strategy.ims");
std::ofstream strategyFile(strategy_path.c_str(), std::ios::out | std::ios::binary);
strategyFile.write(receivedStrategy.data(), receivedStrategy.size());
strategyFile.close();
}
else
{
Common::logWarning("Invalid \"strategy.ims\" received with size: {}", receivedStrategy.size());
}
}
};

std::thread ai_thread(ai_func);
std::thread ref_thread(ref_func);
std::thread str_thread(str_func);

ai_thread.join();
ref_thread.join();
str_thread.join();

delete state;
delete aii;

Common::Services::shutdown();

return 0;
}
7 changes: 7 additions & 0 deletions source/cli/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <fstream>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
103 changes: 54 additions & 49 deletions source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,75 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(tomlplusplus REQUIRED IMPORTED_TARGET tomlplusplus)

set(HEADER_FILES
pch.h
services.h
setting.h
config/config.h
debugging/common_colors.h
debugging/debug.h
logging/logging.h
logging/macros.h
math/angle.h
math/helpers.h
math/linear.h
math/median_filter.h
math/random.h
math/vector.h
math/geom/circle.h
math/geom/line_segment.h
math/geom/line.h
math/geom/rect.h
network/udp_client.h
network/udp_server.h
state/game_commands.h
state/game.h
state/referee.h
state/world.h
timer/timer.h)
pch.h
services.h
setting.h
config/config.h
debugging/common_colors.h
debugging/debug.h
logging/logging.h
logging/macros.h
math/angle.h
math/helpers.h
math/linear.h
math/median_filter.h
math/random.h
math/vector.h
math/geom/circle.h
math/geom/line_segment.h
math/geom/line.h
math/geom/rect.h
network/udp_client.h
network/udp_server.h
state/game_commands.h
state/game.h
state/referee.h
state/world.h
timer/timer.h)

set(SOURCE_FILES
setting.cpp
config/config.cpp
debugging/common_colors.cpp
debugging/debug.cpp
logging/logging.cpp
math/angle.cpp
math/helpers.cpp
math/linear.cpp
math/random.cpp
math/vector.cpp
math/geom/circle.cpp
math/geom/line.cpp
math/geom/rect.cpp
network/udp_client.cpp
network/udp_server.cpp
timer/timer.cpp)
setting.cpp
config/config.cpp
debugging/common_colors.cpp
debugging/debug.cpp
logging/logging.cpp
math/angle.cpp
math/helpers.cpp
math/linear.cpp
math/random.cpp
math/vector.cpp
math/geom/circle.cpp
math/geom/line.cpp
math/geom/rect.cpp
network/udp_client.cpp
network/udp_server.cpp
timer/timer.cpp)

add_library(${PROJECT_NAME}
${SOURCE_FILES} ${HEADER_FILES})
${SOURCE_FILES} ${HEADER_FILES})

target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES} ${HEADER_FILES})

target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_PROJECT_NAME}-protos
asio::asio
PkgConfig::tomlplusplus
spdlog::spdlog)
${CMAKE_PROJECT_NAME}-protos
asio::asio
PkgConfig::tomlplusplus
spdlog::spdlog)

if (WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC _WIN32_WINNT=_WIN32_WINNT_WIN10)
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC _WIN32_WINNT=_WIN32_WINNT_WIN10)
endif()

target_compile_definitions(${PROJECT_NAME} PUBLIC DATA_DIR="${CMAKE_SOURCE_DIR}/data")
target_compile_definitions(${PROJECT_NAME} PUBLIC LOG_DIR="${CMAKE_SOURCE_DIR}/log")

set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${USE_UNITY_BUILDS})

target_precompile_headers(${PROJECT_NAME} PUBLIC pch.h)
get_target_property(PROTOS_PCHS ${CMAKE_PROJECT_NAME}-protos INTERFACE_PRECOMPILE_HEADERS)

target_precompile_headers(${PROJECT_NAME}
PUBLIC ${PROTOS_PCHS}
PUBLIC pch.h
INTERFACE ${HEADER_FILES})
5 changes: 0 additions & 5 deletions source/common/config/config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#pragma once

#include <filesystem>
#include <string_view>

#include <toml++/toml.hpp>

namespace Tyr::Common
{
class ConfigReader
Expand Down
5 changes: 0 additions & 5 deletions source/common/debugging/debug.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#pragma once

#include <memory>
#include <string_view>

#include <immortals/Imm_wrapper.pb.h>

#include "../math/vector.h"
#include "../network/udp_server.h"
#include "common_colors.h"
Expand Down
5 changes: 0 additions & 5 deletions source/common/logging/logging.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#pragma once

#include <memory>
#include <source_location>

#include <spdlog/spdlog.h>

namespace Tyr::Common
{
class Logger
Expand Down
Loading
Loading