Question Ranger (and other ships) from Interstellar?

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Ok. back from vacation. Trying to center the elevator trim with a key. I know you can with a mouse and click on the center bar.

Code:
	else if (key == OAPI_KEY_7)//JETTISON
	{

		SetControlSurfaceLevel(AIRCTRL_ELEVATORTRIM, 0);
		return 1;
	}

We are adding some rcs to adjust the elevator/pitch. So if you trim you are adjusting the amount of thrust to apply to thrusters.

But want to press a button and reset trim to 0.

---------- Post added 08-08-16 at 06:00 AM ---------- Previous post was 08-07-16 at 07:29 AM ----------

UGH:shrug: Now we can a ctd. It runs ok in the debug.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
It runs ok in the debug.

With 99% certainty, "It runs ok in DEBUG" means: There are uninitialized variables, that don't cause problem in DEBUG (because debug initializes memory with test patterns) but cause problems in Release (where memory is not changed during allocation and contains the deceased bits of previous processes)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
OK. Thanks. I will take a look. I assume when you say uninitialized variables. It is like
in the h.
Code:
double pitchlevel;

then in the cpp pitchlevel is never initialized like "
Code:
pitchlevel =0;
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Yes, like that.

Uninitialized variable bug = The variable was never set by your program before you read it.

You should ALWAYS initialize your variables, in the best case already in the constructor. Even if you can safely assume that they will be set before you use them in clbkXXXXStep. One small refactoring, and suddenly the variable is used before you have initialized it with a value.

A common error is having a variable like "old_state" and a (hidden) loop like:

If old_state != new_state then
dosomethinghorrible();
old_state = new_state;
end if
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Well I thought I fixed it. Got it running made changes and now I get a CTD. In debug it opens and then ctd. No symbols loaded is all I get.

So is there a way to check for uninitialized variables?

Code:
	PITCHTRIMLEVEL = 0;
	PITCHTRIMLEVELABS = 0;


Code:
	if (PITCHTRIMLEVEL < 0){
		PITCHTRIMLEVELABS = abs(PITCHTRIMLEVELABS);
		SetThrusterLevel(th_rcs[20], PITCHTRIMLEVELABS);
		SetThrusterLevel(th_rcs[25], PITCHTRIMLEVELABS);
		SetThrusterLevel(th_rcs[27], PITCHTRIMLEVELABS);
		SetThrusterLevel(th_rcs[26], PITCHTRIMLEVELABS);

	
	}
	if (PITCHTRIMLEVEL > 0){
		SetThrusterLevel(th_rcs[21], PITCHTRIMLEVEL);
		SetThrusterLevel(th_rcs[22], PITCHTRIMLEVEL);
		SetThrusterLevel(th_rcs[23], PITCHTRIMLEVEL);
		SetThrusterLevel(th_rcs[24], PITCHTRIMLEVEL);

	
	}
Code:
	else if (key == OAPI_KEY_DELETE)//JETTISON
	{
		
		
		PITCHTRIMLEVEL = PITCHTRIMLEVEL + .01;
		if (PITCHTRIMLEVEL > 1)PITCHTRIMLEVEL = 1;
		return 1;
	}

	else if (key == OAPI_KEY_INSERT)//JETTISON
	{
	PITCHTRIMLEVEL = PITCHTRIMLEVEL - .01;
	if (PITCHTRIMLEVEL <-1)PITCHTRIMLEVEL = -1;
		
		return 1;
	}

PITCHTRIMLEVEL is a counter from 1 to -1 in .01 steps. If it is >0 then fire pitch thrust PITCHTRIMLEVEL amount. if PITCHTRIMLEVEL<0 (negative) then fire pitch thrust abs(PITCHTRIMLEVEL). there are 4 front pitch and 4 rear thrusters. they fire depending if PITCHTRIMLEVELis postive or negative
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
is th_rcs[x] pointing to a valid thruster handle?

