Example #1
0
  //
  // Save from the Var Scope into the FScope
  //
  void Save(FScope *fScope, VarSys::VarScope *vScope)
  {
    // Add all of the items in this vScope to the fScope
    BinTree<VarSys::VarItem>::Iterator i(&vScope->items);
    for (!i; *i; i++)
    {
      switch ((*i)->type)
      {
        case VarSys::VI_SCOPE:
        {
          // Add this scope to the fScope
          FScope *sScope = fScope->AddFunction("VarScope");
          sScope->AddArgString((*i)->itemId.str);
          Save(sScope, (*i)->scope.ptr);
          break;
        }

        case VarSys::VI_INTEGER:
        {
          FScope *sScope = fScope->AddFunction("VarInteger");
          sScope->AddArgString((*i)->itemId.str);
          sScope->AddArgInteger((*i)->Integer());
          break;
        }

        case VarSys::VI_FPOINT:   
        {
          FScope *sScope = fScope->AddFunction("VarFloat");
          sScope->AddArgString((*i)->itemId.str);
          sScope->AddArgFPoint((*i)->Float());
          break;
        }

        case VarSys::VI_STRING:
        {
          FScope *sScope = fScope->AddFunction("VarString");
          sScope->AddArgString((*i)->itemId.str);
          sScope->AddArgString((*i)->Str());
          break;
        }

        case VarSys::VI_BINARY:
        {
          FScope *sScope = fScope->AddFunction("VarBinary");
          sScope->AddArgString((*i)->itemId.str);
          StdSave::TypeU32(sScope, "Size", (*i)->BinarySize());
          StdSave::TypeBinary(sScope, (*i)->BinarySize(), (*i)->Binary());
          break;
        }

        default:
          // We don't save anything else
          break;
      }
    }
  }
  //
  // SaveState
  //
  // Save state information
  //
  void Script::Manager::SaveState(FScope *scope)
  {
    // Save the recruit id
    StdSave::TypeU32(scope, "RecruitId", recruitId);

    // Save each script
    for (NBinTree<Script>::Iterator s(&scripts); *s; s++)
    {
      // Get the script
      Script *script = *s;

      // Create the scope
      FScope *sScope = scope->AddFunction("Script");

      // Add construction data as arguments
      sScope->AddArgString(script->GetName());
      sScope->AddArgString(script->GetConfigName());
      sScope->AddArgInteger(script->GetWeighting());
      sScope->AddArgInteger(script->GetPriority());

      // Save the script state data
      script->SaveState(sScope);
    }
  }
  //
  // SaveState
  //
  // Save state information
  //
  void Resource::Manager::SaveState(FScope *scope)
  {
    StdSave::TypeU32(scope, "ResourceId", resourceId);
    StdSave::TypeReaperList(scope, "ResourceTransports", resourceTransports);

    for (NBinTree<Resource, F32>::Iterator i(&resources); *i; i++)
    {
      // Create a new function
      FScope *sScope = scope->AddFunction("Resource");

      // Save the proximity key
      sScope->AddArgFPoint(i.GetKey());

      // Save the id
      sScope->AddArgInteger((*i)->GetId());

      // Save resource data
      (*i)->SaveState(sScope);
    }

  }