The International Simutrans Forum

 

Author Topic: [Patch] Slight change to code for reading vehicles  (Read 4154 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20918
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
[Patch] Slight change to code for reading vehicles
« on: January 02, 2009, 09:10:31 PM »
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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10829
  • Languages: De,EN,JP
Re: [Patch] Slight change to code for reading vehicles
« Reply #1 on: January 02, 2009, 10:45:16 PM »
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.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20918
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Slight change to code for reading vehicles
« Reply #2 on: January 02, 2009, 11:07:00 PM »
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)?