[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netPanzer-CVS] netpanzer ./ChangeLog ./Jamfile ./TODO maps/Jam...
From: |
Matthias Braun |
Subject: |
[netPanzer-CVS] netpanzer ./ChangeLog ./Jamfile ./TODO maps/Jam... |
Date: |
Wed, 24 Sep 2003 13:43:23 -0400 |
CVSROOT: /cvsroot/netpanzer
Module name: netpanzer
Branch:
Changes by: Matthias Braun <address@hidden> 03/09/24 13:43:23
Modified files:
. : ChangeLog Jamfile TODO
maps : Jamfile
src/Lib/2D : PackedSurface.cpp Surface.cpp
src/Lib/Interfaces: UtilInterface.cpp
src/Lib/PObject/Classes: FileList.cpp FileList.hpp
src/NetPanzer/Classes: SpawnList.cpp SpawnList.hpp WorldMap.cpp
src/NetPanzer/Interfaces: MapsManager.cpp MapsManager.hpp
ObjectiveInterface.cpp
src/NetPanzer/Port: Gdatstct.cpp Gdatstct.hpp
src/NetPanzer/Views/MainMenu/Multi: MapSelectionView.cpp
Log message:
changed some more stuff to use physfs
Patches:
Index: netpanzer/ChangeLog
diff -u netpanzer/ChangeLog:1.4 netpanzer/ChangeLog:1.5
--- netpanzer/ChangeLog:1.4 Tue Sep 23 21:26:18 2003
+++ netpanzer/ChangeLog Wed Sep 24 13:43:20 2003
@@ -2,6 +2,7 @@
-converted lots of code to use physfs (not completely done yet)
-removed the automake system
-added a jam build system
+-added README
23-Sep-2003 by Ivo Danihelka
-Added bots, press 'b' for enable
Index: netpanzer/Jamfile
diff -u netpanzer/Jamfile:1.1 netpanzer/Jamfile:1.2
--- netpanzer/Jamfile:1.1 Tue Sep 23 21:26:18 2003
+++ netpanzer/Jamfile Wed Sep 24 13:43:20 2003
@@ -2,7 +2,7 @@
# construct some clean targets
Clean distclean : config.log config.status config.cache aclocal.m4
- Jamconfig config.h ;
+ Jamconfig config.h out.txt log.txt stamp-h1 ;
CleanDir distclean : autom4te.cache out ;
Depends distclean : clean ;
Index: netpanzer/TODO
diff -u netpanzer/TODO:1.2 netpanzer/TODO:1.3
--- netpanzer/TODO:1.2 Mon Sep 22 09:53:47 2003
+++ netpanzer/TODO Wed Sep 24 13:43:20 2003
@@ -1,45 +1,15 @@
--Fix or completely remove the Joystick code. (IMO we should remove it, because
- controling this game with joystick isn't a good idea) - OK
--Fix FileList.cpp to use only ANSI-C functions, so that we don't need the win32
- _splitpath anymore. The same is in UtilInterface.cpp - OK
--Fix PackedSurface.cpp, Surface.cpp to not use _findfirst anymore... same in
- MapsManager.cpp - OK
--Write new timercode the assembler cTimeStamp.cpp isn't portable - OK
--Write new code instead of the assembler in Span.cpp and Surface.cpp - OK
- (though this could be speed optimized a bit more...)
--ParticleInterface.cpp contains some DirectSound code which needs to be
replaced
- - OK
--GroundExplosionParticle, RadarPingParticle2D and DirtKickParticle2D seem to
- miss some Surface variables, where are these defined? - seems OK
--PUFF_PARTICLE_TYPE isn't defined in SmokingTrajectoryParticle - Old code? -
- yes, OK
--write a new version of DDHardSurface - OK
--network code probably needs a bigger rewrite since directplay is not available
- on unix. - OK (for now)
--look at all the directx code in GameManager.cpp - OK
--need new mousecode in MouseInterface.cpp - OK
--need new directplay code in NetworkClientDPlay.cpp, NetworkServerDPlay.cpp -
- not needed, these files aren't used anymore - OK
--need new code instead of winsock in NetworkClientWinsock.cpp - OK
--rewrite all the windows specific code in NetPanzer/Core - OK (SDL specific
- code is in NetPanze/Core/unix now)
--check if the functions and stuff in Lib/terminate.cpp is really needed (looks
- like some strange hacks for the logging functions to me) Can we remove
- this strange code? - Yes we can :) OK
--Fix the win32 stuff in Lib/Util/UtilInterface.cpp - OK
--rewrite win32 event loop to use a SDL event loop. Don't forget to pump mouse
- events to MouseInterface then. - OK
-
Todo before beta release:
--Fix the problems with mainmenu in >640x480 resolution
+-Fix the problems with mainmenu in >640x480 resolution - OK
-Eventually trim down option windows to only necessary stuff (this can wait
- for after the release though)
+ for after the release though) - OK
-Complete GameConfig::save and GameConfig::load functions
-Test it (esp. with more than 2 players)
--Make it compiling in mingw again.
--Fix all warnings in the sourcecode
+-Make it compiling in mingw again. - droped from my side, if noone volunteers
+ then this release will be unix only... (I really tried with cygwin, but got
+ bored since I didn't even manage to compile physfs and SDL_mixer correctly)
+-Fix all warnings in the sourcecode - OK
-Add configure script (autoconf) which checks for all prerequesits - OK
--Create "make install" target (also a "make uninstall"?)
+-Create "make install" target (also a "make uninstall"?) - OK (jam system now)
-Write a README
-Test it, esp. with more than 2 players and test a complete
getsource/configure/build/install/play cycle. We should be able to find
Index: netpanzer/maps/Jamfile
diff -u netpanzer/maps/Jamfile:1.1 netpanzer/maps/Jamfile:1.2
--- netpanzer/maps/Jamfile:1.1 Tue Sep 23 21:26:18 2003
+++ netpanzer/maps/Jamfile Wed Sep 24 13:43:20 2003
@@ -1,3 +1,3 @@
SubDir TOP maps ;
-InstallData [ WildcardPath *.npm *.opt *.spm ] : maps ;
+InstallData [ WildcardPath *.npm *.opt *.spn ] : maps ;
Index: netpanzer/src/Lib/2D/PackedSurface.cpp
diff -u netpanzer/src/Lib/2D/PackedSurface.cpp:1.14
netpanzer/src/Lib/2D/PackedSurface.cpp:1.15
--- netpanzer/src/Lib/2D/PackedSurface.cpp:1.14 Fri Sep 19 20:05:29 2003
+++ netpanzer/src/Lib/2D/PackedSurface.cpp Wed Sep 24 13:43:20 2003
@@ -21,7 +21,6 @@
#include <string>
#include <algorithm>
-#include "FindFirst.hpp"
#include "PackedSurface.hpp"
#include "Surface.hpp"
#include "TimerInterface.hpp"
Index: netpanzer/src/Lib/2D/Surface.cpp
diff -u netpanzer/src/Lib/2D/Surface.cpp:1.29
netpanzer/src/Lib/2D/Surface.cpp:1.30
--- netpanzer/src/Lib/2D/Surface.cpp:1.29 Tue Sep 23 21:26:18 2003
+++ netpanzer/src/Lib/2D/Surface.cpp Wed Sep 24 13:43:21 2003
@@ -21,7 +21,6 @@
#include <vector>
#include <string>
#include <algorithm>
-#include "FindFirst.hpp"
#include "Log.hpp"
#include "Surface.hpp"
#include "FileSystem.hpp"
Index: netpanzer/src/Lib/Interfaces/UtilInterface.cpp
diff -u netpanzer/src/Lib/Interfaces/UtilInterface.cpp:1.10
netpanzer/src/Lib/Interfaces/UtilInterface.cpp:1.11
--- netpanzer/src/Lib/Interfaces/UtilInterface.cpp:1.10 Fri Sep 19 11:22:30 2003
+++ netpanzer/src/Lib/Interfaces/UtilInterface.cpp Wed Sep 24 13:43:21 2003
@@ -20,7 +20,6 @@
#include <sys/stat.h>
#include <string.h>
#include "SplitPath.hpp"
-#include "FindFirst.hpp"
#include "Exception.hpp"
#include "FileSystem.hpp"
#include "UtilInterface.hpp"
Index: netpanzer/src/Lib/PObject/Classes/FileList.cpp
diff -u netpanzer/src/Lib/PObject/Classes/FileList.cpp:1.7
netpanzer/src/Lib/PObject/Classes/FileList.cpp:1.8
--- netpanzer/src/Lib/PObject/Classes/FileList.cpp:1.7 Tue Sep 16 16:16:09 2003
+++ netpanzer/src/Lib/PObject/Classes/FileList.cpp Wed Sep 24 13:43:21 2003
@@ -49,7 +49,7 @@
}
}
-void FileList::addString( char *string )
+void FileList::addString(const char *string )
{
strcpy( array[contains], string );
contains++;
Index: netpanzer/src/Lib/PObject/Classes/FileList.hpp
diff -u netpanzer/src/Lib/PObject/Classes/FileList.hpp:1.3
netpanzer/src/Lib/PObject/Classes/FileList.hpp:1.4
--- netpanzer/src/Lib/PObject/Classes/FileList.hpp:1.3 Tue Sep 16 16:16:09 2003
+++ netpanzer/src/Lib/PObject/Classes/FileList.hpp Wed Sep 24 13:43:21 2003
@@ -38,7 +38,7 @@
~FileList();
- void addString( char *string );
+ void addString(const char *string );
char * getString( unsigned long index );
Index: netpanzer/src/NetPanzer/Classes/SpawnList.cpp
diff -u netpanzer/src/NetPanzer/Classes/SpawnList.cpp:1.6
netpanzer/src/NetPanzer/Classes/SpawnList.cpp:1.7
--- netpanzer/src/NetPanzer/Classes/SpawnList.cpp:1.6 Tue Sep 16 16:16:11 2003
+++ netpanzer/src/NetPanzer/Classes/SpawnList.cpp Wed Sep 24 13:43:21 2003
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "SpawnList.hpp"
+#include "FileSystem.hpp"
#include "Exception.hpp"
SpawnList::SpawnList( unsigned long size )
@@ -28,26 +29,40 @@
initialize( size );
}
-void SpawnList::loadSpawnFile( char *file_path )
+static inline void readLine(char* buffer, size_t bufsize, ReadFile* file)
+{
+ for(size_t i=0; i<bufsize; i++) {
+ if(file->read(buffer+i, 1, 1) != 1) {
+ buffer[i] = 0;
+ break;
+ }
+ if(buffer[i] == '\n') {
+ buffer[i] = 0;
+ break;
+ }
+ }
+}
+
+void SpawnList::loadSpawnFile(const char *file_path)
{
- FILE *infile;
unsigned long spawn_count;
unsigned long spawn_index;
char comment[64];
+ char buffer[128];
- infile = fopen( file_path, "rt" );
- if(infile == 0)
- throw Exception("couldn't open spawn file '%s'.", file_path);
+ std::auto_ptr<ReadFile> file (FileSystem::openRead(file_path));
deallocate();
- fscanf( infile, "%s %lu", comment, &spawn_count );
+ readLine(buffer, sizeof(buffer), &(*file));
+ sscanf(buffer, "%s %lu", comment, &spawn_count );
initialize( spawn_count );
long x, y;
SpawnPoint *spawn;
for ( spawn_index = 0; spawn_index < spawn_count; spawn_index++ ) {
- fscanf( infile, "%s %lu %lu", comment, &x, &y );
+ readLine(buffer, sizeof(buffer), &(*file));
+ sscanf(buffer, "%s %lu %lu", comment, &x, &y );
spawn = &array[ spawn_index ];
spawn->map_loc.x = x;
spawn->map_loc.y = y;
Index: netpanzer/src/NetPanzer/Classes/SpawnList.hpp
diff -u netpanzer/src/NetPanzer/Classes/SpawnList.hpp:1.4
netpanzer/src/NetPanzer/Classes/SpawnList.hpp:1.5
--- netpanzer/src/NetPanzer/Classes/SpawnList.hpp:1.4 Tue Sep 16 16:16:11 2003
+++ netpanzer/src/NetPanzer/Classes/SpawnList.hpp Wed Sep 24 13:43:21 2003
@@ -45,7 +45,7 @@
SpawnList( unsigned long size );
- void loadSpawnFile( char *file_path );
+ void loadSpawnFile(const char *file_path );
void getFreeSpawnPoint( iXY *spawn_loc );
Index: netpanzer/src/NetPanzer/Classes/WorldMap.cpp
diff -u netpanzer/src/NetPanzer/Classes/WorldMap.cpp:1.6
netpanzer/src/NetPanzer/Classes/WorldMap.cpp:1.7
--- netpanzer/src/NetPanzer/Classes/WorldMap.cpp:1.6 Mon Sep 22 18:43:40 2003
+++ netpanzer/src/NetPanzer/Classes/WorldMap.cpp Wed Sep 24 13:43:21 2003
@@ -20,9 +20,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <memory>
#include "WorldMap.hpp"
#include "MapData.hpp"
+#include "FileSystem.hpp"
#include "Exception.hpp"
WorldMap::WorldMap()
@@ -48,44 +50,9 @@
void WorldMap::loadMapFile( const char *file_path )
{
- FILE *infile;
- //map_file_header_type map_header;
unsigned long map_size;
- /*
- infile = fopen( file_path, "rb" );
- assert( infile != 0 );
-
- if ( map_loaded == true )
- {
- delete[] map_buffer;
- map_buffer = 0;
- map_loaded = false;
- }
-
- fread( &map_header, sizeof( map_file_header_type ), 1, infile );
-
- map_info.x_size = map_header.map_x_size;
-
- map_info.y_size = map_header.map_y_size;
-
- strcpy( (char *) map_info.name, map_header.map_name );
-
- map_buffer = new MapElementType [ map_header.map_data_size ];
- assert( map_buffer != 0 );
-
- fread( map_buffer, map_header.map_data_size, 1, infile );
-
- fclose( infile );
-
- map_loaded = true;
-
- */
- //*****************************************************************
-
- infile = fopen( file_path, "rb" );
- if(infile == 0)
- throw Exception("couldn't open mapfile '%s'.", file_path);
+ std::auto_ptr<ReadFile> file (FileSystem::openRead(file_path));
if ( map_loaded == true ) {
delete[] map_buffer;
@@ -93,17 +60,18 @@
map_loaded = false;
}
- fread( &map_info, sizeof( MAP_HEADER ), 1, infile );
+ if(file->read(&map_info, sizeof( MAP_HEADER ), 1) != 1)
+ throw Exception("Couldn't load mapfile '%s' (while reading mapinfo)",
+ file_path);
map_size = (map_info.x_size * map_info.y_size);
map_buffer = new MapElementType [ map_size ];
assert( map_buffer != 0 );
- fread( map_buffer, map_size, sizeof(MapElementType), infile );
-
- fclose( infile );
+ if(file->read(map_buffer, map_size, sizeof(MapElementType)) !=
sizeof(MapElementType))
+ throw Exception("Couldn't load mapfile '%s' (while reading elements)",
+ file_path);
map_loaded = true;
-
}
Index: netpanzer/src/NetPanzer/Interfaces/MapsManager.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/MapsManager.cpp:1.9
netpanzer/src/NetPanzer/Interfaces/MapsManager.cpp:1.10
--- netpanzer/src/NetPanzer/Interfaces/MapsManager.cpp:1.9 Tue Sep 23
21:26:19 2003
+++ netpanzer/src/NetPanzer/Interfaces/MapsManager.cpp Wed Sep 24 13:43:21 2003
@@ -19,7 +19,8 @@
#include <stdio.h>
#include <string.h>
-#include "FindFirst.hpp"
+#include <memory>
+#include "FileSystem.hpp"
#include "MapsManager.hpp"
#include "MapFileStruct.hpp"
@@ -48,33 +49,15 @@
void MapsManager::scanMaps( const char *map_directory )
{
- char search_path[1024];
- char temp_path[1024];
-
- _finddata_t map_file_info;
- int* hFile;
-
- strcpy( search_path, map_directory );
- strcat( search_path, "*.npm" );
-
- hFile = _findfirst( search_path, &map_file_info );
-
- if( hFile != ((int*) -1L) ) {
- strcpy( temp_path, map_directory );
- strcat( temp_path, map_file_info.name );
-
- master_maps_list.addString( temp_path );
-
- while( _findnext( hFile, &map_file_info ) == 0 ) {
- strcpy( temp_path, map_directory );
- strcat( temp_path, map_file_info.name );
-
- master_maps_list.addString( temp_path );
+ char** list = FileSystem::enumerateFiles(map_directory);
+ for(char** file = list; *file != 0; file++) {
+ std::string path = map_directory;
+ path += *file;
+ if(path.find(".npm") != std::string::npos) {
+ master_maps_list.addString(path.c_str());
}
-
- _findclose( hFile );
}
-
+ FileSystem::freeList(list);
}
void MapsManager::resetMapCycling( void )
@@ -82,7 +65,7 @@
map_cycle_index = 0;
}
-void MapsManager::cycleNextMapName( char *map_name )
+void MapsManager::cycleNextMapName(char *map_name )
{
if ( (map_cycle_index + 1) < master_maps_list.containsItems() ) {
map_cycle_index++;
@@ -93,12 +76,12 @@
master_maps_list.getFilename( map_cycle_index, map_name );
}
-void MapsManager::getCurrentMap( char *map_name )
+void MapsManager::getCurrentMap(char *map_name )
{
master_maps_list.getFilename( map_cycle_index, map_name );
}
-void MapsManager::setCycleStartMap( char *map_name )
+void MapsManager::setCycleStartMap(const char *map_name )
{
int list_size;
char cycle_map_name[256];
@@ -114,7 +97,7 @@
}
}
-int MapsManager::checkMapValidity( char *map_name )
+int MapsManager::checkMapValidity(const char *map_name )
{
bool found = false;
int list_size;
@@ -133,7 +116,6 @@
return( _mapfile_not_found );
}
- FILE *fp;
char temp_path[256];
MAP_HEADER map_info;
@@ -141,21 +123,18 @@
strcat( temp_path, map_name);
strcat( temp_path, ".npm" );
- fp = fopen( temp_path, "rb" );
+ std::auto_ptr<ReadFile> file (FileSystem::openRead(temp_path));
- fread( &map_info, sizeof( MAP_HEADER ), 1, fp );
-
- fclose( fp );
+ if(file->read( &map_info, sizeof( MAP_HEADER ), 1) != 1) {
+ return -1;
+ }
strcpy( temp_path, "wads/");
strcat( temp_path, map_info.tile_set );
- fp = fopen( temp_path, "rb" );
+ if(!FileSystem::exists(temp_path))
+ return _wadfile_not_found;
- if( fp == 0 ) {
- return( _wadfile_not_found );
- }
-
- fclose( fp );
return( _mapfile_valid );
}
+
Index: netpanzer/src/NetPanzer/Interfaces/MapsManager.hpp
diff -u netpanzer/src/NetPanzer/Interfaces/MapsManager.hpp:1.3
netpanzer/src/NetPanzer/Interfaces/MapsManager.hpp:1.4
--- netpanzer/src/NetPanzer/Interfaces/MapsManager.hpp:1.3 Tue Sep 16
16:16:12 2003
+++ netpanzer/src/NetPanzer/Interfaces/MapsManager.hpp Wed Sep 24 13:43:22 2003
@@ -33,18 +33,18 @@
MapsManager();
~MapsManager();
- static void initialize( void );
+ static void initialize();
- static void scanMaps( void );
+ static void scanMaps();
static void scanMaps( const char *map_directory );
- static void resetMapCycling( void );
- static void cycleNextMapName( char *map_name );
- static void getCurrentMap( char *map_name );
- static void setCycleStartMap( char *map_name );
+ static void resetMapCycling();
+ static void cycleNextMapName(char *map_name );
+ static void getCurrentMap(char *map_name );
+ static void setCycleStartMap(const char *map_name );
- static int checkMapValidity( char *map_name );
+ static int checkMapValidity(const char *map_name );
};
Index: netpanzer/src/NetPanzer/Interfaces/ObjectiveInterface.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/ObjectiveInterface.cpp:1.8
netpanzer/src/NetPanzer/Interfaces/ObjectiveInterface.cpp:1.9
--- netpanzer/src/NetPanzer/Interfaces/ObjectiveInterface.cpp:1.8 Mon Sep
22 09:53:52 2003
+++ netpanzer/src/NetPanzer/Interfaces/ObjectiveInterface.cpp Wed Sep 24
13:43:22 2003
@@ -19,9 +19,11 @@
#include "ObjectiveInterface.hpp"
#include <stdio.h>
+#include <memory>
#include "MapInterface.hpp"
#include "PlayerInterface.hpp"
+#include "FileSystem.hpp"
#include "Outpost.hpp"
#include "ObjectiveNetMessage.hpp"
@@ -59,12 +61,12 @@
void ObjectiveInterface::loadObjectiveList( char *file_path )
{
- FILE *infile;
unsigned long objective_count;
unsigned long objective_index;
char comment[64];
- infile = fopen( file_path, "rt" );
+ // XXX FIX THIS! Make it using physfs!!!
+ FILE* infile = fopen(FileSystem::getRealName(file_path).c_str(), "rt" );
assert( infile != 0 );
cleanUpObjectiveList();
@@ -91,7 +93,6 @@
objective_list.add( objective_obj, objective_index );
} // ** for
-
}
unsigned char ObjectiveInterface::
Index: netpanzer/src/NetPanzer/Port/Gdatstct.cpp
diff -u netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.10
netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.11
--- netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.10 Tue Sep 16 16:16:12 2003
+++ netpanzer/src/NetPanzer/Port/Gdatstct.cpp Wed Sep 24 13:43:22 2003
@@ -22,9 +22,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <memory>
#include "Log.hpp"
#include "Exception.hpp"
+#include "FileSystem.hpp"
//*****************************************************************************
@@ -35,39 +37,33 @@
}
//*****************************************************************************
-short tile_dbase::load_dbase( char *dbase_path )
+void tile_dbase::load_dbase( char *dbase_path )
{
- FILE *infile;
long tile_buffer_size;
- infile = fopen( dbase_path, "rb" );
+ std::auto_ptr<ReadFile> file (FileSystem::openRead(dbase_path));
- if ( infile == 0 ) {
- LOG ( ("ERROR: Could Not Open tile set : %s", dbase_path) );
- return( false );
- }
-
- fread( &header, sizeof( tile_dbase_header_type ), 1, infile );
+ if(file->read( &header, sizeof( tile_dbase_header_type ), 1) != 1)
+ throw Exception("Error while reading database %s", dbase_path);
tile_buffer_size = header.tile_size * header.tile_count;
tile_data = (unsigned char *) malloc( sizeof(unsigned char) *
tile_buffer_size );
- fread( tile_data, tile_buffer_size, 1, infile );
+ if(file->read(tile_data, tile_buffer_size, 1) != 1)
+ throw Exception("Error while reading database %s", dbase_path);
dbase_loaded = true;
-
- return( true );
}
//*****************************************************************************
-short tile_dbase::unload_dbase( void )
+void tile_dbase::unload_dbase()
{
- if ( dbase_loaded == true ) {
- free( tile_data );
- return( true );
- }
+ if(!dbase_loaded)
+ return;
- return( false );
+ free(tile_data);
+ tile_data = 0;
+ dbase_loaded = false;
}
Index: netpanzer/src/NetPanzer/Port/Gdatstct.hpp
diff -u netpanzer/src/NetPanzer/Port/Gdatstct.hpp:1.6
netpanzer/src/NetPanzer/Port/Gdatstct.hpp:1.7
--- netpanzer/src/NetPanzer/Port/Gdatstct.hpp:1.6 Tue Sep 16 16:16:12 2003
+++ netpanzer/src/NetPanzer/Port/Gdatstct.hpp Wed Sep 24 13:43:22 2003
@@ -38,9 +38,9 @@
tile_dbase_header_type header;
unsigned char *tile_data;
- tile_dbase( void );
- short load_dbase( char *dbase_path );
- short unload_dbase( void );
+ tile_dbase();
+ void load_dbase( char *dbase_path );
+ void unload_dbase();
};
#endif
Index: netpanzer/src/NetPanzer/Views/MainMenu/Multi/MapSelectionView.cpp
diff -u netpanzer/src/NetPanzer/Views/MainMenu/Multi/MapSelectionView.cpp:1.13
netpanzer/src/NetPanzer/Views/MainMenu/Multi/MapSelectionView.cpp:1.14
--- netpanzer/src/NetPanzer/Views/MainMenu/Multi/MapSelectionView.cpp:1.13
Sat Sep 20 13:52:47 2003
+++ netpanzer/src/NetPanzer/Views/MainMenu/Multi/MapSelectionView.cpp Wed Sep
24 13:43:23 2003
@@ -20,21 +20,19 @@
#include <vector>
#include <string>
#include "SplitPath.hpp"
-#include "FindFirst.hpp"
#include "MapSelectionView.hpp"
#include "GameConfig.hpp"
#include "GameViewGlobals.hpp"
#include "HostOptionsView.hpp"
#include "UtilInterface.hpp"
#include "MapFileStruct.hpp"
-#include "Exception.hpp"
#include "FileSystem.hpp"
+#include "Exception.hpp"
#include "Log.hpp"
cGrowList <MapInfo> MapSelectionView::mapList;
int MapSelectionView::curMap = 0;
-
static void bNextMap()
{
// Make sure some maps are loaded.
@@ -133,6 +131,20 @@
} // end MapSelectionView::doDraw
+static inline void readLine(char* buffer, size_t bufsize, ReadFile* file)
+{
+ for(size_t i=0; i<bufsize; i++) {
+ if(file->read(buffer+i, 1, 1) != 1) {
+ buffer[i] = 0;
+ break;
+ }
+ if(buffer[i] == '\n') {
+ buffer[i] = 0;
+ break;
+ }
+ }
+}
+
// loadMaps
//---------------------------------------------------------------------------
int MapSelectionView::loadMaps()
@@ -166,16 +178,19 @@
mapList.setNum(mapfiles.size());
for (unsigned int i = 0; i < mapfiles.size(); i++) {
- FILE *fp =
- fopen(FileSystem::getRealName(mapfiles[i].c_str()).c_str(), "rb");
- if (fp == 0) {
- LOGGER.warning("cannot open map file '%s'", mapfiles[i].c_str());
+ std::auto_ptr<ReadFile> file;
+ try {
+ file = std::auto_ptr<ReadFile>
(FileSystem::openRead(mapfiles[i].c_str()));
+ } catch(Exception& e) {
+ LOGGER.warning("cannot open map file '%s': %s",
+ mapfiles[i].c_str(), e.getMessage());
continue;
}
MAP_HEADER netPanzerMapHeader;
- fread(&netPanzerMapHeader, sizeof(netPanzerMapHeader), 1, fp);
+ if(file->read(&netPanzerMapHeader, sizeof(netPanzerMapHeader), 1) != 1)
+ continue;
/*
if (strlen(netPanzerMapHeader.name) > 255)
{
@@ -195,7 +210,7 @@
int seekAmount = mapList[i].cells.getArea() * sizeof(WORD);
- fseek(fp, seekAmount, SEEK_CUR);
+ file->seek(file->tell()+seekAmount);
iXY pix;
pix.x = netPanzerMapHeader.thumbnail_x_pix;
@@ -205,17 +220,20 @@
int numBytes = pix.getArea();
- fread(mapList[i].thumbnail.frame0, numBytes, 1, fp);
-
- fclose(fp);
+ if(file->read(mapList[i].thumbnail.frame0, numBytes, 1) != 1)
+ continue;
mapList[i].thumbnail.scale(100);
// Now try to get the outpost count from the outpost file.
int objectiveCount = 0;
sprintf(strBuf, "%s%s.opt", mapsPath, mapList[i].name);
- fp = fopen(strBuf, "rb");
- if (fp == 0 || (!fscanf(fp, "ObjectiveCount: %d", &objectiveCount))) {
+
+ file = std::auto_ptr<ReadFile> (FileSystem::openRead(strBuf));
+
+ char buffer[128];
+ readLine(buffer, sizeof(buffer), &(*file));
+ if(!sscanf(buffer, "ObjectiveCount: %d", &objectiveCount)) {
GameConfig::setGameMapName("");
return 1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [netPanzer-CVS] netpanzer ./ChangeLog ./Jamfile ./TODO maps/Jam...,
Matthias Braun <=