SDKs
C++ and Unreal Engine
valkyr.hpp, the header only C++17 wrapper over the C ABI, with notes for calling it from an Unreal Engine dedicated server.
bindings/ is a header only C++17 wrapper over valkyr.h:
valkyr::,Engine valkyr::,ClientSession valkyr::andProtectedI64 valkyr::are move only RAII owners of the C handles.ProtectedF64 - Strings in and out are
std::; library strings are copied and freed for you.string - No exceptions: failures return
std::,nullopt falseor a negativeVALKYR_code, andERR_* valkyr::gives the message. This keeps it usable in Unreal, which builds with exceptions disabled.last_ error()
Example
valkyr::Engine engine;if (!engine) { std::fprintf(stderr, "engine: %s\n", valkyr::last_error().c_str()); return 1;}// A wall 10 m in front of the origin.engine.set_world(R"({"colliders":[{"min":{"x":-1,"y":0,"z":9},"max":{"x":1,"y":3,"z":10}}]})"); // Positions come from an Unreal style world (cm, Z up): 2000 cm per// 100 ms forward is 20 m/s, far above the default limit.int32_t flags = 0;for (uint64_t i = 0; i < 60; ++i) { valkyr::Vec3 p = valkyr::from_unreal_cm(static_cast<double>(i) * 200.0, 0.0, 0.0); int32_t n = engine.frame(3, i, i * 100, i * 100 + 20, p.x, p.y, p.z, valkyr::yaw_from_unreal(0.0), valkyr::pitch_from_unreal(0.0), true, false); if (n < 0) { std::fprintf(stderr, "frame: %s\n", valkyr::last_error().c_str()); return 1; } flags += n;}std::printf("cpp flags raised: %d\n", flags);if (auto t = engine.trust(3, 6000)) { std::printf("cpp trust: probability=%.3f trust=%.1f action=%d\n", t->probability, t->trust, static_cast<int>(t->action));}
Build it:
# Windows (x64 Native Tools prompt)cl /std:c++17 /EHsc /I ..\..\crates\valkyr-ffi\include /I . example.cpp ..\..\target\release\valkyr_ffi.dll.lib# Linuxg++ -std=c++17 -I../../crates/valkyr-ffi/include -I. example.cpp ../../target/release/libvalkyr_ffi.a -lpthread -ldl -lm -o example_cpp
Status
The wrapper and example compile with MSVC (/std:c++17 /W4 /WX) and run in cargo test -p valkyr-ffi --test c_examples. The Unreal notes below were not built inside an Unreal project.
Unreal Engine
Detection belongs on the dedicated server. Create one valkyr:: per match, for example in your AGameModeBase subclass, and feed it from:
- the server RPC that receives client movement, after your movement component validated it: one
frameper player per server tick; - your server side weapon code: one
shotper accepted shot; RestartPlayerorHandleStartingNewPlayer: aspawnevent with the team.
Guard the code with GetNetMode() == NM_ or HasAuthority() and do not ship the engine in client builds.
Units and axes
Unreal is centimeters and Z up, with yaw 0 along +X. valkyr is meters and Y up, with yaw 0 along +Z and 90 along +X.
valkyr.x = Unreal.Y / 100valkyr.y = Unreal.Z / 100valkyr.z = Unreal.X / 100valkyr yaw = Unreal yaw (forward maps to forward, right to right)valkyr pitch = Unreal pitch
valkyr::, valkyr:: and valkyr:: implement this.
Linking
// YourGame.Build.csusing System.IO;using UnrealBuildTool; public class YourGame : ModuleRules{ public YourGame(ReadOnlyTargetRules Target) : base(Target) { PCHUsageMode = PCHUsageMode.UseExplicitOrSharedPCHs; PublicDependencyModuleNames.AddRange(new[] { "Core", "CoreUObject", "Engine" }); string Valkyr = Path.Combine(ModuleDirectory, "..", "ThirdParty", "Valkyr"); PublicIncludePaths.Add(Path.Combine(Valkyr, "include")); if (Target.Platform == UnrealTargetPlatform.Win64) { string Lib = Path.Combine(Valkyr, "lib", "Win64"); PublicAdditionalLibraries.Add(Path.Combine(Lib, "valkyr_ffi.dll.lib")); PublicDelayLoadDLLs.Add("valkyr_ffi.dll"); RuntimeDependencies.Add("$(BinaryOutputDir)/valkyr_ffi.dll", Path.Combine(Lib, "valkyr_ffi.dll")); } else if (Target.Platform == UnrealTargetPlatform.Linux) { // Static linking avoids shipping a .so next to the server binary. PublicAdditionalLibraries.Add(Path.Combine(Valkyr, "lib", "Linux", "libvalkyr_ffi.a")); } }}
With PublicDelayLoadDLLs, load the DLL before the first call, for example with FPlatformProcess:: in your module's StartupModule.