From 8d16c2e3c0d4e90cd45702ed81e12f2200347721 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 14 Dec 2014 11:29:28 +0200 Subject: [PATCH] OS X native backend no longer use files from src/sdl directly Cocoa backend is compiling but failed to link Some files are referenced using symbolic links Apple's HID Utilities were moved to own directory --- src/CMakeLists.txt | 72 +++++++++++--------- src/cocoa/critsec.cpp | 62 +++++++++++++++++ src/cocoa/critsec.h | 53 ++++++++++++++ src/cocoa/dikeys.h | 1 + src/cocoa/hardware.h | 1 + src/cocoa/{ => hid}/HID_Config_Utilities.c | 0 src/cocoa/{ => hid}/HID_Error_Handler.c | 0 src/cocoa/{ => hid}/HID_Name_Lookup.c | 0 src/cocoa/{ => hid}/HID_Queue_Utilities.c | 0 src/cocoa/{ => hid}/HID_Utilities.c | 0 src/cocoa/{ => hid}/HID_Utilities_External.h | 0 src/cocoa/{ => hid}/IOHIDDevice_.c | 0 src/cocoa/{ => hid}/IOHIDDevice_.h | 0 src/cocoa/{ => hid}/IOHIDElement_.c | 0 src/cocoa/{ => hid}/IOHIDElement_.h | 0 src/cocoa/{ => hid}/IOHIDLib_.h | 0 src/cocoa/{ => hid}/ImmrHIDUtilAddOn.c | 0 src/cocoa/{ => hid}/ImmrHIDUtilAddOn.h | 0 src/cocoa/i_backend_cocoa.mm | 42 ------------ src/cocoa/i_cd.cpp | 1 + src/cocoa/i_input.h | 1 + src/cocoa/i_joystick.cpp | 2 +- src/cocoa/i_movie.cpp | 1 + src/cocoa/i_system.h | 1 + src/cocoa/st_start.cpp | 1 + 25 files changed, 161 insertions(+), 77 deletions(-) create mode 100644 src/cocoa/critsec.cpp create mode 100644 src/cocoa/critsec.h create mode 120000 src/cocoa/dikeys.h create mode 120000 src/cocoa/hardware.h rename src/cocoa/{ => hid}/HID_Config_Utilities.c (100%) rename src/cocoa/{ => hid}/HID_Error_Handler.c (100%) rename src/cocoa/{ => hid}/HID_Name_Lookup.c (100%) rename src/cocoa/{ => hid}/HID_Queue_Utilities.c (100%) rename src/cocoa/{ => hid}/HID_Utilities.c (100%) rename src/cocoa/{ => hid}/HID_Utilities_External.h (100%) rename src/cocoa/{ => hid}/IOHIDDevice_.c (100%) rename src/cocoa/{ => hid}/IOHIDDevice_.h (100%) rename src/cocoa/{ => hid}/IOHIDElement_.c (100%) rename src/cocoa/{ => hid}/IOHIDElement_.h (100%) rename src/cocoa/{ => hid}/IOHIDLib_.h (100%) rename src/cocoa/{ => hid}/ImmrHIDUtilAddOn.c (100%) rename src/cocoa/{ => hid}/ImmrHIDUtilAddOn.h (100%) create mode 120000 src/cocoa/i_cd.cpp create mode 120000 src/cocoa/i_input.h create mode 120000 src/cocoa/i_movie.cpp create mode 120000 src/cocoa/i_system.h create mode 120000 src/cocoa/st_start.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61fea294dd..2e6bb59f50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -545,7 +545,7 @@ set( PLAT_WIN32_SOURCES win32/i_system.cpp win32/st_start.cpp win32/win32video.cpp ) -set( PLAT_SDL_SYSTEM_SOURCES +set( PLAT_SDL_SOURCES sdl/crashcatcher.c sdl/hardware.cpp sdl/i_cd.cpp @@ -553,8 +553,7 @@ set( PLAT_SDL_SYSTEM_SOURCES sdl/i_movie.cpp sdl/i_system.cpp sdl/sdlvideo.cpp - sdl/st_start.cpp ) -set( PLAT_SDL_SPECIAL_SOURCES + sdl/st_start.cpp sdl/i_gui.cpp sdl/i_input.cpp sdl/i_joystick.cpp @@ -563,39 +562,27 @@ set( PLAT_MAC_SOURCES cocoa/iwadpicker_cocoa.mm cocoa/i_system_cocoa.mm ) set( PLAT_COCOA_SOURCES - cocoa/HID_Config_Utilities.c - cocoa/HID_Error_Handler.c - cocoa/HID_Name_Lookup.c - cocoa/HID_Queue_Utilities.c - cocoa/HID_Utilities.c - cocoa/IOHIDDevice_.c - cocoa/IOHIDElement_.c - cocoa/ImmrHIDUtilAddOn.c + cocoa/hid/HID_Config_Utilities.c + cocoa/hid/HID_Error_Handler.c + cocoa/hid/HID_Name_Lookup.c + cocoa/hid/HID_Queue_Utilities.c + cocoa/hid/HID_Utilities.c + cocoa/hid/IOHIDDevice_.c + cocoa/hid/IOHIDElement_.c + cocoa/hid/ImmrHIDUtilAddOn.c + cocoa/critsec.cpp cocoa/i_backend_cocoa.mm + cocoa/i_cd.cpp cocoa/i_joystick.cpp + cocoa/i_movie.cpp + cocoa/st_start.cpp cocoa/i_timer.cpp cocoa/zdoom.icns ) -if( APPLE ) - set( PLAT_SDL_SOURCES ${PLAT_SDL_SYSTEM_SOURCES} "${FMOD_LIBRARY}" ) - - if( OSX_COCOA_BACKEND ) - set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} ) - add_definitions( -DUSE_NATIVE_COCOA ) - else( OSX_COCOA_BACKEND ) - set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} ) - endif( OSX_COCOA_BACKEND ) - - set_source_files_properties( cocoa/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) - set_source_files_properties( "${FMOD_LIBRARY}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks ) -else( APPLE ) - set( PLAT_SDL_SOURCES ${PLAT_SDL_SYSTEM_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} ) -endif( APPLE ) - if( WIN32 ) set( SYSTEM_SOURCES_DIR win32 ) set( SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ) - set( OTHER_SYSTEM_SOURCES ${PLAT_SDL_SOURCES} ${PLAT_MAC_SOURCES} ) + set( OTHER_SYSTEM_SOURCES ${PLAT_SDL_SOURCES} ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} ) if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) # CMake is not set up to compile and link rc files with GCC. :( @@ -606,15 +593,25 @@ if( WIN32 ) else( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) set( SYSTEM_SOURCES ${SYSTEM_SOURCES} win32/zdoom.rc ) endif( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) +elseif( APPLE ) + if( OSX_COCOA_BACKEND ) + set( SYSTEM_SOURCES_DIR cocoa ) + set( SYSTEM_SOURCES ${PLAT_COCOA_SOURCES} ) + set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_SDL_SOURCES} ) + else( OSX_COCOA_BACKEND ) + set( SYSTEM_SOURCES_DIR sdl ) + set( SYSTEM_SOURCES ${PLAT_SDL_SOURCES} ) + set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_COCOA_SOURCES} ) + endif( OSX_COCOA_BACKEND ) + + set( SYSTEM_SOURCES ${SYSTEM_SOURCES} ${PLAT_MAC_SOURCES} "${FMOD_LIBRARY}" ) + + set_source_files_properties( cocoa/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) + set_source_files_properties( "${FMOD_LIBRARY}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks ) else( WIN32 ) set( SYSTEM_SOURCES_DIR sdl ) set( SYSTEM_SOURCES ${PLAT_SDL_SOURCES} ) - if( APPLE ) - set( SYSTEM_SOURCES ${SYSTEM_SOURCES} ${PLAT_MAC_SOURCES} ) - set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ) - else( APPLE ) - set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_MAC_SOURCES} ) - endif( APPLE ) + set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} ) endif( WIN32 ) if( NOT ASM_SOURCES ) @@ -672,11 +669,18 @@ endif( DYN_FLUIDSYNTH ) # there's generally a new cpp for every header so this file will get changed if( WIN32 ) set( EXTRA_HEADER_DIRS win32/*.h ) +elseif( APPLE ) + if( OSX_COCOA_BACKEND ) + set( EXTRA_HEADER_DIRS cocoa/*.h ) + else( OSX_COCOA_BACKEND ) + set( EXTRA_HEADER_DIRS sdl/*.h ) + endif( OSX_COCOA_BACKEND ) else( WIN32 ) set( EXTRA_HEADER_DIRS sdl/*.h ) endif( WIN32 ) file( GLOB HEADER_FILES ${EXTRA_HEADER_DIRS} + cocoa/*.h fragglescript/*.h g_doom/*.h g_heretic/*.h diff --git a/src/cocoa/critsec.cpp b/src/cocoa/critsec.cpp new file mode 100644 index 0000000000..97bc2251c2 --- /dev/null +++ b/src/cocoa/critsec.cpp @@ -0,0 +1,62 @@ +/* + ** critsec.cpp + ** + **--------------------------------------------------------------------------- + ** Copyright 2014 Alexey Lysiuk + ** All rights reserved. + ** + ** Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions + ** are met: + ** + ** 1. Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** 2. Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in the + ** documentation and/or other materials provided with the distribution. + ** 3. The name of the author may not be used to endorse or promote products + ** derived from this software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **--------------------------------------------------------------------------- + ** + */ + +#include "critsec.h" + +// TODO: add error handling + +FCriticalSection::FCriticalSection() +{ + pthread_mutexattr_t attributes; + pthread_mutexattr_init(&attributes); + pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); + + pthread_mutex_init(&m_mutex, &attributes); + + pthread_mutexattr_destroy(&attributes); +} + +FCriticalSection::~FCriticalSection() +{ + pthread_mutex_destroy(&m_mutex); +} + +void FCriticalSection::Enter() +{ + pthread_mutex_lock(&m_mutex); +} + +void FCriticalSection::Leave() +{ + pthread_mutex_unlock(&m_mutex); +} diff --git a/src/cocoa/critsec.h b/src/cocoa/critsec.h new file mode 100644 index 0000000000..20c476ae3e --- /dev/null +++ b/src/cocoa/critsec.h @@ -0,0 +1,53 @@ +/* + ** critsec.h + ** + **--------------------------------------------------------------------------- + ** Copyright 2014 Alexey Lysiuk + ** All rights reserved. + ** + ** Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions + ** are met: + ** + ** 1. Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** 2. Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in the + ** documentation and/or other materials provided with the distribution. + ** 3. The name of the author may not be used to endorse or promote products + ** derived from this software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **--------------------------------------------------------------------------- + ** + */ + +#ifndef CRITSEC_H +#define CRITSEC_H + +#include + +class FCriticalSection +{ +public: + FCriticalSection(); + ~FCriticalSection(); + + void Enter(); + void Leave(); + +private: + pthread_mutex_t m_mutex; + +}; + +#endif diff --git a/src/cocoa/dikeys.h b/src/cocoa/dikeys.h new file mode 120000 index 0000000000..011f85acb9 --- /dev/null +++ b/src/cocoa/dikeys.h @@ -0,0 +1 @@ +../sdl/dikeys.h \ No newline at end of file diff --git a/src/cocoa/hardware.h b/src/cocoa/hardware.h new file mode 120000 index 0000000000..4261b94778 --- /dev/null +++ b/src/cocoa/hardware.h @@ -0,0 +1 @@ +../sdl/hardware.h \ No newline at end of file diff --git a/src/cocoa/HID_Config_Utilities.c b/src/cocoa/hid/HID_Config_Utilities.c similarity index 100% rename from src/cocoa/HID_Config_Utilities.c rename to src/cocoa/hid/HID_Config_Utilities.c diff --git a/src/cocoa/HID_Error_Handler.c b/src/cocoa/hid/HID_Error_Handler.c similarity index 100% rename from src/cocoa/HID_Error_Handler.c rename to src/cocoa/hid/HID_Error_Handler.c diff --git a/src/cocoa/HID_Name_Lookup.c b/src/cocoa/hid/HID_Name_Lookup.c similarity index 100% rename from src/cocoa/HID_Name_Lookup.c rename to src/cocoa/hid/HID_Name_Lookup.c diff --git a/src/cocoa/HID_Queue_Utilities.c b/src/cocoa/hid/HID_Queue_Utilities.c similarity index 100% rename from src/cocoa/HID_Queue_Utilities.c rename to src/cocoa/hid/HID_Queue_Utilities.c diff --git a/src/cocoa/HID_Utilities.c b/src/cocoa/hid/HID_Utilities.c similarity index 100% rename from src/cocoa/HID_Utilities.c rename to src/cocoa/hid/HID_Utilities.c diff --git a/src/cocoa/HID_Utilities_External.h b/src/cocoa/hid/HID_Utilities_External.h similarity index 100% rename from src/cocoa/HID_Utilities_External.h rename to src/cocoa/hid/HID_Utilities_External.h diff --git a/src/cocoa/IOHIDDevice_.c b/src/cocoa/hid/IOHIDDevice_.c similarity index 100% rename from src/cocoa/IOHIDDevice_.c rename to src/cocoa/hid/IOHIDDevice_.c diff --git a/src/cocoa/IOHIDDevice_.h b/src/cocoa/hid/IOHIDDevice_.h similarity index 100% rename from src/cocoa/IOHIDDevice_.h rename to src/cocoa/hid/IOHIDDevice_.h diff --git a/src/cocoa/IOHIDElement_.c b/src/cocoa/hid/IOHIDElement_.c similarity index 100% rename from src/cocoa/IOHIDElement_.c rename to src/cocoa/hid/IOHIDElement_.c diff --git a/src/cocoa/IOHIDElement_.h b/src/cocoa/hid/IOHIDElement_.h similarity index 100% rename from src/cocoa/IOHIDElement_.h rename to src/cocoa/hid/IOHIDElement_.h diff --git a/src/cocoa/IOHIDLib_.h b/src/cocoa/hid/IOHIDLib_.h similarity index 100% rename from src/cocoa/IOHIDLib_.h rename to src/cocoa/hid/IOHIDLib_.h diff --git a/src/cocoa/ImmrHIDUtilAddOn.c b/src/cocoa/hid/ImmrHIDUtilAddOn.c similarity index 100% rename from src/cocoa/ImmrHIDUtilAddOn.c rename to src/cocoa/hid/ImmrHIDUtilAddOn.c diff --git a/src/cocoa/ImmrHIDUtilAddOn.h b/src/cocoa/hid/ImmrHIDUtilAddOn.h similarity index 100% rename from src/cocoa/ImmrHIDUtilAddOn.h rename to src/cocoa/hid/ImmrHIDUtilAddOn.h diff --git a/src/cocoa/i_backend_cocoa.mm b/src/cocoa/i_backend_cocoa.mm index 6abf1b7d1f..be2d142764 100644 --- a/src/cocoa/i_backend_cocoa.mm +++ b/src/cocoa/i_backend_cocoa.mm @@ -1625,48 +1625,6 @@ const char* I_GetBackEndName() extern "C" { -struct SDL_mutex -{ - pthread_mutex_t mutex; -}; - - -SDL_mutex* SDL_CreateMutex() -{ - pthread_mutexattr_t attributes; - pthread_mutexattr_init(&attributes); - pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); - - SDL_mutex* result = new SDL_mutex; - - if (0 != pthread_mutex_init(&result->mutex, &attributes)) - { - delete result; - result = NULL; - } - - pthread_mutexattr_destroy(&attributes); - - return result; -} - -int SDL_mutexP(SDL_mutex* mutex) -{ - return pthread_mutex_lock(&mutex->mutex); -} - -int SDL_mutexV(SDL_mutex* mutex) -{ - return pthread_mutex_unlock(&mutex->mutex); -} - -void SDL_DestroyMutex(SDL_mutex* mutex) -{ - pthread_mutex_destroy(&mutex->mutex); - delete mutex; -} - - static timeval s_startTicks; uint32_t SDL_GetTicks() diff --git a/src/cocoa/i_cd.cpp b/src/cocoa/i_cd.cpp new file mode 120000 index 0000000000..5573d7e1e4 --- /dev/null +++ b/src/cocoa/i_cd.cpp @@ -0,0 +1 @@ +../sdl/i_cd.cpp \ No newline at end of file diff --git a/src/cocoa/i_input.h b/src/cocoa/i_input.h new file mode 120000 index 0000000000..208b03106f --- /dev/null +++ b/src/cocoa/i_input.h @@ -0,0 +1 @@ +../sdl/i_input.h \ No newline at end of file diff --git a/src/cocoa/i_joystick.cpp b/src/cocoa/i_joystick.cpp index 56db8f815d..234f94c8ee 100644 --- a/src/cocoa/i_joystick.cpp +++ b/src/cocoa/i_joystick.cpp @@ -37,7 +37,7 @@ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 -#include "HID_Utilities_External.h" +#include "hid/HID_Utilities_External.h" #include "d_event.h" #include "doomdef.h" diff --git a/src/cocoa/i_movie.cpp b/src/cocoa/i_movie.cpp new file mode 120000 index 0000000000..04258f3e56 --- /dev/null +++ b/src/cocoa/i_movie.cpp @@ -0,0 +1 @@ +../sdl/i_movie.cpp \ No newline at end of file diff --git a/src/cocoa/i_system.h b/src/cocoa/i_system.h new file mode 120000 index 0000000000..ced5163114 --- /dev/null +++ b/src/cocoa/i_system.h @@ -0,0 +1 @@ +../sdl/i_system.h \ No newline at end of file diff --git a/src/cocoa/st_start.cpp b/src/cocoa/st_start.cpp new file mode 120000 index 0000000000..38ce4fa1c7 --- /dev/null +++ b/src/cocoa/st_start.cpp @@ -0,0 +1 @@ +../sdl/st_start.cpp \ No newline at end of file