Advanced Question Drawing on a texture in VC

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
I also tried taking the interior mesh and making it a vc rather than the whole vessel mesh. But to no avail. A tester gets 19 fps. But that seems low also.

All that is left is the view(Lisias wrote code for VC stations and mfds). This allowed the camera to be rotate to give the user a correct view if stationed in a module that would be upside down or 90 degrees from the the exterior.
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Well then maybe I don't need to any thing. But 9 fps is low. Well I need to figure out the crash when exiting.
 

grid4dante

New member
Joined
Mar 22, 2011
Messages
34
Reaction score
0
Points
0
Location
Midwest City
The 19 fps I've been getting regularly when testing the .dll version has been while using D3D9. Standard client I get gives me around 10 fps internal, 16 fps external. This is on an Intel i5-4440 3.1 GHz processor, 12 GB of ram, and a 2 GB Nvidia 960 graphics card.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
You shouldn't accept a low frame rate until you understand where the frames are lost in your code. Orbiter depends on decent framerates to perform properly, so profiling the code is essential (although you definitely should fix the bugs first).

If you get decent framerates with an equivalent SC3 implementation, then there is absolutely no way why a native DLL should perform worse. After all, SC3 is a DLL as well, using the same API. And since your own DLL gives you more freedom, you might even be able to squeeze more performance out.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Either use a profiling tool, or alternatively (I don't know if the free versions of VS contain a profiler), insert your own time checks into any suspect code sections.
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
All that is left is the view(Lisias wrote code for VC stations and mfds).

How about asking the original author of those code sections to take a look and comment on the performance?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
How about asking the original author of those code sections to take a look and comment on the performance?

Ok. He has been involved.

What do you mean try with a DG scenario?
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
What do you mean try with a DG scenario?

Test your pc performance with standard Deltaglider.

My pc have 150 fps in external view,and 56-60 fps in virtual cockpit mode,"Cape Canaveral" scenario,no D3D9.

If your ship has already low fps in SC3 should reduce the mesh first,in SC3 you have only 2 mfd's and hud to work.

Not sure about the soft exit. In D3d9 I get 54 fps. I regular graphics client 12. But the sc3 is 45.

45 fps only SC 3 are very low.
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
Ok on my machine the dg scenario. 45 ext, 44 vc and internal

So I just added the vc mesh to my simple vc and on external 33fps but switch to vc 10. i made a cfg with just the vc mesh and it was ok.

So what do I need to do to fix it.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
So what do I need to do to fix it.

Fight waste = redundant executions.

Does SendHudMessage for example draw a text somewhere everytime you call it?

Or: Do you paint something in the VC in every frame of orbiter?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
On my simple vc I don't have the send hud message.

Code:
void TESTVC::clbkPostStep(double simt, double simdt, double mjd)
{

	

	if (GetNavmodeState(1) == true){
		SetAnimation(anim_killrot, 1);
	}
	else{
		SetAnimation(anim_killrot, 0);
	}

	if (GetNavmodeState(2) == true){
		SetAnimation(anim_horlevel, 1);
	}
	else{
		SetAnimation(anim_horlevel, 0);
	}
	if (GetNavmodeState(3) == true){
		SetAnimation(anim_prograde, 1);
	}
	else{
		SetAnimation(anim_prograde, 0);
	}
	if (GetNavmodeState(4) == true){
		SetAnimation(anim_retrograde, 1);
	}
	else{
		SetAnimation(anim_retrograde, 0);
	}
	if (GetNavmodeState(5) == true){
		SetAnimation(anim_NMLplus, 1);
	}
	else{
		SetAnimation(anim_NMLplus, 0);
	}
	if (GetNavmodeState(6) == true){
		SetAnimation(anim_nmlminus, 1);
	}
	else{
		SetAnimation(anim_nmlminus, 0);
	}
	if (GetNavmodeState(7) == true){
		SetAnimation(anim_althold, 1);
	}
	else{
		SetAnimation(anim_althold, 0);
	}
	if (GetAttitudeMode()==0){
		SetAnimation(anim_rcsoff, 1);
	}
	else{
		SetAnimation(anim_rcsoff, 0);
	}
	if (GetAttitudeMode() == 1){
		SetAnimation(anim_rcsrot, 1);
	}
	else{
		SetAnimation(anim_rcsrot, 0);
	}
	if (GetAttitudeMode() == 2){
		SetAnimation(anim_rcslin, 1);
	}
	else{
		SetAnimation(anim_rcslin, 0);
	}
}
Code:
void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);
	

	

	
	double level = GetThrusterLevel(th_main[0]);
	double m = GetPropellantMass(tank); 

		

		SelectObject(hDC, g_Param.hBrush[5]);//green box
		Rectangle(hDC, 114, 34, (int)((114 - m / FUELMASS)*3.2), 75);

		Rectangle(hDC, 110, 110, (110 + level * (346 - 114)), 160);



		

		oapiReleaseDC(surf, hDC);


}
the only other painting is for the mfd?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
So what do I need to do to fix it.

