shithub: qk1

Download patch

ref: db483593b59cc824ab2eee0650cc9b737bafb014
parent: 98096fe3bd72a2d032bb33575690c0fc3734dd87
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Feb 1 13:42:12 EST 2024

add a dummy macos implementation

--- /dev/null
+++ b/cd_null.c
@@ -1,0 +1,40 @@
+#include "quakedef.h"
+
+void
+stopcd(void)
+{
+}
+
+void
+pausecd(void)
+{
+}
+
+void
+resumecd(void)
+{
+}
+
+void
+shutcd(void)
+{
+}
+
+void
+stepcd(void)
+{
+}
+
+void
+playcd(int nt, bool loop)
+{
+	USED(nt); USED(loop);
+}
+
+int
+initcd(void)
+{
+	Cvar_RegisterVariable(&bgmvolume);
+	Cmd_AddCommand("cd", cdcmd);
+	return 0;
+}
--- /dev/null
+++ b/in_null.c
@@ -1,0 +1,38 @@
+#include "quakedef.h"
+
+void
+conscmd(void)
+{
+}
+
+void
+Sys_SendKeyEvents(void)
+{
+}
+
+void
+IN_Commands(void)
+{
+}
+
+void
+IN_Move(usercmd_t *cmd)
+{
+	USED(cmd);
+}
+
+void
+IN_Grabm(int on)
+{
+	USED(on);
+}
+
+void
+IN_Shutdown(void)
+{
+}
+
+void
+IN_Init(void)
+{
+}
--- a/meson.build
+++ b/meson.build
@@ -110,49 +110,73 @@
 	)
 endif
 
-libm = cc.find_library('m', required: false)
-libws = dependency('', required: false)
-
 src_sys = [
-	'in_sdl.c',
-	'parg.c',
 	'seprint.c',
-	'snd_openal.c',
-	'vid_sdl.c',
 ]
 
-if host_machine.system() == 'windows'
+math = cc.find_library('m', required: false)
+network = dependency('', required: false)
+audio = dependency('', required: false)
+video = dependency('', required: false)
+
+if host_machine.system() == 'macos'
 	src_sys += [
-		'net_udp_windows.c',
-		'sys_windows.c',
+		'cd_null.c',
+		'in_null.c',
+		'net_udp_null.c',
+		'snd_mix.c',
+		'snd_null.c',
+		'sys_macos.c',
+		'vid_null.c',
 	]
-	libws = cc.find_library('ws2_32')
 else
+	audio = dependency('openal')
+	video = dependency('sdl2')
 	src_sys += [
-		'net_udp_unix.c',
-		'sys_unix.c',
+		'in_sdl.c',
+		'parg.c',
+		'snd_openal.c',
+		'vid_sdl.c',
 	]
-	if cc.check_header('endian.h')
-		add_project_arguments(
-			'-DHAVE_ENDIAN_H',
-			language: 'c',
-		)
+	if host_machine.system() == 'windows'
+		src_sys += [
+			'net_udp_windows.c',
+			'sys_windows.c',
+		]
+		network = cc.find_library('ws2_32')
+	else
+		src_sys += [
+			'net_udp_unix.c',
+			'sys_unix.c',
+		]
 	endif
 endif
 
