Post reply

Warning - while you were reading 62 new replies have been posted. You may wish to review your post.

Note: this post will not display until it's been approved by a moderator.

Name:
Email:
Subject:
Message icon:

shortcuts: hit alt+s to submit/post or alt+p to preview

Please read the rules before you post!


Topic Summary

Posted by: Steve Walmsley
« on: Today at 05:26:18 AM »

I don't want to turn this thread into a programming debate, which is one of the reasons that I rarely post code ;)

I hope that none of the other readers of this thread have been put out by our monopolization of the topic of discussion :)

Are you suggesting that instead of a new list, I use the LINQ without assigning to a new list as the target in the foreach loop?

If so, I prefer to avoid that. It's harder to read and harder to debug and those are more important to me than straight performance.

Yes, both the CurrentSystems and PossibleSystems variables would be IEnumerable<KnownSystem> instead of List<KnownSystem>. I can’t really see how the code would be more difficult to read, since everything else would be identical except that you would just not call ToList().

However, I suppose I know what you mean about debugging. You want to stop at a breakpoint and be able to view the lists in the debugger. I tend to forget that not everybody can use omniscient debugging yet (I use a debugger called Pernosco a lot, but it is for Linux only.) If I were using a regular debugger and I wanted to verify which systems had been in the final enumeration, I would add a conditional breakpoint inside the loop to print out some information about ks (the system name and number, for instance) and then continue execution. (In Pernosco you can do the same thing but you get all the information that would have been printed without having to actually run the program again.)

As for performance, if this code is just called once any time a fleet transits an unexplored jump point then it is probably irrelevant. Even though you make two whole copies of the list of systems (and you did just make that list significantly larger), that probably takes so little time that nobody will notice. But you might take a look to see if you have made this mistake in more important parts of the code. What is a very minor mistake here would be much more regrettable in the code that implements ship detection, for instance.

OK, I think I finally understand what you are driving at :)

I was concerned I would have the LINQ in the middle of the foreach statement, if I didn't assign it to a List() first and use that as the target for the foreach. Are you saying I could just replace the List<KnownSystem> = with  IEnumerable<KnownSystem> = , remove the ToList() and then use the IEnumerable as the target of the foreach. That would be the same in terms of readability and I assume I could check the contents of the IEnumerable instead of the List?

I basically picked up C# by writing it and figuring things out when I needed to, without any formal learning, so there will be gaps in my knowledge :)

So now you have made me curious, I started reading about it. Some people expressed a view that IEnumerable  only guarantees an enumeration and doesn't guarantee the order of execution (even if ordered beforehand). However, as I read it, its the same execution as list because the latter inherited the former. Which is correct?

EDIT

I just ran an experiment for the missile salvo list on the fleet window, which I just updated.

This is the ToList() version.

List<MissileSalvo> Salvos = Aurora.MissileSalvos.Values.Where(x => x.SalvoRace == this).OrderBy(x => x.SalvoSystem.SystemID).ThenBy(x => x.MissileSalvoID).ToList();

This is looped and various information is used to display missile salvos, using foreach (MissileSalvo ms in Salvos)

I then created a IEnumerable version of the same function

IEnumerable<MissileSalvo> Salvos = Aurora.MissileSalvos.Values.Where(x => x.SalvoRace == this).OrderBy(x => x.SalvoSystem.SystemID).ThenBy(x => x.MissileSalvoID);

I ran both functions several times and in every case, the List version is faster than the IEnumerable version. It may be that the IEnumerable is faster to create, but the List seems to be faster to use. Maybe because everything is preloaded into memory for the List, whereas the IEnumerable has to retrieve the information as needed.
Posted by: db48x
« on: Today at 02:01:39 AM »

I don't want to turn this thread into a programming debate, which is one of the reasons that I rarely post code ;)

I hope that none of the other readers of this thread have been put out by our monopolization of the topic of discussion :)

Are you suggesting that instead of a new list, I use the LINQ without assigning to a new list as the target in the foreach loop?

If so, I prefer to avoid that. It's harder to read and harder to debug and those are more important to me than straight performance.

