Files
punchie-engine/include/GameEngine.h
T

125 lines
3.9 KiB
C

#ifndef GAME_H
#define GAME_H
#include "AssetManager.h"
#include "ObjectStore.h"
#include "Renderer.h"
#include "SDL_pixels.h"
#include "Window.h"
#include "reusable_ids.h"
#include <aliases.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 close_engine();
i64 get_time();
// END GENERAL ENGINE API
// ASSET MANAGEMENT API
ObjectID add_object(void *object, EventHandlerPtr eh, UpdateFuncPtr uf,
RenderFuncPtr rf);
void remove_object(ObjectID *id);
// END ASSET MANAGEMENT API
// ASSET MANAGEMENT API
AssetID load_asset(const char *path, AssetType type);
void unload_asset(AssetID *id);
// 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_render_rects_to_drawing_area(RenderRect *src, RenderRect *dest);
RenderRect get_texture_asset_rect(AssetID id);
void render_texture_asset(AssetID id, RenderRect *src, 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 render_text_with_font_asset(AssetID id, const char *text, f32 x, f32 y,
SDL_Color color);
void set_font_asset_size(AssetID id, u32 size);
// 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