diff --git a/FindGLEW.cmake b/FindGLEW.cmake new file mode 100644 index 00000000..3e9cb485 --- /dev/null +++ b/FindGLEW.cmake @@ -0,0 +1,46 @@ +# Try to find GLEW library and include path. + # Once done this will define + # + # GLEW_FOUND + # GLEW_INCLUDE_PATH + # GLEW_LIBRARY + # + + IF (WIN32) + FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h + $ENV{PROGRAMFILES}/GLEW/include + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include + DOC "The directory where GL/glew.h resides") + FIND_LIBRARY( GLEW_LIBRARY + NAMES glew GLEW glew32 glew32s + PATHS + $ENV{PROGRAMFILES}/GLEW/lib + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib + DOC "The GLEW library") + ELSE (WIN32) + FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h + /usr/include + /usr/local/include + /sw/include + /opt/local/include + DOC "The directory where GL/glew.h resides") + FIND_LIBRARY( GLEW_LIBRARY + NAMES GLEW glew + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + DOC "The GLEW library") + ENDIF (WIN32) + + IF (GLEW_INCLUDE_PATH) + SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") + ELSE (GLEW_INCLUDE_PATH) + SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") + ENDIF (GLEW_INCLUDE_PATH) + + MARK_AS_ADVANCED( GLEW_FOUND ) diff --git a/README b/README index a247d699..290794ad 100644 --- a/README +++ b/README @@ -9,8 +9,9 @@ Taisei is an open clone of the Touhou series. Touhou is a one-man project of sho Dependencies: - SDL, SDL_ttf - libpng - - OpenGL + - OpenGL, GLEW - OpenAL, ALUT + - flex/bison - CMake (build system) To build and install Taisei just follow these steps. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6822fe83..c85d86df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(OpenAL REQUIRED) find_package(ALUT REQUIRED) find_package(PNG REQUIRED) find_package(SDL_ttf REQUIRED) +find_package(GLEW REQUIRED) find_package(BISON) find_package(FLEX) @@ -38,15 +39,17 @@ set(SRCs resource/font.c resource/shader.c resource/audio.c + taisei_err.c ${BISON_cfgparser_OUTPUTS} ${FLEX_cfgscanner_OUTPUTS}) -add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}" -DGL_GLEXT_PROTOTYPES) +add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}") include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${SDL_INCLUDE_DIRS} ${ALUT_INCLUDE_DIRS}) add_executable(taisei ${SRCs}) -target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARY} ${SDLTTF_LIBRARY} ${OPENAL_LIBRARY} ${ALUT_LIBRARY}) +target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARY} + ${SDLTTF_LIBRARY} ${OPENAL_LIBRARY} ${ALUT_LIBRARY} ${GLEW_LIBRARY}) install(TARGETS taisei RUNTIME DESTINATION bin) diff --git a/src/config.l b/src/config.l index fbb34456..e754c5d4 100644 --- a/src/config.l +++ b/src/config.l @@ -40,14 +40,14 @@ [0-9]+ { yylval = atoi(yytext); return NUMBER; } -[a-zA-Z] { yylval = yytext[0]; return CHAR; } +[a-zA-Z] { yylval = yytext[0]; return tCHAR; } -ä { yylval = SDLK_WORLD_68; return CHAR; } -ü { yylval = SDLK_WORLD_92; return CHAR; } -ö { yylval = SDLK_WORLD_86; return CHAR; } -ß { yylval = SDLK_WORLD_63; return CHAR; } +ä { yylval = SDLK_WORLD_68; return tCHAR; } +ü { yylval = SDLK_WORLD_92; return tCHAR; } +ö { yylval = SDLK_WORLD_86; return tCHAR; } +ß { yylval = SDLK_WORLD_63; return tCHAR; } -K[0-9]+ { yylval = atoi(yytext + 1); return CHAR; } +K[0-9]+ { yylval = atoi(yytext + 1); return tCHAR; } \n return LB; [ \t] ; diff --git a/src/config.y b/src/config.y index 968baa75..f5e59748 100644 --- a/src/config.y +++ b/src/config.y @@ -39,7 +39,7 @@ %token SKEY %token NUMBER -%token CHAR +%token tCHAR %token SEMI %token EQ @@ -57,7 +57,7 @@ line : line nl | nl; key_val : SKEY - | CHAR; + | tCHAR; key_key : tKEY_UP | tKEY_DOWN diff --git a/src/fbo.c b/src/fbo.c index 7ccd6120..f9408e0c 100644 --- a/src/fbo.c +++ b/src/fbo.c @@ -1,6 +1,7 @@ #include "fbo.h" #include "global.h" +#include "taisei_err.h" void init_fbo(FBO *fbo) { glGenTextures(1, &fbo->tex); diff --git a/src/fbo.h b/src/fbo.h index c1041c52..5111c53d 100644 --- a/src/fbo.h +++ b/src/fbo.h @@ -8,7 +8,7 @@ #ifndef FBO_H #define FBO_H -#include +#include typedef struct { GLuint fbo; diff --git a/src/global.c b/src/global.c index 067ae988..7468faeb 100644 --- a/src/global.c +++ b/src/global.c @@ -8,7 +8,6 @@ #include "global.h" #include #include -#include Global global; diff --git a/src/global.h b/src/global.h index 1965c250..23ea6a20 100644 --- a/src/global.h +++ b/src/global.h @@ -118,7 +118,7 @@ void init_rtt(); void game_over(); void frame_rate(); - +void calc_fps(FPSCounter *fps); void set_ortho(); #endif \ No newline at end of file diff --git a/src/item.c b/src/item.c index 4f962371..a978a409 100644 --- a/src/item.c +++ b/src/item.c @@ -2,8 +2,7 @@ * This software is licensed under the terms of the MIT-License * See COPYING for further information. * --- - * Copyright (C) 2011, Lukas Weber - * Code by Juergen Kieslich + * Copyright (C) 2011, Lukas Weber , Juergen Kieslich */ #include "item.h" diff --git a/src/main.c b/src/main.c index b18bf40d..7ec43abd 100644 --- a/src/main.c +++ b/src/main.c @@ -6,8 +6,8 @@ */ #include -#include -#include +#include +#include "taisei_err.h" #include "global.h" #include "stages/stage0.h" @@ -51,12 +51,16 @@ int main(int argc, char** argv) { errx(-1, "Error initializing SDL: %s", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0); if((display = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 32, SDL_OPENGL)) == NULL) errx(-1, "Error opening screen: %s", SDL_GetError()); SDL_WM_SetCaption("TaiseiProject", NULL); + int err; + if((err = glewInit()) != GLEW_OK) + errx(-1, "GLEW failed: %s", glewGetErrorString(err)); + + init_gl(); if(!alutInit(&argc, argv)) diff --git a/src/menu/difficulty.c b/src/menu/difficulty.c index 7c2cb3b0..44b98ea6 100644 --- a/src/menu/difficulty.c +++ b/src/menu/difficulty.c @@ -55,5 +55,5 @@ void draw_difficulty_menu(MenuData *menu) { } int difficulty_menu_loop(MenuData *menu) { - menu_loop(menu, NULL, draw_difficulty_menu); + return menu_loop(menu, NULL, draw_difficulty_menu); } \ No newline at end of file diff --git a/src/menu/mainmenu.c b/src/menu/mainmenu.c index 1a9cca59..403bbf5d 100644 --- a/src/menu/mainmenu.c +++ b/src/menu/mainmenu.c @@ -12,6 +12,7 @@ #include "charselect.h" #include "global.h" +#include "stages/stage0.h" void quit_menu(void *arg) { MenuData *m = arg; diff --git a/src/plrmodes.c b/src/plrmodes.c index 3f325e7b..144534c7 100644 --- a/src/plrmodes.c +++ b/src/plrmodes.c @@ -99,6 +99,8 @@ int mari_laser(Projectile *p, int t) { Player *plr = (Player *)REF(p->args[1]); p->pos = plr->pos + p->pos - creal(p->pos0)*abs(plr->focus)/30.0; + + return 1; } void marisa_shot(Player *plr) { diff --git a/src/projectile.c b/src/projectile.c index 570dd0b7..d25458d9 100644 --- a/src/projectile.c +++ b/src/projectile.c @@ -213,8 +213,6 @@ void DeathShrink(Projectile *p, int t) { } int bullet_flare_move(Projectile *p, int t) { - int i; - if(t > 16 || REF(p->args[1]) == NULL) { free_ref(p->args[1]); return ACTION_DESTROY; @@ -246,4 +244,6 @@ int timeout_linear(Projectile *p, int t) { p->angle = carg(p->args[1]); p->pos = p->pos0 + p->args[1]*t; + + return 1; } \ No newline at end of file diff --git a/src/resource/animation.c b/src/resource/animation.c index cec2c993..e5e05e9f 100644 --- a/src/resource/animation.c +++ b/src/resource/animation.c @@ -10,7 +10,7 @@ #include "list.h" #include -#include +#include "taisei_err.h" Animation *init_animation(char *filename) { Animation *buf = create_element((void **)&global.animations, sizeof(Animation)); diff --git a/src/resource/audio.c b/src/resource/audio.c index 56d5a4e2..a7b30393 100644 --- a/src/resource/audio.c +++ b/src/resource/audio.c @@ -8,7 +8,7 @@ #include "audio.h" #include "global.h" #include "list.h" -#include +#include "taisei_err.h" Sound *load_sound(char *filename) { ALuint sound; diff --git a/src/resource/shader.c b/src/resource/shader.c index 51ae87e1..5147301e 100644 --- a/src/resource/shader.c +++ b/src/resource/shader.c @@ -9,7 +9,7 @@ #include "global.h" #include "list.h" #include -#include +#include "taisei_err.h" void print_info_log(GLuint shader) { int len = 0, alen = 0; @@ -27,7 +27,7 @@ void print_info_log(GLuint shader) { void load_shader(const char *filename) { FILE *file = fopen(filename,"r"); if(file == NULL) - err(-1, "Error opening '%s'", filename); + errx(-1, "Error opening '%s'", filename); fseek(file, 0, SEEK_END); int size = ftell(file); diff --git a/src/resource/shader.h b/src/resource/shader.h index 3fcd0896..1f137630 100644 --- a/src/resource/shader.h +++ b/src/resource/shader.h @@ -8,7 +8,7 @@ #ifndef SHADER_H #define SHADER_H -#include +#include #define DELIM "%% -- FRAG" #define DELIM_SIZE 10 diff --git a/src/resource/texture.c b/src/resource/texture.c index cdf1a0e3..34b7126b 100644 --- a/src/resource/texture.c +++ b/src/resource/texture.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include "taisei_err.h" #include "audio.h" #include "shader.h" #include "list.h" @@ -19,7 +19,7 @@ void recurse_dir(char *path) { DIR *dir = opendir(path); if(dir == NULL) - err(-1, "Couldn't open directory '%s'", path); + errx(-1, "Couldn't open directory '%s'", path); struct dirent *dp; char buf[512]; @@ -88,7 +88,7 @@ Texture *prefix_get_tex(char *name, char *prefix) { else src = name; - char *buf = malloc(strlen(src) + strlen(prefix)); + char *buf = malloc(strlen(src) + strlen(prefix) + 1); strcpy(buf, prefix); strcat(buf, src); @@ -114,7 +114,7 @@ Texture *load_texture(const char *filename) { SDL_Surface *surface = load_png(filename); if(surface == NULL) - err(-1,"load_texture():\n!- cannot load '%s'", filename); + errx(-1,"load_texture():\n!- cannot load '%s'", filename); Texture *texture = create_element((void **)&global.textures, sizeof(Texture)); load_sdl_surf(surface, texture); @@ -135,7 +135,7 @@ Texture *load_texture(const char *filename) { SDL_Surface *load_png(const char *filename) { FILE *fp = fopen(filename, "rb"); if(!fp) - err(-1, "Error loading '%s'", filename); + errx(-1, "Error loading '%s'", filename); png_structp png_ptr; if(!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) diff --git a/src/resource/texture.h b/src/resource/texture.h index ca62c4ea..564a6eff 100644 --- a/src/resource/texture.h +++ b/src/resource/texture.h @@ -9,7 +9,7 @@ #define TEXTURE_H #include -#include +#include #include struct Texture; diff --git a/src/stage.c b/src/stage.c index e5732e81..3963cf50 100644 --- a/src/stage.c +++ b/src/stage.c @@ -112,8 +112,6 @@ void draw_hud() { draw_text(AL_Left, SCREEN_W, SCREEN_H-20, buf, _fonts.standard); } - - void stage_draw() { set_ortho(); diff --git a/src/stages/stage0.c b/src/stages/stage0.c index 1f9980a8..48caae59 100644 --- a/src/stages/stage0.c +++ b/src/stages/stage0.c @@ -7,7 +7,6 @@ #include "stage0.h" -#include #include "../stage.h" #include "../global.h" diff --git a/src/taisei_err.c b/src/taisei_err.c new file mode 100644 index 00000000..e655803b --- /dev/null +++ b/src/taisei_err.c @@ -0,0 +1,40 @@ +/* + * This software is licensed under the terms of the MIT-License + * See COPYING for further information. + * --- + * Copyright (C) 2011, Lukas Weber + */ + +#include "taisei_err.h" +#include +#include + +// void err(int eval, const char *fmt, ...); +void errx(int eval, const char *fmt, ...) { + va_list ap; + + char *buf = malloc(11+strlen(fmt)); + strcpy(buf, "!- ERROR: "); + strcat(buf, fmt); + + va_start(ap, fmt); + vfprintf(buf, ap); + va_end(ap); + free(buf); + + exit(eval); +} + +// void warn(const char *fmt, ...); +void warnx(const char *fmt, ...) { + va_list ap; + + char *buf = malloc(11+strlen(fmt)); + strcpy(buf, "!- WARNING: "); + strcat(buf, fmt); + + va_start(ap, fmt); + vfprintf(buf, ap); + va_end(ap); + free(buf); +} \ No newline at end of file diff --git a/src/taisei_err.h b/src/taisei_err.h new file mode 100644 index 00000000..22d8d8e7 --- /dev/null +++ b/src/taisei_err.h @@ -0,0 +1,16 @@ +/* + * This software is licensed under the terms of the MIT-License + * See COPYING for further information. + * --- + * Copyright (C) 2011, Lukas Weber + */ + +/* replacement for standard err.h, some environments don't have it ... but i like it :/ */ + +#include + +// void err(int eval, const char *fmt, ...); +void errx(int eval, const char *fmt, ...); + +// void warn(const char *fmt, ...); +void warnx(const char *fmt, ...);