Yes, both the CurrentSystems and PossibleSystems variables would be IEnumerable<KnownSystem> instead of List<KnownSystem>. I can’t really see how the code would be more difficult to read, since everything else would be identical except that you would just not call ToList().

However, I suppose I know what you mean about debugging. You want to stop at a breakpoint and be able to view the lists in the debugger. I tend to forget that not everybody can use omniscient debugging yet (I use a debugger called Pernosco a lot, but it is for Linux only.) If I were using a regular debugger and I wanted to verify which systems had been in the final enumeration, I would add a conditional breakpoint inside the loop to print out some information about ks (the system name and number, for instance) and then continue execution. (In Pernosco you can do the same thing but you get all the information that would have been printed without having to actually run the program again.)

As for performance, if this code is just called once any time a fleet transits an unexplored jump point then it is probably irrelevant. Even though you make two whole copies of the list of systems (and you did just make that list significantly larger), that probably takes so little time that nobody will notice. But you might take a look to see if you have made this mistake in more important parts of the code. What is a very minor mistake here would be much more regrettable in the code that implements ship detection, for instance.
Posted by: vorpal+5
« on: Today at 01:40:57 AM »

Transponders: are they always ON for civilian ships? Why would I want to keep them on, as it broadcasts their position to potential hostiles? And what would happen if I turned them off?
Posted by: Steve Walmsley
« on: Yesterday at 06:23:19 PM »

Huh. It may be that C# works differently than I expected, but the docs don’t indicate that the OrderBy method modifies the underlying list.

It's not the OrderBy, it is the Except that precedes it.

The documentation for Except doesn’t say that it modifies the list either. It is my understanding that none of the Enumerable methods modify the underlying data.

I don't want to turn this thread into a programming debate, which is one of the reasons that I rarely post code ;)

Are you suggesting that instead of a new list, I use the LINQ without assigning to a new list as the target in the foreach loop?

If so, I prefer to avoid that. It's harder to read and harder to debug and those are more important to me than straight performance.

If not, maybe DM me with an example of the code as you would write it.
Posted by: Caesar
« on: Yesterday at 03:59:02 PM »

Hi! It's been a while since I played, but I'm getting back into the game again. I wanted to read up on the mechanics, when I noticed the wiki doesn't work. I think I read that it may be a temporary issue but I couldn't find a good post on it. Does anyone have a clearer idea what's going on with the wiki?

Thanks in advance!
Posted by: db48x
« on: Yesterday at 12:32:37 PM »

Huh. It may be that C# works differently than I expected, but the docs don’t indicate that the OrderBy method modifies the underlying list.

It's not the OrderBy, it is the Except that precedes it.

The documentation for Except doesn’t say that it modifies the list either. It is my understanding that none of the Enumerable methods modify the underlying data.
Posted by: Steve Walmsley
« on: Yesterday at 09:33:38 AM »

How can I calculate Aphelion and Perihelion from the values in FCT_SystemBody?

                    sb.Perihelion = sb.OrbitalDistance * (1 - sb.Eccentricity);
                    sb.Aphelion = sb.OrbitalDistance * (1 + sb.Eccentricity);
                    sb.SemiMinorAxis = sb.OrbitalDistance * Math.Sqrt(1 - (sb.Eccentricity * sb.Eccentricity));
Posted by: skoormit
« on: Yesterday at 09:12:22 AM »

How can I calculate Aphelion and Perihelion from the values in FCT_SystemBody?
Posted by: Steve Walmsley
« on: Yesterday at 09:04:59 AM »

Huh. It may be that C# works differently than I expected, but the docs don’t indicate that the OrderBy method modifies the underlying list.

It's not the OrderBy, it is the Except that precedes it.
Posted by: db48x
« on: May 25, 2024, 04:47:58 PM »

I think I copied the code after fixing it.

Ah, that explains it. Fair enough.

I need a temporary list because I don't want to modify the KnownSystems list.

Huh. It may be that C# works differently than I expected, but the docs don’t indicate that the OrderBy method modifies the underlying list.
Posted by: Droll
« on: May 25, 2024, 03:16:20 PM »

