Added support for packed ani and font files
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3084 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Changes towards version 0.7:
|
||||
- Added support for packed ani and font files - Mika
|
||||
- DrawTracedText abstraction (bug #1029), from Nic
|
||||
- Experimental support for Symbian S60 3rd edition - Mika & SvdB
|
||||
- Pthread support - Mika
|
||||
|
||||
+6
-6
@@ -60,6 +60,7 @@ uio_DirHandle *contentDir;
|
||||
uio_DirHandle *configDir;
|
||||
uio_DirHandle *saveDir;
|
||||
uio_DirHandle *meleeDir;
|
||||
uio_MountHandle *contentMountHandle;
|
||||
|
||||
char baseContentPath[PATH_MAX];
|
||||
|
||||
@@ -312,15 +313,14 @@ prepareMeleeDir (void) {
|
||||
static void
|
||||
mountContentDir (uio_Repository *repository, const char *contentPath)
|
||||
{
|
||||
uio_MountHandle *contentHandle;
|
||||
uio_DirHandle *packagesDir, *addonsDir;
|
||||
static uio_AutoMount *autoMount[] = { NULL };
|
||||
availableAddons = NULL;
|
||||
|
||||
contentHandle = uio_mountDir (repository, "/",
|
||||
contentMountHandle = uio_mountDir (repository, "/",
|
||||
uio_FSTYPE_STDIO, NULL, NULL, contentPath, autoMount,
|
||||
uio_MOUNT_TOP | uio_MOUNT_RDONLY, NULL);
|
||||
if (contentHandle == NULL)
|
||||
if (contentMountHandle == NULL)
|
||||
{
|
||||
log_add (log_Fatal, "Fatal error: Could not mount content dir: %s",
|
||||
strerror (errno));
|
||||
@@ -338,7 +338,7 @@ mountContentDir (uio_Repository *repository, const char *contentPath)
|
||||
packagesDir = uio_openDir (repository, "/packages", 0);
|
||||
if (packagesDir != NULL)
|
||||
{
|
||||
mountDirZips (contentHandle, packagesDir, "/");
|
||||
mountDirZips (contentMountHandle, packagesDir, "/");
|
||||
uio_closeDir (packagesDir);
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ mountContentDir (uio_Repository *repository, const char *contentPath)
|
||||
return;
|
||||
}
|
||||
|
||||
mountDirZips (contentHandle, addonsDir, "addons");
|
||||
mountDirZips (contentMountHandle, addonsDir, "addons");
|
||||
|
||||
availableAddons = uio_getDirList (addonsDir, "", "", match_MATCH_PREFIX);
|
||||
if (availableAddons != NULL)
|
||||
@@ -387,7 +387,7 @@ mountContentDir (uio_Repository *repository, const char *contentPath)
|
||||
"not found; addon skipped.", addon);
|
||||
continue;
|
||||
}
|
||||
mountDirZips (contentHandle, addonDir, mountname);
|
||||
mountDirZips (contentMountHandle, addonDir, mountname);
|
||||
uio_closeDir (addonDir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ extern uio_DirHandle *saveDir;
|
||||
extern uio_DirHandle *meleeDir;
|
||||
extern char baseContentPath[PATH_MAX];
|
||||
|
||||
extern uio_MountHandle *contentMountHandle;
|
||||
|
||||
extern uio_DirList *availableAddons;
|
||||
extern const char **optAddons;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ LoadFontFile (const char *pStr)
|
||||
return 0;
|
||||
|
||||
fp = res_OpenResFile (contentDir, pStr, "rb");
|
||||
if (fp == (uio_Stream *) ~0)
|
||||
if (fp != NULL)
|
||||
{
|
||||
FONT hData;
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ getCharFrame (FONT_DESC *fontPtr, wchar_t ch)
|
||||
}
|
||||
else
|
||||
{
|
||||
log_add (log_Debug, "Character %u not present", (unsigned int) ch);
|
||||
//log_add (log_Debug, "Character %u not present", (unsigned int) ch);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ typedef struct anidata
|
||||
int hotspot_y;
|
||||
} AniData;
|
||||
|
||||
extern uio_Repository *repository;
|
||||
static uio_AutoMount *autoMount[] = { NULL };
|
||||
|
||||
static void
|
||||
process_image (FRAME FramePtr, SDL_Surface *img[], AniData *ani, int cel_ct)
|
||||
@@ -375,61 +377,100 @@ _GetCelData (uio_Stream *fp, DWORD length)
|
||||
{
|
||||
int cel_total, cel_index, n;
|
||||
DWORD opos;
|
||||
char CurrentLine[1024], filename[1024];
|
||||
char CurrentLine[1024], filename[PATH_MAX];
|
||||
SDL_Surface **img;
|
||||
AniData *ani;
|
||||
DRAWABLE Drawable;
|
||||
uio_MountHandle *aniMount = 0;
|
||||
uio_DirHandle *aniDir = 0;
|
||||
uio_Stream *aniFile = 0;
|
||||
|
||||
opos = uio_ftell (fp);
|
||||
|
||||
{
|
||||
char *s1, *s2;
|
||||
char aniDirName[PATH_MAX];
|
||||
const char *aniFileName;
|
||||
uint32 header = 0;
|
||||
|
||||
if (_cur_resfile_name == 0
|
||||
|| (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0)
|
||||
&& (s2 = strrchr (_cur_resfile_name, '\\')) == 0))
|
||||
{
|
||||
n = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s2 > s1)
|
||||
s1 = s2;
|
||||
n = s1 - _cur_resfile_name + 1;
|
||||
}
|
||||
|
||||
uio_fread(&header, 4, 1, fp);
|
||||
if (_cur_resfile_name && header == 0x04034b50)
|
||||
{
|
||||
// zipped ani file
|
||||
if (n)
|
||||
{
|
||||
strncpy (aniDirName, _cur_resfile_name, n - 1);
|
||||
aniDirName[n - 1] = 0;
|
||||
aniFileName = _cur_resfile_name + n;
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(aniDirName, ".");
|
||||
aniFileName = _cur_resfile_name;
|
||||
}
|
||||
aniDir = uio_openDir (repository, aniDirName, 0);
|
||||
aniMount = uio_mountDir (repository, aniDirName, uio_FSTYPE_ZIP,
|
||||
aniDir, aniFileName, "/", autoMount,
|
||||
uio_MOUNT_RDONLY | uio_MOUNT_ABOVE,
|
||||
contentMountHandle);
|
||||
aniFile = uio_fopen (aniDir, aniFileName, "r");
|
||||
opos = 0;
|
||||
n = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// unpacked ani file
|
||||
strncpy (filename, _cur_resfile_name, n);
|
||||
aniFile = fp;
|
||||
aniDir = contentDir;
|
||||
}
|
||||
}
|
||||
|
||||
cel_total = 0;
|
||||
while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp))
|
||||
uio_fseek (aniFile, opos, SEEK_SET);
|
||||
while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile))
|
||||
{
|
||||
++cel_total;
|
||||
}
|
||||
|
||||
img = HMalloc (sizeof (SDL_Surface *) * cel_total);
|
||||
if (!img)
|
||||
{
|
||||
log_add (log_Warning, "Couldn't allocate space for '%s' images", _cur_resfile_name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ani = HMalloc (sizeof (AniData) * cel_total);
|
||||
if (!ani)
|
||||
if (!img || !ani)
|
||||
{
|
||||
log_add (log_Warning, "Couldn't allocate space for '%s'", _cur_resfile_name);
|
||||
if (aniMount)
|
||||
{
|
||||
uio_fclose(aniFile);
|
||||
uio_closeDir(aniDir);
|
||||
uio_unmountDir(aniMount);
|
||||
}
|
||||
HFree (img);
|
||||
log_add (log_Warning, "Couldn't allocate space for '%s' anidata", _cur_resfile_name);
|
||||
|
||||
HFree (ani);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cel_index = 0;
|
||||
uio_fseek (fp, opos, SEEK_SET);
|
||||
while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && cel_index < cel_total)
|
||||
uio_fseek (aniFile, opos, SEEK_SET);
|
||||
while (uio_fgets (CurrentLine, sizeof (CurrentLine), aniFile) && cel_index < cel_total)
|
||||
{
|
||||
sscanf (CurrentLine, "%s %d %d %d %d", &filename[n],
|
||||
&ani[cel_index].transparent_color, &ani[cel_index].colormap_index,
|
||||
&ani[cel_index].hotspot_x, &ani[cel_index].hotspot_y);
|
||||
|
||||
img[cel_index] = sdluio_loadImage (contentDir, filename);
|
||||
img[cel_index] = sdluio_loadImage (aniDir, filename);
|
||||
if (img[cel_index] == NULL)
|
||||
{
|
||||
const char *err;
|
||||
@@ -451,7 +492,7 @@ _GetCelData (uio_Stream *fp, DWORD length)
|
||||
++cel_index;
|
||||
}
|
||||
|
||||
if ((int)uio_ftell (fp) - (int)opos >= (int)length)
|
||||
if ((int)uio_ftell (aniFile) - (int)opos >= (int)length)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -483,6 +524,13 @@ _GetCelData (uio_Stream *fp, DWORD length)
|
||||
log_add (log_Warning, "Couldn't get cel data for '%s'",
|
||||
_cur_resfile_name);
|
||||
|
||||
if (aniMount)
|
||||
{
|
||||
uio_fclose(aniFile);
|
||||
uio_closeDir(aniDir);
|
||||
uio_unmountDir(aniMount);
|
||||
}
|
||||
|
||||
HFree (img);
|
||||
HFree (ani);
|
||||
return Drawable;
|
||||
@@ -547,11 +595,45 @@ _GetFontData (uio_Stream *fp, DWORD length)
|
||||
size_t numBCDs = 0;
|
||||
int dirEntryI;
|
||||
uio_DirHandle *fontDirHandle = NULL;
|
||||
uio_MountHandle *fontMount = NULL;
|
||||
FONT fontPtr = NULL;
|
||||
|
||||
if (_cur_resfile_name == 0)
|
||||
goto err;
|
||||
|
||||
if (fp != (uio_Stream*)~0)
|
||||
{
|
||||
// font is zipped instead of being in a directory
|
||||
|
||||
char *s1, *s2;
|
||||
int n;
|
||||
const char *fontZipName;
|
||||
char fontDirName[PATH_MAX];
|
||||
|
||||
if ((((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0)
|
||||
&& (s2 = strrchr (_cur_resfile_name, '\\')) == 0))
|
||||
{
|
||||
strcpy(fontDirName, ".");
|
||||
fontZipName = _cur_resfile_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s2 > s1)
|
||||
s1 = s2;
|
||||
n = s1 - _cur_resfile_name + 1;
|
||||
strncpy (fontDirName, _cur_resfile_name, n - 1);
|
||||
fontDirName[n - 1] = 0;
|
||||
fontZipName = _cur_resfile_name + n;
|
||||
}
|
||||
|
||||
fontDirHandle = uio_openDir (repository, fontDirName, 0);
|
||||
fontMount = uio_mountDir (repository, _cur_resfile_name, uio_FSTYPE_ZIP,
|
||||
fontDirHandle, fontZipName, "/", autoMount,
|
||||
uio_MOUNT_RDONLY | uio_MOUNT_ABOVE,
|
||||
contentMountHandle);
|
||||
uio_closeDir (fontDirHandle);
|
||||
}
|
||||
|
||||
fontDir = CaptureDirEntryTable (LoadDirEntryTable (contentDir,
|
||||
_cur_resfile_name, ".", match_MATCH_SUBSTRING));
|
||||
if (fontDir == 0)
|
||||
@@ -597,6 +679,8 @@ _GetFontData (uio_Stream *fp, DWORD length)
|
||||
}
|
||||
uio_closeDir (fontDirHandle);
|
||||
DestroyDirEntryTable (ReleaseDirEntryTable (fontDir));
|
||||
if (fontMount != 0)
|
||||
uio_unmountDir(fontMount);
|
||||
|
||||
#if 0
|
||||
if (numBCDs == 0)
|
||||
@@ -697,6 +781,10 @@ err:
|
||||
|
||||
if (fontDir != 0)
|
||||
DestroyDirEntryTable (ReleaseDirEntryTable (fontDir));
|
||||
|
||||
if (fontMount != 0)
|
||||
uio_unmountDir(fontMount);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user