Loading

Paste #p9ycmrtfl

  1. /**
  2.  * Load the game elements from the input stream.
  3.  * @param ldr Input stream to load from.
  4.  * @note Order of loading should be the same as in #SaveElements.
  5.  */
  6. static void LoadElements(Loader &ldr)
  7. {
  8.     uint32 version = ldr.OpenBlock("FCTS");
  9.     if (version > 3) ldr.SetFailMessage("Bad file header");
  10.     ldr.CloseBlock();
  11.  
  12.     Loader reset_loader(nullptr);
  13.  
  14.     LoadDate(ldr);
  15.     _world.Load((version >= 3) ? ldr : reset_loader);
  16.     Random::Load(ldr);
  17.     _finances_manager.Load((version >= 2) ? ldr : reset_loader);
  18.  
  19.     if (reset_loader.IsFail()) ldr.SetFailMessage(reset_loader.GetFailMessage());
  20. }
  21.  
  22. /**
  23.  * Write the game elements to the output stream.
  24.  * @param svr Output stream to write to.
  25.  * @note Order of saving should be the same as in #LoadElements.
  26.  */
  27. static void SaveElements(Saver &svr)
  28. {
  29.     svr.StartBlock("FCTS", 3);
  30.     svr.EndBlock();
  31.  
  32.     SaveDate(svr);
  33.     _world.Save(svr);
  34.     Random::Save(svr);
  35.     _finances_manager.Save(svr);
  36. }

Comments