Skip to content

Commit

Permalink
Finished IPC rewrite to gRPC (API, Driver, Amethyst)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 3, 2022
1 parent b79d379 commit 00fc4b9
Show file tree
Hide file tree
Showing 25 changed files with 7,357 additions and 12,365 deletions.
4 changes: 2 additions & 2 deletions Amethyst/Amethyst.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>EIGEN_DONT_ALIGN_STATICALLY;NOGDI;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS;_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS;EIGEN_DONT_ALIGN_STATICALLY;NOGDI;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)external\Kinect;$(SolutionDir)external\openvr\headers;$(SolutionDir)Amethyst_API;$(SolutionDir)Amethyst_API\Generated Files;$(SolutionDir)external\vendor;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MultiThreadedDebug</RuntimeLibrary>
Expand All @@ -113,7 +113,7 @@ xcopy /y /d /s /i "$(ProjectDir)Assets\Strings\*" "$(OutDir)Assets\Strings\"</Co
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>EIGEN_DONT_ALIGN_STATICALLY;NOGDI;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS;_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS;EIGEN_DONT_ALIGN_STATICALLY;NOGDI;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)external\Kinect;$(SolutionDir)external\openvr\headers;$(SolutionDir)Amethyst_API;$(SolutionDir)Amethyst_API\Generated Files;$(SolutionDir)external\vendor;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Release|x64'">stdcpp20</LanguageStandard>
Expand Down
3 changes: 3 additions & 0 deletions Amethyst/Amethyst.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
</ItemGroup>
</Project>
14 changes: 7 additions & 7 deletions Amethyst/JointExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ namespace winrt::Microsoft::UI::Xaml::Controls
{
std::wstring _managing_device_name;
switch (const auto& device = TrackingDevices::TrackingDevicesVector[
TrackingDevices::deviceGUID_ID_Map[
TrackingDevices::GetManagingDevice(*_tracker_pointers[0])]];
device.index())
TrackingDevices::deviceGUID_ID_Map[
TrackingDevices::GetManagingDevice(*_tracker_pointers[0])]];
device.index())
{
case 0:
_managing_device_name =
Expand Down Expand Up @@ -378,8 +378,8 @@ namespace winrt::Microsoft::UI::Xaml::Controls
_ptr_orientation_combo->SelectedIndex(_tracker_pointers[0]->orientationTrackingOption);
_ptr_position_combo->SelectedIndex(
_tracker_pointers[0]->m_no_position_filtering_requested
? -1 // Select the pre-applied placeholder
: _tracker_pointers[0]->positionTrackingFilterOption);
? -1 // Select the pre-applied placeholder
: _tracker_pointers[0]->positionTrackingFilterOption);
}

