This system consists of 7 functions:

  • BeginSave(int iVersion);
  • // Saves current version
  • EndSave(void);
  • // End of a saving process
  • Save(Value);
  • // Save one value
  • BeginLoad(void);
  • // Loads file version
  • EndLoad(void);
  • // End of a loading process
  • Load(int iVersion, Value);
  • // Compares the versions in file and code, then loads value
  • Skip(int iStartVer, int iEndVer, Value);
  • // Skips one value in file

     

     

     

     

     

    Useage:

    • Save

    BeginSave(iVerCurrent);
        Save(Value);
    EndSave();

    • Load

    Initialize(Value);
    BeginLoad(void);
        Load(iVerSaved, Value);
    EndLoad(void);

    Use Case:

    • Version 0

    Save Load

    BeginSave(0);
        Save(a);
    EndSave();

    Initialize(a);
    BeginLoad(void);
        Load(0, a);
    EndLoad(void);

    • Version 1(Add a New Variable)

    Save Load

    BeginSave(1);
        Save(a);
        Save(b);
    EndSave();

    Initialize(a, b);
    BeginLoad(void);
        Load(0, a);
        Load(1, b); // See Comment
    EndLoad(void);

    Comment  
    Load(1, b); The saving version of variable b is 1.
    When loading version 0 file, this call will do nothing.

    • Version 2(Add a New Variable)

    Save Load

    BeginSave(2);
        Save(a);
        Save(b);
        Save(c);
    EndSave();

    Initialize(a, b, c);
    BeginLoad(void);
        Load(0, a);
        Load(1, b);
        Load(2, c); // See Comment
    EndLoad(void);

    Comment  
    Load(2, c); The saving version of variable b is 1.
    When loading version 0 file, this call will do nothing.

    • Version 3(Remove a variable)

    Save Load

    BeginSave(3);
        Save(a);
        Save(c);
    EndSave();

    Initialize(a, c);
    BeginLoad(void);
        Load(0, a);
        Skip(1, 2,  b); // See Comment
        Load(2, c);
    EndLoad(void);

    Comment  
    Skip(1, 2,  b);
    • When loading file version 1 to 2, This call will load the value
      then throw it away.
    • When loading other versions, it will do nothing.

    • Version 4(Reuse a variable)

    Save Load

    BeginSave(4);
        Save(a);
        Save(c);
        Save(b);
    EndSave();

    Initialize(a, b, c);
    BeginLoad(void);
        Load(0, a);
        Skip(1, 2, b);
        Load(2, c);
        Load(4, b);
    EndLoad(void);

    創作者介紹
    創作者 Duke Rabbit's Game Zone 的頭像
    lijy

    Duke Rabbit's Game Zone

    lijy 發表在 痞客邦 留言(0) 人氣( 23 )