1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Use the logger; also, default to not showing much crap in console. Use --info-on-stderr to enable crap.

This commit is contained in:
Perttu Ahola 2011-10-16 14:57:53 +03:00
parent 4846846a2d
commit b65a5aceb0
16 changed files with 844 additions and 646 deletions

View file

@ -27,6 +27,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_sao.h"
#include "mapgen.h"
#include "settings.h"
#include "log.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Environment::Environment():
m_time_of_day(9000)
@ -302,7 +305,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
// Full path to this file
std::string path = players_path + "/" + player_files[i].name;
//dstream<<"Checking player file "<<path<<std::endl;
//infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
ServerRemotePlayer testplayer;
@ -311,24 +314,24 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
dstream<<"Failed to read "<<path<<std::endl;
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
testplayer.deSerialize(is);
}
//dstream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
//infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
// Search for the player
std::string playername = testplayer.getName();
Player *player = getPlayer(playername.c_str());
if(player == NULL)
{
dstream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
infostream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
continue;
}
//dstream<<"Found matching player, overwriting."<<std::endl;
//infostream<<"Found matching player, overwriting."<<std::endl;
// OK, found. Save player there.
{
@ -336,7 +339,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
std::ofstream os(path.c_str(), std::ios_base::binary);
if(os.good() == false)
{
dstream<<"Failed to overwrite "<<path<<std::endl;
infostream<<"Failed to overwrite "<<path<<std::endl;
continue;
}
player->serialize(os);
@ -350,7 +353,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
Player *player = *i;
if(saved_players.find(player) != NULL)
{
/*dstream<<"Player "<<player->getName()
/*infostream<<"Player "<<player->getName()
<<" was already saved."<<std::endl;*/
continue;
}
@ -358,7 +361,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
// Don't save unnamed player
if(playername == "")
{
//dstream<<"Not saving unnamed player."<<std::endl;
//infostream<<"Not saving unnamed player."<<std::endl;
continue;
}
/*
@ -379,18 +382,18 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
}
if(found == false)
{
dstream<<"WARNING: Didn't find free file for player"<<std::endl;
infostream<<"Didn't find free file for player"<<std::endl;
continue;
}
{
/*dstream<<"Saving player "<<player->getName()<<" to "
/*infostream<<"Saving player "<<player->getName()<<" to "
<<path<<std::endl;*/
// Open file and serialize
std::ofstream os(path.c_str(), std::ios_base::binary);
if(os.good() == false)
{
dstream<<"WARNING: Failed to overwrite "<<path<<std::endl;
infostream<<"Failed to overwrite "<<path<<std::endl;
continue;
}
player->serialize(os);
@ -398,7 +401,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
}
}
//dstream<<"Saved "<<saved_players.size()<<" players."<<std::endl;
//infostream<<"Saved "<<saved_players.size()<<" players."<<std::endl;
}
void ServerEnvironment::deSerializePlayers(const std::string &savedir)
@ -416,7 +419,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
// Full path to this file
std::string path = players_path + "/" + player_files[i].name;
dstream<<"Checking player file "<<path<<std::endl;
infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
ServerRemotePlayer testplayer;
@ -425,7 +428,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
dstream<<"Failed to read "<<path<<std::endl;
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
testplayer.deSerialize(is);
@ -433,11 +436,11 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS))
{
dstream<<"Not loading player with invalid name: "
infostream<<"Not loading player with invalid name: "
<<testplayer.getName()<<std::endl;
}
dstream<<"Loaded test player with name "<<testplayer.getName()
infostream<<"Loaded test player with name "<<testplayer.getName()
<<std::endl;
// Search for the player
@ -446,20 +449,20 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
bool newplayer = false;
if(player == NULL)
{
dstream<<"Is a new player"<<std::endl;
infostream<<"Is a new player"<<std::endl;
player = new ServerRemotePlayer();
newplayer = true;
}
// Load player
{
dstream<<"Reading player "<<testplayer.getName()<<" from "
infostream<<"Reading player "<<testplayer.getName()<<" from "
<<path<<std::endl;
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
dstream<<"Failed to read "<<path<<std::endl;
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
player->deSerialize(is);
@ -478,7 +481,7 @@ void ServerEnvironment::saveMeta(const std::string &savedir)
std::ofstream os(path.c_str(), std::ios_base::binary);
if(os.good() == false)
{
dstream<<"WARNING: ServerEnvironment::saveMeta(): Failed to open "
infostream<<"ServerEnvironment::saveMeta(): Failed to open "
<<path<<std::endl;
throw SerializationError("Couldn't save env meta");
}
@ -498,7 +501,7 @@ void ServerEnvironment::loadMeta(const std::string &savedir)
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
dstream<<"WARNING: ServerEnvironment::loadMeta(): Failed to open "
infostream<<"ServerEnvironment::loadMeta(): Failed to open "
<<path<<std::endl;
throw SerializationError("Couldn't load env meta");
}
@ -595,7 +598,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
// Set current time as timestamp (and let it set ChangedFlag)
block->setTimestamp(m_game_time);
//dstream<<"Block is "<<dtime_s<<" seconds old."<<std::endl;
//infostream<<"Block is "<<dtime_s<<" seconds old."<<std::endl;
// Activate stored objects
activateObjects(block);
@ -757,7 +760,7 @@ void ServerEnvironment::step(float dtime)
{
v3s16 p = i.getNode()->getKey();
/*dstream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
<<") became inactive"<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
@ -778,7 +781,7 @@ void ServerEnvironment::step(float dtime)
{
v3s16 p = i.getNode()->getKey();
/*dstream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
<<") became active"<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
@ -802,7 +805,7 @@ void ServerEnvironment::step(float dtime)
{
v3s16 p = i.getNode()->getKey();
/*dstream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
<<") being handled"<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
@ -838,7 +841,7 @@ void ServerEnvironment::step(float dtime)
{
v3s16 p = i.getNode()->getKey();
/*dstream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
<<") being handled"<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
@ -956,18 +959,24 @@ void ServerEnvironment::step(float dtime)
v3f pos = intToFloat(p1, BS);
int i = myrand()%5;
if(i == 0 || i == 1){
actionstream<<"A dungeon master spawns at "
<<PP(p1)<<std::endl;
Settings properties;
getMob_dungeon_master(properties);
ServerActiveObject *obj = new MobV2SAO(
this, 0, pos, &properties);
addActiveObject(obj);
} else if(i == 2 || i == 3){
actionstream<<"Rats spawn at "
<<PP(p1)<<std::endl;
for(int j=0; j<3; j++){
ServerActiveObject *obj = new RatSAO(
this, 0, pos);
addActiveObject(obj);
}
} else {
actionstream<<"An oerkki spawns at "
<<PP(p1)<<std::endl;
ServerActiveObject *obj = new Oerkki1SAO(
this, 0, pos);
addActiveObject(obj);
@ -983,6 +992,9 @@ void ServerEnvironment::step(float dtime)
{
if(myrand()%50 == 0)
{
actionstream<<"A sapling grows into a tree at "
<<PP(p)<<std::endl;
core::map<v3s16, MapBlock*> modified_blocks;
v3s16 tree_p = p;
ManualMapVoxelManipulator vmanip(m_map);
@ -1111,7 +1123,7 @@ void ServerEnvironment::step(float dtime)
//ServerActiveObject *obj = new Oerkki1SAO(this, 0, pos);
//ServerActiveObject *obj = new FireflySAO(this, 0, pos);
dstream<<DTIME<<"INFO: Server: Spawning MobV2SAO at "
infostream<<"Server: Spawning MobV2SAO at "
<<"("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"<<std::endl;
Settings properties;
@ -1202,7 +1214,7 @@ bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj)
succeeded = true;
}
else{
dstream<<"WARNING: ServerEnvironment::addActiveObjectAsStatic: "
infostream<<"ServerEnvironment::addActiveObjectAsStatic: "
<<"Could not find or generate "
<<"a block for storing static object"<<std::endl;
succeeded = false;
@ -1282,13 +1294,13 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
ServerActiveObject *object = getActiveObject(id);
if(object == NULL)
{
dstream<<"WARNING: ServerEnvironment::getRemovedActiveObjects():"
infostream<<"ServerEnvironment::getRemovedActiveObjects():"
<<" object in current_objects is NULL"<<std::endl;
}
else if(object->m_removed == false)
{
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
/*dstream<<"removed == false"
/*infostream<<"removed == false"
<<"distance_f = "<<distance_f
<<", radius_f = "<<radius_f<<std::endl;*/
if(distance_f < radius_f)
@ -1322,7 +1334,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
u16 new_id = getFreeServerActiveObjectId(m_active_objects);
if(new_id == 0)
{
dstream<<"WARNING: ServerEnvironment::addActiveObjectRaw(): "
infostream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"no free ids available"<<std::endl;
delete object;
return 0;
@ -1331,12 +1343,12 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
}
if(isFreeServerActiveObjectId(object->getId(), m_active_objects) == false)
{
dstream<<"WARNING: ServerEnvironment::addActiveObjectRaw(): "
infostream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"id is not free ("<<object->getId()<<")"<<std::endl;
delete object;
return 0;
}
/*dstream<<"INFO: ServerEnvironment::addActiveObjectRaw(): "
/*infostream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"added (id="<<object->getId()<<")"<<std::endl;*/
m_active_objects.insert(object->getId(), object);
@ -1358,7 +1370,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
block->setChangedFlag();
}
else{
dstream<<"WARNING: ServerEnv: Could not find a block for "
infostream<<"ServerEnv: Could not find a block for "
<<"storing newly added static active object"<<std::endl;
}
@ -1380,7 +1392,7 @@ void ServerEnvironment::removeRemovedObjects()
// This shouldn't happen but check it
if(obj == NULL)
{
dstream<<"WARNING: NULL object found in ServerEnvironment"
infostream<<"NULL object found in ServerEnvironment"
<<" while finding removed objects. id="<<id<<std::endl;
// Id to be removed from m_active_objects
objects_to_remove.push_back(id);
@ -1442,7 +1454,7 @@ void ServerEnvironment::activateObjects(MapBlock *block)
i = block->m_static_objects.m_stored.begin();
i != block->m_static_objects.m_stored.end(); i++)
{
/*dstream<<"INFO: Server: Creating an active object from "
/*infostream<<"Server: Creating an active object from "
<<"static data"<<std::endl;*/
StaticObject &s_obj = *i;
// Create an active object from the data
@ -1494,7 +1506,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
// This shouldn't happen but check it
if(obj == NULL)
{
dstream<<"WARNING: NULL object found in ServerEnvironment"
infostream<<"NULL object found in ServerEnvironment"
<<std::endl;
assert(0);
continue;
@ -1553,7 +1565,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
obj->m_static_block = block->getPos();
}
else{
dstream<<"WARNING: ServerEnv: Could not find or generate "
infostream<<"ServerEnv: Could not find or generate "
<<"a block for storing static object"<<std::endl;
obj->m_static_exists = false;
continue;
@ -1571,7 +1583,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
continue;
}
/*dstream<<"INFO: Server: Stored static data. Deleting object."
/*infostream<<"Server: Stored static data. Deleting object."
<<std::endl;*/
// Delete active object
delete obj;
@ -1962,7 +1974,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
u16 new_id = getFreeClientActiveObjectId(m_active_objects);
if(new_id == 0)
{
dstream<<"WARNING: ClientEnvironment::addActiveObject(): "
infostream<<"ClientEnvironment::addActiveObject(): "
<<"no free ids available"<<std::endl;
delete object;
return 0;
@ -1971,12 +1983,12 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
}
if(isFreeClientActiveObjectId(object->getId(), m_active_objects) == false)
{
dstream<<"WARNING: ClientEnvironment::addActiveObject(): "
infostream<<"ClientEnvironment::addActiveObject(): "
<<"id is not free ("<<object->getId()<<")"<<std::endl;
delete object;
return 0;
}
dstream<<"INFO: ClientEnvironment::addActiveObject(): "
infostream<<"ClientEnvironment::addActiveObject(): "
<<"added (id="<<object->getId()<<")"<<std::endl;
m_active_objects.insert(object->getId(), object);
object->addToScene(m_smgr);
@ -1989,7 +2001,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type,
ClientActiveObject* obj = ClientActiveObject::create(type);
if(obj == NULL)
{
dstream<<"WARNING: ClientEnvironment::addActiveObject(): "
infostream<<"ClientEnvironment::addActiveObject(): "
<<"id="<<id<<" type="<<type<<": Couldn't create object"
<<std::endl;
return;
@ -2004,12 +2016,12 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type,
void ClientEnvironment::removeActiveObject(u16 id)
{
dstream<<"ClientEnvironment::removeActiveObject(): "
infostream<<"ClientEnvironment::removeActiveObject(): "
<<"id="<<id<<std::endl;
ClientActiveObject* obj = getActiveObject(id);
if(obj == NULL)
{
dstream<<"WARNING: ClientEnvironment::removeActiveObject(): "
infostream<<"ClientEnvironment::removeActiveObject(): "
<<"id="<<id<<" not found"<<std::endl;
return;
}
@ -2024,7 +2036,7 @@ void ClientEnvironment::processActiveObjectMessage(u16 id,
ClientActiveObject* obj = getActiveObject(id);
if(obj == NULL)
{
dstream<<"WARNING: ClientEnvironment::processActiveObjectMessage():"
infostream<<"ClientEnvironment::processActiveObjectMessage():"
<<" got message for id="<<id<<", which doesn't exist."
<<std::endl;
return;