buffer ini, cleanup defines

This commit is contained in:
GaryOderNichts 2021-01-29 22:07:29 +01:00
parent 1ddf1834d2
commit 99fba1c037
4 changed files with 34 additions and 14 deletions

View File

@ -399,7 +399,6 @@ public:
}; };
#ifdef AUDIO_OAL_USE_SNDFILE #ifdef AUDIO_OAL_USE_SNDFILE
#if 1
static sf_count_t sndfile_vio_get_filelen(void* user_data) static sf_count_t sndfile_vio_get_filelen(void* user_data)
{ {
int32 pos = ftell((FILE*)user_data); int32 pos = ftell((FILE*)user_data);
@ -528,7 +527,8 @@ public:
return size; return size;
} }
}; };
#else
#if DR_WAV_IMPLEMENTATION
static size_t drwav_read_replacement(void* pUserData, void* pBufferOut, size_t bytesToRead) static size_t drwav_read_replacement(void* pUserData, void* pBufferOut, size_t bytesToRead)
{ {
return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData); return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
@ -1156,7 +1156,7 @@ CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBU
if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav")) if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav"))
#ifdef AUDIO_OAL_USE_SNDFILE #ifdef AUDIO_OAL_USE_SNDFILE
m_pSoundFile = new CSndFile(m_aFilename); m_pSoundFile = new CSndFile(m_aFilename);
#elif 0 #elif defined(DR_WAV_IMPLEMENTATION)
m_pSoundFile = new CDrWav(m_aFilename); m_pSoundFile = new CDrWav(m_aFilename);
#else #else
m_pSoundFile = new CWavFile(m_aFilename); m_pSoundFile = new CWavFile(m_aFilename);

View File

@ -11,12 +11,6 @@
const char *_psGetUserFilesFolder(); const char *_psGetUserFilesFolder();
// io is really slow on the Wii U
// so we're buffering files
#ifdef __WIIU__
#define BUFFER
#endif
/* /*
* Windows FILE is BROKEN for GTA. * Windows FILE is BROKEN for GTA.
* *
@ -29,7 +23,7 @@ struct myFILE
{ {
bool isText; bool isText;
FILE *file; FILE *file;
#ifdef BUFFER #ifdef BUFFER_FILES
char* buf; char* buf;
#endif #endif
}; };
@ -90,7 +84,7 @@ found:
myfiles[fd].file = fcaseopen(filename, realmode); myfiles[fd].file = fcaseopen(filename, realmode);
if(myfiles[fd].file == nil) if(myfiles[fd].file == nil)
return 0; return 0;
#ifdef BUFFER #ifdef BUFFER_FILES
myfiles[fd].buf = (char*) memalign(0x40, IO_BUFFER_SIZE); myfiles[fd].buf = (char*) memalign(0x40, IO_BUFFER_SIZE);
setvbuf(myfiles[fd].file, myfiles[fd].buf, _IOFBF, IO_BUFFER_SIZE); setvbuf(myfiles[fd].file, myfiles[fd].buf, _IOFBF, IO_BUFFER_SIZE);
#endif #endif
@ -105,7 +99,7 @@ myfclose(int fd)
if(myfiles[fd].file){ if(myfiles[fd].file){
ret = fclose(myfiles[fd].file); ret = fclose(myfiles[fd].file);
myfiles[fd].file = nil; myfiles[fd].file = nil;
#ifdef BUFFER #ifdef BUFFER_FILES
free(myfiles[fd].buf); free(myfiles[fd].buf);
#endif #endif
return ret; return ret;

View File

@ -141,8 +141,6 @@ enum Config {
NUM_EXPLOSIONS = 48, NUM_EXPLOSIONS = 48,
}; };
#define IO_BUFFER_SIZE 128*1024
// We don't expect to compile for PS2 or Xbox // We don't expect to compile for PS2 or Xbox
// but it might be interesting for documentation purposes // but it might be interesting for documentation purposes
#define GTA_PC #define GTA_PC
@ -410,6 +408,16 @@ enum Config {
#define VC_RAIN_NERF // Reduces number of rain particles #define VC_RAIN_NERF // Reduces number of rain particles
#endif #endif
#ifdef __WIIU__
#define KEEP_FRONTEND_LOADED
#define BUFFER_FILES
#endif
#ifdef BUFFER_FILES
#define IO_BUFFER_SIZE (128*1024)
#define INI_BUFFER_SIZE (8*1024) // 8k should be enough for the ini file
#endif
#if defined __MWERKS__ || defined VANILLA_DEFINES #if defined __MWERKS__ || defined VANILLA_DEFINES
#define FINAL #define FINAL
#undef CHATTYSPLASH #undef CHATTYSPLASH

View File

@ -33,6 +33,9 @@
#include <cstdio> // for std::FILE #include <cstdio> // for std::FILE
#include <algorithm> // for std::find_if #include <algorithm> // for std::find_if
#include <functional> // for std::function #include <functional> // for std::function
#ifdef BUFFER_FILES
#include <malloc.h> // for memalign
#endif
namespace linb namespace linb
{ {
@ -193,6 +196,11 @@ namespace linb
string_type null_string; string_type null_string;
size_type pos; size_type pos;
#ifdef BUFFER_FILES
char* buffer = (char*) memalign(0x40, INI_BUFFER_SIZE);
setvbuf(f, buffer, _IOFBF, INI_BUFFER_SIZE);
#endif
// Trims an string // Trims an string
auto trim = [](string_type& s, bool trimLeft, bool trimRight) -> string_type& auto trim = [](string_type& s, bool trimLeft, bool trimRight) -> string_type&
{ {
@ -264,6 +272,9 @@ namespace linb
} }
fclose(f); fclose(f);
#ifdef BUFFER_FILES
free(buffer);
#endif
return true; return true;
} }
return false; return false;
@ -276,6 +287,10 @@ namespace linb
{ {
if(FILE* f = fopen(filename, "w")) if(FILE* f = fopen(filename, "w"))
{ {
#ifdef BUFFER_FILES
char* buffer = (char*) memalign(0x40, INI_BUFFER_SIZE);
setvbuf(f, buffer, _IOFBF, INI_BUFFER_SIZE);
#endif
bool first = true; bool first = true;
for(auto& sec : this->data) for(auto& sec : this->data)
{ {
@ -290,6 +305,9 @@ namespace linb
} }
} }
fclose(f); fclose(f);
#ifdef BUFFER_FILES
free(buffer);
#endif
return true; return true;
} }
return false; return false;