diff --git a/src/AudioManager.cpp b/src/AudioManager.cpp index 4cc5dcf37..47887ede7 100644 --- a/src/AudioManager.cpp +++ b/src/AudioManager.cpp @@ -1,5 +1,6 @@ #include "AudioManager.h" +#include #include "Log.h" #include "VolumeControl.h" @@ -70,6 +71,12 @@ std::shared_ptr & AudioManager::getInstance() void AudioManager::init() { + if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) + { + LOG(LogError) << "Error initializing SDL audio!\n" << SDL_GetError(); + return; + } + //stop playing all Sounds for(unsigned int i = 0; i < sSoundVector.size(); i++) { @@ -97,8 +104,9 @@ void AudioManager::deinit() { //stop all playback stop(); - + //completely tear down SDL audio. else SDL hogs audio resources and emulators might fail to start... SDL_CloseAudio(); + SDL_QuitSubSystem(SDL_INIT_AUDIO); } void AudioManager::registerSound(std::shared_ptr & sound) diff --git a/src/Font.cpp b/src/Font.cpp index f085c7586..bb62f06a8 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -183,9 +183,10 @@ void Font::buildAtlas() charData[i].texY = y; charData[i].texW = g->bitmap.width; charData[i].texH = g->bitmap.rows; - charData[i].advX = g->metrics.horiAdvance / 64.0f; - charData[i].advY = g->metrics.vertAdvance / 64.0f; - charData[i].bearingY = g->metrics.horiBearingY / 64.0f; + charData[i].advX = (float)g->metrics.horiAdvance / 64.0f; + charData[i].advY = (float)g->metrics.vertAdvance / 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) 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) 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 - vert[i + 0].pos = Vector2(x, y + (charData[letter].texH - charData[letter].bearingY) * fontScale); - vert[i + 1].pos = Vector2(x + charData[letter].texW * fontScale, y - charData[letter].bearingY * fontScale); - vert[i + 2].pos = Vector2(x, vert[i + 1].pos.y); + vert[i + 0].pos = Vector2(glyphStartX, y + (charData[letter].texH - charData[letter].bearingY) * fontScale); + vert[i + 1].pos = Vector2(glyphStartX + charData[letter].texW * fontScale, y - charData[letter].bearingY * fontScale); + vert[i + 2].pos = Vector2(glyphStartX, vert[i + 1].pos.y); Vector2 charTexCoord(charData[letter].texX, charData[letter].texY); Vector2 charTexSize(charData[letter].texW, charData[letter].texH); diff --git a/src/Font.h b/src/Font.h index 22644bdea..69c19fa3d 100644 --- a/src/Font.h +++ b/src/Font.h @@ -26,10 +26,11 @@ public: int texW; int texH; - float advX; - float advY; + float advX; //! InputManager::getInputDevices() const //looks like a joystick. add to devices. currentDevices.push_back(InputDevice(deviceName, 0, 0)); } - dirIt++; + ++dirIt; } //or dump /proc/bus/input/devices anbd search for a Handler=..."js"... entry #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 //any functions or change/allocate/delete stuff, but can send a user event SDL_Event event; - SDL_UserEvent userevent; - userevent.type = SDL_USEREVENT_POLLDEVICES; - userevent.code = 0; - userevent.data1 = nullptr; - userevent.data2 = nullptr; - event.type = SDL_USEREVENT; - event.user = userevent; - SDL_PushEvent(&event); + event.user.type = SDL_USEREVENT; + event.user.code = SDL_USEREVENT_POLLDEVICES; + event.user.data1 = nullptr; + event.user.data2 = nullptr; + if (SDL_PushEvent(&event) != 0) { + LOG(LogError) << "InputManager::devicePollingCallback - SDL event queue is full!"; + } 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)); return true; - case SDL_USEREVENT_POLLDEVICES: - //poll joystick / HID again - std::vector currentDevices = getInputDevices(); - //compare device lists to see if devices were added/deleted - if (currentDevices != inputDevices) { - LOG(LogInfo) << "Device configuration changed!"; - inputDevices = currentDevices; + case SDL_USEREVENT: + if (ev.user.code == SDL_USEREVENT_POLLDEVICES) { + //poll joystick / HID again + std::vector currentDevices = getInputDevices(); + //compare device lists to see if devices were added/deleted + if (currentDevices != inputDevices) { + LOG(LogInfo) << "Device configuration changed!"; + inputDevices = currentDevices; + //deinit and reinit InputManager + deinit(); + init(); + } + return true; } - return true; } return false; diff --git a/src/Renderer_draw_gl.cpp b/src/Renderer_draw_gl.cpp index 22dcf4c1e..afa0b1d4b 100644 --- a/src/Renderer_draw_gl.cpp +++ b/src/Renderer_draw_gl.cpp @@ -14,18 +14,22 @@ namespace Renderer { void setColor4bArray(GLubyte* array, unsigned int color) { - array[0] = (color & 0xff000000) / 0x1000000; - array[1] = (color & 0x00ff0000) / 0x10000; - array[2] = (color & 0x0000ff00) / 0x100; + array[0] = (color & 0xff000000) >> 24; + array[1] = (color & 0x00ff0000) >> 16; + array[2] = (color & 0x0000ff00) >> 8; array[3] = (color & 0x000000ff); } 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++) { - setColor4bArray(ptr, color); - ptr += 4; + uiPtr[i] = colorRGBA; } } diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp index b2aa045b7..9659e3b0a 100644 --- a/src/Renderer_init_sdlgl.cpp +++ b/src/Renderer_init_sdlgl.cpp @@ -33,7 +33,7 @@ namespace Renderer { 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(); return false; diff --git a/src/main.cpp b/src/main.cpp index 64367bb05..4823308bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) timeSinceLastEvent = 0; } break; - case InputManager::SDL_USEREVENT_POLLDEVICES: + case SDL_USEREVENT: //try to poll input devices, but do not necessarily wake up... window.getInputManager()->parseEvent(event); break; @@ -181,7 +181,7 @@ int main(int argc, char* argv[]) if(sleeping) { lastTime = SDL_GetTicks(); - sleep(1); //this doesn't need to accurate + SDL_Delay(1); //this doesn't need to be accurate continue; } @@ -225,7 +225,6 @@ int main(int argc, char* argv[]) Renderer::swapBuffers(); } - Log::flush(); }