Bisecting comes to mind. If you have a good point in your version history (some old where the FPS where acceptable) and a bad one (the latest, where FPS are down), take one version that is in the middle of the ancestry-chain between good and bad. Test this version. Mark if it is good or bad, then repeat the first step. This way you could narrow down the problem to one step, e.g. some modification of VC code.

From there, you can try to disable the modification and check if it is the culprit.

You've written that the original author of the code section has been involved. What does that mean? Did he already check the code for potential performance problems and said that it is alright, or did you just start to contact him? If it is the former - and given all the things you've tried - I think your best bet is backtracking as described above. Otherwise I'd wait for a response.
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
To get the same performance of SC3 you have to have the same use of the VC, 2mfd's and 1 hud.
Out of curiosity I tested a complete DG, with VC, in SC3 was 97 fps, in dll 56 fps , Mesh the DG is about 12,000 polygons, the most VC 11000 polygons.

Your ship has a much more polygons. Usually it is recommended not to go too far beyond the 10,000 polygons to not affect too much on fps.

in Orbitersdk/Doc see 3DModel pdf.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
ENDURAQNCEVC2_zpsdtsskxtt.jpg

So what I did is took the simple vc bar code and used the endurance vc mesh. I get 10 fps. So maybe it is the mfd code. I guess if I remove that and fps go up then we know it is that.

here is the mfd code:
Code:
    oapiVCTriggerRedrawArea(-1, AID_PILOT_MFD_LEFT_BTNS_FN);
    break;
    case MFD_PILOT_RIGHT:
    oapiVCTriggerRedrawArea(-1, AID_PILOT_MFD_RIGHT_BTNS_FN);
    break;
    case MFD_COPILOT_LEFT:
    oapiVCTriggerRedrawArea(-1, AID_COPILOT_MFD_LEFT_BTNS_FN);
    break;
    case MFD_COPILOT_RIGHT:
    oapiVCTriggerRedrawArea(-1, AID_COPILOT_MFD_RIGHT_BTNS_FN);
    break;
    }
    }
    void ClassicMfd::DefineMfds()
    {
    DefineMfd(MFD_PILOT_LEFT, GRP_ENDURANCE22VC_PILOT_MFD_LEFT_SCREEN);
    DefineMfd(MFD_PILOT_RIGHT, GRP_ENDURANCE22VC_PILOT_MFD_RIGHT_SCREEN);
    DefineMfd(MFD_COPILOT_LEFT, GRP_ENDURANCE22VC_COPILOT_MFD_LEFT_SCREEN);
    DefineMfd(MFD_COPILOT_RIGHT, GRP_ENDURANCE22VC_COPILOT_MFD_RIGHT_SCREEN);
    }
    void ClassicMfd::DefineMfd(UINT const mfdId, UINT const screenGroupId)
    {
    VCMFDSPEC mfds;
    mfds.nmesh = meshi_VC;
    mfds.ngroup = screenGroupId;
    oapiVCRegisterMFD(mfdId, &mfds);
    }
    void ClassicMfd::DefineMfdsButtons()
    {
    // Pilot Left
    DefineMfdButtons(
    TEX_ENDURANCE22VC_MFD_DYNAMIC_05,
    AID_PILOT_MFD_LEFT_BTNS_FN, 
    GRP_ENDURANCE22VC_PILOT_MFD_LEFT_BTNS_FN, buttonFnRect[MFD_PILOT_LEFT],
    AID_PILOT_MFD_LEFT_BTNS_SYS, 
    GRP_ENDURANCE22VC_PILOT_MFD_LEFT_BTNS_SYS
    );
    // Pilot Right
    DefineMfdButtons(
    TEX_ENDURANCE22VC_MFD_DYNAMIC_05,
    AID_PILOT_MFD_RIGHT_BTNS_FN, 
    GRP_ENDURANCE22VC_PILOT_MFD_RIGHT_BTNS_FN, buttonFnRect[MFD_PILOT_RIGHT],
    AID_PILOT_MFD_RIGHT_BTNS_SYS, 
    GRP_ENDURANCE22VC_PILOT_MFD_RIGHT_BTNS_SYS
    );
    // CoPilot Left
    DefineMfdButtons(
    TEX_ENDURANCE22VC_MFD_DYNAMIC_05,
    AID_COPILOT_MFD_LEFT_BTNS_FN, 
    GRP_ENDURANCE22VC_COPILOT_MFD_LEFT_BTNS_FN, buttonFnRect[MFD_COPILOT_LEFT],
    AID_COPILOT_MFD_LEFT_BTNS_SYS, 
    GRP_ENDURANCE22VC_COPILOT_MFD_LEFT_BTNS_SYS
    );
    // CoPilot Right
    DefineMfdButtons(
    TEX_ENDURANCE22VC_MFD_DYNAMIC_05,
    AID_COPILOT_MFD_RIGHT_BTNS_FN, 
    GRP_ENDURANCE22VC_COPILOT_MFD_RIGHT_BTNS_FN, buttonFnRect[MFD_COPILOT_RIGHT],
    AID_COPILOT_MFD_RIGHT_BTNS_SYS, 
    GRP_ENDURANCE22VC_COPILOT_MFD_RIGHT_BTNS_SYS
    );
    }
    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);
    }
    void ClassicMfd::DefineStaticClickArea(MESHGROUP const * const gr, int const id,
    bool const rect, const VECTOR3& revert, const VECTOR3& maxShift)
    {
    float minX, maxX, minY, maxY, minZ, maxZ, x, y, z;
    minX = minY = minZ = 1000.0f;
    maxX = maxY = maxZ = -1000.0f;
    for (DWORD i = 0; i < gr->nVtx; i++) {
    x = gr->Vtx[i].x;
    y = gr->Vtx[i].y;
    z = gr->Vtx[i].z;
    if (x < minX) minX = x;
    if (y < minY) minY = y;
    if (z < minZ) minZ = z;
    if (x > maxX) maxX = x + (float)maxShift.x;
    if (y > maxY) maxY = y + (float)maxShift.y;
    if (z > maxZ) maxZ = z + (float)maxShift.z;
    }
    if (rect) {
    VECTOR3 p1 = _V(revert.x > 0 ? maxX : minX, revert.y > 0 ? minY : 
    maxY, revert.z > 0 ? minZ : maxZ);
    VECTOR3 p2 = _V(revert.x > 0 ? minX : maxX, revert.y > 0 ? minY : 
    maxY, revert.z > 0 ? minZ : maxZ);
    VECTOR3 p3 = _V(revert.x > 0 ? maxX : minX, revert.y > 0 ? maxY : 
    minY, revert.z > 0 ? maxZ : minZ);
    VECTOR3 p4 = _V(revert.x > 0 ? minX : maxX, revert.y > 0 ? maxY : 
    minY, revert.z > 0 ? maxZ : minZ);
    oapiVCSetAreaClickmode_Quadrilateral(id, p1, p2, p3, p4);
    }
    else {
    double distX = Distance(minX, maxX);
    double distY = Distance(minY, maxY);
    double distZ = Distance(minZ, maxZ);
    VECTOR3 center = _V(minX + distX / 2.0f, minY + distY / 2.0f, minZ +
    distZ / 2.0f);
    double rad = max(distX, max(distY, distZ)) / 2.0;
    oapiVCSetAreaClickmode_Spherical(id, center, rad);
    }
    }
h:
Code:
    #pragma once
    #include <OrbiterAPI.h>
    #include <VesselAPI.h>
    #include "AreaIds.h"
    #define MFD_PILOT_LEFT (MFD_LEFT)
    #define MFD_PILOT_RIGHT (MFD_RIGHT)
    #define MFD_COPILOT_LEFT (MFD_USER1)
    #define MFD_COPILOT_RIGHT (MFD_USER2)
    typedef struct structDIMENSION
    {
        int width;
        int height;
        int marginWidth;
        int marginHeight;
    }  DIMENSION;
    inline DIMENSION _D (int width, int height, int marginWidth, int marginHeight)
    {
    DIMENSION d = { width, height, marginWidth, marginHeight}; return d;
    }
    class ClassicMfd {
    public:
    ClassicMfd::ClassicMfd(int const mfdQtd, 
    HFONT const labelFont, DWORD const labelColor, HBRUSH const 
    buttonBrush, HBRUSH const buttonLabelBrush, 
    DIMENSION const * const buttonFnDim, RECT const buttonFnRect[],
    DIMENSION const * const buttonSysDim, RECT const buttonSysRect[]);
    ~ClassicMfd();
    void HandleSetClassCaps();
    void HandleLoadMesh(UINT const meshi, MESHHANDLE const meshhg);
    bool HandleLoadVC(UINT const vcId);
    bool HandleRedrawEvent(int const id, int const event, SURFHANDLE const 
    surf);
    bool HandleMouseEvent(int const id, int const event, VECTOR3 const &p);
    void HandleMFDMode (int const mfd, int const mode);
    private:
    HFONT const labelFont;
    HBRUSH const buttonBrush, buttonLabelBrush;
    DWORD const labelColor;
    RECT const * const buttonFnRect;
    DIMENSION const * const buttonFnDim;
    RECT const * const buttonSysRect;
    DIMENSION const * const buttonSysDim;
    int const mfdQtd;
    MESHHANDLE meshhg_VC;
    UINT meshi_VC;
    UINT vcId;
    void DefineMfds();
    void DefineMfd(UINT const mfdId, UINT const screenGroupId);
    void DefineMfdsButtons();
    void ClassicMfd::DefineMfdButtons (
    UINT const texId,
    UINT const fuctionAreaId, UINT const functionGroupId, RECT 
    const functionRect,
    UINT const sysAreaId, UINT const sysGroupId
    );
    void DefineStaticClickArea(MESHGROUP const * const gr, int const id, bool 
    const rect = true, const VECTOR3& revert = _V(0, 0, 0), const VECTOR3& maxShift 
    = _V(0, 0, 0));
    void RedrawMFDButtons(SURFHANDLE const surf, int const mfd);
    bool ProcessMfdFnButton (int const mfd, int const event, VECTOR3 const 
    &p);
    bool ProcessMfdSysButton (int const mfd, int const event, VECTOR3 const 
    &p);
    inline double Distance(double const d1, double const d2) {
    return max(d1, d2) - min(d1, d2);
    }
    };


