📄 wadfile.cpp
字号:
/****************************************************************************************/
/* WadFile.cpp */
/* */
/* Author: Jim Mischel, Ken Baird, Eli Boling */
/* Description: bitmap related stuff */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/*Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/* Modified by Tom Morris for GenEdit-Classic ver. 0.55, Jan. 10, 2001 */
/****************************************************************************************/
#include "stdafx.h"
#include "WadFile.h"
#include "ram.h"
#include "vfile.h"
#include "util.h"
#include <assert.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static void WadFileEntry_Free (WadFileEntry *pe)
{
if (pe->LockedBitmap != NULL)
{
geBitmap_UnLock (pe->LockedBitmap);
}
if (pe->bmp != NULL)
{
geBitmap_Destroy (&pe->bmp);
}
if (pe->Name != NULL)
{
geRam_Free (pe->Name);
}
}
CWadFile::CWadFile()
{
mBitmapCount = 0;
mBitmaps = NULL;
}
CWadFile::DestroyBitmapArray ()
{
if( mBitmaps != NULL )
{
for (; mBitmapCount > 0; --mBitmapCount)
{
WadFileEntry_Free (&mBitmaps[mBitmapCount-1]);
}
geRam_Free (mBitmaps);
}
}
CWadFile::~CWadFile()
{
DestroyBitmapArray ();
}
static int wadCountFiles (geVFile *vfs, const char *fspec)
{
int nFiles = 0;
geVFile_Finder *Finder;
// count the number of files
Finder = geVFile_CreateFinder (vfs, fspec);
if (Finder != NULL)
{
while (geVFile_FinderGetNextFile (Finder) != GE_FALSE)
{
++nFiles;
}
geVFile_DestroyFinder (Finder);
}
return nFiles;
}
// post 0.5 release // comparison function for sorting mBitmaps alphabetically
int CompareNames(const void *pArg1, const void *pArg2)
{
WadFileEntry *pEntry1 = (WadFileEntry *)pArg1; // cast pArg1 as a WadFileEntry type
WadFileEntry *pEntry2 = (WadFileEntry *)pArg2;
return stricmp(pEntry1->Name, pEntry2->Name); // do case-insensitive compare
}
geBoolean CWadFile::Setup(const char *Filename)
{
geVFile * Library;
int nFiles;
geBoolean NoErrors = GE_FALSE;
Library = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_VIRTUAL, Filename, NULL, GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_DIRECTORY);
if (Library != NULL)
{
NoErrors = GE_TRUE;
DestroyBitmapArray ();
nFiles = wadCountFiles (Library, "*.*");
if (nFiles > 0)
{
// make new array and fill it with loaded bitmaps
mBitmaps = (WadFileEntry *)geRam_Allocate (nFiles * sizeof (WadFileEntry));
mBitmaps[10].Name;
// and fill array with filenames
NoErrors = GE_FALSE;
geVFile_Finder *Finder = geVFile_CreateFinder (Library, "*.*");
if (Finder != NULL)
{
NoErrors = GE_TRUE;
geVFile_Properties Props;
while (geVFile_FinderGetNextFile (Finder) != GE_FALSE)
{
geVFile_FinderGetProperties (Finder, &Props);
// load the file and create a DibBitmap from it
geVFile *BmpFile = geVFile_Open (Library, Props.Name, GE_VFILE_OPEN_READONLY);
geBitmap *TheBitmap;
if (BmpFile == NULL)
{
NoErrors = GE_FALSE;
}
else
{
TheBitmap = geBitmap_CreateFromFile (BmpFile);
geVFile_Close (BmpFile);
if (TheBitmap == NULL)
{
NoErrors = GE_FALSE;
}
else
{
if (geBitmap_SetFormat (TheBitmap, GE_PIXELFORMAT_16BIT_555_RGB, GE_FALSE, 0, NULL) != GE_FALSE)
{
WadFileEntry *pe;
geBitmap_Info info, info2;
geBitmap_GetInfo (TheBitmap, &info, &info2);
pe = &mBitmaps[mBitmapCount];
pe->bmp = TheBitmap;
pe->Height = info.Height;
pe->Width = info.Width;
pe->Name = Util_Strdup (Props.Name);
geBitmap_LockForReadNative (pe->bmp, &pe->LockedBitmap, 0, 0);
pe->BitsPtr = geBitmap_GetBits (pe->LockedBitmap);
++mBitmapCount;
}
else
{
geBitmap_Destroy (&TheBitmap);
NoErrors = GE_FALSE;
}
}
}
}
geVFile_DestroyFinder (Finder);
}
}
geVFile_Close (Library);
}
// post 0.5 release // sort the final mBitmaps so the texture browser
// will display textures alphabetically
qsort(mBitmaps, nFiles, sizeof(WadFileEntry), CompareNames);
return GE_TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -