Page 1 of 2

Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 12:35 am
by Pleb
Someone (spara I believe) asked before about having a small rotating ship model on the status screen, as you never really get to see your own ship (unless you press the v button when flying). The following code will allow this and make it optional (so those who don't want it don't have to have it).

First, load up PlayerEntity.h and insert the following around line 826:

Code: Select all

- (void) addStatusModel:(NSString *)shipKey;
Now load up PlayerEntity.m and insert the following around line 6596 (it should replace [self setShowDemoShips:NO];):

Code: Select all

	if (EXPECT_NOT([[NSUserDefaults standardUserDefaults] boolForKey:@"display-status-model"]))
	{
		[UNIVERSE removeDemoShips];
		[self addStatusModel:[self shipDataKey]];
		[self setShowDemoShips:YES];
	}
	else
	{
		[self setShowDemoShips:NO];
	}
Now scroll down to line 6635 and add the following:

Code: Select all

- (void) addStatusModel:(NSString *)shipKey
{
	Quaternion		q2 = { (GLfloat)M_SQRT1_2, (GLfloat)M_SQRT1_2, (GLfloat)0.0f, (GLfloat)0.0f };
	// MKW - retrieve last demo ships' orientation and release it
	if( demoShip != nil )
	{
		q2 = [demoShip orientation];
		[demoShip release];
	}
	NSDictionary *shipData = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
	ShipEntity *ship = [[ProxyPlayerEntity alloc] initWithKey:shipKey definition:shipData];
	[ship wasAddedToUniverse];
	
	GLfloat cr = [ship collisionRadius];
	[ship setOrientation: q2];
	
	[ship setPositionX:2.5 * cr y:1.7 * cr z:8.0 * cr];
	[ship setScanClass: CLASS_NO_DRAW];
	[ship setRoll: M_PI/10.0];
	[ship setPitch: M_PI/25.0];
	if([ship pendingEscortCount] > 0) [ship setPendingEscortCount:0];
	[ship setAITo: @"nullAI.plist"];
	id subEntStatus = [shipData objectForKey:@"subentities_status"];
	// show missing subentities if there's a subentities_status key
	if (subEntStatus != nil) [ship deserializeShipSubEntitiesFrom:(NSString *)subEntStatus];
	[UNIVERSE addEntity: ship];
	// MKW - save demo ship for its rotation
	demoShip = [ship retain];
	
	[ship setStatus: STATUS_COCKPIT_DISPLAY];
	
	[ship release];
}
Now compile your game, and then load up your .GNUstepDefaults file and add "display-status-model" = YES; to enable the model on the status screen. And here you are:

Image

Image

Image

This would now be a completely optional addition to the game, meaning those who want this have to turn it on in order for it not to work, as it would not appear by default.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 7:54 am
by Diziet Sma
Nice job.. it works for OXP ships too, I assume?

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 8:04 am
by another_commander
Very cool. I like it and would seriously consider getting it in the game. Just one note: This code for displaying ships occurs already twice in the core, with this addition being the third. I think it's time to farm out the ship display code from - addScenarioModel: in PlayerEntityLoadSave.m and -showShipyardModel: in PlayerEntityContracts.m to its own method, then just call that one method from whichever part of the code we want.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 8:10 am
by cim
Very nice. A couple of additions you could make to cover OXP cases:
- easier: when adding the model, set its entityPersonality to be equal to the player ship. If the ship has a paint shader like the Griff shipset, this will (probably) get it to be the right colour. I say "probably": for the full guarantee you also need because of things like "Respray for Griffs" to copy the player ship's current shader program over the default too, but entityPersonality would be a big gain on its own.
- harder: some OXP ships have frangible subentities. It should be possible to match the view to the actual currently present subentities. (The "Dark Wheel Cobra" is probably the easiest one to test with)

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 8:38 am
by JensAyton
Harderer: write a new entity subclass which extracts the drawables from a ship/player entity, with their relative positions and orientations intact. If you retain the original drawables, the shaders will still be bound to the original ship, although some properties might be weird while docked.

