Commit 10bf6924 authored by Gerhard Stein's avatar Gerhard Stein Committed by Gerhard Stein

GsKit back as Sources (Removed submodule stuff)

parent 1785d0d8
# CMake file for development of Commander Genius (taken from OLX)
# This CMake file is used under Linux normally.
cmake_minimum_required(VERSION 3.1)
OPTION(USE_SDL2 "SDL2 support" Yes)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
IF(WIN32)
ADD_DEFINITIONS(-DWIN32)
ENDIF(WIN32)
IF (OPENGL)
ADD_DEFINITIONS(-DGL)
ADD_DEFINITIONS(-DUSE_OPENGL)
ENDIF (OPENGL)
# If we want to debug set the proper flags or have release etc.
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG)
ADD_DEFINITIONS(-g)
ADD_DEFINITIONS(-O0)
ADD_DEFINITIONS(-Wall)
ELSEIF(CMAKE_BUILD_TYPE STREQUAL "Release")
ADD_DEFINITIONS(-DRELEASE)
ADD_DEFINITIONS(-O3)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(USE_SDL2)
FIND_PACKAGE(SDL2)
if(SDL2_FOUND)
message(STATUS "Using shared SDL Version 2 for Commander Genius")
include_directories(${SDL2_INCLUDE_DIRS})
message(STATUS "Using shared SDL Version 2 for Commander Genius")
set(SDL2_INCLUDE_DIRS /Library/Frameworks/SDL2.framework/Headers)
set(SDL2_IMAGE_INCLUDE_DIRS /Library/Frameworks/SDL2_image.framework/Headers)
include_directories(${SDL2_INCLUDE_DIR})
include_directories(${SDL2_NET_INCLUDE_DIRS})
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
#include_directories(${SDL2_NET_INCLUDE_DIRS})
endif(SDL2_FOUND)
else(USE_SDL2)
INCLUDE(FindPkgConfig)
# SDL2 not found, try to use SDL1.2
FIND_PACKAGE( SDL REQUIRED )
FIND_PACKAGE( SDL_image REQUIRED )
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include(FindSDL OPTIONAL)
endif()
if(SDL_FOUND)
message(STATUS "Using shared SDL Version 1.2")
include_directories(${SDL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIRS})
else(SDL_FOUND)
# TODO: Use the prebuilt one on Windows
message("Using static SDL from Externals")
include_directories(Externals/SDL Externals/SDL/include)
add_subdirectory(Externals/SDL)
endif(SDL_FOUND)
endif(USE_SDL2)
# Use python3 for AI scripting and more!
IF(USE_PYTHON3)
# Look for Python (Version 3.0 or later is required)
FIND_PACKAGE(PythonLibs)
ADD_DEFINITIONS(-DUSE_PYTHON3=1)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS})
LINK_LIBRARIES(${PYTHON_LIBRARIES})
ENDIF()
Project(GsKit)
# From this point files are globbed for compilation and project setup
file(GLOB_RECURSE ALL_SRCS_GSKIT_BASE *.c* *.h*)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
if(USE_SDL2)
find_package(SDL2 REQUIRED)
if(SDL2_FOUND)
find_package(SDL2_image REQUIRED)
message(STATUS "Using shared SDL Version 2 for Commander Genius")
include_directories(${SDL2_INCLUDE_DIRS})
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
endif(SDL2_FOUND)
endif()
IF(OPENGL)
# OpenGL Parsing
find_package(OpenGL REQUIRED)
ADD_DEFINITIONS(-DGL)
ADD_DEFINITIONS(-DUSE_OPENGL)
ENDIF (OPENGL)
add_library(GsKit ${ALL_SRCS_GSKIT_BASE})
# NOTE: The naming with the new Find cmake files is strange sometimes.
# Some use the "2" as var name others not.
if(USE_SDL2)
Target_link_libraries(GsKit ${SDL2_LIBRARIES})
Target_link_libraries(GsKit ${SDL2_LIBRARY})
Target_link_libraries(GsKit ${SDL2IMAGE_LIBRARIES})
Target_link_libraries(GsKit ${SDLIMAGE_LIBRARY})
else()
Target_link_libraries(GsKit ${SDL_LIBRARY})
Target_link_libraries(GsKit ${SDL_LIBRARIES})
Target_link_libraries(GsKit ${SDL_IMAGE_LIBRARY})
endif()
IF(OPENGL)
# OpenGL stuff to link
target_link_libraries(GsKit ${OPENGL_LIBRARIES})
ENDIF(OPENGL)
cotire(GsKit)
# Locate SDL2 library
# 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 SDL2_main 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 SDL2main.h and SDL2main.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" SDL2 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" SDL2 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).
#
# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
# was not created for redistribution, and exists temporarily pending official
# SDL2 CMake modules.
#=============================================================================
# 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.)
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include/SDL2
/usr/include/SDL2
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
#MESSAGE("SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIR}")
FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
#MESSAGE("SDL2_LIBRARY_TEMP is ${SDL2_LIBRARY_TEMP}")
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
/sw
/opt/local
/opt/csw
/opt
)
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)
SET(SDL2_FOUND "NO")
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 "")
SET(SDL2_FOUND "YES")
ENDIF(SDL2_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
# Locate SDL_image library
# This module defines
# SDLIMAGE_LIBRARY, the name of the library to link against
# SDLIMAGE_FOUND, if false, do not try to link to SDL
# SDLIMAGE_INCLUDE_DIR, where to find SDL/SDL.h
#
# $SDLDIR is an environment variable that would
# correspond to the ./configure --prefix=$SDLDIR
# used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-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.)
FIND_PATH(SDLIMAGE_INCLUDE_DIR SDL2/SDL_image.h
HINTS
$ENV{SDLIMAGEDIR}
$ENV{SDLDIR}
PATH_SUFFIXES include
PATHS
../SDL2_image/prefix
~/Library/Frameworks
/Library/Frameworks
/usr/local/include/SDL
/usr/include/SDL
/usr/local/include/SDL12
/usr/local/include/SDL11 # FreeBSD ports
/usr/include/SDL12
/usr/include/SDL11
/usr/local/include
/usr/include
/sw/include/SDL # Fink
/sw/include
/opt/local/include/SDL # DarwinPorts
/opt/local/include
/opt/csw/include/SDL # Blastwave
/opt/csw/include
/opt/include/SDL
/opt/include
)
SET(SDLIMAGE_INCLUDE_DIR ${SDLIMAGE_INCLUDE_DIR}/SDL2)
FIND_LIBRARY(SDLIMAGE_LIBRARY
NAMES SDL2_image
HINTS
$ENV{SDLIMAGEDIR}
$ENV{SDLDIR}
PATH_SUFFIXES lib64 lib
PATHS
../SDL2_image/prefix
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
)
SET(SDLIMAGE_FOUND "NO")
IF(SDLIMAGE_LIBRARY AND SDLIMAGE_INCLUDE_DIR)
SET(SDLIMAGE_FOUND "YES")
ENDIF(SDLIMAGE_LIBRARY AND SDLIMAGE_INCLUDE_DIR)
message("SDLIMAGE INCLUDE DIR " ${SDLIMAGE_INCLUDE_DIR})
message("SDLIMAGE_LIBRARY " ${SDLIMAGE_LIBRARY})
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* CInput.h
*
* Created on: 20.03.2009
* Author: gerstrong
*/
#ifndef CINPUT_H_
#define CINPUT_H_
#include <SDL.h>
#include <string>
#include <list>
#include <base/utils/Geometry.h>
#include <base/GsEvent.h>
#include <base/InputEvents.h>
#include <base/Singleton.h>
#include <base/GsVirtualinput.h>
#define gInput CInput::get()
// key defines, locations in keytable[]
enum keys{
// Ascii keys
KSPACE = 32,
KEXCLAIM,
KDBLQUOTE,
KHASH,
KDOLLAR,
KPERCENT,
KAMPERSAND,
KQUOTE,
KLEFTPAREN,
KRIGHTPAREN,
KAST,
KPLUS,
KCOMMA,
KMINUS,
KPERIOD,
KSLASH,
KNUM0,
KNUM1,
KNUM2,
KNUM3,
KNUM4,
KNUM5,
KNUM6,
KNUM7,
KNUM8,
KNUM9,
KCOLON,
KSEMICOLON,
KLESS,
KEQUAL,
KGREATER,
KQUESTION,
KAT,
KLEFTBRACKET = 91,
KBACKSLASH,
KRIGHTBRACKET,
KCARET,
KUNDERSCORE,
KBACKQUOTE,
KA,
KB,
KC,
KD,
KE,
KF,
KG,
KH,
KI,
KJ,
KK,
KL,
KM,
KN,
KO,
KP,
KQ,
KR,
KS,
KT,
KU,
KV,
KW,
KX,
KY,
KZ,
KLEFTBRACE,
KLINE,
KRIGHTBRACE,
KTILDE,
// Non Ascii Keys
KSHIFT,
KPGUP,
KPGDN,
KQUIT,
KLEFT,
KRIGHT,
KUP,
KDOWN,
KCTRL, // simply, CTRL, mapped to JUMP or FIRE
KALT, // simply, ALT, mapped to POGO or fire
KENTER,
KF1,
KF2,
KF3,
KF4,
KF5,
KF6,
KF7,
KF8,
KF9,
KF10,
KTAB,
KBCKSPCE,
};
const unsigned int KEYTABLE_SIZE = 160;
#define NUM_INPUTS 4
enum EType
{
ETYPE_KEYBOARD, ETYPE_JOYAXIS,
ETYPE_JOYBUTTON, ETYPE_JOYHAT,
};
struct stInputCommand
{
bool active;
bool lastactive;
bool firsttimeactive;
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Keycode keysym;
#else
SDLKey keysym;
#endif
unsigned int joyeventtype;
int which;
int joyaxis;
unsigned short joybutton;
int joyvalue; // in which direction the axis needs to be moved
int joymotion; // in which direction the axis is really moved
int joyhatval; // in which direction the hat is really moved
};
class CInput : public GsSingleton<CInput>
{
public:
CInput();
/**
* @brief transMouseRelCoord transforms a mouse click from the screen coordinates to the relative coordinates
* @param Pos Resulting relative coordinate to handle
* @param motion SDL Motion Event in which the raw pointer position is requested
* @param activeArea Area which is seen and interacted.
*/
void transMouseRelCoord(Vector2D<float> &Pos,
const SDL_MouseMotionEvent motion,
const GsRect<Uint16> &activeArea);
void pollEvents();
bool getHoldedKey(int key);
bool getPressedKey(int key);
bool getPulsedKey(int key, int msec);
bool getPressedIsTypingKey(void);
bool getPressedIsNumKey(void);
std::string getPressedTypingKey(void);
std::string getPressedNumKey(void);
bool getPressedAnyKey(void);
void sendKey(int key);
bool mouseClicked();
bool getPressedAnyCommand();
bool getPulsedCommand(int command, int msec);
bool getPulsedCommand(int player, int command, int msec);
bool isJoystickAssgmnt(const int player, const int command);
bool getHoldedCommand(int player, int command);
int getJoyValue(int player, int command);
bool getHoldedCommand(int command);
bool getPressedCommand(int command);
bool getPressedCommand(int player, int command);
bool getPressedAnyCommand(const int player);
bool getPressedAnyButtonCommand(const int player);
bool getExitEvent()
{ return m_exit; }
bool getTwoButtonFiring(int player);
void setTwoButtonFiring(int player, bool value);
bool isAnalog(const int player);
void enableAnalog(const int player, const bool value);
bool SuperPogo(const int player) { return mSuperPogo[player]; }
void setSuperPogo(const int player, const bool value) { mSuperPogo[player] = value; }
bool ImpossiblePogo(const int player) { return mImpPogo[player]; }
void setImpossiblePogo(const int player, const bool value) { mImpPogo[player] = value; }
bool AutoGun(const int player) { return mFullyAutomatic[player]; }
void setAutoGun(const int player, const bool value) { mFullyAutomatic[player] = value; }
/**
* @brief render will render stuff the input want's to get on the screen.
* These are usually overlay where you can touch or click, like virtual gamepads.
*/
void render();
/**
* \brief This checks what event has been assigned to the chosen command and builds a string calling it
* a standardized way.
* \param command command where you are looking for the event
* \param input number of input chosen. it's normal the number of the player
* \return returns the assigned event as a std::string
* \note getEventShortName is the short name version for menu prints
*/
std::string getEventName(int command, unsigned char input);
std::string getEventShortName(int command, unsigned char input);
std::string getNewMappedEvent(int &rPos, unsigned char &rInp);
void readNewEvent();
void waitForAnyInput();
void setupNewEvent(Uint8 device, int position);
void setupInputCommand( stInputCommand *pInput, int action, const std::string &string );
void loadControlconfig();
void resetControls(int player);
bool startJoyDriver();
void saveControlconfig();
void flushCommands();
void flushCommand(int command);
void flushCommand(int player, int command);
/**
* @brief setCommand Sets a given command.
* @param player player to which the command wil be setCommand;
* @param command Command object to be set
* @param active Will the command be set active or unactive
*/
void setCommand(const int player, const int command, const bool active)
{
InputCommand[player][command].active = active;
}
void flushKeys();
void flushEvents();
void flushAll();
void renderOverlay(); // for mouse wrapper gfx or other stuff
void shutdown();
bool MappingInput()
{ return remapper.mappingInput; }
/**
* @brief readSDLEventVec Use this for engine which want to access the SDL Events directly
*/
bool readSDLEventVec(std::vector<SDL_Event> &evVec);
/**
* @brief pushBackButtonEventExtEng Use this if want to add the event that normally would
* make open the menu. This event will be processed by the engine for other stuff
*/
void pushBackButtonEventExtEng();
// One virtual input overlay can be active be processed. This is useful for game to ported on mobile devices
std::unique_ptr<GsVirtualInput> mpVirtPad;
private: