diff --git a/common/version.h b/common/version.h index adb0688a..86192915 100644 --- a/common/version.h +++ b/common/version.h @@ -2,8 +2,8 @@ #define MIHAJONG_MAJOR_VER 2 #define MIHAJONG_MINOR_VER 4 -#define MIHAJONG_PATCH_VER 3 -#define MIHAJONG_VER "2.4.3" +#define MIHAJONG_PATCH_VER 4 +#define MIHAJONG_VER "2.4.4" #define MJCORE_MAJOR_VER 2 #define MJCORE_MINOR_VER 4 @@ -32,8 +32,8 @@ #define GRAPHIC_MAJOR_VER 2 #define GRAPHIC_MINOR_VER 4 -#define GRAPHIC_PATCH_VER 2 -#define GRAPHIC_VER "2.4.2" +#define GRAPHIC_PATCH_VER 4 +#define GRAPHIC_VER "2.4.4" #define CONFIG_MAJOR_VER 2 #define CONFIG_MINOR_VER 4 diff --git a/graphic/loadtex.cpp b/graphic/loadtex.cpp index 02dd36b3..594fc9ed 100644 --- a/graphic/loadtex.cpp +++ b/graphic/loadtex.cpp @@ -16,7 +16,7 @@ namespace mihajong_graphic { //namespace { - std::map Textures; + std::map > Textures; #if !defined(_WIN32) || !defined(WITH_DIRECTX) std::map TextureWidth; std::map TextureHeight; @@ -29,11 +29,11 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { #endif auto resourceID = reinterpret_cast(resource); assert((resourceID & 0xffff0000) == 0); // 上位ワードが0なら文字列ではなくリソース番号とみなされる(Win32APIの仕様) - if (Textures.find(resourceID) != Textures.end()) { // 既にロード済みのテクスチャ + if (Textures[reinterpret_cast(device)].find(resourceID) != Textures[reinterpret_cast(device)].end()) { // 既にロード済みのテクスチャ #if defined(_WIN32) && defined(WITH_DIRECTX) Textures[resourceID]->AddRef(); #endif - *texture = Textures[resourceID]; + *texture = Textures[reinterpret_cast(device)][resourceID]; return; } else { // ロードされていない場合 #ifdef _WIN32 @@ -46,16 +46,16 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { DWORD pngSize = SizeofResource(GraphicDLL, Resource); void* pngData = LockResource(ResourceMem); #if defined(_WIN32) && defined(WITH_DIRECTX) - Textures[resourceID] = nullptr; + Textures[reinterpret_cast(device)][resourceID] = nullptr; HRESULT result = D3DXCreateTextureFromFileInMemoryEx(device, pngData, pngSize, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER, D3DX_DEFAULT, - 0x00000000, nullptr, nullptr, &(Textures[resourceID])); + 0x00000000, nullptr, nullptr, &(Textures[reinterpret_cast(device)][resourceID])); UnlockResource(ResourceMem); switch (result) { case D3D_OK: - Textures[resourceID]->AddRef(); - *texture = Textures[resourceID]; + Textures[reinterpret_cast(device)][resourceID]->AddRef(); + *texture = Textures[reinterpret_cast(device)][resourceID]; return; // Congratulations, your texture has been loaded. case D3DERR_NOTAVAILABLE: throw TextureCreationError("", resourceID); @@ -71,12 +71,12 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { throw TextureCreationError("原因不明のエラーです。", resourceID); } #else - Textures[resourceID] = 0; + Textures[reinterpret_cast(device)][resourceID] = 0; glEnable(GL_TEXTURE_2D); - glGenTextures(1, &Textures[resourceID]); - TextureWidth[Textures[resourceID]] = - TextureHeight[Textures[resourceID]] = 0; - glBindTexture(GL_TEXTURE_2D, Textures[resourceID]); + glGenTextures(1, &Textures[reinterpret_cast(device)][resourceID]); + TextureWidth[Textures[reinterpret_cast(device)][resourceID]] = + TextureHeight[Textures[reinterpret_cast(device)][resourceID]] = 0; + glBindTexture(GL_TEXTURE_2D, Textures[reinterpret_cast(device)][resourceID]); HGLOBAL resBuf = GlobalAlloc(GMEM_MOVEABLE, pngSize); void* pResBuf = GlobalLock(resBuf); Bitmap* bitmap = nullptr; @@ -95,8 +95,8 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.Width, data.Height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, data.Scan0); bitmap->UnlockBits(&data); - TextureWidth[Textures[resourceID]] = data.Width; - TextureHeight[Textures[resourceID]] = data.Height; + TextureWidth[Textures[reinterpret_cast(device)][resourceID]] = data.Width; + TextureHeight[Textures[reinterpret_cast(device)][resourceID]] = data.Height; } } glBindTexture(GL_TEXTURE_2D, 0); @@ -105,17 +105,17 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { UnlockResource(ResourceMem); if (stream) stream->Release(); delete bitmap; - *texture = Textures[resourceID]; + *texture = Textures[reinterpret_cast(device)][resourceID]; return; #endif #else /* _WIN32 */ /* テクスチャの仮初期化 */ - Textures[resourceID] = 0; + Textures[reinterpret_cast(device)][resourceID] = 0; glEnable(GL_TEXTURE_2D); - glGenTextures(1, &Textures[resourceID]); - TextureWidth[Textures[resourceID]] = - TextureHeight[Textures[resourceID]] = 0; - glBindTexture(GL_TEXTURE_2D, Textures[resourceID]); + glGenTextures(1, &Textures[reinterpret_cast(device)][resourceID]); + TextureWidth[Textures[reinterpret_cast(device)][resourceID]] = + TextureHeight[Textures[reinterpret_cast(device)][resourceID]] = 0; + glBindTexture(GL_TEXTURE_2D, Textures[reinterpret_cast(device)][resourceID]); /* ファイルをオープン */ const std::string fileName = dataFileName(resourceID); FILE* pngFile = fopen(fileName.c_str(), "rb"); @@ -179,14 +179,14 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { throw TextureCreationError(fileName + std::string(" にアルファチャンネルがありません")); } } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pngWidth, pngHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageDat); - TextureWidth[Textures[resourceID]] = pngWidth; - TextureHeight[Textures[resourceID]] = pngHeight; + TextureWidth[Textures[reinterpret_cast(device)][resourceID]] = pngWidth; + TextureHeight[Textures[reinterpret_cast(device)][resourceID]] = pngHeight; /* 解放 */ delete[] imageDat; png_destroy_read_struct(&pngPtr, &infoPtr, nullptr); @@ -196,19 +196,54 @@ void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource) { } } +void PreloadTextures(DevicePtr device) { // テクスチャの先行読み込み + constexpr intptr_t textureList[] = { + IDB_PNG_TBLBAIZE, + IDB_PNG_TBLBORDER, + IDB_PNG_SDBAR, + IDB_PNG_TILE, + IDB_PNG_FONT, + IDB_PNG_TITLE, + IDB_PNG_BUTTON, + IDB_PNG_FONT_HUGE, + IDB_PNG_DICE, + IDB_PNG_FONT_SMALL, + IDB_PNG_TENBOU, + IDB_PNG_CHICHAMARK, + IDB_PNG_SCORE_INDICATOR, + IDB_PNG_CALL_TEXT, + IDB_PNG_CALL_DIGITS, + IDB_PNG_AGARI_WINDOW, + IDB_PNG_SCORE_DIGITS, + IDB_PNG_CHECKBOX, + IDB_PNG_TILE_BLACK, + IDB_PNG_MOON_CLOCK, + IDB_PNG_SPLASH_SCREEN, + IDB_PNG_TITLE_BACKGROUND, + 0, // sentinel + }; + TexturePtr dummyTexture; + for (const intptr_t* i = textureList; *i != 0; ++i) + LoadTexture(device, &dummyTexture, MAKEINTRESOURCE(*i)); +} + void UnloadAllTextures() { #if defined(_WIN32) && defined(WITH_DIRECTX) - for (const auto& k : Textures) { - ULONG refs = k.second->Release(); - CodeConv::tostringstream o; - o << _T("UnloadAllTextures(): Texture resource #") << k.first << _T(": remaining number of refs is ") << refs << std::endl; - OutputDebugString(o.str().c_str()); + for (const auto& d : Textures) { + for (const auto& k : d.second) { + ULONG refs = k.second->Release(); + CodeConv::tostringstream o; + o << _T("UnloadAllTextures(): Texture resource #") << k.first << _T(": remaining number of refs is ") << refs << std::endl; + OutputDebugString(o.str().c_str()); + } } #else -for (const auto& k : Textures) { - const GLuint tx[1] = {k.second}; - glDeleteTextures(1, tx); -} + for (const auto& d : Textures) { + for (const auto& k : d.second) { + const GLuint tx[1] = {k.second}; + glDeleteTextures(1, tx); + } + } #endif Textures.clear(); #if !defined(_WIN32) || !defined(WITH_DIRECTX) diff --git a/graphic/loadtex.h b/graphic/loadtex.h index a2dcf4b4..1edc61ec 100644 --- a/graphic/loadtex.h +++ b/graphic/loadtex.h @@ -8,6 +8,7 @@ namespace mihajong_graphic { void LoadTexture(DevicePtr device, TexturePtr* texture, LPCTSTR resource); // テクスチャ読み込み + void PreloadTextures(DevicePtr device); // テクスチャの先行読み込み void UnloadAllTextures(); // テクスチャの解放(アプリケーション終了時にだけ呼ぶこと!) #if !defined(_WIN32) || !defined(WITH_DIRECTX) int getTextureWidth(DevicePtr device, TexturePtr texture); diff --git a/graphic/scrmanip.cpp b/graphic/scrmanip.cpp index ed28e170..2de16644 100644 --- a/graphic/scrmanip.cpp +++ b/graphic/scrmanip.cpp @@ -114,34 +114,7 @@ void ScreenManipulator::InitDevice(bool fullscreen) { // Direct3D オブジェ } void ScreenManipulator::preloadTextures() { // テクスチャの先行読み込み - constexpr intptr_t textureList[] = { - IDB_PNG_TBLBAIZE, - IDB_PNG_TBLBORDER, - IDB_PNG_SDBAR, - IDB_PNG_TILE, - IDB_PNG_FONT, - IDB_PNG_TITLE, - IDB_PNG_BUTTON, - IDB_PNG_FONT_HUGE, - IDB_PNG_DICE, - IDB_PNG_FONT_SMALL, - IDB_PNG_TENBOU, - IDB_PNG_CHICHAMARK, - IDB_PNG_SCORE_INDICATOR, - IDB_PNG_CALL_TEXT, - IDB_PNG_CALL_DIGITS, - IDB_PNG_AGARI_WINDOW, - IDB_PNG_SCORE_DIGITS, - IDB_PNG_CHECKBOX, - IDB_PNG_TILE_BLACK, - IDB_PNG_MOON_CLOCK, - IDB_PNG_SPLASH_SCREEN, - IDB_PNG_TITLE_BACKGROUND, - 0, // sentinel - }; - TexturePtr dummyTexture; - for (const intptr_t* i = textureList; *i != 0; ++i) - LoadTexture(pDevice, &dummyTexture, MAKEINTRESOURCE(*i)); + PreloadTextures(pDevice); } void ScreenManipulator::disposeTextures() { @@ -157,7 +130,11 @@ ScreenManipulator::ScreenManipulator(HWND windowHandle, bool fullscreen) { InitDevice(fullscreen); SplashScreen::LoadTexture(pDevice); myScene = new SplashScreen(this); +#ifdef WITH_DIRECTX myFPSIndicator = new FPSIndicator(this); +#else /* WITH_DIRECTX */ + myFPSIndicator = nullptr; +#endif /* WITH_DIRECTX */ lastRedrawTime = 0; redrawFlag = true; } @@ -169,7 +146,8 @@ ScreenManipulator::ScreenManipulator(Display* displayPtr, Window windowHandle, b pDevice = nullptr; disp = displayPtr; hWnd = windowHandle; InitDevice(fullscreen); myScene = new SplashScreen(this); - myFPSIndicator = new FPSIndicator(this); + //myFPSIndicator = new FPSIndicator(this); + myFPSIndicator = nullptr; lastRedrawTime = 0; redrawFlag = true; } diff --git a/graphic/sprite.cpp b/graphic/sprite.cpp index e0efaf79..369a7052 100644 --- a/graphic/sprite.cpp +++ b/graphic/sprite.cpp @@ -33,6 +33,9 @@ SpriteRenderer* SpriteRenderer::instantiate(DevicePtr device) { return renderer[reinterpret_cast(device)]; } else { // デバイスに対応するスプライトは初回の使用(初期化が必要) renderer[reinterpret_cast(device)] = new SpriteRenderer(device); +#ifndef WITH_DIRECTX + PreloadTextures(device); +#endif /* WITH_DIRECTX */ return renderer[reinterpret_cast(device)]; } } diff --git a/mjcore/main.cpp b/mjcore/main.cpp index 08749c6f..da0d70e1 100644 --- a/mjcore/main.cpp +++ b/mjcore/main.cpp @@ -38,6 +38,7 @@ void GameThread::ThreadMain(GameThread* lpParam) { #endif /*_WIN32*/ #ifndef WITH_DIRECTX mihajong_graphic::WaitForWindowInit(); + mihajong_graphic::Transit(mihajong_graphic::SceneID::splash); #endif /*WITH_DIRECTX*/ initapp(gameType, hwnd); startgame(gameType);