Author Topic: Random Loading Screens  (Read 1583 times)

ChupaReaper

  • Guest
Random Loading Screens
« on: 12 May 2011, 14:30:40 »
I think I've requested this before but couldn't find the topic to bump lol! Anyway, when loading a game it would be cool if a random loading screen per faction was used defined in the xml like this:
Code: [Select]
<loading-screen>
<background-image path="images/loading/loading_valkeries.png" />
<background-image path="images/loading/loading_blessings.png" />
<background-image path="images/loading/loading_unicorns.png" />
<background-image path="images/loading/loading_arix.png" />
<background-image path="images/loading/loading_wendigos.png" />
<background-image path="images/loading/loading_harpies.png" />
<background-image path="images/loading/loading_icegolems.png" />
<background-image path="images/loading/loading_frosttempests.png" />
</loading-screen>

As you can see, Malevoelnt Rising would make heavy use out of it! :D
Maybe this too: <loading-screen shuffle="true"> I will be having it random regardless but some people might not for whatever reason.
Also GAE should remember what screens have been used so it tries not to load the same one again by chance until all the others have been used, else there is a small possibility that someone will always see the same one, small but not impossible!
« Last Edit: 12 May 2011, 14:32:42 by ChupaReaper »

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Random Loading Screens
« Reply #1 on: 12 May 2011, 18:20:07 »
Full agreement. I will use this too, in Military. Shuffle would be unneccessary, in my opinion, as it should always randomly play.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

Zoythrus

  • Guest
Re: Random Loading Screens
« Reply #2 on: 12 May 2011, 18:24:31 »
Full agreement. I will use this too, in Military. Shuffle would be unneccessary, in my opinion, as it should always randomly play.

^this^

ChupaReaper

  • Guest
Re: Random Loading Screens
« Reply #3 on: 13 May 2011, 01:05:19 »
Would be nice if loading text could be added separate for different languages. So randomly pick a loading screen which has a language string bound to it that is shown with it. Scenarios could have their own strings and loading screens too.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Random Loading Screens
« Reply #4 on: 13 May 2011, 04:20:56 »
Would be nice if loading text could be added separate for different languages. So randomly pick a loading screen which has a language string bound to it that is shown with it. Scenarios could have their own strings and loading screens too.
Also in agreement, as people will without doubt use tips too. We'd probably have to specify a rectangular area where a textbox would be drawn.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

Snaips

  • Guest
Re: Random Loading Screens
« Reply #5 on: 15 November 2011, 10:59:57 »
Loads tips_en.txt in fraction lang folder  if present.

game.cpp modification
Code: [Select]
// ==================== init and load ====================

void GameState::load() {
GameSettings &gameSettings = g_simInterface.getGameSettings();
const string &mapName = gameSettings.getMapPath();
const string &tilesetName = gameSettings.getTilesetPath();
const string &techName = gameSettings.getTechPath();
const string &scenarioPath = gameSettings.getScenarioPath();
string scenarioName = basename(scenarioPath);
const string &thisFactionName = gameSettings.getFactionTypeName(gameSettings.getThisFactionIndex());

// determine loading screen settings:
// 1. check sceneraio if applicable
// 2. check faction
// 3. check tech
// 4. use defaults
ProgramLog &log = g_logger.getProgramLog();

if (!scenarioName.empty()
&& log.setupLoadingScreen(scenarioPath)) {
} else if (log.setupLoadingScreen(techName + "/factions/" + thisFactionName)) {
} else if (log.setupLoadingScreen(techName)) {
} else {
log.useLoadingScreenDefaults();
}

// maybe use config option instead - hailstone 01May2011
if (g_program.getMouseCursor().descType() == "ImageSetMouseCursor") {
ImageSetMouseCursor &mouse = static_cast<ImageSetMouseCursor&>(g_program.getMouseCursor());
// check for custom mouse (faction then tech)
if (mouse.loadMouse(techName + "/factions/" + thisFactionName)) {
} else if (mouse.loadMouse(techName)) {
} else {
// already using default
}
}

g_logger.getProgramLog().setProgressBar(true);
g_logger.getProgramLog().setState(Lang::getInstance().get("Loading"));
// overwrite subtitles
//if (scenarioName.empty()) {
//log.setSubtitle(formatString(mapName) + " - " +
// formatString(tilesetName) + " - " + formatString(techName));
//} else {
// log.setSubtitle(formatString(scenarioName));
//}

simInterface->loadWorld();

// finished loading
g_logger.getProgramLog().setProgressBar(false);
}

logger.cpp modification
Code: [Select]
/** Load the loading screen settings from xml
  * @return true if loaded successfully
  */
