use SDL_GetBasePath
This commit is contained in:
parent
bf1c9bd3d4
commit
605d6d0970
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
CC ?= gcc
|
||||
CFLAGS = -std=c99 -Wall -Wextra -O3 -I./inc -MMD $(shell sdl2-config --cflags)
|
||||
CFLAGS = -std=c99 -Wall -Wextra -pedantic -O3 -I./inc -MMD $(shell sdl2-config --cflags)
|
||||
LDFLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer $(shell sdl2-config --libs)
|
||||
|
||||
OBJ_NAME = lzy
|
||||
|
|
45
inc/lzy.h
45
inc/lzy.h
|
@ -80,8 +80,8 @@ typedef struct LZY_Event {
|
|||
LZY_EventUnion u;
|
||||
} LZY_Event;
|
||||
|
||||
int LZY_Init(int argc, const char **argv, const char *title, int target_fps,
|
||||
const char *tset_path, const char *font_path);
|
||||
int LZY_Init(const char *title, int target_fps, const char *tset_path,
|
||||
const char *font_path);
|
||||
void LZY_Quit(void);
|
||||
int LZY_DrawBegin(void);
|
||||
int LZY_DrawEnd(void);
|
||||
|
@ -210,13 +210,11 @@ static unsigned int tset_width, tset_height;
|
|||
static unsigned int font_width, font_height;
|
||||
static int timer_callback(volatile int *);
|
||||
|
||||
int LZY_Init(int argc, const char **argv, const char *title, int target_fps,
|
||||
const char *tset_path, const char *font_path) {
|
||||
int LZY_Init(const char *title, int target_fps, const char *tset_path,
|
||||
const char *font_path) {
|
||||
extern bopti_image_t LZY_GINT_TILESET;
|
||||
extern bopti_image_t LZY_GINT_FONT;
|
||||
|
||||
LZY_UNUSED(argc);
|
||||
LZY_UNUSED(argv);
|
||||
LZY_UNUSED(title);
|
||||
LZY_UNUSED(tset_path);
|
||||
LZY_UNUSED(font_path);
|
||||
|
@ -460,7 +458,6 @@ const char *LZY_GetError(void) {
|
|||
#include LZY_SDL_INCLUDE
|
||||
#include LZY_SDL_IMAGE_INCLUDE
|
||||
#include LZY_SDL_MIXER_INCLUDE
|
||||
#include <libgen.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -485,24 +482,6 @@ static uint64_t min_dt;
|
|||
static uint64_t next_time;
|
||||
static char *datadir;
|
||||
|
||||
static char *str_dup(const char *src) {
|
||||
char *copy;
|
||||
|
||||
if (src == NULL) {
|
||||
error = "src is NULL";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
copy = calloc(strlen(src) + 1, sizeof(char));
|
||||
if (copy == NULL) {
|
||||
error = "calloc failed";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(copy, src);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static char *path_relative(const char *path) {
|
||||
char *buf;
|
||||
|
||||
|
@ -516,28 +495,28 @@ static char *path_relative(const char *path) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
buf = calloc(strlen(datadir) + strlen(path) + 2, sizeof(char));
|
||||
buf = calloc(strlen(datadir) + strlen(path) + 1, sizeof(char));
|
||||
if (buf == NULL) {
|
||||
error = "calloc failed";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(buf, datadir);
|
||||
strcat(buf, "/");
|
||||
strcat(buf, path);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int LZY_Init(int argc, const char **argv, const char *title, int target_fps,
|
||||
const char *tset_path, const char *font_path) {
|
||||
int LZY_Init(const char *title, int target_fps, const char *tset_path,
|
||||
const char *font_path) {
|
||||
const int img_flags = IMG_INIT_PNG;
|
||||
char *buf;
|
||||
|
||||
datadir = str_dup((argc < 1) ? ("./rl") : (argv[0]));
|
||||
if (datadir == NULL)
|
||||
datadir = SDL_GetBasePath();
|
||||
if (datadir == NULL) {
|
||||
error = SDL_GetError();
|
||||
return -1;
|
||||
dirname(datadir);
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
error = SDL_GetError();
|
||||
|
@ -625,7 +604,7 @@ int LZY_Init(int argc, const char **argv, const char *title, int target_fps,
|
|||
|
||||
void LZY_Quit(void) {
|
||||
if (datadir != NULL) {
|
||||
free(datadir);
|
||||
SDL_free(datadir);
|
||||
datadir = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,14 @@
|
|||
|
||||
static const int speed = 4;
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int main(int argc, char **argv) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if (LZY_Init(argc, argv, "lzy example", 30, "res/tset.png",
|
||||
"res/font.png")) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
if (LZY_Init("lzy example", 30, "res/tset.png", "res/font.png")) {
|
||||
LZY_Log("LZY_Init failed: %s", LZY_GetError());
|
||||
LZY_Quit();
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue