mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-29 09:35:39 +00:00
Merge branch 'master' into unstable
This commit is contained in:
commit
c18877fdf1
|
@ -1,5 +1,6 @@
|
||||||
#include "AudioManager.h"
|
#include "AudioManager.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "VolumeControl.h"
|
#include "VolumeControl.h"
|
||||||
|
|
||||||
|
@ -70,6 +71,12 @@ std::shared_ptr<AudioManager> & AudioManager::getInstance()
|
||||||
|
|
||||||
void AudioManager::init()
|
void AudioManager::init()
|
||||||
{
|
{
|
||||||
|
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0)
|
||||||
|
{
|
||||||
|
LOG(LogError) << "Error initializing SDL audio!\n" << SDL_GetError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//stop playing all Sounds
|
//stop playing all Sounds
|
||||||
for(unsigned int i = 0; i < sSoundVector.size(); i++)
|
for(unsigned int i = 0; i < sSoundVector.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -97,8 +104,9 @@ void AudioManager::deinit()
|
||||||
{
|
{
|
||||||
//stop all playback
|
//stop all playback
|
||||||
stop();
|
stop();
|
||||||
|
//completely tear down SDL audio. else SDL hogs audio resources and emulators might fail to start...
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::registerSound(std::shared_ptr<Sound> & sound)
|
void AudioManager::registerSound(std::shared_ptr<Sound> & sound)
|
||||||
|
|
15
src/Font.cpp
15
src/Font.cpp
|
@ -183,9 +183,10 @@ void Font::buildAtlas()
|
||||||
charData[i].texY = y;
|
charData[i].texY = y;
|
||||||
charData[i].texW = g->bitmap.width;
|
charData[i].texW = g->bitmap.width;
|
||||||
charData[i].texH = g->bitmap.rows;
|
charData[i].texH = g->bitmap.rows;
|
||||||
charData[i].advX = g->metrics.horiAdvance / 64.0f;
|
charData[i].advX = (float)g->metrics.horiAdvance / 64.0f;
|
||||||
charData[i].advY = g->metrics.vertAdvance / 64.0f;
|
charData[i].advY = (float)g->metrics.vertAdvance / 64.0f;
|
||||||
charData[i].bearingY = g->metrics.horiBearingY / 64.0f;
|
charData[i].bearingX = (float)g->metrics.horiBearingX / 64.0f;
|
||||||
|
charData[i].bearingY = (float)g->metrics.horiBearingY / 64.0f;
|
||||||
|
|
||||||
if(charData[i].texH > mMaxGlyphHeight)
|
if(charData[i].texH > mMaxGlyphHeight)
|
||||||
mMaxGlyphHeight = charData[i].texH;
|
mMaxGlyphHeight = charData[i].texH;
|
||||||
|
@ -257,10 +258,12 @@ void Font::drawText(std::string text, int startx, int starty, int color)
|
||||||
if(letter < 32 || letter >= 128)
|
if(letter < 32 || letter >= 128)
|
||||||
letter = 127; //print [X] if character is not standard ASCII
|
letter = 127; //print [X] if character is not standard ASCII
|
||||||
|
|
||||||
|
//the glyph might not start at the cursor position, but needs to be shifted a bit
|
||||||
|
const float glyphStartX = x + charData[letter].bearingX * fontScale;
|
||||||
//order is bottom left, top right, top left
|
//order is bottom left, top right, top left
|
||||||
vert[i + 0].pos = Vector2<GLfloat>(x, y + (charData[letter].texH - charData[letter].bearingY) * fontScale);
|
vert[i + 0].pos = Vector2<GLfloat>(glyphStartX, y + (charData[letter].texH - charData[letter].bearingY) * fontScale);
|
||||||
vert[i + 1].pos = Vector2<GLfloat>(x + charData[letter].texW * fontScale, y - charData[letter].bearingY * fontScale);
|
vert[i + 1].pos = Vector2<GLfloat>(glyphStartX + charData[letter].texW * fontScale, y - charData[letter].bearingY * fontScale);
|
||||||
vert[i + 2].pos = Vector2<GLfloat>(x, vert[i + 1].pos.y);
|
vert[i + 2].pos = Vector2<GLfloat>(glyphStartX, vert[i + 1].pos.y);
|
||||||
|
|
||||||
Vector2<int> charTexCoord(charData[letter].texX, charData[letter].texY);
|
Vector2<int> charTexCoord(charData[letter].texX, charData[letter].texY);
|
||||||
Vector2<int> charTexSize(charData[letter].texW, charData[letter].texH);
|
Vector2<int> charTexSize(charData[letter].texW, charData[letter].texH);
|
||||||
|
|
|
@ -26,10 +26,11 @@ public:
|
||||||
int texW;
|
int texW;
|
||||||
int texH;
|
int texH;
|
||||||
|
|
||||||
float advX;
|
float advX; //!<The horizontal distance to advance to the next character after this one
|
||||||
float advY;
|
float advY; //!<The vertical distance to advance to the next character after this one
|
||||||
|
|
||||||
float bearingY;
|
float bearingX; //!<The horizontal distance from the cursor to the start of the character
|
||||||
|
float bearingY; //!<The vertical distance from the cursor to the start of the character
|
||||||
};
|
};
|
||||||
|
|
||||||
charPosData charData[128];
|
charPosData charData[128];
|
||||||
|
|
|
@ -28,7 +28,7 @@ bool InputDevice::operator==(const InputDevice & b) const
|
||||||
|
|
||||||
InputManager::InputManager(Window* window) : mWindow(window),
|
InputManager::InputManager(Window* window) : mWindow(window),
|
||||||
mJoysticks(NULL), mInputConfigs(NULL), mKeyboardInputConfig(NULL), mPrevAxisValues(NULL),
|
mJoysticks(NULL), mInputConfigs(NULL), mKeyboardInputConfig(NULL), mPrevAxisValues(NULL),
|
||||||
mNumJoysticks(0), mNumPlayers(0), devicePollingTimer(nullptr)
|
mNumJoysticks(0), mNumPlayers(0), devicePollingTimer(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ std::vector<InputDevice> InputManager::getInputDevices() const
|
||||||
//looks like a joystick. add to devices.
|
//looks like a joystick. add to devices.
|
||||||
currentDevices.push_back(InputDevice(deviceName, 0, 0));
|
currentDevices.push_back(InputDevice(deviceName, 0, 0));
|
||||||
}
|
}
|
||||||
dirIt++;
|
++dirIt;
|
||||||
}
|
}
|
||||||
//or dump /proc/bus/input/devices anbd search for a Handler=..."js"... entry
|
//or dump /proc/bus/input/devices anbd search for a Handler=..."js"... entry
|
||||||
#elif defined(WIN32) || defined(_WIN32)
|
#elif defined(WIN32) || defined(_WIN32)
|
||||||
|
@ -122,14 +122,13 @@ Uint32 InputManager::devicePollingCallback(Uint32 interval, void* param)
|
||||||
//this thing my be running in a different thread, so we're not allowed to call
|
//this thing my be running in a different thread, so we're not allowed to call
|
||||||
//any functions or change/allocate/delete stuff, but can send a user event
|
//any functions or change/allocate/delete stuff, but can send a user event
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent userevent;
|
event.user.type = SDL_USEREVENT;
|
||||||
userevent.type = SDL_USEREVENT_POLLDEVICES;
|
event.user.code = SDL_USEREVENT_POLLDEVICES;
|
||||||
userevent.code = 0;
|
event.user.data1 = nullptr;
|
||||||
userevent.data1 = nullptr;
|
event.user.data2 = nullptr;
|
||||||
userevent.data2 = nullptr;
|
if (SDL_PushEvent(&event) != 0) {
|
||||||
event.type = SDL_USEREVENT;
|
LOG(LogError) << "InputManager::devicePollingCallback - SDL event queue is full!";
|
||||||
event.user = userevent;
|
}
|
||||||
SDL_PushEvent(&event);
|
|
||||||
|
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
@ -165,14 +164,31 @@ void InputManager::init()
|
||||||
SDL_JoystickEventState(SDL_ENABLE);
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
|
|
||||||
//start timer for input device polling
|
//start timer for input device polling
|
||||||
devicePollingTimer = SDL_AddTimer(POLLING_INTERVAL, devicePollingCallback, (void *)this);
|
startPolling();
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputManager::startPolling()
|
||||||
|
{
|
||||||
|
if(devicePollingTimer != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
devicePollingTimer = SDL_AddTimer(POLLING_INTERVAL, devicePollingCallback, (void *)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputManager::stopPolling()
|
||||||
|
{
|
||||||
|
if(devicePollingTimer == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SDL_RemoveTimer(devicePollingTimer);
|
||||||
|
devicePollingTimer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void InputManager::deinit()
|
void InputManager::deinit()
|
||||||
{
|
{
|
||||||
SDL_RemoveTimer(devicePollingTimer);
|
stopPolling();
|
||||||
|
|
||||||
SDL_JoystickEventState(SDL_DISABLE);
|
SDL_JoystickEventState(SDL_DISABLE);
|
||||||
|
|
||||||
|
@ -290,16 +306,21 @@ bool InputManager::parseEvent(const SDL_Event& ev)
|
||||||
mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false));
|
mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case SDL_USEREVENT_POLLDEVICES:
|
case SDL_USEREVENT:
|
||||||
|
if (ev.user.code == SDL_USEREVENT_POLLDEVICES) {
|
||||||
//poll joystick / HID again
|
//poll joystick / HID again
|
||||||
std::vector<InputDevice> currentDevices = getInputDevices();
|
std::vector<InputDevice> currentDevices = getInputDevices();
|
||||||
//compare device lists to see if devices were added/deleted
|
//compare device lists to see if devices were added/deleted
|
||||||
if (currentDevices != inputDevices) {
|
if (currentDevices != inputDevices) {
|
||||||
LOG(LogInfo) << "Device configuration changed!";
|
LOG(LogInfo) << "Device configuration changed!";
|
||||||
inputDevices = currentDevices;
|
inputDevices = currentDevices;
|
||||||
|
//deinit and reinit InputManager
|
||||||
|
deinit();
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -376,6 +397,8 @@ void InputManager::loadConfig()
|
||||||
LOG(LogInfo) << "No input configs loaded. Loading default keyboard config.";
|
LOG(LogInfo) << "No input configs loaded. Loading default keyboard config.";
|
||||||
loadDefaultConfig();
|
loadDefaultConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(LogInfo) << "Loaded InputConfig data for " << getNumPlayers() << " devices.";
|
||||||
}
|
}
|
||||||
|
|
||||||
//used in an "emergency" where no configs could be loaded from the inputmanager config file
|
//used in an "emergency" where no configs could be loaded from the inputmanager config file
|
||||||
|
|
|
@ -77,6 +77,9 @@ public:
|
||||||
bool parseEvent(const SDL_Event& ev);
|
bool parseEvent(const SDL_Event& ev);
|
||||||
|
|
||||||
InputConfig* getInputConfigByPlayer(int player);
|
InputConfig* getInputConfigByPlayer(int player);
|
||||||
|
|
||||||
|
void startPolling();
|
||||||
|
void stopPolling();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -65,6 +65,7 @@ Log::~Log()
|
||||||
fprintf(getOutput(), "%s", os.str().c_str());
|
fprintf(getOutput(), "%s", os.str().c_str());
|
||||||
|
|
||||||
//if it's an error, also print to console
|
//if it's an error, also print to console
|
||||||
if(messageLevel == LogError)
|
//print all messages if using --debug
|
||||||
|
if(messageLevel == LogError || reportingLevel >= LogDebug)
|
||||||
fprintf(stderr, "%s", os.str().c_str());
|
fprintf(stderr, "%s", os.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,22 @@ namespace Renderer {
|
||||||
|
|
||||||
void setColor4bArray(GLubyte* array, unsigned int color)
|
void setColor4bArray(GLubyte* array, unsigned int color)
|
||||||
{
|
{
|
||||||
array[0] = (color & 0xff000000) / 0x1000000;
|
array[0] = (color & 0xff000000) >> 24;
|
||||||
array[1] = (color & 0x00ff0000) / 0x10000;
|
array[1] = (color & 0x00ff0000) >> 16;
|
||||||
array[2] = (color & 0x0000ff00) / 0x100;
|
array[2] = (color & 0x0000ff00) >> 8;
|
||||||
array[3] = (color & 0x000000ff);
|
array[3] = (color & 0x000000ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount)
|
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount)
|
||||||
{
|
{
|
||||||
|
//convert color from ???? to RGBA?
|
||||||
|
unsigned int colorRGBA;
|
||||||
|
setColor4bArray((GLubyte *)&colorRGBA, color);
|
||||||
|
//write color to unsigned int array
|
||||||
|
GLuint * uiPtr = (GLuint *)ptr;
|
||||||
for(unsigned int i = 0; i < vertCount; i++)
|
for(unsigned int i = 0; i < vertCount; i++)
|
||||||
{
|
{
|
||||||
setColor4bArray(ptr, color);
|
uiPtr[i] = colorRGBA;
|
||||||
ptr += 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Renderer
|
||||||
{
|
{
|
||||||
LOG(LogInfo) << "Creating surface...";
|
LOG(LogInfo) << "Creating surface...";
|
||||||
|
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
|
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||||
{
|
{
|
||||||
LOG(LogError) << "Error initializing SDL!\n " << SDL_GetError();
|
LOG(LogError) << "Error initializing SDL!\n " << SDL_GetError();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -44,6 +44,10 @@ bool GuiDetectDevice::input(InputConfig* config, Input input)
|
||||||
if(!input.value)
|
if(!input.value)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//don't allow device list to change once the first player has registered
|
||||||
|
if(mCurrentPlayer == 0)
|
||||||
|
mWindow->getInputManager()->stopPolling();
|
||||||
|
|
||||||
config->setPlayerNum(mCurrentPlayer);
|
config->setPlayerNum(mCurrentPlayer);
|
||||||
mWindow->getInputManager()->setNumPlayers(mWindow->getInputManager()->getNumPlayers() + 1); //inc total number of players
|
mWindow->getInputManager()->setNumPlayers(mWindow->getInputManager()->getNumPlayers() + 1); //inc total number of players
|
||||||
mCurrentPlayer++;
|
mCurrentPlayer++;
|
||||||
|
|
|
@ -38,6 +38,7 @@ bool GuiInputConfig::input(InputConfig* config, Input input)
|
||||||
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1)));
|
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1)));
|
||||||
}else{
|
}else{
|
||||||
mWindow->getInputManager()->writeConfig();
|
mWindow->getInputManager()->writeConfig();
|
||||||
|
mWindow->getInputManager()->startPolling(); //enable polling again since we're done
|
||||||
GuiGameList::create(mWindow);
|
GuiGameList::create(mWindow);
|
||||||
}
|
}
|
||||||
delete this;
|
delete this;
|
||||||
|
|
|
@ -168,7 +168,7 @@ int main(int argc, char* argv[])
|
||||||
timeSinceLastEvent = 0;
|
timeSinceLastEvent = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InputManager::SDL_USEREVENT_POLLDEVICES:
|
case SDL_USEREVENT:
|
||||||
//try to poll input devices, but do not necessarily wake up...
|
//try to poll input devices, but do not necessarily wake up...
|
||||||
window.getInputManager()->parseEvent(event);
|
window.getInputManager()->parseEvent(event);
|
||||||
break;
|
break;
|
||||||
|
@ -181,7 +181,7 @@ int main(int argc, char* argv[])
|
||||||
if(sleeping)
|
if(sleeping)
|
||||||
{
|
{
|
||||||
lastTime = SDL_GetTicks();
|
lastTime = SDL_GetTicks();
|
||||||
sleep(1); //this doesn't need to accurate
|
SDL_Delay(1); //this doesn't need to be accurate
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,6 @@ int main(int argc, char* argv[])
|
||||||
Renderer::swapBuffers();
|
Renderer::swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log::flush();
|
Log::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue