diff options
author | bjarni <bjarni@openttd.org> | 2007-02-05 21:16:56 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2007-02-05 21:16:56 +0000 |
commit | ca1a88f6c4595c2a8250f13a2a3e218558306693 (patch) | |
tree | f736d2ea9376a1705983b456c6a998c6e7bf901c | |
parent | 1bf688e5b5a4d9cb509d06d0d2946cdca819f294 (diff) | |
download | openttd-ca1a88f6c4595c2a8250f13a2a3e218558306693.tar.xz |
(svn r8605) -Codechange: [OSX] changed all objective C to objective C++
This will permanently solve the issue where compilation on OSX broke because C++ code was added to some header files
-Note: (important if you develop mac specific code)
taken from http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html
gdb lacks an integrated C++ with Objective-C parser. This means that gdb won't be able to evaluate expressions that contain both C++ and Objective-C constructs.
gdb assumes that the language for ".mm" files is C++.
you can change it to objective C by typing: (gdb) set language objc
Mixing C++ and objective C has some limitation (see link for all of them)
-rw-r--r-- | Makefile.src.in | 18 | ||||
-rw-r--r-- | config.lib | 2 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | source.list | 4 | ||||
-rw-r--r-- | src/debug.h | 8 | ||||
-rw-r--r-- | src/gfx.h | 13 | ||||
-rw-r--r-- | src/hal.h | 8 | ||||
-rw-r--r-- | src/md5.h | 9 | ||||
-rw-r--r-- | src/os/macosx/macos.h | 12 | ||||
-rw-r--r-- | src/os/macosx/macos.mm (renamed from src/os/macosx/macos.m) | 0 | ||||
-rw-r--r-- | src/unix.cpp | 6 | ||||
-rw-r--r-- | src/video/cocoa_v.h | 15 | ||||
-rw-r--r-- | src/video/cocoa_v.mm (renamed from src/video/cocoa_v.m) | 57 |
13 files changed, 55 insertions, 99 deletions
diff --git a/Makefile.src.in b/Makefile.src.in index 06d6f43b7..8c9e4a8f8 100644 --- a/Makefile.src.in +++ b/Makefile.src.in @@ -35,9 +35,9 @@ CONFIG_CACHE_VERSION = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_VERSION!! OBJS_C := !!OBJS_C!! OBJS_CPP := !!OBJS_CPP!! -OBJS_M := !!OBJS_M!! +OBJS_MM := !!OBJS_MM!! OBJS_RC := !!OBJS_RC!! -OBJS := $(OBJS_C) $(OBJS_CPP) $(OBJS_M) $(OBJS_RC) +OBJS := $(OBJS_C) $(OBJS_CPP) $(OBJS_MM) $(OBJS_RC) SRCS := !!SRCS!! # All C-files depend on those 3 files @@ -126,12 +126,12 @@ $(OBJS_CPP:%.o=%.d): %.d: $(SRC_DIR)/%.cpp $(FILE_DEP) $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.cpp=%.cpp)' $(Q)$(CXX_HOST) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@ -$(OBJS_M:%.o=%.d): %.d: $(SRC_DIR)/%.m $(FILE_DEP) - $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.m=%.m)' - $(Q)$(CC_HOST) $(CC_CFLAGS) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@ +$(OBJS_MM:%.o=%.d): %.d: $(SRC_DIR)/%.mm $(FILE_DEP) + $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)' + $(Q)$(CC_HOST) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@ $(OBJS_RC:%.o=%.d): %.d: $(SRC_DIR)/%.rc $(FILE_DEP) - $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.m=%.m)' + $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)' $(Q)touch $@ else @@ -211,9 +211,9 @@ $(OBJS_CPP): %.o: $(SRC_DIR)/%.cpp $(DEP_MASK) $(FILE_DEP) $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)' $(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $< -$(OBJS_M): %.o: $(SRC_DIR)/%.m $(DEP_MASK) $(FILE_DEP) - $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.m=%.m)' - $(Q)$(CC_HOST) $(CC_CFLAGS) $(CFLAGS) -c -o $@ $< +$(OBJS_MM): %.o: $(SRC_DIR)/%.mm $(DEP_MASK) $(FILE_DEP) + $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.mm=%.mm)' + $(Q)$(CC_HOST) $(CFLAGS) -c -o $@ $< $(OBJS_RC): %.o: $(SRC_DIR)/%.rc $(FILE_DEP) $(E) '$(STAGE) Compiling resource $(<:$(SRC_DIR)/%.rc=%.rc)' diff --git a/config.lib b/config.lib index 804de5223..9189c30f9 100644 --- a/config.lib +++ b/config.lib @@ -1639,7 +1639,7 @@ make_sed() { s#!!LANG_SUPPRESS!!#$lang_suppress#g; s#!!OBJS_C!!#$OBJS_C#g; s#!!OBJS_CPP!!#$OBJS_CPP#g; - s#!!OBJS_M!!#$OBJS_M#g; + s#!!OBJS_MM!!#$OBJS_MM#g; s#!!OBJS_RC!!#$OBJS_RC#g; s#!!SRCS!!#$SRCS#g; s#!!OS!!#$os#g; @@ -100,7 +100,7 @@ SRCS="`< $ROOT_DIR/source.list tr '\r' '\n' | awk ' OBJS_C="` echo \"$SRCS\" | awk ' { ORS = " " } /\.c$/ { gsub(".c$", ".o", $0); print $0; }'`" OBJS_CPP="`echo \"$SRCS\" | awk ' { ORS = " " } /\.cpp$/ { gsub(".cpp$", ".o", $0); print $0; }'`" -OBJS_M="` echo \"$SRCS\" | awk ' { ORS = " " } /\.m$/ { gsub(".m$", ".o", $0); print $0; }'`" +OBJS_MM="` echo \"$SRCS\" | awk ' { ORS = " " } /\.mm$/ { gsub(".mm$", ".o", $0); print $0; }'`" OBJS_RC="` echo \"$SRCS\" | awk ' { ORS = " " } /\.rc$/ { gsub(".rc$", ".o", $0); print $0; }'`" SRCS="` echo \"$SRCS\" | awk ' { ORS = " " } { print $0; }'`" diff --git a/source.list b/source.list index 5966fa0db..e13d597e8 100644 --- a/source.list +++ b/source.list @@ -384,7 +384,7 @@ sound/null_s.cpp #if OSX # OSX Files - os/macosx/macos.m + os/macosx/macos.mm #if DEDICATED #else @@ -392,7 +392,7 @@ sound/null_s.cpp #end #if COCOA - video/cocoa_v.m + video/cocoa_v.mm sound/cocoa_s.cpp os/macosx/splash.cpp #end diff --git a/src/debug.h b/src/debug.h index 0e58dfdce..47d7855f9 100644 --- a/src/debug.h +++ b/src/debug.h @@ -3,10 +3,6 @@ #ifndef DEBUG_H #define DEBUG_H -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - /* Debugging messages policy: * These should be the severities used for direct DEBUG() calls * maximum debugging level should be 10 if really deep, deep @@ -111,8 +107,4 @@ const char *GetDebugString(void); }\ } -#ifdef __cplusplus -} -#endif //__cplusplus - #endif /* DEBUG_H */ @@ -3,11 +3,6 @@ #ifndef GFX_H #define GFX_H -/* !!! Note that the first part of this file if enclosed in extern "C" due to cocoa/obj-C !!! */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ enum WindowKeyCodes { WKC_SHIFT = 0x8000, @@ -175,10 +170,6 @@ void HandleExitGameRequest(void); void GameSizeChanged(void); void UndrawMouseCursor(void); -#ifdef __cplusplus -}; //extern "C" -/* Following part is only for C++ */ - #include "helpers.hpp" typedef enum FontSizes { @@ -245,7 +236,7 @@ void ScreenSizeChanged(void); void UndrawMouseCursor(void); bool ChangeResInGame(int w, int h); void SortResolutions(int count); -extern "C" void ToggleFullScreen(bool fs); +void ToggleFullScreen(bool fs); /* gfx.c */ #define ASCII_LETTERSTART 32 @@ -301,6 +292,4 @@ typedef enum StringColorFlags { extern bool _dbg_screen_rect; #endif -#endif /* __cplusplus */ - #endif /* GFX_H */ @@ -3,10 +3,6 @@ #ifndef HAL_H #define HAL_H -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - typedef struct { const char *(*start)(const char * const *parm); void (*stop)(void); @@ -46,8 +42,4 @@ enum DriverType { MUSIC_DRIVER = 2, }; -#ifdef __cplusplus -} // extern "C" -#endif //__cplusplus - #endif /* HAL_H */ @@ -72,11 +72,6 @@ typedef struct md5_state_s { md5_byte_t buf[64]; /* accumulate block */ } md5_state_t; -#ifdef __cplusplus -extern "C" -{ -#endif - /* Initialize the algorithm. */ void md5_init(md5_state_t *pms); @@ -86,8 +81,4 @@ void md5_append(md5_state_t *pms, const void *data, size_t nbytes); /* Finish the message and return the digest. */ void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); -#ifdef __cplusplus -} /* end extern "C" */ -#endif - #endif /* MD5_INCLUDED */ diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h index ba33ce602..b8a6cd511 100644 --- a/src/os/macosx/macos.h +++ b/src/os/macosx/macos.h @@ -11,15 +11,9 @@ * the function then adds text that tells the user to update and then report the bug if it's present in the newest version * It also quits in a nice way since we call it when we know something happened that will crash OpenTTD (like a needed pointer turns out to be NULL or similar) */ -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel ); - void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression ); - void ShowMacErrorDialog(const char *error); -#ifdef __cplusplus -} -#endif //__cplusplus +void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel ); +void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression ); +void ShowMacErrorDialog(const char *error); // Since MacOS X users will never see an assert unless they started the game from a terminal // we're using a custom assert(e) macro. diff --git a/src/os/macosx/macos.m b/src/os/macosx/macos.mm index 33f296325..33f296325 100644 --- a/src/os/macosx/macos.m +++ b/src/os/macosx/macos.mm diff --git a/src/unix.cpp b/src/unix.cpp index fa49eca4d..cee8082d9 100644 --- a/src/unix.cpp +++ b/src/unix.cpp @@ -127,9 +127,9 @@ void ShowOSErrorBox(const char *buf) } #ifdef WITH_COCOA -extern "C" void cocoaSetWorkingDirectory(void); -extern "C" void cocoaSetupAutoreleasePool(void); -extern "C" void cocoaReleaseAutoreleasePool(void); +void cocoaSetWorkingDirectory(void); +void cocoaSetupAutoreleasePool(void); +void cocoaReleaseAutoreleasePool(void); #endif int CDECL main(int argc, char* argv[]) diff --git a/src/video/cocoa_v.h b/src/video/cocoa_v.h index 42e55bcca..1512a0b64 100644 --- a/src/video/cocoa_v.h +++ b/src/video/cocoa_v.h @@ -5,22 +5,9 @@ #include "../hal.h" -#ifndef __cplusplus -/* Really ugly workaround - * It should be solved right as soon as possible */ -typedef uint32 SpriteID; -#endif //__cplusplus - +#include "../openttd.h" #include "../gfx.h" -#ifdef __cplusplus -extern "C" { -#endif //__cplusplus - extern const HalVideoDriver _cocoa_video_driver; -#ifdef __cplusplus -} // extern "C" -#endif //__cplusplus - #endif diff --git a/src/video/cocoa_v.m b/src/video/cocoa_v.mm index f476c905c..aaa9475ef 100644 --- a/src/video/cocoa_v.m +++ b/src/video/cocoa_v.mm @@ -13,19 +13,28 @@ #import <sys/param.h> /* for MAXPATHLEN */ #import <unistd.h> +/** + * Important notice regarding all modifications!!!!!!! + * There are certain limitations because the file is objective C++. + * gdb has limitations. + * C++ and objective C code can't be joined in all cases (classes stuff). + * Read http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html for more information. + */ + + /* Portions of CPS.h */ typedef struct CPSProcessSerNum { UInt32 lo; UInt32 hi; } CPSProcessSerNum; -extern OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn); -extern OSErr CPSEnableForegroundOperation(CPSProcessSerNum* psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); -extern OSErr CPSSetFrontProcess(CPSProcessSerNum* psn); +extern "C" OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn); +extern "C" OSErr CPSEnableForegroundOperation(CPSProcessSerNum* psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +extern "C" OSErr CPSSetFrontProcess(CPSProcessSerNum* psn); /* From Menus.h (according to Xcode Developer Documentation) */ -extern void ShowMenuBar(void); -extern void HideMenuBar(void); +extern "C" void ShowMenuBar(void); +extern "C" void HideMenuBar(void); /* Disables a warning. This is needed since the method exists but has been dropped from the header, supposedly as of 10.4. */ #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) @@ -353,7 +362,7 @@ static void QZ_DoUnsidedModifiers(unsigned int newMods) const int mapping[] = { QZ_CAPSLOCK, QZ_LSHIFT, QZ_LCTRL, QZ_LALT, QZ_LMETA }; int i; - int bit; + unsigned int bit; if (_cocoa_video_data.current_mods == newMods) return; @@ -817,7 +826,7 @@ static void QZ_SetPortAlphaOpaque(void) newViewFrame = [ _cocoa_video_data.qdview frame ]; /* Update the pixels and pitch */ - thePort = [ _cocoa_video_data.qdview qdPort ]; + thePort = (OpaqueGrafPtr*) [ _cocoa_video_data.qdview qdPort ]; LockPortBits(thePort); _cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap(thePort)); @@ -1083,7 +1092,7 @@ static void QZ_DrawWindow(void) QZ_DrawResizeIcon(); /* Flush the dirty region */ - QDFlushPortBuffer([ _cocoa_video_data.qdview qdPort ], dirty); + QDFlushPortBuffer( (OpaqueGrafPtr*) [ _cocoa_video_data.qdview qdPort ], dirty); DisposeRgn(dirty); DisposeRgn(temp); @@ -1163,10 +1172,12 @@ static const char* QZ_SetVideoWindowed(uint width, uint height) [ _cocoa_video_data.window makeKeyAndOrderFront:nil ]; } - LockPortBits([ _cocoa_video_data.qdview qdPort ]); - _cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); - _cocoa_video_data.pitch = GetPixRowBytes(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); - UnlockPortBits([ _cocoa_video_data.qdview qdPort ]); + CGrafPtr thePort = (OpaqueGrafPtr*) [ _cocoa_video_data.qdview qdPort ]; + + LockPortBits(thePort); + _cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap(thePort)); + _cocoa_video_data.pitch = GetPixRowBytes(GetPortPixMap(thePort)); + UnlockPortBits(thePort); /* _cocoa_video_data.realpixels now points to the window's pixels * We want it to point to the *view's* pixels @@ -1294,17 +1305,17 @@ static const char* QZ_SetVideoFullScreen(int width, int height) /* If the mode wasn't an exact match, check if it has the right bpp, and update width and height */ if (!exact_match) { - number = CFDictionaryGetValue (_cocoa_video_data.mode, kCGDisplayBitsPerPixel); + number = (const __CFNumber*) CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayBitsPerPixel); CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); if (bpp != 8) { errstr = "Failed to find display resolution"; goto ERR_NO_MATCH; } - number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayWidth); + number = (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayWidth); CFNumberGetValue(number, kCFNumberSInt32Type, &width); - number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayHeight); + number = (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayHeight); CFNumberGetValue(number, kCFNumberSInt32Type, &height); } @@ -1412,7 +1423,7 @@ static void QZ_WaitForVerticalBlank(void) double adjustment; CFNumberRef refreshRateCFNumber; - refreshRateCFNumber = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayRefreshRate); + refreshRateCFNumber = (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayRefreshRate); if (refreshRateCFNumber == NULL) return; if (CFNumberGetValue(refreshRateCFNumber, kCFNumberDoubleType, &refreshRate) == 0) @@ -1487,17 +1498,17 @@ static int QZ_ListFullscreenModes(OTTDPoint* mode_list, int max_modes) bool hasMode; uint16 width, height; - onemode = CFArrayGetValueAtIndex(_cocoa_video_data.mode_list, i); - number = CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); + onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(_cocoa_video_data.mode_list, i); + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); if (bpp != 8) continue; - number = CFDictionaryGetValue(onemode, kCGDisplayWidth); + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); width = (uint16)intvalue; - number = CFDictionaryGetValue(onemode, kCGDisplayHeight); + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); height = (uint16)intvalue; @@ -1713,17 +1724,17 @@ static void QZ_VideoInit(void) /* Gather some information that is useful to know about the display */ /* Maybe this should be moved to QZ_SetVideoMode, in case this is changed after startup */ CFNumberGetValue( - CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayBitsPerPixel), + (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayBitsPerPixel), kCFNumberSInt32Type, &_cocoa_video_data.device_bpp ); CFNumberGetValue( - CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayWidth), + (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayWidth), kCFNumberSInt32Type, &_cocoa_video_data.device_width ); CFNumberGetValue( - CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayHeight), + (const __CFNumber*)CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayHeight), kCFNumberSInt32Type, &_cocoa_video_data.device_height ); |