Commit 5e06059e authored by Gerhard Stein's avatar Gerhard Stein

Some more fixes for the 640x480 Game Resolution

parent 078cd060
......@@ -22,8 +22,6 @@ m_animation_enabled(true),
m_Dark(false),
mNumFuses(0),
mFuseInLevel(false),
mGamePlayPosX(0),
mGamePlayPosY(0),
m_Tilemaps(g_pGfxEngine->getTileMaps()),
mAnimtileTimer(0.0f),
mLocked(false)
......@@ -166,6 +164,14 @@ void CMap::fetchNearestVertBlockers(const int x, int &leftCoord, int &rightCoord
{
int blockXleft = 0;
int blockXright = 0;
if(scrollBlockX.empty())
{
leftCoord = blockXleft;
rightCoord = blockXright;
return;
}
std::vector<int>::iterator left = scrollBlockX.begin();
std::vector<int>::iterator right = left;
right++;
......@@ -193,7 +199,17 @@ void CMap::fetchNearestVertBlockers(const int x, int &leftCoord, int &rightCoord
void CMap::fetchNearestHorBlockers(const int y, int &upCoord, int &downCoord)
{
int blockYup, blockYdown;
int blockYup = 0;
int blockYdown = 0;
if(scrollBlockY.empty())
{
upCoord = blockYup;
downCoord = blockYdown;
return;
}
std::vector<int>::iterator up = scrollBlockY.begin();
std::vector<int>::iterator down= up;
down++;
......@@ -389,6 +405,9 @@ bool CMap::gotoPos(int x, int y)
for( int scrolly=0 ; scrolly<-dy ; scrolly++) scrollUp(true);
else retval = true;
calcVisibleArea();
refreshVisibleArea();
return retval;
}
......@@ -417,6 +436,8 @@ bool CMap::scrollRight(const bool force)
if (m_mapxstripepos >= squareSize) m_mapxstripepos = 0;
m_scrollpix = 0;
}
refreshVisibleArea();
return true;
}
return false;
......@@ -450,6 +471,8 @@ bool CMap::scrollLeft(const bool force)
m_scrollpix = 15;
} else m_scrollpix--;
refreshVisibleArea();
return true;
}
return false;
......@@ -479,6 +502,8 @@ bool CMap::scrollDown(const bool force)
if (m_mapystripepos >= squareSize) m_mapystripepos = 0;
m_scrollpixy = 0;
}
refreshVisibleArea();
return true;
}
return false;
......@@ -514,6 +539,9 @@ bool CMap::scrollUp(const bool force)
m_scrollpixy = 15;
} else m_scrollpixy--;
refreshVisibleArea();
return true;
}
return false;
......@@ -532,31 +560,36 @@ bool CMap::scrollUp(const bool force)
void CMap::refreshVisibleArea()
void CMap::calcVisibleArea()
{
// TODO: First we need to get the scroll boundaries and
// Here we need to get the scroll boundaries and
// derive the rect from it.
int blockYup, blockYdown;
int blockXleft, blockXright;
int x2, y2;
fetchNearestVertBlockers( mGamePlayPos.x, mVisArea.x, x2);
fetchNearestHorBlockers( mGamePlayPos.y, mVisArea.y, y2);
CRect<int> relativeVisGameArea;
mVisArea.w = x2 - mVisArea.x;
mVisArea.h = y2 - mVisArea.y;
}
fetchNearestVertBlockers( mGamePlayPosX, blockXleft, blockXright);
fetchNearestHorBlockers( mGamePlayPosY, blockYup, blockYdown);
relativeVisGameArea.x = (blockXleft>>STC)-m_scrollx;
relativeVisGameArea.y = (blockYup>>STC)-m_scrolly;
relativeVisGameArea.w = ((blockXright-blockXleft)>>STC);
relativeVisGameArea.h = ((blockYdown-blockYup)>>STC);
void CMap::refreshVisibleArea()
{
CRect<int> relativeVisGameArea;
CRect<int> GameResolution(g_pVideoDriver->getGameResolution());
relativeVisGameArea.x = (mVisArea.x>>STC)-m_scrollx;
relativeVisGameArea.y = (mVisArea.y>>STC)-m_scrolly;
relativeVisGameArea.w = (mVisArea.w>>STC);
relativeVisGameArea.h = (mVisArea.h>>STC);
CRect<int> gameResolution(g_pVideoDriver->getGameResolution());
// Using the GameResolution to intersect the
// calculated visible area we get another on
// calculated visible area we get another one
// which is the rect allowed for blit operations
GameResolution.intersect(relativeVisGameArea);
gameResolution.intersect(relativeVisGameArea);
g_pVideoDriver->mpVideoEngine->mRelativeVisGameArea = GameResolution;
g_pVideoDriver->mpVideoEngine->mRelativeVisGameArea = gameResolution;
}
......@@ -624,11 +657,9 @@ void CMap::drawAll()
// draw a horizontal stripe, for vertical scrolling
void CMap::drawHstripe(unsigned int y, unsigned int mpy)
{
refreshVisibleArea();
{
if(mpy >= m_height) return;
SDL_Surface *ScrollSurface = g_pVideoDriver->getScrollSurface();
Uint32 num_v_tiles= ScrollSurface->w/16;
......@@ -651,8 +682,6 @@ void CMap::drawHstripe(unsigned int y, unsigned int mpy)
// draws a vertical stripe from map position mapx to scrollbuffer position x
void CMap::drawVstripe(unsigned int x, unsigned int mpx)
{
refreshVisibleArea();
SDL_Surface *ScrollSurface = g_pVideoDriver->getScrollSurface();
const int drawMask = ScrollSurface->w-1;
......
......@@ -55,6 +55,7 @@ public:
bool scrollUp(const bool force=false);
bool scrollDown(const bool force=false);
void calcVisibleArea();
void refreshVisibleArea();
void redrawAt(const Uint32 mx, const Uint32 my);
void drawAll();
......@@ -139,8 +140,7 @@ public:
bool mFuseInLevel;
int mGamePlayPosX;
int mGamePlayPosY;
VectorD2<int> mGamePlayPos;
private:
......@@ -168,6 +168,8 @@ private:
std::vector<int> scrollBlockY;
bool mLocked;
CRect<int> mVisArea;
};
......
......@@ -247,9 +247,9 @@ public:
void moveSlopedTileUp( int x, int y, const int xspeed );
// getters for positions
VectorD2<Uint32> &getPosition()
{ return m_Pos; }
Uint32 getXPosition() const
VectorD2<Uint32> &getPosition()
{ return m_Pos; }
Uint32 getXPosition() const
{ return m_Pos.x; }
Uint32 getYPosition() const
{ return m_Pos.y; }
......@@ -265,7 +265,8 @@ public:
{ return m_Pos.y+m_BBox.y2; }
Uint32 getYMidPos()
{ return m_Pos.y+(m_BBox.y2-m_BBox.y1)/2; }
VectorD2<Uint32> getMidPos()
{ return VectorD2<Uint32>(getXMidPos(), getYMidPos()); }
void processFallPhysics(const int boost);
void processFallPhysics();
......
......@@ -81,7 +81,6 @@ void CMainMenu::createGalaxyMenu( const bool openedGamePlay )
mpMenuDialog->addControl( button );
// TODO: Some items are still disabled, because those are not yet implemented in Galaxy
CGUIButton *loadButton = new CGUIButton( "Load",
......
......@@ -86,8 +86,8 @@ void CCamera::setPosition(const VectorD2<int>& newpos)
mp_Map->gotoPos(cam_x>>STC, cam_y>>STC);
mp_Map->mGamePlayPosX = mp_AttachedObject->getXMidPos();
mp_Map->mGamePlayPosY = mp_AttachedObject->getYMidPos();
VectorD2<int> camPos(cam_x, cam_y);
mp_Map->mGamePlayPos = camPos;
reAdjust();
}
......@@ -140,8 +140,7 @@ void CCamera::process(const bool force)
m_moving = false;
mp_Map->mGamePlayPosX = mp_AttachedObject->getXMidPos();
mp_Map->mGamePlayPosY = mp_AttachedObject->getYMidPos();
mp_Map->mGamePlayPos = mp_AttachedObject->getMidPos();
const Uint32 attached_x = mp_AttachedObject->getXPosition() + m_relcam.x;
const Uint32 attached_y = mp_AttachedObject->getYPosition() + m_relcam.y;
......@@ -227,7 +226,7 @@ void CCamera::process(const bool force)
void CCamera::reAdjust()
{
SDL_Rect gamerect = g_pVideoDriver->getGameResolution().SDLRect();
SDL_Rect gameRes = g_pVideoDriver->getGameResolution().SDLRect();
Uint16 &scroll_x = mp_Map->m_scrollx;
Uint16 &scroll_y = mp_Map->m_scrolly;
......@@ -240,40 +239,51 @@ void CCamera::reAdjust()
mp_Map->fetchNearestVertBlockers(x, blockXleft, blockXright);
mp_Map->fetchNearestHorBlockers(y, blockYup, blockYdown);
blockXleft >>= STC;
blockXleft >>= STC;
blockXright >>= STC;
blockYup >>= STC;
blockYdown >>= STC;
blockYdown >>= STC;
if( (blockYdown-blockYup) < gameRes.h ||
(blockXright-blockXleft) < gameRes.w)
{
mp_Map->calcVisibleArea();
mp_Map->refreshVisibleArea();
return;
}
// This will always snap correctly to the edges
if(scroll_x < blockXleft)
if(scroll_x < blockXleft)
{
for(int amt=0 ; amt<gamerect.w ; amt++ )
mp_Map->scrollRight();
for(int amt=0 ; amt<gamerect.w ; amt++ )
mp_Map->scrollLeft();
for(int amt=0 ; amt<gameRes.w ; amt++ )
mp_Map->scrollRight();
for(int amt=0 ; amt<gameRes.w ; amt++ )
mp_Map->scrollLeft();
}
if(scroll_x > blockXright - gamerect.w)
if(scroll_x > blockXright - gameRes.w)
{
for(int amt=0 ; amt<gamerect.w ; amt++ )
mp_Map->scrollLeft();
for(int amt=0 ; amt<gamerect.w ; amt++ )
mp_Map->scrollRight();
for(int amt=0 ; amt<gameRes.w ; amt++ )
mp_Map->scrollLeft();
for(int amt=0 ; amt<gameRes.w ; amt++ )
mp_Map->scrollRight();
}
if(scroll_y < blockYup)
{
for(int amt=0 ; amt<gamerect.h ; amt++ )
mp_Map->scrollDown();
for(int amt=0 ; amt<gamerect.h ; amt++ )
mp_Map->scrollUp();
for(int amt=0 ; amt<gameRes.h ; amt++ )
mp_Map->scrollDown();
for(int amt=0 ; amt<gameRes.h ; amt++ )
mp_Map->scrollUp();
}
if(scroll_y > blockYdown - gamerect.h)
if(scroll_y > blockYdown - gameRes.h)
{
for(int amt=0 ; amt<gamerect.h ; amt++ )
mp_Map->scrollUp();
for(int amt=0 ; amt<gamerect.h ; amt++ )
mp_Map->scrollDown();
}
for(int amt=0 ; amt<gameRes.h ; amt++ )
mp_Map->scrollUp();
for(int amt=0 ; amt<gameRes.h ; amt++ )
mp_Map->scrollDown();
}
mp_Map->calcVisibleArea();
mp_Map->refreshVisibleArea();
}
......
......@@ -173,6 +173,7 @@ mp_processState(NULL)
memset(m_playcontrol, 0, PA_MAX_ACTIONS);
m_camera.setPosition(m_Pos);
mp_Map->calcVisibleArea();
mp_Map->refreshVisibleArea();
}
......
......@@ -1772,7 +1772,8 @@ void CPlayerLevel::processEnterDoor()
new_pos.x += ((m_BBox.x2-m_BBox.x1)/2);
new_pos.y += ((m_BBox.y2-m_BBox.y1)/2);
m_camera.setPosition(new_pos);
mp_Map->mGamePlayPos = new_pos;
m_camera.setPosition(new_pos);
//o->ypos = TILE2MU(*t%256 - 1) + 15;
//o->xpos = (*t >> 8 << 8);
......
......@@ -869,6 +869,10 @@ void CPlayerWM::processWarpInTeleporter()
new_pos.y += ((m_BBox.y2-m_BBox.y1)/2);
m_camera.setPosition(new_pos);
mp_Map->mGamePlayPos = new_pos;
mp_Map->calcVisibleArea();
mp_Map->refreshVisibleArea();
mProcessPtr = &CPlayerWM::processLeavingTeleporter;
playSound(SOUND_TELEPORT);
......
......@@ -95,12 +95,11 @@ bool CBitmap::loadHQBitmap( const std::string& filename )
}
bool CBitmap::scaleTo(const CRect<Uint16> gameRes)
bool CBitmap::scaleTo(const CRect<Uint16> &gameRes)
{
SDL_Rect newRect = gameRes.SDLRect();
auto bmpSfc = mpBitmapSurface.get();
if(newRect.w == bmpSfc->w && newRect.h == bmpSfc->h)
if(newRect.w == mpBitmapSurface->w && newRect.h == mpBitmapSurface->h)
return true;
// TODO: This is not compatible with SDL 1.2, we need a wrapper for that.
......@@ -109,6 +108,7 @@ bool CBitmap::scaleTo(const CRect<Uint16> gameRes)
// Need to do that, otherwise it won't work.
optimizeSurface();
auto bmpSfc = mpBitmapSurface.get();
auto bmpFormat = bmpSfc->format;
newSfc.reset( SDL_CreateRGBSurface(bmpSfc->flags,
......
......@@ -37,7 +37,7 @@ public:
Uint16 getWidth() const { return mpBitmapSurface->w; }
Uint16 getHeight() const { return mpBitmapSurface->h; }
bool scaleTo(const CRect<Uint16> gameRes);
bool scaleTo(const CRect<Uint16> &gameRes);
std::string getName() const { return mName; }
void setName(const std::string &name) { mName = name; }
......
......@@ -277,11 +277,8 @@ void CGUIDialog::initEmptyBackround()
{
const SDL_Rect lRect = g_pVideoDriver->toBlitRect(mRect);
mpBackgroundSfc.reset( CG_CreateRGBSurface( lRect ), &SDL_FreeSurface );
//#if SDL_VERSION_ATLEAST(2, 0, 0)
//#else
mpBackgroundSfc.reset( g_pVideoDriver->convertThroughBlitSfc( mpBackgroundSfc.get() ), &SDL_FreeSurface );
//#endif
SDL_Surface *sfc = mpBackgroundSfc.get();
SDL_FillRect( sfc, NULL, SDL_MapRGB( sfc->format, 230, 230, 230) );
......@@ -350,25 +347,26 @@ void CGUIDialog::initVorticonBackground()
// Now draw the borders
drawBorderRect(backSfc, Rect);
//#if SDL_VERSION_ATLEAST(2, 0, 0)
//#else
mpTempSfc.reset( g_pVideoDriver->convertThroughBlitSfc( backSfc ), &SDL_FreeSurface );
//#endif
}
void CGUIDialog::initGalaxyBackround()
{
SDL_Surface *swatchBmp = g_pGfxEngine->getBitmap("KEENSWATCH")->getSDLSurface();
{
mBackgroundBmp = *g_pGfxEngine->getBitmap("KEENSWATCH");
CRect<Uint16> gameRes = g_pVideoDriver->getGameResolution();
mBackgroundBmp.scaleTo(gameRes);
SDL_Surface *swatchBmp = mBackgroundBmp.getSDLSurface();
mpBackgroundSfc.reset( g_pVideoDriver->convertThroughBlitSfc( swatchBmp ), &SDL_FreeSurface );
// Besides the Background Bitmap we need to draw two lines
SDL_Surface *backSfc = mpBackgroundSfc.get();
Uint32 color = SDL_MapRGB( backSfc->format, 84, 234, 84);
Uint32 color = SDL_MapRGB( backSfc->format, 84, 234, 84 );
SDL_Rect scoreRect;
scoreRect.w = 150;
scoreRect.h = 1;
......
......@@ -107,6 +107,7 @@ private:
// SDL_Surface of the Background
std::shared_ptr<SDL_Surface> mpBackgroundSfc;
CBitmap mBackgroundBmp;
std::shared_ptr<SDL_Surface> mpTempSfc;
int mSelection;
......
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