The International Simutrans Forum

Development => Patches & Projects => Topic started by: neroden on May 02, 2013, 03:50:32 PM

Title: Attempting to make fabrik_t connections link directly, not through plan_quadrat
Post by: neroden on May 02, 2013, 03:50:32 PM
So, I discovered that the factory suppliers and customers connections are connected, in the code, not to actual factories, but to *grid locations*.
 
 Hmm.
 
 This makes the code rather hairy and makes it substantially more difficult to keep track of things.  (It's obstructing my first attempt to alter the goods generation code in experimental.)
 
 By contrast, halts are currently actually directly connected to each other, via halthandle_t.  Now, what I would like to do is to have the factories directly connected to each other the same way.  I think this change would simplify matters immensely, and allow for a lot of cleanups.
 
 However, I'm not quite sure what needs to be done to make this work right.  It seems to me, based on what was done with haltestelle_t vs. halthandle_t, that it's not as simple as having pointers to fabrik_t.  I have to have handles which are persistent across saved games and across the network.
 
 I would appreciate information from someone who helped implement the halthandle_t type as to what needs to be done.
 
 Crossposted to standard development as this code cleanup would (theoretically) affect standard as well as experimental.

Edit:
If it is as simple as using fabrik_t*, let me know. 

For that matter, if it is as simple as using quickstone_tpl<fabrik_t>, I can also do that very quickly.  That should avoid a number of segmentation faults, relative to using direct pointers.
Title: Re: Attempting to make fabrik_t connections link directly, not through plan_quadrat
Post by: prissi on May 02, 2013, 09:43:12 PM
For loading and saving you can still use koord; actually, you must use koord, as there is a very good chance, that those factories do not yet exist during loading. When calling laden_abschliessen(), you can then convert the koord to pointers (same size, you may use a union ... )

Having said this, you should still consider handles, as this will save you all hassles with deleting factories and the like.