netpanzer-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netPanzer-CVS] netpanzer/src Lib/FileSystem.hpp Lib/FileSystem...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src Lib/FileSystem.hpp Lib/FileSystem...
Date: Sat, 13 Sep 2003 18:52:34 -0400

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/09/13 18:52:33

Modified files:
        src/Lib        : FileSystem.hpp FileSystem.cpp 
        src            : ChangeLog 

Log message:
        added SDL_RWops code

Patches:
Index: netpanzer/src/ChangeLog
diff -u netpanzer/src/ChangeLog:1.20 netpanzer/src/ChangeLog:1.21
--- netpanzer/src/ChangeLog:1.20        Sat Sep 13 18:38:20 2003
+++ netpanzer/src/ChangeLog     Sat Sep 13 18:52:33 2003
@@ -1,5 +1,6 @@
 14-Sep-2003 by Matze Braun
 -applied sound patch by Ivo Danihelka (thanks alot)
+-added code to construct SDL_RWops in physfs files
 
 12-Sep-2003 by Matze Braun
 -use the physfs for the colortable cache now
Index: netpanzer/src/Lib/FileSystem.cpp
diff -u netpanzer/src/Lib/FileSystem.cpp:1.3 
netpanzer/src/Lib/FileSystem.cpp:1.4
--- netpanzer/src/Lib/FileSystem.cpp:1.3        Sat Sep 13 18:38:20 2003
+++ netpanzer/src/Lib/FileSystem.cpp    Sat Sep 13 18:52:33 2003
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <physfs.h>
 #include "Exception.hpp"
+#include "Log.hpp"
 #include "FileSystem.hpp"
 
 void FileSystem::initialize(const char* argv0, const char* company,
@@ -242,6 +243,49 @@
 int64_t ReadFile::read(void* buffer, size_t objsize, size_t objcount)
 {
        return PHYSFS_read(file, buffer, objsize, objcount);
+}
+
+SDL_RWops* ReadFile::getSDLRWOps()
+{
+       SDL_RWops* rwops = (SDL_RWops*) malloc(sizeof(SDL_RWops));
+       memset(rwops, 0, sizeof(SDL_RWops));
+       rwops->read = RWOps_Read;
+       rwops->seek = RWOps_Seek;
+       rwops->close = RWOps_Close;
+       rwops->hidden.unknown.data1 = this;
+
+       return rwops;
+}
+
+int ReadFile::RWOps_Read(SDL_RWops* context, void* ptr, int size, int maxnum)
+{
+       ReadFile* file = (ReadFile*) context->hidden.unknown.data1;
+       return file->read(ptr, size, maxnum);
+}
+
+int ReadFile::RWOps_Seek(SDL_RWops* context, int offset, int whence)
+{
+       ReadFile* file = (ReadFile*) context->hidden.unknown.data1;
+       try { // catch exceptions
+               switch(whence) {
+                       case SEEK_SET: file->seek(offset); break;
+                       case SEEK_CUR: file->seek(file->tell() + offset); break;
+                       case SEEK_END: file->seek(file->fileLength() + offset); 
break;
+               }
+       } catch(...) {
+               LOG(("Unexpected exception while seeking in file."));
+               return -1;
+       }
+
+       return file->tell();
+}
+
+int ReadFile::RWOps_Close(SDL_RWops* context)
+{
+       ReadFile* file = (ReadFile*) context->hidden.unknown.data1;
+       delete file;
+       context->hidden.unknown.data1 = 0;
+       return 1;
 }
 
 int16_t ReadFile::readSLE16()
Index: netpanzer/src/Lib/FileSystem.hpp
diff -u netpanzer/src/Lib/FileSystem.hpp:1.3 
netpanzer/src/Lib/FileSystem.hpp:1.4
--- netpanzer/src/Lib/FileSystem.hpp:1.3        Sat Sep 13 18:38:20 2003
+++ netpanzer/src/Lib/FileSystem.hpp    Sat Sep 13 18:52:33 2003
@@ -19,6 +19,7 @@
 #ifndef __LIB_FILESYSTEM_HPP__
 #define __LIB_FILESYSTEM_HPP__
 
+#include <SDL.h>
 #include <string>
 #include <stdint.h>
 #include <stdlib.h>
@@ -70,9 +71,20 @@
        int64_t readSBE64();
        uint64_t readUBE64();
 
+       // Returns the SDL_RWops structure which can be used in several SDL
+       // commands. Note that you have to free this structure with 
SDL_FreeRWops.
+       // (Most SDL commands also have a freesrc parameter in their calls 
which you
+       // can simply set to 1)
+       SDL_RWops* getSDLRWOps();
+
 protected:
        ReadFile(PHYSFS_file* file);
        friend class FileSystem;
+
+private:
+       static int RWOps_Read(SDL_RWops* context, void* ptr, int size, int 
maxnum);
+       static int RWOps_Seek(SDL_RWops* context, int offset, int whence);
+       static int RWOps_Close(SDL_RWops* context);
 };
 
 //---------------------------------------------------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]