[Scummvm-cvs-logs] SF.net SVN: scummvm:[38793] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Feb 22 21:48:42 CET 2009


Revision: 38793
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38793&view=rev
Author:   fingolfin
Date:     2009-02-22 20:48:42 +0000 (Sun, 22 Feb 2009)

Log Message:
-----------
SCI: Moved the code which iterates over the current dir into a small class

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kfile.cpp
    scummvm/trunk/engines/sci/include/engine.h

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-02-22 20:06:25 UTC (rev 38792)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-02-22 20:48:42 UTC (rev 38793)
@@ -518,9 +518,7 @@
 	s->file_handles = (FILE**)sci_calloc(sizeof(FILE *), s->file_handles_nr);
 	// Allocate memory for file handles
 
-	sci_init_dir(&(s->dirseeker));
-	s->dirseeker_outbuffer = NULL_REG;
-	// Those two are used by FileIO for FIND_FIRST, FIND_NEXT
+	s->dirseeker = 0; // Used by FileIO for FIND_FIRST, FIND_NEXT
 
 	if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE &&
 	        s->version < SCI_VERSION(1, 001, 000))

Modified: scummvm/trunk/engines/sci/engine/kfile.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kfile.cpp	2009-02-22 20:06:25 UTC (rev 38792)
+++ scummvm/trunk/engines/sci/engine/kfile.cpp	2009-02-22 20:48:42 UTC (rev 38793)
@@ -55,7 +55,6 @@
 #  define FO_BINARY ""
 #endif
 
-
 static int _savegame_indices_nr = -1; // means 'uninitialized'
 
 static struct _savegame_index_struct {
@@ -784,9 +783,29 @@
 #define K_FILEIO_FIND_NEXT	9
 #define K_FILEIO_STAT		10
 
-char * write_filename_to_mem(EngineState *s, reg_t address, char *string) {
-	char *mem = kernel_dereference_char_pointer(s, address, 0);
 
+class DirSeeker {
+protected:
+	EngineState *_vm;
+	reg_t _outbuffer;
+	sci_dir_t _dir;
+
+	const char *write_filename_to_mem(const char *string);
+
+public:
+	DirSeeker(EngineState *s) : _vm(s) {
+		_outbuffer = NULL_REG;
+		sci_init_dir(&_dir);
+	}
+	
+	void first_file(const char *dir, char *mask, reg_t buffer);
+	void next_file();
+};
+
+
+const char *DirSeeker::write_filename_to_mem(const char *string) {
+	char *mem = kernel_dereference_char_pointer(_vm, _outbuffer, 0);
+
 	if (string) {
 		memset(mem, 0, 13);
 		strncpy(mem, string, 12);
@@ -795,36 +814,36 @@
 	return string;
 }
 
-void next_file(EngineState *s) {
-	if (write_filename_to_mem(s, s->dirseeker_outbuffer, sci_find_next(&(s->dirseeker))))
-		s->r_acc = s->dirseeker_outbuffer;
+void DirSeeker::next_file() {
+	if (write_filename_to_mem(sci_find_next(&_dir)))
+		_vm->r_acc = _outbuffer;
 	else
-		s->r_acc = NULL_REG;
+		_vm->r_acc = NULL_REG;
 }
 
-void first_file(EngineState *s, const char *dir, char *mask, reg_t buffer) {
+void DirSeeker::first_file(const char *dir, char *mask, reg_t buffer) {
 	if (!buffer.segment) {
 		sciprintf("Warning: first_file(state,\"%s\",\"%s\", 0) invoked!\n", dir, mask);
-		s->r_acc = NULL_REG;
+		_vm->r_acc = NULL_REG;
 		return;
 	}
 
 	if (strcmp(dir, ".")) {
 		sciprintf("%s L%d: Non-local first_file: Not implemented yet\n", __FILE__, __LINE__);
-		s->r_acc = NULL_REG;
+		_vm->r_acc = NULL_REG;
 		return;
 	}
 
 	// Get rid of the old find structure
-	if (s->dirseeker_outbuffer.segment)
-		sci_finish_find(&(s->dirseeker));
+	if (_outbuffer.segment)
+		sci_finish_find(&_dir);
+	
+	_outbuffer = buffer;
 
-	s->dirseeker_outbuffer = buffer;
-
-	if (write_filename_to_mem(s, s->dirseeker_outbuffer, sci_find_first(&(s->dirseeker), mask)))
-		s->r_acc = s->dirseeker_outbuffer;
+	if (write_filename_to_mem(sci_find_first(&_dir, mask)))
+		_vm->r_acc = _outbuffer;
 	else
-		s->r_acc = NULL_REG;
+		_vm->r_acc = NULL_REG;
 }
 
 reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
@@ -900,12 +919,16 @@
 		if (strcmp(mask, "*.*") == 0)
 			strcpy(mask, "*"); // For UNIX
 #endif
-		first_file(s, ".", mask, buf);
+		if (!s->dirseeker)
+			s->dirseeker = new DirSeeker(s);
+		assert(s->dirseeker);
+		s->dirseeker->first_file(".", mask, buf);
 
 		break;
 	}
 	case K_FILEIO_FIND_NEXT : {
-		next_file(s);
+		assert(s->dirseeker);
+		s->dirseeker->next_file();
 		break;
 	}
 	case K_FILEIO_STAT : {

Modified: scummvm/trunk/engines/sci/include/engine.h
===================================================================
--- scummvm/trunk/engines/sci/include/engine.h	2009-02-22 20:06:25 UTC (rev 38792)
+++ scummvm/trunk/engines/sci/include/engine.h	2009-02-22 20:48:42 UTC (rev 38793)
@@ -48,6 +48,8 @@
 
 struct menubar_t;
 
+class DirSeeker;
+
 #define FREESCI_CURRENT_SAVEGAME_VERSION 8
 #define FREESCI_MINIMUM_SAVEGAME_VERSION 8
 
@@ -172,8 +174,7 @@
 	int file_handles_nr; /* maximum numer of allowed file handles */
 	FILE **file_handles; /* Array of file handles. Dynamically increased if required. */
 
-	reg_t dirseeker_outbuffer;
-	sci_dir_t dirseeker;
+	DirSeeker *dirseeker;
 
 	/* VM Information */
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list