Skip to content

Commit 8ac4030

Browse files
author
diekmann
committed
remove support for X11 shared memory.
This simplifies the code and reduces dependencies. We need to rewrite the video driver anyway, so simplifying it first is good. Still compiles and runs as standalone C and wrapped from rust.
1 parent 0d6534e commit 8ac4030

File tree

3 files changed

+1
-213
lines changed

3 files changed

+1
-213
lines changed

doom/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ fn main() {
55

66

77
// libraries which should be removed before going to wasm
8-
println!("cargo:rustc-link-lib=Xext");
98
println!("cargo:rustc-link-lib=X11");
109
println!("cargo:rustc-link-lib=nsl");
1110
}

doom/linuxdoom-1.10/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AR=llvm-ar-10
1313
# apt install gcc-multilib libx11-dev:i386 libxext-dev:i386
1414
CFLAGS=-m32 -O2 -Wall -Wno-unused-const-variable -DNORMALUNIX -DLINUX
1515
LDFLAGS=-L/usr/X11R6/lib
16-
LIBS=-lXext -lX11 -lnsl
16+
LIBS=-lX11 -lnsl
1717

1818
# subdirectory for objects
1919
O=linux

doom/linuxdoom-1.10/i_video.c

-211
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,11 @@ rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
2727
#include <stdlib.h>
2828
#include <unistd.h>
2929
#include <sys/ipc.h>
30-
#include <sys/shm.h>
3130

3231
#include <X11/Xlib.h>
3332
#include <X11/Xutil.h>
3433
#include <X11/keysym.h>
3534

36-
#include <X11/extensions/XShm.h>
37-
// Had to dig up XShm.c for this one.
38-
// It is in the libXext, but not in the XFree86 headers.
39-
#ifdef LINUX
40-
int XShmGetEventBase( Display* dpy ); // problems with g++?
41-
#endif
42-
4335
#include <stdarg.h>
4436
#include <sys/time.h>
4537
#include <sys/types.h>
@@ -71,12 +63,6 @@ XImage* image;
7163
int X_width;
7264
int X_height;
7365

74-
// MIT SHared Memory extension.
75-
boolean doShm;
76-
77-
XShmSegmentInfo X_shminfo;
78-
int X_shmeventtype;
79-
8066
// Fake mouse handling.
8167
// This cannot work properly w/o DGA.
8268
// Needs an invisible mouse cursor at least.
@@ -163,14 +149,6 @@ int xlatekey(void)
163149

