Advanced Question Drawing on a texture in VC

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Well what should it be?

I would suggest PANEL_REDRAW_USER there. Only redraw it, when the propellant level really changes.

And is the third texture dynamic or static now?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks changing to user gets me 30 FPS.:thumbup:

The texture is static
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
The texture is static

static is REAAAAAAALLLLLLY slow when drawing things on it.

You should always make sure the texture gets the "D" flag when you want to draw on it.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. Now I want to display the HUD on a mesh group.

So I added:
Code:
bool ENDURANCE::clbkLoadVC(int id) { // ID is the Preset Camera Position
    //LAPTOPTerminalScreen->HandleLoadVC(id);
    //HABLAPTOPTerminalScreen->HandleLoadVC(id);
    SURFHANDLE tex3 = oapiGetTextureHandle(meshhg_VC, 3);

    mfdController->HandleLoadVC(id);    
    
    viewController->HandleLoadVC(id);
    oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 486, 302), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);
    static VCHUDSPEC hud_pilot = { 2, 38, { 0,-16.023, 7.459 }, 0.338 };
    oapiVCRegisterHUD(&hud_pilot);
    return HandleLoadVC(id);
}
I flagged the mesh group with a 4. I get the HUD. But when I exit it hangs up.

Well now it hangs up with out the hud and ctd on exit.
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Well now it hangs up with out the hud and ctd on exit.

Bad cleanup. This usually happens when you reset variables that Orbiter still uses.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Thanks. Makes sense. How do I fix it though?

Hard to tell, I also get some of those and often need a while of disciplined refactoring before finally finding the variable that was freed in the wrong order.

I have not yet found a single culprit or method that prevents damage. During the destructor operation of your vessel class, you can for example use log output to narrow down the search.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
The one thing I also noticed is this this:pANEL_REDRAW_USER

I would change the thrust but the gauge wouldn't move. I had to switch view and then it would.

I switched to always and getting 28 fps
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
The one thing I also noticed is this this:pANEL_REDRAW_USER

I would change the thrust but the gauge wouldn't move. I had to switch view and then it would.

I switched to always and getting 28 fps

USER means that you have to trigger the redraw when you need it.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
So is there a way to change the font for the hud messages?

Code:
void TESTVC::clbkDrawHUD(int mode, const HUDPAINTSPEC *hps, HDC hDC)
{
	
	// draw the default HUD
	VESSEL2::clbkDrawHUD(mode, hps, hDC);

	// UMmu display messages
	if (UmmuHudDisplayTime>0)
	{
		TextOut(hDC, 5, hps->H / 60 * 15, cUmmuHudDisplay, strlen(cUmmuHudDisplay));
		UmmuHudDisplayTime = max(UmmuHudDisplayTime - oapiGetSimStep(), 0.0);
	}

}

Because of the small width of the hud screen the messages are cut off
the size of the hud screen is .338
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Well I added a text screen and the fps dropped to 6. So I think that will be scraped.
Not sure how to solved the text messages from ummu to be seen on the laptop screen which is our hud.

cpp:

Code:
void TESTVC::SendHudMessage(char const * const msg, ...)
{
	va_list args;

	va_start(args, msg);
	vsprintf(cUmmuHudDisplay, msg, args);
	va_end(args);

	LAPTOPTerminalScreen->SetHeader(cUmmuHudDisplay);
	//HABLAPTOPTerminalScreen->SetHeader(cUmmuHudDisplay);

	UmmuHudDisplayTime = 10.0; // Seconds to keep the mesg on the HUD
}

Code:
 #include "TerminalScreen.h"

using namespace Terminal;

Screen::Screen(OBJHANDLE const hVessel, Terminal::Info const &info) {
	this->hVessel = hVessel;
	this->info = info;
}

void Screen::HandleLoadMesh(MESHHANDLE const mh, UINT const tid)
{
	meshhg = mh;
	texId = tid;
}

void Screen::SetHeader(std::string const newHeader) {
	header = newHeader;
	oapiVCTriggerRedrawArea(-1, info.aid);
}

void Screen::cls() {
	lines.clear();
	cursor.y = lines.size();	
	oapiVCTriggerRedrawArea(-1, info.aid);
}

void Screen::PrintLn(std::string const newLine, COLORREF const newColor) {
	if (lastLine == newLine) return;

	if (lines.size() > info.dim.height) {
		lines.pop_front();
	}
	{
		Line m;
		m.line = newLine;
		m.color = newColor;
		lines.push_back(m);
	}
	lastLine = newLine;

	*(int*)&cursor.y = lines.size();

	oapiVCTriggerRedrawArea(-1, info.aid);
}

bool Screen::HandleLoadVC(UINT const vcId)
{
	SURFHANDLE const surface = oapiGetTextureHandle(meshhg, texId);
	oapiVCRegisterArea(info.aid, info.client_area, PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_NONE, surface);

	return true;
}

bool Screen::HandleRedrawEvent(int const areaId, int const event, SURFHANDLE const surface) {
	if (areaId != this->info.aid) return false;
	Update(surface);
	return true;
}