---------- Post added at 03:23 PM ---------- Previous post was at 07:35 AM ----------

At a loss still get around 10 fps. Could it be the mesh?

This all the code I have: cpp
Code:
// ==============================================================
//                 ORBITER MODULE: TESTVC
//              Copyright (C) 2015 John Gattis
//                   All rights reserved
//
// TESTVC.cpp
// Control module for TESTVC vessel class
//
// Notes:
// ==============================================================

#include <stdio.h>
#include <fstream>

#include "resource.h"

#include "orbitersdk.h"

#include "meshres_endurance22vc.h"

#include "TESTVC.h"

//#include "TARSMESH.h"

#define LOADBMP(id) (LoadBitmap (g_Param.hDLL, MAKEINTRESOURCE (id)))

// ==============================================================
// Global parameters
// ==============================================================





TESTVC::TESTVC(OBJHANDLE hObj, int fmodel)
: VESSEL2(hObj, fmodel)
{


	DefineAnimations();
}

// --------------------------------------------------------------
// Destructor
// --------------------------------------------------------------
TESTVC::~TESTVC() {
	//delete viewController;
	//delete mfdController;


}



void TESTVC::clbkPostCreation(void)
{


}

void TESTVC::clbkSetClassCaps(FILEHANDLE cfg)
{
	// physical specs
	SetSize(5);
	SetEmptyMass(455.7);
	SetCW(0.3, 0.3, 0.6, 0.9);
	SetWingAspect(1.7);
	SetWingEffectiveness(14.1);
	SetCrossSections(_V(444.48,430.21,788.72));
	SetRotDrag(_V(3.5, 3.5, 3.5));
	if (GetFlightModel() >= 1) {
		SetPitchMomentScale(1e-4);
		SetBankMomentScale(1e-4);
	}
	SetPMI(_V(200.48, 205.14, 378.46));
	SetTrimScale(0.08);
	SetCameraOffset(_V(0, -16.29, 6.5));
	SetTouchdownPoints(_V(0, -24.5, 5.7), _V(-3.448, -24.5, -5.0), _V(3.448, -24.5, -5.0));;



	// visual specs
	SetMeshVisibilityMode(meshi_Vessel = AddMesh(meshhg_Vessel = oapiLoadMeshGlobal("INTERSTELLAR\\VESSEL\\ENDURANCE\\endurance12" )), MESHVIS_ALWAYS | MESHVIS_EXTPASS);
	//SetMeshVisibilityMode(meshi_VC1 = AddMesh(meshhg_Vessel), MESHVIS_VC);
	SetMeshVisibilityMode(meshi_VC = AddMesh(meshhg_VC = oapiLoadMeshGlobal("INTERSTELLAR\\VESSEL\\ENDURANCE\\endurance22vc")), MESHVIS_VC);

	//LAPTOPTerminalScreen->HandleLoadMesh(meshhg_VC, TEX_TESTVC19VC_SCREEN);
//	HABLAPTOPTerminalScreen->HandleLoadMesh(meshhg_VC, TEX_TESTVC19VC_SCREEN);

	//mfdController->HandleLoadMesh(meshi_VC, meshhg_VC);

	

	

	//viewController->Commit();	// Commits all changes, so the internal structures can be build.
								// It would too expensive to rebuid them on every change!
								// The Commit can be issued ONLY when ALL meshes has been loaded and all Components and Widgets has beeen Registered.
								// Theorically, you can issue more than one commit, but this doesn't makes sense unless you do Load on Demand on meshes.

	//CreateControlSurfaces();

	// propellant resources
	 tank = CreatePropellantResource(FUELMASS);

	th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, 1), MAXMAINTH, tank, ISP);
	thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);

}

