OpenTTD

Tasklist

FS#1161 - Make town_cmd a bit more readable

Attached to Project: OpenTTD
Opened by Benedikt Brüggemeier (skidd13) - Sunday, 26 August 2007, 10:03 GMT
Type Work in progress
Category Core
Status Closed
Assigned To Jean-Francois Claeys (Belugas)
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

I'm thinking over a partitial rewrite of the town_cmd cause the stuff in there is not for everyone readable. Therefor I started with the tile getting code. Hope someone of the dev's could improve my thoughts. ATM I'm working only in town_cmd.cpp. My plan is to get a nice readable(!!) and smaller code.

The directions used by the town growth are mirrored DiagDirections. IMO it would be nicer and cleaner to convert them to DiagDirections. That will cause a lot of work so I'd be pleased if someone would assist or even recode some parts.

This is what i've done so far.
This task depends upon

This task blocks these from closing
 FS#1207 - town builds non-connectible roads at hills 
Closed by  Jean-Francois Claeys (Belugas)
Wednesday, 12 September 2007, 23:56 GMT
Reason for closing:  Implemented
Additional comments about closing:  r11091 now bears the code you've patiently built.
Thanks
Comment by Benedikt Brüggemeier (skidd13) - Monday, 27 August 2007, 06:59 GMT
Did a few renamings,rearrangements and rewrites. Hope you like it.
Comment by Benedikt Brüggemeier (skidd13) - Monday, 27 August 2007, 19:05 GMT
Did some further work on the basic stuff.
Comment by Benedikt Brüggemeier (skidd13) - Tuesday, 28 August 2007, 20:08 GMT
So further suff is now at the patch. Now I need to move the int to DiagDir. Hope it's now better possible.
Fully rewritten IsNeighborRoadTile. Should increase performance.
Comment by Benedikt Brüggemeier (skidd13) - Wednesday, 29 August 2007, 20:23 GMT
This time I moved some subcode to functions. Converting the town growth to a abstract class in mind.

A side note the Functions to handle the TownGrowth directions are temporary.

My plans so far ATM:
1. Convert the int dir (dir is pos of the set bit in the planded roadbits) to a more native dir (DiagDir). I hope the code gets more readable then.
2. Convert the whole stuff to an abstract class where the growth is implementated diffrent for each layout (with growth I'm talking of "is this a nice tile to plant a road" and "which roadbits we want to plant here") The implementation of the target-tile algorithm (on which side the town grows further) will remain in the main class.

Point 2 needs some further thinking where to initiate the object and if we want to have one object for each town or one for each algorithm or one for all towns.
Comment by Benedikt Brüggemeier (skidd13) - Thursday, 30 August 2007, 19:17 GMT
Split off of the IsNeighborRoadTile optimisation. Another few "outsourced" parts will follow.
Comment by Benedikt Brüggemeier (skidd13) - Friday, 31 August 2007, 12:35 GMT
So next one is here: town bridge check and creation
Comment by Benedikt Brüggemeier (skidd13) - Friday, 31 August 2007, 14:09 GMT
Update (cause of r11015)
Comment by Benedikt Brüggemeier (skidd13) - Saturday, 01 September 2007, 00:13 GMT
Simplyfied the improved_IsNeighborRoadTile.patch
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 02 September 2007, 21:58 GMT
So part one is more or less done! :D
There is the need of optimisation now. But this should now be a smaller problem cause the code is more human readable now.

Patch should apply against 11039.
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 02 September 2007, 21:59 GMT
Oops I forgot to say that I'd like to hear some comments.
Optimisation proposals are very welcome.
Comment by Benedikt Brüggemeier (skidd13) - Monday, 03 September 2007, 17:20 GMT
1st Update of part1. Mainly optimisations and cleanup.
Comment by Benedikt Brüggemeier (skidd13) - Tuesday, 04 September 2007, 13:50 GMT
Updated comments and a missing NOT.
Comment by Benedikt Brüggemeier (skidd13) - Tuesday, 04 September 2007, 15:43 GMT
I thought a bit over the change to the TownGrowth object.
I made 2 graphs to see how the whole stuff is working ATM and will work as Object.
Comment by Benedikt Brüggemeier (skidd13) - Thursday, 06 September 2007, 21:36 GMT
Added a nicer solution for the grid algorithm.  FS#1207  should be solved partialy.
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 09 September 2007, 12:34 GMT
Sorry! Fixed some conditions that could cause the stop of town growth.
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 09 September 2007, 17:58 GMT
I noticed a bug of the current trunk and it appears also with my current patch applyed.
In the attached scenario there is a sign which marks a tile.
If you place a small town there it stops to grow immediately.
I'm working on it.
Comment by Remko Bijker (Rubidium) - Sunday, 09 September 2007, 18:16 GMT
You changed the maximum length of bridges by one (or rather, it tries to build a bridge one more time)
for (int i = -11; ++i != 0;) is not the same as for (int i = 0; i++ > 11;)
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 09 September 2007, 18:55 GMT
oops, thanks for the annotation.
Comment by Benedikt Brüggemeier (skidd13) - Sunday, 09 September 2007, 20:03 GMT
So fixed the bridge thing.
Comment by Benedikt Brüggemeier (skidd13) - Wednesday, 12 September 2007, 14:24 GMT
This should be the final version of part1.

Loading...