![]() |
|
|||||||
| Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Orbinaut
|
Sorry for my English.
I do count my_simt. for example: Code:
class zst_t: public VESSEL2 {
public:
zst_t (OBJHANDLE hVessel, int flightmodel): VESSEL2 (hVessel, flightmodel)
{
}
void clbkSetClassCaps (FILEHANDLE cfg);
void clbkLoadStateEx (FILEHANDLE scn, void *vs);
void clbkSaveState (FILEHANDLE scn);
void clbkPreStep (double simt, double simdt, double mjd);
int clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
void clbkDrawHUD (int mode, const HUDPAINTSPEC* hps, HDC hdc);
private:
double my_simt;
};
It is necessary to have some ships of class zst_t value my_simt were different. How do I do? I am not an expert C + + Thank you. |
|
|
|
|
|
#2 |
|
shoemaker without legs
![]() |
Quote:
Also, I would recommend deriving your class from VESSEL3, as VESSEL2 is somewhat outdated. |
|
|
|
|
|
#3 |
|
Wandering lonely as a cloud
![]() |
With C++ the way you have it now, each my_simt is a different variable. So to have it be different between vessels, just assign it a value. If it was declared with the static keyword, it would have the same value across all classes. So you can just assign it within a method somewhere and it won't change for all vessels.
Also, welcome to the forum! |
|
|
|
|
|
#4 |
|
Orbinaut
|
Quote:
Code:
void zst_t::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
char *line;
while (oapiReadScenario_nextline (scn, line)) {
if (!_strnicmp (line, "MY_SIMTIME", 10))
{
double osmt;
sscanf (line+10, "%lf", &osmt);
my_simt=osmt;
};
ParseScenarioLineEx (line, vs);
}
}
after loading the values from * scn of variables my_simt all ships are equal
|
|
|
|
|
|
#5 |
|
shoemaker without legs
![]() |
Code:
sscanf (line+10, "%lf", &osmt); One thing I can tell for sure is that "+10 is wrong. You don't just have the parameter name to skip, you also have a space to skip. So if anything, it should be +11, but as I said, I don't know if that is even allowed. Since a char string is actualy nothing but a simple array, I would say no. I usually put the char into an std::string and then use its substring function, like this: Code:
void zst_t::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
char *line;
string s = "";
while (oapiReadScenario_nextline (scn, line)) {
if (!_strnicmp (line, "MY_SIMTIME", 10))
{
s = line;
double osmt;
sscanf (s.substr(11).data(), "%lf", &osmt);
my_simt=osmt;
};
ParseScenarioLineEx (line, vs);
}
}
|
|
|
|
|
|
#6 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
Those fancy C++ functions do similar things, but it's hidden from the coder, and making additional conversions between char[] and string one and another way makes larger and much slower code. |
|
|
|
| Thanked by: |
|
|
#7 |
|
Wandering lonely as a cloud
![]() |
To jedidia: using (abusing?) sscanf and char*'s in that manner have not failed me yet. Whether it's proper or not, I don't know, but I do know that it works.
To naunau: are you sure the scenario file has each ship with different MY_SIMTIME values? That should work and looks virtually identical to how I load scenario file values. |
|
|
|
|
|
#8 |
|
Orbinaut
|
Quote:
I experimented so. calculated the number of keystrokes "W". Code:
class zst_t: public VESSEL2 {
public:
zst_t (OBJHANDLE hVessel, int flightmodel): VESSEL2 (hVessel, flightmodel)
{
}
void clbkSetClassCaps (FILEHANDLE cfg);
void clbkLoadStateEx (FILEHANDLE scn, void *vs);
void clbkSaveState (FILEHANDLE scn);
void clbkPreStep (double simt, double simdt, double mjd);
int clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
void clbkDrawHUD (int mode, const HUDPAINTSPEC* hps, HDC hdc);
private:
double my_var;
};
void zst_t::clbkSetClassCaps (FILEHANDLE cfg)
{
.....
my_var=0;
....
};
int zst_t::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
if (key == OAPI_KEY_W && down)
{
my_var++;
};
};
void zst_t::clbkDrawHUD (int mode, const HUDPAINTSPEC* hps, HDC hdc)
{
VESSEL2::clbkDrawHUD(mode,hps,hdc);
TCHAR szTime[30];
WORD n=sprintf(szTime, "%f", my_var);
TextOutA(hdc,0,0, LPCSTR( szTime) ,n);
};
My calculations are in zst_cb :: clbkPreStep seems to zst_cb :: clbkPreStep value of the variable are mixed. there are some features in zst_cb :: clbkPreStep? ---------- Post added at 11:57 AM ---------- Previous post was at 04:10 AM ---------- in the clbkPreStep, I had the following code: Code:
void zst_t::clbkPreStep (double simt, double simdt, double mjd)
{
...............
VESSEL *vessel = oapiGetFocusInterface(); // Get current vessel
double as = ves->GetAirspeed();
double K0 = ves->GetAtmTemperature();
double CP = 2010;
double my_var=K0+(as*as)/CP;
...............
};
so my variables become the same. I had to write it. Code:
void zst_t::clbkPreStep (double simt, double simdt, double mjd)
{
...............
double as = GetAirspeed();
double K0 = GetAtmTemperature();
double CP = 2010;
double my_var=K0+(as*as)/CP;
...............
};
Last edited by naunau; 08-07-2012 at 06:44 AM. |
|
|
|
![]() |
|
| Thread Tools | |
|
|
|||||
| Quick Links | Need Help? |