[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netPanzer-CVS] netpanzer src/Lib/2D/Surface.cpp src/Lib/2D/Sur...
From: |
Matthias Braun |
Subject: |
[netPanzer-CVS] netpanzer src/Lib/2D/Surface.cpp src/Lib/2D/Sur... |
Date: |
Sat, 13 Sep 2003 21:03:15 -0400 |
CVSROOT: /cvsroot/netpanzer
Module name: netpanzer
Branch:
Changes by: Matthias Braun <address@hidden> 03/09/13 21:03:15
Modified files:
src/Lib/2D : Surface.cpp Surface.hpp
src/Lib/View : Desktop.cpp View.cpp
src/NetPanzer/Classes: WorldInputCmdProcessor.cpp
src/NetPanzer/Interfaces: MouseInterface.cpp MouseInterface.hpp
src/NetPanzer/Port: Gdatstct.cpp
src/NetPanzer/Views/Game: GameView.cpp MiniMapView.cpp
src/UILib/SDL : SDLSound.cpp
Added files:
pics/cursors : allie.bmp breakallie.bmp default.bmp move.bmp
noentry.bmp select.bmp target.bmp
Log message:
changed MouseInterface to load a set of .bmp instead of strange
proprietary database files
Patches:
Index: netpanzer/src/Lib/2D/Surface.cpp
diff -u netpanzer/src/Lib/2D/Surface.cpp:1.20
netpanzer/src/Lib/2D/Surface.cpp:1.21
--- netpanzer/src/Lib/2D/Surface.cpp:1.20 Sat Sep 13 18:38:21 2003
+++ netpanzer/src/Lib/2D/Surface.cpp Sat Sep 13 21:03:15 2003
@@ -3933,3 +3933,76 @@
bltLookup(r, table);
} // end Surface::drawLookupBorder
+
+
+void Surface::saveBMP(const char *fname, Palette &pal )
+ {
+ FILE* fp = fopen(fname, "wb");
+
+ BitmapFileHeader file_header;
+ BitmapInfoHeader info_header;
+ RGBQuad palette[256];
+
+ file_header.bfType = 0x4D42;
+ file_header.bfOffBits = sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader)
+ + (sizeof(RGBQuad) * 256);
+ file_header.bfSize = file_header.bfOffBits + (pix.x * pix.y);
+ file_header.bfReserved1 = 0;
+ file_header.bfReserved2 = 0;
+
+ info_header.biSize = sizeof(BitmapInfoHeader);
+ info_header.biWidth = pix.x;
+ info_header.biHeight = pix.y;
+ info_header.biPlanes = 1;
+ info_header.biBitCount = 8;
+ info_header.biCompression = BI_RGB;
+ info_header.biSizeImage= pix.x * pix.y;
+ info_header.biXPelsPerMeter = 0;
+ info_header.biYPelsPerMeter = 0;
+ info_header.biClrUsed = 256;
+ info_header.biClrImportant = 256;
+
+ fwrite( &file_header, sizeof(BitmapFileHeader), 1, fp );
+ fwrite( &info_header, sizeof(BitmapInfoHeader), 1, fp );
+
+ for(int index = 0; index < 256; index++)
+ {
+ RGBColor color;
+
+ color = pal[ index ];
+
+ palette[index].rgbRed = color.red;
+ palette[index].rgbGreen = color.green;
+ palette[index].rgbBlue = color.blue;
+ palette[index].rgbReserved = 0;
+ }//end for index that loads the palette
+
+ fwrite( palette, sizeof(RGBQuad), 256, fp );
+
+ flipVertical();
+
+ if ( (info_header.biWidth % 4) == 0 )
+ {
+ fwrite( mem, info_header.biSizeImage, 1, fp );
+ }
+ else
+ {
+ int padding = ((info_header.biWidth / 4 + 1) * 4) - info_header.biWidth;
+
+ PIX buffer[10];
+ int numRows = pix.y;
+
+ //PIX *sPtr = mem;
+
+ for (int row = 0; row < numRows; row++)
+ {
+ fwrite( mem, pix.x, 1, fp );
+ fwrite( buffer, padding, 1, fp);
+ mem += stride;
+ }
+ }
+
+ flipVertical();
+fclose(fp);
+ }
+
Index: netpanzer/src/Lib/2D/Surface.hpp
diff -u netpanzer/src/Lib/2D/Surface.hpp:1.8
netpanzer/src/Lib/2D/Surface.hpp:1.9
--- netpanzer/src/Lib/2D/Surface.hpp:1.8 Fri Sep 12 20:15:08 2003
+++ netpanzer/src/Lib/2D/Surface.hpp Sat Sep 13 21:03:15 2003
@@ -464,6 +464,7 @@
void bltStringCenteredInRect(const iRect &rect, const char *string,
const PIX &color) const;
void loadBMP(const char *fileName, bool needAlloc = true, void
*returnPalette = 0);
+ void saveBMP(const char* filename, Palette& pal);
void mapFromPalette(const char* oldPalette);
Index: netpanzer/src/Lib/View/Desktop.cpp
diff -u netpanzer/src/Lib/View/Desktop.cpp:1.8
netpanzer/src/Lib/View/Desktop.cpp:1.9
--- netpanzer/src/Lib/View/Desktop.cpp:1.8 Sat Sep 13 18:38:21 2003
+++ netpanzer/src/Lib/View/Desktop.cpp Sat Sep 13 21:03:15 2003
@@ -77,7 +77,7 @@
{
iXY mousePos(mouseX, mouseY);
- MouseInterface::setCursor(MouseInterface::defaultcursor);
+ MouseInterface::setCursor("default.bmp");
prevMouseView = mouseView;
Index: netpanzer/src/Lib/View/View.cpp
diff -u netpanzer/src/Lib/View/View.cpp:1.8 netpanzer/src/Lib/View/View.cpp:1.9
--- netpanzer/src/Lib/View/View.cpp:1.8 Tue Sep 9 13:16:13 2003
+++ netpanzer/src/Lib/View/View.cpp Sat Sep 13 21:03:15 2003
@@ -1533,7 +1533,7 @@
View::searchName = strdup(searchName);
if (View::searchName == 0)
{
- throw Exception("ERROR: Unable to allocate searchName:
", searchName);
+ throw Exception("ERROR: Unable to allocate searchName:
%s", searchName);
}
}
} // end View::setSearchName
@@ -1555,7 +1555,7 @@
View::title = strdup(title);
if (View::title == 0)
{
- throw Exception("ERROR: Unable to allocate title: ",
title);
+ throw Exception("ERROR: Unable to allocate title: %s",
title);
}
}
} // end View::setTitle
@@ -1577,7 +1577,7 @@
View::subTitle = strdup(subTitle);
if (View::subTitle == 0)
{
- throw Exception("ERROR: Unable to allocate subTitle: ",
subTitle);
+ throw Exception("ERROR: Unable to allocate subTitle:
%s", subTitle);
}
}
} // end View::setSubTitle
Index: netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp
diff -u netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.12
netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.13
--- netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.12 Sat Sep
13 18:38:21 2003
+++ netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp Sat Sep 13
21:03:15 2003
@@ -191,45 +191,41 @@
void WorldInputCmdProcessor::
setMouseCursor( unsigned char world_cursor_status )
- {
+{
// XXX yet another abstraction here? probably convert the cursor types
to
// simple strings (which are the names of the cursor images at the same
// time) and get rid of all this code here and in MouseInterface
- switch( world_cursor_status )
- {
- case _cursor_regular :
- MouseInterface::setCursor( MouseInterface::defaultcursor );
- break;
-
- case _cursor_move :
- MouseInterface::setCursor( MouseInterface::move );
- break;
-
- case _cursor_blocked :
- MouseInterface::setCursor( MouseInterface::noentry );
- break;
-
- case _cursor_player_unit :
- MouseInterface::setCursor( MouseInterface::select );
- break;
-
- case _cursor_enemy_unit :
- MouseInterface::setCursor( MouseInterface::target );
- break;
+ switch( world_cursor_status )
+ {
+ case _cursor_regular :
+ MouseInterface::setCursor("default.bmp");
+ break;
+
+ case _cursor_move :
+ MouseInterface::setCursor("move.bmp");
+ break;
+
+ case _cursor_blocked :
+ MouseInterface::setCursor("noentry.bmp");
+ break;
+
+ case _cursor_player_unit :
+ MouseInterface::setCursor("select.bmp");
+ break;
+
+ case _cursor_enemy_unit :
+ MouseInterface::setCursor("target.bmp");
+ break;
- case _cursor_make_allie :
- MouseInterface::setCursor( MouseInterface::allie );
- break;
+ case _cursor_make_allie :
+ MouseInterface::setCursor("allie.bmp");
+ break;
- case _cursor_break_allie :
- MouseInterface::setCursor( MouseInterface::break_allie );
- break;
-
- break;
- } // ** switch
-
-
- }
+ case _cursor_break_allie :
+ MouseInterface::setCursor("breakallie.bmp");
+ break;
+ } // ** switch
+}
void WorldInputCmdProcessor::cycleNextUnitAndChangeFocus( void )
{
Index: netpanzer/src/NetPanzer/Interfaces/MouseInterface.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/MouseInterface.cpp:1.10
netpanzer/src/NetPanzer/Interfaces/MouseInterface.cpp:1.11
--- netpanzer/src/NetPanzer/Interfaces/MouseInterface.cpp:1.10 Sat Sep 13
18:38:21 2003
+++ netpanzer/src/NetPanzer/Interfaces/MouseInterface.cpp Sat Sep 13
21:03:15 2003
@@ -18,18 +18,15 @@
#include <config.h>
#include <SDL.h>
-#include "MouseInterface.hpp"
-
-#include "DDHardSurface.hpp"
+#include "MouseInterface.hpp"
+#include "FileSystem.hpp"
+#include "Exception.hpp"
+#include "Log.hpp"
#include "cMouse.hpp"
-#include "Gdatstct.hpp"
-sprite_dbase CURSOR_DBASE;
-
unsigned char MouseInterface::cursor_x_size;
unsigned char MouseInterface::cursor_y_size;
-Surface MouseInterface::mouse_cursor( false );
iXY MouseInterface::mouse_pos;
@@ -59,12 +56,42 @@
unsigned char MouseInterface::button_mask;
MouseEventQueue MouseInterface::event_queue;
+MouseInterface::cursors_t MouseInterface::cursors;
+#include "Gdatstct.hpp"
void MouseInterface::initialize()
{
event_queue.initialize( 20 );
- mouse_cursor.setOffsetCenter();
- CURSOR_DBASE.load_dbase( "gdbase/cursor.dbs" );
+
+ sprite_dbase CURSOR_DBASE;
+ CURSOR_DBASE.load_dbase( "./gdbase/cursor.dbs");
+
+
+ const char* cursorpath = "pics/cursors/";
+ char** cursorfiles = FileSystem::enumerateFiles(cursorpath);
+ for(char** i = cursorfiles; *i != 0; i++) {
+ if(*i[0]=='.')
+ continue;
+ Surface* surface = new Surface;
+ try {
+ std::string filename = cursorpath;
+ filename += *i;
+ surface->loadBMP(filename.c_str());
+ surface->setOffsetCenter();
+ cursors.insert(std::pair<std::string,Surface*> (*i,
surface));
+ } catch(Exception& e) {
+ LOG(("Couldn't load cursorfile '%s': %s", *i,
e.getMessage()));
+ }
+ }
+ FileSystem::freeList(cursorfiles);
+}
+
+void MouseInterface::shutdown()
+{
+ cursors_t::iterator i = cursors.begin();
+ for( ; i != cursors.end(); i++) {
+ delete i->second;
+ }
}
bool MouseInterface::buttonHeld(unsigned char mask)
@@ -260,96 +287,13 @@
middle_button_hold_time = now();
}
-void MouseInterface::setCursor(CursorType type)
+void MouseInterface::setCursor(const char* cursorname)
{
-
-
- switch(type)
- {
- case defaultcursor:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 0 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 0 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 0 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size, 1);
-
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case noentry:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 4 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 4 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 4 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case move:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 3 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 3 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 3 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case select:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 1 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 1 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 1 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case target:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 2 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 2 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 2 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case allie:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 5 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 5 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 5 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
-
- case break_allie:
- cursor_x_size = CURSOR_DBASE.sprite_list[ 6 ].x_size;
- cursor_y_size = CURSOR_DBASE.sprite_list[ 6 ].y_size;
- mouse_cursor.setTo( (void *) CURSOR_DBASE.sprite_list[ 6 ].data,
- iXY( cursor_x_size, cursor_y_size ),
- cursor_x_size,
- 1
- );
- mouse_cursor.setOffsetCenter();
- mouse.setPointer( &mouse_cursor );
- break;
+ cursors_t::iterator i = cursors.find(cursorname);
+ if(i == cursors.end())
+ throw Exception("mouse cursor '%s' not found.", cursorname);
- } // ** switch
+ mouse.setPointer(i->second);
}
void MouseInterface::updateCursor()
Index: netpanzer/src/NetPanzer/Interfaces/MouseInterface.hpp
diff -u netpanzer/src/NetPanzer/Interfaces/MouseInterface.hpp:1.7
netpanzer/src/NetPanzer/Interfaces/MouseInterface.hpp:1.8
--- netpanzer/src/NetPanzer/Interfaces/MouseInterface.hpp:1.7 Sat Sep 13
18:38:21 2003
+++ netpanzer/src/NetPanzer/Interfaces/MouseInterface.hpp Sat Sep 13
21:03:15 2003
@@ -19,7 +19,7 @@
#define _MOUSEINTERFACE_HPP
#include <string>
-#include <vector>
+#include <map>
#include "QueueTemplate.hpp"
#include "Surface.hpp"
@@ -53,12 +53,8 @@
static unsigned char cursor_x_size;
static unsigned char cursor_y_size;
- struct MouseCursorEntry
- {
- std::string name;
- Surface cursor;
- };
- std::vector<MouseCursorEntry> cursors;
+ typedef std::map<std::string,Surface*> cursors_t;
+ static cursors_t cursors;
protected:
static iXY mouse_pos;
@@ -102,6 +98,7 @@
static MouseEventQueue event_queue;
static void initialize();
+ static void shutdown();
static inline void getMousePosition( long *x, long *y )
{
@@ -129,7 +126,7 @@
static void setMiddleButtonUp();
static void setMiddleButtonDoubleDown();
- static void setCursor(CursorType type);
+ static void setCursor(const char* cursorname);
static void updateCursor();
};
Index: netpanzer/src/NetPanzer/Port/Gdatstct.cpp
diff -u netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.5
netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.6
--- netpanzer/src/NetPanzer/Port/Gdatstct.cpp:1.5 Sat Sep 13 18:38:21 2003
+++ netpanzer/src/NetPanzer/Port/Gdatstct.cpp Sat Sep 13 21:03:15 2003
@@ -95,6 +95,18 @@
dbase_loaded = true;
+ for(int i=0; i<header.sprite_count; i++) {
+ sprite_data* sprite = &sprite_list[i];
+ String filename = sprite->name;
+ filename += ".bmp";
+
+ Surface surf(false);
+ surf.setTo(sprite->data, iXY(32, 32), 32, 1);
+ Palette pal;
+ surf.saveBMP(filename, pal);
+ }
+
+
return( true );
}
Index: netpanzer/src/NetPanzer/Views/Game/GameView.cpp
diff -u netpanzer/src/NetPanzer/Views/Game/GameView.cpp:1.5
netpanzer/src/NetPanzer/Views/Game/GameView.cpp:1.6
--- netpanzer/src/NetPanzer/Views/Game/GameView.cpp:1.5 Wed Sep 10 08:32:55 2003
+++ netpanzer/src/NetPanzer/Views/Game/GameView.cpp Sat Sep 13 21:03:15 2003
@@ -164,7 +164,7 @@
{
Desktop::setFocusView(this);
//Desktop::setActiveView(this);
- MouseInterface::setCursor(MouseInterface::defaultcursor);
+ MouseInterface::setCursor("default.bmp");
}
} // end GameView::mouseMove
Index: netpanzer/src/NetPanzer/Views/Game/MiniMapView.cpp
diff -u netpanzer/src/NetPanzer/Views/Game/MiniMapView.cpp:1.8
netpanzer/src/NetPanzer/Views/Game/MiniMapView.cpp:1.9
--- netpanzer/src/NetPanzer/Views/Game/MiniMapView.cpp:1.8 Wed Sep 10
08:32:55 2003
+++ netpanzer/src/NetPanzer/Views/Game/MiniMapView.cpp Sat Sep 13 21:03:15 2003
@@ -522,14 +522,14 @@
{
if (MiniMapInterface::isValidUnitMove(newPos))
{
-
MouseInterface::setCursor(MouseInterface::move);
+ MouseInterface::setCursor("move.bmp");
} else
{
-
MouseInterface::setCursor(MouseInterface::noentry);
+
MouseInterface::setCursor("noentry.bmp");
}
} else
{
-
MouseInterface::setCursor(MouseInterface::defaultcursor);
+ MouseInterface::setCursor("default.bmp");
}
if (!selectionAnchor)
@@ -541,7 +541,7 @@
selectionAnchor = true;
// Set the selection cursor.
- MouseInterface::setCursor(MouseInterface::select);
+ MouseInterface::setCursor("select.bmp");
} else
{
Index: netpanzer/src/UILib/SDL/SDLSound.cpp
diff -u netpanzer/src/UILib/SDL/SDLSound.cpp:1.6
netpanzer/src/UILib/SDL/SDLSound.cpp:1.7
--- netpanzer/src/UILib/SDL/SDLSound.cpp:1.6 Sat Sep 13 18:38:22 2003
+++ netpanzer/src/UILib/SDL/SDLSound.cpp Sat Sep 13 21:03:15 2003
@@ -27,6 +27,7 @@
#include <SDL_mixer.h>
#include "Log.hpp"
#include "Exception.hpp"
+#include "FileSystem.hpp"
#include "SDLSound.hpp"
musics_t SDLSound::musicfiles;
@@ -138,16 +139,14 @@
* Stop playing the channel.
* @param channel channel to stop
*/
- void
-SDLSound::stopChannel(int channel)
+void SDLSound::stopChannel(int channel)
{
if (channel != -1) {
Mix_HaltChannel(channel);
}
}
//-----------------------------------------------------------------
- int
-SDLSound::getSoundVolume(long distance)
+int SDLSound::getSoundVolume(long distance)
{
//0 to 2 800x600 screen widths away--
if( (distance < 640000)) return MIX_MAX_VOLUME;
@@ -172,8 +171,7 @@
* Load all *.wav from directory.
* @param directory path to the directory
*/
- void
-SDLSound::loadSound(const char* directory)
+void SDLSound::loadSound(const char* directory)
{
DIR* dir = opendir(directory);
if(!dir) {
@@ -189,7 +187,8 @@
std::string filename = directory;
filename += entry->d_name;
- Mix_Chunk *chunk = Mix_LoadWAV(filename.c_str());
+ ReadFile* file = FileSystem::openRead(filename.c_str());
+ Mix_Chunk *chunk = Mix_LoadWAV_RW(file->getSDLRWOps(), 1);
if (!chunk) {
LOG (("Couldn't load wav '%s': %s",
filename.c_str(),
Mix_GetError()));
@@ -205,8 +204,7 @@
* Hash filename to idName.
* @return id name
*/
- std::string
-SDLSound::getIdName(const char *filename)
+std::string SDLSound::getIdName(const char *filename)
{
std::string name = filename;
std::string::size_type pos = name.find_first_of("._");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [netPanzer-CVS] netpanzer src/Lib/2D/Surface.cpp src/Lib/2D/Sur...,
Matthias Braun <=