Skip to content
Permalink
Browse files

Start of SDL2 port

It runs!
  • Loading branch information...
oyvindln committed Mar 13, 2016
1 parent 8df683a commit b07768d152e80df66ad4bff4c526317692e8936e
Showing with 904 additions and 238 deletions.
  1. +57 −53 CMakeLists.txt
  2. +169 −0 cmake/Modules/FindSDL2.cmake
  3. +83 −0 cmake/Modules/FindSDL2_gfx.cmake
  4. +100 −0 cmake/Modules/FindSDL2_image.cmake
  5. +83 −0 cmake/Modules/FindSDL2_mixer.cmake
  6. +98 −0 cmake/Modules/FindSDL2_ttf.cmake
  7. +23 −0 cmake/Modules/module_licences.md
  8. +23 −0 cmake/Modules/module_licences.md~
  9. +12 −12 src/Addons.cpp
  10. +2 −2 src/Addons.h
  11. +1 −1 src/Block.h
  12. +81 −42 src/Functions.cpp
  13. +1 −1 src/Functions.h
  14. +2 −2 src/GUIListBox.cpp
  15. +8 −6 src/GUIObject.cpp
  16. +3 −3 src/GUIOverlay.cpp
  17. +1 −1 src/GUIOverlay.h
  18. +4 −4 src/GUISpinBox.cpp
  19. +7 −7 src/GUITextArea.cpp
  20. +1 −1 src/GUITextArea.h
  21. +3 −3 src/Game.cpp
  22. +3 −3 src/Game.h
  23. +1 −1 src/GameObjects.h
  24. +9 −2 src/Globals.cpp
  25. +11 −5 src/Globals.h
  26. +10 −4 src/ImageManager.cpp
  27. +2 −2 src/ImageManager.h
  28. +4 −2 src/InputManager.cpp
  29. +1 −1 src/InputManager.h
  30. +1 −1 src/LevelEditSelect.cpp
  31. +2 −2 src/LevelEditSelect.h
  32. +23 −20 src/LevelEditor.cpp
  33. +2 −2 src/LevelEditor.h
  34. +2 −2 src/LevelPack.h
  35. +2 −2 src/LevelPackManager.h
  36. +1 −1 src/LevelPlaySelect.cpp
  37. +2 −2 src/LevelPlaySelect.h
  38. +12 −7 src/LevelSelect.cpp
  39. +2 −2 src/LevelSelect.h
  40. +15 −8 src/Main.cpp
  41. +2 −2 src/MusicManager.h
  42. +3 −3 src/Player.cpp
  43. +3 −3 src/Player.h
  44. +1 −1 src/Scenery.h
  45. +1 −1 src/Settings.cpp
  46. +2 −2 src/SoundManager.h
  47. +4 −3 src/StatisticsManager.cpp
  48. +1 −1 src/StatisticsManager.h
  49. +13 −9 src/StatisticsScreen.cpp
  50. +1 −1 src/StatisticsScreen.h
  51. +1 −1 src/ThemeManager.cpp
  52. +3 −2 src/ThemeManager.h
  53. +1 −1 src/Timer.cpp
  54. +1 −1 src/TitleMenu.h
@@ -1,9 +1,10 @@
Project (meandmyshadow)
CMake_Minimum_Required (VERSION 2.6)
CMake_Minimum_Required (VERSION 2.8)
Set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

#Option if the game should be compiled with hardware acceleration.
Option (HARDWARE_ACCELERATION "Use openGL as rendering backend" ON)
#Option (HARDWARE_ACCELERATION "Use openGL as rendering backend" OFF)
Set (HARDWARE_ACCELERATION OFF)
Option (DEBUG_MODE "Compile the game with debug mode enabled" OFF)

#Use openGL only when compiling with HARDWARE_ACCELERATION.
@@ -18,40 +19,40 @@ else (HARDWARE_ACCELERATION)
endif (HARDWARE_ACCELERATION)

#Find the required libraries.
Find_Package (SDL REQUIRED)
Find_Package (SDL_gfx REQUIRED)
Find_Package (SDL_image REQUIRED)
Find_Package (SDL_ttf REQUIRED)
Find_Package (SDL_mixer REQUIRED)
Find_Package (SDL2 REQUIRED)
Find_Package (SDL2_gfx REQUIRED)
Find_Package (SDL2_image REQUIRED)
Find_Package (SDL2_ttf REQUIRED)
Find_Package (SDL2_mixer REQUIRED)
Find_Package (CURL REQUIRED)
Find_Package (LibArchive REQUIRED)
Find_Package (Lua51 REQUIRED)
Find_Package (Lua REQUIRED)

if (HARDWARE_ACCELERATION AND NOT OPENGL_FOUND)
message (FATAL_ERROR "OpenGL library could not be found!")
elseif (NOT HARDWARE_ACCELERATION AND NOT X11_FOUND)
message (FATAL_ERROR "X11 library could not be found!")
endif (HARDWARE_ACCELERATION AND NOT OPENGL_FOUND)

if (NOT SDL_FOUND)
message (FATAL_ERROR "SDL library could not be found!")
endif (NOT SDL_FOUND)
if (NOT SDL2_FOUND)
message (FATAL_ERROR "SDL2 library could not be found!")
endif (NOT SDL2_FOUND)

if (NOT SDLGFX_FOUND)
message (FATAL_ERROR "SDL_gfx library could not be found!")
endif (NOT SDLGFX_FOUND)
if (NOT SDL2_GFX_FOUND)
message (FATAL_ERROR "SDL2_gfx library could not be found!")
endif (NOT SDL2_GFX_FOUND)

if (NOT SDLIMAGE_FOUND)
message (FATAL_ERROR "SDL_gfx library could not be found!")
endif (NOT SDLIMAGE_FOUND)
if (NOT SDL2_IMAGE_FOUND)
message (FATAL_ERROR "SDL2_image library could not be found!")
endif (NOT SDL2_IMAGE_FOUND)

if (NOT SDLTTF_FOUND)
message (FATAL_ERROR "SDL_ttf library could not be found!")
endif (NOT SDLTTF_FOUND)
if (NOT SDL2_TTF_FOUND)
message (FATAL_ERROR "SDL2_ttf library could not be found!")
endif (NOT SDL2_TTF_FOUND)

if (NOT SDLMIXER_FOUND)
message (FATAL_ERROR "SDL_mixer library could not be found!")
endif (NOT SDLMIXER_FOUND)
if (NOT SDL2_MIXER_FOUND)
message (FATAL_ERROR "SDL2_mixer library could not be found!")
endif (NOT SDL2_MIXER_FOUND)

if (NOT CURL_FOUND)
message(FATAL_ERROR "CURL library could not be found!")
@@ -61,28 +62,31 @@ if (NOT LibArchive_FOUND)
message (FATAL_ERROR "LibArchive library could not be found!")
endif (NOT LibArchive_FOUND)

if (NOT LUA51_FOUND)
if (NOT LUA_FOUND)
message (FATAL_ERROR "Lua library could not be found!")
endif (NOT LUA51_FOUND)

#Although Lua is found it could be the wrong version.
#Try to find the header file and extract the Lua version, if we don't find the header file carry on.
if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
#Open the file and extract the version define lines.
file (STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_M(AJ|IN)OR[ \t]")
#Extract only the numbers from the files.
string (REGEX MATCHALL "[0-9]" LUA_VERSION_STRING "${lua_version_str}")
string (COMPARE EQUAL "${LUA_VERSION_STRING}" "5;2" LUA_VERSION_MATCH)
endif (NOT LUA_FOUND)

##Although Lua is found it could be the wrong version.
##Try to find the header file and extract the Lua version, if we don't find the header file carry on.
#if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
# #Open the file and extract the version define lines.
# file (STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_M(AJ|IN)OR[ \t]")
# #Extract only the numbers from the files.
# string (REGEX MATCHALL "[0-9]" LUA_VERSION_STRING "${lua_version_str}")
# string (COMPARE EQUAL "${LUA_VERSION_STRING}" "5;2" LUA_VERSION_MATCH)

if (NOT LUA_VERSION_MATCH)
message (FATAL_ERROR "Incorrect Lua version ${LUA_VERSION_STRING}, expected 5.2!")
endif (NOT LUA_VERSION_MATCH)

#Finally unset the unneeded variables.
unset (lua_version_str)
unset (LUA_VERSION_STRING)
unset (LUA_VERSION_MATCH)
endif()
# if (NOT LUA_VERSION_MATCH)
# message (FATAL_ERROR "Incorrect Lua version ${LUA_VERSION_STRING}, expected 5.2!")
# endif (NOT LUA_VERSION_MATCH)

# #Finally unset the unneeded variables.
# unset (lua_version_str)
# unset (LUA_VERSION_STRING)
# unset (LUA_VERSION_MATCH)
#endif()
if (LUA_VERSION_STRING VERSION_LESS "5.2")
message (FATAL_ERROR "Lua version too old ${LUA_VERSION_STRING}, expected at least 5.2!")
endif ()

#Parse the configure file.
Configure_File (
@@ -95,11 +99,11 @@ Include_Directories(
${PROJECT_BINARY_DIR}
${X11_X11_INCLUDE_PATH}
${OPENGL_gl_INCLUDE_DIR}
${SDL_INCLUDE_DIR}
${SDLGFX_INCLUDE_DIR}
${SDLIMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${SDLMIXER_INCLUDE_DIR}
${SDL2_INCLUDE_DIR}
${SDL2_GFX_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR}
${CURL_INCLUDE_DIR}
${LibArchive_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
@@ -120,11 +124,11 @@ Target_Link_Libraries (
meandmyshadow
${OPENGL_gl_LIBRARY}
${X11_X11_LIB}
${SDL_LIBRARY}
${SDLGFX_LIBRARY}
${SDLIMAGE_LIBRARY}
${SDLTTF_LIBRARY}
${SDLMIXER_LIBRARY}
${SDL2_LIBRARY}
${SDL2_GFX_LIBRARY}
${SDL2_IMAGE_LIBRARY}
${SDL2_TTF_LIBRARY}
${SDL2_MIXER_LIBRARY}
${CURL_LIBRARY}
${LibArchive_LIBRARY}
${LUA_LIBRARIES}
@@ -0,0 +1,169 @@

# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).

#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

message("<FindSDL2.cmake>")

SET(SDL2_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
${SDL2_PATH}
)

FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS}
)

FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)

IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDL2main for compatibility even though they don't
# necessarily need it.
FIND_LIBRARY(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)

# SDL2 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
IF(NOT APPLE)
FIND_PACKAGE(Threads)
ENDIF(NOT APPLE)

# MinGW needs an additional library, mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
# (Actually on second look, I think it only needs one of the m* libraries.)
IF(MINGW)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)

IF(SDL2_LIBRARY_TEMP)
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)

# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
ENDIF(APPLE)

# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
ENDIF(NOT APPLE)

# For MinGW library
IF(MINGW)
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(MINGW)

# Set the final string here so the GUI reflects the final state.
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)

message("</FindSDL2.cmake>")

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

Oops, something went wrong.

0 comments on commit b07768d

Please sign in to comment.
You can’t perform that action at this time.