The International Simutrans Forum

 

Author Topic: simplification to rdwr-functions  (Read 1739 times)

0 Members and 1 Guest are viewing this topic.

Offline kniederk

  • *
  • Posts: 17
simplification to rdwr-functions
« on: June 29, 2010, 05:52:28 PM »
A rather simple patch that removes the second argument from most of the rdwr-methods in the load_save-class.  The char-array provided was not used at all (I guess some syntax from the past).

Additionally I have split up the load_save-methods into save- and load-methods, because I thought that it is easier to understand something like

===================================
save_byte()
{
  if (xml)
    write_to_file_as_xml
  else
    write_to_file_as_binary
}

load_byte()
{
  if (xml)
    read_from_file_as_xml
  else
    read_from_file_as_binary
}

rdwr_byte()
{
  if(saving)
    save_byte;
  else
   load_byte;
}
=================================================

instead of

=================================================


rdwr_byte()
{
  if (xml)
  {
    if(saving)
      write_to_file_as_xml
    else
      read_from_file_as_xml
  }
  else
  {
     if (saving)
       write_to_file_as_binary
    else
       read_from_file_as_binary
  }
}

=================

The improvement by last change is of course arguable.  Just a suggestion, and I could well accept if you were not interested.

Klaus

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10818
  • Languages: De,EN,JP
Re: simplification to rdwr-functions
« Reply #1 on: June 29, 2010, 07:03:41 PM »
The rdwr function have the advantage, that for most stuff nothing needs to take care if it is saved or loaded. The idea is, that the reading and loading is done at the same place in the same order. Using the same function is a good way to avoid errors.

The superflous second parameter stems from the very old text/binary savegame format, which was broken anyway since several versions. This should indeed go.

Offline kniederk

  • *
  • Posts: 17
Re: simplification to rdwr-functions
« Reply #2 on: June 29, 2010, 09:30:38 PM »
I don't mean necessarily to remove the rdrw-functions,  if you want you could even declare the new methods private, and just use them internally in the loadsave-class.  Within this file, I certainly believe that they increase readability, but up to you...

Klaus

Offline kniederk

  • *
  • Posts: 17
Re: simplification to rdwr-functions
« Reply #3 on: July 03, 2010, 09:17:23 AM »
ok, here is a new version of the patch, where I did not split up the rdwr_methods in loadsagegame.cc, but I only removed the last argument of all of these methods.

Klaus

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4897
  • Languages: EN, DE, AT
Re: simplification to rdwr-functions
« Reply #4 on: July 27, 2010, 02:43:40 PM »
thank you. incorporated in 3560.