---------- Post added at 11:01 AM ---------- Previous post was at 08:27 AM ----------

BTW: abs() is usually the integer version of the function, unless you include cmath. Do you have "#include <cmath>" or "#include <math.h>" in your relevant files? If you want to be on the safe side, use "fabs" instead
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. the issues seems to be in the hover thrust gauge.
initial setup of hover thrusters
Code:
//HOVER
	tank2 = CreatePropellantResource(FUELMASS2);

	th_hover[0] = CreateThruster(_V(5, 0, 5), _V(0, 1, 0), MAXHOVERTH / 4, tank2, ISP);
	th_hover[1] = CreateThruster(_V(-5, 0, -5), _V(0, 1, 0), MAXHOVERTH / 4, tank2, ISP);
	th_hover[2] = CreateThruster(_V(-5, 0, 5), _V(0, 1, 0), MAXHOVERTH / 4, tank2, ISP);
	th_hover[3] = CreateThruster(_V(5, 0, -5), _V(0, 1, 0), MAXHOVERTH / 4, tank2, ISP);

	thg_hover = CreateThrusterGroup(th_hover, 4, THGROUP_HOVER);
commented lines no ctd
Code:
 current_thrust_hover_level = GetThrusterGroupLevel(thg_hover);
if (current_thrust_hover_level != thrust_hover_last_drawn){
		thrust_hover_last_drawn = current_thrust_hover_level;
		redrawpanel = true;
	}
this tells how far to draw the bar
Code:
	hoverx2 = int(hoverx1 + current_thrust_hover_level * 284);
draws the bar
Code:
	Rectangle(hDC, hoverx1, hovery1, hoverx2,hovery2);//HOVERthrust
initialized
Code:
	current_thrust_hover_level = 0;
	thrust_hover_last_drawn = 0;
	hoverx1 = 60;
	hovery1 = 509;
	hoverx2 = 342;
	hovery2 = 534;


One thing I did notice it would draw the hover bar full till it refreshed. I was thinking I could just go to one hover thruster. The reason we have it that way is for the 4 exhaust?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
How is th_hover defined?

And why are you not simply using

current_thrust_hover_level = GetThrusterGroupLevel(THGROUP_HOVER);
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Bingo that was it I had changed it to
Code:
th_hover[1];
:blush:


now it is
Code:
th_hover[4];
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Should have caused a minor annoyance there, but it is one code smell less.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
On the lander. I have this code so if the lander is below 10 meters add exhaust stream to show dust. and then if above 10 meters delete exhaust stream.
Code:
if ((alt <10) && (smoke == 0))
	{

		th_hover[0] = AddExhaustStream(th_hover[0], _V(-3.421, 0, 2.43), &exhaust_hover);
		th_hover[1] = AddExhaustStream(th_hover[1], _V(3.421, 0, 2.43), &exhaust_hover);
		th_hover[2] = AddExhaustStream(th_hover[2], _V(-3.421, 0, -2.136), &exhaust_hover);
		th_hover[3] = AddExhaustStream(th_hover[3], _V(3.421, 0, -2.136), &exhaust_hover);
		smoke = 1;
	};
	if ((alt>10) && (smoke==1))
	{



		DelExhaustStream(th_hover[0]);
		DelExhaustStream(th_hover[1]);
		DelExhaustStream(th_hover[2]);
		DelExhaustStream(th_hover[3]);
		smoke = 0;
	}

So the lander using hovers rises. exhaust is seen. and 10 meters no exhaust, Good.
BUT then if the lander drops below 10 not exhaust is seen.