164150
void I_ShutdownGraphics(void)
165151
{
166-
// Detach from X server
167-
if (!XShmDetach(X_display, &X_shminfo))
168-
I_Error("XShmDetach() failed in I_ShutdownGraphics()");
169-
170-
// Release shared memory.
171-
shmdt(X_shminfo.shmaddr);
172-
shmctl(X_shminfo.shmid, IPC_RMID, 0);
173-
174152
// Paranoia.
175153
if (image){
176154
image->data = NULL;
@@ -191,7 +169,6 @@ void I_StartFrame (void)
191169
static int lastmousex = 0;
192170
static int lastmousey = 0;
193171
boolean mousemoved = false;
194-
boolean shmFinished;
195172

196173
void I_GetEvent(void)
197174
{
@@ -274,7 +251,6 @@ void I_GetEvent(void)
274251
break;
275252

276253
default:
277-
if (doShm && X_event.type == X_shmeventtype) shmFinished = true;
278254
break;
279255
}
280256

@@ -482,28 +458,6 @@ void I_FinishUpdate (void)
482458
Expand4 ((unsigned *)(screens[0]), (double *) (image->data));
483459
}
484460

485-
if (doShm)
486-
{
487-
488-
if (!XShmPutImage( X_display,
489-
X_mainWindow,
490-
X_gc,
491-
image,
492-
0, 0,
493-
0, 0,
494-
X_width, X_height,
495-
True ))
496-
I_Error("XShmPutImage() failed\n");
497-
498-
// wait for it to finish and processes all input events
499-
shmFinished = false;
500-
do
501-
{
502-
I_GetEvent();
503-
} while (!shmFinished);
504-
505-
}
506-
else
507461
{
508462

509463
// draw the image
@@ -587,110 +541,6 @@ void I_SetPalette (byte* palette)
587541
}
588542

589543

590-
//
591-
// This function is probably redundant,
592-
// if XShmDetach works properly.
593-
// ddt never detached the XShm memory,
594-
// thus there might have been stale
595-
// handles accumulating.
596-
//
597-
void grabsharedmemory(int size)
598-
{
599-
600-
int key = ('d'<<24) | ('o'<<16) | ('o'<<8) | 'm';
601-
struct shmid_ds shminfo;
602-
int minsize = 320*200;
603-
int id;
604-
int rc;
605-
// UNUSED int done=0;
606-
int pollution=5;
607-
608-
// try to use what was here before
609-
do
610-
{
611-
id = shmget((key_t) key, minsize, 0777); // just get the id
612-
if (id != -1)
613-
{
614-
rc=shmctl(id, IPC_STAT, &shminfo); // get stats on it
615-
if (!rc)
616-
{
617-
if (shminfo.shm_nattch)
618-
{
619-
fprintf(stderr, "User %d appears to be running "
620-
"DOOM. Is that wise?\n", shminfo.shm_cpid);
621-
key++;
622-
}
623-
else
624-
{
625-
if (getuid() == shminfo.shm_perm.cuid)
626-
{
627-
rc = shmctl(id, IPC_RMID, 0);
628-
if (!rc)
629-
fprintf(stderr,
630-
"Was able to kill my old shared memory\n");
631-
else
632-
I_Error("Was NOT able to kill my old shared memory");
633-
634-
id = shmget((key_t)key, size, IPC_CREAT|0777);
635-
if (id==-1)
636-
I_Error("Could not get shared memory");
637-
638-
rc=shmctl(id, IPC_STAT, &shminfo);
639-
640-
break;
641-
642-
}
643-
if (size >= shminfo.shm_segsz)
644-
{
645-
fprintf(stderr,
646-
"will use %d's stale shared memory\n",
647-
shminfo.shm_cpid);
648-
break;
649-
}
650-
else
651-
{
652-
fprintf(stderr,
653-
"warning: can't use stale "
654-
"shared memory belonging to id %d, "
655-
"key=0x%x\n",
656-
shminfo.shm_cpid, key);
657-
key++;
658-
}
659-
}
660-
}
661-
else
662-
{
663-
I_Error("could not get stats on key=%d", key);
664-
}
665-
}
666-
else
667-
{
668-
id = shmget((key_t)key, size, IPC_CREAT|0777);
669-
if (id==-1)
670-
{
671-
extern int errno;
672-
fprintf(stderr, "errno=%d\n", errno);
673-
I_Error("Could not get any shared memory");
674-
}
675-
break;
676-
}
677-
} while (--pollution);
678-
679-
if (!pollution)
680-
{
681-
I_Error("Sorry, system too polluted with stale "
682-
"shared memory segments.\n");
683-
}
684-
685-
X_shminfo.shmid = id;
686-
687-
// attach to the shared memory segment
688-
image->data = X_shminfo.shmaddr = shmat(id, 0, 0);
689-
690-
fprintf(stderr, "shared memory id=%d, addr=0x%x\n", id,
691-
(int) (image->data));
692-
}
693-
694544
void I_InitGraphics(void)
695545
{
696546

@@ -774,23 +624,6 @@ void I_InitGraphics(void)
774624
I_Error("xdoom currently only supports 256-color PseudoColor screens");
775625
X_visual = X_visualinfo.visual;
776626

777-
// check for the MITSHM extension
778-
doShm = XShmQueryExtension(X_display);
779-
780-
// even if it's available, make sure it's a local connection
781-
if (doShm)
782-
{
783-
if (!displayname) displayname = (char *) getenv("DISPLAY");
784-
if (displayname)
785-
{
786-
d = displayname;
787-
while (*d && (*d != ':')) d++;
788-
if (*d) *d = 0;
789-
if (!(!strcasecmp(displayname, "unix") || !*displayname)) doShm = false;
790-
}
791-
}
792-
793-
fprintf(stderr, "Using MITSHM extension\n");
794627

795628
// create the colormap
796629
X_cmap = XCreateColormap(X_display, RootWindow(X_display,
@@ -853,50 +686,6 @@ void I_InitGraphics(void)
853686
GrabModeAsync, GrabModeAsync,
854687
X_mainWindow, None, CurrentTime);
855688

856-
if (doShm)
857-
{
858-
859-
X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion;
860-
861-
// create the image
862-
image = XShmCreateImage( X_display,
863-
X_visual,
864-
8,
865-
ZPixmap,
866-
0,
867-
&X_shminfo,
868-
X_width,
869-
X_height );
870-
871-
grabsharedmemory(image->bytes_per_line * image->height);
872-
873-
874-
// UNUSED
875-
// create the shared memory segment
876-
// X_shminfo.shmid = shmget (IPC_PRIVATE,
877-
// image->bytes_per_line * image->height, IPC_CREAT | 0777);
878-
// if (X_shminfo.shmid < 0)
879-
// {
880-
// perror("");
881-
// I_Error("shmget() failed in InitGraphics()");
882-
// }
883-
// fprintf(stderr, "shared memory id=%d\n", X_shminfo.shmid);
884-
// attach to the shared memory segment
885-
// image->data = X_shminfo.shmaddr = shmat(X_shminfo.shmid, 0, 0);
886-
887-
888-
if (!image->data)
889-
{
890-
perror("");
891-
I_Error("shmat() failed in InitGraphics()");
892-
}
893-
894-
// get the X server to attach to it
895-
if (!XShmAttach(X_display, &X_shminfo))
896-
I_Error("XShmAttach() failed in InitGraphics()");
897-
898-
}
899-
else
900689
{
901690
image = XCreateImage( X_display,
902691
X_visual,

0 commit comments

Comments
 (0)