void TESTVC::clbkPostStep(double simt, double simdt, double mjd)
{

	

	if (GetNavmodeState(1) == true){
		SetAnimation(anim_killrot, 1);
	}
	else{
		SetAnimation(anim_killrot, 0);
	}

	if (GetNavmodeState(2) == true){
		SetAnimation(anim_horlevel, 1);
	}
	else{
		SetAnimation(anim_horlevel, 0);
	}
	if (GetNavmodeState(3) == true){
		SetAnimation(anim_prograde, 1);
	}
	else{
		SetAnimation(anim_prograde, 0);
	}
	if (GetNavmodeState(4) == true){
		SetAnimation(anim_retrograde, 1);
	}
	else{
		SetAnimation(anim_retrograde, 0);
	}
	if (GetNavmodeState(5) == true){
		SetAnimation(anim_NMLplus, 1);
	}
	else{
		SetAnimation(anim_NMLplus, 0);
	}
	if (GetNavmodeState(6) == true){
		SetAnimation(anim_nmlminus, 1);
	}
	else{
		SetAnimation(anim_nmlminus, 0);
	}
	if (GetNavmodeState(7) == true){
		SetAnimation(anim_althold, 1);
	}
	else{
		SetAnimation(anim_althold, 0);
	}
	if (GetAttitudeMode()==0){
		SetAnimation(anim_rcsoff, 1);
	}
	else{
		SetAnimation(anim_rcsoff, 0);
	}
	if (GetAttitudeMode() == 1){
		SetAnimation(anim_rcsrot, 1);
	}
	else{
		SetAnimation(anim_rcsrot, 0);
	}
	if (GetAttitudeMode() == 2){
		SetAnimation(anim_rcslin, 1);
	}
	else{
		SetAnimation(anim_rcslin, 0);
	}
}




void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);
	

	

	
	double level = GetThrusterLevel(th_main[0]);
	double m = GetPropellantMass(tank); 

		

		SelectObject(hDC, g_Param.hBrush[5]);//green box
		//Rectangle(hDC, 114, 34, (int)((114 - m / FUELMASS)*3.2), 75);

		//Rectangle(hDC, 110, 110, (110 + level * (346 - 114)), 160);



		

		oapiReleaseDC(surf, hDC);


}






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

	
	return 0;
}

// ====================================================================
// clbkVisualCreated used to display UMMU initialisation message 
// because oapiDebugString() doesn't work in clbkSetClassCap
// ====================================================================
void TESTVC::clbkVisualCreated(VISHANDLE vis, int refcount)
{
	
}

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

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

	
}

void TESTVC::clbkSaveState(FILEHANDLE scn)
{
	char cbuf[256];

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


	// UMmu, this will save all our members of crew in scenario
	// as airlock state depend of your ship (you may have a real animated airlock)
	// it's your responsabilites to save and reload UMmu's airlock state.
}

void TESTVC::clbkLoadStateEx(FILEHANDLE scn, void *status)
{
	char *line;
	while (oapiReadScenario_nextline(scn, line))
	{
		// UMMU, Load all saved member from scenario. 
		// Return TRUE when a "UMMUCREW" line is encountered 
		// FALSE when it must pass this line to you or default parser

		
			// ORBITER, unrecognised option - pass to Orbiter's generic parser
			ParseScenarioLineEx(line, status);
	}


	// as airlock state depend of your ship (you may have a real animated airlock)
	// it's your responsabilites to save and reload UMmu airlock state and set it accordingly
	// to your airlock. IE: call here "SetAirlockDoorState" TRUE of FALSE depend
	// of your animated airlock
}



bool TESTVC::clbkLoadGenericCockpit() {
	//viewController->HandleLoadGC();
	return true;
}

bool TESTVC::clbkLoadVC(int id) { // ID is the Preset Camera Position
	SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC, 3);

	
	
	//mfdController->HandleLoadVC(id);	
	oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 486, 302), PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);

	return HandleLoadVC(id);
}

bool TESTVC::HandleLoadVC(UINT const id)
{
	
	

	return true;
}

