mirror of https://github.com/stella-emu/stella.git
added multiple image searching delay
This commit is contained in:
parent
40f472b913
commit
8f8efafd98
|
@ -475,6 +475,9 @@ void LauncherDialog::tick()
|
||||||
if(myPendingReload && myReloadTime < TimerManager::getTicks() / 1000)
|
if(myPendingReload && myReloadTime < TimerManager::getTicks() / 1000)
|
||||||
reload();
|
reload();
|
||||||
|
|
||||||
|
if(myPendingRomInfo && myRomInfoTime < TimerManager::getTicks() / 1000)
|
||||||
|
loadRomInfo(true);
|
||||||
|
|
||||||
Dialog::tick();
|
Dialog::tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,8 +551,10 @@ void LauncherDialog::updateUI()
|
||||||
<< (myShortCount ? " items" : " items found");
|
<< (myShortCount ? " items" : " items found");
|
||||||
myRomCount->setLabel(buf.str());
|
myRomCount->setLabel(buf.str());
|
||||||
|
|
||||||
// Update ROM info UI item
|
// Update ROM info UI item, delayed
|
||||||
loadRomInfo();
|
myRomInfoTime = TimerManager::getTicks() / 1000 + 250; // TODO: define delay
|
||||||
|
myPendingRomInfo = true;
|
||||||
|
loadRomInfo(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -668,18 +673,20 @@ void LauncherDialog::setRomInfoFont(const Common::Size& area)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void LauncherDialog::loadRomInfo()
|
void LauncherDialog::loadRomInfo(bool complete)
|
||||||
{
|
{
|
||||||
|
myPendingRomInfo = !complete;
|
||||||
|
|
||||||
if(!myRomImageWidget || !myROMInfoFont)
|
if(!myRomImageWidget || !myROMInfoFont)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const string& md5 = selectedRomMD5();
|
const string& md5 = selectedRomMD5();
|
||||||
if(md5 != EmptyString)
|
if(md5 != EmptyString)
|
||||||
{
|
{
|
||||||
myRomImageWidget->setProperties(currentNode(), md5);
|
myRomImageWidget->setProperties(currentNode(), md5, complete);
|
||||||
myRomInfoWidget->setProperties(currentNode(), md5);
|
myRomInfoWidget->setProperties(currentNode(), md5); // TODO: skip controller detector?
|
||||||
}
|
}
|
||||||
else
|
else if(!complete)
|
||||||
{
|
{
|
||||||
myRomImageWidget->clearProperties();
|
myRomImageWidget->clearProperties();
|
||||||
myRomInfoWidget->clearProperties();
|
myRomInfoWidget->clearProperties();
|
||||||
|
|
|
@ -147,7 +147,7 @@ class LauncherDialog : public Dialog, CommandSender
|
||||||
void setRomInfoFont(const Common::Size& area);
|
void setRomInfoFont(const Common::Size& area);
|
||||||
|
|
||||||
void loadRom();
|
void loadRom();
|
||||||
void loadRomInfo();
|
void loadRomInfo(bool complete);
|
||||||
void openSettings();
|
void openSettings();
|
||||||
void openGameProperties();
|
void openGameProperties();
|
||||||
void openContextMenu(int x = -1, int y = -1);
|
void openContextMenu(int x = -1, int y = -1);
|
||||||
|
@ -209,6 +209,8 @@ class LauncherDialog : public Dialog, CommandSender
|
||||||
bool myShortCount{false};
|
bool myShortCount{false};
|
||||||
bool myPendingReload{false};
|
bool myPendingReload{false};
|
||||||
uInt64 myReloadTime{0};
|
uInt64 myReloadTime{0};
|
||||||
|
bool myPendingRomInfo{false};
|
||||||
|
uInt64 myRomInfoTime{0};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kAllfilesCmd = 'lalf', // show all files (or ROMs only)
|
kAllfilesCmd = 'lalf', // show all files (or ROMs only)
|
||||||
|
|
|
@ -40,7 +40,7 @@ RomImageWidget::RomImageWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void RomImageWidget::setProperties(const FSNode& node, const string& md5)
|
void RomImageWidget::setProperties(const FSNode& node, const string& md5, bool complete)
|
||||||
{
|
{
|
||||||
myHaveProperties = true;
|
myHaveProperties = true;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void RomImageWidget::setProperties(const FSNode& node, const string& md5)
|
||||||
|
|
||||||
// Decide whether the information should be shown immediately
|
// Decide whether the information should be shown immediately
|
||||||
if(instance().eventHandler().state() == EventHandlerState::LAUNCHER)
|
if(instance().eventHandler().state() == EventHandlerState::LAUNCHER)
|
||||||
parseProperties(node);
|
parseProperties(node, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -74,11 +74,11 @@ void RomImageWidget::reloadProperties(const FSNode& node)
|
||||||
// by saving a different image or through a change in video renderer,
|
// by saving a different image or through a change in video renderer,
|
||||||
// so we reload the properties
|
// so we reload the properties
|
||||||
if(myHaveProperties)
|
if(myHaveProperties)
|
||||||
parseProperties(node);
|
parseProperties(node, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void RomImageWidget::parseProperties(const FSNode& node)
|
void RomImageWidget::parseProperties(const FSNode& node, bool complete)
|
||||||
{
|
{
|
||||||
if(myNavSurface == nullptr)
|
if(myNavSurface == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -123,17 +123,32 @@ void RomImageWidget::parseProperties(const FSNode& node)
|
||||||
myImageList.clear();
|
myImageList.clear();
|
||||||
myImageIdx = 0;
|
myImageIdx = 0;
|
||||||
|
|
||||||
// 1. Try to load snapshots by property name
|
if(complete)
|
||||||
getImageList(myProperties.get(PropType::Cart_Name));
|
{
|
||||||
// 2. Also try to load snapshot images by filename
|
// Try to load snapshots by property name and ROM file name
|
||||||
getImageList(node.getNameWithExt());
|
getImageList(myProperties.get(PropType::Cart_Name), node.getNameWithExt());
|
||||||
|
|
||||||
if(myImageList.size())
|
if(myImageList.size())
|
||||||
mySurfaceIsValid = loadPng(myImageList[0].getPath());
|
mySurfaceIsValid = loadPng(myImageList[0].getPath());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const string& path = instance().snapshotLoadDir().getPath();
|
||||||
|
string filename = path + myProperties.get(PropType::Cart_Name) + ".png";
|
||||||
|
|
||||||
|
mySurfaceIsValid = loadPng(filename);
|
||||||
|
if(!mySurfaceIsValid)
|
||||||
|
{
|
||||||
|
filename = path + node.getNameWithExt("png");
|
||||||
|
mySurfaceIsValid = loadPng(filename);
|
||||||
|
}
|
||||||
|
if(mySurfaceIsValid)
|
||||||
|
myImageList.emplace_back(filename);
|
||||||
|
}
|
||||||
|
|
||||||
if(!mySurfaceIsValid)
|
if(!mySurfaceIsValid)
|
||||||
{
|
{
|
||||||
// 3. If no ROM snapshots exist, try to load a default snapshot
|
// If no ROM snapshots exist, try to load a default snapshot
|
||||||
mySurfaceIsValid = loadPng(instance().snapshotLoadDir().getPath() + "default_snapshot.png");
|
mySurfaceIsValid = loadPng(instance().snapshotLoadDir().getPath() + "default_snapshot.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,14 +174,22 @@ bool RomImageWidget::changeImage(int direction)
|
||||||
|
|
||||||
#ifdef PNG_SUPPORT
|
#ifdef PNG_SUPPORT
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool RomImageWidget::getImageList(const string& filename)
|
bool RomImageWidget::getImageList(const string& propname, const string& filename)
|
||||||
{
|
{
|
||||||
const string pngName = filename + ".png";
|
// TODO: search for consecutive digits and letters instead of getChildren
|
||||||
|
//std::ifstream in(filename, std::ios_base::binary);
|
||||||
|
//if(!in.is_open())
|
||||||
|
// loadImageERROR("No snapshot found");
|
||||||
|
// or use a timer before updating the images
|
||||||
|
|
||||||
|
const string pngPropName = propname + ".png";
|
||||||
|
const string pngFileName = filename + ".png";
|
||||||
FSNode::NameFilter filter = ([&](const FSNode& node)
|
FSNode::NameFilter filter = ([&](const FSNode& node)
|
||||||
{
|
{
|
||||||
const string& nodeName = node.getName();
|
const string& nodeName = node.getName();
|
||||||
return (!node.isDirectory() &&
|
return (!node.isDirectory() &&
|
||||||
(nodeName == pngName ||
|
(nodeName == pngPropName || nodeName == pngFileName ||
|
||||||
|
(nodeName.find(propname + " #") == 0 && nodeName.find(".png") == nodeName.length() - 4) ||
|
||||||
(nodeName.find(filename + " #") == 0 && nodeName.find(".png") == nodeName.length() - 4)));
|
(nodeName.find(filename + " #") == 0 && nodeName.find(".png") == nodeName.length() - 4)));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,7 +36,7 @@ class RomImageWidget : public Widget, public CommandSender
|
||||||
return font.getFontHeight() * 9 / 8;
|
return font.getFontHeight() * 9 / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setProperties(const FSNode& node, const string& md5);
|
void setProperties(const FSNode& node, const string& md5, bool complete);
|
||||||
void clearProperties();
|
void clearProperties();
|
||||||
void reloadProperties(const FSNode& node);
|
void reloadProperties(const FSNode& node);
|
||||||
bool changeImage(int direction = 1);
|
bool changeImage(int direction = 1);
|
||||||
|
@ -49,9 +49,9 @@ class RomImageWidget : public Widget, public CommandSender
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseProperties(const FSNode& node);
|
void parseProperties(const FSNode& node, bool complete);
|
||||||
#ifdef PNG_SUPPORT
|
#ifdef PNG_SUPPORT
|
||||||
bool getImageList(const string& filename);
|
bool getImageList(const string& propname, const string& filename);
|
||||||
bool loadPng(const string& filename);
|
bool loadPng(const string& filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue