From 928c6acf4b7fa009599c508fa2337578c2b8f3ca Mon Sep 17 00:00:00 2001 From: yoshibot Date: Tue, 17 May 2016 22:56:49 -0500 Subject: [PATCH 01/12] Simplify OS X bundle resource discovery, fix a sigsegv --- src/sdl/macosx/mac_resources.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/sdl/macosx/mac_resources.c b/src/sdl/macosx/mac_resources.c index dacc8014b..706c5e7fc 100644 --- a/src/sdl/macosx/mac_resources.c +++ b/src/sdl/macosx/mac_resources.c @@ -9,23 +9,21 @@ void OSX_GetResourcesPath(char * buffer) mainBundle = CFBundleGetMainBundle(); if (mainBundle) { + const int BUF_SIZE = 256; // because we somehow always know that + CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); - CFStringRef resources = CFStringCreateWithCString(kCFAllocatorMalloc, "/Contents/Resources", kCFStringEncodingASCII); - const void* rawarray[2] = {macPath, resources}; - CFArrayRef array = CFArrayCreate(kCFAllocatorMalloc, rawarray, 2, NULL); - CFStringRef separator = CFStringCreateWithCString(kCFAllocatorMalloc, "", kCFStringEncodingASCII); - CFStringRef fullPath = CFStringCreateByCombiningStrings(kCFAllocatorMalloc, array, separator); - const char * path = CFStringGetCStringPtr(fullPath, kCFStringEncodingASCII); - strcpy(buffer, path); - CFRelease(fullPath); - path = NULL; - CFRelease(array); - CFRelease(resources); + + const char* rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII); + + if (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE) + { + strcpy(buffer, rawPath); + strcat(buffer, "/Contents/Resources"); + } + CFRelease(macPath); CFRelease(appUrlRef); - //CFRelease(mainBundle); - CFRelease(separator); } - -} \ No newline at end of file + CFRelease(mainBundle); +} From df89563882d8eb7e2bc848944a0b76853d086970 Mon Sep 17 00:00:00 2001 From: yoshibot Date: Wed, 18 May 2016 19:14:53 -0500 Subject: [PATCH 02/12] Add a way to build OS X binaries (not .app) through Makefiles --- src/Makefile | 14 ++++++++++++++ src/Makefile.cfg | 11 +++++++++++ src/doomtype.h | 2 +- src/sdl/MakeNIX.cfg | 9 +++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 701cdcfb1..deee38545 100644 --- a/src/Makefile +++ b/src/Makefile @@ -189,6 +189,10 @@ ifdef FREEBSD UNIXCOMMON=1 endif +ifdef MACOSX +UNIXCOMMON=1 +endif + ifdef NDS NOPNG=1 NONET=1 @@ -588,11 +592,16 @@ ifndef WINDOWSHELL -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt endif endif + +# i dont know why, but the os x executable absolutely hates +# being touched by objcopy. so let's not do it +ifndef MACOSX ifndef PSP $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME) $(OBJCOPY) --strip-debug $(BIN)/$(EXENAME) -$(OBJCOPY) --add-gnu-debuglink=$(BIN)/$(DBGNAME) $(BIN)/$(EXENAME) endif +endif ifndef NOUPX -$(UPX) $(UPX_OPTS) $(BIN)/$(EXENAME) endif @@ -737,6 +746,11 @@ $(OBJDIR)/%.o: %.c $(OBJDIR)/%.o: $(INTERFACE)/%.c $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +ifdef MACOSX +$(OBJDIR)/%.o: sdl/macosx/%.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +endif + $(OBJDIR)/%.o: hardware/%.c $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ diff --git a/src/Makefile.cfg b/src/Makefile.cfg index fa8896a7c..7acb45596 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -403,6 +403,17 @@ else WINDRES=windres endif +# because Apple screws with us on this +# need to get bintools from homebrew +# need to get gzip from homebrew (it's in dupes) +ifdef MACOSX + CC=clang + CXX=clang + OBJCOPY=gobjcopy + OBJDUMP=gobjdump + GZIP=/usr/local/bin/gzip +endif + OBJDUMP_OPTS?=--wide --source --line-numbers LD=$(CC) diff --git a/src/doomtype.h b/src/doomtype.h index d833176f7..6bc2c5731 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -92,7 +92,7 @@ typedef long ssize_t; #endif #ifdef __APPLE_CC__ -#define DIRECTFULLSCREEN +#define DIRECTFULLSCREEN 1 #define DEBUG_LOG #define NOIPX #endif diff --git a/src/sdl/MakeNIX.cfg b/src/sdl/MakeNIX.cfg index f5c9b2075..1a0b54210 100644 --- a/src/sdl/MakeNIX.cfg +++ b/src/sdl/MakeNIX.cfg @@ -56,6 +56,15 @@ ifdef FREEBSD LIBS+=-lipx -lkvm endif +# +#here is Mac OS X +# +ifdef MACOSX + OBJS+=$(OBJDIR)/mac_resources.o + OBJS+=$(OBJDIR)/mac_alert.o + LIBS+=-framework CoreFoundation +endif + # #here is GP2x (arm-gp2x-linux) # From bb90c8366a4cd16ead76b96819065acf332ca3d3 Mon Sep 17 00:00:00 2001 From: yoshibot Date: Wed, 18 May 2016 22:13:53 -0500 Subject: [PATCH 03/12] Fixed bugs in OS X alert code and simplified; added more NULL checks in OS X resource code --- src/sdl/macosx/mac_alert.c | 37 +++++++++++++++++++++++++--------- src/sdl/macosx/mac_resources.c | 18 ++++++++++++----- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/sdl/macosx/mac_alert.c b/src/sdl/macosx/mac_alert.c index 455e36509..2a139041a 100644 --- a/src/sdl/macosx/mac_alert.c +++ b/src/sdl/macosx/mac_alert.c @@ -25,19 +25,38 @@ #include "mac_alert.h" #include +#define CFSTRINGIFY(x) CFStringCreateWithCString(NULL, x, kCFStringEncodingASCII) + int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3) { CFOptionFlags results; - CFUserNotificationDisplayAlert(0, - kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag, - NULL, NULL, NULL, - CFStringCreateWithCString(NULL, title, kCFStringEncodingASCII), - CFStringCreateWithCString(NULL, message, kCFStringEncodingASCII), - button1 != NULL ? CFStringCreateWithCString(NULL, button1, kCFStringEncodingASCII) : NULL, - button2 != NULL ? CFStringCreateWithCString(NULL, button2, kCFStringEncodingASCII) : NULL, - button3 != NULL ? CFStringCreateWithCString(NULL, button3, kCFStringEncodingASCII) : NULL, - &results); + CFStringRef cf_title = CFSTRINGIFY(title); + CFStringRef cf_message = CFSTRINGIFY(message); + CFStringRef cf_button1 = NULL; + CFStringRef cf_button2 = NULL; + CFStringRef cf_button3 = NULL; + + if (button1 != NULL) + cf_button1 = CFSTRINGIFY(button1); + if (button2 != NULL) + cf_button2 = CFSTRINGIFY(button2); + if (button3 != NULL) + cf_button3 = CFSTRINGIFY(button3); + + CFOptionFlags alert_flags = kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag; + + CFUserNotificationDisplayAlert(0, alert_flags, NULL, NULL, NULL, cf_title, cf_message, + cf_button1, cf_button2, cf_button3, &results); + + if (cf_button1 != NULL) + CFRelease(cf_button1); + if (cf_button2 != NULL) + CFRelease(cf_button2); + if (cf_button3 != NULL) + CFRelease(cf_button3); + CFRelease(cf_message); + CFRelease(cf_title); return (int)results; } diff --git a/src/sdl/macosx/mac_resources.c b/src/sdl/macosx/mac_resources.c index 706c5e7fc..d67b92580 100644 --- a/src/sdl/macosx/mac_resources.c +++ b/src/sdl/macosx/mac_resources.c @@ -12,11 +12,20 @@ void OSX_GetResourcesPath(char * buffer) const int BUF_SIZE = 256; // because we somehow always know that CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle); - CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); + CFStringRef macPath; + if (appUrlRef != NULL) + macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); + else + macPath = NULL; - const char* rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII); - - if (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE) + const char* rawPath; + + if (macPath != NULL) + rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII); + else + rawPath = NULL; + + if (rawPath != NULL && (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE)) { strcpy(buffer, rawPath); strcat(buffer, "/Contents/Resources"); @@ -25,5 +34,4 @@ void OSX_GetResourcesPath(char * buffer) CFRelease(macPath); CFRelease(appUrlRef); } - CFRelease(mainBundle); } From 8fbc0d7f69cd683bd23253522fcf696fd10674e8 Mon Sep 17 00:00:00 2001 From: yoshibot Date: Wed, 18 May 2016 23:52:06 -0500 Subject: [PATCH 04/12] remove bogus homebrew gzip; objdump allowed to fail in that way --- src/Makefile | 3 +-- src/Makefile.cfg | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index deee38545..cbd362ae1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -593,8 +593,7 @@ ifndef WINDOWSHELL endif endif -# i dont know why, but the os x executable absolutely hates -# being touched by objcopy. so let's not do it +# mac os x lsdlsrb2 does not like objcopy ifndef MACOSX ifndef PSP $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME) diff --git a/src/Makefile.cfg b/src/Makefile.cfg index 7acb45596..2e67474ca 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -405,13 +405,11 @@ endif # because Apple screws with us on this # need to get bintools from homebrew -# need to get gzip from homebrew (it's in dupes) ifdef MACOSX CC=clang CXX=clang OBJCOPY=gobjcopy OBJDUMP=gobjdump - GZIP=/usr/local/bin/gzip endif OBJDUMP_OPTS?=--wide --source --line-numbers From f94d3a1fb0a407f31c35854f370883a6bceaf361 Mon Sep 17 00:00:00 2001 From: Hank Brannock Date: Sun, 22 May 2016 22:38:16 -0400 Subject: [PATCH 05/12] The code in i_net.c doesn't actually seem to be used in SRB2. I was able to compile a build without it, and hosting and joining netgames worked just fine (well, as fine as they can with the current state of the netcode...). Do we really need to keep it around? If not, I say get rid of it. It seems like useless clutter that is just going to confuse people who are trying to understand the source code. --- src/Makefile.cfg | 1 - src/d_net.c | 2 +- src/i_net.h | 3 - src/sdl/Srb2SDL-vc10.vcxproj | 1 - src/sdl/Srb2SDL-vc10.vcxproj.filters | 3 - src/sdl/i_net.c | 442 --------------------------- src/sdl12/i_net.c | 442 --------------------------- 7 files changed, 1 insertion(+), 893 deletions(-) delete mode 100644 src/sdl/i_net.c delete mode 100644 src/sdl12/i_net.c diff --git a/src/Makefile.cfg b/src/Makefile.cfg index fa8896a7c..5fdea8474 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -207,7 +207,6 @@ endif #determine the interface directory (where you put all i_*.c) i_cdmus_o=$(OBJDIR)/i_cdmus.o -i_net_o=$(OBJDIR)/i_net.o i_system_o=$(OBJDIR)/i_system.o i_sound_o=$(OBJDIR)/i_sound.o i_main_o=$(OBJDIR)/i_main.o diff --git a/src/d_net.c b/src/d_net.c index 03e126b50..4b6678c23 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1080,7 +1080,7 @@ boolean D_CheckNetGame(void) multiplayer = false; // only dos version with external driver will return true - netgame = I_InitNetwork(); + netgame = false; // I_InitNetwork() is no longer used if (!netgame && !I_NetOpenSocket) { D_SetDoomcom(); diff --git a/src/i_net.h b/src/i_net.h index e378f5723..ae4697015 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -148,7 +148,4 @@ extern const char *(*I_GetBanMask) (size_t ban); extern boolean (*I_SetBanAddress) (const char *address,const char *mask); extern boolean *bannednode; -/// \brief Called by D_SRB2Main to be defined by extern network driver -boolean I_InitNetwork(void); - #endif diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj index 452b47ed1..5dc01cfd9 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj +++ b/src/sdl/Srb2SDL-vc10.vcxproj @@ -398,7 +398,6 @@ - diff --git a/src/sdl/Srb2SDL-vc10.vcxproj.filters b/src/sdl/Srb2SDL-vc10.vcxproj.filters index 9396b4823..b037140e5 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj.filters +++ b/src/sdl/Srb2SDL-vc10.vcxproj.filters @@ -837,9 +837,6 @@ SDLApp - - SDLApp - SDLApp diff --git a/src/sdl/i_net.c b/src/sdl/i_net.c deleted file mode 100644 index ee4a34c13..000000000 --- a/src/sdl/i_net.c +++ /dev/null @@ -1,442 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief SDL network interface - -#include "../doomdef.h" - -#include "../i_system.h" -#include "../d_event.h" -#include "../d_net.h" -#include "../m_argv.h" - -#include "../doomstat.h" - -#include "../i_net.h" - -#include "../z_zone.h" - -#include "../i_tcp.h" - -#ifdef HAVE_SDL - -#ifdef HAVE_SDLNET - -#include "SDL_net.h" - -#define MAXBANS 20 - -static IPaddress clientaddress[MAXNETNODES+1]; -static IPaddress banned[MAXBANS]; - -static UDPpacket mypacket; -static UDPsocket mysocket = NULL; -static SDLNet_SocketSet myset = NULL; - -static size_t numbans = 0; -static boolean NET_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? -static boolean init_SDLNet_driver = false; - -static const char *NET_AddrToStr(IPaddress* sk) -{ - static char s[22]; // 255.255.255.255:65535 - strcpy(s, SDLNet_ResolveIP(sk)); - if (sk->port != 0) strcat(s, va(":%d", sk->port)); - return s; -} - -static const char *NET_GetNodeAddress(INT32 node) -{ - if (!nodeconnected[node]) - return NULL; - return NET_AddrToStr(&clientaddress[node]); -} - -static const char *NET_GetBanAddress(size_t ban) -{ - if (ban > numbans) - return NULL; - return NET_AddrToStr(&banned[ban]); -} - -static boolean NET_cmpaddr(IPaddress* a, IPaddress* b) -{ - return (a->host == b->host && (b->port == 0 || a->port == b->port)); -} - -static boolean NET_CanGet(void) -{ - return myset?(SDLNet_CheckSockets(myset,0) == 1):false; -} - -static void NET_Get(void) -{ - INT32 mystatus; - INT32 newnode; - mypacket.len = MAXPACKETLENGTH; - if (!NET_CanGet()) - { - doomcom->remotenode = -1; // no packet - return; - } - mystatus = SDLNet_UDP_Recv(mysocket,&mypacket); - if (mystatus != -1) - { - if (mypacket.channel != -1) - { - doomcom->remotenode = mypacket.channel+1; // good packet from a game player - doomcom->datalength = mypacket.len; - return; - } - newnode = SDLNet_UDP_Bind(mysocket,-1,&mypacket.address); - if (newnode != -1) - { - size_t i; - newnode++; - M_Memcpy(&clientaddress[newnode], &mypacket.address, sizeof (IPaddress)); - DEBFILE(va("New node detected: node:%d address:%s\n", newnode, - NET_GetNodeAddress(newnode))); - doomcom->remotenode = newnode; // good packet from a game player - doomcom->datalength = mypacket.len; - for (i = 0; i < numbans; i++) - { - if (NET_cmpaddr(&mypacket.address, &banned[i])) - { - DEBFILE("This dude has been banned\n"); - NET_bannednode[newnode] = true; - break; - } - } - if (i == numbans) - NET_bannednode[newnode] = false; - return; - } - else - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } - else if (mystatus == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } - - DEBFILE("New node detected: No more free slots\n"); - doomcom->remotenode = -1; // no packet -} - -#if 0 -static boolean NET_CanSend(void) -{ - return true; -} -#endif - -static void NET_Send(void) -{ - if (!doomcom->remotenode) - return; - mypacket.len = doomcom->datalength; - if (SDLNet_UDP_Send(mysocket,doomcom->remotenode-1,&mypacket) == 0) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } -} - -static void NET_FreeNodenum(INT32 numnode) -{ - // can't disconnect from self :) - if (!numnode) - return; - - DEBFILE(va("Free node %d (%s)\n", numnode, NET_GetNodeAddress(numnode))); - - SDLNet_UDP_Unbind(mysocket,numnode-1); - - memset(&clientaddress[numnode], 0, sizeof (IPaddress)); -} - -static UDPsocket NET_Socket(void) -{ - UDPsocket temp = NULL; - Uint16 portnum = 0; - IPaddress tempip = {INADDR_BROADCAST,0}; - //Hurdler: I'd like to put a server and a client on the same computer - //Logan: Me too - //BP: in fact for client we can use any free port we want i have read - // in some doc that connect in udp can do it for us... - //Alam: where? - if (M_CheckParm("-clientport")) - { - if (!M_IsNextParm()) - I_Error("syntax: -clientport "); - portnum = atoi(M_GetNextParm()); - } - else - portnum = sock_port; - temp = SDLNet_UDP_Open(portnum); - if (!temp) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return NULL; - } - if (SDLNet_UDP_Bind(temp,BROADCASTADDR-1,&tempip) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - SDLNet_UDP_Close(temp); - return NULL; - } - clientaddress[BROADCASTADDR].port = sock_port; - clientaddress[BROADCASTADDR].host = INADDR_BROADCAST; - - doomcom->extratics = 1; // internet is very high ping - - return temp; -} - -static void I_ShutdownSDLNetDriver(void) -{ - if (myset) SDLNet_FreeSocketSet(myset); - myset = NULL; - SDLNet_Quit(); - init_SDLNet_driver = false; -} - -static void I_InitSDLNetDriver(void) -{ - if (init_SDLNet_driver) - I_ShutdownSDLNetDriver(); - if (SDLNet_Init() == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return; // No good! - } - D_SetDoomcom(); - mypacket.data = doomcom->data; - init_SDLNet_driver = true; -} - -static void NET_CloseSocket(void) -{ - if (mysocket) - SDLNet_UDP_Close(mysocket); - mysocket = NULL; -} - -static SINT8 NET_NetMakeNodewPort(const char *hostname, const char *port) -{ - INT32 newnode; - UINT16 portnum = sock_port; - IPaddress hostnameIP; - - // retrieve portnum from address! - if (port && !port[0]) - portnum = atoi(port); - - if (SDLNet_ResolveHost(&hostnameIP,hostname,portnum) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return -1; - } - newnode = SDLNet_UDP_Bind(mysocket,-1,&hostnameIP); - if (newnode == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return newnode; - } - newnode++; - M_Memcpy(&clientaddress[newnode],&hostnameIP,sizeof (IPaddress)); - return (SINT8)newnode; -} - - -static boolean NET_OpenSocket(void) -{ - memset(clientaddress, 0, sizeof (clientaddress)); - - //I_OutputMsg("SDL_Net Code starting up\n"); - - I_NetSend = NET_Send; - I_NetGet = NET_Get; - I_NetCloseSocket = NET_CloseSocket; - I_NetFreeNodenum = NET_FreeNodenum; - I_NetMakeNodewPort = NET_NetMakeNodewPort; - - //I_NetCanSend = NET_CanSend; - - // build the socket but close it first - NET_CloseSocket(); - mysocket = NET_Socket(); - - if (!mysocket) - return false; - - // for select - myset = SDLNet_AllocSocketSet(1); - if (!myset) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return false; - } - if (SDLNet_UDP_AddSocket(myset,mysocket) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return false; - } - return true; -} - -static boolean NET_Ban(INT32 node) -{ - if (numbans == MAXBANS) - return false; - - M_Memcpy(&banned[numbans], &clientaddress[node], sizeof (IPaddress)); - banned[numbans].port = 0; - numbans++; - return true; -} - -static boolean NET_SetBanAddress(const char *address, const char *mask) -{ - (void)mask; - if (bans == MAXBANS) - return false; - - if (SDLNet_ResolveHost(&banned[numbans], address, 0) == -1) - return false; - numbans++; - return true; -} - -static void NET_ClearBans(void) -{ - numbans = 0; -} -#endif - -// -// I_InitNetwork -// Only required for DOS, so this is more a dummy -// -boolean I_InitNetwork(void) -{ -#ifdef HAVE_SDLNET - char serverhostname[255]; - boolean ret = false; - SDL_version SDLcompiled; - const SDL_version *SDLlinked = SDLNet_Linked_Version(); - SDL_NET_VERSION(&SDLcompiled) - I_OutputMsg("Compiled for SDL_Net version: %d.%d.%d\n", - SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); - I_OutputMsg("Linked with SDL_Net version: %d.%d.%d\n", - SDLlinked->major, SDLlinked->minor, SDLlinked->patch); - //if (!M_CheckParm ("-sdlnet")) - // return false; - // initilize the driver - I_InitSDLNetDriver(); - I_AddExitFunc(I_ShutdownSDLNetDriver); - if (!init_SDLNet_driver) - return false; - - if (M_CheckParm("-udpport")) - { - if (M_IsNextParm()) - sock_port = (UINT16)atoi(M_GetNextParm()); - else - sock_port = 0; - } - - // parse network game options, - if (M_CheckParm("-server") || dedicated) - { - server = true; - - // If a number of clients (i.e. nodes) is specified, the server will wait for the clients - // to connect before starting. - // If no number is specified here, the server starts with 1 client, and others can join - // in-game. - // Since Boris has implemented join in-game, there is no actual need for specifying a - // particular number here. - // FIXME: for dedicated server, numnodes needs to be set to 0 upon start -/* if (M_IsNextParm()) - doomcom->numnodes = (INT16)atoi(M_GetNextParm()); - else */if (dedicated) - doomcom->numnodes = 0; - else - doomcom->numnodes = 1; - - if (doomcom->numnodes < 0) - doomcom->numnodes = 0; - if (doomcom->numnodes > MAXNETNODES) - doomcom->numnodes = MAXNETNODES; - - // server - servernode = 0; - // FIXME: - // ??? and now ? - // server on a big modem ??? 4*isdn - net_bandwidth = 16000; - hardware_MAXPACKETLENGTH = INETPACKETLENGTH; - - ret = true; - } - else if (M_CheckParm("-connect")) - { - if (M_IsNextParm()) - strcpy(serverhostname, M_GetNextParm()); - else - serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it - - // server address only in ip - if (serverhostname[0]) - { - COM_BufAddText("connect \""); - COM_BufAddText(serverhostname); - COM_BufAddText("\"\n"); - - // probably modem - hardware_MAXPACKETLENGTH = INETPACKETLENGTH; - } - else - { - // so we're on a LAN - COM_BufAddText("connect any\n"); - - net_bandwidth = 800000; - hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; - } - } - - mypacket.maxlen = hardware_MAXPACKETLENGTH; - I_NetOpenSocket = NET_OpenSocket; - I_Ban = NET_Ban; - I_ClearBans = NET_ClearBans; - I_GetNodeAddress = NET_GetNodeAddress; - I_GetBenAddress = NET_GetBenAddress; - I_SetBanAddress = NET_SetBanAddress; - bannednode = NET_bannednode; - - return ret; -#else - if ( M_CheckParm ("-net") ) - { - I_Error("-net not supported, use -server and -connect\n" - "see docs for more\n"); - } - return false; -#endif -} -#endif diff --git a/src/sdl12/i_net.c b/src/sdl12/i_net.c deleted file mode 100644 index ee4a34c13..000000000 --- a/src/sdl12/i_net.c +++ /dev/null @@ -1,442 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief SDL network interface - -#include "../doomdef.h" - -#include "../i_system.h" -#include "../d_event.h" -#include "../d_net.h" -#include "../m_argv.h" - -#include "../doomstat.h" - -#include "../i_net.h" - -#include "../z_zone.h" - -#include "../i_tcp.h" - -#ifdef HAVE_SDL - -#ifdef HAVE_SDLNET - -#include "SDL_net.h" - -#define MAXBANS 20 - -static IPaddress clientaddress[MAXNETNODES+1]; -static IPaddress banned[MAXBANS]; - -static UDPpacket mypacket; -static UDPsocket mysocket = NULL; -static SDLNet_SocketSet myset = NULL; - -static size_t numbans = 0; -static boolean NET_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? -static boolean init_SDLNet_driver = false; - -static const char *NET_AddrToStr(IPaddress* sk) -{ - static char s[22]; // 255.255.255.255:65535 - strcpy(s, SDLNet_ResolveIP(sk)); - if (sk->port != 0) strcat(s, va(":%d", sk->port)); - return s; -} - -static const char *NET_GetNodeAddress(INT32 node) -{ - if (!nodeconnected[node]) - return NULL; - return NET_AddrToStr(&clientaddress[node]); -} - -static const char *NET_GetBanAddress(size_t ban) -{ - if (ban > numbans) - return NULL; - return NET_AddrToStr(&banned[ban]); -} - -static boolean NET_cmpaddr(IPaddress* a, IPaddress* b) -{ - return (a->host == b->host && (b->port == 0 || a->port == b->port)); -} - -static boolean NET_CanGet(void) -{ - return myset?(SDLNet_CheckSockets(myset,0) == 1):false; -} - -static void NET_Get(void) -{ - INT32 mystatus; - INT32 newnode; - mypacket.len = MAXPACKETLENGTH; - if (!NET_CanGet()) - { - doomcom->remotenode = -1; // no packet - return; - } - mystatus = SDLNet_UDP_Recv(mysocket,&mypacket); - if (mystatus != -1) - { - if (mypacket.channel != -1) - { - doomcom->remotenode = mypacket.channel+1; // good packet from a game player - doomcom->datalength = mypacket.len; - return; - } - newnode = SDLNet_UDP_Bind(mysocket,-1,&mypacket.address); - if (newnode != -1) - { - size_t i; - newnode++; - M_Memcpy(&clientaddress[newnode], &mypacket.address, sizeof (IPaddress)); - DEBFILE(va("New node detected: node:%d address:%s\n", newnode, - NET_GetNodeAddress(newnode))); - doomcom->remotenode = newnode; // good packet from a game player - doomcom->datalength = mypacket.len; - for (i = 0; i < numbans; i++) - { - if (NET_cmpaddr(&mypacket.address, &banned[i])) - { - DEBFILE("This dude has been banned\n"); - NET_bannednode[newnode] = true; - break; - } - } - if (i == numbans) - NET_bannednode[newnode] = false; - return; - } - else - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } - else if (mystatus == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } - - DEBFILE("New node detected: No more free slots\n"); - doomcom->remotenode = -1; // no packet -} - -#if 0 -static boolean NET_CanSend(void) -{ - return true; -} -#endif - -static void NET_Send(void) -{ - if (!doomcom->remotenode) - return; - mypacket.len = doomcom->datalength; - if (SDLNet_UDP_Send(mysocket,doomcom->remotenode-1,&mypacket) == 0) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - } -} - -static void NET_FreeNodenum(INT32 numnode) -{ - // can't disconnect from self :) - if (!numnode) - return; - - DEBFILE(va("Free node %d (%s)\n", numnode, NET_GetNodeAddress(numnode))); - - SDLNet_UDP_Unbind(mysocket,numnode-1); - - memset(&clientaddress[numnode], 0, sizeof (IPaddress)); -} - -static UDPsocket NET_Socket(void) -{ - UDPsocket temp = NULL; - Uint16 portnum = 0; - IPaddress tempip = {INADDR_BROADCAST,0}; - //Hurdler: I'd like to put a server and a client on the same computer - //Logan: Me too - //BP: in fact for client we can use any free port we want i have read - // in some doc that connect in udp can do it for us... - //Alam: where? - if (M_CheckParm("-clientport")) - { - if (!M_IsNextParm()) - I_Error("syntax: -clientport "); - portnum = atoi(M_GetNextParm()); - } - else - portnum = sock_port; - temp = SDLNet_UDP_Open(portnum); - if (!temp) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return NULL; - } - if (SDLNet_UDP_Bind(temp,BROADCASTADDR-1,&tempip) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - SDLNet_UDP_Close(temp); - return NULL; - } - clientaddress[BROADCASTADDR].port = sock_port; - clientaddress[BROADCASTADDR].host = INADDR_BROADCAST; - - doomcom->extratics = 1; // internet is very high ping - - return temp; -} - -static void I_ShutdownSDLNetDriver(void) -{ - if (myset) SDLNet_FreeSocketSet(myset); - myset = NULL; - SDLNet_Quit(); - init_SDLNet_driver = false; -} - -static void I_InitSDLNetDriver(void) -{ - if (init_SDLNet_driver) - I_ShutdownSDLNetDriver(); - if (SDLNet_Init() == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return; // No good! - } - D_SetDoomcom(); - mypacket.data = doomcom->data; - init_SDLNet_driver = true; -} - -static void NET_CloseSocket(void) -{ - if (mysocket) - SDLNet_UDP_Close(mysocket); - mysocket = NULL; -} - -static SINT8 NET_NetMakeNodewPort(const char *hostname, const char *port) -{ - INT32 newnode; - UINT16 portnum = sock_port; - IPaddress hostnameIP; - - // retrieve portnum from address! - if (port && !port[0]) - portnum = atoi(port); - - if (SDLNet_ResolveHost(&hostnameIP,hostname,portnum) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return -1; - } - newnode = SDLNet_UDP_Bind(mysocket,-1,&hostnameIP); - if (newnode == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return newnode; - } - newnode++; - M_Memcpy(&clientaddress[newnode],&hostnameIP,sizeof (IPaddress)); - return (SINT8)newnode; -} - - -static boolean NET_OpenSocket(void) -{ - memset(clientaddress, 0, sizeof (clientaddress)); - - //I_OutputMsg("SDL_Net Code starting up\n"); - - I_NetSend = NET_Send; - I_NetGet = NET_Get; - I_NetCloseSocket = NET_CloseSocket; - I_NetFreeNodenum = NET_FreeNodenum; - I_NetMakeNodewPort = NET_NetMakeNodewPort; - - //I_NetCanSend = NET_CanSend; - - // build the socket but close it first - NET_CloseSocket(); - mysocket = NET_Socket(); - - if (!mysocket) - return false; - - // for select - myset = SDLNet_AllocSocketSet(1); - if (!myset) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return false; - } - if (SDLNet_UDP_AddSocket(myset,mysocket) == -1) - { - I_OutputMsg("SDL_Net: %s",SDLNet_GetError()); - return false; - } - return true; -} - -static boolean NET_Ban(INT32 node) -{ - if (numbans == MAXBANS) - return false; - - M_Memcpy(&banned[numbans], &clientaddress[node], sizeof (IPaddress)); - banned[numbans].port = 0; - numbans++; - return true; -} - -static boolean NET_SetBanAddress(const char *address, const char *mask) -{ - (void)mask; - if (bans == MAXBANS) - return false; - - if (SDLNet_ResolveHost(&banned[numbans], address, 0) == -1) - return false; - numbans++; - return true; -} - -static void NET_ClearBans(void) -{ - numbans = 0; -} -#endif - -// -// I_InitNetwork -// Only required for DOS, so this is more a dummy -// -boolean I_InitNetwork(void) -{ -#ifdef HAVE_SDLNET - char serverhostname[255]; - boolean ret = false; - SDL_version SDLcompiled; - const SDL_version *SDLlinked = SDLNet_Linked_Version(); - SDL_NET_VERSION(&SDLcompiled) - I_OutputMsg("Compiled for SDL_Net version: %d.%d.%d\n", - SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); - I_OutputMsg("Linked with SDL_Net version: %d.%d.%d\n", - SDLlinked->major, SDLlinked->minor, SDLlinked->patch); - //if (!M_CheckParm ("-sdlnet")) - // return false; - // initilize the driver - I_InitSDLNetDriver(); - I_AddExitFunc(I_ShutdownSDLNetDriver); - if (!init_SDLNet_driver) - return false; - - if (M_CheckParm("-udpport")) - { - if (M_IsNextParm()) - sock_port = (UINT16)atoi(M_GetNextParm()); - else - sock_port = 0; - } - - // parse network game options, - if (M_CheckParm("-server") || dedicated) - { - server = true; - - // If a number of clients (i.e. nodes) is specified, the server will wait for the clients - // to connect before starting. - // If no number is specified here, the server starts with 1 client, and others can join - // in-game. - // Since Boris has implemented join in-game, there is no actual need for specifying a - // particular number here. - // FIXME: for dedicated server, numnodes needs to be set to 0 upon start -/* if (M_IsNextParm()) - doomcom->numnodes = (INT16)atoi(M_GetNextParm()); - else */if (dedicated) - doomcom->numnodes = 0; - else - doomcom->numnodes = 1; - - if (doomcom->numnodes < 0) - doomcom->numnodes = 0; - if (doomcom->numnodes > MAXNETNODES) - doomcom->numnodes = MAXNETNODES; - - // server - servernode = 0; - // FIXME: - // ??? and now ? - // server on a big modem ??? 4*isdn - net_bandwidth = 16000; - hardware_MAXPACKETLENGTH = INETPACKETLENGTH; - - ret = true; - } - else if (M_CheckParm("-connect")) - { - if (M_IsNextParm()) - strcpy(serverhostname, M_GetNextParm()); - else - serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it - - // server address only in ip - if (serverhostname[0]) - { - COM_BufAddText("connect \""); - COM_BufAddText(serverhostname); - COM_BufAddText("\"\n"); - - // probably modem - hardware_MAXPACKETLENGTH = INETPACKETLENGTH; - } - else - { - // so we're on a LAN - COM_BufAddText("connect any\n"); - - net_bandwidth = 800000; - hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; - } - } - - mypacket.maxlen = hardware_MAXPACKETLENGTH; - I_NetOpenSocket = NET_OpenSocket; - I_Ban = NET_Ban; - I_ClearBans = NET_ClearBans; - I_GetNodeAddress = NET_GetNodeAddress; - I_GetBenAddress = NET_GetBenAddress; - I_SetBanAddress = NET_SetBanAddress; - bannednode = NET_bannednode; - - return ret; -#else - if ( M_CheckParm ("-net") ) - { - I_Error("-net not supported, use -server and -connect\n" - "see docs for more\n"); - } - return false; -#endif -} -#endif From 69f556d40a281caa75697bf2241703418c763648 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 5 Jun 2016 21:29:40 +0100 Subject: [PATCH 06/12] Split AA trees code from m_misc.c/.h into m_aatree.c/.h Also updated any relevant project files that I can think of to include the new files, as well as the makefile of course. Some of the other project files haven't been touched in years so I'll leave those alone ...unless someone objects --- SRB2.cbp | 33 +++++ src/CMakeLists.txt | 2 + src/Makefile | 1 + src/m_aatree.c | 167 +++++++++++++++++++++++++ src/m_aatree.h | 31 +++++ src/m_misc.c | 155 ----------------------- src/m_misc.h | 13 -- src/sdl/Srb2SDL-vc10.vcxproj | 2 + src/sdl/Srb2SDL-vc10.vcxproj.filters | 6 + src/w_wad.h | 4 +- src/win32/Srb2win-vc10.vcxproj | 2 + src/win32/Srb2win-vc10.vcxproj.filters | 6 + 12 files changed, 251 insertions(+), 171 deletions(-) create mode 100644 src/m_aatree.c create mode 100644 src/m_aatree.h diff --git a/SRB2.cbp b/SRB2.cbp index 43696ee2e..99a712264 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -2815,6 +2815,39 @@ HW3SOUND for 3D hardware sound support