bool ProgramLog::setupLoadingScreen(const string &dir) {
string path = dir + "/" + basename(dir) + ".xml";

//open xml file
XmlTree xmlTree;
try {
xmlTree.load(path);
} catch (runtime_error e) {
g_logger.logXmlError(path, "File missing or wrongly named.");
return false; // bail
}
const XmlNode *rootNode;
try {
rootNode = xmlTree.getRootNode();
} catch (runtime_error e) {
g_logger.logXmlError(path, "File appears to lack contents.");
return false; // bail
}

const XmlNode *loadingScreenNode = rootNode->getChild("loading-screen", 0, false);

if (loadingScreenNode) {
// could randomly choose from multiple or choose
// based on resolution - hailstone 21Jan2011

// background texture
int x = loadingScreenNode->getChildCount();
int k = 0;

if (x!=1) {
int seed = int(Chrono::getCurMicros());
Random random(seed);
k = random.randRange(0, x - 1);
}

const XmlNode *backgroundImageNode = loadingScreenNode->getChild("background-image", k, true);

if (backgroundImageNode) {
// load background image from faction.xml
m_backgroundTexture = g_renderer.newTexture2D(ResourceScope::GLOBAL);
m_backgroundTexture->setMipmap(false);
m_backgroundTexture->getPixmap()->load(dir + "/" +
backgroundImageNode->getAttribute("path")->getValue());
try {
m_backgroundTexture->init(Texture::fBilinear);
} catch (...) {
m_backgroundTexture = Texture2D::defaultTexture;
}
}

// faction tips
string path = dir + "/lang/tips_" + g_lang.getLocale() + ".txt";
vector<string> Strings;
FileOps *f = g_fileFactory.getFileOps();
char *buf = 0;
try {
f->openRead(path.c_str());
int size = f->fileSize();
buf = new char[size + 1];
f->read(buf, size, 1);
buf[size] = '\0';
stringstream ss(buf);
delete [] buf;
buf = 0;
char buffer[1024];
while (!ss.eof()) {
ss.getline(buffer, 1023);
if (buffer[0] == ';' || buffer[0] == '\0' || buffer[0] == 10 || buffer[0] == 13) {
continue;
}
string str(buffer);
if (*(str.end() - 1) == 13) {
str = str.substr(0, str.size() - 1);
}
if (!str.empty()) {
Strings.push_back(str);
}
}
} catch (runtime_error &e) {
delete [] buf;
Strings.clear();
}
delete f;
// random tips selection
if(Strings.size()!=0){
int seed = int(Chrono::getCurMicros());
Random random(seed);
int k = random.randRange(0, Strings.size() - 1);
setSubtitle(Strings.at(k));
Strings.clear();
}

return true; // successfully using settings
}
return false;
}

Code: [Select]
void ProgramLog::renderLoadingScreen(){
g_renderer.reset2d();
g_renderer.clearBuffers();

const Font *normFont = g_widgetConfig.getMenuFont();
const Font *bigFont = g_widgetConfig.getTitleFont();

if (m_backgroundTexture) {
g_renderer.renderBackground(m_backgroundTexture);
}

Vec2i headerPos(g_metrics.getScreenW() / 4, 25 * g_metrics.getScreenH() / 100);
Vec4f colour(1.f);
g_renderer.renderText(state, bigFont, colour, headerPos.x, headerPos.y);
int yStart = headerPos.y + int(bigFont->getMetrics()->getHeight()) + 6;

if (loadingGame) {
int offset = 0;
int step = int(normFont->getMetrics()->getHeight()) + 4;
//for (Strings::reverse_iterator it = logLines.rbegin(); it != logLines.rend(); ++it) {
// colour.a = 1.f - float(offset) / float(logLineCount + 1);
// g_renderer.renderText(*it, normFont, colour, g_metrics.getScreenW() / 4,
// 30 * g_metrics.getScreenH() / 100 + offset * step);
// ++offset;
//}
colour.a = 1.f - float(offset);
string k = logLines.back();
g_renderer.renderText(k, normFont, colour, g_metrics.getScreenW() / 4,
30 * g_metrics.getScreenH() / 100 + offset * step);

g_renderer.renderText(subtitle, normFont, colour, g_metrics.getScreenW() / 4,
38 * g_metrics.getScreenH() / 100);

if (m_progressBar) {
Vec2i progBarPos = headerPos;
progBarPos.x += int(bigFont->getMetrics()->getTextDiminsions(state).w) + 20;
int w = g_metrics.getScreenW() / 4 * 3 - progBarPos.x;
int h = int(normFont->getMetrics()->getHeight() + 2.f);
g_renderer.renderProgressBar(m_progress, progBarPos.x, progBarPos.y, w, h, normFont);
}
} else {
g_renderer.renderText(current, normFont, colour, g_metrics.getScreenW() / 4,
38 * g_metrics.getScreenH() / 100);
}
g_renderer.swapBuffers();
}
« Last Edit: 18 November 2011, 14:12:15 by Snaips »

Coldfusionstorm

  • Golem
  • ******
  • Posts: 868
    • View Profile
