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
0
Merge Requests
0
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
YGOPRO-520DIY
ygopro
Commits
805ec687
Commit
805ec687
authored
May 25, 2020
by
mercury233
Committed by
GitHub
May 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use multi-thread in loading thumbnails (#2207)
parent
697a6f7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
17 deletions
+99
-17
gframe/drawing.cpp
gframe/drawing.cpp
+6
-1
gframe/image_manager.cpp
gframe/image_manager.cpp
+86
-16
gframe/image_manager.h
gframe/image_manager.h
+7
-0
No files found.
gframe/drawing.cpp
View file @
805ec687
...
@@ -1157,8 +1157,13 @@ void Game::DrawDeckBd() {
...
@@ -1157,8 +1157,13 @@ void Game::DrawDeckBd() {
DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
driver->draw2DRectangleOutline(Resize(804, 159, 1020, 630));
driver->draw2DRectangleOutline(Resize(804, 159, 1020, 630));
for
(
size_t
i
=
0
;
i
<
7
&&
i
+
scrFilter
->
getPos
()
<
deckBuilder
.
results
.
size
();
++
i
)
{
for(size_t i = 0; i <
9
&& i + scrFilter->getPos() < deckBuilder.results.size(); ++i) {
code_pointer ptr = deckBuilder.results[i + scrFilter->getPos()];
code_pointer ptr = deckBuilder.results[i + scrFilter->getPos()];
if(i >= 7)
{
imageManager.GetTextureThumb(ptr->second.code);
break;
}
if(deckBuilder.hovered_pos == 4 && deckBuilder.hovered_seq == (int)i)
if(deckBuilder.hovered_pos == 4 && deckBuilder.hovered_seq == (int)i)
driver->draw2DRectangle(0x80000000, Resize(806, 164 + i * 66, 1019, 230 + i * 66));
driver->draw2DRectangle(0x80000000, Resize(806, 164 + i * 66, 1019, 230 + i * 66));
DrawThumb(ptr, position2di(810, 165 + i * 66), deckBuilder.filterList);
DrawThumb(ptr, position2di(810, 165 + i * 66), deckBuilder.filterList);
...
...
gframe/image_manager.cpp
View file @
805ec687
...
@@ -15,6 +15,8 @@ bool ImageManager::Initial() {
...
@@ -15,6 +15,8 @@ bool ImageManager::Initial() {
tUnknown
=
NULL
;
tUnknown
=
NULL
;
tUnknownFit
=
NULL
;
tUnknownFit
=
NULL
;
tUnknownThumb
=
NULL
;
tUnknownThumb
=
NULL
;
tLoading
=
NULL
;
tThumbLoadingThreadRunning
=
false
;
tAct
=
driver
->
getTexture
(
"textures/act.png"
);
tAct
=
driver
->
getTexture
(
"textures/act.png"
);
tAttack
=
driver
->
getTexture
(
"textures/attack.png"
);
tAttack
=
driver
->
getTexture
(
"textures/attack.png"
);
tChain
=
driver
->
getTexture
(
"textures/chain.png"
);
tChain
=
driver
->
getTexture
(
"textures/chain.png"
);
...
@@ -55,12 +57,18 @@ void ImageManager::ClearTexture() {
...
@@ -55,12 +57,18 @@ 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
)
{
if
(
tit
->
second
)
if
(
tit
->
second
&&
tit
->
second
!=
tLoading
)
driver
->
removeTexture
(
tit
->
second
);
driver
->
removeTexture
(
tit
->
second
);
}
}
tMap
[
0
].
clear
();
tMap
[
0
].
clear
();
tMap
[
1
].
clear
();
tMap
[
1
].
clear
();
tThumb
.
clear
();
tThumb
.
clear
();
tThumbLoadingMutex
.
lock
();
tThumbLoading
.
clear
();
while
(
!
tThumbLoadingCodes
.
empty
())
tThumbLoadingCodes
.
pop
();
tThumbLoadingThreadRunning
=
false
;
tThumbLoadingMutex
.
unlock
();
tFields
.
clear
();
tFields
.
clear
();
}
}
void
ImageManager
::
RemoveTexture
(
int
code
)
{
void
ImageManager
::
RemoveTexture
(
int
code
)
{
...
@@ -96,9 +104,11 @@ void ImageManager::ResizeTexture() {
...
@@ -96,9 +104,11 @@ void ImageManager::ResizeTexture() {
driver
->
removeTexture
(
tUnknown
);
driver
->
removeTexture
(
tUnknown
);
driver
->
removeTexture
(
tUnknownFit
);
driver
->
removeTexture
(
tUnknownFit
);
driver
->
removeTexture
(
tUnknownThumb
);
driver
->
removeTexture
(
tUnknownThumb
);
driver
->
removeTexture
(
tLoading
);
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
=
GetTextureFromFile
(
"textures/bg.jpg"
,
bgWidth
,
bgHeight
);
tBackGround
=
GetTextureFromFile
(
"textures/bg.jpg"
,
bgWidth
,
bgHeight
);
driver
->
removeTexture
(
tBackGround_menu
);
driver
->
removeTexture
(
tBackGround_menu
);
...
@@ -236,30 +246,90 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
...
@@ -236,30 +246,90 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
else
else
return
mainGame
->
gameConf
.
use_image_scale
?
(
fit
?
tUnknownFit
:
tUnknown
)
:
GetTextureThumb
(
code
);
return
mainGame
->
gameConf
.
use_image_scale
?
(
fit
?
tUnknownFit
:
tUnknown
)
:
GetTextureThumb
(
code
);
}
}
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureThumb
(
int
code
)
{
int
ImageManager
::
LoadThumbThread
()
{
if
(
code
==
0
)
while
(
true
)
{
return
tUnknownThumb
;
imageManager
.
tThumbLoadingMutex
.
lock
();
auto
tit
=
tThumb
.
find
(
code
);
int
code
=
imageManager
.
tThumbLoadingCodes
.
front
();
int
width
=
CARD_THUMB_WIDTH
*
mainGame
->
xScale
;
imageManager
.
tThumbLoadingCodes
.
pop
();
int
height
=
CARD_THUMB_HEIGHT
*
mainGame
->
yScale
;
imageManager
.
tThumbLoadingMutex
.
unlock
();
if
(
tit
==
tThumb
.
end
())
{
char
file
[
256
];
char
file
[
256
];
sprintf
(
file
,
"expansions/pics/thumbnail/%d.jpg"
,
code
);
sprintf
(
file
,
"expansions/pics/thumbnail/%d.jpg"
,
code
);
irr
::
video
::
I
Texture
*
img
=
GetTextureFromFile
(
file
,
width
,
height
);
irr
::
video
::
I
Image
*
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
if
(
img
==
NULL
)
{
if
(
img
==
NULL
)
{
sprintf
(
file
,
"pics/thumbnail/%d.jpg"
,
code
);
sprintf
(
file
,
"pics/thumbnail/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
}
}
if
(
img
==
NULL
&&
mainGame
->
gameConf
.
use_image_scale
)
{
if
(
img
==
NULL
&&
mainGame
->
gameConf
.
use_image_scale
)
{
sprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
sprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
if
(
img
==
NULL
)
{
}
sprintf
(
file
,
"pics/%d.jpg"
,
code
);
if
(
img
==
NULL
&&
mainGame
->
gameConf
.
use_image_scale
)
{
img
=
GetTextureFromFile
(
file
,
width
,
height
);
sprintf
(
file
,
"pics/%d.jpg"
,
code
);
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
}
if
(
img
!=
NULL
)
{
int
width
=
CARD_THUMB_WIDTH
*
mainGame
->
xScale
;
int
height
=
CARD_THUMB_HEIGHT
*
mainGame
->
yScale
;
if
(
img
->
getDimension
()
==
irr
::
core
::
dimension2d
<
u32
>
(
width
,
height
))
{
img
->
grab
();
imageManager
.
tThumbLoadingMutex
.
lock
();
if
(
imageManager
.
tThumbLoadingThreadRunning
)
imageManager
.
tThumbLoading
[
code
]
=
img
;
imageManager
.
tThumbLoadingMutex
.
unlock
();
}
else
{
irr
::
video
::
IImage
*
destimg
=
imageManager
.
driver
->
createImage
(
img
->
getColorFormat
(),
irr
::
core
::
dimension2d
<
u32
>
(
width
,
height
));
imageScaleNNAA
(
img
,
destimg
);
img
->
drop
();
destimg
->
grab
();
imageManager
.
tThumbLoadingMutex
.
lock
();
if
(
imageManager
.
tThumbLoadingThreadRunning
)
imageManager
.
tThumbLoading
[
code
]
=
destimg
;
imageManager
.
tThumbLoadingMutex
.
unlock
();
}
}
}
else
{
imageManager
.
tThumbLoadingMutex
.
lock
();
if
(
imageManager
.
tThumbLoadingThreadRunning
)
imageManager
.
tThumbLoading
[
code
]
=
NULL
;
imageManager
.
tThumbLoadingMutex
.
unlock
();
}
imageManager
.
tThumbLoadingMutex
.
lock
();
imageManager
.
tThumbLoadingThreadRunning
=
!
imageManager
.
tThumbLoadingCodes
.
empty
();
if
(
!
imageManager
.
tThumbLoadingThreadRunning
)
break
;
imageManager
.
tThumbLoadingMutex
.
unlock
();
}
imageManager
.
tThumbLoadingMutex
.
unlock
();
return
0
;
}
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureThumb
(
int
code
)
{
if
(
code
==
0
)
return
tUnknownThumb
;
imageManager
.
tThumbLoadingMutex
.
lock
();
auto
lit
=
tThumbLoading
.
find
(
code
);
if
(
lit
!=
tThumbLoading
.
end
())
{
if
(
lit
->
second
!=
NULL
)
{
char
file
[
256
];
sprintf
(
file
,
"pics/thumbnail/%d.jpg"
,
code
);
irr
::
video
::
ITexture
*
texture
=
driver
->
addTexture
(
file
,
lit
->
second
);
// textures must be added in the main thread due to OpenGL
lit
->
second
->
drop
();
tThumb
[
code
]
=
texture
;
}
else
{
tThumb
[
code
]
=
NULL
;
}
tThumbLoading
.
erase
(
lit
);
}
imageManager
.
tThumbLoadingMutex
.
unlock
();
auto
tit
=
tThumb
.
find
(
code
);
if
(
tit
==
tThumb
.
end
())
{
tThumb
[
code
]
=
tLoading
;
imageManager
.
tThumbLoadingMutex
.
lock
();
tThumbLoadingCodes
.
push
(
code
);
if
(
!
tThumbLoadingThreadRunning
)
{
tThumbLoadingThreadRunning
=
true
;
std
::
thread
(
LoadThumbThread
).
detach
();
}
}
tThumb
[
code
]
=
img
;
imageManager
.
tThumbLoadingMutex
.
unlock
()
;
return
(
img
==
NULL
)
?
tUnknownThumb
:
im
g
;
return
tLoadin
g
;
}
}
if
(
tit
->
second
)
if
(
tit
->
second
)
return
tit
->
second
;
return
tit
->
second
;
...
...
gframe/image_manager.h
View file @
805ec687
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "config.h"
#include "config.h"
#include "data_manager.h"
#include "data_manager.h"
#include <unordered_map>
#include <unordered_map>
#include <queue>
namespace
ygo
{
namespace
ygo
{
...
@@ -18,16 +19,22 @@ public:
...
@@ -18,16 +19,22 @@ public:
irr
::
video
::
ITexture
*
GetTexture
(
int
code
,
bool
fit
=
false
);
irr
::
video
::
ITexture
*
GetTexture
(
int
code
,
bool
fit
=
false
);
irr
::
video
::
ITexture
*
GetTextureThumb
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureThumb
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureField
(
int
code
);
irr
::
video
::
ITexture
*
GetTextureField
(
int
code
);
static
int
LoadThumbThread
();
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
;
std
::
unordered_map
<
int
,
irr
::
video
::
IImage
*>
tThumbLoading
;
std
::
queue
<
int
>
tThumbLoadingCodes
;
std
::
mutex
tThumbLoadingMutex
;
bool
tThumbLoadingThreadRunning
;
irr
::
IrrlichtDevice
*
device
;
irr
::
IrrlichtDevice
*
device
;
irr
::
video
::
IVideoDriver
*
driver
;
irr
::
video
::
IVideoDriver
*
driver
;
irr
::
video
::
ITexture
*
tCover
[
4
];
irr
::
video
::
ITexture
*
tCover
[
4
];
irr
::
video
::
ITexture
*
tUnknown
;
irr
::
video
::
ITexture
*
tUnknown
;
irr
::
video
::
ITexture
*
tUnknownFit
;
irr
::
video
::
ITexture
*
tUnknownFit
;
irr
::
video
::
ITexture
*
tUnknownThumb
;
irr
::
video
::
ITexture
*
tUnknownThumb
;
irr
::
video
::
ITexture
*
tLoading
;
irr
::
video
::
ITexture
*
tAct
;
irr
::
video
::
ITexture
*
tAct
;
irr
::
video
::
ITexture
*
tAttack
;
irr
::
video
::
ITexture
*
tAttack
;
irr
::
video
::
ITexture
*
tNegated
;
irr
::
video
::
ITexture
*
tNegated
;
...
...
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