bool TESTVC::clbkVCMouseEvent(int id, int event, VECTOR3 &p)
{
	bool result = false;
	//result = result || mfdController->HandleMouseEvent(id, event, p);
	result = result || VCMouseEvent(id, event, p);
	return result;
}

bool TESTVC::VCMouseEvent(int const id, int const event, VECTOR3& const p)
{
	
	

	return false; // We must return false, as we didn't processed the event!
}



bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf) {
	bool result = false;
//	result = result || mfdController->HandleRedrawEvent(id, event, surf);


	result = result || VCRedrawEvent(id, event, surf);
	

	{

		switch (id) {
		case AID_FUELSTATUS:
			RedrawPanel_Fuelstatus(surf, id - AID_FUELSTATUS);
			return true;
		}
	//	return false;

		

	}
	return result;
}

bool TESTVC::VCRedrawEvent(int const id, int const event, SURFHANDLE const surf) {
	return false;
}

void TESTVC::clbkMFDMode (int mfd, int mode)
{
	//mfdController->HandleMFDMode(mfd, mode);
}

void TESTVC::DefineAnimations()
{
	static UINT NAVMODE_01 = 29;
	static MGROUP_TRANSLATE killrot(1, &NAVMODE_01, 1, _V(0, 0.0, -.001));
	anim_killrot = CreateAnimation(0);
	AddAnimationComponent(anim_killrot, 0.0f, 1.0f, &killrot);

	static UINT NAVMODE_02 = 28;
	static MGROUP_TRANSLATE H_level(1, &NAVMODE_02, 1, _V(0, 0.0, -.002));
	anim_horlevel = CreateAnimation(0);
	AddAnimationComponent(anim_horlevel, 0.0f, 1.0f, &H_level);

	static UINT NAVMODE_03 = 27;
	static MGROUP_TRANSLATE prograde(1, &NAVMODE_03, 1, _V(0, 0.0, -.001));
	anim_prograde = CreateAnimation(0);
	AddAnimationComponent(anim_prograde, 0.0f, 1.0f, &prograde);

	static UINT NAVMODE_04 = 26;
	static MGROUP_TRANSLATE retrograde(1, &NAVMODE_04, 1, _V(0, 0.0, -.001));
	anim_retrograde = CreateAnimation(0);
	AddAnimationComponent(anim_retrograde, 0.0f, 1.0f, &retrograde);

	static UINT NAVMODE_05 = 25;
	static MGROUP_TRANSLATE NMLPLUS(1, &NAVMODE_05, 1, _V(0, 0.0, -.001));
	anim_NMLplus = CreateAnimation(0);
	AddAnimationComponent(anim_NMLplus, 0.0f, 1.0f, &NMLPLUS);

	static UINT NAVMODE_06 = 24;
	static MGROUP_TRANSLATE NMLMINUS(1, &NAVMODE_06, 1, _V(0, 0.0, -.002));
	anim_nmlminus = CreateAnimation(0);
	AddAnimationComponent(anim_nmlminus, 0.0f, 1.0f, &NMLMINUS);

	static UINT NAVMODE_07 = 30;
	static MGROUP_TRANSLATE ALTHOLD(1, &NAVMODE_07, 1, _V(0, 0.0, -.002));
	anim_althold = CreateAnimation(0);
	AddAnimationComponent(anim_althold, 0.0f, 1.0f, &ALTHOLD);

	static UINT RCS_OFF = 36;
	static MGROUP_TRANSLATE RCS_off(1, &RCS_OFF, 1, _V(0, 0.0, -.002));
	anim_rcsoff = CreateAnimation(0);
	AddAnimationComponent(anim_rcsoff, 0.0f, 1.0f, &RCS_off);

	static UINT RCS_ROT1 = 35;
	static MGROUP_TRANSLATE RCS_rot(1, &RCS_ROT1, 1, _V(0, 0.0, -.002));
	anim_rcsrot = CreateAnimation(0);
	AddAnimationComponent(anim_rcsrot, 0.0f, 1.0f, &RCS_rot);

	static UINT RCS_LIN1 = 34;
	static MGROUP_TRANSLATE RCS_lin(1, &RCS_LIN1, 1, _V(0, 0.0, -.002));
	anim_rcslin = CreateAnimation(0);
	AddAnimationComponent(anim_rcslin, 0.0f, 1.0f, &RCS_lin);

}

h:
Code:
// ==============================================================
//                 ORBITER MODULE: LSENDURANCE
//              Copyright (C) 2015 John Gattis
//                   All rights reserved
//
// LSENDURANCE.cpp
// Control module for LSENDURANCE vessel class
//
// Notes:
// ==============================================================

#include "orbitersdk.h"
#include "UMmuSDK.h"

#include "TerminalScreen.h"
#include "Station.h"

