Question about particular bit of source code

General discussion for players of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Question about particular bit of source code

Post by phkb »

This one is for anyone who might know the history of the source code.

In the "PlayerEntity.m" file, line 8049, reads like this:

Code: Select all

	for (eqTypeEnum = [OOEquipmentType reverseEquipmentEnumerator]; (eqType = [eqTypeEnum nextObject]); )
Click here to jump straight to the location and view it in context at GitHub.

It's the "reverseEquipmentEnumerator" bit I'm confused by. Not for what it does (it cycles through the player's equipment in reverse order), but why. Why does it need to go in reverse order for display on the F5 screen? I thought it might be because of damaged items, but those are handled separately and are forced to the top of the list, no matter which order the equipment is displayed in.

I honestly can't see a reason for it. But before I push a code change into trunk, I just wanted to pick the brains of anyone who might remember why this was important to do.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: Question about particular bit of source code

Post by another_commander »

Check https://github.com/OoliteProject/oolite ... e9975fbd8d

and https://github.com/OoliteProject/oolite/issues/70

That is when the change was made and addresses issue #70. #70 does not seem to be very clear about why a reverse enumeration is necessary, but I'm sure cim had a good practical reason for it.

Mind you this whole part in the source about equipment sorting and presenting to player is very delicate and easy to break with the various parameters, equipment incompatibilities and all. Proceed with great caution to avoid older bugs getting unexpectedly reintroduced.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Question about particular bit of source code

Post by phkb »

Thanks a_c, I’ll have a good hard look at everything.
User avatar
Cholmondely
Archivist
Archivist
Posts: 5364
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Question about particular bit of source code

Post by Cholmondely »

Stumbled across this: Default order of equipment on F5 (Dec 2013 - July 2014)
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
hiran
Theorethicist
Posts: 2403
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Question about particular bit of source code

Post by hiran »

Not sure about Objective C or the history of this project.
But is it possible that the list of equipment can change while it is being iterated? Items get appended or removed?

That is what might make me switch direction for processing the list. The other solution would be to take a copy first.
Last edited by hiran on Sun Dec 10, 2023 9:14 am, edited 1 time in total.
Sunshine - Moonlight - Good Times - Oolite
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: Question about particular bit of source code

Post by another_commander »

hiran wrote: Sun Dec 10, 2023 6:38 am
Not sure about Objective C or the history of this project.
But is it oossible that the list of equipment can change while it is being iterated? Items get appended or removed?
Yes, this is true in certain cases. However, in this particular case, I believe that the intent was to simply avoid pushing important equipment items into the second f5 page when the list became too long. Cholmondely's finding plus issue #70 both seem to point towards that direction.
User avatar
hiran
Theorethicist
Posts: 2403
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Question about particular bit of source code

Post by hiran »

another_commander wrote: Sun Dec 10, 2023 8:11 am
hiran wrote: Sun Dec 10, 2023 6:38 am
Not sure about Objective C or the history of this project.
But is it oossible that the list of equipment can change while it is being iterated? Items get appended or removed?
Yes, this is true in certain cases. However, in this particular case, I believe that the intent was to simply avoid pushing important equipment items into the second f5 page when the list became too long. Cholmondely's finding plus issue #70 both seem to point towards that direction.
Even better. Then the reason for such code is known.
How about we add such thoughts/answers into comments, maybe comments that are recognized by Doxygen? With that answers to such questions are visible where they arise - also for future developers.
Sunshine - Moonlight - Good Times - Oolite
Post Reply