Merge commit '171ca9a' from HorstBaerbel fork

This commit is contained in:
Aloshi 2013-06-29 07:35:00 -05:00
commit 20d08587f2
7 changed files with 55 additions and 36 deletions

View file

@ -1,5 +1,6 @@
#include "AudioManager.h"
#include <SDL.h>
#include "Log.h"
#include "VolumeControl.h"
@ -70,6 +71,12 @@ std::shared_ptr<AudioManager> & 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> & sound)

View file

@ -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<GLfloat>(x, 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 + 2].pos = Vector2<GLfloat>(x, vert[i + 1].pos.y);
vert[i + 0].pos = Vector2<GLfloat>(glyphStartX, y + (charData[letter].texH - 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>(glyphStartX, vert[i + 1].pos.y);
Vector2<int> charTexCoord(charData[letter].texX, charData[letter].texY);
Vector2<int> charTexSize(charData[letter].texW, charData[letter].texH);

View file

@ -26,10 +26,11 @@ public:
int texW;
int texH;
float advX;
float advY;
float advX; //!<The horizontal distance to advance to the next character after this one
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];

View file

@ -58,7 +58,7 @@ std::vector<InputDevice> 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<InputDevice> 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<InputDevice> 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;

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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();
}