Commit bea701c0 authored by Gerhard Stein's avatar Gerhard Stein

Animation code for the galaxy engine

parent 9b5c8c6d
......@@ -24,8 +24,8 @@ void CBehaviorEngine::addMessage(const std::string &name,
{ stringmap[name] = message; }
std::vector<CTileProperties> &CBehaviorEngine::getTileProperties()
{ return m_TileProperties; }
std::vector<CTileProperties> &CBehaviorEngine::getTileProperties(size_t tmnum)
{ return m_TileProperties[tmnum]; }
CPhysicsSettings &CBehaviorEngine::getPhysicsSettings()
{ return m_PhysicsSettings; }
......
......@@ -31,14 +31,14 @@ public:
void addMessage(const std::string &name,
const std::string &message);
std::vector<CTileProperties> &getTileProperties();
std::vector<CTileProperties> &getTileProperties(size_t tmnum = 1);
CPhysicsSettings &getPhysicsSettings();
std::string getString(const std::string& name);
virtual ~CBehaviorEngine();
private:
std::vector<CTileProperties> m_TileProperties;
std::vector<CTileProperties> m_TileProperties[2];
CPhysicsSettings m_PhysicsSettings;
std::map<std::string,std::string> stringmap;
......
......@@ -138,8 +138,9 @@ bool CEGAGraphicsGalaxy::loadData()
// First, retrieve the Tile properties so the tilemap gets properly formatted
// Important especially for masks, and later in the game for the behaviours
// of those objects
CTileLoader TileLoader( m_Exefile, EpisodeInfo[m_episode-4].Num16MaskedTiles );
if(!TileLoader.load())
CTileLoader TileLoader( m_Exefile );
if(!TileLoader.load(EpisodeInfo[m_episode-4].Num16Tiles,
EpisodeInfo[m_episode-4].Num16MaskedTiles))
return false;
if(!readfonts()) return false;
......
......@@ -88,7 +88,7 @@ void CPlayGameGalaxy::processInput()
void CPlayGameGalaxy::processRendering()
{
// Animate the tiles of the map
//m_Map.animateAllTiles();
m_Map.animateAllTiles();
// Blit the background
g_pVideoDriver->blitScrollSurface();
......
......@@ -111,8 +111,8 @@ bool CEGAGraphicsVort::loadData( int version, unsigned char *p_exedata )
// Important especially for masks, and later in the game for the behaviours
// of those objects
CTileLoader TileLoader( m_episode, version, Num16Tiles, p_exedata );
if(!TileLoader.load())
CTileLoader TileLoader( m_episode, version, p_exedata );
if(!TileLoader.load(0, Num16Tiles))
return false;
m_Latch = new CEGALatch(LatchPlaneSize,
......
......@@ -13,25 +13,21 @@
#include <cstdlib>
#include <string>
CTileLoader::CTileLoader(int episode, int version, size_t NumTiles, unsigned char *data) :
m_TileProperties(g_pBehaviorEngine->getTileProperties())
CTileLoader::CTileLoader(int episode, int version, unsigned char *data)
{
m_episode = episode;
m_version = version;
m_data = data;
m_offset = 0;
m_numtiles = NumTiles;
setupOffsetMap();
}
CTileLoader::CTileLoader(CExeFile &Exefile, size_t NumTiles) :
m_TileProperties(g_pBehaviorEngine->getTileProperties())
CTileLoader::CTileLoader(CExeFile &Exefile)
{
m_episode = Exefile.getEpisode();
m_version = Exefile.getEXEVersion();
m_data = Exefile.getRawData();
m_offset = 0;
m_numtiles = NumTiles;
setupOffsetMap();
}
......@@ -40,30 +36,45 @@ void CTileLoader::setupOffsetMap()
m_offsetMap[1][110] = 0x131F8;
m_offsetMap[1][131] = 0x130F8;
m_offsetMap[1][134] = 0x130F8;
m_offsetMap[2][100] = 0x17938;
m_offsetMap[2][131] = 0x17828;
m_offsetMap[3][100] = 0x199F8;
m_offsetMap[3][131] = 0x198C8;
m_offsetMap[4][140] = 0x249C2;
m_offsetMap[5][140] = 0x25B22;
m_offsetMap[6][140] = 0x25212;
m_offsetMap[7][100] = 0x11322;
}
bool CTileLoader::load()
bool CTileLoader::load(size_t NumUnMaskedTiles, size_t NumMaskedTiles)
{
std::string fname;
long offset = m_offsetMap[m_episode][m_version];
m_data += offset;
CTileProperties TileProperties;
m_TileProperties.assign(m_numtiles, TileProperties);
if(m_offsetMap[m_episode][m_version])
{
if(m_episode == 1 || m_episode == 2 || m_episode == 3 )
readVorticonTileinfo();
if(m_episode == 4 || m_episode == 5 || m_episode == 6 )
readGalaxyTileinfo();
{
CTileProperties TileProperties;
g_pBehaviorEngine->getTileProperties(1).assign(NumMaskedTiles, TileProperties);
readVorticonTileinfo(NumMaskedTiles);
}
if(m_episode == 4 || m_episode == 5 || m_episode == 6 || m_episode == 7 )
{
CTileProperties TileProperties;
g_pBehaviorEngine->getTileProperties(0).assign(NumUnMaskedTiles, TileProperties);
g_pBehaviorEngine->getTileProperties(1).assign(NumMaskedTiles, TileProperties);
readGalaxyTileinfo(NumUnMaskedTiles, NumMaskedTiles);
}
}
return true;
......@@ -73,94 +84,98 @@ bool CTileLoader::load()
* \brief This function assings the tileinfo data block previously read to the internal TileProperties
* structure in CG.
*/
void CTileLoader::readVorticonTileinfo()
void CTileLoader::readVorticonTileinfo(size_t NumTiles)
{
for(size_t j=0 ; j < m_numtiles ; j++)
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties(1);
for(size_t j=0 ; j < NumTiles ; j++)
{
m_TileProperties[j].animation = GETWORD( m_data+(2*j) );
m_TileProperties[j].behaviour = GETWORD( m_data+2*(m_numtiles)+2*j);
m_TileProperties[j].bup = GETWORD( m_data+4*(m_numtiles)+2*j );
m_TileProperties[j].bright = GETWORD( m_data+6*(m_numtiles)+2*j);
m_TileProperties[j].bdown = GETWORD( m_data+8*(m_numtiles)+2*j);
m_TileProperties[j].bleft = GETWORD( m_data+10*(m_numtiles)+2*j);
if( m_TileProperties[j].bleft && m_TileProperties[j].bright &&
m_TileProperties[j].bup && m_TileProperties[j].bdown )
TileProperties[j].animation = GETWORD( m_data+(2*j) );
TileProperties[j].behaviour = GETWORD( m_data+2*(NumTiles)+2*j);
TileProperties[j].bup = GETWORD( m_data+4*(NumTiles)+2*j );
TileProperties[j].bright = GETWORD( m_data+6*(NumTiles)+2*j);
TileProperties[j].bdown = GETWORD( m_data+8*(NumTiles)+2*j);
TileProperties[j].bleft = GETWORD( m_data+10*(NumTiles)+2*j);
if( TileProperties[j].bleft && TileProperties[j].bright &&
TileProperties[j].bup && TileProperties[j].bdown )
{ // This should solve some tile bugs in Episode 2
if(m_TileProperties[j].behaviour == -2 or m_TileProperties[j].behaviour == -1)
m_TileProperties[j].behaviour = 0;
if(TileProperties[j].behaviour == -2 or TileProperties[j].behaviour == -1)
TileProperties[j].behaviour = 0;
}
}
for(size_t j=0 ; j < m_numtiles ; )
for(size_t j=0 ; j < NumTiles ; )
{
size_t value = m_TileProperties[j].animation;
size_t value = TileProperties[j].animation;
if(value == 0) {
j++; continue;
}
// stuff for animated tiles
for( size_t i=0 ; i<value ; i++ )
m_TileProperties[j+i].animOffset = i;
TileProperties[j+i].animOffset = i;
j += value;
}
// This function assigns the correct tiles that have to be changed
assignChangeTileAttribute();
assignChangeTileAttribute(NumTiles);
}
void CTileLoader::readGalaxyTileinfo()
void CTileLoader::readGalaxyTileinfo(size_t NumUnMaskedTiles, size_t NumMaskedTiles)
{
for(size_t j=0 ; j < m_numtiles ; j++)
std::vector<CTileProperties> &TileUnmaskedProperties = g_pBehaviorEngine->getTileProperties(0);
std::vector<CTileProperties> &TileMaskedProperties = g_pBehaviorEngine->getTileProperties(1);
for(size_t j=0 ; j < NumUnMaskedTiles ; j++)
{
m_TileProperties[j].animation = GETWORD( m_data+(2*j) );
m_TileProperties[j].behaviour = GETWORD( m_data+2*(m_numtiles)+2*j);
TileUnmaskedProperties[j].animation = m_data[j];
TileUnmaskedProperties[j].animOffset = m_data[NumUnMaskedTiles+j];
m_TileProperties[j].bup = GETWORD( m_data+4*(m_numtiles)+2*j );
m_TileProperties[j].bright = GETWORD( m_data+6*(m_numtiles)+2*j);
m_TileProperties[j].bdown = GETWORD( m_data+8*(m_numtiles)+2*j);
m_TileProperties[j].bleft = GETWORD( m_data+10*(m_numtiles)+2*j);
/*TileProperties[j].bup = GETWORD( m_data+2*(NumTiles)+j );
TileProperties[j].bright = GETWORD( m_data+3*(NumTiles)+j);
TileProperties[j].bdown = GETWORD( m_data+4*(NumTiles)+j);
TileProperties[j].bleft = GETWORD( m_data+5*(NumTiles)+j);
if( m_TileProperties[j].bleft && m_TileProperties[j].bright &&
m_TileProperties[j].bup && m_TileProperties[j].bdown )
if( TileProperties[j].bleft && TileProperties[j].bright &&
TileProperties[j].bup && TileProperties[j].bdown )
{ // This should solve some tile bugs in Episode 2
if(m_TileProperties[j].behaviour == -2 or m_TileProperties[j].behaviour == -1)
m_TileProperties[j].behaviour = 0;
}
if(TileProperties[j].behaviour == -2 or TileProperties[j].behaviour == -1)
TileProperties[j].behaviour = 0;
}*/
}
for(size_t j=0 ; j < m_numtiles ; )
/*for(size_t j=0 ; j < NumTiles ; )
{
size_t value = m_TileProperties[j].animation;
size_t value = TileProperties[j].animation;
if(value == 0) {
j++; continue;
}
// stuff for animated tiles
for( size_t i=0 ; i<value ; i++ )
m_TileProperties[j+i].animOffset = i;
TileProperties[j+i].animOffset = i;
j += value;
}
// This function assigns the correct tiles that have to be changed
assignChangeTileAttribute();
assignChangeTileAttribute();*/
}
void CTileLoader::assignChangeTileAttribute()
void CTileLoader::assignChangeTileAttribute(size_t NumTiles)
{
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties(1);
// This special call is used for workarounds which are wrong in the tiles attributes file of CG.
// I hope those attributes can be read out of the exe-files in future.
// Everything to zero in order to avoid bugs in mods
// It also assigns the special background tile which is sometimes used in the game for changes
// to real backgrounds
for(size_t i=0 ; i<m_numtiles ; i++)
m_TileProperties[i].chgtile = 0;
for(size_t i=0 ; i<NumTiles ; i++)
TileProperties[i].chgtile = 0;
// At any other case, except some special ones, the tile is always 143 for pickuppable items
// 17 is tile for an exit. Until row 19, this seems to be valid
for(size_t i=0 ; i<m_numtiles ; i++)
for(size_t i=0 ; i<NumTiles ; i++)
if(canbePickedup(i) || isaDoor(i) )
m_TileProperties[i].chgtile = 143;
TileProperties[i].chgtile = 143;
switch(m_episode)
{
......@@ -170,29 +185,29 @@ void CTileLoader::assignChangeTileAttribute()
// TODO: Check out how to perform that chgtile algorithm
for(int i=38*13 ; i<39*13 ; i++) // Workaround for silcar 1. Row 38
if( canbePickedup(i) )
m_TileProperties[i].chgtile = 439;
TileProperties[i].chgtile = 439;
for(int i=35*13 ; i<36*13 ; i++) // Workaround for silcar 4. Row 35
if( canbePickedup(i) )
m_TileProperties[i].chgtile = 335;
TileProperties[i].chgtile = 335;
for(int i=23*13 ; i<24*13 ; i++) // Workaround in Level 12 of Episode 2, where the tiles are solid after a taken item.
m_TileProperties[i].chgtile = 276; // Row 23
TileProperties[i].chgtile = 276; // Row 23
break;
}
case 3:
{
// Episode 3 is a special case, because the items are repeated 6 times
for(size_t i=0 ; i<m_numtiles ; i++)
for(size_t i=0 ; i<NumTiles ; i++)
{
// Only items!!
if(canbePickedup(i))
m_TileProperties[i].chgtile = (i/13)*13;
TileProperties[i].chgtile = (i/13)*13;
// Only for Doors! Tile is always 182
if(isaDoor(i))
m_TileProperties[i].chgtile = 182;
TileProperties[i].chgtile = 182;
}
break;
......@@ -202,16 +217,18 @@ void CTileLoader::assignChangeTileAttribute()
bool CTileLoader::canbePickedup(int tile)
{
return ((m_TileProperties[tile].behaviour >= 6 &&
m_TileProperties[tile].behaviour <= 21 &&
m_TileProperties[tile].behaviour != 17) ||
m_TileProperties[tile].behaviour == 27 ||
m_TileProperties[tile].behaviour == 28);
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties(1);
return ((TileProperties[tile].behaviour >= 6 &&
TileProperties[tile].behaviour <= 21 &&
TileProperties[tile].behaviour != 17) ||
TileProperties[tile].behaviour == 27 ||
TileProperties[tile].behaviour == 28);
}
bool CTileLoader::isaDoor(int tile)
{
return (m_TileProperties[tile].behaviour >= 2 && m_TileProperties[tile].behaviour <= 5);
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties(1);
return (TileProperties[tile].behaviour >= 2 && TileProperties[tile].behaviour <= 5);
}
CTileLoader::~CTileLoader() {
......
......@@ -15,14 +15,12 @@
class CTileLoader {
public:
CTileLoader(int episode, int version, size_t NumTiles, unsigned char *data);
CTileLoader(CExeFile &Exefile, size_t NumTiles);
CTileLoader(int episode, int version, unsigned char *data);
CTileLoader(CExeFile &Exefile);
bool load();
void readVorticonTileinfo();
void readGalaxyTileinfo();
int getNumTiles() { return m_numtiles; }
bool load(size_t NumUnMaskedTiles, size_t NumMaskedTiles);
void readVorticonTileinfo(size_t NumTiles);
void readGalaxyTileinfo(size_t NumUnMaskedTiles, size_t NumMaskedTiles);
virtual ~CTileLoader();
......@@ -31,15 +29,12 @@ private:
int m_version;
long m_offset;
unsigned char *m_data;
size_t m_numtiles;
//std::map<std::map<int,int>, long> m_offsetMap;
typedef std::map<int,long> VersionMap;
std::map<int, VersionMap> m_offsetMap;
std::vector<CTileProperties> &m_TileProperties;
void assignChangeTileAttribute();
void assignChangeTileAttribute(size_t NumTiles);
void setupOffsetMap();
bool canbePickedup(int tile);
bool isaDoor(int tile);
......
......@@ -21,7 +21,8 @@ m_fgcolour(0x0),
m_bgcolour(0x0),
m_monochrome(false)
{
m_widthtable.assign(256,8);
//m_widthtable.assign(256,8);
memset(&m_widthtable, 8, 256);
}
bool CFont::CreateSurface(SDL_Color *Palette, Uint32 Flags, Uint8 bpp, Uint16 width, Uint16 height)
......@@ -90,7 +91,7 @@ bool CFont::loadHiColourFont( const std::string& filename )
// in the galaxy engine.
void CFont::setWidthToCharacter(Uint8 width, Uint16 letter)
{
m_widthtable.at(letter) = width;
m_widthtable[letter] = width;
}
/**
......@@ -155,7 +156,7 @@ void CFont::drawCharacter(SDL_Surface* dst, Uint16 character, Uint16 xoff, Uint1
scrrect.x = (m_ColouredSurface->w/16)*(character%16);
scrrect.y = (m_ColouredSurface->h/16)*(character/16);
scrrect.w = dstrect.w = (m_widthtable.at(character));
scrrect.w = dstrect.w = (m_widthtable[character]);
scrrect.h = dstrect.h = (m_ColouredSurface->h/16);
dstrect.x = xoff; dstrect.y = yoff;
......
......@@ -46,7 +46,8 @@ public:
private:
SDL_Surface *m_FontSurface, *m_ColouredSurface;
Uint32 m_fgcolour, m_bgcolour;
std::vector<Uint8> m_widthtable;
//std::vector<Uint8> m_widthtable;
Uint8 m_widthtable[256];
bool m_monochrome;
};
......
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