/programs/games/doom/trunk/d_main.c |
---|
17,10 → 17,10 |
// $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. |
// |
//----------------------------------------------------------------------------- |
27,31 → 27,15 |
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 <stdio.h> |
#include <stdlib.h> |
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" |
58,7 → 42,6 |
#include "dstrings.h" |
#include "sounds.h" |
#include "z_zone.h" |
#include "w_wad.h" |
#include "s_sound.h" |
86,8 → 69,13 |
#include "r_local.h" |
#include "d_main.h" |
//#include "kolibri.h" |
extern int access(char *file, int mode); |
// |
// D-DoomLoop() |
// Not a globally visible function, |
100,41 → 88,41 |
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 |
// |
event_t events[MAXEVENTS]; |
int eventhead; |
int eventtail; |
int eventtail; |
// |
171,19 → 159,19 |
// |
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 |
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 |
// 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 |
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 |
// |
void D_PageTicker (void) |
{ |
if (--pagetic < 0) |
D_AdvanceDemo (); |
if (--pagetic < 0) |
D_AdvanceDemo (); |
} |
526,53 → 502,53 |
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 |
{ |
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 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,12 → 631,11 |
// 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); |
668,66 → 642,65 |
// 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 |
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 |
{ |
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<myargc;k++) |
// __libclog_printf("%s\n",myargv[k]); |
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<myargc;k++) |
// __libclog_printf("%s\n",myargv[k]); |
break; |
} |
break; |
} |
} |
856,101 → 829,98 |
char file[256]; |
FindResponseFile (); |
IdentifyVersion (); |
// I_BeginSplash(); |
// setbuf (stdout, NULL); |
modifiedgame = false; |
nomonsters = M_CheckParm ("-nomonsters"); |
respawnparm = M_CheckParm ("-respawn"); |
fastparm = M_CheckParm ("-fast"); |
devparm = M_CheckParm ("-devparm"); |
if (M_CheckParm ("-altdeath")) |
deathmatch = 2; |
deathmatch = 2; |
else if (M_CheckParm ("-deathmatch")) |
deathmatch = 1; |
deathmatch = 1; |
switch ( gamemode ) |
{ |
case retail: |
sprintf (title, |
" " |
"The Ultimate DOOM Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"The Ultimate DOOM Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
case shareware: |
sprintf (title, |
" " |
"DOOM Shareware Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"DOOM Shareware Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
case registered: |
sprintf (title, |
" " |
"DOOM Registered Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"DOOM Registered Startup v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
case commercial: |
sprintf (title, |
" " |
"DOOM 2: Hell on Earth v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"DOOM 2: Hell on Earth v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
/*FIXME |
case pack_plut: |
sprintf (title, |
" " |
"DOOM 2: Plutonia Experiment v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"DOOM 2: Plutonia Experiment v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
case pack_tnt: |
sprintf (title, |
" " |
"DOOM 2: TNT - Evilution v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"DOOM 2: TNT - Evilution v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
*/ |
default: |
sprintf (title, |
" " |
"Public DOOM - v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
sprintf (title, |
" " |
"Public DOOM - v%i.%i" |
" ", |
VERSION_NUM/100,VERSION_NUM%100); |
break; |
} |
// __libclog_printf ("%s\n",title); |
if (devparm) |
// __libclog_printf(D_DEVSTR); |
printf(D_DEVSTR); |
// turbo option |
if ( (p=M_CheckParm ("-turbo")) ) |
{ |
int scale = 200; |
extern int forwardmove[2]; |
extern int sidemove[2]; |
if (p<myargc-1) |
scale = atoi (myargv[p+1]); |
if (scale < 10) |
scale = 10; |
if (scale > 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<myargc-1) |
scale = atoi (myargv[p+1]); |
if (scale < 10) |
scale = 10; |
if (scale > 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 |
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,105 → 981,102 |
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 ) |
1119,52 → 1083,50 |
{ |
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 |
1171,11 → 1133,11 |
p = M_CheckParm ("-statcopy"); |
if (p && p<myargc-1) |
{ |
// for statistics driver |
extern void* statcopy; |
// for statistics driver |
extern void* statcopy; |
statcopy = (void*)atoi(myargv[p+1]); |
printf ("External statistics registered.\n"); |
statcopy = (void*)atoi(myargv[p+1]); |
//printf ("External statistics registered.\n\r"); |
} |
// start the apropriate game based on parms |
1183,42 → 1145,42 |
if (p && p < myargc-1) |
{ |
G_RecordDemo (myargv[p+1]); |
autostart = true; |
G_RecordDemo (myargv[p+1]); |
autostart = true; |
} |
p = M_CheckParm ("-playdemo"); |
if (p && p < myargc-1) |
{ |
singledemo = true; // quit after one demo |
G_DeferedPlayDemo (myargv[p+1]); |
D_DoomLoop (); // never returns |
singledemo = true; // quit after one demo |
G_DeferedPlayDemo (myargv[p+1]); |
D_DoomLoop (); // never returns |
} |
p = M_CheckParm ("-timedemo"); |
if (p && p < myargc-1) |
{ |
G_TimeDemo (myargv[p+1]); |
D_DoomLoop (); // never returns |
G_TimeDemo (myargv[p+1]); |
D_DoomLoop (); // never returns |
} |
p = M_CheckParm ("-loadgame"); |
if (p && p < myargc-1) |
{ |
if (M_CheckParm("-cdrom")) |
sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]); |
else |
sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]); |
G_LoadGame (file); |
if (M_CheckParm("-cdrom")) |
sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]); |
else |
sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]); |
G_LoadGame (file); |
} |
if ( gameaction != ga_loadgame ) |
{ |
if (autostart || netgame) |
G_InitNew (startskill, startepisode, startmap); |
else |
D_StartTitle (); // start up intro loop |
if (autostart || netgame) |
G_InitNew (startskill, startepisode, startmap); |
else |
D_StartTitle (); // start up intro loop |
} |
/programs/games/doom/trunk/d_net.c |
---|
17,8 → 17,8 |
// $Log:$ |
// |
// DESCRIPTION: |
// DOOM Network game communication and protocol, |
// all OS independend parts. |
// DOOM Network game communication and protocol, |
// all OS independend parts. |
// |
//----------------------------------------------------------------------------- |
34,15 → 34,15 |
#include "doomdef.h" |
#include "doomstat.h" |
#define NCMD_EXIT 0x80000000 |
#define NCMD_RETRANSMIT 0x40000000 |
#define NCMD_SETUP 0x20000000 |
#define NCMD_KILL 0x10000000 // kill game |
#define NCMD_CHECKSUM 0x0fffffff |
#define NCMD_EXIT 0x80000000 |
#define NCMD_RETRANSMIT 0x40000000 |
#define NCMD_SETUP 0x20000000 |
#define NCMD_KILL 0x10000000 // kill game |
#define NCMD_CHECKSUM 0x0fffffff |
doomcom_t* doomcom; |
doomdata_t* netbuffer; // points inside doomcom |
doomcom_t* doomcom; |
doomdata_t* netbuffer; // points inside doomcom |
// |
54,25 → 54,25 |
// |
// a gametic cannot be run until nettics[] > 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); |
79,8 → 79,8 |
void G_BuildTiccmd (ticcmd_t *cmd); |
void D_DoAdvanceDemo (void); |
boolean reboundpacket; |
doomdata_t reboundstore; |
boolean reboundpacket; |
doomdata_t reboundstore; |
97,19 → 97,19 |
// |
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 ; i<l ; i++) |
c += ((unsigned *)&netbuffer->retransmitfrom)[i] * (i+1); |
c += ((unsigned *)&netbuffer->retransmitfrom)[i] * (i+1); |
return c & NCMD_CHECKSUM; |
} |
119,17 → 119,17 |
// |
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 |
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 ; i<doomcom->datalength ; i++) |
printf ("%i ",((byte *)netbuffer)[i]); |
printf ("send (%i + %i, R %i) [%i] ", |
ExpandTics(netbuffer->starttic), |
netbuffer->numtics, realretrans, doomcom->datalength); |
for (i=0 ; i<doomcom->datalength ; i++) |
printf ("%i ",((byte *)netbuffer)[i]); |
printf ("\n"); |
printf ("\n"); |
} |
I_NetCmd (); |
187,66 → 187,66 |
// 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 ; i<doomcom->datalength ; i++) |
printf ("%i ",((byte *)netbuffer)[i]); |
printf ("\n"); |
} |
for (i=0 ; i<doomcom->datalength ; i++) |
printf ("%i ",((byte *)netbuffer)[i]); |
printf ("\n"); |
} |
} |
return true; |
return true; |
} |
257,98 → 257,98 |
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"); |
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; |
} |
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 |
// update command store from the packet |
{ |
int start; |
int start; |
remoteresend[netnode] = false; |
start = nettics[netnode] - realstart; |
src = &netbuffer->cmds[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++; |
} |
} |
while (nettics[netnode] < realend) |
{ |
dest = &netcmds[netconsole][nettics[netnode]%BACKUPTICS]; |
nettics[netnode]++; |
*dest = *src; |
src++; |
} |
} |
} |
} |
364,30 → 364,30 |
{ |
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 |
394,46 → 394,46 |
gameticdiv = gametic/ticdup; |
for (i=0 ; i<newtics ; i++) |
{ |
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++; |
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 ; i<doomcom->numnodes ; 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 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 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 ; i<doomcom->numnodes ; 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 ; i<doomcom->numnodes ; 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 ; i<doomcom->numnodes ; i++) |
if (!gotinfo[i]) |
break; |
} while (i < doomcom->numnodes); |
for (i=1 ; i<doomcom->numnodes ; i++) |
if (!gotinfo[i]) |
break; |
} while (i < doomcom->numnodes); |
} |
} |
545,46 → 545,46 |
// 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 ; i<MAXNETNODES ; i++) |
{ |
nodeingame[i] = false; |
nettics[i] = 0; |
remoteresend[i] = false; // set when local needs tics |
resendto[i] = 0; // which tic to start sending |
nodeingame[i] = false; |
nettics[i] = 0; |
remoteresend[i] = false; // set when local needs tics |
resendto[i] = 0; // which tic to start sending |
} |
// I_InitNetwork sets doomcom and netgame |
I_InitNetwork (); |
if (doomcom->id != 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 ; i<doomcom->numplayers ; i++) |
playeringame[i] = true; |
playeringame[i] = true; |
for (i=0 ; i<doomcom->numnodes ; 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_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 ; j<doomcom->numnodes ; j++) |
if (nodeingame[j]) |
HSendPacket (j, NCMD_EXIT); |
I_WaitVBL (1); |
for (j=1 ; j<doomcom->numnodes ; j++) |
if (nodeingame[j]) |
HSendPacket (j, NCMD_EXIT); |
I_WaitVBL (1); |
} |
} |
621,25 → 621,25 |
// |
// 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; |
646,117 → 646,116 |
// get available tics |
NetUpdate (); |
lowtic = MAXINT; |
numplaying = 0; |
for (i=0 ; i<doomcom->numnodes ; 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<MAXPLAYERS ; i++) |
if (playeringame[i]) |
break; |
if (consoleplayer == i) |
{ |
// the key player does not adapt |
} |
else |
{ |
if (nettics[0] <= nettics[nodeforplayer[i]]) |
{ |
gametime--; |
// printf ("-"); |
} |
frameskip[frameon&3] = (oldnettics > 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<MAXPLAYERS ; i++) |
if (playeringame[i]) |
break; |
if (consoleplayer == i) |
{ |
// the key player does not adapt |
} |
else |
{ |
if (nettics[0] <= nettics[nodeforplayer[i]]) |
{ |
gametime--; |
// printf ("-"); |
} |
frameskip[frameon&3] = (oldnettics > 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 ; i<doomcom->numnodes ; 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 ; i<doomcom->numnodes ; 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<ticdup ; i++) |
{ |
if (gametic/ticdup > 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 ; j<MAXPLAYERS ; j++) |
{ |
cmd = &netcmds[j][buf]; |
cmd->chatchar = 0; |
if (cmd->buttons & BT_SPECIAL) |
cmd->buttons = 0; |
} |
} |
} |
NetUpdate (); // check for new console commands |
for (i=0 ; i<ticdup ; i++) |
{ |
if (gametic/ticdup > 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 ; j<MAXPLAYERS ; j++) |
{ |
cmd = &netcmds[j][buf]; |
cmd->chatchar = 0; |
if (cmd->buttons & BT_SPECIAL) |
cmd->buttons = 0; |
} |
} |
} |
NetUpdate (); // check for new console commands |
} |
} |
/programs/games/doom/trunk/f_finale.c |
---|
28,8 → 28,8 |
#include <ctype.h> |
// Functions. |
#include "i_system.h" |
#include "m_swap.h" |
#include "i_system.h" |
#include "z_zone.h" |
#include "v_video.h" |
#include "w_wad.h" |
/programs/games/doom/trunk/g_game.c |
---|
71,49 → 71,49 |
#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,19 → 127,19 |
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; |
// |
146,16 → 146,16 |
// 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 |
#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,26 → 236,26 |
// |
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; |
262,177 → 262,177 |
// 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 ; i<NUMWEAPONS-1 ; i++) |
if (gamekeydown['1'+i]) |
{ |
cmd->buttons |= BT_CHANGE; |
cmd->buttons |= i<<BT_WEAPONSHIFT; |
break; |
} |
if (gamekeydown['1'+i]) |
{ |
cmd->buttons |= BT_CHANGE; |
cmd->buttons |= i<<BT_WEAPONSHIFT; |
break; |
} |
// mouse |
if (mousebuttons[mousebforward]) |
forward += forwardmove[speed]; |
forward += forwardmove[speed]; |
// forward double click |
if (mousebuttons[mousebforward] != dclickstate && dclicktime > 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<<BTS_SAVESHIFT); |
sendsave = false; |
cmd->buttons = BT_SPECIAL | BTS_SAVEGAME | (savegameslot<<BTS_SAVESHIFT); |
} |
} |
456,33 → 456,33 |
// DOOM determines the sky texture to be used |
// depending on the current episode, and the game version. |
if ( (gamemode == commercial) |
|| ( gamemode == pack_tnt ) |
|| ( gamemode == pack_plut ) ) |
|| ( gamemode == pack_tnt ) |
|| ( gamemode == pack_plut ) ) |
{ |
skytexture = R_TextureNumForName ("SKY3"); |
if (gamemap < 12) |
skytexture = R_TextureNumForName ("SKY1"); |
else |
if (gamemap < 21) |
skytexture = R_TextureNumForName ("SKY2"); |
skytexture = R_TextureNumForName ("SKY3"); |
if (gamemap < 12) |
skytexture = R_TextureNumForName ("SKY1"); |
else |
if (gamemap < 21) |
skytexture = R_TextureNumForName ("SKY2"); |
} |
levelstarttic = gametic; // for time calculation |
if (wipegamestate == GS_LEVEL) |
wipegamestate = -1; // force a wipe |
wipegamestate = -1; // force a wipe |
gamestate = GS_LEVEL; |
for (i=0 ; i<MAXPLAYERS ; i++) |
{ |
if (playeringame[i] && players[i].playerstate == PST_DEAD) |
players[i].playerstate = PST_REBORN; |
memset (players[i].frags,0,sizeof(players[i].frags)); |
if (playeringame[i] && players[i].playerstate == PST_DEAD) |
players[i].playerstate = PST_REBORN; |
memset (players[i].frags,0,sizeof(players[i].frags)); |
} |
P_SetupLevel (gameepisode, gamemap, 0, gameskill); |
displayplayer = consoleplayer; // view the guy you are playing |
displayplayer = consoleplayer; // view the guy you are playing |
starttime = I_GetTime (); |
gameaction = ga_nothing; |
Z_CheckHeap (); |
505,92 → 505,92 |
{ |
// allow spy mode changes even during the demo |
if (gamestate == GS_LEVEL && ev->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 <NUMKEYS) |
gamekeydown[ev->data1] = true; |
return true; // eat key down events |
if (ev->data1 == KEY_PAUSE) |
{ |
sendpause = true; |
return true; |
} |
if (ev->data1 <NUMKEYS) |
gamekeydown[ev->data1] = true; |
return true; // eat key down events |
case ev_keyup: |
if (ev->data1 <NUMKEYS) |
gamekeydown[ev->data1] = false; |
return false; // always let key up events filter down |
if (ev->data1 <NUMKEYS) |
gamekeydown[ev->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 |
// |
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 ; i<MAXPLAYERS ; i++) |
if (playeringame[i] && players[i].playerstate == PST_REBORN) |
G_DoReborn (i); |
if (playeringame[i] && players[i].playerstate == PST_REBORN) |
G_DoReborn (i); |
// do things to change the game state |
while (gameaction != ga_nothing) |
{ |
switch (gameaction) |
{ |
case ga_loadlevel: |
G_DoLoadLevel (); |
break; |
case ga_newgame: |
G_DoNewGame (); |
break; |
case ga_loadgame: |
G_DoLoadGame (); |
break; |
case ga_savegame: |
G_DoSaveGame (); |
break; |
case ga_playdemo: |
G_DoPlayDemo (); |
break; |
case ga_completed: |
G_DoCompleted (); |
break; |
case ga_victory: |
F_StartFinale (); |
break; |
case ga_worlddone: |
G_DoWorldDone (); |
break; |
case ga_screenshot: |
M_ScreenShot (); |
gameaction = ga_nothing; |
break; |
case ga_nothing: |
break; |
} |
switch (gameaction) |
{ |
case ga_loadlevel: |
G_DoLoadLevel (); |
break; |
case ga_newgame: |
G_DoNewGame (); |
break; |
case ga_loadgame: |
G_DoLoadGame (); |
break; |
case ga_savegame: |
G_DoSaveGame (); |
break; |
case ga_playdemo: |
G_DoPlayDemo (); |
break; |
case ga_completed: |
G_DoCompleted (); |
break; |
case ga_victory: |
F_StartFinale (); |
break; |
case ga_worlddone: |
G_DoWorldDone (); |
break; |
case ga_screenshot: |
M_ScreenShot (); |
gameaction = ga_nothing; |
break; |
case ga_nothing: |
break; |
} |
} |
// get commands, check consistancy, |
657,70 → 657,70 |
for (i=0 ; i<MAXPLAYERS ; i++) |
{ |
if (playeringame[i]) |
{ |
cmd = &players[i].cmd; |
if (playeringame[i]) |
{ |
cmd = &players[i].cmd; |
memcpy (cmd, &netcmds[i][buf], sizeof(ticcmd_t)); |
memcpy (cmd, &netcmds[i][buf], sizeof(ticcmd_t)); |
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; |
} |
} |
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<MAXPLAYERS ; i++) |
{ |
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; |
} |
} |
} |
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 |
727,23 → 727,23 |
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_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_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_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,7 → 819,7 |
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; |
826,10 → 826,10 |
p->weaponowned[wp_fist] = true; |
p->weaponowned[wp_pistol] = true; |
p->ammo[am_clip] = 50; |
for (i=0 ; i<NUMAMMO ; i++) |
p->maxammo[i] = maxammo[i]; |
p->maxammo[i] = maxammo[i]; |
} |
// |
842,48 → 842,48 |
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 ; i<playernum ; i++) |
if (players[i].mo->x == mthing->x << FRACBITS |
&& players[i].mo->y == mthing->y << FRACBITS) |
return false; |
return true; |
// first spawn of level, before corpses |
for (i=0 ; i<playernum ; i++) |
if (players[i].mo->x == 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 |
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_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 ; i<MAXPLAYERS ; i++) |
{ |
if (G_CheckSpot (playernum, &playerstarts[i]) ) |
{ |
playerstarts[i].type = playernum+1; // fake as other player |
P_SpawnPlayer (&playerstarts[i]); |
playerstarts[i].type = i+1; // restore |
return; |
} |
// he's going to be inside something. Too bad. |
} |
P_SpawnPlayer (&playerstarts[playernum]); |
// 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 ; i<MAXPLAYERS ; i++) |
{ |
if (G_CheckSpot (playernum, &playerstarts[i]) ) |
{ |
playerstarts[i].type = playernum+1; // fake as other player |
P_SpawnPlayer (&playerstarts[i]); |
playerstarts[i].type = i+1; // restore |
return; |
} |
// he's going to be inside something. Too bad. |
} |
P_SpawnPlayer (&playerstarts[playernum]); |
} |
} |
986,10 → 986,10 |
// DOOM II Par Times |
int cpars[32] = |
{ |
30,90,120,120,90,150,120,120,270,90, // 1-10 |
210,150,150,150,210,150,420,150,210,150, // 11-20 |
240,150,180,150,150,300,330,420,300,180, // 21-30 |
120,30 // 31-32 |
30,90,120,120,90,150,120,120,270,90, // 1-10 |
210,150,150,150,210,150,420,150,210,150, // 11-20 |
240,150,180,150,150,300,330,420,300,180, // 21-30 |
120,30 // 31-32 |
}; |
996,8 → 996,8 |
// |
// G_DoCompleted |
// |
boolean secretexit; |
extern char* pagename; |
boolean secretexit; |
extern char* pagename; |
void G_ExitLevel (void) |
{ |
1011,9 → 1011,9 |
// IF NO WOLF3D LEVELS, NO SECRET EXIT! |
if ( (gamemode == commercial) |
&& (W_CheckNumForName("map31")<0)) |
secretexit = false; |
secretexit = false; |
else |
secretexit = true; |
secretexit = true; |
gameaction = ga_completed; |
} |
1020,47 → 1020,47 |
void G_DoCompleted (void) |
{ |
int i; |
gameaction = ga_nothing; |
for (i=0 ; i<MAXPLAYERS ; i++) |
if (playeringame[i]) |
G_PlayerFinishLevel (i); // take away cards and stuff |
if (playeringame[i]) |
G_PlayerFinishLevel (i); // take away cards and stuff |
if (automapactive) |
AM_Stop (); |
AM_Stop (); |
if ( gamemode != commercial) |
switch(gamemap) |
{ |
case 8: |
gameaction = ga_victory; |
return; |
case 9: |
for (i=0 ; i<MAXPLAYERS ; i++) |
players[i].didsecret = true; |
break; |
} |
switch(gamemap) |
{ |
case 8: |
gameaction = ga_victory; |
return; |
case 9: |
for (i=0 ; i<MAXPLAYERS ; i++) |
players[i].didsecret = true; |
break; |
} |
//#if 0 Hmmm - why? |
if ( (gamemap == 8) |
&& (gamemode != commercial) ) |
&& (gamemode != commercial) ) |
{ |
// victory |
gameaction = ga_victory; |
return; |
// victory |
gameaction = ga_victory; |
return; |
} |
if ( (gamemap == 9) |
&& (gamemode != commercial) ) |
&& (gamemode != commercial) ) |
{ |
// exit secret level |
for (i=0 ; i<MAXPLAYERS ; i++) |
players[i].didsecret = true; |
// exit secret level |
for (i=0 ; i<MAXPLAYERS ; i++) |
players[i].didsecret = true; |
} |
//#endif |
wminfo.didsecret = players[consoleplayer].didsecret; |
wminfo.epsd = gameepisode -1; |
wminfo.last = gamemap -1; |
1068,66 → 1068,66 |
// wminfo.next is 0 biased, unlike gamemap |
if ( gamemode == commercial) |
{ |
if (secretexit) |
switch(gamemap) |
{ |
case 15: wminfo.next = 30; break; |
case 31: wminfo.next = 31; break; |
} |
else |
switch(gamemap) |
{ |
case 31: |
case 32: wminfo.next = 15; break; |
default: wminfo.next = gamemap; |
} |
if (secretexit) |
switch(gamemap) |
{ |
case 15: wminfo.next = 30; break; |
case 31: wminfo.next = 31; break; |
} |
else |
switch(gamemap) |
{ |
case 31: |
case 32: wminfo.next = 15; break; |
default: wminfo.next = gamemap; |
} |
} |
else |
{ |
if (secretexit) |
wminfo.next = 8; // go to secret level |
else if (gamemap == 9) |
{ |
// returning from secret level |
switch (gameepisode) |
{ |
case 1: |
wminfo.next = 3; |
break; |
case 2: |
wminfo.next = 5; |
break; |
case 3: |
wminfo.next = 6; |
break; |
case 4: |
wminfo.next = 2; |
break; |
} |
} |
else |
wminfo.next = gamemap; // go to next level |
if (secretexit) |
wminfo.next = 8; // go to secret level |
else if (gamemap == 9) |
{ |
// returning from secret level |
switch (gameepisode) |
{ |
case 1: |
wminfo.next = 3; |
break; |
case 2: |
wminfo.next = 5; |
break; |
case 3: |
wminfo.next = 6; |
break; |
case 4: |
wminfo.next = 2; |
break; |
} |
} |
else |
wminfo.next = gamemap; // go to next level |
} |
wminfo.maxkills = totalkills; |
wminfo.maxitems = totalitems; |
wminfo.maxsecret = totalsecret; |
wminfo.maxfrags = 0; |
if ( gamemode == commercial ) |
wminfo.partime = 35*cpars[gamemap-1]; |
wminfo.partime = 35*cpars[gamemap-1]; |
else |
wminfo.partime = 35*pars[gameepisode][gamemap]; |
wminfo.partime = 35*pars[gameepisode][gamemap]; |
wminfo.pnum = consoleplayer; |
for (i=0 ; i<MAXPLAYERS ; i++) |
{ |
wminfo.plyr[i].in = playeringame[i]; |
wminfo.plyr[i].skills = players[i].killcount; |
wminfo.plyr[i].sitems = players[i].itemcount; |
wminfo.plyr[i].ssecret = players[i].secretcount; |
wminfo.plyr[i].stime = leveltime; |
memcpy (wminfo.plyr[i].frags, players[i].frags |
, sizeof(wminfo.plyr[i].frags)); |
wminfo.plyr[i].in = playeringame[i]; |
wminfo.plyr[i].skills = players[i].killcount; |
wminfo.plyr[i].sitems = players[i].itemcount; |
wminfo.plyr[i].ssecret = players[i].secretcount; |
wminfo.plyr[i].stime = leveltime; |
memcpy (wminfo.plyr[i].frags, players[i].frags |
, sizeof(wminfo.plyr[i].frags)); |
} |
gamestate = GS_INTERMISSION; |
1135,8 → 1135,8 |
automapactive = false; |
if (statcopy) |
memcpy (statcopy, &wminfo, sizeof(wminfo)); |
memcpy (statcopy, &wminfo, sizeof(wminfo)); |
WI_Start (&wminfo); |
} |
1149,23 → 1149,23 |
gameaction = ga_worlddone; |
if (secretexit) |
players[consoleplayer].didsecret = true; |
players[consoleplayer].didsecret = true; |
if ( gamemode == commercial ) |
{ |
switch (gamemap) |
{ |
case 15: |
case 31: |
if (!secretexit) |
break; |
case 6: |
case 11: |
case 20: |
case 30: |
F_StartFinale (); |
break; |
} |
switch (gamemap) |
{ |
case 15: |
case 31: |
if (!secretexit) |
break; |
case 6: |
case 11: |
case 20: |
case 30: |
F_StartFinale (); |
break; |
} |
} |
} |
1187,7 → 1187,7 |
extern boolean setsizeneeded; |
void R_ExecuteSetViewSize (void); |
char savename[256]; |
char savename[256]; |
void G_LoadGame (char* name) |
{ |
1195,18 → 1195,18 |
gameaction = ga_loadgame; |
} |
#define VERSIONSIZE 16 |
#define VERSIONSIZE 16 |
void G_DoLoadGame (void) |
{ |
int length; |
int i; |
int a,b,c; |
char vcheck[VERSIONSIZE]; |
int length; |
int i; |
int a,b,c; |
char vcheck[VERSIONSIZE]; |
gameaction = ga_nothing; |
length = M_ReadFile (savename, &savebuffer); |
save_p = savebuffer + SAVESTRINGSIZE; |
1214,14 → 1214,14 |
memset (vcheck,0,sizeof(vcheck)); |
sprintf (vcheck,"version %i",VERSION_NUM); |
if (strcmp ((char *)save_p, vcheck)) |
return; // bad version |
return; // bad version |
save_p += VERSIONSIZE; |
gameskill = *save_p++; |
gameepisode = *save_p++; |
gamemap = *save_p++; |
for (i=0 ; i<MAXPLAYERS ; i++) |
playeringame[i] = *save_p++; |
playeringame[i] = *save_p++; |
// load a base level |
G_InitNew (gameskill, gameepisode, gamemap); |
1231,7 → 1231,7 |
b = *save_p++; |
c = *save_p++; |
leveltime = (a<<16) + (b<<8) + c; |
// dearchive all the modifications |
P_UnArchivePlayers (); |
P_UnArchiveWorld (); |
1239,13 → 1239,13 |
P_UnArchiveSpecials (); |
if (*save_p != 0x1d) |
I_Error ("Bad savegame"); |
I_Error ("Bad savegame"); |
// done |
Z_Free (savebuffer); |
if (setsizeneeded) |
R_ExecuteSetViewSize (); |
R_ExecuteSetViewSize (); |
// draw the pattern into the back screen |
R_FillBackScreen (); |
1259,8 → 1259,8 |
// |
void |
G_SaveGame |
( int slot, |
char* description ) |
( int slot, |
char* description ) |
{ |
savegameslot = slot; |
strcpy (savedescription, description); |
1269,17 → 1269,17 |
void G_DoSaveGame (void) |
{ |
char name[100]; |
char name2[VERSIONSIZE]; |
char* description; |
int length; |
int i; |
char name[100]; |
char name2[VERSIONSIZE]; |
char* description; |
int length; |
int i; |
sprintf (name,"%d.dsg",savegameslot); |
description = savedescription; |
save_p = savebuffer = screens[1]+0x4000; |
memcpy (save_p, description, SAVESTRINGSIZE); |
save_p += SAVESTRINGSIZE; |
memset (name2,0,sizeof(name2)); |
1286,12 → 1286,12 |
sprintf (name2,"version %i",VERSION_NUM); |
memcpy (save_p, name2, VERSIONSIZE); |
save_p += VERSIONSIZE; |
*save_p++ = gameskill; |
*save_p++ = gameepisode; |
*save_p++ = gamemap; |
for (i=0 ; i<MAXPLAYERS ; i++) |
*save_p++ = playeringame[i]; |
*save_p++ = playeringame[i]; |
*save_p++ = leveltime>>16; |
*save_p++ = leveltime>>8; |
*save_p++ = leveltime; |
1300,20 → 1300,20 |
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 |
// 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 |
} |
// 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 |
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 ; i<MAXPLAYERS ; i++) |
players[i].playerstate = PST_REBORN; |
players[i].playerstate = PST_REBORN; |
usergame = true; // will be set false if a demo |
paused = false; |
1451,29 → 1451,29 |
// set the sky map for the episode |
if ( gamemode == commercial) |
{ |
skytexture = R_TextureNumForName ("SKY3"); |
if (gamemap < 12) |
skytexture = R_TextureNumForName ("SKY1"); |
else |
if (gamemap < 21) |
skytexture = R_TextureNumForName ("SKY2"); |
skytexture = R_TextureNumForName ("SKY3"); |
if (gamemap < 12) |
skytexture = R_TextureNumForName ("SKY1"); |
else |
if (gamemap < 21) |
skytexture = R_TextureNumForName ("SKY2"); |
} |
else |
switch (episode) |
{ |
case 1: |
skytexture = R_TextureNumForName ("SKY1"); |
break; |
case 2: |
skytexture = R_TextureNumForName ("SKY2"); |
break; |
case 3: |
skytexture = R_TextureNumForName ("SKY3"); |
break; |
case 4: // Special Edition sky |
skytexture = R_TextureNumForName ("SKY4"); |
break; |
} |
switch (episode) |
{ |
case 1: |
skytexture = R_TextureNumForName ("SKY1"); |
break; |
case 2: |
skytexture = R_TextureNumForName ("SKY2"); |
break; |
case 3: |
skytexture = R_TextureNumForName ("SKY3"); |
break; |
case 4: // Special Edition sky |
skytexture = R_TextureNumForName ("SKY4"); |
break; |
} |
G_DoLoadLevel (); |
} |
1482,7 → 1482,7 |
// |
// DEMO RECORDING |
// |
#define DEMOMARKER 0x80 |
#define DEMOMARKER 0x80 |
void G_ReadDemoTiccmd (ticcmd_t* cmd) |
1489,9 → 1489,9 |
{ |
if (*demo_p == DEMOMARKER) |
{ |
// end of demo data stream |
G_CheckDemoStatus (); |
return; |
// end of demo data stream |
G_CheckDemoStatus (); |
return; |
} |
cmd->forwardmove = ((signed char)*demo_p++); |
cmd->sidemove = ((signed char)*demo_p++); |
1503,7 → 1503,7 |
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 |
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,8 → 1527,8 |
void G_RecordDemo (char* name) |
{ |
int i; |
int maxsize; |
int maxsize; |
usergame = false; |
strcpy (demoname, name); |
strcat (demoname, ".lmp"); |
1535,10 → 1535,10 |
maxsize = 0x20000; |
i = M_CheckParm ("-maxdemo"); |
if (i && i<myargc-1) |
maxsize = atoi(myargv[i+1])*1024; |
maxsize = atoi(myargv[i+1])*1024; |
demobuffer = Z_Malloc (maxsize,PU_STATIC,NULL); |
demoend = demobuffer + maxsize; |
demorecording = true; |
} |
1546,9 → 1546,9 |
void G_BeginRecording (void) |
{ |
int i; |
demo_p = demobuffer; |
*demo_p++ = VERSION_NUM; |
*demo_p++ = gameskill; |
*demo_p++ = gameepisode; |
1558,9 → 1558,9 |
*demo_p++ = fastparm; |
*demo_p++ = nomonsters; |
*demo_p++ = consoleplayer; |
for (i=0 ; i<MAXPLAYERS ; i++) |
*demo_p++ = playeringame[i]; |
*demo_p++ = playeringame[i]; |
} |
1568,7 → 1568,7 |
// G_PlayDemo |
// |
char* defdemoname; |
char* defdemoname; |
void G_DeferedPlayDemo (char* name) |
{ |
1580,7 → 1580,7 |
{ |
skill_t skill; |
int i, episode, map; |
gameaction = ga_nothing; |
demobuffer = demo_p = W_CacheLumpName (defdemoname, PU_STATIC); |
if ( *demo_p++ != VERSION_NUM) |
1597,13 → 1597,13 |
fastparm = *demo_p++; |
nomonsters = *demo_p++; |
consoleplayer = *demo_p++; |
for (i=0 ; i<MAXPLAYERS ; i++) |
playeringame[i] = *demo_p++; |
playeringame[i] = *demo_p++; |
if (playeringame[1]) |
{ |
netgame = true; |
netdemo = true; |
netgame = true; |
netdemo = true; |
} |
// don't spend a lot of time in loadlevel |
1619,7 → 1619,7 |
// G_TimeDemo |
// |
void G_TimeDemo (char* name) |
{ |
{ |
nodrawers = M_CheckParm ("-nodraw"); |
noblit = M_CheckParm ("-noblit"); |
timingdemo = true; |
1643,42 → 1643,42 |
boolean G_CheckDemoStatus (void) |
{ |
int endtime; |
if (timingdemo) |
{ |
endtime = I_GetTime (); |
I_Error ("timed %i gametics in %i realtics",gametic |
, endtime-starttime); |
endtime = I_GetTime (); |
I_Error ("timed %i gametics in %i realtics",gametic |
, endtime-starttime); |
} |
if (demoplayback) |
{ |
/* if (singledemo) |
I_Quit (); */ |
Z_ChangeTag (demobuffer, PU_CACHE); |
demoplayback = false; |
netdemo = false; |
netgame = false; |
deathmatch = false; |
playeringame[1] = playeringame[2] = playeringame[3] = 0; |
respawnparm = false; |
fastparm = false; |
nomonsters = false; |
consoleplayer = 0; |
D_AdvanceDemo (); |
return true; |
/* if (singledemo) |
I_Quit (); */ |
Z_ChangeTag (demobuffer, PU_CACHE); |
demoplayback = false; |
netdemo = false; |
netgame = false; |
deathmatch = false; |
playeringame[1] = playeringame[2] = playeringame[3] = 0; |
respawnparm = false; |
fastparm = false; |
nomonsters = false; |
consoleplayer = 0; |
D_AdvanceDemo (); |
return true; |
} |
if (demorecording) |
{ |
*demo_p++ = DEMOMARKER; |
M_WriteFile (demoname, demobuffer, demo_p - demobuffer); |
Z_Free (demobuffer); |
demorecording = false; |
I_Error ("Demo %s recorded",demoname); |
*demo_p++ = DEMOMARKER; |
M_WriteFile (demoname, demobuffer, demo_p - demobuffer); |
Z_Free (demobuffer); |
demorecording = false; |
I_Error ("Demo %s recorded",demoname); |
} |
return false; |
} |
/programs/games/doom/trunk/hu_lib.c |
---|
25,11 → 25,10 |
#include <ctype.h> |
#include "m_swap.h" |
#include "doomdef.h" |
#include "v_video.h" |
#include "m_swap.h" |
#include "hu_lib.h" |
#include "r_local.h" |
/programs/games/doom/trunk/i_main.c |
---|
17,7 → 17,7 |
// $Log:$ |
// |
// DESCRIPTION: |
// Main program, simply calls D_DoomMain high level loop. |
// Main program, simply calls D_DoomMain high level loop. |
// |
//----------------------------------------------------------------------------- |
24,25 → 24,33 |
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; |
/programs/games/doom/trunk/i_net.c |
---|
1,3 → 1,4 |
#include <stdlib.h> |
#include <string.h> |
#include <stdio.h> |
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 |
// |
#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 |
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 |
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 |
// |
// 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 |
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 && p<myargc-1) |
{ |
DOOMPORT = atoi (myargv[p+1]); |
// __libclog_printf ("using alternate port %i\n",DOOMPORT); |
DOOMPORT = atoi (myargv[p+1]); |
// __libclog_printf ("using alternate port %i\n",DOOMPORT); |
} |
// parse network game options, |
198,13 → 218,13 |
if (!i) |
{ |
// single player game |
netgame = false; |
doomcom->id = 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 |
// 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 |
// __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); |
} |
/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 |
// 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 |
// 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 |
// 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 |
// 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<NUM_CHANNELS ; i++) |
{ |
// Active, and using the same SFX? |
if ( (channels[i]) |
&& (channelids[i] == sfxid) ) |
{ |
// Reset. |
channels[i] = 0; |
// We are sure that iff, |
// there will only be one. |
break; |
} |
} |
// Loop all channels, check. |
for (i=0 ; i<NUM_CHANNELS ; i++) |
{ |
// Active, and using the same SFX? |
if ( (channels[i]) |
&& (channelids[i] == sfxid) ) |
{ |
// Reset. |
channels[i] = 0; |
// We are sure that iff, |
// there will only be one. |
break; |
} |
} |
} |
// Loop all channels to find oldest SFX. |
for (i=0; (i<NUM_CHANNELS) && (channels[i]); i++) |
{ |
if (channelstart[i] < oldest) |
{ |
oldestnum = i; |
oldest = channelstart[i]; |
} |
if (channelstart[i] < oldest) |
{ |
oldestnum = i; |
oldest = channelstart[i]; |
} |
} |
// Tales from the cryptic. |
248,9 → 248,9 |
// If not, we simply overwrite the first one, 0. |
// Probably only happens at startup. |
if (i == NUM_CHANNELS) |
slot = oldestnum; |
slot = oldestnum; |
else |
slot = i; |
slot = i; |
// Okay, in the less recent channel, |
// we will handle the new SFX. |
261,7 → 261,7 |
// Reset current handle number, limited to 0..100. |
if (!handlenums) |
handlenums = 100; |
handlenums = 100; |
// Assign current handle number. |
// Preserved so sounds could be stopped (unused). |
282,17 → 282,17 |
// x^2 seperation, |
// adjust volume properly. |
leftvol = |
volume - ((volume*seperation*seperation) >> 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 |
// 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<NUM_CHANNELS; i++) |
332,8 → 332,8 |
channels[i] = 0; |
} |
for (i=-128 ; i<128 ; i++) |
steptablemid[i] = (int)(pow(2.0, (i/64.0))*65536.0); |
// for (i=-128 ; i<128 ; i++) |
// steptablemid[i] = (int)(pow(2.0, (i/64.0))*65536.0); |
// Generates volume lookup tables |
// which also turn the unsigned samples |
341,7 → 341,7 |
for (i=0 ; i<128 ; i++) |
for (j=0 ; j<256 ; j++) |
vol_lookup[i*256+j] = (i*(j-128)*256)/127; |
} |
} |
void I_SetSfxVolume(int volume) |
428,19 → 428,19 |
// Mix current sound data. |
// Data, from raw sound, for right and left. |
register unsigned int sample; |
register int dl; |
register int dr; |
register unsigned int sample; |
register int dl; |
register int dr; |
// Pointers in global mixbuffer, left, right, end. |
signed short* leftout; |
signed short* rightout; |
signed short* leftend; |
signed short* leftout; |
signed short* rightout; |
signed short* leftend; |
// Step in mixbuffer, left and right, thus two. |
int step; |
int step; |
// Mixing channel index. |
int chan; |
int chan; |
// Left and right channel |
// are in global mixbuffer, alternating. |
457,65 → 457,65 |
// that is 512 values for two channels. |
while (leftout != leftend) |
{ |
// Reset left/right value. |
dl = 0; |
dr = 0; |
// Reset left/right value. |
dl = 0; |
dr = 0; |
// 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; |
// 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 |
{ |
// Load data from WAD file. |
S_sfx[i].data = getsfx( S_sfx[i].name, &lengths[i] ); |
} |
} |
else |
{ |
// Previously loaded already? |
603,11 → 603,11 |
// 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) |
{ |
/programs/games/doom/trunk/i_system.c |
---|
26,8 → 26,6 |
#include <stdlib.h> |
#include <stdarg.h> |
#include <ctype.h> |
//#include "SDL.h" |
//#include "SDL_timer.h" |
#include "doomdef.h" |
#include "m_misc.h" |
39,36 → 37,23 |
#include "i_system.h" |
#include "kolibri.h" |
int mb_used = 6; |
int mb_used = 8; |
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); |
} |
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 |
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,22 → 76,18 |
// 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 |
// }; |
_asm |
{ push ebx |
mov eax, 26 |
mov ebx, 9 |
int 0x40 |
mov dword ptr [tm], eax |
pop ebx |
}; |
tm=GetTickCount()/10; |
return (tm*TICRATE)/100; |
} |
118,7 → 99,7 |
void I_Init (void) |
{ |
I_InitGraphics(); |
I_InitSound(); |
// I_InitSound(); |
} |
// |
148,16 → 129,17 |
{ |
} |
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 |
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(); |
/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 |
#include <stdlib.h> |
//#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 |
#include "d_main.h" |
#include "doomdef.h" |
#define WIN32_LEAN_AND_MEAN |
#include <windows.h> |
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 scr_w =0; |
static int scr_h =0; |
static int win_x, win_y; |
static int win_w, win_h; |
static int lastmousex = 0; |
static int lastmousey = 0; |
boolean mousemoved = false; |
boolean shmFinished; |
//int palette_color[256]; |
// |
// Translates the key |
// |
static int lastmousex = 0; |
static int lastmousey = 0; |
boolean mousemoved = false; |
/******* |
int xlatekey(SDL_keysym *key) |
{ |
int rc; |
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_StartFrame (void) |
{ |
// er? |
//printf("start new frame\n\r" ); |
} |
/* This processes SDL events */ |
/***** |
void I_GetEvent(SDL_Event *Event) |
{ |
Uint8 buttonstate; |
event_t event; |
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; |
}; |
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; |
} |
} |
*******/ |
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_StartTic (void) |
{ |
// SDL_Event Event; |
// while ( SDL_PollEvent(&Event) ) |
// I_GetEvent(&Event); |
I_GetEvent(); |
} |
302,152 → 199,65 |
// I_SetPalette |
// |
typedef struct SDL_Color |
{ |
byte r; |
byte g; |
byte b; |
byte unused; |
} SDL_Color; |
unsigned int colors[256]; |
SDL_Color 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 EndDraw() |
{ _asm |
{ push ebx |
mov eax,12 |
mov ebx, 2 |
int 0x40 |
pop ebx |
}; |
}; |
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 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 |
/* 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); |
BeginDraw(); |
DrawWindow(win_x,win_y,win_w,win_h,0x404040,3,0,0,0); |
EndDraw(); |
/* 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; |
case WM_MOVE: |
GetWindowRect(win, &rect); |
printf("%u,%u - %u, %u\n", |
rect.left,rect.top,rect.right,rect.bottom); |
ClipCursor(&rect); |
break; |
void conv(char *dst, char *src); |
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); |
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 |
} |
}; |
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; |
} |
// |
// 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<tics*2 ; i+=2) |
screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff; |
for ( ; i<20*2 ; i+=2) |
screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0; |
} |
// scales the screen size before blitting it |
if (multiply == 1) |
char *dst0; |
char *dst1; |
char *src; |
int x, y; |
dst0 = &((char *)screen.pixels)[0]; |
dst1 = dst0+640*3; |
src= (char*)screens[0]; |
y = SCREENHEIGHT; |
while (y--) |
{ |
unsigned char *olineptr; |
unsigned char *ilineptr; |
int y; |
ilineptr = (unsigned char *) screens[0]; |
olineptr = (unsigned char *) screen.pixels; |
y = SCREENHEIGHT; |
while (y--) |
{ |
memcpy(olineptr, ilineptr, screen.w); |
ilineptr += SCREENWIDTH; |
olineptr += screen.pitch; |
} |
x = SCREENWIDTH; |
conv(dst0,src); |
src+=320; |
dst0+=640*3*2; |
dst1+=640*3*2; |
} |
else if (multiply == 2) |
{ |
unsigned int *olineptrs[2]; |
unsigned int *ilineptr; |
int x, y, i; |
unsigned int twoopixels; |
unsigned int twomoreopixels; |
unsigned int fouripixels; |
ilineptr = (unsigned int *) (screens[0]); |
for (i=0 ; i<2 ; i++) { |
olineptrs[i] = |
(unsigned int *)&((byte *)screen.pixels)[i*screen.pitch]; |
} |
y = SCREENHEIGHT; |
while (y--) |
{ |
x = SCREENWIDTH; |
do |
{ |
fouripixels = *ilineptr++; |
twoopixels = (fouripixels & 0xff000000) |
| ((fouripixels>>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"); |
} |
} |
*****/ |
/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 <string.h> |
#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<myargc;i++) |
{ |
if ( !I_strncasecmp(check, myargv[i], strlen(check)) ) |
return i; |
} |
return 0; |
} |
// 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 <string.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<myargc;i++) |
{ |
if ( !strnicmp(check, myargv[i], strlen(check)) ) |
return i; |
} |
return 0; |
} |
/programs/games/doom/trunk/m_misc.c |
---|
18,9 → 18,9 |
// $Log:$ |
// |
// DESCRIPTION: |
// Main loop menu stuff. |
// Default Config File. |
// PCX Screenshots. |
// Main loop menu stuff. |
// Default Config File. |
// PCX Screenshots. |
// |
//----------------------------------------------------------------------------- |
29,8 → 29,9 |
#include <stdlib.h> |
#include <ctype.h> |
//#include "//kolibc.h" |
extern int access(char *file, int mode); |
//extern int access(char *file, int mode); |
#include "doomdef.h" |
60,36 → 61,36 |
// 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 |
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,16 → 135,19 |
// |
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); |
150,10 → 154,10 |
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 |
// |
// 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 |
{"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 |
}; |
int numdefaults; |
char* defaultfile; |
int numdefaults; |
char* defaultfile; |
// |
280,27 → 290,27 |
// |
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<numdefaults ; i++) |
{ |
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)); |
} |
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,75 → 318,90 |
// |
// 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 ; i<numdefaults ; i++) |
*defaults[i].location = defaults[i].defaultvalue; |
*defaults[i].location = defaults[i].defaultvalue; |
// check for a custom default file |
i = M_CheckParm ("-config"); |
if (i && i<myargc-1) |
{ |
defaultfile = myargv[i+1]; |
// __libclog_printf (" default file: %s\n",defaultfile); |
defaultfile = myargv[i+1]; |
// __libclog_printf (" default file: %s\n",defaultfile); |
} |
else |
defaultfile = basedefault; |
/********** |
defaultfile = basedefault; |
// read the file in, overriding any set defaults |
f = fopen (defaultfile, "r"); |
f = fopen (defaultfile, "rb"); |
if (f) |
{ |
while (!feof(f)) |
{ |
isstring = false; |
if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2) |
{ |
if (strparm[0] == '"') |
{ |
// get a string default |
isstring = true; |
len = strlen(strparm); |
newstring = (char *) malloc(len); |
strparm[len-1] = 0; |
strcpy(newstring, strparm+1); |
} |
else if (strparm[0] == '0' && strparm[1] == 'x') |
sscanf(strparm+2, "%x", &parm); |
else |
sscanf(strparm, "%i", &parm); |
for (i=0 ; i<numdefaults ; i++) |
if (!strcmp(def, defaults[i].name)) |
{ |
if (!isstring) |
*defaults[i].location = parm; |
else |
*defaults[i].location = |
(int) newstring; |
break; |
} |
} |
} |
fclose (f); |
} |
**********/ |
} |
len=FileSize(f)+1; |
buf = malloc(len); |
memset(buf,0,len); |
val = fread(buf,1,len,f); |
fclose (f); |
p = buf; |
while(*p) |
{ |
isstring = false; |
if (sscanf (p, "%79s %[^\n]\n", def, strparm) == 2) |
{ |
if (strparm[0] == '"') |
{ |
// get a string default |
isstring = true; |
len = strlen(strparm); |
newstring = (char *) malloc(len); |
strparm[len-1] = 0; |
strcpy(newstring, strparm+1); |
} |
else |
if (strparm[0] == '0' && strparm[1] == 'x') |
sscanf(strparm+2, "%x", &parm); |
else |
sscanf(strparm, "%i", &parm); |
for (i=0 ; i<numdefaults ; i++) |
if (!strcmp(def, defaults[i].name)) |
{ |
if (!isstring) |
*defaults[i].location = parm; |
else |
*defaults[i].location = (int) newstring; |
break; |
} |
}; |
p=strchr(p, '\n')+1; |
}; |
free(buf); |
}; |
}; |
// |
// SCREEN SHOTS |
// |
384,28 → 409,28 |
typedef struct |
{ |
char manufacturer; |
char version; |
char encoding; |
char bits_per_pixel; |
char manufacturer; |
char version; |
char encoding; |
char bits_per_pixel; |
unsigned short xmin; |
unsigned short ymin; |
unsigned short xmax; |
unsigned short ymax; |
unsigned short xmin; |
unsigned short ymin; |
unsigned short xmax; |
unsigned short ymax; |
unsigned short hres; |
unsigned short vres; |
unsigned short hres; |
unsigned short vres; |
unsigned char palette[48]; |
unsigned char palette[48]; |
char reserved; |
char color_planes; |
unsigned short bytes_per_line; |
unsigned short palette_type; |
char reserved; |
char color_planes; |
unsigned short bytes_per_line; |
unsigned short palette_type; |
char filler[58]; |
unsigned char data; // unbounded |
char filler[58]; |
unsigned char data; // unbounded |
} pcx_t; |
414,23 → 439,23 |
// |
void |
WritePCXfile |
( char* filename, |
byte* data, |
int width, |
int height, |
byte* palette ) |
( char* filename, |
byte* data, |
int width, |
int height, |
byte* palette ) |
{ |
int i; |
int length; |
pcx_t* pcx; |
byte* pack; |
int i; |
int length; |
pcx_t* pcx; |
byte* pack; |
pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL); |
pcx->manufacturer = 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 |
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<width*height ; i++) |
{ |
if ( (*data & 0xc0) != 0xc0) |
*pack++ = *data++; |
else |
{ |
*pack++ = 0xc1; |
*pack++ = *data++; |
} |
if ( (*data & 0xc0) != 0xc0) |
*pack++ = *data++; |
else |
{ |
*pack++ = 0xc1; |
*pack++ = *data++; |
} |
} |
// write the palette |
*pack++ = 0x0c; // palette ID byte |
*pack++ = 0x0c; // palette ID byte |
for (i=0 ; i<768 ; i++) |
*pack++ = *palette++; |
*pack++ = *palette++; |
// write output file |
length = pack - (byte *)pcx; |
476,9 → 501,9 |
// |
void M_ScreenShot (void) |
{ |
int i; |
byte* linear; |
char lbmname[12]; |
int i; |
byte* linear; |
char lbmname[12]; |
// munge planar buffer to linear |
linear = screens[2]; |
486,22 → 511,22 |
// find a file name to save it to |
strcpy(lbmname,"DOOM00.pcx"); |
for (i=0 ; i<=99 ; i++) |
{ |
lbmname[4] = i/10 + '0'; |
lbmname[5] = i%10 + '0'; |
if (access(lbmname,0) == -1) |
break; // file doesn't exist |
lbmname[4] = i/10 + '0'; |
lbmname[5] = i%10 + '0'; |
if (access(lbmname,0) == -1) |
break; // file doesn't exist |
} |
if (i==100) |
I_Error ("M_ScreenShot: Couldn't create a PCX"); |
I_Error ("M_ScreenShot: Couldn't create a PCX"); |
// save the pcx file |
WritePCXfile (lbmname, linear, |
SCREENWIDTH, SCREENHEIGHT, |
W_CacheLumpName ("PLAYPAL",PU_CACHE)); |
SCREENWIDTH, SCREENHEIGHT, |
W_CacheLumpName ("PLAYPAL",PU_CACHE)); |
players[consoleplayer].message = "screen shot"; |
} |
/programs/games/doom/trunk/m_swap.c |
---|
31,6 → 31,9 |
#include "m_swap.h" |
// Not needed with big endian. |
#ifndef __BIG_ENDIAN__ |
// Swap 16bit, that is, MSB and LSB byte. |
unsigned short SwapSHORT(unsigned short x) |
{ |
49,3 → 52,6 |
} |
#endif |
/programs/games/doom/trunk/r_data.c |
---|
18,8 → 18,8 |
// |
// Revision 1.3 1997/01/29 20:10 |
// DESCRIPTION: |
// Preparation of data for rendering, |
// generation of lookups, caching, retrieval by name. |
// Preparation of data for rendering, |
// generation of lookups, caching, retrieval by name. |
// |
//----------------------------------------------------------------------------- |
27,19 → 27,11 |
static const char |
rcsid[] = "$Id: r_data.c,v 1.4 1997/02/03 16:47:55 b1 Exp $"; |
#ifdef __BEOS__ |
#ifdef __GNUC__ |
extern void *alloca(int); |
#else |
#include <alloca.h> |
#endif |
#endif /* __BEOS__ */ |
#include "i_system.h" |
#include "z_zone.h" |
#include "m_swap.h" |
#include "i_system.h" |
#include "z_zone.h" |
#include "w_wad.h" |
#include "doomdef.h" |
49,8 → 41,11 |
#include "doomstat.h" |
#include "r_sky.h" |
#include <malloc.h> |
#include "r_data.h" |
#include <malloc.h> |
// |
// Graphics. |
// DOOM graphics for walls and sprites |
71,11 → 66,11 |
// |
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 |
{ |
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 |
// 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 |
{ |
// 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 |
// |
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,23 → 225,23 |
// |
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]; |
253,37 → 248,37 |
// Composite the columns together. |
patch = texture->patches; |
for (i=0 , patch = texture->patches; |
i<texture->patchcount; |
i++, patch++) |
i<texture->patchcount; |
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<x2 ; x++) |
{ |
// Column does not have multiple patches? |
if (collump[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<x2 ; x++) |
{ |
// Column does not have multiple patches? |
if (collump[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 |
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 |
patchcount = (byte *)alloca (texture->width); |
memset (patchcount, 0, texture->width); |
patch = texture->patches; |
for (i=0 , patch = texture->patches; |
i<texture->patchcount; |
i++, patch++) |
i<texture->patchcount; |
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 ( ; x<x2 ; x++) |
{ |
patchcount[x]++; |
collump[x] = patch->patch; |
colofs[x] = LONG(realpatch->columnofs[x-x1])+3; |
} |
if (x2 > texture->width) |
x2 = texture->width; |
for ( ; x<x2 ; x++) |
{ |
patchcount[x]++; |
collump[x] = patch->patch; |
colofs[x] = LONG(realpatch->columnofs[x-x1])+3; |
} |
} |
for (x=0 ; x<texture->width ; 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 |
// |
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 |
// |
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 |
for (i=0 ; i<nummappatches ; i++) |
{ |
strncpy (name,name_p+i*8, 8); |
patchlookup[i] = W_CheckNumForName (name); |
strncpy (name,name_p+i*8, 8); |
patchlookup[i] = W_CheckNumForName (name); |
} |
Z_Free (names); |
465,21 → 462,21 |
numtextures1 = LONG(*maptex); |
maxoff = W_LumpLength (W_GetNumForName ("TEXTURE1")); |
directory = maptex+1; |
if (W_CheckNumForName ("TEXTURE2") != -1) |
{ |
maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC); |
numtextures2 = LONG(*maptex2); |
maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); |
maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC); |
numtextures2 = LONG(*maptex2); |
maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); |
} |
else |
{ |
maptex2 = NULL; |
numtextures2 = 0; |
maxoff2 = 0; |
maptex2 = NULL; |
numtextures2 = 0; |
maxoff2 = 0; |
} |
numtextures = numtextures1 + numtextures2; |
textures = Z_Malloc (numtextures*4, PU_STATIC, 0); |
texturecolumnlump = Z_Malloc (numtextures*4, PU_STATIC, 0); |
texturecolumnofs = Z_Malloc (numtextures*4, PU_STATIC, 0); |
490,98 → 487,88 |
totalwidth = 0; |
// Really complex printing shit... |
// Really complex printing shit... |
temp1 = W_GetNumForName ("S_START"); // P_??????? |
temp2 = W_GetNumForName ("S_END") - 1; |
temp3 = ((temp2-temp1+63)/64) + ((numtextures+63)/64); |
printf("["); |
for (i = 0; i < temp3; i++) |
printf(" "); |
printf(" "); |
printf(" ]"); |
for (i = 0; i < temp3; i++) |
printf("\x8"); |
printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8"); |
printf("\x8"); |
printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8"); |
for (i=0 ; i<numtextures ; i++, directory++) |
{ |
if (!(i&63)) |
printf ("."); |
if (!(i&63)) |
printf ("."); |
if (i == numtextures1) |
{ |
// Start looking in second texture file. |
maptex = maptex2; |
maxoff = maxoff2; |
directory = maptex+1; |
} |
if (i == numtextures1) |
{ |
// Start looking in second texture file. |
maptex = maptex2; |
maxoff = maxoff2; |
directory = maptex+1; |
} |
offset = LONG(*directory); |
offset = LONG(*directory); |
if (offset > 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; j<sizeof(texture->name); ++j ) |
*dst++ = *src++; |
} |
#endif |
mpatch = &mtexture->patches[0]; |
patch = &texture->patches[0]; |
for (j=0 ; j<texture->patchcount ; 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 ; j<texture->patchcount ; 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<<FRACBITS; |
totalwidth += texture->width; |
texturewidthmask[i] = j-1; |
textureheight[i] = texture->height<<FRACBITS; |
totalwidth += texture->width; |
} |
Z_Free (maptex1); |
if (maptex2) |
Z_Free (maptex2); |
Z_Free (maptex2); |
// Precalculate whatever possible. |
// Precalculate whatever possible. |
for (i=0 ; i<numtextures ; i++) |
R_GenerateLookup (i); |
R_GenerateLookup (i); |
// Create translation table for global animation. |
texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0); |
for (i=0 ; i<numtextures ; i++) |
texturetranslation[i] = i; |
texturetranslation[i] = i; |
} |
591,17 → 578,17 |
// |
void R_InitFlats (void) |
{ |
int i; |
int i; |
firstflat = W_GetNumForName ("F_START") + 1; |
lastflat = W_GetNumForName ("F_END") - 1; |
numflats = lastflat - firstflat + 1; |
// Create translation table for global animation. |
flattranslation = Z_Malloc ((numflats+1)*4, PU_STATIC, 0); |
for (i=0 ; i<numflats ; i++) |
flattranslation[i] = i; |
flattranslation[i] = i; |
} |
613,9 → 600,9 |
// |
void R_InitSpriteLumps (void) |
{ |
int i; |
patch_t *patch; |
int i; |
patch_t *patch; |
firstspritelump = W_GetNumForName ("S_START") + 1; |
lastspritelump = W_GetNumForName ("S_END") - 1; |
623,16 → 610,16 |
spritewidth = Z_Malloc (numspritelumps*4, PU_STATIC, 0); |
spriteoffset = Z_Malloc (numspritelumps*4, PU_STATIC, 0); |
spritetopoffset = Z_Malloc (numspritelumps*4, PU_STATIC, 0); |
for (i=0 ; i< numspritelumps ; i++) |
{ |
if (!(i&63)) |
printf ("."); |
if (!(i&63)) |
printf ("."); |
patch = W_CacheLumpNum (firstspritelump+i, PU_CACHE); |
spritewidth[i] = SHORT(patch->width)<<FRACBITS; |
spriteoffset[i] = SHORT(patch->leftoffset)<<FRACBITS; |
spritetopoffset[i] = SHORT(patch->topoffset)<<FRACBITS; |
patch = W_CacheLumpNum (firstspritelump+i, PU_CACHE); |
spritewidth[i] = SHORT(patch->width)<<FRACBITS; |
spriteoffset[i] = SHORT(patch->leftoffset)<<FRACBITS; |
spritetopoffset[i] = SHORT(patch->topoffset)<<FRACBITS; |
} |
} |
643,7 → 630,7 |
// |
void R_InitColormaps (void) |
{ |
int lump, length; |
int lump, length; |
// Load in the light tables, |
// 256 byte align tables. |
665,13 → 652,13 |
void R_InitData (void) |
{ |
R_InitTextures (); |
printf ("\nInitTextures"); |
printf ("InitTextures\n\r"); |
R_InitFlats (); |
printf ("\nInitFlats"); |
printf ("InitFlats\n\r"); |
R_InitSpriteLumps (); |
printf ("\nInitSprites"); |
printf ("InitSprites\n\r"); |
R_InitColormaps (); |
printf ("\nInitColormaps"); |
printf ("InitColormaps\n\r"); |
} |
682,16 → 669,16 |
// |
int R_FlatNumForName (char* name) |
{ |
int i; |
char namet[9]; |
int i; |
char namet[9]; |
i = W_CheckNumForName (name); |
if (i == -1) |
{ |
namet[8] = 0; |
memcpy (namet, name,8); |
I_Error ("R_FlatNumForName: %s not found",namet); |
namet[8] = 0; |
memcpy (namet, name,8); |
I_Error ("R_FlatNumForName: %s not found",namet); |
} |
return i - firstflat; |
} |
704,38 → 691,36 |
// Check whether texture is available. |
// Filter out NoTexture indicator. |
// |
int R_CheckTextureNumForName (char *name) |
int R_CheckTextureNumForName (char *name) |
{ |
int i; |
int i; |
// "NoTexture" marker. |
if (name[0] == '-') |
return 0; |
if (name[0] == '-') |
return 0; |
for (i=0 ; i<numtextures ; i++) |
if (!I_strncasecmp (textures[i]->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 |
// 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 ; i<numsectors ; i++) |
{ |
flatpresent[sectors[i].floorpic] = 1; |
flatpresent[sectors[i].ceilingpic] = 1; |
flatpresent[sectors[i].floorpic] = 1; |
flatpresent[sectors[i].ceilingpic] = 1; |
} |
flatmemory = 0; |
for (i=0 ; i<numflats ; i++) |
{ |
if (flatpresent[i]) |
{ |
lump = firstflat + i; |
flatmemory += lumpinfo[lump].size; |
W_CacheLumpNum(lump, PU_CACHE); |
} |
if (flatpresent[i]) |
{ |
lump = firstflat + i; |
flatmemory += lumpinfo[lump].size; |
W_CacheLumpNum(lump, PU_CACHE); |
} |
} |
// Precache textures. |
texturepresent = alloca(numtextures); |
memset (texturepresent,0, numtextures); |
for (i=0 ; i<numsides ; i++) |
{ |
texturepresent[sides[i].toptexture] = 1; |
texturepresent[sides[i].midtexture] = 1; |
texturepresent[sides[i].bottomtexture] = 1; |
texturepresent[sides[i].toptexture] = 1; |
texturepresent[sides[i].midtexture] = 1; |
texturepresent[sides[i].bottomtexture] = 1; |
} |
// Sky texture is always present. |
809,49 → 794,49 |
// a wall texture, with an episode dependend |
// name. |
texturepresent[skytexture] = 1; |
texturememory = 0; |
for (i=0 ; i<numtextures ; i++) |
{ |
if (!texturepresent[i]) |
continue; |
if (!texturepresent[i]) |
continue; |
texture = textures[i]; |
for (j=0 ; j<texture->patchcount ; j++) |
{ |
lump = texture->patches[j].patch; |
texturememory += lumpinfo[lump].size; |
W_CacheLumpNum(lump , PU_CACHE); |
} |
texture = textures[i]; |
for (j=0 ; j<texture->patchcount ; 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 ; i<numsprites ; i++) |
{ |
if (!spritepresent[i]) |
continue; |
if (!spritepresent[i]) |
continue; |
for (j=0 ; j<sprites[i].numframes ; j++) |
{ |
sf = &sprites[i].spriteframes[j]; |
for (k=0 ; k<8 ; k++) |
{ |
lump = firstspritelump + sf->lump[k]; |
spritememory += lumpinfo[lump].size; |
W_CacheLumpNum(lump , PU_CACHE); |
} |
} |
for (j=0 ; j<sprites[i].numframes ; j++) |
{ |
sf = &sprites[i].spriteframes[j]; |
for (k=0 ; k<8 ; k++) |
{ |
lump = firstspritelump + sf->lump[k]; |
spritememory += lumpinfo[lump].size; |
W_CacheLumpNum(lump , PU_CACHE); |
} |
} |
} |
} |
/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,62 → 45,62 |
// 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. |
107,18 → 107,18 |
// 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 |
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 |
// |
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 |
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 |
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 |
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 |
{ |
// 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 |
// |
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,7 → 481,7 |
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)<<detailshift; |
den = FixedMul(rw_distance,sinea); |
488,16 → 488,16 |
if (den > 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 |
{ |
// 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<FINEANGLES/2 ; i++) |
{ |
a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES; |
fv = FRACUNIT*tan (a); |
t = fv; |
finetangent[i] = t; |
a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES; |
fv = FRACUNIT*tan (a); |
t = fv; |
finetangent[i] = t; |
} |
// finesine table |
for (i=0 ; i<5*FINEANGLES/4 ; i++) |
{ |
// OPTIMIZE: mirror... |
a = (i+0.5)*PI*2/FINEANGLES; |
t = FRACUNIT*sin (a); |
finesine[i] = t; |
// OPTIMIZE: mirror... |
a = (i+0.5)*PI*2/FINEANGLES; |
t = FRACUNIT*sin (a); |
finesine[i] = t; |
} |
#endif |
543,10 → 543,10 |
// |
void R_InitTextureMapping (void) |
{ |
int i; |
int x; |
int t; |
fixed_t focallength; |
int i; |
int x; |
int t; |
fixed_t focallength; |
// Use tangent table to generate viewangletox: |
// viewangletox will give the next greatest x |
555,50 → 555,50 |
// Calc focallength |
// so FIELDOFVIEW angles covers SCREENWIDTH. |
focallength = FixedDiv (centerxfrac, |
finetangent[FINEANGLES/4+FIELDOFVIEW/2] ); |
finetangent[FINEANGLES/4+FIELDOFVIEW/2] ); |
for (i=0 ; i<FINEANGLES/2 ; i++) |
{ |
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 (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<<ANGLETOFINESHIFT)-ANG90; |
i = 0; |
while (viewangletox[i]>x) |
i++; |
xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90; |
} |
// Take out the fencepost cases from viewangletox. |
for (i=0 ; i<FINEANGLES/2 ; i++) |
{ |
t = FixedMul (finetangent[i], focallength); |
t = centerx - t; |
if (viewangletox[i] == -1) |
viewangletox[i] = 0; |
else if (viewangletox[i] == viewwidth+1) |
viewangletox[i] = viewwidth; |
t = FixedMul (finetangent[i], focallength); |
t = centerx - t; |
if (viewangletox[i] == -1) |
viewangletox[i] = 0; |
else if (viewangletox[i] == viewwidth+1) |
viewangletox[i] = viewwidth; |
} |
clipangle = xtoviewangle[0]; |
} |
609,35 → 609,35 |
// Only inits the zlight table, |
// because the scalelight table changes with view size. |
// |
#define DISTMAP 2 |
#define DISTMAP 2 |
void R_InitLightTables (void) |
{ |
int i; |
int j; |
int level; |
int startmap; |
int scale; |
int i; |
int j; |
int level; |
int startmap; |
int scale; |
// Calculate the light levels to use |
// for each level / distance combination. |
for (i=0 ; i< LIGHTLEVELS ; i++) |
{ |
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; |
for (j=0 ; j<MAXLIGHTZ ; j++) |
{ |
scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT); |
scale >>= LIGHTSCALESHIFT; |
level = startmap - scale/DISTMAP; |
if (level < 0) |
level = 0; |
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; |
for (j=0 ; j<MAXLIGHTZ ; j++) |
{ |
scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT); |
scale >>= 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 |
// 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 |
// |
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<<FRACBITS; |
701,21 → 701,21 |
if (!detailshift) |
{ |
colfunc = basecolfunc = R_DrawColumn; |
fuzzcolfunc = R_DrawFuzzColumn; |
transcolfunc = R_DrawTranslatedColumn; |
spanfunc = R_DrawSpan; |
colfunc = basecolfunc = R_DrawColumn; |
fuzzcolfunc = R_DrawFuzzColumn; |
transcolfunc = R_DrawTranslatedColumn; |
spanfunc = R_DrawSpan; |
} |
else |
{ |
colfunc = basecolfunc = R_DrawColumnLow; |
fuzzcolfunc = R_DrawFuzzColumn; |
transcolfunc = R_DrawTranslatedColumn; |
spanfunc = R_DrawSpanLow; |
colfunc = basecolfunc = R_DrawColumnLow; |
fuzzcolfunc = R_DrawFuzzColumn; |
transcolfunc = R_DrawTranslatedColumn; |
spanfunc = R_DrawSpanLow; |
} |
R_InitBuffer (scaledviewwidth, viewheight); |
R_InitTextureMapping (); |
// psprite scales |
724,20 → 724,20 |
// thing clipping |
for (i=0 ; i<viewwidth ; i++) |
screenheightarray[i] = viewheight; |
screenheightarray[i] = viewheight; |
// planes |
for (i=0 ; i<viewheight ; i++) |
{ |
dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2; |
dy = abs(dy); |
yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy); |
dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2; |
dy = abs(dy); |
yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy); |
} |
for (i=0 ; i<viewwidth ; i++) |
{ |
cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]); |
distscale[i] = FixedDiv (FRACUNIT,cosadj); |
cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]); |
distscale[i] = FixedDiv (FRACUNIT,cosadj); |
} |
// Calculate the light levels to use |
744,19 → 744,19 |
// for each level / scale combination. |
for (i=0 ; i< LIGHTLEVELS ; i++) |
{ |
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; |
for (j=0 ; j<MAXLIGHTSCALE ; j++) |
{ |
level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP; |
if (level < 0) |
level = 0; |
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; |
for (j=0 ; j<MAXLIGHTSCALE ; j++) |
{ |
level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP; |
if (level < 0) |
level = 0; |
if (level >= NUMCOLORMAPS) |
level = NUMCOLORMAPS-1; |
if (level >= NUMCOLORMAPS) |
level = NUMCOLORMAPS-1; |
scalelight[i][j] = colormaps + level*256; |
} |
scalelight[i][j] = colormaps + level*256; |
} |
} |
} |
765,8 → 765,8 |
// |
// R_Init |
// |
extern int detailLevel; |
extern int screenblocks; |
extern int detailLevel; |
extern int screenblocks; |
773,23 → 773,23 |
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 |
// |
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_SetupFrame |
// |
void R_SetupFrame (player_t* player) |
{ |
int i; |
{ |
int i; |
viewplayer = player; |
viewx = player->mo->x; |
841,23 → 841,23 |
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<MAXLIGHTSCALE ; i++) |
scalelightfixed[i] = fixedcolormap; |
for (i=0 ; i<MAXLIGHTSCALE ; i++) |
scalelightfixed[i] = fixedcolormap; |
} |
else |
fixedcolormap = 0; |
fixedcolormap = 0; |
framecount++; |
validcount++; |
} |
868,7 → 868,7 |
// R_RenderView |
// |
void R_RenderPlayerView (player_t* player) |
{ |
{ |
R_SetupFrame (player); |
// Clear buffers. |
894,5 → 894,5 |
R_DrawMasked (); |
// Check for new console commands. |
NetUpdate (); |
NetUpdate (); |
} |
/programs/games/doom/trunk/s_sound.c |
---|
51,37 → 51,37 |
const char snd_prefixen[] |
= { 'P', 'P', 'A', 'S', 'S', 'S', 'M', 'M', 'M', 'S', 'S', 'S' }; |
#define S_MAX_VOLUME 127 |
#define S_MAX_VOLUME 127 |
// when to clip out sounds |
// Does not fit the large outdoor areas. |
#define S_CLIPPING_DIST (1200*0x10000) |
#define S_CLIPPING_DIST (1200*0x10000) |
// Distance tp origin when sounds should be maxed out. |
// This should relate to movement clipping resolution |
// (see BLOCKMAP handling). |
// Originally: (200*0x10000). |
#define S_CLOSE_DIST (160*0x10000) |
#define S_CLOSE_DIST (160*0x10000) |
#define S_ATTENUATOR ((S_CLIPPING_DIST-S_CLOSE_DIST)>>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 |
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 |
// |
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 |
// 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 |
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 |
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 |
if (volume > snd_SfxVolume) |
volume = snd_SfxVolume; |
} |
} |
else |
{ |
pitch = NORM_PITCH; |
301,7 → 301,7 |
{ |
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 |
//WriteDebug("No rc from S_AdjustSoundParams...\n"); |
return; |
} |
} |
} |
else |
{ |
sep = NORM_SEP; |
317,7 → 317,7 |
// 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 |
// 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 |
{ |
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; i<numChannels ; i++) |
{ |
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawful] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++; |
} |
if (n>1) |
{ |
for (i=0; i<numChannels ; i++) |
{ |
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawful] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) |
{ |
fprintf(stderr, |
"chn: sfxinfo=0x%lx, origin=0x%lx, " |
"handle=%d\n", |
channels[i].sfxinfo, |
channels[i].origin, |
channels[i].handle); |
} |
} |
fprintf(stderr, "\n"); |
} |
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; i<numChannels ; i++) |
{ |
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawful] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++; |
} |
if (n>1) |
{ |
for (i=0; i<numChannels ; i++) |
{ |
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawful] |
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) |
{ |
fprintf(stderr, |
"chn: sfxinfo=0x%lx, origin=0x%lx, " |
"handle=%d\n", |
channels[i].sfxinfo, |
channels[i].origin, |
channels[i].handle); |
} |
} |
fprintf(stderr, "\n"); |
} |
} |
} |
#endif |
457,11 → 456,11 |
for (cnum=0 ; cnum<numChannels ; cnum++) |
{ |
if (channels[cnum].sfxinfo && channels[cnum].origin == origin) |
{ |
S_StopChannel(cnum); |
break; |
} |
if (channels[cnum].sfxinfo && channels[cnum].origin == origin) |
{ |
S_StopChannel(cnum); |
break; |
} |
} |
} |
480,8 → 479,8 |
{ |
if (mus_playing && !mus_paused) |
{ |
I_PauseSong(mus_playing->handle); |
mus_paused = true; |
I_PauseSong(mus_playing->handle); |
mus_paused = true; |
} |
} |
489,8 → 488,8 |
{ |
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_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 |
// DOS 8bit remains. |
/*if (gametic > nextcleanup) |
{ |
for (i=1 ; i<NUMSFX ; i++) |
{ |
if (S_sfx[i].usefulness < 1 |
&& S_sfx[i].usefulness > -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<NUMSFX ; i++) |
{ |
if (S_sfx[i].usefulness < 1 |
&& S_sfx[i].usefulness > -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 ; cnum<numChannels ; cnum++) |
{ |
c = &channels[cnum]; |
sfx = c->sfxinfo; |
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 |
{ |
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 |
{ |
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 |
{ |
// I_PlaySong(music->handle, looping); |
// mus_playing = music; |
// mus_playing = music; |
} |
642,12 → 641,12 |
{ |
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; |
} |
} |
654,36 → 653,36 |
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 ; i<numChannels ; i++) |
{ |
if (cnum != i |
&& c->sfxinfo == 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 ; i<numChannels ; i++) |
{ |
if (cnum != i |
&& c->sfxinfo == channels[i].sfxinfo) |
{ |
break; |
} |
} |
// degrade usefulness of sound data |
c->sfxinfo->usefulness--; |
c->sfxinfo = 0; |
c->sfxinfo = 0; |
} |
} |
698,10 → 697,10 |
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 |
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 |
// 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 |
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++) |
/programs/games/doom/trunk/st_lib.c |
---|
32,6 → 32,8 |
#include "z_zone.h" |
#include "v_video.h" |
#include "m_swap.h" |
#include "i_system.h" |
#include "w_wad.h" |
94,8 → 96,8 |
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 |
{ |
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 |
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"); |
/programs/games/doom/trunk/st_stuff.c |
---|
1074,13 → 1074,13 |
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 |
for (i=0;i<3;i++) |
keyboxes[i] = -1; |
// STlib_init(); |
STlib_init(); |
} |
/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 ( ; col<w ; x++, col++, desttop++) |
{ |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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 ( ; col<w ; x++, col++, desttop++) |
{ |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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 ; col<w ; col++) |
{ |
outp (SC_INDEX+1,1<<(x&3)); |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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 ( ; col<w ; x++, col++, desttop++) |
{ |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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 ( ; col<w ; x++, col++, desttop++) |
{ |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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 ; col<w ; col++) |
{ |
outp (SC_INDEX+1,1<<(x&3)); |
column = (column_t *)((byte *)patch + LONG(patch->columnofs[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; |
} |
/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 <windows.h> |
#include <dsound.h> |
#include "sounds.h" |
char MsgText[256]; |
67,13 → 65,13 |
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 |
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); |
/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 |
#include <malloc.h> |
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; |
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; |
} |
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 |
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,29 → 123,24 |
// specially to allow map reloads. |
// But: the reload feature is a fragile hack... |
#ifdef __BEOS__ |
#ifdef __GNUC__ |
extern void *alloca(int); |
#else |
#include <alloca.h> |
#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 |
144,62 → 147,57 |
// 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 |
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 ; i<numlumps ; i++,lump_p++, fileinfo++) |
{ |
lump_p->handle = 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_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 ; |
i<reloadlump+lumpcount ; |
i++,lump_p++, fileinfo++) |
i<reloadlump+lumpcount ; |
i++,lump_p++, fileinfo++) |
{ |
if (lumpcache[i]) |
Z_Free (lumpcache[i]); |
if (lumpcache[i]) |
Z_Free (lumpcache[i]); |
lump_p->position = 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,20 → 287,20 |
// 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); |
314,7 → 307,7 |
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_InitFile (char* filename) |
{ |
char* names[2]; |
char* names[2]; |
names[0] = filename; |
names[1] = NULL; |
355,14 → 348,14 |
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 |
name8.s[8] = 0; |
// case insensitive |
strupr (name8.s); |
strupr (name8.s); |
v1 = name8.x[0]; |
v2 = name8.x[1]; |
382,11 → 375,11 |
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_GetNumForName (char* name) |
{ |
int i; |
int i; |
i = W_CheckNumForName (name); |
420,7 → 413,7 |
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 |
// |
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 |
// |
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 |
// |
void* |
W_CacheLumpName |
( char* name, |
int tag ) |
( char* name, |
int tag ) |
{ |
return W_CacheLumpNum (W_GetNumForName(name), tag); |
} |
520,62 → 514,69 |
// |
// 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 ; i<numlumps ; i++) |
{ |
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; |
{ |
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 ; i<numlumps ; i++) |
{ |
memcpy (name,lumpinfo[i].name,8); |
memcpy (name,lumpinfo[i].name,8); |
for (j=0 ; j<8 ; j++) |
if (!name[j]) |
break; |
for (j=0 ; j<8 ; j++) |
if (!name[j]) |
break; |
for ( ; j<8 ; j++) |
name[j] = ' '; |
for ( ; j<8 ; j++) |
name[j] = ' '; |
printf ("%s ",name); |
//printf ("%s ",name); |
for (j=0 ; j<profilecount ; j++) |
fprintf (f," %c",info[i][j]); |
for (j=0 ; j<profilecount ; j++) |
fprintf (f," %c",info[i][j]); |
printf ("\n"); |
//printf ("\n"); |
} |
fclose (f); |
} |
#endif |
/programs/games/doom/trunk/z_zone.c |
---|
26,7 → 26,7 |
// |
// |
// DESCRIPTION: |
// Zone Memory Allocation. Neat. |
// Zone Memory Allocation. Neat. |
// |
//----------------------------------------------------------------------------- |
49,24 → 49,24 |
// because it will get overwritten automatically if needed. |
// |
#define ZONEID 0x1d4a11 |
#define ZONEID 0x1d4a11 |
typedef struct |
{ |
// total bytes malloced, including header |
int size; |
int size; |
// start / end cap for linked list |
memblock_t blocklist; |
memblock_t blocklist; |
memblock_t* rover; |
memblock_t* rover; |
} memzone_t; |
memzone_t* mainzone; |
memzone_t* mainzone; |
75,21 → 75,21 |
// |
void Z_ClearZone (memzone_t* zone) |
{ |
memblock_t* block; |
memblock_t* block; |
// set the entire zone to one free block |
zone->blocklist.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,8 → 101,8 |
// |
void Z_Init (void) |
{ |
memblock_t* block; |
int size; |
memblock_t* block; |
int size; |
mainzone = (memzone_t *)I_ZoneBase (&size); |
mainzone->size = size; |
109,13 → 109,13 |
// 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_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 |
// 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 |
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 |
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 |
// |
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 |
// |
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 |
// |
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_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_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 |
// |
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; |
} |