Re: Random Loading Screens
« Reply #6 on: 15 November 2011, 11:08:00 »
I think I've requested this before but couldn't find the topic to bump lol! Anyway, when loading a game it would be cool if a random loading screen per faction was used defined in the xml like this:
Code: [Select]
<loading-screen>
<background-image path="images/loading/loading_valkeries.png" />
<background-image path="images/loading/loading_blessings.png" />
<background-image path="images/loading/loading_unicorns.png" />
<background-image path="images/loading/loading_arix.png" />
<background-image path="images/loading/loading_wendigos.png" />
<background-image path="images/loading/loading_harpies.png" />
<background-image path="images/loading/loading_icegolems.png" />
<background-image path="images/loading/loading_frosttempests.png" />
</loading-screen>

As you can see, Malevoelnt Rising would make heavy use out of it! :D
Maybe this too: <loading-screen shuffle="true"> I will be having it random regardless but some people might not for whatever reason.
Also GAE should remember what screens have been used so it tries not to load the same one again by chance until all the others have been used, else there is a small possibility that someone will always see the same one, small but not impossible!

Instead of this just make is so that if you define a single image you will get that image, but if you want to randomize you just pick a folder, like so

Code: [Select]

<loading-screen>
<background-image path="images/loading/loading_valkeries.png" />
</loading-screen>

Code: [Select]
<loading-screen>
<background-image path="images/random_images_folder" />
</loading-screen>

WiP Game developer.
I do danish translations.
"i break stuff"

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Random Loading Screens
« Reply #7 on: 15 November 2011, 21:52:55 »
Code: [Select]
/** Load the loading screen settings from xml
  * @return true if loaded successfully
  */
bool ProgramLog::setupLoadingScreen(const string &dir) {
string path = dir + "/" + basename(dir) + ".xml";

//open xml file
XmlTree xmlTree;
try {
xmlTree.load(path);
} catch (runtime_error e) {
g_logger.logXmlError(path, "File missing or wrongly named.");
return false; // bail
}
const XmlNode *rootNode;
try {
rootNode = xmlTree.getRootNode();
} catch (runtime_error e) {
g_logger.logXmlError(path, "File appears to lack contents.");
return false; // bail
}

const XmlNode *loadingScreenNode = rootNode->getChild("loading-screen", 0, false);

if (loadingScreenNode) {
// could randomly choose from multiple or choose
// based on resolution - hailstone 21Jan2011

// background texture
int x = loadingScreenNode->getChildCount();
int k = 0;

if (x!=1) {
int seed = int(Chrono::getCurMicros());
Random random(seed);
k = random.randRange(0, x - 1);
}

const XmlNode *backgroundImageNode = loadingScreenNode->getChild("background-image", k, true);

if (backgroundImageNode) {
// load background image from faction.xml
m_backgroundTexture = g_renderer.newTexture2D(ResourceScope::GLOBAL);
m_backgroundTexture->setMipmap(false);
m_backgroundTexture->getPixmap()->load(dir + "/" +
backgroundImageNode->getAttribute("path")->getValue());
try {
m_backgroundTexture->init(Texture::fBilinear);
} catch (...) {
m_backgroundTexture = Texture2D::defaultTexture;
}
}

// faction tips

return true; // successfully using settings
}
return false;
}
Nice job, and welcome, Snaips! I never tested it, but this was really needed, and hope that a GAE team member will be able to check and implement the code.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

Psychedelic_hands

  • Guest
Re: Random Loading Screens
« Reply #8 on: 18 November 2011, 06:50:04 »
Code: [Select]
/** Load the loading screen settings from xml
  * @return true if loaded successfully
  */
bool ProgramLog::setupLoadingScreen(const string &dir) {
string path = dir + "/" + basename(dir) + ".xml";

//open xml file
XmlTree xmlTree;
try {
xmlTree.load(path);
} catch (runtime_error e) {
g_logger.logXmlError(path, "File missing or wrongly named.");
return false; // bail
}
const XmlNode *rootNode;
try {
rootNode = xmlTree.getRootNode();
} catch (runtime_error e) {
g_logger.logXmlError(path, "File appears to lack contents.");
return false; // bail
}

const XmlNode *loadingScreenNode = rootNode->getChild("loading-screen", 0, false);

if (loadingScreenNode) {
// could randomly choose from multiple or choose
// based on resolution - hailstone 21Jan2011

// background texture
int x = loadingScreenNode->getChildCount();
int k = 0;

if (x!=1) {
int seed = int(Chrono::getCurMicros());
Random random(seed);
k = random.randRange(0, x - 1);
}

const XmlNode *backgroundImageNode = loadingScreenNode->getChild("background-image", k, true);

if (backgroundImageNode) {
// load background image from faction.xml
m_backgroundTexture = g_renderer.newTexture2D(ResourceScope::GLOBAL);
m_backgroundTexture->setMipmap(false);
m_backgroundTexture->getPixmap()->load(dir + "/" +
backgroundImageNode->getAttribute("path")->getValue());
try {
m_backgroundTexture->init(Texture::fBilinear);
} catch (...) {
m_backgroundTexture = Texture2D::defaultTexture;
}
}

// faction tips

return true; // successfully using settings
}
return false;
}

Cool! I don't know C++ well at all but it looks pretty good. Maybe a ticket should be made of this so it is not lost?

 

anything