1
0
forked from 0ad/0ad

file: provide FILE_TEXT flag that enables newline translation - useful when outputting XML files, so notepad doesn't see "\n" (which it can't handle)

vfs: no longer watch dirs when mounting - need to pass flag. allows
turning this off for screenshots dir (where hotloading doesn't make
sense)

vfs_tree: expand hash table when 3/4 full; 1/2 was quite wasteful.

main: do CPU init early, so timing during init can use TSCmain: do CPU
init early, so timing during init can use TSC

This was SVN commit r2098.
This commit is contained in:
janwas 2005-04-29 13:17:17 +00:00
parent dfb576c563
commit 9d139926c9
7 changed files with 60 additions and 25 deletions

View File

@ -555,7 +555,10 @@ int file_open(const char* p_fn, const uint flags, File* f)
}
#ifdef _WIN32
oflag |= O_BINARY;
if(flags & FILE_TEXT)
oflag |= O_TEXT_NP;
else
oflag |= O_BINARY_NP;
// if AIO is disabled (at user's behest or because the file is small),
// so inform wposix.

View File

@ -49,6 +49,13 @@ enum
// write-only access; otherwise, read only
FILE_WRITE = 0x01,
// translate newlines: convert from/to native representation when
// reading/writing. this is useful if files we create need to be
// edited externally - e.g. Notepad requires \r\n.
// caveats:
// - FILE_NO_AIO must be set; translation is done by OS read()/write().
// - not supported by POSIX, so this currently only has meaning on Win32.
FILE_TEXT = 0x02,
// the file's contents aren't cached at a higher level; do so here.
// we keep the file open (until the cache is "full enough"). if it

View File

@ -388,15 +388,23 @@ static int dirent_cb(const char* name, const struct stat* s, uintptr_t user)
// add the contents of directory <p_path> to this TDir,
// marking the files' locations as <mount_point>.
// if desired, we recursively add the contents of subdirectories as well.
// if <archives> != 0, all archives found in this directory only
// (not its subdirs! see below) are opened in alphabetical order,
// their files added, and a TMountPoint appended to <*archives>.
static int populate_dir(TDir* dir_, const char* p_path_, const TMountPoint* mount_point, bool recursive, TMountPoints* archives)
// marking the files' locations as <mount_point>. flags: see VfsMountFlags.
//
// note: we are only able to add archives found in the root directory,
// due to dirent_cb implementation. that's ok - we don't want to check
// every single file to see if it's an archive (slow!).
static int populate_dir(TDir* dir_, const char* p_path_, const TMountPoint* mount_point, int flags, TMountPoints* parchives_)
{
DirQueue dir_queue;
const bool recursive = (flags & VFS_MOUNT_RECURSIVE) != 0;
const bool archives = (flags & VFS_MOUNT_ARCHIVES ) != 0;
const bool watch = (flags & VFS_MOUNT_WATCH ) != 0;
// instead of propagating flags down to dirent_cb, prevent recursing
// and adding archives by setting the destination pointers to 0 (easier).
DirQueue* const pdir_queue = recursive? &dir_queue : 0;
TMountPoints* parchives = archives? parchives_ : 0;
// kickoff (less efficient than goto, but c_str reference requires
// pop to come at end of loop => this is easiest)
@ -407,16 +415,16 @@ static int populate_dir(TDir* dir_, const char* p_path_, const TMountPoint* moun
TDir* const dir = dir_queue.front().dir;
const char* p_path = dir_queue.front().path.c_str();
tree_mount(dir, p_path, mount_point);
tree_mount(dir, p_path, mount_point, watch);
// add files and subdirs to this dir;
// also adds the contents of archives if archives != 0.
const DirentCBParams params(dir, mount_point, p_path, pdir_queue, archives);
const DirentCBParams params(dir, mount_point, p_path, pdir_queue, parchives);
file_enum(p_path, dirent_cb, (uintptr_t)&params);
// xxx load all archive_loc archives here instead
archives = 0;
parchives = 0;
// prevent searching for archives in subdirectories (slow!). this
// is currently required by the dirent_cb implementation anyway.
@ -512,12 +520,9 @@ static int remount(Mount& m)
TDir* dir;
CHECK_ERR(tree_lookup_dir(v_mount_point, &dir, LF_CREATE_MISSING));
const bool recursive = !!(flags & VFS_MOUNT_RECURSIVE);
TMountPoints* parchive_locs = (flags & VFS_MOUNT_ARCHIVES)? &archives : 0;
// add all loose files and subdirectories (recursive).
// also mounts all archives in p_real_path and adds to archives.
return populate_dir(dir, p_real_path, mount_point, recursive, parchive_locs);
return populate_dir(dir, p_real_path, mount_point, flags, &archives);
}

View File

@ -51,7 +51,13 @@ enum VfsMountFlags
// when mounting a directory, all directories beneath it are
// added recursively as well.
VFS_MOUNT_RECURSIVE = 2
VFS_MOUNT_RECURSIVE = 2,
// all real directories mounted during this operation will be watched
// for changes (using hotload.h). this flag is provided to avoid
// watches in output-only directories, e.g. screenshots/
// (only causes unnecessary overhead).
VFS_MOUNT_WATCH = 4
};
// mount <p_real_dir> into the VFS at <vfs_mount_point>,

