mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
use correct paths for data files when game is installed
This commit is contained in:
parent
a977a1928a
commit
8420a5ca92
12 changed files with 94 additions and 43 deletions
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
|
|||
|
||||
project(SuperDerpy C)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ansi -g")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
|
||||
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
|
||||
if(MINGW)
|
||||
|
@ -18,7 +18,7 @@ if(MINGW)
|
|||
# Search in MINGDIR for headers and libraries.
|
||||
set(CMAKE_PREFIX_PATH "${MINGDIR}")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows")
|
||||
|
||||
endif(MINGW)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ void About_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
game->about.letter = LoadScaledBitmap("about/letter.png", game->viewportHeight*1.3, game->viewportHeight*1.3 );
|
||||
PROGRESS;
|
||||
|
||||
game->about.sample = al_load_sample( "data/about/about.flac" );
|
||||
game->about.sample = al_load_sample( GetDataFilePath("about/about.flac") );
|
||||
PROGRESS;
|
||||
|
||||
game->about.music = al_create_sample_instance(game->about.sample);
|
||||
|
@ -82,7 +82,7 @@ void About_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
al_set_sample_instance_playmode(game->about.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
al_set_sample_instance_position(game->about.music, game->music ? 420000 : 700000);
|
||||
|
||||
game->about.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.035,0 );
|
||||
game->about.font = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.035,0 );
|
||||
PROGRESS;
|
||||
game->about.x = -0.1;
|
||||
if (!game->about.sample){
|
||||
|
|
15
src/config.c
15
src/config.c
|
@ -24,8 +24,13 @@
|
|||
ALLEGRO_CONFIG *config;
|
||||
|
||||
void InitConfig() {
|
||||
config = al_load_config_file("SuperDerpy.ini");
|
||||
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
|
||||
ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
|
||||
al_join_paths(path, data);
|
||||
config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
|
||||
if (!config) config=al_create_config();
|
||||
al_destroy_path(path);
|
||||
al_destroy_path(data);
|
||||
}
|
||||
|
||||
void SetConfigOption(char* section, char* name, char* value) {
|
||||
|
@ -42,6 +47,12 @@ const char* GetConfigOptionDefault(char* section, char* name, const char* def) {
|
|||
}
|
||||
|
||||
void DeinitConfig() {
|
||||
al_save_config_file("SuperDerpy.ini", config);
|
||||
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
|
||||
ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
|
||||
al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
|
||||
al_join_paths(path, data);
|
||||
al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), config);
|
||||
al_destroy_path(path);
|
||||
al_destroy_path(data);
|
||||
al_destroy_config(config);
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ int Disclaimer_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
|
||||
void Disclaimer_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
||||
if (!game->menu.loaded) {
|
||||
game->menu.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.05,0 );
|
||||
game->menu.font_selected = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.065,0 );
|
||||
game->menu.font = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.05,0 );
|
||||
game->menu.font_selected = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.065,0 );
|
||||
}
|
||||
PrintConsole(game, "Preloading GAMESTATE_INTRO...");
|
||||
Intro_Preload(game, progress);
|
||||
|
|
|
@ -49,9 +49,9 @@ void AnimPage(struct Game *game, int page, ALLEGRO_COLOR tint) {
|
|||
|
||||
void FillPage(struct Game *game, int page) {
|
||||
char filename[30] = { };
|
||||
sprintf(filename, "data/intro/%d.flac", page);
|
||||
sprintf(filename, "intro/%d.flac", page);
|
||||
|
||||
game->intro.audiostream = al_load_audio_stream(filename, 4, 1024);
|
||||
game->intro.audiostream = al_load_audio_stream(GetDataFilePath(filename), 4, 1024);
|
||||
al_attach_audio_stream_to_mixer(game->intro.audiostream, game->audio.voice);
|
||||
al_set_audio_stream_playing(game->intro.audiostream, false);
|
||||
al_set_audio_stream_gain(game->intro.audiostream, 1.75);
|
||||
|
@ -240,7 +240,7 @@ void Intro_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
game->intro.frame =LoadScaledBitmap("intro/frame.png", game->viewportWidth, game->viewportHeight);
|
||||
PROGRESS;
|
||||
|
||||
game->intro.sample = al_load_sample( "data/intro/intro.flac" );
|
||||
game->intro.sample = al_load_sample( GetDataFilePath("intro/intro.flac") );
|
||||
PROGRESS;
|
||||
|
||||
game->intro.music = al_create_sample_instance(game->intro.sample);
|
||||
|
@ -254,7 +254,7 @@ void Intro_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
}
|
||||
game->intro.table = al_create_bitmap(game->viewportWidth*2, game->viewportHeight);
|
||||
|
||||
game->intro.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.04,0 );
|
||||
game->intro.font = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.04,0 );
|
||||
|
||||
FillPage(game, 1);
|
||||
PROGRESS;
|
||||
|
|
|
@ -58,8 +58,8 @@ void SelectDerpySpritesheet(struct Game *game, char* name) {
|
|||
|
||||
void RegisterDerpySpritesheet(struct Game *game, char* name) {
|
||||
char filename[255] = { };
|
||||
sprintf(filename, "data/levels/derpy/%s.ini", name);
|
||||
ALLEGRO_CONFIG *config = al_load_config_file(filename);
|
||||
sprintf(filename, "levels/derpy/%s.ini", name);
|
||||
ALLEGRO_CONFIG *config = al_load_config_file(GetDataFilePath(filename));
|
||||
struct Spritesheet *s = malloc(sizeof(struct Spritesheet));
|
||||
s->name = malloc((strlen(name)+1)*sizeof(char));
|
||||
strcpy(s->name, name);
|
||||
|
@ -399,7 +399,7 @@ void Level_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
RegisterDerpySpritesheet(game, "stand");
|
||||
if (game->level.current_level!=1) Moonwalk_Preload(game);
|
||||
else {
|
||||
game->level.sample = al_load_sample( "data/levels/1/music.flac" );
|
||||
game->level.sample = al_load_sample( GetDataFilePath("levels/1/music.flac") );
|
||||
game->level.music = al_create_sample_instance(game->level.sample);
|
||||
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
|
||||
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
|
@ -518,7 +518,7 @@ void Level_PreloadBitmaps(struct Game *game, void (*progress)(struct Game*, floa
|
|||
PROGRESS;
|
||||
game->level.owl = LoadScaledBitmap("levels/owl.png", game->viewportWidth*0.08, game->viewportWidth*0.08);
|
||||
PROGRESS;
|
||||
game->level.letter_font = al_load_ttf_font("data/DejaVuSans.ttf",game->viewportHeight*0.0225,0 );
|
||||
game->level.letter_font = al_load_ttf_font(GetDataFilePath("DejaVuSans.ttf"),game->viewportHeight*0.0225,0 );
|
||||
PROGRESS;
|
||||
game->level.letter = LoadScaledBitmap("levels/letter.png", game->viewportHeight*1.3, game->viewportHeight*1.2);
|
||||
al_set_target_bitmap(game->level.letter);
|
||||
|
|
|
@ -224,7 +224,7 @@ bool Letter(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
|||
*f = 0;
|
||||
action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(ALLEGRO_AUDIO_STREAM*)));
|
||||
ALLEGRO_AUDIO_STREAM** stream = (ALLEGRO_AUDIO_STREAM**)action->arguments->next->value;
|
||||
*stream = al_load_audio_stream("data/levels/letter.flac", 4, 1024);
|
||||
*stream = al_load_audio_stream(GetDataFilePath("levels/letter.flac"), 4, 1024);
|
||||
al_attach_audio_stream_to_mixer(*stream, game->audio.voice);
|
||||
al_set_audio_stream_playing(*stream, true);
|
||||
al_set_audio_stream_gain(*stream, 2.00);
|
||||
|
|
63
src/main.c
63
src/main.c
|
@ -61,6 +61,46 @@
|
|||
double old_time = 0, fps;
|
||||
int frames_done = 0;
|
||||
|
||||
char* GetDataFilePath(char* filename) {
|
||||
|
||||
char *result = 0;
|
||||
|
||||
if (al_filename_exists(filename)) {
|
||||
return strdup(filename);
|
||||
}
|
||||
|
||||
char origfn[255] = "data/";
|
||||
strcat(origfn, filename);
|
||||
|
||||
if (al_filename_exists(origfn)) {
|
||||
return strdup(origfn);
|
||||
}
|
||||
|
||||
void TestPath(char* subpath) {
|
||||
ALLEGRO_PATH *tail = al_create_path(filename);
|
||||
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
|
||||
ALLEGRO_PATH *data = al_create_path(subpath);
|
||||
al_join_paths(path, data);
|
||||
al_join_paths(path, tail);
|
||||
//printf("Testing for %s\n", al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
|
||||
if (al_filename_exists(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP))) {
|
||||
result = strdup(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
|
||||
}
|
||||
al_destroy_path(tail);
|
||||
al_destroy_path(data);
|
||||
al_destroy_path(path);
|
||||
}
|
||||
TestPath("../share/superderpy/data/");
|
||||
TestPath("../data/");
|
||||
TestPath("data/");
|
||||
|
||||
if (!result) {
|
||||
printf("FATAL: Could not find data file: %s!\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PrintConsole(struct Game *game, char* format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
|
@ -230,10 +270,7 @@ ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height) {
|
|||
ALLEGRO_BITMAP *source, *target = al_create_bitmap(width, height);
|
||||
al_set_target_bitmap(target);
|
||||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
char origfn[255] = "data/";
|
||||
/*char cachefn[255] = "data/cache/";*/
|
||||
strcat(origfn, filename);
|
||||
/*strcat(cachefn, filename);*/
|
||||
char* origfn = GetDataFilePath(filename);
|
||||
void GenerateBitmap() {
|
||||
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
|
||||
|
||||
|
@ -251,6 +288,7 @@ ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height) {
|
|||
if ((al_get_bitmap_width(source)!=width) || (al_get_bitmap_height(source)!=height)) {
|
||||
al_destroy_bitmap(source);*/
|
||||
GenerateBitmap();
|
||||
free(origfn);
|
||||
return target;
|
||||
/* }
|
||||
return source;
|
||||
|
@ -289,12 +327,12 @@ void SetupViewport(struct Game *game) {
|
|||
}
|
||||
|
||||
int Shared_Load(struct Game *game) {
|
||||
game->font = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.09,0 );
|
||||
game->font = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.09,0 );
|
||||
if(!game->font) {
|
||||
fprintf(stderr, "failed to load game font!\n");
|
||||
return -1;
|
||||
}
|
||||
game->font_console = al_load_ttf_font("data/DejaVuSansMono.ttf",game->viewportHeight*0.018,0 );
|
||||
game->font_console = al_load_ttf_font(GetDataFilePath("DejaVuSansMono.ttf"),game->viewportHeight*0.018,0 );
|
||||
if(!game->font_console) {
|
||||
fprintf(stderr, "failed to load console font!\n");
|
||||
return -1;
|
||||
|
@ -326,7 +364,12 @@ int main(int argc, char **argv){
|
|||
al_set_org_name("Super Derpy");
|
||||
al_set_app_name("Muffin Attack");
|
||||
|
||||
InitConfig();
|
||||
if(!al_init()) {
|
||||
fprintf(stderr, "failed to initialize allegro!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
InitConfig();
|
||||
|
||||
bool redraw = true;
|
||||
|
||||
|
@ -343,12 +386,6 @@ int main(int argc, char **argv){
|
|||
game.height = atoi(GetConfigOptionDefault("SuperDerpy", "height", "500"));
|
||||
if (game.height<200) game.height=200;
|
||||
|
||||
if(!al_init()) {
|
||||
fprintf(stderr, "failed to initialize allegro!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(!al_init_image_addon()) {
|
||||
fprintf(stderr, "failed to initialize image addon!\n");
|
||||
/*al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!",
|
||||
|
|
|
@ -308,6 +308,9 @@ void UnloadGameState(struct Game *game);
|
|||
/*! \brief Loads gamestate set in game->loadstate. */
|
||||
void LoadGameState(struct Game *game);
|
||||
|
||||
/*! \brief Finds path for data file. */
|
||||
char* GetDataFilePath(char* filename);
|
||||
|
||||
/*! \brief Print some message on game console.
|
||||
*
|
||||
* Draws message on console bitmap, so it'll be displayed when calling DrawConsole.
|
||||
|
|
|
@ -113,12 +113,12 @@ void Map_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
game->map.highlight = LoadScaledBitmap(filename, game->viewportWidth, game->viewportHeight);
|
||||
PROGRESS;
|
||||
|
||||
game->map.arrow = al_load_bitmap( "data/map/arrow.png" );
|
||||
game->map.arrow = al_load_bitmap( GetDataFilePath("map/arrow.png") );
|
||||
PROGRESS;
|
||||
|
||||
game->map.click_sample = al_load_sample( "data/menu/click.flac" );
|
||||
game->map.click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
|
||||
PROGRESS;
|
||||
game->map.sample = al_load_sample( "data/map/map.flac" );
|
||||
game->map.sample = al_load_sample( GetDataFilePath("map/map.flac") );
|
||||
PROGRESS;
|
||||
|
||||
game->map.music = al_create_sample_instance(game->map.sample);
|
||||
|
|
18
src/menu.c
18
src/menu.c
|
@ -216,17 +216,17 @@ void Menu_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
game->menu.pinkcloud = LoadScaledBitmap( "menu/pinkcloud.png", game->viewportWidth*0.33125, game->viewportHeight*0.8122);
|
||||
PROGRESS;
|
||||
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
|
||||
game->menu.rain = al_load_bitmap( "data/menu/rain.png" );
|
||||
game->menu.rain = al_load_bitmap( GetDataFilePath("menu/rain.png") );
|
||||
PROGRESS;
|
||||
game->menu.pie = al_load_bitmap( "data/levels/pie1.png" );
|
||||
game->menu.pie = al_load_bitmap( GetDataFilePath("levels/pie1.png") );
|
||||
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
|
||||
PROGRESS;
|
||||
|
||||
game->menu.sample = al_load_sample( "data/menu/menu.flac" );
|
||||
game->menu.sample = al_load_sample( GetDataFilePath("menu/menu.flac") );
|
||||
PROGRESS;
|
||||
game->menu.rain_sample = al_load_sample( "data/menu/rain.flac" );
|
||||
game->menu.rain_sample = al_load_sample( GetDataFilePath("menu/rain.flac") );
|
||||
PROGRESS;
|
||||
game->menu.click_sample = al_load_sample( "data/menu/click.flac" );
|
||||
game->menu.click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
|
||||
PROGRESS;
|
||||
game->menu.mountain_position = game->viewportWidth*0.7;
|
||||
|
||||
|
@ -242,10 +242,10 @@ void Menu_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
|
|||
al_attach_sample_instance_to_mixer(game->menu.click, game->audio.fx);
|
||||
al_set_sample_instance_playmode(game->menu.click, ALLEGRO_PLAYMODE_ONCE);
|
||||
|
||||
game->menu.font_title = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.16,0 );
|
||||
game->menu.font_subtitle = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.08,0 );
|
||||
game->menu.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.05,0 );
|
||||
game->menu.font_selected = al_load_ttf_font("data/ShadowsIntoLight.ttf",game->viewportHeight*0.065,0 );
|
||||
game->menu.font_title = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.16,0 );
|
||||
game->menu.font_subtitle = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.08,0 );
|
||||
game->menu.font = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.05,0 );
|
||||
game->menu.font_selected = al_load_ttf_font(GetDataFilePath("ShadowsIntoLight.ttf"),game->viewportHeight*0.065,0 );
|
||||
PROGRESS;
|
||||
|
||||
if (!game->menu.sample){
|
||||
|
|
|
@ -94,7 +94,7 @@ void Moonwalk_PreloadBitmaps(struct Game *game) {
|
|||
|
||||
void Moonwalk_Preload(struct Game *game) {
|
||||
PrintConsole(game, "Initializing level %d...", game->level.current_level);
|
||||
game->level.sample = al_load_sample( "data/levels/moonwalk.flac" );
|
||||
game->level.sample = al_load_sample( GetDataFilePath("levels/moonwalk.flac") );
|
||||
game->level.music = al_create_sample_instance(game->level.sample);
|
||||
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
|
||||
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
|
||||
|
|
Loading…
Reference in a new issue