Matias Saibene
Development hell
Well it's time to address some errors (that is, the entire code). Today's topic: change of liveries.
It turns out that I programmed a function that builds the path where the skins are stored, that depend on a text file that defines the position of the skin and its name, in such a way that the path where the DDS file is is built and Orbiter searches for it, Orbiter finds it and we are all happy.
The problem is that as soon as I move the skin list file to the corresponding directory, instead of being in the root of Orbiter, and update the code, Orbiter no longer manages to change the skins and I suspect that it is not actually being able to build the path.
This is my function, and part of the header, any help is appreciated.
And that's how it was before the change, when Orbiter was still looking for the skin list file in the Orbiter root. And it worked.
It turns out that I programmed a function that builds the path where the skins are stored, that depend on a text file that defines the position of the skin and its name, in such a way that the path where the DDS file is is built and Orbiter searches for it, Orbiter finds it and we are all happy.
The problem is that as soon as I move the skin list file to the corresponding directory, instead of being in the root of Orbiter, and update the code, Orbiter no longer manages to change the skins and I suspect that it is not actually being able to build the path.
This is my function, and part of the header, any help is appreciated.
C++:
void B747SP::NextSkin() {
if (currentSkin >= 15) {
currentSkin = 0;
}
ChangeLivery();
currentSkin++;
}
void B747SP::ChangeLivery() {
const char item[5] = "SKIN";
char skinname[256];
char completedir_fus[256];
char completedir_vs[256];
char completedir_rw[256];
char completedir_eng[256];
char completedir_lw[256];
const char SKINLIST[][15] = {"SKIN1", "SKIN2", "SKIN3", "SKIN4", "SKIN5", "SKIN6", "SKIN7", "SKIN8", "SKIN9", "SKIN10", "SKIN11", "SKIN12", "SKIN13", "SKIN14", "SKIN15"};
skinlist = oapiOpenFile(fname, FILE_IN, TEXTURES);
oapiReadItem_string(skinlist, SKINLIST[currentSkin], skinname);
strcpy(completedir_fus, skindir);
strcat(completedir_fus, skinname);
strcat(completedir_fus, texname_fus);
strcpy(completedir_vs, skindir);
strcat(completedir_vs, skinname);
strcat(completedir_vs, texname_vs);
strcpy(completedir_rw, skindir);
strcat(completedir_rw, skinname);
strcat(completedir_rw, texname_rw);
strcpy(completedir_eng, skindir);
strcat(completedir_eng, skinname);
strcat(completedir_eng, texname_eng);
strcpy(completedir_lw, skindir);
strcat(completedir_lw, skinname);
strcat(completedir_lw, texname_lw);
skin[0] = oapiLoadTexture(completedir_fus);
skin[1] = oapiLoadTexture(completedir_vs);
skin[2] = oapiLoadTexture(completedir_rw);
skin[3] = oapiLoadTexture(completedir_eng);
skin[4] = oapiLoadTexture(completedir_lw);
ApplyLivery();
}
void B747SP::ApplyLivery(){
if(!b747sp_dmesh) return;
if(skin[0]) oapiSetTexture(b747sp_dmesh, 1, skin[0]);
if(skin[1]) oapiSetTexture(b747sp_dmesh, 2, skin[1]);
if(skin[2]) oapiSetTexture(b747sp_dmesh, 3, skin[2]);
if(skin[3]) oapiSetTexture(b747sp_dmesh, 4, skin[3]);
if(skin[4]) oapiSetTexture(b747sp_dmesh, 9, skin[4]);
}
C++:
//B747SP class interface
class B747SP : public VESSEL4{
public:
enum MySounds {engines_start, engines_shutdown, engines, cabin_ambiance, rotate};
enum LandingGearStatus{GEAR_DOWN, GEAR_UP, GEAR_DEPLOYING, GEAR_STOWING} landing_gear_status;
B747SP(OBJHANDLE hVessel, int flightmodel);
virtual ~B747SP();
void DefineAnimations(void);
void ActivateLandingGear(LandingGearStatus action);
void SetGearDown(void);
void UpdateLandingGearAnimation(double);
double UpdateLvlEnginesContrail();
void ParkingBrake();
void NextSkin();
void ChangeLivery();
void ApplyLivery();
void ActivateBeacons(void);
void LightsControl(void);
void EnginesAutostart(void);
void EnginesAutostop(void);
void UpdateEnginesStatus(void);
void clbkSetClassCaps(FILEHANDLE cfg) override;
void clbkLoadStateEx(FILEHANDLE scn, void *vs) override;
void clbkSaveState(FILEHANDLE scn) override;
void clbkPreStep(double, double, double) override;
void clbkPostCreation(void) override;
void clbkPostStep(double, double, double) override;
int clbkConsumeBufferedKey(int, bool, char *) override;
bool clbkLoadVC(int) override;
//void clbkMFDMode(int, int) override;
//bool clbkVCRedrawEvent(int, int, SURFHANDLE) override;
void clbkVisualCreated(VISHANDLE vis, int refcount) override;
void clbkVisualDestroyed (VISHANDLE vis, int refcount) override;
VISHANDLE visual;
MESHHANDLE b747sp_mesh, mhcockpit_mesh, fccabin_mesh; //Mesh handle
unsigned int uimesh_Cockpit = 1;
DEVMESHHANDLE b747sp_dmesh; //Mesh template handle
XRSound *m_pXRSound;
private:
unsigned int anim_landing_gear;
unsigned int anim_door;
unsigned int anim_laileron;
unsigned int anim_raileron;
unsigned int anim_elevator;
unsigned int anim_elevator_trim;
unsigned int anim_rudder;
unsigned int anim_engines;
double lvlcontrailengines;
double landing_gear_proc;
double engines_proc;
double pwr;
AIRFOILHANDLE lwing, rwing, lstabilizer, rstabilizer;
CTRLSURFHANDLE hlaileron, hraileron;
THRUSTER_HANDLE th_main[4], th_retro[4];
THGROUP_HANDLE thg_main, thg_retro;
BEACONLIGHTSPEC beacon[5];
FILEHANDLE skinlist, skinlog;
SURFHANDLE skin[5];
SURFHANDLE vcMfdTex;
char skinpath[256];
LightEmitter *l1, *l2, *l3, *l4, *cpl1, *cpl2, *fcl1, *fcl2, *fcl3, *fcl4, *fcl5, *fcl6, *fcl7, *fcl8, *fcl9, *fcl10, *fcl11, *fcl12;
COLOUR4 col_d = {0.9,0.8,1,0};
COLOUR4 col_s = {1.9,0.8,1,0};
COLOUR4 col_a = {0,0,0,0};
COLOUR4 ccol_d = {1, 0.508, 0.100};
COLOUR4 ccol_s = {1, 0.508, 0.100};
COLOUR4 ccol_a = {1, 0.508, 0.100};
COLOUR4 fccol_d = {1, 1, 1};
COLOUR4 fccol_s = {1, 1, 1};
COLOUR4 fccol_a = {1, 1, 1};
const char fname[34] = "Boeing_747\\B747SP\\Skins\\skins.txt"; //File where skin list is stored. Relative to ORBITER_ROOT.
const char skindir[25] = "Boeing_747\\B747SP\\Skins\\"; //Path where actual skins are stored. Relative to ORBITER_ROOT\\Textures.
//Name of the textures to be applied.
const char texname_fus[14] = "\\Fuselage.dds";
const char texname_vs[25] = "\\Vertical_stabilizer.dds";
const char texname_rw[15] = "Right_wing.dds";
const char texname_eng[9] = "ENG1.dds";
const char texname_lw[14] = "Left_wing.dds";
};
And that's how it was before the change, when Orbiter was still looking for the skin list file in the Orbiter root. And it worked.
C++:
void B747SP::NextSkin() {
if (currentSkin >= 5) {
currentSkin = 0;
}
ChangeLivery();
currentSkin++;
}
void B747SP::ChangeLivery() {
const char item[5] = "SKIN";
char skinname[256];
char completedir_fus[256];
char completedir_vs[256];
char completedir_rw[256];
char completedir_eng[256];
char completedir_lw[256];
const char SKINLIST[][6] = {"SKIN1", "SKIN2", "SKIN3", "SKIN4", "SKIN5"};
skinlist = oapiOpenFile(fname, FILE_IN, ROOT);
oapiReadItem_string(skinlist, SKINLIST[currentSkin], skinname);
strcpy(completedir_fus, skindir);
strcat(completedir_fus, skinname);
strcat(completedir_fus, texname_fus);
strcpy(completedir_vs, skindir);
strcat(completedir_vs, skinname);
strcat(completedir_vs, texname_vs);
strcpy(completedir_rw, skindir);
strcat(completedir_rw, skinname);
strcat(completedir_rw, texname_rw);
strcpy(completedir_eng, skindir);
strcat(completedir_eng, skinname);
strcat(completedir_eng, texname_eng);
strcpy(completedir_lw, skindir);
strcat(completedir_lw, skinname);
strcat(completedir_lw, texname_lw);
skin[0] = oapiLoadTexture(completedir_fus);
skin[1] = oapiLoadTexture(completedir_vs);
skin[2] = oapiLoadTexture(completedir_rw);
skin[3] = oapiLoadTexture(completedir_eng);
skin[4] = oapiLoadTexture(completedir_lw);
ApplyLivery();
}
void B747SP::ApplyLivery(){
if(!b747sp_dmesh) return;
if(skin[0]) oapiSetTexture(b747sp_dmesh, 1, skin[0]);
if(skin[1]) oapiSetTexture(b747sp_dmesh, 2, skin[1]);
if(skin[2]) oapiSetTexture(b747sp_dmesh, 3, skin[2]);
if(skin[3]) oapiSetTexture(b747sp_dmesh, 4, skin[3]);
if(skin[4]) oapiSetTexture(b747sp_dmesh, 9, skin[4]);
}