Commit c18e6073 authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

Many cleanups more improvements on download thread

parent 0ebe5109
#ifndef __GSGEAR_H__
#define __GSGEAR_H__
#ifndef GSGEAR_H__
#define GSGEAR_H__
/**
\description GsGear is pretty much what ensures a correct connection
......@@ -15,9 +15,9 @@
class GsGear
{
public:
virtual void pumpEvent(const CEvent *evPtr) {}
virtual void pumpEvent(const CEvent *) {}
virtual void run(const float deltaT) = 0;
virtual void render() {}
};
#endif // __GSGEAR_H__
#endif // GSGEAR_H__
......@@ -75,14 +75,7 @@ m_start_level(start_level)
}
CGameLauncher::~CGameLauncher()
{
if(mp_Thread)
{
int ret = 0;
threadPool->wait(mp_Thread, &ret);
mp_Thread = nullptr;
}
}
{}
////
// Initialization Routine
......
......@@ -205,8 +205,6 @@ private:
int m_DownloadProgress = 0;
int m_DownloadProgressError = 0;
bool m_DownloadCancel = false;
ThreadPoolItem *mp_Thread = nullptr;
};
......
......@@ -14,300 +14,6 @@
#include <base/video/GsEffectController.h>
#include <cassert>
CResourceLoader::CResourceLoader() :
m_permil(0),
m_permiltarget(0),
m_min_permil(0),
m_max_permil(1000),
m_style(PROGRESS_STYLE_TEXT)
{
SDL_Rect rect;
GsRect<Uint16> gameRes = gVideoDriver.getGameResolution();
rect.x = 0; rect.y = 0;
rect.w = gameRes.w; rect.h = gameRes.h;
mProgressSfc.createRGBSurface(rect);
mProgressSfc.makeBlitCompatible();
}
/**
* Set the style how the loading screen will be shown
*/
void CResourceLoader::setStyle(ProgressStyle style)
{
m_style = style;
}
/**
* This will start up the thread for the load display and process the display of loading
* and then return
*/
int CResourceLoader::RunLoadAction(Action* act,
const std::string &threadname,
const int min_permil,
const int max_permil)
{
assert(!mp_Thread);
m_max_permil = max_permil;
m_min_permil = min_permil;
m_permil = m_min_permil;
m_permiltarget = m_min_permil;
mp_Thread = threadPool->start(act, threadname);
gVideoDriver.clearSurfaces();
int ret = 0;
process(&ret);
return ret;
}
bool CResourceLoader::process(int* ret)
{
float acc = 0.0f;
float start = 0.0f;
float elapsed = 0.0f;
float total_elapsed = 0.0f;
float curr = 0.0f;
int counter = 0;
if(!mp_Thread)
return false;
// Background go black while rendering
SDL_Surface *blit = gVideoDriver.getBlitSurface();
SDL_FillRect( blit, nullptr, SDL_MapRGB(blit->format, 0, 0, 0) );
// Draw the first Frame, so transition looks complete!
renderLoadingGraphic();
gVideoDriver.updateDisplay();
start = timerTicks();
bool threadFinalized = false;
// Now, do rendering here and the cycle
while(!threadFinalized || gEffectController.applyingEffects())
{
const float logicLatency = gTimer.LogicLatency();
const float renderLatency = gTimer.RenderLatency();
curr = timerTicks();
elapsed = curr - start;
acc += elapsed;
start = timerTicks();
// Perform the game cycle
while( acc > logicLatency )
{
renderLoadingGraphic();
if(m_permil >= m_permiltarget)
{
setPermilage(m_permil+1);
}
else
{
int delta_permil = (m_permiltarget-m_permil)/2;
if(delta_permil == 0)
setPermilageForce(m_permil+1);
else
setPermilageForce(m_permil+delta_permil);
}
// Here we try to process all the drawing related Tasks not yet done
acc -= logicLatency;
// Apply graphical effects if any. It does not render, it only prepares for the rendering task.
gEffectController.run(logicLatency);
}
// Pass all the surfaces to one
gVideoDriver.collectSurfaces();
// Apply graphical effects if any.
gEffectController.render();
// Now you really render the screen
// When enabled, it also will apply Filters
gVideoDriver.updateDisplay();
elapsed = timerTicks() - start;
total_elapsed += elapsed;
int waitTime = renderLatency - elapsed;
// wait time remaining in current loop
if( waitTime > 0 )
{
timerDelay(waitTime);
}
total_elapsed += static_cast<float>(waitTime);
// This will refresh the fps display, so it stays readable and calculates an average value.
counter++;
if(counter >= 100)
{
counter = 0;
gTimer.setTimeforLastLoop(total_elapsed/100.0f);
total_elapsed = 0.0f;
}
if(!threadFinalized)
{
threadFinalized = threadPool->finalizeIfReady(mp_Thread, ret);
}
}
// Draw the last Frame, so transition looks complete!
setPermilageForce(m_max_permil);
setPermilage(m_max_permil);
renderLoadingGraphic();
gVideoDriver.updateDisplay();
m_permiltarget = m_permil = m_min_permil;
mp_Thread = nullptr;
gTimer.setLogicReset(true);
return true;
}
/**
* Set the percentage of progress
*/
void CResourceLoader::setPermilageForce(int permil)
{
if(permil<m_max_permil && permil>m_min_permil)
m_permil = permil;
else
m_permil = m_max_permil;
}
void CResourceLoader::setPermilage(int permil)
{
if(permil<m_max_permil && permil>=m_min_permil)
{
m_permiltarget = permil;
}
else
{
m_permil = m_permiltarget = m_max_permil;
}
}
/**
* Progress the shown graphic here
*/
void CResourceLoader::renderLoadingGraphic()
{
mProgressSfc.fillRGB(0, 0, 0);
GsRect<Uint16> gameRes = gVideoDriver.getGameResolution();
const int gameWidth = gameRes.w;
const int gameHeight = gameRes.h;
const int halfWidth = gameWidth/2;
if(m_style == PROGRESS_STYLE_TEXT)
{
// Draw Loading Font... here!
GsFont &Font = gGraphics.getFont(0);
int percent = m_permil/10;
int rest = m_permil%10;
std::string text = "Loading ... " + itoa(percent)+"."+ itoa(rest)+" \%";
SDL_Rect textRect;
GsRect<Uint16> gameRes = gVideoDriver.getGameResolution();
const float scaleUpW = float(gameRes.w)/320.0f;
const float scaleUpH = float(gameRes.h)/200.0f;
textRect.x = (int)(80.0*scaleUpW); textRect.y = (int)(100.0*scaleUpH);
textRect.w = 200; textRect.h = 10;
mProgressSfc.fillRGB(0,0,0);
Font.drawFont(mProgressSfc, text , textRect.x, textRect.y, true);
}
else if(m_style == PROGRESS_STYLE_BITMAP)
{
GsBitmap &Bitmap = *gGraphics.getBitmapFromStr("ONEMOMEN");
GsRect<Uint16> rect;
int width = Bitmap.width();
int height = Bitmap.height();
Bitmap._draw( (gameWidth-width)/2, (gameHeight-height)/2, mProgressSfc.getSDLSurface());
rect.x = (gameWidth-width)/2;
rect.y = (gameHeight+height)/2;
rect.w = (width*m_permil)/1000;
rect.h = 4;
// Fade from yellow to green with this formula
mProgressSfc.fillRGB(rect, 200-(200*m_permil)/1000, 200, 0);
}
else if(m_style == PROGRESS_STYLE_BAR)
{
GsRect<Uint16> rect;
GsRect<Uint16> bgRect;
rect.x = (gameWidth-halfWidth)/2;
rect.y = gameHeight/2;
rect.w = (halfWidth*m_permil)/1000;
rect.h = gameHeight/50;
bgRect = rect;
bgRect.x--;
bgRect.y--;
bgRect.w = halfWidth+2;
bgRect.h = rect.h+2;
// Fade from yellow to green with this formula
const Uint8 r = gameHeight-(gameHeight*m_permil)/1000;
const Uint8 g = gameHeight;
const Uint8 b = 0;
mProgressSfc.fillRGB(bgRect, 128, 128, 128);
mProgressSfc.fillRGB(rect, r, g, b);
}
// In there is garbage of other drawn stuff clean it up.
auto &gameSfc = gVideoDriver.gameSfc();
gameSfc.fillRGB(0, 0, 0);
mProgressSfc.blitTo(gameSfc);
}
/////////////////////// Background routine version ///////////////////
/// TODO: We have a well integrated workaround here, which will ///////
/// interprocess with GsApp and fit into its cycle ////////////////////
/// Goal is to be remove the original resourceloader //////////////////
///////////////////////////////////////////////////////////////////////
CResourceLoaderBackground::CResourceLoaderBackground() :
m_permil(0),
......@@ -327,6 +33,9 @@ m_style(PROGRESS_STYLE_TEXT)
}
CResourceLoaderBackground::~CResourceLoaderBackground()
{}
/**
* This will start up the thread for the load display and process the display of loading
* and then return
......@@ -379,7 +88,7 @@ void CResourceLoaderBackground::setPermilage(const int permil)
void CResourceLoaderBackground::run(const float deltaT)
void CResourceLoaderBackground::run(const float)
{
int ret;
if(threadPool->finalizeIfReady(mpThread, &ret))
......
......@@ -20,7 +20,6 @@
#include <memory>
#include <SDL.h>
#define gResourceLoader CResourceLoader::get()
enum ProgressStyle
{
......@@ -29,49 +28,18 @@ enum ProgressStyle
PROGRESS_STYLE_BAR
};
class CResourceLoader : public GsSingleton<CResourceLoader>
{
public:
CResourceLoader();
void setStyle(ProgressStyle style);
int RunLoadAction(Action* act,
const std::string &threadname,
const int min_permil=0,
const int max_permil=1000);
bool process(int* ret);
void setPermilage(int permil);
private:
void setPermilageForce(int permil);
void renderLoadingGraphic();
int m_permil;
int m_permiltarget;
int m_min_permil;
int m_max_permil;
ProgressStyle m_style;
ThreadPoolItem *mp_Thread;
GsSurface mProgressSfc;
};
// TODO: The resource will have to load in the background. Multithreading will be done later on...
class CResourceLoaderBackground : public GsGear
{
public:
public:
CResourceLoaderBackground();
virtual ~CResourceLoaderBackground();
void start();
void run(const float deltaT);
void render();
void run(const float deltaT) override;
void render() override;
void setStyle(ProgressStyle style)
{ m_style = style; }
......
......@@ -58,25 +58,14 @@ void CGameLauncher::verifyGameStore()
mGameCatalogue = gameDownloader.getGameCatalogue();
// Try to download the catalogue file, in the background
if(!mp_Thread)
{
GameDownloader *pCatalogueDownloader =
new GameDownloader(m_DownloadProgress,
m_DownloadProgressError,
m_DownloadCancel);
pCatalogueDownloader->setupDownloadCatalogue(true);
mp_Thread = threadPool->start(pCatalogueDownloader, "Loading catalogue file in the background");
}
else
{
if(mp_Thread)
{
int ret;
if(threadPool->finalizeIfReady(mp_Thread, &ret))
{
mp_Thread = nullptr;
}
}
threadPool->start(pCatalogueDownloader,
"Loading catalogue file in the background");
}
}
......@@ -140,7 +129,6 @@ void CGameLauncher::ponderDownloadDialog()
}
// When everything is done, The launcher should be restarted, for searching new games.
if( mFinishedDownload &&
mpGameDownloadThread->finished &&
mpDloadProgressCtrl->finished() )
......
......@@ -5,7 +5,9 @@ add_subdirectory(galaxy)
add_subdirectory(vorticon)
add_subdirectory(dreams)
add_library(engine_keen KeenEngine.cpp KeenEngine.h)
add_library(engine_keen KeenEngine.cpp
KeenEngine.h
menu/CSelectionMenu.h)
target_link_libraries(engine_keen
fileio)
......@@ -97,9 +97,6 @@ public:
private:
//std::unique_ptr<Action> mpPlayLoopAction;
//std::unique_ptr<ThreadPoolItem> mpPlayLoopThread;
/**
* @brief mChangeMode An integer that triggers internal resolution change
*/
......
......@@ -7,6 +7,8 @@ GalaxyMenu.cpp
set(HSRC
CConfirmMenu.h
CHelpMenu.h
ComputerWrist.h
GalaxyMenu.h
)
add_library(engine_keen_galaxy_menu ${CXXSRC} ${HSRC} )
......@@ -105,7 +105,8 @@ bool CEGAGraphicsVort::loadData( int version, unsigned char *p_exedata )
SpriteStart,
NumSprites,
SpriteLocation,
gamedir, episode);
gamedir, episode,
mLoader);
m_Sprit->loadHead(&data[0]);
struct SpriteLoad: public Action
......
......@@ -10,6 +10,7 @@
#include "CEGALatch.h"
#include "CEGASprit.h"
#include "engine/core/CResourceLoader.h"
namespace vorticon
{
......@@ -17,7 +18,13 @@ namespace vorticon
class CEGAGraphicsVort
{
public:
bool loadData( int version, unsigned char *p_exedata );
CEGAGraphicsVort(CResourceLoaderBackground &loader) :
mLoader(loader) {}
bool loadData( int version,
unsigned char *p_exedata);
short getNumTiles();
int getNumSprites();
......@@ -52,6 +59,8 @@ private:
SDL_Surface *m_BigTileSurface = nullptr; // May be 32x32. Never used in the original games
SDL_Surface *m_TileSurface = nullptr; // 16x16 Tiles
SDL_Surface *m_BitmapsSurface = nullptr; // Bitmaps of the games, like title screen
CResourceLoaderBackground &mLoader;
};
}
......
......@@ -43,10 +43,11 @@ CEGASprit::CEGASprit(int planesize,
int numsprites,
long spriteloc,
const std::string &gamepath,
size_t episode) :
size_t episode,
CResourceLoaderBackground &loader) :
m_gamepath(gamepath),
m_Episode(episode),
EGASpriteModell(NULL)
mLoader(loader)
{
m_planesize = planesize;
m_spritestartloc = spritestartloc;
......@@ -95,7 +96,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
return false;
}
gResourceLoader.setPermilage(10);
mLoader.setPermilage(10);
byte RawData[m_planesize * 5];
// get the data out of the file into the memory, decompressing it if necessary.
......@@ -112,7 +113,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
fclose(latchfile);
gResourceLoader.setPermilage(50);
mLoader.setPermilage(50);
// TODO: Try to blit the Font map here!
// these are the offsets of the different video planes as
......@@ -148,10 +149,10 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
gGraphics.Palette.m_Palette );
percent = (i*50)/mNumsprites;
gResourceLoader.setPermilage(50+percent);
mLoader.setPermilage(50+percent);
}
gResourceLoader.setPermilage(100);
mLoader.setPermilage(100);
// Read unmasked sprite
for(int p=0 ; p<4 ; p++)
......@@ -167,11 +168,11 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
sfc.unlock();
percent = (s*100)/mNumsprites;
gResourceLoader.setPermilage(100+percent);
mLoader.setPermilage(100+percent);
}
}
gResourceLoader.setPermilage(200);
mLoader.setPermilage(200);
// Read its mask
// now load the 5th plane, which contains the sprite masks.
......@@ -209,10 +210,10 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
sfc.unlock();
percent = (s*100)/mNumsprites;
gResourceLoader.setPermilage(200+percent);
mLoader.setPermilage(200+percent);
}
gResourceLoader.setPermilage(300);
mLoader.setPermilage(300);
LoadSpecialSprites( SpriteVecPlayer1 );
......@@ -294,11 +295,11 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
}
percent = (s*50)/mNumsprites;
gResourceLoader.setPermilage(300+percent);
mLoader.setPermilage(300+percent);
}
}
gResourceLoader.setPermilage(350);
mLoader.setPermilage(350);
std::set<std::string> filelist;
FileListAdder fileListAdder;
......@@ -324,10 +325,10 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
}
percent = (c*150)/listsize;
gResourceLoader.setPermilage(350+percent);
mLoader.setPermilage(350+percent);
}
gResourceLoader.setPermilage(500);
mLoader.setPermilage(500);
for(unsigned int i=0 ; i<4 ; i++)
{
......@@ -338,15 +339,15 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
spriteVec[s].applyTransparency();
percent = (s*250)/noSprites;
gResourceLoader.setPermilage(500+percent);
mLoader.setPermilage(500+percent);
}
}
gResourceLoader.setPermilage(750);
mLoader.setPermilage(750);
// Now create special sprites, like those for effects and the doors!
DeriveSpecialSprites( gGraphics.getTileMap(1), gGraphics.getSpriteVec(0) );
gResourceLoader.setPermilage(800);
mLoader.setPermilage(800);
// Here special Effects if desired
if(gBehaviorEngine.mOptions[GameOption::SPECIALFX].value)
......@@ -354,7 +355,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
ApplySpecialFX();
}
gResourceLoader.setPermilage(900);
mLoader.setPermilage(900);
// Apply the sprites for player 2,3 and 4
DerivePlayerSprites( 1, gGraphics.getSpriteVec(1) );
......@@ -362,7 +363,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
DerivePlayerSprites( 3, gGraphics.getSpriteVec(3) );
gResourceLoader.setPermilage(1000);
mLoader.setPermilage(1000);
return true;
......@@ -543,6 +544,10 @@ void CEGASprit::ApplySpecialFX()
}
CEGASprit::~CEGASprit() {
if(EGASpriteModell) delete [] EGASpriteModell, EGASpriteModell = NULL;
CEGASprit::~CEGASprit()
{
if(EGASpriteModell)
{
delete [] EGASpriteModell, EGASpriteModell = nullptr;
}
}
......@@ -12,7 +12,7 @@
#include <SDL.h>
#include <vector>
#include "graphics/GsGraphics.h"
//#include "common/CTileProperties.h"
#include "engine/core/CResourceLoader.h"
class CEGASprit {
......@@ -22,7 +22,8 @@ public:
int numsprites,
long spriteloc,
const std::string &gamepath,
size_t episode);
size_t episode,
CResourceLoaderBackground &loader);
virtual ~CEGASprit();
bool loadHead(char *data);
......@@ -49,7 +50,9 @@ private:
long hv_offset; // Unused in Keen games. Used in later games such as Shadow Knights
// There are 3 copies of the same Elements in the file. There were used for performance
// in DOS but are ignored here.
}*EGASpriteModell;
} *EGASpriteModell = nullptr;
CResourceLoaderBackground &mLoader;
void generateSprite( const int points, GsSprite &sprite );
void LoadSpecialSprites( std::vector<GsSprite> &sprite );
......
......@@ -155,7 +155,7 @@ bool VorticonEngine::loadResources( const Uint8 flags )
{
// Decode the entire graphics for the game (EGALATCH, EGASPRIT, etc.)
// This will also read the Tile-Properties
CEGAGraphicsVort graphics;
CEGAGraphicsVort graphics(mLoader);
graphics.loadData(version, p_exedata);
mLoader.setPermilage(400);
mLoader.setStyle(PROGRESS_STYLE_BITMAP);
......
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