mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-30 12:05:39 +00:00
Merge commit '171ca9a' from HorstBaerbel fork
This commit is contained in:
commit
20d08587f2
|
@ -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];
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -290,15 +289,20 @@ 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:
|
||||||
//poll joystick / HID again
|
if (ev.user.code == SDL_USEREVENT_POLLDEVICES) {
|
||||||
std::vector<InputDevice> currentDevices = getInputDevices();
|
//poll joystick / HID again
|
||||||
//compare device lists to see if devices were added/deleted
|
std::vector<InputDevice> currentDevices = getInputDevices();
|
||||||
if (currentDevices != inputDevices) {
|
//compare device lists to see if devices were added/deleted
|
||||||
LOG(LogInfo) << "Device configuration changed!";
|
if (currentDevices != inputDevices) {
|
||||||
inputDevices = currentDevices;
|
LOG(LogInfo) << "Device configuration changed!";
|
||||||
|
inputDevices = currentDevices;
|
||||||
|
//deinit and reinit InputManager
|
||||||
|
deinit();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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