2012-07-19 01:14:17 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <SDL/SDL.h>
|
2012-07-20 01:08:29 +00:00
|
|
|
#include <SDL/SDL_ttf.h>
|
2012-07-19 01:14:17 +00:00
|
|
|
#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-02 01:43:55 +00:00
|
|
|
#include "XMLReader.h"
|
2012-07-22 21:15:55 +00:00
|
|
|
|
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-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-07-23 21:47:30 +00:00
|
|
|
std::cerr << "\nAre you in the 'video' and 'input' groups?\n";
|
2012-07-19 01:14:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
if(TTF_Init() != 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Error - could not initialize SDL_ttf!\n";
|
2012-07-21 19:06:24 +00:00
|
|
|
std::cerr << " " << TTF_GetError() << "\n";
|
2012-07-20 01:08:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-07-19 01:14:17 +00:00
|
|
|
|
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-02 01:43:55 +00:00
|
|
|
Renderer::screen = SDL_SetVideoMode(width, height, 16, SDL_SWSURFACE); //| SDL_FULLSCREEN);
|
2012-07-27 22:35:45 +00:00
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
if(Renderer::screen == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "Error - could not set video mode!\n";
|
2012-07-21 19:06:24 +00:00
|
|
|
std::cerr << " " << SDL_GetError() << "\n";
|
2012-07-27 22:35:45 +00:00
|
|
|
std::cerr << "\nYou may want to try using -w and -h to specify a resolution.\n";
|
2012-07-19 16:13:27 +00:00
|
|
|
return 1;
|
2012-07-27 22:35:45 +00:00
|
|
|
}else{
|
|
|
|
std::cout << "Video mode is " << Renderer::screen->w << "x" << Renderer::screen->h << "\n";
|
2012-07-19 16:13:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 01:08:29 +00:00
|
|
|
SDL_ShowCursor(false);
|
2012-07-22 21:15:55 +00:00
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
2012-07-19 16:13:27 +00:00
|
|
|
|
2012-08-02 02:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
//make sure the config directory exists
|
|
|
|
std::string home = getenv("HOME");
|
|
|
|
std::string configDir = home + "/.emulationstation";
|
|
|
|
if(!boost::filesystem::exists(configDir))
|
|
|
|
{
|
2012-08-04 21:38:37 +00:00
|
|
|
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
2012-08-02 02:37:07 +00:00
|
|
|
boost::filesystem::create_directory(configDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//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";
|
|
|
|
if(boost::filesystem::exists(oldSysPath))
|
|
|
|
{
|
|
|
|
std::cout << "Moving old system config file " << oldSysPath << " to new path at " << SystemData::getConfigPath() << "\n";
|
|
|
|
boost::filesystem::copy_file(oldSysPath, SystemData::getConfigPath());
|
|
|
|
boost::filesystem::remove(oldSysPath);
|
|
|
|
}
|
|
|
|
if(boost::filesystem::exists(oldInpPath))
|
|
|
|
{
|
2012-08-04 21:38:37 +00:00
|
|
|
std::cout << "Deleting old input config file\n";
|
2012-08-02 02:37:07 +00:00
|
|
|
boost::filesystem::remove(oldInpPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-23 23:53:33 +00:00
|
|
|
if(!boost::filesystem::exists(SystemData::getConfigPath()))
|
|
|
|
{
|
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-07-23 23:57:07 +00:00
|
|
|
if(SystemData::sSystemVector.size() == 0)
|
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;
|
|
|
|
|
|
|
|
//loaded system config, so try parsing the test XML doc
|
|
|
|
if(boost::filesystem::exists("gamelist.xml"))
|
|
|
|
{
|
|
|
|
parseXMLFile("gamelist.xml");
|
|
|
|
useDetail = true;
|
|
|
|
}
|
|
|
|
|
2012-07-23 23:57:07 +00:00
|
|
|
if(boost::filesystem::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;
|
|
|
|
|
|
|
|
GuiComponent::processTicks(deltaTime);
|
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
Renderer::render();
|
|
|
|
SDL_Flip(Renderer::screen);
|
|
|
|
}
|
|
|
|
|
2012-07-22 21:15:55 +00:00
|
|
|
Renderer::deleteAll();
|
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";
|
|
|
|
|
|
|
|
TTF_Quit();
|
2012-07-19 01:14:17 +00:00
|
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
|
|
}
|