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-08-08 00:50:45 +00:00
|
|
|
|
|
|
|
bool PARSEGAMELISTONLY = false;
|
2012-08-11 04:17:52 +00:00
|
|
|
bool IGNOREGAMELIST = false;
|
2012-08-16 15:23:23 +00:00
|
|
|
|
|
|
|
#ifdef DRAWFRAMERATE
|
|
|
|
float FRAMERATE = 0;
|
|
|
|
#endif
|
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-07-23 23:53:33 +00:00
|
|
|
bool running = true;
|
|
|
|
|
2012-08-13 18:32:53 +00:00
|
|
|
//by the way, if anyone ever tries to port this to a different renderer but leave SDL as input -
|
|
|
|
//KEEP INITIALIZING VIDEO. It starts SDL's event system, and without it, input won't work.
|
2012-07-23 21:47:30 +00:00
|
|
|
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
|
2012-07-19 01:14:17 +00:00
|
|
|
{
|
|
|
|
std::cerr << "Error - could not initialize SDL!\n";
|
2012-07-21 19:06:24 +00:00
|
|
|
std::cerr << " " << SDL_GetError() << "\n";
|
2012-08-12 14:43:09 +00:00
|
|
|
std::cerr << "Are you in the 'video' and 'input' groups? Are you running with X closed?\n";
|
2012-07-19 01:14:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
SDL_Surface* sdlScreen = SDL_SetVideoMode(1, 1, 0, SDL_SWSURFACE);
|
|
|
|
std::cout << "Fake SDL window is " << sdlScreen->w << "x" << sdlScreen->h << "\n";
|
2012-07-27 22:35:45 +00:00
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
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-07-27 22:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
if(!Renderer::init(width, height))
|
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-08-29 18:53: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
|
|
|
}
|
|
|
|
|
|
|
|
//check if there are config files in the old places, and if so, move them to the new directory
|
|
|
|
std::string oldSysPath = home + "/.es_systems.cfg";
|
|
|
|
std::string oldInpPath = home + "/.es_input.cfg";
|
2012-08-12 14:43:09 +00:00
|
|
|
if(fs::exists(oldSysPath))
|
2012-08-02 02:37:07 +00:00
|
|
|
{
|
|
|
|
std::cout << "Moving old system config file " << oldSysPath << " to new path at " << SystemData::getConfigPath() << "\n";
|
2012-08-12 14:43:09 +00:00
|
|
|
fs::copy_file(oldSysPath, SystemData::getConfigPath());
|
|
|
|
fs::remove(oldSysPath);
|
2012-08-02 02:37:07 +00:00
|
|
|
}
|
2012-08-12 14:43:09 +00:00
|
|
|
if(fs::exists(oldInpPath))
|
2012-08-02 02:37:07 +00:00
|
|
|
{
|
2012-08-04 21:38:37 +00:00
|
|
|
std::cout << "Deleting old input config file\n";
|
2012-08-12 14:43:09 +00:00
|
|
|
fs::remove(oldInpPath);
|
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-07-23 23:57:07 +00:00
|
|
|
std::cerr << "You should probably go read that, or delete it.\n";
|
|
|
|
running = false;
|
2012-07-23 23:53:33 +00:00
|
|
|
}else{
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
bool useDetail = false;
|
|
|
|
|
2012-08-08 00:50:45 +00:00
|
|
|
//see if any systems had gamelists present, if so we'll use the detailed GuiGameList
|
2012-08-11 04:17:52 +00:00
|
|
|
if(!IGNOREGAMELIST)
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2012-08-11 04:17:52 +00:00
|
|
|
for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++)
|
2012-08-08 00:50:45 +00:00
|
|
|
{
|
2012-08-11 04:17:52 +00:00
|
|
|
if(SystemData::sSystemVector.at(i)->hasGamelist())
|
|
|
|
{
|
|
|
|
useDetail = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-08 00:50:45 +00:00
|
|
|
}
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 00:50:45 +00:00
|
|
|
//choose which Gui to open up
|
2012-08-12 14:43:09 +00:00
|
|
|
if(fs::exists(InputManager::getConfigPath()))
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
2012-07-23 23:57:07 +00:00
|
|
|
InputManager::loadConfig();
|
2012-08-02 01:43:55 +00:00
|
|
|
new GuiGameList(useDetail);
|
2012-07-23 23:57:07 +00:00
|
|
|
}else{
|
|
|
|
if(SDL_NumJoysticks() > 0)
|
|
|
|
{
|
|
|
|
new GuiInputConfig();
|
|
|
|
}else{
|
|
|
|
std::cout << "Note - it looks like you have no joysticks connected.\n";
|
2012-08-02 01:43:55 +00:00
|
|
|
new GuiGameList(useDetail);
|
2012-07-23 23:57: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;
|
|
|
|
|
2012-08-16 15:23:23 +00:00
|
|
|
#ifdef DRAWFRAMERATE
|
|
|
|
FRAMERATE = 1/((float)deltaTime)*1000;
|
|
|
|
#endif
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
GuiComponent::processTicks(deltaTime);
|
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
Renderer::render();
|
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-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();
|
|
|
|
return 0;
|
|
|
|
}
|