Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
ygopro
Commits
42772b77
Commit
42772b77
authored
May 06, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'patch-openmp' of github.com:mercury233/ygopro into develop
parents
5ba8db12
1ab9382f
Pipeline
#35966
failed with stages
in 5 minutes and 55 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
29 deletions
+86
-29
gframe/image_manager.cpp
gframe/image_manager.cpp
+71
-29
gframe/image_manager.h
gframe/image_manager.h
+12
-0
gframe/premake5.lua
gframe/premake5.lua
+3
-0
No files found.
gframe/image_manager.cpp
View file @
42772b77
#include "image_manager.h"
#include "image_manager.h"
#include "game.h"
#include "game.h"
#include <thread>
#include "myfilesystem.h"
#include "myfilesystem.h"
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
#include <thread>
#endif
#ifdef _OPENMP
#include <omp.h>
#endif
namespace
ygo
{
namespace
ygo
{
...
@@ -24,8 +29,10 @@ bool ImageManager::Initial() {
...
@@ -24,8 +29,10 @@ bool ImageManager::Initial() {
tUnknownFit
=
nullptr
;
tUnknownFit
=
nullptr
;
tUnknownThumb
=
nullptr
;
tUnknownThumb
=
nullptr
;
tBigPicture
=
nullptr
;
tBigPicture
=
nullptr
;
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
tLoading
=
nullptr
;
tLoading
=
nullptr
;
tThumbLoadingThreadRunning
=
false
;
tThumbLoadingThreadRunning
=
false
;
#endif
tAct
=
GetRandomImage
(
TEXTURE_ACTIVATE
);
tAct
=
GetRandomImage
(
TEXTURE_ACTIVATE
);
tAttack
=
GetRandomImage
(
TEXTURE_ATTACK
);
tAttack
=
GetRandomImage
(
TEXTURE_ATTACK
);
if
(
!
tAct
)
if
(
!
tAct
)
...
@@ -134,7 +141,11 @@ void ImageManager::ClearTexture() {
...
@@ -134,7 +141,11 @@ void ImageManager::ClearTexture() {
driver
->
removeTexture
(
tit
->
second
);
driver
->
removeTexture
(
tit
->
second
);
}
}
for
(
auto
tit
=
tThumb
.
begin
();
tit
!=
tThumb
.
end
();
++
tit
)
{
for
(
auto
tit
=
tThumb
.
begin
();
tit
!=
tThumb
.
end
();
++
tit
)
{
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
if
(
tit
->
second
&&
tit
->
second
!=
tLoading
)
if
(
tit
->
second
&&
tit
->
second
!=
tLoading
)
#else
if
(
tit
->
second
)
#endif
driver
->
removeTexture
(
tit
->
second
);
driver
->
removeTexture
(
tit
->
second
);
}
}
if
(
tBigPicture
!=
nullptr
)
{
if
(
tBigPicture
!=
nullptr
)
{
...
@@ -144,12 +155,14 @@ void ImageManager::ClearTexture() {
...
@@ -144,12 +155,14 @@ void ImageManager::ClearTexture() {
tMap
[
0
].
clear
();
tMap
[
0
].
clear
();
tMap
[
1
].
clear
();
tMap
[
1
].
clear
();
tThumb
.
clear
();
tThumb
.
clear
();
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
tThumbLoadingMutex
.
lock
();
tThumbLoadingMutex
.
lock
();
tThumbLoading
.
clear
();
tThumbLoading
.
clear
();
while
(
!
tThumbLoadingCodes
.
empty
())
while
(
!
tThumbLoadingCodes
.
empty
())
tThumbLoadingCodes
.
pop
();
tThumbLoadingCodes
.
pop
();
tThumbLoadingThreadRunning
=
false
;
tThumbLoadingThreadRunning
=
false
;
tThumbLoadingMutex
.
unlock
();
tThumbLoadingMutex
.
unlock
();
#endif
tFields
.
clear
();
tFields
.
clear
();
}
}
void
ImageManager
::
RemoveTexture
(
int
code
)
{
void
ImageManager
::
RemoveTexture
(
int
code
)
{
...
@@ -191,11 +204,13 @@ void ImageManager::ResizeTexture() {
...
@@ -191,11 +204,13 @@ void ImageManager::ResizeTexture() {
driver
->
removeTexture
(
tUnknown
);
driver
->
removeTexture
(
tUnknown
);
driver
->
removeTexture
(
tUnknownFit
);
driver
->
removeTexture
(
tUnknownFit
);
driver
->
removeTexture
(
tUnknownThumb
);
driver
->
removeTexture
(
tUnknownThumb
);
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
driver
->
removeTexture
(
tLoading
);
driver
->
removeTexture
(
tLoading
);
tLoading
=
GetTextureFromFile
(
"textures/cover.jpg"
,
imgWidthThumb
,
imgHeightThumb
);
#endif
tUnknown
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
CARD_IMG_WIDTH
,
CARD_IMG_HEIGHT
);
tUnknown
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
CARD_IMG_WIDTH
,
CARD_IMG_HEIGHT
);
tUnknownFit
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
imgWidthFit
,
imgHeightFit
);
tUnknownFit
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
imgWidthFit
,
imgHeightFit
);
tUnknownThumb
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
imgWidthThumb
,
imgHeightThumb
);
tUnknownThumb
=
GetTextureFromFile
(
"textures/unknown.jpg"
,
imgWidthThumb
,
imgHeightThumb
);
tLoading
=
GetTextureFromFile
(
"textures/cover.jpg"
,
imgWidthThumb
,
imgHeightThumb
);
driver
->
removeTexture
(
tBackGround
);
driver
->
removeTexture
(
tBackGround
);
tBackGround
=
GetRandomImage
(
TEXTURE_DUEL
,
bgWidth
,
bgHeight
);
tBackGround
=
GetRandomImage
(
TEXTURE_DUEL
,
bgWidth
,
bgHeight
);
if
(
!
tBackGround
)
if
(
!
tBackGround
)
...
@@ -221,25 +236,27 @@ void ImageManager::ResizeTexture() {
...
@@ -221,25 +236,27 @@ void ImageManager::ResizeTexture() {
}
}
// function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
// 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
)
{
double
sx
,
sy
,
minsx
,
maxsx
,
minsy
,
maxsy
,
area
,
ra
,
ga
,
ba
,
aa
,
pw
,
ph
,
pa
;
const
irr
::
core
::
dimension2d
<
irr
::
u32
>
srcDim
=
src
->
getDimension
();
irr
::
u32
dy
,
dx
;
const
irr
::
core
::
dimension2d
<
irr
::
u32
>
destDim
=
dest
->
getDimension
();
irr
::
video
::
SColor
pxl
;
// Cache
rectsngle boundarie
s.
// Cache
scale ratio
s.
double
sw
=
src
->
getDimension
().
Width
*
1.0
;
const
double
rx
=
(
double
)
srcDim
.
Width
/
destDim
.
Width
;
double
sh
=
src
->
getDimension
().
Height
*
1.0
;
const
double
ry
=
(
double
)
srcDim
.
Height
/
destDim
.
Height
;
// Walk each destination image pixel.
#pragma omp parallel
// Note: loop y around x for better cache locality.
{
irr
::
core
::
dimension2d
<
irr
::
u32
>
dim
=
dest
->
getDimension
();
double
sx
,
sy
,
minsx
,
maxsx
,
minsy
,
maxsy
,
area
,
ra
,
ga
,
ba
,
aa
,
pw
,
ph
,
pa
;
for
(
dy
=
0
;
dy
<
dim
.
Height
;
dy
++
)
irr
::
video
::
SColor
pxl
,
npxl
;
for
(
dx
=
0
;
dx
<
dim
.
Width
;
dx
++
)
{
// Walk each destination image pixel.
#pragma omp for schedule(dynamic)
for
(
irr
::
s32
dy
=
0
;
dy
<
destDim
.
Height
;
dy
++
)
{
for
(
irr
::
s32
dx
=
0
;
dx
<
destDim
.
Width
;
dx
++
)
{
// Calculate floating-point source rectangle bounds.
// Calculate floating-point source rectangle bounds.
minsx
=
dx
*
sw
/
dim
.
Width
;
minsx
=
dx
*
rx
;
maxsx
=
minsx
+
sw
/
dim
.
Width
;
maxsx
=
minsx
+
rx
;
minsy
=
dy
*
sh
/
dim
.
Height
;
minsy
=
dy
*
ry
;
maxsy
=
minsy
+
sh
/
dim
.
Height
;
maxsy
=
minsy
+
ry
;
// Total area, and integral of r, g, b values over that area,
// Total area, and integral of r, g, b values over that area,
// initialized to zero, to be summed up in next loops.
// initialized to zero, to be summed up in next loops.
...
@@ -250,9 +267,8 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
...
@@ -250,9 +267,8 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
aa
=
0
;
aa
=
0
;
// Loop over the integral pixel positions described by those bounds.
// Loop over the integral pixel positions described by those bounds.
for
(
sy
=
floor
(
minsy
);
sy
<
maxsy
;
sy
++
)
for
(
sy
=
floor
(
minsy
);
sy
<
maxsy
;
sy
++
)
{
for
(
sx
=
floor
(
minsx
);
sx
<
maxsx
;
sx
++
)
{
for
(
sx
=
floor
(
minsx
);
sx
<
maxsx
;
sx
++
)
{
// Calculate width, height, then area of dest pixel
// Calculate width, height, then area of dest pixel
// that's covered by this source pixel.
// that's covered by this source pixel.
pw
=
1
;
pw
=
1
;
...
@@ -276,21 +292,20 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
...
@@ -276,21 +292,20 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
ba
+=
pa
*
pxl
.
getBlue
();
ba
+=
pa
*
pxl
.
getBlue
();
aa
+=
pa
*
pxl
.
getAlpha
();
aa
+=
pa
*
pxl
.
getAlpha
();
}
}
}
// Set the destination image pixel to the average color.
// Set the destination image pixel to the average color.
if
(
area
>
0
)
{
if
(
area
>
0
)
{
pxl
.
setRed
(
ra
/
area
+
0.5
);
npxl
.
set
((
irr
::
u32
)(
aa
/
area
+
0.5
),
pxl
.
setGreen
(
ga
/
area
+
0.5
);
(
irr
::
u32
)(
ra
/
area
+
0.5
),
pxl
.
setBlue
(
ba
/
area
+
0.5
);
(
irr
::
u32
)(
ga
/
area
+
0.5
),
pxl
.
setAlpha
(
aa
/
area
+
0.5
);
(
irr
::
u32
)(
ba
/
area
+
0.5
)
);
}
else
{
}
else
{
pxl
.
setRed
(
0
);
npxl
.
set
(
0
);
pxl
.
setGreen
(
0
);
pxl
.
setBlue
(
0
);
pxl
.
setAlpha
(
0
);
}
}
dest
->
setPixel
(
dx
,
dy
,
pxl
);
dest
->
setPixel
(
dx
,
dy
,
n
pxl
);
}
}
}
}
// end of parallel region
}
}
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureFromFile
(
const
char
*
file
,
irr
::
s32
width
,
irr
::
s32
height
)
{
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureFromFile
(
const
char
*
file
,
irr
::
s32
width
,
irr
::
s32
height
)
{
if
(
mainGame
->
gameConf
.
use_image_scale
)
{
if
(
mainGame
->
gameConf
.
use_image_scale
)
{
...
@@ -392,6 +407,7 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
...
@@ -392,6 +407,7 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
tBigPicture
=
texture
;
tBigPicture
=
texture
;
return
texture
;
return
texture
;
}
}
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
int
ImageManager
::
LoadThumbThread
()
{
int
ImageManager
::
LoadThumbThread
()
{
while
(
true
)
{
while
(
true
)
{
imageManager
.
tThumbLoadingMutex
.
lock
();
imageManager
.
tThumbLoadingMutex
.
lock
();
...
@@ -479,9 +495,34 @@ int ImageManager::LoadThumbThread() {
...
@@ -479,9 +495,34 @@ int ImageManager::LoadThumbThread() {
imageManager
.
tThumbLoadingMutex
.
unlock
();
imageManager
.
tThumbLoadingMutex
.
unlock
();
return
0
;
return
0
;
}
}
#endif // YGOPRO_USE_THUMB_LOAD_THERAD
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureThumb
(
int
code
)
{
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureThumb
(
int
code
)
{
if
(
code
==
0
)
if
(
code
==
0
)
return
tUnknownThumb
;
return
tUnknownThumb
;
#ifndef YGOPRO_USE_THUMB_LOAD_THERAD
auto
tit
=
tThumb
.
find
(
code
);
if
(
tit
==
tThumb
.
end
())
{
char
file
[
256
];
std
::
snprintf
(
file
,
sizeof
file
,
"expansions/pics/thumbnail/%d.jpg"
,
code
);
int
width
=
CARD_THUMB_WIDTH
*
mainGame
->
xScale
;
int
height
=
CARD_THUMB_HEIGHT
*
mainGame
->
yScale
;
irr
::
video
::
ITexture
*
img
=
GetTextureFromFile
(
file
,
width
,
height
);
if
(
img
==
NULL
)
{
std
::
snprintf
(
file
,
sizeof
file
,
"pics/thumbnail/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
}
if
(
img
==
NULL
&&
mainGame
->
gameConf
.
use_image_scale
)
{
std
::
snprintf
(
file
,
sizeof
file
,
"expansions/pics/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
if
(
img
==
NULL
)
{
std
::
snprintf
(
file
,
sizeof
file
,
"pics/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
}
}
tThumb
[
code
]
=
img
;
return
(
img
==
NULL
)
?
tUnknownThumb
:
img
;
}
#else // YGOPRO_USE_THUMB_LOAD_THERAD
imageManager
.
tThumbLoadingMutex
.
lock
();
imageManager
.
tThumbLoadingMutex
.
lock
();
auto
lit
=
tThumbLoading
.
find
(
code
);
auto
lit
=
tThumbLoading
.
find
(
code
);
if
(
lit
!=
tThumbLoading
.
end
())
{
if
(
lit
!=
tThumbLoading
.
end
())
{
...
@@ -509,6 +550,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
...
@@ -509,6 +550,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
imageManager
.
tThumbLoadingMutex
.
unlock
();
imageManager
.
tThumbLoadingMutex
.
unlock
();
return
tLoading
;
return
tLoading
;
}
}
#endif // YGOPRO_USE_THUMB_LOAD_THERAD
if
(
tit
->
second
)
if
(
tit
->
second
)
return
tit
->
second
;
return
tit
->
second
;
else
else
...
...
gframe/image_manager.h
View file @
42772b77
#ifndef IMAGEMANAGER_H
#ifndef IMAGEMANAGER_H
#define IMAGEMANAGER_H
#define IMAGEMANAGER_H
#ifndef _OPENMP
#define YGOPRO_USE_THUMB_LOAD_THERAD
#endif
#include "config.h"
#include "config.h"
#include "data_manager.h"
#include "data_manager.h"
#include <unordered_map>
#include <unordered_map>
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
#include <queue>
#include <queue>
#include <mutex>
#include <mutex>
#endif
namespace
ygo
{
namespace
ygo
{
...
@@ -28,15 +34,19 @@ public:
...
@@ -28,15 +34,19 @@ public:
irr
::
video
::
ITexture
*
GetBigPicture
(
int
code
,
float
zoom
);
irr
::
video
::
ITexture
*
GetBigPicture
(
int
code
,
float
zoom
);
irr
::
video
::
ITexture
*
GetTextureThumb
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureThumb
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureField
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureField
(
int
code
);
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
static
int
LoadThumbThread
();
static
int
LoadThumbThread
();
#endif
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tMap
[
2
];
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tMap
[
2
];
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tThumb
;
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tThumb
;
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tFields
;
std
::
unordered_map
<
int
,
irr
::
video
::
ITexture
*>
tFields
;
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
std
::
unordered_map
<
int
,
irr
::
video
::
IImage
*>
tThumbLoading
;
std
::
unordered_map
<
int
,
irr
::
video
::
IImage
*>
tThumbLoading
;
std
::
queue
<
int
>
tThumbLoadingCodes
;
std
::
queue
<
int
>
tThumbLoadingCodes
;
std
::
mutex
tThumbLoadingMutex
;
std
::
mutex
tThumbLoadingMutex
;
bool
tThumbLoadingThreadRunning
;
bool
tThumbLoadingThreadRunning
;
#endif
irr
::
IrrlichtDevice
*
device
;
irr
::
IrrlichtDevice
*
device
;
irr
::
video
::
IVideoDriver
*
driver
;
irr
::
video
::
IVideoDriver
*
driver
;
irr
::
video
::
ITexture
*
tCover
[
4
];
irr
::
video
::
ITexture
*
tCover
[
4
];
...
@@ -44,7 +54,9 @@ public:
...
@@ -44,7 +54,9 @@ public:
irr
::
video
::
ITexture
*
tUnknownFit
;
irr
::
video
::
ITexture
*
tUnknownFit
;
irr
::
video
::
ITexture
*
tUnknownThumb
;
irr
::
video
::
ITexture
*
tUnknownThumb
;
irr
::
video
::
ITexture
*
tBigPicture
;
irr
::
video
::
ITexture
*
tBigPicture
;
#ifdef YGOPRO_USE_THUMB_LOAD_THERAD
irr
::
video
::
ITexture
*
tLoading
;
irr
::
video
::
ITexture
*
tLoading
;
#endif
irr
::
video
::
ITexture
*
tAct
;
irr
::
video
::
ITexture
*
tAct
;
irr
::
video
::
ITexture
*
tAttack
;
irr
::
video
::
ITexture
*
tAttack
;
irr
::
video
::
ITexture
*
tNegated
;
irr
::
video
::
ITexture
*
tNegated
;
...
...
gframe/premake5.lua
View file @
42772b77
...
@@ -5,6 +5,7 @@ project "YGOPro"
...
@@ -5,6 +5,7 @@ project "YGOPro"
kind
"WindowedApp"
kind
"WindowedApp"
cppdialect
"C++14"
cppdialect
"C++14"
rtti
"Off"
rtti
"Off"
openmp
"On"
files
{
"*.cpp"
,
"*.h"
,
"CGUISkinSystem/*.cpp"
,
"CGUISkinSystem/*.h"
,
"CXMLRegistry/*.cpp"
,
"CXMLRegistry/*.h"
}
files
{
"*.cpp"
,
"*.h"
,
"CGUISkinSystem/*.cpp"
,
"CGUISkinSystem/*.h"
,
"CXMLRegistry/*.cpp"
,
"CXMLRegistry/*.h"
}
includedirs
{
"../ocgcore"
}
includedirs
{
"../ocgcore"
}
...
@@ -83,6 +84,7 @@ project "YGOPro"
...
@@ -83,6 +84,7 @@ project "YGOPro"
filter
"not system:windows"
filter
"not system:windows"
links
{
"event_pthreads"
,
"dl"
,
"pthread"
,
"resolv"
}
links
{
"event_pthreads"
,
"dl"
,
"pthread"
,
"resolv"
}
filter
"system:macosx"
filter
"system:macosx"
openmp
"Off"
links
{
"z"
}
links
{
"z"
}
defines
{
"GL_SILENCE_DEPRECATION"
}
defines
{
"GL_SILENCE_DEPRECATION"
}
if
MAC_ARM
then
if
MAC_ARM
then
...
@@ -95,6 +97,7 @@ project "YGOPro"
...
@@ -95,6 +97,7 @@ project "YGOPro"
filter
"system:linux"
filter
"system:linux"
linkoptions
{
"-static-libstdc++"
,
"-static-libgcc"
}
linkoptions
{
"-static-libstdc++"
,
"-static-libgcc"
}
links
{
"GL"
,
"X11"
,
"Xxf86vm"
}
links
{
"GL"
,
"X11"
,
"Xxf86vm"
}
linkoptions
{
"-fopenmp"
}
if
USE_AUDIO
and
AUDIO_LIB
==
"irrklang"
then
if
USE_AUDIO
and
AUDIO_LIB
==
"irrklang"
then
links
{
"IrrKlang"
}
links
{
"IrrKlang"
}
linkoptions
{
IRRKLANG_LINK_RPATH
}
linkoptions
{
IRRKLANG_LINK_RPATH
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment