2010-10-12 10:55:23 +02:00
|
|
|
/*
|
2011-03-05 13:44:21 +01:00
|
|
|
* This software is licensed under the terms of the MIT-License
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2011-03-05 13:44:21 +01:00
|
|
|
* ---
|
|
|
|
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
2010-10-12 10:55:23 +02:00
|
|
|
*/
|
|
|
|
|
2011-07-03 19:24:39 +02:00
|
|
|
#include <sys/stat.h>
|
2011-06-26 16:10:13 +02:00
|
|
|
#include "taisei_err.h"
|
2010-10-12 10:55:23 +02:00
|
|
|
|
|
|
|
#include "global.h"
|
2012-07-28 22:53:53 +02:00
|
|
|
#include "video.h"
|
2017-03-02 11:23:30 +01:00
|
|
|
#include "audio.h"
|
2012-07-14 09:40:37 +02:00
|
|
|
#include "stage.h"
|
2011-06-13 18:48:36 +02:00
|
|
|
#include "menu/mainmenu.h"
|
2011-07-03 19:49:52 +02:00
|
|
|
#include "paths/native.h"
|
2012-08-15 02:41:21 +02:00
|
|
|
#include "gamepad.h"
|
2017-01-24 14:40:57 +01:00
|
|
|
#include "resource/bgm.h"
|
2017-02-11 10:52:37 +01:00
|
|
|
#include "progress.h"
|
2017-02-28 18:16:38 +01:00
|
|
|
#include "hashtable.h"
|
2010-10-18 14:40:15 +02:00
|
|
|
|
2012-08-10 22:08:51 +02:00
|
|
|
void taisei_shutdown(void) {
|
2012-08-03 07:06:19 +02:00
|
|
|
config_save(CONFIG_FILE);
|
2017-02-11 10:52:37 +01:00
|
|
|
progress_save();
|
2012-04-05 20:31:16 +02:00
|
|
|
printf("\nshutdown:\n");
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-28 15:38:02 +01:00
|
|
|
free_all_refs();
|
2012-07-15 08:15:47 +02:00
|
|
|
free_resources();
|
2017-03-02 11:23:30 +01:00
|
|
|
audio_shutdown();
|
2012-07-28 22:53:53 +02:00
|
|
|
video_shutdown();
|
2012-08-15 02:41:21 +02:00
|
|
|
gamepad_shutdown();
|
2017-02-15 13:53:24 +01:00
|
|
|
stage_free_array();
|
2017-02-17 17:03:49 +01:00
|
|
|
config_uninit();
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2010-10-18 14:40:15 +02:00
|
|
|
SDL_Quit();
|
2012-04-05 20:31:16 +02:00
|
|
|
printf("-- Good Bye.\n");
|
2010-10-18 14:40:15 +02:00
|
|
|
}
|
|
|
|
|
2017-02-06 23:54:15 +01:00
|
|
|
void init_log(void) {
|
2017-02-08 01:52:17 +01:00
|
|
|
#if defined(__WINDOWS__) && !defined(__WINDOWS_CONSOLE__)
|
2017-02-06 23:54:15 +01:00
|
|
|
const char *pref = get_config_path();
|
|
|
|
char *s;
|
|
|
|
|
2017-03-06 01:03:06 +01:00
|
|
|
s = strfmt("%s/%s", pref, "stdout.txt");
|
2017-02-06 23:54:15 +01:00
|
|
|
freopen(s, "w", stdout);
|
2017-03-06 01:03:06 +01:00
|
|
|
free(s);
|
2017-02-06 23:54:15 +01:00
|
|
|
|
2017-03-06 01:03:06 +01:00
|
|
|
s = strfmt("%s/%s", pref, "stderr.txt");
|
2017-02-06 23:54:15 +01:00
|
|
|
freopen(s, "w", stderr);
|
2017-03-06 01:03:06 +01:00
|
|
|
free(s);
|
2017-02-06 23:54:15 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-09 01:13:06 +01:00
|
|
|
int run_tests(void) {
|
|
|
|
if(tsrand_test()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(replay_test()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-22 21:52:25 +01:00
|
|
|
if(zrwops_test()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-28 18:16:38 +01:00
|
|
|
if(hashtable_test()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-26 21:59:51 +01:00
|
|
|
if(color_test()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-09 01:13:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-08 03:36:09 +01:00
|
|
|
#ifndef __POSIX__
|
2012-07-16 17:47:06 +02:00
|
|
|
#define MKDIR(p) mkdir(p)
|
2011-07-03 20:14:53 +02:00
|
|
|
#else
|
2012-07-16 17:47:06 +02:00
|
|
|
#define MKDIR(p) mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
|
2011-07-03 20:14:53 +02:00
|
|
|
#endif
|
2012-07-16 17:47:06 +02:00
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
int main(int argc, char **argv) {
|
2017-02-09 01:13:06 +01:00
|
|
|
if(run_tests()) {
|
2012-07-27 19:11:45 +02:00
|
|
|
return 0;
|
2017-02-09 01:13:06 +01:00
|
|
|
}
|
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(argc >= 2 && argv[1] && !strcmp(argv[1], "dumpstages")) {
|
|
|
|
stage_init_array();
|
|
|
|
|
2017-02-26 13:17:48 +01:00
|
|
|
for(StageInfo *stg = stages; stg->procs; ++stg) {
|
2017-02-10 11:39:42 +01:00
|
|
|
printf("%i %s: %s\n", stg->id, stg->title, stg->subtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-21 21:31:46 +01:00
|
|
|
Replay replay = {0};
|
|
|
|
const char *replay_path = NULL;
|
|
|
|
int replay_stage = 0;
|
|
|
|
|
|
|
|
if(argc >= 2 && !strcmp(argv[1], "replay")) {
|
|
|
|
if(argc < 3) {
|
|
|
|
fprintf(stderr, "Usage: %s replay /path/to/replay.tsr [stage num]\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
replay_path = argv[2];
|
|
|
|
|
|
|
|
if(argc > 3) {
|
|
|
|
replay_stage = atoi(argv[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!replay_load(&replay, replay_path, REPLAY_READ_ALL | REPLAY_READ_RAWPATH)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-04 07:27:46 +01:00
|
|
|
init_paths();
|
2017-02-06 23:54:15 +01:00
|
|
|
init_log();
|
2017-02-04 07:27:46 +01:00
|
|
|
|
|
|
|
printf("Content path: %s\n", get_prefix());
|
|
|
|
printf("Userdata path: %s\n", get_config_path());
|
|
|
|
|
2012-07-16 17:47:06 +02:00
|
|
|
MKDIR(get_config_path());
|
|
|
|
MKDIR(get_screenshots_path());
|
|
|
|
MKDIR(get_replays_path());
|
2017-02-04 07:27:46 +01:00
|
|
|
|
2012-08-03 07:06:19 +02:00
|
|
|
config_load(CONFIG_FILE);
|
2017-02-04 07:27:46 +01:00
|
|
|
|
2011-06-26 20:23:28 +02:00
|
|
|
printf("initialize:\n");
|
2017-02-24 01:54:28 +01:00
|
|
|
|
2017-03-02 11:23:30 +01:00
|
|
|
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
2010-10-12 10:55:23 +02:00
|
|
|
errx(-1, "Error initializing SDL: %s", SDL_GetError());
|
2017-03-02 11:23:30 +01:00
|
|
|
printf("-- SDL\n");
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-10 01:07:19 +01:00
|
|
|
init_global();
|
|
|
|
|
2012-07-28 22:53:53 +02:00
|
|
|
video_init();
|
2017-02-24 01:54:28 +01:00
|
|
|
printf("-- Video and OpenGL\n");
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-03-02 11:23:30 +01:00
|
|
|
audio_init();
|
|
|
|
printf("-- Audio\n");
|
|
|
|
|
2017-02-28 18:47:47 +01:00
|
|
|
init_resources();
|
2012-08-18 09:44:38 +02:00
|
|
|
draw_loading_screen();
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-03-02 11:23:30 +01:00
|
|
|
load_resources();
|
2012-08-15 02:41:21 +02:00
|
|
|
gamepad_init();
|
2017-02-10 11:39:42 +01:00
|
|
|
stage_init_array();
|
2017-02-11 10:52:37 +01:00
|
|
|
progress_load(); // stage_init_array goes first!
|
2017-02-10 01:07:19 +01:00
|
|
|
|
2017-02-25 14:23:22 +01:00
|
|
|
set_transition(TransLoader, 0, FADE_TIME*2);
|
|
|
|
|
2017-02-24 01:54:28 +01:00
|
|
|
printf("initialization complete.\n");
|
2012-04-05 20:31:16 +02:00
|
|
|
atexit(taisei_shutdown);
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-21 21:31:46 +01:00
|
|
|
if(replay_path) {
|
|
|
|
replay_play(&replay, replay_stage);
|
|
|
|
replay_destroy(&replay);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-06 17:50:17 +02:00
|
|
|
#ifdef DEBUG
|
2017-02-28 23:10:23 +01:00
|
|
|
|
|
|
|
if(argc >= 2 && argv[1] && !strcmp(argv[1], "dumprestables")) {
|
2017-03-02 11:23:30 +01:00
|
|
|
print_resource_hashtables();
|
2017-02-28 23:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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]));
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
StageInfo* stg = stage_get(atoi(argv[1]));
|
|
|
|
|
|
|
|
if(!stg) {
|
|
|
|
errx(-1, "Invalid stage id");
|
|
|
|
}
|
|
|
|
|
|
|
|
global.diff = stg->difficulty;
|
|
|
|
|
|
|
|
if(!global.diff) {
|
|
|
|
global.diff = D_Easy;
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2012-07-13 18:44:56 +02:00
|
|
|
if(argc == 3 && argv[2]) {
|
|
|
|
printf("** Setting difficulty to %d.\n", atoi(argv[2]));
|
|
|
|
global.diff = atoi(argv[2]);
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
printf("** Entering %s.\n", stg->title);
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
do {
|
|
|
|
global.game_over = 0;
|
|
|
|
init_player(&global.plr);
|
2017-02-26 13:17:48 +01:00
|
|
|
stage_loop(stg);
|
2017-02-10 11:39:42 +01:00
|
|
|
} while(global.game_over == GAMEOVER_RESTART);
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
return 0;
|
2012-04-06 17:50:17 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
MenuData menu;
|
|
|
|
create_main_menu(&menu);
|
2017-02-24 22:58:27 +01:00
|
|
|
menu_loop(&menu);
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2012-08-16 15:50:28 +02:00
|
|
|
return 0;
|
2011-07-03 15:11:18 +02:00
|
|
|
}
|