shithub: duke3d

Download patch

ref: ad369f8403210aaec8e9f1fbfbcafbe54c0c4823
parent: f0cbb3aa78575448238c4b8ee66fa0cfaee3a855
author: Juan Manuel Borges Caño <juanmabcmail@gmail.com>
date: Wed Jul 31 09:24:08 EDT 2013

Really minimal modification for Linux integration

--- /dev/null
+++ b/Engine/src/Makefile
@@ -1,0 +1,10 @@
+SOURCES=cache.c display.c draw.c dummy_multi.c engine.c filesystem.c fixedPoint_math.c mmulti.c network.c tiles.c
+OBJECTS=cache.o display.o draw.o dummy_multi.o engine.o filesystem.o fixedPoint_math.o mmulti.o network.o tiles.o
+
+../../libEngine.a: $(SOURCES)
+	gcc -DPLATFORM_UNIX -DBYTE_ORDER=LITTLE_ENDIAN -D_XOPEN_SOURCE=500 -I /usr/include/SDL -I /usr/include/enet -c $(SOURCES)
+	ar cru ../../libEngine.a $(OBJECTS)
+	ranlib ../../libEngine.a
+
+clean:
+	rm $(OBJECTS) ../../libEngine.a
--- a/Engine/src/filesystem.c
+++ b/Engine/src/filesystem.c
@@ -404,7 +404,7 @@
 	
 }
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__linux__)
 int32_t filelength(int32_t fd){
     struct stat stats;
     fstat(fd, &stats);
--- a/Engine/src/filesystem.h
+++ b/Engine/src/filesystem.h
@@ -42,7 +42,7 @@
 
 int32_t  TCkopen4load(const char  *filename, int32_t readfromGRP);
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__linux__)
 int32_t  filelength(int32_t fd);
 #endif
 
--- /dev/null
+++ b/Engine/src/unix_compat.h
@@ -1,0 +1,67 @@
+//
+//  unix_compat.h
+//  Duke3D
+//
+//  Based on macos_compat.h
+//  Copyright Wed, Jul 31, 2013, Juan Manuel Borges Caño (GPLv3+)
+//
+
+#ifndef Duke3D_unix_compat_h
+#define Duke3D_unix_compat_h
+
+//#define BYTE_ORDER LITTLE_ENDIAN
+#define PLATFORM_SUPPORTS_SDL
+
+#include <stdlib.h>
+
+#define kmalloc(x) malloc(x)
+#define kkmalloc(x) malloc(x)
+#define kfree(x) free(x)
+#define kkfree(x) free(x)
+
+#ifdef FP_OFF
+#undef FP_OFF
+#endif
+
+// Horrible horrible macro: Watcom allowed memory pointer to be cast
+// to a 32bits integer. The code is unfortunately stuffed with this :( !
+#define FP_OFF(x) ((int32_t) (x))
+
+#ifndef max
+#define max(x, y)  (((x) > (y)) ? (x) : (y))
+#endif
+
+#ifndef min
+#define min(x, y)  (((x) < (y)) ? (x) : (y))
+#endif
+
+#include <inttypes.h>
+#define __int64 int64_t
+
+#define O_BINARY 0
+
+#define UDP_NETWORKING 1
+
+#define PLATFORM_UNIX 1
+
+/*
+#define SOL_IP SOL_SOCKET
+#define IP_RECVERR  SO_BROADCAST
+*/
+
+#define stricmp strcasecmp
+#define strcmpi strcasecmp
+
+#define S_IREAD S_IRUSR
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <string.h>
+
+#define USER_DUMMY_NETWORK 1
+
+#endif
--- /dev/null
+++ b/Game/src/Makefile
@@ -1,0 +1,17 @@
+SOURCES=actors.c animlib.c config.c console.c control.c cvar_defs.c cvars.c dummy_audiolib.c game.c gamedef.c global.c keyboard.c menues.c player.c premap.c rts.c scriplib.c sector.c sounds.c
+OBJECTS=actors.o animlib.o config.o console.o control.o cvar_defs.o cvars.o dummy_audiolib.o game.o gamedef.o global.o keyboard.o menues.o player.o premap.o rts.o scriplib.o sector.o sounds.o
+
+../../libGame.a: audiolib.a libmidi.a $(SOURCES)
+	gcc -DPLATFORM_UNIX -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -I /usr/include/SDL/ -I enet/include -I ../../Engine/src/ -c $(SOURCES)
+	ar cru ../../libGame.a $(OBJECTS) audiolib/*.o midi/*.o
+	ranlib ../../libGame.a
+
+audiolib.a:
+	cd audiolib && make
+libmidi.a:
+	cd midi && make
+
+clean:
+	rm $(OBJECTS) ../../libGame.a
+	cd midi && make clean
+	cd audiolib && make clean
--- a/Game/src/audiolib/Makefile
+++ b/Game/src/audiolib/Makefile
@@ -4,19 +4,19 @@
 CFLAGS=-g -O2
 LDLIBS=
 
-CFLAGS += $(shell sdl-config --cflags)
+CFLAGS += $(shell sdl-config --cflags) -DPLATFORM_UNIX -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -DBYTE_ORDER=LITTLE_ENDIAN -I /usr/include/SDL -I ../../../Engine/src/
 LDLIBS += $(shell sdl-config --libs)
 
 OBJ=fx_man.o dsl.o ll_man.o multivoc.o mv_mix.o mvreverb.o nodpmi.o \
 	pitch.o user.o usrhooks.o
 
-audiolib.a: $(OBJ)
+../audiolib.a: $(OBJ)
 	rm -rf $@
 	$(AR) rc $@ $^
 	$(RANLIB) $@
 
 clean:
-	rm -rf audiolib.a *.o
+	rm -rf ../audiolib.a *.o
 
 distclean: clean
 	rm -rf *~
--- a/Game/src/audiolib/usrhooks.c
+++ b/Game/src/audiolib/usrhooks.c
@@ -43,7 +43,7 @@
 int USRHOOKS_GetMem
    (
    void **ptr,
-   unsigned long size
+   uint32_t size
    )
 
    {
--- a/Game/src/game.c
+++ b/Game/src/game.c
@@ -8068,7 +8068,8 @@
     {
         
         
-        if (dukeGRP_Match(dirEntry->d_name,dirEntry->d_namlen))
+        //if (dukeGRP_Match(dirEntry->d_name,dirEntry->d_namlen))
+        if (dukeGRP_Match(dirEntry->d_name, _D_EXACT_NAMLEN(dirEntry)))
         {
             sprintf(groupfilefullpath,"%s",dirEntry->d_name);
             return;
--- a/Game/src/global.c
+++ b/Game/src/global.c
@@ -839,7 +839,7 @@
 	return string;
 }
 
-uint8_t  *ultoa(unsigned int32_t value, uint8_t  *string, int radix)
+uint8_t  *ultoa(uint32_t value, uint8_t  *string, int radix)
 {
 	switch (radix) {
 		case 10:
@@ -866,7 +866,8 @@
 
 	snprintf (ApogeePath, sizeof (ApogeePath), "%s/.duke3d/", getenv ("HOME"));
 
-	err = mkdir (ApogeePath, S_IRWXU);
+	//err = mkdir (ApogeePath, S_IRWXU);
+	err = mkdir (ApogeePath);
 	if (err == -1 && errno != EEXIST)
 	{
 		fprintf (stderr, "Couldn't create preferences directory: %s\n", 
--- /dev/null
+++ b/Game/src/midi/Makefile
@@ -1,0 +1,10 @@
+SOURCES=sdl_midi.c
+OBJECTS=sdl_midi.o
+
+../libmidi.a: $(SOURCES)
+	gcc -DPLATFORM_UNIX -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -DBYTE_ORDER=LITTLE_ENDIAN -I /usr/include/SDL/ -I ../../../Engine/src/ -c $(SOURCES)
+	ar cru ../libmidi.a $(OBJECTS)
+	ranlib ../libmidi.a
+
+clean:
+	rm ../libmidi.a $(OBJECTS)
--- a/Game/src/midi/sdl_midi.c
+++ b/Game/src/midi/sdl_midi.c
@@ -9,7 +9,7 @@
 #include <stdio.h>
 #include "../audiolib/music.h"
 #include "SDL.h"
-#include "SDL_Mixer.h"
+#include "SDL_mixer.h"
 #include "build.h"
 
 /*
@@ -185,4 +185,4 @@
 // This is the method called from the Game Module.
 void PlayMusic(char  *fileName){
     MUSIC_PlaySong(fileName,1);
-}
\ No newline at end of file
+}
--- /dev/null
+++ b/Makefile
@@ -1,0 +1,9 @@
+all:
+	cd Engine/src && make
+	cd Game/src && make
+	gcc libGame.a libEngine.a `pkg-config --cflags --libs sdl SDL_mixer` -lenet -o chocolate-duke3d
+
+clean:
+	cd Game/src && make clean
+	cd Engine/src && make clean
+	rm chocolate-duke3d
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@
 Requirements
 ============
 
-[SDL](http://libsdl.org) and SDL_mixer to compile and run the code.
+[SDL](http://libsdl.org), SDL_mixer and [enet](http://enet.bespin.org) to compile and run the code.
 
 An original copy of Duke Nukem 3D (specifically the DUKE3D.GRP file from the original CD).
 
@@ -23,7 +23,7 @@
 
 Windows: Use Visual Studio 2005 or Visual Studio 2012  
 OS X: Use Xcode 4.0  
-Linux: Not yet tested 
+Linux: Use 'make' (.grp in working directory and with rw permissions)
 
 
 Background
@@ -30,7 +30,7 @@
 ==========
 
 **Project initiator:** Fabien Sanglard 
+**Linux integration:** Juan Manuel Borges Caño
 
-**More information:** [Review of the Duke 3D source code](http://fabiensanglard.net/duke3d/)
-
+**More information:** [Review of the Duke 3D source code](http://fabiensanglard.net/duke3d/) [Linux integration](http://juanmabcblog.blogspot.com/2013/07/chocolate-duke3d.html)
 
--