Example #1
0
//
// I_Quit
//
// Primary atexit routine for shutting down the game engine.
//
void I_Quit(void)
{
   has_exited = 1;   /* Prevent infinitely recursive exits -- killough */
   
   // haleyjd 06/05/10: not in fatal error situations; causes heap calls
   if(error_exitcode < I_ERRORLEVEL_FATAL && demorecording)
      G_CheckDemoStatus();
   
   // sf : rearrange this so the errmsg doesn't get messed up
   if(error_exitcode >= I_ERRORLEVEL_MESSAGE)
      puts(errmsg);   // killough 8/8/98
   else
      I_EndDoom();

   // SoM: 7/5/2002: Why I didn't remember this in the first place I'll never know.
   // haleyjd 10/09/05: moved down here
   SDL_Quit();

   // haleyjd 03/18/10: none of these should be called in fatal error situations.
   //         06/06/10: check each call, as an I_FatalError called from any of this
   //                   code could escalate the error status.

   IFNOTFATAL(M_SaveDefaults());
   IFNOTFATAL(M_SaveSysConfig());
   IFNOTFATAL(G_SaveDefaults()); // haleyjd
   
#ifdef _MSC_VER
   // Under Visual C++, the console window likes to rudely slam
   // shut -- this can stop it, but is now optional except when an error occurs
   if(error_exitcode >= I_ERRORLEVEL_NORMAL || waitAtExit)
   {
      puts("Press any key to continue\n");
      getch();
   }
#endif
}
Example #2
0
void G_PlayDemo(const char* name) {
    int i;
    int p;
    char filename[256];

    gameaction = ga_nothing;
    endDemo = false;

    p = M_CheckParm("-playdemo");
    if(p && p < myargc-1) {
        // 20120107 bkw: add .lmp extension if missing.
        if(dstrrchr(myargv[p+1], '.')) {
            dstrcpy(filename, myargv[p+1]);
        }
        else {
            dsprintf(filename, "%s.lmp", myargv[p+1]);
        }

        CON_DPrintf("--------Reading demo %s--------\n", filename);
        if(M_ReadFile(filename, &demobuffer) == -1) {
            gameaction = ga_exitdemo;
            return;
        }

        demo_p = demobuffer;
    }
    else {
        if(W_CheckNumForName(name) == -1) {
            gameaction = ga_exitdemo;
            return;
        }

        CON_DPrintf("--------Playing demo %s--------\n", name);
        demobuffer = demo_p = W_CacheLumpName(name, PU_STATIC);
    }
    
    if(strncmp((char*)demo_p, "DM64", 4)) {
        I_Error("G_PlayDemo: Mismatched demo header");
        return;
    }

    G_SaveDefaults();

    demo_p++;
    demo_p++;
    demo_p++;
    demo_p++;
    demo_p++;

    startskill      = *demo_p++;
    startmap        = *demo_p++;
    deathmatch      = *demo_p++;
    respawnparm     = *demo_p++;
    respawnitem     = *demo_p++;
    fastparm        = *demo_p++;
    nomonsters      = *demo_p++;
    consoleplayer   = *demo_p++;
    
    rngseed  = *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    
    gameflags  = *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    
    compatflags  = *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;

    for(i = 0; i < MAXPLAYERS; i++) {
        playeringame[i] = *demo_p++;
    }

    G_InitNew(startskill, startmap);

    if(playeringame[1]) {
        netgame = true;
        netdemo = true;
    }

    precache = true;
    usergame = false;
    demoplayback = true;

    G_RunGame();
    iwadDemo = false;
}