-openal = dependency('openal')
-sdl2 = dependency('sdl2')
-threads = dependency('threads')
+if cc.check_header('endian.h')
+	add_project_arguments(
+		'-DHAVE_ENDIAN_H',
+		language: 'c',
+	)
+elif host_machine.endian() == 'big'
+	add_project_arguments(
+		'-DQUAKE_BIG_ENDIAN',
+		language: 'c',
+	)
+else
+	add_project_arguments(
+		'-DQUAKE_LITTLE_ENDIAN',
+		language: 'c',
+	)
+endif
 
 executable(
 	'qk1',
 	sources: src_common + src_sys,
 	dependencies: [
-		libm,
-		libws,
-		openal,
-		sdl2,
-		threads,
+		audio,
+		math,
+		network,
+		video,
 	],
 	include_directories: include_directories(
 		'posix',
--- /dev/null
+++ b/net_udp_null.c
@@ -1,0 +1,95 @@
+#include "quakedef.h"
+
+Addr myip;
+
+int
+UDP_Init(void)
+{
+	return -1;
+}
+
+void
+UDP_Shutdown(void)
+{
+}
+
+void
+UDP_Listen(bool on)
+{
+	USED(on);
+}
+
+void
+udpinfo(Addr *a)
+{
+	USED(a);
+}
+
+int
+UDP_Connect(Addr *a)
+{
+	USED(a);
+	return -1;
+}
+
+int
+getnewcon(Addr *a)
+{
+	USED(a);
+	return 0;
+}
+
+int
+udpread(byte *buf, int len, Addr *a)
+{
+	USED(buf); USED(len); USED(a);
+	return -1;
+}
+
+int
+udpwrite(byte *buf, int len, Addr *a)
+{
+	USED(buf); USED(len); USED(a);
+	return -1;
+}
+
+char *
+UDP_AddrToString(Addr *a)
+{
+	USED(a);
+	return "";
+}
+
+int
+UDP_Broadcast(byte *buf, int len)
+{
+	USED(buf); USED(len);
+	return -1;
+}
+
+int
+getip(char *s, Addr *a)
+{
+	USED(s); USED(a);
+	return -1;
+}
+
+int
+UDP_AddrCompare(Addr *a1, Addr *a2)
+{
+	USED(a1); USED(a2);
+	return 0;
+}
+
+u16int
+UDP_GetSocketPort(Addr *a)
+{
+	USED(a);
+	return 0;
+}
+
+void
+UDP_SetSocketPort(Addr *a, u16int port)
+{
+	USED(a); USED(port);
+}
--- /dev/null
+++ b/snd_null.c
@@ -1,0 +1,29 @@
+#include "quakedef.h"
+
+long
+sndqueued(void)
+{
+	return 0;
+}
+
+void
+sndstop(void)
+{
+}
+
+void
+sndwrite(byte *buf, long sz)
+{
+	USED(buf); USED(sz);
+}
+
+void
+sndclose(void)
+{
+}
+
+int
+sndopen(void)
+{
+	return -1;
+}
--- /dev/null
+++ b/sys_macos.c
@@ -1,0 +1,153 @@
+#include "quakedef.h"
+#include <time.h>
+#include <errno.h>
+
+char *game;
+int debug;
+char lasterr[256] = {0};
+static const char *disabled[32];
+static int ndisabled;
+
+int
+nrand(int n)
+{
+	if(n < 1)
+		return 0;
+	return m_random_63() % n;
+}
+
+int
+mkdir(const char *path, mode_t mode)
+{
+	USED(path); USED(mode);
+	return -1;
+}
+
+int
+dup(int a)
+{
+	USED(a);
+	return -1;
+}
+
+bool
+isdisabled(char *s)
+{
+	int i;
+
+	for(i = 0; i < ndisabled; i++){
+		if(strcmp(disabled[i], s) == 0)
+			return true;
+	}
+	return false;
+}
+
+char *
+lerr(void)
+{
+	static char lasterrcopy[256];
+	if(*lasterr == 0 && errno != 0)
+		return strerror(errno);
+	strcpy(lasterrcopy, lasterr);
+	return lasterrcopy;
+}
+
+int
+sys_mkdir(char *path)
+{
+	return (mkdir(path, 0770) == 0 || errno == EEXIST) ? 0 : -1;
+}
+
+char *
+sys_timestamp(void)
+{
+	static char ts[32];
+	struct tm *tm;
+	time_t t;
+
+	if((t = time(nil)) == (time_t)-1 || (tm = localtime(&t)) == nil)
+		return nil;
+	snprint(ts, sizeof(ts),
+		"%04d%02d%02d-%02d%02d%02d",
+		tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec
+	);
+
+	return ts;
+}
+
+void
+fatal(char *fmt, ...)
+{
+	va_list arg;
+
+	va_start(arg, fmt);
+	vfprintf(stderr, fmt, arg);
+	va_end(arg);
+	Host_Shutdown();
+	exit(1);
+}
+
+void *
+emalloc(long n)
+{
+	void *p;
+
+	if(p = calloc(1, n), p == nil)
+		fatal("emalloc");
+	setmalloctag(p, getcallerpc(&n));
+	return p;
+}
+
+u64int
+nanosec(void)
+{
+	return 0;
+}
+
+double
+dtime(void)
+{
+	return nanosec()/1000000000.0;
+}
+
+void
+game_shutdown(void)
+{
+	stopfb();
+	Host_Shutdown();
+	exit(0);
+}
+
+int
+main(int argc, char **argv)
+{
+	double t, t2, dt;
+	int c, nargs, i;
+	static char *paths[8] = {0};
+
+	i = 0;
+	paths[i++] = ".";
+
+	m_random_init(time(nil));
+	srand(time(nil));
+
+	paths[i] = sys_wrpath();
+	Host_Init(nargs, argv, paths);
+
+	t = dtime() - 1.0 / Fpsmax;
+	for(;;){
+		t2 = dtime();
+		dt = t2 - t;
+		if(cls.state == ca_dedicated){
+			if(dt < sys_ticrate.value)
+				continue;
+			dt = sys_ticrate.value;
+		}
+		if(dt > sys_ticrate.value * 2)
+			t = t2;
+		else
+			t += dt;
+		Host_Frame(dt);
+	}
+	return 0;
+}
--- /dev/null
+++ b/vid_null.c
@@ -1,0 +1,37 @@
+#include "quakedef.h"
+
+pixel_t q1pal[256];
+
+void
+stopfb(void)
+{
+}
+
+void
+flipfb(void)
+{
+}
+
+void
+setpal(byte *p0)
+{
+	int x;
+	byte *p;
+
+	for(p = p0, x = 0; x < 256; x++, p += 3)
+		q1pal[x] = (x < 256-32 ? 0xff : 0)<<24 | p[0]<<16 | p[1]<<8 | p[2];
+	q1pal[255] &= 0;
+
+	scr_fullupdate = 0;
+}
+
+char *
+sys_wrpath(void)
+{
+	return "";
+}
+
+void
+initfb(void)
+{
+}