-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathlutro.h
84 lines (71 loc) · 2.66 KB
/
lutro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef LUTRO_H
#define LUTRO_H
#include <stdint.h>
#include <stdbool.h>
#include <libretro.h>
#include "lutro_assert.h"
#ifndef PATH_MAX_LENGTH
#define PATH_MAX_LENGTH 4096
#endif
#define VERSION_MAJOR 0
#define VERSION_MINOR 0
#define VERSION_PATCH 1
#define VERSION_STRING "0.0.1"
typedef struct lutro_settings_t {
int width;
int height;
int pitch;
int pitch_pixels; // pitch in pixels to avoid recalculating it all the time
uint32_t *framebuffer;
retro_input_state_t input_cb;
int live_enable;
int live_call_load;
char gamedir[PATH_MAX_LENGTH];
char identity[PATH_MAX_LENGTH];
double delta;
double deltaCounter;
int frameCounter;
int fps;
retro_environment_t* environ_cb;
} lutro_settings_t;
extern lutro_settings_t settings;
extern struct retro_perf_callback perf_cb;
void lutro_init(void);
void lutro_deinit(void);
int lutro_load(const char *path);
void lutro_run(double delta);
void lutro_reset(void);
size_t lutro_serialize_size(void);
bool lutro_serialize(void *data_, size_t size);
bool lutro_unserialize(const void *data_, size_t size);
void lutro_cheat_reset(void);
void lutro_cheat_set(unsigned index, bool enabled, const char *code);
void lutro_shutdown_game(void);
typedef struct _AssetPathInfo
{
char fullpath[4096];
char ext[16]; // ext is only for matching ones we know so its OK to truncate long ones.
} AssetPathInfo;
void lutro_assetPath_init(AssetPathInfo* dest, const char* path);
// Use wrapper to handle C allocation rather than direct call
// the goal is to easy allow to trace/check memory leak
#ifndef TRACE_ALLOCATION
#define TRACE_ALLOCATION 0 // Enable a printf trace of C allocation
#endif
void *lutro_malloc_internal(size_t size, const char* debug, int line);
void *lutro_calloc_internal(size_t nmemb, size_t size, const char* debug, int line);
void *lutro_realloc_internal(void *ptr, size_t size, const char* debug, int line);
void lutro_free_internal(void *ptr, const char* debug, int line);
void lutro_print_allocation(void);
#define lutro_malloc(size) lutro_malloc_internal(size, __FILE__, __LINE__)
#define lutro_calloc(nmemb, size) lutro_calloc_internal(nmemb, size, __FILE__, __LINE__)
#define lutro_realloc(ptr, size) lutro_realloc_internal(ptr, size, __FILE__, __LINE__)
#define lutro_free(ptr) lutro_free_internal(ptr, __FILE__, __LINE__)
#if TRACE_ALLOCATION // Allow to trace allocation done in stb (and freed in ludo)
#ifndef STBI_MALLOC
#define STBI_MALLOC(sz) lutro_malloc_internal(sz, __FILE__, __LINE__)
#define STBI_REALLOC(p,newsz) lutro_realloc_internal(p, newsz, __FILE__, __LINE__)
#define STBI_FREE(p) lutro_free_internal(p, __FILE__, __LINE__)
#endif
#endif
#endif // LUTRO_H