C++ Question Save state issue

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
I have seen this is a lot of my addons. and it doesn't do it all the time.


SOLAR 1 1.0000 FDOORL 0 0.0000 FDOORR 0 0.0000 ADOORL 1 1.0000 ADOORR 1 1.0000 SOLP 0 0 0 -2222868362908545898858136888734573973241496362852462441143111967526658423854091629388310134497313286441770390279717928873260208820158122422956083383769193866369917618605713022480235858309032843535037998261369289301229828886843617208760863304863401268520221172530772349619006545045747293749248000.0000 CAM 1 1.0000

initialized.
solp_status = 4; solp_rot_status = 0; solp_rot_proc = .5; solp_proc = 0;

{ char cbuf[256]; //UACS mdlAPI.clbkSaveState(scn); if (lightFRONTon == 1) oapiWriteScenario_string(scn, "LIGHTF", " ");// sprintf(cbuf, "%d %0.4f", SOLAR_status, SOLAR_proc); oapiWriteScenario_string(scn, "SOLAR", cbuf); sprintf(cbuf, "%d %0.4f", ADOOR1_status, ADOOR1_proc); oapiWriteScenario_string(scn, "FDOORL", cbuf); sprintf(cbuf, "%d %0.4f", ADOOR2_status, ADOOR2_proc); oapiWriteScenario_string(scn, "FDOORR", cbuf); sprintf(cbuf, "%d %0.4f", DOOR1_status, DOOR1_proc); oapiWriteScenario_string(scn, "ADOORL", cbuf); sprintf(cbuf, "%d %0.4f", DOOR2_status, DOOR2_proc); oapiWriteScenario_string(scn, "ADOORR", cbuf); sprintf(cbuf, "%d %d %d %0.4f", solp_status, solp_proc, solp_rot_status, solp_rot_proc); oapiWriteScenario_string(scn, "SOLP", cbuf); sprintf(cbuf, "%d %0.4f", CAM_status, CAMERA_proc); oapiWriteScenario_string(scn, "CAM", cbuf); // ORBITER, default vessel parameters SaveDefaultState (scn); }

It usually show up in the solar tracking
double step_time, solp_proc; int solp_rot_status, solp_status ; double solp_rot_proc;;
 

n72.75

Move slow and try not to break too much.
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,705
Reaction score
1,381
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
Could you paste that into some code tags. it's kinda hard to tell.

If the problem only happens sometimes, it's almost certianly due to uninitialized memory.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
code tags
not sure what those are?

If the problem only happens sometimes, it's almost certianly due to uninitialized memory.
ok. It usually happens with the solar panel or HGA animation

Is there a fix?
this is the solar panel tracking animation code
void MMSEV::DoSolpRot() { if (solp_rot_status == 0)solp_rot_status = 1; if (solp_rot_status == 1) { double Solpangle; VECTOR3 rsun; VECTOR3 rsuninv; VECTOR3 rsunloc; GetGlobalPos(rsun); rsuninv = _V(-rsun.x, -rsun.y, -rsun.z); Global2Local(rsuninv, rsunloc); Solpangle = (PI * ((solp_rot_proc * 2))); // current rotation angle of panels double sunangle = atan2(-rsunloc.x, rsunloc.z); // current angle of sun on ZY plane relative to z axis sunangle = sunangle + PI; if (sunangle < 0) sunangle = sunangle + (2 * PI); // sanity check - angle always positive if (sunangle < 0) sunangle = sunangle + (2 * PI); // sanity check - angle always positive double angle_diff = sunangle - Solpangle; // angular difference between sun and panels int a = 1; if (angle_diff < PI && angle_diff > 0)a = 1; // check which way the panels should rotate else if (angle_diff > PI && angle_diff > 0)a = -1; // check which way the panels should rotate else if (angle_diff > -PI && angle_diff < 0)a = -1; // check which way the panels should rotate else if (angle_diff < -PI && angle_diff < 0)a = 1; // check which way the panels should rotate double max_rot = step_time * SOLP_SPEED * 2 * PI; // check if angular difference if (angle_diff > 0 && angle_diff < max_rot) a = 0; // is less than panel rotation else if (angle_diff < 0 && -angle_diff < max_rot) a = 0; // during this frame double db = step_time * SOLP_SPEED; if (a == 1) solp_rot_proc = (solp_rot_proc + db); else if (a == -1) solp_rot_proc = (solp_rot_proc - db); else if (a == 0) solp_rot_proc = sunangle / (2 * PI); // set exactly perpendicular to sun if (solp_rot_proc > 1) solp_rot_proc = (solp_rot_proc - 1); // range always 0-1 else if (solp_rot_proc < 0) solp_rot_proc = (solp_rot_proc + 1); // range always 0-1 //sprintf(oapiDebugString(), "sunangle %2.2fsunangledf %2.2f rotf %2.2f db %2.2f status%d", sunangle,angle_diff, solp_rot_proc, db, solp_rot_status); SetAnimation(anim_solp_rot, solp_rot_proc); // set the animation state and we're done! } else if (solp_rot_status == 2) { double db = step_time * SOLP_SPEED; if (solp_rot_proc > 0.5) { solp_rot_proc = solp_rot_proc + db; if (solp_rot_proc > 1) { solp_rot_proc = .5; solp_rot_status = 3; } } else { solp_rot_proc = solp_rot_proc - db; if (solp_rot_proc < 0) { solp_rot_proc = .5; solp_rot_status = 3; } } if (solp_rot_proc > 1) solp_rot_proc = (solp_rot_proc - 1); // range always 0-1 else if (solp_rot_proc < 0) solp_rot_proc = (solp_rot_proc + 1); // range always 0-1 SetAnimation(anim_solp_rot, solp_rot_proc); } else if (solp_rot_status == 3)SetAnimation(anim_solp_rot, 0.5); }
 

Buck Rogers

Major Spacecadet
Joined
Feb 26, 2013
Messages
464
Reaction score
409
Points
63
if (sunangle < 0) sunangle = sunangle + (2 * PI); // sanity check - angle always positive
if (sunangle < 0) sunangle = sunangle + (2 * PI); // sanity check - angle always positive
this line is doubled, maybe by copy/paste something was deleted?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
That's ICODE, something else entirely. Just use CODE tags from now on.
??? so don't use inline code? but use
Code:
    test

Looking for a clean solar tracking code. I have seen that double line is a lot of mine. I wouldn't think that would do it though. I think I got the solar tracking from @BrianJ
 
Last edited:

DaveS

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Feb 4, 2008
Messages
9,484
Reaction score
739
Points
203
??? so don't use inline code? but use
Code:
    test
No. Using the CODE tags embeds the code text in it's own scroll-able section, preventing the thread from getting longer vertically than it has to.
 

DaveS

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Feb 4, 2008
Messages
9,484
Reaction score
739
Points
203
Ok. At a lost. what do the code tags look like?
What do you mean? Do you mean the tags themselves or what something embedded with the tags look like?
Code:
// ==============================================================
//                    ORBITER MODULE: HST
//                  Part of the ORBITER SDK
//          Copyright (C) 2001-2007 Martin Schweiger
//                   All rights reserved
//
// HST.cpp
// HST basic specs and animations
//
// HST mesh and textures by David Sundstrom
// ==============================================================

#define ORBITER_MODULE

#include "HST.h"
#include <stdio.h>

// ==============================================================
// HST class implementation
// ==============================================================

// --------------------------------------------------------------
// Constructor
// --------------------------------------------------------------
HST::HST (OBJHANDLE hObj, int fmodel)
: VESSEL3 (hObj, fmodel)
{
    ant_proc = 0.0;
    ant_status = DOOR_CLOSED;
    hatch_proc = 0.0;
    hatch_status = DOOR_CLOSED;
    array_proc = 1.0;
    array_status = DOOR_OPEN;
    DefineAnimations ();
}

// --------------------------------------------------------------
// Define animation sequences for moving parts
// --------------------------------------------------------------
void HST::DefineAnimations (void)
{
    // 1. Hi-gain antenna
    static UINT HiGainAnt1Grp[2] = {1,3};
    static MGROUP_ROTATE HiGainAnt1 (0, HiGainAnt1Grp, 2, _V(0.002579,1.993670,0.238158), _V(-1,0,0), (float)(PI*0.51));
    static UINT HiGainAnt2Grp[2] = {0,2};
    static MGROUP_ROTATE HiGainAnt2 (0, HiGainAnt2Grp, 2, _V(0.002740,-2.013091,0.238118), _V(1,0,0), (float)(PI*0.51));
    anim_ant = CreateAnimation (0.0196);
    AddAnimationComponent (anim_ant, 0, 0.5, &HiGainAnt1);
    AddAnimationComponent (anim_ant, 0, 1,   &HiGainAnt2);

    // 2. Main telescope hatch
    static UINT HatchGrp[1] = {86};
    static MGROUP_ROTATE Hatch (0, HatchGrp, 1, _V(0.089688,1.456229,7.526453), _V(-1,0,0), (float)(RAD*113));
    anim_hatch = CreateAnimation (0);
    AddAnimationComponent (anim_hatch, 0, 1, &Hatch);

    // 3. Solar arrays - folding
    anim_array = CreateAnimation (1);
    static UINT ArrayLFoldGrp[5] = {87,88,89,90,103};
    static UINT ArrayRFoldGrp[5] = {92,93,94,95,102};
    static MGROUP_ROTATE ArrayLFold1 (0, ArrayLFoldGrp, 5, _V(-1.9, 0.053583,1.429349), _V(0,-1,0), (float)(PI*0.5));
    AddAnimationComponent (anim_array, 0,   0.4, &ArrayLFold1);
    static MGROUP_ROTATE ArrayLFold2 (0, ArrayLFoldGrp, 5, _V(0,0.053583,1.429349), _V(-1,0,0), (float)(PI*0.5));
    AddAnimationComponent (anim_array, 0.4, 0.6, &ArrayLFold2);
    static MGROUP_SCALE  ArrayLFold3 (0, ArrayLFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4));
    AddAnimationComponent (anim_array, 0.6, 1,   &ArrayLFold3);
    static MGROUP_ROTATE ArrayRFold1 (0, ArrayRFoldGrp, 5, _V( 1.9, 0.053583,1.429349), _V(0, 1,0), (float)(PI*0.5));
    AddAnimationComponent (anim_array, 0,   0.4, &ArrayRFold1);
    static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 5, _V(0,0.053583,1.429349), _V(-1,0,0), (float)(PI*0.5));
    AddAnimationComponent (anim_array, 0.4, 0.6, &ArrayRFold2);
    static MGROUP_SCALE  ArrayRFold3 (0, ArrayRFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4));
    AddAnimationComponent (anim_array, 0.6, 1,   &ArrayRFold3);
}

void HST::ActivateAntenna (DoorStatus action)
{
    ant_status = action;
}

void HST::RevertAntenna (void)
{
    ActivateAntenna ((ant_status == DOOR_CLOSED || ant_status == DOOR_CLOSING) ?
        DOOR_OPENING : DOOR_CLOSING);
}

void HST::ActivateHatch (DoorStatus action)
{
    hatch_status = action;
}

void HST::RevertHatch (void)
{
    ActivateHatch ((hatch_status == DOOR_CLOSED || hatch_status == DOOR_CLOSING) ?
        DOOR_OPENING : DOOR_CLOSING);
}

void HST::ActivateArray (DoorStatus action)
{
    array_status = action;
}

void HST::RevertArray (void)
{
    ActivateArray ((array_status == DOOR_CLOSED || array_status == DOOR_CLOSING) ?
        DOOR_OPENING : DOOR_CLOSING);
}

// ==============================================================
// Overloaded callback functions
// ==============================================================

// --------------------------------------------------------------
// Set vessel class parameters
// --------------------------------------------------------------
void HST::clbkSetClassCaps (FILEHANDLE cfg)
{
    SetSize (HST_SIZE);
    SetEmptyMass (HST_EMPTY_MASS);
}

// --------------------------------------------------------------
// Read status from scenario file
// --------------------------------------------------------------
void HST::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
    char *line;

    while (oapiReadScenario_nextline (scn, line)) {
        if (!_strnicmp (line, "ANT", 3)) {
            sscanf (line+3, "%d%lf", &ant_status, &ant_proc);
        } else if (!_strnicmp (line, "HATCH", 5)) {
            sscanf (line+5, "%d%lf", &hatch_status, &hatch_proc);
        } else if (!_strnicmp (line, "FOLD", 4)) {
            sscanf (line+5, "%d%lf", &array_status, &array_proc);
        } else {
            ParseScenarioLineEx (line, vs);
        }
    }

    SetAnimation (anim_ant, ant_proc);
    SetAnimation (anim_hatch, hatch_proc);
    SetAnimation (anim_array, array_proc);
}

