doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

commit d50af960b6b3a4f0c59a5bd3713afd969ee83503
parent 41ea012cacbf2bb674b8c0b9755df2f180efb72a
Author: ssnf <ssnf@ssnf.xyz>
Date:   Thu, 17 Jun 2021 03:14:34 +0000

make it compilable

Diffstat:
Msrc/Makefile | 105+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/d_main.c | 25++++++++-----------------
Msrc/i_net.c | 8++++----
Msrc/i_video.c | 22+++++++++++-----------
Msrc/m_misc.c | 42+++++++++++++++++-------------------------
Msrc/r_data.c | 6+-----
Msrc/sounds.c | 1-
Msrc/w_wad.c | 2--
Msrc/z_zone.h | 2+-
9 files changed, 96 insertions(+), 117 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -2,67 +2,69 @@ CC = c89 CFLAGS = -g -Wall -Wpedantic -D_DEFAULT_SOURCE -Wno-deprecated-declarations LIBS = -lXext -lX11 -lnsl -lm LDFLAGS = ${LIBS} -L/usr/X11R6/lib -SRC = doomstat.c \ +SRC = am_map.c \ + d_items.c \ + d_main.c \ + d_net.c \ + doomdef.c \ + doomstat.c \ dstrings.c \ - i_system.c \ - i_sound.c \ - i_video.c \ - i_net.c \ - i_main.c \ - tables.c \ f_finale.c \ - f_wipe.c \ - d_main.c \ - d_net.c \ - d_items.c \ - g_game.c \ - m_menu.c \ - m_misc.c \ - m_argv.c \ - m_bbox.c \ - m_fixed.c \ - m_swap.c \ - m_cheat.c \ + f_wipe.c \ + g_game.c \ + hu_lib.c \ + hu_stuff.c \ + i_main.c \ + i_net.c \ + i_sound.c \ + i_system.c \ + i_video.c \ + info.c \ + m_argv.c \ + m_bbox.c \ + m_cheat.c \ + m_fixed.c \ + m_menu.c \ + m_misc.c \ m_random.c \ - am_map.c \ + m_swap.c \ p_ceilng.c \ - p_doors.c \ - p_enemy.c \ - p_floor.c \ - p_inter.c \ + p_doors.c \ + p_enemy.c \ + p_floor.c \ + p_inter.c \ p_lights.c \ - p_map.c \ + p_map.c \ p_maputl.c \ - p_plats.c \ - p_pspr.c \ - p_setup.c \ - p_sight.c \ - p_spec.c \ + p_mobj.c \ + p_plats.c \ + p_pspr.c \ + p_saveg.c \ + p_setup.c \ + p_sight.c \ + p_spec.c \ p_switch.c \ - p_mobj.c \ p_telept.c \ - p_tick.c \ - p_saveg.c \ - p_user.c \ - r_bsp.c \ - r_data.c \ - r_draw.c \ - r_main.c \ - r_plane.c \ - r_segs.c \ + p_tick.c \ + p_user.c \ + r_bsp.c \ + r_data.c \ + r_draw.c \ + r_main.c \ + r_plane.c \ + r_segs.c \ + r_sky.c \ r_things.c \ - w_wad.c \ - wi_stuff.c \ - v_video.c \ - st_lib.c \ + s_sound.c \ + sounds.c \ + st_lib.c \ st_stuff.c \ - hu_stuff.c \ - hu_lib.c \ - s_sound.c \ - z_zone.c \ - info.c \ - lang.c \ - sounds.c + tables.c \ + v_video.c \ + w_wad.c \ + wi_stuff.c \ + z_zone.c + OBJ = ${SRC:.c=.o} all: doom clean: @@ -71,3 +73,4 @@ doom: ${OBJ} ${CC} ${CFLAGS} ${LDFLAGS} ${OBJ} -o $@ %.o: %.c ${CC} ${CFLAGS} -c $< -o $@ + diff --git a/src/d_main.c b/src/d_main.c @@ -1,13 +1,11 @@ #define BGCOLOR 7 #define FGCOLOR 8 -#ifdef NORMALUNIX #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#endif #include "doomdef.h" #include "doomstat.h" #include "dstrings.h" @@ -57,10 +55,12 @@ void D_DoAdvanceDemo (void); event_t events[MAXEVENTS]; int eventhead; int eventtail; -void D_PostEvent (event_t* ev) + +void +D_PostEvent(event_t* ev) { events[eventhead] = *ev; - eventhead = (++eventhead)&(MAXEVENTS-1); + eventhead = (eventhead + 1)&(MAXEVENTS-1); } void D_ProcessEvents (void) { @@ -68,7 +68,7 @@ void D_ProcessEvents (void) if ( ( gamemode == commercial ) && (W_CheckNumForName("map01")<0) ) return; - for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) ) + for ( ; eventtail != eventhead ; eventtail = (eventtail + 1)&(MAXEVENTS-1) ) { ev = &events[eventtail]; if (M_Responder (ev)) @@ -326,9 +326,8 @@ void D_AddFile (char *file) { int numwadfiles; char *newfile; - for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++) - ; - newfile = malloc (strlen(file)+1); + for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++); + newfile = malloc(strlen(file)+1); strcpy (newfile, file); wadfiles[numwadfiles] = newfile; } @@ -341,9 +340,9 @@ void IdentifyVersion (void) char* doom2fwad; char* plutoniawad; char* tntwad; -#ifdef NORMALUNIX char *home; char *doomwaddir; + doomwaddir = getenv("DOOMWADDIR"); if (!doomwaddir) doomwaddir = "."; @@ -365,7 +364,6 @@ void IdentifyVersion (void) if (!home) I_Error("Please set $HOME to your home directory"); sprintf(basedefault, "%s/.doomrc", home); -#endif if (M_CheckParm ("-shdev")) { gamemode = shareware; @@ -763,13 +761,6 @@ void D_DoomMain (void) HU_Init (); printf ("ST_Init: Init status bar.\n"); ST_Init (); - p = M_CheckParm ("-statcopy"); - if (p && p<myargc-1) - { - extern void* statcopy; - statcopy = (void*)atoi(myargv[p+1]); - printf ("External statistics registered.\n"); - } p = M_CheckParm ("-record"); if (p && p < myargc-1) { diff --git a/src/i_net.c b/src/i_net.c @@ -24,7 +24,7 @@ (((unsigned long int)(x) & 0xff000000U) >> 24))) #define ntohs(x) \ ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \ - (((unsigned short int)(x) & 0xff00) >> 8))) \ + (((unsigned short int)(x) & 0xff00) >> 8))) #define htonl(x) ntohl(x) #define htons(x) ntohs(x) void NetSend (void); @@ -85,11 +85,11 @@ void PacketGet (void) int i; int c; struct sockaddr_in fromaddress; - int fromlen; + socklen_t fromlen; doomdata_t sw; + fromlen = sizeof(fromaddress); - c = recvfrom (insocket, &sw, sizeof(sw), 0 - , (struct sockaddr *)&fromaddress, &fromlen ); + c = recvfrom(insocket, &sw, sizeof(sw), 0 , (struct sockaddr *)&fromaddress, &fromlen ); if (c == -1 ) { if (errno != EWOULDBLOCK) diff --git a/src/i_video.c b/src/i_video.c @@ -493,10 +493,10 @@ void grabsharedmemory(int size) } X_shminfo.shmid = id; image->data = X_shminfo.shmaddr = shmat(id, 0, 0); - fprintf(stderr, "shared memory id=%d, addr=0x%x\n", id, - (int) (image->data)); } -void I_InitGraphics(void) + +void +I_InitGraphics() { char* displayname; char* d; @@ -706,45 +706,45 @@ Expand4 do { fourpixels = lineptr[0]; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) ); + dpixel = *(double*)((long)exp + ( (fourpixels&0xffff0000)>>13) ); xline[0] = dpixel; xline[160] = dpixel; xline[320] = dpixel; xline[480] = dpixel; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff)<<3 ) ); xline[1] = dpixel; xline[161] = dpixel; xline[321] = dpixel; xline[481] = dpixel; fourpixels = lineptr[1]; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff0000)>>13) ); xline[2] = dpixel; xline[162] = dpixel; xline[322] = dpixel; xline[482] = dpixel; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff)<<3 ) ); xline[3] = dpixel; xline[163] = dpixel; xline[323] = dpixel; xline[483] = dpixel; fourpixels = lineptr[2]; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff0000)>>13) ); xline[4] = dpixel; xline[164] = dpixel; xline[324] = dpixel; xline[484] = dpixel; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff)<<3 ) ); xline[5] = dpixel; xline[165] = dpixel; xline[325] = dpixel; xline[485] = dpixel; fourpixels = lineptr[3]; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff0000)>>13) ); xline[6] = dpixel; xline[166] = dpixel; xline[326] = dpixel; xline[486] = dpixel; - dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) ); + dpixel = *(double *)( (long)exp + ( (fourpixels&0xffff)<<3 ) ); xline[7] = dpixel; xline[167] = dpixel; xline[327] = dpixel; diff --git a/src/m_misc.c b/src/m_misc.c @@ -88,6 +88,7 @@ M_ReadFile *buffer = buf; return length; } + int usemouse; int usejoystick; extern int key_right; @@ -128,9 +129,9 @@ typedef struct { char* name; int* location; - int defaultvalue; - int scantranslate; - int untranslated; + long defaultvalue; + long scantranslate; + long untranslated; } default_t; default_t defaults[] = { @@ -138,7 +139,6 @@ default_t defaults[] = {"sfx_volume",&snd_SfxVolume, 8}, {"music_volume",&snd_MusicVolume, 8}, {"show_messages",&showMessages, 1}, -#ifdef NORMALUNIX {"key_right",&key_right, KEY_RIGHTARROW}, {"key_left",&key_left, KEY_LEFTARROW}, {"key_up",&key_up, KEY_UPARROW}, @@ -149,15 +149,7 @@ default_t defaults[] = {"key_use",&key_use, ' '}, {"key_strafe",&key_strafe, KEY_RALT}, {"key_speed",&key_speed, KEY_RSHIFT}, -#ifdef SNDSERV - {"sndserver", (int *) &sndserver_filename, (int) "sndserver"}, {"mb_used", &mb_used, 2}, -#endif -#endif -#ifdef LINUX - {"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"}, - {"mousetype", (int*)&mousetype, (int)"microsoft"}, -#endif {"use_mouse",&usemouse, 1}, {"mouseb_fire",&mousebfire,0}, {"mouseb_strafe",&mousebstrafe,1}, @@ -171,16 +163,16 @@ default_t defaults[] = {"detaillevel",&detailLevel, 0}, {"snd_channels",&numChannels, 3}, {"usegamma",&usegamma, 0}, - {"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 }, - {"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 }, - {"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 }, - {"chatmacro3", (int *) &chat_macros[3], (int) HUSTR_CHATMACRO3 }, - {"chatmacro4", (int *) &chat_macros[4], (int) HUSTR_CHATMACRO4 }, - {"chatmacro5", (int *) &chat_macros[5], (int) HUSTR_CHATMACRO5 }, - {"chatmacro6", (int *) &chat_macros[6], (int) HUSTR_CHATMACRO6 }, - {"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 }, - {"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 }, - {"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 } + {"chatmacro0", (int*) &chat_macros[0], (long)HUSTR_CHATMACRO0 }, + {"chatmacro1", (int*) &chat_macros[1], (long)HUSTR_CHATMACRO1 }, + {"chatmacro2", (int*) &chat_macros[2], (long)HUSTR_CHATMACRO2 }, + {"chatmacro3", (int*) &chat_macros[3], (long)HUSTR_CHATMACRO3 }, + {"chatmacro4", (int*) &chat_macros[4], (long)HUSTR_CHATMACRO4 }, + {"chatmacro5", (int*) &chat_macros[5], (long)HUSTR_CHATMACRO5 }, + {"chatmacro6", (int*) &chat_macros[6], (long)HUSTR_CHATMACRO6 }, + {"chatmacro7", (int*) &chat_macros[7], (long)HUSTR_CHATMACRO7 }, + {"chatmacro8", (int*) &chat_macros[8], (long)HUSTR_CHATMACRO8 }, + {"chatmacro9", (int*) &chat_macros[9], (long)HUSTR_CHATMACRO9 } }; int numdefaults; char* defaultfile; @@ -215,7 +207,7 @@ void M_LoadDefaults (void) char def[80]; char strparm[100]; char* newstring; - int parm; + unsigned int parm; boolean isstring; numdefaults = sizeof(defaults)/sizeof(defaults[0]); for (i=0 ; i<numdefaults ; i++) @@ -247,7 +239,7 @@ void M_LoadDefaults (void) else if (strparm[0] == '0' && strparm[1] == 'x') sscanf(strparm+2, "%x", &parm); else - sscanf(strparm, "%i", &parm); + sscanf(strparm, "%ud", &parm); for (i=0 ; i<numdefaults ; i++) if (!strcmp(def, defaults[i].name)) { @@ -255,7 +247,7 @@ void M_LoadDefaults (void) *defaults[i].location = parm; else *defaults[i].location = - (int) newstring; + (long) newstring; break; } } diff --git a/src/r_data.c b/src/r_data.c @@ -7,9 +7,7 @@ #include "p_local.h" #include "doomstat.h" #include "r_sky.h" -#ifdef LINUX #include <alloca.h> -#endif #include "r_data.h" typedef struct { @@ -76,8 +74,6 @@ R_DrawColumnInCache int count; int position; byte* source; - byte* dest; - dest = (byte *)cache + 3; while (patch->topdelta != 0xff) { source = (byte *)patch + 3; @@ -380,7 +376,7 @@ void R_InitColormaps (void) lump = W_GetNumForName("COLORMAP"); length = W_LumpLength (lump) + 255; colormaps = Z_Malloc (length, PU_STATIC, 0); - colormaps = (byte *)( ((int)colormaps + 255)&~0xff); + colormaps = (byte *)( ((long)colormaps + 255)&~0xff); W_ReadLump (lump,colormaps); } void R_InitData (void) diff --git a/src/sounds.c b/src/sounds.c @@ -1,4 +1,3 @@ -static const char #include "doomtype.h" #include "sounds.h" musicinfo_t S_music[] = diff --git a/src/w_wad.c b/src/w_wad.c @@ -1,4 +1,3 @@ -#ifdef NORMALUNIX #include <ctype.h> #include <sys/types.h> #include <string.h> @@ -8,7 +7,6 @@ #include <sys/stat.h> #include <alloca.h> #define O_BINARY 0 -#endif #include "doomtype.h" #include "m_swap.h" #include "i_system.h" diff --git a/src/z_zone.h b/src/z_zone.h @@ -30,7 +30,7 @@ typedef struct memblock_s #define Z_ChangeTag(p,t) \ { \ if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \ - I_Error("Z_CT at "__FILE__":%i",__LINE__); \ + I_Error("Z_CT at "__FILE__":%i",__LINE__); \ Z_ChangeTag2(p,t); \ }; #endif