2017-08-24 21:09:07 +02:00
|
|
|
/*! \file libsuperderpy.h
|
|
|
|
* \brief Headers of main file of libsuperderpy engine.
|
2012-02-28 13:09:12 +01:00
|
|
|
*
|
2017-08-24 21:09:07 +02:00
|
|
|
* Include this to use the engine functions.
|
2012-02-28 13:09:12 +01:00
|
|
|
*/
|
2012-03-04 13:32:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2017-07-22 18:22:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2012-03-04 13:32:42 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-07-22 18:22:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-03-04 13:32:42 +01:00
|
|
|
*/
|
2016-07-03 00:43:32 +02:00
|
|
|
#ifndef LIBSUPERDERPY_MAIN_H
|
|
|
|
#define LIBSUPERDERPY_MAIN_H
|
2012-02-16 15:40:58 +01:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Game;
|
2018-06-30 00:50:55 +02:00
|
|
|
struct GamestateResources;
|
|
|
|
|
|
|
|
#ifndef LIBSUPERDERPY_DATA_TYPE
|
|
|
|
#define LIBSUPERDERPY_DATA_TYPE void
|
|
|
|
#endif
|
2017-09-10 21:35:14 +02:00
|
|
|
|
2018-12-05 02:09:06 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define UNICODE
|
|
|
|
#define _UNICODE
|
|
|
|
#include <tchar.h>
|
|
|
|
#endif
|
|
|
|
|
2012-02-16 15:40:58 +01:00
|
|
|
#include <allegro5/allegro.h>
|
2017-09-10 21:35:14 +02:00
|
|
|
#include <allegro5/allegro_acodec.h>
|
2012-02-16 15:40:58 +01:00
|
|
|
#include <allegro5/allegro_audio.h>
|
2018-11-26 01:25:56 +01:00
|
|
|
#include <allegro5/allegro_color.h>
|
2012-02-16 15:40:58 +01:00
|
|
|
#include <allegro5/allegro_font.h>
|
2017-09-10 21:35:14 +02:00
|
|
|
#include <allegro5/allegro_image.h>
|
2018-02-03 03:41:11 +01:00
|
|
|
#include <allegro5/allegro_opengl.h>
|
2016-08-21 21:58:47 +02:00
|
|
|
#include <allegro5/allegro_primitives.h>
|
|
|
|
#include <allegro5/allegro_ttf.h>
|
2018-04-08 01:33:13 +02:00
|
|
|
#include <allegro5/allegro_video.h>
|
2018-11-26 01:25:56 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#if defined(ALLEGRO_ANDROID)
|
2018-07-31 21:25:07 +02:00
|
|
|
#define ALLEGRO_UNSTABLE
|
2016-11-06 03:10:43 +01:00
|
|
|
#include <allegro5/allegro_android.h>
|
2018-11-26 01:25:56 +01:00
|
|
|
#elif defined(ALLEGRO_WINDOWS)
|
|
|
|
#include <allegro5/allegro_windows.h>
|
|
|
|
#elif defined(ALLEGRO_WITH_XWINDOWS)
|
|
|
|
#include <allegro5/allegro_x.h>
|
|
|
|
#elif defined(ALLEGRO_MACOS)
|
|
|
|
#include <allegro5/allegro_osx.h>
|
|
|
|
#elif defined(ALLEGRO_IPHONE)
|
|
|
|
#include <allegro5/allegro_iphone.h>
|
|
|
|
#elif defined(__EMSCRIPTEN__)
|
2017-09-10 21:35:14 +02:00
|
|
|
#include <emscripten.h>
|
2017-08-22 21:54:58 +02:00
|
|
|
#endif
|
2018-11-26 01:25:56 +01:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
#include "character.h"
|
2016-07-03 00:43:32 +02:00
|
|
|
#include "config.h"
|
2017-09-10 21:35:14 +02:00
|
|
|
#include "gamestate.h"
|
2018-09-10 03:18:52 +02:00
|
|
|
#include "mainloop.h"
|
2018-07-12 20:18:23 +02:00
|
|
|
#include "maths.h"
|
2018-11-26 09:18:28 +01:00
|
|
|
#include "particle.h"
|
2018-05-30 21:11:46 +02:00
|
|
|
#include "shader.h"
|
2016-07-03 00:43:32 +02:00
|
|
|
#include "timeline.h"
|
2018-04-22 05:30:56 +02:00
|
|
|
#include "tween.h"
|
2016-07-03 00:43:32 +02:00
|
|
|
#include "utils.h"
|
2018-11-26 01:25:56 +01:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
#include "emscripten-audio-stream.h"
|
|
|
|
#endif
|
2012-02-16 15:40:58 +01:00
|
|
|
|
2018-11-29 04:37:08 +01:00
|
|
|
#ifdef LIBSUPERDERPY_IMGUI
|
2018-12-05 02:30:53 +01:00
|
|
|
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS 1
|
|
|
|
#include "3rdparty/cimgui/cimgui.h"
|
2018-11-29 04:37:08 +01:00
|
|
|
#endif
|
|
|
|
|
2018-08-03 05:02:44 +02:00
|
|
|
#define LIBSUPERDERPY_BITMAP_HASHMAP_BUCKETS 16
|
|
|
|
|
2018-12-15 05:29:32 +01:00
|
|
|
#if !defined(LIBSUPERDERPY_PRIV_ACCESS) && defined(__GNUC__)
|
2018-12-15 00:59:34 +01:00
|
|
|
#define LIBSUPERDERPY_DEPRECATED_PRIV __attribute__((deprecated))
|
|
|
|
#else
|
|
|
|
#define LIBSUPERDERPY_DEPRECATED_PRIV
|
|
|
|
#endif
|
|
|
|
|
2018-12-05 02:09:06 +01:00
|
|
|
#if defined(ALLEGRO_WINDOWS) && !defined(LIBSUPERDERPY_NO_MAIN_MANGLING)
|
|
|
|
int _libsuperderpy_main(int argc, char** argv);
|
|
|
|
#define main(a, b) \
|
|
|
|
wmain(int argc, wchar_t** wargv) { \
|
|
|
|
char* argv[argc]; \
|
|
|
|
for (int i = 0; i < argc; i++) { \
|
|
|
|
size_t size = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL); \
|
|
|
|
argv[i] = alloca(sizeof(char) * size); \
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], size, NULL, NULL); \
|
|
|
|
} \
|
|
|
|
return _libsuperderpy_main(argc, argv); \
|
|
|
|
} \
|
|
|
|
int _libsuperderpy_main(a, b)
|
|
|
|
#endif
|
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
/*! \brief A list of user callbacks to register. */
|
|
|
|
struct Handlers {
|
|
|
|
bool (*event)(struct Game* game, ALLEGRO_EVENT* ev);
|
|
|
|
void (*destroy)(struct Game* game);
|
|
|
|
void (*compositor)(struct Game* game, struct Gamestate* gamestates, ALLEGRO_BITMAP* loading_fb);
|
|
|
|
void (*prelogic)(struct Game* game, double delta);
|
|
|
|
void (*postlogic)(struct Game* game, double delta);
|
|
|
|
void (*predraw)(struct Game* game);
|
|
|
|
void (*postdraw)(struct Game* game);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Parameters for engine initialization. All values default to 0/false/NULL. */
|
|
|
|
struct Params {
|
2018-02-03 03:46:33 +01:00
|
|
|
int width; /*!< Width of the drawing canvas. */
|
|
|
|
int height; /*!< Height of the drawing canvas. */
|
|
|
|
float aspect; /*!< When set instead of width/height pair, makes the viewport side fluid; when non-zero, locks its aspect ratio. */
|
|
|
|
bool integer_scaling; /*!< Ensure that the viewport is zoomed only with integer factors. */
|
2018-11-27 03:06:43 +01:00
|
|
|
bool depth_buffer; /*!< Request a depth buffer for the framebuffer's render target. */
|
2018-12-15 00:59:34 +01:00
|
|
|
bool show_loading_on_launch; /*!< Whether the loading screen should be shown when loading the initial set of gamestates. */
|
|
|
|
char* window_title; /*!< A title of the game's window. When NULL, al_get_app_name() is used. */
|
|
|
|
struct Handlers handlers; /*!< A list of user callbacks to register. */
|
2016-08-23 02:13:15 +02:00
|
|
|
};
|
|
|
|
|
2012-12-24 19:41:12 +01:00
|
|
|
/*! \brief Main struct of the game. */
|
|
|
|
struct Game {
|
2017-09-10 21:35:14 +02:00
|
|
|
ALLEGRO_DISPLAY* display; /*!< Main Allegro display. */
|
2018-12-15 00:59:34 +01:00
|
|
|
ALLEGRO_EVENT_SOURCE event_source; /*!< Event source for user events. */
|
|
|
|
struct {
|
|
|
|
ALLEGRO_VOICE* v; /*!< Main voice used by the game. */
|
|
|
|
ALLEGRO_MIXER* mixer; /*!< Main mixer of the game. */
|
|
|
|
ALLEGRO_MIXER* music; /*!< Music mixer. */
|
|
|
|
ALLEGRO_MIXER* voice; /*!< Voice mixer. */
|
|
|
|
ALLEGRO_MIXER* fx; /*!< Effects mixer. */
|
|
|
|
} audio; /*!< Audio resources. */
|
2017-09-10 21:35:14 +02:00
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
LIBSUPERDERPY_DATA_TYPE* data; /*!< User defined structure. */
|
2017-09-10 21:35:14 +02:00
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
struct {
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} viewport; /*!< Canvas size. */
|
2017-09-10 21:35:14 +02:00
|
|
|
|
2018-08-03 13:15:06 +02:00
|
|
|
double time; /*!< In-game total passed time in seconds. */
|
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct {
|
|
|
|
int fx; /*!< Effects volume. */
|
|
|
|
int music; /*!< Music volume. */
|
|
|
|
int voice; /*!< Voice volume. */
|
2018-07-26 15:33:02 +02:00
|
|
|
bool mute; /*!< Whether audio should be muted globally. */
|
2017-09-10 21:35:14 +02:00
|
|
|
bool fullscreen; /*!< Fullscreen toggle. */
|
|
|
|
int width; /*!< Width of window as being set in configuration. */
|
|
|
|
int height; /*!< Height of window as being set in configuration. */
|
2018-12-15 01:09:44 +01:00
|
|
|
struct {
|
|
|
|
bool enabled; /*!< Toggles debug mode. */
|
|
|
|
bool verbose; /*!< Prints file names and line numbers with every message. */
|
|
|
|
bool livereload; /*!< Automatically reloads gamestates on window focus. */
|
|
|
|
bool autopause; /*!< Pauses/resumes the game when the window loses/gains focus. */
|
|
|
|
} debug; /*!< Debug mode settings. */
|
2018-12-15 00:59:34 +01:00
|
|
|
} config; /*!< Configuration values from the config file. */
|
2017-09-10 21:35:14 +02:00
|
|
|
|
|
|
|
struct {
|
2018-12-15 00:59:34 +01:00
|
|
|
int x, y;
|
|
|
|
int w, h;
|
|
|
|
} clip_rect; /*!< Clipping rectangle of the display's backbuffer. */
|
2017-09-10 21:35:14 +02:00
|
|
|
|
|
|
|
struct {
|
2018-12-15 00:59:34 +01:00
|
|
|
float progress;
|
|
|
|
bool shown;
|
|
|
|
} loading; /*!< Data about gamestate loading process. */
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct {
|
|
|
|
bool touch;
|
|
|
|
bool joystick;
|
|
|
|
bool mouse;
|
|
|
|
} available;
|
|
|
|
} input;
|
|
|
|
|
2018-12-16 15:15:38 +01:00
|
|
|
/// \private
|
2018-12-15 00:59:34 +01:00
|
|
|
struct {
|
|
|
|
struct Params params;
|
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Gamestate* gamestates; /*!< List of known gamestates. */
|
|
|
|
ALLEGRO_FONT* font_console; /*!< Font used in game console. */
|
|
|
|
ALLEGRO_FONT* font_bsod; /*!< Font used in Blue Screens of Derp. */
|
|
|
|
char console[5][1024];
|
|
|
|
unsigned int console_pos;
|
|
|
|
ALLEGRO_EVENT_QUEUE* event_queue; /*!< Main event queue. */
|
|
|
|
ALLEGRO_TIMER* timer; /*!< Main LPS (logic) timer. */
|
|
|
|
bool showconsole; /*!< If true, game console is rendered on screen. */
|
|
|
|
bool showtimeline;
|
2012-02-16 15:40:58 +01:00
|
|
|
|
2012-12-24 19:41:12 +01:00
|
|
|
struct {
|
2018-03-20 23:49:22 +01:00
|
|
|
double old_time, fps, time;
|
2017-09-10 21:35:14 +02:00
|
|
|
int frames_done;
|
|
|
|
} fps_count; /*!< Used for counting the effective FPS. */
|
2012-02-18 04:14:35 +01:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
ALLEGRO_CONFIG* config; /*!< Configuration file interface. */
|
2012-12-24 19:41:12 +01:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
int argc;
|
|
|
|
char** argv;
|
2012-12-24 19:41:12 +01:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct {
|
|
|
|
struct Gamestate* gamestate;
|
|
|
|
struct Gamestate* current;
|
|
|
|
int progress;
|
2018-12-16 15:35:53 +01:00
|
|
|
int loaded, to_load;
|
2018-12-15 00:59:34 +01:00
|
|
|
volatile bool in_progress;
|
2018-04-21 01:08:39 +02:00
|
|
|
double time;
|
2018-12-15 00:59:34 +01:00
|
|
|
ALLEGRO_BITMAP* fb;
|
2017-09-10 21:35:14 +02:00
|
|
|
} loading;
|
2016-08-16 18:41:50 +02:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Gamestate* current_gamestate;
|
2016-07-04 00:06:50 +02:00
|
|
|
|
2018-08-03 05:02:44 +02:00
|
|
|
struct List *garbage, *timelines, *shaders, *bitmaps[LIBSUPERDERPY_BITMAP_HASHMAP_BUCKETS];
|
2016-08-15 04:37:27 +02:00
|
|
|
|
2018-02-03 03:37:44 +01:00
|
|
|
double timestamp;
|
|
|
|
|
2018-04-16 01:06:58 +02:00
|
|
|
bool paused;
|
|
|
|
|
2018-06-23 04:44:36 +02:00
|
|
|
volatile bool texture_sync;
|
|
|
|
ALLEGRO_MUTEX* texture_sync_mutex;
|
|
|
|
ALLEGRO_COND* texture_sync_cond;
|
|
|
|
|
2018-12-02 00:26:33 +01:00
|
|
|
volatile bool in_bsod;
|
|
|
|
volatile bool bsod_sync;
|
|
|
|
ALLEGRO_MUTEX* bsod_mutex;
|
|
|
|
ALLEGRO_COND* bsod_cond;
|
|
|
|
|
2018-12-14 02:18:05 +01:00
|
|
|
ALLEGRO_MUTEX* mutex;
|
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
const char* name;
|
|
|
|
|
|
|
|
bool shutting_down; /*!< If true then shut down of the game is pending. */
|
|
|
|
bool restart; /*!< If true then restart of the game is pending. */
|
|
|
|
|
|
|
|
ALLEGRO_TRANSFORM projection; /*!< Projection of the game canvas into the actual game window. */
|
|
|
|
|
2016-09-08 00:32:21 +02:00
|
|
|
#ifdef ALLEGRO_MACOSX
|
2017-09-10 21:35:14 +02:00
|
|
|
char cwd[MAXPATHLEN];
|
2016-09-08 00:32:21 +02:00
|
|
|
#endif
|
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
} _priv LIBSUPERDERPY_DEPRECATED_PRIV; /*!< Private resources. Do not use in gamestates! */
|
2012-12-24 19:41:12 +01:00
|
|
|
};
|
2012-08-04 20:58:24 +02:00
|
|
|
|
2018-12-15 00:59:34 +01:00
|
|
|
struct Game* libsuperderpy_init(int argc, char** argv, const char* name, struct Params params);
|
2018-09-10 03:18:52 +02:00
|
|
|
int libsuperderpy_start(struct Game* game);
|
2016-07-03 22:38:36 +02:00
|
|
|
int libsuperderpy_run(struct Game* game);
|
|
|
|
void libsuperderpy_destroy(struct Game* game);
|
2016-07-02 23:23:08 +02:00
|
|
|
|
2012-02-26 00:47:41 +01:00
|
|
|
#endif
|