Permalink
Browse files

Start of PCK code

  • Loading branch information...
pmprog committed Jul 11, 2014
1 parent c176887 commit 7f280843c14a5ed22e2bbd9362c96a5a5b431a49
View
@@ -196,6 +196,10 @@
RelativePath=".\library\configfile.cpp"
>
</File>
<File
RelativePath=".\game\apocresources\cursor.cpp"
>
</File>
<File
RelativePath=".\framework\event.cpp"
>
@@ -248,6 +252,10 @@
RelativePath=".\game\apocresources\palette.cpp"
>
</File>
<File
RelativePath=".\game\apocresources\pck.cpp"
>
</File>
<File
RelativePath=".\game\apocresources\rawsound.cpp"
>
@@ -310,6 +318,10 @@
RelativePath=".\library\configfile.h"
>
</File>
<File
RelativePath=".\game\apocresources\cursor.h"
>
</File>
<File
RelativePath=".\framework\event.h"
>
@@ -366,6 +378,10 @@
RelativePath=".\game\apocresources\palette.h"
>
</File>
<File
RelativePath=".\game\apocresources\pck.h"
>
</File>
<File
RelativePath=".\game\apocresources\rawsound.h"
>
View
BIN +4.05 KB apocicon.ico
Binary file not shown.
@@ -18,18 +18,21 @@ ApocalypseFont::ApocalypseFont( FontType Face, Palette* ColourPalette )
fontrows = 24;
fontchars = 129;
charmaxwidth = 14;
spacewidth = 6;
break;
case ApocalypseFont::SmallFont:
datfile.append( "SMALFONT" );
fontrows = 15;
fontchars = 140;
charmaxwidth = 14;
spacewidth = 3;
break;
case ApocalypseFont::TinyFont:
datfile.append( "SMALLSET" );
fontrows = 12;
fontchars = 128;
charmaxwidth = 8;
spacewidth = 3;
break;
}
std::string spcfile( datfile );
@@ -53,10 +56,8 @@ ApocalypseFont::ApocalypseFont( FontType Face, Palette* ColourPalette )
rowptr->r = palcol->r;
rowptr->g = palcol->g;
rowptr->b = palcol->b;
if( palidx == 0 )
if ( palcol->a > 0 && x > w )
{
rowptr->a = 0;
} else if ( x > w ) {
w = x;
}
}
@@ -87,7 +88,7 @@ void ApocalypseFont::DrawString( int X, int Y, std::string Text, int Alignment )
{
textlen += fontwidths.at( charidx );
} else {
textlen += 3;
textlen += spacewidth;
}
}
@@ -110,7 +111,7 @@ void ApocalypseFont::DrawString( int X, int Y, std::string Text, int Alignment )
al_draw_bitmap( fontbitmaps.at( charidx ), xpos, Y, 0 );
xpos += fontwidths.at( charidx );
} else {
xpos += 3;
xpos += spacewidth;
}
}
}
@@ -17,7 +17,7 @@ class ApocalypseFont
std::vector<ALLEGRO_BITMAP*> fontbitmaps;
std::vector<int> fontwidths;
int spacewidth;
public:
enum FontType
@@ -0,0 +1,61 @@
#include "cursor.h"
Cursor::Cursor( Palette* ColourPalette )
{
ALLEGRO_FILE* f = al_fopen( "data/TACDATA/MOUSE.DAT", "rb" );
while( images.size() < al_fsize( f ) / 576 )
{
ALLEGRO_BITMAP* b = al_create_bitmap( 24, 24 );
ALLEGRO_LOCKED_REGION* r = al_lock_bitmap( b, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 );
for( int y = 0; y < 24; y++ )
{
for( int x = 0; x < 24; x++ )
{
int palidx = al_fgetc( f );
Colour* rowptr = (Colour*)(&((char*)r->data)[ (y * r->pitch) + (x * 4) ]);
Colour* palcol = ColourPalette->GetColour( palidx );
rowptr->a = palcol->a;
rowptr->r = palcol->r;
rowptr->g = palcol->g;
rowptr->b = palcol->b;
}
}
al_unlock_bitmap( b );
images.push_back( b );
}
CurrentType = CursorType::Normal;
cursorx = 0;
cursory = 0;
}
Cursor::~Cursor()
{
while( images.size() > 0 )
{
al_destroy_bitmap( images.back() );
images.pop_back();
}
}
void Cursor::EventOccured( Event* e )
{
if( e->Type == EVENT_MOUSE_MOVE )
{
cursorx = e->Data.Mouse.X;
cursory = e->Data.Mouse.Y;
}
if( e->Type == EVENT_MOUSE_DOWN )
{
CurrentType = (CursorType)(((int)CurrentType + 1) % images.size());
}
}
void Cursor::Render()
{
al_draw_bitmap( images.at( (int)CurrentType ), cursorx, cursory, 0 );
}
@@ -0,0 +1,37 @@
#pragma once
#include "../../framework/includes.h"
#include "../../framework/event.h"
#include "palette.h"
class Cursor
{
private:
std::vector<ALLEGRO_BITMAP*> images;
int cursorx;
int cursory;
public:
enum CursorType
{
Normal,
ThrowTarget,
PsiTarget,
NoTarget,
Add,
Shoot,
Control,
Teleport,
NoTeleport
};
CursorType CurrentType;
Cursor( Palette* ColourPalette );
~Cursor();
void EventOccured( Event* e );
void Render();
};
@@ -16,10 +16,10 @@ Palette::Palette( std::string Filename )
while( !al_feof( f ) )
{
al_fread( f, (void*)&colourblock, 3 );
colours[idx].a = 255;
colours[idx].r = colourblock[0] << 2;
colours[idx].a = (idx == 0 ? 0 : 255);
colours[idx].r = colourblock[2] << 2;
colours[idx].g = colourblock[1] << 2;
colours[idx].b = colourblock[2] << 2;
colours[idx].b = colourblock[0] << 2;
idx++;
}
View
@@ -0,0 +1,110 @@
#include "pck.h"
PCK::PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain, Palette* ColourPalette )
{
ALLEGRO_FILE* pck = al_fopen( PckFilename.c_str(), "rb" );
ALLEGRO_FILE* tab = al_fopen( TabFilename.c_str(), "rb" );
terrain = ContainsTerrain;
PCKImageHeader imgheader;
ALLEGRO_BITMAP* bitmap;
ALLEGRO_LOCKED_REGION* region;
int c1_regionlocation;
int32_t c1_pixelstoskip;
int c1_startcol;
int c1_pixelsinrecord;
int c1_reserved;
int c1_pxcount2;
for( int i = 0; i < al_fsize( tab ) / 4; i++ )
{
unsigned int offset = al_fread32le( tab );
al_fseek( pck, offset, ALLEGRO_SEEK_SET );
// Terrain blocks
if( terrain )
{
offset *= 4;
}
// Read each "angle"
for( int tidx = 1; tidx <= (terrain ? 4 : 1); tidx++ )
{
al_fread( pck, &imgheader, sizeof( PCKImageHeader ) );
switch( imgheader.CompressionMethod )
{
case 0:
// No images
break;
case 1:
bitmap = al_create_bitmap( 640, 480 );
region = al_lock_bitmap( bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 );
c1_regionlocation = 0;
c1_pixelstoskip = al_fread32le( pck );
while( c1_pixelstoskip != -1 )
{
c1_regionlocation = ((c1_pixelstoskip / 640) * region->pitch) + (c1_pixelstoskip % 640);
c1_startcol = al_fgetc( pck );
c1_pixelsinrecord = al_fgetc( pck );
c1_reserved = al_fgetc( pck );
c1_pxcount2 = al_fgetc( pck );
for( int c1_x = 0; c1_x < c1_pixelsinrecord; c1_x++ )
{
Colour* c1_rowptr = (Colour*)(&((char*)region->data)[ c1_regionlocation + (c1_x * 4) ]);
Colour* c1_palcol = ColourPalette->GetColour( al_fgetc( pck ) );
c1_rowptr->a = c1_palcol->a;
c1_rowptr->r = c1_palcol->r;
c1_rowptr->g = c1_palcol->g;
c1_rowptr->b = c1_palcol->b;
}
c1_pixelstoskip = al_fread32le( pck );
}
al_unlock_bitmap( bitmap );
images.push_back( bitmap );
break;
case 2:
// Unknown/unused
break;
case 3:
break;
case 128:
break;
default:
// No idea
break;
}
}
}
al_fclose( tab );
al_fclose( pck );
}
PCK::~PCK()
{
}
int PCK::GetImageCount()
{
return images.size();
}
void PCK::RenderImage( int Index, int X, int Y )
{
al_draw_bitmap( images.at(Index), X, Y, 0 );
}
View
@@ -0,0 +1,33 @@
#pragma once
#include "../../framework/includes.h"
#include "../../library/memory.h"
#include "palette.h"
typedef struct PCKImageHeader
{
char CompressionMethod;
char Reserved1;
char Reserved2;
char Reserved3;
int16_t LeftMostPixel;
int16_t RightMostPixel;
int16_t TopMostPixel;
int16_t BottomMostPixel;
} PCKImageHeader;
class PCK
{
private:
bool terrain;
std::vector<ALLEGRO_BITMAP*> images;
public:
PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain, Palette* ColourPalette );
~PCK();
int GetImageCount();
void RenderImage( int Index, int X, int Y );
};
Oops, something went wrong.

0 comments on commit 7f28084

Please sign in to comment.