commit
db37e875d4
35 changed files with 592 additions and 151 deletions
|
@ -1,9 +1,13 @@
|
|||
project(taisei)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${taisei_SOURCE_DIR}/cmake" "${taisei_SOURCE_DIR}/cmake/sdl2")
|
||||
|
||||
if(NOT DEFINED USE_SDL2_PATHS)
|
||||
set(USE_SDL2_PATHS BOOL TRUE)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DRELATIVE)
|
||||
set(RELATIVE TRUE)
|
||||
endif()
|
||||
|
||||
|
@ -14,17 +18,16 @@ endif()
|
|||
add_subdirectory(src)
|
||||
|
||||
if(RELATIVE)
|
||||
add_definitions(-DRELATIVE)
|
||||
set(DATA_DIR "data")
|
||||
|
||||
install(FILES "story.txt" DESTINATION .)
|
||||
else()
|
||||
set(DATA_DIR "share/taisei")
|
||||
endif()
|
||||
|
||||
if(NOT RELATIVE)
|
||||
install(FILES "taisei.desktop" DESTINATION "share/applications")
|
||||
install(FILES "taisei.png" DESTINATION "share/icons/hicolor/128x128/apps")
|
||||
install(FILES "story.txt" DESTINATION ${DATA_DIR})
|
||||
else()
|
||||
install(FILES "story.txt" DESTINATION .)
|
||||
install(FILES "taisei.desktop" DESTINATION "share/applications")
|
||||
install(FILES "taisei.png" DESTINATION "share/icons/hicolor/128x128/apps")
|
||||
install(FILES "story.txt" DESTINATION ${DATA_DIR})
|
||||
endif()
|
||||
|
||||
install(DIRECTORY gfx DESTINATION ${DATA_DIR}
|
||||
|
@ -44,4 +47,4 @@ configure_file(
|
|||
IMMEDIATE @ONLY)
|
||||
|
||||
add_custom_target(uninstall
|
||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Taisei
|
||||
Taisei
|
||||
|
||||
## Introduction
|
||||
|
||||
|
@ -8,7 +8,7 @@ shoot-em-up games set in an isolated world full of Japanese folklore.
|
|||
## Installation
|
||||
|
||||
Dependencies:
|
||||
* SDL, SDL\_ttf
|
||||
* SDL2, SDL2\_ttf
|
||||
* libpng, ZLIB
|
||||
* OpenGL
|
||||
* OpenAL, ALUT
|
||||
|
|
167
cmake/sdl2/FindSDL2.cmake
Normal file
167
cmake/sdl2/FindSDL2.cmake
Normal file
|
@ -0,0 +1,167 @@
|
|||
|
||||
# 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 lib/x64 lib/x86
|
||||
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 lib/x64 lib/x86
|
||||
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 link flag, -mwindows
|
||||
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
|
||||
IF(MINGW)
|
||||
SET(MINGW32_LIBRARY mingw32 "-mwindows" 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)
|
98
cmake/sdl2/FindSDL2_ttf.cmake
Normal file
98
cmake/sdl2/FindSDL2_ttf.cmake
Normal file
|
@ -0,0 +1,98 @@
|
|||
# Locate SDL_image library
|
||||
#
|
||||
# This module defines:
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# SDL_TTF_LIBRARIES, the name of the library to link against
|
||||
# SDL_TTF_INCLUDE_DIRS, where to find the headers
|
||||
# SDL_TTF_FOUND, if false, do not try to link against
|
||||
# SDL_F_VERSION_STRING - human-readable string containing the version of SDL_ttf
|
||||
#
|
||||
#
|
||||
#
|
||||
# For backward compatiblity the following variables are also set:
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# SDLTTF_LIBRARY (same value as SDL_TTF_LIBRARIES)
|
||||
# SDLTTF_INCLUDE_DIR (same value as SDL_TTF_INCLUDE_DIRS)
|
||||
# SDLTTF_FOUND (same value as SDL_TTF_FOUND)
|
||||
#
|
||||
#
|
||||
#
|
||||
# $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.
|
||||
# Copyright 2012 Benjamin Eikel
|
||||
#
|
||||
# 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_TTF_INCLUDE_DIR SDL_ttf.h
|
||||
HINTS
|
||||
ENV SDL2TTFDIR
|
||||
ENV SDL2DIR
|
||||
PATH_SUFFIXES SDL2
|
||||
# path suffixes to search inside ENV{SDLDIR}
|
||||
include/SDL2 include
|
||||
PATHS ${SDL2_PATH}
|
||||
)
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(VC_LIB_PATH_SUFFIX lib/x64)
|
||||
else ()
|
||||
set(VC_LIB_PATH_SUFFIX lib/x86)
|
||||
endif ()
|
||||
|
||||
find_library(SDL2_TTF_LIBRARY
|
||||
NAMES SDL2_ttf
|
||||
HINTS
|
||||
ENV SDL2TTFDIR
|
||||
ENV SDL2DIR
|
||||
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
|
||||
PATHS ${SDL2_PATH}
|
||||
)
|
||||
|
||||
if (SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h")
|
||||
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+[0-9]+$")
|
||||
file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+[0-9]+$")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}")
|
||||
string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}")
|
||||
set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH})
|
||||
unset(SDL2_TTF_VERSION_MAJOR_LINE)
|
||||
unset(SDL2_TTF_VERSION_MINOR_LINE)
|
||||
unset(SDL2_TTF_VERSION_PATCH_LINE)
|
||||
unset(SDL2_TTF_VERSION_MAJOR)
|
||||
unset(SDL2_TTF_VERSION_MINOR)
|
||||
unset(SDL2_TTF_VERSION_PATCH)
|
||||
endif ()
|
||||
|
||||
set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY})
|
||||
set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf
|
||||
REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS
|
||||
VERSION_VAR SDL2_TTF_VERSION_STRING)
|
||||
|
||||
# for backward compatiblity
|
||||
#set(SDLTTF_LIBRARY ${SDL_TTF_LIBRARIES})
|
||||
#set(SDLTTF_INCLUDE_DIR ${SDL_TTF_INCLUDE_DIRS})
|
||||
#set(SDLTTF_FOUND ${SDL_TTF_FOUND})
|
1
cmake/sdl2/SOURCE
Normal file
1
cmake/sdl2/SOURCE
Normal file
|
@ -0,0 +1 @@
|
|||
https://github.com/tcbrindle/sdl2-cmake-scripts
|
|
@ -1,11 +1,11 @@
|
|||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
|
||||
|
||||
find_package(SDL REQUIRED)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(OpenAL REQUIRED)
|
||||
find_package(ALUT REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
find_package(SDL_ttf REQUIRED)
|
||||
find_package(SDL2_ttf REQUIRED)
|
||||
find_package(Freetype)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OGG)
|
||||
|
@ -81,7 +81,9 @@ if(VORBISFILE_FOUND)
|
|||
add_definitions(-DOGG_SUPPORT_ENABLED)
|
||||
endif()
|
||||
|
||||
if(RELATIVE)
|
||||
if(USE_SDL2_PATHS)
|
||||
set(SRCs ${SRCs} paths/sdl.c)
|
||||
elseif(RELATIVE)
|
||||
set(SRCs ${SRCs} paths/relative.c)
|
||||
else()
|
||||
set(SRCs ${SRCs} paths/static.c)
|
||||
|
@ -93,6 +95,10 @@ endif()
|
|||
|
||||
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}" -Wall -Wno-parentheses)
|
||||
|
||||
if(RELATIVE)
|
||||
add_definitions(-DRELATIVE)
|
||||
endif()
|
||||
|
||||
if(TAISEI_DEBUG)
|
||||
add_definitions(-DDEBUG)
|
||||
if(TAISEI_IDDQD)
|
||||
|
@ -109,9 +115,9 @@ if(FATALERRS)
|
|||
endif()
|
||||
|
||||
set(LIBs ${LIBs}
|
||||
${SDL_LIBRARY}
|
||||
${PNG_LIBRARY}
|
||||
${SDLTTF_LIBRARY}
|
||||
${SDL2_LIBRARY}
|
||||
${SDL2_TTF_LIBRARIES}
|
||||
${PNG_LIBRARY}
|
||||
${OPENAL_LIBRARY}
|
||||
${ALUT_LIBRARY}
|
||||
${OPENGL_LIBRARY}
|
||||
|
@ -140,7 +146,7 @@ if(WIN32)
|
|||
set(SRCs ${SRCs} taisei.rc)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SDL_INCLUDE_DIR} ${ALUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SDL2_INCLUDE_DIR} ${ALUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${PNG_INCLUDE_DIR})
|
||||
add_executable(taisei WIN32 ${SRCs})
|
||||
target_link_libraries(taisei ${LIBs})
|
||||
|
||||
|
|
17
src/config.c
17
src/config.c
|
@ -233,7 +233,7 @@ void config_save(char *filename) {
|
|||
break;
|
||||
|
||||
case CFGT_KEYBINDING:
|
||||
fprintf(out, "%s = K%i\n", e->name, config_intval_p(e));
|
||||
fprintf(out, "%s = %s\n", e->name, SDL_GetKeyName(config_intval_p(e)));
|
||||
break;
|
||||
|
||||
case CFGT_STRING:
|
||||
|
@ -257,7 +257,7 @@ void config_set(char *key, char *val) {
|
|||
ConfigEntry *e = config_findentry(key);
|
||||
|
||||
if(!e) {
|
||||
warnx("config_set(): unknown key '%s'", key);
|
||||
warnx("config_set(): unknown setting '%s'", key);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -266,9 +266,18 @@ void config_set(char *key, char *val) {
|
|||
tconfig.intval[e->key] = INTOF(val);
|
||||
break;
|
||||
|
||||
case CFGT_KEYBINDING:
|
||||
tconfig.intval[e->key] = INTOF(val+1);
|
||||
case CFGT_KEYBINDING: {
|
||||
SDL_Keycode k = SDL_GetKeyFromName(val);
|
||||
|
||||
if(k == SDLK_UNKNOWN) {
|
||||
warnx("config_set(): unknown key '%s'", val);
|
||||
} else {
|
||||
tconfig.intval[e->key] = k;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case CFGT_STRING:
|
||||
stralloc(&(tconfig.strval[e->key]), val);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <SDL/SDL_keysym.h>
|
||||
#include <SDL_keycode.h>
|
||||
|
||||
typedef struct Config {
|
||||
int intval[64];
|
||||
|
|
|
@ -255,7 +255,7 @@ void credits_loop(void) {
|
|||
credits_process();
|
||||
credits_draw();
|
||||
global.frames++;
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(video.window);
|
||||
frame_rate(&global.lasttime);
|
||||
}
|
||||
credits_free();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ending.h"
|
||||
#include "global.h"
|
||||
#include "video.h"
|
||||
|
||||
void add_ending_entry(Ending *e, int dur, char *msg, char *tex) {
|
||||
EndingEntry *entry;
|
||||
|
@ -131,7 +132,7 @@ void ending_loop(void) {
|
|||
|
||||
ending_draw(&e);
|
||||
global.frames++;
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(video.window);
|
||||
frame_rate(&global.lasttime);
|
||||
|
||||
if(global.frames >= e.entries[e.pos+1].time)
|
||||
|
|
59
src/events.c
59
src/events.c
|
@ -6,7 +6,6 @@
|
|||
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
|
||||
*/
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include "events.h"
|
||||
#include "config.h"
|
||||
#include "global.h"
|
||||
|
@ -15,17 +14,27 @@
|
|||
|
||||
void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
||||
SDL_Event event;
|
||||
Uint8 *keys = SDL_GetKeyState(NULL);
|
||||
const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||
|
||||
int kbd = flags & EF_Keyboard;
|
||||
int text = flags & EF_Text;
|
||||
int menu = flags & EF_Menu;
|
||||
int game = flags & EF_Game;
|
||||
|
||||
if(text) SDL_EnableUNICODE(True);
|
||||
|
||||
// TODO: rewrite text input handling to properly support multibyte characters and IMEs
|
||||
|
||||
if(text) {
|
||||
if(!SDL_IsTextInputActive()) {
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
} else {
|
||||
if(SDL_IsTextInputActive()) {
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
int sym = event.key.keysym.sym;
|
||||
int uni = event.key.keysym.unicode;
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
|
@ -33,14 +42,12 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
take_screenshot();
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef WIN32 // TODO: remove when we're on SDL2
|
||||
if((sym == SDLK_RETURN && (keys[SDLK_LALT] || keys[SDLK_RALT])) || sym == tconfig.intval[KEY_FULLSCREEN]) {
|
||||
|
||||
if((sym == SDLK_RETURN && (keys[SDL_SCANCODE_LALT] || keys[SDL_SCANCODE_RALT])) || sym == tconfig.intval[KEY_FULLSCREEN]) {
|
||||
video_toggle_fullscreen();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if(kbd)
|
||||
handler(E_KeyDown, sym, arg);
|
||||
|
||||
|
@ -60,7 +67,7 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
}
|
||||
}
|
||||
|
||||
if(game) {
|
||||
if(game && !event.key.repeat) {
|
||||
if(sym == SDLK_ESCAPE)
|
||||
handler(E_Pause, 0, arg);
|
||||
else {
|
||||
|
@ -77,9 +84,6 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
handler(E_SubmitText, 0, arg);
|
||||
else if(sym == SDLK_BACKSPACE)
|
||||
handler(E_CharErased, 0, arg);
|
||||
else if(uni && sym != SDLK_TAB) {
|
||||
handler(E_CharTyped, uni, arg);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -88,7 +92,7 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
if(kbd)
|
||||
handler(E_KeyUp, sym, arg);
|
||||
|
||||
if(game) {
|
||||
if(game && !event.key.repeat) {
|
||||
int key = config_sym2key(sym);
|
||||
if(key >= 0)
|
||||
handler(E_PlrKeyUp, key, arg);
|
||||
|
@ -96,6 +100,30 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT: {
|
||||
char *c;
|
||||
|
||||
for(c = event.text.text; *c; ++c) {
|
||||
handler(E_CharTyped, *c, arg);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch(event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
video_resize(event.window.data1, event.window.data2);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if(game) {
|
||||
handler(E_Pause, 0, arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
exit(0);
|
||||
break;
|
||||
|
@ -105,5 +133,4 @@ void handle_events(EventHandler handler, EventFlags flags, void *arg) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(text) SDL_EnableUNICODE(False);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
|
||||
*/
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include "gamepad.h"
|
||||
#include "taisei_err.h"
|
||||
#include "config.h"
|
||||
|
@ -36,7 +35,7 @@ void gamepad_init(void) {
|
|||
int i, cnt = gamepad_devicecount();
|
||||
printf("gamepad_init(): found %i devices\n", cnt);
|
||||
for(i = 0; i < cnt; ++i)
|
||||
printf("%i: %s\n", i, SDL_JoystickName(i));
|
||||
printf("%i: %s\n", i, SDL_JoystickNameForIndex(i));
|
||||
|
||||
int dev = config_intval("gamepad_device");
|
||||
if(dev < 0 || dev >= cnt) {
|
||||
|
@ -78,11 +77,19 @@ void gamepad_restart(void) {
|
|||
}
|
||||
|
||||
int gamepad_axis2gamekey(int id, int val) {
|
||||
if(id == tconfig.intval[GAMEPAD_AXIS_LR])
|
||||
val *= SIGN(gamepad_axis_sens(id));
|
||||
|
||||
if(!val) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(id == tconfig.intval[GAMEPAD_AXIS_LR]) {
|
||||
return val == AXISVAL_LEFT ? KEY_LEFT : KEY_RIGHT;
|
||||
}
|
||||
|
||||
if(id == tconfig.intval[GAMEPAD_AXIS_UD])
|
||||
if(id == tconfig.intval[GAMEPAD_AXIS_UD]) {
|
||||
return val == AXISVAL_UP ? KEY_UP : KEY_DOWN;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -134,8 +141,19 @@ void gamepad_axis(int id, int raw, EventHandler handler, EventFlags flags, void
|
|||
|
||||
if(game && free) {
|
||||
int evt = gamepad_axis2gameevt(id);
|
||||
if(evt >= 0)
|
||||
handler(evt, clamp(raw * gamepad_axis_sens(id), -GAMEPAD_AXIS_RANGE-1, GAMEPAD_AXIS_RANGE), arg);
|
||||
if(evt >= 0) {
|
||||
double sens = gamepad_axis_sens(id);
|
||||
int sens_sign = SIGN(sens);
|
||||
|
||||
double x = raw / (double)GAMEPAD_AXIS_RANGE;
|
||||
int in_sign = SIGN(x);
|
||||
|
||||
x = pow(fabs(x), 1.0 / fabs(sens)) * in_sign * sens_sign;
|
||||
x = x ? x : 0;
|
||||
x = clamp(x * GAMEPAD_AXIS_RANGE, -GAMEPAD_AXIS_RANGE-1, GAMEPAD_AXIS_RANGE);
|
||||
|
||||
handler(evt, x, arg);
|
||||
}
|
||||
}
|
||||
|
||||
if(val) { // simulate press
|
||||
|
@ -229,7 +247,7 @@ int gamepad_devicecount(void) {
|
|||
}
|
||||
|
||||
char* gamepad_devicename(int id) {
|
||||
return (char*)SDL_JoystickName(id);
|
||||
return (char*)SDL_JoystickNameForIndex(id);
|
||||
}
|
||||
|
||||
int gamepad_buttonpressed(int btn) {
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
#ifndef GAMEPAD_H
|
||||
#define GAMEPAD_H
|
||||
|
||||
#include <SDL.h>
|
||||
#include "events.h"
|
||||
|
||||
void gamepad_init(void);
|
||||
void gamepad_shutdown(void);
|
||||
void gamepad_restart(void);
|
||||
int gamepad_devicecount(void);
|
||||
float gamepad_axis_sens(int);
|
||||
char* gamepad_devicename(int);
|
||||
void gamepad_event(SDL_Event*, EventHandler, EventFlags, void*);
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "global.h"
|
||||
#include "video.h"
|
||||
#include <SDL/SDL.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <png.h>
|
||||
|
@ -32,8 +31,6 @@ void init_global(void) {
|
|||
|
||||
memset(&global.replay, 0, sizeof(Replay));
|
||||
global.replaymode = REPLAY_RECORD;
|
||||
|
||||
SDL_EnableKeyRepeat(TS_KR_DELAY, TS_KR_INTERVAL);
|
||||
}
|
||||
|
||||
void print_state_checksum(void) {
|
||||
|
@ -245,5 +242,5 @@ void stralloc(char **dest, char *src) {
|
|||
// Inputdevice-agnostic method of checking whether a game control is pressed.
|
||||
// ALWAYS use this instead of SDL_GetKeyState if you need it.
|
||||
int gamekeypressed(int key) {
|
||||
return SDL_GetKeyState(NULL)[tconfig.intval[key]] || gamepad_gamekeypressed(key);
|
||||
return SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey(tconfig.intval[key])] || gamepad_gamekeypressed(key);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef GLOBAL_H
|
||||
#define GLOBAL_H
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "resource/audio.h"
|
||||
#include "resource/bgm.h"
|
||||
|
|
12
src/main.c
12
src/main.c
|
@ -5,7 +5,6 @@
|
|||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
*/
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <sys/stat.h>
|
||||
#include "taisei_err.h"
|
||||
|
||||
|
@ -58,13 +57,18 @@ void taisei_shutdown(void) {
|
|||
int main(int argc, char** argv) {
|
||||
if(tsrand_test())
|
||||
return 0;
|
||||
|
||||
|
||||
init_paths();
|
||||
|
||||
printf("Content path: %s\n", get_prefix());
|
||||
printf("Userdata path: %s\n", get_config_path());
|
||||
|
||||
MKDIR(get_config_path());
|
||||
MKDIR(get_screenshots_path());
|
||||
MKDIR(get_replays_path());
|
||||
|
||||
|
||||
config_load(CONFIG_FILE);
|
||||
|
||||
|
||||
printf("initialize:\n");
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
errx(-1, "Error initializing SDL: %s", SDL_GetError());
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "menu.h"
|
||||
#include "global.h"
|
||||
#include "video.h"
|
||||
|
||||
MenuEntry *add_menu_entry(MenuData *menu, char *name, MenuAction action, void *arg) {
|
||||
return add_menu_entry_f(menu, name, action, arg, 0);
|
||||
|
@ -155,7 +156,7 @@ int menu_loop(MenuData *menu, void (*input)(MenuData*), void (*draw)(MenuData*),
|
|||
if(!(menu->flags & MF_ManualDrawTransition))
|
||||
draw_transition();
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(video.window);
|
||||
frame_rate(&menu->lasttime);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include "transition.h"
|
||||
|
||||
#define IMENU_BLUR 0.05
|
||||
#define TS_KR_DELAY SDL_DEFAULT_REPEAT_DELAY
|
||||
#define TS_KR_INTERVAL (SDL_DEFAULT_REPEAT_INTERVAL*2)
|
||||
|
||||
#include "events.h"
|
||||
|
||||
|
|
|
@ -237,9 +237,7 @@ int bind_common_onoffset_inverted(void *b, int v) {
|
|||
// --- Binding callbacks for individual options --- //
|
||||
|
||||
int bind_fullscreen_set(void *b, int v) {
|
||||
#ifndef WIN32 // TODO: remove when we're on SDL2
|
||||
video_toggle_fullscreen();
|
||||
#endif
|
||||
return bind_common_onoffset(b, v);
|
||||
}
|
||||
|
||||
|
@ -321,13 +319,8 @@ void destroy_options_menu(MenuData *m) {
|
|||
if(bind->type == BT_Resolution) {
|
||||
if(bind->selected != -1) {
|
||||
VideoMode *m = video.modes + bind->selected;
|
||||
|
||||
#ifndef WIN32 // TODO: remove when we're on SDL2
|
||||
|
||||
video_setmode(m->width, m->height, tconfig.intval[FULLSCREEN]);
|
||||
#else
|
||||
video.intended.width = m->width;
|
||||
video.intended.height = m->height;
|
||||
#endif
|
||||
|
||||
tconfig.intval[VID_WIDTH] = video.intended.width;
|
||||
tconfig.intval[VID_HEIGHT] = video.intended.height;
|
||||
|
@ -506,11 +499,11 @@ void options_sub_gamepad(void *arg) {
|
|||
bind_addvalue(b, "restricted");
|
||||
|
||||
add_menu_entry(m, "UD axis sensitivity", do_nothing,
|
||||
b = bind_scale(GAMEPAD_AXIS_UD_SENS, -3, 3, 0.05)
|
||||
b = bind_scale(GAMEPAD_AXIS_UD_SENS, -2, 2, 0.05)
|
||||
); bind_setdependence(b, gamepad_sens_depencence);
|
||||
|
||||
add_menu_entry(m, "LR axis sensitivity", do_nothing,
|
||||
b = bind_scale(GAMEPAD_AXIS_LR_SENS, -3, 3, 0.05)
|
||||
b = bind_scale(GAMEPAD_AXIS_LR_SENS, -2, 2, 0.05)
|
||||
); bind_setdependence(b, gamepad_sens_depencence);
|
||||
|
||||
add_menu_entry(m, "Dead zone", do_nothing,
|
||||
|
@ -563,11 +556,9 @@ void options_sub_controls(void *arg) {
|
|||
|
||||
add_menu_separator(m);
|
||||
|
||||
#ifndef WIN32 // TODO: remove when we're on SDL2
|
||||
add_menu_entry(m, "Toggle fullscreen", do_nothing,
|
||||
bind_keybinding(KEY_FULLSCREEN)
|
||||
);
|
||||
#endif
|
||||
|
||||
add_menu_entry(m, "Take a screenshot", do_nothing,
|
||||
bind_keybinding(KEY_SCREENSHOT)
|
||||
|
|
|
@ -13,4 +13,6 @@ const char *get_config_path(void);
|
|||
const char *get_screenshots_path(void);
|
||||
const char *get_replays_path(void);
|
||||
|
||||
void init_paths(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,18 +7,21 @@
|
|||
|
||||
#include "native.h"
|
||||
|
||||
const char *get_prefix() {
|
||||
const char *get_prefix(void) {
|
||||
return "./data/";
|
||||
}
|
||||
|
||||
const char *get_config_path() {
|
||||
const char *get_config_path(void) {
|
||||
return ".";
|
||||
}
|
||||
|
||||
const char *get_screenshots_path() {
|
||||
const char *get_screenshots_path(void) {
|
||||
return "./screenshots";
|
||||
}
|
||||
|
||||
const char *get_replays_path() {
|
||||
const char *get_replays_path(void) {
|
||||
return "./replays";
|
||||
}
|
||||
|
||||
void init_paths(void) {
|
||||
}
|
||||
|
|
59
src/paths/sdl.c
Normal file
59
src/paths/sdl.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT-License
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
*/
|
||||
|
||||
#include "native.h"
|
||||
#include "global.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DATA_DIR "data/"
|
||||
|
||||
#define SCR_DIR "screenshots"
|
||||
#define RPY_DIR "replays"
|
||||
|
||||
char *content_path;
|
||||
char *conf_path;
|
||||
char *scr_path;
|
||||
char *rpy_path;
|
||||
|
||||
const char *get_prefix(void) {
|
||||
return content_path;
|
||||
}
|
||||
|
||||
const char *get_config_path(void) {
|
||||
return conf_path;
|
||||
}
|
||||
|
||||
const char *get_screenshots_path(void) {
|
||||
return scr_path;
|
||||
}
|
||||
|
||||
const char *get_replays_path(void) {
|
||||
return rpy_path;
|
||||
}
|
||||
|
||||
void init_paths(void) {
|
||||
#ifdef RELATIVE
|
||||
char *basedir = SDL_GetBasePath();
|
||||
content_path = malloc(strlen(basedir) + strlen(DATA_DIR) + 1);
|
||||
strcpy(content_path, basedir);
|
||||
strcat(content_path, DATA_DIR);
|
||||
free(basedir);
|
||||
#else
|
||||
content_path = FILE_PREFIX;
|
||||
#endif
|
||||
|
||||
conf_path = SDL_GetPrefPath("", "taisei");
|
||||
|
||||
scr_path = malloc(strlen(SCR_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(scr_path, get_config_path());
|
||||
strcat(scr_path, SCR_DIR);
|
||||
|
||||
rpy_path = malloc(strlen(RPY_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(rpy_path, get_config_path());
|
||||
strcat(rpy_path, RPY_DIR);
|
||||
}
|
|
@ -14,40 +14,36 @@
|
|||
#define SCR_DIR "/screenshots"
|
||||
#define RPY_DIR "/replays"
|
||||
|
||||
char *conf_path = NULL;
|
||||
char *scr_path = NULL;
|
||||
char *rpy_path = NULL;
|
||||
char *conf_path;
|
||||
char *scr_path;
|
||||
char *rpy_path;
|
||||
|
||||
const char *get_prefix() {
|
||||
const char *get_prefix(void) {
|
||||
return FILE_PREFIX;
|
||||
}
|
||||
|
||||
const char *get_config_path() {
|
||||
if(conf_path == NULL) {
|
||||
conf_path = malloc(strlen(CFG_DIR) + strlen(getenv("HOME")) + 1);
|
||||
strcpy(conf_path, getenv("HOME"));
|
||||
strcat(conf_path, CFG_DIR);
|
||||
}
|
||||
|
||||
const char *get_config_path(void) {
|
||||
return conf_path;
|
||||
}
|
||||
|
||||
const char *get_screenshots_path() {
|
||||
if(scr_path == NULL) {
|
||||
scr_path = malloc(strlen(SCR_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(scr_path, get_config_path());
|
||||
strcat(scr_path, SCR_DIR);
|
||||
}
|
||||
|
||||
const char *get_screenshots_path(void) {
|
||||
return scr_path;
|
||||
}
|
||||
|
||||
const char *get_replays_path() {
|
||||
if(rpy_path == NULL) {
|
||||
rpy_path = malloc(strlen(RPY_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(rpy_path, get_config_path());
|
||||
strcat(rpy_path, RPY_DIR);
|
||||
}
|
||||
|
||||
const char *get_replays_path(void) {
|
||||
return rpy_path;
|
||||
}
|
||||
|
||||
void init_paths(void) {
|
||||
conf_path = malloc(strlen(CFG_DIR) + strlen(getenv("HOME")) + 1);
|
||||
strcpy(conf_path, getenv("HOME"));
|
||||
strcat(conf_path, CFG_DIR);
|
||||
|
||||
scr_path = malloc(strlen(SCR_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(scr_path, get_config_path());
|
||||
strcat(scr_path, SCR_DIR);
|
||||
|
||||
rpy_path = malloc(strlen(RPY_DIR) + strlen(get_config_path()) + 1);
|
||||
strcpy(rpy_path, get_config_path());
|
||||
strcat(rpy_path, RPY_DIR);
|
||||
}
|
||||
|
|
14
src/player.c
14
src/player.c
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "player.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include "projectile.h"
|
||||
#include "global.h"
|
||||
#include "plrmodes.h"
|
||||
|
@ -305,9 +304,14 @@ void player_event(Player* plr, int type, int key) {
|
|||
|
||||
// free-axis movement
|
||||
int player_applymovement_gamepad(Player *plr) {
|
||||
if(!plr->axis_lr && !plr->axis_ud)
|
||||
if(!plr->axis_lr && !plr->axis_ud) {
|
||||
if(plr->gamepadmove) {
|
||||
plr->gamepadmove = False;
|
||||
plr->moveflags = 0;
|
||||
}
|
||||
return False;
|
||||
|
||||
}
|
||||
|
||||
complex direction = (plr->axis_lr + plr->axis_ud*I) / (double)GAMEPAD_AXIS_RANGE;
|
||||
if(cabs(direction) > 1)
|
||||
direction /= cabs(direction);
|
||||
|
@ -322,8 +326,10 @@ int player_applymovement_gamepad(Player *plr) {
|
|||
player_setmoveflag(plr, KEY_LEFT, sr == -1);
|
||||
player_setmoveflag(plr, KEY_RIGHT, sr == 1);
|
||||
|
||||
if(direction)
|
||||
if(direction) {
|
||||
plr->gamepadmove = True;
|
||||
player_move(&global.plr, direction);
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,8 @@ typedef struct {
|
|||
int movetime;
|
||||
int prevmove;
|
||||
int prevmovetime;
|
||||
|
||||
int gamepadmove;
|
||||
|
||||
int axis_ud;
|
||||
int axis_lr;
|
||||
} Player;
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "texture.h"
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "paths/native.h"
|
||||
#include "config.h"
|
||||
#include "taisei_err.h"
|
||||
#include "video.h"
|
||||
|
||||
Resources resources;
|
||||
|
||||
|
@ -162,5 +163,5 @@ void draw_loading_screen(void) {
|
|||
tex = load_texture(buf);
|
||||
|
||||
draw_texture_p(SCREEN_W/2,SCREEN_H/2, tex);
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(video.window);
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL.h>
|
||||
#include "taiseigl.h"
|
||||
#include <math.h>
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "stage.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <time.h>
|
||||
#include "global.h"
|
||||
#include "video.h"
|
||||
|
@ -303,7 +302,7 @@ void stage_draw(StageInfo *info, StageRule bgdraw, ShaderRule *shaderrules, int
|
|||
|
||||
if(!tconfig.intval[NO_SHADER]) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, video.current.width, video.current.height);
|
||||
video_set_viewport();
|
||||
glPushMatrix();
|
||||
if(global.shake_view)
|
||||
glTranslatef(global.shake_view*sin(global.frames),global.shake_view*sin(global.frames+3),0);
|
||||
|
@ -508,7 +507,6 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
|
|||
|
||||
start();
|
||||
|
||||
SDL_EnableKeyRepeat(0, 0);
|
||||
while(global.game_over <= 0) {
|
||||
if(!global.boss && !global.dialog)
|
||||
event();
|
||||
|
@ -523,7 +521,7 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
|
|||
|
||||
// print_state_checksum();
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(video.window);
|
||||
frame_rate(&global.lasttime);
|
||||
}
|
||||
|
||||
|
@ -536,7 +534,6 @@ void stage_loop(StageInfo* info, StageRule start, StageRule end, StageRule draw,
|
|||
tsrand_switch(&global.rand_visual);
|
||||
// if(global.replaymode != REPLAY_PLAY)
|
||||
// replay_destroy(&global.replay);
|
||||
SDL_EnableKeyRepeat(TS_KR_DELAY, TS_KR_INTERVAL);
|
||||
}
|
||||
|
||||
void draw_title(int t, StageInfo *info, Alignment al, int x, int y, const char *text, TTF_Font *font, Color *color) {
|
||||
|
|
114
src/video.c
114
src/video.c
|
@ -45,66 +45,114 @@ static int video_compare_modes(const void *a, const void *b) {
|
|||
return va->width * va->height - vb->width * vb->height;
|
||||
}
|
||||
|
||||
void video_set_viewport(void) {
|
||||
float w = video.current.width;
|
||||
float h = video.current.height;
|
||||
float r = w / h;
|
||||
|
||||
if(r > VIEWPORT_ASPECT_RATIO) {
|
||||
w = h * VIEWPORT_ASPECT_RATIO;
|
||||
} else if(r < VIEWPORT_ASPECT_RATIO) {
|
||||
h = w / VIEWPORT_ASPECT_RATIO;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport((video.current.width - w) / 2, (video.current.height - h) / 2, (int)w, (int)h);
|
||||
}
|
||||
|
||||
static void _video_setmode(int w, int h, int fs, int fallback) {
|
||||
int flags = SDL_OPENGL;
|
||||
if(fs) flags |= SDL_FULLSCREEN;
|
||||
Uint32 flags = SDL_WINDOW_OPENGL;
|
||||
|
||||
if(fs) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
} else {
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
}
|
||||
|
||||
if(!fallback) {
|
||||
video.intended.width = w;
|
||||
video.intended.height = h;
|
||||
}
|
||||
|
||||
if(display)
|
||||
SDL_FreeSurface(display);
|
||||
|
||||
if(!(display = SDL_SetVideoMode(w, h, 32, flags))) {
|
||||
if(fallback) {
|
||||
errx(-1, "video_setmode(): error opening screen: %s", SDL_GetError());
|
||||
if(video.window) {
|
||||
SDL_DestroyWindow(video.window);
|
||||
video.window = NULL;
|
||||
}
|
||||
|
||||
video.window = SDL_CreateWindow(WINDOW_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags);
|
||||
|
||||
if(video.window) {
|
||||
if(video.glcontext) {
|
||||
SDL_GL_MakeCurrent(video.window, video.glcontext);
|
||||
} else {
|
||||
video.glcontext = SDL_GL_CreateContext(video.window);
|
||||
}
|
||||
|
||||
if(!video.glcontext) {
|
||||
errx(-1, "video_setmode(): error creating OpenGL context: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
warnx("video_setmode(): setting %dx%d failed, falling back to %dx%d", w, h, RESX, RESY);
|
||||
_video_setmode(RESX, RESY, fs, True);
|
||||
|
||||
SDL_GL_GetDrawableSize(video.window, &video.current.width, &video.current.height);
|
||||
video_set_viewport();
|
||||
return;
|
||||
}
|
||||
|
||||
if(fallback) {
|
||||
errx(-1, "video_setmode(): error opening screen: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_VideoInfo *info = SDL_GetVideoInfo();
|
||||
video.current.width = info->current_w;
|
||||
video.current.height = info->current_h;
|
||||
|
||||
glViewport(0, 0, video.current.width, video.current.height);
|
||||
warnx("video_setmode(): setting %dx%d (%s) failed, falling back to %dx%d (windowed)", w, h, fs ? "fullscreen" : "windowed", RESX, RESY);
|
||||
_video_setmode(RESX, RESY, False, True);
|
||||
}
|
||||
|
||||
void video_setmode(int w, int h, int fs) {
|
||||
if(w == video.current.width && h == video.current.height && fs == video_isfullscreen())
|
||||
return;
|
||||
|
||||
_video_setmode(w, h, fs, False);
|
||||
}
|
||||
|
||||
int video_isfullscreen(void) {
|
||||
return !!(display->flags & SDL_FULLSCREEN);
|
||||
return !!(SDL_GetWindowFlags(video.window) & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP));
|
||||
}
|
||||
|
||||
void video_toggle_fullscreen(void) {
|
||||
video_setmode(video.intended.width, video.intended.height, !video_isfullscreen());
|
||||
}
|
||||
|
||||
void video_resize(int w, int h) {
|
||||
video.current.width = w;
|
||||
video.current.height = h;
|
||||
video_set_viewport();
|
||||
}
|
||||
|
||||
void video_init(void) {
|
||||
SDL_Rect **modes;
|
||||
int i;
|
||||
|
||||
int i, s, fullscreen_available = False;
|
||||
|
||||
memset(&video, 0, sizeof(video));
|
||||
|
||||
// First, register all resolutions that are available in fullscreen
|
||||
|
||||
// First register all resolutions that are available in fullscreen
|
||||
modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
|
||||
if(!modes) {
|
||||
warnx("video_init(): no available fullscreen modes");
|
||||
tconfig.intval[FULLSCREEN] = False;
|
||||
} else if(modes == (SDL_Rect**)-1) {
|
||||
warnx("video_init(): you seem to have a weird video driver");
|
||||
} else {
|
||||
for(i = 0; modes[i]; ++i) {
|
||||
video_add_mode(modes[i]->w, modes[i]->h);
|
||||
for(s = 0; s < SDL_GetNumVideoDisplays(); ++s) {
|
||||
for(i = 0; i < SDL_GetNumDisplayModes(s); ++i) {
|
||||
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
||||
|
||||
if(SDL_GetDisplayMode(s, i, &mode) != 0) {
|
||||
warnx("SDL_GetDisplayMode failed: %s", SDL_GetError());
|
||||
} else {
|
||||
video_add_mode(mode.w, mode.h);
|
||||
fullscreen_available = True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!fullscreen_available) {
|
||||
warnx("video_init(): no available fullscreen modes");
|
||||
tconfig.intval[FULLSCREEN] = False;
|
||||
}
|
||||
|
||||
// Then, add some common 4:3 modes for the windowed mode if they are not there yet.
|
||||
// This is required for some multihead setups.
|
||||
for(i = 0; common_modes[i].width; ++i)
|
||||
|
@ -114,10 +162,10 @@ void video_init(void) {
|
|||
qsort(video.modes, video.mcount, sizeof(VideoMode), video_compare_modes);
|
||||
|
||||
video_setmode(tconfig.intval[VID_WIDTH], tconfig.intval[VID_HEIGHT], tconfig.intval[FULLSCREEN]);
|
||||
SDL_WM_SetCaption("TaiseiProject", NULL);
|
||||
}
|
||||
|
||||
void video_shutdown(void) {
|
||||
SDL_FreeSurface(display);
|
||||
SDL_DestroyWindow(video.window);
|
||||
SDL_GL_DeleteContext(video.glcontext);
|
||||
free(video.modes);
|
||||
}
|
||||
|
|
12
src/video.h
12
src/video.h
|
@ -9,9 +9,12 @@
|
|||
#ifndef VIDEO_H
|
||||
#define VIDEO_H
|
||||
|
||||
#define WINDOW_TITLE "TaiseiProject"
|
||||
#define VIEWPORT_ASPECT_RATIO (4.0f/3.0f)
|
||||
|
||||
typedef struct VideoMode {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
int width;
|
||||
int height;
|
||||
} VideoMode;
|
||||
|
||||
typedef struct {
|
||||
|
@ -19,15 +22,18 @@ typedef struct {
|
|||
int mcount;
|
||||
VideoMode intended;
|
||||
VideoMode current;
|
||||
SDL_Window *window;
|
||||
SDL_GLContext *glcontext;
|
||||
} Video;
|
||||
|
||||
Video video;
|
||||
SDL_Surface *display;
|
||||
|
||||
void video_init(void);
|
||||
void video_shutdown(void);
|
||||
void video_setmode(int w, int h, int fs);
|
||||
void video_set_viewport(void);
|
||||
int video_isfullscreen(void);
|
||||
void video_toggle_fullscreen(void);
|
||||
void video_resize(int w, int h);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue