Implemented better handling of init failure, fixed input 'lag' and fullscreen bugs by recompiling SDL2 with automake and more libraries installed

dev
shariq 10 years ago
parent 5c5ac44b98
commit 4ddb5576cd
  1. 2
      build/linux/makefile
  2. 354
      include/SDL2/SDL_config.h
  3. BIN
      libs/release/linux64_gcc/libSDL2.a
  4. 2
      orgfile.org
  5. 53
      src/game.c
  6. 3
      src/game.h
  7. 10
      src/input.c
  8. 40
      src/platform.c
  9. 7
      src/platform.h

@ -11,7 +11,7 @@ OBJS_DEBUG = $(patsubst %.c,.debug/%.o,$(SRCS))
CFLAGS = -Wall -I$(INCLUDE_DIR) -DUSE_GLAD
CFLAGS_DEBUG = -g -DGL_DEBUG_CONTEXT -DAL_DEBUG -std=c99
CFLAGS_RELEASE = -O3 -ffast-math
LFLAGS = -lSDL2 -lpthread -ldl -lm -lopenal
LFLAGS = -Wl,--enable-new-dtags -lSDL2 -Wl,--no-undefined -lpthread -ldl -lm -lopenal
all: release

@ -1,3 +1,4 @@
/* include/SDL_config.h. Generated from SDL_config.h.in by configure. */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
@ -23,34 +24,341 @@
#define _SDL_config_h
/**
* \file SDL_config.h
* \file SDL_config.h.in
*
* This is a set of defines to configure the SDL features
*/
/* Add any platform that doesn't build using the configure system. */
#ifdef __linux__
#include "SDL_config_linux.h"
#elif defined(USING_PREMAKE_CONFIG_H)
#include "SDL_config_premake.h"
#elif defined(__WIN32__)
#include "SDL_config_windows.h"
#elif defined(__WINRT__)
#include "SDL_config_winrt.h"
#elif defined(__MACOSX__)
#include "SDL_config_macosx.h"
#elif defined(__IPHONEOS__)
#include "SDL_config_iphoneos.h"
#elif defined(__ANDROID__)
#include "SDL_config_android.h"
#elif defined(__PSP__)
#include "SDL_config_psp.h"
/* General platform specific identifiers */
#include "SDL_platform.h"
/* Make sure that this isn't included by Visual C++ */
#ifdef _MSC_VER
#error You should run hg revert SDL_config.h
#endif
/* C language features */
/* #undef const */
/* #undef inline */
/* #undef volatile */
/* C datatypes */
#ifdef __LP64__
#define SIZEOF_VOIDP 8
#else
/* This is a minimal configuration just to get SDL running on new platforms */
#include "SDL_config_minimal.h"
#endif /* platform config */
#define SIZEOF_VOIDP 4
#endif
#define HAVE_GCC_ATOMICS 1
/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
/* #undef HAVE_DDRAW_H */
/* #undef HAVE_DINPUT_H */
/* #undef HAVE_DSOUND_H */
/* #undef HAVE_DXGI_H */
/* #undef HAVE_XINPUT_H */
#ifdef USING_GENERATED_CONFIG_H
#error Wrong SDL_config.h, check your include path?
/* Comment this if you want to build without any C library requirements */
#define HAVE_LIBC 1
#if HAVE_LIBC
/* Useful headers */
#define HAVE_ALLOCA_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STDLIB_H 1
#define HAVE_STDARG_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRING_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
#define HAVE_ICONV_H 1
#define HAVE_SIGNAL_H 1
/* #undef HAVE_ALTIVEC_H */
/* #undef HAVE_PTHREAD_NP_H */
/* #undef HAVE_LIBUDEV_H */
#define HAVE_DBUS_DBUS_H 1
#define HAVE_IBUS_IBUS_H 1
#define HAVE_FCITX_FRONTEND_H 1
/* C library functions */
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
#define HAVE_ALLOCA 1
#ifndef __WIN32__ /* Don't use C runtime versions of these on Windows */
#define HAVE_GETENV 1
#define HAVE_SETENV 1
#define HAVE_PUTENV 1
#define HAVE_UNSETENV 1
#endif
#define HAVE_QSORT 1
#define HAVE_ABS 1
#define HAVE_BCOPY 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMCMP 1
#define HAVE_STRLEN 1
/* #undef HAVE_STRLCPY */
/* #undef HAVE_STRLCAT */
#define HAVE_STRDUP 1
/* #undef HAVE__STRREV */
/* #undef HAVE__STRUPR */
/* #undef HAVE__STRLWR */
/* #undef HAVE_INDEX */
/* #undef HAVE_RINDEX */
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
/* #undef HAVE_ITOA */
/* #undef HAVE__LTOA */
/* #undef HAVE__UITOA */
/* #undef HAVE__ULTOA */
#define HAVE_STRTOL 1
#define HAVE_STRTOUL 1
/* #undef HAVE__I64TOA */
/* #undef HAVE__UI64TOA */
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
/* #undef HAVE__STRICMP */
#define HAVE_STRCASECMP 1
/* #undef HAVE__STRNICMP */
#define HAVE_STRNCASECMP 1
/* #undef HAVE_SSCANF */
#define HAVE_VSSCANF 1
/* #undef HAVE_SNPRINTF */
#define HAVE_VSNPRINTF 1
#define HAVE_M_PI /**/
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_ACOS 1
#define HAVE_ASIN 1
#define HAVE_CEIL 1
#define HAVE_COPYSIGN 1
#define HAVE_COS 1
#define HAVE_COSF 1
#define HAVE_FABS 1
#define HAVE_FLOOR 1
#define HAVE_LOG 1
#define HAVE_POW 1
#define HAVE_SCALBN 1
#define HAVE_SIN 1
#define HAVE_SINF 1
#define HAVE_SQRT 1
#define HAVE_SQRTF 1
#define HAVE_TAN 1
#define HAVE_TANF 1
#define HAVE_FSEEKO 1
#define HAVE_FSEEKO64 1
#define HAVE_SIGACTION 1
#define HAVE_SA_SIGACTION 1
#define HAVE_SETJMP 1
#define HAVE_NANOSLEEP 1
#define HAVE_SYSCONF 1
/* #undef HAVE_SYSCTLBYNAME */
#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_GETPAGESIZE */
#define HAVE_MPROTECT 1
#define HAVE_ICONV 1
#define HAVE_PTHREAD_SETNAME_NP 1
/* #undef HAVE_PTHREAD_SET_NAME_NP */
#define HAVE_SEM_TIMEDWAIT 1
#else
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#define HAVE_STDINT_H 1
#endif /* HAVE_LIBC */
/* SDL internal assertion support */
/* #undef SDL_DEFAULT_ASSERT_LEVEL */
/* Allow disabling of core subsystems */
/* #undef SDL_ATOMIC_DISABLED */
/* #undef SDL_AUDIO_DISABLED */
/* #undef SDL_CPUINFO_DISABLED */
/* #undef SDL_EVENTS_DISABLED */
/* #undef SDL_FILE_DISABLED */
/* #undef SDL_JOYSTICK_DISABLED */
/* #undef SDL_HAPTIC_DISABLED */
/* #undef SDL_LOADSO_DISABLED */
/* #undef SDL_RENDER_DISABLED */
/* #undef SDL_THREADS_DISABLED */
/* #undef SDL_TIMERS_DISABLED */
/* #undef SDL_VIDEO_DISABLED */
/* #undef SDL_POWER_DISABLED */
/* #undef SDL_FILESYSTEM_DISABLED */
/* Enable various audio drivers */
#define SDL_AUDIO_DRIVER_ALSA 1
#define SDL_AUDIO_DRIVER_ALSA_DYNAMIC "libasound.so.2"
/* #undef SDL_AUDIO_DRIVER_ARTS */
/* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
#define SDL_AUDIO_DRIVER_PULSEAUDIO 1
#define SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "libpulse-simple.so.0"
/* #undef SDL_AUDIO_DRIVER_HAIKU */
/* #undef SDL_AUDIO_DRIVER_BSD */
/* #undef SDL_AUDIO_DRIVER_COREAUDIO */
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_AUDIO_DRIVER_DUMMY 1
/* #undef SDL_AUDIO_DRIVER_ANDROID */
/* #undef SDL_AUDIO_DRIVER_XAUDIO2 */
/* #undef SDL_AUDIO_DRIVER_DSOUND */
/* #undef SDL_AUDIO_DRIVER_ESD */
/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_NACL */
/* #undef SDL_AUDIO_DRIVER_NAS */
/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_SNDIO */
/* #undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
#define SDL_AUDIO_DRIVER_OSS 1
/* #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H */
/* #undef SDL_AUDIO_DRIVER_PAUDIO */
/* #undef SDL_AUDIO_DRIVER_QSA */
/* #undef SDL_AUDIO_DRIVER_SUNAUDIO */
/* #undef SDL_AUDIO_DRIVER_WINMM */
/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND */
/* #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */
/* #undef SDL_AUDIO_DRIVER_EMSCRIPTEN */
/* Enable various input drivers */
#define SDL_INPUT_LINUXEV 1
#define SDL_INPUT_LINUXKD 1
/* #undef SDL_INPUT_TSLIB */
/* #undef SDL_JOYSTICK_HAIKU */
/* #undef SDL_JOYSTICK_DINPUT */
/* #undef SDL_JOYSTICK_XINPUT */
/* #undef SDL_JOYSTICK_DUMMY */
/* #undef SDL_JOYSTICK_IOKIT */
#define SDL_JOYSTICK_LINUX 1
/* #undef SDL_JOYSTICK_ANDROID */
/* #undef SDL_JOYSTICK_WINMM */
/* #undef SDL_JOYSTICK_USBHID */
/* #undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
/* #undef SDL_JOYSTICK_EMSCRIPTEN */
/* #undef SDL_HAPTIC_DUMMY */
#define SDL_HAPTIC_LINUX 1
/* #undef SDL_HAPTIC_IOKIT */
/* #undef SDL_HAPTIC_DINPUT */
/* #undef SDL_HAPTIC_XINPUT */
/* Enable various shared object loading systems */
/* #undef SDL_LOADSO_HAIKU */
#define SDL_LOADSO_DLOPEN 1
/* #undef SDL_LOADSO_DUMMY */
/* #undef SDL_LOADSO_LDG */
/* #undef SDL_LOADSO_WINDOWS */
/* Enable various threading systems */
#define SDL_THREAD_PTHREAD 1
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
/* #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP */
/* #undef SDL_THREAD_WINDOWS */
/* Enable various timer systems */
/* #undef SDL_TIMER_HAIKU */
/* #undef SDL_TIMER_DUMMY */
#define SDL_TIMER_UNIX 1
/* #undef SDL_TIMER_WINDOWS */
/* Enable various video drivers */
/* #undef SDL_VIDEO_DRIVER_HAIKU */
/* #undef SDL_VIDEO_DRIVER_COCOA */
/* #undef SDL_VIDEO_DRIVER_DIRECTFB */
/* #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC */
#define SDL_VIDEO_DRIVER_DUMMY 1
/* #undef SDL_VIDEO_DRIVER_WINDOWS */
#define SDL_VIDEO_DRIVER_WAYLAND 1
#define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "libwayland-client.so.0"
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "libwayland-egl.so.1"
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "libwayland-cursor.so.0"
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "libxkbcommon.so.0"
/* #undef SDL_VIDEO_DRIVER_MIR */
/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC */
/* #undef SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON */
#define SDL_VIDEO_DRIVER_X11 1
/* #undef SDL_VIDEO_DRIVER_RPI */
/* #undef SDL_VIDEO_DRIVER_ANDROID */
/* #undef SDL_VIDEO_DRIVER_EMSCRIPTEN */
#define SDL_VIDEO_DRIVER_X11_DYNAMIC "libX11.so.6"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "libXext.so.6"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "libXcursor.so.1"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "libXinerama.so.1"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "libXi.so.6"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "libXrandr.so.2"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "libXss.so.1"
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "libXxf86vm.so.1"
#define SDL_VIDEO_DRIVER_X11_XCURSOR 1
#define SDL_VIDEO_DRIVER_X11_XDBE 1
#define SDL_VIDEO_DRIVER_X11_XINERAMA 1
#define SDL_VIDEO_DRIVER_X11_XINPUT2 1
#define SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1
#define SDL_VIDEO_DRIVER_X11_XRANDR 1
#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
#define SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1
#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
/* #undef SDL_VIDEO_DRIVER_NACL */
/* #undef SDL_VIDEO_DRIVER_VIVANTE */
/* #undef SDL_VIDEO_DRIVER_VIVANTE_VDK */
/* #undef SDL_VIDEO_RENDER_D3D */
/* #undef SDL_VIDEO_RENDER_D3D11 */
#define SDL_VIDEO_RENDER_OGL 1
/* #undef SDL_VIDEO_RENDER_OGL_ES */
#define SDL_VIDEO_RENDER_OGL_ES2 1
/* #undef SDL_VIDEO_RENDER_DIRECTFB */
/* Enable OpenGL support */
#define SDL_VIDEO_OPENGL 1
/* #undef SDL_VIDEO_OPENGL_ES */
#define SDL_VIDEO_OPENGL_ES2 1
/* #undef SDL_VIDEO_OPENGL_BGL */
/* #undef SDL_VIDEO_OPENGL_CGL */
#define SDL_VIDEO_OPENGL_EGL 1
#define SDL_VIDEO_OPENGL_GLX 1
/* #undef SDL_VIDEO_OPENGL_WGL */
/* #undef SDL_VIDEO_OPENGL_OSMESA */
/* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */
/* Enable system power support */
#define SDL_POWER_LINUX 1
/* #undef SDL_POWER_WINDOWS */
/* #undef SDL_POWER_MACOSX */
/* #undef SDL_POWER_HAIKU */
/* #undef SDL_POWER_ANDROID */
/* #undef SDL_POWER_EMSCRIPTEN */
/* #undef SDL_POWER_HARDWIRED */
/* Enable system filesystem support */
/* #undef SDL_FILESYSTEM_HAIKU */
/* #undef SDL_FILESYSTEM_COCOA */
/* #undef SDL_FILESYSTEM_DUMMY */
#define SDL_FILESYSTEM_UNIX 1
/* #undef SDL_FILESYSTEM_WINDOWS */
/* #undef SDL_FILESYSTEM_NACL */
/* #undef SDL_FILESYSTEM_ANDROID */
/* #undef SDL_FILESYSTEM_EMSCRIPTEN */
/* Enable assembly routines */
#define SDL_ASSEMBLY_ROUTINES 1
/* #undef SDL_ALTIVEC_BLITTERS */
/* Enable ime support */
#define SDL_USE_IME 1
#endif /* _SDL_config_h */

