Optional rotating ship on status screen (Code & Preview)

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

User avatar
Pleb
---- E L I T E ----
---- E L I T E ----
Posts: 908
Joined: Sun Apr 29, 2012 2:23 pm
Location: United Kingdom

Optional rotating ship on status screen (Code & Preview)

Post 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.
Desktop PC: CPU: Intel i7-4790K Quad Core 4.4GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1080Ti RAM: 32GB DDR3

Laptop PC: CPU: Intel i5-10300H Quad Core 4.5GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1650 RAM: 32GB DDR4
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6312
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

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

Post by Diziet Sma »

Nice job.. it works for OXP ships too, I assume?
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6681
Joined: Wed Feb 28, 2007 7:54 am

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

Post 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.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

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

Post 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)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

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

Post 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.)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6681
Joined: Wed Feb 28, 2007 7:54 am

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

Post 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.
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

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

Post by Lestradae »

Is this going into the future standard game?

Please say it does ... :D
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

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

Post 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?
Last edited by spara on Mon Jan 27, 2014 12:37 pm, edited 1 time in total.
Zireael
---- E L I T E ----
---- E L I T E ----
Posts: 1396
Joined: Tue Nov 09, 2010 1:44 pm

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

Post by Zireael »

This is really amazing!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6681
Joined: Wed Feb 28, 2007 7:54 am

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

Post 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.
User avatar
Pleb
---- E L I T E ----
---- E L I T E ----
Posts: 908
Joined: Sun Apr 29, 2012 2:23 pm
Location: United Kingdom

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

Post 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. :)
Desktop PC: CPU: Intel i7-4790K Quad Core 4.4GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1080Ti RAM: 32GB DDR3

Laptop PC: CPU: Intel i5-10300H Quad Core 4.5GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1650 RAM: 32GB DDR4
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

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

Post 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.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

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

Post by Cody »

Liking this, it looks cool - thanks, Pleb.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
CaptSolo
---- E L I T E ----
---- E L I T E ----
Posts: 909
Joined: Wed Feb 23, 2011 10:08 pm
Location: Preying Manta
Contact:

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

Post by CaptSolo »

Good job, Pleb, and thank you all.
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2685
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

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

Post 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)...
Post Reply