taisei/src/main.c

156 lines
3.1 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
2011-07-03 19:24:39 +02:00
#include <sys/stat.h>
#include "taisei_err.h"
#include "global.h"
2012-07-28 22:53:53 +02:00
#include "video.h"
#include "stage.h"
#include "menu/mainmenu.h"
#include "paths/native.h"
#include "taiseigl.h"
2012-08-15 02:41:21 +02:00
#include "gamepad.h"
2017-01-24 14:40:57 +01:00
#include "resource/bgm.h"
void init_gl(void) {
load_gl_functions();
check_gl_extensions();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
init_quadvbo();
2012-07-30 17:57:38 +02:00
2012-08-09 21:27:49 +02:00
glClear(GL_COLOR_BUFFER_BIT);
}
void taisei_shutdown(void) {
config_save(CONFIG_FILE);
2012-04-05 20:31:16 +02:00
printf("\nshutdown:\n");
2017-01-24 14:40:57 +01:00
if (!tconfig.intval[NO_AUDIO]) shutdown_sfx();
if (!tconfig.intval[NO_MUSIC]) shutdown_bgm();
2012-07-15 08:15:47 +02:00
free_resources();
2012-07-28 22:53:53 +02:00
video_shutdown();
2012-08-15 02:41:21 +02:00
gamepad_shutdown();
SDL_Quit();
2012-04-05 20:31:16 +02:00
printf("-- Good Bye.\n");
}
void init_log(void) {
#ifdef __WINDOWS__
const char *pref = get_config_path();
char *s;
s = malloc(strlen(pref) + strlen("stdout.txt") + 2);
strcpy(s, pref);
strcat(s, "/stdout.txt");
freopen(s, "w", stdout);
strcpy(s, pref);
strcat(s, "/stderr.txt");
freopen(s, "w", stderr);
#endif
}
#ifdef __WINDOWS__
#define MKDIR(p) mkdir(p)
#else
#define MKDIR(p) mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
#endif
int main(int argc, char** argv) {
2012-07-27 19:11:45 +02:00
if(tsrand_test())
return 0;
init_paths();
init_log();
printf("Content path: %s\n", get_prefix());
printf("Userdata path: %s\n", get_config_path());
MKDIR(get_config_path());
MKDIR(get_screenshots_path());
MKDIR(get_replays_path());
config_load(CONFIG_FILE);
2011-06-26 20:23:28 +02:00
printf("initialize:\n");
if(SDL_Init(SDL_INIT_VIDEO) < 0)
errx(-1, "Error initializing SDL: %s", SDL_GetError());
2011-06-26 20:23:28 +02:00
printf("-- SDL_Init\n");
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
2012-07-28 22:53:53 +02:00
video_init();
2011-06-26 20:23:28 +02:00
printf("-- SDL viewport\n");
2012-07-28 22:53:53 +02:00
init_gl();
2011-06-26 20:23:28 +02:00
printf("-- GL\n");
2012-08-18 09:44:38 +02:00
draw_loading_screen();
2017-01-24 14:40:57 +01:00
// Order DOES matter: init_global, then sfx/bgm, then load_resources.
2011-07-04 11:09:41 +02:00
init_global();
2012-08-15 02:41:21 +02:00
gamepad_init();
2017-01-24 14:40:57 +01:00
init_sfx(&argc, argv);
init_bgm(&argc, argv);
load_resources();
printf("initialization complete.\n");
2012-04-05 20:31:16 +02:00
atexit(taisei_shutdown);
2012-04-06 17:50:17 +02:00
#ifdef DEBUG
2012-07-13 18:44:56 +02:00
printf("** Compiled with DEBUG flag!\n");
if(argc >= 2 && argv[1]) {
printf("** Entering stage skip mode: Stage %d\n", atoi(argv[1]));
global.diff = D_Easy;
if(argc == 3 && argv[2]) {
printf("** Setting difficulty to %d.\n", atoi(argv[2]));
global.diff = atoi(argv[2]);
}
2012-04-06 17:50:17 +02:00
StageInfo* stg = stage_get(atoi(argv[1]));
2012-04-06 17:50:17 +02:00
if(stg) {
printf("** Entering %s.\n", stg->title);
2012-08-16 15:50:28 +02:00
do {
global.game_over = 0;
init_player(&global.plr);
stg->loop();
} while(global.game_over == GAMEOVER_RESTART);
return 0;
2012-04-06 17:50:17 +02:00
}
2012-07-13 18:44:56 +02:00
printf("** Invalid stage number. Quitting stage skip mode.\n");
2012-04-06 17:50:17 +02:00
}
#endif
2012-08-05 03:36:55 +02:00
MenuData menu;
create_main_menu(&menu);
printf("-- menu\n");
set_sfx_volume(tconfig.fltval[SFX_VOLUME]);
set_bgm_volume(tconfig.fltval[BGM_VOLUME]);
2017-01-24 14:40:57 +01:00
start_bgm("bgm_menu");
main_menu_loop(&menu);
2012-08-16 15:50:28 +02:00
return 0;
}