View File

@ -330,7 +330,7 @@ bool TChildren::expand_tbl()
TNode* TChildren::add(const char* fn)
{
// expand before determining slot; this will invalidate previous pnodes.
if(num_entries*2 >= max_entries)
if(num_entries*4 >= max_entries*3)
{
if(!expand_tbl())
return 0;

View File

@ -223,15 +223,21 @@ extern int munmap(void* start, size_t len);
#define O_CREAT 0x0100 // create and open file
#define O_TRUNC 0x0200 // open and truncate
#define O_EXCL 0x0400 // open only if file doesn't already exist
#define O_BINARY 0x8000 // file mode is binary (untranslated)
// .. Win32-only (not specified by POSIX)
#define O_TEXT_NP 0x4000 // file mode is text (translated)
#define O_BINARY_NP 0x8000 // file mode is binary (untranslated)
// .. wposix.cpp only (bit values not used by MS _open)
#define O_NO_AIO_NP 0x20000
// wposix-specific: do not open a separate AIO-capable handle.
// this is used for small files where AIO overhead isn't worth it,
// thus speeding up loading and reducing resource usage.
// .. not supported by Win32 (bit values not used by MS _open)
#define O_NONBLOCK 0x1000000
// redefinition error here => io.h is getting included somewhere.
// we implement this function, so the io.h definition conflicts if
// compiling against the DLL CRT. either rename the io.h def

View File

@ -203,7 +203,7 @@ static void WriteSysInfo()
{
double t1 = get_time();
get_gfx_info();
get_cpu_info();
// get_cpu_info already called during init - see call site
get_snd_info();
get_mem_status();
double t2 = get_time();
@ -805,7 +805,7 @@ TIMER(InitVfs)
{
TIMER(VFS_INIT);
vfs_init();
vfs_mount("", "mods/official", VFS_MOUNT_RECURSIVE|VFS_MOUNT_ARCHIVES);
vfs_mount("", "mods/official", VFS_MOUNT_RECURSIVE|VFS_MOUNT_ARCHIVES|VFS_MOUNT_WATCH);
vfs_mount("screenshots/", "screenshots");
vfs_mount("profiles/", "profiles");
}
@ -1099,11 +1099,22 @@ static void Init(int argc, char* argv[], bool setup_gfx = true)
u64 TSC=rdtsc();
debug_out(
"----------------------------------------\n"\
"MAIN\n"\
"INITIALIZING\n"\
"----------------------------------------\n");
PREVTSC=TSC;
#endif
// set 24 bit (float) FPU precision for faster divides / sqrts
#ifdef _M_IX86
_control87(_PC_24, _MCW_PC);
#endif
// detects CPU clock frequency and capabilities, which are prerequisites
// for using the TSC as a timer (desirable due to its high resolution).
// do this before lengthy init so we can time those accurately.
get_cpu_info();
// Call LoadLanguage(NULL) to initialise the I18n system, but
// without loading an actual language file - translate() will
// just show the English key text, which is better than crashing
@ -1113,11 +1124,6 @@ PREVTSC=TSC;
MICROLOG(L"init i18n");
I18n::LoadLanguage(NULL);
// set 24 bit (float) FPU precision for faster divides / sqrts
#ifdef _M_IX86
_control87(_PC_24, _MCW_PC);
#endif
// Do this as soon as possible, because it chdirs
// and will mess up the error reporting if anything
// crashes before the working directory is set.
@ -1187,10 +1193,12 @@ sle(11340106);
vfs_display();
}
else
{
// speed up startup by disabling all sound
// (OpenAL init will be skipped).
// must be called before first snd_open.
snd_disable(true);
}
if(!oglHaveExtension("GL_ARB_multitexture") || !oglHaveExtension("GL_ARB_texture_env_combine") ||
!glActiveTexture) // prevent crashing later if multitexture support is falsely