Commit fd5f1af5 authored by nanahira's avatar nanahira

update random image

parent e871b745
...@@ -60,10 +60,12 @@ bool ImageManager::Initial() { ...@@ -60,10 +60,12 @@ bool ImageManager::Initial() {
irr::video::ITexture* ImageManager::GetRandomImage(int image_type) { irr::video::ITexture* ImageManager::GetRandomImage(int image_type) {
int count = ImageList[image_type].size(); int count = ImageList[image_type].size();
if(count <= 0) if(count <= 0)
return 0; return NULL;
char ImageName[1024]; char ImageName[1024];
wchar_t fname[1024]; wchar_t fname[1024];
int image_id = rand() % count; if(saved_image_id[image_type] == -1)
saved_image_id[image_type] = rand() % count;
int image_id = saved_image_id[image_type];
auto name = ImageList[image_type][image_id].c_str(); auto name = ImageList[image_type][image_id].c_str();
myswprintf(fname, L"./textures/%ls", name); myswprintf(fname, L"./textures/%ls", name);
BufferIO::EncodeUTF8(fname, ImageName); BufferIO::EncodeUTF8(fname, ImageName);
...@@ -72,10 +74,12 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type) { ...@@ -72,10 +74,12 @@ irr::video::ITexture* ImageManager::GetRandomImage(int image_type) {
irr::video::ITexture* ImageManager::GetRandomImage(int image_type, s32 width, s32 height) { irr::video::ITexture* ImageManager::GetRandomImage(int image_type, s32 width, s32 height) {
int count = ImageList[image_type].size(); int count = ImageList[image_type].size();
if(count <= 0) if(count <= 0)
return 0; return NULL;
char ImageName[1024]; char ImageName[1024];
wchar_t fname[1024]; wchar_t fname[1024];
int image_id = rand() % count; if(saved_image_id[image_type] == -1)
saved_image_id[image_type] = rand() % count;
int image_id = saved_image_id[image_type];
auto name = ImageList[image_type][image_id].c_str(); auto name = ImageList[image_type][image_id].c_str();
myswprintf(fname, L"./textures/%ls", name); myswprintf(fname, L"./textures/%ls", name);
BufferIO::EncodeUTF8(fname, ImageName); BufferIO::EncodeUTF8(fname, ImageName);
...@@ -90,6 +94,10 @@ void ImageManager::RefreshRandomImageList() { ...@@ -90,6 +94,10 @@ void ImageManager::RefreshRandomImageList() {
RefreshImageDir(L"cover2/", TEXTURE_COVER_O); RefreshImageDir(L"cover2/", TEXTURE_COVER_O);
RefreshImageDir(L"attack/", TEXTURE_ATTACK); RefreshImageDir(L"attack/", TEXTURE_ATTACK);
RefreshImageDir(L"act/", TEXTURE_ACTIVATE); RefreshImageDir(L"act/", TEXTURE_ACTIVATE);
for(int i = 0; i < 7; ++ i) {
saved_image_id[i] = -1;
}
} }
void ImageManager::RefreshImageDir(std::wstring path, int image_type) { void ImageManager::RefreshImageDir(std::wstring path, int image_type) {
#ifdef _WIN32 #ifdef _WIN32
......
...@@ -10,6 +10,7 @@ namespace ygo { ...@@ -10,6 +10,7 @@ namespace ygo {
class ImageManager { class ImageManager {
public: public:
std::vector<std::wstring> ImageList[7]; std::vector<std::wstring> ImageList[7];
int saved_image_id[7];
bool Initial(); bool Initial();
//random image //random image
irr::video::ITexture* GetRandomImage(int image_type); irr::video::ITexture* GetRandomImage(int image_type);
......
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