#include "AreaIds.h"
#include "ClassicMfd.h"

#define AID_FUELSTATUS         115
#define AID_MFDCONTROLLER          116

const double FUELMASS = 10400.0;
const double ISP = 4e6;//4e6
const double MAXMAINTH = 12503443;//4.0e5

const double MAXRETROTH = 6.8e4;
const double MAXHOVERTH = 2.8e5;
const double MAXRCSTH = 2.5e3;
const double fakethrust = 0;
const double EMPTY_MASS = 11000.0;  // standard configuration


// 2D instrument panel parameters

const DWORD PANEL2D_WIDTH = 1280;  // panel width [pixel]
const DWORD PANEL2D_TEXW = 2048;  // texture width
const DWORD PANEL2D_TEXH = 1024;  // texture height

typedef struct {
	HINSTANCE hDLL;
	HFONT hFont[3];
	DWORD col[5];
	HBRUSH hBrush[3];
	HPEN hPen[2];
} GDIParams;

extern GDIParams g_Param;


// dllmain Prototypes


class TESTVC : public VESSEL2 {
public:
	TESTVC(OBJHANDLE hVessel, int flightmodel);
	~TESTVC();

	void clbkPostCreation(void);
	void clbkSaveState(FILEHANDLE scn);
	void clbkLoadStateEx(FILEHANDLE scn, void *status);
	void HUD_Text(const HUDPAINTSPEC* pHPS, HDC hdc);
	void clbkDrawHUD(int mode, const HUDPAINTSPEC *hps, HDC hDC);
	//void clbkFocusChanged(bool getfocus, OBJHANDLE hNewVessel, OBJHANDLE hOldVessel);

	void clbkSetClassCaps(FILEHANDLE cfg);
	int clbkConsumeBufferedKey(DWORD key, bool down, char *kstate);
	void clbkVisualCreated(VISHANDLE vis, int refcount);

	void clbkVisualDestroyed(VISHANDLE vis, int refcount);
	void clbkPostStep(double simtt, double simdt, double mjd);
	void DefineAnimations();
	void RedrawPanel_Fuelstatus(SURFHANDLE surf, int part);
	void UpdateCentralStatusMonitor();

	void clbkMFDMode (int mfd, int mode);
	bool clbkLoadVC(int id);
	bool clbkLoadGenericCockpit();
	bool clbkVCRedrawEvent(int id, int event, SURFHANDLE surf);
	bool clbkVCMouseEvent(int id, int event, VECTOR3 &p);

	void InitPanel(int panel);


private:
#define CTR_SURFACE_SIZE 6
//#define	TARS_TEX_SCREEN 15
	CTRLSURFHANDLE control_surfaces[CTR_SURFACE_SIZE];
//	void CreateControlSurfaces();;

//	MGROUP_TRANSFORM *VCMFD_anim[4];
//	ANIMATIONCOMPONENT_HANDLE MFD_anim[4];
//	ANIMATIONCOMPONENT_HANDLE rotate_parent_front, rotate_parent_rear; // Parents where VC animatinos are hooked.
//	ANIMATIONCOMPONENT_HANDLE elevate_parent_front; // Parents where VC animatinos are hooked.
	
	
	

//	SURFHANDLE srf[nsurf];          // handles for panel bitmaps

//	const int nsurf = 12; // number of bitmap handles


	bool HandleLoadVC(UINT const id);

	//typedef struct {
	//	HINSTANCE hDLL;
	//	HFONT hFont[1];
	//	HPEN hPen[2];
	//	HBRUSH hBrush[1];
	//} GDIParams;
	PROPELLANT_HANDLE tank;

	MESHHANDLE meshhg_Vessel,meshhg1_Vessel, meshhg_VC, meshhg_CREW[5];
	UINT meshi_Vessel, meshi_VC, meshi_VC1, meshi_CREW[5];

	VCMFDSPEC mfds_pilot_left, mfds_pilot_right;
	VCMFDSPEC mfds_copilot_left, mfds_copilot_right;

	//ClassicMfd* mfdController;
private:
	THRUSTER_HANDLE th_main[1], th_retro[1], th_rcs[40], th_group[4], th_hover[1];
	THRUSTER_HANDLE thg_main, thg_retro, thg_hover;

	// Chairs pivots for rotating.

	bool VCRedrawEvent(int const id, int const event, SURFHANDLE const surf);
	bool VCMouseEvent(int const id, int const event, VECTOR3& const p);
	UINT anim_killrot, anim_horlevel, anim_prograde, anim_retrograde, anim_NMLplus, anim_nmlminus, anim_althold, anim_rcslin, anim_rcsrot, anim_rcsoff ;

};

Code:
// dllmain.cpp : Defines the entry point for the DLL application.
#define ORBITER_MODULE

#include "OrbiterAPI.h"
#include "VesselAPI.h"
#include "TESTVC.h"

GDIParams g_Param;

DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel, int flightmodel)
{
	return new TESTVC(hvessel, flightmodel);
}

DLLCLBK void ovcExit(VESSEL *vessel)
{
	if (vessel) delete (TESTVC*)vessel;
}



// --------------------------------------------------------------
// Module initialisation
// --------------------------------------------------------------




DLLCLBK void InitModule(HINSTANCE hModule)
{
	g_Param.hDLL = hModule;

	// allocate GDI resources
	g_Param.hFont[0] = CreateFont(-12, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
	g_Param.hFont[1] = CreateFont(-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
	g_Param.hFont[2] = CreateFont(-20, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Lucida Console");
	g_Param.col[0] = RGB(255, 255, 255); // white
	g_Param.col[1] = RGB(196, 196, 196); // gray
	g_Param.col[2] = RGB(0, 0, 0);		 // black
	g_Param.col[3] = RGB(25, 25, 25);	 // dark gray
	g_Param.col[4] = RGB(196, 255, 196);
	g_Param.col[5] = RGB(224, 224, 224);
	g_Param.hBrush[0] = CreateSolidBrush(g_Param.col[2]);
	g_Param.hBrush[1] = CreateSolidBrush(g_Param.col[0]);
	g_Param.hBrush[2] = CreateSolidBrush(g_Param.col[2]);
	g_Param.hPen[0] = CreatePen(PS_SOLID, 1, RGB(224, 224, 224));
	g_Param.hPen[1] = CreatePen(PS_SOLID, 3, RGB(164, 164, 164));
}


mesh vc info 39 grps, 388 vertices, 198 triangles , 8 materials, 7 textures
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
this should not be in the CPP?

Code:
// dllmain.cpp : Defines the entry point for the DLL application.
#define ORBITER_MODULE

#include "OrbiterAPI.h"
#include "VesselAPI.h"
#include "TESTVC.h"

GDIParams g_Param;

DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel, int flightmodel)
{
	return new TESTVC(hvessel, flightmodel);
}

DLLCLBK void ovcExit(VESSEL *vessel)
{
	if (vessel) delete (TESTVC*)vessel;
}



// --------------------------------------------------------------
// Module initialisation
// --------------------------------------------------------------




DLLCLBK void InitModule(HINSTANCE hModule)
{
	g_Param.hDLL = hModule;

	// allocate GDI resources
	g_Param.hFont[0] = CreateFont(-12, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
	g_Param.hFont[1] = CreateFont(-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
	g_Param.hFont[2] = CreateFont(-20, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Lucida Console");
	g_Param.col[0] = RGB(255, 255, 255); // white
	g_Param.col[1] = RGB(196, 196, 196); // gray
	g_Param.col[2] = RGB(0, 0, 0);		 // black
	g_Param.col[3] = RGB(25, 25, 25);	 // dark gray
	g_Param.col[4] = RGB(196, 255, 196);
	g_Param.col[5] = RGB(224, 224, 224);
	g_Param.hBrush[0] = CreateSolidBrush(g_Param.col[2]);
	g_Param.hBrush[1] = CreateSolidBrush(g_Param.col[0]);
	g_Param.hBrush[2] = CreateSolidBrush(g_Param.col[2]);
	g_Param.hPen[0] = CreatePen(PS_SOLID, 1, RGB(224, 224, 224));
	g_Param.hPen[1] = CreatePen(PS_SOLID, 3, RGB(164, 164, 164));
}


mesh vc info 39 grps, 388 vertices, 198 triangles , 8 materials, 7 textures
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,627
Reaction score
2,345
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 486, 302), PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);


That is a possible source for slowness.

Also what does the mfdcontroller do?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,728
Reaction score
2,692
Points
203
Location
Dallas, TX
oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 486, 302), PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);


That is a possible source for slowness.

Also what does the mfdcontroller do?

Well what should it be?

The mfd controller controled the mfd buttons and screen. I posted the code earlier. But i removed it from the last.dll


On this: in is in a seperate .cpp named dllmain_testvc.cpp
Code:
// dllmain.cpp : Defines the entry point for the DLL application.
#define ORBITER_MODULE

#include "OrbiterAPI.h"
#include "VesselAPI.h"
#include "TESTVC.h"

GDIParams g_Param;

DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel, int flightmodel)
{
    return new TESTVC(hvessel, flightmodel);
}

DLLCLBK void ovcExit(VESSEL *vessel)
{
    if (vessel) delete (TESTVC*)vessel;
}
...
 
Top