41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <functional>
|
|
|
|
#include "botcraft/AI/TemplatedBehaviourClient.hpp"
|
|
|
|
namespace Bilicraft
|
|
{
|
|
// CRTP keeps future behaviour-tree leaves typed as BilicraftClient, with access
|
|
// to its custom fields as well as Botcraft's world/inventory/physics managers.
|
|
class BilicraftClient : public Botcraft::TemplatedBehaviourClient<BilicraftClient>
|
|
{
|
|
public:
|
|
BilicraftClient();
|
|
~BilicraftClient() override;
|
|
bool WasDisconnected() const;
|
|
bool HasEnteredPlay() const;
|
|
|
|
// Synchronous .act execution: tasks yield to a main-thread cancellation/
|
|
// pacing hook instead of starting the upstream behaviour worker. Never use
|
|
// this mode concurrently with StartBehaviour/BehaviourStep/SyncAction.
|
|
void SetActionYieldHandler(std::function<void()> handler);
|
|
void Yield() override;
|
|
|
|
protected:
|
|
using Botcraft::TemplatedBehaviourClient<BilicraftClient>::Handle;
|
|
void Handle(ProtocolCraft::ClientboundLoginPacket &packet) override;
|
|
void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &packet) override;
|
|
void Handle(ProtocolCraft::ClientboundDisconnectConfigurationPacket &packet) override;
|
|
void Handle(ProtocolCraft::ClientboundDisconnectPacket &packet) override;
|
|
|
|
private:
|
|
// Main-thread-only hook; it is never called by network/physics handlers.
|
|
std::function<void()> actionYieldHandler;
|
|
// Do not use upstream's non-atomic should_be_closed as our cross-thread signal.
|
|
std::atomic<bool> disconnected{false};
|
|
std::atomic<bool> enteredPlay{false};
|
|
};
|
|
} // namespace Bilicraft
|