I’m engaged on a closed-source C++ utility: an OpenGL-based simulation recreation with plane (pleasant and enemy). I wish to combine autonomous behaviors reminiscent of Hierarchical Process Networks (HTN) to deal with complicated planning like:
- Assaulting an enemy.
- Following an enemy plane.
- Coordinating a platoon for group assaults.
I need the applying to help plugins for these autonomous behaviors, enabling customers to dynamically change or add new habits with out modifying the core utility.
To realize this I’ve tried the tactic beneath:
Plane Class
class Plane {
public:
// Constructor
Plane(const std::string& title, float velocity, float altitude);
// Member capabilities to simulate behaviors
bool FollowTarget();
bool AttackTarget();
bool AvoidTarget();
// Utility capabilities
void setSpeed(float velocity);
float getSpeed() const;
void setAltitude(float altitude);
float getAltitude() const;
const std::string& getName() const;
non-public:
std::string title; // Identify of the plane
float velocity; // Velocity in items
float altitude; // Altitude in items
};
AircraftAPI Class
class AircraftAPI {
public:
// Exposes Plane's FollowTarget methodology
static bool FollowTarget(Plane* plane);
// Exposes Plane's AttackTarget methodology
static bool AttackTarget(Plane* plane);
// Exposes Plane's AvoidTarget methodology
static bool AvoidTarget(Plane* plane);
// Utility strategies for setting and getting properties
static void SetSpeed(Plane* plane, float velocity);
static float GetSpeed(Plane* plane);
static void SetAltitude(Plane* plane, float altitude);
static float GetAltitude(Plane* plane);
static const std::string& GetName(Plane* plane);
};
Plugin Interface
class IPlugin {
public:
digital ~IPlugin() = default;
digital bool initialize() = 0;
digital void replace(float deltaTime) = 0;
digital void cleanup() = 0;
digital std::string getName() const = 0;
};
AttackPlugin Class
// AttackPlugin class
class AttackPlugin : public IPlugin {
public:
AttackPlugin(Plane* plane) : plane(plane), attackCooldown(0.0f) {}
bool initialize() override {
return plane != nullptr;
}
void replace(float deltaTime) override {
attackCooldown -= deltaTime;
if (attackCooldown <= 0.0f && plane) {
AircraftAPI::AttackTarget(plane);
attackCooldown = 3.0f;
}
}
void cleanup() override {}
std::string getName() const override {
return "AttackPlugin";
}
non-public:
Plane* plane;
float attackCooldown;
};
NOTE: This isn’t my precise code It is only for an instance. My methodology is comparable. How can I make my utility unbiased of Attackplugin
I wish to expose a C++ API to work together with the sport, permitting customers to instantiate courses, cross information, and invoke strategies utilizing native C++ objects and utility characters will be managed exterior the applying like inside plugin utilizing HTN.
How can I implement this in such a method that the API should preserve the applying closed-source.