// Set mathbased to enable/disable
Expand Down Expand Up @@ -698,8 +698,8 @@ namespace winrt::Microsoft::UI::Xaml::Controls
for (int i = 0; i < 3; i++)
{
// Update status in server
ktvr::set_tracker_state<false>(
tracker_p->base_tracker, tracker_p->data_isActive);
ktvr::update_tracker_state_vector<false>(
{{tracker_p->base_tracker, tracker_p->data_isActive}});
Sleep(20); // Wait a bit
}
}
Expand Down
62 changes: 25 additions & 37 deletions Amethyst/K2Interfacing.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace k2app::interfacing
arg.find(L"focus_trackers") != std::wstring::npos)
{
shared::main::thisDispatcherQueue->TryEnqueue([&]()
-> winrt::Windows::Foundation::IAsyncAction
-> winrt::Windows::Foundation::IAsyncAction
{
// Bring Amethyst to front
SetActiveWindow(shared::main::thisAppWindowID);
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace k2app::interfacing
else if (arg.find(L"focus_restart") != std::wstring::npos)
{
shared::main::thisDispatcherQueue->TryEnqueue([&]()
-> winrt::Windows::Foundation::IAsyncAction
-> winrt::Windows::Foundation::IAsyncAction
{
// Bring Amethyst to front
SetActiveWindow(shared::main::thisAppWindowID);
Expand Down Expand Up @@ -566,9 +566,10 @@ namespace k2app::interfacing
if (!k2_tracker_statuses.empty())
for (int i = 0; i < 3; i++)
{
// Update status in server
spawned.push_back(
ktvr::update_tracker_state_vector<true>(k2_tracker_statuses).success());
// Update tracker statuses in the server
for (const auto& result : ktvr::update_tracker_state_vector<true>(k2_tracker_statuses) |
std::views::values) // Slice by values (only use the success? property)
spawned.push_back(result); // Push back the message call result, sleep a bit before proceeding
std::this_thread::sleep_for(std::chrono::milliseconds(15));
}

Expand Down Expand Up @@ -762,44 +763,31 @@ namespace k2app::interfacing
try
{
// Send a ping message and capture the data
const auto [test_response, send_time, full_time] = ktvr::test_connection();
const auto [success, send_time,
receive_time, full_time] = ktvr::test_connection();

// Dump data to variables
pingTime = full_time;
parsingTime = // Subtract message creation (got) time and send time
test_response.messagemanualtimestamp() - test_response.messagetimestamp();
parsingTime = receive_time - send_time;

// Log ?success
LOG(INFO) <<
"Connection test has ended, [result: " <<
(test_response.success() ? "success" : "fail") <<
"], response code: " << test_response.result();
(success ? "success" : "fail") << "]";

// Log some data if needed
LOG(INFO) <<
"\nTested ping time: " << full_time << " [micros], "

<< "call time: " <<
// Subtract message creation (got) time and send time
test_response.messagemanualtimestamp() - send_time
<< " [micros], " <<

"\nparsing time: " <<
parsingTime // Just look at the k2api
<< " [micros], "

"flight-back time: " <<
// Subtract message creation (got) time and send time
AME_API_GET_TIMESTAMP_NOW - test_response.messagemanualtimestamp()
<< " [micros]";
LOG(INFO) << "\n" <<
"Tested ping time: " << pingTime << " [micros], " <<
"call/parsing time: " << parsingTime << " [micros], " <<
"flight-back time: " << AME_API_GET_TIMESTAMP_NOW - receive_time << " [micros]";

// Release
pingCheckingThreadsNumber = std::clamp(
static_cast<int>(pingCheckingThreadsNumber) - 1, 0,
static_cast<int>(maxPingCheckingThreads) + 1);

// Return the result
return test_response.success();
return success;
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -935,7 +923,7 @@ namespace k2app::interfacing

else
shared::main::thisDispatcherQueue->TryEnqueue([&]()
-> winrt::Windows::Foundation::IAsyncAction
-> winrt::Windows::Foundation::IAsyncAction
{
// Sleep a bit before checking
winrt::apartment_context ui_thread;
Expand Down Expand Up @@ -1192,10 +1180,10 @@ namespace k2app::interfacing

inline bool IsCurrentWindowActive()
{
if (k2app::shared::main::thisAppWindowID == nullptr)
if (shared::main::thisAppWindowID == nullptr)
return true; // Give up k?

return GetActiveWindow() == k2app::shared::main::thisAppWindowID;
return GetActiveWindow() == shared::main::thisAppWindowID;
}

inline bool IsDashboardOpen()
Expand Down Expand Up @@ -1852,7 +1840,7 @@ namespace k2app::interfacing
const std::function
_n_callback = [this](const winrt::Windows::Foundation::IInspectable& sender,
const RoutedEventArgs& e) ->
void
void
{
if (OnClick) // Check if not null
OnClick(this);
Expand Down Expand Up @@ -2009,7 +1997,7 @@ namespace k2app::interfacing
_n_callback = [this](const winrt::Windows::Foundation::IInspectable& sender,
const Controls::NumberBoxValueChangedEventArgs
& e) ->
void
void
{
if (OnValueChanged) // Check if not null
OnValueChanged(this, static_cast<int>(e.NewValue()));
Expand Down Expand Up @@ -2208,7 +2196,7 @@ namespace k2app::interfacing
_n_callback = [this](const winrt::Windows::Foundation::IInspectable& sender,
const Controls::SelectionChangedEventArgs
& e) ->
void
void
{
if (OnSelectionChanged) // Check if not null
OnSelectionChanged(this, _ptr_combo_box->SelectedIndex());
Expand Down Expand Up @@ -2363,7 +2351,7 @@ namespace k2app::interfacing
const std::function
_n_callback_checked = [this](const winrt::Windows::Foundation::IInspectable& sender,
const RoutedEventArgs& e) ->
void
void
{
if (OnChecked) // Check if not null
OnChecked(this);
Expand All @@ -2376,7 +2364,7 @@ namespace k2app::interfacing
const std::function
_n_callback_unchecked = [this](const winrt::Windows::Foundation::IInspectable& sender,
const RoutedEventArgs& e) ->
void
void
{
if (OnUnchecked) // Check if not null
OnUnchecked(this);
Expand Down Expand Up @@ -2525,7 +2513,7 @@ namespace k2app::interfacing
const std::function
_n_callback = [this](const winrt::Windows::Foundation::IInspectable& sender,
const RoutedEventArgs& e) ->
void
void
{
// Check which handler to raise
if (this->Get()->IsOn())
Expand Down Expand Up @@ -2664,7 +2652,7 @@ namespace k2app::interfacing
const std::function
_n_callback = [this](const winrt::Windows::Foundation::IInspectable& sender,
const Input::KeyRoutedEventArgs& e) ->
void
void
{
if (e.Key() == winrt::Windows::System::VirtualKey::Enter)
OnEnterKeyDown(this);
Expand Down
19 changes: 13 additions & 6 deletions Amethyst/K2Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,13 @@ namespace k2app::main
// (When they're unfrozen, they go back to instant updates)
if (p_frozen_loops >= 1000)
{
std::vector<ktvr::ITrackerType> frozen_k2_tracker_bases;
for (const auto& tracker : K2Settings.K2TrackersVector)
if (tracker.data_isActive)
ktvr::refresh_tracker_pose<false>(tracker.base_tracker);
frozen_k2_tracker_bases.push_back(tracker.base_tracker);

// Refresh in the server driver
refresh_tracker_pose_vector<false>(frozen_k2_tracker_bases);

// Reset
p_frozen_loops = 0;
Expand Down Expand Up @@ -360,11 +364,14 @@ namespace k2app::main
// (When they're unfrozen, they go back to instant updates)
if (p_frozen_loops >= 1000)
{
// Only lower body joints
std::vector<ktvr::ITrackerType> frozen_k2_tracker_bases;
for (auto& tracker : K2Settings.K2TrackersVector)
if (tracker.data_isActive &&
if (tracker.data_isActive && // Only lower body joints
static_cast<int>(ITrackerType_Joint[tracker.base_tracker]) >= 16)
ktvr::refresh_tracker_pose<false>(tracker.base_tracker);
frozen_k2_tracker_bases.push_back(tracker.base_tracker);

// Refresh in the server driver
refresh_tracker_pose_vector<false>(frozen_k2_tracker_bases);

// Reset
p_frozen_loops = 0;
Expand Down Expand Up @@ -524,8 +531,8 @@ namespace k2app::main
// try even 5 times cause why not
for (int i = 0; i < 5; i++)
{
ktvr::set_tracker_state<false>(
K2Settings.K2TrackersVector[tracker_index].base_tracker, false);
ktvr::update_tracker_state_vector<false>(
{{K2Settings.K2TrackersVector[tracker_index].base_tracker, false}});
Sleep(20);
}
co_await _ui_thread;
Expand Down
12 changes: 6 additions & 6 deletions Amethyst/SettingsPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ void Amethyst::implementation::SettingsPage::TrackerConfigButton_Click(
menuTrackerToggleItem.Click(
[&, index, tracker_map, current_tracker, this]
(const Windows::Foundation::IInspectable& sender, const RoutedEventArgs& e)
-> Windows::Foundation::IAsyncAction
-> Windows::Foundation::IAsyncAction
{
// Notify of the setup end
k2app::shared::settings::settings_localInitFinished = false;
Expand All @@ -1219,8 +1219,8 @@ void Amethyst::implementation::SettingsPage::TrackerConfigButton_Click(

// Make actual changes
if (trackerState && k2app::interfacing::K2AppTrackersInitialized)
ktvr::set_tracker_state<false>(
k2app::K2Settings.K2TrackersVector.at(_t).base_tracker, false);
ktvr::update_tracker_state_vector<false>(
{{k2app::K2Settings.K2TrackersVector.at(_t).base_tracker, false}});

// Sleep on UI's background
apartment_context _ui_thread;
Expand Down Expand Up @@ -1921,9 +1921,9 @@ Windows::Foundation::IAsyncAction Amethyst::implementation::SettingsPage::AutoSt
}


void winrt::Amethyst::implementation::SettingsPage::ToggleFlipTeachingTip_Closed(
const winrt::Microsoft::UI::Xaml::Controls::TeachingTip& sender,
const winrt::Microsoft::UI::Xaml::Controls::TeachingTipClosedEventArgs& args)
void Amethyst::implementation::SettingsPage::ToggleFlipTeachingTip_Closed(
const Controls::TeachingTip& sender,
const Controls::TeachingTipClosedEventArgs& args)
{
k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(false);
}
Loading

0 comments on commit 00fc4b9

Please sign in to comment.