2012-09-07 21:44:07 +00:00
|
|
|
//EmulationStation, a graphical front-end for ROM browsing. Created by Alec "Aloshi" Lofquist.
|
|
|
|
|
2012-07-19 01:14:17 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "Renderer.h"
|
2012-07-20 16:14:09 +00:00
|
|
|
#include "components/GuiGameList.h"
|
|
|
|
#include "SystemData.h"
|
2012-07-23 23:53:33 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2012-07-22 21:15:55 +00:00
|
|
|
#include "components/GuiInputConfig.h"
|
2012-08-29 18:53:53 +00:00
|
|
|
#include <SDL.h>
|
2012-10-13 18:29:53 +00:00
|
|
|
#include "AudioManager.h"
|
2012-09-10 18:10:59 +00:00
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
#ifdef _RPI_
|
|
|
|
#include <bcm_host.h>
|
|
|
|
#endif
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
#include <sstream>
|
2012-08-08 00:50:45 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//these can be set by command-line arguments
|
2012-08-08 00:50:45 +00:00
|
|
|
bool PARSEGAMELISTONLY = false;
|
2012-08-11 04:17:52 +00:00
|
|
|
bool IGNOREGAMELIST = false;
|
2012-09-07 21:44:07 +00:00
|
|
|
bool DRAWFRAMERATE = false;
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2012-08-12 14:43:09 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2012-07-27 22:35:45 +00:00
|
|
|
int main(int argc, char* argv[])
|
2012-07-19 01:14:17 +00:00
|
|
|
{
|
2012-08-29 21:52:25 +00:00
|
|
|
unsigned int width = 0;
|
|
|
|
unsigned int height = 0;
|
2012-07-27 22:35:45 +00:00
|
|
|
if(argc > 1)
|
|
|
|
{
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if(strcmp(argv[i], "-w") == 0)
|
|
|
|
{
|
|
|
|
width = atoi(argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
}else if(strcmp(argv[i], "-h") == 0)
|
|
|
|
{
|
|
|
|
height = atoi(argv[i + 1]);
|
|
|
|
i++;
|
2012-08-08 00:50:45 +00:00
|
|
|
}else if(strcmp(argv[i], "--gamelist-only") == 0)
|
|
|
|
{
|
|
|
|
PARSEGAMELISTONLY = true;
|
2012-08-11 04:17:52 +00:00
|
|
|
}else if(strcmp(argv[i], "--ignore-gamelist") == 0)
|
|
|
|
{
|
|
|
|
IGNOREGAMELIST = true;
|
2012-09-07 21:44:07 +00:00
|
|
|
}else if(strcmp(argv[i], "--draw-framerate") == 0)
|
|
|
|
{
|
|
|
|
DRAWFRAMERATE = true;
|
|
|
|
}else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
|
|
|
|
{
|
|
|
|
std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n";
|
|
|
|
std::cout << "Command line arguments:\n";
|
2012-09-07 21:53:27 +00:00
|
|
|
std::cout << "-w [width in pixels] set screen width\n";
|
|
|
|
std::cout << "-h [height in pixels] set screen height\n";
|
|
|
|
std::cout << "--gamelist-only skip automatic game detection, only read from gamelist.xml\n";
|
2012-09-07 21:44:07 +00:00
|
|
|
std::cout << "--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n";
|
|
|
|
std::cout << "--draw-framerate display the framerate\n";
|
2012-09-07 21:53:27 +00:00
|
|
|
std::cout << "--help summon a sentient, angry tuba\n\n";
|
2012-09-07 21:44:07 +00:00
|
|
|
std::cout << "More information available in README.md.\n";
|
|
|
|
return 0;
|
2012-07-27 22:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 21:53:27 +00:00
|
|
|
|
2012-09-10 18:10:59 +00:00
|
|
|
#ifdef _RPI_
|
|
|
|
bcm_host_init();
|
|
|
|
#endif
|
2012-09-07 21:53:27 +00:00
|
|
|
|
|
|
|
bool running = true;
|
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
//the renderer also takes care of setting up SDL for input and sound
|
2012-08-29 21:52:25 +00:00
|
|
|
bool renderInit = Renderer::init(width, height);
|
|
|
|
if(!renderInit)
|
2012-07-19 16:13:27 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
std::cerr << "Error initializing renderer!\n";
|
2012-07-19 16:13:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
//initialize audio
|
|
|
|
AudioManager::init();
|
|
|
|
|
2012-08-02 02:37:07 +00:00
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
2012-08-02 02:37:07 +00:00
|
|
|
|
|
|
|
//make sure the config directory exists
|
|
|
|
std::string home = getenv("HOME");
|
|
|
|
std::string configDir = home + "/.emulationstation";
|
2012-08-12 14:43:09 +00:00
|
|
|
if(!fs::exists(configDir))
|
2012-08-02 02:37:07 +00:00
|
|
|
{
|
2012-08-04 21:38:37 +00:00
|
|
|
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
2012-08-12 14:43:09 +00:00
|
|
|
fs::create_directory(configDir);
|
2012-08-02 02:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-08 00:50:45 +00:00
|
|
|
//try loading the system config file
|
2012-08-12 14:43:09 +00:00
|
|
|
if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
2012-08-02 02:37:07 +00:00
|
|
|
std::cerr << "A system config file in " << SystemData::getConfigPath() << " was not found. An example will be created.\n";
|
2012-07-23 23:53:33 +00:00
|
|
|
SystemData::writeExampleConfig();
|
|
|
|
std::cerr << "Set it up, then re-run EmulationStation.\n";
|
|
|
|
running = false;
|
|
|
|
}else{
|
|
|
|
SystemData::loadConfig();
|
2012-07-19 16:13:27 +00:00
|
|
|
|
2012-08-08 00:50:45 +00:00
|
|
|
if(SystemData::sSystemVector.size() == 0) //if it exists but was empty, notify the user and quit
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
2012-08-02 02:37:07 +00:00
|
|
|
std::cerr << "A system config file in " << SystemData::getConfigPath() << " was found, but contained no systems.\n";
|
2012-09-07 21:44:07 +00:00
|
|
|
std::cerr << "Does at least one system have a game presesnt?\n";
|
2012-07-23 23:57:07 +00:00
|
|
|
running = false;
|
2012-07-23 23:53:33 +00:00
|
|
|
}else{
|
2012-09-07 21:44:07 +00:00
|
|
|
//choose which GUI to open depending on Input configuration
|
2012-08-12 14:43:09 +00:00
|
|
|
if(fs::exists(InputManager::getConfigPath()))
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
2012-09-07 21:44:07 +00:00
|
|
|
//an input config already exists - load it and proceed to the gamelist as usual.
|
2012-07-23 23:57:07 +00:00
|
|
|
InputManager::loadConfig();
|
2012-10-05 20:18:36 +00:00
|
|
|
GuiGameList::create();
|
2012-07-23 23:57:07 +00:00
|
|
|
}else{
|
2012-09-07 21:44:07 +00:00
|
|
|
//if no input.cfg is present, but a joystick is connected, launch the input config GUI
|
2012-07-23 23:57:07 +00:00
|
|
|
if(SDL_NumJoysticks() > 0)
|
|
|
|
new GuiInputConfig();
|
2012-09-07 21:44:07 +00:00
|
|
|
else
|
2012-10-05 20:18:36 +00:00
|
|
|
GuiGameList::create();
|
2012-09-07 21:44:07 +00:00
|
|
|
|
2012-07-23 23:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
int lastTime = 0;
|
2012-07-19 16:13:27 +00:00
|
|
|
while(running)
|
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
while(SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch(event.type)
|
|
|
|
{
|
2012-07-24 02:10:05 +00:00
|
|
|
case SDL_JOYHATMOTION:
|
2012-07-23 17:27:38 +00:00
|
|
|
case SDL_JOYAXISMOTION:
|
2012-07-22 21:15:55 +00:00
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
case SDL_JOYBUTTONUP:
|
2012-07-19 16:13:27 +00:00
|
|
|
case SDL_KEYDOWN:
|
2012-07-20 01:08:29 +00:00
|
|
|
case SDL_KEYUP:
|
|
|
|
InputManager::processEvent(&event);
|
2012-07-19 16:13:27 +00:00
|
|
|
break;
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
case SDL_QUIT:
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
int curTime = SDL_GetTicks();
|
|
|
|
int deltaTime = curTime - lastTime;
|
|
|
|
lastTime = curTime;
|
|
|
|
|
|
|
|
GuiComponent::processTicks(deltaTime);
|
2012-07-19 16:13:27 +00:00
|
|
|
Renderer::render();
|
2012-09-07 21:44:07 +00:00
|
|
|
|
|
|
|
if(DRAWFRAMERATE)
|
|
|
|
{
|
|
|
|
float framerate = 1/((float)deltaTime)*1000;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << framerate;
|
|
|
|
std::string fps;
|
|
|
|
ss >> fps;
|
|
|
|
Renderer::drawText(fps, 50, 50, 0x00FF00);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
Renderer::swapBuffers();
|
2012-07-19 16:13:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
AudioManager::deinit();
|
2012-07-22 21:15:55 +00:00
|
|
|
Renderer::deleteAll();
|
2012-08-29 18:53:53 +00:00
|
|
|
Renderer::deinit();
|
2012-07-21 20:57:53 +00:00
|
|
|
SystemData::deleteSystems();
|
2012-07-19 01:14:17 +00:00
|
|
|
|
2012-07-20 01:08:29 +00:00
|
|
|
std::cout << "EmulationStation cleanly shutting down...\n";
|
|
|
|
|
2012-07-19 01:14:17 +00:00
|
|
|
SDL_Quit();
|
2012-09-04 16:45:16 +00:00
|
|
|
|
2012-09-10 18:10:59 +00:00
|
|
|
#ifdef _RPI_
|
|
|
|
bcm_host_deinit();
|
|
|
|
#endif
|
2012-09-04 16:45:16 +00:00
|
|
|
|
2012-07-19 01:14:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|