From 02e5effdd0faec8095094bbd750a596115941175 Mon Sep 17 00:00:00 2001 Date: Thu, 11 Aug 2016 18:07:01 +0200 Subject: [PATCH] Fix compiling on Mac OS X --- Makefile | 10 +++++++-- boden/wege/weg.cc | 2 +- convoy.cc | 6 +++--- dataobj/loadsave.cc | 1 + dings/crossing.cc | 2 +- dings/tunnel.cc | 2 +- dings/wayobj.cc | 2 +- freight_list_sorter.cc | 2 +- pthread_barrier.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ pthread_barrier.h | 25 +++++++++++++++++++++++ simsys_opengl.cc | 8 ++++++++ simview.cc | 1 + 12 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 pthread_barrier.cc create mode 100644 pthread_barrier.h diff --git a/Makefile b/Makefile index 8f42b86..d9ef39f 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ ifeq ($(OSTYPE),freebsd) endif ifeq ($(OSTYPE),mac) - CCFLAGS += -Os -fast + CCFLAGS += -Os -fast -I/usr/include LIBS += -lz -lbz2 endif @@ -337,6 +337,7 @@ SOURCES += gui/trafficlight_info.cc SOURCES += gui/welt.cc SOURCES += gui/werkzeug_waehler.cc SOURCES += old_blockmanager.cc +SOURCES += pthread_barrier.cc SOURCES += player/ai.cc SOURCES += player/ai_goods.cc SOURCES += player/ai_passenger.cc @@ -555,9 +556,14 @@ ifeq ($(BACKEND),opengl) endif endif CFLAGS += $(SDL_CFLAGS) - LIBS += $(SDL_LDFLAGS) -lglew32 + LIBS += $(SDL_LDFLAGS) + ifneq ($(OSTYPE),mac) + LIBS += -lglew32 + endif ifeq ($(OSTYPE),mingw) LIBS += -lopengl32 + else ifeq ($(OSTYPE),mac) + LIBS += -framework OpenGL else LIBS += -lGL endif diff --git a/boden/wege/weg.cc b/boden/wege/weg.cc index 9fdb65d..7f84e19 100644 --- a/boden/wege/weg.cc +++ b/boden/wege/weg.cc @@ -47,7 +47,7 @@ #if MULTI_THREAD>1 #include -static pthread_mutex_t weg_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t weg_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; #endif /** diff --git a/convoy.cc b/convoy.cc index b6759c5..ce59907 100644 --- a/convoy.cc +++ b/convoy.cc @@ -254,12 +254,12 @@ sint32 convoy_t::calc_max_weight(sint32 sin_alpha) { return 0; } - return abs(min(f, float32e8_t(get_starting_force())) / (_101_percent * g_accel * (adverse.fr + milli * sin_alpha))); + return abs(min(f, float32e8_t(get_starting_force())) / (_101_percent * g_accel * (adverse.fr + float32e8_t::milli * sin_alpha))); } sint32 convoy_t::calc_max_starting_weight(sint32 sin_alpha) { - return abs(get_starting_force() / (_101_percent * g_accel * (adverse.fr + milli * sin_alpha))); // 1.01 to compensate inaccuracy of calculation + return abs(get_starting_force() / (_101_percent * g_accel * (adverse.fr + float32e8_t::milli * sin_alpha))); // 1.01 to compensate inaccuracy of calculation } // The timeslice to calculate acceleration, speed and covered distance in reasonable small chuncks. @@ -433,7 +433,7 @@ void convoy_t::calc_move(const settings_t &settings, long delta_t, const weight_ { // don't run beyond xbrk, where we must start braking. x = xbrk; - if (xbrk > dx && abs(a) > milli) + if (xbrk > dx && abs(a) > float32e8_t::milli) { // turn back time to when we reached xbrk: dt_s = (sqrt(v0 * v0 + 2 * a * (xbrk - dx)) - v0) / a; diff --git a/dataobj/loadsave.cc b/dataobj/loadsave.cc index f72cec9..02704f5 100644 --- a/dataobj/loadsave.cc +++ b/dataobj/loadsave.cc @@ -30,6 +30,7 @@ // enable barriers by this #define _XOPEN_SOURCE 600 #include +#include "../pthread_barrier.h" static pthread_t ls_thread; static pthread_barrier_t loadsave_barrier; diff --git a/dings/crossing.cc b/dings/crossing.cc index 0165c6e..6f724f8 100644 --- a/dings/crossing.cc +++ b/dings/crossing.cc @@ -26,7 +26,7 @@ #if MULTI_THREAD>1 #include -static pthread_mutex_t crossing_logic_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t crossing_logic_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; #endif diff --git a/dings/tunnel.cc b/dings/tunnel.cc index 1473477..fead594 100644 --- a/dings/tunnel.cc +++ b/dings/tunnel.cc @@ -26,7 +26,7 @@ #if MULTI_THREAD>1 #include -static pthread_mutex_t tunnel_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t tunnel_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; #endif diff --git a/dings/wayobj.cc b/dings/wayobj.cc index 5a01c45..8b4e718 100644 --- a/dings/wayobj.cc +++ b/dings/wayobj.cc @@ -43,7 +43,7 @@ #if MULTI_THREAD>1 #include -static pthread_mutex_t wayobj_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t wayobj_calc_bild_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; #endif // the descriptions ... diff --git a/freight_list_sorter.cc b/freight_list_sorter.cc index 147173c..d66c451 100644 --- a/freight_list_sorter.cc +++ b/freight_list_sorter.cc @@ -15,7 +15,7 @@ #include "utils/cbuffer_t.h" // Necessary for MinGW -#include "malloc.h" +// #include "malloc.h" karte_t *freight_list_sorter_t::welt = NULL; diff --git a/pthread_barrier.cc b/pthread_barrier.cc new file mode 100644 index 0000000..5088a9b --- /dev/null +++ b/pthread_barrier.cc @@ -0,0 +1,55 @@ +#ifdef __APPLE__ + +#include "pthread_barrier.h" + +#include + +int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) +{ + if(count == 0) + { + errno = EINVAL; + return -1; + } + if(pthread_mutex_init(&barrier->mutex, 0) < 0) + { + return -1; + } + if(pthread_cond_init(&barrier->cond, 0) < 0) + { + pthread_mutex_destroy(&barrier->mutex); + return -1; + } + barrier->tripCount = count; + barrier->count = 0; + + return 0; +} + +int pthread_barrier_destroy(pthread_barrier_t *barrier) +{ + pthread_cond_destroy(&barrier->cond); + pthread_mutex_destroy(&barrier->mutex); + return 0; +} + +int pthread_barrier_wait(pthread_barrier_t *barrier) +{ + pthread_mutex_lock(&barrier->mutex); + ++(barrier->count); + if(barrier->count >= barrier->tripCount) + { + barrier->count = 0; + pthread_cond_broadcast(&barrier->cond); + pthread_mutex_unlock(&barrier->mutex); + return 1; + } + else + { + pthread_cond_wait(&barrier->cond, &(barrier->mutex)); + pthread_mutex_unlock(&barrier->mutex); + return 0; + } +} + +#endif // __APPLE__ diff --git a/pthread_barrier.h b/pthread_barrier.h new file mode 100644 index 0000000..15a7ab0 --- /dev/null +++ b/pthread_barrier.h @@ -0,0 +1,25 @@ +#ifdef __APPLE__ + +#ifndef PTHREAD_BARRIER_H_ +#define PTHREAD_BARRIER_H_ + +#include + +typedef int pthread_barrierattr_t; +typedef struct +{ + pthread_mutex_t mutex; + pthread_cond_t cond; + int count; + int tripCount; +} pthread_barrier_t; + + +int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count); + +int pthread_barrier_destroy(pthread_barrier_t *barrier); + +int pthread_barrier_wait(pthread_barrier_t *barrier); + +#endif // PTHREAD_BARRIER_H_ +#endif // __APPLE__ diff --git a/simsys_opengl.cc b/simsys_opengl.cc index 20cb79e..a637a60 100644 --- a/simsys_opengl.cc +++ b/simsys_opengl.cc @@ -16,8 +16,12 @@ #include +#ifdef __APPLE__ +#include +#else #include #include +#endif #include #include @@ -216,6 +220,8 @@ static void update_tex_dims(){ */ static void check_for_extensions(){ +#ifndef __APPLE__ + // Initialize GLEW GLenum err = glewInit(); if (GLEW_OK != err){ @@ -245,6 +251,8 @@ static void check_for_extensions(){ fprintf(stderr, "Renderer is not PBO able.\n"); DBG_MESSAGE("check_for_extensions(OpenGL)", "Renderer does NOT support PBO extension"); } + +#endif } diff --git a/simview.cc b/simview.cc index d3158c5..ca7f37f 100644 --- a/simview.cc +++ b/simview.cc @@ -44,6 +44,7 @@ static const sint8 hours2night[] = // enable barriers by this #define _XOPEN_SOURCE 600 #include +#include "pthread_barrier.h" bool spawned_threads=false; // global job indicator array static pthread_barrier_t display_barrier_start; --