Revision | 605173e5071152ddfedac3f7d34c019e13fc0b64 (tree) |
---|---|
Time | 2013-05-19 22:19:32 |
Author | Face |
Commiter | Face |
Merged in reload prototype
@@ -11,6 +11,7 @@ | ||
11 | 11 | #include <math.h> |
12 | 12 | #include <stdio.h> |
13 | 13 | #include "orbitersdk.h" |
14 | +#include "resource.h" | |
14 | 15 | //############################################################################// |
15 | 16 | #include "genericvessel.h" |
16 | 17 |
@@ -64,24 +65,47 @@ | ||
64 | 65 | *cm = 0.0; |
65 | 66 | *cd = 0.015 + oapiGetInducedDrag (*cl, 1.5, 0.6) + oapiGetWaveDrag (M, 0.75, 1.0, 1.1, 0.04); |
66 | 67 | } |
67 | -//############################################################################// | |
68 | -//############################################################################// | |
69 | -GenericVessel::GenericVessel(OBJHANDLE hObj,int fmodel):VESSEL3(hObj,fmodel) | |
68 | +//############################################################################// | |
69 | +void GenericVessel::do_init() | |
70 | 70 | { |
71 | 71 | ph_h=NULL; |
72 | 72 | th_h=NULL; |
73 | - thg_h=NULL; | |
73 | + thg_h=NULL; | |
74 | + exh_h=NULL; | |
74 | 75 | msh_h=NULL; |
75 | 76 | msh_idh=NULL; |
76 | 77 | ani=NULL; |
77 | 78 | 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 | + | |
82 | 105 | delete [] ph_h; |
83 | 106 | delete [] th_h; |
84 | 107 | delete [] thg_h; |
108 | + delete [] exh_h; | |
85 | 109 | delete [] msh_h; |
86 | 110 | delete [] msh_idh; |
87 | 111 | if (ani) for(int i=0;i<sc3.Config.anicnt;i++) |
@@ -91,9 +115,13 @@ | ||
91 | 115 | delete [] ani[i].comp; |
92 | 116 | } |
93 | 117 | delete [] ani; |
94 | - delete [] att_h; | |
118 | + delete [] att_h; | |
119 | + delete [] iniFile; | |
95 | 120 | } |
96 | 121 | //############################################################################// |
122 | +GenericVessel::GenericVessel(OBJHANDLE hObj,int fmodel):VESSEL3(hObj,fmodel){do_init();} | |
123 | +GenericVessel::~GenericVessel(){do_clean();} | |
124 | +//############################################################################// | |
97 | 125 | //############################################################################// |
98 | 126 | void GenericVessel::clbkSetClassCaps(FILEHANDLE cfg) |
99 | 127 | { |
@@ -107,6 +135,8 @@ | ||
107 | 135 | char *className=GetClassName(), *cn=NULL; |
108 | 136 | char *name=GetName(); |
109 | 137 | strcpy(cn=new char[(k=strlen(className))+1], className); |
138 | + in_cfg=cfg; | |
139 | + | |
110 | 140 | strlwr(cn); |
111 | 141 | for(i=0;i<k;i++)if(cn[i]=='/')cn[i]='\\'; |
112 | 142 | if (strncmp(cn, SPACECRAFTCLASS, strlen(SPACECRAFTCLASS))==0){ |
@@ -148,7 +178,6 @@ | ||
148 | 178 | //Load the configuration |
149 | 179 | sc3.Init(this, iniFile, make_vessel); |
150 | 180 | delete [] cn; |
151 | - delete [] iniFile; | |
152 | 181 | |
153 | 182 | //Attachments |
154 | 183 | att_h=new ATTACHMENTHANDLE[sc3.Config.attcnt]; |
@@ -180,7 +209,7 @@ | ||
180 | 209 | SetCrossSections(sc3.Config.cross); |
181 | 210 | SetRotDrag(sc3.Config.rdrag); |
182 | 211 | 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)); | |
184 | 213 | SetSurfaceFrictionCoeff(sc3.Config.frc1,sc3.Config.frc2); |
185 | 214 | SetCW(sc3.Config.cw1,sc3.Config.cw2,sc3.Config.cw3,sc3.Config.cw4); |
186 | 215 | EnableTransponder(sc3.Config.transponder!=0); |
@@ -226,10 +255,11 @@ | ||
226 | 255 | delete [] grps; |
227 | 256 | delete [] grpc; |
228 | 257 | |
229 | - //Exhausts | |
258 | + //Exhausts | |
259 | + exh_h=new UINT[gv_config.exhcnt]; | |
230 | 260 | 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); | |
233 | 263 | } |
234 | 264 | |
235 | 265 | //Meshes |
@@ -631,7 +661,66 @@ | ||
631 | 661 | //Do the new native API callback now |
632 | 662 | sc3.clbkPostStep(simt, simdt, mjd); |
633 | 663 | } |
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 | +} | |
635 | 724 | //#######################################################################################// |
636 | 725 | //Link with xves.dll |
637 | 726 | void config_fromsc3(HINSTANCE hModule) |
@@ -651,6 +740,8 @@ | ||
651 | 740 | DLLCLBK void InitModule(HINSTANCE hModule) |
652 | 741 | { |
653 | 742 | config_fromsc3(hModule); |
743 | + g_hInst=hModule; | |
744 | + g_dwCmd=oapiRegisterCustomCmd("GenericVessel editor","GenericVessel editor",OpenDlgClbk, NULL); | |
654 | 745 | } |
655 | 746 | //############################################################################// |
656 | 747 | //Free the dll on exit |
@@ -658,6 +749,7 @@ | ||
658 | 749 | { |
659 | 750 | if(hlib)FreeLibrary(hlib); |
660 | 751 | make_vessel=NULL; |
752 | + oapiUnregisterCustomCmd(g_dwCmd); | |
661 | 753 | } |
662 | 754 | //############################################################################// |
663 | 755 | DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel,int flightmodel){if(inited)return new GenericVessel(hvessel,flightmodel);else return NULL;} |
@@ -30,6 +30,10 @@ | ||
30 | 30 | #define ANI_PAUSE 2 |
31 | 31 | #define ANI_BACK_PAUSE -2 |
32 | 32 | //############################################################################// |
33 | + | |
34 | + | |
35 | +HINSTANCE g_hInst; // module instance handle | |
36 | +DWORD g_dwCmd; // custom function identifier | |
33 | 37 | //Vessel class |
34 | 38 | class GenericVessel:public VESSEL3{ |
35 | 39 | public: |
@@ -44,10 +48,14 @@ | ||
44 | 48 | int clbkConsumeBufferedKey(DWORD key,bool down,char *kstate); |
45 | 49 | int clbkConsumeDirectKey(char *kstate); |
46 | 50 | bool clbkLoadVC(int id); |
51 | + bool do_reload(); | |
47 | 52 | |
48 | -private: | |
53 | +private: | |
49 | 54 | //INI file data |
50 | 55 | SC3Data::Vessel sc3; |
56 | + void do_init(); | |
57 | + void do_clean(); | |
58 | + | |
51 | 59 | char configDir[CUSTOMDIRSLENGTH]; |
52 | 60 | char meshDir[CUSTOMDIRSLENGTH]; |
53 | 61 | char textureDir[CUSTOMDIRSLENGTH]; |
@@ -57,10 +65,15 @@ | ||
57 | 65 | //Methods |
58 | 66 | void toggle_attach(int point); |
59 | 67 | |
68 | + //INI file name | |
69 | + char *iniFile; | |
70 | + FILEHANDLE in_cfg; | |
71 | + | |
60 | 72 | //Thrusters |
61 | 73 | PROPELLANT_HANDLE *ph_h; |
62 | 74 | THRUSTER_HANDLE *th_h; |
63 | 75 | THGROUP_HANDLE *thg_h; |
76 | + UINT *exh_h; | |
64 | 77 | |
65 | 78 | //Mesh |
66 | 79 | MESHHANDLE *msh_h; |
@@ -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 | + |
@@ -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 |