138 lines
4.6 KiB
C
138 lines
4.6 KiB
C
#ifndef GAME_H
|
|
#define GAME_H
|
|
|
|
#include "AssetManager.h"
|
|
#include "BitmapFont.h"
|
|
#include "ObjectStore.h"
|
|
#include "Renderer.h"
|
|
#include "SDL_pixels.h"
|
|
#include "Window.h"
|
|
#include "aliases.h"
|
|
#include "reusable_ids.h"
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // !__cplusplus
|
|
|
|
// GENERAL ENGINE API
|
|
|
|
/**
|
|
* Initialises the game engine. Returns true on success and false on failure.
|
|
*
|
|
* The audio_tracks parameter determines how many audio tracks to be allocated.
|
|
* Pass 0 if you want to allocate the default number.
|
|
*/
|
|
bool init_engine(const char *game_name, WindowSize window_size,
|
|
SDL_Color window_background_color, bool full_screen,
|
|
u8 audio_tracks);
|
|
|
|
bool game_running();
|
|
void stop_game();
|
|
void close_engine();
|
|
|
|
i64 get_time();
|
|
// END GENERAL ENGINE API
|
|
|
|
// OBJECT MANAGEMENT API
|
|
ObjectID add_object(void *object, EventHandlerPtr eh, UpdateFuncPtr uf,
|
|
RenderFuncPtr rf);
|
|
void remove_object(ObjectID *id);
|
|
// END OBJECT MANAGEMENT API
|
|
|
|
// ASSET MANAGEMENT API
|
|
AssetID load_asset(const char *path, AssetType type);
|
|
void unload_asset(AssetID *id);
|
|
BitmapFont *load_bitmap_font(const char *filepath, u64 tile_width,
|
|
u64 tile_height);
|
|
void unload_bitmap_font(BitmapFont **font);
|
|
// END ASSET MANAGEMENT API
|
|
|
|
// RENDERING API
|
|
|
|
/**
|
|
* Returns the user-defined window size or the screen size when in full screen.
|
|
*/
|
|
WindowSize get_window_defined_size();
|
|
|
|
/**
|
|
* Returns the actual window size which can be different from the user-defined
|
|
* size or the screen size if the window is on a display that supports high DPI.
|
|
*/
|
|
WindowSize get_window_real_size();
|
|
|
|
/**
|
|
* Returns the valid drawing area which can be a portion of the screen when
|
|
* running in full screen mode and the width to height ratio of the user-defined
|
|
* window size is different from the width to height ratio of the screen.
|
|
*/
|
|
WindowDrawingArea get_window_drawing_area();
|
|
|
|
void draw_rectangle(RenderRect rect, SDL_Color color);
|
|
void fill_rectangle(RenderRect rect, SDL_Color color);
|
|
|
|
/**
|
|
* Ensures that a rendered rectangle is clipped to the drawing area when it is
|
|
* smaller than the actual size of the window.
|
|
*/
|
|
void clip_texture_render_rects_to_drawing_area(RenderRect *src,
|
|
RenderRect *dest);
|
|
|
|
RenderRect get_texture_asset_rect(AssetID id);
|
|
void render_texture_asset(AssetID id, const RenderRect *src,
|
|
const RenderRect *dest);
|
|
void modulate_texture_color(AssetID id, SDL_Color color);
|
|
void modulate_texture_alpha(AssetID id, u8 alpha);
|
|
TextSize get_text_size_from_font_asset(AssetID id, const char *text);
|
|
void set_font_asset_size(AssetID id, u32 size);
|
|
i32 set_font_direction(AssetID id, FontDirection direction);
|
|
i32 set_font_script_name(AssetID id, const char *script);
|
|
void render_text_with_font_asset(AssetID id, const char *text,
|
|
const RenderRect *src, RenderRect dest,
|
|
SDL_Color color);
|
|
void render_text_with_bitmap_font(BitmapFont *font, const char *text,
|
|
u64 font_size, u64 start_index,
|
|
RenderRect dest, SDL_Color color);
|
|
// END RENDERING API
|
|
|
|
// AUDIO API
|
|
i8 play_audio_asset(AssetID id, i16 loops, bool fade_in, u32 fade_length_in_ms);
|
|
void pause_audio_asset_on_track(AssetID id, u8 track);
|
|
void resume_audio_asset_on_track(AssetID id, u8 track);
|
|
void stop_audio_asset_on_track(AssetID id, u8 track);
|
|
void fade_out_audio_asset_on_track(AssetID id, u8 track, u32 fade_length_in_ms);
|
|
void pause_all_instances_of_audio_asset(AssetID id);
|
|
void resume_all_instances_of_audio_asset(AssetID id);
|
|
void stop_all_instances_of_audio_asset(AssetID id);
|
|
void fade_out_all_instances_of_audio_asset(AssetID id, u32 fade_length_in_ms);
|
|
i8 get_audio_asset_volume(AssetID id);
|
|
void set_audio_asset_volume(AssetID id, i8 volume);
|
|
void play_music_asset(AssetID id, i16 loops, bool fade_in,
|
|
u32 fade_length_in_ms);
|
|
void pause_music_asset(AssetID id);
|
|
void resume_music_asset(AssetID id);
|
|
void stop_music_asset(AssetID id);
|
|
void fade_out_music_asset(AssetID id, u32 fade_length_in_ms);
|
|
i8 get_music_asset_volume(AssetID id);
|
|
void set_music_asset_volume(AssetID id, i8 volume);
|
|
bool is_music_asset_playing(AssetID id);
|
|
void pause_playing_music();
|
|
void resume_playing_music();
|
|
void stop_playing_music();
|
|
void fade_out_playing_music(u32 fade_length_in_ms);
|
|
void set_playing_music_volume(i8 volume);
|
|
bool is_music_playing();
|
|
// END AUDIO API
|
|
|
|
// GAME LOOP API
|
|
void handle_events();
|
|
void update();
|
|
void render();
|
|
// END GAME LOOP API
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif // !__cplusplus
|
|
|
|
#endif // !GAME_H
|