Move MameNameMap out of the source and into mamenames.xml

This commit is contained in:
Tomas Jakobsson 2018-02-09 18:23:58 +01:00
parent 4d732a448e
commit 3f3e1ceb16
10 changed files with 121908 additions and 30510 deletions

View file

@ -61,7 +61,6 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/FileSorts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNameMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MetaData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/PlatformId.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ScraperCmdLine.cpp

View file

@ -8,6 +8,7 @@
#include "FileFilterIndex.h"
#include "FileSorts.h"
#include "Log.h"
#include "MameNames.h"
#include "platform.h"
#include "SystemData.h"
#include "VolumeControl.h"
@ -38,7 +39,7 @@ std::string FileData::getDisplayName() const
{
std::string stem = Utils::FileSystem::getStem(mPath);
if(mSystem && mSystem->hasPlatformId(PlatformIds::ARCADE) || mSystem->hasPlatformId(PlatformIds::NEOGEO))
stem = PlatformIds::mameTitleSearch(stem.c_str());
stem = MameNames::getInstance()->getRealName(stem);
return stem;
}

File diff suppressed because it is too large Load diff

View file

@ -94,53 +94,4 @@ namespace PlatformIds
{
return PlatformNames[id];
}
int getMameTitleCount()
{
const char** mameNames = mameNameToRealName;
int count = 0;
while (*mameNames != NULL)
{
mameNames += 2;
count++;
}
return count;
}
const char* mameTitleSearch(const char* from)
{
// The start and end index range from [0, number of roms]
int iStart = 0;
static int mameCount = getMameTitleCount();
int iEnd = mameCount;
while (iStart < iEnd)
{
// The middle entry is halfway between the start and end index
const int iMiddle = (iStart + iEnd) / 2;
// mameNameToRealName contains 2 sequential entries for every entry, so the indexes look like this:
// 0: key, value,
// 2: key, value,
// 4: key, value
// This means that there are twice as many indexes as there are numbers of ROMs. So to get the
// iMiddle'th entry, we need to multiply by 2 because iMiddle goes from [0, number of roms].
const int iKey = iMiddle * 2;
const int comp = strcmp(mameNameToRealName[iKey], from);
if (comp < 0)
{
// Remember, iMiddle ranges from [0, number of roms] so we only increment by 1
iStart = iMiddle + 1;
}
else if (comp > 0)
{
iEnd = iMiddle;
}
// The Key was found, now return the Value
else return mameNameToRealName[iKey + 1];
}
return from;
}
}

View file

@ -77,13 +77,6 @@ namespace PlatformIds
PlatformId getPlatformId(const char* str);
const char* getPlatformName(PlatformId id);
// Get the number of Mame titles in the mameNameToRealName array
// Should only run this once and store in a static or cached variable
int getMameTitleCount();
// Perform a binary search for a game title given a rom name
const char* mameTitleSearch(const char* from);
}
#endif // ES_APP_PLATFORM_ID_H

View file

@ -9,6 +9,7 @@
#include "EmulationStation.h"
#include "InputManager.h"
#include "Log.h"
#include "MameNames.h"
#include "platform.h"
#include "PowerSaver.h"
#include "ScraperCmdLine.h"
@ -282,6 +283,7 @@ int main(int argc, char* argv[])
PowerSaver::init();
ViewController::init(&window);
CollectionSystemManager::init(&window);
MameNames::init();
window.pushGui(ViewController::get());
if(!scrape_cmdline)
@ -409,6 +411,7 @@ int main(int argc, char* argv[])
delete window.peekGui();
window.deinit();
MameNames::deinit();
CollectionSystemManager::deinit();
SystemData::deleteSystems();

View file

@ -11,6 +11,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.h
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.h
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNames.h
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.h
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer.h
@ -84,6 +85,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNames.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp

85
es-core/src/MameNames.cpp Normal file
View file

@ -0,0 +1,85 @@
#include "MameNames.h"
#include "resources/ResourceManager.h"
#include "utils/FileSystemUtil.h"
#include "Log.h"
#include <pugixml/src/pugixml.hpp>
#include <string.h>
MameNames* MameNames::sInstance = nullptr;
void MameNames::init()
{
if(!sInstance)
sInstance = new MameNames();
} // init
void MameNames::deinit()
{
if(sInstance)
{
delete sInstance;
sInstance = nullptr;
}
} // deinit
MameNames* MameNames::getInstance()
{
if(!sInstance)
sInstance = new MameNames();
return sInstance;
} // getInstance
MameNames::MameNames()
{
std::string xmlpath = ResourceManager::getInstance()->getResourcePath(":/mamenames.xml");
if(!Utils::FileSystem::exists(xmlpath))
return;
LOG(LogInfo) << "Parsing XML file \"" << xmlpath << "\"...";
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(xmlpath.c_str());
if(!result)
{
LOG(LogError) << "Error parsing XML file \"" << xmlpath << "\"!\n " << result.description();
return;
}
for(pugi::xml_node gameNode = doc.child("game"); gameNode; gameNode = gameNode.next_sibling("game"))
{
NamePair namePair = { gameNode.child("mamename").text().get(), gameNode.child("realname").text().get() };
names.push_back(namePair);
}
} // MameNames
MameNames::~MameNames()
{
} // ~MameNames
std::string MameNames::getRealName(const std::string& _mameName)
{
size_t start = 0;
size_t end = names.size();
while(start < end)
{
const size_t index = (start + end) / 2;
const int compare = strcmp(names[index].mameName.c_str(), _mameName.c_str());
if(compare < 0) start = index + 1;
else if( compare > 0) end = index;
else return names[index].realName;
}
return _mameName;
} // getRealName

38
es-core/src/MameNames.h Normal file
View file

@ -0,0 +1,38 @@
#pragma once
#ifndef ES_CORE_MAMENAMES_H
#define ES_CORE_MAMENAMES_H
#include <string>
#include <vector>
namespace CEC { class ICECAdapter; }
class MameNames
{
public:
static void init ();
static void deinit ();
static MameNames* getInstance();
std::string getRealName(const std::string& _mameName);
private:
struct NamePair
{
std::string mameName;
std::string realName;
};
typedef std::vector<NamePair> namePairVector;
MameNames();
~MameNames();
static MameNames* sInstance;
namePairVector names;
}; // MameNames
#endif // ES_CORE_MAMENAMES_H

121778
resources/mamenames.xml Normal file

File diff suppressed because it is too large Load diff