dev
parent
0547958961
commit
0af53d7456
@ -1,186 +1,211 @@ |
|||||||
#ifndef COMMON_H |
#ifndef COMMON_H |
||||||
#define COMMON_H |
#define COMMON_H |
||||||
|
|
||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
|
|
||||||
#include "num_types.h" |
#include "num_types.h" |
||||||
|
|
||||||
#ifdef GAME_LIB |
#ifdef GAME_LIB |
||||||
extern struct Platform_Api* platform; |
extern struct Platform_Api* platform; |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifdef GAME |
#ifdef GAME |
||||||
extern struct Game_Api game; |
extern struct Game_Api game; |
||||||
#endif |
#endif |
||||||
|
|
||||||
struct Window; |
struct Window; |
||||||
struct Hashmap; |
struct Hashmap; |
||||||
struct Sound_Source_Buffer; |
struct Sound_Source_Buffer; |
||||||
|
|
||||||
//Physics Decls
|
//Physics Decls
|
||||||
typedef void* Rigidbody; |
typedef void* Rigidbody; |
||||||
typedef void (*RigidbodyMoveCB)(Rigidbody); |
typedef void* Collision_Shape; |
||||||
typedef void (*RigidbodyColCB)(Rigidbody, Rigidbody); |
typedef void (*RigidbodyMoveCB)(Rigidbody); |
||||||
|
typedef void (*RigidbodyColCB)(Rigidbody, Rigidbody); |
||||||
// Function Pointer decls
|
|
||||||
typedef void (*Keyboard_Event_Func) (int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift, int mod_alt); |
// Function Pointer decls
|
||||||
typedef void (*Mousebutton_Event_Func) (int button, int state, int x, int y, int8 num_clicks); |
typedef void (*Keyboard_Event_Func) (int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift, int mod_alt); |
||||||
typedef void (*Mousemotion_Event_Func) (int x, int y, int xrel, int yrel); |
typedef void (*Mousebutton_Event_Func) (int button, int state, int x, int y, int8 num_clicks); |
||||||
typedef void (*Mousewheel_Event_Func) (int x, int y); |
typedef void (*Mousemotion_Event_Func) (int x, int y, int xrel, int yrel); |
||||||
typedef void (*Windowresize_Event_Func) (int x, int y); |
typedef void (*Mousewheel_Event_Func) (int x, int y); |
||||||
typedef void (*Textinput_Event_Func) (const char* text); |
typedef void (*Windowresize_Event_Func) (int x, int y); |
||||||
|
typedef void (*Textinput_Event_Func) (const char* text); |
||||||
enum Directory_Type |
|
||||||
{ |
enum Directory_Type |
||||||
DIRT_USER, /* User directory or preferences directory */ |
{ |
||||||
DIRT_INSTALL, /* Directory where the game's assets are, usually alongside the game's executable where the game is installed */ |
DIRT_USER, /* User directory or preferences directory */ |
||||||
DIRT_EXECUTABLE, /* Directory where the game's executable is located */ |
DIRT_INSTALL, /* Directory where the game's assets are, usually alongside the game's executable where the game is installed */ |
||||||
DIRT_COUNT |
DIRT_EXECUTABLE, /* Directory where the game's executable is located */ |
||||||
}; |
DIRT_COUNT |
||||||
|
}; |
||||||
enum Sound_Source_Type |
|
||||||
{ |
enum Sound_Source_Type |
||||||
ST_WAV = 0, |
{ |
||||||
ST_WAV_STREAM |
ST_WAV = 0, |
||||||
}; |
ST_WAV_STREAM |
||||||
|
}; |
||||||
enum Sound_Attenuation_Type |
|
||||||
{ |
enum Sound_Attenuation_Type |
||||||
|
{ |
||||||
SA_NONE = 0, // No attenuation
|
SA_NONE = 0, // No attenuation
|
||||||
SA_INVERSE, // Inverse distance attenuation model
|
SA_INVERSE, // Inverse distance attenuation model
|
||||||
SA_LINEAR, // Linear distance attenuation model
|
SA_LINEAR, // Linear distance attenuation model
|
||||||
SA_EXPONENTIAL // Exponential distance attenuation model
|
SA_EXPONENTIAL // Exponential distance attenuation model
|
||||||
}; |
}; |
||||||
|
|
||||||
struct Physics_Api |
struct Physics_Api |
||||||
{ |
{ |
||||||
void (*init)(void); |
void (*init)(void); |
||||||
void (*cleanup)(void); |
void (*cleanup)(void); |
||||||
void (*step)(float); |
void (*step)(float); |
||||||
void (*gravity_set)(float x, float y, float z); |
void (*gravity_set)(float x, float y, float z); |
||||||
void (*gravity_get)(float* x, float* y, float* z); |
void (*gravity_get)(float* x, float* y, float* z); |
||||||
void (*body_position_set)(Rigidbody body, float x, float y, float z); |
|
||||||
void (*body_position_get)(Rigidbody body, float* x, float* y, float* z); |
void (*cs_remove)(Collision_Shape shape); |
||||||
void (*body_rotation_set)(Rigidbody body, float x, float y, float z, float w); |
|
||||||
void (*body_rotation_get)(Rigidbody body, float* x, float* y, float* z, float* w); |
Collision_Shape (*cs_plane_create)(float a, float b, float c, float d); |
||||||
Rigidbody (*plane_create)(float a, float b, float c, float d); |
void (*cs_plane_params_set)(Collision_Shape shape, float a, float b, float c, float d); |
||||||
Rigidbody (*box_create)(float length, float width, float height); |
void (*cs_plane_params_get)(Collision_Shape shape, float* a, float* b, float* c, float* d); |
||||||
void (*body_set_moved_callback)(RigidbodyMoveCB callback); |
|
||||||
void (*body_set_collision_callback)(RigidbodyColCB callback); |
Collision_Shape (*cs_box_create)(float x, float y, float z); |
||||||
void (*body_kinematic_set)(Rigidbody body); |
void (*cs_box_params_set)(Collision_Shape shape, float x, float y, float z); |
||||||
void (*body_mass_set)(Rigidbody body, float mass); |
void (*cs_box_params_get)(Collision_Shape shape, float* x, float* y, float* z); |
||||||
float (*body_mass_get)(Rigidbody body); |
|
||||||
void* (*body_data_get)(Rigidbody body); |
Collision_Shape (*cs_sphere_create)(float radius); |
||||||
void (*body_data_set)(Rigidbody body, void* data); |
void (*cs_shpere_radius_set)(Collision_Shape shape, float radius); |
||||||
}; |
float (*cs_sphere_radius_get)(Collision_Shape shape); |
||||||
|
|
||||||
struct Sound_Api |
Collision_Shape (*cs_capsule_create)(float radius, float length); |
||||||
{ |
void (*cs_capsule_params_set)(Collision_Shape shape, float radius, float length); |
||||||
void (*update_3d)(void); |
void (*cs_capsule_params_get)(Collision_Shape shape, float* radius, float* length); |
||||||
void (*volume_set)(float volume); |
|
||||||
void (*listener_update)(float apos_x, float apos_y, float apos_z, |
void (*body_remove)(Rigidbody body); |
||||||
float afwd_x, float afwd_y, float afwd_z, |
Rigidbody (*body_box_create)(float length, float width, float height); |
||||||
float aup_x, float aup_y, float aup_z); |
Rigidbody (*body_sphere_create)(float radius); |
||||||
|
Rigidbody (*body_capsule_create)(float radius, float height); |
||||||
void (*source_instance_update_position)(uint source_instance, float apos_x, float apos_y, float apos_z); |
Collision_Shape (*body_cs_get)(Rigidbody body); |
||||||
uint (*source_instance_create)(struct Sound_Source_Buffer* source, bool is3d); |
void (*body_cs_set)(Rigidbody body, Collision_Shape shape); |
||||||
void (*source_instance_destroy)(uint source_instance); |
void (*body_position_set)(Rigidbody body, float x, float y, float z); |
||||||
void (*source_instance_volume_set)(uint source_instance, float volume); |
void (*body_position_get)(Rigidbody body, float* x, float* y, float* z); |
||||||
void (*source_instance_loop_set)(uint source_instance, bool loop); |
void (*body_rotation_set)(Rigidbody body, float x, float y, float z, float w); |
||||||
void (*source_instance_play)(uint source_instance); |
void (*body_rotation_get)(Rigidbody body, float* x, float* y, float* z, float* w); |
||||||
void (*source_instance_pause)(uint source_instance); |
void (*body_set_moved_callback)(RigidbodyMoveCB callback); |
||||||
void (*source_instance_rewind)(uint source_instance); |
void (*body_set_collision_callback)(RigidbodyColCB callback); |
||||||
void (*source_instance_stop)(uint source_instance); |
void (*body_kinematic_set)(Rigidbody body); |
||||||
void (*source_instance_min_max_distance_set)(uint source_instance, float min_distance, float max_distance); |
void (*body_mass_set)(Rigidbody body, float mass); |
||||||
void (*source_instance_attenuation_set)(uint source_instance, int attenuation_type, float rolloff_factor); |
float (*body_mass_get)(Rigidbody body); |
||||||
float (*source_instance_volume_get)(uint source_instance); |
void* (*body_data_get)(Rigidbody body); |
||||||
bool (*source_instance_loop_get)(uint source_instance); |
void (*body_data_set)(Rigidbody body, void* data); |
||||||
bool (*source_instance_is_paused)(uint source_instance); |
void (*body_force_add)(Rigidbody body, float fx, float fy, float fz); |
||||||
|
}; |
||||||
struct Sound_Source_Buffer* (*source_create)(const char* filename, int type); |
|
||||||
struct Sound_Source_Buffer* (*source_get)(const char* name); |
struct Sound_Api |
||||||
void (*source_destroy)(const char* buffer_name); |
{ |
||||||
void (*source_volume_set)(struct Sound_Source_Buffer* source, float volume); |
void (*update_3d)(void); |
||||||
void (*source_loop_set)(struct Sound_Source_Buffer* source, bool loop); |
void (*volume_set)(float volume); |
||||||
void (*source_stop_all)(struct Sound_Source_Buffer* source); |
void (*listener_update)(float apos_x, float apos_y, float apos_z, |
||||||
void (*source_min_max_distance_set)(struct Sound_Source_Buffer* source, float min_distance, float max_distance); |
float afwd_x, float afwd_y, float afwd_z, |
||||||
}; |
float aup_x, float aup_y, float aup_z); |
||||||
|
|
||||||
struct Window_Api |
void (*source_instance_update_position)(uint source_instance, float apos_x, float apos_y, float apos_z); |
||||||
{ |
uint (*source_instance_create)(struct Sound_Source_Buffer* source, bool is3d); |
||||||
struct Window* (*create)(const char* title, int width, int height, int msaa, int msaa_levels); |
void (*source_instance_destroy)(uint source_instance); |
||||||
void (*destroy)(struct Window* window); |
void (*source_instance_volume_set)(uint source_instance, float volume); |
||||||
void (*show)(struct Window* window); |
void (*source_instance_loop_set)(uint source_instance, bool loop); |
||||||
void (*hide)(struct Window* window); |
void (*source_instance_play)(uint source_instance); |
||||||
void (*raise)(struct Window* window); |
void (*source_instance_pause)(uint source_instance); |
||||||
void (*make_context_current)(struct Window* window); |
void (*source_instance_rewind)(uint source_instance); |
||||||
void (*set_size)(struct Window* window, int width, int height); |
void (*source_instance_stop)(uint source_instance); |
||||||
void (*get_size)(struct Window* window, int* out_width, int* out_height); |
void (*source_instance_min_max_distance_set)(uint source_instance, float min_distance, float max_distance); |
||||||
void (*get_drawable_size)(struct Window* window, int* out_width, int* out_height); |
void (*source_instance_attenuation_set)(uint source_instance, int attenuation_type, float rolloff_factor); |
||||||
void (*swap_buffers)(struct Window* window); |
float (*source_instance_volume_get)(uint source_instance); |
||||||
int (*fullscreen_set)(struct Window* window, int fullscreen); |
bool (*source_instance_loop_get)(uint source_instance); |
||||||
}; |
bool (*source_instance_is_paused)(uint source_instance); |
||||||
|
|
||||||
struct File_Api |
struct Sound_Source_Buffer* (*source_create)(const char* filename, int type); |
||||||
{ |
struct Sound_Source_Buffer* (*source_get)(const char* name); |
||||||
char* (*read)(const int directory_type, const char* path, const char* mode, long* file_size); |
void (*source_destroy)(const char* buffer_name); |
||||||
FILE* (*open)(const int directory_type, const char* path, const char* mode); |
void (*source_volume_set)(struct Sound_Source_Buffer* source, float volume); |
||||||
bool (*copy)(const int directory_type, const char* source, const char* destination); |
void (*source_loop_set)(struct Sound_Source_Buffer* source, bool loop); |
||||||
bool (*delete)(const int directory_type, const char* filename); |
void (*source_stop_all)(struct Sound_Source_Buffer* source); |
||||||
}; |
void (*source_min_max_distance_set)(struct Sound_Source_Buffer* source, float min_distance, float max_distance); |
||||||
|
}; |
||||||
struct Config_Api |
|
||||||
{ |
struct Window_Api |
||||||
bool (*load)(const char* filename, int directory_type); |
{ |
||||||
bool (*save)(const char* filename, int directory_types); |
struct Window* (*create)(const char* title, int width, int height, int msaa, int msaa_levels); |
||||||
struct Hashmap* (*get)(void); |
void (*destroy)(struct Window* window); |
||||||
}; |
void (*show)(struct Window* window); |
||||||
|
void (*hide)(struct Window* window); |
||||||
struct Log_Api |
void (*raise)(struct Window* window); |
||||||
{ |
void (*make_context_current)(struct Window* window); |
||||||
FILE* (*file_handle_get)(void); |
void (*set_size)(struct Window* window, int width, int height); |
||||||
}; |
void (*get_size)(struct Window* window, int* out_width, int* out_height); |
||||||
|
void (*get_drawable_size)(struct Window* window, int* out_width, int* out_height); |
||||||
struct Platform_Api |
void (*swap_buffers)(struct Window* window); |
||||||
{ |
int (*fullscreen_set)(struct Window* window, int fullscreen); |
||||||
// General platform api
|
}; |
||||||
void (*poll_events)(bool* out_quit); |
|
||||||
void (*keyboard_callback_set)(Keyboard_Event_Func func); |
struct File_Api |
||||||
void (*mousebutton_callback_set)(Mousebutton_Event_Func func); |
{ |
||||||
void (*mousemotion_callback_set)(Mousemotion_Event_Func func); |
char* (*read)(const int directory_type, const char* path, const char* mode, long* file_size); |
||||||
void (*mousewheel_callback_set)(Mousewheel_Event_Func func); |
FILE* (*open)(const int directory_type, const char* path, const char* mode); |
||||||
void (*windowresize_callback_set)(Windowresize_Event_Func func); |
bool (*copy)(const int directory_type, const char* source, const char* destination); |
||||||
void (*textinput_callback_set)(Textinput_Event_Func func); |
bool (*delete)(const int directory_type, const char* filename); |
||||||
int (*is_key_pressed)(int key); |
}; |
||||||
int (*mousebutton_state_get)(uint button); |
|
||||||
void (*mouse_position_get)(int* x, int* y); |
struct Config_Api |
||||||
void (*mouse_delta_get)(int* x, int* y); |
{ |
||||||
void (*mouse_position_set)(struct Window* window, int x, int y); |
bool (*load)(const char* filename, int directory_type); |
||||||
void (*mouse_global_position_set)(int x, int y); |
bool (*save)(const char* filename, int directory_types); |
||||||
void (*mouse_relative_mode_set)(int relative_mode); |
struct Hashmap* (*get)(void); |
||||||
int (*mouse_relative_mode_get)(void); |
}; |
||||||
uint32 (*ticks_get)(void); |
|
||||||
char* (*install_directory_get)(void); |
struct Log_Api |
||||||
char* (*user_directory_get)(const char* organization, const char* application); |
{ |
||||||
void (*clipboard_text_set)(const char* text); |
FILE* (*file_handle_get)(void); |
||||||
char* (*clipboard_text_get)(void); |
}; |
||||||
int (*key_from_name)(const char* key_name); |
|
||||||
const char* (*key_name_get)(int key); |
struct Platform_Api |
||||||
void* (*load_function_gl)(const char* name); |
{ |
||||||
void (*reload_game_lib)(void); |
// General platform api
|
||||||
|
void (*poll_events)(bool* out_quit); |
||||||
struct Window_Api window; |
void (*keyboard_callback_set)(Keyboard_Event_Func func); |
||||||
struct Sound_Api sound; |
void (*mousebutton_callback_set)(Mousebutton_Event_Func func); |
||||||
struct File_Api file; |
void (*mousemotion_callback_set)(Mousemotion_Event_Func func); |
||||||
struct Config_Api config; |
void (*mousewheel_callback_set)(Mousewheel_Event_Func func); |
||||||
struct Log_Api log; |
void (*windowresize_callback_set)(Windowresize_Event_Func func); |
||||||
struct Physics_Api physics; |
void (*textinput_callback_set)(Textinput_Event_Func func); |
||||||
}; |
int (*is_key_pressed)(int key); |
||||||
|
int (*mousebutton_state_get)(uint button); |
||||||
struct Game_Api |
void (*mouse_position_get)(int* x, int* y); |
||||||
{ |
void (*mouse_delta_get)(int* x, int* y); |
||||||
bool (*init)(struct Window*, struct Platform_Api* platform_api); |
void (*mouse_position_set)(struct Window* window, int x, int y); |
||||||
void (*cleanup)(void); |
void (*mouse_global_position_set)(int x, int y); |
||||||
}; |
void (*mouse_relative_mode_set)(int relative_mode); |
||||||
|
int (*mouse_relative_mode_get)(void); |
||||||
#endif |
uint32 (*ticks_get)(void); |
||||||
|
char* (*install_directory_get)(void); |
||||||
|
char* (*user_directory_get)(const char* organization, const char* application); |
||||||
|
void (*clipboard_text_set)(const char* text); |
||||||
|
char* (*clipboard_text_get)(void); |
||||||
|
int (*key_from_name)(const char* key_name); |
||||||
|
const char* (*key_name_get)(int key); |
||||||
|
void* (*load_function_gl)(const char* name); |
||||||
|
void (*reload_game_lib)(void); |
||||||
|
|
||||||
|
struct Window_Api window; |
||||||
|
struct Sound_Api sound; |
||||||
|
struct File_Api file; |
||||||
|
struct Config_Api config; |
||||||
|
struct Log_Api log; |
||||||
|
struct Physics_Api physics; |
||||||
|
}; |
||||||
|
|
||||||
|
struct Game_Api |
||||||
|
{ |
||||||
|
bool (*init)(struct Window*, struct Platform_Api* platform_api); |
||||||
|
void (*cleanup)(void); |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
||||||
|
Loading…
Reference in new issue