void Screen::Update(SURFHANDLE const surface) {
	HDC const hDC = oapiGetDC(surface);

	SelectObject(hDC, info.background_brush);
	SetBkMode(hDC, OPAQUE);
	Rectangle(hDC, info.client_area.left, info.client_area.top, info.client_area.right, info.client_area.bottom);

	SelectObject(hDC, info.font);
	SetTextAlign(hDC, TA_LEFT);
	SetTextColor(hDC, info.header_foreground_color);
	SetBkMode(hDC, TRANSPARENT);
	{
		size_t const len = header.length();
		TextOut(hDC, 5, 2, header.c_str(), min(info.dim.width,len));
		if (len > info.dim.width)
			TextOut(hDC, 5, 20, header.c_str()+info.dim.width, len-info.dim.width);
	}

	int line = 0;
	for (std::list<Line>::iterator i = lines.begin(); i != lines.end(); ++i) {
		SetTextColor(hDC, i->color);
		TextOut(hDC, 5, 44 + 19 * line, i->line.data(), i->line.length());
		line++;
	}

	oapiReleaseDC(surface, hDC);
}

Code:
#pragma once

/** Terminal Screen
 *
 * A class to implement text displays screens on Surfaces
 */

#include <OrbiterAPI.h>

#include <string>
#include <list>


namespace Terminal {
	typedef struct {
		size_t	width;
		size_t	height;
	} Dimension;

	typedef struct {
		int	x;
		int	y;
	} Cursor;

	typedef struct  {
		UINT	aid;
		RECT	client_area;
		Dimension dim;
		HBRUSH	background_brush;
		DWORD	header_foreground_color;
		HFONT	font;
	} Info;

	typedef struct {
		std::string line;
		COLORREF color;
	} Line;

	class Screen {
	public:
		Screen(OBJHANDLE const hVessel, Info const &info);

		void SetHeader(std::string const newHeader);
		void cls();
		void PrintLn(std::string const newLine, COLORREF const newColor);
		void HandleLoadMesh(MESHHANDLE const mh, UINT const tid);
		bool HandleLoadVC(UINT const vcId);
		bool HandleRedrawEvent(int const areaId, int const event, SURFHANDLE const surface);

	protected:
		OBJHANDLE hVessel;
		Info info;
		Cursor cursor;
		std::list<Line> lines;

	public:
		inline Info Info() const { return info; }
		inline Cursor Cursor() const { return cursor; }

	private:
		std::string lastLine;
		std::string header;
		
		MESHHANDLE meshhg;
		UINT texId;

		void Update(SURFHANDLE const surface);
	};
}
 

Attachments

  • endurancetextbox.jpg
    endurancetextbox.jpg
    121.5 KB · Views: 11
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks. Now I frustrated. I gutted the whole cpp and h. I kept getting a soft ctd.

Then slowly added things in exited and restarted several times.

no issues:thumbup:

But then I added Ummu back in an get a hang up.

I think it has to do with drawing on the hud, though?



Code:
char *TESTVC::SendHudMessage()
{
	dHudMessageDelay = 15;
	return cUmmuHudDisplay;
}


Code:
void TESTVC::clbkVisualCreated(VISHANDLE vis, int refcount)
{
	
}

// ==============================================================
// Visual destroyed
// ==============================================================
void TESTVC::clbkVisualDestroyed(VISHANDLE vis, int refcount)
{
}

void TESTVC::clbkDrawHUD(int iMode, const HUDPAINTSPEC* pHPS, HDC hdc)
{


	VESSEL2::clbkDrawHUD(iMode, pHPS, hdc);
	//HUD_Text(pHPS, hdc);
	if (dHudMessageDelay>0)
	{
		TextOut(hdc, 5, pHPS->H / 60 * 15, cUmmuHudDisplay, strlen(cUmmuHudDisplay));
		dHudMessageDelay -= oapiGetSimStep();
		if (dHudMessageDelay<0)
			dHudMessageDelay = 0;
	}
}
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Is cUmmuHudDisplay initialized and ALWAYS properly terminated?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Thanks.

Yes on initialize
Code:
	// The HUD display method variables, see PDF doc
	cUmmuHudDisplay[0] = 0;	// Initialisation of UMmu hud char variable
	dHudMessageDelay = 0;	// Initialisation of UMmu delay variable
	strcpy(SendHudMessage(), "Welcome aboard ! E=EVA 1,2=select UMmu A=Open/Close airlock S=info M=add crew");

Not sure on the proper termination.
h:
Code:
	char cUmmuHudDisplay[255];			// UMmu hud char variable
	double dHudMessageDelay;			// UMmu hud display delay
	char *SendHudMessage(void);
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Wait a minute... do you use VESSEL2 or VESSEL3 as base?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
vessel 2. I can change to 3 if need be

No, is OK. drawing with HDC would not work if you are using a VESSEL3, that is all. Possibly it would also not work with a rendering client if you use VESSEL2.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
I feel as if I am missing something but I have double check against the uumu code and nothing appears to be different
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,637
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I feel as if I am missing something but I have double check against the uumu code and nothing appears to be different

It is not UMMU, because UMMU usually works for everybody else. It is how you use it.

Can't you use a debugger for finding where it crashes?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Yes It has been a while. But it crashes on exit. So when I press Ctrl Q it exits but hangs up.
 
Top