Hello,
I want to make the system in the attachments.
The custom cargoes inherit the custom cargo interface. The custom cargo interface will make static calls to add the cargoes to the main API.
This how it's done in code:
Custom Cargo Vessel:
Custom Cargo Interface:
Main Cargo API:
The main cargo API and custom cargo interface are all in one project and compiled into one .lib file.
The code works until the custom cargo interface calls the static add function. The problem is the method is never called actually. So the custom cargo interface constructor is executed correctly, however, the main cargo API AddCustomCargo method isn't actually called, and the custom cargo isn't added to the customCargoes vector.
I am trying to use the design @Enjo used in his HUD Drawer SDK.
I want to make the system in the attachments.
The custom cargoes inherit the custom cargo interface. The custom cargo interface will make static calls to add the cargoes to the main API.
This how it's done in code:
Custom Cargo Vessel:
Code:
class Custom: public VESSEL4, public CustomCargo {
public:
Custom(OBJHANDLE hVessel, int flightmodel) : VESSEL4(hVessel, flightmodel), CustomCargo(hVessel, false) {};
~Custom();
ATTACHMENTHANDLE GetCargoAttachmentHandle() override;
bool IsUnpacked() override;
void CargoGrappled() override;
void CargoReleased() override;
bool PackCargo() override;
bool UnpackCargo() override;
};
Custom Cargo Interface:
Code:
CustomCargo.h:
class __declspec(dllexport) CustomCargo
{
public:
CustomCargo(OBJHANDLE handle, bool unpackable);
virtual ATTACHMENTHANDLE GetCargoAttachmentHandle() = 0;
virtual bool IsUnpacked() = 0;
virtual void CargoGrappled() = 0;
virtual void CargoReleased() = 0;
virtual bool PackCargo() = 0;
virtual bool UnpackCargo() = 0;
virtual ~CustomCargo();
private:
friend class UCSO_API;
OBJHANDLE handle;
bool unpackable;
};
================================
CustomCargo.cpp:
#include "CustomCargo.h"
#include "UCSO_API.h"
CustomCargo::CustomCargo(OBJHANDLE handle, bool unpackable)
{
this->handle = handle;
this->unpackable = unpackable;
UCSO_API::AddCustomCargo(this);
}
CustomCargo::~CustomCargo() { UCSO_API::DeleteCustomCargo(this); }
Main Cargo API:
Code:
UCSO_API.h:
class UCSO_API
{
private:
friend class CustomCargo;
static void AddCustomCargo(CustomCargo* cargo);
static void DeleteCustomCargo(CustomCargo* cargo);
static std::vector<CustomCargo*> customCargoes;
};
================================
UCSO_API.cpp:
#include "UCSO_API.h"
std::vector<CustomCargo*> UCSO_API::customCargoes;
void UCSO_API::AddCustomCargo(CustomCargo* cargo)
{
customCargoes.push_back(cargo);
}
void UCSO_API::DeleteCustomCargo(CustomCargo* cargo)
{
std::vector<CustomCargo*>::iterator it = find(customCargoes.begin(), customCargoes.end(), cargo);
if (it != customCargoes.end()) customCargoes.erase(it);
}
The main cargo API and custom cargo interface are all in one project and compiled into one .lib file.
The code works until the custom cargo interface calls the static add function. The problem is the method is never called actually. So the custom cargo interface constructor is executed correctly, however, the main cargo API AddCustomCargo method isn't actually called, and the custom cargo isn't added to the customCargoes vector.
I am trying to use the design @Enjo used in his HUD Drawer SDK.
Attachments
Last edited: