forked from oerkki/voxelands
keep the players directory celan
This commit is contained in:
parent
21b26ff396
commit
5e7b3bd8f7
|
@ -87,11 +87,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
|
||||||
const u32 image_pitch = image->getPitch() / sizeof(u16);
|
const u32 image_pitch = image->getPitch() / sizeof(u16);
|
||||||
u16* image_data = (u16*)image->lock();
|
u16* image_data = (u16*)image->lock();
|
||||||
u8* glyph_data = bits.buffer;
|
u8* glyph_data = bits.buffer;
|
||||||
for (s32 y = 0; y < bits.rows; ++y)
|
for (u32 y = 0; y < bits.rows; ++y) {
|
||||||
{
|
|
||||||
u16* row = image_data;
|
u16* row = image_data;
|
||||||
for (s32 x = 0; x < bits.width; ++x)
|
for (u32 x = 0; x < bits.width; ++x) {
|
||||||
{
|
|
||||||
// Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80.
|
// Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80.
|
||||||
// So, we go through the data each bit at a time.
|
// So, we go through the data each bit at a time.
|
||||||
if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0)
|
if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0)
|
||||||
|
@ -116,11 +114,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
|
||||||
const u32 image_pitch = image->getPitch() / sizeof(u32);
|
const u32 image_pitch = image->getPitch() / sizeof(u32);
|
||||||
u32* image_data = (u32*)image->lock();
|
u32* image_data = (u32*)image->lock();
|
||||||
u8* glyph_data = bits.buffer;
|
u8* glyph_data = bits.buffer;
|
||||||
for (s32 y = 0; y < bits.rows; ++y)
|
for (u32 y = 0; y < bits.rows; ++y) {
|
||||||
{
|
|
||||||
u8* row = glyph_data;
|
u8* row = glyph_data;
|
||||||
for (s32 x = 0; x < bits.width; ++x)
|
for (u32 x = 0; x < bits.width; ++x) {
|
||||||
{
|
|
||||||
image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24;
|
image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24;
|
||||||
//data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24);
|
//data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24);
|
||||||
}
|
}
|
||||||
|
@ -460,7 +456,7 @@ CGUITTGlyphPage* CGUITTFont::getLastGlyphPage() const
|
||||||
CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8& pixel_mode)
|
CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8& pixel_mode)
|
||||||
{
|
{
|
||||||
CGUITTGlyphPage* page = 0;
|
CGUITTGlyphPage* page = 0;
|
||||||
|
|
||||||
// Name of our page.
|
// Name of our page.
|
||||||
io::path name("TTFontGlyphPage_");
|
io::path name("TTFontGlyphPage_");
|
||||||
name += tt_face->family_name;
|
name += tt_face->family_name;
|
||||||
|
|
|
@ -301,23 +301,19 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
||||||
core::map<Player*, bool> saved_players;
|
core::map<Player*, bool> saved_players;
|
||||||
|
|
||||||
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
||||||
for(u32 i=0; i<player_files.size(); i++)
|
for (u32 i=0; i<player_files.size(); i++) {
|
||||||
{
|
if (player_files[i].dir)
|
||||||
if(player_files[i].dir)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Full path to this file
|
// Full path to this file
|
||||||
std::string path = players_path + "/" + player_files[i].name;
|
std::string path = players_path + "/" + player_files[i].name;
|
||||||
|
|
||||||
//infostream<<"Checking player file "<<path<<std::endl;
|
|
||||||
|
|
||||||
// Load player to see what is its name
|
// Load player to see what is its name
|
||||||
ServerRemotePlayer testplayer;
|
ServerRemotePlayer testplayer;
|
||||||
{
|
{
|
||||||
// Open file and deserialize
|
// Open file and deserialize
|
||||||
std::ifstream is(path.c_str(), std::ios_base::binary);
|
std::ifstream is(path.c_str(), std::ios_base::binary);
|
||||||
if(is.good() == false)
|
if (is.good() == false) {
|
||||||
{
|
|
||||||
infostream<<"Failed to read "<<path<<std::endl;
|
infostream<<"Failed to read "<<path<<std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -329,9 +325,8 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
||||||
// Search for the player
|
// Search for the player
|
||||||
std::string playername = testplayer.getName();
|
std::string playername = testplayer.getName();
|
||||||
Player *player = getPlayer(playername.c_str());
|
Player *player = getPlayer(playername.c_str());
|
||||||
if(player == NULL)
|
if (player == NULL) {
|
||||||
{
|
fs::RecursiveDelete(path);
|
||||||
infostream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,8 +336,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
||||||
{
|
{
|
||||||
// Open file and serialize
|
// Open file and serialize
|
||||||
std::ofstream os(path.c_str(), std::ios_base::binary);
|
std::ofstream os(path.c_str(), std::ios_base::binary);
|
||||||
if(os.good() == false)
|
if (os.good() == false) {
|
||||||
{
|
|
||||||
infostream<<"Failed to overwrite "<<path<<std::endl;
|
infostream<<"Failed to overwrite "<<path<<std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -351,41 +345,29 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for (core::list<Player*>::Iterator i = m_players.begin(); i != m_players.end(); i++) {
|
||||||
i != m_players.end(); i++)
|
|
||||||
{
|
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(saved_players.find(player) != NULL)
|
if (saved_players.find(player) != NULL)
|
||||||
{
|
|
||||||
/*infostream<<"Player "<<player->getName()
|
|
||||||
<<" was already saved."<<std::endl;*/
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
std::string playername = player->getName();
|
std::string playername = player->getName();
|
||||||
// Don't save unnamed player
|
// Don't save unnamed player
|
||||||
if(playername == "")
|
if (playername == "")
|
||||||
{
|
|
||||||
//infostream<<"Not saving unnamed player."<<std::endl;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Find a sane filename
|
Find a sane filename
|
||||||
*/
|
*/
|
||||||
if(string_allowed(playername, PLAYERNAME_ALLOWED_CHARS) == false)
|
if (string_allowed(playername, PLAYERNAME_ALLOWED_CHARS) == false)
|
||||||
playername = "player";
|
playername = "player";
|
||||||
std::string path = players_path + "/" + playername;
|
std::string path = players_path + "/" + playername;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for(u32 i=0; i<1000; i++)
|
for (u32 i=0; i<1000; i++) {
|
||||||
{
|
if (fs::PathExists(path) == false) {
|
||||||
if(fs::PathExists(path) == false)
|
|
||||||
{
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path = players_path + "/" + playername + itos(i);
|
path = players_path + "/" + playername + itos(i);
|
||||||
}
|
}
|
||||||
if(found == false)
|
if (found == false) {
|
||||||
{
|
|
||||||
infostream<<"Didn't find free file for player"<<std::endl;
|
infostream<<"Didn't find free file for player"<<std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -395,8 +377,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
||||||
<<path<<std::endl;*/
|
<<path<<std::endl;*/
|
||||||
// Open file and serialize
|
// Open file and serialize
|
||||||
std::ofstream os(path.c_str(), std::ios_base::binary);
|
std::ofstream os(path.c_str(), std::ios_base::binary);
|
||||||
if(os.good() == false)
|
if (os.good() == false) {
|
||||||
{
|
|
||||||
infostream<<"Failed to overwrite "<<path<<std::endl;
|
infostream<<"Failed to overwrite "<<path<<std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +418,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS)) {
|
if (!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS)) {
|
||||||
infostream<<"Not loading player with invalid name: "<<testplayer.getName()<<std::endl;
|
fs::RecursiveDelete(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue