mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Reworked the sfml-main module, added Main.hpp, moved the main() internal entry point for iOS from sfml-window to sfml-main
This commit is contained in:
parent
b9fd685a60
commit
3872b27569
@ -212,12 +212,15 @@ macro(sfml_add_example target)
|
||||
# set a source group for the source files
|
||||
source_group("" FILES ${THIS_SOURCES})
|
||||
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND SFML_OS_WINDOWS)
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND SFML_OS_WINDOWS)
|
||||
add_executable(${target} WIN32 ${THIS_SOURCES})
|
||||
target_link_libraries(${target} sfml-main)
|
||||
elseif(IOS)
|
||||
add_executable(${target} MACOSX_BUNDLE ${THIS_SOURCES})
|
||||
if(THIS_GUI_APP)
|
||||
target_link_libraries(${target} sfml-main)
|
||||
endif()
|
||||
else()
|
||||
add_executable(${target} ${THIS_SOURCES})
|
||||
endif()
|
||||
@ -261,6 +264,13 @@ macro(sfml_add_example target)
|
||||
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples
|
||||
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
||||
|
||||
# fix install rules broken in CMake (see http://public.kitware.com/Bug/view.php?id=12506)
|
||||
if(IOS)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/\$ENV{CONFIGURATION}\$ENV{EFFECTIVE_PLATFORM_NAME}/${target}.app
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples)
|
||||
endif()
|
||||
|
||||
# install the example's source code
|
||||
install(FILES ${THIS_SOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
|
@ -4,6 +4,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <SFML/Main.hpp>
|
||||
|
||||
|
||||
// Some platform-specific stuff
|
||||
|
@ -4,6 +4,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include "Effect.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Main.hpp>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <SFML/Main.hpp>
|
||||
|
||||
|
||||
// Some platform-specific stuff
|
||||
|
@ -31,10 +31,12 @@
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
// On iOS, we have no choice but to have our own main,
|
||||
// so we need to rename the user one and call it later
|
||||
#if defined(SFML_SYSTEM_IOS)
|
||||
|
||||
// On iOS, we have no choice but to have our own main,
|
||||
// so we need to rename the user one and call it later
|
||||
#define main sfmlMain
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/Joystick.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/Window/Main.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
|
@ -43,8 +43,6 @@ add_subdirectory(Window)
|
||||
add_subdirectory(Network)
|
||||
add_subdirectory(Graphics)
|
||||
if(NOT SFML_OS_IOS)
|
||||
add_subdirectory(Audio)
|
||||
endif()
|
||||
if(SFML_OS_WINDOWS OR SFML_OS_ANDROID)
|
||||
add_subdirectory(Main)
|
||||
add_subdirectory(Audio)
|
||||
endif()
|
||||
add_subdirectory(Main)
|
||||
|
@ -1,8 +1,17 @@
|
||||
|
||||
set(INCROOT ${PROJECT_SOURCE_DIR}/include/SFML/Main)
|
||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/Main)
|
||||
|
||||
# sources
|
||||
set(SRC
|
||||
${PROJECT_SOURCE_DIR}/src/SFML/Main/SFML_Main.cpp
|
||||
)
|
||||
if(WINDOWS)
|
||||
set(SRC ${SRC} ${SRCROOT}/MainWin32.cpp)
|
||||
elseif(IOS)
|
||||
set(SRC ${SRC} ${SRCROOT}/MainiOS.mm)
|
||||
elseif(ANDROID)
|
||||
set(SRC ${SRC} ${SRCROOT}/MainAndroid.cpp)
|
||||
else()
|
||||
return()
|
||||
endif()
|
||||
source_group("" FILES ${SRC})
|
||||
|
||||
if(NOT ANDROID)
|
||||
|
@ -23,48 +23,9 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Windows specific : defines the WinMain entry function,
|
||||
// so that developers can use the standard main function
|
||||
// even in a Win32 Application project, and keep a portable code
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
extern int main(int argc, char* argv[]);
|
||||
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
|
||||
{
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Windows specific : defines the WinMain entry function,
|
||||
// so that developers can use the standard main function
|
||||
// even in a Win32 Application project, and keep a portable code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
extern int main(int argc, char* argv[]);
|
||||
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
|
||||
{
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
|
||||
|
||||
#elif defined(__ANDROID__)
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
@ -700,4 +661,4 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
|
||||
activity->instance = states;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // SFML_SYSTEM_ANDROID
|
@ -1,38 +1,54 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/iOS/SFAppDelegate.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
[SFAppDelegate main:argc argv:argv];
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
|
||||
// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Windows specific: we define the WinMain entry point,
|
||||
// so that developers can use the standard main function
|
||||
// even in a Win32 Application project, and thus keep a
|
||||
// portable code
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
#ifdef SFML_SYSTEM_WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
extern int main(int argc, char* argv[]);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
|
||||
{
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
|
||||
#endif // SFML_SYSTEM_WINDOWS
|
||||
|
63
src/SFML/Main/MainiOS.mm
Normal file
63
src/SFML/Main/MainiOS.mm
Normal file
@ -0,0 +1,63 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
|
||||
// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// iOS specific: SFML needs to hook the main function, to
|
||||
// launch the iOS application (event loop), and then call the
|
||||
// user main from inside it.
|
||||
//
|
||||
// Our strategy is to rename the user main to 'sfmlMain' with
|
||||
// a macro (see Main.hpp), and call this modified main ourselves.
|
||||
//
|
||||
// Note that half of this trick (the sfmlMain placeholders and
|
||||
// the application delegate) is defined sfml-window; see there
|
||||
// for the full implementation.
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Note: we intentionally drop command line arguments,
|
||||
// there's no such thing as a command line on an iOS device :)
|
||||
|
||||
// Important: "SFAppDelegate" must always match the name of the
|
||||
// application delegate class defined in sfml-window
|
||||
|
||||
return UIApplicationMain(argc, argv, nil, @"SFAppDelegate");
|
||||
}
|
||||
|
||||
#endif // SFML_SYSTEM_IOS
|
@ -21,7 +21,6 @@ set(SRC
|
||||
${SRCROOT}/JoystickManager.hpp
|
||||
${INCROOT}/Keyboard.hpp
|
||||
${SRCROOT}/Keyboard.cpp
|
||||
${INCROOT}/Main.hpp
|
||||
${INCROOT}/Mouse.hpp
|
||||
${SRCROOT}/Mouse.cpp
|
||||
${SRCROOT}/VideoMode.cpp
|
||||
@ -127,7 +126,6 @@ elseif(IOS)
|
||||
${SRCROOT}/iOS/VideoModeImpl.mm
|
||||
${SRCROOT}/iOS/WindowImplUIKit.hpp
|
||||
${SRCROOT}/iOS/WindowImplUIKit.mm
|
||||
${SRCROOT}/iOS/Main.mm
|
||||
${SRCROOT}/iOS/ObjCType.hpp
|
||||
${SRCROOT}/iOS/SFAppDelegate.hpp
|
||||
${SRCROOT}/iOS/SFAppDelegate.mm
|
||||
|
@ -41,12 +41,6 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface SFAppDelegate : NSObject<UIApplicationDelegate>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Run the application
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
+(int)main:(int)argc argv:(char**)argv;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the instance of the application delegate
|
||||
///
|
||||
|
@ -31,10 +31,6 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
// Save the main's arguments, to pass them back to the user's main
|
||||
int mainArgc;
|
||||
char** mainArgv;
|
||||
|
||||
// Save the global instance of the delegate
|
||||
SFAppDelegate* delegateInstance = NULL;
|
||||
}
|
||||
@ -53,15 +49,6 @@ namespace
|
||||
@synthesize sfWindow;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
+(int)main:(int)argc argv:(char**)argv
|
||||
{
|
||||
mainArgc = argc;
|
||||
mainArgv = argv;
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SFAppDelegate class]));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
+(SFAppDelegate*)getInstance
|
||||
{
|
||||
@ -72,7 +59,8 @@ namespace
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)runUserMain
|
||||
{
|
||||
sfmlMain(mainArgc, mainArgv);
|
||||
// Arguments intentionally dropped, see comments in main in sfml-main
|
||||
sfmlMain(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,14 +28,23 @@
|
||||
#include <SFML/Window/iOS/SFMain.hpp>
|
||||
|
||||
|
||||
// We declare both versions of sfmlMain, but with the 'weak' attribute (GCC extension)
|
||||
// so that the user-declared one will replace SFML's one at linking stage.
|
||||
// sfmlMain is called by the application delegate (SFAppDelegate).
|
||||
//
|
||||
// If user defines main(argc, argv) then it will be called directly,
|
||||
// if he defines main() then it will be called by our placeholder.
|
||||
// Since we don't know which prototype of main the user
|
||||
// defines, we declare both versions of sfmlMain, but with
|
||||
// the 'weak' attribute (GCC extension) so that the
|
||||
// user-declared one will replace SFML's one at linking stage.
|
||||
//
|
||||
// The sfmlMain() version is never called, it is just defined to avoid a
|
||||
// linker error if the user directly defines the version with arguments.
|
||||
// If user defines main(argc, argv) then it will be called
|
||||
// directly, if he defines main() then it will be called by
|
||||
// our placeholder.
|
||||
//
|
||||
// The sfmlMain() version is never called, it is just defined
|
||||
// to avoid a linker error if the user directly defines the
|
||||
// version with arguments.
|
||||
//
|
||||
// See the sfml-main module for the other half of this
|
||||
// initialization trick.
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user