diff --git a/programs/games/doom/trunk/d_main.c b/programs/games/doom/trunk/d_main.c index 6605819d7a..a7f3d109d3 100644 --- a/programs/games/doom/trunk/d_main.c +++ b/programs/games/doom/trunk/d_main.c @@ -17,48 +17,31 @@ // $Log:$ // // DESCRIPTION: -// DOOM main program (D_DoomMain) and game loop (D_DoomLoop), -// plus functions to determine game mode (shareware, registered), -// parse command line parameters, configure game parameters (turbo), -// and call the startup functions. +// DOOM main program (D_DoomMain) and game loop (D_DoomLoop), +// plus functions to determine game mode (shareware, registered), +// parse command line parameters, configure game parameters (turbo), +// and call the startup functions. // //----------------------------------------------------------------------------- static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; -#define BGCOLOR 7 -#define FGCOLOR 8 +#define BGCOLOR 7 +#define FGCOLOR 8 +#define R_OK 4 + #include #include -extern int access(char *file, int mode); - -#define R_OK 4 -#if 0 -static int access(char *file, int mode) -{ - FILE *test_fp; - - test_fp = fopen(file, "r"); - if ( test_fp != NULL ) { - fclose(test_fp); - return(0); - } - return(-1); -} -#endif - - #include "doomdef.h" #include "doomstat.h" #include "dstrings.h" #include "sounds.h" - #include "z_zone.h" #include "w_wad.h" #include "s_sound.h" @@ -86,7 +69,12 @@ static int access(char *file, int mode) #include "r_local.h" + #include "d_main.h" +//#include "kolibri.h" + + +extern int access(char *file, int mode); // // D-DoomLoop() @@ -100,41 +88,41 @@ static int access(char *file, int mode) void D_DoomLoop (void); -char* wadfiles[MAXWADFILES]; +char* wadfiles[MAXWADFILES]; -boolean devparm; // started game with -devparm -boolean nomonsters; // checkparm of -nomonsters -boolean respawnparm; // checkparm of -respawn -boolean fastparm; // checkparm of -fast +boolean devparm; // started game with -devparm +boolean nomonsters; // checkparm of -nomonsters +boolean respawnparm; // checkparm of -respawn +boolean fastparm; // checkparm of -fast boolean drone; -boolean singletics = false; // debug flag to cancel adaptiveness +boolean singletics = false; // debug flag to cancel adaptiveness //extern int soundVolume; -//extern int sfxVolume; -//extern int musicVolume; +//extern int sfxVolume; +//extern int musicVolume; -extern boolean inhelpscreens; +extern boolean inhelpscreens; -skill_t startskill; +skill_t startskill; int startepisode; -int startmap; -boolean autostart; +int startmap; +boolean autostart; -FILE* debugfile; +FILE* debugfile; -boolean advancedemo; +boolean advancedemo; -char wadfile[1024]; // primary wad file -char mapdir[1024]; // directory of development maps -char basedefault[1024]; // default file +char wadfile[1024]; // primary wad file +char mapdir[1024]; // directory of development maps +char basedefault[1024]; // default file void D_CheckNetGame (void); @@ -151,7 +139,7 @@ void D_DoAdvanceDemo (void); // event_t events[MAXEVENTS]; int eventhead; -int eventtail; +int eventtail; // @@ -171,19 +159,19 @@ void D_PostEvent (event_t* ev) // void D_ProcessEvents (void) { - event_t* ev; - + event_t* ev; + // IF STORE DEMO, DO NOT ACCEPT INPUT if ( ( gamemode == commercial ) - && (W_CheckNumForName("map01")<0) ) + && (W_CheckNumForName("map01")<0) ) return; - + for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) ) { - ev = &events[eventtail]; - if (M_Responder (ev)) - continue; // menu ate the event - G_Responder (ev); + ev = &events[eventtail]; + if (M_Responder (ev)) + continue; // menu ate the event + G_Responder (ev); } } @@ -202,141 +190,137 @@ extern int showMessages; void R_ExecuteSetViewSize (void); -// #define XXX(n) __libclog_printf("d_main.c: %u\n",n) +// #define XXX(n) __libclog_printf("d_main.c: %u\n",n) #define XXX(n) void D_Display (void) { - static boolean viewactivestate = false; - static boolean menuactivestate = false; - static boolean inhelpscreensstate = false; - static boolean fullscreen = false; - static gamestate_t oldgamestate = -1; - static int borderdrawcount; - int nowtime; - int tics; - int wipestart; - int y; - boolean done; - boolean wipe; - boolean redrawsbar; + static boolean viewactivestate = false; + static boolean menuactivestate = false; + static boolean inhelpscreensstate = false; + static boolean fullscreen = false; + static gamestate_t oldgamestate = -1; + static int borderdrawcount; + int nowtime; + int tics; + int wipestart; + int y; + boolean done; + boolean wipe; + boolean redrawsbar; if (nodrawers) { - XXX(0); - return; // for comparative timing / profiling - } + XXX(0); + return; // for comparative timing / profiling + } redrawsbar = false; // change the view size if needed if (setsizeneeded) { - XXX(1); - R_ExecuteSetViewSize (); - XXX(2); - oldgamestate = -1; // force background redraw - borderdrawcount = 3; + XXX(1); + R_ExecuteSetViewSize (); + XXX(2); + oldgamestate = -1; // force background redraw + borderdrawcount = 3; } // save the current screen if about to wipe - XXX(3); + XXX(3); if (gamestate != wipegamestate) { - wipe = true; - XXX(4); - wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); - XXX(5); + wipe = true; + wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); } else - wipe = false; - XXX(6); + wipe = false; + XXX(6); if (gamestate == GS_LEVEL && gametic) { - XXX(7); - HU_Erase(); - XXX(8); + HU_Erase(); } // do buffered drawing - XXX(9); + XXX(9); switch (gamestate) { case GS_LEVEL: - XXX(10); - if (!gametic) - break; - if (automapactive) - AM_Drawer (); - if (wipe || (viewheight != 200 && fullscreen) ) - redrawsbar = true; - if (inhelpscreensstate && !inhelpscreens) - redrawsbar = true; // just put away the help screen - ST_Drawer (viewheight == 200, redrawsbar ); - fullscreen = viewheight == 200; - break; + XXX(10); + if (!gametic) + break; + if (automapactive) + AM_Drawer (); + if (wipe || (viewheight != 200 && fullscreen) ) + redrawsbar = true; + if (inhelpscreensstate && !inhelpscreens) + redrawsbar = true; // just put away the help screen + ST_Drawer (viewheight == 200, redrawsbar ); + fullscreen = viewheight == 200; + break; case GS_INTERMISSION: - XXX(11); - WI_Drawer (); - break; + XXX(11); + WI_Drawer (); + break; case GS_FINALE: - XXX(12); - F_Drawer (); - break; + XXX(12); + F_Drawer (); + break; case GS_DEMOSCREEN: - XXX(13); - D_PageDrawer (); - XXX(14); - break; + XXX(13); + D_PageDrawer (); + XXX(14); + break; } // draw buffered stuff to screen - XXX(15); + XXX(15); I_UpdateNoBlit (); - XXX(16); + XXX(16); // draw the view directly if (gamestate == GS_LEVEL && !automapactive && gametic) - R_RenderPlayerView (&players[displayplayer]); - XXX(17); + R_RenderPlayerView (&players[displayplayer]); + XXX(17); if (gamestate == GS_LEVEL && gametic) - HU_Drawer (); - XXX(18); + HU_Drawer (); + XXX(18); // clean up border stuff if (gamestate != oldgamestate && gamestate != GS_LEVEL) - I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE)); - XXX(19); + I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE)); + XXX(19); // see if the border needs to be initially drawn if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL) { - XXX(20); - viewactivestate = false; // view was not active - R_FillBackScreen (); // draw the pattern into the back screen - XXX(21); + XXX(20); + viewactivestate = false; // view was not active + R_FillBackScreen (); // draw the pattern into the back screen + XXX(21); } - XXX(22); + XXX(22); // see if the border needs to be updated to the screen if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320) { - XXX(23); - if (menuactive || menuactivestate || !viewactivestate) - borderdrawcount = 3; - if (borderdrawcount) - { - XXX(24); - R_DrawViewBorder (); // erase old menu stuff - XXX(25); - borderdrawcount--; - } + XXX(23); + if (menuactive || menuactivestate || !viewactivestate) + borderdrawcount = 3; + if (borderdrawcount) + { + XXX(24); + R_DrawViewBorder (); // erase old menu stuff + XXX(25); + borderdrawcount--; + } } - XXX(26); + XXX(26); menuactivestate = menuactive; viewactivestate = viewactive; @@ -346,60 +330,60 @@ void D_Display (void) // draw pause pic if (paused) { - if (automapactive) - y = 4; - else - y = viewwindowy+4; - V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2, - y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE)); + if (automapactive) + y = 4; + else + y = viewwindowy+4; + V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2, + y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE)); } // menus go directly to the screen - XXX(27); + XXX(27); M_Drawer (); // menu is drawn even on top of everything - XXX(28); + XXX(28); NetUpdate (); // send out any new accumulation - XXX(29); + XXX(29); // normal update if (!wipe) { - XXX(30); - I_FinishUpdate (); // page flip or blit buffer - XXX(31); - return; + XXX(30); + I_FinishUpdate (); // page flip or blit buffer + XXX(31); + return; } - XXX(32); + XXX(32); // wipe update wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT); - XXX(33); + XXX(33); wipestart = I_GetTime () - 1; - XXX(34); + XXX(34); do { - do - { - nowtime = I_GetTime (); - tics = nowtime - wipestart; - } while (!tics); - wipestart = nowtime; - XXX(35); - done = wipe_ScreenWipe(wipe_Melt - , 0, 0, SCREENWIDTH, SCREENHEIGHT, tics); - XXX(36); - I_UpdateNoBlit (); - XXX(37); - M_Drawer (); // menu is drawn even on top of wipes - XXX(38); - I_FinishUpdate (); // page flip or blit buffer - XXX(39); + do + { + nowtime = I_GetTime (); + tics = nowtime - wipestart; + } while (!tics); + wipestart = nowtime; + XXX(35); + done = wipe_ScreenWipe(wipe_Melt + , 0, 0, SCREENWIDTH, SCREENHEIGHT, tics); + XXX(36); + I_UpdateNoBlit (); + XXX(37); + M_Drawer (); // menu is drawn even on top of wipes + XXX(38); + I_FinishUpdate (); // page flip or blit buffer + XXX(39); } while (!done); - XXX(40); + XXX(40); } // @@ -410,58 +394,50 @@ extern boolean demorecording; void D_DoomLoop (void) { if (demorecording) - G_BeginRecording (); - + G_BeginRecording (); + if (M_CheckParm ("-debugfile")) { - char filename[20]; - sprintf (filename,"debug%i.txt",consoleplayer); -// __libclog_printf ("debug output to: %s\n",filename); - debugfile = fopen (filename,"w"); + char filename[32]; + sprintf (filename,"debug%i.txt",consoleplayer); + debugfile = fopen (filename,"w"); } - + I_InitGraphics (); while (1) { - // frame syncronous IO operations - XXX(100); - I_StartFrame (); - XXX(101); - - // process one or more tics - if (singletics) - { - XXX(201); - I_StartTic (); - XXX(202); - D_ProcessEvents (); - XXX(203); - G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]); - XXX(204); - if (advancedemo) - D_DoAdvanceDemo (); - XXX(205); - M_Ticker (); - XXX(206); - G_Ticker (); - gametic++; - maketic++; - } - else - { - XXX(102); - TryRunTics (); // will run at least one tic - XXX(103); - } + // frame syncronous IO operations + XXX(100); + I_StartFrame (); + XXX(101); + + // process one or more tics + if (singletics) + { + I_StartTic (); - S_UpdateSounds (players[consoleplayer].mo);// move positional sounds + D_ProcessEvents (); - // Update display, next frame, with current state. - XXX(104); - D_Display (); - I_UpdateSound(); - XXX(105); + G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]); + + if (advancedemo) + { + D_DoAdvanceDemo (); + }; + M_Ticker (); + G_Ticker (); + gametic++; + maketic++; + } + else + TryRunTics (); // will run at least one tic + + S_UpdateSounds (players[consoleplayer].mo);// move positional sounds + + D_Display (); +// I_UpdateSound(); + XXX(105); } } @@ -481,8 +457,8 @@ char *pagename; // void D_PageTicker (void) { - if (--pagetic < 0) - D_AdvanceDemo (); + if (--pagetic < 0) + D_AdvanceDemo (); } @@ -526,53 +502,53 @@ void D_AdvanceDemo (void) switch (demosequence) { case 0: - if ( gamemode == commercial ) - pagetic = 35 * 11; - else - pagetic = 170; - gamestate = GS_DEMOSCREEN; - pagename = "TITLEPIC"; -// if ( gamemode == commercial ) -// S_StartMusic(mus_dm2ttl); -// else -// S_StartMusic (mus_intro); - break; + if ( gamemode == commercial ) + pagetic = 35 * 11; + else + pagetic = 170; + gamestate = GS_DEMOSCREEN; + pagename = "TITLEPIC"; +// if ( gamemode == commercial ) +// S_StartMusic(mus_dm2ttl); +// else +// S_StartMusic (mus_intro); + break; case 1: - G_DeferedPlayDemo ("demo1"); - break; + G_DeferedPlayDemo ("demo1"); + break; case 2: - pagetic = 200; - gamestate = GS_DEMOSCREEN; - pagename = "CREDIT"; - break; + pagetic = 200; + gamestate = GS_DEMOSCREEN; + pagename = "CREDIT"; + break; case 3: - G_DeferedPlayDemo ("demo2"); - break; + G_DeferedPlayDemo ("demo2"); + break; case 4: - gamestate = GS_DEMOSCREEN; - if ( gamemode == commercial) - { - pagetic = 35 * 11; - pagename = "TITLEPIC"; -// S_StartMusic(mus_dm2ttl); - } - else - { - pagetic = 200; + gamestate = GS_DEMOSCREEN; + if ( gamemode == commercial) + { + pagetic = 35 * 11; + pagename = "TITLEPIC"; +// S_StartMusic(mus_dm2ttl); + } + else + { + pagetic = 200; - if ( gamemode == retail ) - pagename = "CREDIT"; - else - pagename = "HELP2"; - } - break; + if ( gamemode == retail ) + pagename = "CREDIT"; + else + pagename = "HELP2"; + } + break; case 5: - G_DeferedPlayDemo ("demo3"); - break; + G_DeferedPlayDemo ("demo3"); + break; // THE DEFINITIVE DOOM Special Edition demo case 6: - G_DeferedPlayDemo ("demo4"); - break; + G_DeferedPlayDemo ("demo4"); + break; } } @@ -603,13 +579,13 @@ void D_AddFile (char *file) { int numwadfiles; char *newfile; - + for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++) - ; + ; newfile = malloc (strlen(file)+1); strcpy (newfile, file); - + wadfiles[numwadfiles] = newfile; } @@ -622,25 +598,24 @@ void D_AddFile (char *file) void IdentifyVersion (void) { - char* doom1wad; - char* doomwad; - char* doomuwad; - char* doom2wad; + char* doom1wad; + char* doomwad; + char* doomuwad; + char* doom2wad; - char* doom2fwad; - char* plutoniawad; - char* tntwad; + char* doom2fwad; + char* plutoniawad; + char* tntwad; char *home; char *doomwaddir; // doomwaddir = getenv("DOOMWADDIR"); // if (!doomwaddir) - doomwaddir = "."; + doomwaddir = "."; // Commercial. doom2wad = malloc(strlen(doomwaddir)+1+9+1); sprintf(doom2wad, "%s/doom2.wad", doomwaddir); - // Retail. doomuwad = malloc(strlen(doomwaddir)+1+8+1); sprintf(doomuwad, "%s/doomu.wad", doomwaddir); @@ -656,78 +631,76 @@ void IdentifyVersion (void) // Bug, dear Shawn. // Insufficient malloc, caused spurious realloc errors. plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1); - sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir); + sprintf(plutoniawad, "%splutonia.wad", doomwaddir); tntwad = malloc(strlen(doomwaddir)+1+9+1); sprintf(tntwad, "%s/tnt.wad", doomwaddir); - // French stuff. doom2fwad = malloc(strlen(doomwaddir)+1+10+1); sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir); // home = getenv("HOME"); // if (!home) - home = "."; + home = "."; sprintf(basedefault, "%s/doomrc.txt", home); if (M_CheckParm ("-shdev")) { - gamemode = shareware; - devparm = true; - D_AddFile (DEVDATA"doom1.wad"); - D_AddFile (DEVMAPS"data_se/texture1.lmp"); - D_AddFile (DEVMAPS"data_se/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; + gamemode = shareware; + devparm = true; + D_AddFile (DEVDATA"doom1.wad"); + D_AddFile (DEVMAPS"data_se/texture1.lmp"); + D_AddFile (DEVMAPS"data_se/pnames.lmp"); + strcpy (basedefault,DEVDATA"default.cfg"); + return; } if (M_CheckParm ("-regdev")) { - gamemode = registered; - devparm = true; - D_AddFile (DEVDATA"doom.wad"); - D_AddFile (DEVMAPS"data_se/texture1.lmp"); - D_AddFile (DEVMAPS"data_se/texture2.lmp"); - D_AddFile (DEVMAPS"data_se/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; + gamemode = registered; + devparm = true; + D_AddFile (DEVDATA"doom.wad"); + D_AddFile (DEVMAPS"data_se/texture1.lmp"); + D_AddFile (DEVMAPS"data_se/texture2.lmp"); + D_AddFile (DEVMAPS"data_se/pnames.lmp"); + strcpy (basedefault,DEVDATA"default.cfg"); + return; } if (M_CheckParm ("-comdev")) { - gamemode = commercial; - devparm = true; - /* I don't bother - if(plutonia) - D_AddFile (DEVDATA"plutonia.wad"); - else if(tnt) - D_AddFile (DEVDATA"tnt.wad"); - else*/ - D_AddFile (DEVDATA"doom2.wad"); - - D_AddFile (DEVMAPS"cdata/texture1.lmp"); - D_AddFile (DEVMAPS"cdata/pnames.lmp"); - strcpy (basedefault,DEVDATA"default.cfg"); - return; + gamemode = commercial; + devparm = true; + /* I don't bother + if(plutonia) + D_AddFile (DEVDATA"plutonia.wad"); + else if(tnt) + D_AddFile (DEVDATA"tnt.wad"); + else*/ + D_AddFile (DEVDATA"doom2.wad"); + + D_AddFile (DEVMAPS"cdata/texture1.lmp"); + D_AddFile (DEVMAPS"cdata/pnames.lmp"); + strcpy (basedefault,DEVDATA"default.cfg"); + return; } if ( !access (doom2fwad,R_OK) ) { - gamemode = commercial; - // C'est ridicule! - // Let's handle languages in config files, okay? - language = french; -// __libclog_printf("French version\n"); - D_AddFile (doom2fwad); - return; + gamemode = commercial; + // C'est ridicule! + // Let's handle languages in config files, okay? + language = french; + D_AddFile (doom2fwad); + return; } if ( !access (doom2wad,R_OK) ) { - gamemode = commercial; - D_AddFile (doom2wad); - return; + gamemode = commercial; + D_AddFile (doom2wad); + return; } if ( !access (plutoniawad, R_OK ) ) @@ -765,7 +738,7 @@ void IdentifyVersion (void) return; } - // __libclog_printf("Game mode indeterminate.\n"); + printf("Game mode indeterminate.\n"); gamemode = indetermined; // We don't abort. Let's see what the PWAD contains. @@ -780,70 +753,70 @@ void FindResponseFile (void) { int i; #define MAXARGVS 100 - + for (i = 1;i < myargc;i++) - if (myargv[i][0] == '@') - { - FILE * handle; - int size; - int k; - int index; - int indexinfile; - char *infile; - char *file; - char *moreargs[20]; - char *firstargv; - - // READ THE RESPONSE FILE INTO MEMORY - handle = fopen (&myargv[i][1],"rb"); - if (!handle) - { -// __libclog_printf ("\nNo such response file!"); - exit(1); - } -// __libclog_printf("Found response file %s!\n",&myargv[i][1]); - fseek (handle,0,SEEK_END); - size = ftell(handle); - fseek (handle,0,SEEK_SET); - file = malloc (size); - fread (file,size,1,handle); - fclose (handle); - - // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG - for (index = 0,k = i+1; k < myargc; k++) - moreargs[index++] = myargv[k]; - - firstargv = myargv[0]; - myargv = malloc(sizeof(char *)*MAXARGVS); - memset(myargv,0,sizeof(char *)*MAXARGVS); - myargv[0] = firstargv; - - infile = file; - indexinfile = k = 0; - indexinfile++; // SKIP PAST ARGV[0] (KEEP IT) - do - { - myargv[indexinfile++] = infile+k; - while(k < size && - ((*(infile+k)>= ' '+1) && (*(infile+k)<='z'))) - k++; - *(infile+k) = 0; - while(k < size && - ((*(infile+k)<= ' ') || (*(infile+k)>'z'))) - k++; - } while(k < size); - - for (k = 0;k < index;k++) - myargv[indexinfile++] = moreargs[k]; - myargc = indexinfile; - - // DISPLAY ARGS -// __libclog_printf("%d command-line args:\n",myargc); - for (k=1;k= ' '+1) && (*(infile+k)<='z'))) + k++; + *(infile+k) = 0; + while(k < size && + ((*(infile+k)<= ' ') || (*(infile+k)>'z'))) + k++; + } while(k < size); + + for (k = 0;k < index;k++) + myargv[indexinfile++] = moreargs[k]; + myargc = indexinfile; + + // DISPLAY ARGS +// __libclog_printf("%d command-line args:\n",myargc); +// for (k=1;k 400) - scale = 400; -// __libclog_printf ("turbo scale: %i%%\n",scale); - forwardmove[0] = forwardmove[0]*scale/100; - forwardmove[1] = forwardmove[1]*scale/100; - sidemove[0] = sidemove[0]*scale/100; - sidemove[1] = sidemove[1]*scale/100; + int scale = 200; + extern int forwardmove[2]; + extern int sidemove[2]; + + if (p 400) + scale = 400; + printf ("turbo scale: %i%%\n",scale); + forwardmove[0] = forwardmove[0]*scale/100; + forwardmove[1] = forwardmove[1]*scale/100; + sidemove[0] = sidemove[0]*scale/100; + sidemove[1] = sidemove[1]*scale/100; } // add any files specified on the command line with -file wadfile @@ -961,52 +931,49 @@ void D_DoomMain (void) p = M_CheckParm ("-wart"); if (p) { - myargv[p][4] = 'p'; // big hack, change to -warp + myargv[p][4] = 'p'; // big hack, change to -warp - // Map name handling. - switch (gamemode ) - { - case shareware: - case retail: - case registered: - sprintf (file,"~"DEVMAPS"E%cM%c.wad", - myargv[p+1][0], myargv[p+2][0]); -// __libclog_printf("Warping to Episode %s, Map %s.\n", -// myargv[p+1],myargv[p+2]); - break; - - case commercial: - default: - p = atoi (myargv[p+1]); - if (p<10) - sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p); - else - sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p); - break; - } - D_AddFile (file); + // Map name handling. + switch (gamemode ) + { + case shareware: + case retail: + case registered: + sprintf (file,"~"DEVMAPS"E%cM%c.wad", + myargv[p+1][0], myargv[p+2][0]); + break; + + case commercial: + default: + p = atoi (myargv[p+1]); + if (p<10) + sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p); + else + sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p); + break; + } + D_AddFile (file); } - + p = M_CheckParm ("-file"); if (p) { - // the parms after p are wadfile/lump names, - // until end of parms or another - preceded parm - modifiedgame = true; // homebrew levels - while (++p != myargc && myargv[p][0] != '-') - D_AddFile (myargv[p]); + // the parms after p are wadfile/lump names, + // until end of parms or another - preceded parm + modifiedgame = true; // homebrew levels + while (++p != myargc && myargv[p][0] != '-') + D_AddFile (myargv[p]); } p = M_CheckParm ("-playdemo"); if (!p) - p = M_CheckParm ("-timedemo"); + p = M_CheckParm ("-timedemo"); if (p && p < myargc-1) { - sprintf (file,"%s.lmp", myargv[p+1]); - D_AddFile (file); - printf("Playing demo %s.lmp.\n",myargv[p+1]); + sprintf (file,"%s.lmp", myargv[p+1]); + D_AddFile (file); } // get skill / episode / map from parms @@ -1014,168 +981,163 @@ void D_DoomMain (void) startepisode = 1; startmap = 1; autostart = false; - - + p = M_CheckParm ("-skill"); if (p && p < myargc-1) { - startskill = myargv[p+1][0]-'1'; - autostart = true; + startskill = myargv[p+1][0]-'1'; + autostart = true; } p = M_CheckParm ("-episode"); if (p && p < myargc-1) { - startepisode = myargv[p+1][0]-'0'; - startmap = 1; - autostart = true; + startepisode = myargv[p+1][0]-'0'; + startmap = 1; + autostart = true; } - + p = M_CheckParm ("-timer"); if (p && p < myargc-1 && deathmatch) { - int time; - time = atoi(myargv[p+1]); - printf("Levels will end after %d minute",time); - if (time>1) - printf("s"); - printf(".\n"); + int time; + time = atoi(myargv[p+1]); + if (time>1) + printf("s"); + printf(".\n"); } p = M_CheckParm ("-avg"); if (p && p < myargc-1 && deathmatch) - printf("Austin Virtual Gaming: Levels will end after 20 minutes\n"); + printf("Austin Virtual Gaming: Levels will end after 20 minutes\n"); p = M_CheckParm ("-warp"); if (p && p < myargc-1) { - if (gamemode == commercial) - startmap = atoi (myargv[p+1]); - else - { - startepisode = myargv[p+1][0]-'0'; - startmap = myargv[p+2][0]-'0'; - } - autostart = true; + if (gamemode == commercial) + startmap = atoi (myargv[p+1]); + else + { + startepisode = myargv[p+1][0]-'0'; + startmap = myargv[p+2][0]-'0'; + } + autostart = true; } - + + // init subsystems - printf ("V_Init: allocate screens.\n"); + printf ("V_Init: allocate screens.\n\r"); V_Init (); - printf ("M_LoadDefaults: Load system defaults.\n"); + printf ("M_LoadDefaults: Load system defaults.\n\r"); M_LoadDefaults (); // load before initing other systems - printf ("Z_Init: Init zone memory allocation daemon. \n"); + printf ("Z_Init: Init zone memory allocation daemon. \n\r"); Z_Init (); - printf ("W_Init: Init WADfiles.\n"); + printf ("W_Init: Init WADfiles.\n\r"); W_InitMultipleFiles (wadfiles); - printf("added\n"); - // Check for -file in shareware if (modifiedgame) { - // These are the lumps that will be checked in IWAD, - // if any one is not present, execution will be aborted. - char name[23][8]= - { - "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9", - "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9", - "dphoof","bfgga0","heada1","cybra1","spida1d1" - }; - int i; - - if ( gamemode == shareware) - I_Error("\nYou cannot -file with the shareware " - "version. Register!"); + // These are the lumps that will be checked in IWAD, + // if any one is not present, execution will be aborted. + char name[23][8]= + { + "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9", + "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9", + "dphoof","bfgga0","heada1","cybra1","spida1d1" + }; + int i; + + if ( gamemode == shareware) + I_Error("\n\rYou cannot -file with the shareware " + "version. Register!"); - // Check for fake IWAD with right name, - // but w/o all the lumps of the registered version. - if (gamemode == registered) - for (i = 0;i < 23; i++) - if (W_CheckNumForName(name[i])<0) - I_Error("\nThis is not the registered version."); + // Check for fake IWAD with right name, + // but w/o all the lumps of the registered version. + if (gamemode == registered) + for (i = 0;i < 23; i++) + if (W_CheckNumForName(name[i])<0) + I_Error("\n\rThis is not the registered version."); } // Iff additonal PWAD files are used, print modified banner if (modifiedgame) { - printf ( - "===========================================================================\n" - "ATTENTION: This version of DOOM has been modified. If you would like to\n" - "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n" - " You will not receive technical support for modified games.\n" - " press enter to continue\n" - "===========================================================================\n" - ); -// getchar (); +// //printf ( +// "===========================================================================\n\r" +// "ATTENTION: This version of DOOM has been modified. If you would like to\n\r" +// "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n\r" +// " You will not receive technical support for modified games.\n\r" +// " press enter to continue\n\r" +// "===========================================================================\n\r" +// ); +// getchar (); } - + // Check and print which version is executed. switch ( gamemode ) { case shareware: case indetermined: - printf ( - "===========================================================================\n" - " Shareware!\n" - "===========================================================================\n" - ); - break; +// //printf ( +// "===========================================================================\n\r" +// " Shareware!\n\r" +// "===========================================================================\n\r" +// ); + break; case registered: case retail: case commercial: - printf ( - "===========================================================================\n" - " Commercial product - do not distribute!\n" - " Please report software piracy to the SPA: 1-800-388-PIR8\n" - "===========================================================================\n" - ); - break; - +// //printf ( +// "===========================================================================\n\r" +// " Commercial product - do not distribute!\n\r" +// " Please report software piracy to the SPA: 1-800-388-PIR8\n\r" +// "===========================================================================\n\r" +// ); + break; + default: - // Ouch. - break; + // Ouch. + break; } - printf ("M_Init: Init miscellaneous info.\n"); + printf ("M_Init: Init miscellaneous info.\n\r"); M_Init (); - printf ("R_Init: Init DOOM refresh daemon - "); + printf ("R_Init: Init DOOM refresh daemon - \n\r"); R_Init (); - printf ("\nP_Init: Init Playloop state.\n"); + printf ("\nP_Init: Init Playloop state.\n\r"); P_Init (); - printf ("I_Init: Setting up machine state.\n"); + printf ("I_Init: Setting up machine state.\n\r"); I_Init (); - printf ("D_CheckNetGame: Checking network game status.\n"); + printf ("D_CheckNetGame: Checking network game status.\n\r"); D_CheckNetGame (); - printf ("S_Init: Setting up sound.\n"); - S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ ); +// printf ("S_Init: Setting up sound.\n\r"); +// S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ ); - printf ("HU_Init: Setting up heads up display.\n"); + printf ("HU_Init: Setting up heads up display.\n\r"); HU_Init (); -// I_EndSplash(); - - printf ("ST_Init: Init status bar.\n"); + printf ("ST_Init: Init status bar.\n\r"); ST_Init (); // check for a driver that wants intermission stats p = M_CheckParm ("-statcopy"); if (p && p gametic for all players // -#define RESENDCOUNT 10 -#define PL_DRONE 0x80 // bit flag in doomdata->player +#define RESENDCOUNT 10 +#define PL_DRONE 0x80 // bit flag in doomdata->player -ticcmd_t localcmds[BACKUPTICS]; +ticcmd_t localcmds[BACKUPTICS]; ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; -int nettics[MAXNETNODES]; -boolean nodeingame[MAXNETNODES]; // set false as nodes leave game -boolean remoteresend[MAXNETNODES]; // set when local needs tics -int resendto[MAXNETNODES]; // set when remote needs tics -int resendcount[MAXNETNODES]; +int nettics[MAXNETNODES]; +boolean nodeingame[MAXNETNODES]; // set false as nodes leave game +boolean remoteresend[MAXNETNODES]; // set when local needs tics +int resendto[MAXNETNODES]; // set when remote needs tics +int resendcount[MAXNETNODES]; -int nodeforplayer[MAXPLAYERS]; +int nodeforplayer[MAXPLAYERS]; int maketic; -int lastnettic; -int skiptics; -int ticdup; -int maxsend; // BACKUPTICS/(2*ticdup)-1 +int lastnettic; +int skiptics; +int ticdup; +int maxsend; // BACKUPTICS/(2*ticdup)-1 void D_ProcessEvents (void); void G_BuildTiccmd (ticcmd_t *cmd); void D_DoAdvanceDemo (void); -boolean reboundpacket; -doomdata_t reboundstore; +boolean reboundpacket; +doomdata_t reboundstore; @@ -97,19 +97,19 @@ int NetbufferSize (void) // unsigned NetbufferChecksum (void) { - unsigned c; - int i,l; + unsigned c; + int i,l; c = 0x1234567; // FIXME -endianess? #ifdef NORMALUNIX - return 0; // byte order problems + return 0; // byte order problems #endif l = (NetbufferSize () - (int)&(((doomdata_t *)0)->retransmitfrom))/4; for (i=0 ; iretransmitfrom)[i] * (i+1); + c += ((unsigned *)&netbuffer->retransmitfrom)[i] * (i+1); return c & NCMD_CHECKSUM; } @@ -119,17 +119,17 @@ unsigned NetbufferChecksum (void) // int ExpandTics (int low) { - int delta; - + int delta; + delta = low - (maketic&0xff); - + if (delta >= -64 && delta <= 64) - return (maketic&~0xff) + low; + return (maketic&~0xff) + low; if (delta > 64) - return (maketic&~0xff) - 256 + low; + return (maketic&~0xff) - 256 + low; if (delta < -64) - return (maketic&~0xff) + 256 + low; - + return (maketic&~0xff) + 256 + low; + I_Error ("ExpandTics: strange value %i at maketic %i",low,maketic); return 0; } @@ -145,38 +145,38 @@ void HSendPacket (int node,int flags ) if (!node) { - reboundstore = *netbuffer; - reboundpacket = true; - return; + reboundstore = *netbuffer; + reboundpacket = true; + return; } if (demoplayback) - return; + return; if (!netgame) - I_Error ("Tried to transmit to another node"); - + I_Error ("Tried to transmit to another node"); + doomcom->command = CMD_SEND; doomcom->remotenode = node; doomcom->datalength = NetbufferSize (); - + if (debugfile) { - int i; - int realretrans; - if (netbuffer->checksum & NCMD_RETRANSMIT) - realretrans = ExpandTics (netbuffer->retransmitfrom); - else - realretrans = -1; + int i; + int realretrans; + if (netbuffer->checksum & NCMD_RETRANSMIT) + realretrans = ExpandTics (netbuffer->retransmitfrom); + else + realretrans = -1; - printf ("send (%i + %i, R %i) [%i] ", - ExpandTics(netbuffer->starttic), - netbuffer->numtics, realretrans, doomcom->datalength); - - for (i=0 ; idatalength ; i++) - printf ("%i ",((byte *)netbuffer)[i]); + printf ("send (%i + %i, R %i) [%i] ", + ExpandTics(netbuffer->starttic), + netbuffer->numtics, realretrans, doomcom->datalength); + + for (i=0 ; idatalength ; i++) + printf ("%i ",((byte *)netbuffer)[i]); - printf ("\n"); + printf ("\n"); } I_NetCmd (); @@ -187,66 +187,66 @@ void HSendPacket (int node,int flags ) // Returns false if no packet is waiting // boolean HGetPacket (void) -{ +{ if (reboundpacket) { - *netbuffer = reboundstore; - doomcom->remotenode = 0; - reboundpacket = false; - return true; + *netbuffer = reboundstore; + doomcom->remotenode = 0; + reboundpacket = false; + return true; } if (!netgame) - return false; + return false; if (demoplayback) - return false; - + return false; + doomcom->command = CMD_GET; I_NetCmd (); if (doomcom->remotenode == -1) - return false; + return false; if (doomcom->datalength != NetbufferSize ()) { - if (debugfile) - printf ("bad packet length %i\n",doomcom->datalength); - return false; + if (debugfile) + printf ("bad packet length %i\n",doomcom->datalength); + return false; } - + if (NetbufferChecksum () != (netbuffer->checksum&NCMD_CHECKSUM) ) { - if (debugfile) - printf ("bad packet checksum\n"); - return false; + if (debugfile) + printf ("bad packet checksum\n"); + return false; } if (debugfile) { - int realretrans; - int i; - - if (netbuffer->checksum & NCMD_SETUP) - printf ("setup packet\n"); - else - { - if (netbuffer->checksum & NCMD_RETRANSMIT) - realretrans = ExpandTics (netbuffer->retransmitfrom); - else - realretrans = -1; - - printf ("get %i = (%i + %i, R %i)[%i] ", - doomcom->remotenode, - ExpandTics(netbuffer->starttic), - netbuffer->numtics, realretrans, doomcom->datalength); + int realretrans; + int i; + + if (netbuffer->checksum & NCMD_SETUP) + printf ("setup packet\n"); + else + { + if (netbuffer->checksum & NCMD_RETRANSMIT) + realretrans = ExpandTics (netbuffer->retransmitfrom); + else + realretrans = -1; + + printf ("get %i = (%i + %i, R %i)[%i] ", + doomcom->remotenode, + ExpandTics(netbuffer->starttic), + netbuffer->numtics, realretrans, doomcom->datalength); - for (i=0 ; idatalength ; i++) - printf ("%i ",((byte *)netbuffer)[i]); - printf ("\n"); - } + for (i=0 ; idatalength ; i++) + printf ("%i ",((byte *)netbuffer)[i]); + printf ("\n"); + } } - return true; + return true; } @@ -257,98 +257,98 @@ char exitmsg[80]; void GetPackets (void) { - int netconsole; - int netnode; - ticcmd_t *src, *dest; - int realend; - int realstart; - + int netconsole; + int netnode; + ticcmd_t *src, *dest; + int realend; + int realstart; + while ( HGetPacket() ) { - if (netbuffer->checksum & NCMD_SETUP) - continue; // extra setup packet - - netconsole = netbuffer->player & ~PL_DRONE; - netnode = doomcom->remotenode; - - // to save bytes, only the low byte of tic numbers are sent - // Figure out what the rest of the bytes are - realstart = ExpandTics (netbuffer->starttic); - realend = (realstart+netbuffer->numtics); - - // check for exiting the game - if (netbuffer->checksum & NCMD_EXIT) - { - if (!nodeingame[netnode]) - continue; - nodeingame[netnode] = false; - playeringame[netconsole] = false; - strcpy (exitmsg, "Player 1 left the game"); - exitmsg[7] += netconsole; - players[consoleplayer].message = exitmsg; - if (demorecording) - G_CheckDemoStatus (); - continue; - } - - // check for a remote game kill - if (netbuffer->checksum & NCMD_KILL) - I_Error ("Killed by network driver"); - - nodeforplayer[netconsole] = netnode; - - // check for retransmit request - if ( resendcount[netnode] <= 0 - && (netbuffer->checksum & NCMD_RETRANSMIT) ) - { - resendto[netnode] = ExpandTics(netbuffer->retransmitfrom); - if (debugfile) - printf ("retransmit from %i\n", resendto[netnode]); - resendcount[netnode] = RESENDCOUNT; - } - else - resendcount[netnode]--; - - // check for out of order / duplicated packet - if (realend == nettics[netnode]) - continue; - - if (realend < nettics[netnode]) - { - if (debugfile) - printf ("out of order packet (%i + %i)\n" , - realstart,netbuffer->numtics); - continue; - } - - // check for a missed packet - if (realstart > nettics[netnode]) - { - // stop processing until the other system resends the missed tics - if (debugfile) - printf ("missed tics from %i (%i - %i)\n", - netnode, realstart, nettics[netnode]); - remoteresend[netnode] = true; - continue; - } - - // update command store from the packet + if (netbuffer->checksum & NCMD_SETUP) + continue; // extra setup packet + + netconsole = netbuffer->player & ~PL_DRONE; + netnode = doomcom->remotenode; + + // to save bytes, only the low byte of tic numbers are sent + // Figure out what the rest of the bytes are + realstart = ExpandTics (netbuffer->starttic); + realend = (realstart+netbuffer->numtics); + + // check for exiting the game + if (netbuffer->checksum & NCMD_EXIT) { - int start; + if (!nodeingame[netnode]) + continue; + nodeingame[netnode] = false; + playeringame[netconsole] = false; + strcpy (exitmsg, "Player 1 left the game"); + exitmsg[7] += netconsole; + players[consoleplayer].message = exitmsg; + if (demorecording) + G_CheckDemoStatus (); + continue; + } + + // check for a remote game kill + if (netbuffer->checksum & NCMD_KILL) + I_Error ("Killed by network driver"); - remoteresend[netnode] = false; - - start = nettics[netnode] - realstart; - src = &netbuffer->cmds[start]; + nodeforplayer[netconsole] = netnode; + + // check for retransmit request + if ( resendcount[netnode] <= 0 + && (netbuffer->checksum & NCMD_RETRANSMIT) ) + { + resendto[netnode] = ExpandTics(netbuffer->retransmitfrom); + if (debugfile) + printf ("retransmit from %i\n", resendto[netnode]); + resendcount[netnode] = RESENDCOUNT; + } + else + resendcount[netnode]--; + + // check for out of order / duplicated packet + if (realend == nettics[netnode]) + continue; + + if (realend < nettics[netnode]) + { + if (debugfile) + printf ("out of order packet (%i + %i)\n" , + realstart,netbuffer->numtics); + continue; + } + + // check for a missed packet + if (realstart > nettics[netnode]) + { + // stop processing until the other system resends the missed tics + if (debugfile) + printf ("missed tics from %i (%i - %i)\n", + netnode, realstart, nettics[netnode]); + remoteresend[netnode] = true; + continue; + } - while (nettics[netnode] < realend) - { - dest = &netcmds[netconsole][nettics[netnode]%BACKUPTICS]; - nettics[netnode]++; - *dest = *src; - src++; - } - } + // update command store from the packet + { + int start; + + remoteresend[netnode] = false; + + start = nettics[netnode] - realstart; + src = &netbuffer->cmds[start]; + + while (nettics[netnode] < realend) + { + dest = &netcmds[netconsole][nettics[netnode]%BACKUPTICS]; + nettics[netnode]++; + *dest = *src; + src++; + } + } } } @@ -364,76 +364,76 @@ void NetUpdate (void) { int nowtime; int newtics; - int i,j; - int realstart; - int gameticdiv; + int i,j; + int realstart; + int gameticdiv; // check time nowtime = I_GetTime ()/ticdup; newtics = nowtime - gametime; gametime = nowtime; - - if (newtics <= 0) // nothing new to update - goto listen; + + if (newtics <= 0) // nothing new to update + goto listen; if (skiptics <= newtics) { - newtics -= skiptics; - skiptics = 0; + newtics -= skiptics; + skiptics = 0; } else { - skiptics -= newtics; - newtics = 0; + skiptics -= newtics; + newtics = 0; } - - + + netbuffer->player = consoleplayer; // build new ticcmds for console player gameticdiv = gametic/ticdup; for (i=0 ; i= BACKUPTICS/2-1) - break; // can't hold any more - - //printf ("mk:%i ",maketic); - G_BuildTiccmd (&localcmds[maketic%BACKUPTICS]); - maketic++; + I_StartTic (); + D_ProcessEvents (); + if (maketic - gameticdiv >= BACKUPTICS/2-1) + break; // can't hold any more + + //printf ("mk:%i ",maketic); + G_BuildTiccmd (&localcmds[maketic%BACKUPTICS]); + maketic++; } if (singletics) - return; // singletic update is syncronous + return; // singletic update is syncronous // send the packet to the other nodes for (i=0 ; inumnodes ; i++) - if (nodeingame[i]) - { - netbuffer->starttic = realstart = resendto[i]; - netbuffer->numtics = maketic - realstart; - if (netbuffer->numtics > BACKUPTICS) - I_Error ("NetUpdate: netbuffer->numtics > BACKUPTICS"); + if (nodeingame[i]) + { + netbuffer->starttic = realstart = resendto[i]; + netbuffer->numtics = maketic - realstart; + if (netbuffer->numtics > BACKUPTICS) + I_Error ("NetUpdate: netbuffer->numtics > BACKUPTICS"); - resendto[i] = maketic - doomcom->extratics; + resendto[i] = maketic - doomcom->extratics; - for (j=0 ; j< netbuffer->numtics ; j++) - netbuffer->cmds[j] = - localcmds[(realstart+j)%BACKUPTICS]; - - if (remoteresend[i]) - { - netbuffer->retransmitfrom = nettics[i]; - HSendPacket (i, NCMD_RETRANSMIT); - } - else - { - netbuffer->retransmitfrom = 0; - HSendPacket (i, 0); - } - } + for (j=0 ; j< netbuffer->numtics ; j++) + netbuffer->cmds[j] = + localcmds[(realstart+j)%BACKUPTICS]; + + if (remoteresend[i]) + { + netbuffer->retransmitfrom = nettics[i]; + HSendPacket (i, NCMD_RETRANSMIT); + } + else + { + netbuffer->retransmitfrom = 0; + HSendPacket (i, 0); + } + } // listen for other packets listen: @@ -448,19 +448,19 @@ void NetUpdate (void) void CheckAbort (void) { event_t *ev; - int stoptic; - + int stoptic; + stoptic = I_GetTime () + 2; while (I_GetTime() < stoptic) - I_StartTic (); - + I_StartTic (); + I_StartTic (); for ( ; eventtail != eventhead - ; eventtail = (++eventtail)&(MAXEVENTS-1) ) + ; eventtail = (++eventtail)&(MAXEVENTS-1) ) { - ev = &events[eventtail]; - if (ev->type == ev_keydown && ev->data1 == KEY_ESCAPE) - I_Error ("Network game synchronization aborted."); + ev = &events[eventtail]; + if (ev->type == ev_keydown && ev->data1 == KEY_ESCAPE) + I_Error ("Network game synchronization aborted."); } } @@ -470,74 +470,74 @@ void CheckAbort (void) // void D_ArbitrateNetStart (void) { - int i; - boolean gotinfo[MAXNETNODES]; - + int i; + boolean gotinfo[MAXNETNODES]; + autostart = true; memset (gotinfo,0,sizeof(gotinfo)); - + if (doomcom->consoleplayer) { - // listen for setup info from key player -// __libclog_printf ("listening for network start info...\n"); - while (1) - { - CheckAbort (); - if (!HGetPacket ()) - continue; - if (netbuffer->checksum & NCMD_SETUP) - { - if (netbuffer->player != VERSION_NUM) - I_Error ("Different DOOM versions cannot play a net game!"); - startskill = netbuffer->retransmitfrom & 15; - deathmatch = (netbuffer->retransmitfrom & 0xc0) >> 6; - nomonsters = (netbuffer->retransmitfrom & 0x20) > 0; - respawnparm = (netbuffer->retransmitfrom & 0x10) > 0; - startmap = netbuffer->starttic & 0x3f; - startepisode = netbuffer->starttic >> 6; - return; - } - } + // listen for setup info from key player +// __libclog_printf ("listening for network start info...\n"); + while (1) + { + CheckAbort (); + if (!HGetPacket ()) + continue; + if (netbuffer->checksum & NCMD_SETUP) + { + if (netbuffer->player != VERSION_NUM) + I_Error ("Different DOOM versions cannot play a net game!"); + startskill = netbuffer->retransmitfrom & 15; + deathmatch = (netbuffer->retransmitfrom & 0xc0) >> 6; + nomonsters = (netbuffer->retransmitfrom & 0x20) > 0; + respawnparm = (netbuffer->retransmitfrom & 0x10) > 0; + startmap = netbuffer->starttic & 0x3f; + startepisode = netbuffer->starttic >> 6; + return; + } + } } else { - // key player, send the setup info -// __libclog_printf ("sending network start info...\n"); - do - { - CheckAbort (); - for (i=0 ; inumnodes ; i++) - { - netbuffer->retransmitfrom = startskill; - if (deathmatch) - netbuffer->retransmitfrom |= (deathmatch<<6); - if (nomonsters) - netbuffer->retransmitfrom |= 0x20; - if (respawnparm) - netbuffer->retransmitfrom |= 0x10; - netbuffer->starttic = startepisode * 64 + startmap; - netbuffer->player = VERSION_NUM; - netbuffer->numtics = 0; - HSendPacket (i, NCMD_SETUP); - } + // key player, send the setup info +// __libclog_printf ("sending network start info...\n"); + do + { + CheckAbort (); + for (i=0 ; inumnodes ; i++) + { + netbuffer->retransmitfrom = startskill; + if (deathmatch) + netbuffer->retransmitfrom |= (deathmatch<<6); + if (nomonsters) + netbuffer->retransmitfrom |= 0x20; + if (respawnparm) + netbuffer->retransmitfrom |= 0x10; + netbuffer->starttic = startepisode * 64 + startmap; + netbuffer->player = VERSION_NUM; + netbuffer->numtics = 0; + HSendPacket (i, NCMD_SETUP); + } #if 1 - for(i = 10 ; i && HGetPacket(); --i) - { - if((netbuffer->player&0x7f) < MAXNETNODES) - gotinfo[netbuffer->player&0x7f] = true; - } + for(i = 10 ; i && HGetPacket(); --i) + { + if((netbuffer->player&0x7f) < MAXNETNODES) + gotinfo[netbuffer->player&0x7f] = true; + } #else - while (HGetPacket ()) - { - gotinfo[netbuffer->player&0x7f] = true; - } + while (HGetPacket ()) + { + gotinfo[netbuffer->player&0x7f] = true; + } #endif - for (i=1 ; inumnodes ; i++) - if (!gotinfo[i]) - break; - } while (i < doomcom->numnodes); + for (i=1 ; inumnodes ; i++) + if (!gotinfo[i]) + break; + } while (i < doomcom->numnodes); } } @@ -545,46 +545,46 @@ void D_ArbitrateNetStart (void) // D_CheckNetGame // Works out player numbers among the net participants // -extern int viewangleoffset; +extern int viewangleoffset; void D_CheckNetGame (void) { int i; - + for (i=0 ; iid != DOOMCOM_ID) - I_Error ("Doomcom buffer invalid!"); + I_Error ("Doomcom buffer invalid!"); netbuffer = &doomcom->data; consoleplayer = displayplayer = doomcom->consoleplayer; if (netgame) - D_ArbitrateNetStart (); + D_ArbitrateNetStart (); // __libclog_printf ("startskill %i deathmatch: %i startmap: %i startepisode: %i\n", -// startskill, deathmatch, startmap, startepisode); - +// startskill, deathmatch, startmap, startepisode); + // read values out of doomcom ticdup = doomcom->ticdup; maxsend = BACKUPTICS/(2*ticdup)-1; if (maxsend<1) - maxsend = 1; - + maxsend = 1; + for (i=0 ; inumplayers ; i++) - playeringame[i] = true; + playeringame[i] = true; for (i=0 ; inumnodes ; i++) - nodeingame[i] = true; - + nodeingame[i] = true; + // __libclog_printf ("player %i of %i (%i nodes)\n", -// consoleplayer+1, doomcom->numplayers, doomcom->numnodes); +// consoleplayer+1, doomcom->numplayers, doomcom->numnodes); } @@ -597,22 +597,22 @@ void D_CheckNetGame (void) void D_QuitNetGame (void) { int i, j; - + if (debugfile) - fclose (debugfile); - + fclose (debugfile); + if (!netgame || !usergame || consoleplayer == -1 || demoplayback) - return; - + return; + // send a bunch of packets for security netbuffer->player = consoleplayer; netbuffer->numtics = 0; for (i=0 ; i<4 ; i++) { - for (j=1 ; jnumnodes ; j++) - if (nodeingame[j]) - HSendPacket (j, NCMD_EXIT); - I_WaitVBL (1); + for (j=1 ; jnumnodes ; j++) + if (nodeingame[j]) + HSendPacket (j, NCMD_EXIT); + I_WaitVBL (1); } } @@ -621,142 +621,141 @@ void D_QuitNetGame (void) // // TryRunTics // -int frametics[4]; -int frameon; -int frameskip[4]; -int oldnettics; +int frametics[4]; +int frameon; +int frameskip[4]; +int oldnettics; -extern boolean advancedemo; +extern boolean advancedemo; void TryRunTics (void) { - int i; - int lowtic; - int entertic; - static int oldentertics; - int realtics; - int availabletics; - int counts; - int numplaying; + int i; + int lowtic; + int entertic; + static int oldentertics; + int realtics; + int availabletics; + int counts; + int numplaying; - // get real tics + // get real tics entertic = I_GetTime ()/ticdup; realtics = entertic - oldentertics; oldentertics = entertic; // get available tics NetUpdate (); - + lowtic = MAXINT; numplaying = 0; for (i=0 ; inumnodes ; i++) { - if (nodeingame[i]) - { - numplaying++; - if (nettics[i] < lowtic) - lowtic = nettics[i]; - } + if (nodeingame[i]) + { + numplaying++; + if (nettics[i] < lowtic) + lowtic = nettics[i]; + } } availabletics = lowtic - gametic/ticdup; // decide how many tics to run if (realtics < availabletics-1) - counts = realtics+1; + counts = realtics+1; else if (realtics < availabletics) - counts = realtics; + counts = realtics; else - counts = availabletics; + counts = availabletics; if (counts < 1) - counts = 1; - + counts = 1; + frameon++; if (debugfile) - fprintf (debugfile, - "=======real: %i avail: %i game: %i\n", - realtics, availabletics,counts); + printf ( "=======real: %i avail: %i game: %i\n", + realtics, availabletics,counts); if (!demoplayback) - { - // ideally nettics[0] should be 1 - 3 tics above lowtic - // if we are consistantly slower, speed up time - for (i=0 ; i nettics[nodeforplayer[i]]); - oldnettics = nettics[0]; - if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) - { - skiptics = 1; - // printf ("+"); - } - } + { + // ideally nettics[0] should be 1 - 3 tics above lowtic + // if we are consistantly slower, speed up time + for (i=0 ; i nettics[nodeforplayer[i]]); + oldnettics = nettics[0]; + if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) + { + skiptics = 1; + // printf ("+"); + } + } }// demoplayback - + // wait for new tics if needed - while (lowtic < gametic/ticdup + counts) + while (lowtic < gametic/ticdup + counts) { - NetUpdate (); - lowtic = MAXINT; - - for (i=0 ; inumnodes ; i++) - if (nodeingame[i] && nettics[i] < lowtic) - lowtic = nettics[i]; - - if (lowtic < gametic/ticdup) - I_Error ("TryRunTics: lowtic < gametic"); - - // don't stay in here forever -- give the menu a chance to work - if (I_GetTime ()/ticdup - entertic >= 20) - { - M_Ticker (); - return; - } + NetUpdate (); + lowtic = MAXINT; + + for (i=0 ; inumnodes ; i++) + if (nodeingame[i] && nettics[i] < lowtic) + lowtic = nettics[i]; + + if (lowtic < gametic/ticdup) + I_Error ("TryRunTics: lowtic < gametic"); + + // don't stay in here forever -- give the menu a chance to work + if (I_GetTime ()/ticdup - entertic >= 20) + { + M_Ticker (); + return; + } } // run the count * ticdup dics while (counts--) { - for (i=0 ; i lowtic) - I_Error ("gametic>lowtic"); - if (advancedemo) - D_DoAdvanceDemo (); - M_Ticker (); - G_Ticker (); - gametic++; - - // modify command for duplicated tics - if (i != ticdup-1) - { - ticcmd_t *cmd; - int buf; - int j; - - buf = (gametic/ticdup)%BACKUPTICS; - for (j=0 ; jchatchar = 0; - if (cmd->buttons & BT_SPECIAL) - cmd->buttons = 0; - } - } - } - NetUpdate (); // check for new console commands + for (i=0 ; i lowtic) + I_Error ("gametic>lowtic"); + if (advancedemo) + D_DoAdvanceDemo (); + M_Ticker (); + G_Ticker (); + gametic++; + + // modify command for duplicated tics + if (i != ticdup-1) + { + ticcmd_t *cmd; + int buf; + int j; + + buf = (gametic/ticdup)%BACKUPTICS; + for (j=0 ; jchatchar = 0; + if (cmd->buttons & BT_SPECIAL) + cmd->buttons = 0; + } + } + } + NetUpdate (); // check for new console commands } } diff --git a/programs/games/doom/trunk/f_finale.c b/programs/games/doom/trunk/f_finale.c index e739873764..a6e74dd4ce 100644 --- a/programs/games/doom/trunk/f_finale.c +++ b/programs/games/doom/trunk/f_finale.c @@ -28,8 +28,8 @@ rcsid[] = "$Id: f_finale.c,v 1.5 1997/02/03 21:26:34 b1 Exp $"; #include // Functions. -#include "m_swap.h" #include "i_system.h" +#include "m_swap.h" #include "z_zone.h" #include "v_video.h" #include "w_wad.h" diff --git a/programs/games/doom/trunk/g_game.c b/programs/games/doom/trunk/g_game.c index b9f3205556..2b7c52b4b8 100644 --- a/programs/games/doom/trunk/g_game.c +++ b/programs/games/doom/trunk/g_game.c @@ -71,49 +71,49 @@ rcsid[] = "$Id: g_game.c,v 1.8 1997/02/03 22:45:09 b1 Exp $"; #include "g_game.h" -#define SAVEGAMESIZE 0x2c000 -#define SAVESTRINGSIZE 24 +#define SAVEGAMESIZE 0x2c000 +#define SAVESTRINGSIZE 24 -boolean G_CheckDemoStatus (void); -void G_ReadDemoTiccmd (ticcmd_t* cmd); -void G_WriteDemoTiccmd (ticcmd_t* cmd); -void G_PlayerReborn (int player); -void G_InitNew (skill_t skill, int episode, int map); +boolean G_CheckDemoStatus (void); +void G_ReadDemoTiccmd (ticcmd_t* cmd); +void G_WriteDemoTiccmd (ticcmd_t* cmd); +void G_PlayerReborn (int player); +void G_InitNew (skill_t skill, int episode, int map); -void G_DoReborn (int playernum); +void G_DoReborn (int playernum); -void G_DoLoadLevel (void); -void G_DoNewGame (void); -void G_DoLoadGame (void); -void G_DoPlayDemo (void); -void G_DoCompleted (void); -void G_DoVictory (void); -void G_DoWorldDone (void); -void G_DoSaveGame (void); +void G_DoLoadLevel (void); +void G_DoNewGame (void); +void G_DoLoadGame (void); +void G_DoPlayDemo (void); +void G_DoCompleted (void); +void G_DoVictory (void); +void G_DoWorldDone (void); +void G_DoSaveGame (void); gameaction_t gameaction; gamestate_t gamestate; skill_t gameskill; -boolean respawnmonsters; +boolean respawnmonsters; int gameepisode; int gamemap; boolean paused; -boolean sendpause; // send a pause event next tic -boolean sendsave; // send a save event next tic +boolean sendpause; // send a pause event next tic +boolean sendsave; // send a save event next tic boolean usergame; // ok to save / end game boolean timingdemo; // if true, exit with report on completion boolean nodrawers; // for comparative timing purposes boolean noblit; // for comparative timing purposes -int starttime; // for comparative timing purposes +int starttime; // for comparative timing purposes boolean viewactive; -boolean deathmatch; // only if started as net death +boolean deathmatch; // only if started as net death boolean netgame; // only true if packets are broadcast boolean playeringame[MAXPLAYERS]; player_t players[MAXPLAYERS]; @@ -127,35 +127,35 @@ int totalkills, totalitems, totalsecret; // for intermission char demoname[32]; boolean demorecording; boolean demoplayback; -boolean netdemo; -byte* demobuffer; -byte* demo_p; -byte* demoend; -boolean singledemo; // quit after playing a demo from cmdline +boolean netdemo; +byte* demobuffer; +byte* demo_p; +byte* demoend; +boolean singledemo; // quit after playing a demo from cmdline boolean precache = true; // if true, load all graphics at start -wbstartstruct_t wminfo; // parms for world map / intermission +wbstartstruct_t wminfo; // parms for world map / intermission -short consistancy[MAXPLAYERS][BACKUPTICS]; +short consistancy[MAXPLAYERS][BACKUPTICS]; -byte* savebuffer; +byte* savebuffer; // // controls (have defaults) // int key_right; -int key_left; +int key_left; -int key_up; -int key_down; +int key_up; +int key_down; int key_strafeleft; -int key_straferight; +int key_straferight; int key_fire; -int key_use; -int key_strafe; -int key_speed; +int key_use; +int key_strafe; +int key_speed; int mousebfire; int mousebstrafe; @@ -168,62 +168,62 @@ int joybspeed; -#define MAXPLMOVE (forwardmove[1]) +#define MAXPLMOVE (forwardmove[1]) -#define TURBOTHRESHOLD 0x32 +#define TURBOTHRESHOLD 0x32 -fixed_t forwardmove[2] = {0x19, 0x32}; -fixed_t sidemove[2] = {0x18, 0x28}; -fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn +fixed_t forwardmove[2] = {0x19, 0x32}; +fixed_t sidemove[2] = {0x18, 0x28}; +fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn -#define SLOWTURNTICS 6 +#define SLOWTURNTICS 6 -#define NUMKEYS 256 +#define NUMKEYS 256 boolean gamekeydown[NUMKEYS]; -int turnheld; // for accelerative turning +int turnheld; // for accelerative turning -boolean mousearray[4]; -boolean* mousebuttons = &mousearray[1]; // allow [-1] +boolean mousearray[4]; +boolean* mousebuttons = &mousearray[1]; // allow [-1] // mouse values are used once int mousex; -int mousey; +int mousey; int dclicktime; -int dclickstate; -int dclicks; +int dclickstate; +int dclicks; int dclicktime2; -int dclickstate2; -int dclicks2; +int dclickstate2; +int dclicks2; // joystick values are repeated int joyxmove; -int joyymove; +int joyymove; boolean joyarray[5]; -boolean* joybuttons = &joyarray[1]; // allow [-1] +boolean* joybuttons = &joyarray[1]; // allow [-1] -int savegameslot; -char savedescription[32]; +int savegameslot; +char savedescription[32]; -#define BODYQUESIZE 32 +#define BODYQUESIZE 32 -mobj_t* bodyque[BODYQUESIZE]; -int bodyqueslot; +mobj_t* bodyque[BODYQUESIZE]; +int bodyqueslot; -void* statcopy; // for statistics driver +void* statcopy; // for statistics driver int G_CmdChecksum (ticcmd_t* cmd) { - int i; - int sum = 0; - + int i; + int sum = 0; + for (i=0 ; i< sizeof(*cmd)/4 - 1 ; i++) - sum += ((int *)cmd)[i]; - + sum += ((int *)cmd)[i]; + return sum; } @@ -236,203 +236,203 @@ int G_CmdChecksum (ticcmd_t* cmd) // void G_BuildTiccmd (ticcmd_t* cmd) { - int i; - boolean strafe; - boolean bstrafe; - int speed; - int tspeed; - int forward; - int side; + int i; + boolean strafe; + boolean bstrafe; + int speed; + int tspeed; + int forward; + int side; - ticcmd_t* base; + ticcmd_t* base; - base = I_BaseTiccmd (); // empty, or external driver + base = I_BaseTiccmd (); // empty, or external driver memcpy (cmd,base,sizeof(*cmd)); - + cmd->consistancy = - consistancy[consoleplayer][maketic%BACKUPTICS]; + consistancy[consoleplayer][maketic%BACKUPTICS]; - strafe = gamekeydown[key_strafe] || mousebuttons[mousebstrafe] - || joybuttons[joybstrafe]; - speed = gamekeydown[key_speed] || joybuttons[joybspeed]; + strafe = gamekeydown[key_strafe]; // || mousebuttons[mousebstrafe] +// || joybuttons[joybstrafe]; + speed = gamekeydown[key_speed]; // || joybuttons[joybspeed]; forward = side = 0; // use two stage accelerative turning // on the keyboard and joystick if (joyxmove < 0 - || joyxmove > 0 - || gamekeydown[key_right] - || gamekeydown[key_left]) - turnheld += ticdup; + || joyxmove > 0 + || gamekeydown[key_right] + || gamekeydown[key_left]) + turnheld += ticdup; else - turnheld = 0; + turnheld = 0; if (turnheld < SLOWTURNTICS) - tspeed = 2; // slow turn + tspeed = 2; // slow turn else - tspeed = speed; + tspeed = speed; // let movement keys cancel each other out if (strafe) { - if (gamekeydown[key_right]) - { - // fprintf(stderr, "strafe right\n"); - side += sidemove[speed]; - } - if (gamekeydown[key_left]) - { - // fprintf(stderr, "strafe left\n"); - side -= sidemove[speed]; - } - if (joyxmove > 0) - side += sidemove[speed]; - if (joyxmove < 0) - side -= sidemove[speed]; + if (gamekeydown[key_right]) + { + // fprintf(stderr, "strafe right\n"); + side += sidemove[speed]; + } + if (gamekeydown[key_left]) + { + // fprintf(stderr, "strafe left\n"); + side -= sidemove[speed]; + } + if (joyxmove > 0) + side += sidemove[speed]; + if (joyxmove < 0) + side -= sidemove[speed]; } else { - if (gamekeydown[key_right]) - cmd->angleturn -= angleturn[tspeed]; - if (gamekeydown[key_left]) - cmd->angleturn += angleturn[tspeed]; - if (joyxmove > 0) - cmd->angleturn -= angleturn[tspeed]; - if (joyxmove < 0) - cmd->angleturn += angleturn[tspeed]; + if (gamekeydown[key_right]) + cmd->angleturn -= angleturn[tspeed]; + if (gamekeydown[key_left]) + cmd->angleturn += angleturn[tspeed]; + if (joyxmove > 0) + cmd->angleturn -= angleturn[tspeed]; + if (joyxmove < 0) + cmd->angleturn += angleturn[tspeed]; } if (gamekeydown[key_up]) { - // fprintf(stderr, "up\n"); - forward += forwardmove[speed]; + // fprintf(stderr, "up\n"); + forward += forwardmove[speed]; } if (gamekeydown[key_down]) { - // fprintf(stderr, "down\n"); - forward -= forwardmove[speed]; + forward -= forwardmove[speed]; +// printf("forward= %d\n\r", forward); } - if (joyymove < 0) - forward += forwardmove[speed]; - if (joyymove > 0) - forward -= forwardmove[speed]; +// if (joyymove < 0) +// forward += forwardmove[speed]; +// if (joyymove > 0) +// forward -= forwardmove[speed]; if (gamekeydown[key_straferight]) - side += sidemove[speed]; + side += sidemove[speed]; if (gamekeydown[key_strafeleft]) - side -= sidemove[speed]; + side -= sidemove[speed]; // buttons cmd->chatchar = HU_dequeueChatChar(); if (gamekeydown[key_fire] || mousebuttons[mousebfire] - || joybuttons[joybfire]) - cmd->buttons |= BT_ATTACK; + || joybuttons[joybfire]) + cmd->buttons |= BT_ATTACK; if (gamekeydown[key_use] || joybuttons[joybuse] ) { - cmd->buttons |= BT_USE; - // clear double clicks if hit use button - dclicks = 0; + cmd->buttons |= BT_USE; + // clear double clicks if hit use button + dclicks = 0; } // chainsaw overrides for (i=0 ; ibuttons |= BT_CHANGE; - cmd->buttons |= i<buttons |= BT_CHANGE; + cmd->buttons |= i< 1 ) { - dclickstate = mousebuttons[mousebforward]; - if (dclickstate) - dclicks++; - if (dclicks == 2) - { - cmd->buttons |= BT_USE; - dclicks = 0; - } - else - dclicktime = 0; + dclickstate = mousebuttons[mousebforward]; + if (dclickstate) + dclicks++; + if (dclicks == 2) + { + cmd->buttons |= BT_USE; + dclicks = 0; + } + else + dclicktime = 0; } else { - dclicktime += ticdup; - if (dclicktime > 20) - { - dclicks = 0; - dclickstate = 0; - } + dclicktime += ticdup; + if (dclicktime > 20) + { + dclicks = 0; + dclickstate = 0; + } } // strafe double click bstrafe = - mousebuttons[mousebstrafe] - || joybuttons[joybstrafe]; + mousebuttons[mousebstrafe] + || joybuttons[joybstrafe]; if (bstrafe != dclickstate2 && dclicktime2 > 1 ) { - dclickstate2 = bstrafe; - if (dclickstate2) - dclicks2++; - if (dclicks2 == 2) - { - cmd->buttons |= BT_USE; - dclicks2 = 0; - } - else - dclicktime2 = 0; + dclickstate2 = bstrafe; + if (dclickstate2) + dclicks2++; + if (dclicks2 == 2) + { + cmd->buttons |= BT_USE; + dclicks2 = 0; + } + else + dclicktime2 = 0; } else { - dclicktime2 += ticdup; - if (dclicktime2 > 20) - { - dclicks2 = 0; - dclickstate2 = 0; - } + dclicktime2 += ticdup; + if (dclicktime2 > 20) + { + dclicks2 = 0; + dclickstate2 = 0; + } } - forward += mousey; +// forward += mousey; if (strafe) - side += mousex*2; + side += mousex*2; else - cmd->angleturn -= mousex*0x8; + cmd->angleturn -= mousex*0x8; mousex = mousey = 0; - + if (forward > MAXPLMOVE) - forward = MAXPLMOVE; + forward = MAXPLMOVE; else if (forward < -MAXPLMOVE) - forward = -MAXPLMOVE; + forward = -MAXPLMOVE; if (side > MAXPLMOVE) - side = MAXPLMOVE; + side = MAXPLMOVE; else if (side < -MAXPLMOVE) - side = -MAXPLMOVE; + side = -MAXPLMOVE; cmd->forwardmove += forward; cmd->sidemove += side; - + // special buttons if (sendpause) { - sendpause = false; - cmd->buttons = BT_SPECIAL | BTS_PAUSE; + sendpause = false; + cmd->buttons = BT_SPECIAL | BTS_PAUSE; } if (sendsave) { - sendsave = false; - cmd->buttons = BT_SPECIAL | BTS_SAVEGAME | (savegameslot<buttons = BT_SPECIAL | BTS_SAVEGAME | (savegameslot<type == ev_keydown - && ev->data1 == KEY_F12 && (singledemo || !deathmatch) ) + && ev->data1 == KEY_F12 && (singledemo || !deathmatch) ) { - // spy mode - do - { - displayplayer++; - if (displayplayer == MAXPLAYERS) - displayplayer = 0; - } while (!playeringame[displayplayer] && displayplayer != consoleplayer); - return true; + // spy mode + do + { + displayplayer++; + if (displayplayer == MAXPLAYERS) + displayplayer = 0; + } while (!playeringame[displayplayer] && displayplayer != consoleplayer); + return true; } // any other key pops up menu if in demos if (gameaction == ga_nothing && !singledemo && - (demoplayback || gamestate == GS_DEMOSCREEN) - ) + (demoplayback || gamestate == GS_DEMOSCREEN) + ) { - if (ev->type == ev_keydown || - (ev->type == ev_mouse && ev->data1) || - (ev->type == ev_joystick && ev->data1) ) - { - M_StartControlPanel (); - return true; - } - return false; + if (ev->type == ev_keydown || + (ev->type == ev_mouse && ev->data1) || + (ev->type == ev_joystick && ev->data1) ) + { + M_StartControlPanel (); + return true; + } + return false; } if (gamestate == GS_LEVEL) { #if 0 - if (devparm && ev->type == ev_keydown && ev->data1 == ';') - { - G_DeathMatchSpawnPlayer (0); - return true; - } + if (devparm && ev->type == ev_keydown && ev->data1 == ';') + { + G_DeathMatchSpawnPlayer (0); + return true; + } #endif - if (HU_Responder (ev)) - return true; // chat ate the event - if (ST_Responder (ev)) - return true; // status window ate it - if (AM_Responder (ev)) - return true; // automap ate it + if (HU_Responder (ev)) + return true; // chat ate the event + if (ST_Responder (ev)) + return true; // status window ate it + if (AM_Responder (ev)) + return true; // automap ate it } - + if (gamestate == GS_FINALE) { - if (F_Responder (ev)) - return true; // finale ate the event + if (F_Responder (ev)) + return true; // finale ate the event } - + switch (ev->type) { case ev_keydown: - if (ev->data1 == KEY_PAUSE) - { - sendpause = true; - return true; - } - if (ev->data1 data1] = true; - return true; // eat key down events + if (ev->data1 == KEY_PAUSE) + { + sendpause = true; + return true; + } + if (ev->data1 data1] = true; + return true; // eat key down events case ev_keyup: - if (ev->data1 data1] = false; - return false; // always let key up events filter down - + if (ev->data1 data1] = false; + return false; // always let key up events filter down + case ev_mouse: - mousebuttons[0] = ev->data1 & 1; - mousebuttons[1] = ev->data1 & 2; - mousebuttons[2] = ev->data1 & 4; - mousex = ev->data2*(mouseSensitivity+5)/10; - mousey = ev->data3*(mouseSensitivity+5)/10; - return true; // eat events + mousebuttons[0] = ev->data1 & 1; + mousebuttons[1] = ev->data1 & 2; + mousebuttons[2] = ev->data1 & 4; + mousex = ev->data2*(mouseSensitivity+5)/10; + mousey = ev->data3*(mouseSensitivity+5)/10; + return true; // eat events case ev_joystick: - joybuttons[0] = ev->data1 & 1; - joybuttons[1] = ev->data1 & 2; - joybuttons[2] = ev->data1 & 4; - joybuttons[3] = ev->data1 & 8; - joyxmove = ev->data2; - joyymove = ev->data3; - return true; // eat events + joybuttons[0] = ev->data1 & 1; + joybuttons[1] = ev->data1 & 2; + joybuttons[2] = ev->data1 & 4; + joybuttons[3] = ev->data1 & 8; + joyxmove = ev->data2; + joyymove = ev->data3; + return true; // eat events default: - break; + break; } return false; @@ -604,51 +604,51 @@ boolean G_Responder (event_t* ev) // void G_Ticker (void) { - int i; - int buf; - ticcmd_t* cmd; + int i; + int buf; + ticcmd_t* cmd; // do player reborns if needed for (i=0 ; iforwardmove > TURBOTHRESHOLD - && !(gametic&31) && ((gametic>>5)&3) == i ) - { - static char turbomessage[80]; - extern char *player_names[4]; - sprintf (turbomessage, "%s is turbo!",player_names[i]); - players[consoleplayer].message = turbomessage; - } - - if (netgame && !netdemo && !(gametic%ticdup) ) - { - if (gametic > BACKUPTICS - && consistancy[i][buf] != cmd->consistancy) - { - I_Error ("consistency failure (%i should be %i)", - cmd->consistancy, consistancy[i][buf]); - } - if (players[i].mo) - consistancy[i][buf] = players[i].mo->x; - else - consistancy[i][buf] = rndindex; - } - } + if (demoplayback) + G_ReadDemoTiccmd (cmd); + if (demorecording) + G_WriteDemoTiccmd (cmd); + + // check for turbo cheats + if (cmd->forwardmove > TURBOTHRESHOLD + && !(gametic&31) && ((gametic>>5)&3) == i ) + { + static char turbomessage[80]; + extern char *player_names[4]; + sprintf (turbomessage, "%s is turbo!",player_names[i]); + players[consoleplayer].message = turbomessage; + } + + if (netgame && !netdemo && !(gametic%ticdup) ) + { + if (gametic > BACKUPTICS + && consistancy[i][buf] != cmd->consistancy) + { + I_Error ("consistency failure (%i should be %i)", + cmd->consistancy, consistancy[i][buf]); + } + if (players[i].mo) + consistancy[i][buf] = players[i].mo->x; + else + consistancy[i][buf] = rndindex; + } + } } // check for special buttons for (i=0 ; i>BTS_SAVESHIFT; - gameaction = ga_savegame; - break; - } - } - } + if (playeringame[i]) + { + if (players[i].cmd.buttons & BT_SPECIAL) + { + switch (players[i].cmd.buttons & BT_SPECIALMASK) + { + case BTS_PAUSE: + paused ^= 1; + // if (paused) + // S_PauseSound (); + // else + // S_ResumeSound (); + break; + + case BTS_SAVEGAME: + if (!savedescription[0]) + strcpy (savedescription, "NET GAME"); + savegameslot = + (players[i].cmd.buttons & BTS_SAVEMASK)>>BTS_SAVESHIFT; + gameaction = ga_savegame; + break; + } + } + } } // do main actions switch (gamestate) { case GS_LEVEL: - P_Ticker (); - ST_Ticker (); - AM_Ticker (); - HU_Ticker (); - break; - + P_Ticker (); + ST_Ticker (); + AM_Ticker (); + HU_Ticker (); + break; + case GS_INTERMISSION: - WI_Ticker (); - break; - + WI_Ticker (); + break; + case GS_FINALE: - F_Ticker (); - break; + F_Ticker (); + break; case GS_DEMOSCREEN: - D_PageTicker (); - break; + D_PageTicker (); + break; } } @@ -760,14 +760,14 @@ void G_Ticker (void) // void G_InitPlayer (int player) { - player_t* p; + player_t* p; // set up the saved info p = &players[player]; - + // clear everything else to defaults G_PlayerReborn (player); - + } @@ -778,16 +778,16 @@ void G_InitPlayer (int player) // void G_PlayerFinishLevel (int player) { - player_t* p; - + player_t* p; + p = &players[player]; - + memset (p->powers, 0, sizeof (p->powers)); memset (p->cards, 0, sizeof (p->cards)); - p->mo->flags &= ~MF_SHADOW; // cancel invisibility - p->extralight = 0; // cancel gun flashes - p->fixedcolormap = 0; // cancel ir gogles - p->damagecount = 0; // no palette changes + p->mo->flags &= ~MF_SHADOW; // cancel invisibility + p->extralight = 0; // cancel gun flashes + p->fixedcolormap = 0; // cancel ir gogles + p->damagecount = 0; // no palette changes p->bonuscount = 0; } @@ -799,18 +799,18 @@ void G_PlayerFinishLevel (int player) // void G_PlayerReborn (int player) { - player_t* p; - int i; - int frags[MAXPLAYERS]; - int killcount; - int itemcount; - int secretcount; - + player_t* p; + int i; + int frags[MAXPLAYERS]; + int killcount; + int itemcount; + int secretcount; + memcpy (frags,players[player].frags,sizeof(frags)); killcount = players[player].killcount; itemcount = players[player].itemcount; secretcount = players[player].secretcount; - + p = &players[player]; memset (p, 0, sizeof(*p)); @@ -819,17 +819,17 @@ void G_PlayerReborn (int player) players[player].itemcount = itemcount; players[player].secretcount = secretcount; - p->usedown = p->attackdown = true; // don't do anything immediately + p->usedown = p->attackdown = true; // don't do anything immediately p->playerstate = PST_LIVE; p->health = MAXHEALTH; p->readyweapon = p->pendingweapon = wp_pistol; p->weaponowned[wp_fist] = true; p->weaponowned[wp_pistol] = true; p->ammo[am_clip] = 50; - + for (i=0 ; imaxammo[i] = maxammo[i]; - + p->maxammo[i] = maxammo[i]; + } // @@ -842,48 +842,48 @@ void P_SpawnPlayer (mapthing_t* mthing); boolean G_CheckSpot -( int playernum, - mapthing_t* mthing ) +( int playernum, + mapthing_t* mthing ) { - fixed_t x; - fixed_t y; - subsector_t* ss; - unsigned an; - mobj_t* mo; - int i; - + fixed_t x; + fixed_t y; + subsector_t* ss; + unsigned an; + mobj_t* mo; + int i; + if (!players[playernum].mo) { - // first spawn of level, before corpses - for (i=0 ; ix == mthing->x << FRACBITS - && players[i].mo->y == mthing->y << FRACBITS) - return false; - return true; + // first spawn of level, before corpses + for (i=0 ; ix == mthing->x << FRACBITS + && players[i].mo->y == mthing->y << FRACBITS) + return false; + return true; } - + x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; - + if (!P_CheckPosition (players[playernum].mo, x, y) ) - return false; + return false; // flush an old corpse if needed if (bodyqueslot >= BODYQUESIZE) - P_RemoveMobj (bodyque[bodyqueslot%BODYQUESIZE]); + P_RemoveMobj (bodyque[bodyqueslot%BODYQUESIZE]); bodyque[bodyqueslot%BODYQUESIZE] = players[playernum].mo; bodyqueslot++; - + // spawn a teleport fog ss = R_PointInSubsector (x,y); an = ( ANG45 * (mthing->angle/45) ) >> ANGLETOFINESHIFT; mo = P_SpawnMobj (x+20*finecosine[an], y+20*finesine[an] - , ss->sector->floorheight - , MT_TFOG); - - if (players[consoleplayer].viewz != 1) - S_StartSound (mo, sfx_telept); // don't start sound on first frame + , ss->sector->floorheight + , MT_TFOG); + + // if (players[consoleplayer].viewz != 1) + // S_StartSound (mo, sfx_telept); // don't start sound on first frame return true; } @@ -897,21 +897,21 @@ G_CheckSpot void G_DeathMatchSpawnPlayer (int playernum) { int i,j; - int selections; - + int selections; + selections = deathmatch_p - deathmatchstarts; if (selections < 4) - I_Error ("Only %i deathmatch spots, 4 required", selections); + I_Error ("Only %i deathmatch spots, 4 required", selections); for (j=0 ; j<20 ; j++) { - i = P_Random() % selections; - if (G_CheckSpot (playernum, &deathmatchstarts[i]) ) - { - deathmatchstarts[i].type = playernum+1; - P_SpawnPlayer (&deathmatchstarts[i]); - return; - } + i = P_Random() % selections; + if (G_CheckSpot (playernum, &deathmatchstarts[i]) ) + { + deathmatchstarts[i].type = playernum+1; + P_SpawnPlayer (&deathmatchstarts[i]); + return; + } } // no good spot, so the player will probably get stuck @@ -924,45 +924,45 @@ void G_DeathMatchSpawnPlayer (int playernum) void G_DoReborn (int playernum) { int i; - + if (!netgame) { - // reload the level from scratch - gameaction = ga_loadlevel; + // reload the level from scratch + gameaction = ga_loadlevel; } else { - // respawn at the start + // respawn at the start - // first dissasociate the corpse - players[playernum].mo->player = NULL; - - // spawn at random spot if in death match - if (deathmatch) - { - G_DeathMatchSpawnPlayer (playernum); - return; - } - - if (G_CheckSpot (playernum, &playerstarts[playernum]) ) - { - P_SpawnPlayer (&playerstarts[playernum]); - return; - } - - // try to spawn at one of the other players spots - for (i=0 ; iplayer = NULL; + + // spawn at random spot if in death match + if (deathmatch) + { + G_DeathMatchSpawnPlayer (playernum); + return; + } + + if (G_CheckSpot (playernum, &playerstarts[playernum]) ) + { + P_SpawnPlayer (&playerstarts[playernum]); + return; + } + + // try to spawn at one of the other players spots + for (i=0 ; i>16; *save_p++ = leveltime>>8; *save_p++ = leveltime; @@ -1300,20 +1300,20 @@ void G_DoSaveGame (void) P_ArchiveWorld (); P_ArchiveThinkers (); P_ArchiveSpecials (); - - *save_p++ = 0x1d; // consistancy marker - + + *save_p++ = 0x1d; // consistancy marker + length = save_p - savebuffer; if (length > SAVEGAMESIZE) - I_Error ("Savegame buffer overrun"); + I_Error ("Savegame buffer overrun"); M_WriteFile (name, savebuffer, length); gameaction = ga_nothing; - savedescription[0] = 0; - + savedescription[0] = 0; + players[consoleplayer].message = GGSAVED; // draw the pattern into the back screen - R_FillBackScreen (); + R_FillBackScreen (); } @@ -1322,15 +1322,15 @@ void G_DoSaveGame (void) // Can be called by the startup code or the menu task, // consoleplayer, displayplayer, playeringame[] should be set. // -skill_t d_skill; +skill_t d_skill; int d_episode; int d_map; void G_DeferedInitNew -( skill_t skill, - int episode, - int map) +( skill_t skill, + int episode, + int map) { d_skill = skill; d_episode = episode; @@ -1355,26 +1355,26 @@ void G_DoNewGame (void) } // The sky texture to be used instead of the F_SKY1 dummy. -extern int skytexture; +extern int skytexture; void G_InitNew -( skill_t skill, - int episode, - int map ) +( skill_t skill, + int episode, + int map ) { int i; - + if (paused) { - paused = false; - S_ResumeSound (); + paused = false; + // S_ResumeSound (); } - + if (skill > sk_nightmare) - skill = sk_nightmare; + skill = sk_nightmare; // This was quite messy with SPECIAL and commented parts. @@ -1386,56 +1386,56 @@ G_InitNew if ( gamemode == retail ) { if (episode > 4) - episode = 4; + episode = 4; } else if ( gamemode == shareware ) { if (episode > 1) - episode = 1; // only start episode 1 on shareware + episode = 1; // only start episode 1 on shareware } else { if (episode > 3) - episode = 3; + episode = 3; } if (map < 1) - map = 1; + map = 1; if ( (map > 9) - && ( gamemode != commercial) ) + && ( gamemode != commercial) ) map = 9; - + M_ClearRandom (); - + if (skill == sk_nightmare || respawnparm ) - respawnmonsters = true; + respawnmonsters = true; else - respawnmonsters = false; - + respawnmonsters = false; + if (fastparm || (skill == sk_nightmare && gameskill != sk_nightmare) ) { - for (i=S_SARG_RUN1 ; i<=S_SARG_PAIN2 ; i++) - states[i].tics >>= 1; - mobjinfo[MT_BRUISERSHOT].speed = 20*FRACUNIT; - mobjinfo[MT_HEADSHOT].speed = 20*FRACUNIT; - mobjinfo[MT_TROOPSHOT].speed = 20*FRACUNIT; + for (i=S_SARG_RUN1 ; i<=S_SARG_PAIN2 ; i++) + states[i].tics >>= 1; + mobjinfo[MT_BRUISERSHOT].speed = 20*FRACUNIT; + mobjinfo[MT_HEADSHOT].speed = 20*FRACUNIT; + mobjinfo[MT_TROOPSHOT].speed = 20*FRACUNIT; } else if (skill != sk_nightmare && gameskill == sk_nightmare) { - for (i=S_SARG_RUN1 ; i<=S_SARG_PAIN2 ; i++) - states[i].tics <<= 1; - mobjinfo[MT_BRUISERSHOT].speed = 15*FRACUNIT; - mobjinfo[MT_HEADSHOT].speed = 10*FRACUNIT; - mobjinfo[MT_TROOPSHOT].speed = 10*FRACUNIT; + for (i=S_SARG_RUN1 ; i<=S_SARG_PAIN2 ; i++) + states[i].tics <<= 1; + mobjinfo[MT_BRUISERSHOT].speed = 15*FRACUNIT; + mobjinfo[MT_HEADSHOT].speed = 10*FRACUNIT; + mobjinfo[MT_TROOPSHOT].speed = 10*FRACUNIT; } - - + + // force players to be initialized upon first level load for (i=0 ; iforwardmove = ((signed char)*demo_p++); cmd->sidemove = ((signed char)*demo_p++); @@ -1503,7 +1503,7 @@ void G_ReadDemoTiccmd (ticcmd_t* cmd) void G_WriteDemoTiccmd (ticcmd_t* cmd) { if (gamekeydown['q']) // press q to end demo recording - G_CheckDemoStatus (); + G_CheckDemoStatus (); *demo_p++ = cmd->forwardmove; *demo_p++ = cmd->sidemove; *demo_p++ = (cmd->angleturn+128)>>8; @@ -1511,11 +1511,11 @@ void G_WriteDemoTiccmd (ticcmd_t* cmd) demo_p -= 4; if (demo_p > demoend - 16) { - // no more space - G_CheckDemoStatus (); - return; + // no more space + G_CheckDemoStatus (); + return; } - + G_ReadDemoTiccmd (cmd); // make SURE it is exactly the same } @@ -1527,18 +1527,18 @@ void G_WriteDemoTiccmd (ticcmd_t* cmd) void G_RecordDemo (char* name) { int i; - int maxsize; - + int maxsize; + usergame = false; strcpy (demoname, name); strcat (demoname, ".lmp"); maxsize = 0x20000; i = M_CheckParm ("-maxdemo"); if (i && i -#include "m_swap.h" - #include "doomdef.h" #include "v_video.h" +#include "m_swap.h" #include "hu_lib.h" #include "r_local.h" diff --git a/programs/games/doom/trunk/i_main.c b/programs/games/doom/trunk/i_main.c index 08111b884e..0afa1d547b 100644 --- a/programs/games/doom/trunk/i_main.c +++ b/programs/games/doom/trunk/i_main.c @@ -17,32 +17,40 @@ // $Log:$ // // DESCRIPTION: -// Main program, simply calls D_DoomMain high level loop. +// Main program, simply calls D_DoomMain high level loop. // //----------------------------------------------------------------------------- static const char rcsid[] = "$Id: i_main.c,v 1.4 1997/02/03 22:45:10 b1 Exp $"; - -//#include "SDL.h" - #include "doomdef.h" #include "m_argv.h" #include "d_main.h" +#include "kolibri.h" -int -main( int argc, char** argv) +int main(int argc, char **argv) { - static char * tmp[]= - {"/hd/1/menuetos/doom/mdoom", - NULL}; +// static char * tmp[]= +// {"/hd/1/menuetos/doom/mdoom", +// NULL}; myargc = 1; - myargv = tmp; + myargv = argv; - // chdir("/hd/1/menuetos/doom"); - +// InitHeap(32*1024*1024); + _asm + { + push ebx + push ecx + mov eax, 66 + mov ebx, 1 + mov ecx, 1 + int 0x40 + pop ecx + pop ebx + }; + D_DoomMain (); return 0; diff --git a/programs/games/doom/trunk/i_net.c b/programs/games/doom/trunk/i_net.c index 5447c82116..b8ee5be40e 100644 --- a/programs/games/doom/trunk/i_net.c +++ b/programs/games/doom/trunk/i_net.c @@ -1,3 +1,4 @@ + #include #include #include @@ -9,6 +10,18 @@ #include "doomstat.h" #include "i_net.h" +#ifdef DLHEAP + +void* _cdecl dlmalloc(size_t); +void _cdecl dlfree(void*); +void _cdecl mf_init(); + +#define malloc dlmalloc +#define free dlfree +#define realloc dlrealloc + +#endif + #ifndef B_HOST_IS_LENDIAN #define B_HOST_IS_LENDIAN 1 #endif @@ -26,7 +39,7 @@ ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \ (((unsigned short int)(x) & 0xff00) >> 8))) #endif - + #ifndef htonl #define htonl(x) ntohl(x) #endif @@ -35,7 +48,7 @@ #endif #endif -void NetSend (void); +void NetSend (void); int NetListen (void); @@ -44,18 +57,19 @@ int NetListen (void); // #ifndef IPPORT_USERRESERVED -#define IPPORT_USERRESERVED 5000 +#define IPPORT_USERRESERVED 5000 #endif -int DOOMPORT = (IPPORT_USERRESERVED+0x1d); -int sendsocket[MAXNETNODES]; -int insocket; +int DOOMPORT = (IPPORT_USERRESERVED+0x1d); +int sendsocket[MAXNETNODES]; +int insocket; -void (*netget) (void); -void (*netsend) (void); +void (*netget) (void); +void (*netsend) (void); static int first_user_port=IPPORT_USERRESERVED+0x1D+0x10; +/********** int GetAvailPort(void) { int i,d0; @@ -70,11 +84,11 @@ int GetAvailPort(void) I_Error("Unable to get new port\n"); return -1; } - +**********/ int CreateInputUDPsocket(void) { - int d0; + int d0=0; //__asm__ __volatile__( // "int $0x40" // :"=a"(d0) @@ -108,7 +122,12 @@ int CreateOutputUDPSocket(int remote_ip) void PacketSend (void) { int c; - doomdata_t sw; + doomdata_t sw; + + + //printf("ERROR Packet Send\n\r"); + + // byte swap sw.checksum = htonl(netbuffer->checksum); sw.player = netbuffer->player; @@ -158,12 +177,13 @@ int GetLocalAddress (void) // // I_InitNetwork // + void I_InitNetwork (void) { - boolean trueval = true; - int i; - int p; - + boolean trueval = true; + int i; + int p; + doomcom = malloc (sizeof (*doomcom) ); memset (doomcom, 0, sizeof(*doomcom) ); @@ -171,25 +191,25 @@ void I_InitNetwork (void) i = M_CheckParm ("-dup"); if (i && i< myargc-1) { - doomcom->ticdup = myargv[i+1][0]-'0'; - if (doomcom->ticdup < 1) - doomcom->ticdup = 1; - if (doomcom->ticdup > 9) - doomcom->ticdup = 9; + doomcom->ticdup = myargv[i+1][0]-'0'; + if (doomcom->ticdup < 1) + doomcom->ticdup = 1; + if (doomcom->ticdup > 9) + doomcom->ticdup = 9; } else - doomcom-> ticdup = 1; - + doomcom-> ticdup = 1; + if (M_CheckParm ("-extratic")) - doomcom-> extratics = 1; + doomcom-> extratics = 1; else - doomcom-> extratics = 0; - + doomcom-> extratics = 0; + p = M_CheckParm ("-port"); if (p && pid = DOOMCOM_ID; - doomcom->numplayers = doomcom->numnodes = 1; - doomcom->deathmatch = false; - doomcom->consoleplayer = 0; - return; + // single player game + netgame = false; + doomcom->id = DOOMCOM_ID; + doomcom->numplayers = doomcom->numnodes = 1; + doomcom->deathmatch = false; + doomcom->consoleplayer = 0; + return; } netsend = PacketSend; @@ -214,7 +234,7 @@ void I_InitNetwork (void) // parse player number and host list doomcom->consoleplayer = myargv[i+1][0]-'1'; - doomcom->numnodes = 1; // this node for sure + doomcom->numnodes = 1; // this node for sure doomcom->id = DOOMCOM_ID; doomcom->numplayers = doomcom->numnodes; sendsocket[0]=0; @@ -226,17 +246,21 @@ void I_InitNetwork (void) // __libclog_printf("DOOM: Input UDP socket is %d\n",insocket); } - void I_NetCmd (void) { + + + //printf("ERROR NetCmd"); + + if (doomcom->command == CMD_SEND) { - netsend (); +// netsend (); } else if (doomcom->command == CMD_GET) { - netget (); +// netget (); } else - I_Error ("Bad net cmd: %i\n",doomcom->command); + I_Error ("Bad net cmd: %i\n",doomcom->command); } diff --git a/programs/games/doom/trunk/i_sound.c b/programs/games/doom/trunk/i_sound.c index dcea05f5f4..bf4c58561b 100644 --- a/programs/games/doom/trunk/i_sound.c +++ b/programs/games/doom/trunk/i_sound.c @@ -17,7 +17,7 @@ // $Log:$ // // DESCRIPTION: -// System interface for sound. +// System interface for sound. // //----------------------------------------------------------------------------- @@ -55,37 +55,37 @@ rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $"; // Needed for calling the actual sound output. -#define SAMPLECOUNT 512 -#define NUM_CHANNELS 16 +#define SAMPLECOUNT 512 +#define NUM_CHANNELS 16 // It is 2 for 16bit, and 2 for two channels. #define BUFMUL 4 -#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) +#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) -#define SAMPLERATE 11025 // Hz -#define SAMPLESIZE 2 // 16bit +#define SAMPLERATE 11025 // Hz +#define SAMPLESIZE 2 // 16bit // The actual lengths of all sound effects. -int lengths[NUMSFX]; +int lengths[NUMSFX]; // The actual output device. -int audio_fd; +int audio_fd; // The global mixing buffer. // Basically, samples from all active internal channels // are modifed and added, and stored in the buffer // that is submitted to the audio device. -signed short mixbuffer[MIXBUFFERSIZE]; +signed short mixbuffer[MIXBUFFERSIZE]; // The channel step amount... -unsigned int channelstep[NUM_CHANNELS]; +unsigned int channelstep[NUM_CHANNELS]; // ... and a 0.16 bit remainder of last step. -unsigned int channelstepremainder[NUM_CHANNELS]; +unsigned int channelstepremainder[NUM_CHANNELS]; // The channel data pointers, start and end. -unsigned char* channels[NUM_CHANNELS]; -unsigned char* channelsend[NUM_CHANNELS]; +unsigned char* channels[NUM_CHANNELS]; +unsigned char* channelsend[NUM_CHANNELS]; // Time/gametic that the channel started playing, @@ -93,27 +93,27 @@ unsigned char* channelsend[NUM_CHANNELS]; // has lowest priority. // In case number of active sounds exceeds // available channels. -int channelstart[NUM_CHANNELS]; +int channelstart[NUM_CHANNELS]; // The sound in channel handles, // determined on registration, // might be used to unregister/stop/modify, // currently unused. -int channelhandles[NUM_CHANNELS]; +int channelhandles[NUM_CHANNELS]; // SFX id of the playing sound effect. // Used to catch duplicates (like chainsaw). -int channelids[NUM_CHANNELS]; +int channelids[NUM_CHANNELS]; // Pitch to stepping lookup, unused. -int steptable[256]; +int steptable[256]; // Volume lookups. -int vol_lookup[128*256]; +int vol_lookup[128*256]; // Hardware left and right channel volume lookup. -int* channelleftvol_lookup[NUM_CHANNELS]; -int* channelrightvol_lookup[NUM_CHANNELS]; +int* channelleftvol_lookup[NUM_CHANNELS]; +int* channelrightvol_lookup[NUM_CHANNELS]; // @@ -155,7 +155,7 @@ void* getsfx (char* sfxname, int* len) // Debug. // fprintf( stderr, "." ); //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n", - // sfxname, sfxlump, size ); + // sfxname, sfxlump, size ); //fflush( stderr ); sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC ); @@ -193,54 +193,54 @@ void* getsfx (char* sfxname, int* len) // Returns a handle. // -static unsigned short handlenums = 0; +static unsigned short handlenums = 0; int addsfx(int sfxid, int volume, int step, int seperation) { - int i; - int rc = -1; + int i; + int rc = -1; - int oldest = gametic; - int oldestnum = 0; - int slot; + int oldest = gametic; + int oldestnum = 0; + int slot; - int rightvol; - int leftvol; + int rightvol; + int leftvol; // Chainsaw troubles. // Play these sound effects only one at a time. if ( sfxid == sfx_sawup - || sfxid == sfx_sawidl - || sfxid == sfx_sawful - || sfxid == sfx_sawhit - || sfxid == sfx_stnmov - || sfxid == sfx_pistol ) + || sfxid == sfx_sawidl + || sfxid == sfx_sawful + || sfxid == sfx_sawhit + || sfxid == sfx_stnmov + || sfxid == sfx_pistol ) { - // Loop all channels, check. - for (i=0 ; i> 16); ///(256*256); + volume - ((volume*seperation*seperation) >> 16); ///(256*256); seperation = seperation - 257; rightvol = - volume - ((volume*seperation*seperation) >> 16); + volume - ((volume*seperation*seperation) >> 16); // Sanity check, clamp volume. if (rightvol < 0 || rightvol > 127) - I_Error("rightvol out of bounds"); + I_Error("rightvol out of bounds"); if (leftvol < 0 || leftvol > 127) - I_Error("leftvol out of bounds"); + I_Error("leftvol out of bounds"); // Get the proper lookup table piece // for this volume level??? @@ -321,10 +321,10 @@ void I_SetChannels() // Init internal lookups (raw data, mixing buffer, channels). // This function sets up internal lookups used during // the mixing process. - int i; - int j; + int i; + int j; - int* steptablemid = steptable + 128; + int* steptablemid = steptable + 128; // Okay, reset internal mixing channels to zero. for (i=0; i> 16; - - channelstepremainder[ chan ] &= 65536-1; + // Love thy L2 chache - made this a loop. + // Now more channels could be set at compile time + // as well. Thus loop those channels. + for ( chan = 0; chan < NUM_CHANNELS; chan++ ) + { + // Check channel, if active. + if (channels[ chan ]) + { + // Get the raw data from the channel. + sample = *channels[ chan ]; + // Add left and right part + // for this channel (sound) + // to the current data. + // Adjust volume accordingly. + dl += channelleftvol_lookup[ chan ][sample]; + dr += channelrightvol_lookup[ chan ][sample]; + + channelstepremainder[ chan ] += channelstep[ chan ]; + + channels[ chan ] += channelstepremainder[ chan ] >> 16; + + channelstepremainder[ chan ] &= 65536-1; - // Check whether we are done. - if (channels[ chan ] >= channelsend[ chan ]) - channels[ chan ] = 0; - } - } - - // Clamp to range. Left hardware channel. - // Has been char instead of short. - // if (dl > 127) *leftout = 127; - // else if (dl < -128) *leftout = -128; - // else *leftout = dl; + // Check whether we are done. + if (channels[ chan ] >= channelsend[ chan ]) + channels[ chan ] = 0; + } + } + + // Clamp to range. Left hardware channel. + // Has been char instead of short. + // if (dl > 127) *leftout = 127; + // else if (dl < -128) *leftout = -128; + // else *leftout = dl; - if (dl > 0x7fff) - *leftout = 0x7fff; - else if (dl < -0x8000) - *leftout = -0x8000; - else - *leftout = dl; + if (dl > 0x7fff) + *leftout = 0x7fff; + else if (dl < -0x8000) + *leftout = -0x8000; + else + *leftout = dl; - // Same for right hardware channel. - if (dr > 0x7fff) - *rightout = 0x7fff; - else if (dr < -0x8000) - *rightout = -0x8000; - else - *rightout = dr; + // Same for right hardware channel. + if (dr > 0x7fff) + *rightout = 0x7fff; + else if (dr < -0x8000) + *rightout = -0x8000; + else + *rightout = dr; - // Increment current pointers in mixbuffer. - leftout += step; - rightout += step; + // Increment current pointers in mixbuffer. + leftout += step; + rightout += step; } - I_SubmitSound(mixbuffer); + // I_SubmitSound(mixbuffer); } @@ -577,7 +577,7 @@ void I_InitSound() { // Load data from WAD file. S_sfx[i].data = getsfx( S_sfx[i].name, &lengths[i] ); - } + } else { // Previously loaded already? @@ -603,11 +603,11 @@ void I_InitSound() // Still no music done. // Remains. Dummies. // -void I_InitMusic(void) { } -void I_ShutdownMusic(void) { } +void I_InitMusic(void) { } +void I_ShutdownMusic(void) { } -static int looping=0; -static int musicdies=-1; +static int looping=0; +static int musicdies=-1; void I_PlaySong(int handle, int looping) { diff --git a/programs/games/doom/trunk/i_system.c b/programs/games/doom/trunk/i_system.c index 7bb4a3c95b..9f58c66a6f 100644 --- a/programs/games/doom/trunk/i_system.c +++ b/programs/games/doom/trunk/i_system.c @@ -26,8 +26,6 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; #include #include #include -//#include "SDL.h" -//#include "SDL_timer.h" #include "doomdef.h" #include "m_misc.h" @@ -39,36 +37,23 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; #include "i_system.h" + #include "kolibri.h" -int mb_used = 6; - - -int I_strncasecmp(char *str1, char *str2, int len) -{ - char c1, c2; - - while ( *str1 && *str2 && len-- ) { - c1 = *str1++; - c2 = *str2++; - if ( toupper(c1) != toupper(c2) ) - return(1); - } - return(0); -} +int mb_used = 8; void I_Tactile -( int on, - int off, - int total ) +( int on, + int off, + int total ) { // UNUSED. on = off = total = 0; } -ticcmd_t emptycmd; -ticcmd_t* I_BaseTiccmd(void) +ticcmd_t emptycmd; +ticcmd_t* I_BaseTiccmd(void) { return &emptycmd; } @@ -79,7 +64,7 @@ int I_GetHeapSize (void) return mb_used*1024*1024; } -byte* I_ZoneBase (int* size) +byte* I_ZoneBase (int* size) { *size = mb_used*1024*1024; return (byte *) UserAlloc(*size); @@ -91,21 +76,17 @@ byte* I_ZoneBase (int* size) // returns time in 1/35 second tics // -__declspec(dllimport) unsigned int __stdcall GetTickCount(void); - int I_GetTime (void) { unsigned int tm; -// _asm -// { -// mov eax, 26 -// mov ebx, 9 -// int 0x40 -// mov [tm], eax -// }; - - tm=GetTickCount()/10; - + _asm + { push ebx + mov eax, 26 + mov ebx, 9 + int 0x40 + mov dword ptr [tm], eax + pop ebx + }; return (tm*TICRATE)/100; } @@ -118,7 +99,7 @@ int I_GetTime (void) void I_Init (void) { I_InitGraphics(); - I_InitSound(); + // I_InitSound(); } // @@ -148,15 +129,16 @@ void I_EndRead(void) { } -byte* I_AllocLow(int length) +/*********** +byte* I_AllocLow(int length) { - byte* mem; + byte* mem; mem = (byte *)malloc (length); memset (mem,0,length); return mem; } - +************/ // // I_Error @@ -165,18 +147,18 @@ extern boolean demorecording; void I_Error (char *error, ...) { - va_list argptr; + va_list argptr; // Message first. va_start (argptr,error); - printf ("Error: "); - printf (argptr); - printf ("\n"); + printf ("Error: "); + printf (error,argptr); + printf ("\n\r"); va_end (argptr); // Shutdown. Here might be other errors. if (demorecording) - G_CheckDemoStatus(); + G_CheckDemoStatus(); D_QuitNetGame (); I_ShutdownGraphics(); diff --git a/programs/games/doom/trunk/i_video.c b/programs/games/doom/trunk/i_video.c index 9ee295f17d..43268a2e03 100644 --- a/programs/games/doom/trunk/i_video.c +++ b/programs/games/doom/trunk/i_video.c @@ -17,7 +17,7 @@ // $Log:$ // // DESCRIPTION: -// DOOM graphics stuff for SDL library +// DOOM graphics stuff for SDL library // //----------------------------------------------------------------------------- @@ -26,9 +26,7 @@ rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $"; #include -//#include "SDL.h" - -//#include "m_swap.h" +#include "m_swap.h" #include "doomstat.h" #include "i_system.h" #include "v_video.h" @@ -36,131 +34,50 @@ rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $"; #include "d_main.h" #include "doomdef.h" -#define WIN32_LEAN_AND_MEAN -#include -typedef struct SURFACE -{ - int w, h; - int pitch; - unsigned char *pixels; - int offset; -} SURFACE; +#include "kolibri.h" + +void BlitDIB(); + +typedef struct SURFACE +{ + unsigned char *pixels; + int w, h; + int pitch; + int offset; +} SURFACE; SURFACE screen; // Fake mouse handling. -boolean grabMouse; +boolean grabMouse; // Blocky mode, // replace each 320x200 pixel with multiply*multiply pixels. // According to Dave Taylor, it still is a bonehead thing // to use .... -static int multiply=2; +static int multiply=2; -void WinError(char *msg); - - -int BPP; -byte *hicolortable; -short hicolortransmask1,hicolortransmask2; -int X_width; -int X_height; static int disableVerticalMouse = 0; -static int closed=0; -static int windowActive = 0; -HWND win; -static HINSTANCE inst; -static HDC dibDC; -static LOGPALETTE *palette; -static HPALETTE dibPal; -BITMAPINFO *bminfo; -static unsigned char *dibData; -static int bits8; -int palette_color[256]; - - -static int lastmousex = 0; -static int lastmousey = 0; -boolean mousemoved = false; -boolean shmFinished; +static int scr_w =0; +static int scr_h =0; +static int win_x, win_y; +static int win_w, win_h; -// -// Translates the key -// +//int palette_color[256]; -/******* -int xlatekey(SDL_keysym *key) -{ - int rc; +static int lastmousex = 0; +static int lastmousey = 0; +boolean mousemoved = false; - switch(key->sym) - { - case SDLK_LEFT: rc = KEY_LEFTARROW; break; - case SDLK_RIGHT: rc = KEY_RIGHTARROW; break; - case SDLK_DOWN: rc = KEY_DOWNARROW; break; - case SDLK_UP: rc = KEY_UPARROW; break; - case SDLK_ESCAPE: rc = KEY_ESCAPE; break; - case SDLK_RETURN: rc = KEY_ENTER; break; - case SDLK_TAB: rc = KEY_TAB; break; - case SDLK_F1: rc = KEY_F1; break; - case SDLK_F2: rc = KEY_F2; break; - case SDLK_F3: rc = KEY_F3; break; - case SDLK_F4: rc = KEY_F4; break; - case SDLK_F5: rc = KEY_F5; break; - case SDLK_F6: rc = KEY_F6; break; - case SDLK_F7: rc = KEY_F7; break; - case SDLK_F8: rc = KEY_F8; break; - case SDLK_F9: rc = KEY_F9; break; - case SDLK_F10: rc = KEY_F10; break; - case SDLK_F11: rc = KEY_F11; break; - case SDLK_F12: rc = KEY_F12; break; - - case SDLK_BACKSPACE: - case SDLK_DELETE: rc = KEY_BACKSPACE; break; - - case SDLK_PAUSE: rc = KEY_PAUSE; break; - - case SDLK_EQUALS: rc = KEY_EQUALS; break; - - case SDLK_KP_MINUS: - case SDLK_MINUS: rc = KEY_MINUS; break; - - case SDLK_LSHIFT: - case SDLK_RSHIFT: - rc = KEY_RSHIFT; - break; - - case 'z': - case SDLK_LCTRL: - case SDLK_RCTRL: - rc = KEY_RCTRL; - break; - - case SDLK_LALT: - case SDLK_LMETA: - case SDLK_RALT: - case SDLK_RMETA: - rc = KEY_RALT; - break; - - default: - rc = key->sym; - break; - } - - return rc; - -} -**********/ void I_ShutdownGraphics(void) { - // SDL_Quit(); + } @@ -171,98 +88,82 @@ void I_ShutdownGraphics(void) void I_StartFrame (void) { // er? + + //printf("start new frame\n\r" ); } -/* This processes SDL events */ -/***** -void I_GetEvent(SDL_Event *Event) -{ - Uint8 buttonstate; - event_t event; - - switch (Event->type) - { - case SDL_KEYDOWN: - event.type = ev_keydown; - event.data1 = xlatekey(&Event->key.keysym); - D_PostEvent(&event); - break; - case SDL_KEYUP: - event.type = ev_keyup; - event.data1 = xlatekey(&Event->key.keysym); - D_PostEvent(&event); - break; - case SDL_QUIT: - I_Quit(); - break; - } -} - -*******/ - - +int test_for_event(void) +{ int retval; + _asm + { push ebx + push ecx + push edx + push esi + push edi + mov eax,11 + int 0x40 + mov [retval], eax + pop edi + pop esi + pop edx + pop ecx + pop ebx + }; + return retval; +}; void I_GetEvent(void) { - MSG msg; - POINT point; - static LONG prevX, prevY; - static int hadMouse = 0; - event_t event; - RECT rect; - int lb, rb; - static int prevlb = 0, prevrb = 0; - - /* Dispatch all messages: */ - while ( PeekMessage(&msg, NULL, 0, 0xFFFFFFFF, PM_REMOVE) ) - { - TranslateMessage (&msg) ; - DispatchMessage (&msg) ; - } + event_t evnt; + int val; + int key; + //printf("begin get_event()\n\r"); + do + { val= test_for_event(); + switch(val) + { case EV_REDRAW: + BeginDraw(); + DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0); + EndDraw(); + BlitDIB(); + break; - /* Check mouse and generate events if necessary: */ - if ( !GetCursorPos(&point) ) - WinError("GetCursorPos() failed"); - if ( hadMouse && windowActive) - { - lb = (GetAsyncKeyState(VK_LBUTTON) < 0); - rb = (GetAsyncKeyState(VK_RBUTTON) < 0); - - if ( (prevX != point.x) || (prevY != point.y) || - (prevlb != lb) || (prevrb != rb) ) - { - event.type = ev_mouse; - event.data1 = lb | (rb << 1); - event.data2 = (point.x - prevX)*9; - if ( disableVerticalMouse ) - event.data3 = 0; - else - event.data3 = (prevY - point.y)*9; - prevX = point.x; - prevY = point.y; - prevlb = lb; - prevrb = rb; - D_PostEvent(&event); - } + case EV_KEY: + if(!get_key(&key)) + { + switch(key) + { case 0xE0: + case 0xE1: + continue; + default: + if(key&0x80) + { //printf("key released\n\r"); + evnt.type = ev_keyup; + } + else + { //printf("key pressed %x\n\r",key); + evnt.type = ev_keydown; + }; + key&=0x7F; + evnt.data1=remap_key(key); + if ( evnt.data1 != 0 ) + D_PostEvent(&evnt); + continue; + }; + }; + continue; - if ( grabMouse ) - { - GetWindowRect(win, &rect); - if ( !SetCursorPos((rect.left + rect.right) / 2, - (rect.top + rect.bottom) / 2) ) - WinError("SetCursorPos() failed"); - prevX = (rect.left + rect.right) / 2; - prevY = (rect.top + rect.bottom) / 2; - } - } - else - { - prevX = point.x; - prevY = point.y; - hadMouse = 1; - } + case EV_BUTTON: + switch(get_button_id()) + { case 1: + return; + + default:; + }; + }; + }while(val); } @@ -272,12 +173,8 @@ void I_GetEvent(void) // void I_StartTic (void) { -// SDL_Event Event; - -// while ( SDL_PollEvent(&Event) ) -// I_GetEvent(&Event); I_GetEvent(); - + } @@ -302,152 +199,65 @@ void I_ReadScreen (byte* scr) // I_SetPalette // -typedef struct SDL_Color -{ - byte r; - byte g; - byte b; - byte unused; -} SDL_Color; - -SDL_Color colors[256]; +unsigned int colors[256]; void I_SetPalette (byte* palette) { int i; - RGBQUAD *rgb; - -// -// for ( i=0; i<256; ++i ) { -// colors[i].r = gammatable[usegamma][*palette++]; -// colors[i].g = gammatable[usegamma][*palette++]; -// colors[i].b = gammatable[usegamma][*palette++]; -// colors[i].unused = 0; -// } -// SDL_SetColors(screen, colors, 0, 256); - - rgb = bminfo->bmiColors; - for ( i = 0; i < 256; i++ ) + unsigned int r; + unsigned int g; + unsigned int b; + + for ( i=0; i<256; ++i ) { - rgb->rgbRed = gammatable[usegamma][*palette++]; - rgb->rgbGreen = gammatable[usegamma][*palette++]; - rgb->rgbBlue = gammatable[usegamma][*palette++]; - rgb->rgbReserved = 0; - rgb++; - }; - - -} - - - -int makecol(int r, int g, int b) -{ - // assert(BPP==2); - return (b >> 3) | ((g >> 3) << 5) | ((r >> 3) << 10); -} - -int TranslateKey(unsigned k) -{ -/*wtf? if ( (k >= VK_0) && (k <= VK_9) )*/ - if ( (k >= 0x30) && (k <= 0x39) ) - return (k - 0x30 + '0'); - if ( (k >= 0x41) && (k <= 0x5a) ) - return (k - 0x41 + 'a'); - -#define K(a,b) case a: return b; - switch ( k ) - { - K(VK_LEFT, KEY_LEFTARROW); - K(VK_RIGHT, KEY_RIGHTARROW); - K(VK_UP, KEY_UPARROW); - K(VK_DOWN, KEY_DOWNARROW); - K(VK_BACK, KEY_BACKSPACE); - K(VK_TAB, KEY_TAB); - K(VK_RETURN, KEY_ENTER); - K(VK_SHIFT, KEY_RSHIFT); - K(VK_CONTROL, KEY_RCTRL); - K(VK_MENU, KEY_RALT); - K(VK_PAUSE, KEY_PAUSE); - K(VK_ESCAPE, KEY_ESCAPE); - K(VK_SPACE, ' '); - K(VK_DELETE, KEY_BACKSPACE); - K(VK_ADD, '+'); - K(VK_SUBTRACT, KEY_MINUS); - K(0xBC, ','); - K(0xBE, '.'); - K(VK_F1, KEY_F1); - K(VK_F2, KEY_F2); - K(VK_F3, KEY_F3); - K(VK_F4, KEY_F4); - K(VK_F5, KEY_F5); - K(VK_F6, KEY_F6); - K(VK_F7, KEY_F7); - K(VK_F8, KEY_F8); - K(VK_F9, KEY_F9); - K(VK_F10, KEY_F10); - K(VK_F11, KEY_F11); - K(VK_F12, KEY_F12); + r = gammatable[usegamma][*palette++]; + g = gammatable[usegamma][*palette++]; + b = gammatable[usegamma][*palette++]; + colors[i]= b|(g<<8)|(r<<16); } - - return 0; } -void WinError(char *msg) -{ - printf("Windows Error: %s, GetLastError(): %u\n", msg, GetLastError()); - exit(EXIT_FAILURE); -} +void BeginDraw() +{ _asm + { push ebx + mov eax,12 + mov ebx, 1 + int 0x40 + pop ebx + }; +}; -static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam); - -void BlitDIB(void) -{ - RECT rect; - - GetClientRect(win, &rect); - if ( StretchDIBits(dibDC, rect.left, rect.top, rect.right-rect.left, - rect.bottom-rect.top, 0, 0, SCREENWIDTH*2, - SCREENHEIGHT*2, dibData, bminfo, DIB_RGB_COLORS, - SRCCOPY) - == GDI_ERROR ) - WinError("StrecthDIBits failed"); - - GdiFlush(); -} - +void EndDraw() +{ _asm + { push ebx + mov eax,12 + mov ebx, 2 + int 0x40 + pop ebx + }; +}; void I_InitGraphics(void) { static int firsttime=1; - - WNDCLASS wc; - unsigned i, x, y, j; - WORD *d; - unsigned char *b; - int bits; - int frameX, frameY, capY; - RECT rect; - int width, height; - RGBQUAD *rgb; - int retval; + + int frameX, frameY; if (!firsttime) - return; + return; firsttime = 0; if (M_CheckParm("-2")) - multiply = 2; + multiply = 2; if (M_CheckParm("-3")) - multiply = 3; + multiply = 3; if (M_CheckParm("-4")) - multiply = 4; + multiply = 4; - X_width = SCREENWIDTH * multiply; - X_height = SCREENHEIGHT * multiply; + win_w = SCREENWIDTH * multiply; + win_h = SCREENHEIGHT * multiply; // check if the user wants to grab the mouse (quite unnice) grabMouse = !!M_CheckParm("-grabmouse"); @@ -458,409 +268,111 @@ void I_InitGraphics(void) /* Build and initialize the window: */ - inst = (HINSTANCE) GetModuleHandle(NULL); - - frameX = GetSystemMetrics(SM_CXFRAME); - frameY = GetSystemMetrics(SM_CYFRAME); - capY = GetSystemMetrics(SM_CYCAPTION); - - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = inst; - wc.hIcon = NULL; - if ( grabMouse ) - wc.hCursor = LoadCursor( 0, IDC_ARROW ); - else - wc.hCursor = LoadCursor( 0, IDC_ARROW ); - /*wc.hbrBackground = GetStockObject( WHITE_BRUSH );*/ - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = "DoomWindowClass"; - - retval= RegisterClass(&wc); - - width = X_width + 2*frameX; - height = X_height + 2*frameY + capY; - - win = CreateWindow("DoomWindowClass", "NTDOOM", - WS_OVERLAPPEDWINDOW | WS_VISIBLE, 200, 200, width, height, - NULL, NULL, inst, NULL); - - /* Display the window: */ - ShowWindow(win, SW_SHOW); - UpdateWindow(win); - - GetClientRect(win, &rect); - printf("I_InitGraphics: Client area: %ux%u\n", - rect.right-rect.left, rect.bottom-rect.top); - - if ( (rect.right-rect.left) != X_width ) - { - printf("I_InitGraphics: Fixing width\n"); - width += X_width - (rect.right-rect.left); - MoveWindow(win, 0, 0, width, height, TRUE); - } - if ( (rect.bottom-rect.top) != X_height ) - { - printf("I_InitGraphics: Fixing height\n"); - height += X_height - (rect.bottom-rect.top); - MoveWindow(win, 0, 0, width, height, TRUE); - } - - GetClientRect(win, &rect); - printf("I_InitGraphics: Client area: %ux%u\n", - rect.right-rect.left, rect.bottom-rect.top); - - dibDC = GetDC(win); - BPP=1; - bits = 8; //GetDeviceCaps(dibDC, BITSPIXEL); - printf("I_InitGraphics: %i bpp screen\n", bits); - - if ( BPP == 1 ) - bminfo = malloc(sizeof(BITMAPINFOHEADER) + 4*256); - else - bminfo = malloc(sizeof(BITMAPINFOHEADER)); - - - if ( BPP == 1 ) - { - rgb = bminfo->bmiColors; - for ( i = 0; i < 256; i++ ) - { - rgb->rgbRed = i; - rgb->rgbGreen = i; - rgb->rgbBlue = i; - rgb->rgbReserved = 0; - rgb++; - } - } + frameX = 0; + frameY = 18; - bminfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bminfo->bmiHeader.biWidth = 640; X_width; - bminfo->bmiHeader.biHeight = -400 ;X_height; - bminfo->bmiHeader.biPlanes = 1; - if ( BPP == 1 ) - bminfo->bmiHeader.biBitCount = 8; - else - bminfo->bmiHeader.biBitCount = 16; - bminfo->bmiHeader.biCompression = BI_RGB; - bminfo->bmiHeader.biSizeImage = 0; - bminfo->bmiHeader.biXPelsPerMeter = 0; - bminfo->bmiHeader.biYPelsPerMeter = 0; - bminfo->bmiHeader.biClrUsed = 0; - bminfo->bmiHeader.biClrImportant = 0; + GetScreenSize(&scr_w, &scr_h); + win_x = (scr_w-win_w)/2; + win_y = (scr_h-win_h)/2; + + // hCursor = LoadCursor( 0, IDC_ARROW ); - dibData = malloc(640*400*BPP); + printf("I_InitGraphics: Client area: %ux%u\n\r", win_w, win_h); -// BlitDIB(); - - screen.pixels=(unsigned char *) (dibData); - screen.h=400; - screen.w=640; + screen.pixels= (byte*) UserAlloc(640*400*4); + screen.h = win_w; + screen.w = win_h; screen.pitch=640; - - // screens[0] = malloc(320*200); - - /* Build magic highcolor table: */ - if (BPP==2) - { - byte *tempptr, *tempptr2; - - tempptr=hicolortable=(byte *)malloc(256*32*9); - - for (i=0;i<32;i++) - { - for (j=0;j<256;j++) - { - *tempptr=j*gammatable[3][i*(256/32)]/256; - tempptr++; - } - } - for (i=1;i<=8;i++) - { - tempptr2=hicolortable; - for (j=0;j<(256*32);j++) - { - *tempptr=(byte)(((int)(*tempptr2))*(8-i)/8); - tempptr++; tempptr2++; - } - } - hicolortransmask1=makecol(127,127,127); - hicolortransmask2=makecol(63,63,63); - } -} - -static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam) -{ - event_t event; - RECT rect; - switch ( message ) - { - case WM_DESTROY: - if ( grabMouse ) - { - ClipCursor(NULL); - ShowCursor(TRUE); - } - printf("WM_DESTROY\n"); - PostQuitMessage(0); - closed = 1; - break; + BeginDraw(); + DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0); + EndDraw(); - case WM_MOVE: - GetWindowRect(win, &rect); - printf("%u,%u - %u, %u\n", - rect.left,rect.top,rect.right,rect.bottom); - ClipCursor(&rect); - break; - - case WM_ACTIVATE: - printf("WM_ACTIVATE %u\n", (unsigned) LOWORD(wparam)); - if ( LOWORD(wparam) ) - { - if ( !windowActive ) - { - if ( grabMouse ) - { - ClipCursor(NULL); /* helps with Win95? */ - GetWindowRect(win, &rect); - printf("%u,%u - %u, %u\n", - rect.left,rect.top,rect.right,rect.bottom); - ClipCursor(&rect); - ShowCursor(FALSE); - } - } - windowActive = 1; - if ( bits8 ) - { - if ( SetPaletteEntries(dibPal, 0, 256, palette->palPalEntry) != 256 ) - WinError("SetPaletteEntries failed"); - if ( !UnrealizeObject(dibPal) ) - WinError("UnrealizeObject failed"); - if ( SelectPalette(dibDC, dibPal, FALSE) == NULL ) - WinError("SelectPalette failed"); - } - } - else - { - if ( grabMouse ) - { - ClipCursor(NULL); - ShowCursor(TRUE); - } - windowActive = 0; - } - return DefWindowProc(hwnd, message, wparam, lparam); - - case WM_KEYDOWN: - event.type = ev_keydown; - event.data1 = TranslateKey(wparam); - if ( event.data1 != 0 ) - D_PostEvent(&event); - break; - - case WM_KEYUP: - event.type = ev_keyup; - event.data1 = TranslateKey(wparam); - if ( event.data1 != 0 ) - D_PostEvent(&event); - break; - - default: - return(DefWindowProc(hwnd, message, wparam, lparam)); - } - - return 0; } + +void conv(char *dst, char *src); + +void BlitDIB() +{ + _asm + { push ebx + push ecx + push edx + mov eax, 7 + mov ebx, dword ptr [screen] + mov ecx, 0x02800190 + xor edx, edx + int 0x40 + pop edx + pop ecx + pop ebx + } +}; + // // I_FinishUpdate -// +// void I_FinishUpdate (void) { - - static int lasttic; - int tics; - int i; - - // draws little dots on the bottom of the screen - if (devparm) - { i = I_GetTime(); - - tics = i - lasttic; - lasttic = i; - if (tics > 20) - tics = 20; - - for (i=0 ; i>8) & 0xffff00) - | ((fouripixels>>16) & 0xff); - twomoreopixels = ((fouripixels<<16) & 0xff000000) - | ((fouripixels<<8) & 0xffff00) - | (fouripixels & 0xff); - *olineptrs[0]++ = twomoreopixels; - *olineptrs[1]++ = twomoreopixels; - *olineptrs[0]++ = twoopixels; - *olineptrs[1]++ = twoopixels; - } while (x-=4); - olineptrs[0] += screen.pitch/4; - olineptrs[1] += screen.pitch/4; - } - - } - else if (multiply == 3) - { - unsigned int *olineptrs[3]; - unsigned int *ilineptr; - int x, y, i; - unsigned int fouropixels[3]; - unsigned int fouripixels; - - ilineptr = (unsigned int *) (screens[0]); - for (i=0 ; i<3 ; i++) { - olineptrs[i] = - (unsigned int *)&((byte *)screen.pixels)[i*screen.pitch]; - } - - y = SCREENHEIGHT; - while (y--) - { - x = SCREENWIDTH; - do - { - fouripixels = *ilineptr++; - fouropixels[0] = (fouripixels & 0xff000000) - | ((fouripixels>>8) & 0xff0000) - | ((fouripixels>>16) & 0xffff); - fouropixels[1] = ((fouripixels<<8) & 0xff000000) - | (fouripixels & 0xffff00) - | ((fouripixels>>8) & 0xff); - fouropixels[2] = ((fouripixels<<16) & 0xffff0000) - | ((fouripixels<<8) & 0xff00) - | (fouripixels & 0xff); - *olineptrs[0]++ = fouropixels[2]; - *olineptrs[1]++ = fouropixels[2]; - *olineptrs[2]++ = fouropixels[2]; - *olineptrs[0]++ = fouropixels[1]; - *olineptrs[1]++ = fouropixels[1]; - *olineptrs[2]++ = fouropixels[1]; - *olineptrs[0]++ = fouropixels[0]; - *olineptrs[1]++ = fouropixels[0]; - *olineptrs[2]++ = fouropixels[0]; - } while (x-=4); - olineptrs[0] += 2*screen.pitch/4; - olineptrs[1] += 2*screen.pitch/4; - olineptrs[2] += 2*screen.pitch/4; - } - - } - BlitDIB(); + BlitDIB(); } - - - -/** -void I_InitGraphics(void) +void conv(char *dst, char *src) { + _asm + { + push ebx + push ecx + push esi + push edi + + mov ecx, 320 + mov esi, [src] + mov edi, [dst] + cld +l1: + lodsb + movzx eax, al + mov eax, [colors+eax*4] + mov ebx, eax + bswap ebx + and ebx, 0xFF000000 + or eax, ebx + mov [edi],eax + mov [edi+640*3], eax + shr eax, 8 + mov [edi+4], ax + mov [edi+640*3+4], ax + add edi, 6 + dec ecx + jnz l1 + + pop edi + pop esi + pop ecx + pop ebx + }; +}; + + - static int firsttime=1; - int video_w, video_h, w, h; - byte video_bpp; - unsigned int video_flags; - if (!firsttime) - return; - firsttime = 0; - - video_flags = (SDL_SWSURFACE|SDL_HWPALETTE); - if (!!M_CheckParm("-fullscreen")) - video_flags |= SDL_FULLSCREEN; - - if (M_CheckParm("-2")) - multiply = 2; - - if (M_CheckParm("-3")) - multiply = 3; - - // check if the user wants to grab the mouse (quite unnice) - grabMouse = !!M_CheckParm("-grabmouse"); - - video_w = w = SCREENWIDTH * multiply; - video_h = h = SCREENHEIGHT * multiply; - video_bpp = 8; - - - if ( multiply > 3 ) { - I_Error("Smallest available mode (%dx%d) is too large!", - video_w, video_h); - } - screen = SDL_SetVideoMode(video_w, video_h, 8, video_flags); - if ( screen == NULL ) { - I_Error("Could not set %dx%d video mode: %s", video_w, video_h, - SDL_GetError()); - } - SDL_ShowCursor(0); - SDL_WM_SetCaption("MenuetOS-DOOM", "doom"); - - w = SCREENWIDTH * multiply; - h = SCREENHEIGHT * multiply; - if (multiply == 1 && !SDL_MUSTLOCK(screen) ) { - screens[0] = (unsigned char *) screen->pixels; - } else { - screens[0] = (unsigned char *) malloc (SCREENWIDTH * SCREENHEIGHT); - if ( screens[0] == NULL ) - I_Error("Couldn't allocate screen memory"); - } -} -*****/ \ No newline at end of file diff --git a/programs/games/doom/trunk/m_argv.c b/programs/games/doom/trunk/m_argv.c index 8cbd622a79..af90305329 100644 --- a/programs/games/doom/trunk/m_argv.c +++ b/programs/games/doom/trunk/m_argv.c @@ -1,58 +1,56 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// $Id:$ -// -// Copyright (C) 1993-1996 by id Software, Inc. -// -// This source is available for distribution and/or modification -// only under the terms of the DOOM Source Code License as -// published by id Software. All rights reserved. -// -// The source is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License -// for more details. -// -// $Log:$ -// -// DESCRIPTION: -// -//----------------------------------------------------------------------------- - -static const char -rcsid[] = "$Id: m_argv.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; - - -#include - -#include "i_system.h" - -int myargc; -char** myargv; - - - - -// -// M_CheckParm -// Checks for the given parameter -// in the program's command line arguments. -// Returns the argument number (1 to argc-1) -// or 0 if not present -int M_CheckParm (char *check) -{ - int i; - - for (i = 1;i + +int myargc; +char** myargv; + + + + +// +// M_CheckParm +// Checks for the given parameter +// in the program's command line arguments. +// Returns the argument number (1 to argc-1) +// or 0 if not present +int M_CheckParm (char *check) +{ + int i; + + for (i = 1;i #include +//#include "//kolibc.h" -extern int access(char *file, int mode); +//extern int access(char *file, int mode); #include "doomdef.h" @@ -60,36 +61,36 @@ extern int access(char *file, int mode); // Returns the final X coordinate // HU_Init must have been called to init the font // -extern patch_t* hu_font[HU_FONTSIZE]; +extern patch_t* hu_font[HU_FONTSIZE]; int M_DrawText -( int x, - int y, - boolean direct, - char* string ) +( int x, + int y, + boolean direct, + char* string ) { - int c; - int w; + int c; + int w; while (*string) { - c = toupper(*string) - HU_FONTSTART; - string++; - if (c < 0 || c> HU_FONTSIZE) - { - x += 4; - continue; - } - - w = SHORT (hu_font[c]->width); - if (x+w > SCREENWIDTH) - break; - if (direct) - V_DrawPatchDirect(x, y, 0, hu_font[c]); - else - V_DrawPatch(x, y, 0, hu_font[c]); - x+=w; + c = toupper(*string) - HU_FONTSTART; + string++; + if (c < 0 || c> HU_FONTSIZE) + { + x += 4; + continue; + } + + w = SHORT (hu_font[c]->width); + if (x+w > SCREENWIDTH) + break; + if (direct) + V_DrawPatchDirect(x, y, 0, hu_font[c]); + else + V_DrawPatch(x, y, 0, hu_font[c]); + x+=w; } return x; @@ -107,24 +108,24 @@ M_DrawText boolean M_WriteFile -( char const* name, - void* source, - int length ) +( char const* name, + void* source, + int length ) { FILE *handle; - int count; - + int count; + handle = fopen ( name, "wb"); if (handle == NULL) - return false; + return false; - count = fwrite (source, 1, length, handle); + // count = fwrite (source, 1, length, handle); fclose (handle); - + if (count < length) - return false; - + return false; + return true; } @@ -134,26 +135,29 @@ M_WriteFile // int M_ReadFile -( char const* name, - byte** buffer ) +( char const* name, + byte** buffer ) { FILE *handle; int count, length; - byte *buf; - + byte *buf; + + handle=0; + buf=0; + handle = fopen (name, "rb"); if (handle == NULL) - I_Error ("Couldn't read file %s", name); + I_Error ("Couldn't read file %s", name); fseek(handle, 0, SEEK_END); length = ftell(handle); rewind(handle); buf = Z_Malloc (length, PU_STATIC, NULL); count = fread (buf, 1, length, handle); fclose (handle); - + if (count < length) - I_Error ("Couldn't read file %s", name); - + I_Error ("Couldn't read file %s", name); + *buffer = buf; return length; } @@ -162,61 +166,61 @@ M_ReadFile // // DEFAULTS // -int usemouse; -int usejoystick; +int usemouse; +int usejoystick; -extern int key_right; -extern int key_left; -extern int key_up; -extern int key_down; +extern int key_right; +extern int key_left; +extern int key_up; +extern int key_down; -extern int key_strafeleft; -extern int key_straferight; +extern int key_strafeleft; +extern int key_straferight; -extern int key_fire; -extern int key_use; -extern int key_strafe; -extern int key_speed; +extern int key_fire; +extern int key_use; +extern int key_strafe; +extern int key_speed; -extern int mousebfire; -extern int mousebstrafe; -extern int mousebforward; +extern int mousebfire; +extern int mousebstrafe; +extern int mousebforward; -extern int joybfire; -extern int joybstrafe; -extern int joybuse; -extern int joybspeed; +extern int joybfire; +extern int joybstrafe; +extern int joybuse; +extern int joybspeed; -extern int viewwidth; -extern int viewheight; +extern int viewwidth; +extern int viewheight; -extern int mouseSensitivity; -extern int showMessages; +extern int mouseSensitivity; +extern int showMessages; -extern int detailLevel; +extern int detailLevel; -extern int screenblocks; +extern int screenblocks; -extern int showMessages; +extern int showMessages; // machine-independent sound params -extern int numChannels; +extern int numChannels; -extern char* chat_macros[]; +extern char* chat_macros[]; typedef struct { - char* name; - int* location; - int defaultvalue; - int scantranslate; // PC scan code hack - int untranslated; // lousy hack + char* name; + int* location; + int defaultvalue; + int scantranslate; // PC scan code hack + int untranslated; // lousy hack } default_t; -default_t defaults[] = +default_t defaults[] = { {"mouse_sensitivity",&mouseSensitivity, 5}, {"sfx_volume",&snd_SfxVolume, 8}, @@ -228,6 +232,12 @@ default_t defaults[] = {"key_left",&key_left, KEY_LEFTARROW}, {"key_up",&key_up, KEY_UPARROW}, {"key_down",&key_down, KEY_DOWNARROW}, + +// {"key_right",&key_right, KEY_D}, +// {"key_left",&key_left, KEY_A}, +// {"key_up",&key_up, KEY_W}, +// {"key_down",&key_down, KEY_S}, + {"key_strafeleft",&key_strafeleft, ','}, {"key_straferight",&key_straferight, '.'}, @@ -271,8 +281,8 @@ default_t defaults[] = }; -int numdefaults; -char* defaultfile; +int numdefaults; +char* defaultfile; // @@ -280,27 +290,27 @@ char* defaultfile; // void M_SaveDefaults (void) { - int i; - int v; - FILE* f; - + int i; + int v; + FILE* f; + f = fopen (defaultfile, "w"); if (!f) - return; // can't write the file, but don't complain - + return; // can't write the file, but don't complain + for (i=0 ; i -0xfff - && defaults[i].defaultvalue < 0xfff) - { - v = *defaults[i].location; - printf ("%s\t\t%i\n",defaults[i].name,v); - } else { - printf ("%s\t\t\"%s\"\n",defaults[i].name, - * (char **) (defaults[i].location)); - } + if (defaults[i].defaultvalue > -0xfff + && defaults[i].defaultvalue < 0xfff) + { + v = *defaults[i].location; + printf ("%s\t\t%i\n",defaults[i].name,v); + } else { + printf ("%s\t\t\"%s\"\n",defaults[i].name, + * (char **) (defaults[i].location)); + } } - + fclose (f); } @@ -308,73 +318,88 @@ void M_SaveDefaults (void) // // M_LoadDefaults // -extern byte scantokey[128]; +extern byte scantokey[128]; + +size_t FileSize(FILE *handle); void M_LoadDefaults (void) { - int i; - int len; - FILE* f; - char def[80]; - char strparm[100]; - char* newstring; - int parm; - boolean isstring; + int i; + int len; + FILE* f; + char def[80]; + char strparm[100]; + char* newstring; + int parm; + boolean isstring; + char *buf; + char *p; + size_t val; // set everything to base values numdefaults = sizeof(defaults)/sizeof(defaults[0]); for (i=0 ; imanufacturer = 0x0a; // PCX id - pcx->version = 5; // 256 color - pcx->encoding = 1; // uncompressed - pcx->bits_per_pixel = 8; // 256 color + pcx->manufacturer = 0x0a; // PCX id + pcx->version = 5; // 256 color + pcx->encoding = 1; // uncompressed + pcx->bits_per_pixel = 8; // 256 color pcx->xmin = 0; pcx->ymin = 0; pcx->xmax = SHORT(width-1); @@ -438,30 +463,30 @@ WritePCXfile pcx->hres = SHORT(width); pcx->vres = SHORT(height); memset (pcx->palette,0,sizeof(pcx->palette)); - pcx->color_planes = 1; // chunky image + pcx->color_planes = 1; // chunky image pcx->bytes_per_line = SHORT(width); - pcx->palette_type = SHORT(2); // not a grey scale + pcx->palette_type = SHORT(2); // not a grey scale memset (pcx->filler,0,sizeof(pcx->filler)); // pack the image pack = &pcx->data; - + for (i=0 ; i -#endif -#endif /* __BEOS__ */ - -#include "m_swap.h" - #include "i_system.h" #include "z_zone.h" +#include "m_swap.h" + #include "w_wad.h" #include "doomdef.h" @@ -49,8 +41,11 @@ extern void *alloca(int); #include "doomstat.h" #include "r_sky.h" +#include + + #include "r_data.h" -#include + // // Graphics. // DOOM graphics for walls and sprites @@ -71,11 +66,11 @@ extern void *alloca(int); // typedef struct { - short originx; - short originy; - short patch; - short stepdir; - short colormap; + short originx; + short originy; + short patch; + short stepdir; + short colormap; } mappatch_t; @@ -86,13 +81,13 @@ typedef struct // typedef struct { - char name[8]; - int masked; - short width; - short height; - void **columndirectory; // OBSOLETE - short patchcount; - mappatch_t patches[1]; + char name[8]; + int masked; + short width; + short height; + void **columndirectory; // OBSOLETE + short patchcount; + mappatch_t patches[1]; } maptexture_t; @@ -104,9 +99,9 @@ typedef struct // Block origin (allways UL), // which has allready accounted // for the internal origin of the patch. - int originx; - int originy; - int patch; + int originx; + int originy; + int patch; } texpatch_t; @@ -116,53 +111,53 @@ typedef struct typedef struct { // Keep name for switch changing, etc. - char name[8]; - short int width; - short int height; + char name[8]; + short int width; + short int height; // All the patches[patchcount] // are drawn back to front into the cached texture. - short patchcount; - texpatch_t patches[1]; + short int patchcount; + texpatch_t patches[1]; } texture_t; -int firstflat; -int lastflat; -int numflats; +int firstflat; +int lastflat; +int numflats; -int firstpatch; -int lastpatch; -int numpatches; +int firstpatch; +int lastpatch; +int numpatches; -int firstspritelump; -int lastspritelump; -int numspritelumps; +int firstspritelump; +int lastspritelump; +int numspritelumps; -int numtextures; -texture_t** textures; +int numtextures; +texture_t** textures; -int* texturewidthmask; +int* texturewidthmask; // needed for texture pegging -fixed_t* textureheight; -int* texturecompositesize; -short** texturecolumnlump; -unsigned short** texturecolumnofs; -byte** texturecomposite; +fixed_t* textureheight; +int* texturecompositesize; +short** texturecolumnlump; +unsigned short** texturecolumnofs; +byte** texturecomposite; // for global animation -int* flattranslation; -int* texturetranslation; +int* flattranslation; +int* texturetranslation; // needed for pre rendering -fixed_t* spritewidth; -fixed_t* spriteoffset; -fixed_t* spritetopoffset; +fixed_t* spritewidth; +fixed_t* spriteoffset; +fixed_t* spritetopoffset; -lighttable_t *colormaps; +lighttable_t *colormaps; // @@ -186,37 +181,37 @@ lighttable_t *colormaps; // void R_DrawColumnInCache -( column_t* patch, - byte* cache, - int originy, - int cacheheight ) +( column_t* patch, + byte* cache, + int originy, + int cacheheight ) { - int count; - int position; - byte* source; - byte* dest; - + int count; + int position; + byte* source; + byte* dest; + dest = (byte *)cache + 3; - + while (patch->topdelta != 0xff) { - source = (byte *)patch + 3; - count = patch->length; - position = originy + patch->topdelta; + source = (byte *)patch + 3; + count = patch->length; + position = originy + patch->topdelta; - if (position < 0) - { - count += position; - position = 0; - } + if (position < 0) + { + count += position; + position = 0; + } - if (position + count > cacheheight) - count = cacheheight - position; + if (position + count > cacheheight) + count = cacheheight - position; - if (count > 0) - memcpy (cache + position, source, count); - - patch = (column_t *)( (byte *)patch + patch->length + 4); + if (count > 0) + memcpy (cache + position, source, count); + + patch = (column_t *)( (byte *)patch + patch->length + 4); } } @@ -230,60 +225,60 @@ R_DrawColumnInCache // void R_GenerateComposite (int texnum) { - byte* block; - texture_t* texture; - texpatch_t* patch; - patch_t* realpatch; - int x; - int x1; - int x2; - int i; - column_t* patchcol; - short* collump; - unsigned short* colofs; - + byte* block; + texture_t* texture; + texpatch_t* patch; + patch_t* realpatch; + int x; + int x1; + int x2; + int i; + column_t* patchcol; + short* collump; + unsigned short* colofs; + texture = textures[texnum]; block = Z_Malloc (texturecompositesize[texnum], - PU_STATIC, - &texturecomposite[texnum]); + PU_STATIC, + &texturecomposite[texnum]); collump = texturecolumnlump[texnum]; colofs = texturecolumnofs[texnum]; // Composite the columns together. patch = texture->patches; - + for (i=0 , patch = texture->patches; - ipatchcount; - i++, patch++) + ipatchcount; + i++, patch++) { - realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); + realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); + x1 = patch->originx; + x2 = x1 + SHORT(realpatch->width); - if (x1<0) - x = 0; - else - x = x1; - - if (x2 > texture->width) - x2 = texture->width; + if (x1<0) + x = 0; + else + x = x1; + + if (x2 > texture->width) + x2 = texture->width; - for ( ; x= 0) - continue; - - patchcol = (column_t *)((byte *)realpatch - + LONG(realpatch->columnofs[x-x1])); - R_DrawColumnInCache (patchcol, - block + colofs[x], - patch->originy, - texture->height); - } - + for ( ; x= 0) + continue; + + patchcol = (column_t *)((byte *)realpatch + + LONG(realpatch->columnofs[x-x1])); + R_DrawColumnInCache (patchcol, + block + colofs[x], + patch->originy, + texture->height); + } + } // Now that the texture has been built in column cache, @@ -291,22 +286,24 @@ void R_GenerateComposite (int texnum) Z_ChangeTag (block, PU_CACHE); } + + // // R_GenerateLookup // void R_GenerateLookup (int texnum) { - texture_t* texture; - byte* patchcount; // patchcount[texture->width] - texpatch_t* patch; - patch_t* realpatch; - int x; - int x1; - int x2; - int i; - short* collump; - unsigned short* colofs; - + texture_t* texture; + byte* patchcount; // patchcount[texture->width] + texpatch_t* patch; + patch_t* realpatch; + int x; + int x1; + int x2; + int i; + short* collump; + unsigned short* colofs; + texture = textures[texnum]; // Composited texture not created yet. @@ -323,55 +320,55 @@ void R_GenerateLookup (int texnum) patchcount = (byte *)alloca (texture->width); memset (patchcount, 0, texture->width); patch = texture->patches; - + for (i=0 , patch = texture->patches; - ipatchcount; - i++, patch++) + ipatchcount; + i++, patch++) { - realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); - - if (x1 < 0) - x = 0; - else - x = x1; + realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); + x1 = patch->originx; + x2 = x1 + SHORT(realpatch->width); + + if (x1 < 0) + x = 0; + else + x = x1; - if (x2 > texture->width) - x2 = texture->width; - for ( ; xpatch; - colofs[x] = LONG(realpatch->columnofs[x-x1])+3; - } + if (x2 > texture->width) + x2 = texture->width; + for ( ; xpatch; + colofs[x] = LONG(realpatch->columnofs[x-x1])+3; + } } - + for (x=0 ; xwidth ; x++) { - if (!patchcount[x]) - { - printf("R_GenerateLookup: column without a patch (%s)\n", - texture->name); - return; - } -// I_Error ("R_GenerateLookup: column without a patch"); - - if (patchcount[x] > 1) - { - // Use the cached block. - collump[x] = -1; - colofs[x] = texturecompositesize[texnum]; - - if (texturecompositesize[texnum] > 0x10000-texture->height) - { - I_Error ("R_GenerateLookup: texture %i is >64k", - texnum); - } - - texturecompositesize[texnum] += texture->height; - } - } + if (!patchcount[x]) + { + printf ("R_GenerateLookup: column without a patch (%s)\n", + texture->name); + return; + } + // I_Error ("R_GenerateLookup: column without a patch"); + + if (patchcount[x] > 1) + { + // Use the cached block. + collump[x] = -1; + colofs[x] = texturecompositesize[texnum]; + + if (texturecompositesize[texnum] > 0x10000-texture->height) + { + I_Error ("R_GenerateLookup: texture %i is >64k", + texnum); + } + + texturecompositesize[texnum] += texture->height; + } + } } @@ -382,21 +379,21 @@ void R_GenerateLookup (int texnum) // byte* R_GetColumn -( int tex, - int col ) +( int tex, + int col ) { - int lump; - int ofs; - + int lump; + int ofs; + col &= texturewidthmask[tex]; lump = texturecolumnlump[tex][col]; ofs = texturecolumnofs[tex][col]; if (lump > 0) - return (byte *)W_CacheLumpNum(lump,PU_CACHE)+ofs; + return (byte *)W_CacheLumpNum(lump,PU_CACHE)+ofs; if (!texturecomposite[tex]) - R_GenerateComposite (tex); + R_GenerateComposite (tex); return texturecomposite[tex] + ofs; } @@ -411,41 +408,41 @@ R_GetColumn // void R_InitTextures (void) { - maptexture_t* mtexture; - texture_t* texture; - mappatch_t* mpatch; - texpatch_t* patch; + maptexture_t* mtexture; + texture_t* texture; + mappatch_t* mpatch; + texpatch_t* patch; - int i; - int j; + int i; + int j; - int* maptex; - int* maptex2; - int* maptex1; + int* maptex; + int* maptex2; + int* maptex1; - char name[9]; - char* names; - char* name_p; + char name[9]; + char* names; + char* name_p; - int* patchlookup; + int* patchlookup; - int totalwidth; - int nummappatches; - int offset; - int maxoff; - int maxoff2; - int numtextures1; - int numtextures2; + int totalwidth; + int nummappatches; + int offset; + int maxoff; + int maxoff2; + int numtextures1; + int numtextures2; - int* directory; + int* directory; - int temp1; - int temp2; - int temp3; + int temp1; + int temp2; + int temp3; // Load the patch names from pnames.lmp. - name[8] = 0; + name[8] = 0; names = W_CacheLumpName ("PNAMES", PU_STATIC); nummappatches = LONG ( *((int *)names) ); name_p = names+4; @@ -453,8 +450,8 @@ void R_InitTextures (void) for (i=0 ; i maxoff) + I_Error ("R_InitTextures: bad texture directory"); + + mtexture = (maptexture_t *) ( (byte *)maptex + offset); - if (offset > maxoff) - I_Error ("R_InitTextures: bad texture directory"); - - mtexture = (maptexture_t *) ( (byte *)maptex + offset); + texture = textures[i] = + Z_Malloc (sizeof(texture_t) + + sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1), + PU_STATIC, 0); + + texture->width = SHORT(mtexture->width); + texture->height = SHORT(mtexture->height); + texture->patchcount = SHORT(mtexture->patchcount); - texture = textures[i] = - Z_Malloc (sizeof(texture_t) - + sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1), - PU_STATIC, 0); - - texture->width = SHORT(mtexture->width); - texture->height = SHORT(mtexture->height); - texture->patchcount = SHORT(mtexture->patchcount); + memcpy (texture->name, mtexture->name, sizeof(texture->name)); + mpatch = &mtexture->patches[0]; + patch = &texture->patches[0]; - // memcpy() generates a BUS error on Solaris with optimization on */ -#if 1 - memcpy (texture->name, mtexture->name, sizeof(texture->name)); -#else - { char *src; char *dst; - src = (char *)mtexture->name; - dst = (char *)texture->name; - for (j=0; jname); ++j ) - *dst++ = *src++; - } -#endif - mpatch = &mtexture->patches[0]; - patch = &texture->patches[0]; + for (j=0 ; jpatchcount ; j++, mpatch++, patch++) + { + patch->originx = SHORT(mpatch->originx); + patch->originy = SHORT(mpatch->originy); + patch->patch = patchlookup[SHORT(mpatch->patch)]; + if (patch->patch == -1) + { + I_Error ("R_InitTextures: Missing patch in texture %s", + texture->name); + } + } + texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0); + texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0); - for (j=0 ; jpatchcount ; j++, mpatch++, patch++) - { - patch->originx = SHORT(mpatch->originx); - patch->originy = SHORT(mpatch->originy); - patch->patch = patchlookup[SHORT(mpatch->patch)]; - if (patch->patch == -1) - { - I_Error ("R_InitTextures: Missing patch in texture %s", - texture->name); - } - } - texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0); - texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0); + j = 1; + while (j*2 <= texture->width) + j<<=1; - j = 1; - while (j*2 <= texture->width) - j<<=1; - - texturewidthmask[i] = j-1; - textureheight[i] = texture->height<width; + texturewidthmask[i] = j-1; + textureheight[i] = texture->height<width; } Z_Free (maptex1); if (maptex2) - Z_Free (maptex2); + Z_Free (maptex2); - // Precalculate whatever possible. + // Precalculate whatever possible. for (i=0 ; iwidth)<leftoffset)<topoffset)<width)<leftoffset)<topoffset)<name, name, 8) ) - return i; - + if (!strnicmp (textures[i]->name, name, 8) ) + return i; + return -1; } - - // // R_TextureNumForName // Calls R_CheckTextureNumForName, // aborts with error message. // -int R_TextureNumForName (char* name) +int R_TextureNumForName (char* name) { - int i; - + int i; + i = R_CheckTextureNumForName (name); if (i==-1) { - I_Error ("R_TextureNumForName: %s not found", - name); + I_Error ("R_TextureNumForName: %s not found", + name); } return i; } @@ -747,59 +732,59 @@ int R_TextureNumForName (char* name) // R_PrecacheLevel // Preloads all relevant graphics for the level. // -int flatmemory; -int texturememory; -int spritememory; +int flatmemory; +int texturememory; +int spritememory; void R_PrecacheLevel (void) { - char* flatpresent; - char* texturepresent; - char* spritepresent; + char* flatpresent; + char* texturepresent; + char* spritepresent; - int i; - int j; - int k; - int lump; + int i; + int j; + int k; + int lump; - texture_t* texture; - thinker_t* th; - spriteframe_t* sf; + texture_t* texture; + thinker_t* th; + spriteframe_t* sf; if (demoplayback) - return; + return; // Precache flats. flatpresent = alloca(numflats); - memset (flatpresent,0,numflats); + memset (flatpresent,0,numflats); for (i=0 ; ipatchcount ; j++) - { - lump = texture->patches[j].patch; - texturememory += lumpinfo[lump].size; - W_CacheLumpNum(lump , PU_CACHE); - } + texture = textures[i]; + + for (j=0 ; jpatchcount ; j++) + { + lump = texture->patches[j].patch; + texturememory += lumpinfo[lump].size; + W_CacheLumpNum(lump , PU_CACHE); + } } // Precache sprites. spritepresent = alloca(numsprites); memset (spritepresent,0, numsprites); - + for (th = thinkercap.next ; th != &thinkercap ; th=th->next) { - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - spritepresent[((mobj_t *)th)->sprite] = 1; + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + spritepresent[((mobj_t *)th)->sprite] = 1; } - + spritememory = 0; for (i=0 ; ilump[k]; - spritememory += lumpinfo[lump].size; - W_CacheLumpNum(lump , PU_CACHE); - } - } + for (j=0 ; jlump[k]; + spritememory += lumpinfo[lump].size; + W_CacheLumpNum(lump , PU_CACHE); + } + } } } diff --git a/programs/games/doom/trunk/r_main.c b/programs/games/doom/trunk/r_main.c index ad942c7c66..8ebadc848e 100644 --- a/programs/games/doom/trunk/r_main.c +++ b/programs/games/doom/trunk/r_main.c @@ -17,14 +17,14 @@ // $Log:$ // // DESCRIPTION: -// Rendering main loop and setup functions, -// utility functions (BSP, geometry, trigonometry). -// See tables.c, too. +// Rendering main loop and setup functions, +// utility functions (BSP, geometry, trigonometry). +// See tables.c, too. // //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $"; +//static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $"; @@ -45,80 +45,80 @@ static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $"; // Fineangles in the SCREENWIDTH wide window. -#define FIELDOFVIEW 2048 +#define FIELDOFVIEW 2048 -int viewangleoffset; +int viewangleoffset; // increment every time a check is made -int validcount = 1; +int validcount = 1; -lighttable_t* fixedcolormap; -extern lighttable_t** walllights; +lighttable_t* fixedcolormap; +extern lighttable_t** walllights; -int centerx; -int centery; +int centerx; +int centery; -fixed_t centerxfrac; -fixed_t centeryfrac; -fixed_t projection; +fixed_t centerxfrac; +fixed_t centeryfrac; +fixed_t projection; // just for profiling purposes -int framecount; +int framecount; -int sscount; -int linecount; -int loopcount; +int sscount; +int linecount; +int loopcount; -fixed_t viewx; -fixed_t viewy; -fixed_t viewz; +fixed_t viewx; +fixed_t viewy; +fixed_t viewz; -angle_t viewangle; +angle_t viewangle; -fixed_t viewcos; -fixed_t viewsin; +fixed_t viewcos; +fixed_t viewsin; -player_t* viewplayer; +player_t* viewplayer; // 0 = high, 1 = low -int detailshift; +int detailshift; // // precalculated math tables // -angle_t clipangle; +angle_t clipangle; // The viewangletox[viewangle + FINEANGLES/4] lookup // maps the visible view angles to screen X coordinates, // flattening the arc to a flat projection plane. // There will be many angles mapped to the same X. -int viewangletox[FINEANGLES/2]; +int viewangletox[FINEANGLES/2]; // The xtoviewangleangle[] table maps a screen pixel // to the lowest viewangle that maps back to x ranges // from clipangle to -clipangle. -angle_t xtoviewangle[SCREENWIDTH+1]; +angle_t xtoviewangle[SCREENWIDTH+1]; // UNUSED. // The finetangentgent[angle+FINEANGLES/4] table // holds the fixed_t tangent values for view angles, // ranging from MININT to 0 to MAXINT. -// fixed_t finetangent[FINEANGLES/2]; +// fixed_t finetangent[FINEANGLES/2]; -// fixed_t finesine[5*FINEANGLES/4]; -fixed_t* finecosine = &finesine[FINEANGLES/4]; +// fixed_t finesine[5*FINEANGLES/4]; +fixed_t* finecosine = &finesine[FINEANGLES/4]; -lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; -lighttable_t* scalelightfixed[MAXLIGHTSCALE]; -lighttable_t* zlight[LIGHTLEVELS][MAXLIGHTZ]; +lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; +lighttable_t* scalelightfixed[MAXLIGHTSCALE]; +lighttable_t* zlight[LIGHTLEVELS][MAXLIGHTZ]; // bumped light from gun blasts -int extralight; +int extralight; @@ -137,18 +137,18 @@ void (*spanfunc) (void); // void R_AddPointToBox -( int x, - int y, - fixed_t* box ) +( int x, + int y, + fixed_t* box ) { if (x< box[BOXLEFT]) - box[BOXLEFT] = x; + box[BOXLEFT] = x; if (x> box[BOXRIGHT]) - box[BOXRIGHT] = x; + box[BOXRIGHT] = x; if (y< box[BOXBOTTOM]) - box[BOXBOTTOM] = y; + box[BOXBOTTOM] = y; if (y> box[BOXTOP]) - box[BOXTOP] = y; + box[BOXTOP] = y; } @@ -160,117 +160,117 @@ R_AddPointToBox // int R_PointOnSide -( fixed_t x, - fixed_t y, - node_t* node ) +( fixed_t x, + fixed_t y, + node_t* node ) { - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - + fixed_t dx; + fixed_t dy; + fixed_t left; + fixed_t right; + if (!node->dx) { - if (x <= node->x) - return node->dy > 0; - - return node->dy < 0; + if (x <= node->x) + return node->dy > 0; + + return node->dy < 0; } if (!node->dy) { - if (y <= node->y) - return node->dx < 0; - - return node->dx > 0; + if (y <= node->y) + return node->dx < 0; + + return node->dx > 0; } - + dx = (x - node->x); dy = (y - node->y); - + // Try to quickly decide by looking at sign bits. if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 ) { - if ( (node->dy ^ dx) & 0x80000000 ) - { - // (left is negative) - return 1; - } - return 0; + if ( (node->dy ^ dx) & 0x80000000 ) + { + // (left is negative) + return 1; + } + return 0; } left = FixedMul ( node->dy>>FRACBITS , dx ); right = FixedMul ( dy , node->dx>>FRACBITS ); - + if (right < left) { - // front side - return 0; + // front side + return 0; } // back side - return 1; + return 1; } int R_PointOnSegSide -( fixed_t x, - fixed_t y, - seg_t* line ) +( fixed_t x, + fixed_t y, + seg_t* line ) { - fixed_t lx; - fixed_t ly; - fixed_t ldx; - fixed_t ldy; - fixed_t dx; - fixed_t dy; - fixed_t left; - fixed_t right; - + fixed_t lx; + fixed_t ly; + fixed_t ldx; + fixed_t ldy; + fixed_t dx; + fixed_t dy; + fixed_t left; + fixed_t right; + lx = line->v1->x; ly = line->v1->y; - + ldx = line->v2->x - lx; ldy = line->v2->y - ly; - + if (!ldx) { - if (x <= lx) - return ldy > 0; - - return ldy < 0; + if (x <= lx) + return ldy > 0; + + return ldy < 0; } if (!ldy) { - if (y <= ly) - return ldx < 0; - - return ldx > 0; + if (y <= ly) + return ldx < 0; + + return ldx > 0; } - + dx = (x - lx); dy = (y - ly); - + // Try to quickly decide by looking at sign bits. if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 ) { - if ( (ldy ^ dx) & 0x80000000 ) - { - // (left is negative) - return 1; - } - return 0; + if ( (ldy ^ dx) & 0x80000000 ) + { + // (left is negative) + return 1; + } + return 0; } left = FixedMul ( ldy>>FRACBITS , dx ); right = FixedMul ( dy , ldx>>FRACBITS ); - + if (right < left) { - // front side - return 0; + // front side + return 0; } // back side - return 1; + return 1; } @@ -290,85 +290,85 @@ R_PointOnSegSide angle_t R_PointToAngle -( fixed_t x, - fixed_t y ) -{ +( fixed_t x, + fixed_t y ) +{ x -= viewx; y -= viewy; if ( (!x) && (!y) ) - return 0; + return 0; if (x>= 0) { - // x >=0 - if (y>= 0) - { - // y>= 0 + // x >=0 + if (y>= 0) + { + // y>= 0 - if (x>y) - { - // octant 0 - return tantoangle[ SlopeDiv(y,x)]; - } - else - { - // octant 1 - return ANG90-1-tantoangle[ SlopeDiv(x,y)]; - } - } - else - { - // y<0 - y = -y; + if (x>y) + { + // octant 0 + return tantoangle[ SlopeDiv(y,x)]; + } + else + { + // octant 1 + return ANG90-1-tantoangle[ SlopeDiv(x,y)]; + } + } + else + { + // y<0 + y = -y; - if (x>y) - { - // octant 8 - return -tantoangle[SlopeDiv(y,x)]; - } - else - { - // octant 7 - return ANG270+tantoangle[ SlopeDiv(x,y)]; - } - } + if (x>y) + { + // octant 8 + return -tantoangle[SlopeDiv(y,x)]; + } + else + { + // octant 7 + return ANG270+tantoangle[ SlopeDiv(x,y)]; + } + } } else { - // x<0 - x = -x; + // x<0 + x = -x; - if (y>= 0) - { - // y>= 0 - if (x>y) - { - // octant 3 - return ANG180-1-tantoangle[ SlopeDiv(y,x)]; - } - else - { - // octant 2 - return ANG90+ tantoangle[ SlopeDiv(x,y)]; - } - } - else - { - // y<0 - y = -y; + if (y>= 0) + { + // y>= 0 + if (x>y) + { + // octant 3 + return ANG180-1-tantoangle[ SlopeDiv(y,x)]; + } + else + { + // octant 2 + return ANG90+ tantoangle[ SlopeDiv(x,y)]; + } + } + else + { + // y<0 + y = -y; - if (x>y) - { - // octant 4 - return ANG180+tantoangle[ SlopeDiv(y,x)]; - } - else - { - // octant 5 - return ANG270-1-tantoangle[ SlopeDiv(x,y)]; - } - } + if (x>y) + { + // octant 4 + return ANG180+tantoangle[ SlopeDiv(y,x)]; + } + else + { + // octant 5 + return ANG270-1-tantoangle[ SlopeDiv(x,y)]; + } + } } return 0; } @@ -376,11 +376,11 @@ R_PointToAngle angle_t R_PointToAngle2 -( fixed_t x1, - fixed_t y1, - fixed_t x2, - fixed_t y2 ) -{ +( fixed_t x1, + fixed_t y1, + fixed_t x2, + fixed_t y2 ) +{ viewx = x1; viewy = y1; @@ -390,30 +390,30 @@ R_PointToAngle2 fixed_t R_PointToDist -( fixed_t x, - fixed_t y ) +( fixed_t x, + fixed_t y ) { - int angle; - fixed_t dx; - fixed_t dy; - fixed_t temp; - fixed_t dist; - + int angle; + fixed_t dx; + fixed_t dy; + fixed_t temp; + fixed_t dist; + dx = abs(x - viewx); dy = abs(y - viewy); - + if (dy>dx) { - temp = dx; - dx = dy; - dy = temp; + temp = dx; + dx = dy; + dy = temp; } - + angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT; // use as cosine - dist = FixedDiv (dx, finesine[angle] ); - + dist = FixedDiv (dx, finesine[angle] ); + return dist; } @@ -427,17 +427,17 @@ void R_InitPointToAngle (void) { // UNUSED - now getting from tables.c #if 0 - int i; - long t; - float f; + int i; + long t; + float f; // // slope (tangent) to angle lookup // for (i=0 ; i<=SLOPERANGE ; i++) { - f = atan( (float)i/SLOPERANGE )/(3.141592657*2); - t = 0xffffffff*f; - tantoangle[i] = t; + f = atan( (float)i/SLOPERANGE )/(3.141592657*2); + t = 0xffffffff*f; + tantoangle[i] = t; } #endif } @@ -452,23 +452,23 @@ void R_InitPointToAngle (void) // fixed_t R_ScaleFromGlobalAngle (angle_t visangle) { - fixed_t scale; - int anglea; - int angleb; - int sinea; - int sineb; - fixed_t num; - int den; + fixed_t scale; + int anglea; + int angleb; + int sinea; + int sineb; + fixed_t num; + int den; // UNUSED #if 0 { - fixed_t dist; - fixed_t z; - fixed_t sinv; - fixed_t cosv; - - sinv = finesine[(visangle-rw_normalangle)>>ANGLETOFINESHIFT]; + fixed_t dist; + fixed_t z; + fixed_t sinv; + fixed_t cosv; + + sinv = finesine[(visangle-rw_normalangle)>>ANGLETOFINESHIFT]; dist = FixedDiv (rw_distance, sinv); cosv = finecosine[(viewangle-visangle)>>ANGLETOFINESHIFT]; z = abs(FixedMul (dist, cosv)); @@ -481,23 +481,23 @@ fixed_t R_ScaleFromGlobalAngle (angle_t visangle) angleb = ANG90 + (visangle-rw_normalangle); // both sines are allways positive - sinea = finesine[anglea>>ANGLETOFINESHIFT]; + sinea = finesine[anglea>>ANGLETOFINESHIFT]; sineb = finesine[angleb>>ANGLETOFINESHIFT]; num = FixedMul(projection,sineb)< num>>16) { - scale = FixedDiv (num, den); + scale = FixedDiv (num, den); - if (scale > 64*FRACUNIT) - scale = 64*FRACUNIT; - else if (scale < 256) - scale = 256; + if (scale > 64*FRACUNIT) + scale = 64*FRACUNIT; + else if (scale < 256) + scale = 256; } else - scale = 64*FRACUNIT; - + scale = 64*FRACUNIT; + return scale; } @@ -510,27 +510,27 @@ void R_InitTables (void) { // UNUSED: now getting from tables.c #if 0 - int i; - float a; - float fv; - int t; + int i; + float a; + float fv; + int t; // viewangle tangent table for (i=0 ; i FRACUNIT*2) - t = -1; - else if (finetangent[i] < -FRACUNIT*2) - t = viewwidth+1; - else - { - t = FixedMul (finetangent[i], focallength); - t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS; + if (finetangent[i] > FRACUNIT*2) + t = -1; + else if (finetangent[i] < -FRACUNIT*2) + t = viewwidth+1; + else + { + t = FixedMul (finetangent[i], focallength); + t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS; - if (t < -1) - t = -1; - else if (t>viewwidth+1) - t = viewwidth+1; - } - viewangletox[i] = t; + if (t < -1) + t = -1; + else if (t>viewwidth+1) + t = viewwidth+1; + } + viewangletox[i] = t; } // Scan viewangletox[] to generate xtoviewangle[]: // xtoviewangle will give the smallest view angle - // that maps to x. + // that maps to x. for (x=0;x<=viewwidth;x++) { - i = 0; - while (viewangletox[i]>x) - i++; - xtoviewangle[x] = (i<x) + i++; + xtoviewangle[x] = (i<>= LIGHTSCALESHIFT; - level = startmap - scale/DISTMAP; - - if (level < 0) - level = 0; + startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; + for (j=0 ; j>= LIGHTSCALESHIFT; + level = startmap - scale/DISTMAP; + + if (level < 0) + level = 0; - if (level >= NUMCOLORMAPS) - level = NUMCOLORMAPS-1; + if (level >= NUMCOLORMAPS) + level = NUMCOLORMAPS-1; - zlight[i][j] = colormaps + level*256; - } + zlight[i][j] = colormaps + level*256; + } } } @@ -649,15 +649,15 @@ void R_InitLightTables (void) // because it might be in the middle of a refresh. // The change will take effect next refresh. // -boolean setsizeneeded; -int setblocks; -int setdetail; +boolean setsizeneeded; +int setblocks; +int setdetail; void R_SetViewSize -( int blocks, - int detail ) +( int blocks, + int detail ) { setsizeneeded = true; setblocks = blocks; @@ -670,29 +670,29 @@ R_SetViewSize // void R_ExecuteSetViewSize (void) { - fixed_t cosadj; - fixed_t dy; - int i; - int j; - int level; - int startmap; + fixed_t cosadj; + fixed_t dy; + int i; + int j; + int level; + int startmap; setsizeneeded = false; if (setblocks == 11) { - scaledviewwidth = SCREENWIDTH; - viewheight = SCREENHEIGHT; + scaledviewwidth = SCREENWIDTH; + viewheight = SCREENHEIGHT; } else { - scaledviewwidth = setblocks*32; - viewheight = (setblocks*168/10)&~7; + scaledviewwidth = setblocks*32; + viewheight = (setblocks*168/10)&~7; } detailshift = setdetail; viewwidth = scaledviewwidth>>detailshift; - + centery = viewheight/2; centerx = viewwidth/2; centerxfrac = centerx<>ANGLETOFINESHIFT]); - distscale[i] = FixedDiv (FRACUNIT,cosadj); + cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]); + distscale[i] = FixedDiv (FRACUNIT,cosadj); } // Calculate the light levels to use // for each level / scale combination. for (i=0 ; i< LIGHTLEVELS ; i++) { - startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; - for (j=0 ; j= NUMCOLORMAPS) - level = NUMCOLORMAPS-1; + if (level >= NUMCOLORMAPS) + level = NUMCOLORMAPS-1; - scalelight[i][j] = colormaps + level*256; - } + scalelight[i][j] = colormaps + level*256; + } } } @@ -765,31 +765,31 @@ void R_ExecuteSetViewSize (void) // // R_Init // -extern int detailLevel; -extern int screenblocks; +extern int detailLevel; +extern int screenblocks; void R_Init (void) { R_InitData (); - printf ("\nR_InitData"); + printf ("R_InitData\n\r"); R_InitPointToAngle (); - printf ("\nR_InitPointToAngle"); + printf ("R_InitPointToAngle\n\r"); R_InitTables (); // viewwidth / viewheight / detailLevel are set by the defaults - printf ("\nR_InitTables"); + printf ("R_InitTables\n\r"); R_SetViewSize (screenblocks, detailLevel); R_InitPlanes (); - printf ("\nR_InitPlanes"); + printf ("R_InitPlanes\n\r"); R_InitLightTables (); - printf ("\nR_InitLightTables"); + printf ("R_InitLightTables\n\r"); R_InitSkyMap (); - printf ("\nR_InitSkyMap"); + printf ("R_InitSkyMap\n\r"); R_InitTranslationTables (); - printf ("\nR_InitTranslationsTables"); - + printf ("R_InitTranslationsTables\n\r"); + framecount = 0; } @@ -799,26 +799,26 @@ void R_Init (void) // subsector_t* R_PointInSubsector -( fixed_t x, - fixed_t y ) +( fixed_t x, + fixed_t y ) { - node_t* node; - int side; - int nodenum; + node_t* node; + int side; + int nodenum; // single subsector is a special case - if (!numnodes) - return subsectors; - + if (!numnodes) + return subsectors; + nodenum = numnodes-1; while (! (nodenum & NF_SUBSECTOR) ) { - node = &nodes[nodenum]; - side = R_PointOnSide (x, y, node); - nodenum = node->children[side]; + node = &nodes[nodenum]; + side = R_PointOnSide (x, y, node); + nodenum = node->children[side]; } - + return &subsectors[nodenum & ~NF_SUBSECTOR]; } @@ -828,8 +828,8 @@ R_PointInSubsector // R_SetupFrame // void R_SetupFrame (player_t* player) -{ - int i; +{ + int i; viewplayer = player; viewx = player->mo->x; @@ -841,23 +841,23 @@ void R_SetupFrame (player_t* player) viewsin = finesine[viewangle>>ANGLETOFINESHIFT]; viewcos = finecosine[viewangle>>ANGLETOFINESHIFT]; - + sscount = 0; - + if (player->fixedcolormap) { - fixedcolormap = - colormaps - + player->fixedcolormap*256*sizeof(lighttable_t); - - walllights = scalelightfixed; + fixedcolormap = + colormaps + + player->fixedcolormap*256*sizeof(lighttable_t); + + walllights = scalelightfixed; - for (i=0 ; i>FRACBITS) +#define S_ATTENUATOR ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS) // Adjustable by menu. -#define NORM_VOLUME snd_MaxVolume +#define NORM_VOLUME snd_MaxVolume -#define NORM_PITCH 128 -#define NORM_PRIORITY 64 -#define NORM_SEP 128 +#define NORM_PITCH 128 +#define NORM_PRIORITY 64 +#define NORM_SEP 128 -#define S_PITCH_PERTURB 1 -#define S_STEREO_SWING (96*0x10000) +#define S_PITCH_PERTURB 1 +#define S_STEREO_SWING (96*0x10000) // percent attenuation from front to back -#define S_IFRACVOL 30 +#define S_IFRACVOL 30 -#define NA 0 -//#define S_NUMCHANNELS 2 -#define NUM_CHANNELS 16 +#define NA 0 +//#define S_NUMCHANNELS 2 +#define NUM_CHANNELS 16 // Current music/sfx card - index useless // w/o a reference LUT in a sound module. @@ -95,42 +95,42 @@ extern int snd_DesiredSfxDevice; typedef struct { // sound information (if null, channel avail.) - sfxinfo_t* sfxinfo; + sfxinfo_t* sfxinfo; // origin of sound - void* origin; + void* origin; // handle of the sound being played - int handle; + int handle; } channel_t; // the set of channels available -static channel_t* channels; +static channel_t* channels; // These are not used, but should be (menu). // Maximum volume of a sound effect. // Internal default is max out of 0-15. -int snd_SfxVolume = 80; +int snd_SfxVolume = 80; // Maximum volume of music. Useless so far. -int snd_MusicVolume = 80; +int snd_MusicVolume = 80; // whether songs are mus_paused -static boolean mus_paused; +static boolean mus_paused; // music currently being played -static musicinfo_t* mus_playing=0; +static musicinfo_t* mus_playing=0; // following is set // by the defaults code in M_misc: // number of channels available -int numChannels; +int numChannels; -static int nextcleanup; +static int nextcleanup; @@ -139,18 +139,18 @@ static int nextcleanup; // int S_getChannel -( void* origin, - sfxinfo_t* sfxinfo, +( void* origin, + sfxinfo_t* sfxinfo, int sfxid ); int S_AdjustSoundParams -( mobj_t* listener, - mobj_t* source, - int* vol, - int* sep, - int* pitch ); +( mobj_t* listener, + mobj_t* source, + int* vol, + int* sep, + int* pitch ); void S_StopChannel(int cnum); @@ -162,14 +162,14 @@ void S_StopChannel(int cnum); // allocates channel buffer, sets S_sfx lookup. // void S_Init -( int sfxVolume, - int musicVolume ) +( int sfxVolume, + int musicVolume ) { - int i; + int i; printf("S_Init: default sfx volume %d\n", sfxVolume); - I_CreateSound(); + //I_CreateSound(); numChannels = NUM_CHANNELS; // Whatever these did with DMX, these are rather dummies now. @@ -217,37 +217,37 @@ void S_Start(void) mus_paused = 0; if (gamemode == commercial) - mnum = mus_runnin + gamemap - 1; + mnum = mus_runnin + gamemap - 1; else { - int spmus[]= - { - // Song - Who? - Where? - mus_e3m4, // American e4m1 - mus_e3m2, // Romero e4m2 - mus_e3m3, // Shawn e4m3 - mus_e1m5, // American e4m4 - mus_e2m7, // Tim e4m5 - mus_e2m4, // Romero e4m6 - mus_e2m6, // J.Anderson e4m7 CHIRON.WAD - mus_e2m5, // Shawn e4m8 - mus_e1m9 // Tim e4m9 - }; - - if (gameepisode < 4) - mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1; - else - mnum = spmus[gamemap-1]; - } + int spmus[]= + { + // Song - Who? - Where? + mus_e3m4, // American e4m1 + mus_e3m2, // Romero e4m2 + mus_e3m3, // Shawn e4m3 + mus_e1m5, // American e4m4 + mus_e2m7, // Tim e4m5 + mus_e2m4, // Romero e4m6 + mus_e2m6, // J.Anderson e4m7 CHIRON.WAD + mus_e2m5, // Shawn e4m8 + mus_e1m9 // Tim e4m9 + }; + + if (gameepisode < 4) + mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1; + else + mnum = spmus[gamemap-1]; + } // HACK FOR COMMERCIAL - // if (commercial && mnum > mus_e3m9) + // if (commercial && mnum > mus_e3m9) // mnum -= mus_e3m9; S_ChangeMusic(mnum, true); nextcleanup = 15; -} +} void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) { @@ -259,7 +259,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) int cnum; // int chnum; <-- 10.9.98 compiler warning - mobj_t* origin = (mobj_t *)origin_p; + mobj_t* origin = (mobj_t *)origin_p; //WriteDebug("S_StartSoundAtVolume...\n"); @@ -287,7 +287,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) if (volume > snd_SfxVolume) volume = snd_SfxVolume; - } + } else { pitch = NORM_PITCH; @@ -301,7 +301,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) { rc = S_AdjustSoundParams(players[consoleplayer].mo, origin, &volume, &sep, &pitch); if ( origin->x == players[consoleplayer].mo->x && origin->y == players[consoleplayer].mo->y) - { + { sep = NORM_SEP; } if (!rc) @@ -309,7 +309,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) //WriteDebug("No rc from S_AdjustSoundParams...\n"); return; } - } + } else { sep = NORM_SEP; @@ -317,7 +317,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) // hacks to vary the sfx pitches if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit) - { + { pitch += 8 - (M_Random()&15); if (pitch < 0) pitch = 0; @@ -372,12 +372,11 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume ) // Assigns the handle to one of the channels in the // mix/output buffer. //WriteDebug("I_StartSound...\n"); - channels[cnum].handle = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin); - //cnum = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin); + channels[cnum].handle = I_StartSound(sfx_id,volume,sep,pitch,priority); channels[cnum].handle = cnum; channels[cnum].sfxinfo = sfx; channels[cnum].origin = origin; -} +} void S_StartSound( void *origin, int sfx_id ) { @@ -394,53 +393,53 @@ void S_StartSound( void *origin, int sfx_id ) { int i; int n; - + static mobj_t* last_saw_origins[10] = {1,1,1,1,1,1,1,1,1,1}; - static int first_saw=0; - static int next_saw=0; - + static int first_saw=0; + static int next_saw=0; + if (sfx_id == sfx_sawidl - || sfx_id == sfx_sawful - || sfx_id == sfx_sawhit) + || sfx_id == sfx_sawful + || sfx_id == sfx_sawhit) { - for (i=first_saw;i!=next_saw;i=(i+1)%10) - if (last_saw_origins[i] != origin) - fprintf(stderr, "old origin 0x%lx != " - "origin 0x%lx for sfx %d\n", - last_saw_origins[i], - origin, - sfx_id); - - last_saw_origins[next_saw] = origin; - next_saw = (next_saw + 1) % 10; - if (next_saw == first_saw) - first_saw = (first_saw + 1) % 10; - - for (n=i=0; i1) - { - for (i=0; i1) + { + for (i=0; ihandle); - mus_paused = true; + I_PauseSong(mus_playing->handle); + mus_paused = true; } } @@ -489,8 +488,8 @@ void S_ResumeSound(void) { if (mus_playing && mus_paused) { - I_ResumeSong(mus_playing->handle); - mus_paused = false; + I_ResumeSong(mus_playing->handle); + mus_paused = false; } } @@ -500,15 +499,15 @@ void S_ResumeSound(void) // void S_UpdateSounds(void* listener_p) { - int audible; - int cnum; - int volume; - int sep; - int pitch; - sfxinfo_t* sfx; - channel_t* c; + int audible; + int cnum; + int volume; + int sep; + int pitch; + sfxinfo_t* sfx; + channel_t* c; - mobj_t* listener = (mobj_t*)listener_p; + mobj_t* listener = (mobj_t*)listener_p; @@ -517,78 +516,78 @@ void S_UpdateSounds(void* listener_p) // DOS 8bit remains. /*if (gametic > nextcleanup) { - for (i=1 ; i -1) - { - if (--S_sfx[i].usefulness == -1) - { - Z_ChangeTag(S_sfx[i].data, PU_CACHE); - S_sfx[i].data = 0; - } - } - } - nextcleanup = gametic + 15; + for (i=1 ; i -1) + { + if (--S_sfx[i].usefulness == -1) + { + Z_ChangeTag(S_sfx[i].data, PU_CACHE); + S_sfx[i].data = 0; + } + } + } + nextcleanup = gametic + 15; }*/ for (cnum=0 ; cnumsfxinfo; + c = &channels[cnum]; + sfx = c->sfxinfo; - if (c->sfxinfo) - { - if (I_SoundIsPlaying(c->handle)) - { - // initialize parameters - volume = snd_SfxVolume; - pitch = NORM_PITCH; - sep = NORM_SEP; + if (c->sfxinfo) + { + if (I_SoundIsPlaying(c->handle)) + { + // initialize parameters + volume = snd_SfxVolume; + pitch = NORM_PITCH; + sep = NORM_SEP; - if (sfx->link) - { - pitch = sfx->pitch; - volume += sfx->volume; - if (volume < 1) - { - S_StopChannel(cnum); - continue; - } - else if (volume > snd_SfxVolume) - { - volume = snd_SfxVolume; - } - } + if (sfx->link) + { + pitch = sfx->pitch; + volume += sfx->volume; + if (volume < 1) + { + S_StopChannel(cnum); + continue; + } + else if (volume > snd_SfxVolume) + { + volume = snd_SfxVolume; + } + } - // check non-local sounds for distance clipping - // or modify their params - if (c->origin && listener_p != c->origin) - { - audible = S_AdjustSoundParams(listener, - c->origin, - &volume, - &sep, - &pitch); - - if (!audible) - { - S_StopChannel(cnum); - } - else - I_UpdateSoundParams(c->handle, volume, sep, pitch); - } - } - else - { - // if channel is allocated but sound has stopped, - // free it - S_StopChannel(cnum); - } - } + // check non-local sounds for distance clipping + // or modify their params + if (c->origin && listener_p != c->origin) + { + audible = S_AdjustSoundParams(listener, + c->origin, + &volume, + &sep, + &pitch); + + if (!audible) + { + S_StopChannel(cnum); + } + else + I_UpdateSoundParams(c->handle, volume, sep, pitch); + } + } + else + { + // if channel is allocated but sound has stopped, + // free it + S_StopChannel(cnum); + } + } } // kill music if it is a single-play && finished - // if ( mus_playing + // if ( mus_playing // && !I_QrySongPlaying(mus_playing->handle) // && !mus_paused ) // S_StopMusic(); @@ -599,8 +598,8 @@ void S_SetMusicVolume(int volume) { if (volume < 0 || volume > 127) { - I_Error("Attempt to set music volume at %d", - volume); + I_Error("Attempt to set music volume at %d", + volume); } I_SetMusicVolume(127); @@ -614,7 +613,7 @@ void S_SetSfxVolume(int volume) { if (volume < 0 || volume > 127) - I_Error("Attempt to set sfx volume at %d", volume); + I_Error("Attempt to set sfx volume at %d", volume); snd_SfxVolume = volume; @@ -634,7 +633,7 @@ void S_ChangeMusic(int musicnum, int looping) { // I_PlaySong(music->handle, looping); -// mus_playing = music; +// mus_playing = music; } @@ -642,48 +641,48 @@ void S_StopMusic(void) { if (mus_playing) { - if (mus_paused) I_ResumeSong(mus_playing->handle); - I_StopSong(mus_playing->handle); - I_UnRegisterSong(mus_playing->handle); - Z_ChangeTag(mus_playing->data, PU_CACHE); - mus_playing->data = 0; - mus_playing = 0; + if (mus_paused) I_ResumeSong(mus_playing->handle); + I_StopSong(mus_playing->handle); + I_UnRegisterSong(mus_playing->handle); + Z_ChangeTag(mus_playing->data, PU_CACHE); + mus_playing->data = 0; + mus_playing = 0; } } void S_StopChannel(int cnum) { - int i; - channel_t* c = &channels[cnum]; + int i; + channel_t* c = &channels[cnum]; if (c->sfxinfo) { - // stop the sound playing - if (I_SoundIsPlaying(c->handle)) - { + // stop the sound playing + if (I_SoundIsPlaying(c->handle)) + { #ifdef SAWDEBUG - if (c->sfxinfo == &S_sfx[sfx_sawful]) - fprintf(stderr, "stopped\n"); + if (c->sfxinfo == &S_sfx[sfx_sawful]) + fprintf(stderr, "stopped\n"); #endif - I_StopSound(c->handle); - } + I_StopSound(c->handle); + } - // check to see - // if other channels are playing the sound - for (i=0 ; isfxinfo == channels[i].sfxinfo) - { - break; - } - } - - // degrade usefulness of sound data - c->sfxinfo->usefulness--; + // check to see + // if other channels are playing the sound + for (i=0 ; isfxinfo == channels[i].sfxinfo) + { + break; + } + } + + // degrade usefulness of sound data + c->sfxinfo->usefulness--; - c->sfxinfo = 0; + c->sfxinfo = 0; } } @@ -698,10 +697,10 @@ int S_AdjustSoundParams (mobj_t* listener, mobj_t* source, int* vol, int* sep, int* pitch) { - fixed_t approx_dist; - fixed_t adx; - fixed_t ady; - angle_t angle; + fixed_t approx_dist; + fixed_t adx; + fixed_t ady; + angle_t angle; // calculate the distance to sound origin // and clip it if necessary @@ -712,21 +711,21 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source, approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1); if (gamemap != 8 - && approx_dist > S_CLIPPING_DIST) + && approx_dist > S_CLIPPING_DIST) { - return 0; + return 0; } // angle of source to listener angle = R_PointToAngle2(listener->x, - listener->y, - source->x, - source->y); + listener->y, + source->x, + source->y); if (angle > listener->angle) - angle = angle - listener->angle; + angle = angle - listener->angle; else - angle = angle + (0xffffffff - listener->angle); + angle = angle + (0xffffffff - listener->angle); angle >>= ANGLETOFINESHIFT; @@ -736,23 +735,23 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source, // volume calculation if (approx_dist < S_CLOSE_DIST) { - *vol = snd_SfxVolume; + *vol = snd_SfxVolume; } else if (gamemap == 8) { - if (approx_dist > S_CLIPPING_DIST) - approx_dist = S_CLIPPING_DIST; + if (approx_dist > S_CLIPPING_DIST) + approx_dist = S_CLIPPING_DIST; - *vol = 15+ ((snd_SfxVolume-15) - *((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) - / S_ATTENUATOR; + *vol = 15+ ((snd_SfxVolume-15) + *((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) + / S_ATTENUATOR; } else { - // distance effect - *vol = (snd_SfxVolume - * ((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) - / S_ATTENUATOR; + // distance effect + *vol = (snd_SfxVolume + * ((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) + / S_ATTENUATOR; } return (*vol > 0); @@ -765,9 +764,9 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source, int S_getChannel( void *origin, sfxinfo_t *sfxinfo, int sfxid ) { // channel number to use - int cnum; + int cnum; - channel_t* c; + channel_t* c; // Find an open channel //for (cnum = 0; cnum < numChannels; cnum++) diff --git a/programs/games/doom/trunk/st_lib.c b/programs/games/doom/trunk/st_lib.c index dda355a021..1f060cfc90 100644 --- a/programs/games/doom/trunk/st_lib.c +++ b/programs/games/doom/trunk/st_lib.c @@ -32,6 +32,8 @@ rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $"; #include "z_zone.h" #include "v_video.h" +#include "m_swap.h" + #include "i_system.h" #include "w_wad.h" @@ -94,8 +96,8 @@ STlib_drawNum int numdigits = n->width; int num = *n->num; - int w = (n->p[0]->width); - int h = (n->p[0]->height); + int w = SHORT(n->p[0]->width); + int h = SHORT(n->p[0]->height); int x = n->x; int neg; @@ -222,10 +224,10 @@ STlib_updateMultIcon { if (mi->oldinum != -1) { - x = mi->x - (mi->p[mi->oldinum]->leftoffset); - y = mi->y - (mi->p[mi->oldinum]->topoffset); - w = (mi->p[mi->oldinum]->width); - h = (mi->p[mi->oldinum]->height); + x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset); + y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset); + w = SHORT(mi->p[mi->oldinum]->width); + h = SHORT(mi->p[mi->oldinum]->height); if (y - ST_Y < 0) I_Error("updateMultIcon: y - ST_Y < 0"); @@ -271,10 +273,10 @@ STlib_updateBinIcon if (*bi->on && (bi->oldval != *bi->val || refresh)) { - x = bi->x - (bi->p->leftoffset); - y = bi->y - (bi->p->topoffset); - w = (bi->p->width); - h = (bi->p->height); + x = bi->x - SHORT(bi->p->leftoffset); + y = bi->y - SHORT(bi->p->topoffset); + w = SHORT(bi->p->width); + h = SHORT(bi->p->height); if (y - ST_Y < 0) I_Error("updateBinIcon: y - ST_Y < 0"); diff --git a/programs/games/doom/trunk/st_stuff.c b/programs/games/doom/trunk/st_stuff.c index 166e8c8043..16f2e3f146 100644 --- a/programs/games/doom/trunk/st_stuff.c +++ b/programs/games/doom/trunk/st_stuff.c @@ -1074,13 +1074,13 @@ void ST_drawWidgets(boolean refresh) STlib_updateBinIcon(&w_armsbg, refresh); - for (i=0;i<5;i++) - STlib_updateMultIcon(&w_arms[i], refresh); + for (i=0;i<6;i++) + STlib_updateMultIcon(&w_arms[i], refresh); STlib_updateMultIcon(&w_faces, refresh); for (i=0;i<3;i++) - STlib_updateMultIcon(&w_keyboxes[i], refresh); + STlib_updateMultIcon(&w_keyboxes[i], refresh); STlib_updateNum(&w_frags, refresh); @@ -1273,7 +1273,7 @@ void ST_initData(void) for (i=0;i<3;i++) keyboxes[i] = -1; - // STlib_init(); + STlib_init(); } diff --git a/programs/games/doom/trunk/v_video.c b/programs/games/doom/trunk/v_video.c index d4daddfb49..1de1b3e642 100644 --- a/programs/games/doom/trunk/v_video.c +++ b/programs/games/doom/trunk/v_video.c @@ -1,493 +1,493 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// $Id:$ -// -// Copyright (C) 1993-1996 by id Software, Inc. -// -// This source is available for distribution and/or modification -// only under the terms of the DOOM Source Code License as -// published by id Software. All rights reserved. -// -// The source is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License -// for more details. -// -// $Log:$ -// -// DESCRIPTION: -// Gamma correction LUT stuff. -// Functions to draw patches (by post) directly to screen. -// Functions to blit a block to the screen. -// -//----------------------------------------------------------------------------- - - -static const char -rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $"; - - -#include "m_swap.h" -#include "i_system.h" -#include "r_local.h" - -#include "doomdef.h" -#include "doomdata.h" - -#include "m_bbox.h" - -#include "v_video.h" -#include "kolibri.h" - -// Each screen is [SCREENWIDTH*SCREENHEIGHT]; -byte* screens[5]; - -int dirtybox[4]; - - - -// Now where did these came from? -byte gammatable[5][256] = -{ - {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, - 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, - 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, - 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, - 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, - 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, - 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}, - - {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31, - 32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55, - 56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77, - 78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98, - 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, - 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129, - 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145, - 146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160, - 161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175, - 175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189, - 190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204, - 205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218, - 219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232, - 233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246, - 247,248,249,250,251,252,252,253,254,255}, - - {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42, - 43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69, - 70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93, - 94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144, - 144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159, - 160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173, - 174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188, - 188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201, - 202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215, - 216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228, - 229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241, - 242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254, - 255}, - - {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55, - 57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85, - 86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107, - 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124, - 125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140, - 141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155, - 155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169, - 169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182, - 183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195, - 195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207, - 207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219, - 219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230, - 231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241, - 242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252, - 253,253,254,254,255}, - - {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76, - 78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106, - 107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124, - 125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141, - 142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155, - 156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169, - 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181, - 182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193, - 193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203, - 204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214, - 214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224, - 224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233, - 234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242, - 243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251, - 251,252,252,253,254,254,255,255} -}; - - - -int usegamma; - -// -// V_MarkRect -// -void -V_MarkRect -( int x, - int y, - int width, - int height ) -{ - M_AddToBox (dirtybox, x, y); - M_AddToBox (dirtybox, x+width-1, y+height-1); -} - - -// -// V_CopyRect -// -void -V_CopyRect -( int srcx, - int srcy, - int srcscrn, - int width, - int height, - int destx, - int desty, - int destscrn ) -{ - byte* src; - byte* dest; - -#ifdef RANGECHECK - if (srcx<0 - ||srcx+width >SCREENWIDTH - || srcy<0 - || srcy+height>SCREENHEIGHT - ||destx<0||destx+width >SCREENWIDTH - || desty<0 - || desty+height>SCREENHEIGHT - || (unsigned)srcscrn>4 - || (unsigned)destscrn>4) - { - I_Error ("Bad V_CopyRect"); - } -#endif - V_MarkRect (destx, desty, width, height); - - src = screens[srcscrn]+SCREENWIDTH*srcy+srcx; - dest = screens[destscrn]+SCREENWIDTH*desty+destx; - - for ( ; height>0 ; height--) - { - memcpy (dest, src, width); - src += SCREENWIDTH; - dest += SCREENWIDTH; - } -} - - -// -// V_DrawPatch -// Masks a column based masked pic to the screen. -// -void -V_DrawPatch -( int x, - int y, - int scrn, - patch_t* patch ) -{ - - int count; - int col; - column_t* column; - byte* desttop; - byte* dest; - byte* source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); -#ifdef RANGECHECK - if (x<0 - ||x+SHORT(patch->width) >SCREENWIDTH - || y<0 - || y+SHORT(patch->height)>SCREENHEIGHT - || (unsigned)scrn>4) - { - printf("Patch at %d,%d exceeds LFB\n", x,y ); - // No I_Error abort - what is up with TNT.WAD? - printf("V_DrawPatch: bad patch (ignored)\n"); - return; - } -#endif - - if (!scrn) - V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); - - col = 0; - desttop = screens[scrn]+y*SCREENWIDTH+x; - - w = SHORT(patch->width); - - for ( ; colcolumnofs[col])); - - // step through the posts in a column - while (column->topdelta != 0xff ) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta*SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH; - } - column = (column_t *)( (byte *)column + column->length - + 4 ); - } - } -} - -// -// V_DrawPatchFlipped -// Masks a column based masked pic to the screen. -// Flips horizontally, e.g. to mirror face. -// -void -V_DrawPatchFlipped -( int x, - int y, - int scrn, - patch_t* patch ) -{ - - int count; - int col; - column_t* column; - byte* desttop; - byte* dest; - byte* source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); -#ifdef RANGECHECK - if (x<0 - ||x+SHORT(patch->width) >SCREENWIDTH - || y<0 - || y+SHORT(patch->height)>SCREENHEIGHT - || (unsigned)scrn>4) - { - printf("Patch origin %d,%d exceeds LFB\n", x,y ); - I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped"); - } -#endif - - if (!scrn) - V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); - - col = 0; - desttop = screens[scrn]+y*SCREENWIDTH+x; - - w = SHORT(patch->width); - - for ( ; colcolumnofs[w-1-col])); - - // step through the posts in a column - while (column->topdelta != 0xff ) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta*SCREENWIDTH; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH; - } - column = (column_t *)( (byte *)column + column->length - + 4 ); - } - } -} - - - -// -// V_DrawPatchDirect -// Draws directly to the screen on the pc. -// -void -V_DrawPatchDirect -( int x, - int y, - int scrn, - patch_t* patch ) -{ - V_DrawPatch (x,y,scrn, patch); - - /* - int count; - int col; - column_t* column; - byte* desttop; - byte* dest; - byte* source; - int w; - - y -= SHORT(patch->topoffset); - x -= SHORT(patch->leftoffset); - -#ifdef RANGECHECK - if (x<0 - ||x+SHORT(patch->width) >SCREENWIDTH - || y<0 - || y+SHORT(patch->height)>SCREENHEIGHT - || (unsigned)scrn>4) - { - I_Error ("Bad V_DrawPatchDirect"); - } -#endif - - // V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); - desttop = destscreen + y*SCREENWIDTH/4 + (x>>2); - - w = SHORT(patch->width); - for ( col = 0 ; colcolumnofs[col])); - - // step through the posts in a column - - while (column->topdelta != 0xff ) - { - source = (byte *)column + 3; - dest = desttop + column->topdelta*SCREENWIDTH/4; - count = column->length; - - while (count--) - { - *dest = *source++; - dest += SCREENWIDTH/4; - } - column = (column_t *)( (byte *)column + column->length - + 4 ); - } - if ( ((++x)&3) == 0 ) - desttop++; // go to next byte, not next plane - }*/ -} - - - -// -// V_DrawBlock -// Draw a linear block of pixels into the view buffer. -// -void -V_DrawBlock -( int x, - int y, - int scrn, - int width, - int height, - byte* src ) -{ - byte* dest; - -#ifdef RANGECHECK - if (x<0 - ||x+width >SCREENWIDTH - || y<0 - || y+height>SCREENHEIGHT - || (unsigned)scrn>4 ) - { - I_Error ("Bad V_DrawBlock"); - } -#endif - - V_MarkRect (x, y, width, height); - - dest = screens[scrn] + y*SCREENWIDTH+x; - - while (height--) - { - memcpy (dest, src, width); - src += width; - dest += SCREENWIDTH; - } -} - - - -// -// V_GetBlock -// Gets a linear block of pixels from the view buffer. -// -void -V_GetBlock -( int x, - int y, - int scrn, - int width, - int height, - byte* dest ) -{ - byte* src; - -#ifdef RANGECHECK - if (x<0 - ||x+width >SCREENWIDTH - || y<0 - || y+height>SCREENHEIGHT - || (unsigned)scrn>4 ) - { - I_Error ("Bad V_DrawBlock"); - } -#endif - - src = screens[scrn] + y*SCREENWIDTH+x; - - while (height--) - { - memcpy (dest, src, width); - src += SCREENWIDTH; - dest += width; - } -} - - - - -// -// V_Init -// -void V_Init (void) -{ - int i; - byte* base; - size_t size; - // stick these in low dos memory on PCs - size = SCREENWIDTH*SCREENHEIGHT*4; - base = (byte*)UserAlloc(size); - - for (i=0 ; i<4 ; i++) - screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT; -} +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id:$ +// +// Copyright (C) 1993-1996 by id Software, Inc. +// +// This source is available for distribution and/or modification +// only under the terms of the DOOM Source Code License as +// published by id Software. All rights reserved. +// +// The source is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License +// for more details. +// +// $Log:$ +// +// DESCRIPTION: +// Gamma correction LUT stuff. +// Functions to draw patches (by post) directly to screen. +// Functions to blit a block to the screen. +// +//----------------------------------------------------------------------------- + + +static const char +rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $"; + + +#include "m_swap.h" +#include "i_system.h" +#include "r_local.h" + +#include "doomdef.h" +#include "doomdata.h" + +#include "m_bbox.h" + +#include "v_video.h" +#include "kolibri.h" + +// Each screen is [SCREENWIDTH*SCREENHEIGHT]; +byte* screens[5]; + +int dirtybox[4]; + + + +// Now where did these came from? +byte gammatable[5][256] = +{ + {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, + 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, + 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, + 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, + 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, + 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, + 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, + 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, + 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}, + + {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31, + 32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55, + 56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77, + 78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98, + 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, + 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129, + 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145, + 146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160, + 161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175, + 175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189, + 190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204, + 205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218, + 219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232, + 233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246, + 247,248,249,250,251,252,252,253,254,255}, + + {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42, + 43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69, + 70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93, + 94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112, + 113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, + 129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144, + 144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159, + 160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173, + 174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188, + 188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201, + 202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215, + 216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228, + 229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241, + 242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254, + 255}, + + {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55, + 57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85, + 86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107, + 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124, + 125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140, + 141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155, + 155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169, + 169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182, + 183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195, + 195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207, + 207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219, + 219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230, + 231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241, + 242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252, + 253,253,254,254,255}, + + {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76, + 78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106, + 107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124, + 125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141, + 142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155, + 156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169, + 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181, + 182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193, + 193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203, + 204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214, + 214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224, + 224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233, + 234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242, + 243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251, + 251,252,252,253,254,254,255,255} +}; + + + +int usegamma; + +// +// V_MarkRect +// +void +V_MarkRect +( int x, + int y, + int width, + int height ) +{ + M_AddToBox (dirtybox, x, y); + M_AddToBox (dirtybox, x+width-1, y+height-1); +} + + +// +// V_CopyRect +// +void +V_CopyRect +( int srcx, + int srcy, + int srcscrn, + int width, + int height, + int destx, + int desty, + int destscrn ) +{ + byte* src; + byte* dest; + +#ifdef RANGECHECK + if (srcx<0 + ||srcx+width >SCREENWIDTH + || srcy<0 + || srcy+height>SCREENHEIGHT + ||destx<0||destx+width >SCREENWIDTH + || desty<0 + || desty+height>SCREENHEIGHT + || (unsigned)srcscrn>4 + || (unsigned)destscrn>4) + { + I_Error ("Bad V_CopyRect"); + } +#endif + V_MarkRect (destx, desty, width, height); + + src = screens[srcscrn]+SCREENWIDTH*srcy+srcx; + dest = screens[destscrn]+SCREENWIDTH*desty+destx; + + for ( ; height>0 ; height--) + { + memcpy (dest, src, width); + src += SCREENWIDTH; + dest += SCREENWIDTH; + } +} + + +// +// V_DrawPatch +// Masks a column based masked pic to the screen. +// +void +V_DrawPatch +( int x, + int y, + int scrn, + patch_t* patch ) +{ + + int count; + int col; + column_t* column; + byte* desttop; + byte* dest; + byte* source; + int w; + + y -= SHORT(patch->topoffset); + x -= SHORT(patch->leftoffset); +#ifdef RANGECHECK + if (x<0 + ||x+SHORT(patch->width) >SCREENWIDTH + || y<0 + || y+SHORT(patch->height)>SCREENHEIGHT + || (unsigned)scrn>4) + { + //printf("Patch at %d,%d exceeds LFB\n", x,y ); + // No I_Error abort - what is up with TNT.WAD? + //printf("V_DrawPatch: bad patch (ignored)\n"); + return; + } +#endif + + if (!scrn) + V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); + + col = 0; + desttop = screens[scrn]+y*SCREENWIDTH+x; + + w = SHORT(patch->width); + + for ( ; colcolumnofs[col])); + + // step through the posts in a column + while (column->topdelta != 0xff ) + { + source = (byte *)column + 3; + dest = desttop + column->topdelta*SCREENWIDTH; + count = column->length; + + while (count--) + { + *dest = *source++; + dest += SCREENWIDTH; + } + column = (column_t *)( (byte *)column + column->length + + 4 ); + } + } +} + +// +// V_DrawPatchFlipped +// Masks a column based masked pic to the screen. +// Flips horizontally, e.g. to mirror face. +// +void +V_DrawPatchFlipped +( int x, + int y, + int scrn, + patch_t* patch ) +{ + + int count; + int col; + column_t* column; + byte* desttop; + byte* dest; + byte* source; + int w; + + y -= SHORT(patch->topoffset); + x -= SHORT(patch->leftoffset); +#ifdef RANGECHECK + if (x<0 + ||x+SHORT(patch->width) >SCREENWIDTH + || y<0 + || y+SHORT(patch->height)>SCREENHEIGHT + || (unsigned)scrn>4) + { + //printf("Patch origin %d,%d exceeds LFB\n", x,y ); + I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped"); + } +#endif + + if (!scrn) + V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); + + col = 0; + desttop = screens[scrn]+y*SCREENWIDTH+x; + + w = SHORT(patch->width); + + for ( ; colcolumnofs[w-1-col])); + + // step through the posts in a column + while (column->topdelta != 0xff ) + { + source = (byte *)column + 3; + dest = desttop + column->topdelta*SCREENWIDTH; + count = column->length; + + while (count--) + { + *dest = *source++; + dest += SCREENWIDTH; + } + column = (column_t *)( (byte *)column + column->length + + 4 ); + } + } +} + + + +// +// V_DrawPatchDirect +// Draws directly to the screen on the pc. +// +void +V_DrawPatchDirect +( int x, + int y, + int scrn, + patch_t* patch ) +{ + V_DrawPatch (x,y,scrn, patch); + + /* + int count; + int col; + column_t* column; + byte* desttop; + byte* dest; + byte* source; + int w; + + y -= SHORT(patch->topoffset); + x -= SHORT(patch->leftoffset); + +#ifdef RANGECHECK + if (x<0 + ||x+SHORT(patch->width) >SCREENWIDTH + || y<0 + || y+SHORT(patch->height)>SCREENHEIGHT + || (unsigned)scrn>4) + { + I_Error ("Bad V_DrawPatchDirect"); + } +#endif + + // V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height)); + desttop = destscreen + y*SCREENWIDTH/4 + (x>>2); + + w = SHORT(patch->width); + for ( col = 0 ; colcolumnofs[col])); + + // step through the posts in a column + + while (column->topdelta != 0xff ) + { + source = (byte *)column + 3; + dest = desttop + column->topdelta*SCREENWIDTH/4; + count = column->length; + + while (count--) + { + *dest = *source++; + dest += SCREENWIDTH/4; + } + column = (column_t *)( (byte *)column + column->length + + 4 ); + } + if ( ((++x)&3) == 0 ) + desttop++; // go to next byte, not next plane + }*/ +} + + + +// +// V_DrawBlock +// Draw a linear block of pixels into the view buffer. +// +void +V_DrawBlock +( int x, + int y, + int scrn, + int width, + int height, + byte* src ) +{ + byte* dest; + +#ifdef RANGECHECK + if (x<0 + ||x+width >SCREENWIDTH + || y<0 + || y+height>SCREENHEIGHT + || (unsigned)scrn>4 ) + { + I_Error ("Bad V_DrawBlock"); + } +#endif + + V_MarkRect (x, y, width, height); + + dest = screens[scrn] + y*SCREENWIDTH+x; + + while (height--) + { + memcpy (dest, src, width); + src += width; + dest += SCREENWIDTH; + } +} + + + +// +// V_GetBlock +// Gets a linear block of pixels from the view buffer. +// +void +V_GetBlock +( int x, + int y, + int scrn, + int width, + int height, + byte* dest ) +{ + byte* src; + +#ifdef RANGECHECK + if (x<0 + ||x+width >SCREENWIDTH + || y<0 + || y+height>SCREENHEIGHT + || (unsigned)scrn>4 ) + { + I_Error ("Bad V_DrawBlock"); + } +#endif + + src = screens[scrn] + y*SCREENWIDTH+x; + + while (height--) + { + memcpy (dest, src, width); + src += SCREENWIDTH; + dest += width; + } +} + + + + +// +// V_Init +// +void V_Init (void) +{ + int i; + byte* base; + size_t size; + // stick these in low dos memory on PCs + size = SCREENWIDTH*SCREENHEIGHT*4; + base = (byte*)UserAlloc(size); + + for (i=0 ; i<4 ; i++) + screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT; +} diff --git a/programs/games/doom/trunk/w_sound.c b/programs/games/doom/trunk/w_sound.c index bd0eefc5d3..8d74b04098 100644 --- a/programs/games/doom/trunk/w_sound.c +++ b/programs/games/doom/trunk/w_sound.c @@ -24,8 +24,6 @@ static const char rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $"; -#include -#include #include "sounds.h" char MsgText[256]; @@ -67,13 +65,13 @@ void I_CreateSound(void) hret = DirectSoundCreate8(NULL, &lpDS, NULL); if (hret != DS_OK) { - printf("failed DirectSoundCreate"); + //printf("failed DirectSoundCreate"); return; } hret = lpDS->lpVtbl->SetCooperativeLevel(lpDS, win, DSSCL_PRIORITY); if (hret != DS_OK) - printf("failled DirectSound.SetCooperativeLevel"); + //printf("failled DirectSound.SetCooperativeLevel"); memset( &wfx,0, sizeof(WAVEFORMATEX) ); wfx.wFormatTag = WAVE_FORMAT_PCM; @@ -119,7 +117,7 @@ void I_SubmitSound(signed short *mixbuffer) hret=lpMix[mixbuff]->lpVtbl->Lock(lpMix[mixbuff],0,MIXBUFFERSIZE,&pPtr1, &dwSize1,&pPtr2,&dwSize2,0); if (hret!=DS_OK) - { printf("Error locking on play start"); + { //printf("Error locking on play start"); return ; } memcpy(pPtr1, (void*)mixbuffer, MIXBUFFERSIZE); diff --git a/programs/games/doom/trunk/w_wad.c b/programs/games/doom/trunk/w_wad.c index a6fc3f9635..3f49ea0291 100644 --- a/programs/games/doom/trunk/w_wad.c +++ b/programs/games/doom/trunk/w_wad.c @@ -17,7 +17,7 @@ // $Log:$ // // DESCRIPTION: -// Handles WAD file header, directory, lump I/O. +// Handles WAD file header, directory, lump I/O. // //----------------------------------------------------------------------------- @@ -40,45 +40,53 @@ rcsid[] = "$Id: w_wad.c,v 1.5 1997/02/03 16:47:57 b1 Exp $"; #include +extern char *main_file; + +#ifdef DLHEAP + +void* _cdecl dlmalloc(size_t); +void _cdecl dlfree(void*); +void _cdecl mf_init(); + +#define malloc dlmalloc +#define free dlfree +#define realloc dlrealloc + +#endif + +size_t FileSize(FILE *handle); + +int _stdcall read_file (char *name, void *buff, + size_t offset, size_t count, size_t *reads); + + + // // GLOBALS // // Location of each lump on disk. -lumpinfo_t* lumpinfo; -int numlumps; - -void** lumpcache; - - -int filelength (FILE *handle) -{ - unsigned long pos, size; - - pos = ftell(handle); - fseek(handle, 0, SEEK_END); - size = ftell(handle); - fseek(handle, pos, SEEK_SET); - return (int)size; -} +lumpinfo_t* lumpinfo; +int numlumps; +void** lumpcache; void ExtractFileBase -( char* path, - char* dest ) +( char* path, + char* dest ) { - char* src; - int length; + char* src; + int length; src = path + strlen(path) - 1; // back up until a \ or the start while (src != path - && *(src-1) != '\\' - && *(src-1) != '/') + && *(src-1) != '\\' + && *(src-1) != '/') { - src--; + src--; } // copy up to eight characters @@ -87,10 +95,10 @@ ExtractFileBase while (*src && *src != '.') { - if (++length == 9) - I_Error ("Filename base of %s >8 chars",path); + if (++length == 9) + I_Error ("Filename base of %s >8 chars",path); - *dest++ = toupper((int)*src++); + *dest++ = toupper((int)*src++); } } @@ -115,91 +123,81 @@ ExtractFileBase // specially to allow map reloads. // But: the reload feature is a fragile hack... -#ifdef __BEOS__ -#ifdef __GNUC__ -extern void *alloca(int); -#else -#include -#endif -#endif /* __BEOS__ */ -int reloadlump; -char* reloadname; +int reloadlump; +char* reloadname; void W_AddFile (char *filename) { - wadinfo_t header; - lumpinfo_t* lump_p; - unsigned i; - FILE *handle; - int length; - int startlump; - filelump_t* fileinfo; - filelump_t singleinfo; - int storehandle; + wadinfo_t header; + lumpinfo_t* lump_p; + unsigned i; + FILE *handle; + int length; + int startlump; + filelump_t* fileinfo; + filelump_t singleinfo; + int storehandle; + int err; + size_t bytes; // open the file and add to directory // handle reload indicator. if (filename[0] == '~') { - filename++; - reloadname = filename; - reloadlump = numlumps; + filename++; + reloadname = filename; + reloadlump = numlumps; } - + if ( (handle = fopen (filename,"rb")) == NULL) { - printf (" couldn't open %s\n",filename); - return; + printf (" couldn't open %s\n",filename); + return; } - printf (" adding %s\n",filename); + printf (" adding %s\n\r",filename); startlump = numlumps; - - if (I_strncasecmp (filename+strlen(filename)-3 , "wad", 3 ) ) + + if (strnicmp (filename+strlen(filename)-3 , "wad", 3 ) ) { - // single lump file - fileinfo = &singleinfo; - singleinfo.filepos = 0; - singleinfo.size = LONG(filelength(handle)); - ExtractFileBase (filename, singleinfo.name); - numlumps++; + // single lump file + fileinfo = &singleinfo; + singleinfo.filepos = 0; + singleinfo.size = FileSize(handle); + ExtractFileBase (filename, singleinfo.name); + numlumps++; } else { - //WAD file - printf("f1 at %x,%u\n",&header,handle); - fread (&header, 1, sizeof(header), handle); - printf("f2\n"); - if (strncmp(header.identification,"IWAD",4)) - { - printf("No IWAD id\n"); - // Homebrew levels? - if (strncmp(header.identification,"PWAD",4)) - { - I_Error ("Wad file %s doesn't have IWAD " - "or PWAD id\n", filename); - } -// printf("WAD magic OK\n"); - // ???modifiedgame = true; - } - printf("after checking hdr\n"); - header.numlumps = LONG(header.numlumps); - printf("%u lumps in WAD\n",header.numlumps); - header.infotableofs = LONG(header.infotableofs); - printf("infor table at %x\n",header.infotableofs); - length = header.numlumps*sizeof(filelump_t); - printf("length %u\n",length); - fileinfo = alloca(length); - - printf("seeking to info table\n"); - fseek (handle, header.infotableofs, SEEK_SET); - printf("f3\n"); - fread (fileinfo, 1, length, handle); - printf("f4\n"); - numlumps += header.numlumps; + //WAD file + fread (&header, 1, sizeof(header), handle); + + if (strncmp(header.identification,"IWAD",4)) + { + printf("No IWAD id\n"); + // Homebrew levels? + if (strncmp(header.identification,"PWAD",4)) + { + I_Error ("Wad file %s doesn't have IWAD " + "or PWAD id\n", filename); + } + printf("WAD magic OK\n"); + // ???modifiedgame = true; + } + header.numlumps = LONG(header.numlumps); + + header.infotableofs = LONG(header.infotableofs); + + length = header.numlumps*sizeof(filelump_t); + + fileinfo = alloca(length); + + fseek (handle, header.infotableofs, SEEK_SET); + fread (fileinfo, 1, length, handle); + numlumps += header.numlumps; } @@ -207,22 +205,22 @@ void W_AddFile (char *filename) lumpinfo = realloc (lumpinfo, numlumps*sizeof(lumpinfo_t)); if (!lumpinfo) - I_Error ("Couldn't realloc lumpinfo"); + I_Error ("Couldn't realloc lumpinfo"); lump_p = &lumpinfo[startlump]; - + storehandle = reloadname ? -1 : (int)handle; - + for (i=startlump ; ihandle = storehandle; - lump_p->position = LONG(fileinfo->filepos); - lump_p->size = LONG(fileinfo->size); - strncpy (lump_p->name, fileinfo->name, 8); + lump_p->handle = storehandle; + lump_p->position = LONG(fileinfo->filepos); + lump_p->size = LONG(fileinfo->size); + strncpy (lump_p->name, fileinfo->name, 8); } - + if (reloadname) - fclose (handle); + fclose (handle); } @@ -235,51 +233,46 @@ void W_AddFile (char *filename) // void W_Reload (void) { - wadinfo_t header; - int lumpcount; - lumpinfo_t* lump_p; - unsigned i; - FILE *handle; - int length; - filelump_t* fileinfo; - + wadinfo_t header; + int lumpcount; + lumpinfo_t* lump_p; + unsigned i; + FILE *handle; + int length; + filelump_t* fileinfo; + if (!reloadname) - return; - + return; + if ( (handle = fopen (reloadname,"rb")) == NULL) - I_Error ("W_Reload: couldn't open %s",reloadname); + I_Error ("W_Reload: couldn't open %s",reloadname); - printf("f5\n"); fread (&header, 1, sizeof(header), handle); - printf("f6\n"); + lumpcount = LONG(header.numlumps); header.infotableofs = LONG(header.infotableofs); length = lumpcount*sizeof(filelump_t); fileinfo = malloc (length); fseek (handle, header.infotableofs, SEEK_SET); - printf("f7\n"); fread (fileinfo, 1, length, handle); - printf("f8\n"); // Fill in lumpinfo lump_p = &lumpinfo[reloadlump]; - + for (i=reloadlump ; - iposition = LONG(fileinfo->filepos); - lump_p->size = LONG(fileinfo->size); + lump_p->position = LONG(fileinfo->filepos); + lump_p->size = LONG(fileinfo->size); } - + fclose (handle); } - - // // W_InitMultipleFiles // Pass a null terminated list of files to use. @@ -294,27 +287,27 @@ void W_Reload (void) // does override all earlier ones. // void W_InitMultipleFiles (char** filenames) -{ - int size; +{ + int size; // open all the files, load headers, and count lumps numlumps = 0; // will be realloced as lumps are added - lumpinfo = malloc(1); + lumpinfo = malloc(16384); for ( ; *filenames ; filenames++) - W_AddFile (*filenames); + W_AddFile (*filenames); if (!numlumps) - I_Error ("W_InitFiles: no files found"); + I_Error ("W_InitFiles: no files found"); // set up caching size = numlumps * sizeof(*lumpcache); lumpcache = malloc (size); if (!lumpcache) - I_Error ("Couldn't allocate lumpcache"); + I_Error ("Couldn't allocate lumpcache"); memset (lumpcache,0, size); } @@ -328,7 +321,7 @@ void W_InitMultipleFiles (char** filenames) // void W_InitFile (char* filename) { - char* names[2]; + char* names[2]; names[0] = filename; names[1] = NULL; @@ -355,14 +348,14 @@ int W_NumLumps (void) int W_CheckNumForName (char* name) { union { - char s[9]; - int x[2]; - + char s[9]; + int x[2]; + } name8; - int v1; - int v2; - lumpinfo_t* lump_p; + int v1; + int v2; + lumpinfo_t* lump_p; // make the name into two integers for easy compares strncpy (name8.s,name,8); @@ -371,7 +364,7 @@ int W_CheckNumForName (char* name) name8.s[8] = 0; // case insensitive - strupr (name8.s); + strupr (name8.s); v1 = name8.x[0]; v2 = name8.x[1]; @@ -382,11 +375,11 @@ int W_CheckNumForName (char* name) while (lump_p-- != lumpinfo) { - if ( *(int *)lump_p->name == v1 - && *(int *)&lump_p->name[4] == v2) - { - return lump_p - lumpinfo; - } + if ( *(int *)lump_p->name == v1 + && *(int *)&lump_p->name[4] == v2) + { + return lump_p - lumpinfo; + } } // TFB. Not found. @@ -402,7 +395,7 @@ int W_CheckNumForName (char* name) // int W_GetNumForName (char* name) { - int i; + int i; i = W_CheckNumForName (name); @@ -420,7 +413,7 @@ int W_GetNumForName (char* name) int W_LumpLength (int lump) { if (lump >= numlumps) - I_Error ("W_LumpLength: %i >= numlumps",lump); + I_Error ("W_LumpLength: %i >= numlumps",lump); return lumpinfo[lump].size; } @@ -434,38 +427,39 @@ int W_LumpLength (int lump) // void W_ReadLump -( int lump, - void* dest ) +( int lump, + void* dest ) { - int c; - lumpinfo_t* l; - FILE *handle; - + int c; + lumpinfo_t* l; + FILE *handle; + size_t bytes; + if (lump >= numlumps) - I_Error ("W_ReadLump: %i >= numlumps",lump); + I_Error ("W_ReadLump: %i >= numlumps",lump); l = lumpinfo+lump; - + // ??? I_BeginRead (); - + if (l->handle == -1) { - // reloadable file, so use open / read / close - if ( (handle = fopen (reloadname,"rb")) == NULL) - I_Error ("W_ReadLump: couldn't open %s",reloadname); + // reloadable file, so use open / read / close + if ( (handle = fopen (reloadname,"rb")) == NULL) + I_Error ("W_ReadLump: couldn't open %s",reloadname); } else - handle = (FILE *)l->handle; - + handle = (FILE *)l->handle; + fseek (handle, l->position, SEEK_SET); c = fread (dest, 1, l->size, handle); if (c < l->size) - I_Error ("W_ReadLump: only read %i of %i on lump %i", - c,l->size,lump); + I_Error ("W_ReadLump: only read %i of %i on lump %i", + c,l->size,lump); if (l->handle == -1) - fclose (handle); - + fclose (handle); + // ??? I_EndRead (); } @@ -477,28 +471,28 @@ W_ReadLump // void* W_CacheLumpNum -( int lump, - int tag ) +( int lump, + int tag ) { - byte* ptr; + byte* ptr; - if ((unsigned)lump >= numlumps) - I_Error ("W_CacheLumpNum: %i >= numlumps",lump); - + if ((unsigned)lump >= (unsigned)numlumps) + I_Error ("W_CacheLumpNum: %i >= numlumps",lump); + if (!lumpcache[lump]) { - // read the lump in - - //printf ("cache miss on lump %i\n",lump); - ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]); - W_ReadLump (lump, lumpcache[lump]); + // read the lump in + + //printf ("cache miss on lump %i\n",lump); + ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]); + W_ReadLump (lump, lumpcache[lump]); } else { - //printf ("cache hit on lump %i\n",lump); - Z_ChangeTag (lumpcache[lump],tag); + //printf ("cache hit on lump %i\n",lump); + Z_ChangeTag (lumpcache[lump],tag); } - + return lumpcache[lump]; } @@ -509,8 +503,8 @@ W_CacheLumpNum // void* W_CacheLumpName -( char* name, - int tag ) +( char* name, + int tag ) { return W_CacheLumpNum (W_GetNumForName(name), tag); } @@ -520,62 +514,69 @@ W_CacheLumpName // // W_Profile // -int info[2500][10]; -int profilecount; +int info[2500][10]; +int profilecount; void W_Profile (void) { - int i; - memblock_t* block; - void* ptr; - char ch; - FILE* f; - int j; - char name[9]; - - + int i; + memblock_t* block; + void* ptr; + char ch; + FILE* f; + int j; + char name[9]; + + for (i=0 ; itag < PU_PURGELEVEL) - ch = 'S'; - else - ch = 'P'; - } - info[i][profilecount] = ch; + { + ptr = lumpcache[i]; + if (!ptr) + { + ch = ' '; + continue; + } + else + { + block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t)); + if (block->tag < PU_PURGELEVEL) + ch = 'S'; + else + ch = 'P'; + } + info[i][profilecount] = ch; } profilecount++; - + f = fopen ("waddump.txt","w"); name[8] = 0; for (i=0 ; iblocklist.next = - zone->blocklist.prev = - block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) ); + zone->blocklist.prev = + block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) ); zone->blocklist.user = (void *)zone; zone->blocklist.tag = PU_STATIC; zone->rover = block; - + block->prev = block->next = &zone->blocklist; // NULL indicates a free block. - block->user = NULL; + block->user = NULL; block->size = zone->size - sizeof(memzone_t); } @@ -101,21 +101,21 @@ void Z_ClearZone (memzone_t* zone) // void Z_Init (void) { - memblock_t* block; - int size; + memblock_t* block; + int size; mainzone = (memzone_t *)I_ZoneBase (&size); mainzone->size = size; // set the entire zone to one free block mainzone->blocklist.next = - mainzone->blocklist.prev = - block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) ); + mainzone->blocklist.prev = + block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) ); mainzone->blocklist.user = (void *)mainzone; mainzone->blocklist.tag = PU_STATIC; mainzone->rover = block; - + block->prev = block->next = &mainzone->blocklist; // NULL indicates a free block. @@ -130,53 +130,53 @@ void Z_Init (void) // void Z_Free (void* ptr) { - memblock_t* block; - memblock_t* other; - + memblock_t* block; + memblock_t* other; + block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) - I_Error ("Z_Free: freed a pointer without ZONEID"); - + I_Error ("Z_Free: freed a pointer without ZONEID"); + if (block->user > (void **)0x100) { - // smaller values are not pointers - // Note: OS-dependend? - - // clear the user's mark - *block->user = 0; + // smaller values are not pointers + // Note: OS-dependend? + + // clear the user's mark + *block->user = 0; } // mark as free - block->user = NULL; + block->user = NULL; block->tag = 0; block->id = 0; - + other = block->prev; if (!other->user) { - // merge with previous free block - other->size += block->size; - other->next = block->next; - other->next->prev = other; + // merge with previous free block + other->size += block->size; + other->next = block->next; + other->next->prev = other; - if (block == mainzone->rover) - mainzone->rover = other; + if (block == mainzone->rover) + mainzone->rover = other; - block = other; + block = other; } - + other = block->next; if (!other->user) { - // merge the next free block onto the end - block->size += other->size; - block->next = other->next; - block->next->prev = block; + // merge the next free block onto the end + block->size += other->size; + block->next = other->next; + block->next->prev = block; - if (other == mainzone->rover) - mainzone->rover = block; + if (other == mainzone->rover) + mainzone->rover = block; } } @@ -186,20 +186,20 @@ void Z_Free (void* ptr) // Z_Malloc // You can pass a NULL user if the tag is < PU_PURGELEVEL. // -#define MINFRAGMENT 64 +#define MINFRAGMENT 64 void* Z_Malloc -( int size, - int tag, - void* user ) +( int size, + int tag, + void* user ) { - int extra; - memblock_t* start; + int extra; + memblock_t* start; memblock_t* rover; memblock_t* newblock; - memblock_t* base; + memblock_t* base; size = (size + 3) & ~3; @@ -216,40 +216,40 @@ Z_Malloc base = mainzone->rover; if (!base->prev->user) - base = base->prev; - + base = base->prev; + rover = base; start = base->prev; - + do { - if (rover == start) - { - // scanned all the way around the list - I_Error ("Z_Malloc: failed on allocation of %i bytes", size); - } - - if (rover->user) - { - if (rover->tag < PU_PURGELEVEL) - { - // hit a block that can't be purged, - // so move base past it - base = rover = rover->next; - } - else - { - // free the rover block (adding the size to base) + if (rover == start) + { + // scanned all the way around the list + I_Error ("Z_Malloc: failed on allocation of %i bytes", size); + } + + if (rover->user) + { + if (rover->tag < PU_PURGELEVEL) + { + // hit a block that can't be purged, + // so move base past it + base = rover = rover->next; + } + else + { + // free the rover block (adding the size to base) - // the rover can be the base block - base = base->prev; - Z_Free ((byte *)rover+sizeof(memblock_t)); - base = base->next; - rover = base->next; - } - } - else - rover = rover->next; + // the rover can be the base block + base = base->prev; + Z_Free ((byte *)rover+sizeof(memblock_t)); + base = base->next; + rover = base->next; + } + } + else + rover = rover->next; } while (base->user || base->size < size); @@ -258,40 +258,40 @@ Z_Malloc if (extra > MINFRAGMENT) { - // there will be a free fragment after the allocated block - newblock = (memblock_t *) ((byte *)base + size ); - newblock->size = extra; - - // NULL indicates free block. - newblock->user = NULL; - newblock->tag = 0; - newblock->prev = base; - newblock->next = base->next; - newblock->next->prev = newblock; + // there will be a free fragment after the allocated block + newblock = (memblock_t *) ((byte *)base + size ); + newblock->size = extra; + + // NULL indicates free block. + newblock->user = NULL; + newblock->tag = 0; + newblock->prev = base; + newblock->next = base->next; + newblock->next->prev = newblock; - base->next = newblock; - base->size = size; + base->next = newblock; + base->size = size; } - + if (user) { - // mark as an in use block - base->user = user; - *(void **)user = (void *) ((byte *)base + sizeof(memblock_t)); + // mark as an in use block + base->user = user; + *(void **)user = (void *) ((byte *)base + sizeof(memblock_t)); } else { - if (tag >= PU_PURGELEVEL) - I_Error ("Z_Malloc: an owner is required for purgable blocks"); + if (tag >= PU_PURGELEVEL) + I_Error ("Z_Malloc: an owner is required for purgable blocks"); - // mark as in use, but unowned - base->user = (void *)2; + // mark as in use, but unowned + base->user = (void *)2; } base->tag = tag; // next allocation will start looking here - mainzone->rover = base->next; - + mainzone->rover = base->next; + base->id = ZONEID; return (void *) ((byte *)base + sizeof(memblock_t)); @@ -304,25 +304,25 @@ Z_Malloc // void Z_FreeTags -( int lowtag, - int hightag ) +( int lowtag, + int hightag ) { - memblock_t* block; - memblock_t* next; - + memblock_t* block; + memblock_t* next; + for (block = mainzone->blocklist.next ; - block != &mainzone->blocklist ; - block = next) + block != &mainzone->blocklist ; + block = next) { - // get link before freeing - next = block->next; + // get link before freeing + next = block->next; - // free block? - if (!block->user) - continue; - - if (block->tag >= lowtag && block->tag <= hightag) - Z_Free ( (byte *)block+sizeof(memblock_t)); + // free block? + if (!block->user) + continue; + + if (block->tag >= lowtag && block->tag <= hightag) + Z_Free ( (byte *)block+sizeof(memblock_t)); } } @@ -334,37 +334,37 @@ Z_FreeTags // void Z_DumpHeap -( int lowtag, - int hightag ) +( int lowtag, + int hightag ) { - memblock_t* block; - - printf ("zone size: %i location: %p\n", - mainzone->size,mainzone); + memblock_t* block; + + //printf ("zone size: %i location: %p\n", +// mainzone->size,mainzone); - printf ("tag range: %i to %i\n", - lowtag, hightag); - + //printf ("tag range: %i to %i\n", +// lowtag, hightag); + for (block = mainzone->blocklist.next ; ; block = block->next) { - if (block->tag >= lowtag && block->tag <= hightag) - printf ("block:%p size:%7i user:%p tag:%3i\n", - block, block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - // all blocks have been hit - break; - } - - if ( (byte *)block + block->size != (byte *)block->next) - printf ("ERROR: block size does not touch the next block\n"); + if (block->tag >= lowtag && block->tag <= hightag) + printf ("block:%p size:%7i user:%p tag:%3i\n", + block, block->size, block->user, block->tag); + + if (block->next == &mainzone->blocklist) + { + // all blocks have been hit + break; + } + + if ( (byte *)block + block->size != (byte *)block->next) + printf ("ERROR: block size does not touch the next block\n"); - if ( block->next->prev != block) - printf ("ERROR: next block doesn't have proper back link\n"); + if ( block->next->prev != block) + printf ("ERROR: next block doesn't have proper back link\n"); - if (!block->user && !block->next->user) - printf ("ERROR: two consecutive free blocks\n"); + if (!block->user && !block->next->user) + printf ("ERROR: two consecutive free blocks\n"); } } @@ -374,29 +374,29 @@ Z_DumpHeap // void Z_FileDumpHeap (FILE* f) { - memblock_t* block; - - fprintf (f,"zone size: %i location: %p\n",mainzone->size,mainzone); - + memblock_t* block; + + //printf ("zone size: %i location: %p\n",mainzone->size,mainzone); + for (block = mainzone->blocklist.next ; ; block = block->next) { - fprintf (f,"block:%p size:%7i user:%p tag:%3i\n", - block, block->size, block->user, block->tag); - - if (block->next == &mainzone->blocklist) - { - // all blocks have been hit - break; - } - - if ( (byte *)block + block->size != (byte *)block->next) - fprintf (f,"ERROR: block size does not touch the next block\n"); + printf ("block:%p size:%7i user:%p tag:%3i\n", + block, block->size, block->user, block->tag); + + if (block->next == &mainzone->blocklist) + { + // all blocks have been hit + break; + } + + if ( (byte *)block + block->size != (byte *)block->next) + printf ("ERROR: block size does not touch the next block\n"); - if ( block->next->prev != block) - fprintf (f,"ERROR: next block doesn't have proper back link\n"); + if ( block->next->prev != block) + printf ("ERROR: next block doesn't have proper back link\n"); - if (!block->user && !block->next->user) - fprintf (f,"ERROR: two consecutive free blocks\n"); + if (!block->user && !block->next->user) + printf ("ERROR: two consecutive free blocks\n"); } } @@ -407,24 +407,24 @@ void Z_FileDumpHeap (FILE* f) // void Z_CheckHeap (void) { - memblock_t* block; - + memblock_t* block; + for (block = mainzone->blocklist.next ; ; block = block->next) { - if (block->next == &mainzone->blocklist) - { - // all blocks have been hit - break; - } - - if ( (byte *)block + block->size != (byte *)block->next) - I_Error ("Z_CheckHeap: block size does not touch the next block\n"); + if (block->next == &mainzone->blocklist) + { + // all blocks have been hit + break; + } + + if ( (byte *)block + block->size != (byte *)block->next) + I_Error ("Z_CheckHeap: block size does not touch the next block\n"); - if ( block->next->prev != block) - I_Error ("Z_CheckHeap: next block doesn't have proper back link\n"); + if ( block->next->prev != block) + I_Error ("Z_CheckHeap: next block doesn't have proper back link\n"); - if (!block->user && !block->next->user) - I_Error ("Z_CheckHeap: two consecutive free blocks\n"); + if (!block->user && !block->next->user) + I_Error ("Z_CheckHeap: two consecutive free blocks\n"); } } @@ -436,18 +436,18 @@ void Z_CheckHeap (void) // void Z_ChangeTag2 -( void* ptr, - int tag ) +( void* ptr, + int tag ) { - memblock_t* block; - + memblock_t* block; + block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) - I_Error ("Z_ChangeTag: freed a pointer without ZONEID"); + I_Error ("Z_ChangeTag: freed a pointer without ZONEID"); if (tag >= PU_PURGELEVEL && (unsigned)block->user < 0x100) - I_Error ("Z_ChangeTag: an owner is required for purgable blocks"); + I_Error ("Z_ChangeTag: an owner is required for purgable blocks"); block->tag = tag; } @@ -459,17 +459,17 @@ Z_ChangeTag2 // int Z_FreeMemory (void) { - memblock_t* block; - int free; - + memblock_t* block; + int free; + free = 0; for (block = mainzone->blocklist.next ; - block != &mainzone->blocklist; - block = block->next) + block != &mainzone->blocklist; + block = block->next) { - if (!block->user || block->tag >= PU_PURGELEVEL) - free += block->size; + if (!block->user || block->tag >= PU_PURGELEVEL) + free += block->size; } return free; }