News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

[Patch] Slight change to code for reading vehicles

Started by jamespetts, January 02, 2009, 09:10:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jamespetts

Attached is a small patch that changes the if/else if statement dealing with the version numbers in vehicle_reader.cc for a switch/case statement. There are three reasons for this, which are, in ascending order of importance: (1) switch/case statements are neater than if/else if statements when there are multiple alternatives; (2) switch/case statements execute slightly more quickly than if/else if statements; and (3) by using the "default" operator above the highest current version number (currently 8) and adding no code so that it falls through to 8, any version higher than 8 will be able to be read as if it were version 8 (rather than version 0, which now has explicit code), making Simutrans's vehicles forwards compatible with future versions of Makeobj (although, obviously, without the new features). From my understanding of the present code, if, for example, a version 9 object was read, it would be treated as a version 0 object, and none of the features introduced between versions 1 and 8 would be read.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

No, if a future version is read, it should give an error (a fatal one), because the meaning of the fields is unknown. Often field are removed or added or the bit size is changed. LIke the engine type for version==2 compared to version==1

Also switch is not neccessarily faster (and this is anyway not releavant for speed) nor it is easier to see, for me at least.

jamespetts

Hmm... wouldn't that cause problems if ever anyone created a branch and wanted paksets with branch specific features also to work with the default version (ignoring those features)?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.