@ -89,6 +89,7 @@ msaa_levels: 8
- State "DONE" from "TODO" [2015-08-19 Wed 13:30]
** TODO Bounding Boxes
- Recalculated bounding boxes for rotated meshes?
** TODO Fix input lag and other framerate related issues
** TODO File extension checking for asset loading
** DONE Materials
- State "DONE" from "TODO" [2015-10-13 Tue 19:38]
@ -148,6 +149,7 @@ x Font atlas proper cleanup
** DONE 3d sound using OpenAL
- State "DONE" from "TODO" [2017-03-23 Thu 01:43]
** TODO Ogg format loading and playback
** TODO Stick with OpenAL or switch to SoLoud + SDL for sound?
** TODO Sound streaming
** TODO Implment missing sound source properties (inner/outer cone, getting sound source data)
** TODO Ingame console and console commands etc

@ -38,7 +38,7 @@
#define MAX_FRAME_TIME 0.5f
static void run(void);
static int run(void);
static void update(float dt, int* window_should_close);
static void render(void);
static void debug(float dt);
@ -47,15 +47,26 @@ static void scene_setup(void);
static struct Game_State* game_state = NULL;
void game_init(struct Window* window)
int game_init(struct Window* window)
{
/* TODO: Implement dealing with init failures */
game_state = malloc(sizeof(*game_state));
if(!game_state)
{
log_error("game:init", "Out of memory, failed to allocate game_state");
return 0;
}
else
{
game_state->window = window;
game_state->player_node = -1;
game_state->player_pitch_node = -1;
game_state->is_initialized = 0;
}
/* TODO: Decouple systems' init/cleanup from game, they should exist and run even if there's no "game" */
/* Init systems */
input_init();
char* base_path = platform_get_base_path();
char* base_path = platform_base_path_get();
io_file_init(base_path);
free(base_path);
sound_init();
@ -76,8 +87,8 @@ void game_init(struct Window* window)
/* Debug scene setup */
scene_setup();
run();
game_state->is_initialized = 1;
return run();
}
void scene_setup(void)
@ -95,6 +106,8 @@ void scene_setup(void)
int sprint_keys[2] = {KEY_LSHIFT, KEY_RSHIFT};
int recompute_keys[2] = {KEY_F5, KEY_H};
int ed_toggle_keys[1] = {KEY_F1};
int win_fullscr_keys[1] = {KEY_F11};
int win_max_keys[1] = {KEY_F12};
input_map_create("Move_Forward", forward_keys, 2);
input_map_create("Move_Backward", backward_keys, 2);
input_map_create("Move_Up", up_keys, 1);
@ -108,6 +121,8 @@ void scene_setup(void)
input_map_create("Sprint", sprint_keys, 2);
input_map_create("Recompute", recompute_keys, 2);
input_map_create("Editor_Toggle", ed_toggle_keys, 1);
input_map_create("Window_Fullscreen", win_fullscr_keys, 1);
input_map_create("Window_Maximize", win_max_keys, 1);
struct Entity* player = scene_add_new("player", "None");
game_state->player_node = player->node;
@ -149,7 +164,7 @@ void scene_setup(void)
}
int parent_node = new_ent->node;
int num_suz = 1;
int num_suz = 200;
srand(time(NULL));
for(int i = 0; i < num_suz; i++)
{
@ -159,7 +174,7 @@ void scene_setup(void)
x++; y++; z++;
struct Entity* suz = scene_add_as_child("Suzanne", NULL, parent_node);
//struct Entity* suz = scene_add_new("Suzanne", NULL);
struct Model* suz_model = entity_component_add(suz, C_MODEL, "default.pamesh", "Blinn_Phong");
struct Model* suz_model = entity_component_add(suz, C_MODEL, "suzanne.pamesh", "Blinn_Phong");
model_set_material_param(suz_model, "diffuse_color", &color);
float spec_str = 80.f;
model_set_material_param(suz_model, "specular_strength", &spec_str);
@ -386,30 +401,34 @@ void debug(float dt)
/* } */
}
void run(void)
int run(void)
{
uint32 last_time = platform_get_ticks();
uint32 last_time = platform_ticks_get();
int should_window_close = 0;
while(!should_window_close)
{
uint32 curr_time = platform_get_ticks();
uint32 curr_time = platform_ticks_get();
float delta_time = (float)(curr_time - last_time) / 1000.f;
last_time = curr_time;
if(delta_time > MAX_FRAME_TIME) delta_time = (1.f / 60.f); /* To deal with resuming from breakpoint we artificially set delta time */
update(delta_time, &should_window_close);
render();
window_swap_buffers(game_state->window);
gui_input_begin();
platform_poll_events(&should_window_close);
gui_input_end();
update(delta_time, &should_window_close);
render();
window_swap_buffers(game_state->window);
}
return 1;
}
void update(float dt, int* window_should_close)
{
if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = 1;
if(input_map_state_get("Editor_Toggle", KS_RELEASED)) editor_toggle();
if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, 1);
if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, 0);
debug(dt);
//debug_gui(dt);
@ -1629,6 +1648,10 @@ void render(void)
void game_cleanup(void)
{
if(game_state)
{
if(game_state->is_initialized)
{
editor_cleanup();
scene_cleanup();
config_vars_cleanup();
@ -1649,7 +1672,9 @@ void game_cleanup(void)
window_destroy(game_state->window);
gl_cleanup();
window_cleanup();
}
free(game_state);
}
}
struct Game_State* game_state_get(void)

