oculus1

annotate libovr/Src/Kernel/OVR_SysFile.cpp @ 29:9a973ef0e2a3

fixed the performance issue under MacOSX by replacing glutSolidTeapot (which uses glEvalMesh) with my own teapot generator.
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 27 Oct 2013 06:31:18 +0200
parents e2f9e4603129
children
rev   line source
nuclear@3 1 /**************************************************************************
nuclear@3 2
nuclear@3 3 Filename : OVR_SysFile.cpp
nuclear@3 4 Content : File wrapper class implementation (Win32)
nuclear@3 5
nuclear@3 6 Created : April 5, 1999
nuclear@3 7 Authors : Michael Antonov
nuclear@3 8
nuclear@3 9 Copyright : Copyright 2011 Oculus VR, Inc. All Rights reserved.
nuclear@3 10
nuclear@3 11 Use of this software is subject to the terms of the Oculus license
nuclear@3 12 agreement provided at the time of installation or download, or which
nuclear@3 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@3 14
nuclear@3 15 **************************************************************************/
nuclear@3 16
nuclear@3 17 #define GFILE_CXX
nuclear@3 18
nuclear@3 19 // Standard C library (Captain Obvious guarantees!)
nuclear@3 20 #include <stdio.h>
nuclear@3 21
nuclear@3 22 #include "OVR_SysFile.h"
nuclear@3 23
nuclear@3 24 namespace OVR {
nuclear@3 25
nuclear@3 26 // This is - a dummy file that fails on all calls.
nuclear@3 27
nuclear@3 28 class UnopenedFile : public File
nuclear@3 29 {
nuclear@3 30 public:
nuclear@3 31 UnopenedFile() { }
nuclear@3 32 ~UnopenedFile() { }
nuclear@3 33
nuclear@3 34 virtual const char* GetFilePath() { return 0; }
nuclear@3 35
nuclear@3 36 // ** File Information
nuclear@3 37 virtual bool IsValid() { return 0; }
nuclear@3 38 virtual bool IsWritable() { return 0; }
nuclear@3 39
nuclear@3 40 // Return position / file size
nuclear@3 41 virtual int Tell() { return 0; }
nuclear@3 42 virtual SInt64 LTell() { return 0; }
nuclear@3 43 virtual int GetLength() { return 0; }
nuclear@3 44 virtual SInt64 LGetLength() { return 0; }
nuclear@3 45
nuclear@3 46 // virtual bool Stat(FileStats *pfs) { return 0; }
nuclear@3 47 virtual int GetErrorCode() { return Error_FileNotFound; }
nuclear@3 48
nuclear@3 49 // ** Stream implementation & I/O
nuclear@3 50 virtual int Write(const UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
nuclear@3 51 virtual int Read(UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
nuclear@3 52 virtual int SkipBytes(int numBytes) { return 0; OVR_UNUSED(numBytes); }
nuclear@3 53 virtual int BytesAvailable() { return 0; }
nuclear@3 54 virtual bool Flush() { return 0; }
nuclear@3 55 virtual int Seek(int offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
nuclear@3 56 virtual SInt64 LSeek(SInt64 offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
nuclear@3 57
nuclear@3 58 virtual int CopyFromStream(File *pstream, int byteSize) { return -1; OVR_UNUSED2(pstream, byteSize); }
nuclear@3 59 virtual bool Close() { return 0; }
nuclear@3 60 };
nuclear@3 61
nuclear@3 62
nuclear@3 63
nuclear@3 64 // ***** System File
nuclear@3 65
nuclear@3 66 // System file is created to access objects on file system directly
nuclear@3 67 // This file can refer directly to path
nuclear@3 68
nuclear@3 69 // ** Constructor
nuclear@3 70 SysFile::SysFile() : DelegatedFile(0)
nuclear@3 71 {
nuclear@3 72 pFile = *new UnopenedFile;
nuclear@3 73 }
nuclear@3 74
nuclear@3 75 File* FileFILEOpen(const String& path, int flags, int mode);
nuclear@3 76
nuclear@3 77 // Opens a file
nuclear@3 78 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
nuclear@3 79 {
nuclear@3 80 Open(path, flags, mode);
nuclear@3 81 }
nuclear@3 82
nuclear@3 83
nuclear@3 84 // ** Open & management
nuclear@3 85 // Will fail if file's already open
nuclear@3 86 bool SysFile::Open(const String& path, int flags, int mode)
nuclear@3 87 {
nuclear@3 88 pFile = *FileFILEOpen(path, flags, mode);
nuclear@3 89 if ((!pFile) || (!pFile->IsValid()))
nuclear@3 90 {
nuclear@3 91 pFile = *new UnopenedFile;
nuclear@3 92 return 0;
nuclear@3 93 }
nuclear@3 94 //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
nuclear@3 95 if (flags & Open_Buffered)
nuclear@3 96 pFile = *new BufferedFile(pFile);
nuclear@3 97 return 1;
nuclear@3 98 }
nuclear@3 99
nuclear@3 100
nuclear@3 101 // ** Overrides
nuclear@3 102
nuclear@3 103 int SysFile::GetErrorCode()
nuclear@3 104 {
nuclear@3 105 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
nuclear@3 106 }
nuclear@3 107
nuclear@3 108
nuclear@3 109 // Overrides to provide re-open support
nuclear@3 110 bool SysFile::IsValid()
nuclear@3 111 {
nuclear@3 112 return pFile && pFile->IsValid();
nuclear@3 113 }
nuclear@3 114 bool SysFile::Close()
nuclear@3 115 {
nuclear@3 116 if (IsValid())
nuclear@3 117 {
nuclear@3 118 DelegatedFile::Close();
nuclear@3 119 pFile = *new UnopenedFile;
nuclear@3 120 return 1;
nuclear@3 121 }
nuclear@3 122 return 0;
nuclear@3 123 }
nuclear@3 124
nuclear@3 125 } // OVR