/// Display a random backdrop from files in dirname starting with basename. /// dirname must have a trailing slash. void screen_SetRandomBackdrop(const char *dirname, const char *basename) { std::vector<std::string> names; // vector to hold the strings we want char **rc = PHYSFS_enumerateFiles(dirname); // all the files in dirname // Walk thru the files in our dir, adding the ones that start with basename to our vector of strings size_t len = strlen(basename); for (char **i = rc; *i != NULL; i++) { // does our filename start with basename? if (!strncmp(*i, basename, len)) { names.push_back(*i); } } PHYSFS_freeList(rc); // pick a random name from our vector of names int ran = rand() % names.size(); std::string full_path = std::string(dirname) + names[ran]; screen_SetBackDropFromFile(full_path.c_str()); }
void pie_LoadBackDrop(SCREENTYPE screenType) { char backd[128]; //randomly load in a backdrop piccy. srand( (unsigned)time(NULL) + 17 ); // Use offset since time alone doesn't work very well switch (screenType) { case SCREEN_RANDOMBDROP: snprintf(backd, sizeof(backd), "texpages/bdrops/backdrop%i.png", rand() % NUM_BACKDROPS); // Range: 0 to (NUM_BACKDROPS-1) break; case SCREEN_MISSIONEND: sstrcpy(backd, "texpages/bdrops/missionend.png"); break; case SCREEN_CREDITS: default: sstrcpy(backd, "texpages/bdrops/credits.png"); break; } screen_SetBackDropFromFile(backd); }