smoke is initialized. All that indicates isif the exhaust stream were added.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
2 issues and the Lander will be done:)
We just want hover exhaust below 10 meters.
Code:
if (alt <10)//hover exhaust
	{

		th_hover[0] = AddExhaustStream(th_hover[0], _V(-3.421, 0, 2.43), &exhaust_hover);
		th_hover[1] = AddExhaustStream(th_hover[1], _V(3.421, 0, 2.43), &exhaust_hover);
		th_hover[2] = AddExhaustStream(th_hover[2], _V(-3.421, 0, -2.136), &exhaust_hover);
		th_hover[3] = AddExhaustStream(th_hover[3], _V(3.421, 0, -2.136), &exhaust_hover);
		//smoke = 1;
	};
	if (alt>10)  //no hover exhaust
	{	DelExhaustStream(th_hover[0]);
		DelExhaustStream(th_hover[1]);
		DelExhaustStream(th_hover[2]);
		DelExhaustStream(th_hover[3]);
		
	}

The exhaust keeps going past 10m.

The other is harder. It is getting the labels on the COpilot mfd's. The pilots are fine. All I see is the texture. No idea why?

defines the size and texture.
Code:
static DIMENSION const MFD_BUTTONS_FN_DIM = _D(50, 28, 2, 2);
static RECT const MFD_BUTTONS_FN_RECT[] = {
	_R(000, 000, 100, 168), _R(100, 000, 200, 168), _R(200, 000, 300, 168), _R(000, 169, 100, 333)
//	_R(000, 000, 100, 168), _R(200, 000, 300, 168), _R(300, 000, 400, 168), _R(400, 000, 500, 168)
};

Code:
void ClassicMfd::DefineMfdButtons(
	UINT const texId,
	UINT const fuctionAreaId, UINT const functionGroupId, RECT const functionRect,
	UINT const sysAreaId, UINT const sysGroupId
	)
{
	SURFHANDLE const texDyn = oapiGetTextureHandle(meshhg_VC, texId);
	oapiVCRegisterArea(fuctionAreaId, functionRect, PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN | PANEL_MOUSE_LBPRESSED | PANEL_MOUSE_ONREPLAY, PANEL_MAP_NONE, texDyn);
	DefineStaticClickArea(oapiMeshGroup(meshhg_VC, functionGroupId), fuctionAreaId, true);

	oapiVCRegisterArea(sysAreaId, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN | PANEL_MOUSE_ONREPLAY);
	DefineStaticClickArea(oapiMeshGroup(meshhg_VC, sysGroupId), sysAreaId, true);
}

static int get_font_height(HDC const hDC)
{
	TEXTMETRIC tm;
	if (GetTextMetrics(hDC, &tm))
	{
		return abs(tm.tmAscent);
	}

	return 5; // Wild, crazy guessing
}

void ClassicMfd::RedrawMFDButtons(SURFHANDLE const surf, int const mfd)
{
	int const btnWidth = buttonFnDim->width;
	int const btnHeight = buttonFnDim->height;
	RECT const draw_area = _R(0, 0, buttonFnRect[mfd].right - buttonFnRect[mfd].left, buttonFnRect[mfd].bottom - buttonFnRect[mfd].top);

	HDC const hDC = oapiGetDC(surf);

	SelectObject(hDC, buttonBrush);
	SetBkMode(hDC, OPAQUE);
	Rectangle(hDC, draw_area.left, draw_area.top, draw_area.right, draw_area.bottom);

	HFONT pFont = (HFONT)SelectObject(hDC, labelFont);
	SetTextColor(hDC, labelColor);
	SetTextAlign(hDC, TA_CENTER);
	int const half_font_height = get_font_height(hDC) / 2;

	char const * label;
	int const label_x_offset = (btnWidth / 2);
	int const label_y_offset = (btnHeight / 2) - buttonFnDim->marginHeight - half_font_height;
	for (int i = 0; i < 12; i++) {
		int const x = i / 6;
		int const y = i % 6;
		if (label = oapiMFDButtonLabel(mfd, i)) {
			int const xwidth = (x * btnWidth);
			int const yheight = (y * btnHeight);

			SelectObject(hDC, buttonLabelBrush);
			SetBkMode(hDC, OPAQUE);
			Rectangle(hDC,
				draw_area.left + xwidth + buttonFnDim->marginWidth,
				draw_area.top + yheight + buttonFnDim->marginHeight,
				draw_area.left + xwidth + btnWidth - buttonFnDim->marginWidth,
				draw_area.top + yheight + btnHeight - buttonFnDim->marginHeight
				);
			SetBkMode(hDC, TRANSPARENT);
			TextOut(hDC, draw_area.left + xwidth + label_x_offset, draw_area.top + yheight + label_y_offset, label, strlen(label));
		}
		else break;
	}

	SelectObject(hDC, pFont);
	oapiReleaseDC(surf, hDC);
}

