Changed TR library to use LOAD_FILE_FOR_ME

ns-alfred-2.zip


git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@177 67975925-1194-0748-b3d5-c16f83f1a3a1
This commit is contained in:
puzl 2005-06-10 03:00:15 +00:00
parent beff88b4ac
commit e844e297ae
7 changed files with 63 additions and 41 deletions

Binary file not shown.

Binary file not shown.

View file

@ -49,7 +49,7 @@ cl_enginefunc_t gEngfuncs;
//UIHud gHUD("StratHL/ui.txt", new AvHUIFactory());
AvHHud& getHUD() {
static AvHHud theGlobalHud( (string(getModDirectory()) + string("/ui.txt")).c_str(), new AvHUIFactory());
static AvHHud theGlobalHud( "ui.txt", new AvHUIFactory());
return theGlobalHud;
}

View file

@ -2059,22 +2059,37 @@ void AvHGamerules::PreWorldPrecacheInitParticles()
// Load up the particle systems from modname.ps then levelname.ps
TRDescriptionList theDescriptionList;
string theLevelBaseSystemFile = string(getModDirectory()) + "/" + kBasePSName;
if(TRFactory::ReadDescriptions(theLevelBaseSystemFile, theDescriptionList))
char *pbuffer = NULL;
int len;
// Read them in from proper file
pbuffer = (char *)LOAD_FILE_FOR_ME( kBasePSName, &len ); // Use malloc
ASSERT(pbuffer);
strstream trstream(pbuffer, len);
if(TRFactory::ReadDescriptions(trstream, theDescriptionList))
{
gParticleTemplateList.CreateTemplates(theDescriptionList);
}
theDescriptionList.clear();
FREE_FILE(pbuffer);
// TODO: the level name isn't populated yet for some reason
const char* theCStrLevelName = STRING(gpGlobals->mapname);
if(theCStrLevelName && !FStrEq(theCStrLevelName, ""))
{
string theLevelName = theCStrLevelName;
string theLevelParticleSystemFile = string(getModDirectory()) + string("/") + theLevelName + string(".ps");
if(TRFactory::ReadDescriptions(theLevelParticleSystemFile, theDescriptionList))
{
gParticleTemplateList.CreateTemplates(theDescriptionList);
string theLevelParticleSystemFile = theLevelName + string(".ps");
// Read them in from proper file
pbuffer = (char *)LOAD_FILE_FOR_ME( (char *)theLevelParticleSystemFile.c_str(), &len ); // Use malloc
if ( pbuffer ) {
strstream trstream(pbuffer, len);
if(TRFactory::ReadDescriptions(trstream, theDescriptionList))
{
gParticleTemplateList.CreateTemplates(theDescriptionList);
}
FREE_FILE(pbuffer);
}
}
}

View file

@ -25,35 +25,30 @@
const int maxLineLength = 256;
bool TRFactory::ReadDescriptions(const string& inRelativePathFilename, TRDescriptionList& outDescriptionList)
bool TRFactory::ReadDescriptions(strstream &trstream, TRDescriptionList& outDescriptionList)
{
bool theSuccess = false;
bool theDescriptionRead = false;
int count=0;
do
{
// Try to read the next description in
TRDescription theNextDescription;
theDescriptionRead = ReadDescription(trstream, theNextDescription);
// Open file specified by relative path name
fstream infile;
infile.open(inRelativePathFilename.c_str(), ios::in);
if(infile.is_open())
{
do
// add it to the description list
if(theDescriptionRead)
{
// Try to read the next description in
TRDescription theNextDescription;
theDescriptionRead = ReadDescription(infile, theNextDescription);
count++;
// Function is successful if at least one description was found
outDescriptionList.push_back(theNextDescription);
theSuccess = true;
}
else {
int a=0;
}
// add it to the description list
if(theDescriptionRead)
{
// Function is successful if at least one description was found
outDescriptionList.push_back(theNextDescription);
theSuccess = true;
}
} while(theDescriptionRead);
infile.close();
}
} while(theDescriptionRead);
return theSuccess;
}
@ -93,7 +88,7 @@ bool TRFactory::WriteDescriptions(const string& inRelativePathFilename, const TR
}
// TODO: Add case-insensitivity
bool TRFactory::ReadDescription(fstream& infile, TRDescription& outDescription)
bool TRFactory::ReadDescription(strstream& infile, TRDescription& outDescription)
{
bool theSuccess = false;
string currentLine;

View file

@ -18,7 +18,7 @@
//===============================================================================
#ifndef TRFACTORY_H
#define TRFACTORY_H
#include <strstream>
#include "textrep/TRDescription.h"
#include "string.h"
@ -28,11 +28,11 @@ class TRFactory
{
public:
// Read all the descriptions from the file
static bool ReadDescriptions(const string& inRelativePathFilename, TRDescriptionList& outDescriptionList);
static bool ReadDescriptions(strstream& trstream, TRDescriptionList& outDescriptionList);
static bool WriteDescriptions(const string& inRelativePathFilename, const TRDescriptionList& inDescriptionList, const string& inHeader);
private:
static bool ReadDescription(fstream& infile, TRDescription& outDescription);
static bool ReadDescription(strstream& infile, TRDescription& outDescription);
static bool WriteDescription(fstream& outfile, const TRDescription& inDescription);
static bool charIsWhiteSpace(char inChar);

View file

@ -2,6 +2,9 @@
#include "textrep/TRFactory.h"
#include "cl_dll/cl_util.h"
#include "cl_dll/hud.h"
#include "cl_dll/wrect.h"
#include "cl_dll/cl_dll.h"
#include "dlls/extdll.h"
#include "vgui_Scheme.h"
#include "vgui_Panel.h"
#include "mod/AvHClientVariables.h"
@ -39,15 +42,24 @@ UIHud::UIHud(const string& inFilename, UIFactory* inFactory) : CHud(), mFilename
// Init cursor variables
this->mArrowBitmap = NULL;
this->mArrowCursor = NULL;
// Open file specified by relative path name
char *pbuffer = NULL;
int len;
// Read them in from proper file
pbuffer = (char *)gEngfuncs.COM_LoadFile( (char *)inFilename.c_str(), 5, &len ); // Use malloc
if(TRFactory::ReadDescriptions(mFilename, this->mDescriptionList))
{
}
else
{
// TODO: Emit error
}
if ( pbuffer ) {
strstream trstream(pbuffer, len);
if(TRFactory::ReadDescriptions(trstream, this->mDescriptionList))
{
}
else
{
// TODO: Emit error
}
gEngfuncs.COM_FreeFile(pbuffer);
}
this->mSchemeManager = NULL;
}