I’m engaged on a closed-source C++ software: an OpenGL-based simulation recreation with plane (pleasant and enemy). I wish to combine autonomous behaviors resembling Hierarchical Job Networks (HTN) to deal with complicated planning like:
- Assaulting an enemy.
- Following an enemy plane.
- Coordinating a platoon for staff assaults.
I would like the applying to assist plugins for these autonomous behaviors, enabling customers to dynamically change or add new habits with out modifying the core software.
To realize this I’ve tried the tactic beneath:
Plane Class
class Plane {
public:
// Constructor
Plane(const std::string& identify, 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 identify; // Title of the plane
float velocity; // Velocity in items
float altitude; // Altitude in items
};
AircraftAPI Class
class AircraftAPI {
public:
// Exposes Plane's FollowTarget technique
static bool FollowTarget(Plane* plane);
// Exposes Plane's AttackTarget technique
static bool AttackTarget(Plane* plane);
// Exposes Plane's AvoidTarget technique
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
NOTE: This isn’t my precise code It is only for an instance. My methodology is analogous. How can I make my software impartial of Attackplugin
I wish to expose a C++ API to work together with the sport, permitting customers to instantiate lessons, go information, and invoke strategies utilizing native C++ objects and software characters will be managed outdoors the applying like inside plugin utilizing HTN.
How can I implement this in such a method that the API should hold the applying closed-source.