I think I copied the code after fixing it.

Code duplication detected, billions must die.  ;D
Posted by: Steve Walmsley
« on: May 25, 2024, 11:46:11 AM »

Yes, you are correct.

Here is the relevant code:
 
Code: [Select]

PossibleSystems = KnownSystems.Values.Except(CurrentSystems).OrderBy(x => Math.Pow(x.X - StartSystem.RealSystem.X, 2.0) + Math.Pow(x.Y - StartSystem.RealSystem.Y, 2.0) + Math.Pow(x.Z - StartSystem.RealSystem.Z, 2.0)).ToList();


The + should be -, as you stated above. Its been like this since C# launched and you are the first person to figure it out :)

I think correcting it is better than leaving as is, as it will be easier to understand what is happening.

Am I missing something? That looks like the right distance formula to me, with minus signs in the correct place.

As an aside, are you sure that you need to call ToList() there? OrderBy returns an IOrderedEnumerable, which you can directly enumerate over with a foreach loop. Calling ToList() will allocate a new List and copy the (sorted) elements into it. Then after the loop the List will be thrown away. Seems like wasted effort, but I have only a passing acquaintance with C# and could be wrong.

I think I copied the code after fixing it.

I need a temporary list because I don't want to modify the KnownSystems list.
Posted by: skoormit
« on: May 25, 2024, 09:20:56 AM »

Is it the fleet commander's logistic used, or does each ship have its own schedule and speed based on the logistics of its captain?
I recall fleet members being un/loaded in series so every bonus for every ship helps. An unfortunate reality which sacrifices efficiency for reduced micromanagement. It would make me very happy to be proven wrong on this point so please do if able.

Get ready to be happy.
Ships in a fleet load in parallel, and the overall load/unload time of the fleet is just the maximum time of any single ship in the fleet.
Ship commanders only modify the time for their own ship.
Therefore, in a fleet where all the ships have the same unmodified load/unload time, the net time bonus will be based on the ship commander with the smallest logistics bonus (and other bonus sources, as usual).
Posted by: kyonkundenwa
« on: May 25, 2024, 01:41:31 AM »

Reading Steve's note, I'm not sure if this is a drawback or a bonus to have a small hydro extent? It seems to contribute to CC but so it's a problem?
Yes. The CC penalty is 2 at 0% at 0 at 20%.

Is it the fleet commander's logistic used, or does each ship have its own schedule and speed based on the logistics of its captain?
I recall fleet members being un/loaded in series so every bonus for every ship helps. An unfortunate reality which sacrifices efficiency for reduced micromanagement. It would make me very happy to be proven wrong on this point so please do if able.

What would an EXO on an orbital miner or jumpgate constructor do? It seems to do nothing so far for me, so perhaps I'm missing something!
Nothing as far as I know. With all surveyors being military vessels in C+ I don't think any of the extra control spaces will meaningfully contribute to commercial vessels. Perhaps commercial vessels that find themselves in combat situations such as [drop] troop transports could benefit from the training bonus of the Auxiliary Control or the engineering bonus of the Main Engineering but overall it doesn't seem worth it.
Posted by: vorpal+5
« on: May 25, 2024, 12:57:15 AM »

Does water do anything special for the planet, to have some?

Hydro extent (or lack thereof) contributes to colony cost if not above 20% and liquid: https://aurora2.pentarch.org/index.php?topic=8495.msg101987#msg101987

Above 75% hydro extent the population capacity of the body starts to suffer: https://aurora2.pentarch.org/index.php?topic=8495.msg100078#msg100078

Reading Steve's note, I'm not sure if this is a drawback or a bonus to have a small hydro extent? It seems to contribute to CC but so it's a problem?

Questions:
When you have a fleet with several commanders having a logistic bonus, how is it factored when unloading stuff? Is it the fleet commander's logistic used, or does each ship have its own schedule and speed based on the logistics of its captain? This means that for a fleet of many freighters, chances are you end up with a 0% bonus.

What would an EXO on an orbital miner or jumpgate constructor do? It seems to do nothing so far for me, so perhaps I'm missing something!