Do not hardcode backdrop numbers and filenames. Allow all backdrop types to have
random variations, based on filename base. Hardcoded limits removed. Patch by stiv, modified by me. Closes ticket:4168master
parent
9a6fdec2b5
commit
8c0cb1bb23
|
@ -42,6 +42,7 @@
|
|||
#include "piematrix.h"
|
||||
#include "screen.h"
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/*
|
||||
* Local Variables
|
||||
|
@ -463,27 +464,19 @@ void pie_RenderRadar()
|
|||
radarGfx->draw();
|
||||
}
|
||||
|
||||
/// Load and display a random backdrop picture.
|
||||
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;
|
||||
case SCREEN_RANDOMBDROP:
|
||||
screen_SetRandomBackdrop("texpages/bdrops/", "backdrop");
|
||||
break;
|
||||
case SCREEN_MISSIONEND:
|
||||
screen_SetRandomBackdrop("textpages/bdrops/", "missionend");
|
||||
break;
|
||||
case SCREEN_CREDITS:
|
||||
screen_SetRandomBackdrop("texpages/bdrops/", "credits");
|
||||
break;
|
||||
}
|
||||
|
||||
screen_SetBackDropFromFile(backd);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,13 @@
|
|||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
//using namespace std;
|
||||
|
||||
/* global used to indicate preferred internal OpenGL format */
|
||||
int wz_texture_compression = 0;
|
||||
|
||||
|
@ -357,6 +364,32 @@ void screenShutDown(void)
|
|||
glErrors();
|
||||
}
|
||||
|
||||
/// 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 screen_SetBackDropFromFile(const char* filename)
|
||||
{
|
||||
backdropGfx->loadTexture(filename);
|
||||
|
|
|
@ -38,10 +38,13 @@
|
|||
|
||||
/* ------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
extern unsigned screenWidth;
|
||||
extern unsigned screenHeight;
|
||||
|
||||
/* backDrop */
|
||||
void screen_SetRandomBackdrop( const char* dirname,
|
||||
const char* basename );
|
||||
extern void screen_SetBackDropFromFile(const char* filename);
|
||||
extern void screen_StopBackDrop(void);
|
||||
extern void screen_RestartBackDrop(void);
|
||||
|
|
Loading…
Reference in New Issue