diff --git a/blupi.h b/blupi.h index 9ca21b2..708bf01 100644 --- a/blupi.h +++ b/blupi.h @@ -1,7 +1,6 @@ #pragma once -struct SDL_Window; -struct SDL_Renderer; +#include extern SDL_Window *g_window; extern SDL_Renderer *g_renderer; \ No newline at end of file diff --git a/decmap.cpp b/decmap.cpp index 68f2166..e914579 100644 --- a/decmap.cpp +++ b/decmap.cpp @@ -1,6 +1,7 @@ // DecMap.cpp // +#include "blupi.h" #include "DEF.H" #include "DECOR.H" @@ -31,8 +32,7 @@ // Bitmap de la carte. -static char g_map8_bits[DIMMAPY][DIMMAPX]; -static unsigned short g_map16_bits[DIMMAPY][DIMMAPX]; +static Uint32 g_map32_bits[DIMMAPY][DIMMAPX]; static bool g_bPalette; @@ -42,51 +42,55 @@ static bool g_bPalette; void CDecor::MapInitColors() { - g_bPalette = m_pPixmap->IsPalette(); + SDL_PixelFormat *fmt; - m_colors[MAP_CADRE] = m_pPixmap->SearchColor(255,0,0); // rouge - m_colors[MAP_FOG] = m_pPixmap->SearchColor(0,0,0); // noir - m_colors[MAP_BLUPI] = m_pPixmap->SearchColor(255,255,0); // jaune - m_colors[MAP_SEE] = m_pPixmap->SearchColor(102,102,204); // bleu - m_colors[MAP_DALLE] = m_pPixmap->SearchColor(192,192,192); // gris - m_colors[MAP_PERSO] = m_pPixmap->SearchColor(255,0,0); // rouge - m_colors[MAP_NURSE] = m_pPixmap->SearchColor(255,0,0); // rouge - m_colors[MAP_ROC] = m_pPixmap->SearchColor(214,214,214); // gris clair - m_colors[MAP_MUR] = m_pPixmap->SearchColor(100,100,100); // gris moyen - m_colors[MAP_EGG] = m_pPixmap->SearchColor(255,255,255); // blanc - m_colors[MAP_FIRE] = m_pPixmap->SearchColor(255,0,0); // rouge - m_colors[MAP_TOMAT] = m_pPixmap->SearchColor(255,0,0); // rouge - m_colors[MAP_BUILD] = m_pPixmap->SearchColor(0,0,0); // noir - m_colors[MAP_ENNEMI]= m_pPixmap->SearchColor(0,192,255); // bleu métal - m_colors[MAP_FLEUR] = m_pPixmap->SearchColor(255,206,0); // jaune + fmt = SDL_GetWindowSurface (g_window)->format; - m_colors[MAP_TREE] = m_pPixmap->SearchColor(0,102,0); // vert foncé - m_colors[MAP_HERB1] = m_pPixmap->SearchColor(0,204,51); // vert clair - m_colors[MAP_HERB2] = m_pPixmap->SearchColor(0,156,8); // vert moyen - m_colors[MAP_TERRE] = m_pPixmap->SearchColor(94,78,12); // brun + //g_bPalette = m_pPixmap->IsPalette(); + + m_colors[MAP_CADRE] = SDL_MapRGB (fmt, 255, 0, 0); // rouge + m_colors[MAP_FOG] = SDL_MapRGB (fmt, 0, 0, 0); // noir + m_colors[MAP_BLUPI] = SDL_MapRGB (fmt, 255, 255, 0); // jaune + m_colors[MAP_SEE] = SDL_MapRGB (fmt, 102, 102, 204); // bleu + m_colors[MAP_DALLE] = SDL_MapRGB (fmt, 192, 192, 192); // gris + m_colors[MAP_PERSO] = SDL_MapRGB (fmt, 255, 0, 0); // rouge + m_colors[MAP_NURSE] = SDL_MapRGB (fmt, 255, 0, 0); // rouge + m_colors[MAP_ROC] = SDL_MapRGB (fmt, 214, 214, 214); // gris clair + m_colors[MAP_MUR] = SDL_MapRGB (fmt, 100, 100, 100); // gris moyen + m_colors[MAP_EGG] = SDL_MapRGB (fmt, 255, 255, 255); // blanc + m_colors[MAP_FIRE] = SDL_MapRGB (fmt, 255, 0, 0); // rouge + m_colors[MAP_TOMAT] = SDL_MapRGB (fmt, 255, 0, 0); // rouge + m_colors[MAP_BUILD] = SDL_MapRGB (fmt, 0, 0, 0); // noir + m_colors[MAP_ENNEMI]= SDL_MapRGB (fmt, 0, 192, 255); // bleu métal + m_colors[MAP_FLEUR] = SDL_MapRGB (fmt, 255, 206, 0); // jaune + + m_colors[MAP_TREE] = SDL_MapRGB (fmt, 0 ,102, 0); // vert foncé + m_colors[MAP_HERB1] = SDL_MapRGB (fmt, 0 ,204, 51); // vert clair + m_colors[MAP_HERB2] = SDL_MapRGB (fmt, 0 ,156, 8); // vert moyen + m_colors[MAP_TERRE] = SDL_MapRGB (fmt, 94, 78, 12); // brun if ( m_region == 1 ) // palmiers { - m_colors[MAP_TREE] = m_pPixmap->SearchColor(38,197,42); - m_colors[MAP_HERB1] = m_pPixmap->SearchColor(184,140,1); - m_colors[MAP_HERB2] = m_pPixmap->SearchColor(145,110,5); - m_colors[MAP_TERRE] = m_pPixmap->SearchColor(192,192,192); + m_colors[MAP_TREE] = SDL_MapRGB (fmt, 38, 197, 42); + m_colors[MAP_HERB1] = SDL_MapRGB (fmt, 184, 140, 1); + m_colors[MAP_HERB2] = SDL_MapRGB (fmt, 145, 110, 5); + m_colors[MAP_TERRE] = SDL_MapRGB (fmt, 192, 192, 192); } if ( m_region == 2 ) // hiver { - m_colors[MAP_TREE] = m_pPixmap->SearchColor(152,205,222); - m_colors[MAP_HERB1] = m_pPixmap->SearchColor(219,234,239); - m_colors[MAP_HERB2] = m_pPixmap->SearchColor(223,173,90); - m_colors[MAP_TERRE] = m_pPixmap->SearchColor(152,205,222); + m_colors[MAP_TREE] = SDL_MapRGB (fmt, 152, 205, 222); + m_colors[MAP_HERB1] = SDL_MapRGB (fmt, 219, 234, 239); + m_colors[MAP_HERB2] = SDL_MapRGB (fmt, 223, 173, 90); + m_colors[MAP_TERRE] = SDL_MapRGB (fmt, 152, 205, 222); } if ( m_region == 3 ) // sapins { - m_colors[MAP_TREE] = m_pPixmap->SearchColor(0,102,0); - m_colors[MAP_HERB1] = m_pPixmap->SearchColor(38,197,42); - m_colors[MAP_HERB2] = m_pPixmap->SearchColor(140,140,0); - m_colors[MAP_TERRE] = m_pPixmap->SearchColor(172,178,173); + m_colors[MAP_TREE] = SDL_MapRGB (fmt, 0, 102, 0); + m_colors[MAP_HERB1] = SDL_MapRGB (fmt, 38, 197, 42); + m_colors[MAP_HERB2] = SDL_MapRGB (fmt, 140, 140, 0); + m_colors[MAP_TERRE] = SDL_MapRGB (fmt, 172, 178, 173); } } @@ -461,8 +465,6 @@ void CDecor::MapPutCel(POINT pos) else pColors = color_deffloor; color: - if ( g_bPalette ) - { for ( i=0 ; i<4 ; i++ ) { if ( pos.x+i >= 0 && pos.x+i < DIMMAPX ) @@ -470,25 +472,10 @@ void CDecor::MapPutCel(POINT pos) icon = *pColors++; if ( icon != 0 ) { - g_map8_bits[pos.y][pos.x+i] = (char)m_colors[icon]; + g_map32_bits[pos.y][pos.x+i] = m_colors[icon]; } } } - } - else - { - for ( i=0 ; i<4 ; i++ ) - { - if ( pos.x+i >= 0 && pos.x+i < DIMMAPX ) - { - icon = *pColors++; - if ( icon != 0 ) - { - g_map16_bits[pos.y][pos.x+i] = m_colors[icon]; - } - } - } - } } @@ -524,20 +511,11 @@ bool CDecor::GenerateMap() if ( m_blupi[rank].perso == 0 || m_blupi[rank].perso == 8 ) i = MAP_BLUPI; else i = MAP_PERSO; - if ( g_bPalette ) - { - g_map8_bits[pos.y+0][pos.x+0] = (char)m_colors[i]; - g_map8_bits[pos.y+0][pos.x+1] = (char)m_colors[i]; - g_map8_bits[pos.y+1][pos.x+0] = (char)m_colors[i]; - g_map8_bits[pos.y+1][pos.x+1] = (char)m_colors[i]; - } - else - { - g_map16_bits[pos.y+0][pos.x+0] = m_colors[i]; - g_map16_bits[pos.y+0][pos.x+1] = m_colors[i]; - g_map16_bits[pos.y+1][pos.x+0] = m_colors[i]; - g_map16_bits[pos.y+1][pos.x+1] = m_colors[i]; - } + + g_map32_bits[pos.y+0][pos.x+0] = m_colors[i]; + g_map32_bits[pos.y+0][pos.x+1] = m_colors[i]; + g_map32_bits[pos.y+1][pos.x+0] = m_colors[i]; + g_map32_bits[pos.y+1][pos.x+1] = m_colors[i]; } } } @@ -546,46 +524,27 @@ bool CDecor::GenerateMap() cel = m_celCoin; pos = ConvCelToMap(cel); - if ( g_bPalette ) - { for ( i=pos.x ; iCache(CHMAP, hbm, dim); + m_pPixmap->Cache(CHMAP, surface, dim); pos.x = POSMAPX; pos.y = POSMAPY; diff --git a/decor.h b/decor.h index 49ba9d9..44c86e9 100644 --- a/decor.h +++ b/decor.h @@ -465,7 +465,7 @@ protected: bool m_bBuild; // true -> construction bool m_bInvincible; // true -> cheat code bool m_bSuper; // true -> cheat code - short m_colors[100]; + Uint32 m_colors[100]; int m_time; // temps relatif global int m_timeConst; // temps relatif global constant int m_timeFlipOutline; // temps quand basculer mode outline diff --git a/pixmap.cpp b/pixmap.cpp index e95a1ac..cfdead4 100644 --- a/pixmap.cpp +++ b/pixmap.cpp @@ -351,7 +351,7 @@ HRESULT CPixmap::BltFast(int chDst, int channel, POINT dst, RECT rcRect, int mode) { DWORD dwTrans; - HRESULT ddrval; + HRESULT ddrval = DD_OK; int limit; if ( mode == 0 ) dwTrans = DDBLTFAST_SRCCOLORKEY; @@ -396,6 +396,7 @@ HRESULT CPixmap::BltFast(int chDst, int channel, dstRect.y = dst.y; //SDL_BlitSurface (m_lpSDLSurface[channel], &srcRect, m_lpSDLBack, &dstRect); SDL_RenderCopy (g_renderer, m_lpSDLTexture[channel], &srcRect, &dstRect); + if (channel != CHMAP) ddrval = m_lpDDSBack->BltFast(dst.x, dst.y, m_lpDDSurface[channel], &rcRect, dwTrans); @@ -403,6 +404,7 @@ HRESULT CPixmap::BltFast(int chDst, int channel, } else { + if (channel != CHMAP) ddrval = m_lpDDSurface[chDst]->BltFast(dst.x, dst.y, m_lpDDSurface[channel], &rcRect, dwTrans); @@ -690,7 +692,7 @@ bool CPixmap::Cache(int channel, char *pFilename, POINT totalDim, bool bUsePalet // Cache une image provenant d'un bitmap. -bool CPixmap::Cache(int channel, HBITMAP hbm, POINT totalDim) +bool CPixmap::Cache(int channel, SDL_Surface *surface, POINT totalDim) { if ( channel < 0 || channel >= MAXIMAGE ) return false; @@ -700,16 +702,16 @@ bool CPixmap::Cache(int channel, HBITMAP hbm, POINT totalDim) } // Create the offscreen surface, by loading our bitmap. - m_lpDDSurface[channel] = DDConnectBitmap(m_lpDD, hbm); + m_lpSDLTexture[channel] = SDL_CreateTextureFromSurface (g_renderer, surface); - if ( m_lpDDSurface[channel] == NULL ) + if (m_lpSDLTexture[channel] == NULL ) { OutputDebug("Fatal error: DDLoadBitmap\n"); return false; } // Set the color key to white - DDSetColorKey(m_lpDDSurface[channel], RGB(255,255,255)); // blanc + //DDSetColorKey(m_lpDDSurface[channel], RGB(255,255,255)); // blanc m_totalDim[channel] = totalDim; m_iconDim[channel] = totalDim; @@ -813,7 +815,7 @@ bool CPixmap::DrawIcon(int chDst, int channel, int rank, POINT pos, COLORREF oldColor1, oldColor2; if ( channel < 0 || channel >= MAXIMAGE ) return false; - if ( m_lpDDSurface[channel] == NULL ) return false; + if ( channel != CHMAP && m_lpDDSurface[channel] == NULL ) return false; if ( m_iconDim[channel].x == 0 || m_iconDim[channel].y == 0 ) return false; @@ -830,9 +832,9 @@ bool CPixmap::DrawIcon(int chDst, int channel, int rank, POINT pos, oldColor1 = m_colorSurface[2*channel+0]; oldColor2 = m_colorSurface[2*channel+1]; - if ( bMask ) SetTransparent(channel, RGB(255,255,255)); // blanc + if (channel != CHMAP && bMask ) SetTransparent(channel, RGB(255,255,255)); // blanc ddrval = BltFast(chDst, channel, pos, rect, mode); - if ( bMask ) SetTransparent2(channel, oldColor1, oldColor2); + if (channel != CHMAP && bMask ) SetTransparent2(channel, oldColor1, oldColor2); if ( ddrval != DD_OK ) return false; return true; diff --git a/pixmap.h b/pixmap.h index 00b2a31..7638bb2 100644 --- a/pixmap.h +++ b/pixmap.h @@ -30,7 +30,7 @@ public: int SearchColor(int red, int green, int blue); bool Cache(int channel, char *pFilename, POINT totalDim, POINT iconDim, bool bUsePalette); bool Cache(int channel, char *pFilename, POINT totalDim, bool bUsePalette); - bool Cache(int channel, HBITMAP hbm, POINT totalDim); + bool Cache(int channel, SDL_Surface *surface, POINT totalDim); void Flush(int channel); void SetTransparent(int channel, COLORREF color); void SetTransparent2(int channel, COLORREF color1, COLORREF color2);