Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 07-12-2017, 04:48 PM   #1
TCR_500
Biblical Creationist
Default Are Multiple Vessels Per Module Possible

If someone were to create a vessel pack that had several vessels all related to each other in some way (eg: stages), would it be possible to for the developer of such a set to put all of their vessels into a single module?

And if they did do that, would the scenario editor be able to spawn each type of vessel independently of the other types in the module, or would they all be spawned at once and have to be deleted one by one?
TCR_500 is offline   Reply With Quote
Old 07-12-2017, 05:31 PM   #2
orb
O-F Administrator
Ninja
 
orb's Avatar

Default

Yes. Multiple vessel classes are possible in a single DLL.

You can spawn each of them separately in scenario editor.
orb is offline   Reply With Quote
Thanked by:
Old 07-12-2017, 05:55 PM   #3
jedidia
shoemaker without legs
 
jedidia's Avatar
Default

Quote:
Yes. Multiple vessel classes are possible in a single DLL.
How do you define the entry points if there's multiple vessels?
jedidia is offline   Reply With Quote
Old 07-12-2017, 06:13 PM   #4
Face
Beta Tester
 
Face's Avatar

Default

Quote:
Originally Posted by jedidia View Post
 How do you define the entry points if there's multiple vessels?
I'd say class name.
Face is offline   Reply With Quote
Old 07-13-2017, 09:49 AM   #5
fred18
Addon Developer

Default

That's very interesting, i've never thought about that.
fred18 is offline   Reply With Quote
Old 07-13-2017, 01:12 PM   #6
Face
Beta Tester
 
Face's Avatar

Default

Given that you can create vessel config A and B that point to the same module M, you can compile both classes cA and cB into M with a common ovcInit and ovcExit like so:
Code:
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
	VESSEL *vessel=new VESSEL(hvessel, flightmodel);
	char *className=new char[strlen(vessel->GetClassName())+1];
	strcpy(className, vessel->GetClassName());
	delete vessel;
	strlwr(className);
	if (strcmp(className, "a")==0) vessel=new cA (hvessel, flightmodel);
	else if (strcmp(className, "b")==0) vessel=new cB (hvessel, flightmodel);
	delete [] className;	
	return vessel;
}

DLLCLBK void ovcExit (VESSEL *vessel)
{
	if (vessel)
	{
		char *className=new char[strlen(vessel->GetClassName())+1];
		strcpy(className, vessel->GetClassName());
		strlwr(className);
		if (strcmp(className, "a")==0) delete (cA*)vessel;
		else if (strcmp(className, "b")==0) delete (cB*)vessel;
		delete [] className;
	}
}
This should work for the scenario editor, too. The new-VESSEL-trick from ye olde days is necessary, because at the time of the ovcInit-call, a oapiGetVesselInterface() on the handle returns NULL.
Face is offline   Reply With Quote
Thanked by:
Old 07-14-2017, 02:09 PM   #7
TCR_500
Biblical Creationist
Default

I did not know that the VESSEL class had a GetClassName() function. Though I was told that polymorphic objects don't need a (derived*) cast when delete is called. I was also told that objects always need delete[] to be called even if new (not new[]) is called. Since a class is technically an array.
TCR_500 is offline   Reply With Quote
Old 07-14-2017, 02:53 PM   #8
Face
Beta Tester
 
Face's Avatar

Default

Quote:
Originally Posted by TCR_500 View Post
 Though I was told that polymorphic objects don't need a (derived*) cast when delete is called.
AFAIK, you have to explicitly declare a destructor of a base class virtual for that to work. I don't know who has told you otherwise, but here is a reference for that: http://www.studytonight.com/cpp/virtual-destructors.php

I must admit that I never tried it for myself, but I've learned to not trust C++ to do the right thing implicitly.

Quote:
Originally Posted by TCR_500 View Post
 I was also told that objects always need delete[] to be called even if new (not new[]) is called. Since a class is technically an array.
*sigh* Was it the same person as above that told you that? https://stackoverflow.com/questions/...lete-vs-delete
Face is offline   Reply With Quote
Thanked by:
Old 07-14-2017, 03:56 PM   #9
martins
Orbiter Founder
Default

