mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
Optimize the wide background stuff by loading only on demand
It uses less memory.
This commit is contained in:
parent
22c06ac92e
commit
39a2cf926b
@ -847,81 +847,6 @@ DoInit (int argc, char * argv[], bool & exit)
|
||||
g_pPixmap->DrawImage (-1, CHBACK, rcRect); // dessine le fond
|
||||
g_pPixmap->Display ();
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (
|
||||
CHBACKSTARS, "image/back-stars.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (
|
||||
CHBACKBUILD, "image/back-build.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (CHBACKBOOK, "image/back-book.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (
|
||||
CHBACKSETUP, "image/back-setup.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (
|
||||
CHBACKCHESTR, "image/back-chest-r.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (
|
||||
CHBACKCHESTW, "image/back-chest-w.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (CHBACKWIN, "image/back-win.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (CHBACKWIN0, "image/back-disco.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (CHBACKLOST, "image/back-lost.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!g_pPixmap->Cache (CHBACKBYE, "image/back-bye.png", totalDim, iconDim))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
totalDim.x = DIMCELX * 2 * 16;
|
||||
totalDim.y = DIMCELY * 2 * 6;
|
||||
iconDim.x = DIMCELX * 2;
|
||||
|
11
src/def.h
11
src/def.h
@ -67,7 +67,6 @@
|
||||
#define DIMLITTLEX 16 // max small char size
|
||||
#define DIMLITTLEY 12
|
||||
|
||||
#define CHNONE -1
|
||||
#define CHBACK 0
|
||||
#define CHFLOOR 1
|
||||
#define CHOBJECT 2
|
||||
@ -84,16 +83,6 @@
|
||||
#define CHTEXT 13
|
||||
#define CHBIGNUM 14
|
||||
#define CHMASK2 15
|
||||
#define CHBACKBUILD 16
|
||||
#define CHBACKBOOK 17
|
||||
#define CHBACKCHESTR 18
|
||||
#define CHBACKCHESTW 19
|
||||
#define CHBACKSETUP 20
|
||||
#define CHBACKBYE 21
|
||||
#define CHBACKWIN 22
|
||||
#define CHBACKLOST 23
|
||||
#define CHBACKSTARS 24
|
||||
#define CHBACKWIN0 25
|
||||
|
||||
#define MAX_PRIVATE_MISSIONS 20
|
||||
|
||||
|
@ -102,7 +102,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_TESTCD,
|
||||
"image/init.png",
|
||||
CHBACKSTARS,
|
||||
"image/back-stars.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -115,7 +115,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_INTRO1,
|
||||
"image/intro1.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -128,7 +128,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_INIT,
|
||||
"image/init.png",
|
||||
CHBACKSTARS,
|
||||
"image/back-stars.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -177,7 +177,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_HISTORY0,
|
||||
"image/history0.png",
|
||||
CHBACKBOOK,
|
||||
"image/back-book.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -202,7 +202,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_HISTORY1,
|
||||
"image/history1.png",
|
||||
CHBACKBOOK,
|
||||
"image/back-book.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -227,7 +227,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_INFO,
|
||||
"image/info%.3d.png",
|
||||
CHBACKBOOK,
|
||||
"image/back-book.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -294,7 +294,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_PLAY,
|
||||
"image/play.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::EXPAND,
|
||||
false,
|
||||
{
|
||||
@ -325,7 +325,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_STOP,
|
||||
"image/stop%.3d.png",
|
||||
CHBACKBOOK,
|
||||
"image/back-book.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -374,7 +374,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_HELP,
|
||||
"image/help.png",
|
||||
CHBACKBOOK,
|
||||
"image/back-book.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -417,7 +417,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_SETUP,
|
||||
"image/setup01.png",
|
||||
CHBACKSETUP,
|
||||
"image/back-setup.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -496,7 +496,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_SETUPp,
|
||||
"image/setup01.png",
|
||||
CHBACKSETUP,
|
||||
"image/back-setup.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -575,7 +575,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_READ,
|
||||
"image/read.png",
|
||||
CHBACKCHESTR,
|
||||
"image/back-chest-r.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -654,7 +654,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_WRITE,
|
||||
"image/write.png",
|
||||
CHBACKCHESTW,
|
||||
"image/back-chest-w.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -733,7 +733,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_WRITEp,
|
||||
"image/write.png",
|
||||
CHBACKCHESTW,
|
||||
"image/back-chest-w.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -812,7 +812,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_LOST,
|
||||
"image/lost.png",
|
||||
CHBACKLOST,
|
||||
"image/back-lost.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -831,7 +831,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_WIN,
|
||||
"image/win.png",
|
||||
CHBACKWIN,
|
||||
"image/back-win.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -850,7 +850,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_LASTWIN,
|
||||
"image/last%.3d.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -869,7 +869,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_BUILD,
|
||||
"image/build.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::EXPAND,
|
||||
true,
|
||||
{
|
||||
@ -986,7 +986,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_BUTTON,
|
||||
"image/button.png",
|
||||
CHBACKBUILD,
|
||||
"image/back-build.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -1208,7 +1208,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_TERM,
|
||||
"image/term.png",
|
||||
CHBACKBUILD,
|
||||
"image/back-build.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -1299,7 +1299,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_MUSIC,
|
||||
"image/music.png",
|
||||
CHBACKBUILD,
|
||||
"image/back-build.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -1384,7 +1384,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_REGION,
|
||||
"image/region.png",
|
||||
CHBACKBUILD,
|
||||
"image/back-build.png",
|
||||
CPixmap::Mode::FIX,
|
||||
true,
|
||||
{
|
||||
@ -1427,7 +1427,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_PLAYMOVIE,
|
||||
"image/movie.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1440,7 +1440,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_WINMOVIE,
|
||||
"image/movie.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1453,7 +1453,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_H0MOVIE,
|
||||
"image/movie.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1466,7 +1466,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_H1MOVIE,
|
||||
"image/movie.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1479,7 +1479,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_H2MOVIE,
|
||||
"image/movie.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1492,7 +1492,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_BYE,
|
||||
"image/bye.png",
|
||||
CHBACKBYE,
|
||||
"image/back-bye.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1505,7 +1505,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_INSERT,
|
||||
"image/insert.png",
|
||||
CHNONE,
|
||||
"",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -1524,7 +1524,7 @@ static Phase table[] =
|
||||
{
|
||||
EV_PHASE_SETTINGS,
|
||||
"image/setup00.png",
|
||||
CHBACKSETUP,
|
||||
"image/back-setup.png",
|
||||
CPixmap::Mode::FIX,
|
||||
false,
|
||||
{
|
||||
@ -2203,8 +2203,7 @@ CEvent::DrawButtons ()
|
||||
SetEnable (EV_BUTTON8, !g_restoreMidi && mid && ogg);
|
||||
|
||||
table[m_index].buttons[4].toolTips[0] =
|
||||
g_bFullScreen ? gettext ("Desktop mode")
|
||||
: gettext ("Reduce window size");
|
||||
g_bFullScreen ? gettext ("Desktop mode") : gettext ("Reduce window size");
|
||||
table[m_index].buttons[5].toolTips[0] =
|
||||
g_bFullScreen ? gettext ("Legacy mode (640x480)")
|
||||
: gettext ("Increase window size");
|
||||
@ -3312,7 +3311,7 @@ CEvent::ChangePhase (Uint32 phase)
|
||||
m_phase = phase; // change phase
|
||||
m_index = index;
|
||||
|
||||
auto backWide = table[m_index].chBackWide;
|
||||
auto backWideName = table[m_index].backWideName;
|
||||
|
||||
filename = table[m_index].backName;
|
||||
if (filename.find ("%.3d") != std::string::npos)
|
||||
@ -3325,23 +3324,24 @@ CEvent::ChangePhase (Uint32 phase)
|
||||
switch (id)
|
||||
{
|
||||
case 0:
|
||||
backWide = CHBACKWIN0;
|
||||
backWideName = "image/back-disco.png";
|
||||
break;
|
||||
case 1:
|
||||
backWide = CHBACKSTARS;
|
||||
backWideName = "image/back-stars.png";
|
||||
break;
|
||||
case 2:
|
||||
backWide = CHBACKWIN;
|
||||
backWideName = "image/back-win.png";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
totalDim.x = LXLOGIC ();
|
||||
totalDim.y = LYLOGIC ();
|
||||
iconDim.x = 0;
|
||||
iconDim.y = 0;
|
||||
if (!m_pPixmap->Cache (
|
||||
CHBACK, filename, totalDim, iconDim, table[m_index].mode, backWide))
|
||||
CHBACK, filename, totalDim, iconDim, table[m_index].mode, backWideName))
|
||||
{
|
||||
WaitMouse (false);
|
||||
m_tryInsertCount = 40;
|
||||
|
@ -44,7 +44,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
Uint32 phase;
|
||||
char backName[20];
|
||||
Sint32 chBackWide;
|
||||
std::string backWideName;
|
||||
CPixmap::Mode mode;
|
||||
Sint32 bCDrom;
|
||||
Button buttons[MAXBUTTON];
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <SDL_image.h>
|
||||
|
||||
#include "kitchensink/kitchensink.h"
|
||||
|
||||
#include "blupi.h"
|
||||
@ -70,6 +72,12 @@ CMovie::fileCloseMovie ()
|
||||
m_videoTex = nullptr;
|
||||
}
|
||||
|
||||
if (this->backTexture)
|
||||
{
|
||||
SDL_DestroyTexture (this->backTexture);
|
||||
this->backTexture = nullptr;
|
||||
}
|
||||
|
||||
if (m_player)
|
||||
{
|
||||
SDL_CloseAudioDevice (m_audioDev);
|
||||
@ -141,15 +149,20 @@ CMovie::fileOpenMovie (const std::string & pFilename)
|
||||
if (m_videoTex == nullptr)
|
||||
return false;
|
||||
|
||||
this->chBackWide = CHNONE;
|
||||
std::string backWideName = "";
|
||||
if (Display::getDisplay ().isWide ())
|
||||
{
|
||||
if (path.rfind ("win005.mkv") != std::string::npos)
|
||||
this->chBackWide = CHBACKWIN0;
|
||||
backWideName = "image/back-disco.png";
|
||||
else if (path.rfind ("win129.mkv") != std::string::npos)
|
||||
this->chBackWide = CHBACKSTARS;
|
||||
backWideName = "image/back-stars.png";
|
||||
}
|
||||
|
||||
std::string file = GetBaseDir () + backWideName;
|
||||
SDL_Surface * surface = IMG_Load (file.c_str ());
|
||||
this->backTexture = SDL_CreateTextureFromSurface (g_renderer, surface);
|
||||
SDL_FreeSurface (surface);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -191,8 +204,7 @@ CMovie::CMovie (CPixmap * pixmap)
|
||||
|
||||
memset (m_audiobuf, 0, sizeof (m_audiobuf));
|
||||
|
||||
this->chBackWide = CHNONE;
|
||||
this->rw_ops = nullptr;
|
||||
this->rw_ops = nullptr;
|
||||
|
||||
m_ret = 0;
|
||||
}
|
||||
@ -310,22 +322,14 @@ CMovie::Render ()
|
||||
this->starting = false;
|
||||
}
|
||||
|
||||
if (this->chBackWide == CHNONE)
|
||||
if (!this->backTexture)
|
||||
{
|
||||
// Clear screen with black
|
||||
SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear (g_renderer);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = LXIMAGE ();
|
||||
rect.h = LYIMAGE ();
|
||||
auto texture = this->pixmap->getTexture (chBackWide);
|
||||
SDL_RenderCopy (g_renderer, texture, &rect, nullptr);
|
||||
}
|
||||
SDL_RenderCopy (g_renderer, this->backTexture, nullptr, nullptr);
|
||||
|
||||
// Refresh videotexture and render it
|
||||
Kit_GetPlayerVideoData (m_player, m_videoTex);
|
||||
|
@ -57,10 +57,10 @@ protected:
|
||||
Kit_Source * m_movie;
|
||||
Kit_Player * m_player;
|
||||
SDL_Texture * m_videoTex;
|
||||
SDL_Texture * backTexture;
|
||||
Sint32 m_ret;
|
||||
SDL_AudioDeviceID m_audioDev;
|
||||
SDL_RWops * rw_ops;
|
||||
int chBackWide;
|
||||
|
||||
char m_audiobuf[AUDIOBUFFER_SIZE];
|
||||
bool m_bEnable;
|
||||
|
@ -305,7 +305,7 @@ CPixmap::Cache (size_t channel, Point totalDim)
|
||||
bool
|
||||
CPixmap::Cache (
|
||||
size_t channel, const std::string & pFilename, Point totalDim, Point iconDim,
|
||||
Mode mode, size_t chBackWide)
|
||||
Mode mode, std::string wideName)
|
||||
{
|
||||
std::string file = GetBaseDir () + pFilename;
|
||||
SDL_Surface * surface = IMG_Load (file.c_str ());
|
||||
@ -363,14 +363,15 @@ CPixmap::Cache (
|
||||
{
|
||||
if (channel == CHBACK && (ow < LXIMAGE () || oh < LYIMAGE ()))
|
||||
{
|
||||
if (chBackWide > 0)
|
||||
if (!wideName.empty ())
|
||||
{
|
||||
Rect srcRect;
|
||||
srcRect.left = 0;
|
||||
srcRect.right = LXIMAGE ();
|
||||
srcRect.top = 0;
|
||||
srcRect.bottom = LYIMAGE ();
|
||||
this->DrawImage (-1, chBackWide, srcRect);
|
||||
std::string file = GetBaseDir () + wideName;
|
||||
SDL_Surface * surface = IMG_Load (file.c_str ());
|
||||
SDL_Texture * texture =
|
||||
SDL_CreateTextureFromSurface (g_renderer, surface);
|
||||
SDL_FreeSurface (surface);
|
||||
SDL_RenderCopy (g_renderer, texture, nullptr, nullptr);
|
||||
SDL_DestroyTexture (texture);
|
||||
}
|
||||
|
||||
SDL_Rect dst;
|
||||
|
@ -66,7 +66,7 @@ public:
|
||||
bool Cache (size_t channel, Point totalDim);
|
||||
bool Cache (
|
||||
size_t channel, const std::string & pFilename, Point totalDim,
|
||||
Point iconDim, Mode mode = FIX, size_t chBackWide = CHNONE);
|
||||
Point iconDim, Mode mode = FIX, std::string wideName = "");
|
||||
bool Cache (size_t channel, const std::string & pFilename, Point totalDim);
|
||||
bool Cache (size_t channel, SDL_Surface * surface, Point totalDim);
|
||||
SDL_Texture * getTexture (size_t channel);
|
||||
|
Loading…
x
Reference in New Issue
Block a user