// --------------------------------------------------------------
// Save status to scenario file
// --------------------------------------------------------------
void HST::clbkSaveState (FILEHANDLE scn)
{
    char cbuf[256];
    SaveDefaultState (scn);
    sprintf (cbuf, "%d %0.4f", ant_status, ant_proc);
    oapiWriteScenario_string (scn, "ANT", cbuf);
    sprintf (cbuf, "%d %0.4f", hatch_status, hatch_proc);
    oapiWriteScenario_string (scn, "HATCH", cbuf);
    sprintf (cbuf, "%d %0.4f", array_status, array_proc);
    oapiWriteScenario_string (scn, "FOLD", cbuf);
}

// --------------------------------------------------------------
// Frame update
// --------------------------------------------------------------
void HST::clbkPostStep (double simt, double simdt, double mjd)
{
    // Animate hi-gain antenna
    if (ant_status >= DOOR_CLOSING) {
        double da = simdt * ANTENNA_OPERATING_SPEED;
        if (ant_status == DOOR_CLOSING) {
            if (ant_proc > 0.0) ant_proc = max (0.0, ant_proc-da);
            else                ant_status = DOOR_CLOSED;
        } else {
            if (ant_proc < 1.0) ant_proc = min (1.0, ant_proc+da);
            else                ant_status = DOOR_OPEN;
        }
        SetAnimation (anim_ant, ant_proc);
    }

    // Animate main telescope hatch
    if (hatch_status >= DOOR_CLOSING) {
        double da = simdt * HATCH_OPERATING_SPEED;
        if (hatch_status == DOOR_CLOSING) {
            if (hatch_proc > 0.0) hatch_proc = max (0.0, hatch_proc-da);
            else                  hatch_status = DOOR_CLOSED;
        } else {
            if (hatch_proc < 1.0) hatch_proc = min (1.0, hatch_proc+da);
            else                  hatch_status = DOOR_OPEN;
        }
        SetAnimation (anim_hatch, hatch_proc);
    }

    // Animate solar arrays
    if (array_status >= DOOR_CLOSING) {
        double da = simdt * ARRAY_OPERATING_SPEED;
        if (array_status == DOOR_CLOSING) {
            if (array_proc > 0.0) array_proc = max (0.0, array_proc-da);
            else                  array_status = DOOR_CLOSED;
        } else {
            if (array_proc < 1.0) array_proc = min (1.0, array_proc+da);
            else                  array_status = DOOR_OPEN;
        }
        SetAnimation (anim_array, array_proc);
    }
}

