Skip to content

Commit

Permalink
fixed multi rom load bug, moved to shared_ptr, cleaned settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavbh12 committed Feb 18, 2017
1 parent 38d86fa commit 1e6cf8b
Show file tree
Hide file tree
Showing 37 changed files with 360 additions and 1,240 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ if(APPLE)
endif()

if(WINDOWS OR MINGW)
list(APPEND SOURCES ${SOURCE_DIR}/os_dependent/SettingsWin32.cxx ${SOURCE_DIR}/os_dependent/OSystemWin32.cxx ${SOURCE_DIR}/os_dependent/FSNodeWin32.cxx)
list(APPEND SOURCES ${SOURCE_DIR}/os_dependent/FSNodeWin32.cxx)
else()
list(APPEND SOURCES ${SOURCE_DIR}/os_dependent/SettingsUNIX.cxx ${SOURCE_DIR}/os_dependent/RleSystemUNIX.cxx ${SOURCE_DIR}/os_dependent/FSNodePOSIX.cxx)
list(APPEND SOURCES ${SOURCE_DIR}/os_dependent/FSNodePOSIX.cxx)
endif()

if(UNIX)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self):
ds.spawn(['./copy_cores.sh'])
_build.build.run(self)

version = '1.1.0'
version = '1.1.1'
setup(name = 'rle_python_interface',
version=version,
description = 'Retro Learning Environment Python Interface based on Ben Goodrich\'s work',
Expand Down
2 changes: 1 addition & 1 deletion src/common/display_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace std;
using namespace rle;

#ifdef __USE_SDL
DisplayScreen::DisplayScreen(RetroAgent* rAgent ): manual_control_active(false), delay_msec(5), ragent(rAgent) {
DisplayScreen::DisplayScreen(pRetroAgent rAgent ): manual_control_active(false), delay_msec(5), ragent(rAgent) {

bpp = ragent->getBpp();
screen_height = ragent->getHeight();
Expand Down
8 changes: 4 additions & 4 deletions src/common/display_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace rle {

class DisplayScreen {
public:
// todo save RetroAgent as shared_ptr
DisplayScreen(RetroAgent* ragent );
// todo save RetroAgent as unique_ptr
DisplayScreen(pRetroAgent ragent );
virtual ~DisplayScreen();

// Displays the current frame buffer from the mediasource.
Expand Down Expand Up @@ -64,7 +64,7 @@ class DisplayScreen {
Uint32 last_frame_time;

Uint8 bpp;
RetroAgent* ragent;
pRetroAgent ragent;
};

} // namespace rle
Expand All @@ -74,7 +74,7 @@ namespace rle {
/** A dummy class that simply ignores display events. */
class DisplayScreen {
public:
DisplayScreen(RetroAgent* ragent) {}
DisplayScreen(pRetroAgent ragent) {}
void display_screen() {}
bool manual_control_engaged() { return false; }
Action getUserAction() { return JOYPAD_UNDEFINED; }
Expand Down
13 changes: 9 additions & 4 deletions src/environment/RetroAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ static void core_unload() {
// dlclose(RetroAgent::g_retro.handle);
}

RetroAgent::RetroAgent() : coreLoaded(false){
RetroAgent::RetroAgent() : coreLoaded(false), romLoaded(false){
agentNum = numAgents++;
RetroAgent::g_retro.initialized = false;
}
Expand All @@ -454,6 +454,9 @@ static void copyFile(string srcName, string dstName){
}

void RetroAgent::loadCore(const string& coreName){
if(coreLoaded){
unloadCore();
}
string suffix = ".so";
size_t start_pos = coreName.find(suffix);
if(start_pos == std::string::npos){
Expand Down Expand Up @@ -481,15 +484,20 @@ void RetroAgent::unloadCore(){
}

void RetroAgent::loadRom(const string& romName){
if(romLoaded){
unloadRom();
}
core_load_game(romName.c_str());
RetroAgent::g_retro.serializeSize = RetroAgent::g_retro.retro_serialize_size();
romLoaded = true;
}

void RetroAgent::unloadRom(){
if (RetroAgent::g_retro.initialized){
RetroAgent::g_retro.retro_unload_game();
RetroAgent::g_retro.initialized = false;
}
romLoaded = false;
}

void RetroAgent::run(){
Expand Down Expand Up @@ -543,9 +551,6 @@ void RetroAgent::SetActions(const Action& player_a_action, const Action& player_
g_retro.action_b = player_b_action;
}

void RetroAgent::updateScreen(){

}
void* RetroAgent::getCurrentBuffer() const{
return RetroAgent::g_video.currentBuffer;
}
Expand Down
3 changes: 2 additions & 1 deletion src/environment/RetroAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class RetroAgent{
uint8_t* getRamAddress();
uint32_t getRamSize();
void SetActions(const Action& player_a_action, const Action& player_b_action);
void updateScreen();
void* getCurrentBuffer() const;
uint32_t getBufferSize() const; // in pixels
uint8_t getBpp() const; //in bits
Expand Down Expand Up @@ -106,11 +105,13 @@ class RetroAgent{

private:
bool coreLoaded;
bool romLoaded;
static std::atomic_uint numAgents;
unsigned agentNum;
void unloadCore();
void unloadRom();
};
typedef shared_ptr<RetroAgent> pRetroAgent;

} // namespace rle

Expand Down
105 changes: 6 additions & 99 deletions src/environment/RleSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,21 @@ using namespace std;
#include "RleSystem.hxx"
#include <time.h>

#include "bspf.hxx"
//#include "bspf.hxx"

using namespace rle;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RleSystem::RleSystem(RetroAgent* retroagent)
RleSystem::RleSystem(pRetroAgent retroagent, pSettings settings)
:
mySettings(NULL),
mySettings(settings), //RLE
myRetroAgent(retroagent), //RLE
myRomFile(""),
myCoreFile(""),
p_display_screen(NULL)
myCoreFile("")
// p_display_screen(NULL)
{}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RleSystem::~RleSystem()
{

// RleSystem takes responsibility for framebuffer and sound,
// since it created them
// if (mySound != NULL)
// delete mySound;

if (p_display_screen != NULL) {
delete p_display_screen;
}

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RleSystem::create()
{
// Create the sound object; the sound subsystem isn't actually
// opened until needed, so this is non-blocking (on those systems
// that only have a single sound device (no hardware mixing)
// createSound();

// Seed RNG. This will likely get re-called, e.g. by the RLEInterface, but is needed
// by other interfaces.
resetRNGSeed();

return true;
}
RleSystem::~RleSystem(){}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RleSystem::resetRNGSeed() {
Expand All @@ -78,70 +51,12 @@ bool RleSystem::saveState(Serializer& out) {
bool RleSystem::loadState(Deserializer& in) {
return myRandGen.loadState(in);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//void RleSystem::setConfigPaths()
//{
// myGameListCacheFile = myBaseDir + BSPF_PATH_SEPARATOR + "stella.cache";
//
// myCheatFile = mySettings->getString("cheatfile");
// if(myCheatFile == "")
// myCheatFile = myBaseDir + BSPF_PATH_SEPARATOR + "stella.cht";
// mySettings->setString("cheatfile", myCheatFile);
//
// myPrletteFile = mySettings->getString("prlettefile");
// if(myPrletteFile == "")
// myPrletteFile = myBaseDir + BSPF_PATH_SEPARATOR + "stella.pal";
// mySettings->setString("prlettefile", myPrletteFile);
//
// myPropertiesFile = mySettings->getString("propsfile");
// if(myPropertiesFile == "")
// myPropertiesFile = myBaseDir + BSPF_PATH_SEPARATOR + "stella.pro";
// mySettings->setString("propsfile", myPropertiesFile);
//}

void RleSystem::setBaseDir(const string& basedir)
{
myBaseDir = basedir;
if(!FilesystemNode::dirExists(myBaseDir))
FilesystemNode::makeDir(myBaseDir);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void RleSystem::step() {
myRetroAgent->run();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RleSystem::setFramerate(uInt32 framerate)
{
myDisplayFrameRate = framerate;
myTimePerFrame = (uInt32)(1000000.0 / (double)myDisplayFrameRate);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//void RleSystem::createSound()
//{
// if (mySound != NULL) {
// delete mySound;
// }
// mySound = NULL;
//
//#ifdef SOUND_SUPPORT
// // If requested (& supported), enable sound
// if (mySettings->getBool("sound") == true) {
// mySound = new SoundSDL(this);
// mySound->initialize();
// }
// else {
// mySound = new SoundNull(this);
// }
//#else
// mySettings->setBool("sound", false);
// mySound = new SoundNull(this);
//#endif
//}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RleSystem::loadCore(const string& corePath){
myCoreFile = corePath;
Expand All @@ -154,11 +69,3 @@ bool RleSystem::loadRom(const string& rom){
myRetroAgent->loadRom(rom);
return true;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//void RleSystem::resetLoopTiming()
//{
// memset(&myTimingInfo, 0, sizeof(TimingInfo));
// myTimingInfo.start = getTicks();
// myTimingInfo.virt = getTicks();
//}
Loading

0 comments on commit 1e6cf8b

Please sign in to comment.