(There would be some weird effects, though: animated entities would be frozen, but shader-bound properties would be updated. Even better would perhaps be copying the drawables and the values of all bound properties, or arranging things so that the actual PlayerEntity can be drawn there without changing its position and orientation in the universe.)

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 9:58 am
by another_commander
Revision 8f0f0cf has taken care of the code duplication. Pleb, you may want to try a git pull. Having one central point for calling the model drawing stuff enables us to simplify the code for showing it in the status screen to just this:

Code: Select all

if (EXPECT_NOT([[NSUserDefaults standardUserDefaults] boolForKey:@"display-status-model"]))
{
      [UNIVERSE removeDemoShips];
      [self showShipModelWithKey:[self shipDataKey] shipData:nil personality:[self entityPersonality] factorX:2.5 factorY:1.7 
            factorZ:8.0 inContext:@"StatusScreen"];
      [self setShowDemoShips:YES];
}
else
{
      [self setShowDemoShips:NO];
}
As you see, the method showShipModelWithKey: shipData: etc is now responsible for drawing and is now called also from contracts and from the scenario screens that want to display models. It enables you to pass a specific key, ship data dictionary, a specific personality, specific x,y and z positioning factors so that you can put the model anywhere on screen and zoomed in/out if preferred and even the option of logging the context in which you are displaying the model, if you so wish. It could even be further expanded to include variable pitch and roll rates for the model rotation.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 10:37 am
by Lestradae
Is this going into the future standard game?

Please say it does ... :D

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 12:01 pm
by spara
This is really cool Pleb 8) . It will make the game look and feel more polished. And I would also say that it adds immersion too, as you see the ship you're flying every time you visit the status screen. Does it work in-flight too? If I recall it right, you can't animate ships in mission screens when in-flight. Not that I would really miss it.

Now that you seem to be on fire with tweaking the source... :twisted: Next piece of polish that I would greatly value is adding more ship details to the ship market screen. I have proposed the idea here. Any interest?

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 12:30 pm
by Zireael
This is really amazing!

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 12:54 pm
by another_commander
Lestradae wrote:
Is this going into the future standard game?

Please say it does ... :D
It's already gone in. Revision cf08bb2.
spara wrote:
Does it work in-flight too?
Yes.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 12:58 pm
by Pleb
Thanks all! another_commander, I will take a look at the revised code in the source this evening and see if anything more can be added to it (along the lines of what has been mentioned by cim and JensAyton) but just from looking at it I can see already the personality function has been taken care of. I will also test this against some more OXPs, including "Respray for Griffs" and "Dark Wheel Cobra" as mentioned previously. However what you've already put in looks like it will do the job! :D
spara wrote:
Now that you seem to be on fire with tweaking the source... :twisted: Next piece of polish that I would greatly value is adding more ship details to the ship market screen. I have proposed the idea here. Any interest?
I don't want to over-extend myself at the moment, as I am also still in the process of fine tuning the new custom ratings and legal status code. However I will take a look and see what/if I can do anything. :)

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Mon Jan 27, 2014 5:51 pm
by cim
spara wrote:
Now that you seem to be on fire with tweaking the source... :twisted: Next piece of polish that I would greatly value is adding more ship details to the ship market screen. I have proposed the idea here. Any interest?
Similar enhancements - including the option to redact particular entries - could be made to the demoships screen now that's its own thing.
JensAyton wrote:
or arranging things so that the actual PlayerEntity can be drawn there without changing its position and orientation in the universe.
Or even an arbitrary ShipEntity - there could be some interesting mission screen uses for that.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Tue Jan 28, 2014 1:35 pm
by Cody
Liking this, it looks cool - thanks, Pleb.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Thu Jan 30, 2014 2:14 pm
by CaptSolo
Good job, Pleb, and thank you all.

Re: Optional rotating ship on status screen (Code & Preview)

Posted: Thu Jan 30, 2014 3:12 pm
by Redspear
Nice work again Pleb 8) Thanks :D

I'd really like to see something like this when targeting ships/stations (i.e. as a HUD element or similar)...