@ -8,11 +8,12 @@ struct Game_State
struct Window* window;
int player_node;
int player_pitch_node;
int is_initialized;
};
struct Game_State* game_state_get(void);
void game_init(struct Window* window);
int game_init(struct Window* window);
void game_cleanup(void);
#endif

@ -17,7 +17,7 @@ struct Input_Map
int state;
};
static void input_on_key(int key, int scancode, int state, int mod_ctrl, int mod_shift);
static void input_on_key(int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift);
static void input_on_mousebutton(int button, int state, int x, int y, int8 num_clicks);
static void input_on_mousemotion(int x, int y, int xrel, int yrel);
static void input_on_mousewheel(int x, int y);
@ -68,8 +68,14 @@ void input_mouse_pos_set(int xpos, int ypos)
platform_mouse_global_position_set(xpos, ypos);
}
void input_on_key(int key, int scancode, int state, int mod_ctrl, int mod_shift)
void input_on_key(int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift)
{
if(repeat)
{
log_message("Repeat ignored");
return; /* Ignore key repeat */
}
for(int i = 0; i < array_len(input_map_list); i++)
{
struct Input_Map* map = &input_map_list[i];

@ -10,6 +10,7 @@ struct Window
{
void* sdl_window;
SDL_GLContext gl_context;
int is_fullscreen;
};
struct Platform_State
@ -38,6 +39,7 @@ struct Window* window_create(const char* title, int width, int height)
}
new_window->sdl_window = NULL;
new_window->gl_context = NULL;
new_window->is_fullscreen = 0;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@ -96,6 +98,28 @@ struct Window* window_create(const char* title, int width, int height)
return new_window;
}
int window_fullscreen_set(struct Window* window, int fullscreen)
{
int success = 0;
int rc = SDL_SetWindowFullscreen(window->sdl_window, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
if(rc == 0)
{
window->is_fullscreen = fullscreen ? 1 : 0;
success = 1;
log_message("Window set to %s mode", fullscreen ? "fullscreen" : "windowed");
int w, h;
window_get_size(window, &w, &h);
log_message("Window size : %dx%d", w, h);
window_get_drawable_size(window, &w, &h);
log_message("Drawable size : %dx%d", w, h);
}
else
{
log_error("platform:window_fullscreen", "window_fullscreen_set failed, %s", SDL_GetError());
}
return success;
}
void window_make_context_current(struct Window* window)
{
SDL_GL_MakeCurrent((SDL_Window*)window->sdl_window, window->gl_context);
@ -163,6 +187,15 @@ int platform_init(void)
log_error("platform_init", "Could not create platform state, out of memory");
success = 0;
}
else
{
platform_state->on_keyboard_func = NULL;
platform_state->on_mousebutton_func = NULL;
platform_state->on_mousemotion_func = NULL;
platform_state->on_mousewheel_func = NULL;
platform_state->on_textinput_func = NULL;
platform_state->on_windowresize_func = NULL;
}
}
return success;
}
@ -188,9 +221,10 @@ void platform_poll_events(int* out_quit)
int scancode = event.key.keysym.scancode;
int key = event.key.keysym.sym;
int state = event.key.state;
int repeat = event.key.repeat;
int mod_ctrl = (event.key.keysym.mod & KMOD_CTRL);
int mod_shift = (event.key.keysym.mod & KMOD_SHIFT);
platform_state->on_keyboard_func(key, scancode, state, mod_ctrl, mod_shift);
platform_state->on_keyboard_func(key, scancode, state, repeat, mod_ctrl, mod_shift);
break;
}
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
@ -306,7 +340,7 @@ int platform_mouse_relative_mode_get(void)
return SDL_GetRelativeMouseMode() == SDL_TRUE ? 1 : 0;
}
uint32 platform_get_ticks(void)
uint32 platform_ticks_get(void)
{
return SDL_GetTicks();
}
@ -316,7 +350,7 @@ void platform_mouse_delta_get(int* x, int* y)
SDL_GetRelativeMouseState(x, y);
}
char* platform_get_base_path(void)
char* platform_base_path_get(void)
{
char* returned_path = SDL_GetBasePath();
char* path = NULL;

@ -4,7 +4,7 @@
#include "num_types.h"
// Function Pointer decls
typedef void (*Keyboard_Event_Func) (int key, int scancode, int state, int mod_ctrl, int mod_shift);
typedef void (*Keyboard_Event_Func) (int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift);
typedef void (*Mousebutton_Event_Func) (int button, int state, int x, int y, int8 num_clicks);
typedef void (*Mousemotion_Event_Func) (int x, int y, int xrel, int yrel);
typedef void (*Mousewheel_Event_Func) (int x, int y);
@ -25,6 +25,7 @@ void window_set_size(struct Window* window, int width, int height);
void window_get_size(struct Window* window, int* out_width, int* out_height);
void window_get_drawable_size(struct Window* window, int* out_width, int* out_height);
void window_swap_buffers(struct Window* window);
int window_fullscreen_set(struct Window* window, int fullscreen);
// Platform functions
int platform_init(void);
@ -44,8 +45,8 @@ void platform_mouse_position_set(struct Window* window, int x, int y);
void platform_mouse_global_position_set(int x, int y);
void platform_mouse_relative_mode_set(int relative_mode);
int platform_mouse_relative_mode_get(void);
uint32 platform_get_ticks(void);
char* platform_get_base_path(void);
uint32 platform_ticks_get(void);
char* platform_base_path_get(void);
void platform_clipboard_text_set(const char* text);
char* platform_clipboard_text_get(void);

Loading…
Cancel
Save