From ef208e1b7d93b6e434c17df26c8edcaa51088539 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sat, 20 Mar 2004 17:16:28 +0000 Subject: [PATCH] new level-format, many changes to level-related stuff SVN-Revision: 279 --- src/button.cpp | 2 +- src/button.h | 2 +- src/collision.cpp | 2 +- src/gameloop.cpp | 4 +- src/gameloop.h | 2 +- src/high_scores.cpp | 3 +- src/level.cpp | 298 +++++++++++++++++++++++++++------------------------- src/level.h | 54 ++++++---- src/leveleditor.cpp | 134 ++++++++--------------- src/lispreader.cpp | 22 +++- src/lispreader.h | 1 + src/menu.cpp | 4 +- src/menu.h | 4 +- src/physic.cpp | 2 + src/player.cpp | 4 +- src/setup.cpp | 15 ++- src/setup.h | 12 +-- src/text.cpp | 14 ++- src/text.h | 12 +-- src/texture.cpp | 12 +-- src/texture.h | 12 +-- src/timer.cpp | 4 +- src/timer.h | 4 +- src/title.cpp | 38 ++++--- src/type.cpp | 5 +- src/type.h | 4 +- 26 files changed, 327 insertions(+), 343 deletions(-) diff --git a/src/button.cpp b/src/button.cpp index b209969cb..6efc8c8f3 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -55,7 +55,7 @@ void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortc pbutton->bkgd = NULL; } -button_type* button_change_icon(button_type* pbutton,char* icon_file) +void button_change_icon(button_type* pbutton,char* icon_file) { char filename[1024]; diff --git a/src/button.h b/src/button.h index dff208a0a..183d9fe10 100644 --- a/src/button.h +++ b/src/button.h @@ -39,7 +39,7 @@ button_type; void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortcut, int x, int y); button_type* button_create(char* icon_file, char* info, SDLKey shortcut, int x, int y); -button_type* button_change_icon(button_type* pbutton,char* icon_file); +void button_change_icon(button_type* pbutton,char* icon_file); void button_draw(button_type* pbutton); void button_free(button_type* pbutton); void button_event(button_type* pbutton, SDL_Event* event); diff --git a/src/collision.cpp b/src/collision.cpp index fbde783cd..01ae29b84 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -218,7 +218,7 @@ int collision_swept_object_map(base_type* old, base_type* current) } *old = *current; - +return 0; } void collision_handler() diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 05171b124..72901d1ca 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -79,7 +79,7 @@ void levelintro(void) sprintf(str, "LEVEL %d", level); text_drawf(&blue_text, str, 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE); - sprintf(str, "%s", current_level.name); + sprintf(str, "%s", current_level.name.c_str()); text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE); sprintf(str, "TUX x %d", tux.lives); @@ -578,7 +578,7 @@ void game_draw(void) /* --- GAME LOOP! --- */ -int gameloop(char * subset, int levelnb, int mode) +int gameloop(const char * subset, int levelnb, int mode) { int fps_cnt, jump, done; timer_type fps_timer, frame_timer; diff --git a/src/gameloop.h b/src/gameloop.h index 0d68c23c2..b3718e62c 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -29,7 +29,7 @@ extern st_level current_level; /* Function prototypes: */ -int gameloop(char * subset, int levelnb, int mode); +int gameloop(const char * subset, int levelnb, int mode); void savegame(int slot); void loadgame(int slot); void slotinfo(char **pinfo, int slot); diff --git a/src/high_scores.cpp b/src/high_scores.cpp index 33836d471..d1b4d94ec 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -63,7 +63,8 @@ void load_hs(void) { FILE * fi; char temp[128]; - int c, i, strl; + int strl; + unsigned int i, c; hs_score = 100; strcpy(hs_name, "Grandma\0"); diff --git a/src/level.cpp b/src/level.cpp index 9a8a42c0e..a48422499 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "globals.h" #include "setup.h" #include "screen.h" @@ -21,17 +22,28 @@ #include "scene.h" #include "lispreader.h" +using namespace std; + texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; -void subset_init(st_subset* st_subset) +st_subset::st_subset() +{ + levels = 0; +} + +void st_subset::create(const std::string& subset_name) { - st_subset->title = NULL; - st_subset->description = NULL; - st_subset->name = NULL; - st_subset->levels = 0; + st_level new_lev; + st_subset new_subset; + new_subset.name = subset_name; + new_subset.title = "Unknown Title"; + new_subset.description = "No description so far."; + new_subset.save(); + level_default(&new_lev); + level_save(&new_lev,subset_name.c_str(),1); } -void subset_parse (st_subset* st_subset, lisp_object_t* cursor) +void st_subset::parse (lisp_object_t* cursor) { while(!lisp_nil_p(cursor)) { @@ -48,16 +60,14 @@ void subset_parse (st_subset* st_subset, lisp_object_t* cursor) { if(( s = lisp_string(lisp_car(lisp_cdr(cur)))) != NULL) { - st_subset->title = (char*) malloc(sizeof(char)*(strlen(s)+1)); - strcpy(st_subset->title,s); + title = s; } } else if (strcmp(lisp_symbol(lisp_car(cur)), "description") == 0) { if(( s = lisp_string(lisp_car(lisp_cdr(cur)))) != NULL) { - st_subset->description = (char*) malloc(sizeof(char)*(strlen(s)+1)); - strcpy(st_subset->description,s); + description = s; } } } @@ -65,16 +75,15 @@ void subset_parse (st_subset* st_subset, lisp_object_t* cursor) } } -void subset_load(st_subset* st_subset, char *subset) +void st_subset::load(char *subset) { FILE* fi; char filename[1024]; char str[1024]; - int len,i; + int i; lisp_object_t* root_obj = 0; - st_subset->name = (char*) malloc(sizeof(char)*(strlen(subset)+1)); - strcpy(st_subset->name,subset); + name = subset; snprintf(filename, 1024, "%s/levels/%s/info", st_dir, subset); if(!faccessible(filename)) @@ -104,7 +113,7 @@ void subset_load(st_subset* st_subset, char *subset) if (strcmp(lisp_symbol(cur), "level-subset") == 0) { - subset_parse(st_subset,lisp_cdr(root_obj)); + parse(lisp_cdr(root_obj)); } @@ -113,12 +122,12 @@ void subset_load(st_subset* st_subset, char *subset) snprintf(str, 1024, "%s.png", filename); if(faccessible(str)) { - texture_load(&st_subset->image,str,IGNORE_ALPHA); + texture_load(&image,str,IGNORE_ALPHA); } else { snprintf(filename, 1024, "%s/images/status/level-subset-info.png", DATA_PREFIX); - texture_load(&st_subset->image,filename,IGNORE_ALPHA); + texture_load(&image,filename,IGNORE_ALPHA); } } @@ -133,57 +142,81 @@ void subset_load(st_subset* st_subset, char *subset) break; } } - st_subset->levels = --i; + levels = --i; } -void subset_save(st_subset* st_subset) +void st_subset::save() { FILE* fi; - char filename[1024]; + string filename; /* Save data file: */ - sprintf(filename, "/levels/%s/", st_subset->name); + filename = "/levels/" + name + "/"; - fcreatedir(filename); - snprintf(filename, 1024, "%s/levels/%s/info", st_dir, st_subset->name); - if(!fwriteable(filename)) - snprintf(filename, 1024, "%s/levels/%s/info", DATA_PREFIX, st_subset->name); - if(fwriteable(filename)) + fcreatedir(filename.c_str()); + filename = string(st_dir) + "/levels/" + name + "/info"; + if(!fwriteable(filename.c_str())) + filename = string(DATA_PREFIX) + "/levels/" + name + "/info"; + if(fwriteable(filename.c_str())) { - fi = fopen(filename, "w"); + fi = fopen(filename.c_str(), "w"); if (fi == NULL) { - perror(filename); + perror(filename.c_str()); } - + /* Write header: */ fprintf(fi,";SuperTux-Level-Subset\n"); fprintf(fi,"(level-subset\n"); - + /* Save title info: */ - fprintf(fi," (title \"%s\")\n",st_subset->title); + fprintf(fi," (title \"%s\")\n", title.c_str()); /* Save the description: */ - fprintf(fi," (description \"%s\")\n",st_subset->description); - + fprintf(fi," (description \"%s\")\n", description.c_str()); + fprintf( fi,")"); fclose(fi); } } -void subset_free(st_subset* st_subset) +void st_subset::free() +{ + title.clear(); + description.clear(); + name.clear(); + texture_free(&image); + levels = 0; +} + +void level_default(st_level* plevel) { - free(st_subset->title); - free(st_subset->description); - free(st_subset->name); - texture_free(&st_subset->image); - st_subset->levels = 0; + int i,y; + plevel->name = "UnNamed"; + plevel->theme = "antarctica"; + plevel->song_title = "Mortimers_chipdisko.mod"; + plevel->bkgd_image = "arctis.png"; + plevel->width = 21; + plevel->time_left = 100; + plevel->gravity = 10.; + plevel->bkgd_red = 0; + plevel->bkgd_green = 0; + plevel->bkgd_blue = 0; + + for(i = 0; i < 15; ++i) + { + plevel->tiles[i] = (unsigned int*) malloc((plevel->width+1)*sizeof(unsigned int)); + plevel->tiles[i][plevel->width] = (unsigned int) '\0'; + for(y = 0; y < plevel->width; ++y) + plevel->tiles[i][y] = (unsigned int) '.'; + plevel->tiles[i][plevel->width] = (unsigned int) '\0'; + } } /* Load data for this level: */ /* Returns -1, if the loading of the level failed. */ -int level_load(st_level* plevel, char *subset, int level) +int level_load(st_level* plevel,const char *subset, int level) { char filename[1024]; @@ -198,10 +231,9 @@ int level_load(st_level* plevel, char *subset, int level) int level_load(st_level* plevel, const char* filename) { - char str[80]; int x, y; - char * line; FILE * fi; + lisp_object_t* root_obj = 0; fi = fopen(filename, "r"); if (fi == NULL) { @@ -209,80 +241,59 @@ int level_load(st_level* plevel, const char* filename) return -1; } - /* Load header info: */ - - - /* (Level title) */ - fgets(str, 20, fi); - strcpy(plevel->name, str); - plevel->name[strlen(plevel->name)-1] = '\0'; - - /* (Level theme) */ - fgets(str, 20, fi); - strcpy(plevel->theme, str); - plevel->theme[strlen(plevel->theme)-1] = '\0'; + lisp_stream_t stream; + lisp_stream_init_file (&stream, fi); + root_obj = lisp_read (&stream); - - - /* (Time to beat level) */ - fgets(str, 10, fi); - plevel->time_left = atoi(str); - - /* (Song file for this level) */ - fgets(str, sizeof(plevel->song_title), fi); - strcpy(plevel->song_title, str); - plevel->song_title[strlen(plevel->song_title)-1] = '\0'; - - /* (Level background image) */ - fgets(str, sizeof(plevel->bkgd_image), fi); - strcpy(plevel->bkgd_image, str); - plevel->bkgd_image[strlen(plevel->bkgd_image)-1] = '\0'; - - /* (Level background color) */ - fgets(str, 10, fi); - plevel->bkgd_red = atoi(str); - fgets(str, 10, fi); - plevel->bkgd_green= atoi(str); - fgets(str, 10, fi); - plevel->bkgd_blue = atoi(str); - - /* (Level width) */ - fgets(str, 10, fi); - plevel->width = atoi(str); - - /* (Level gravity) */ - fgets(str, 10, fi); - plevel->gravity = atof(str); - - /* Set the global gravity to the latest loaded level's gravity */ - gravity = plevel->gravity; - - /* Allocate some space for the line-reading! */ - - line = (char *) malloc(sizeof(char) * (plevel->width + 5)); - if (line == NULL) + if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) { - fprintf(stderr, "Couldn't allocate space to load level data!"); - fclose(fi); - return -1; + printf("World: Parse Error in file %s", filename); } + vector vi; - /* Load the level lines: */ +DEBUG_MSG("LLALAL"); + if (strcmp(lisp_symbol(lisp_car(root_obj)), "level") == 0) + { + LispReader reader(lisp_cdr(root_obj)); + + DEBUG_MSG("TAGAF"); + reader.read_int("width", &plevel->width); + reader.read_int("time", &plevel->time_left); + reader.read_int("bkgd_red", &plevel->bkgd_red); + reader.read_int("bkgd_green", &plevel->bkgd_green); + reader.read_int("bkgd_blue", &plevel->bkgd_blue); + reader.read_float("gravity", &plevel->gravity); + reader.read_string("name", &plevel->name); + reader.read_string("theme", &plevel->theme); + reader.read_string("music", &plevel->song_title); + reader.read_string("background", &plevel->bkgd_image); + reader.read_int_vector("tilemap", &vi); + } + + DEBUG_MSG("LOLOL"); + + int i; + for( i = 0; i < 15; ++i) + plevel->tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) ); - for (y = 0; y < 15; y++) + i = 0; + int j = 0; + for(vector::iterator it = vi.begin(); it != vi.end(); ++it, ++i) { - if(fgets(line, plevel->width + 5, fi) == NULL) + + plevel->tiles[j][i] = (*it); + if(i == plevel->width) { - fprintf(stderr, "Level %s isn't complete!\n",plevel->name); - free(line); - fclose(fi); - return -1; + i = 0; + ++j; + DEBUG_MSG("joa"); } - line[strlen(line) - 1] = '\0'; - plevel->tiles[y] = (unsigned char*) strdup(line); } + /* Set the global gravity to the latest loaded level's gravity */ + gravity = plevel->gravity; + /* Mark the end position of this level! - Is a bit wrong here thought */ for (y = 0; y < 15; ++y) @@ -297,18 +308,17 @@ int level_load(st_level* plevel, const char* filename) } } - free(line); fclose(fi); return 0; } /* Save data for level: */ -void level_save(st_level* plevel, char * subset, int level) +void level_save(st_level* plevel,const char * subset, int level) { FILE * fi; char filename[1024]; - int y; + int y,i; char str[80]; /* Save data file: */ @@ -326,31 +336,31 @@ void level_save(st_level* plevel, char * subset, int level) exit(-1); } - fputs(plevel->name, fi); - fputs("\n", fi); - fputs(plevel->theme, fi); - fputs("\n", fi); - sprintf(str, "%d\n", plevel->time_left); /* time */ - fputs(str, fi); - fputs(plevel->song_title, fi); /* song filename */ - fputs("\n",fi); - fputs(plevel->bkgd_image, fi); /* background image */ - sprintf(str, "\n%d\n", plevel->bkgd_red); /* red background color */ - fputs(str, fi); - sprintf(str, "%d\n", plevel->bkgd_green); /* green background color */ - fputs(str, fi); - sprintf(str, "%d\n", plevel->bkgd_blue); /* blue background color */ - fputs(str, fi); - sprintf(str, "%d\n", plevel->width); /* level width */ - fputs(str, fi); - sprintf(str, "%2.1f\n", plevel->gravity); /* level gravity */ - fputs(str, fi); + /* Write header: */ + fprintf(fi,";SuperTux-Level\n"); + fprintf(fi,"(level\n"); + + fprintf(fi," (name \"%s\")\n", plevel->name.c_str()); + fprintf(fi," (theme \"%s\")\n", plevel->theme.c_str()); + fprintf(fi," (music \"%s\")\n", plevel->song_title.c_str()); + fprintf(fi," (background \"%s\")\n", plevel->bkgd_image.c_str()); + fprintf(fi," (bkgd_red %d)\n", plevel->bkgd_red); + fprintf(fi," (bkgd_green %d)\n", plevel->bkgd_green); + fprintf(fi," (bkgd_blue %d)\n", plevel->bkgd_blue); + fprintf(fi," (time %d)\n", plevel->time_left); + fprintf(fi," (width %d)\n", plevel->width); + fprintf(fi," (gravity %2.1f)\n", plevel->gravity); + fprintf(fi," (tilemap "); + for(y = 0; y < 15; ++y) { - fputs((const char*)plevel->tiles[y], fi); - fputs("\n", fi); + for(i = 0; i < plevel->width; ++i) + fprintf(fi," %d ", plevel->tiles[y][i]); } + + fprintf( fi,")"); + fprintf( fi,")\n"); fclose(fi); } @@ -364,10 +374,10 @@ void level_free(st_level* plevel) for(i=0; i < 15; ++i) free(plevel->tiles[i]); - plevel->name[0] = '\0'; - plevel->theme[0] = '\0'; - plevel->song_title[0] = '\0'; - plevel->bkgd_image[0] = '\0'; + plevel->name.clear(); + plevel->theme.clear(); + plevel->song_title.clear(); + plevel->bkgd_image.clear(); } /* Load graphics: */ @@ -392,12 +402,12 @@ void level_load_gfx(st_level *plevel) level_load_image(&img_bkgd_tile[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA); level_load_image(&img_bkgd_tile[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA); - if(strcmp(plevel->bkgd_image,"") != 0) + if(!plevel->bkgd_image.empty()) { char fname[1024]; - snprintf(fname, 1024, "%s/background/%s", st_dir, plevel->bkgd_image); + snprintf(fname, 1024, "%s/background/%s", st_dir, plevel->bkgd_image.c_str()); if(!faccessible(fname)) - snprintf(fname, 1024, "%s/images/background/%s", DATA_PREFIX, plevel->bkgd_image); + snprintf(fname, 1024, "%s/images/background/%s", DATA_PREFIX, plevel->bkgd_image.c_str()); texture_load(&img_bkgd, fname, IGNORE_ALPHA); } else @@ -429,13 +439,13 @@ void level_free_gfx(void) /* Load a level-specific graphic... */ -void level_load_image(texture_type* ptexture, char* theme, char * file, int use_alpha) +void level_load_image(texture_type* ptexture, string theme,const char * file, int use_alpha) { char fname[1024]; - snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme, file); + snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme.c_str(), file); if(!faccessible(fname)) - snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file); + snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme.c_str(), file); texture_load(ptexture, fname, use_alpha); } @@ -470,17 +480,17 @@ void level_load_song(st_level* plevel) char * song_subtitle; song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + - strlen(plevel->song_title) + 8)); - sprintf(song_path, "%s/music/%s", DATA_PREFIX, plevel->song_title); + strlen(plevel->song_title.c_str()) + 8)); + sprintf(song_path, "%s/music/%s", DATA_PREFIX, plevel->song_title.c_str()); level_song = load_song(song_path); free(song_path); song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + - strlen(plevel->song_title) + 8 + 5)); - song_subtitle = strdup(plevel->song_title); + strlen(plevel->song_title.c_str()) + 8 + 5)); + song_subtitle = strdup(plevel->song_title.c_str()); strcpy(strstr(song_subtitle, "."), "\0"); - sprintf(song_path, "%s/music/%s-fast%s", DATA_PREFIX, song_subtitle, strstr(plevel->song_title, ".")); + sprintf(song_path, "%s/music/%s-fast%s", DATA_PREFIX, song_subtitle, strstr(plevel->song_title.c_str(), ".")); level_song_fast = load_song(song_path); free(song_subtitle); free(song_path); diff --git a/src/level.h b/src/level.h index d798fc82e..1a9b1647b 100644 --- a/src/level.h +++ b/src/level.h @@ -1,7 +1,7 @@ // // C Interface: level // -// Description: +// Description: // // // Author: Tobias Glaesser , (C) 2003 @@ -13,52 +13,60 @@ #ifndef SUPERTUX_LEVEL_H #define SUPERTUX_LEVEL_H +#include #include "texture.h" #include "lispreader.h" /* This type holds meta-information about a level-subset. */ /* It could be extended to handle manipulation of subsets. */ -typedef struct st_subset +class st_subset { - char *name; - char *title; - char *description; + public: + st_subset(); + static void create(const std::string& subset_name); + void load(char *subset); + void save(); + void free(); + + std::string name; + std::string title; + std::string description; texture_type image; int levels; - } st_subset; + + private: + void parse(lisp_object_t* cursor); + }; -void subset_init(st_subset* st_subset); -void subset_parse(st_subset* st_subset, lisp_object_t* cursor); -void subset_load(st_subset* st_subset, char *subset); -void subset_save(st_subset* st_subset); -void subset_free(st_subset* st_subset); - #define LEVEL_NAME_MAX 20 typedef struct st_level /*It is easier to read the sources IMHO, if we don't write something like int a,b,c; */ { - char name[LEVEL_NAME_MAX]; - char theme[100]; - char song_title[100]; - char bkgd_image[100]; - unsigned char* tiles[15]; + std::string name; + std::string theme; + std::string song_title; + std::string bkgd_image; + unsigned int* tiles[15]; int time_left; int bkgd_red; int bkgd_green; int bkgd_blue; int width; float gravity; - } st_level; - + } +st_level; + extern texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; - -int level_load(st_level* plevel, char * subset, int level); + +void level_default(st_level* plevel); +int level_load(st_level* plevel, const char * subset, int level); +void level_parse(st_level* plevel, lisp_object_t* cursor); int level_load(st_level* plevel, const char* filename); -void level_save(st_level* plevel, char * subset, int level); +void level_save(st_level* plevel, const char * subset, int level); void level_free(st_level* plevel); void level_load_gfx(st_level* plevel); void level_free_gfx(); -void level_load_image(texture_type* ptexture, char* theme, char * file, int use_alpha); +void level_load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha); void level_change(st_level* plevel, float x, float y, unsigned char c); void level_load_song(st_level* plevel); void level_free_song(void); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index d0d7b9e13..a7c5b8b7e 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -71,19 +71,18 @@ void le_testlevel(); void le_showhelp(); void le_set_defaults(void); void le_activate_bad_guys(void); -void le_new_subset(char *subset_name); void le_highlight_selection(); void apply_level_settings_menu(); void update_subset_settings_menu(); void save_subset_settings_menu(); -void le_update_buttons(char*); +void le_update_buttons(const char*); /* leveleditor internals */ static string_list_type level_subsets; static int le_level_changed; /* if changes, ask for saving, when quiting*/ -static int pos_x, cursor_x, cursor_y, cursor_tile, fire; +static int pos_x, cursor_x, cursor_y, fire; static int le_level; static st_level* le_current_level; static st_subset le_level_subset; @@ -225,18 +224,18 @@ int leveleditor(int levelnb) default: if(i != -1) { - subset_load(&le_level_subset,level_subsets.item[i-2]); + le_level_subset.load(level_subsets.item[i-2]); leveleditor_menu.item[3].kind = MN_GOTO; le_level = 1; arrays_init(); loadshared(); - le_current_level = (st_level*) malloc(sizeof(st_level)); - if(level_load(le_current_level, le_level_subset.name, le_level) != 0) + le_current_level = new st_level; + if(level_load(le_current_level, le_level_subset.name.c_str(), le_level) != 0) { le_quit(); return 1; } - le_update_buttons(le_current_level->theme); + le_update_buttons(le_current_level->theme.c_str()); le_set_defaults(); level_load_gfx(le_current_level); le_activate_bad_guys(); @@ -256,19 +255,19 @@ int leveleditor(int levelnb) switch (i = menu_check(&subset_new_menu)) { case 3: - le_new_subset(subset_new_menu.item[2].input); - subset_load(&le_level_subset,subset_new_menu.item[2].input); + st_subset::create(subset_new_menu.item[2].input); + le_level_subset.load(subset_new_menu.item[2].input); leveleditor_menu.item[3].kind = MN_GOTO; le_level = 1; arrays_init(); loadshared(); le_current_level = (st_level*) malloc(sizeof(st_level)); - if(level_load(le_current_level, le_level_subset.name, le_level) != 0) + if(level_load(le_current_level, le_level_subset.name.c_str(), le_level) != 0) { le_quit(); return 1; } - le_update_buttons(le_current_level->theme); + le_update_buttons(le_current_level->theme.c_str()); le_set_defaults(); level_load_gfx(le_current_level); le_activate_bad_guys(); @@ -280,7 +279,7 @@ int leveleditor(int levelnb) } else if(current_menu == &subset_settings_menu) { - if(strcmp(le_level_subset.title,subset_settings_menu.item[2].input) == 0 && strcmp(le_level_subset.description,subset_settings_menu.item[3].input) == 0 ) + if(le_level_subset.title.compare(subset_settings_menu.item[2].input) == 0 && le_level_subset.description.compare(subset_settings_menu.item[3].input) == 0 ) subset_settings_menu.item[5].kind = MN_DEACTIVE; else subset_settings_menu.item[5].kind = MN_ACTION; @@ -318,46 +317,8 @@ int leveleditor(int levelnb) return done; } -void le_default_level(st_level* plevel) -{ - int i,y; - strcpy(plevel->name,"UnNamed"); - strcpy(plevel->theme,"antarctica"); - strcpy(plevel->song_title,"Mortimers_chipdisko.mod"); - strcpy(plevel->bkgd_image,"arctis.png"); - plevel->width = 21; - plevel->time_left = 100; - plevel->gravity = 10.; - plevel->bkgd_red = 0; - plevel->bkgd_green = 0; - plevel->bkgd_blue = 0; - - for(i = 0; i < 15; ++i) - { - plevel->tiles[i] = (unsigned char*) malloc((plevel->width+1)*sizeof(unsigned char)); - plevel->tiles[i][plevel->width] = (unsigned char) '\0'; - for(y = 0; y < plevel->width; ++y) - plevel->tiles[i][y] = (unsigned char) '.'; - plevel->tiles[i][plevel->width] = (unsigned char) '\0'; - } -} - -void le_new_subset(char *subset_name) -{ - st_level new_lev; - st_subset new_subset; - new_subset.name = (char*) malloc((strlen(subset_name)+1)*sizeof(char)); - strcpy(new_subset.name,subset_name); - new_subset.title = (char*) malloc((strlen("Unknown Title")+1)*sizeof(char)); - strcpy(new_subset.title,"Unknown Title"); - new_subset.description = (char*) malloc((strlen("No description so far.")+1)*sizeof(char)); - strcpy(new_subset.description,"No description so far."); - subset_save(&new_subset); - le_default_level(&new_lev); - level_save(&new_lev,subset_name,1); -} -void le_update_buttons(char *theme) +void le_update_buttons(const char *theme) { int i; char filename[1024]; @@ -401,8 +362,7 @@ void le_update_buttons(char *theme) int le_init() { - int i,j; - char str[80]; + int i; char filename[1024]; SDLKey key; string_list_type fgd_files; @@ -417,9 +377,6 @@ int le_init() done = 0; le_frame = 0; /* support for frames in some tiles, like waves and bad guys */ le_level_changed = NO; - - subset_init(&le_level_subset); - le_current_level = NULL; le_current_tile = '.'; @@ -518,7 +475,6 @@ int le_init() le_fgd_panel.item[16].bkgd = &le_fgd_panel.item[14].icon; le_fgd_panel.item[17].bkgd = &le_fgd_panel.item[15].icon; - bad_files; string_list_init(&bad_files); string_list_add_item(&bad_files,"bsod-left-0.png"); string_list_add_item(&bad_files,"laptop-left-0.png"); @@ -601,18 +557,18 @@ void update_level_settings_menu() char str[80]; int i; - menu_item_change_input(&level_settings_menu.item[2], le_current_level->name); + menu_item_change_input(&level_settings_menu.item[2], le_current_level->name.c_str()); sprintf(str,"%d",le_current_level->width); string_list_copy(level_settings_menu.item[3].list, dsubdirs("images/themes", "solid0.png")); string_list_copy(level_settings_menu.item[4].list, dfiles("music/",NULL, "-fast")); string_list_copy(level_settings_menu.item[5].list, dfiles("images/background",NULL, NULL)); string_list_add_item(level_settings_menu.item[5].list,""); - if((i = string_list_find(level_settings_menu.item[3].list,le_current_level->theme)) != -1) + if((i = string_list_find(level_settings_menu.item[3].list,le_current_level->theme.c_str())) != -1) level_settings_menu.item[3].list->active_item = i; - if((i = string_list_find(level_settings_menu.item[4].list,le_current_level->song_title)) != -1) + if((i = string_list_find(level_settings_menu.item[4].list,le_current_level->song_title.c_str())) != -1) level_settings_menu.item[4].list->active_item = i; - if((i = string_list_find(level_settings_menu.item[5].list,le_current_level->bkgd_image)) != -1) + if((i = string_list_find(level_settings_menu.item[5].list,le_current_level->bkgd_image.c_str())) != -1) level_settings_menu.item[5].list->active_item = i; menu_item_change_input(&level_settings_menu.item[6], str); @@ -630,8 +586,8 @@ void update_level_settings_menu() void update_subset_settings_menu() { - menu_item_change_input(&subset_settings_menu.item[2], le_level_subset.title); - menu_item_change_input(&subset_settings_menu.item[3], le_level_subset.description); + menu_item_change_input(&subset_settings_menu.item[2], le_level_subset.title.c_str()); + menu_item_change_input(&subset_settings_menu.item[3], le_level_subset.description.c_str()); } void apply_level_settings_menu() @@ -639,18 +595,18 @@ void apply_level_settings_menu() int i,y,j; i = NO; - strcpy(le_current_level->name,level_settings_menu.item[2].input); + le_current_level->name = level_settings_menu.item[2].input; - if(strcmp(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list)) != 0) + if(le_current_level->bkgd_image.compare(string_list_active(level_settings_menu.item[5].list)) != 0) { - strcpy(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list)); + le_current_level->bkgd_image = string_list_active(level_settings_menu.item[5].list); i = YES; } - if(strcmp(le_current_level->theme,string_list_active(level_settings_menu.item[3].list)) != 0) + if(le_current_level->theme.compare(string_list_active(level_settings_menu.item[3].list)) != 0) { - strcpy(le_current_level->theme,string_list_active(level_settings_menu.item[3].list)); - le_update_buttons(le_current_level->theme); + le_current_level->theme = string_list_active(level_settings_menu.item[3].list); + le_update_buttons(le_current_level->theme.c_str()); i = YES; } @@ -660,7 +616,7 @@ void apply_level_settings_menu() level_load_gfx(le_current_level); } - strcpy(le_current_level->song_title,string_list_active(level_settings_menu.item[4].list)); + le_current_level->song_title = string_list_active(level_settings_menu.item[4].list); i = le_current_level->width; le_current_level->width = atoi(level_settings_menu.item[6].input); @@ -670,18 +626,18 @@ void apply_level_settings_menu() le_current_level->width = 21; for(y = 0; y < 15; ++y) { - le_current_level->tiles[y] = (unsigned char*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned char)); - le_current_level->tiles[y][le_current_level->width] = (unsigned char) '\0'; + le_current_level->tiles[y] = (unsigned int*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned int)); + le_current_level->tiles[y][le_current_level->width] = (unsigned int) '\0'; } } else if(le_current_level->width > i) { for(y = 0; y < 15; ++y) { - le_current_level->tiles[y] = (unsigned char*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned char)); + le_current_level->tiles[y] = (unsigned int*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned int)); for(j = 0; j < le_current_level->width - i; ++j) - le_current_level->tiles[y][i+j] = (unsigned char) '.'; - le_current_level->tiles[y][le_current_level->width] = (unsigned char) '\0'; + le_current_level->tiles[y][i+j] = (unsigned int) '.'; + le_current_level->tiles[y][le_current_level->width] = (unsigned int) '\0'; } } le_current_level->time_left = atoi(level_settings_menu.item[7].input); @@ -693,13 +649,9 @@ void apply_level_settings_menu() void save_subset_settings_menu() { - free(le_level_subset.title); - le_level_subset.title = (char*) malloc(sizeof(char)*(strlen(subset_settings_menu.item[2].input)+1)); - strcpy(le_level_subset.title,subset_settings_menu.item[2].input); - free(le_level_subset.description); - le_level_subset.description = (char*) malloc(sizeof(char)*(strlen(subset_settings_menu.item[3].input)+1)); - strcpy(le_level_subset.description,subset_settings_menu.item[3].input); - subset_save(&le_level_subset); + le_level_subset.title = subset_settings_menu.item[2].input; + le_level_subset.description = subset_settings_menu.item[3].input; + le_level_subset.save(); } void le_goto_level(int levelnb) @@ -708,9 +660,9 @@ void le_goto_level(int levelnb) arrays_init(); level_free(le_current_level); - if(level_load(le_current_level, le_level_subset.name, levelnb) != 0) + if(level_load(le_current_level, le_level_subset.name.c_str(), levelnb) != 0) { - level_load(le_current_level, le_level_subset.name, le_level); + level_load(le_current_level, le_level_subset.name.c_str(), le_level); } else { @@ -719,7 +671,7 @@ void le_goto_level(int levelnb) le_set_defaults(); - le_update_buttons(le_current_level->theme); + le_update_buttons(le_current_level->theme.c_str()); level_free_gfx(); level_load_gfx(le_current_level); @@ -866,7 +818,6 @@ void le_drawinterface() void le_drawlevel() { int y,x,i,s; - static char str[LEVEL_NAME_MAX]; /* Draw the real background */ if(le_current_level->bkgd_image[0] != '\0') @@ -1098,7 +1049,7 @@ void le_checkevents() le_testlevel(); button_event(&le_save_level_bt,&event); if(button_get_state(&le_save_level_bt) == BN_CLICKED) - level_save(le_current_level,le_level_subset.name,le_level); + level_save(le_current_level,le_level_subset.name.c_str(),le_level); button_event(&le_next_level_bt,&event); if(button_get_state(&le_next_level_bt) == BN_CLICKED) { @@ -1125,14 +1076,16 @@ void le_checkevents() switch(event.key.keysym.sym) { case SDLK_y: - le_default_level(&new_lev); - level_save(&new_lev,le_level_subset.name,++le_level); + level_default(&new_lev); + level_save(&new_lev,le_level_subset.name.c_str(),++le_level); le_level_subset.levels = le_level; le_goto_level(le_level); d = 1; break; case SDLK_n: d = 1; + break; + default: break; } break; @@ -1326,7 +1279,6 @@ void le_checkevents() void le_highlight_selection() { - int x,y,i; int x1, x2, y1, y2; if(selection.x1 < selection.x2) @@ -1456,7 +1408,7 @@ void le_testlevel() void le_showhelp() { SDL_Event event; - int i, done; + unsigned int i, done; char *text[] = { " - This is SuperTux's built-in level editor -", "It has been designed to be light and easy to use from the start.", diff --git a/src/lispreader.cpp b/src/lispreader.cpp index c1145cc6e..8a64fc25d 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -568,7 +568,8 @@ _compile_pattern (lisp_object_t **obj, int *index) int type; int i; lisp_object_t *pattern; - + type = -1; + if (lisp_type(lisp_car(*obj)) != LISP_TYPE_SYMBOL) return 0; @@ -1075,12 +1076,29 @@ LispReader::read_int_vector (const char* name, std::vector* vec) } bool +LispReader::read_char_vector (const char* name, std::vector* vec) +{ + lisp_object_t* obj = search_for (name); + if (obj) + { + while(!lisp_nil_p(obj)) + { + vec->push_back(*lisp_string(lisp_car(obj))); + obj = lisp_cdr(obj); + } + return true; + } + return false; +} + +bool LispReader::read_string (const char* name, std::string* str) { lisp_object_t* obj = search_for (name); if (obj) { - *str = lisp_string(lisp_car(obj)); + + *str = lisp_string(lisp_car(obj)); return true; } return false; diff --git a/src/lispreader.h b/src/lispreader.h index ddf5eec1c..28d1a2083 100644 --- a/src/lispreader.h +++ b/src/lispreader.h @@ -167,6 +167,7 @@ class LispReader LispReader (lisp_object_t* l); bool read_int_vector (const char* name, std::vector* vec); + bool read_char_vector (const char* name, std::vector* vec); bool read_string (const char* name, std::string* str); bool read_int (const char* name, int* i); bool read_float (const char* name, float* f); diff --git a/src/menu.cpp b/src/menu.cpp index df4dc7d7d..96ce85079 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -80,7 +80,7 @@ menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* ta return pnew_item; } -void menu_item_change_text(menu_item_type* pmenu_item, char *text) +void menu_item_change_text(menu_item_type* pmenu_item,const char *text) { if(text) { @@ -89,7 +89,7 @@ void menu_item_change_text(menu_item_type* pmenu_item, char *text) strcpy(pmenu_item->text,text); } } -void menu_item_change_input(menu_item_type* pmenu_item, char *text) +void menu_item_change_input(menu_item_type* pmenu_item,const char *text) { if(text) { diff --git a/src/menu.h b/src/menu.h index 0274e35c0..e5bbdba82 100644 --- a/src/menu.h +++ b/src/menu.h @@ -30,8 +30,8 @@ typedef struct menu_item_type menu_item_type; menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* target_menu); -void menu_item_change_text(menu_item_type* pmenu_item, char *text); -void menu_item_change_input(menu_item_type* pmenu_item, char *text); +void menu_item_change_text(menu_item_type* pmenu_item, const char *text); +void menu_item_change_input(menu_item_type* pmenu_item, const char *text); typedef struct menu_type { diff --git a/src/physic.cpp b/src/physic.cpp index f95c923d7..0f6fddeb3 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -64,6 +64,8 @@ float physic_get_velocity(physic_type* pphysic) return - (pphysic->start_vy - gravity* ((float)(st_get_ticks() - pphysic->start_time))/1000.); else if(pphysic->state == PH_HA) return - (pphysic->start_vx - pphysic->acceleration * ((float)(st_get_ticks() - pphysic->start_time))/1000.); + else + return 0; } float physic_get_max_distance(physic_type* pphysic) diff --git a/src/player.cpp b/src/player.cpp index 3d5e05774..fc119e1ce 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -133,7 +133,7 @@ void player_level_begin(player_type* pplayer) void player_action(player_type* pplayer) { - int i, jumped_in_solid; + int jumped_in_solid; jumped_in_solid = NO; /* --- HANDLE TUX! --- */ @@ -461,7 +461,7 @@ void player_handle_vertical_input(player_type *pplayer) if (player_on_ground(pplayer)) { physic_init(&pplayer->vphysic); - pplayer->jumping == NO; + pplayer->jumping = NO; } else { diff --git a/src/setup.cpp b/src/setup.cpp index 45fd99bb9..e932d80e0 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -43,7 +43,7 @@ void seticon(void); void usage(char * prog, int ret); /* Does the given file exist and is it accessible? */ -int faccessible(char *filename) +int faccessible(const char *filename) { struct stat filestat; if (stat(filename, &filestat) == -1) @@ -60,7 +60,7 @@ int faccessible(char *filename) } /* Can we write to this location? */ -int fwriteable(char *filename) +int fwriteable(const char *filename) { FILE* fi; fi = fopen(filename, "wa"); @@ -72,7 +72,7 @@ int fwriteable(char *filename) } /* Makes sure a directory is created in either the SuperTux base directory or the SuperTux base directory.*/ -int fcreatedir(char* relative_dir) +int fcreatedir(const char* relative_dir) { char path[1024]; snprintf(path, 1024, "%s/%s/", st_dir, relative_dir); @@ -97,11 +97,10 @@ int fcreatedir(char* relative_dir) /* Get all names of sub-directories in a certain directory. */ /* Returns the number of sub-directories found. */ /* Note: The user has to free the allocated space. */ -string_list_type dsubdirs(char *rel_path, char* expected_file) +string_list_type dsubdirs(const char *rel_path,const char* expected_file) { DIR *dirStructP; struct dirent *direntp; - int i = 0; string_list_type sdirs; char filename[1024]; char path[1024]; @@ -168,13 +167,11 @@ string_list_type dsubdirs(char *rel_path, char* expected_file) return sdirs; } -string_list_type dfiles(char *rel_path, char* glob, char* exception_str) +string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str) { DIR *dirStructP; struct dirent *direntp; - int i = 0; string_list_type sdirs; - char filename[1024]; char path[1024]; string_list_init(&sdirs); @@ -766,7 +763,7 @@ void st_shutdown(void) /* --- ABORT! --- */ -void st_abort(char * reason, char * details) +void st_abort(const char * reason,const char * details) { fprintf(stderr, "\nError: %s\n%s\n\n", reason, details); st_shutdown(); diff --git a/src/setup.h b/src/setup.h index 9e2ff62a4..cc2b68da3 100644 --- a/src/setup.h +++ b/src/setup.h @@ -17,11 +17,11 @@ #include "sound.h" #include "type.h" -int faccessible(char *filename); -int fcreatedir(char* relative_dir); -int fwriteable(char *filename); -string_list_type dsubdirs(char *rel_path, char* expected_file); -string_list_type dfiles(char *rel_path, char* glob, char* exception_str); +int faccessible(const char *filename); +int fcreatedir(const char* relative_dir); +int fwriteable(const char *filename); +string_list_type dsubdirs(const char *rel_path, const char* expected_file); +string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str); void free_strings(char **strings, int num); void st_directory_setup(void); void st_general_setup(void); @@ -32,7 +32,7 @@ void st_audio_setup(void); void st_joystick_setup(void); void st_shutdown(void); void st_menu(void); -void st_abort(char * reason, char * details); +void st_abort( const char * reason, const char * details); void process_options_menu(void); void process_save_load_game_menu(int save); void update_load_save_game_menu(menu_type* pmenu, int load); diff --git a/src/text.cpp b/src/text.cpp index 666425855..c17d12908 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -17,9 +17,8 @@ #include "screen.h" #include "text.h" -void text_load(text_type* ptext, char* file, int kind, int w, int h) +void text_load(text_type* ptext,const char* file, int kind, int w, int h) { - int x, y; int mx, my; SDL_Surface *conv; int pixels; @@ -62,7 +61,7 @@ void text_load(text_type* ptext, char* file, int kind, int w, int h) SDL_FreeSurface(conv); } -void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int update) +void text_draw(text_type* ptext,const char* text, int x, int y, int shadowsize, int update) { if(text != NULL) { @@ -73,7 +72,7 @@ void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int u } } -void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x, int y, int update) +void text_draw_chars(text_type* ptext, texture_type* pchars,const char* text, int x, int y, int update) { int i,j,len; int w, h; @@ -116,7 +115,7 @@ void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x, } } -void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int valign, int shadowsize, int update) +void text_drawf(text_type* ptext,const char* text, int x, int y, int halign, int valign, int shadowsize, int update) { if(text != NULL) { @@ -136,7 +135,6 @@ void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int vali void text_free(text_type* ptext) { - int c; if(ptext->kind == TEXT_TEXT) texture_free(&ptext->chars); else if(ptext->kind == TEXT_NUM) @@ -145,7 +143,7 @@ void text_free(text_type* ptext) /* --- ERASE TEXT: --- */ -void erasetext(text_type* ptext, char * text, int x, int y, texture_type * ptexture, int update, int shadowsize) +void erasetext(text_type* ptext,const char * text, int x, int y, texture_type * ptexture, int update, int shadowsize) { SDL_Rect dest; @@ -167,7 +165,7 @@ void erasetext(text_type* ptext, char * text, int x, int y, texture_type * ptext /* --- ERASE CENTERED TEXT: --- */ -void erasecenteredtext(text_type* ptext, char * text, int y, texture_type * ptexture, int update, int shadowsize) +void erasecenteredtext(text_type* ptext,const char * text, int y, texture_type * ptexture, int update, int shadowsize) { erasetext(ptext, text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize); } diff --git a/src/text.h b/src/text.h index fcde8f66a..b09004b9f 100644 --- a/src/text.h +++ b/src/text.h @@ -42,13 +42,13 @@ enum { A_NONE }; -void text_load(text_type* ptext, char* file, int kind, int w, int h); -void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int update); -void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x, int y, int update); -void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int valign, int shadowsize, int update); +void text_load(text_type* ptext, const char* file, int kind, int w, int h); +void text_draw(text_type* ptext, const char* text, int x, int y, int shadowsize, int update); +void text_draw_chars(text_type* ptext, texture_type* pchars, const char* text, int x, int y, int update); +void text_drawf(text_type* ptext, const char* text, int x, int y, int halign, int valign, int shadowsize, int update); void text_free(text_type* ptext); -void erasetext(text_type* ptext, char * text, int x, int y, texture_type * surf, int update, int shadowsize); -void erasecenteredtext(text_type* ptext, char * text, int y, texture_type * surf, int update, int shadowsize); +void erasetext(text_type* ptext, const char * text, int x, int y, texture_type * surf, int update, int shadowsize); +void erasecenteredtext(text_type* ptext, const char * text, int y, texture_type * surf, int update, int shadowsize); #endif /*SUPERTUX_TEXT_H*/ diff --git a/src/texture.cpp b/src/texture.cpp index 05c3d3423..b13b463f2 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -17,8 +17,8 @@ #include "setup.h" #include "texture.h" -void (*texture_load) (texture_type* ptexture, char * file, int use_alpha); -void (*texture_load_part) (texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); +void (*texture_load) (texture_type* ptexture,const char * file, int use_alpha); +void (*texture_load_part) (texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha); void (*texture_free) (texture_type* ptexture); void (*texture_draw) (texture_type* ptexture, float x, float y, int update); void (*texture_draw_bg) (texture_type* ptexture, int update); @@ -58,13 +58,13 @@ void texture_setup(void) } #ifndef NOOPENGL -void texture_load_gl(texture_type* ptexture, char * file, int use_alpha) +void texture_load_gl(texture_type* ptexture,const char * file, int use_alpha) { texture_load_sdl(ptexture,file,use_alpha); texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); } -void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha) +void texture_load_part_gl(texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha) { texture_load_part_sdl(ptexture,file,x,y,w,h,use_alpha); texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); @@ -218,7 +218,7 @@ float ph = power_of_two(ptexture->h); } #endif -void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha) +void texture_load_sdl(texture_type* ptexture,const char * file, int use_alpha) { SDL_Surface * temp; @@ -245,7 +245,7 @@ void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha) } -void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha) +void texture_load_part_sdl(texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha) { SDL_Rect src; diff --git a/src/texture.h b/src/texture.h index 820a75b8e..2fcc5a103 100644 --- a/src/texture.h +++ b/src/texture.h @@ -28,22 +28,22 @@ typedef struct texture_type } texture_type; void texture_setup(void); -extern void (*texture_load) (texture_type* ptexture, char * file, int use_alpha); -extern void (*texture_load_part) (texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); +extern void (*texture_load) (texture_type* ptexture,const char * file, int use_alpha); +extern void (*texture_load_part) (texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha); extern void (*texture_free) (texture_type* ptexture); extern void (*texture_draw) (texture_type* ptexture, float x, float y, int update); extern void (*texture_draw_bg) (texture_type* ptexture, int update); extern void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update); -void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha); -void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); +void texture_load_sdl(texture_type* ptexture,const char * file, int use_alpha); +void texture_load_part_sdl(texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha); void texture_free_sdl(texture_type* ptexture); void texture_draw_sdl(texture_type* ptexture, float x, float y, int update); void texture_draw_bg_sdl(texture_type* ptexture, int update); void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update); void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha); #ifndef NOOPENGL -void texture_load_gl(texture_type* ptexture, char * file, int use_alpha); -void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha); +void texture_load_gl(texture_type* ptexture,const char * file, int use_alpha); +void texture_load_part_gl(texture_type* ptexture,const char * file, int x, int y, int w, int h, int use_alpha); void texture_free_gl(texture_type* ptexture); void texture_draw_gl(texture_type* ptexture, float x, float y, int update); void texture_draw_bg_gl(texture_type* ptexture, int update); diff --git a/src/timer.cpp b/src/timer.cpp index 25a63a37a..bff15a944 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -96,7 +96,7 @@ int timer_get_gone(timer_type* ptimer) return (ptimer->get_ticks() - ptimer->time); } -int timer_fwrite(timer_type* ptimer, FILE* fi) +void timer_fwrite(timer_type* ptimer, FILE* fi) { unsigned int diff_ticks; int tick_mode; @@ -114,7 +114,7 @@ int timer_fwrite(timer_type* ptimer, FILE* fi) fwrite(&tick_mode,sizeof(unsigned int),1,fi); } -int timer_fread(timer_type* ptimer, FILE* fi) +void timer_fread(timer_type* ptimer, FILE* fi) { unsigned int diff_ticks; int tick_mode; diff --git a/src/timer.h b/src/timer.h index f2f18235d..146b76130 100644 --- a/src/timer.h +++ b/src/timer.h @@ -50,8 +50,8 @@ int timer_started(timer_type* ptimer); ======================================================================*/ int timer_get_left(timer_type* ptimer); int timer_get_gone(timer_type* ptimer); -int timer_fwrite(timer_type* ptimer, FILE* fi); -int timer_fread(timer_type* ptimer, FILE* fi); +void timer_fwrite(timer_type* ptimer, FILE* fi); +void timer_fread(timer_type* ptimer, FILE* fi); #endif /*SUPERTUX_TIMER_H*/ diff --git a/src/title.cpp b/src/title.cpp index ba6e6c0ca..34af37351 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -72,8 +72,6 @@ int title(void) st_subset subset; level_subsets = dsubdirs("/levels", "info"); - subset_init(&subset); - /* Reset menu variables */ menu_reset(); menu_set_current(&main_menu); @@ -167,7 +165,7 @@ int title(void) i = 0; if(level_subsets.num_items != 0) { - subset_load(&subset,level_subsets.item[0]); + subset.load(level_subsets.item[0]); while(!done) { texture_draw(&img_choose_subset,(screen->w - img_choose_subset.w) / 2, 0, NO_UPDATE); @@ -177,12 +175,12 @@ int title(void) if(level_subsets.num_items > 1) { if(i > 0) - texture_draw(&arrow_left,(screen->w / 2) - ((strlen(subset.title)+2)*16)/2,20,NO_UPDATE); + texture_draw(&arrow_left,(screen->w / 2) - ((subset.title.length()+2)*16)/2,20,NO_UPDATE); if(i < level_subsets.num_items-1) - texture_draw(&arrow_right,(screen->w / 2) + ((strlen(subset.title))*16)/2,20,NO_UPDATE); + texture_draw(&arrow_right,(screen->w / 2) + ((subset.description.length())*16)/2,20,NO_UPDATE); } - text_drawf(&gold_text, subset.title, 0, 20, A_HMIDDLE, A_TOP, 1, NO_UPDATE); - text_drawf(&gold_text, subset.description, 20, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); + text_drawf(&gold_text, subset.title.c_str(), 0, 20, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + text_drawf(&gold_text, subset.description.c_str(), 20, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); } updatescreen(); SDL_Delay(50); @@ -204,8 +202,8 @@ int title(void) if(i > 0) { --i; - subset_free(&subset); - subset_load(&subset,level_subsets.item[i]); + subset.free(); + subset.load(level_subsets.item[i]); } } else if(key == SDLK_RIGHT) @@ -213,15 +211,15 @@ int title(void) if(i < level_subsets.num_items -1) { ++i; - subset_free(&subset); - subset_load(&subset,level_subsets.item[i]); + subset.free(); + subset.load(level_subsets.item[i]); } } else if(key == SDLK_SPACE || key == SDLK_RETURN) { done = YES; - quit = gameloop(subset.name,1,ST_GL_PLAY); - subset_free(&subset); + quit = gameloop(subset.name.c_str(),1,ST_GL_PLAY); + subset.free(); } else if(key == SDLK_ESCAPE) { @@ -304,12 +302,12 @@ void display_credits() } fclose(fi); } - else + else { - string_list_add_item(&names,"Credits were not found!"); - string_list_add_item(&names,"Shame on the guy, who"); - string_list_add_item(&names,"forgot to include them"); - string_list_add_item(&names,"in your SuperTux distribution."); + string_list_add_item(&names,"Credits were not found!"); + string_list_add_item(&names,"Shame on the guy, who"); + string_list_add_item(&names,"forgot to include them"); + string_list_add_item(&names,"in your SuperTux distribution."); } @@ -387,8 +385,8 @@ void display_credits() text_drawf(&blue_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); } } - - + + texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130, NO_UPDATE); flipscreen(); diff --git a/src/type.cpp b/src/type.cpp index 3b0e1a453..52b44be16 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -38,7 +38,7 @@ char* string_list_active(string_list_type* pstring_list) return ""; } -void string_list_add_item(string_list_type* pstring_list, char* str) +void string_list_add_item(string_list_type* pstring_list,const char* str) { char *pnew_string; pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1)); @@ -58,7 +58,7 @@ void string_list_copy(string_list_type* pstring_list, string_list_type pstring_l string_list_add_item(pstring_list,pstring_list_orig.item[i]); } -int string_list_find(string_list_type* pstring_list, char* str) +int string_list_find(string_list_type* pstring_list,const char* str) { int i; for(i = 0; i < pstring_list->num_items; ++i) @@ -74,7 +74,6 @@ int string_list_find(string_list_type* pstring_list, char* str) void string_list_sort(string_list_type* pstring_list) { int i,j,y; - short int sorter[pstring_list->num_items]; for(j = 0; j < pstring_list->num_items; ++j) for(i = 0; i < pstring_list->num_items-1; ++i) diff --git a/src/type.h b/src/type.h index cde7d783a..daaba7ae7 100644 --- a/src/type.h +++ b/src/type.h @@ -41,9 +41,9 @@ string_list_type; void string_list_init(string_list_type* pstring_list); char* string_list_active(string_list_type* pstring_list); void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); -int string_list_find(string_list_type* pstring_list, char* str); +int string_list_find(string_list_type* pstring_list, const char* str); void string_list_sort(string_list_type* pstring_list); -void string_list_add_item(string_list_type* pstring_list, char* str); +void string_list_add_item(string_list_type* pstring_list, const char* str); void string_list_free(string_list_type* pstring_list); #endif /*SUPERTUX_TYPE_H*/ -- 2.11.0