News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

simplification to rdwr-functions

Started by kniederk, June 29, 2010, 05:52:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kniederk

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

prissi

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.

kniederk

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

kniederk

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

Dwachs

Parsley, sage, rosemary, and maggikraut.