Quote:
Originally Posted by TCR_500 View Post
 Since a class is technically an array.
A class is technically a struct. The only difference is that by default struct members are public, while class members are private.

Edit: Also I don't know if structs support virtual members or inheritance. Never tried that ...
martins is offline   Reply With Quote
Thanked by:
Old 07-14-2017, 04:50 PM   #10
Zatnikitelman
Addon Developer
 
Zatnikitelman's Avatar
Default

They do, I tried that out a while ago in a failed attempt at an Orbiter mission system. I know now a class would have been better, but I think in C++, there's no longer any meaningful difference between a class and struct. Just something about the default visibility of members I think.

Last edited by Zatnikitelman; 07-14-2017 at 04:53 PM.
Zatnikitelman is online now   Reply With Quote
Old 07-14-2017, 05:00 PM   #11
Face
Beta Tester
 
Face's Avatar

Default

Quote:
Originally Posted by Zatnikitelman View Post
 They do, I tried that out a while ago in a failed attempt at an Orbiter mission system. I know now a class would have been better, but I think in C++, there's no longer any meaningful difference between a class and struct. Just something about the default visibility of members I think.
I don't get that statement.
You know now that a class would have been better. You think that there is no meaningful difference between a class and a struct.
So.. if you know that a class would have been better, you'd know that there is a difference.
But.. if you know that there is a difference, why do you think there is none?
Face is offline   Reply With Quote
Old 07-14-2017, 06:01 PM   #12
jangofett287
Heat shield 'tester'
 
jangofett287's Avatar
Default

Quote:
Originally Posted by Face View Post
 AFAIK, you have to explicitly declare a destructor of a base class virtual for that to work. I don't know who has told you otherwise, but here is a reference for that: http://www.studytonight.com/cpp/virtual-destructors.php
I learned that you HAD to make your destructor virtual if you were going to make derived classes.

Quote:
Originally Posted by TCR_500 View Post
 I was also told that objects always need delete[] to be called even if new (not new[]) is called. Since a class is technically an array.
As Face and martins have pointed out that's not true. Each new/new[]/malloc in a constructor should be paired with an equivalent delete/delete[]/free in the destructor. You should always make sure you delete things you put on the heap and in some cases you need to make sure it hasn't already been deleted.
jangofett287 is offline   Reply With Quote
Thanked by:
Old 07-14-2017, 08:14 PM   #13
Zatnikitelman
Addon Developer
 
Zatnikitelman's Avatar
Default

Quote:
Originally Posted by Face View Post
 I don't get that statement.
You know now that a class would have been better. You think that there is no meaningful difference between a class and a struct.
So.. if you know that a class would have been better, you'd know that there is a difference.
But.. if you know that there is a difference, why do you think there is none?
Bad wording on my part. Better here refers more to standards and readability than a technical reason.
Zatnikitelman is online now   Reply With Quote
Thanked by:
Old 07-14-2017, 08:41 PM   #14
jedidia
shoemaker without legs
 
jedidia's Avatar
Default

Quote:
I must admit that I never tried it for myself, but I've learned to not trust C++ to do the right thing implicitly.
I need it in a few cases to clean up memory. In a tall inheritance tree it's quite a common requirement, actually, especially when working with abstract base classes and multiple inheritance.
I didn't realise that I needed virtual destructors until then, though, and the realisation was not very funny. C++ has quite a few questionable decisions in its syntax, but this one tops it all. Like, I can't imagine any situation where it would be a good thing not to call the destructor of an inheriting class...

Quote:
Better here refers more to standards and readability than a technical reason.
A struct knows neither access modifiers nor inheritance. If you consider those matters of "standards and readability", then you did not yet understand what object oriented programming is about
jedidia is offline   Reply With Quote
Old 07-14-2017, 08:53 PM   #15
TCR_500
Biblical Creationist
Default

The virtual destructors I already knew about, but thanks anyways. I also already knew that structs and classes are basically identical except for default access (at least for C++). And it seems like the C++ community lied to me again.
TCR_500 is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 07:47 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.