ref: c51a074fad4fba6ccbd51e13205966790bc4834d
parent: fd0733f6e77a4d0ed07f3d198449e1d34dba12cb
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Apr 13 14:19:39 EDT 2020
Big disgusting backend rework We need to avoid `WindowsWrapper.h` in the backends whenever we can, to avoid name collisions (the Wii U homebrew library) defines its own BOOL/TRUE/FALSE, which really doesn't work with CSE2.
--- a/src/Backends/Audio.h
+++ b/src/Backends/Audio.h
@@ -2,17 +2,15 @@
#include <stddef.h>
-#include "../WindowsWrapper.h"
-
typedef struct AudioBackend_Sound AudioBackend_Sound;
-BOOL AudioBackend_Init(void);
+bool AudioBackend_Init(void);
void AudioBackend_Deinit(void);
AudioBackend_Sound* AudioBackend_CreateSound(unsigned int frequency, const unsigned char *samples, size_t length);
void AudioBackend_DestroySound(AudioBackend_Sound *sound);
-void AudioBackend_PlaySound(AudioBackend_Sound *sound, BOOL looping);
+void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping);
void AudioBackend_StopSound(AudioBackend_Sound *sound);
void AudioBackend_RewindSound(AudioBackend_Sound *sound);
@@ -20,4 +18,4 @@
void AudioBackend_SetSoundVolume(AudioBackend_Sound *sound, long volume);
void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan);
-void AudioBackend_SetOrganyaTimer(unsigned short timer);
+void AudioBackend_SetOrganyaCallback(void (*callback)(void), unsigned int milliseconds);
--- a/src/Backends/Audio/SDL2.cpp
+++ b/src/Backends/Audio/SDL2.cpp
@@ -7,8 +7,6 @@
#include "SDL.h"
#include "../Misc.h"
-#include "../../Organya.h"
-#include "../../WindowsWrapper.h"
#include "SoftwareMixer.h"
@@ -18,7 +16,8 @@
static unsigned long output_frequency;
-static unsigned short organya_timer;
+static void (*organya_callback)(void);
+static unsigned int organya_callback_milliseconds;
static void Callback(void *user_data, Uint8 *stream_uint8, int len)
{
@@ -30,7 +29,7 @@
for (unsigned int i = 0; i < frames_total * 2; ++i)
stream[i] = 0.0f;
- if (organya_timer == 0)
+ if (organya_callback_milliseconds == 0)
{
Mixer_MixSounds(stream, frames_total);
}
@@ -49,8 +48,8 @@
if (organya_countdown == 0)
{
- organya_countdown = (organya_timer * output_frequency) / 1000; // organya_timer is in milliseconds, so convert it to audio frames
- UpdateOrganya();
+ organya_countdown = (organya_callback_milliseconds * output_frequency) / 1000; // organya_timer is in milliseconds, so convert it to audio frames
+ organya_callback();
}
const unsigned int frames_to_do = MIN(organya_countdown, frames_total - frames_done);
@@ -63,13 +62,13 @@
}
}
-BOOL AudioBackend_Init(void)
+bool AudioBackend_Init(void)
{
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
std::string errorMessage = std::string("'SDL_InitSubSystem(SDL_INIT_AUDIO)' failed: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", errorMessage.c_str());
- return FALSE;
+ return false;
}
Backend_PrintInfo("Available SDL audio drivers:");
@@ -91,7 +90,7 @@
{
std::string error_message = std::string("'SDL_OpenAudioDevice' failed: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", error_message.c_str());
- return FALSE;
+ return false;
}
output_frequency = obtained_specification.freq;
@@ -101,7 +100,7 @@
Backend_PrintInfo("Selected SDL audio driver: %s", SDL_GetCurrentAudioDriver());
- return TRUE;
+ return true;
}
void AudioBackend_Deinit(void)
@@ -134,7 +133,7 @@
SDL_UnlockAudioDevice(device_id);
}
-void AudioBackend_PlaySound(AudioBackend_Sound *sound, BOOL looping)
+void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
{
if (sound == NULL)
return;
@@ -206,11 +205,12 @@
SDL_UnlockAudioDevice(device_id);
}
-void AudioBackend_SetOrganyaTimer(unsigned short timer)
+void AudioBackend_SetOrganyaCallback(void (*callback)(void), unsigned int milliseconds)
{
SDL_LockAudioDevice(device_id);
- organya_timer = timer;
+ organya_callback = callback;
+ organya_callback_milliseconds = milliseconds;
SDL_UnlockAudioDevice(device_id);
}
--- a/src/Backends/Audio/miniaudio.cpp
+++ b/src/Backends/Audio/miniaudio.cpp
@@ -8,8 +8,6 @@
#include "../../../external/miniaudio.h"
#include "../Misc.h"
-#include "../../Organya.h"
-#include "../../WindowsWrapper.h"
#include "SoftwareMixer.h"
@@ -21,7 +19,8 @@
static unsigned long output_frequency;
-static unsigned short organya_timer;
+static void (*organya_callback)(void);
+static unsigned int organya_callback_milliseconds;
static void Callback(ma_device *device, void *output_stream, const void *input_stream, ma_uint32 frames_total)
{
@@ -32,7 +31,7 @@
ma_mutex_lock(&organya_mutex);
- if (organya_timer == 0)
+ if (organya_callback_milliseconds == 0)
{
ma_mutex_lock(&mutex);
Mixer_MixSounds(stream, frames_total);
@@ -53,8 +52,8 @@
if (organya_countdown == 0)
{
- organya_countdown = (organya_timer * output_frequency) / 1000; // organya_timer is in milliseconds, so convert it to audio frames
- UpdateOrganya();
+ organya_countdown = (organya_callback_milliseconds * output_frequency) / 1000; // organya_timer is in milliseconds, so convert it to audio frames
+ organya_callback();
}
const unsigned int frames_to_do = MIN(organya_countdown, frames_total - frames_done);
@@ -71,7 +70,7 @@
ma_mutex_unlock(&organya_mutex);
}
-BOOL AudioBackend_Init(void)
+bool AudioBackend_Init(void)
{
ma_device_config config = ma_device_config_init(ma_device_type_playback);
config.playback.pDeviceID = NULL;
@@ -103,7 +102,7 @@
Mixer_Init(device.sampleRate);
- return TRUE;
+ return true;
}
else
{
@@ -132,7 +131,7 @@
}
- return FALSE;
+ return false;
}
void AudioBackend_Deinit(void)
@@ -172,7 +171,7 @@
ma_mutex_unlock(&mutex);
}
-void AudioBackend_PlaySound(AudioBackend_Sound *sound, BOOL looping)
+void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
{
if (sound == NULL)
return;
@@ -244,11 +243,12 @@
ma_mutex_unlock(&mutex);
}
-void AudioBackend_SetOrganyaTimer(unsigned short timer)
+void AudioBackend_SetOrganyaCallback(void (*callback)(void), unsigned int milliseconds)
{
ma_mutex_lock(&organya_mutex);
- organya_timer = timer;
+ organya_callback = callback;
+ organya_callback_milliseconds = milliseconds;
ma_mutex_unlock(&organya_mutex);
}
--- a/src/Backends/GLFW3/Controller.cpp
+++ b/src/Backends/GLFW3/Controller.cpp
@@ -1,7 +1,6 @@
#include "../Controller.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
#define GLFW_INCLUDE_NONE
--- a/src/Backends/GLFW3/Misc.cpp
+++ b/src/Backends/GLFW3/Misc.cpp
@@ -10,8 +10,6 @@
#include <GLFW/glfw3.h>
-#include "../../WindowsWrapper.h"
-
#include "Window.h"
#include "../Rendering.h"
#include "../../Attributes.h"
@@ -25,7 +23,7 @@
keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \
break;
-static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
+static bool keyboard_state[BACKEND_KEYBOARD_TOTAL];
static GLFWcursor* cursor;
@@ -155,16 +153,16 @@
Backend_PrintError("GLFW error received (%d): %s", code, description);
}
-BOOL Backend_Init(void)
+bool Backend_Init(void)
{
glfwSetErrorCallback(ErrorCallback);
if (glfwInit() == GL_TRUE)
- return TRUE;
+ return true;
Backend_ShowMessageBox("Fatal error", "Could not initialise GLFW3");
- return FALSE;
+ return false;
}
void Backend_Deinit(void)
@@ -183,12 +181,12 @@
glfwSetWindowSizeCallback(window, WindowSizeCallback);
}
-BOOL Backend_GetBasePath(char *string_buffer)
+bool Backend_GetBasePath(char *string_buffer)
{
(void)string_buffer;
// GLFW3 doesn't seem to have a mechanism for this
- return FALSE;
+ return false;
}
void Backend_HideMouse(void)
@@ -270,12 +268,12 @@
glfwSetDropCallback(window, DragAndDropCallback);
}
-BOOL Backend_SystemTask(BOOL active)
+bool Backend_SystemTask(bool active)
{
if (glfwWindowShouldClose(window))
{
StopOrganyaMusic();
- return FALSE;
+ return false;
}
if (active)
@@ -283,10 +281,10 @@
else
glfwWaitEvents();
- return TRUE;
+ return true;
}
-void Backend_GetKeyboardState(BOOL *out_keyboard_state)
+void Backend_GetKeyboardState(bool *out_keyboard_state)
{
memcpy(out_keyboard_state, keyboard_state, sizeof(keyboard_state));
}
--- a/src/Backends/GLFW3/Window-OpenGL3.cpp
+++ b/src/Backends/GLFW3/Window-OpenGL3.cpp
@@ -11,13 +11,11 @@
#endif
#include <GLFW/glfw3.h>
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
GLFWwindow *window;
-BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
{
#ifdef USE_OPENGLES2
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
@@ -61,7 +59,7 @@
#endif
Backend_PostWindowCreation();
- return TRUE;
+ return true;
#ifndef USE_OPENGLES2
}
else
@@ -82,7 +80,7 @@
Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window");
}
- return FALSE;
+ return false;
}
void WindowBackend_OpenGL_DestroyWindow(void)
--- a/src/Backends/GLFW3/Window-Software.cpp
+++ b/src/Backends/GLFW3/Window-Software.cpp
@@ -11,8 +11,6 @@
#endif
#include <GLFW/glfw3.h>
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
GLFWwindow *window;
@@ -26,7 +24,7 @@
static GLuint screen_texture_id;
-unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, BOOL fullscreen, size_t *pitch)
+unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch)
{
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
--- a/src/Backends/Misc.h
+++ b/src/Backends/Misc.h
@@ -1,7 +1,6 @@
#pragma once
#include "../Attributes.h"
-#include "../WindowsWrapper.h"
enum
{
@@ -84,16 +83,16 @@
BACKEND_KEYBOARD_TOTAL
};
-BOOL Backend_Init(void);
+bool Backend_Init(void);
void Backend_Deinit(void);
void Backend_PostWindowCreation(void);
-BOOL Backend_GetBasePath(char *string_buffer);
+bool Backend_GetBasePath(char *string_buffer);
void Backend_HideMouse(void);
void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
void PlaybackBackend_EnableDragAndDrop(void);
-BOOL Backend_SystemTask(BOOL active);
-void Backend_GetKeyboardState(BOOL *keyboard_state);
+bool Backend_SystemTask(bool active);
+void Backend_GetKeyboardState(bool *keyboard_state);
void Backend_ShowMessageBox(const char *title, const char *message);
ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintError(const char *format, ...);
ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintInfo(const char *format, ...);
--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -1,22 +1,28 @@
#pragma once
-#include "../WindowsWrapper.h"
-
typedef struct RenderBackend_Surface RenderBackend_Surface;
typedef struct RenderBackend_Glyph RenderBackend_Glyph;
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen);
+typedef struct RenderBackend_Rect
+{
+ long left;
+ long top;
+ long right;
+ long bottom;
+} RenderBackend_Rect;
+
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen);
void RenderBackend_Deinit(void);
void RenderBackend_DrawScreen(void);
void RenderBackend_ClearScreen(void);
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height);
void RenderBackend_FreeSurface(RenderBackend_Surface *surface);
-BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface);
+bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface);
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface);
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height);
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height);
-void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key);
-void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue);
+void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key);
+void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue);
RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch);
void RenderBackend_UnloadGlyph(RenderBackend_Glyph *glyph);
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surface, const unsigned char *colour_channels);
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -3,7 +3,6 @@
#include "../Rendering.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -584,7 +583,7 @@
// Render-backend initialisation
// ====================
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
#ifndef USE_OPENGLES2
glad_set_post_callback(PostGLCallCallback);
@@ -855,11 +854,11 @@
free(surface);
}
-BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
+bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
{
(void)surface;
- return FALSE;
+ return false;
}
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
@@ -897,7 +896,7 @@
// Drawing
// ====================
-void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key)
+void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)
{
if (source_surface == NULL || destination_surface == NULL)
return;
@@ -976,7 +975,7 @@
}
}
-void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
+void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue)
{
static unsigned char last_red;
static unsigned char last_green;
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -7,8 +7,6 @@
#include "SDL.h"
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
#include "../SDL2/Window.h"
@@ -31,7 +29,7 @@
static unsigned char glyph_colour_channels[3];
static SDL_Surface *glyph_destination_sdlsurface;
-static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect)
+static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
{
sdl_rect->x = (int)rect->left;
sdl_rect->y = (int)rect->top;
@@ -45,7 +43,7 @@
sdl_rect->h = 0;
}
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
@@ -130,11 +128,11 @@
free(surface);
}
-BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
+bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
{
(void)surface;
- return FALSE;
+ return false;
}
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
@@ -161,7 +159,7 @@
(void)height;
}
-void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key)
+void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)
{
if (source_surface == NULL || destination_surface == NULL)
return;
@@ -183,7 +181,7 @@
Backend_PrintError("Couldn't blit surface: %s", SDL_GetError());
}
-void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
+void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue)
{
if (surface == NULL)
return;
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -1,7 +1,6 @@
#include "../Rendering.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
@@ -26,7 +25,7 @@
unsigned char *pixels;
unsigned int width;
unsigned int height;
- BOOL lost;
+ bool lost;
struct RenderBackend_Surface *next;
struct RenderBackend_Surface *prev;
@@ -51,7 +50,7 @@
static spritebatch_t glyph_batcher;
-static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect)
+static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
{
sdl_rect->x = (int)rect->left;
sdl_rect->y = (int)rect->top;
@@ -126,7 +125,7 @@
SDL_DestroyTexture((SDL_Texture*)texture_id);
}
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
Backend_PrintInfo("Available SDL render drivers:");
@@ -254,7 +253,7 @@
surface->width = width;
surface->height = height;
- surface->lost = FALSE;
+ surface->lost = false;
// Add to linked-list
surface->prev = NULL;
@@ -282,7 +281,7 @@
free(surface);
}
-BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
+bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
{
return surface->lost;
}
@@ -289,7 +288,7 @@
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
{
- surface->lost = FALSE;
+ surface->lost = false;
}
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
@@ -349,7 +348,7 @@
free(buffer);
}
-void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key)
+void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)
{
if (source_surface == NULL || destination_surface == NULL)
return;
@@ -370,7 +369,7 @@
Backend_PrintError("Couldn't copy part of texture to rendering target: %s", SDL_GetError());
}
-void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
+void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue)
{
if (surface == NULL)
return;
@@ -474,7 +473,7 @@
void RenderBackend_HandleRenderTargetLoss(void)
{
for (RenderBackend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next)
- surface->lost = TRUE;
+ surface->lost = true;
}
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -4,8 +4,6 @@
#include <stdlib.h>
#include <string.h>
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
#include "../Window-Software.h"
#include "../../Attributes.h"
@@ -33,7 +31,7 @@
static unsigned char glyph_colour_channels[3];
static RenderBackend_Surface *glyph_destination_surface;
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
size_t pitch;
framebuffer.pixels = WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen, &pitch);
@@ -91,11 +89,11 @@
free(surface);
}
-BOOL RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
+bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface)
{
(void)surface;
- return FALSE;
+ return false;
}
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
@@ -122,12 +120,12 @@
(void)height;
}
-ATTRIBUTE_HOT void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, RenderBackend_Surface *destination_surface, long x, long y, BOOL colour_key)
+ATTRIBUTE_HOT void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)
{
if (source_surface == NULL || destination_surface == NULL)
return;
- RECT rect_clamped;
+ RenderBackend_Rect rect_clamped;
rect_clamped.left = rect->left;
rect_clamped.top = rect->top;
@@ -205,12 +203,12 @@
}
}
-ATTRIBUTE_HOT void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue)
+ATTRIBUTE_HOT void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue)
{
if (surface == NULL)
return;
- RECT rect_clamped;
+ RenderBackend_Rect rect_clamped;
rect_clamped.left = rect->left;
rect_clamped.top = rect->top;
--- a/src/Backends/SDL2/Controller.cpp
+++ b/src/Backends/SDL2/Controller.cpp
@@ -2,7 +2,6 @@
#include "Controller.h"
#include <stddef.h>
-#include <stdio.h>
#include "SDL.h"
--- a/src/Backends/SDL2/Controller.h
+++ b/src/Backends/SDL2/Controller.h
@@ -2,7 +2,5 @@
#include "SDL.h"
-#include "../../WindowsWrapper.h"
-
void ControllerBackend_JoystickConnect(Sint32 joystick_id);
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id);
--- a/src/Backends/SDL2/Misc.cpp
+++ b/src/Backends/SDL2/Misc.cpp
@@ -1,7 +1,6 @@
#include "../Misc.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
@@ -8,8 +7,6 @@
#include "SDL.h"
-#include "../../WindowsWrapper.h"
-
#include "Controller.h"
#include "Window.h"
#include "../Rendering.h"
@@ -23,13 +20,13 @@
keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \
break;
-static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
+static bool keyboard_state[BACKEND_KEYBOARD_TOTAL];
static unsigned char *cursor_surface_pixels;
static SDL_Surface *cursor_surface;
static SDL_Cursor *cursor;
-BOOL Backend_Init(void)
+bool Backend_Init(void)
{
if (SDL_Init(SDL_INIT_EVENTS) == 0)
{
@@ -46,7 +43,7 @@
{
Backend_PrintInfo("Selected SDL video driver: %s", driver);
- return TRUE;
+ return true;
}
else
{
@@ -67,7 +64,7 @@
Backend_ShowMessageBox("Fatal error", error_message.c_str());
}
- return FALSE;
+ return false;
}
void Backend_Deinit(void)
@@ -88,11 +85,11 @@
}
-BOOL Backend_GetBasePath(char *string_buffer)
+bool Backend_GetBasePath(char *string_buffer)
{
char *base_path = SDL_GetBasePath();
if (base_path == NULL)
- return FALSE;
+ return false;
// Trim the trailing '/'
size_t base_path_length = strlen(base_path);
@@ -100,7 +97,7 @@
strcpy(string_buffer, base_path);
SDL_free(base_path);
- return TRUE;
+ return true;
}
void Backend_HideMouse(void)
@@ -155,7 +152,7 @@
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
}
-BOOL Backend_SystemTask(BOOL active)
+bool Backend_SystemTask(bool active)
{
if (SDL_PollEvent(NULL) || !active)
{
@@ -162,7 +159,7 @@
SDL_Event event;
if (!SDL_WaitEvent(&event))
- return FALSE;
+ return false;
switch (event.type)
{
@@ -286,7 +283,7 @@
case SDL_QUIT:
StopOrganyaMusic();
- return FALSE;
+ return false;
case SDL_RENDER_TARGETS_RESET:
RenderBackend_HandleRenderTargetLoss();
@@ -295,10 +292,10 @@
}
}
- return TRUE;
+ return true;
}
-void Backend_GetKeyboardState(BOOL *out_keyboard_state)
+void Backend_GetKeyboardState(bool *out_keyboard_state)
{
memcpy(out_keyboard_state, keyboard_state, sizeof(keyboard_state));
}
--- a/src/Backends/SDL2/Window-OpenGL3.cpp
+++ b/src/Backends/SDL2/Window-OpenGL3.cpp
@@ -11,8 +11,6 @@
#endif
#include "SDL.h"
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
#include "../../Resource.h"
@@ -20,7 +18,7 @@
static SDL_GLContext context;
-BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
{
#ifdef USE_OPENGLES2
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES) < 0)
@@ -67,7 +65,7 @@
#endif
Backend_PostWindowCreation();
- return TRUE;
+ return true;
#ifndef USE_OPENGLES2
}
else
@@ -103,7 +101,7 @@
Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", error_message.c_str());
}
- return FALSE;
+ return false;
}
void WindowBackend_OpenGL_DestroyWindow(void)
--- a/src/Backends/SDL2/Window-Software.cpp
+++ b/src/Backends/SDL2/Window-Software.cpp
@@ -7,8 +7,6 @@
#include "SDL.h"
-#include "../../WindowsWrapper.h"
-
#include "../Misc.h"
SDL_Window *window;
@@ -16,7 +14,7 @@
static SDL_Surface *window_sdlsurface;
static SDL_Surface *framebuffer_sdlsurface;
-unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, BOOL fullscreen, size_t *pitch)
+unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch)
{
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
--- a/src/Backends/Window-OpenGL.h
+++ b/src/Backends/Window-OpenGL.h
@@ -2,6 +2,6 @@
#include "../WindowsWrapper.h"
-BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen);
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen);
void WindowBackend_OpenGL_DestroyWindow(void);
void WindowBackend_OpenGL_Display(void);
--- a/src/Backends/Window-Software.h
+++ b/src/Backends/Window-Software.h
@@ -2,9 +2,7 @@
#include <stddef.h>
-#include "../WindowsWrapper.h"
-
-unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, BOOL fullscreen, size_t *pitch);
+unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch);
void WindowBackend_Software_DestroyWindow(void);
void WindowBackend_Software_Display(void);
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -412,7 +412,7 @@
void BackupSurface(SurfaceID surf_no, const RECT *rect)
{
- static RECT scaled_rect;
+ static RenderBackend_Rect scaled_rect;
scaled_rect.left = rect->left * magnification;
scaled_rect.top = rect->top * magnification;
scaled_rect.right = rect->right * magnification;
@@ -423,9 +423,12 @@
void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no) // Transparency
{
- static RECT rcWork;
+ static RenderBackend_Rect rcWork;
- rcWork = *rect;
+ rcWork.left = rect->left;
+ rcWork.top = rect->top;
+ rcWork.right = rect->right;
+ rcWork.bottom = rect->bottom;
if (x + rect->right - rect->left > rcView->right)
rcWork.right -= (x + rect->right - rect->left) - rcView->right;
@@ -455,9 +458,12 @@
void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no) // No Transparency
{
- static RECT rcWork;
+ static RenderBackend_Rect rcWork;
- rcWork = *rect;
+ rcWork.left = rect->left;
+ rcWork.top = rect->top;
+ rcWork.right = rect->right;
+ rcWork.bottom = rect->bottom;
if (x + rect->right - rect->left > rcView->right)
rcWork.right -= (x + rect->right - rect->left) - rcView->right;
@@ -487,7 +493,7 @@
void Surface2Surface(int x, int y, const RECT *rect, int to, int from)
{
- static RECT rcWork;
+ static RenderBackend_Rect rcWork;
rcWork.left = rect->left * magnification;
rcWork.top = rect->top * magnification;
@@ -505,7 +511,7 @@
void CortBox(const RECT *rect, unsigned long col)
{
- static RECT dst_rect;
+ static RenderBackend_Rect dst_rect;
dst_rect.left = rect->left * magnification;
dst_rect.top = rect->top * magnification;
dst_rect.right = rect->right * magnification;
@@ -520,7 +526,7 @@
void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no)
{
- static RECT dst_rect;
+ static RenderBackend_Rect dst_rect;
dst_rect.left = rect->left * magnification;
dst_rect.top = rect->top * magnification;
dst_rect.right = rect->right * magnification;
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -19,7 +19,7 @@
BOOL GetJoystickStatus(JOYSTICK_STATUS *status)
{
- BOOL *buttons;
+ bool *buttons;
unsigned int button_count;
short *axes;
@@ -63,7 +63,7 @@
BOOL ResetJoystickStatus(void)
{
- BOOL *buttons;
+ bool *buttons;
unsigned int button_count;
short *axes;
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -395,7 +395,7 @@
return FALSE;
} while(!bActive);
- BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
+ bool keyboard_state[BACKEND_KEYBOARD_TOTAL];
Backend_GetKeyboardState(keyboard_state);
for (unsigned int i = 0; i < BACKEND_KEYBOARD_TOTAL; ++i)
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -398,6 +398,11 @@
ORGDATA org_data;
+static void OrganyaCallback(void)
+{
+ org_data.PlayData();
+}
+
OrgData::OrgData(void)
{
for (int i = 0; i < MAXTRACK; i++)
@@ -830,7 +835,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaTimer(org_data.info.wait);
+ AudioBackend_SetOrganyaCallback(OrganyaCallback, org_data.info.wait);
}
BOOL ChangeOrganyaVolume(signed int volume)
@@ -850,7 +855,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaTimer(0);
+ AudioBackend_SetOrganyaCallback(NULL, 0);
// Stop notes
for (int i = 0; i < MAXMELODY; i++)
@@ -873,7 +878,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaTimer(0);
+ AudioBackend_SetOrganyaCallback(NULL, 0);
// Release everything related to org
org_data.ReleaseNote();
@@ -883,9 +888,4 @@
PlayOrganObject(0, 0, i, 0);
ReleaseOrganyaObject(i);
}
-}
-
-void UpdateOrganya(void)
-{
- org_data.PlayData();
}
--- a/src/Organya.h
+++ b/src/Organya.h
@@ -20,4 +20,3 @@
void SetOrganyaFadeout(void);
BOOL StartOrganya(const char *wave_filename);
void EndOrganya(void);
-void UpdateOrganya(void);