many C-string -> std::string replacements and some additional code taken from OpenLieroX

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@87 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
albertzeyer
2009-07-22 15:17:41 +00:00
parent cb3c2e2502
commit 5fcc021293
73 changed files with 12091 additions and 6988 deletions

View File

@@ -480,7 +480,7 @@ char tempbuf[80];
#else
sprintf(tempbuf, "FPS: %03d", fps);
#endif
g_pGraphics->drawFont( (unsigned char *) tempbuf, 320-3-(strlen( (char *) tempbuf)<<3), 3, 1);
g_pGraphics->drawFont( tempbuf, 320-3-(strlen( (char *) tempbuf)<<3), 3, 1);
}
update_screen();
@@ -765,7 +765,7 @@ int y;
y = CONSOLE_MESSAGE_Y;
for(i=0;i<NumConsoleMessages;i++)
{
g_pGraphics->drawFont( (unsigned char *) cmsg[i].msg, CONSOLE_MESSAGE_X, y, 1);
g_pGraphics->drawFont( cmsg[i].msg, CONSOLE_MESSAGE_X, y, 1);
y += CONSOLE_MESSAGE_SPACING;
}
}

View File

@@ -21,7 +21,6 @@ struct st_resolution
#include <SDL.h>
#include <iostream>
#include <list>
using namespace std;
inline bool LockSurface(SDL_Surface * bmp) {
if (SDL_MUSTLOCK(bmp))
@@ -110,8 +109,8 @@ private:
st_resolution m_Resolution;
list<st_resolution> m_Resolutionlist;
list<st_resolution> :: iterator m_Resolution_pos;
std::list<st_resolution> m_Resolutionlist;
std::list<st_resolution> :: iterator m_Resolution_pos;
unsigned int Mode;
bool Fullscreen;

View File

@@ -12,6 +12,7 @@
#include "../../hqp/CMusic.h"
#include "../../vorticon/sounds.h"
#include "../../fileio/CExeFile.h"
#include "../../StringUtils.h"
#define SAFE_DELETE_ARRAY(x) if(x) delete[] x; x=NULL
@@ -44,7 +45,7 @@ CSound::~CSound() {
bool CSound::init(void)
{
char name[MAX_STRING_LENGTH];
char name[256];
SDL_AudioSpec *desired, *obtained;
desired = &AudioSpec;
@@ -297,14 +298,14 @@ playsound: ;
m_soundchannel[chnl].setupSound((unsigned short)snd, 0, true, WAVE_IN, 0, (mode==PLAY_FORCE) ? true : false );
}
char CSound::loadSoundData(unsigned short Episode, char *DataDirectory)
char CSound::loadSoundData(unsigned short Episode, const std::string& DataDirectory)
{
if(!m_active) return false;
char *path;
std::string path;
int ok;
char soundfile[80];
char buf[256];
std::string soundfile;
std::string buf;
if(m_soundslot) delete[] m_soundslot;
m_soundslot = new CSoundSlot[MAX_SOUNDS];
@@ -318,21 +319,16 @@ char CSound::loadSoundData(unsigned short Episode, char *DataDirectory)
g_pLogFile->ftextOut("sound_load_all(): loading all sounds...<br>");
char buffer[256];
formatPathString(buffer,path);
sprintf(soundfile, "%ssounds.ck%d", buffer,Episode);
soundfile = formatPathString(path) + "sounds.ck" + itoa(Episode);
FILE *p_file;
if( ( p_file = fopen(soundfile,"rb") ) == NULL )
if( ( p_file = fopen(soundfile.c_str(),"rb") ) == NULL )
{
formatPathString(buffer,path);
sprintf(buf,"keen%d.exe",Episode);
g_pLogFile->ftextOut("sound_load_all(): \"%s\" was not found in the data directory. Looking for \"%s\" in \"%s\" and trying to extract this file<br>", soundfile, buf, buffer);
extractOfExeFile(buffer, Episode);
buf = "keen" + itoa(Episode) + ".exe";
g_pLogFile->ftextOut("sound_load_all(): \"%s\" was not found in the data directory. Looking for \"%s\" in \"%s\" and trying to extract this file<br>", soundfile.c_str(), buf.c_str(), formatPathString(path).c_str());
extractOfExeFile(formatPathString(path), Episode);
}
else
fclose(p_file);
@@ -409,18 +405,16 @@ char CSound::loadSoundData(unsigned short Episode, char *DataDirectory)
the sound data.
*/
char CSound::extractOfExeFile(char *inputpath, int episode)
char CSound::extractOfExeFile(const std::string& inputpath, int episode)
{
const char *outputfname;
std::string outputfname;
int bit_count;
int pos, sounds_start, sounds_end, ret = 0;
char buffer[MAX_STRING_LENGTH];
char inputfname[MAX_STRING_LENGTH];
std::string buffer;
std::string inputfname;
pos = 0;
bit_count = 0;
memset(buffer,0, MAX_STRING_LENGTH*sizeof(char));
memset(inputfname,0, MAX_STRING_LENGTH*sizeof(char));
// Set Offsets. Episode 1 already provides this
if (episode == 2)
@@ -437,7 +431,7 @@ char CSound::extractOfExeFile(char *inputpath, int episode)
}
else
{
g_pLogFile->ftextOut("Error: Unknown keen executable name: %s<br>", inputfname);
g_pLogFile->ftextOut("Error: Unknown keen executable name: %s<br>", inputfname.c_str());
return 1;
}
@@ -446,7 +440,7 @@ char CSound::extractOfExeFile(char *inputpath, int episode)
else
{
FILE *fout;
if(!(fout = fopen(outputfname,"wb"))) ret = 1;
if(!(fout = fopen(outputfname.c_str(),"wb"))) ret = 1;
else
{
fwrite( ExeFile->getData()+sounds_start, 1, (sounds_end-sounds_start), fout);

View File

@@ -11,10 +11,12 @@
#include "../../CSingleton.h"
#define g_pSound CSound::Get()
#include <string>
#include <SDL.h>
#include "CSoundChannel.h"
#include "CSoundSlot.h"
class CSound : public CSingleton<CSound>
{
public:
@@ -23,11 +25,11 @@ public:
bool init(void);
void stop(void);
char loadSoundData(unsigned short Episode, char *DataDirectory);
char loadSoundData(unsigned short Episode, const std::string& DataDirectory);
void stopAllSounds(void);
bool forcedisPlaying(void);
char sound_load_all(const char *path);
char sound_load_all(const std::string& path);
void transform_into_logaritmic_sound(int *pcmstream, int len);
void callback(void *unused, Uint8 *stream, int len);
void pauseSound(void);
@@ -44,7 +46,7 @@ public:
void setSoundmode(int freq, bool stereo);
char extractOfExeFile(char *inputpath, int episode); // This is a special funktion. It doesn't belong here!
char extractOfExeFile(const std::string& inputpath, int episode); // This is a special funktion. It doesn't belong here!
private:
CSoundChannel *m_soundchannel;

View File

@@ -34,7 +34,7 @@ CSoundSlot::~CSoundSlot() {
// loads sound searchname from file fname, into sounds[] entry loadnum
// return value is nonzero on failure
bool CSoundSlot::loadSound(const char *fname, const char *searchname, unsigned int loadnum)
bool CSoundSlot::loadSound(const std::string& fname, const std::string& searchname, unsigned int loadnum)
{
// Unload the sound if any was previously loaded
if(m_sounddata){ delete[] m_sounddata; m_sounddata = NULL; }
@@ -57,10 +57,10 @@ bool CSoundSlot::loadSound(const char *fname, const char *searchname, unsigned i
for(i=0;i<12;i++)
name[i] = 0;
fp = fopen(fname, "rb");
fp = fopen(fname.c_str(), "rb");
if (!fp)
{
g_pLogFile->ftextOut("loadSound : Sounds file '%s' unopenable attempting load of '%s'<br>", fname, searchname);
g_pLogFile->ftextOut("loadSound : Sounds file '%s' unopenable attempting load of '%s'<br>", fname.c_str(), searchname.c_str());
return false;
}
@@ -75,12 +75,12 @@ bool CSoundSlot::loadSound(const char *fname, const char *searchname, unsigned i
priority = fgetc(fp);
garbage = fgetc(fp);
for(i=0;i<12;i++) name[i] = fgetc(fp);
if (!strcmp(name, searchname)) goto sound_found;
if (name == searchname) goto sound_found;
curheader += 0x10;
}
// sound could not be found
g_pLogFile->ftextOut("loadSound : sound %s could not be found in %s.<br>", searchname, fname);
g_pLogFile->ftextOut("loadSound : sound %s could not be found in %s.<br>", searchname.c_str(), fname.c_str());
fclose(fp);
return false;
@@ -115,7 +115,7 @@ bool CSoundSlot::loadSound(const char *fname, const char *searchname, unsigned i
memcpy(m_sounddata, tempstack, m_soundlength*sizeof(unsigned int));
g_pLogFile->ftextOut("loadSound : loaded sound %s of %d bytes.<br>", searchname, m_soundlength);
g_pLogFile->ftextOut("loadSound : loaded sound %s of %d bytes.<br>", searchname.c_str(), m_soundlength);
m_hqsound.enabled = false;
fclose(fp);

View File

@@ -15,7 +15,7 @@ public:
CSoundSlot();
virtual ~CSoundSlot();
bool loadSound(const char *fname, const char *searchname, unsigned int loadnum);
bool loadSound(const std::string& fname, const std::string& searchname, unsigned int loadnum);
void setpAudioSpec(SDL_AudioSpec *pAudioSpec){ m_pAudioSpec = pAudioSpec; }