45° rotated rectangle clearing / leveling patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Post by NukeBuster »

The compiler warnings about viewport.cpp are now fixed, Thanks to Eddi(irc, don't know forum nick.)

Please test this patch. Also please give me some feedback on the code.

Patched against r10414
Attachments
diagonal_demolish_and_leveling_r10414_177.patch
(21.76 KiB) Downloaded 159 times
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
r_a_s_robin
Engineer
Engineer
Posts: 11
Joined: 17 Jan 2007 12:06

Post by r_a_s_robin »

Is there anyway to apply this patch to 0.5.2?
I'm not a code expert but i have seen that some copy-paste tool could just be installed without compiling or anything like that. Maybe something like that is possible for this great patch as well?
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Post by belugas »

r_a_s_robin wrote:Is there anyway to apply this patch to 0.5.2?
I'm not a code expert but i have seen that some copy-paste tool could just be installed without compiling or anything like that. Maybe something like that is possible for this great patch as well?
A patch, in this context, means a difference on the source code level. Not an executable that can modify the binary of the 0.5.2.
So, no, this cannot be applied without a full recompilation of the code-source of 0.5.2.
Furthermore, 0.5.2 is an older version of the code, still written in C, while this patch is aimed for C++ in trunk. So, unless the author adapt it for the 0.5.2 environnement, not a chance.
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
r_a_s_robin
Engineer
Engineer
Posts: 11
Joined: 17 Jan 2007 12:06

Post by r_a_s_robin »

When will it be in the nightly versions?
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

r_a_s_robin wrote:When will it be in the nightly versions?
It's got to be added to trunk first, then you have to wait until 19:00 GMT for the nightly to be built.
We Am De Best

Host of ThroughTheTube site
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Post by belugas »

r_a_s_robin wrote:When will it be in the nightly versions?
When we decide it can be included in trunk.
When we think it is ready for trunk.
When we are sure it will not break anything.
When we'll have time to evaluate the code and
when we'll have time to merge it.
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by NukeBuster »

Just an revision update.

Flyspray
Attachments
diagonal_demolish_and_leveling_r10644.patch
(21.58 KiB) Downloaded 147 times
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by belugas »

Little note :

Code: Select all

+	if (((fx >= 0 && xx <= fx && xx >= 0) || (fx < 0 && xx >= fx && xx <= 0)) &&
+			((fy >= 0 && yy <= fy && yy >= 0) || (fy < 0 && yy >= fy && yy <= 0))) {
+		return true;
+	} else {
+		return false;
could very well be cleaner with

Code: Select all

+	return ((fx >= 0 && xx <= fx && xx >= 0) || (fx < 0 && xx >= fx && xx <= 0)) &&
+			((fy >= 0 && yy <= fy && yy >= 0) || (fy < 0 && yy >= fy && yy <= 0));
Another note :

Code: Select all

ex >= sx ? x += 1 : x -= 1;
could be made the same as

Code: Select all

curh += (curh > h) ? -1 : 1;
If you see what i mean :)

Watch out, there are roaming tabs here and there

I still like that patch ;)
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by NukeBuster »

I've implemented your coding suggestions and am looking through the code to eliminate all the instances.

There is one thing troubeling me, there are 3 or 4 parts in the code that are almost the same... I'm looking into if it is worth making a function.
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: 45° rotated rectangle clearing / leveling patch

Post by Bilbo »

NukeBuster wrote:I've implemented your coding suggestions and am looking through the code to eliminate all the instances.

There is one thing troubeling me, there are 3 or 4 parts in the code that are almost the same... I'm looking into if it is worth making a function.
Definitely. Though if it is called often, it may possibly be worthy to declare it as inline function, which will essentially instruct the compliler to fut the function code directly where the function was called, saving the call.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by belugas »

Might be a big inline... We are not too fund of big inline functions...
And definitively not macros too ;)
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: 45° rotated rectangle clearing / leveling patch

Post by Bilbo »

Well, if it is big, then make it ordinary function - not inline. Basically, the difference in source is just having/not having inline keyword (+ some conventions that inline functions have to be in headers, non-inline not (only declaration should be there), which can be solved by simply moving the function around :)), though the generated binary is then quite different fopr inline/non-inline case;)

Inline is good for very small functions like "return m[x].something" where the call overhead would be large.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by NukeBuster »

The function will replace code in viewport.cpp, landscape.cpp and cmd_clear.cpp in which file should the function reside?
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: 45° rotated rectangle clearing / leveling patch

Post by Bilbo »

Depends on what the function does - it should be put near "similar" functions. If unsure, I'd stick the function body probably in landscape.cpp, and its declaration in landscape.h as I think it would be probably the correct place for it. It can be easily moved if necessary, after all :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
mamuf
Engineer
Engineer
Posts: 33
Joined: 30 Mar 2007 21:31
Location: Prague, CZ

Re: 45° rotated rectangle clearing / leveling patch

Post by mamuf »

Is this patch network-compatible with vanilla nightly?
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: 45° rotated rectangle clearing / leveling patch

Post by Bilbo »

mamuf wrote:Is this patch network-compatible with vanilla nightly?
As I looked in the patch - since it modifies the network protocol for leveling and clearing area by adding flag for dialognal clear ... no. Unfortunately, it is not network compatible - i.e. both you and server either need to have or have not the patch.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by NukeBuster »

Thanks for the help on the function. I am still looking into that.

Updated the patch to the latest nightly(r10684). No new features or big code changes were added.
Attachments
diagonal_demolish_and_leveling_r10684.patch
(21.54 KiB) Downloaded 175 times
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: 45° rotated rectangle clearing / leveling patch

Post by belugas »

Looks really better :)
But indeed, still that code duplication that is irritating (not your fault, by the way)...
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
CobraA1
Route Supervisor
Route Supervisor
Posts: 480
Joined: 07 Nov 2003 17:52
Location: USA

Re: 45° rotated rectangle clearing / leveling patch

Post by CobraA1 »

could very well be cleaner with
Shorter yes - I dunno about "cleaner" though - his code makes the return value obviously a boolean, and your code is a bit less obvious.
"If a man does not keep pace with his companions, perhaps it is because he hears a different drummer. Let him step to the music he hears, however measured or far away" --Henry David Thoreau
Aydan
Traffic Manager
Traffic Manager
Posts: 199
Joined: 28 Feb 2003 14:49
Location: Germany

Re: 45° rotated rectangle clearing / leveling patch

Post by Aydan »

belugas wrote:Little note :

Code: Select all

+	if (((fx >= 0 && xx <= fx && xx >= 0) || (fx < 0 && xx >= fx && xx <= 0)) &&
+			((fy >= 0 && yy <= fy && yy >= 0) || (fy < 0 && yy >= fy && yy <= 0))) {
+		return true;
+	} else {
+		return false;
could very well be cleaner with

Code: Select all

+	return ((fx >= 0 && xx <= fx && xx >= 0) || (fx < 0 && xx >= fx && xx <= 0)) &&
+			((fy >= 0 && yy <= fy && yy >= 0) || (fy < 0 && yy >= fy && yy <= 0));
CobraA1 wrote: Shorter yes - I dunno about "cleaner" though - his code makes the return value obviously a boolean, and your code is a bit less obvious.
What's the return value of || or && ? Obviously boolean, since they're logic operators, so no need for the if. Everything else is just cosmetics i think.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 4 guests