From 66524ff74ce9510cc633b0202095f5ecb8a7c9ba Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Wed, 1 Dec 2004 13:01:00 +0000 Subject: [PATCH] Make cfopen into an inline, where a read buffer is set up. This speeds up loading significantly. --- ChangeLog | 3 +++ include/cfile.h | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc3f7b8a..deeaf541 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,9 @@ * README: add PhysicsFS to the required 'tools' in README, and instructions for building in MPW. + * include/cfile.h: Make cfopen into an inline, where a read buffer + is set up. This speeds up loading significantly. + 2004-12-01 Bradley Bell * include/physfsx.h, include/strio.h, main/cntrlcen.c, diff --git a/include/cfile.h b/include/cfile.h index 2698113f..bb0bb5a7 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -1,4 +1,4 @@ -/* $Id: cfile.h,v 1.12 2004-12-01 12:48:13 btb Exp $ */ +/* $Id: cfile.h,v 1.13 2004-12-01 13:01:00 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -31,13 +31,30 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "physfsx.h" #define CFILE PHYSFS_file -#define cfopen(n,m) PHYSFS_openRead(n) #define cfread(p,s,n,fp) PHYSFS_read(fp,p,s,n) #define cfclose PHYSFS_close #define cftell PHYSFS_tell #define cfexist PHYSFS_exists #define cfilelength PHYSFS_fileLength +//Open a file, set up a read buffer +static inline PHYSFS_file *cfopen(char *filename, char *mode) +{ + PHYSFS_file *fp; + PHYSFS_uint64 bufSize; + + mode = mode; // no warning + fp = PHYSFS_openRead(filename); + if (!fp) + return NULL; + + bufSize = PHYSFS_fileLength(fp); + while (!PHYSFS_setBuffer(fp, bufSize) && bufSize) + bufSize /= 2; // even if the error isn't memory full, for a 20MB file it'll only do this 8 times + + return fp; +} + //Specify the name of the hogfile. Returns 1 if hogfile found & had files static inline int cfile_init(char *hogname) { -- 2.39.2