libretro: handle m3u format as gamepath.
Implement retro_set_initial_image. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
30dbfad59c
commit
02740cee80
5 changed files with 78 additions and 18 deletions
|
@ -7,6 +7,8 @@
|
|||
#include "Disk.h"
|
||||
#include "Harddisk.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace ra2
|
||||
{
|
||||
|
||||
|
@ -17,11 +19,6 @@ namespace ra2
|
|||
|
||||
bool DiskControl::insertDisk(const std::string & filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (insertFloppyDisk(filename))
|
||||
{
|
||||
myIndex = 0;
|
||||
|
@ -34,6 +31,45 @@ namespace ra2
|
|||
return insertHardDisk(filename);
|
||||
}
|
||||
|
||||
bool DiskControl::insertPlaylist(const std::string & filename)
|
||||
{
|
||||
std::ifstream playlist(filename);
|
||||
if (!playlist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myImages.clear();
|
||||
|
||||
std::string line;
|
||||
while (std::getline(playlist, line))
|
||||
{
|
||||
// should we trim initial spaces?
|
||||
if (!line.empty() && line[0] != '#')
|
||||
{
|
||||
myImages.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
// if we have an initial disk image, let's try to honour it
|
||||
if (!ourInitialPath.empty() && ourInitialIndex < myImages.size() && myImages[ourInitialIndex] == ourInitialPath)
|
||||
{
|
||||
myIndex = ourInitialIndex;
|
||||
// do we need to reset for next time?
|
||||
ourInitialPath.clear();
|
||||
ourInitialIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// insert the first image
|
||||
myIndex = 0;
|
||||
}
|
||||
|
||||
// this is safe even if myImages is empty
|
||||
myEjected = true;
|
||||
return setEjectedState(false);
|
||||
}
|
||||
|
||||
bool DiskControl::insertFloppyDisk(const std::string & filename) const
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
@ -206,4 +242,15 @@ namespace ra2
|
|||
}
|
||||
}
|
||||
|
||||
unsigned DiskControl::ourInitialIndex = 0;
|
||||
std::string DiskControl::ourInitialPath;
|
||||
void DiskControl::setInitialPath(unsigned index, const char *path)
|
||||
{
|
||||
if (path && *path)
|
||||
{
|
||||
ourInitialIndex = index;
|
||||
ourInitialPath = path;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,15 @@ namespace ra2
|
|||
bool removeImageIndex(size_t index);
|
||||
bool addImageIndex();
|
||||
|
||||
// these 2 functions update the images for the Disc Control Interface
|
||||
bool insertDisk(const std::string & filename);
|
||||
bool insertPlaylist(const std::string & filename);
|
||||
|
||||
bool getImagePath(unsigned index, char *path, size_t len) const;
|
||||
bool getImageLabel(unsigned index, char *label, size_t len) const;
|
||||
|
||||
static void setInitialPath(unsigned index, const char *path);
|
||||
|
||||
private:
|
||||
std::vector<std::string> myImages;
|
||||
|
||||
|
@ -36,6 +40,9 @@ namespace ra2
|
|||
bool insertHardDisk(const std::string & filename) const;
|
||||
|
||||
void checkState() const;
|
||||
|
||||
static unsigned ourInitialIndex;
|
||||
static std::string ourInitialPath;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -258,12 +258,6 @@ namespace ra2
|
|||
return myMouse[i].position;
|
||||
}
|
||||
|
||||
bool Game::loadGame(const std::string & path)
|
||||
{
|
||||
const bool ok = myDiskControl.insertDisk(path);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool Game::loadSnapshot(const std::string & path)
|
||||
{
|
||||
common2::setSnapshotFilename(path, true);
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace ra2
|
|||
Game();
|
||||
~Game();
|
||||
|
||||
bool loadGame(const std::string & path);
|
||||
bool loadSnapshot(const std::string & path);
|
||||
|
||||
void executeOneFrame();
|
||||
|
|
|
@ -85,8 +85,8 @@ namespace
|
|||
bool retro_set_initial_image(unsigned index, const char *path)
|
||||
{
|
||||
ra2::log_cb(RETRO_LOG_INFO, "RA2: %s (%d) = %s\n", __FUNCTION__, index, path);
|
||||
// I have not been able to trigger this yet.
|
||||
return false;
|
||||
ra2::DiskControl::setInitialPath(index, path);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool retro_get_image_path(unsigned index, char *path, size_t len)
|
||||
|
@ -304,16 +304,29 @@ bool retro_load_game(const retro_game_info *info)
|
|||
std::unique_ptr<ra2::Game> game(new ra2::Game());
|
||||
|
||||
const std::string snapshotEnding = ".aws.yaml";
|
||||
const std::string gamePath = info->path;
|
||||
const std::string playlistEnding = ".m3u";
|
||||
|
||||
bool ok;
|
||||
if (endsWith(gamePath, snapshotEnding))
|
||||
|
||||
if (info->path && *info->path)
|
||||
{
|
||||
ok = game->loadSnapshot(gamePath);
|
||||
const std::string gamePath = info->path;
|
||||
if (endsWith(gamePath, snapshotEnding))
|
||||
{
|
||||
ok = game->loadSnapshot(gamePath);
|
||||
}
|
||||
else if (endsWith(gamePath, playlistEnding))
|
||||
{
|
||||
ok = game->getDiskControl().insertPlaylist(gamePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = game->getDiskControl().insertDisk(gamePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = game->loadGame(gamePath);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
ra2::log_cb(RETRO_LOG_INFO, "Game path: %s -> %d\n", info->path, ok);
|
||||
|
|
Loading…
Add table
Reference in a new issue