Rise
The Vieneo Province
Loading...
Searching...
No Matches
FreeTrack.cpp
Go to the documentation of this file.
1#include "FreeTrack.h"
2
3#include "Viewscreen.h"
4
6 : viewscreen(prmViewscreen), logger(prmViewscreen->logger),
7 hinstLib(nullptr), getData(nullptr), getDllVersion(nullptr), reportID(nullptr), provider(nullptr)
8{
9 // Loading metadata is safe while unselected; FTGetData is strictly opt-in.
10 hinstLib = LoadLibrary(L"FreeTrackClient.dll");
11 if (!hinstLib)
12 {
13 logger->Log("FreeTrack: Unable to load DLL", Logger::Level::Warn);
14 return;
15 }
16 getData = reinterpret_cast<importGetData>(GetProcAddress(hinstLib, "FTGetData"));
17 getDllVersion = reinterpret_cast<importGetDllVersion>(GetProcAddress(hinstLib, "FTGetDllVersion"));
18 reportID = reinterpret_cast<importReportID>(GetProcAddress(hinstLib, "FTReportName"));
19 provider = reinterpret_cast<importProvider>(GetProcAddress(hinstLib, "FTProvider"));
20 if (!getData)
21 logger->Log("FreeTrack: Unable to find 'FTGetData' function", Logger::Level::Warn);
22 if (getDllVersion)
23 {
24 if (const char* version = getDllVersion()) dllVersion = version;
25 logger->Log(("FreeTrack: DLL Version: " + dllVersion).c_str());
26 }
27}
28
30{
31 input.Reset();
33}
34
36{
37 const auto& lateral = viewscreen->gameclass->config.inputConfigLookLateral;
38 const auto& vertical = viewscreen->gameclass->config.inputConfigLookVertical;
39 try
40 {
41 const bool fresh = input.Poll(lateral.IsFreeTrack(), vertical.IsFreeTrack(), GetTickCount64(),
42 [this](FreeTrackData* data) { return getData && getData(data); });
43 if (fresh)
44 input.Apply(lateral.IsFreeTrack() && viewscreen->camera->allowPan,
45 vertical.IsFreeTrack() && viewscreen->camera->allowTilt,
46 lateral.invert, vertical.invert, viewscreen->targetLeftright, viewscreen->targetUpdown);
48 }
49 catch (...)
50 {
51 Reset();
52 getData = nullptr; // A faulty client must not keep failing every frame.
53 logger->Log("FreeTrack::Poll unhandled exception!", Logger::Level::Error);
54 }
55}
56
58{
59 if (hinstLib) FreeLibrary(hinstLib);
60}
InputConfig inputConfigLookLateral
Definition config.h:43
InputConfig inputConfigLookVertical
Definition config.h:44
void Poll()
Definition FreeTrack.cpp:35
HINSTANCE hinstLib
Definition FreeTrack.h:30
importReportID reportID
Definition FreeTrack.h:43
std::string dllVersion
Definition FreeTrack.h:46
const char *(WINAPI *) importProvider()
Definition FreeTrack.h:38
importProvider provider
Definition FreeTrack.h:44
FreeTrackInput input
Definition FreeTrack.h:49
FreeTrack(Viewscreen *prmViewscreen)
Definition FreeTrack.cpp:5
importGetDllVersion getDllVersion
Definition FreeTrack.h:42
BOOL(WINAPI *) importGetData(FreeTrackData *data)
Definition FreeTrack.h:35
const char *(WINAPI *) importGetDllVersion()
Definition FreeTrack.h:36
Logger * logger
Definition FreeTrack.h:28
Viewscreen * viewscreen
Definition FreeTrack.h:27
void(WINAPI *) importReportID(int name)
Definition FreeTrack.h:37
void Reset()
Definition FreeTrack.cpp:29
importGetData getData
Definition FreeTrack.h:41
void Apply(bool lateral, bool vertical, bool invertLateral, bool invertVertical, float &targetLateral, float &targetVertical) const
bool Poll(bool lateral, bool vertical, std::uint64_t now, Reader read)
Config config
Definition GameClass.h:100
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
@ Warn
Definition Logger.h:26
@ Error
Definition Logger.h:28
bool allowPan
Definition Camera.h:18
bool allowTilt
Definition Camera.h:19
GameClass * gameclass
Definition Viewscreen.h:439
float rolltilt
Definition Viewscreen.h:447
float targetUpdown
Definition Viewscreen.h:445
float targetLeftright
Definition Viewscreen.h:444
SCamera * camera
Definition Viewscreen.h:137