Commit MetaInfo

Revision605173e5071152ddfedac3f7d34c019e13fc0b64 (tree)
Time2013-05-19 22:19:32
AuthorFace
CommiterFace

Log Message

Merged in reload prototype

Change Summary

Incremental Difference

diff -r 8cb43c48b632 -r 605173e50711 Orbitersdk/samples/genericvessel/GenericVessel.cpp
--- a/Orbitersdk/samples/genericvessel/GenericVessel.cpp Thu Mar 07 19:38:41 2013 +0100
+++ b/Orbitersdk/samples/genericvessel/GenericVessel.cpp Sun May 19 15:19:32 2013 +0200
@@ -11,6 +11,7 @@
1111 #include <math.h>
1212 #include <stdio.h>
1313 #include "orbitersdk.h"
14+#include "resource.h"
1415 //############################################################################//
1516 #include "genericvessel.h"
1617
@@ -64,24 +65,47 @@
6465 *cm = 0.0;
6566 *cd = 0.015 + oapiGetInducedDrag (*cl, 1.5, 0.6) + oapiGetWaveDrag (M, 0.75, 1.0, 1.1, 0.04);
6667 }
67-//############################################################################//
68-//############################################################################//
69-GenericVessel::GenericVessel(OBJHANDLE hObj,int fmodel):VESSEL3(hObj,fmodel)
68+//############################################################################//
69+void GenericVessel::do_init()
7070 {
7171 ph_h=NULL;
7272 th_h=NULL;
73- thg_h=NULL;
73+ thg_h=NULL;
74+ exh_h=NULL;
7475 msh_h=NULL;
7576 msh_idh=NULL;
7677 ani=NULL;
7778 att_h=NULL;
78-}
79-//############################################################################//
80-GenericVessel::~GenericVessel()
81-{
79+ iniFile=NULL;
80+}
81+//############################################################################//
82+void GenericVessel::do_clean()
83+{
84+
85+ for(i=0;i<gv_config.attcnt;i++)DelAttachment(att_h[i]);
86+ for(i=0;i<gv_config.propcnt;i++)DelPropellantResource(ph_h[i]);
87+ for(i=0;i<gv_config.thcnt;i++)DelThruster(th_h[i]);
88+ for(i=0;i<gv_config.thgcnt;i++)DelThrusterGroup(thg_h[i]);
89+ for(i=0;i<gv_config.exhcnt;i++)DelExhaust(exh_h[i]);
90+
91+ for(i=0;i<gv_config.mshcnt;i++)if(gv_data.msh[i].typ==0){
92+ DelMesh(msh_idh[i]);
93+ //msh_h[i]=oapiLoadMeshGlobal(gv_data.msh[i].nam);
94+ }
95+
96+ for(i=0;i<gv_config.anicnt;i++)DelAnimation(ani[i].id);
97+
98+
99+ //for(i=0;i<gv_config.beaccnt;i++)DelBeacon(&gv_data.beac[i].bl);
100+ //for(i=0;i<gv_config.dockcnt;i++)DelDock(gv_data.dock[i].pos,gv_data.dock[i].dir,gv_data.dock[i].rot);
101+
102+ if(gv_config.crewcnt!=0)if(gv_data.crew[0].maxcrew!=0)Crew.InitUmmu(GetHandle());
103+
104+
82105 delete [] ph_h;
83106 delete [] th_h;
84107 delete [] thg_h;
108+ delete [] exh_h;
85109 delete [] msh_h;
86110 delete [] msh_idh;
87111 if (ani) for(int i=0;i<sc3.Config.anicnt;i++)
@@ -91,9 +115,13 @@
91115 delete [] ani[i].comp;
92116 }
93117 delete [] ani;
94- delete [] att_h;
118+ delete [] att_h;
119+ delete [] iniFile;
95120 }
96121 //############################################################################//
122+GenericVessel::GenericVessel(OBJHANDLE hObj,int fmodel):VESSEL3(hObj,fmodel){do_init();}
123+GenericVessel::~GenericVessel(){do_clean();}
124+//############################################################################//
97125 //############################################################################//
98126 void GenericVessel::clbkSetClassCaps(FILEHANDLE cfg)
99127 {
@@ -107,6 +135,8 @@
107135 char *className=GetClassName(), *cn=NULL;
108136 char *name=GetName();
109137 strcpy(cn=new char[(k=strlen(className))+1], className);
138+ in_cfg=cfg;
139+
110140 strlwr(cn);
111141 for(i=0;i<k;i++)if(cn[i]=='/')cn[i]='\\';
112142 if (strncmp(cn, SPACECRAFTCLASS, strlen(SPACECRAFTCLASS))==0){
@@ -148,7 +178,6 @@
148178 //Load the configuration
149179 sc3.Init(this, iniFile, make_vessel);
150180 delete [] cn;
151- delete [] iniFile;
152181
153182 //Attachments
154183 att_h=new ATTACHMENTHANDLE[sc3.Config.attcnt];
@@ -180,7 +209,7 @@
180209 SetCrossSections(sc3.Config.cross);
181210 SetRotDrag(sc3.Config.rdrag);
182211 if(sc3.Config.tdcnt>0)SetTouchdownPoints(sc3.Data.td[0].pta,sc3.Data.td[0].ptb,sc3.Data.td[0].ptc);
183- else SetTouchdownPoints(_V(0,0,1),_V(-1,0,-1),_V(1,0,-1));
212+ else SetTouchdownPoints(_V(0,0,1),_V(-1,0,-1),_V(1,0,-1));
184213 SetSurfaceFrictionCoeff(sc3.Config.frc1,sc3.Config.frc2);
185214 SetCW(sc3.Config.cw1,sc3.Config.cw2,sc3.Config.cw3,sc3.Config.cw4);
186215 EnableTransponder(sc3.Config.transponder!=0);
@@ -226,10 +255,11 @@
226255 delete [] grps;
227256 delete [] grpc;
228257
229- //Exhausts
258+ //Exhausts
259+ exh_h=new UINT[gv_config.exhcnt];
230260 for(i=0;i<sc3.Config.exhcnt;i++){
231- if(sc3.Data.exh[i].tp==0)AddExhaust(th_h[sc3.Data.exh[i].th],sc3.Data.exh[i].lscl,sc3.Data.exh[i].wscl);
232- if(sc3.Data.exh[i].tp==1)AddExhaust(th_h[sc3.Data.exh[i].th],sc3.Data.exh[i].lscl,sc3.Data.exh[i].wscl,sc3.Data.exh[i].pos,sc3.Data.exh[i].rot);
261+ if(sc3.Data.exh[i].tp==0)exh_h[i]=AddExhaust(th_h[sc3.Data.exh[i].th],sc3.Data.exh[i].lscl,sc3.Data.exh[i].wscl);
262+ if(sc3.Data.exh[i].tp==1)exh_h[i]=AddExhaust(th_h[sc3.Data.exh[i].th],sc3.Data.exh[i].lscl,sc3.Data.exh[i].wscl,sc3.Data.exh[i].pos,sc3.Data.exh[i].rot);
233263 }
234264
235265 //Meshes
@@ -631,7 +661,66 @@
631661 //Do the new native API callback now
632662 sc3.clbkPostStep(simt, simdt, mjd);
633663 }
634-//#######################################################################################//
664+//#######################################################################################//
665+//#######################################################################################//
666+bool GenericVessel::do_reload()
667+{
668+ do_clean();
669+ do_init();
670+ clbkSetClassCaps(in_cfg);
671+
672+ return TRUE;
673+}
674+//#######################################################################################//
675+//#######################################################################################//
676+void reload_vessel()
677+{
678+ VESSEL *ves=oapiGetVesselInterface(oapiGetFocusObject());
679+ //if (ves is GenericVessel) {
680+ ((GenericVessel*)ves)->do_reload();
681+ //}
682+}
683+//#######################################################################################//
684+int myprm = 0;
685+//#######################################################################################//
686+void CloseDlg(HWND hDlg)
687+{
688+ oapiCloseDialog(hDlg);
689+}
690+//#######################################################################################//
691+BOOL CALLBACK MsgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
692+{
693+ char name[256];
694+
695+ switch(uMsg){
696+ case WM_INITDIALOG:
697+ sprintf(name,"%d",myprm);
698+ //SetWindowText(GetDlgItem(hDlg,IDC_REMEMBER),name);
699+ return TRUE;
700+
701+ case WM_DESTROY:
702+ return TRUE;
703+
704+ case WM_COMMAND:
705+ switch (LOWORD (wParam)) {
706+
707+ case ID_RELOAD:
708+ reload_vessel();
709+ return TRUE;
710+
711+ case IDCANCEL: //dialog closed by user
712+ CloseDlg (hDlg);
713+ return TRUE;
714+ }
715+ break;
716+ }
717+ return oapiDefDialogProc (hDlg, uMsg, wParam, lParam);
718+}
719+//#######################################################################################//
720+void OpenDlgClbk(void *context)
721+{
722+ HWND hDlg=oapiOpenDialog(g_hInst,IDD_MYDIALOG,MsgProc);
723+}
635724 //#######################################################################################//
636725 //Link with xves.dll
637726 void config_fromsc3(HINSTANCE hModule)
@@ -651,6 +740,8 @@
651740 DLLCLBK void InitModule(HINSTANCE hModule)
652741 {
653742 config_fromsc3(hModule);
743+ g_hInst=hModule;
744+ g_dwCmd=oapiRegisterCustomCmd("GenericVessel editor","GenericVessel editor",OpenDlgClbk, NULL);
654745 }
655746 //############################################################################//
656747 //Free the dll on exit
@@ -658,6 +749,7 @@
658749 {
659750 if(hlib)FreeLibrary(hlib);
660751 make_vessel=NULL;
752+ oapiUnregisterCustomCmd(g_dwCmd);
661753 }
662754 //############################################################################//
663755 DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel,int flightmodel){if(inited)return new GenericVessel(hvessel,flightmodel);else return NULL;}
diff -r 8cb43c48b632 -r 605173e50711 Orbitersdk/samples/genericvessel/GenericVessel.h
--- a/Orbitersdk/samples/genericvessel/GenericVessel.h Thu Mar 07 19:38:41 2013 +0100
+++ b/Orbitersdk/samples/genericvessel/GenericVessel.h Sun May 19 15:19:32 2013 +0200
@@ -30,6 +30,10 @@
3030 #define ANI_PAUSE 2
3131 #define ANI_BACK_PAUSE -2
3232 //############################################################################//
33+
34+
35+HINSTANCE g_hInst; // module instance handle
36+DWORD g_dwCmd; // custom function identifier
3337 //Vessel class
3438 class GenericVessel:public VESSEL3{
3539 public:
@@ -44,10 +48,14 @@
4448 int clbkConsumeBufferedKey(DWORD key,bool down,char *kstate);
4549 int clbkConsumeDirectKey(char *kstate);
4650 bool clbkLoadVC(int id);
51+ bool do_reload();
4752
48-private:
53+private:
4954 //INI file data
5055 SC3Data::Vessel sc3;
56+ void do_init();
57+ void do_clean();
58+
5159 char configDir[CUSTOMDIRSLENGTH];
5260 char meshDir[CUSTOMDIRSLENGTH];
5361 char textureDir[CUSTOMDIRSLENGTH];
@@ -57,10 +65,15 @@
5765 //Methods
5866 void toggle_attach(int point);
5967
68+ //INI file name
69+ char *iniFile;
70+ FILEHANDLE in_cfg;
71+
6072 //Thrusters
6173 PROPELLANT_HANDLE *ph_h;
6274 THRUSTER_HANDLE *th_h;
6375 THGROUP_HANDLE *thg_h;
76+ UINT *exh_h;
6477
6578 //Mesh
6679 MESHHANDLE *msh_h;
diff -r 8cb43c48b632 -r 605173e50711 Orbitersdk/samples/genericvessel/editdialog.rc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Orbitersdk/samples/genericvessel/editdialog.rc Sun May 19 15:19:32 2013 +0200
@@ -0,0 +1,111 @@
1+// Microsoft Visual C++ generated resource script.
2+//
3+#include "resource.h"
4+
5+#define APSTUDIO_READONLY_SYMBOLS
6+/////////////////////////////////////////////////////////////////////////////
7+//
8+// Generated from the TEXTINCLUDE 2 resource.
9+//
10+#include "afxres.h"
11+
12+/////////////////////////////////////////////////////////////////////////////
13+#undef APSTUDIO_READONLY_SYMBOLS
14+
15+/////////////////////////////////////////////////////////////////////////////
16+// English (U.K.) resources
17+
18+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
19+#ifdef _WIN32
20+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
21+#pragma code_page(1252)
22+#endif //_WIN32
23+
24+/////////////////////////////////////////////////////////////////////////////
25+//
26+// Dialog
27+//
28+
29+IDD_MYDIALOG DIALOGEX 0, 0, 314, 198
30+STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
31+EXSTYLE WS_EX_TOOLWINDOW
32+CAPTION "Generic vessel editor"
33+FONT 8, "MS Sans Serif", 0, 0, 0x1
34+BEGIN
35+ PUSHBUTTON "Close",IDCANCEL,257,177,50,14
36+ EDITTEXT IDC_EDIT,7,7,300,164,ES_MULTILINE | ES_AUTOHSCROLL | ES_NUMBER | WS_VSCROLL | WS_HSCROLL
37+ PUSHBUTTON "Reload",ID_RELOAD,7,178,55,13
38+END
39+
40+
41+/////////////////////////////////////////////////////////////////////////////
42+//
43+// DESIGNINFO
44+//
45+
46+#ifdef APSTUDIO_INVOKED
47+GUIDELINES DESIGNINFO
48+BEGIN
49+ IDD_MYDIALOG, DIALOG
50+ BEGIN
51+ LEFTMARGIN, 7
52+ RIGHTMARGIN, 307
53+ TOPMARGIN, 7
54+ BOTTOMMARGIN, 191
55+ END
56+END
57+#endif // APSTUDIO_INVOKED
58+
59+
60+#ifdef APSTUDIO_INVOKED
61+/////////////////////////////////////////////////////////////////////////////
62+//
63+// TEXTINCLUDE
64+//
65+
66+1 TEXTINCLUDE
67+BEGIN
68+ "resource.h\0"
69+END
70+
71+2 TEXTINCLUDE
72+BEGIN
73+ "#include ""afxres.h""\r\n"
74+ "\0"
75+END
76+
77+3 TEXTINCLUDE
78+BEGIN
79+ "\r\n"
80+ "\0"
81+END
82+
83+#endif // APSTUDIO_INVOKED
84+
85+
86+/////////////////////////////////////////////////////////////////////////////
87+//
88+// String Table
89+//
90+
91+STRINGTABLE
92+BEGIN
93+ IDS_INFO "DIALOG TEMPLATE:\r\n\r\nA simple SDK example which provides a dialog box that can be opened during a simulation session via the ""My dialog"" entry in the Custom Functions list (Ctrl-F4).\r\n\r\nThis addon is not very useful - it is intended as a starting point for developers."
94+ IDS_TYPE "Developer resources and samples"
95+END
96+
97+#endif // English (U.K.) resources
98+/////////////////////////////////////////////////////////////////////////////
99+
100+
101+
102+#ifndef APSTUDIO_INVOKED
103+/////////////////////////////////////////////////////////////////////////////
104+//
105+// Generated from the TEXTINCLUDE 3 resource.
106+//
107+
108+
109+/////////////////////////////////////////////////////////////////////////////
110+#endif // not APSTUDIO_INVOKED
111+
diff -r 8cb43c48b632 -r 605173e50711 Orbitersdk/samples/genericvessel/resource.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Orbitersdk/samples/genericvessel/resource.h Sun May 19 15:19:32 2013 +0200
@@ -0,0 +1,22 @@
1+//{{NO_DEPENDENCIES}}
2+// Microsoft Visual C++ generated include file.
3+// Used by editdialog.rc
4+//
5+#define IDD_MYDIALOG 101
6+#define IDC_WHOAMI 1000
7+#define IDS_INFO 1000
8+#define IDC_IAM 1001
9+#define IDS_TYPE 1001
10+#define IDC_EDIT 1002
11+#define ID_RELOAD 1003
12+
13+// Next default values for new objects
14+//
15+#ifdef APSTUDIO_INVOKED
16+#ifndef APSTUDIO_READONLY_SYMBOLS
17+#define _APS_NEXT_RESOURCE_VALUE 103
18+#define _APS_NEXT_COMMAND_VALUE 40001
19+#define _APS_NEXT_CONTROL_VALUE 1004
20+#define _APS_NEXT_SYMED_VALUE 101
21+#endif
22+#endif
Show on old repository browser