Page 1 of 1

Question about particular bit of source code

Posted: Fri Dec 08, 2023 10:32 pm
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.

Re: Question about particular bit of source code

Posted: Sat Dec 09, 2023 9:20 am
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.

Re: Question about particular bit of source code

Posted: Sat Dec 09, 2023 10:18 am
by phkb
Thanks a_c, I’ll have a good hard look at everything.

Re: Question about particular bit of source code

Posted: Sat Dec 09, 2023 6:23 pm
by Cholmondely
Stumbled across this: Default order of equipment on F5 (Dec 2013 - July 2014)

Re: Question about particular bit of source code

Posted: Sun Dec 10, 2023 6:38 am
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.

Re: Question about particular bit of source code

Posted: Sun Dec 10, 2023 8:11 am
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.

Re: Question about particular bit of source code

Posted: Sun Dec 10, 2023 9:17 am
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.