mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Fix threaded handlers initialization, cleanup
This commit is contained in:
@ -925,7 +925,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
|
|||||||
k -= SDLK_KP0 + 1;
|
k -= SDLK_KP0 + 1;
|
||||||
#else
|
#else
|
||||||
k -= SDLK_KP_1;
|
k -= SDLK_KP_1;
|
||||||
#endif // 0
|
#endif // VCMI_SDL1
|
||||||
if(k < 0 || k > 8)
|
if(k < 0 || k > 8)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -137,28 +137,16 @@ void startGameFromFile(const std::string &fname)
|
|||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
CStopWatch tmh, pomtime;
|
CStopWatch tmh, pomtime;
|
||||||
logGlobal->infoStream() << "\tInitializing minors: " << pomtime.getDiff();
|
|
||||||
|
|
||||||
//initializing audio
|
|
||||||
// Note: because of interface button range, volume can only be a
|
|
||||||
// multiple of 11, from 0 to 99.
|
|
||||||
CCS->soundh = new CSoundHandler;
|
|
||||||
CCS->soundh->init();
|
|
||||||
CCS->soundh->setVolume(settings["general"]["sound"].Float());
|
|
||||||
CCS->musich = new CMusicHandler;
|
|
||||||
CCS->musich->init();
|
|
||||||
CCS->musich->setVolume(settings["general"]["music"].Float());
|
|
||||||
logGlobal->infoStream()<<"\tInitializing sound: "<<pomtime.getDiff();
|
|
||||||
logGlobal->infoStream()<<"Initializing screen and sound handling: "<<tmh.getDiff();
|
|
||||||
|
|
||||||
loadDLLClasses();
|
loadDLLClasses();
|
||||||
const_cast<CGameInfo*>(CGI)->setFromLib();
|
const_cast<CGameInfo*>(CGI)->setFromLib();
|
||||||
|
|
||||||
logGlobal->infoStream()<<"Initializing VCMI_Lib: "<<tmh.getDiff();
|
logGlobal->infoStream()<<"Initializing VCMI_Lib: "<<tmh.getDiff();
|
||||||
|
|
||||||
pomtime.getDiff();
|
|
||||||
if(!gNoGUI)
|
if(!gNoGUI)
|
||||||
{
|
{
|
||||||
|
pomtime.getDiff();
|
||||||
CCS->curh = new CCursorHandler;
|
CCS->curh = new CCursorHandler;
|
||||||
graphics = new Graphics(); // should be before curh->init()
|
graphics = new Graphics(); // should be before curh->init()
|
||||||
|
|
||||||
@ -168,7 +156,7 @@ void init()
|
|||||||
pomtime.getDiff();
|
pomtime.getDiff();
|
||||||
|
|
||||||
graphics->loadHeroAnims();
|
graphics->loadHeroAnims();
|
||||||
logGlobal->infoStream()<<"\tMain graphics: "<<tmh.getDiff();
|
logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
|
||||||
logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
|
logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
|
||||||
|
|
||||||
CMessage::init();
|
CMessage::init();
|
||||||
@ -400,11 +388,21 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
logGlobal->infoStream()<<"\tInitializing video: "<<pomtime.getDiff();
|
logGlobal->infoStream()<<"\tInitializing video: "<<pomtime.getDiff();
|
||||||
|
|
||||||
#if defined(__ANDROID__) || !defined(VCMI_SDL1)
|
#if defined(__ANDROID__)
|
||||||
//on Android threaded init is broken
|
//on Android threaded init is broken
|
||||||
#define VCMI_NO_THREADED_LOAD
|
#define VCMI_NO_THREADED_LOAD
|
||||||
#endif // defined
|
#endif // defined
|
||||||
|
|
||||||
|
//initializing audio
|
||||||
|
// Note: because of interface button range, volume can only be a
|
||||||
|
// multiple of 11, from 0 to 99.
|
||||||
|
CCS->soundh = new CSoundHandler;
|
||||||
|
CCS->soundh->init();
|
||||||
|
CCS->soundh->setVolume(settings["general"]["sound"].Float());
|
||||||
|
CCS->musich = new CMusicHandler;
|
||||||
|
CCS->musich->init();
|
||||||
|
CCS->musich->setVolume(settings["general"]["music"].Float());
|
||||||
|
logGlobal->infoStream()<<"Initializing screen and sound handling: "<<pomtime.getDiff();
|
||||||
|
|
||||||
#ifndef VCMI_NO_THREADED_LOAD
|
#ifndef VCMI_NO_THREADED_LOAD
|
||||||
//we can properly play intro only in the main thread, so we have to move loading to the separate thread
|
//we can properly play intro only in the main thread, so we have to move loading to the separate thread
|
||||||
@ -1043,10 +1041,8 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo
|
|||||||
|
|
||||||
if(!recreateWindow(w,h,bpp,fullscreen))
|
if(!recreateWindow(w,h,bpp,fullscreen))
|
||||||
{
|
{
|
||||||
return;
|
throw std::runtime_error("Requested screen resolution is not available\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // VCMI_SDL1
|
#endif // VCMI_SDL1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1144,7 +1140,7 @@ static void handleEvent(SDL_Event & ev)
|
|||||||
fullScreenChanged();
|
fullScreenChanged();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logGlobal->errorStream() << "Error: unknown user event. Code " << ev.user.code;
|
logGlobal->errorStream() << "Unknown user event. Code " << ev.user.code;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,13 +75,7 @@ void Graphics::loadPaletteAndColors()
|
|||||||
neutralColorPalette[i].r = reader.readUInt8();
|
neutralColorPalette[i].r = reader.readUInt8();
|
||||||
neutralColorPalette[i].g = reader.readUInt8();
|
neutralColorPalette[i].g = reader.readUInt8();
|
||||||
neutralColorPalette[i].b = reader.readUInt8();
|
neutralColorPalette[i].b = reader.readUInt8();
|
||||||
#ifdef VCMI_SDL1
|
CSDL_Ext::colorSetAlpha(neutralColorPalette[i], !reader.readUInt8());
|
||||||
neutralColorPalette[i].unused = reader.readUInt8();
|
|
||||||
neutralColorPalette[i].unused = !neutralColorPalette[i].unused;
|
|
||||||
#else
|
|
||||||
neutralColorPalette[i].a = reader.readUInt8();
|
|
||||||
neutralColorPalette[i].a = !neutralColorPalette[i].a;
|
|
||||||
#endif // 0
|
|
||||||
}
|
}
|
||||||
//colors initialization
|
//colors initialization
|
||||||
SDL_Color colors[] = {
|
SDL_Color colors[] = {
|
||||||
|
@ -304,6 +304,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
|
|||||||
it->textEdited(sEvent->edit);
|
it->textEdited(sEvent->edit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//todo: muiltitouch
|
||||||
#endif // VCMI_SDL1
|
#endif // VCMI_SDL1
|
||||||
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
@ -472,7 +473,7 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
|
|||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
return SDLK_KP6;
|
return SDLK_KP6;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
throw std::runtime_error("Wrong key!");assert(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch(key)
|
switch(key)
|
||||||
@ -486,10 +487,9 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
|
|||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
return SDLK_KP_6;
|
return SDLK_KP_6;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
throw std::runtime_error("Wrong key!");
|
||||||
}
|
}
|
||||||
#endif // 0
|
#endif // 0
|
||||||
throw std::runtime_error("Wrong key!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLKey CGuiHandler::numToDigit( SDLKey key )
|
SDLKey CGuiHandler::numToDigit( SDLKey key )
|
||||||
@ -548,11 +548,7 @@ bool CGuiHandler::isNumKey( SDLKey key, bool number )
|
|||||||
|
|
||||||
bool CGuiHandler::isArrowKey( SDLKey key )
|
bool CGuiHandler::isArrowKey( SDLKey key )
|
||||||
{
|
{
|
||||||
#ifdef VCMI_SDL1
|
|
||||||
return key >= SDLK_UP && key <= SDLK_LEFT;
|
|
||||||
#else
|
|
||||||
return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT;
|
return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGuiHandler::amIGuiThread()
|
bool CGuiHandler::amIGuiThread()
|
||||||
|
@ -515,9 +515,6 @@ void CSDL_Ext::update(SDL_Surface * what)
|
|||||||
if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch))
|
if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch))
|
||||||
logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError();
|
logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError();
|
||||||
#endif // VCMI_SDL1
|
#endif // VCMI_SDL1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color)
|
void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user