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 ;
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>
# 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>
2016-11-06 03:10:43 +01:00
# ifdef ALLEGRO_ANDROID
# include <allegro5/allegro_android.h>
# endif
2017-08-22 21:54:58 +02:00
# ifdef __EMSCRIPTEN__
2017-08-24 21:09:07 +02:00
# include "emscripten-audio-stream.h"
2017-09-10 21:35:14 +02:00
# include <emscripten.h>
2017-08-22 21:54:58 +02:00
# endif
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"
2016-07-03 00:43:32 +02:00
# include "timeline.h"
# include "utils.h"
2017-09-10 21:35:14 +02:00
# include <sys/param.h>
2012-02-16 15:40:58 +01:00
2016-07-03 22:38:36 +02:00
# ifndef LIBSUPERDERPY_DATA_TYPE
# define LIBSUPERDERPY_DATA_TYPE void
# endif
2012-12-24 19:41:12 +01:00
struct Gamestate ;
2012-05-03 13:20:25 +02:00
2016-09-08 00:32:21 +02:00
struct Viewport {
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. */
bool pixel_perfect ; /*!< Ensure that the resulting image is really viewport-sized and (potentially) rescaled afterwards, as opposed to default transformation-based scaling. */
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. */
ALLEGRO_TRANSFORM projection ; /*!< Projection of the game canvas into the actual game window. */
struct Viewport viewport , viewport_config ;
struct {
int fx ; /*!< Effects volume. */
int music ; /*!< Music volume. */
int voice ; /*!< Voice volume. */
bool fullscreen ; /*!< Fullscreen toggle. */
bool debug ; /*!< Toggles debug mode. */
int width ; /*!< Width of window as being set in configuration. */
int height ; /*!< Height of window as being set in configuration. */
} config ;
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. */
struct {
struct Gamestate * gamestates ; /*!< List of known gamestates. */
bool gamestate_scheduled ; /*!< Whether there's some gamestate lifecycle management work to do. */
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
2018-02-03 03:46:33 +01:00
ALLEGRO_BITMAP * fb ; /*!< Default framebuffer. */
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 ;
int loaded , toLoad ;
bool inProgress ;
} 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
2017-09-10 21:35:14 +02:00
struct libsuperderpy_list * garbage , * timelines ;
2016-08-15 04:37:27 +02:00
2017-09-10 21:35:14 +02:00
bool draw ;
2016-11-06 03:10:43 +01:00
2018-02-03 03:37:44 +01:00
double timestamp ;
2018-02-03 03:46:33 +01:00
struct {
int x , y ;
int w , h ;
} clip_rect ;
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
2017-09-10 21:35:14 +02:00
} _priv ; /*!< Private resources. Do not use in gamestates! */
2012-05-19 18:09:20 +02:00
2017-09-10 21:35:14 +02:00
bool shutting_down ; /*!< If true then shut down of the game is pending. */
bool restart ; /*!< If true then restart of the game is pending. */
bool touch ;
2012-03-08 22:21:02 +01:00
2017-09-10 21:35:14 +02:00
bool show_loading_on_launch ;
2016-08-20 03:32:32 +02:00
2017-09-10 21:35:14 +02:00
const char * name ;
2016-07-03 22:38:36 +02:00
2017-09-10 21:35:14 +02:00
ALLEGRO_EVENT_SOURCE event_source ;
2016-08-29 22:47:55 +02:00
2017-09-10 21:35:14 +02:00
float loading_progress ;
2016-11-08 22:11:10 +01:00
2017-09-10 21:35:14 +02:00
struct {
bool ( * event ) ( struct Game * game , ALLEGRO_EVENT * ev ) ;
void ( * destroy ) ( struct Game * game ) ;
2018-02-03 03:46:33 +01:00
void ( * compositor ) ( struct Game * game , struct Gamestate * gamestates ) ;
2018-02-03 03:39:30 +01:00
void ( * prelogic ) ( struct Game * game , double delta ) ;
void ( * postlogic ) ( struct Game * game , double delta ) ;
void ( * predraw ) ( struct Game * game ) ;
void ( * postdraw ) ( struct Game * game ) ;
2017-09-10 21:35:14 +02:00
} handlers ;
2016-07-03 22:38:36 +02:00
2017-09-10 21:35:14 +02:00
LIBSUPERDERPY_DATA_TYPE * data ;
2012-12-24 19:41:12 +01:00
} ;
2012-08-04 20:58:24 +02:00
2017-09-10 21:35:14 +02:00
struct Game * libsuperderpy_init ( int argc , char * * argv , const char * name , struct Viewport viewport ) ;
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
2017-09-09 00:11:43 +02:00
struct GamestateResources ;
extern int Gamestate_ProgressCount ;
2017-09-10 21:35:14 +02:00
void Gamestate_ProcessEvent ( struct Game * game , struct GamestateResources * data , ALLEGRO_EVENT * ev ) ;
2018-02-03 03:37:44 +01:00
void Gamestate_Logic ( struct Game * game , struct GamestateResources * data , double delta ) ;
2017-09-10 21:35:14 +02:00
void Gamestate_Draw ( struct Game * game , struct GamestateResources * data ) ;
void * Gamestate_Load ( struct Game * game , void ( * progress ) ( struct Game * ) ) ;
void Gamestate_Unload ( struct Game * game , struct GamestateResources * data ) ;
void Gamestate_Start ( struct Game * game , struct GamestateResources * data ) ;
void Gamestate_Stop ( struct Game * game , struct GamestateResources * data ) ;
void Gamestate_Reload ( struct Game * game , struct GamestateResources * data ) ;
void Gamestate_Pause ( struct Game * game , struct GamestateResources * data ) ;
void Gamestate_Resume ( struct Game * game , struct GamestateResources * data ) ;
2017-09-09 00:11:43 +02:00
2012-02-26 00:47:41 +01:00
# endif