106 lines
2.9 KiB
C
106 lines
2.9 KiB
C
|
|
#pragma once
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Map
|
|||
|
|
extern std::unordered_map<std::string, std::map<int,TexturePtr>>ImageRecObject;
|
|||
|
|
std::mutex ImageRecObjectmutex;
|
|||
|
|
|
|||
|
|
extern NPK_M* npk;
|
|||
|
|
|
|||
|
|
extern WThreadPool threadPool;
|
|||
|
|
|
|||
|
|
void ThreadPreloadImg_Success(std::string Name , SQInteger Scene)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ûص<C3BB>
|
|||
|
|
sq_pushroottable(v);
|
|||
|
|
sq_pushstring(v, _SST(Name.c_str()), -1);
|
|||
|
|
sq_get(v, -2);
|
|||
|
|
sq_pushroottable(v);
|
|||
|
|
sq_pushinteger(v, Scene);
|
|||
|
|
sq_call(v, 2, 0, 1);
|
|||
|
|
sq_pop(v, 2);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ThreadPreloadImgFunc(std::vector<std::string> ImgList, std::string Name , SQInteger Scene) {
|
|||
|
|
//<2F>ȱ<EFBFBD><C8B1><EFBFBD>һ<EFBFBD><D2BB> <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ص<EFBFBD>img<6D><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
std::vector<std::string> RealImgList;
|
|||
|
|
ImageRecObjectmutex.lock();
|
|||
|
|
for (auto it = ImgList.begin(); it != ImgList.end(); ++it) {
|
|||
|
|
std::string Iname = *it;
|
|||
|
|
if (!ImageRecObject.count(Iname)) {
|
|||
|
|
RealImgList.push_back(*it);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
ImageRecObjectmutex.unlock();
|
|||
|
|
|
|||
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>img <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱmap
|
|||
|
|
std::map<std::string ,std::map<int,TexturePtr>> TexturePtrVL;
|
|||
|
|
for (auto it = RealImgList.begin(); it != RealImgList.end(); ++it) {
|
|||
|
|
std::string imgpath = *it;
|
|||
|
|
IMG* img = npk->ReadNpkTable(imgpath);
|
|||
|
|
|
|||
|
|
for (int i = 0; i < img->png_sum; i++)
|
|||
|
|
{
|
|||
|
|
std::string RealTextureName = imgpath;
|
|||
|
|
|
|||
|
|
DWORD Height = img->lp_lplist[i].Height;
|
|||
|
|
DWORD Width = img->lp_lplist[i].Width;
|
|||
|
|
BYTE* Data = img->lp_lplist[i].PNGdata;
|
|||
|
|
|
|||
|
|
BinaryData data = { ((void*)Data) ,Height * Width * 4 };
|
|||
|
|
TexturePtr t = new Texture;
|
|||
|
|
t->Load(PixelSize(Width, Height), data, PixelFormat::Bpp32BGRA);
|
|||
|
|
t->SetUserData(&img->lp_lplist[i]);
|
|||
|
|
|
|||
|
|
TexturePtrVL[RealTextureName][i] = t;
|
|||
|
|
}
|
|||
|
|
npk->ReleaseNpkTable(img);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD> <20><>ֵmap
|
|||
|
|
ImageRecObjectmutex.lock();
|
|||
|
|
for (auto it = TexturePtrVL.begin(); it != TexturePtrVL.end(); it++) {
|
|||
|
|
if (!ImageRecObject.count(it->first)) {
|
|||
|
|
ImageRecObject[it->first] = it->second;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
ImageRecObjectmutex.unlock();
|
|||
|
|
|
|||
|
|
|
|||
|
|
auto f1 = std::bind(&ThreadPreloadImg_Success, Name , Scene);
|
|||
|
|
Application::GetInstance().PerformInMainThread(f1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F>̼߳<DFB3><CCBC><EFBFBD>Img<6D><67>Դ
|
|||
|
|
static SQInteger ThreadPreloadImg(HSQUIRRELVM v)
|
|||
|
|
{
|
|||
|
|
SQInteger Top = sq_gettop(v);
|
|||
|
|
if (Top <= 0)
|
|||
|
|
{
|
|||
|
|
sq_throwerror(v, _SST("Incorrect function argument"));
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::vector<std::string> ImgList;
|
|||
|
|
sq_pushnull(v); // null iterator
|
|||
|
|
while (SQ_SUCCEEDED(sq_next(v, 2)))
|
|||
|
|
{
|
|||
|
|
const SQChar* path;
|
|||
|
|
sq_getstring(v, -1, &path);
|
|||
|
|
ImgList.push_back((char*)path);
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>-1<><31>ֵ<EFBFBD><D6B5>-2<>Ǽ<EFBFBD>
|
|||
|
|
sq_pop(v, 2); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
|
}
|
|||
|
|
sq_pop(v, 1);
|
|||
|
|
|
|||
|
|
const SQChar* Name;
|
|||
|
|
sq_getstring(v, 3,&Name);
|
|||
|
|
|
|||
|
|
SQInteger SceneId;
|
|||
|
|
sq_getinteger(v, 4, &SceneId);
|
|||
|
|
|
|||
|
|
auto f1 = std::bind(&ThreadPreloadImgFunc, ImgList, (char*)Name, SceneId);
|
|||
|
|
|
|||
|
|
threadPool.concurrentRun(f1);
|
|||
|
|
|
|||
|
|
return 1;
|
|||
|
|
}
|