// --------------------------------------------------------------
// Keyboard interface handler (buffered key events)
// --------------------------------------------------------------
int HST::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
    if (!down) return 0; // only process keydown events

    if (KEYMOD_CONTROL (kstate)) {

        switch (key) {
        case OAPI_KEY_1: // deploy/retract antenna
            RevertAntenna();
            return 1;
        case OAPI_KEY_2: // open/close hatch
            RevertHatch();
            return 1;
        case OAPI_KEY_3: // open/fold solar arrays
            RevertArray();
            return 1;
        }
    }
    return 0;
}

// --------------------------------------------------------------
// Respond to generic messages
// --------------------------------------------------------------
int HST::clbkGeneric (int msgid, int prm, void *context)
{
    switch (msgid) {
    case VMSG_LUAINTERPRETER:
        return Lua_InitInterpreter (context);
    case VMSG_LUAINSTANCE:
        return Lua_InitInstance (context);
    }
    return 0;
}

// ==============================================================
// API callback interface
// ==============================================================

// --------------------------------------------------------------
// Vessel initialisation
// --------------------------------------------------------------
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
    return new HST (hvessel, flightmodel);
}

// --------------------------------------------------------------
// Vessel cleanup
// --------------------------------------------------------------
DLLCLBK void ovcExit (VESSEL *vessel)
{
    if (vessel) delete (HST*)vessel;
}
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,220
Reaction score
1,568
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
Based on the code in the first post and the output written, it looks to me like the solp_rot_proc variable is either uninitialized or was overwritten with a garbage value, so the "%0.4f" format specification writes that trashed value out ("-2222868362908545898858136888734573973241496362852462441143111967526658423854091629388310134497313286441770390279717928873260208820158122422956083383769193866369917618605713022480235858309032843535037998261369289301229828886843617208760863304863401268520221172530772349619006545045747293749248000.0000").
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
Code:
solp_status = 4;
solp_rot_status = 0;
solp_rot_proc = .5;
solp_proc = 0;
step_time = 0;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
So I got AI code with debugging info. In game here is the exit states. But then when you look at the scn the rotation value is BAD
Code:
void MMSEV::DoSolpRot() {
    if (solp_rot_status == 0) {
        solp_rot_status = 1;
    }

    if (solp_rot_status == 1) {
        double Solpangle;
        VECTOR3 rsun;
        VECTOR3 rsuninv;
        VECTOR3 rsunloc;
        GetGlobalPos(rsun);
        rsuninv = _V(-rsun.x, -rsun.y, -rsun.z);
        Global2Local(rsuninv, rsunloc);

        Solpangle = (PI * ((solp_rot_proc * 2))); // current rotation angle of panels
        double sunangle = atan2(-rsunloc.x, rsunloc.z); // current angle of sun on ZY plane relative to z axis
        sunangle = fmod(sunangle + 2 * PI, 2 * PI); // ensure angle is always positive

        double angle_diff = sunangle - Solpangle;
        if (angle_diff < -PI) {
            angle_diff += 2 * PI;
        }
        else if (angle_diff > PI) {
            angle_diff -= 2 * PI;
        }

        int a = (angle_diff > 0) ? 1 : -1; // determine rotation direction
        if (fabs(angle_diff) < step_time * SOLP_SPEED * 2 * PI) {
            a = 0; // if angular difference is less than panel rotation during this frame
        }

        double db = step_time * SOLP_SPEED;
        solp_rot_proc = fmod(solp_rot_proc + a * db, 1.0); // update rotation process and ensure within range 0-1

        if (solp_rot_proc < 0) {
            solp_rot_proc += 1;
        }

        if (a == 0) {
            solp_rot_proc = sunangle / (2 * PI); // set exactly perpendicular to sun
        }

        SetAnimation(anim_solp_rot, solp_rot_proc); // set the animation state and we're done!

        // Debugging output
        sprintf(oapiDebugString(), "solp_rot_status: %d, sunangle: %f, angle_diff: %f, solp_rot_proc: %f", solp_rot_status, sunangle, angle_diff, solp_rot_proc);
    }
    else if (solp_rot_status == 2) {
        double db = step_time * SOLP_SPEED;
        if (solp_rot_proc > 0.5) {
            solp_rot_proc += db;
            if (solp_rot_proc > 1) {
                solp_rot_proc = 0.5;
                solp_rot_status = 3;
            }
        }
        else {
            solp_rot_proc -= db;
            if (solp_rot_proc < 0) {
                solp_rot_proc = 0.5;
                solp_rot_status = 3;
            }
        }

        solp_rot_proc = fmod(solp_rot_proc, 1.0); // ensure within range 0-1
        if (solp_rot_proc < 0) {
            solp_rot_proc += 1;
        }

        SetAnimation(anim_solp_rot, solp_rot_proc);

        // Debugging output
        sprintf(oapiDebugString(), "solp_rot_status: %d, solp_rot_proc: %f", solp_rot_status, solp_rot_proc);
    }
    else if (solp_rot_status == 3) {
        SetAnimation(anim_solp_rot, 0.5);

        // Debugging output
        sprintf(oapiDebugString(), "solp_rot_status: %d, solp_rot_proc: 0.5", solp_rot_status);
    }
}
and the save state:
Code:
void MMSEV::clbkSaveState(FILEHANDLE scn)
{
    char cbuf[256];
    //UACS
    mdlAPI.clbkSaveState(scn);
    
    if (lightFRONTon == 1) oapiWriteScenario_string(scn, "LIGHTF", " ");// 

    

    sprintf(cbuf, "%d %0.4f", SOLAR_status, SOLAR_proc);
    oapiWriteScenario_string(scn, "SOLAR", cbuf);

    sprintf(cbuf, "%d %0.4f", ADOOR1_status, ADOOR1_proc);
    oapiWriteScenario_string(scn, "FDOORL", cbuf);

    sprintf(cbuf, "%d %0.4f", ADOOR2_status, ADOOR2_proc);
    oapiWriteScenario_string(scn, "FDOORR", cbuf);

    sprintf(cbuf, "%d %0.4f", DOOR1_status, DOOR1_proc);
    oapiWriteScenario_string(scn, "ADOORL", cbuf);

    sprintf(cbuf, "%d %0.4f", DOOR2_status, DOOR2_proc);
    oapiWriteScenario_string(scn, "ADOORR", cbuf);

    sprintf(cbuf, "%d %d %d %0.4f", solp_status, solp_proc, solp_rot_status, solp_rot_proc);
    oapiWriteScenario_string(scn, "SOLP", cbuf);

    sprintf(cbuf, "%d %0.4f", CAM_status, CAMERA_proc);
    oapiWriteScenario_string(scn, "CAM", cbuf);



    // ORBITER, default vessel parameters
    SaveDefaultState (scn);
    
}