Code:
void ClassicMfd::DefineMfdsButtons()
{
	// Pilot Left
	DefineMfdButtons(
		TEX_LANDER16VC_MFD_DYNAMIC_06,
		AID_PILOT_MFD_LEFT_BTNS_FN, GRP_LANDER16VC_PILOT_MFD_LEFT_BTNS_FN, buttonFnRect[MFD_PILOT_LEFT],
		AID_PILOT_MFD_LEFT_BTNS_SYS, GRP_LANDER16VC_PILOT_MFD_LEFT_BTNS_SYS
		);

	// Pilot Right
	DefineMfdButtons(
		TEX_LANDER16VC_MFD_DYNAMIC_06,
		AID_PILOT_MFD_RIGHT_BTNS_FN, GRP_LANDER16VC_PILOT_MFD_RIGHT_BTNS_FN, buttonFnRect[MFD_PILOT_RIGHT],
		AID_PILOT_MFD_RIGHT_BTNS_SYS, GRP_LANDER16VC_PILOT_MFD_RIGHT_BTNS_SYS
		);

	// CoPilot Left
	DefineMfdButtons(
		TEX_LANDER16VC_MFD_DYNAMIC_06,
		AID_COPILOT_MFD_LEFT_BTNS_FN, GRP_LANDER16VC_COPILOT_MFD_LEFT_BTNS_FN, buttonFnRect[MFD_COPILOT_LEFT],
		AID_COPILOT_MFD_LEFT_BTNS_SYS, GRP_LANDER16VC_COPILOT_MFD_LEFT_BTNS_SYS
		);

	// CoPilot Right
	DefineMfdButtons(
		TEX_LANDER16VC_MFD_DYNAMIC_06,
		AID_COPILOT_MFD_RIGHT_BTNS_FN, GRP_LANDER16VC_COPILOT_MFD_RIGHT_BTNS_FN, buttonFnRect[MFD_COPILOT_RIGHT],
		AID_COPILOT_MFD_RIGHT_BTNS_SYS, GRP_LANDER16VC_COPILOT_MFD_RIGHT_BTNS_SYS
		);


}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
I don't know why this isn't working:(
Code:
	alt = GetAltitude();
	//level = GetThrusterGroupLevel(THGROUP_HOVER);

	if ((alt <10) && (smoke == 0)) //alt<10 and exhaust deleted
	{
			th_hover[0] = AddExhaustStream(th_hover[0], _V(-3.421, 0, 2.43), &exhaust_hover);
			th_hover[1] = AddExhaustStream(th_hover[1], _V(3.421, 0, 2.43), &exhaust_hover);
			th_hover[2] = AddExhaustStream(th_hover[2], _V(-3.421, 0, -2.136), &exhaust_hover);
			th_hover[3] = AddExhaustStream(th_hover[3], _V(3.421, 0, -2.136), &exhaust_hover);
			smoke = 1;// exhaust added
	};
	if ((alt>10) && (smoke == 1))  //alt>10 and exhausted added
	{
		SetThrusterGroupLevel(THGROUP_HOVER, 0.0);
			DelExhaustStream(th_hover[0]);
			DelExhaustStream(th_hover[1]);
			DelExhaustStream(th_hover[2]);
			DelExhaustStream(th_hover[3]);
			SetThrusterGroupLevel(THGROUP_HOVER, current_thrust_hover_level);
			smoke = 0;//del exhaust streams
		};

So if the alt is less than 10 add exhaust. If alt>10 then delete exhaust streams

If I run this the exhaust shows up , go above 10 no exhaust :)
but if I drop below 10 no exhaust smoke =1 in saved state.

She works in 2016:)
 

GLS

Well-known member
Orbiter Contributor
Addon Developer
Joined
Mar 22, 2008
Messages
5,917
Reaction score
2,920
Points
188
Website
github.com
th_hover[0] = AddExhaustStream(th_hover[0], _V(-3.421, 0, 2.43), &exhaust_hover);

Could it be that you're overwriting the thruster handle? Doesn't a warning show up on compilation?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
No errors on compilation. I first thought it was making more thrust exhaust than it was deleting.
As I understand the exhaust should be made once. Then is above 10 delete 0-3.
 

GLS

Well-known member
Orbiter Contributor
Addon Developer
Joined
Mar 22, 2008
Messages
5,917
Reaction score
2,920
Points
188
Website
github.com
No errors on compilation. I first thought it was making more thrust exhaust than it was deleting.
As I understand the exhaust should be made once. Then is above 10 delete 0-3.

What about warnings? Are you using /W3? (project properties > C/C++ > General > Warning Level)

You should create the thrusters once, and initially assume that either you are above 10m and don't add plumes, or assume you are below and add plumes. And then you have that piece of code that should add, or delete, the plumes when pass 10m. Right now you are mixing thruster handles with exhaust handles... not good.

BTW: in Orbiter2016 use the correct altitude measurement so get altitude above ground and not the mean radius.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I see the issue.
So like this:
Code:
	alt = GetAltitude();
	//level = GetThrusterGroupLevel(THGROUP_HOVER);

	if ((alt <10) && (smoke == 0)) //alt<10 and exhaust deleted
	{
			AddExhaustStream(th_hover[0], _V(-3.421, 0, 2.43), &exhaust_hover);
			AddExhaustStream(th_hover[1], _V(3.421, 0, 2.43), &exhaust_hover);
			AddExhaustStream(th_hover[2], _V(-3.421, 0, -2.136), &exhaust_hover);
			AddExhaustStream(th_hover[3], _V(3.421, 0, -2.136), &exhaust_hover);
			smoke = 1;// exhaust added
	};
	if ((alt>10) && (smoke == 1))  //alt>10 and exhausted added
	{
		SetThrusterGroupLevel(THGROUP_HOVER, 0.0);
			DelExhaustStream(th_hover[0]);
			DelExhaustStream(th_hover[1]);
			DelExhaustStream(th_hover[2]);
			DelExhaustStream(th_hover[3]);
			SetThrusterGroupLevel(THGROUP_HOVER, current_thrust_hover_level);
			smoke = 0;//del exhaust streams
		};
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,616
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
No. Please read the API Reference about the functions before you use them.

Code:
/**
	 * \brief Delete an existing particle stream.
	 * \param ch particle stream handle
	 * \return \e false indicates failure (particle stream not found)
	 * \note If a thruster is deleted (with ref DelThruster), any attached
	 *   particle streams are deleted automatically.
	 * \note A deleted particle stream will no longer emit particles, but
	 *   existing particles persist until they expire.
	 * \sa AddParticleStream, AddExhaustStream, AddReentryStream
	 */
	bool DelExhaustStream (PSTREAM_HANDLE ch) const;

You should store the return value of AddExhaustStream in a new variable and use this PSTREAM_HANDLE for DelExhaustStream then.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
I am away for computer. But basically have a variable to tell if added or not added exhaust stream, right

Then if added and alt is above 10 del exhaust stream?
 
Top