#include "Room.h" #include "resourceManager.h" #include "usageDatabase.h" #include "uniqueID.h" #include "imageCache.h" #include "packSaver.h" #include "minorGems/util/stringUtils.h" #include "minorGems/util/log/AppLog.h" // static inits Tile *Room::sBlankTile = NULL; Room *Room::sBlankRoom = NULL; void Room::staticInit() { sBlankTile = new Tile(); // ensure that blank tile is saved at least once sBlankTile->finishEdit(); sBlankRoom = new Room(); // save once sBlankRoom->finishEdit(); } void Room::staticFree() { delete sBlankTile; delete sBlankRoom; } void Room::setupDefault() { const char *defaultName = "default"; memcpy( mName, defaultName, strlen( defaultName ) + 1 ); uniqueID blankID = sBlankTile->getUniqueID(); int x; int y; for( y=0; y 10 ) { AppLog::getLog()->logPrintf( Log::ERROR_LEVEL, "Error: Room name %s is too long (10 max)\n", inName ); } else { memcpy( mName, inName, newLength + 1 ); } } uniqueID Room::getTile( int inX, int inY ) { return mTiles[inY][inX]; } char Room::getWall( int inX, int inY ) { return mWallFlags[inY][inX]; } char *Room::getRoomName() { return stringDuplicate( mName ); } // finishes the edit, generates a new unique ID, saves result void Room::finishEdit( char inGenerateNewID ) { uniqueID oldID = mID; if( inGenerateNewID ) { makeUniqueID(); } if( !equal( oldID, mID ) || ! resourceExists( "room", mID ) ) { // change int numBytes; unsigned char *bytes = makeBytes( &numBytes ); saveResourceData( "room", mID, mName, bytes, numBytes ); delete [] bytes; // track usages for( int y=0; ygetChannel( 0 ), fullImage->getChannel( 1 ), fullImage->getChannel( 2 ) }; for( int ty=0; tygetChannel( 0 ), tImage->getChannel( 1 ), tImage->getChannel( 2 ) }; // compute average of all tile pixels for( int c=0; c<3; c++ ) { // sum first for( int i=0; i buffer; int y, x; for( y=0; y= G*G ) { memcpy( (void *)mWallFlags, inBytes, G*G ); inBytes = &( inBytes[ G*G ] ); inLength -= G*G; } // remainder is name if( inLength <= 11 ) { memcpy( mName, inBytes, inLength ); } } void Room::makeUniqueID() { int numBytes; unsigned char *bytes = makeBytes( &numBytes ); mID = ::makeUniqueID( bytes, numBytes ); delete [] bytes; }