Since no one really seemed to properly understand WHY changing 0 to 4 would make any difference I continued to mull over the matter. I added the following debug output lines to simhalt.cc:
(It might be that the %i-casting done by the DBG_MESSAGE is confusing the whole issue... in which case I apologize for taking up your time)
uint8 current_rotation = welt->get_einstellungen()->get_rotation();
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "Current rotation %i.", current_rotation);
current_rotation = 0-welt->get_einstellungen()->get_rotation();
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "0-xx: %i.", current_rotation);
current_rotation = (0-welt->get_einstellungen()->get_rotation())%4;
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "%4: %i.", current_rotation);
current_rotation = welt->get_einstellungen()->get_rotation();
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "Current rotation %i.", current_rotation);
current_rotation = 4-welt->get_einstellungen()->get_rotation();
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "4-xx: %i.", current_rotation);
current_rotation = (0-welt->get_einstellungen()->get_rotation())%4;
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "%4: %i.", current_rotation);
When placing a stop on an unrotated map this gives the following output:Message: simhalt.cc::haltestelle_t::create_name: Current rotation 0.
Message: simhalt.cc::haltestelle_t::create_name: 0-xx: 0.
Message: simhalt.cc::haltestelle_t::create_name: %4: 0.
Message: simhalt.cc::haltestelle_t::create_name: Current rotation 0.
Message: simhalt.cc::haltestelle_t::create_name: 4-xx: 4.
Message: simhalt.cc::haltestelle_t::create_name: %4: 0.
That is the result of 0- and 4- are identical. However, when placing the bus stop on a rotated map, I get the following output:Message: simhalt.cc::haltestelle_t::create_name: Current rotation 1.
Message: simhalt.cc::haltestelle_t::create_name: 0-xx: 255.
Message: simhalt.cc::haltestelle_t::create_name: %4: 255.
Message: simhalt.cc::haltestelle_t::create_name: Current rotation 1.
Message: simhalt.cc::haltestelle_t::create_name: 4-xx: 3.
Message: simhalt.cc::haltestelle_t::create_name: %4: 3.
That is, with a 4 I get the expected '3' from modulo, but with 0 it does not work.
Just for comparison, I then tested with declaring current_rotation as a plain int, and with an explicitly set sint8, instead, and then (for both at least - getting very suspicious of the int-types right now!) I get the following output on a rotated map:Message: simhalt.cc::haltestelle_t::create_name: Current rotation 1.
Message: simhalt.cc::haltestelle_t::create_name: 0-xx: -1.
Message: simhalt.cc::haltestelle_t::create_name: %4: -1.
Message: simhalt.cc::haltestelle_t::create_name: Current rotation 1.
Message: simhalt.cc::haltestelle_t::create_name: 4-xx: 3.
Message: simhalt.cc::haltestelle_t::create_name: %4: 3.
That is again modulo is broken with 0-
So finally I got a "bit" exasperated and decided to do a "force test". I added the following debug output:uint8 forcetest_u = 0;
forcetest_u = forcetest_u - 1;
sint8 forcetest_s = forcetest_u;
DBG_MESSAGE("simhalt.cc::haltestelle_t::create_name", "Force test: u = %i / %i ; s = %i / %i", forcetest_u, forcetest_u%4, forcetest_s, forcetest_s%4);
which yielded the following output:Message: simhalt.cc::haltestelle_t::create_name: Force test: u = 255 / 3 ; s = -1 / -1
which I interpret (and this might very well be totally wrong) as that modulo on a uint8 works fine, but if it is cast to a signed integer, whether explicitly by sint8 or implicitly by being subtracted from a plain numeral (0-...), will result in modulo on a negative number, which in turn fails.
The thing is... that as far as I can tell from the above, it is no longer a uint8 when the modulo is applied.
I am sorry for such a long and hard to read post.
--
Stats: debian/squeeze, gcc 4.3.3, Source: modified svn up from 2009-06-04, compiled with debug 3 (compiled once with optimisations and then a clean build without them, both show same behaviour)
EDIT: The conclusion of this test, which I forgot to include *blush*, is that the modification of 0- to 4- is insufficient, since the same error may occur with 1-, 2- as well (if the rotation is larger than the numeral). Perhaps a explicit cast such as dirname = diagonal_name[((uint8) 0-welt->get_einstellungen()->get_rotation())%4];
could be used, but I have no idea how that would impact performance.