scn:
Code:
MMSEVUACS:MMSEVUACS
  LIGHTF  
  SOLAR 1 1.0000
  FDOORL 0 0.0000
  FDOORR 0 0.0000
  ADOORL 1 1.0000
  ADOORR 1 1.0000
  SOLP 0 0 0 2829643879397636285268549782275210599896175274140079442833907957644662682561012700203931001746867762495024143532032.0000
  CAM 0 0.0000
  STATUS Landed Mars
  POS -102.1979860 -7.0117279
  HEADING 249.28
  ALT 2.239
  AROT -51.617 63.760 -151.350
  AFCMODE 7
  NAVFREQ 0 0
  XPDR 0
END
[\code]
 

Attachments

  • mmsevsolartracking1.jpg
    mmsevsolartracking1.jpg
    77.7 KB · Views: 2

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
253
Reaction score
301
Points
78
Location
On my chair
Why do you have sol_proc as an int (%d) and solp_rot_proc as a float (%0.4f)? Are your types correct?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
Code:
double step_time, solp_proc; int solp_rot_status, solp_status ; double solp_rot_proc;;
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
253
Reaction score
301
Points
78
Location
On my chair
Looks like a format mismatch then, try this instead :
Code:
sprintf(cbuf, "%d %0.4f %d %0.4f", solp_status, solp_proc, solp_rot_status, solp_rot_proc);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
Thanks. That seemed to fix it.
Working on a load from scn that I can't get to load.
Code:
void STARLAB::clbkLoadStateEx(FILEHANDLE scn, void* status)
{
    char* line;
    while (oapiReadScenario_nextline(scn, line))
    {
        if (!_strnicmp(line, "SOLARP", 6)) {
            sscanf(line + 6, "%d %0.4f", &solp_rot_status, &solp_rot_proc);
        }
        if (!_strnicmp(line, "RADPANEL", 8)) {
            sscanf(line + 8, "%d %0.4f", &solp_rotRAD_status, &solp_rotRAD_proc);
        }
        if (!_strnicmp(line, "RADEXT", 6)) {
            sscanf(line + 6, "%d %lf", &RADEXT_status, &RADEXT_proc);
        }
        if (!_strnicmp(line, "CENT", 4)) {
            sscanf(line + 4, " %lf", &CENT_proc);
        }
        if (!_strnicmp(line, "CARGO", 5)) {
            sscanf(line + 5, " %d", &cargo);
        }
        if (!_strnicmp(line, "CREW", 4)) {
            sscanf(line + 4, " %d", &crew);
        }
        if (!_strnicmp(line, "LIGHT", 5)) {
            sscanf(line + 5, " %d", &lightON);
        }
        
        else if (!_strnicmp(line, "EARTHTRACKING", 13)) {
            sscanf(line + 13, "%lf %lf", &hga_azimuth_proc, &hga_elevation_proc);
        }
            ParseScenarioLineEx(line, status);
            UpdateMesh();
            //DoSolpRot();
        }

    
    //DoSolpRot();
    if (cargo == 0)    SetMeshVisibilityMode(STARLAB_mesh_idx[2], MESHVIS_NEVER);
    else if (cargo == 1)    SetMeshVisibilityMode(STARLAB_mesh_idx[2], MESHVIS_ALWAYS);
    if (crew == 0) {
        SetMeshVisibilityMode(STARLAB_mesh_idx[3], MESHVIS_NEVER);
        SetMeshVisibilityMode(STARLAB_mesh_idx[4], MESHVIS_NEVER);
    }
    else if (crew == 1) {
        SetMeshVisibilityMode(STARLAB_mesh_idx[3], MESHVIS_ALWAYS);
        SetMeshVisibilityMode(STARLAB_mesh_idx[4], MESHVIS_ALWAYS);
    }
    }
in the scn:
STARLAB:STARLAB
STATUS Orbiting Earth
RPOS 3671436.493 86.163 5969341.690
RVEL -6424.3108 0.4076 3950.9106
AROT -108.506 35.076 -62.294
VROT 0.0408 -0.0430 -0.0437
AFCMODE 7
PRPLEVEL 0:0.999780
NAVFREQ 0 0
XPDR 468
SOLARP 0 0.7
RADEXT 1 1.0000
RADPANEL 0 0.7
END
When I run the debug the
solp_rotRAD_proc is 0
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
253
Reaction score
301
Points
78
Location
On my chair
Your strcmp chain looks wrong, it should be if .. else if ... else if ...
and the ParseScenarioLineEx should be in a final else statement.
The closing of the while loops looks misplaced too. don't know if it's a copy paste error when you posted but it should end after the last else (ParseScenarioLineEx)
 
Top