⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p_saveg.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 5 页
字号:
{  short *short_p;  int i;  int num_variables;    //CheckSaveGame(sizeof(short) * 8); // room for 8 shorts    short_p = (short *) save_p;  *short_p++ = rs->script->scriptnum;      // save scriptnum  *short_p++ = rs->savepoint - rs->script->data; // offset  *short_p++ = rs->wait_type;  *short_p++ = rs->wait_data;    // save pointer to trigger using prev  *((ULONG *)short_p)++ = (ULONG)rs->trigger;    // count number of variables  num_variables = 0;  for(i=0; i<VARIABLESLOTS; i++)    {      svariable_t *sv = rs->variables[i];      while(sv && sv->type != svt_label)        {          num_variables++;          sv = sv->next;        }    }  *short_p++ = num_variables;  save_p = (char *)short_p;    // save num_variables    // store variables  // go thru hash chains, store each variable  for(i=0; i<VARIABLESLOTS; i++)    {      // go thru this hashchain      svariable_t *sv = rs->variables[i];            // once we get to a label there can be no more actual      // variables in the list to store      while(sv && sv->type != svt_label)        {                    //CheckSaveGame(strlen(sv->name)+10); // 10 for type and safety                    // write svariable: name                    strcpy(save_p, sv->name);          save_p += strlen(sv->name) + 1; // 1 extra for ending NULL                          // type          *save_p++ = sv->type;   // store type;                    switch(sv->type)        // store depending on type            {            case svt_string:              {                //CheckSaveGame(strlen(sv->value.s)+5); // 5 for safety                strcpy(save_p, sv->value.s);                save_p += strlen(sv->value.s) + 1;                break;              }            case svt_int:              {                long *long_p;                                //CheckSaveGame(sizeof(long)+4);                 long_p = (long *) save_p;                *long_p++ = sv->value.i;                save_p = (char *)long_p;                break;              }            case svt_mobj:              {                ULONG *long_p;                                //CheckSaveGame(sizeof(long)+4);                 long_p = (ULONG *) save_p;                *long_p++ = (ULONG)sv->value.mobj;                save_p = (char *)long_p;                break;              }            case svt_fixed:              {                fixed_t *fixed_p;                fixed_p = (fixed_t *)save_p;                *fixed_p++ = sv->value.fixed;                save_p = (char *)fixed_p;                break;              }            // others do not appear in user scripts                        default:              break;            }                    sv = sv->next;        }    }}// get the next runningscriptrunningscript_t *P_UnArchiveRunningScript(){  int i;  int scriptnum;  int num_variables;  runningscript_t *rs;  // create a new runningscript  rs = new_runningscript();    {    short *short_p = (short*) save_p;        scriptnum = *short_p++;        // get scriptnum        // levelscript?    if(scriptnum == -1)      rs->script = &levelscript;    else      rs->script = levelscript.children[scriptnum];        // read out offset from save    rs->savepoint = rs->script->data + (*short_p++);    rs->wait_type = *short_p++;    rs->wait_data = *short_p++;    // read out trigger thing    rs->trigger = FindNewPosition((mobj_t *)(READULONG(short_p)));        // get number of variables    num_variables = *short_p++;    save_p = (char*) short_p;      // restore save_p  }    // read out the variables now (fun!)    // start with basic script slots/labels    for(i=0; i<VARIABLESLOTS; i++)    rs->variables[i] = rs->script->variables[i];    for(i=0; i<num_variables; i++)    {      svariable_t *sv = Z_Malloc(sizeof(svariable_t), PU_LEVEL, 0);      int hashkey;            // name      sv->name = Z_Strdup(save_p, PU_LEVEL, 0);      save_p += strlen(sv->name) + 1;            sv->type = *save_p++;            switch(sv->type)        // read depending on type        {        case svt_string:          {            sv->value.s = Z_Strdup(save_p, PU_LEVEL, 0);            save_p += strlen(sv->value.s) + 1;            break;          }        case svt_int:          {            long *long_p = (long *) save_p;            sv->value.i = *long_p++;            save_p = (char *)long_p;            break;          }        case svt_mobj:          {            ULONG *long_p = (ULONG *) save_p;            sv->value.mobj = FindNewPosition((mobj_t *)long_p);            save_p = (char *)long_p;            break;          }        case svt_fixed:          {            fixed_t *fixed_p = (fixed_t *)save_p;            sv->value.fixed = *fixed_p++;            save_p = (char *)fixed_p;            break;          }        default:          break;        }            // link in the new variable      hashkey = variable_hash(sv->name);      sv->next = rs->variables[hashkey];      rs->variables[hashkey] = sv;    }    return rs;}// archive all runningscripts in chainvoid P_ArchiveRunningScripts(){  long *long_p;  runningscript_t *rs;  int num_runningscripts = 0;    // count runningscripts  for(rs = runningscripts.next; rs; rs = rs->next)    num_runningscripts++;    //CheckSaveGame(sizeof(long));    // store num_runningscripts  long_p = (long *) save_p;  *long_p++ = num_runningscripts;  save_p = (char *) long_p;            // now archive them  rs = runningscripts.next;  while(rs)    {      P_ArchiveRunningScript(rs);      rs = rs->next;    }    long_p = (long *) save_p;}// restore all runningscripts from save_pvoid P_UnArchiveRunningScripts(){  runningscript_t *rs;  long *long_p;  int num_runningscripts;  int i;    // remove all runningscripts first : may have been started  // by levelscript on level load    clear_runningscripts();     // get num_runningscripts  long_p = (long *) save_p;  num_runningscripts = *long_p++;  save_p = (char *) long_p;            for(i=0; i<num_runningscripts; i++)    {      // get next runningscript      rs = P_UnArchiveRunningScript();            // hook into chain      rs->next = runningscripts.next;      rs->prev = &runningscripts;      rs->prev->next = rs;      if(rs->next)        rs->next->prev = rs;    }}void P_ArchiveScripts(){#ifdef FRAGGLESCRIPT  // save levelscript  P_ArchiveLevelScript();  // save runningscripts  P_ArchiveRunningScripts();  // Archive the script camera.  WRITELONG(save_p, (long)script_camera_on);  WRITEULONG(save_p, (ULONG)script_camera.mo);  WRITEANGLE(save_p, script_camera.aiming);  WRITEFIXED(save_p, script_camera.viewheight);  WRITEANGLE(save_p, script_camera.startangle);#endif}void P_UnArchiveScripts(){#ifdef FRAGGLESCRIPT  // restore levelscript  P_UnArchiveLevelScript();  // restore runningscripts  P_UnArchiveRunningScripts();  // Unarchive the script camera  script_camera_on         = (boolean)READLONG(save_p);  script_camera.mo         = FindNewPosition((mobj_t *)(READULONG(save_p)));  script_camera.aiming     = READANGLE(save_p);  script_camera.viewheight = READFIXED(save_p);  script_camera.startangle = READANGLE(save_p);#endif  P_FinishMobjs();}// =======================================================================//          Misc// =======================================================================void P_ArchiveMisc(){    ULONG pig=0;    int i;    WRITEBYTE ( save_p, gameskill);    WRITEBYTE ( save_p, gameepisode);    WRITEBYTE ( save_p, gamemap);    for (i=0 ; i<MAXPLAYERS ; i++)        pig |= (playeringame[i] != 0)<<i;    WRITEULONG( save_p, pig );    WRITEULONG( save_p, leveltime );    WRITEBYTE ( save_p, P_GetRandIndex());}boolean P_UnArchiveMisc(){    ULONG pig;    int i;    gameskill   = READBYTE(save_p);    gameepisode = READBYTE(save_p);    gamemap     = READBYTE(save_p);    pig         = READULONG(save_p);    for (i=0 ; i<MAXPLAYERS ; i++)    {        playeringame[i] = (pig & (1<<i))!=0;        players[i].playerstate = PST_REBORN;    }    if( !P_SetupLevel (gameepisode, gamemap, gameskill, NULL) )        return false;    // get the time    leveltime = READULONG(save_p);    P_SetRandIndex(READBYTE(save_p));    return true;}void P_SaveGame (void){    CV_SaveNetVars((char**)&save_p);    P_ArchiveMisc();    P_ArchivePlayers ();    P_ArchiveWorld ();    P_ArchiveThinkers ();    P_ArchiveSpecials ();    P_ArchiveScripts ();        WRITEBYTE( save_p, 0x1d);           // consistancy marker}boolean P_LoadGame (void){    CV_LoadNetVars((char**)&save_p);    if( !P_UnArchiveMisc() )        return false;    P_UnArchivePlayers ();    P_UnArchiveWorld ();    P_UnArchiveThinkers ();    P_UnArchiveSpecials ();    P_UnArchiveScripts ();    return READBYTE(save_p)==0x1d;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -