Commit b150b878 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master' into develop

parents 15e7e2c4 fcebe3ee
#include "image_manager.h"
#include "game.h"
#include <cmath>
#include <thread>
#ifdef _OPENMP
#include <omp.h>
......@@ -121,57 +122,61 @@ void ImageManager::ResizeTexture() {
}
/** Scale image using nearest neighbor anti-aliasing.
* Function by Warr1024, from https://github.com/minetest/minetest/issues/2419, modified. */
void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
void imageScaleNNAA(irr::video::IImage* src, irr::video::IImage* dest, bool use_threading) {
const auto& srcDim = src->getDimension();
const auto& destDim = dest->getDimension();
if (destDim.Width == 0 || destDim.Height == 0)
return;
// Cache scale ratios.
const double rx = (double)srcDim.Width / destDim.Width;
const double ry = (double)srcDim.Height / destDim.Height;
#pragma omp parallel if(mainGame->gameConf.use_image_scale_multi_thread)
#pragma omp parallel if(use_threading)
{
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
irr::video::SColor pxl, npxl;
// Walk each destination image pixel.
#pragma omp for schedule(dynamic)
for(irr::s32 dy = 0; dy < (irr::s32)destDim.Height; dy++) {
for(irr::s32 dx = 0; dx < (irr::s32)destDim.Width; dx++) {
// Calculate floating-point source rectangle bounds.
minsx = dx * rx;
maxsx = minsx + rx;
minsy = dy * ry;
maxsy = minsy + ry;
double minsx = dx * rx;
double maxsx = minsx + rx;
double minsy = dy * ry;
double maxsy = minsy + ry;
irr::u32 sx_begin = (irr::u32)std::floor(minsx);
irr::u32 sx_end = (irr::u32)std::ceil(maxsx);
if (sx_end > srcDim.Width)
sx_end = srcDim.Width;
irr::u32 sy_begin = (irr::u32)std::floor(minsy);
irr::u32 sy_end = (irr::u32)std::ceil(maxsy);
if (sy_end > srcDim.Height)
sy_end = srcDim.Height;
// Total area, and integral of r, g, b values over that area,
// initialized to zero, to be summed up in next loops.
area = 0;
ra = 0;
ga = 0;
ba = 0;
aa = 0;
double area = 0, ra = 0, ga = 0, ba = 0, aa = 0;
irr::video::SColor pxl, npxl;
// Loop over the integral pixel positions described by those bounds.
for(sy = floor(minsy); sy < maxsy; sy++) {
for(sx = floor(minsx); sx < maxsx; sx++) {
for(irr::u32 sy = sy_begin; sy < sy_end; sy++) {
for(irr::u32 sx = sx_begin; sx < sx_end; sx++) {
// Calculate width, height, then area of dest pixel
// that's covered by this source pixel.
pw = 1;
double pw = 1;
if(minsx > sx)
pw += sx - minsx;
if(maxsx < (sx + 1))
pw += maxsx - sx - 1;
ph = 1;
double ph = 1;
if(minsy > sy)
ph += sy - minsy;
if(maxsy < (sy + 1))
ph += maxsy - sy - 1;
pa = pw * ph;
double pa = pw * ph;
// Get source pixel and add it to totals, weighted
// by covered area and alpha.
pxl = src->getPixel((irr::u32)sx, (irr::u32)sy);
pxl = src->getPixel(sx, sy);
area += pa;
ra += pa * pxl.getRed();
ga += pa * pxl.getGreen();
......@@ -205,7 +210,7 @@ irr::video::ITexture* ImageManager::addTexture(const char* name, irr::video::IIm
texture = driver->addTexture(name, srcimg);
} else {
irr::video::IImage* destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<irr::u32>(width, height));
imageScaleNNAA(srcimg, destimg);
imageScaleNNAA(srcimg, destimg, mainGame->gameConf.use_image_scale_multi_thread);
texture = driver->addTexture(name, destimg);
destimg->drop();
}
......@@ -316,7 +321,7 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingMutex.unlock();
} else {
irr::video::IImage *destimg = imageManager.driver->createImage(img->getColorFormat(), irr::core::dimension2d<irr::u32>(width, height));
imageScaleNNAA(img, destimg);
imageScaleNNAA(img, destimg, mainGame->gameConf.use_image_scale_multi_thread);
img->drop();
imageManager.tThumbLoadingMutex.lock();
if(imageManager.tThumbLoadingThreadRunning)
......
......@@ -88,143 +88,142 @@ void SoundManager::PlaySoundEffect(int sound) {
#ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableSound->isChecked())
return;
char soundName[32];
std::string soundName;
switch(sound) {
case SOUND_SUMMON: {
strcpy(soundName, "summon");
soundName = "summon";
break;
}
case SOUND_SPECIAL_SUMMON: {
strcpy(soundName, "specialsummon");
soundName = "specialsummon";
break;
}
case SOUND_ACTIVATE: {
strcpy(soundName, "activate");
soundName = "activate";
break;
}
case SOUND_SET: {
strcpy(soundName, "set");
soundName = "set";
break;
}
case SOUND_FLIP: {
strcpy(soundName, "flip");
soundName = "flip";
break;
}
case SOUND_REVEAL: {
strcpy(soundName, "reveal");
soundName = "reveal";
break;
}
case SOUND_EQUIP: {
strcpy(soundName, "equip");
soundName = "equip";
break;
}
case SOUND_DESTROYED: {
strcpy(soundName, "destroyed");
soundName = "destroyed";
break;
}
case SOUND_BANISHED: {
strcpy(soundName, "banished");
soundName = "banished";
break;
}
case SOUND_TOKEN: {
strcpy(soundName, "token");
soundName = "token";
break;
}
case SOUND_NEGATE: {
strcpy(soundName, "negate");
soundName = "negate";
break;
}
case SOUND_ATTACK: {
strcpy(soundName, "attack");
soundName = "attack";
break;
}
case SOUND_DIRECT_ATTACK: {
strcpy(soundName, "directattack");
soundName = "directattack";
break;
}
case SOUND_DRAW: {
strcpy(soundName, "draw");
soundName = "draw";
break;
}
case SOUND_SHUFFLE: {
strcpy(soundName, "shuffle");
soundName = "shuffle";
break;
}
case SOUND_DAMAGE: {
strcpy(soundName, "damage");
soundName = "damage";
break;
}
case SOUND_RECOVER: {
strcpy(soundName, "gainlp");
soundName = "gainlp";
break;
}
case SOUND_COUNTER_ADD: {
strcpy(soundName, "addcounter");
soundName = "addcounter";
break;
}
case SOUND_COUNTER_REMOVE: {
strcpy(soundName, "removecounter");
soundName = "removecounter";
break;
}
case SOUND_COIN: {
strcpy(soundName, "coinflip");
soundName = "coinflip";
break;
}
case SOUND_DICE: {
strcpy(soundName, "diceroll");
soundName = "diceroll";
break;
}
case SOUND_NEXT_TURN: {
strcpy(soundName, "nextturn");
soundName = "nextturn";
break;
}
case SOUND_PHASE: {
strcpy(soundName, "phase");
soundName = "phase";
break;
}
case SOUND_MENU: {
strcpy(soundName, "menu");
soundName = "menu";
break;
}
case SOUND_BUTTON: {
strcpy(soundName, "button");
soundName = "button";
break;
}
case SOUND_INFO: {
strcpy(soundName, "info");
soundName = "info";
break;
}
case SOUND_QUESTION: {
strcpy(soundName, "question");
soundName = "question";
break;
}
case SOUND_CARD_PICK: {
strcpy(soundName, "cardpick");
soundName = "cardpick";
break;
}
case SOUND_CARD_DROP: {
strcpy(soundName, "carddrop");
soundName = "carddrop";
break;
}
case SOUND_PLAYER_ENTER: {
strcpy(soundName, "playerenter");
soundName = "playerenter";
break;
}
case SOUND_CHAT: {
strcpy(soundName, "chatmessage");
soundName = "chatmessage";
break;
}
default:
break;
return;
}
char soundPath[40];
mysnprintf(soundPath, "./sound/%s.wav", soundName);
std::string soundPath = "./sound/" + soundName + ".wav";
SetSoundVolume(mainGame->gameConf.sound_volume);
#ifdef YGOPRO_USE_MINIAUDIO
ma_engine_play_sound(&engineSound, soundPath, nullptr);
ma_engine_play_sound(&engineSound, soundPath.c_str(), nullptr);
#endif
#ifdef YGOPRO_USE_IRRKLANG
engineSound->play2D(soundPath);
engineSound->play2D(soundPath.c_str());
#endif
#endif // YGOPRO_USE_AUDIO
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment