update cmd client
This commit is contained in:
@@ -4,66 +4,72 @@
|
||||
|
||||
namespace basalt::presenter::cmd_client {
|
||||
|
||||
CommandClient::CommandClient() : m_PipeOperator(BSTEXT("ed0e3f1f-d214-4880-9562-640bce15e72e")), m_Status(ClientStatus::Ready) {}
|
||||
CmdClient::CmdClient() : m_PipeOperator(BSTEXT("ed0e3f1f-d214-4880-9562-640bce15e72e")), m_Status(CmdClientStatus::Ready) {}
|
||||
|
||||
CommandClient::~CommandClient() {}
|
||||
CmdClient::~CmdClient() {}
|
||||
|
||||
HandshakePayload CommandClient::WaitHandshake() {
|
||||
if (m_Status != ClientStatus::Ready) {
|
||||
HandshakePayload CmdClient::wait_handshake() {
|
||||
if (m_Status != CmdClientStatus::Ready) {
|
||||
throw std::runtime_error("unexcpected client status");
|
||||
}
|
||||
|
||||
// Wait for handshake request from Trainer (code 0x61)
|
||||
ProtocolCode request_code;
|
||||
m_PipeOperator.Read(&request_code, sizeof(request_code));
|
||||
m_PipeOperator.read_pod(request_code);
|
||||
if (request_code != ProtocolCode::HANDSHAKE_REQUEST) {
|
||||
throw std::runtime_error("unexpcted handshake code");
|
||||
}
|
||||
// Accept payload
|
||||
HandshakePayload handshake_payload;
|
||||
m_PipeOperator.Read(&handshake_payload, sizeof(HandshakePayload));
|
||||
m_PipeOperator.read_pod(handshake_payload);
|
||||
|
||||
// Send handshake response (code 0x62) back to Trainer
|
||||
ProtocolCode response_code = ProtocolCode::HANDSHAKE_RESPONSE;
|
||||
m_PipeOperator.Write(&response_code, sizeof(response_code));
|
||||
m_PipeOperator.write_pod(response_code);
|
||||
|
||||
// Set status and return
|
||||
m_Status = ClientStatus::Running;
|
||||
m_Status = CmdClientStatus::Running;
|
||||
return handshake_payload;
|
||||
}
|
||||
|
||||
bool CommandClient::Tick(bool actively_stop) {
|
||||
if (m_Status != ClientStatus::Running) {
|
||||
bool CmdClient::tick(bool actively_stop) {
|
||||
if (m_Status != CmdClientStatus::Running) {
|
||||
throw std::runtime_error("unexcpected client status");
|
||||
}
|
||||
|
||||
// If actively stop, send actively stop code to Trainer first
|
||||
if (actively_stop) {
|
||||
ProtocolCode sent_code = ProtocolCode::STOP_REQUEST;
|
||||
m_PipeOperator.Write(&sent_code, sizeof(sent_code));
|
||||
ProtocolCode actively_stop_code = ProtocolCode::STOP_REQUEST;
|
||||
m_PipeOperator.write_pod(actively_stop_code);
|
||||
}
|
||||
|
||||
// Send data ready code to Trainer
|
||||
ProtocolCode sent_code = ProtocolCode::DATA_READY;
|
||||
m_PipeOperator.Write(&sent_code, sizeof(sent_code));
|
||||
ProtocolCode data_ready_code = ProtocolCode::DATA_READY;
|
||||
m_PipeOperator.write_pod(data_ready_code);
|
||||
|
||||
// Process the response from Trainer
|
||||
while (true) {
|
||||
ProtocolCode recv_code;
|
||||
m_PipeOperator.Read(&recv_code, sizeof(recv_code));
|
||||
m_PipeOperator.read_pod(recv_code);
|
||||
|
||||
switch (recv_code) {
|
||||
case ProtocolCode::DATA_RECEIVED:
|
||||
case ProtocolCode::DATA_RECEIVED: {
|
||||
// Normal response, continue processing
|
||||
return false; // Not stopping
|
||||
case Basalt::Presenter::ProtocolCode::STOP:
|
||||
}
|
||||
case ProtocolCode::STOP_REQUEST: {
|
||||
// Trainer wants to stop
|
||||
m_Status = ClientStatus::Stop;
|
||||
// We sent response first
|
||||
ProtocolCode stop_response_code = ProtocolCode::STOP_RESPONSE;
|
||||
m_PipeOperator.write_pod(stop_response_code);
|
||||
// Set status and return.
|
||||
m_Status = CmdClientStatus::Stop;
|
||||
return true; // Should stop
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("unexpected code when running");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Basalt::Presenter
|
||||
} // namespace basalt::presenter::cmd_client
|
||||
@@ -10,9 +10,9 @@ namespace basalt::presenter::cmd_client {
|
||||
HANDSHAKE_RESPONSE = 0x62, ///< Presenter -> Trainer
|
||||
DATA_READY = 0x01, ///< Presenter -> Trainer
|
||||
DATA_RECEIVED = 0x02, ///< Trainer -> Presenter
|
||||
ACTIVELY_STOP = 0x21, ///< Presenter-->Trainer
|
||||
STOP_REQUEST = 0X71, ///< Presenter<--Trainer
|
||||
STOP_RESPONSE = 0x72, //< Presenter-->Trainer
|
||||
ACTIVELY_STOP = 0x21, ///< Presenter-->Trainer
|
||||
STOP_REQUEST = 0X71, ///< Presenter<--Trainer
|
||||
STOP_RESPONSE = 0x72, ///< Presenter-->Trainer
|
||||
};
|
||||
|
||||
// Pixel kind values
|
||||
@@ -32,26 +32,26 @@ namespace basalt::presenter::cmd_client {
|
||||
#pragma pack(pop)
|
||||
|
||||
// Status
|
||||
enum class ClientStatus {
|
||||
enum class CmdClientStatus {
|
||||
Ready,
|
||||
Running,
|
||||
Stop,
|
||||
};
|
||||
|
||||
class CommandClient {
|
||||
class CmdClient {
|
||||
public:
|
||||
CommandClient();
|
||||
~CommandClient();
|
||||
CmdClient();
|
||||
~CmdClient();
|
||||
|
||||
public:
|
||||
// Wait for handshake from Trainer, send response with data properties
|
||||
HandshakePayload WaitHandshake();
|
||||
HandshakePayload wait_handshake();
|
||||
// Tick function called every frame to send data ready and wait for response
|
||||
bool Tick(bool actively_stop = false);
|
||||
bool tick(bool actively_stop = false);
|
||||
|
||||
private:
|
||||
Shared::PipeOperator m_PipeOperator;
|
||||
ClientStatus m_Status;
|
||||
shared::pipe_operator::PipeOperator m_PipeOperator;
|
||||
CmdClientStatus m_Status;
|
||||
};
|
||||
|
||||
} // namespace Basalt::Presenter
|
||||
} // namespace basalt::presenter::cmd_client
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace basalt::presenter::dll_loader {
|
||||
|
||||
enum class DllKind {
|
||||
Engine, ///< Render engine
|
||||
Deliver, ///< Data deliver
|
||||
Engine, ///< Render engine
|
||||
Deliver, ///< Data deliver
|
||||
ObjectLoader, ///< 3D object loader
|
||||
AnimeLoader, ///< Camera animation loader
|
||||
AnimeLoader, ///< Camera animation loader
|
||||
};
|
||||
|
||||
class DllLoader {
|
||||
@@ -40,7 +40,7 @@ namespace basalt::presenter::dll_loader {
|
||||
}
|
||||
template<typename T>
|
||||
void DestroyInstance(T* instance) {
|
||||
using Fct = void (*) (T*);
|
||||
using Fct = void (*)(T*);
|
||||
constexpr char EXPOSE_FUNC_NAME[] = "BSDestroyInstance";
|
||||
auto fct = (Fct) GetFunctionPointer(EXPOSE_FUNC_NAME);
|
||||
fct(instance);
|
||||
@@ -50,4 +50,4 @@ namespace basalt::presenter::dll_loader {
|
||||
Handle m_Handle;
|
||||
};
|
||||
|
||||
} // namespace Basalt::Presenter
|
||||
} // namespace basalt::presenter::dll_loader
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
#include "dll_loader.hpp"
|
||||
#include "command_client.hpp"
|
||||
#include "cmd_client.hpp"
|
||||
#include <basalt/char_types.hpp>
|
||||
#include <basalt/kernel.hpp>
|
||||
|
||||
namespace Presenter = ::Basalt::Presenter;
|
||||
namespace Kernel = ::Basalt::Shared::Kernel;
|
||||
namespace dll_loader = ::basalt::presenter::dll_loader;
|
||||
using dll_loader::DllKind;
|
||||
using dll_loader::DllLoader;
|
||||
|
||||
using ::basalt::presenter::cmd_client::CmdClient;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
auto engine_dll = Presenter::DllLoader(Presenter::DllKind::Engine, BSTEXT("BasaltDirectX11Engine"));
|
||||
auto deliver_dll = Presenter::DllLoader(Presenter::DllKind::Deliver, BSTEXT("BasaltPipeDeliver"));
|
||||
auto engine_dll = DllLoader(DllKind::Engine, BSTEXT("BasaltDirectX11Engine"));
|
||||
auto deliver_dll = DllLoader(DllKind::Deliver, BSTEXT("BasaltPipeDeliver"));
|
||||
|
||||
auto client = Presenter::CommandClient();
|
||||
auto payload = client.WaitHandshake();
|
||||
auto client = CmdClient();
|
||||
auto payload = client.wait_handshake();
|
||||
|
||||
auto* engine = engine_dll.CreateInstance<Kernel::IEngine>();
|
||||
auto* deliver = deliver_dll.CreateInstance<Kernel::IDeliver>();
|
||||
//auto* engine = engine_dll.CreateInstance<Kernel::IEngine>();
|
||||
//auto* deliver = deliver_dll.CreateInstance<Kernel::IDeliver>();
|
||||
|
||||
Kernel::EngineConfig engine_config{.headless = false, .title = BSTEXT("Fuck You"), .width = payload.width, .height = payload.height};
|
||||
engine->Startup(std::move(engine_config));
|
||||
//Kernel::EngineConfig engine_config{.headless = false, .title = BSTEXT("Fuck You"), .width = payload.width, .height = payload.height};
|
||||
//engine->startup(std::move(engine_config));
|
||||
|
||||
while (true) {
|
||||
auto req_stop = engine->Tick();
|
||||
auto can_stop = client.Tick(req_stop);
|
||||
auto req_stop = false; //engine->tick();
|
||||
auto can_stop = client.tick(req_stop);
|
||||
if (can_stop) break;
|
||||
}
|
||||
|
||||
engine->Shutdown();
|
||||
engine_dll.DestroyInstance(engine);
|
||||
//engine->shutdown();
|
||||
//engine_dll.DestroyInstance(engine);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user