System info & network
This commit is contained in:
92
code/platform.h
Normal file
92
code/platform.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef _PIUMA_PLATFORM_H_
|
||||
#define _PIUMA_PLATFORM_H_
|
||||
/*
|
||||
=== PLATFORM INTERFACE ===
|
||||
Every function or struct must be implemented in the code for each platform
|
||||
|
||||
==========================
|
||||
*/
|
||||
|
||||
#include "lib/types.h"
|
||||
#include "lib/event.h"
|
||||
|
||||
// @Feature: Initialization structures with preferred initial state (window resolution, fullcreen)
|
||||
|
||||
// Generic platform initialization
|
||||
void p_init(bool capture_os_signals = false);
|
||||
void p_deinit();
|
||||
|
||||
// Memory
|
||||
void * p_alloc(u64 size);
|
||||
void * p_realloc(void *ptr, u64 new_size);
|
||||
void p_free(void *ptr);
|
||||
|
||||
// File IO
|
||||
#define P_FILE_CREATE_IF_NOT_EXISTS 1
|
||||
|
||||
struct p_file; // Defined by specific platform implementation
|
||||
|
||||
bool p_file_init(p_file *file, const char *filename, b32 flags = 0);
|
||||
u64 p_file_size(p_file *file);
|
||||
bool p_file_read(p_file *file, Buffer *buf, u64 max_size);
|
||||
bool p_file_write(p_file *file, u8 *data, u64 size);
|
||||
// @Performance: add append + write at position. Maybe not needed
|
||||
void p_file_deinit(p_file *file);
|
||||
|
||||
// Timers
|
||||
f64 p_time(); // Returns seconds
|
||||
void p_wait(f64 milliseconds);
|
||||
|
||||
// Windowing
|
||||
// We suppose we only need 1 window. Every GL command will render to it.
|
||||
void p_window_open();
|
||||
void p_window_name(char *name);
|
||||
void p_window_resize(u32 width, u32 height, bool fullscreen = false);
|
||||
void p_window_dimensions(u32 *width, u32 *height);
|
||||
void p_window_close();
|
||||
|
||||
// Graphics
|
||||
void p_graphics_swap_interval(s32 frames); // -1 for Adaptive Sync, 0 for no interval, >0 to wait 'frames' frames between each swap
|
||||
void p_graphics_swap();
|
||||
|
||||
// Input (keyboard / mouse / controller)
|
||||
void p_mouse_grab(bool grab);
|
||||
|
||||
// Events
|
||||
bool p_next_event(Event *e);
|
||||
|
||||
// Audio
|
||||
struct p_audio_buffer;
|
||||
typedef void (*p_audio_callback)(p_audio_buffer *);
|
||||
|
||||
void p_audio_register_data_callback(p_audio_callback cb);
|
||||
u32 p_audio_sample_rate();
|
||||
|
||||
|
||||
// Threads
|
||||
// @Feature: OS threads and syncronization
|
||||
|
||||
|
||||
|
||||
// Audio structs
|
||||
struct p_audio_sample
|
||||
{
|
||||
f32 left;
|
||||
f32 right;
|
||||
};
|
||||
|
||||
struct p_audio_buffer
|
||||
{
|
||||
p_audio_sample *samples;
|
||||
u64 size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
#include "linux_platform.h"
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user