Elevate Engine 1
Loading...
Searching...
No Matches
WAAPIClient.cpp
Go to the documentation of this file.
1#include "WAAPIClient.h"
2
4
5#if defined(EE_USES_WWISE) && !defined(EE_PLATFORM_WEB)
6 #include <AK/WwiseAuthoringAPI/AkAutobahn/Client.h>
7 #include <AK/WwiseAuthoringAPI/AkAutobahn/Logger.h>
8 #include <AK/WwiseAuthoringAPI/waapi.h>
9 #define EE_WAAPI_AVAILABLE 1
10#else
11 #define EE_WAAPI_AVAILABLE 0
12#endif
13
14namespace Elevate
15{
17 {
18#if EE_WAAPI_AVAILABLE
19 m_isConnected = m_client->Connect(m_ip.c_str(), m_port);
20 if (!m_isConnected)
21 {
22 EE_CORE_ERROR("Could not connect to WAAPI.");
23 }
24
25 // todo remove this test
26 using namespace AK::WwiseAuthoringAPI;
27 AkJson wwiseInfoJson;
28 if (!m_client->Call(ak::wwise::core::getInfo, AkJson(AkJson::Type::Map), AkJson(AkJson::Type::Map), wwiseInfoJson, 10))
29 {
30 EE_CORE_ERROR("Failed to obtain Wwise Info within 10ms: {}", std::string(wwiseInfoJson["message"].GetVariant()));
31 }
32
33 // todo remove this test
34 // Fetch all of the supported objects via WAAPI
35 // use this as the wwise data source
36 //const AkJson args( AkJson::Map{
37 // { "from", AkJson::Map{ { "ofType", AkJson::Array{
38 // AkVariant("Bus"),
39 // AkVariant("Event"),
40 // AkVariant("SoundBank"),
41 // AkVariant("State"),
42 // AkVariant("Switch"),
43 // AkVariant("SwitchGroup"),
44 // AkVariant("StateGroup"),
45 // } } } }
46 //});
47
48 //const AkJson options(AkJson::Map{
49 // { "return", AkJson::Array{
50 // AkVariant("name"),
51 // AkVariant("id"),
52 // AkVariant("shortId"),
53 // AkVariant("type"),
54 // AkVariant("path"),
55 // } }
56 //});
57
58 //AkJson res;
59 //if (!m_client->Call(ak::wwise::core::object::get, args, options, res, 2000))
60 //{
61 // EE_CORE_ERROR("Failed to fetch all of the objects in the Wwise Project.");
62 //}
63 //else
64 //{
65 // if (res.IsMap() && res.HasKey("return"));
66 // {
67 // auto resArr = res["return"];
68 // for (auto obj : resArr.GetArray())
69 // {
70 // std::string name = obj["name"].GetVariant();
71 // std::string guid = obj["id"].GetVariant();
72 // std::string type = obj["type"].GetVariant();
73 // std::string path = obj["path"].GetVariant();
74 // uint64_t shortId = obj["shortId"].GetVariant();
75 // }
76 // }
77 //}
78
79 return m_isConnected;
80#else
81 return false;
82#endif
83 }
84
86 {
87#if EE_WAAPI_AVAILABLE
88 if (m_client)
89 {
90 m_client->Disconnect();
91 }
92#endif
93 }
94
95 WAAPIClient::WAAPIClient()
96 {
97#if EE_WAAPI_AVAILABLE
98 m_client = new AK::WwiseAuthoringAPI::Client();
99
100 AK::WwiseAuthoringAPI::Logger::Get()->SetLoggerFunction(LoggerCallback);
101
102 Connect();
103 // todo create an async system to try and reconnect if not working
104 // 1s -> 2s -> 4s -> 8s -> 16s mult. tiime by 2 each time.
105#endif
106 }
107
109 {
110#if EE_WAAPI_AVAILABLE
111 delete m_client;
112#endif
113 }
114
115 void WAAPIClient::LoggerCallback([[maybe_unused]] const char* logMessage)
116 {
117#if EE_WAAPI_AVAILABLE
118 // todo use a custom logger here to know who prints what
119 EE_CORE_TRACE("{}", logMessage);
120#endif
121 }
122
124 {
125#if EE_WAAPI_AVAILABLE
126 return Get().m_isConnected;
127#else
128 return false;
129#endif
130 }
131}
AK::WwiseAuthoringAPI::Client * m_client
Definition WAAPIClient.h:48
static WAAPIClient & Get()
Definition WAAPIClient.h:21
static bool IsConnected()