Mark Holmquist 2011-10-16 11:22:12 -07:00
commit d5b2db1932
33 changed files with 1300 additions and 795 deletions

View File

@ -3,6 +3,19 @@ Minetest-c55 changelog
This should contain all the major changes.
For minor stuff, refer to the commit log of the repository.
0.3.dev-20111016:
- Locked chest
- Server user limit setting (max_users)
- Wielded tool is shown in HUD
- View bobbing
- Saplings that drop from leaf blocks and when placed on ground will grow to trees
- Optimized map saving (does not re-save everything all the time)
- New mob system and new mob: dungeon master
- Death/respawn screen
0.2.20110922_3:
- Fix the build for MSVC2010; also released for windows using MSVC2010.
0.2.20110922_1:
- Make client report a newer version number to the server than 2011-07-31 does and make server disallow old clients

View File

@ -122,6 +122,8 @@ screenH# = 600
#creative_mode = false
# Enable players getting damage and dying
#enable_damage = false
# Despawn all non-peaceful mobs
#only_peaceful_mobs = false
# A chosen map seed for a new map, leave empty for random
#fixed_map_seed =
# Gives some stuff to players at the beginning

View File

@ -90,6 +90,7 @@ configure_file(
)
set(common_SRCS
log.cpp
content_sao.cpp
mapgen.cpp
content_inventory.cpp

View File

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"
#include "settings.h"
#include "profiler.h"
#include "log.h"
/*
QueuedMeshUpdate
@ -131,6 +132,8 @@ void * MeshUpdateThread::Thread()
{
ThreadStarted();
log_register_thread("MeshUpdateThread");
DSTACK(__FUNCTION_NAME);
BEGIN_DEBUG_EXCEPTION_HANDLER
@ -163,7 +166,7 @@ void * MeshUpdateThread::Thread()
r.mesh = mesh_new;
r.ack_block_to_server = q->ack_block_to_server;
/*dstream<<"MeshUpdateThread: Processed "
/*infostream<<"MeshUpdateThread: Processed "
<<"("<<q->p.X<<","<<q->p.Y<<","<<q->p.Z<<")"
<<std::endl;*/
@ -172,7 +175,7 @@ void * MeshUpdateThread::Thread()
delete q;
}
END_DEBUG_EXCEPTION_HANDLER
END_DEBUG_EXCEPTION_HANDLER(errorstream)
return NULL;
}
@ -273,7 +276,7 @@ void Client::step(float dtime)
else
m_ignore_damage_timer = 0.0;
//dstream<<"Client steps "<<dtime<<std::endl;
//infostream<<"Client steps "<<dtime<<std::endl;
{
//TimeTaker timer("ReceiveAll()", m_device);
@ -298,8 +301,8 @@ void Client::step(float dtime)
{
counter = 20.0;
dout_client<<"Client packetcounter (20s):"<<std::endl;
m_packetcounter.print(dout_client);
infostream<<"Client packetcounter (20s):"<<std::endl;
m_packetcounter.print(infostream);
m_packetcounter.clear();
}
}
@ -343,9 +346,9 @@ void Client::step(float dtime)
if(deleted_blocks.size() > 0)
{
/*dstream<<DTIME<<"Client: Deleted blocks of "<<num
/*infostream<<"Client: Deleted blocks of "<<num
<<" unused sectors"<<std::endl;*/
/*dstream<<DTIME<<"Client: Deleted "<<num
/*infostream<<"Client: Deleted "<<num
<<" unused sectors"<<std::endl;*/
/*
@ -424,7 +427,7 @@ void Client::step(float dtime)
memset((char*)&data[3], 0, PLAYERNAME_SIZE);
snprintf((char*)&data[3], PLAYERNAME_SIZE, "%s", myplayer->getName());
/*dstream<<"Client: sending initial password hash: \""<<m_password<<"\""
/*infostream<<"Client: sending initial password hash: \""<<m_password<<"\""
<<std::endl;*/
memset((char*)&data[23], 0, PASSWORD_SIZE);
@ -458,7 +461,7 @@ void Client::step(float dtime)
&deleted_blocks);
/*if(deleted_blocks.size() > 0)
dstream<<"Client: Unloaded "<<deleted_blocks.size()
infostream<<"Client: Unloaded "<<deleted_blocks.size()
<<" unused blocks"<<std::endl;*/
/*
@ -561,7 +564,7 @@ void Client::step(float dtime)
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
// connectedAndInitialized() is true, peer exists.
con::Peer *peer = m_con.GetPeer(PEER_ID_SERVER);
dstream<<DTIME<<"Client: avg_rtt="<<peer->avg_rtt<<std::endl;
infostream<<"Client: avg_rtt="<<peer->avg_rtt<<std::endl;
}
}
@ -587,7 +590,7 @@ void Client::step(float dtime)
//TimeTaker timer("** Processing mesh update result queue");
// 0ms
/*dstream<<"Mesh update result queue size is "
/*infostream<<"Mesh update result queue size is "
<<m_mesh_update_thread.m_queue_out.size()
<<std::endl;*/
@ -601,7 +604,7 @@ void Client::step(float dtime)
}
if(r.ack_block_to_server)
{
/*dstream<<"Client: ACK block ("<<r.p.X<<","<<r.p.Y
/*infostream<<"Client: ACK block ("<<r.p.X<<","<<r.p.Y
<<","<<r.p.Z<<")"<<std::endl;*/
/*
Acknowledge block
@ -628,12 +631,12 @@ void Client::step(float dtime)
// Virtual methods from con::PeerHandler
void Client::peerAdded(con::Peer *peer)
{
derr_client<<"Client::peerAdded(): peer->id="
infostream<<"Client::peerAdded(): peer->id="
<<peer->id<<std::endl;
}
void Client::deletingPeer(con::Peer *peer, bool timeout)
{
derr_client<<"Client::deletingPeer(): "
infostream<<"Client::deletingPeer(): "
"Server Peer is getting deleted "
<<"(timeout="<<timeout<<")"<<std::endl;
}
@ -652,7 +655,7 @@ void Client::ReceiveAll()
}
catch(con::InvalidIncomingDataException &e)
{
dout_client<<DTIME<<"Client::ReceiveAll(): "
infostream<<"Client::ReceiveAll(): "
"InvalidIncomingDataException: what()="
<<e.what()<<std::endl;
}
@ -691,7 +694,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
ToClientCommand command = (ToClientCommand)readU16(&data[0]);
//dstream<<"Client: received command="<<command<<std::endl;
//infostream<<"Client: received command="<<command<<std::endl;
m_packetcounter.add((u16)command);
/*
@ -700,7 +703,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
*/
if(sender_peer_id != PEER_ID_SERVER)
{
dout_client<<DTIME<<"Client::ProcessData(): Discarding data not "
infostream<<"Client::ProcessData(): Discarding data not "
"coming from server: peer_id="<<sender_peer_id
<<std::endl;
return;
@ -716,7 +719,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
u8 ser_version = m_server_ser_ver;
//dstream<<"Client received command="<<(int)command<<std::endl;
//infostream<<"Client received command="<<(int)command<<std::endl;
if(command == TOCLIENT_INIT)
{
@ -725,13 +728,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
u8 deployed = data[2];
dout_client<<DTIME<<"Client: TOCLIENT_INIT received with "
infostream<<"Client: TOCLIENT_INIT received with "
"deployed="<<((int)deployed&0xff)<<std::endl;
if(deployed < SER_FMT_VER_LOWEST
|| deployed > SER_FMT_VER_HIGHEST)
{
derr_client<<DTIME<<"Client: TOCLIENT_INIT: Server sent "
infostream<<"Client: TOCLIENT_INIT: Server sent "
<<"unsupported ser_fmt_ver"<<std::endl;
return;
}
@ -757,7 +760,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
{
// Get map seed
m_map_seed = readU64(&data[2+1+6]);
dstream<<"Client: received map seed: "<<m_map_seed<<std::endl;
infostream<<"Client: received map seed: "<<m_map_seed<<std::endl;
}
// Reply to server
@ -788,7 +791,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
if(ser_version == SER_FMT_VER_INVALID)
{
dout_client<<DTIME<<"WARNING: Client: Server serialization"
infostream<<"Client: Server serialization"
" format invalid or not initialized."
" Skipping incoming command="<<command<<std::endl;
return;
@ -842,9 +845,9 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
p.Y = readS16(&data[4]);
p.Z = readS16(&data[6]);
/*dout_client<<DTIME<<"Client: Thread: BLOCKDATA for ("
/*infostream<<"Client: Thread: BLOCKDATA for ("
<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
/*dstream<<DTIME<<"Client: Thread: BLOCKDATA for ("
/*infostream<<"Client: Thread: BLOCKDATA for ("
<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
std::string datastring((char*)&data[8], datasize-8);
@ -867,7 +870,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
/*
Update an existing block
*/
//dstream<<"Updating"<<std::endl;
//infostream<<"Updating"<<std::endl;
block->deSerialize(istr, ser_version);
}
else
@ -875,7 +878,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
/*
Create a new block
*/
//dstream<<"Creating new"<<std::endl;
//infostream<<"Creating new"<<std::endl;
block = new MapBlock(&m_env.getMap(), p);
block->deSerialize(istr, ser_version);
sector->insertBlock(block);
@ -921,12 +924,12 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
/*
Add it to mesh update queue and set it to be acknowledged after update.
*/
//std::cerr<<"Adding mesh update task for received block"<<std::endl;
//infostream<<"Adding mesh update task for received block"<<std::endl;
addUpdateMeshTaskWithEdge(p, true);
}
else if(command == TOCLIENT_PLAYERPOS)
{
dstream<<"WARNING: Received deprecated TOCLIENT_PLAYERPOS"
infostream<<"Received deprecated TOCLIENT_PLAYERPOS"
<<std::endl;
/*u16 our_peer_id;
{
@ -935,7 +938,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
// Cancel if we don't have a peer id
if(our_peer_id == PEER_ID_INEXISTENT){
dout_client<<DTIME<<"TOCLIENT_PLAYERPOS cancelled: "
infostream<<"TOCLIENT_PLAYERPOS cancelled: "
"we have no peer id"
<<std::endl;
return;
@ -972,7 +975,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
v3s32 ss = readV3S32(&data[start+2+12]);
s32 pitch_i = readS32(&data[start+2+12+12]);
s32 yaw_i = readS32(&data[start+2+12+12+4]);
/*dstream<<"Client: got "
/*infostream<<"Client: got "
<<"pitch_i="<<pitch_i
<<" yaw_i="<<yaw_i<<std::endl;*/
f32 pitch = (f32)pitch_i / 100.0;
@ -984,7 +987,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
player->setPitch(pitch);
player->setYaw(yaw);
/*dstream<<"Client: player "<<peer_id
/*infostream<<"Client: player "<<peer_id
<<" pitch="<<pitch
<<" yaw="<<yaw<<std::endl;*/
@ -1001,13 +1004,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
// Cancel if we don't have a peer id
if(our_peer_id == PEER_ID_INEXISTENT){
dout_client<<DTIME<<"TOCLIENT_PLAYERINFO cancelled: "
infostream<<"TOCLIENT_PLAYERINFO cancelled: "
"we have no peer id"
<<std::endl;
return;
}
//dstream<<DTIME<<"Client: Server reports players:"<<std::endl;
//infostream<<"Client: Server reports players:"<<std::endl;
{ //envlock
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
@ -1026,7 +1029,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
players_alive.push_back(peer_id);
/*dstream<<DTIME<<"peer_id="<<peer_id
/*infostream<<"peer_id="<<peer_id
<<" name="<<((char*)&data[start+2])<<std::endl;*/
// Don't update the info of the local player
@ -1047,7 +1050,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
-1);
player->peer_id = peer_id;
m_env.addPlayer(player);
dout_client<<DTIME<<"Client: Adding new player "
infostream<<"Client: Adding new player "
<<peer_id<<std::endl;
}
@ -1060,7 +1063,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
Remove those players from the environment that
weren't listed by the server.
*/
//dstream<<DTIME<<"Removing dead players"<<std::endl;
//infostream<<"Removing dead players"<<std::endl;
core::list<Player*> players = m_env.getPlayers();
core::list<Player*>::Iterator ip;
for(ip=players.begin(); ip!=players.end(); ip++)
@ -1072,7 +1075,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
// Warn about a special case
if((*ip)->peer_id == 0)
{
dstream<<DTIME<<"WARNING: Client: Removing "
infostream<<"Client: Removing "
"dead player with id=0"<<std::endl;
}
@ -1086,11 +1089,11 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
break;
}
}
/*dstream<<DTIME<<"peer_id="<<((*ip)->peer_id)
/*infostream<<"peer_id="<<((*ip)->peer_id)
<<" is_alive="<<is_alive<<std::endl;*/
if(is_alive)
continue;
dstream<<DTIME<<"Removing dead player "<<(*ip)->peer_id
infostream<<"Removing dead player "<<(*ip)->peer_id
<<std::endl;
m_env.removePlayer((*ip)->peer_id);
}
@ -1098,7 +1101,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
else if(command == TOCLIENT_SECTORMETA)
{
dstream<<"Client received DEPRECATED TOCLIENT_SECTORMETA"<<std::endl;
infostream<<"Client received DEPRECATED TOCLIENT_SECTORMETA"<<std::endl;
#if 0
/*
[0] u16 command
@ -1108,7 +1111,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
if(datasize < 3)
return;
//dstream<<"Client received TOCLIENT_SECTORMETA"<<std::endl;
//infostream<<"Client received TOCLIENT_SECTORMETA"<<std::endl;
{ //envlock
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
@ -1121,14 +1124,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
is.read((char*)buf, 1);
u16 sector_count = readU8(buf);
//dstream<<"sector_count="<<sector_count<<std::endl;
//infostream<<"sector_count="<<sector_count<<std::endl;
for(u16 i=0; i<sector_count; i++)
{
// Read position
is.read((char*)buf, 4);
v2s16 pos = readV2S16(buf);
/*dstream<<"Client: deserializing sector at "
/*infostream<<"Client: deserializing sector at "
<<"("<<pos.X<<","<<pos.Y<<")"<<std::endl;*/
// Create sector
assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
@ -1154,7 +1157,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
std::istringstream is(datastring, std::ios_base::binary);
//t3.stop();
//m_env.printPlayers(dstream);
//m_env.printPlayers(infostream);
//TimeTaker t4("player get", m_device);
Player *player = m_env.getLocalPlayer();
@ -1167,8 +1170,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
m_inventory_updated = true;
//dstream<<"Client got player inventory:"<<std::endl;
//player->inventory.print(dstream);
//infostream<<"Client got player inventory:"<<std::endl;
//player->inventory.print(infostream);
}
}
//DEBUG
@ -1233,7 +1236,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
// Read active block count
u16 blockcount = readU16(is);
if(blockcount != 0){
dstream<<"WARNING: TOCLIENT_OBJECTDATA: blockcount != 0 "
infostream<<"TOCLIENT_OBJECTDATA: blockcount != 0 "
"not supported"<<std::endl;
return;
}
@ -1245,7 +1248,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
u16 time_of_day = readU16(&data[2]);
time_of_day = time_of_day % 24000;
//dstream<<"Client: time_of_day="<<time_of_day<<std::endl;
//infostream<<"Client: time_of_day="<<time_of_day<<std::endl;
/*
time_of_day:
@ -1257,7 +1260,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
u32 dr = m_env.getDayNightRatio();
dstream<<"Client: time_of_day="<<time_of_day
infostream<<"Client: time_of_day="<<time_of_day
<<", dr="<<dr
<<std::endl;
}
@ -1285,7 +1288,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
message += (wchar_t)readU16(buf);
}
/*dstream<<"Client received chat message: "
/*infostream<<"Client received chat message: "
<<wide_to_narrow(message)<<std::endl;*/
m_chat_queue.push_back(message);
@ -1414,7 +1417,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
/*player->setPitch(pitch);
player->setYaw(yaw);*/
dstream<<"Client got TOCLIENT_MOVE_PLAYER"
infostream<<"Client got TOCLIENT_MOVE_PLAYER"
<<" pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"
<<" pitch="<<pitch
<<" yaw="<<yaw
@ -1449,13 +1452,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
if (player == NULL)
{
dout_client<<DTIME<<"Client: ignoring player item "
infostream<<"Client: ignoring player item "
<< deSerializeString(is)
<< " for non-existing peer id " << peer_id
<< std::endl;
continue;
} else if (player->isLocal()) {
dout_client<<DTIME<<"Client: ignoring player item "
infostream<<"Client: ignoring player item "
<< deSerializeString(is)
<< " for local player" << std::endl;
continue;
@ -1464,15 +1467,15 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
std::string itemstring(deSerializeString(is));
if (itemstring.empty()) {
inv->deleteItem(0);
dout_client<<DTIME
infostream
<<"Client: empty player item for peer "
<< peer_id << std::endl;
} else {
std::istringstream iss(itemstring);
delete inv->changeItem(0, InventoryItem::deSerialize(iss));
dout_client<<DTIME<<"Client: player item for peer " << peer_id << ": ";
player->getWieldItem()->serialize(dout_client);
dout_client<<std::endl;
infostream<<"Client: player item for peer " << peer_id << ": ";
player->getWieldItem()->serialize(infostream);
infostream<<std::endl;
}
}
}
@ -1495,7 +1498,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
else
{
dout_client<<DTIME<<"WARNING: Client: Ignoring unknown command "
infostream<<"Client: Ignoring unknown command "
<<command<<std::endl;
}
}
@ -1510,7 +1513,7 @@ void Client::groundAction(u8 action, v3s16 nodepos_undersurface,
v3s16 nodepos_oversurface, u16 item)
{
if(connectedAndInitialized() == false){
dout_client<<DTIME<<"Client::groundAction() "
infostream<<"Client::groundAction() "
"cancelled (not connected)"
<<std::endl;
return;
@ -1542,7 +1545,7 @@ void Client::groundAction(u8 action, v3s16 nodepos_undersurface,
void Client::clickActiveObject(u8 button, u16 id, u16 item_i)
{
if(connectedAndInitialized() == false){
dout_client<<DTIME<<"Client::clickActiveObject() "
infostream<<"Client::clickActiveObject() "
"cancelled (not connected)"
<<std::endl;
return;
@ -1954,12 +1957,12 @@ Inventory* Client::getInventory(InventoryContext *c, std::string id)
NodeMetadata* meta = getNodeMetadata(p);
if(meta)
return meta->getInventory();
dstream<<"nodemeta at ("<<p.X<<","<<p.Y<<","<<p.Z<<"): "
infostream<<"nodemeta at ("<<p.X<<","<<p.Y<<","<<p.Z<<"): "
<<"no metadata found"<<std::endl;
return NULL;
}
dstream<<__FUNCTION_NAME<<": unknown id "<<id<<std::endl;
infostream<<__FUNCTION_NAME<<": unknown id "<<id<<std::endl;
return NULL;
}
void Client::inventoryAction(InventoryAction *a)
@ -1977,7 +1980,7 @@ ClientActiveObject * Client::getSelectedActiveObject(
m_env.getActiveObjects(from_pos_f_on_map, max_d, objects);
//dstream<<"Collected "<<objects.size()<<" nearby objects"<<std::endl;
//infostream<<"Collected "<<objects.size()<<" nearby objects"<<std::endl;
// Sort them.
// After this, the closest object is the first in the array.
@ -2000,12 +2003,12 @@ ClientActiveObject * Client::getSelectedActiveObject(
if(offsetted_box.intersectsWithLine(shootline_on_map))
{
//dstream<<"Returning selected object"<<std::endl;
//infostream<<"Returning selected object"<<std::endl;
return obj;
}
}
//dstream<<"No object selected; returning NULL."<<std::endl;
//infostream<<"No object selected; returning NULL."<<std::endl;
return NULL;
}
@ -2069,7 +2072,7 @@ void Client::clearTempMod(v3s16 p)
void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server)
{
/*dstream<<"Client::addUpdateMeshTask(): "
/*infostream<<"Client::addUpdateMeshTask(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;*/
@ -2096,7 +2099,7 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server)
// Add task to queue
m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server);
/*dstream<<"Mesh update input queue size is "
/*infostream<<"Mesh update input queue size is "
<<m_mesh_update_thread.m_queue_in.size()
<<std::endl;*/
@ -2123,7 +2126,7 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server)
{
/*{
v3s16 p = blockpos;
dstream<<"Client::addUpdateMeshTaskWithEdge(): "
infostream<<"Client::addUpdateMeshTaskWithEdge(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;
}*/

View File

@ -116,7 +116,7 @@ void TestCAO::step(float dtime, ClientEnvironment *env)
if(m_node)
{
v3f rot = m_node->getRotation();
//dstream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
//infostream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
rot.Y += dtime * 180;
m_node->setRotation(rot);
}
@ -124,7 +124,7 @@ void TestCAO::step(float dtime, ClientEnvironment *env)
void TestCAO::processMessage(const std::string &data)
{
dstream<<"TestCAO: Got data: "<<data<<std::endl;
infostream<<"TestCAO: Got data: "<<data<<std::endl;
std::istringstream is(data, std::ios::binary);
u16 cmd;
is>>cmd;
@ -259,7 +259,7 @@ void ItemCAO::step(float dtime, ClientEnvironment *env)
void ItemCAO::processMessage(const std::string &data)
{
dstream<<"ItemCAO: Got message"<<std::endl;
infostream<<"ItemCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
@ -273,7 +273,7 @@ void ItemCAO::processMessage(const std::string &data)
void ItemCAO::initialize(const std::string &data)
{
dstream<<"ItemCAO: Got init data"<<std::endl;
infostream<<"ItemCAO: Got init data"<<std::endl;
{
std::istringstream is(data, std::ios::binary);
@ -313,7 +313,7 @@ void ItemCAO::initialize(const std::string &data)
try{
InventoryItem *item = NULL;
item = InventoryItem::deSerialize(is);
dstream<<__FUNCTION_NAME<<": m_inventorystring=\""
infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item
<<std::endl;
if(item)
@ -324,7 +324,7 @@ void ItemCAO::initialize(const std::string &data)
}
catch(SerializationError &e)
{
dstream<<"WARNING: "<<__FUNCTION_NAME
infostream<<"WARNING: "<<__FUNCTION_NAME
<<": error deSerializing inventorystring \""
<<m_inventorystring<<"\""<<std::endl;
}
@ -446,7 +446,7 @@ void RatCAO::step(float dtime, ClientEnvironment *env)
void RatCAO::processMessage(const std::string &data)
{
//dstream<<"RatCAO: Got message"<<std::endl;
//infostream<<"RatCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
@ -463,7 +463,7 @@ void RatCAO::processMessage(const std::string &data)
void RatCAO::initialize(const std::string &data)
{
//dstream<<"RatCAO: Got init data"<<std::endl;
//infostream<<"RatCAO: Got init data"<<std::endl;
{
std::istringstream is(data, std::ios::binary);
@ -670,7 +670,7 @@ void Oerkki1CAO::step(float dtime, ClientEnvironment *env)
void Oerkki1CAO::processMessage(const std::string &data)
{
//dstream<<"Oerkki1CAO: Got message"<<std::endl;
//infostream<<"Oerkki1CAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
@ -692,7 +692,7 @@ void Oerkki1CAO::processMessage(const std::string &data)
void Oerkki1CAO::initialize(const std::string &data)
{
//dstream<<"Oerkki1CAO: Got init data"<<std::endl;
//infostream<<"Oerkki1CAO: Got init data"<<std::endl;
{
std::istringstream is(data, std::ios::binary);
@ -831,7 +831,7 @@ void FireflyCAO::step(float dtime, ClientEnvironment *env)
void FireflyCAO::processMessage(const std::string &data)
{
//dstream<<"FireflyCAO: Got message"<<std::endl;
//infostream<<"FireflyCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
@ -848,7 +848,7 @@ void FireflyCAO::processMessage(const std::string &data)
void FireflyCAO::initialize(const std::string &data)
{
//dstream<<"FireflyCAO: Got init data"<<std::endl;
//infostream<<"FireflyCAO: Got init data"<<std::endl;
{
std::istringstream is(data, std::ios::binary);
@ -912,7 +912,7 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr)
if(m_node != NULL)
return;
/*dstream<<"MobV2CAO::addToScene using texture_name="<<
/*infostream<<"MobV2CAO::addToScene using texture_name="<<
m_texture_name<<std::endl;*/
std::string texture_string = "[makealpha2:128,0,0;128,128,0:";
texture_string += m_texture_name;
@ -944,7 +944,7 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr)
bill->setTCoords(2, v2f(txs*0, tys*0));
bill->setTCoords(3, v2f(txs*0, tys*1));
} else {
dstream<<"MobV2CAO: Unknown sprite type \""<<m_sprite_type<<"\""
infostream<<"MobV2CAO: Unknown sprite type \""<<m_sprite_type<<"\""
<<std::endl;
}
@ -1023,7 +1023,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env)
float mob_dir = atan2(cam_to_mob.Z, cam_to_mob.X) / PI * 180.;
float dir = mob_dir - m_yaw;
dir = wrapDegrees_180(dir);
//dstream<<"id="<<m_id<<" dir="<<dir<<std::endl;
//infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
col = 2;
else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
@ -1074,7 +1074,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env)
bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row)));
bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row)));
} else {
dstream<<"MobV2CAO::step(): Unknown sprite type \""
infostream<<"MobV2CAO::step(): Unknown sprite type \""
<<m_sprite_type<<"\""<<std::endl;
}
@ -1104,7 +1104,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env)
if(m_damage_visual_timer >= 0){
m_damage_visual_timer -= dtime;
if(m_damage_visual_timer <= 0){
dstream<<"id="<<m_id<<" damage visual ended"<<std::endl;
infostream<<"id="<<m_id<<" damage visual ended"<<std::endl;
}
}
@ -1128,7 +1128,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env)
void MobV2CAO::processMessage(const std::string &data)
{
//dstream<<"MobV2CAO: Got message"<<std::endl;
//infostream<<"MobV2CAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
@ -1182,7 +1182,7 @@ void MobV2CAO::processMessage(const std::string &data)
void MobV2CAO::initialize(const std::string &data)
{
//dstream<<"MobV2CAO: Got init data"<<std::endl;
//infostream<<"MobV2CAO: Got init data"<<std::endl;
{
std::istringstream is(data, std::ios::binary);
@ -1190,7 +1190,7 @@ void MobV2CAO::initialize(const std::string &data)
u8 version = readU8(is);
// check version
if(version != 0){
dstream<<__FUNCTION_NAME<<": Invalid version"<<std::endl;
infostream<<__FUNCTION_NAME<<": Invalid version"<<std::endl;
return;
}
@ -1199,8 +1199,8 @@ void MobV2CAO::initialize(const std::string &data)
std::istringstream tmp_is(tmp_os.str(), std::ios::binary);
m_properties->parseConfigLines(tmp_is, "MobArgsEnd");
dstream<<"INFO: MobV2CAO::initialize(): got properties:"<<std::endl;
m_properties->writeLines(dstream);
infostream<<"MobV2CAO::initialize(): got properties:"<<std::endl;
m_properties->writeLines(infostream);
m_properties->setDefault("looks", "dummy_default");
m_properties->setDefault("yaw", "0");

View File

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_nodemeta.h"
#include "inventory.h"
#include "content_mapnode.h"
#include "log.h"
/*
SignNodeMetadata
@ -287,12 +288,12 @@ bool FurnaceNodeMetadata::nodeRemovalDisabled()
}
void FurnaceNodeMetadata::inventoryModified()
{
dstream<<"Furnace inventory modification callback"<<std::endl;
infostream<<"Furnace inventory modification callback"<<std::endl;
}
bool FurnaceNodeMetadata::step(float dtime)
{
if(dtime > 60.0)
dstream<<"Furnace stepping a long time ("<<dtime<<")"<<std::endl;
infostream<<"Furnace stepping a long time ("<<dtime<<")"<<std::endl;
// Update at a fixed frequency
const float interval = 2.0;
m_step_accumulator += dtime;
@ -302,7 +303,7 @@ bool FurnaceNodeMetadata::step(float dtime)
m_step_accumulator -= interval;
dtime = interval;
//dstream<<"Furnace step dtime="<<dtime<<std::endl;
//infostream<<"Furnace step dtime="<<dtime<<std::endl;
InventoryList *dst_list = m_inventory->getList("dst");
assert(dst_list);
@ -334,7 +335,7 @@ bool FurnaceNodeMetadata::step(float dtime)
*/
if(m_fuel_time < m_fuel_totaltime)
{
//dstream<<"Furnace is active"<<std::endl;
//infostream<<"Furnace is active"<<std::endl;
m_fuel_time += dtime;
m_src_time += dtime;
if(m_src_time >= m_src_totaltime && m_src_totaltime > 0.001
@ -369,7 +370,7 @@ bool FurnaceNodeMetadata::step(float dtime)
break;
}
//dstream<<"Furnace is out of fuel"<<std::endl;
//infostream<<"Furnace is out of fuel"<<std::endl;
InventoryList *fuel_list = m_inventory->getList("fuel");
assert(fuel_list);
@ -454,7 +455,7 @@ bool FurnaceNodeMetadata::step(float dtime)
}
else
{
//dstream<<"No fuel found"<<std::endl;
//infostream<<"No fuel found"<<std::endl;
// No fuel, stop loop.
m_step_accumulator = 0;
break;

View File

@ -84,7 +84,6 @@ void TestSAO::step(float dtime, bool send_recommended)
if(m_timer1 < 0.0)
{
m_timer1 += 0.125;
//dstream<<"TestSAO: id="<<getId()<<" sending data"<<std::endl;
std::string data;
@ -131,7 +130,7 @@ ServerActiveObject* ItemSAO::create(ServerEnvironment *env, u16 id, v3f pos,
if(version != 0)
return NULL;
std::string inventorystring = deSerializeString(is);
dstream<<"ItemSAO::create(): Creating item \""
infostream<<"ItemSAO::create(): Creating item \""
<<inventorystring<<"\""<<std::endl;
return new ItemSAO(env, id, pos, inventorystring);
}
@ -206,7 +205,7 @@ std::string ItemSAO::getClientInitializationData()
std::string ItemSAO::getStaticData()
{
dstream<<__FUNCTION_NAME<<std::endl;
infostream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
char buf[1];
// version
@ -222,14 +221,14 @@ InventoryItem * ItemSAO::createInventoryItem()
try{
std::istringstream is(m_inventorystring, std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is);
dstream<<__FUNCTION_NAME<<": m_inventorystring=\""
infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item
<<std::endl;
return item;
}
catch(SerializationError &e)
{
dstream<<__FUNCTION_NAME<<": serialization error: "
infostream<<__FUNCTION_NAME<<": serialization error: "
<<"m_inventorystring=\""<<m_inventorystring<<"\""<<std::endl;
return NULL;
}
@ -237,7 +236,7 @@ InventoryItem * ItemSAO::createInventoryItem()
void ItemSAO::rightClick(Player *player)
{
dstream<<__FUNCTION_NAME<<std::endl;
infostream<<__FUNCTION_NAME<<std::endl;
InventoryItem *item = createInventoryItem();
if(item == NULL)
return;
@ -424,7 +423,7 @@ std::string RatSAO::getClientInitializationData()
std::string RatSAO::getStaticData()
{
//dstream<<__FUNCTION_NAME<<std::endl;
//infostream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
@ -669,7 +668,7 @@ std::string Oerkki1SAO::getClientInitializationData()
std::string Oerkki1SAO::getStaticData()
{
//dstream<<__FUNCTION_NAME<<std::endl;
//infostream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
@ -689,7 +688,7 @@ u16 Oerkki1SAO::punch(const std::string &toolname, v3f dir)
void Oerkki1SAO::doDamage(u16 d)
{
dstream<<"oerkki damage: "<<d<<std::endl;
infostream<<"oerkki damage: "<<d<<std::endl;
if(d < m_hp)
{
@ -877,7 +876,7 @@ std::string FireflySAO::getClientInitializationData()
std::string FireflySAO::getStaticData()
{
//dstream<<__FUNCTION_NAME<<std::endl;
//infostream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
@ -960,7 +959,7 @@ std::string MobV2SAO::getStaticData()
std::string MobV2SAO::getClientInitializationData()
{
//dstream<<__FUNCTION_NAME<<std::endl;
//infostream<<__FUNCTION_NAME<<std::endl;
updateProperties();
@ -1091,8 +1090,10 @@ void MobV2SAO::step(float dtime, bool send_recommended)
f32 dist = m_base_position.getDistanceFrom(playerpos);
if(dist < BS*16)
{
if(myrand_range(0,2) == 0){
dstream<<"ACTION: id="<<m_id<<" got randomly disturbed by "
if(myrand_range(0,3) == 0){
actionstream<<"Mob id="<<m_id<<" at "
<<PP(m_base_position/BS)
<<" got randomly disturbed by "
<<player->getName()<<std::endl;
m_disturbing_player = player->getName();
m_disturb_timer = 0;
@ -1135,7 +1136,8 @@ void MobV2SAO::step(float dtime, bool send_recommended)
dir.normalize();
v3f speed = dir * BS * 10.0;
v3f pos = m_base_position + shoot_pos;
dstream<<__FUNCTION_NAME<<": Shooting fireball from "<<PP(pos)
infostream<<__FUNCTION_NAME<<": Mob id="<<m_id
<<" shooting fireball from "<<PP(pos)
<<" at speed "<<PP(speed)<<std::endl;
Settings properties;
properties.set("looks", "fireball");
@ -1152,7 +1154,8 @@ void MobV2SAO::step(float dtime, bool send_recommended)
//m_env->addActiveObjectAsStatic(obj);
m_env->addActiveObject(obj);
} else {
dstream<<__FUNCTION_NAME<<": Unknown shoot_type="<<shoot_type
infostream<<__FUNCTION_NAME<<": Mob id="<<m_id
<<": Unknown shoot_type="<<shoot_type
<<std::endl;
}
}
@ -1163,16 +1166,23 @@ void MobV2SAO::step(float dtime, bool send_recommended)
if(m_disturb_timer <= 15.0)
reload_time = 3.0;
bool shoot_without_player = false;
if(m_properties->getBool("mindless_rage"))
shoot_without_player = true;
if(!m_shooting && m_shoot_reload_timer >= reload_time &&
!m_next_pos_exists)
!m_next_pos_exists &&
(m_disturb_timer <= 60.0 || shoot_without_player))
{
m_shoot_y = 0;
if(m_disturb_timer < 30.0 && disturbing_player &&
if(m_disturb_timer < 60.0 && disturbing_player &&
disturbing_player_distance < 16*BS &&
fabs(disturbing_player_norm.Y) < 0.8){
m_yaw = disturbing_player_dir;
sendPosition();
m_shoot_y += disturbing_player_norm.Y;
} else {
m_shoot_y = 0.01 * myrand_range(-30,10);
}
m_shoot_reload_timer = 0.0;
m_shooting = true;
@ -1229,7 +1239,8 @@ void MobV2SAO::step(float dtime, bool send_recommended)
m_base_position = pos_f;
if((pos_f - next_pos_f).getLength() < 0.1 || arrived){
//dstream<<"id="<<m_id<<": arrived to "<<PP(m_next_pos_i)<<std::endl;
verbosestream<<"Mob id="<<m_id<<": arrived to "
<<PP(m_next_pos_i)<<std::endl;
m_next_pos_exists = false;
}
}
@ -1271,16 +1282,10 @@ void MobV2SAO::step(float dtime, bool send_recommended)
}
u32 order[3*3*3];
get_random_u32_array(order, num_dps);
/*dstream<<"At pos "<<PP(pos_i)<<"; Random array: ";
for(int i=0; i<num_dps; i++){
dstream<<order[i]<<" ";
}
dstream<<std::endl;*/
for(int i=0; i<num_dps; i++){
v3s16 p = dps[order[i]] + pos_i;
bool is_free = checkFreeAndWalkablePosition(map,
p + pos_size_off, size_blocks);
//dstream<<PP(p)<<" is_free="<<is_free<<std::endl;
if(!is_free)
continue;
m_next_pos_i = p;
@ -1310,7 +1315,7 @@ void MobV2SAO::step(float dtime, bool send_recommended)
}
else
{
dstream<<"MobV2SAO::step(): id="<<m_id<<" unknown move_type=\""
errorstream<<"MobV2SAO::step(): id="<<m_id<<" unknown move_type=\""
<<m_move_type<<"\""<<std::endl;
}
@ -1329,8 +1334,9 @@ u16 MobV2SAO::punch(const std::string &toolname, v3f dir,
assert(m_env);
Map *map = &m_env->getMap();
dstream<<"ACTION: "<<playername<<" punches id="<<m_id
<<" with a \""<<toolname<<"\""<<std::endl;
actionstream<<playername<<" punches mob id="<<m_id
<<" with a \""<<toolname<<"\" at "
<<PP(m_base_position/BS)<<std::endl;
m_disturb_timer = 0;
m_disturbing_player = playername;
@ -1370,6 +1376,11 @@ u16 MobV2SAO::punch(const std::string &toolname, v3f dir,
return 65536/100;
}
bool MobV2SAO::isPeaceful()
{
return m_properties->getBool("is_peaceful");
}
void MobV2SAO::sendPosition()
{
m_last_sent_position = m_base_position;
@ -1388,6 +1399,7 @@ void MobV2SAO::sendPosition()
void MobV2SAO::setPropertyDefaults()
{
m_properties->setDefault("is_peaceful", "false");
m_properties->setDefault("move_type", "ground_nodes");
m_properties->setDefault("speed", "(0,0,0)");
m_properties->setDefault("age", "0");
@ -1398,6 +1410,7 @@ void MobV2SAO::setPropertyDefaults()
m_properties->setDefault("size", "(1,2)");
m_properties->setDefault("shoot_type", "fireball");
m_properties->setDefault("shoot_y", "0");
m_properties->setDefault("mindless_rage", "false");
}
void MobV2SAO::readProperties()
{
@ -1426,7 +1439,7 @@ void MobV2SAO::updateProperties()
void MobV2SAO::doDamage(u16 d)
{
dstream<<"MobV2 hp="<<m_hp<<" damage="<<d<<std::endl;
infostream<<"MobV2 hp="<<m_hp<<" damage="<<d<<std::endl;
if(d < m_hp)
{
@ -1434,6 +1447,8 @@ void MobV2SAO::doDamage(u16 d)
}
else
{
actionstream<<"A "<<(isPeaceful()?"peaceful":"non-peaceful")
<<" mob id="<<m_id<<" dies at "<<PP(m_base_position)<<std::endl;
// Die
m_hp = 0;
m_removed = true;

View File

@ -97,6 +97,7 @@ public:
std::string getStaticData();
InventoryItem* createPickedUpItem(){return NULL;}
u16 punch(const std::string &toolname, v3f dir);
bool isPeaceful(){return false;}
private:
void doDamage(u16 d);
@ -157,6 +158,7 @@ public:
InventoryItem* createPickedUpItem(){return NULL;}
u16 punch(const std::string &toolname, v3f dir,
const std::string &playername);
bool isPeaceful();
private:
void sendPosition();
void setPropertyDefaults();

View File

@ -235,10 +235,9 @@ private:
#if CATCH_UNHANDLED_EXCEPTIONS == 1
#define BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER try{
#define END_PORTABLE_DEBUG_EXCEPTION_HANDLER\
#define END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)\
}catch(std::exception &e){\
dstream<<std::endl<<DTIME\
<<"ERROR: An unhandled exception occurred: "\
logstream<<"ERROR: An unhandled exception occurred: "\
<<e.what()<<std::endl;\
assert(0);\
}
@ -257,24 +256,24 @@ public:
BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER\
_set_se_translator(se_trans_func);
#define END_DEBUG_EXCEPTION_HANDLER \
END_PORTABLE_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER(logstream) \
END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
#else // Probably mingw
#define BEGIN_DEBUG_EXCEPTION_HANDLER\
BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER\
END_PORTABLE_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER(logstream)\
END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
#endif
#else // Posix
#define BEGIN_DEBUG_EXCEPTION_HANDLER\
BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER\
END_PORTABLE_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER(logstream)\
END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
#endif
#else
// Dummy ones
#define BEGIN_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER
#define END_DEBUG_EXCEPTION_HANDLER(logstream)
#endif
#endif // DEBUG_HEADER

View File

@ -83,6 +83,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("strict_protocol_version_checking", "true");
settings->setDefault("creative_mode", "false");
settings->setDefault("enable_damage", "true");
settings->setDefault("only_peaceful_mobs", "false");
settings->setDefault("fixed_map_seed", "");
settings->setDefault("give_initial_stuff", "false");
settings->setDefault("default_password", "");

View File

@ -27,6 +27,10 @@ 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"
#include "profiler.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Environment::Environment():
m_time_of_day(9000)
@ -302,7 +306,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 +315,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 +340,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 +354,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 +362,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 +383,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 +402,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 +420,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 +429,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 +437,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 +450,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 +482,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 +502,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 +599,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);
@ -654,6 +658,7 @@ static void getMob_dungeon_master(Settings &properties)
properties.set("player_hit_damage", "1");
properties.set("player_hit_distance", "1.0");
properties.set("player_hit_interval", "0.5");
properties.setBool("mindless_rage", myrand_range(0,100)==0);
}
void ServerEnvironment::step(float dtime)
@ -678,37 +683,40 @@ void ServerEnvironment::step(float dtime)
/*
Handle players
*/
for(core::list<Player*>::Iterator i = m_players.begin();
i != m_players.end(); i++)
{
Player *player = *i;
// Ignore disconnected players
if(player->peer_id == 0)
continue;
v3f playerpos = player->getPosition();
// Move
player->move(dtime, *m_map, 100*BS);
/*
Add footsteps to grass
*/
if(footprints)
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_LOWPASS);
for(core::list<Player*>::Iterator i = m_players.begin();
i != m_players.end(); i++)
{
// Get node that is at BS/4 under player
v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
try{
MapNode n = m_map->getNode(bottompos);
if(n.getContent() == CONTENT_GRASS)
{
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
}
}
catch(InvalidPositionException &e)
Player *player = *i;
// Ignore disconnected players
if(player->peer_id == 0)
continue;
v3f playerpos = player->getPosition();
// Move
player->move(dtime, *m_map, 100*BS);
/*
Add footsteps to grass
*/
if(footprints)
{
// Get node that is at BS/4 under player
v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
try{
MapNode n = m_map->getNode(bottompos);
if(n.getContent() == CONTENT_GRASS)
{
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
}
}
catch(InvalidPositionException &e)
{
}
}
}
}
@ -718,6 +726,7 @@ void ServerEnvironment::step(float dtime)
*/
if(m_active_blocks_management_interval.step(dtime, 2.0))
{
ScopeProfiler sp(g_profiler, "SEnv: manage act. block list avg", SPT_LOWPASS);
/*
Get player block positions
*/
@ -757,7 +766,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 +787,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);
@ -794,6 +803,8 @@ void ServerEnvironment::step(float dtime)
*/
if(m_active_blocks_nodemetadata_interval.step(dtime, 1.0))
{
ScopeProfiler sp(g_profiler, "SEnv: mess in act. blocks avg", SPT_LOWPASS);
float dtime = 1.0;
for(core::map<v3s16, bool>::Iterator
@ -802,7 +813,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);
@ -828,8 +839,10 @@ void ServerEnvironment::step(float dtime)
}
}
}
if(m_active_blocks_test_interval.step(dtime, 10.0))
{
ScopeProfiler sp(g_profiler, "SEnv: modify in blocks avg", SPT_LOWPASS);
//float dtime = 10.0;
for(core::map<v3s16, bool>::Iterator
@ -838,7 +851,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);
@ -863,7 +876,7 @@ void ServerEnvironment::step(float dtime)
// TODO: Implement usage of ActiveBlockModifier
// Find out how many objects the block contains
u32 active_object_count = block->m_static_objects.m_active.size();
//u32 active_object_count = block->m_static_objects.m_active.size();
// Find out how many objects this and all the neighbors contain
u32 active_object_count_wider = 0;
for(s16 x=-1; x<=1; x++)
@ -956,18 +969,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 +1002,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);
@ -1060,6 +1082,7 @@ void ServerEnvironment::step(float dtime)
Step active objects
*/
{
ScopeProfiler sp(g_profiler, "SEnv: step act. objs avg", SPT_LOWPASS);
//TimeTaker timer("Step active objects");
// This helps the objects to send data at the same time
@ -1076,6 +1099,11 @@ void ServerEnvironment::step(float dtime)
i.atEnd()==false; i++)
{
ServerActiveObject* obj = i.getNode()->getValue();
// Remove non-peaceful mobs on peaceful mode
if(g_settings->getBool("only_peaceful_mobs")){
if(!obj->isPeaceful())
obj->m_removed = true;
}
// Don't step if is to be removed or stored statically
if(obj->m_removed || obj->m_pending_deactivation)
continue;
@ -1095,6 +1123,7 @@ void ServerEnvironment::step(float dtime)
*/
if(m_object_management_interval.step(dtime, 0.5))
{
ScopeProfiler sp(g_profiler, "SEnv: remove removed objs avg", SPT_LOWPASS);
/*
Remove objects that satisfy (m_removed && m_known_by_count==0)
*/
@ -1143,7 +1172,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;
@ -1234,7 +1263,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;
@ -1314,13 +1343,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)
@ -1354,7 +1383,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;
@ -1363,12 +1392,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);
@ -1390,7 +1419,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;
}
@ -1412,7 +1441,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);
@ -1474,7 +1503,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
@ -1526,7 +1555,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;
@ -1585,7 +1614,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;
@ -1603,7 +1632,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;
@ -1691,11 +1720,6 @@ void ClientEnvironment::step(float dtime)
*/
bool is_climbing = lplayer->is_climbing;
/*
Check if the player is frozen (don't apply physics)
*/
bool is_frozen = lplayer->is_frozen;
f32 player_speed = 0.001; // just some small value
player_speed = lplayer->getSpeed().getLength();
@ -1753,7 +1777,7 @@ void ClientEnvironment::step(float dtime)
v3f lplayerpos = lplayer->getPosition();
// Apply physics
if(free_move == false && is_climbing == false && is_frozen == false)
if(free_move == false && is_climbing == false)
{
// Gravity
v3f speed = lplayer->getSpeed();
@ -1787,7 +1811,7 @@ void ClientEnvironment::step(float dtime)
while(dtime_downcount > 0.001);
//std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
for(core::list<CollisionInfo>::Iterator
i = player_collisions.begin();
i != player_collisions.end(); i++)
@ -1994,7 +2018,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;
@ -2003,12 +2027,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);
@ -2021,7 +2045,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;
@ -2036,12 +2060,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;
}
@ -2056,7 +2080,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;

View File

@ -279,7 +279,7 @@ bool RecursiveDeleteContent(std::string path)
{
if(trim(list[i].name) == "." || trim(list[i].name) == "..")
continue;
std::string childpath = path + "/" + list[i].name;
std::string childpath = path + DIR_DELIM + list[i].name;
bool r = RecursiveDelete(childpath);
if(r == false)
{
@ -299,7 +299,7 @@ bool CreateAllDirs(std::string path)
while(!PathExists(basepath))
{
tocreate.push_back(basepath);
pos = basepath.rfind('/');
pos = basepath.rfind(DIR_DELIM_C);
if(pos == std::string::npos)
return false;
basepath = basepath.substr(0,pos);

View File

@ -24,6 +24,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <vector>
#include "exceptions.h"
#ifdef _WIN32 // WINDOWS
#define DIR_DELIM "\\"
#define DIR_DELIM_C '\\'
#else // POSIX
#define DIR_DELIM "/"
#define DIR_DELIM_C '/'
#endif
namespace fs
{

View File

@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h"
#include "mainmenumanager.h"
#include "gettext.h"
#include "log.h"
#include "filesys.h"
/*
TODO: Move content-aware stuff to separate file by adding properties
@ -122,7 +124,7 @@ struct TextDestSignNode : public TextDest
void gotText(std::wstring text)
{
std::string ntext = wide_to_narrow(text);
dstream<<"Changing text of a sign node: "
infostream<<"Changing text of a sign node: "
<<ntext<<std::endl;
m_client->sendSignNodeText(m_p, ntext);
}
@ -161,7 +163,7 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
InventoryList *mainlist = inventory->getList("main");
if(mainlist == NULL)
{
dstream<<"WARNING: draw_hotbar(): mainlist == NULL"<<std::endl;
errorstream<<"draw_hotbar(): mainlist == NULL"<<std::endl;
return;
}
@ -299,7 +301,7 @@ void getPointedNode(Client *client, v3f player_position,
v3s16 pos_i = floatToInt(player_position, BS);
/*dstream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
/*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
<<std::endl;*/
s16 a = d;
@ -706,7 +708,7 @@ void the_game(
SharedPtr<Server> server;
if(address == ""){
draw_load_screen(L"Creating server...", driver, font);
dstream<<DTIME<<"Creating server"<<std::endl;
infostream<<"Creating server"<<std::endl;
server = new Server(map_dir, configpath);
server->start(port);
}
@ -716,7 +718,7 @@ void the_game(
*/
draw_load_screen(L"Creating client...", driver, font);
dstream<<DTIME<<"Creating client"<<std::endl;
infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control;
Client client(device, playername.c_str(), password, draw_control);
@ -731,7 +733,7 @@ void the_game(
}
catch(ResolveError &e)
{
dstream<<DTIME<<"Couldn't resolve address"<<std::endl;
errorstream<<"Couldn't resolve address"<<std::endl;
//return 0;
error_message = L"Couldn't resolve address";
//gui_loadingtext->remove();
@ -742,9 +744,9 @@ void the_game(
Attempt to connect to the server
*/
dstream<<DTIME<<"Connecting to server at ";
connect_address.print(&dstream);
dstream<<std::endl;
infostream<<"Connecting to server at ";
connect_address.print(&infostream);
infostream<<std::endl;
client.connect(connect_address);
bool could_connect = false;
@ -800,12 +802,12 @@ void the_game(
{
error_message = L"Access denied. Reason: "
+client.accessDeniedReason();
dstream<<DTIME<<wide_to_narrow(error_message)<<std::endl;
errorstream<<wide_to_narrow(error_message)<<std::endl;
}
else
{
error_message = L"Connection timed out.";
dstream<<DTIME<<"Timed out."<<std::endl;
errorstream<<"Timed out."<<std::endl;
}
//gui_loadingtext->remove();
return;
@ -963,7 +965,7 @@ void the_game(
{
error_message = L"Access denied. Reason: "
+client.accessDeniedReason();
dstream<<DTIME<<wide_to_narrow(error_message)<<std::endl;
errorstream<<wide_to_narrow(error_message)<<std::endl;
break;
}
@ -1029,7 +1031,7 @@ void the_game(
busytime = busytime_u32 / 1000.0;
}
//dstream<<"busytime_u32="<<busytime_u32<<std::endl;
//infostream<<"busytime_u32="<<busytime_u32<<std::endl;
// Necessary for device->getTimer()->getTime()
device->run();
@ -1068,6 +1070,8 @@ void the_game(
object_hit_delay_timer -= dtime;
g_profiler->add("Elapsed time", dtime * 1000);
/*
Log frametime for visualization
*/
@ -1082,8 +1086,8 @@ void the_game(
Visualize frametime in terminal
*/
/*for(u32 i=0; i<dtime*400; i++)
dstream<<"X";
dstream<<std::endl;*/
infostream<<"X";
infostream<<std::endl;*/
/*
Time average and jitter calculation
@ -1148,7 +1152,7 @@ void the_game(
if(counter < 0)
{
counter = 30.0;
client.printDebugInfo(dstream);
client.printDebugInfo(infostream);
}
}
@ -1161,8 +1165,8 @@ void the_game(
{
if(m_profiler_interval.step(0.030, profiler_print_interval))
{
dstream<<"Profiler:"<<std::endl;
g_profiler->print(dstream);
infostream<<"Profiler:"<<std::endl;
g_profiler->print(infostream);
g_profiler->clear();
}
}
@ -1185,7 +1189,7 @@ void the_game(
*/
if(input->wasKeyDown(getKeySetting("keymap_inventory")))
{
dstream<<DTIME<<"the_game: "
infostream<<"the_game: "
<<"Launching inventory"<<std::endl;
GUIInventoryMenu *menu =
@ -1211,7 +1215,7 @@ void the_game(
}
else if(input->wasKeyDown(EscapeKey))
{
dstream<<DTIME<<"the_game: "
infostream<<"the_game: "
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
@ -1280,16 +1284,16 @@ void the_game(
irr::video::IImage* const image = driver->createScreenShot();
if (image) {
irr::c8 filename[256];
snprintf(filename, 256, "%s/screenshot_%u.png",
snprintf(filename, 256, "%s" DIR_DELIM "screenshot_%u.png",
g_settings->get("screenshot_path").c_str(),
device->getTimer()->getRealTime());
if (driver->writeImageToFile(image, filename)) {
std::wstringstream sstr;
sstr<<"Saved screenshot to '"<<filename<<"'";
dstream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
chat_lines.push_back(ChatLine(sstr.str()));
} else{
dstream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
}
image->drop();
}
@ -1327,7 +1331,7 @@ void the_game(
{
g_selected_item = i;
dstream<<DTIME<<"Selected item: "
infostream<<"Selected item: "
<<g_selected_item<<std::endl;
}
}
@ -1339,12 +1343,12 @@ void the_game(
if(draw_control.range_all)
{
draw_control.range_all = false;
dstream<<DTIME<<"Disabled full viewing range"<<std::endl;
infostream<<"Disabled full viewing range"<<std::endl;
}
else
{
draw_control.range_all = true;
dstream<<DTIME<<"Enabled full viewing range"<<std::endl;
infostream<<"Enabled full viewing range"<<std::endl;
}
}
@ -1374,7 +1378,7 @@ void the_game(
}
if(first_loop_after_window_activation){
//dstream<<"window active, first loop"<<std::endl;
//infostream<<"window active, first loop"<<std::endl;
first_loop_after_window_activation = false;
}
else{
@ -1382,7 +1386,7 @@ void the_game(
s32 dy = input->getMousePos().Y - displaycenter.Y;
if(invert_mouse)
dy = -dy;
//dstream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
//infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;
/*const float keyspeed = 500;
if(input->isKeyDown(irr::KEY_UP))
@ -1406,7 +1410,7 @@ void the_game(
if(device->getCursorControl()->isVisible() == false)
device->getCursorControl()->setVisible(true);
//dstream<<"window inactive"<<std::endl;
//infostream<<"window inactive"<<std::endl;
first_loop_after_window_activation = true;
}
@ -1486,7 +1490,7 @@ void the_game(
else if(event.type == CE_PLAYER_DAMAGE)
{
//u16 damage = event.player_damage.amount;
//dstream<<"Player damage: "<<damage<<std::endl;
//infostream<<"Player damage: "<<damage<<std::endl;
damage_flash_timer = 0.05;
if(event.player_damage.amount >= 2){
damage_flash_timer += 0.05 * event.player_damage.amount;
@ -1575,7 +1579,7 @@ void the_game(
nodepos_old = v3s16(-32768,-32768,-32768);
}
//dstream<<"Client returned selected_active_object != NULL"<<std::endl;
//infostream<<"Client returned selected_active_object != NULL"<<std::endl;
core::aabbox3d<f32> *selection_box
= selected_active_object->getSelectionBox();
@ -1610,7 +1614,7 @@ void the_game(
do_punch = true;
}
if(do_punch){
dstream<<DTIME<<"Left-clicked object"<<std::endl;
infostream<<"Left-clicked object"<<std::endl;
left_punch = true;
}
if(do_punch_damage){
@ -1620,7 +1624,7 @@ void the_game(
}
else if(input->getRightClicked())
{
dstream<<DTIME<<"Right-clicked object"<<std::endl;
infostream<<"Right-clicked object"<<std::endl;
client.clickActiveObject(1,
selected_active_object->getId(), g_selected_item);
}
@ -1687,7 +1691,7 @@ void the_game(
{
if(nodepos != nodepos_old)
{
dstream<<DTIME<<"Pointing at ("<<nodepos.X<<","
infostream<<"Pointing at ("<<nodepos.X<<","
<<nodepos.Y<<","<<nodepos.Z<<")"<<std::endl;
if(nodepos_old != v3s16(-32768,-32768,-32768))
@ -1701,7 +1705,7 @@ void the_game(
if(input->getLeftClicked() ||
(input->getLeftState() && nodepos != nodepos_old))
{
dstream<<DTIME<<"Started digging"<<std::endl;
infostream<<"Started digging"<<std::endl;
client.groundAction(0, nodepos, neighbourpos, g_selected_item);
}
if(input->getLeftClicked())
@ -1734,7 +1738,7 @@ void the_game(
if(prop.diggable == false)
{
/*dstream<<"Material "<<(int)material
/*infostream<<"Material "<<(int)material
<<" not diggable with \""
<<toolname<<"\""<<std::endl;*/
// I guess nobody will wait for this long
@ -1759,12 +1763,12 @@ void the_game(
if(dig_index < CRACK_ANIMATION_LENGTH)
{
//TimeTaker timer("client.setTempMod");
//dstream<<"dig_index="<<dig_index<<std::endl;
//infostream<<"dig_index="<<dig_index<<std::endl;
client.setTempMod(nodepos, NodeMod(NODEMOD_CRACK, dig_index));
}
else
{
dstream<<DTIME<<"Digging completed"<<std::endl;
infostream<<"Digging completed"<<std::endl;
client.groundAction(3, nodepos, neighbourpos, g_selected_item);
client.clearTempMod(nodepos);
client.removeNode(nodepos);
@ -1798,12 +1802,12 @@ void the_game(
if(input->getRightClicked())
{
dstream<<DTIME<<"Ground right-clicked"<<std::endl;
infostream<<"Ground right-clicked"<<std::endl;
// If metadata provides an inventory view, activate it
if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
{
dstream<<DTIME<<"Launching custom inventory view"<<std::endl;
infostream<<"Launching custom inventory view"<<std::endl;
/*
Construct the unique identification string of the node
*/
@ -1836,7 +1840,7 @@ void the_game(
}
else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input)
{
dstream<<"Sign node right-clicked"<<std::endl;
infostream<<"Sign node right-clicked"<<std::endl;
SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
@ -1873,13 +1877,13 @@ void the_game(
if(input->getLeftReleased())
{
dstream<<DTIME<<"Left button released (stopped digging)"
infostream<<"Left button released (stopped digging)"
<<std::endl;
client.groundAction(2, v3s16(0,0,0), v3s16(0,0,0), 0);
}
if(input->getRightReleased())
{
//dstream<<DTIME<<"Right released"<<std::endl;
//inostream<<DTIME<<"Right released"<<std::endl;
// Nothing here
}
@ -2124,7 +2128,7 @@ void the_game(
{
client.selectPlayerItem(g_selected_item);
old_selected_item = g_selected_item;
//dstream<<"Updating local inventory"<<std::endl;
//infostream<<"Updating local inventory"<<std::endl;
client.getLocalInventory(local_inventory);
// Update wielded tool
@ -2163,7 +2167,7 @@ void the_game(
//timer3.stop();
//dstream<<DTIME<<"smgr->drawAll()"<<std::endl;
//infostream<<"smgr->drawAll()"<<std::endl;
{
TimeTaker timer("smgr");
@ -2189,7 +2193,7 @@ void the_game(
for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
i != hilightboxes.end(); i++)
{
/*dstream<<"hilightbox min="
/*infostream<<"hilightbox min="
<<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
<<" max="
<<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"

144
src/log.cpp Normal file
View File

@ -0,0 +1,144 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "log.h"
#include <map>
#include <list>
#include <sstream>
#include "threads.h"
#include "debug.h"
#include "gettime.h"
std::list<ILogOutput*> log_outputs[LMT_NUM_VALUES];
std::map<threadid_t, std::string> log_threadnames;
void log_add_output(ILogOutput *out, enum LogMessageLevel lev)
{
log_outputs[lev].push_back(out);
}
void log_add_output_maxlev(ILogOutput *out, enum LogMessageLevel lev)
{
for(int i=0; i<=lev; i++)
log_outputs[i].push_back(out);
}
void log_add_output_all_levs(ILogOutput *out)
{
for(int i=0; i<LMT_NUM_VALUES; i++)
log_outputs[i].push_back(out);
}
void log_register_thread(const std::string &name)
{
threadid_t id = get_current_thread_id();
log_threadnames[id] = name;
}
static std::string get_lev_string(enum LogMessageLevel lev)
{
switch(lev){
case LMT_ERROR:
return "ERROR";
case LMT_ACTION:
return "ACTION";
case LMT_INFO:
return "INFO";
case LMT_VERBOSE:
return "VERBOSE";
case LMT_NUM_VALUES:
break;
}
return "(unknown level)";
}
void log_printline(enum LogMessageLevel lev, const std::string &text)
{
std::string threadname = "(unknown thread)";
std::map<threadid_t, std::string>::const_iterator i;
i = log_threadnames.find(get_current_thread_id());
if(i != log_threadnames.end())
threadname = i->second;
std::string levelname = get_lev_string(lev);
std::ostringstream os(std::ios_base::binary);
os<<getTimestamp()<<": "<<levelname<<"["<<threadname<<"]: "<<text;
for(std::list<ILogOutput*>::iterator i = log_outputs[lev].begin();
i != log_outputs[lev].end(); i++){
ILogOutput *out = *i;
out->printLog(os.str());
out->printLog(lev, text);
}
}
class Logbuf : public std::streambuf
{
public:
Logbuf(enum LogMessageLevel lev):
m_lev(lev)
{
}
~Logbuf()
{
}
int overflow(int c)
{
bufchar(c);
return c;
}
std::streamsize xsputn(const char *s, std::streamsize n)
{
for(int i=0; i<n; i++)
bufchar(s[i]);
return n;
}
void printbuf()
{
log_printline(m_lev, m_buf);
}
void bufchar(char c)
{
if(c == '\n' || c == '\r'){
if(m_buf != "")
printbuf();
m_buf = "";
return;
}
m_buf += c;
}
private:
enum LogMessageLevel m_lev;
std::string m_buf;
};
Logbuf errorbuf(LMT_ERROR);
Logbuf actionbuf(LMT_ACTION);
Logbuf infobuf(LMT_INFO);
Logbuf verbosebuf(LMT_VERBOSE);
std::ostream errorstream(&errorbuf);
std::ostream actionstream(&actionbuf);
std::ostream infostream(&infobuf);
std::ostream verbosestream(&verbosebuf);

69
src/log.h Normal file
View File

@ -0,0 +1,69 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef LOG_HEADER
#define LOG_HEADER
#include <string>
/*
Use this for logging everything.
If you need to explicitly print something, use dstream or cout or cerr.
*/
enum LogMessageLevel {
LMT_ERROR, /* Something failed ("invalid map data on disk, block (2,2,1)") */
LMT_ACTION, /* In-game actions ("celeron55 placed block at (12,4,-5)") */
LMT_INFO, /* More deep info ("saving map on disk (only_modified=true)") */
LMT_VERBOSE, /* Flood-style ("loaded block (2,2,2) from disk") */
LMT_NUM_VALUES,
};
class ILogOutput
{
public:
/* line: Full line with timestamp, level and thread */
virtual void printLog(const std::string &line){};
/* line: Only actual printed text */
virtual void printLog(enum LogMessageLevel lev, const std::string &line){};
};
void log_add_output(ILogOutput *out, enum LogMessageLevel lev);
void log_add_output_maxlev(ILogOutput *out, enum LogMessageLevel lev);
void log_add_output_all_levs(ILogOutput *out);
void log_register_thread(const std::string &name);
void log_printline(enum LogMessageLevel lev, const std::string &text);
#define LOGLINEF(lev, ...)\
{\
char buf[10000];\
snprintf(buf, 10000, __VA_ARGS__);\
log_printline(lev, buf);\
}
extern std::ostream errorstream;
extern std::ostream actionstream;
extern std::ostream infostream;
extern std::ostream verbosestream;
#endif

View File

@ -438,6 +438,7 @@ Doing currently:
#include "gettext.h"
#include "settings.h"
#include "profiler.h"
#include "log.h"
// This makes textures
ITextureSource *g_texturesource = NULL;
@ -479,19 +480,15 @@ MainGameCallback *g_gamecallback = NULL;
// Connection
std::ostream *dout_con_ptr = &dummyout;
std::ostream *derr_con_ptr = &dstream_no_stderr;
//std::ostream *dout_con_ptr = &dstream_no_stderr;
//std::ostream *derr_con_ptr = &dstream_no_stderr;
//std::ostream *dout_con_ptr = &dstream;
//std::ostream *derr_con_ptr = &dstream;
std::ostream *derr_con_ptr = &verbosestream;
// Server
std::ostream *dout_server_ptr = &dstream;
std::ostream *derr_server_ptr = &dstream;
std::ostream *dout_server_ptr = &infostream;
std::ostream *derr_server_ptr = &errorstream;
// Client
std::ostream *dout_client_ptr = &dstream;
std::ostream *derr_client_ptr = &dstream;
std::ostream *dout_client_ptr = &infostream;
std::ostream *derr_client_ptr = &errorstream;
/*
gettime.h implementation
@ -583,7 +580,6 @@ public:
}
else
{
//dstream<<"MyEventReceiver: mouse input"<<std::endl;
left_active = event.MouseInput.isLeftPressed();
middle_active = event.MouseInput.isMiddlePressed();
right_active = event.MouseInput.isRightPressed();
@ -1026,7 +1022,7 @@ void SpeedTests()
u32 dtime = timer.stop();
u32 per_ms = n / dtime;
std::cout<<"Done. "<<dtime<<"ms, "
dstream<<"Done. "<<dtime<<"ms, "
<<per_ms<<"/ms"<<std::endl;
}
}
@ -1078,12 +1074,37 @@ void drawMenuBackground(video::IVideoDriver* driver)
}
}
class DstreamLogOutput: public ILogOutput
{
public:
/* line: Full line with timestamp, level and thread */
void printLog(const std::string &line)
{
dstream<<line<<std::endl;
}
} main_dstream_log_out;
class DstreamNoStderrLogOutput: public ILogOutput
{
public:
/* line: Full line with timestamp, level and thread */
void printLog(const std::string &line)
{
dstream_no_stderr<<line<<std::endl;
}
} main_dstream_no_stderr_log_out;
int main(int argc, char *argv[])
{
/*
Initialization
*/
log_add_output_maxlev(&main_dstream_log_out, LMT_ACTION);
log_add_output_all_levs(&main_dstream_no_stderr_log_out);
log_register_thread("main");
// Set locale. This is for forcing '.' as the decimal point.
std::locale::global(std::locale("C"));
// This enables printing all characters in bitmap font
@ -1110,6 +1131,7 @@ int main(int argc, char *argv[])
allowed_options.insert("dstream-on-stderr", ValueSpec(VALUETYPE_FLAG));
#endif
allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("info-on-stderr", ValueSpec(VALUETYPE_FLAG));
Settings cmd_args;
@ -1151,6 +1173,9 @@ int main(int argc, char *argv[])
if(cmd_args.getFlag("dstream-on-stderr") == false)
disable_stderr = true;
#endif
if(cmd_args.getFlag("info-on-stderr"))
log_add_output(&main_dstream_log_out, LMT_INFO);
porting::signal_handler_init();
bool &kill = *porting::signal_handler_killstatus();
@ -1161,13 +1186,13 @@ int main(int argc, char *argv[])
// Create user data directory
fs::CreateDir(porting::path_userdata);
init_gettext((porting::path_data+"/../locale").c_str());
init_gettext((porting::path_data+DIR_DELIM+".."+DIR_DELIM+"locale").c_str());
// Initialize debug streams
#ifdef RUN_IN_PLACE
std::string debugfile = DEBUGFILE;
#else
std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE;
#endif
debugstreams_init(disable_stderr, debugfile.c_str());
// Initialize debug stacks
@ -1182,7 +1207,7 @@ int main(int argc, char *argv[])
BEGIN_DEBUG_EXCEPTION_HANDLER
// Print startup message
dstream<<DTIME<<PROJECT_NAME
actionstream<<PROJECT_NAME<<
" with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
<<", "<<BUILD_INFO
<<std::endl;
@ -1210,7 +1235,7 @@ int main(int argc, char *argv[])
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
if(r == false)
{
dstream<<"Could not read configuration from \""
errorstream<<"Could not read configuration from \""
<<cmd_args.get("config")<<"\""<<std::endl;
return 1;
}
@ -1219,9 +1244,11 @@ int main(int argc, char *argv[])
else
{
core::array<std::string> filenames;
filenames.push_back(porting::path_userdata + "/minetest.conf");
filenames.push_back(porting::path_userdata +
DIR_DELIM + "minetest.conf");
#ifdef RUN_IN_PLACE
filenames.push_back(porting::path_userdata + "/../minetest.conf");
filenames.push_back(porting::path_userdata +
DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
#endif
for(u32 i=0; i<filenames.size(); i++)
@ -1283,7 +1310,7 @@ int main(int argc, char *argv[])
port = 30000;
// Map directory
std::string map_dir = porting::path_userdata+"/world";
std::string map_dir = porting::path_userdata+DIR_DELIM+"world";
if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir");
else if(g_settings->exists("map-dir"))
@ -1356,7 +1383,7 @@ int main(int argc, char *argv[])
driverType = video::EDT_OPENGL;
else
{
dstream<<"WARNING: Invalid video_driver specified; defaulting "
errorstream<<"WARNING: Invalid video_driver specified; defaulting "
"to opengl"<<std::endl;
driverType = video::EDT_OPENGL;
}
@ -1427,14 +1454,14 @@ int main(int argc, char *argv[])
if(font)
skin->setFont(font);
else
dstream<<"WARNING: Font file was not found."
errorstream<<"WARNING: Font file was not found."
" Using default font."<<std::endl;
// If font was not found, this will get us one
font = skin->getFont();
assert(font);
u32 text_height = font->getDimension(L"Hello, world!").Height;
dstream<<"text_height="<<text_height<<std::endl;
infostream<<"text_height="<<text_height<<std::endl;
//skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
@ -1522,7 +1549,7 @@ int main(int argc, char *argv[])
if(error_message != L"")
{
dstream<<"WARNING: error_message = "
errorstream<<"error_message = "
<<wide_to_narrow(error_message)<<std::endl;
GUIMessageMenu *menu2 =
@ -1534,7 +1561,7 @@ int main(int argc, char *argv[])
video::IVideoDriver* driver = device->getVideoDriver();
dstream<<"Created main menu"<<std::endl;
infostream<<"Created main menu"<<std::endl;
while(device->run() && kill == false)
{
@ -1559,7 +1586,7 @@ int main(int argc, char *argv[])
if(device->run() == false || kill == true)
break;
dstream<<"Dropping main menu"<<std::endl;
infostream<<"Dropping main menu"<<std::endl;
menu->drop();
@ -1576,7 +1603,7 @@ int main(int argc, char *argv[])
password = translatePassword(playername, menudata.password);
//dstream<<"Main: password hash: '"<<password<<"'"<<std::endl;
//infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
address = wide_to_narrow(menudata.address);
int newport = stoi(wide_to_narrow(menudata.port));
@ -1643,12 +1670,12 @@ int main(int argc, char *argv[])
} //try
catch(con::PeerNotFoundException &e)
{
dstream<<DTIME<<"Connection error (timed out?)"<<std::endl;
errorstream<<"Connection error (timed out?)"<<std::endl;
error_message = L"Connection error (timed out?)";
}
catch(SocketException &e)
{
dstream<<DTIME<<"Socket error (port already in use?)"<<std::endl;
errorstream<<"Socket error (port already in use?)"<<std::endl;
error_message = L"Socket error (port already in use?)";
}
#ifdef NDEBUG
@ -1657,7 +1684,7 @@ int main(int argc, char *argv[])
std::string narrow_message = "Some exception, what()=\"";
narrow_message += e.what();
narrow_message += "\"";
dstream<<DTIME<<narrow_message<<std::endl;
errorstream<<narrow_message<<std::endl;
error_message = narrow_to_wide(narrow_message);
}
#endif
@ -1671,7 +1698,7 @@ int main(int argc, char *argv[])
*/
device->drop();
END_DEBUG_EXCEPTION_HANDLER
END_DEBUG_EXCEPTION_HANDLER(errorstream)
debugstreams_deinit();

View File

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IMaterialRenderer.h>
#endif
#include "settings.h"
#include "log.h"
/*
SQLite format specification:
@ -346,7 +347,7 @@ void Map::unspreadLight(enum LightBank bank,
*/
/*if(light_sources.find(n2pos))
{
std::cout<<"Removed from light_sources"<<std::endl;
infostream<<"Removed from light_sources"<<std::endl;
light_sources.remove(n2pos);
}*/
}
@ -377,7 +378,7 @@ void Map::unspreadLight(enum LightBank bank,
}
}
/*dstream<<"unspreadLight(): Changed block "
/*infostream<<"unspreadLight(): Changed block "
<<blockchangecount<<" times"
<<" for "<<from_nodes.size()<<" nodes"
<<std::endl;*/
@ -439,7 +440,7 @@ void Map::spreadLight(enum LightBank bank,
{
v3s16 pos = j.getNode()->getKey();
//v3s16 pos = *j;
//dstream<<"pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"<<std::endl;
//infostream<<"pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"<<std::endl;
v3s16 blockpos = getNodeBlockPos(pos);
// Only fetch a new block if the block position has changed
@ -544,7 +545,7 @@ void Map::spreadLight(enum LightBank bank,
}
}
/*dstream<<"spreadLight(): Changed block "
/*infostream<<"spreadLight(): Changed block "
<<blockchangecount<<" times"
<<" for "<<from_nodes.size()<<" nodes"
<<std::endl;*/
@ -728,7 +729,7 @@ void Map::updateLighting(enum LightBank bank,
dummy block.
*/
//assert(0);
dstream<<"updateLighting(): InvalidPositionException"
infostream<<"updateLighting(): InvalidPositionException"
<<std::endl;
}
}
@ -752,7 +753,7 @@ void Map::updateLighting(enum LightBank bank,
assert(0);
}
/*dstream<<"Bottom for sunlight-propagated block ("
/*infostream<<"Bottom for sunlight-propagated block ("
<<pos.X<<","<<pos.Y<<","<<pos.Z<<") not valid"
<<std::endl;*/
@ -799,7 +800,7 @@ void Map::updateLighting(enum LightBank bank,
{
u32 diff = modified_blocks.size() - count_was;
count_was = modified_blocks.size();
dstream<<"unspreadLight modified "<<diff<<std::endl;
infostream<<"unspreadLight modified "<<diff<<std::endl;
}
{
@ -811,7 +812,7 @@ void Map::updateLighting(enum LightBank bank,
{
u32 diff = modified_blocks.size() - count_was;
count_was = modified_blocks.size();
dstream<<"spreadLight modified "<<diff<<std::endl;
infostream<<"spreadLight modified "<<diff<<std::endl;
}
#endif
@ -867,7 +868,7 @@ void Map::updateLighting(enum LightBank bank,
//TimeTaker timer("blitBack");
vmanip.blitBack(modified_blocks);
}
/*dstream<<"emerge_time="<<emerge_time<<std::endl;
/*infostream<<"emerge_time="<<emerge_time<<std::endl;
emerge_time = 0;*/
}
@ -1471,12 +1472,12 @@ void Map::timerUpdate(float dtime, float unload_timeout,
if(deleted_blocks_count != 0)
{
PrintInfo(dstream); // ServerMap/ClientMap:
dstream<<"Unloaded "<<deleted_blocks_count
PrintInfo(infostream); // ServerMap/ClientMap:
infostream<<"Unloaded "<<deleted_blocks_count
<<" blocks from memory";
if(save_before_unloading)
dstream<<", of which "<<saved_blocks_count<<" were written";
dstream<<"."<<std::endl;
infostream<<", of which "<<saved_blocks_count<<" were written";
infostream<<"."<<std::endl;
}
}
@ -1543,7 +1544,7 @@ void Map::unloadUnusedData(float timeout,
deleteSectors(sector_deletion_queue);
dstream<<"Map: Unloaded "<<deleted_blocks_count<<" blocks from memory"
infostream<<"Map: Unloaded "<<deleted_blocks_count<<" blocks from memory"
<<", of which "<<saved_blocks_count<<" were wr."
<<std::endl;
@ -1579,7 +1580,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
u32 initial_size = m_transforming_liquid.size();
/*if(initial_size != 0)
dstream<<"transformLiquids(): initial_size="<<initial_size<<std::endl;*/
infostream<<"transformLiquids(): initial_size="<<initial_size<<std::endl;*/
// list of nodes that due to viscosity have not reached their max level height
UniqueQueue<v3s16> must_reflow;
@ -1807,7 +1808,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
break;
}
}
//dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
while (must_reflow.size() > 0)
m_transforming_liquid.push_back(must_reflow.pop_front());
updateLighting(lighting_modified_blocks, modified_blocks);
@ -1820,7 +1821,7 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p)
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
{
dstream<<"WARNING: Map::setNodeMetadata(): Block not found"
infostream<<"WARNING: Map::setNodeMetadata(): Block not found"
<<std::endl;
return NULL;
}
@ -1835,7 +1836,7 @@ void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
{
dstream<<"WARNING: Map::setNodeMetadata(): Block not found"
infostream<<"WARNING: Map::setNodeMetadata(): Block not found"
<<std::endl;
return;
}
@ -1849,7 +1850,7 @@ void Map::removeNodeMetadata(v3s16 p)
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
{
dstream<<"WARNING: Map::removeNodeMetadata(): Block not found"
infostream<<"WARNING: Map::removeNodeMetadata(): Block not found"
<<std::endl;
return;
}
@ -1897,7 +1898,7 @@ ServerMap::ServerMap(std::string savedir):
m_database_read(NULL),
m_database_write(NULL)
{
dstream<<__FUNCTION_NAME<<std::endl;
infostream<<__FUNCTION_NAME<<std::endl;
//m_chunksize = 8; // Takes a few seconds
@ -1935,7 +1936,7 @@ ServerMap::ServerMap(std::string savedir):
// If directory is empty, it is safe to save into it.
if(fs::GetDirListing(m_savedir).size() == 0)
{
dstream<<DTIME<<"Server: Empty save directory is valid."
infostream<<"Server: Empty save directory is valid."
<<std::endl;
m_map_saving_enabled = true;
}
@ -1946,7 +1947,7 @@ ServerMap::ServerMap(std::string savedir):
loadMapMeta();
}
catch(FileNotGoodException &e){
dstream<<DTIME<<"WARNING: Could not load map metadata"
infostream<<"WARNING: Could not load map metadata"
//<<" Disabling chunk-based generator."
<<std::endl;
//m_chunksize = 0;
@ -1957,18 +1958,18 @@ ServerMap::ServerMap(std::string savedir):
loadChunkMeta();
}
catch(FileNotGoodException &e){
dstream<<DTIME<<"WARNING: Could not load chunk metadata."
infostream<<"WARNING: Could not load chunk metadata."
<<" Disabling chunk-based generator."
<<std::endl;
m_chunksize = 0;
}*/
/*dstream<<DTIME<<"Server: Successfully loaded chunk "
/*infostream<<"Server: Successfully loaded chunk "
"metadata and sector (0,0) from "<<savedir<<
", assuming valid save directory."
<<std::endl;*/
dstream<<DTIME<<"INFO: Server: Successfully loaded map "
infostream<<"Server: Successfully loaded map "
<<"and chunk metadata from "<<savedir
<<", assuming valid save directory."
<<std::endl;
@ -1985,13 +1986,13 @@ ServerMap::ServerMap(std::string savedir):
}
catch(std::exception &e)
{
dstream<<DTIME<<"WARNING: Server: Failed to load map from "<<savedir
infostream<<"WARNING: Server: Failed to load map from "<<savedir
<<", exception: "<<e.what()<<std::endl;
dstream<<"Please remove the map or fix it."<<std::endl;
dstream<<"WARNING: Map saving will be disabled."<<std::endl;
infostream<<"Please remove the map or fix it."<<std::endl;
infostream<<"WARNING: Map saving will be disabled."<<std::endl;
}
dstream<<DTIME<<"INFO: Initializing new map."<<std::endl;
infostream<<"Initializing new map."<<std::endl;
// Create zero sector
emergeSector(v2s16(0,0));
@ -2002,7 +2003,7 @@ ServerMap::ServerMap(std::string savedir):
ServerMap::~ServerMap()
{
dstream<<__FUNCTION_NAME<<std::endl;
infostream<<__FUNCTION_NAME<<std::endl;
try
{
@ -2010,16 +2011,16 @@ ServerMap::~ServerMap()
{
// Save only changed parts
save(true);
dstream<<DTIME<<"Server: saved map to "<<m_savedir<<std::endl;
infostream<<"Server: saved map to "<<m_savedir<<std::endl;
}
else
{
dstream<<DTIME<<"Server: map not saved"<<std::endl;
infostream<<"Server: map not saved"<<std::endl;
}
}
catch(std::exception &e)
{
dstream<<DTIME<<"Server: Failed to save map to "<<m_savedir
infostream<<"Server: Failed to save map to "<<m_savedir
<<", exception: "<<e.what()<<std::endl;
}
@ -2050,7 +2051,7 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
{
bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
if(enable_mapgen_debug_info)
dstream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
infostream<<"initBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
<<blockpos.Z<<")"<<std::endl;
// Do nothing if not inside limits (+-1 because of neighbors)
@ -2134,19 +2135,19 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
core::map<v3s16, MapBlock*> &changed_blocks)
{
v3s16 blockpos = data->blockpos;
/*dstream<<"finishBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
/*infostream<<"finishBlockMake(): ("<<blockpos.X<<","<<blockpos.Y<<","
<<blockpos.Z<<")"<<std::endl;*/
if(data->no_op)
{
//dstream<<"finishBlockMake(): no-op"<<std::endl;
//infostream<<"finishBlockMake(): no-op"<<std::endl;
return NULL;
}
bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
/*dstream<<"Resulting vmanip:"<<std::endl;
data->vmanip.print(dstream);*/
/*infostream<<"Resulting vmanip:"<<std::endl;
data->vmanip.print(infostream);*/
/*
Blit generated stuff to map
@ -2159,7 +2160,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
}
if(enable_mapgen_debug_info)
dstream<<"finishBlockMake: changed_blocks.size()="
infostream<<"finishBlockMake: changed_blocks.size()="
<<changed_blocks.size()<<std::endl;
/*
@ -2300,7 +2301,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
*/
//save(true);
/*dstream<<"finishBlockMake() done for ("<<blockpos.X<<","<<blockpos.Y<<","
/*infostream<<"finishBlockMake() done for ("<<blockpos.X<<","<<blockpos.Y<<","
<<blockpos.Z<<")"<<std::endl;*/
#if 0
if(enable_mapgen_debug_info)
@ -2316,7 +2317,7 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
MapBlock *block = getBlockNoCreateNoEx(p);
char spos[20];
snprintf(spos, 20, "(%2d,%2d,%2d)", x, y, z);
dstream<<"Generated "<<spos<<": "
infostream<<"Generated "<<spos<<": "
<<analyze_block(block)<<std::endl;
}
}
@ -2352,7 +2353,7 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d)
ServerMapSector *sector = (ServerMapSector*)getSectorNoGenerateNoEx(p2d);
if(sector == NULL)
{
dstream<<"ServerMap::createSector(): loadSectorFull didn't make a sector"<<std::endl;
infostream<<"ServerMap::createSector(): loadSectorFull didn't make a sector"<<std::endl;
throw InvalidPositionException("");
}
return sector;
@ -2394,7 +2395,7 @@ MapBlock * ServerMap::generateBlock(
{
DSTACKF("%s: p=(%d,%d,%d)", __FUNCTION_NAME, p.X, p.Y, p.Z);
/*dstream<<"generateBlock(): "
/*infostream<<"generateBlock(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;*/
@ -2412,7 +2413,7 @@ MapBlock * ServerMap::generateBlock(
*/
if(blockpos_over_limit(p))
{
dstream<<__FUNCTION_NAME<<": Block position over limit"<<std::endl;
infostream<<__FUNCTION_NAME<<": Block position over limit"<<std::endl;
throw InvalidPositionException("generateBlock(): pos. over limit");
}
@ -2458,7 +2459,7 @@ MapBlock * ServerMap::generateBlock(
MapNode n = block->getNode(p);
if(n.getContent() == CONTENT_IGNORE)
{
dstream<<"CONTENT_IGNORE at "
infostream<<"CONTENT_IGNORE at "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;
erroneus_content = true;
@ -2532,7 +2533,7 @@ MapBlock * ServerMap::createBlock(v3s16 p)
}
catch(InvalidPositionException &e)
{
dstream<<"createBlock: createSector() failed"<<std::endl;
infostream<<"createBlock: createSector() failed"<<std::endl;
throw e;
}
/*
@ -2542,7 +2543,7 @@ MapBlock * ServerMap::createBlock(v3s16 p)
*/
/*catch(std::exception &e)
{
dstream<<"createBlock: createSector() failed: "
infostream<<"createBlock: createSector() failed: "
<<e.what()<<std::endl;
throw e;
}*/
@ -2634,18 +2635,18 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
}
catch(InvalidPositionException &e)
{
dstream<<"emergeBlock: createSector() failed: "
infostream<<"emergeBlock: createSector() failed: "
<<e.what()<<std::endl;
dstream<<"Path to failed sector: "<<getSectorDir(p2d)
infostream<<"Path to failed sector: "<<getSectorDir(p2d)
<<std::endl
<<"You could try to delete it."<<std::endl;
throw e;
}
catch(VersionMismatchException &e)
{
dstream<<"emergeBlock: createSector() failed: "
infostream<<"emergeBlock: createSector() failed: "
<<e.what()<<std::endl;
dstream<<"Path to failed sector: "<<getSectorDir(p2d)
infostream<<"Path to failed sector: "<<getSectorDir(p2d)
<<std::endl
<<"You could try to delete it."<<std::endl;
throw e;
@ -2681,7 +2682,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
else
{
// Valid block
//dstream<<"emergeBlock(): Returning already valid block"<<std::endl;
//infostream<<"emergeBlock(): Returning already valid block"<<std::endl;
return block;
}
@ -2691,7 +2692,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
*/
if(only_from_disk && (does_not_exist || lighting_expired))
{
//dstream<<"emergeBlock(): Was not on disk but not generating"<<std::endl;
//infostream<<"emergeBlock(): Was not on disk but not generating"<<std::endl;
if(block == NULL)
{
@ -2705,11 +2706,11 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
return block;
}
//dstream<<"Not found on disk, generating."<<std::endl;
//infostream<<"Not found on disk, generating."<<std::endl;
// 0ms
//TimeTaker("emergeBlock() generate");
//dstream<<"emergeBlock(): Didn't find valid block -> making one"<<std::endl;
//infostream<<"emergeBlock(): Didn't find valid block -> making one"<<std::endl;
/*
If the block doesn't exist, generate the block.
@ -2811,7 +2812,7 @@ void ServerMap::createDatabase() {
if(e == SQLITE_ABORT)
throw FileNotGoodException("Could not create database structure");
else
dstream<<"Server: Database structure was created";
infostream<<"Server: Database structure was created";
}
void ServerMap::verifyDatabase() {
@ -2819,7 +2820,7 @@ void ServerMap::verifyDatabase() {
return;
{
std::string dbp = m_savedir + "/map.sqlite";
std::string dbp = m_savedir + DIR_DELIM + "map.sqlite";
bool needs_create = false;
int d;
@ -2834,7 +2835,7 @@ void ServerMap::verifyDatabase() {
d = sqlite3_open_v2(dbp.c_str(), &m_database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if(d != SQLITE_OK) {
dstream<<"WARNING: Database failed to open: "<<sqlite3_errmsg(m_database)<<std::endl;
infostream<<"WARNING: Database failed to open: "<<sqlite3_errmsg(m_database)<<std::endl;
throw FileNotGoodException("Cannot open database file");
}
@ -2843,22 +2844,22 @@ void ServerMap::verifyDatabase() {
d = sqlite3_prepare(m_database, "SELECT `data` FROM `blocks` WHERE `pos`=? LIMIT 1", -1, &m_database_read, NULL);
if(d != SQLITE_OK) {
dstream<<"WARNING: Database read statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
infostream<<"WARNING: Database read statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
throw FileNotGoodException("Cannot prepare read statement");
}
d = sqlite3_prepare(m_database, "REPLACE INTO `blocks` VALUES(?, ?)", -1, &m_database_write, NULL);
if(d != SQLITE_OK) {
dstream<<"WARNING: Database write statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
infostream<<"WARNING: Database write statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
throw FileNotGoodException("Cannot prepare write statement");
}
dstream<<"Server: Database opened"<<std::endl;
infostream<<"Server: Database opened"<<std::endl;
}
}
bool ServerMap::loadFromFolders() {
if(!m_database && !fs::PathExists(m_savedir + "/map.sqlite"))
if(!m_database && !fs::PathExists(m_savedir + DIR_DELIM + "map.sqlite"))
return true;
return false;
}
@ -2888,13 +2889,13 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout)
(unsigned int)pos.X&0xffff,
(unsigned int)pos.Y&0xffff);
return m_savedir + "/sectors/" + cc;
return m_savedir + DIR_DELIM + "sectors" + DIR_DELIM + cc;
case 2:
snprintf(cc, 9, "%.3x/%.3x",
snprintf(cc, 9, "%.3x" DIR_DELIM "%.3x",
(unsigned int)pos.X&0xfff,
(unsigned int)pos.Y&0xfff);
return m_savedir + "/sectors2/" + cc;
return m_savedir + DIR_DELIM + "sectors2" + DIR_DELIM + cc;
default:
assert(false);
}
@ -2904,7 +2905,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
{
unsigned int x, y;
int r;
size_t spos = dirname.rfind('/') + 1;
size_t spos = dirname.rfind(DIR_DELIM_C) + 1;
assert(spos != std::string::npos);
if(dirname.size() - spos == 8)
{
@ -2914,7 +2915,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
else if(dirname.size() - spos == 3)
{
// New layout
r = sscanf(dirname.substr(spos-4).c_str(), "%3x/%3x", &x, &y);
r = sscanf(dirname.substr(spos-4).c_str(), "%3x" DIR_DELIM "%3x", &x, &y);
// Sign-extend the 12 bit values up to 16 bits...
if(x&0x800) x|=0xF000;
if(y&0x800) y|=0xF000;
@ -2954,12 +2955,12 @@ void ServerMap::save(bool only_changed)
DSTACK(__FUNCTION_NAME);
if(m_map_saving_enabled == false)
{
dstream<<DTIME<<"WARNING: Not saving map, saving disabled."<<std::endl;
infostream<<"WARNING: Not saving map, saving disabled."<<std::endl;
return;
}
if(only_changed == false)
dstream<<DTIME<<"ServerMap: Saving whole map, this can take time."
infostream<<"ServerMap: Saving whole map, this can take time."
<<std::endl;
if(only_changed == false || m_map_metadata_changed)
@ -3000,7 +3001,7 @@ void ServerMap::save(bool only_changed)
saveBlock(block);
block_count++;
/*dstream<<"ServerMap: Written block ("
/*infostream<<"ServerMap: Written block ("
<<block->getPos().X<<","
<<block->getPos().Y<<","
<<block->getPos().Z<<")"
@ -3017,7 +3018,7 @@ void ServerMap::save(bool only_changed)
if(only_changed == false || sector_meta_count != 0
|| block_count != 0)
{
dstream<<DTIME<<"ServerMap: Written: "
infostream<<"ServerMap: Written: "
<<sector_meta_count<<" sector metadata files, "
<<block_count<<" block files"
<<", "<<block_count_all<<" blocks in memory."
@ -3029,17 +3030,17 @@ void ServerMap::saveMapMeta()
{
DSTACK(__FUNCTION_NAME);
dstream<<"INFO: ServerMap::saveMapMeta(): "
infostream<<"ServerMap::saveMapMeta(): "
<<"seed="<<m_seed
<<std::endl;
createDirs(m_savedir);
std::string fullpath = m_savedir + "/map_meta.txt";
std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
std::ofstream os(fullpath.c_str(), std::ios_base::binary);
if(os.good() == false)
{
dstream<<"ERROR: ServerMap::saveMapMeta(): "
infostream<<"ERROR: ServerMap::saveMapMeta(): "
<<"could not open"<<fullpath<<std::endl;
throw FileNotGoodException("Cannot open chunk metadata");
}
@ -3058,14 +3059,14 @@ void ServerMap::loadMapMeta()
{
DSTACK(__FUNCTION_NAME);
dstream<<"INFO: ServerMap::loadMapMeta(): Loading map metadata"
infostream<<"ServerMap::loadMapMeta(): Loading map metadata"
<<std::endl;
std::string fullpath = m_savedir + "/map_meta.txt";
std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
{
dstream<<"ERROR: ServerMap::loadMapMeta(): "
infostream<<"ERROR: ServerMap::loadMapMeta(): "
<<"could not open"<<fullpath<<std::endl;
throw FileNotGoodException("Cannot open map metadata");
}
@ -3087,9 +3088,7 @@ void ServerMap::loadMapMeta()
m_seed = params.getU64("seed");
dstream<<"INFO: ServerMap::loadMapMeta(): "
<<"seed="<<m_seed
<<std::endl;
infostream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
}
void ServerMap::saveSectorMeta(ServerMapSector *sector)
@ -3102,7 +3101,7 @@ void ServerMap::saveSectorMeta(ServerMapSector *sector)
std::string dir = getSectorDir(pos);
createDirs(dir);
std::string fullpath = dir + "/meta";
std::string fullpath = dir + DIR_DELIM + "meta";
std::ofstream o(fullpath.c_str(), std::ios_base::binary);
if(o.good() == false)
throw FileNotGoodException("Cannot open sector metafile");
@ -3120,7 +3119,7 @@ MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load
ServerMapSector *sector = NULL;
std::string fullpath = sectordir + "/meta";
std::string fullpath = sectordir + DIR_DELIM + "meta";
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
{
@ -3128,7 +3127,7 @@ MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load
// format. Just go ahead and create the sector.
if(fs::PathExists(sectordir))
{
/*dstream<<"ServerMap::loadSectorMeta(): Sector metafile "
/*infostream<<"ServerMap::loadSectorMeta(): Sector metafile "
<<fullpath<<" doesn't exist but directory does."
<<" Continuing with a sector with no metadata."
<<std::endl;*/
@ -3259,7 +3258,7 @@ bool ServerMap::loadSectorFull(v2s16 p2d)
if(loadlayout != 2)
{
dstream<<"Sector converted to new layout - deleting "<<
infostream<<"Sector converted to new layout - deleting "<<
sectordir1<<std::endl;
fs::RecursiveDelete(sectordir1);
}
@ -3271,13 +3270,13 @@ bool ServerMap::loadSectorFull(v2s16 p2d)
void ServerMap::beginSave() {
verifyDatabase();
if(sqlite3_exec(m_database, "BEGIN;", NULL, NULL, NULL) != SQLITE_OK)
dstream<<"WARNING: beginSave() failed, saving might be slow.";
infostream<<"WARNING: beginSave() failed, saving might be slow.";
}
void ServerMap::endSave() {
verifyDatabase();
if(sqlite3_exec(m_database, "COMMIT;", NULL, NULL, NULL) != SQLITE_OK)
dstream<<"WARNING: endSave() failed, map might not have saved.";
infostream<<"WARNING: endSave() failed, map might not have saved.";
}
void ServerMap::saveBlock(MapBlock *block)
@ -3289,7 +3288,7 @@ void ServerMap::saveBlock(MapBlock *block)
if(block->isDummy())
{
/*v3s16 p = block->getPos();
dstream<<"ServerMap::saveBlock(): WARNING: Not writing dummy block "
infostream<<"ServerMap::saveBlock(): WARNING: Not writing dummy block "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
return;
}
@ -3306,7 +3305,7 @@ void ServerMap::saveBlock(MapBlock *block)
createDirs(sectordir);
std::string fullpath = sectordir+"/"+getBlockFilename(p3d);
std::string fullpath = sectordir+DIR_DELIM+getBlockFilename(p3d);
std::ofstream o(fullpath.c_str(), std::ios_base::binary);
if(o.good() == false)
throw FileNotGoodException("Cannot open block data");
@ -3334,12 +3333,12 @@ void ServerMap::saveBlock(MapBlock *block)
const char *bytes = tmp.c_str();
if(sqlite3_bind_int64(m_database_write, 1, getBlockAsInteger(p3d)) != SQLITE_OK)
dstream<<"WARNING: Block position failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl;
infostream<<"WARNING: Block position failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl;
if(sqlite3_bind_blob(m_database_write, 2, (void *)bytes, o.tellp(), NULL) != SQLITE_OK) // TODO this mught not be the right length
dstream<<"WARNING: Block data failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl;
infostream<<"WARNING: Block data failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl;
int written = sqlite3_step(m_database_write);
if(written != SQLITE_DONE)
dstream<<"WARNING: Block failed to save ("<<p3d.X<<", "<<p3d.Y<<", "<<p3d.Z<<") "
infostream<<"WARNING: Block failed to save ("<<p3d.X<<", "<<p3d.Y<<", "<<p3d.Z<<") "
<<sqlite3_errmsg(m_database)<<std::endl;
// Make ready for later reuse
sqlite3_reset(m_database_write);
@ -3352,7 +3351,7 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
{
DSTACK(__FUNCTION_NAME);
std::string fullpath = sectordir+"/"+blockfile;
std::string fullpath = sectordir+DIR_DELIM+blockfile;
try{
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
@ -3415,7 +3414,7 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
}
catch(SerializationError &e)
{
dstream<<"WARNING: Invalid block data on disk "
infostream<<"WARNING: Invalid block data on disk "
<<"fullpath="<<fullpath
<<" (SerializationError). "
<<"what()="<<e.what()
@ -3482,7 +3481,7 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool
}
catch(SerializationError &e)
{
dstream<<"WARNING: Invalid block data in database "
infostream<<"WARNING: Invalid block data in database "
<<" (SerializationError). "
<<"what()="<<e.what()
<<std::endl;
@ -3503,7 +3502,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
verifyDatabase();
if(sqlite3_bind_int64(m_database_read, 1, getBlockAsInteger(blockpos)) != SQLITE_OK)
dstream<<"WARNING: Could not bind block position for load: "
infostream<<"WARNING: Could not bind block position for load: "
<<sqlite3_errmsg(m_database)<<std::endl;
if(sqlite3_step(m_database_read) == SQLITE_ROW) {
/*
@ -3578,7 +3577,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
*/
std::string blockfilename = getBlockFilename(blockpos);
if(fs::PathExists(sectordir+"/"+blockfilename) == false)
if(fs::PathExists(sectordir+DIR_DELIM+blockfilename) == false)
return NULL;
/*
@ -3769,7 +3768,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
int time2 = time(0);
if(time2 > time1 + 4)
{
dstream<<"ClientMap::renderMap(): "
infostream<<"ClientMap::renderMap(): "
"Rendering takes ages, returning."
<<std::endl;
return;
@ -3931,7 +3930,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
m_control.blocks_drawn = blocks_drawn;
m_control.blocks_would_have_drawn = blocks_would_have_drawn;
/*dstream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
/*infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
<<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
}
@ -4181,7 +4180,7 @@ MapVoxelManipulator::MapVoxelManipulator(Map *map)
MapVoxelManipulator::~MapVoxelManipulator()
{
/*dstream<<"MapVoxelManipulator: blocks: "<<m_loaded_blocks.size()
/*infostream<<"MapVoxelManipulator: blocks: "<<m_loaded_blocks.size()
<<std::endl;*/
}
@ -4213,11 +4212,11 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
{
TimeTaker timer1("emerge load", &emerge_load_time);
/*dstream<<"Loading block (caller_id="<<caller_id<<")"
/*infostream<<"Loading block (caller_id="<<caller_id<<")"
<<" ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<" wanted area: ";
a.print(dstream);
dstream<<std::endl;*/
a.print(infostream);
infostream<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreate(p);
if(block->isDummy())
@ -4245,7 +4244,7 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
m_loaded_blocks.insert(p, !block_data_inexistent);
}
//dstream<<"emerge done"<<std::endl;
//infostream<<"emerge done"<<std::endl;
}
/*
@ -4261,7 +4260,7 @@ void MapVoxelManipulator::blitBack
//TimeTaker timer1("blitBack");
/*dstream<<"blitBack(): m_loaded_blocks.size()="
/*infostream<<"blitBack(): m_loaded_blocks.size()="
<<m_loaded_blocks.size()<<std::endl;*/
/*
@ -4350,10 +4349,10 @@ void ManualMapVoxelManipulator::initialEmerge(
u32 size_MB = block_area_nodes.getVolume()*4/1000000;
if(size_MB >= 1)
{
dstream<<"initialEmerge: area: ";
block_area_nodes.print(dstream);
dstream<<" ("<<size_MB<<"MB)";
dstream<<std::endl;
infostream<<"initialEmerge: area: ";
block_area_nodes.print(infostream);
infostream<<" ("<<size_MB<<"MB)";
infostream<<std::endl;
}
addArea(block_area_nodes);
@ -4421,7 +4420,7 @@ void ManualMapVoxelManipulator::blitBackAll(
if(existed == false)
{
// The Great Bug was found using this
/*dstream<<"ManualMapVoxelManipulator::blitBackAll: "
/*infostream<<"ManualMapVoxelManipulator::blitBackAll: "
<<"Inexistent ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;*/
continue;
@ -4429,7 +4428,7 @@ void ManualMapVoxelManipulator::blitBackAll(
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
if(block == NULL)
{
dstream<<"WARNING: "<<__FUNCTION_NAME
infostream<<"WARNING: "<<__FUNCTION_NAME
<<": got NULL block "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;

View File

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inventory.h"
#include <sstream>
#include "content_mapnode.h"
#include "log.h"
/*
NodeMetadata
@ -55,7 +56,7 @@ NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
if(n == NULL)
{
// If factory is not found, just return.
dstream<<"WARNING: NodeMetadata: No factory for typeId="
infostream<<"WARNING: NodeMetadata: No factory for typeId="
<<id<<std::endl;
return NULL;
}
@ -71,7 +72,7 @@ NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
}
catch(SerializationError &e)
{
dstream<<"WARNING: NodeMetadata: ignoring SerializationError"<<std::endl;
infostream<<"WARNING: NodeMetadata: ignoring SerializationError"<<std::endl;
return NULL;
}
}
@ -138,7 +139,7 @@ void NodeMetadataList::deSerialize(std::istream &is)
if(version > 1)
{
dstream<<__FUNCTION_NAME<<": version "<<version<<" not supported"
infostream<<__FUNCTION_NAME<<": version "<<version<<" not supported"
<<std::endl;
throw SerializationError("NodeMetadataList::deSerialize");
}
@ -165,7 +166,7 @@ void NodeMetadataList::deSerialize(std::istream &is)
if(m_data.find(p))
{
dstream<<"WARNING: NodeMetadataList::deSerialize(): "
infostream<<"WARNING: NodeMetadataList::deSerialize(): "
<<"already set data at position"
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<"): Ignoring."
<<std::endl;

View File

@ -33,7 +33,6 @@ Player::Player():
in_water_stable(false),
is_climbing(false),
swimming_up(false),
is_frozen(false),
inventory_backup(NULL),
craftresult_is_preview(true),
hp(20),
@ -335,19 +334,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
/*
Calculate new position
*/
if(is_frozen) {
// Still move very slowly so as not to feel all completely stuck
position += m_speed * dtime * 0.001;
}
else {
position += m_speed * dtime;
}
position += m_speed * dtime;
/*
If the player enters an unloaded chunk this is set to true.
*/
is_frozen = false;
// Skip collision detection if a special movement mode is used
bool free_move = g_settings->getBool("free_move");
if(free_move)
@ -505,6 +493,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z
<<"):"<<std::endl;*/
bool standing_on_unloaded = false;
/*
Go through every node around the player
*/
@ -512,6 +502,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
{
bool is_unloaded = false;
try{
// Player collides into walkable nodes
if(content_walkable(map.getNode(v3s16(x,y,z)).getContent()) == false)
@ -519,11 +510,9 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
}
catch(InvalidPositionException &e)
{
if(!is_frozen) {
// freeze when entering unloaded areas
is_frozen = true;
}
continue;
is_unloaded = true;
// Doing nothing here will block the player from
// walking over map borders
}
core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
@ -546,6 +535,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
&& nodebox.MinEdge.Z+d < playerbox.MaxEdge.Z
){
touching_ground = true;
if(is_unloaded)
standing_on_unloaded = true;
}
// If player doesn't intersect with node, ignore node.
@ -727,7 +718,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
if(collision_info)
{
// Report fall collision
if(old_speed.Y < m_speed.Y - 0.1)
if(old_speed.Y < m_speed.Y - 0.1 && !standing_on_unloaded)
{
CollisionInfo info;
info.t = COLLISION_FALL;

View File

@ -150,7 +150,6 @@ public:
bool in_water_stable;
bool is_climbing;
bool swimming_up;
bool is_frozen;
u8 light;

View File

@ -87,8 +87,8 @@ void signal_handler_init(void)
Path mangler
*/
std::string path_data = "../data";
std::string path_userdata = "../";
std::string path_data = ".." DIR_DELIM "data";
std::string path_userdata = "..";
void pathRemoveFile(char *path, char delim)
{
@ -127,10 +127,10 @@ void initializePaths()
pathRemoveFile(buf, '\\');
// Use "./bin/../data"
path_data = std::string(buf) + "/../data";
path_data = std::string(buf) + DIR_DELIM ".." DIR_DELIM "data";
// Use "./bin/../"
path_userdata = std::string(buf) + "/../";
path_userdata = std::string(buf) + DIR_DELIM ".." DIR_DELIM;
/*
Linux
@ -188,13 +188,13 @@ void initializePaths()
pathRemoveFile(buf, '\\');
// Use "./bin/../data"
path_data = std::string(buf) + "/../data";
path_data = std::string(buf) + DIR_DELIM ".." DIR_DELIM "data";
//path_data = std::string(buf) + "/../share/" + PROJECT_NAME;
// Use "C:\Documents and Settings\user\Application Data\<PROJECT_NAME>"
len = GetEnvironmentVariable("APPDATA", buf, buflen);
assert(len < buflen);
path_userdata = std::string(buf) + "/" + PROJECT_NAME;
path_userdata = std::string(buf) + DIR_DELIM + PROJECT_NAME;
/*
Linux

View File

@ -38,24 +38,38 @@ public:
m_mutex.Init();
}
void add(const std::string &name, u32 duration)
void add(const std::string &name, float value)
{
JMutexAutoLock lock(m_mutex);
core::map<std::string, u32>::Node *n = m_data.find(name);
core::map<std::string, float>::Node *n = m_data.find(name);
if(n == NULL)
{
m_data[name] = duration;
m_data[name] = value;
}
else
{
n->setValue(n->getValue()+duration);
n->setValue(n->getValue() + value);
}
}
void lowpass(const std::string &name, float value, float factor)
{
JMutexAutoLock lock(m_mutex);
core::map<std::string, float>::Node *n = m_data.find(name);
if(n == NULL)
{
m_data[name] = value;
}
else
{
n->setValue(n->getValue() * (1.0 - 1.0/factor) + value / factor);
}
}
void clear()
{
JMutexAutoLock lock(m_mutex);
for(core::map<std::string, u32>::Iterator
for(core::map<std::string, float>::Iterator
i = m_data.getIterator();
i.atEnd() == false; i++)
{
@ -66,14 +80,14 @@ public:
void print(std::ostream &o)
{
JMutexAutoLock lock(m_mutex);
for(core::map<std::string, u32>::Iterator
for(core::map<std::string, float>::Iterator
i = m_data.getIterator();
i.atEnd() == false; i++)
{
std::string name = i.getNode()->getKey();
o<<name<<": ";
o<<" "<<name<<": ";
s32 clampsize = 40;
s32 space = clampsize-name.size();
s32 space = clampsize - name.size();
for(s32 j=0; j<space; j++)
{
if(j%2 == 0 && j < space - 1)
@ -88,25 +102,34 @@ public:
private:
JMutex m_mutex;
core::map<std::string, u32> m_data;
core::map<std::string, float> m_data;
};
enum ScopeProfilerType{
SPT_ADD,
SPT_LOWPASS
};
class ScopeProfiler
{
public:
ScopeProfiler(Profiler *profiler, const std::string &name):
ScopeProfiler(Profiler *profiler, const std::string &name,
enum ScopeProfilerType type = SPT_ADD):
m_profiler(profiler),
m_name(name),
m_timer(NULL)
m_timer(NULL),
m_type(type)
{
if(m_profiler)
m_timer = new TimeTaker(m_name.c_str());
}
// name is copied
ScopeProfiler(Profiler *profiler, const char *name):
ScopeProfiler(Profiler *profiler, const char *name,
enum ScopeProfilerType type = SPT_ADD):
m_profiler(profiler),
m_name(name),
m_timer(NULL)
m_timer(NULL),
m_type(type)
{
if(m_profiler)
m_timer = new TimeTaker(m_name.c_str());
@ -116,8 +139,16 @@ public:
if(m_timer)
{
u32 duration = m_timer->stop(true);
if(m_profiler)
m_profiler->add(m_name, duration);
if(m_profiler){
switch(m_type){
case SPT_ADD:
m_profiler->add(m_name, duration);
break;
case SPT_LOWPASS:
m_profiler->lowpass(m_name, duration, 20.0);
break;
}
}
delete m_timer;
}
}
@ -125,6 +156,7 @@ private:
Profiler *m_profiler;
std::string m_name;
TimeTaker *m_timer;
enum ScopeProfilerType m_type;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -472,6 +472,9 @@ public:
{
return m_con.GetPeerNoEx(peer_id);
}
// Envlock and conlock should be locked when calling this
void notifyPlayer(const char *name, const std::wstring msg);
private:

View File

@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "utility.h"
#include "settings.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
void cmd_status(std::wostringstream &os,
ServerCommandContext *ctx)
{
@ -94,10 +96,31 @@ void cmd_grantrevoke(std::wostringstream &os,
std::string playername = wide_to_narrow(ctx->parms[1]);
u64 privs = ctx->server->getPlayerAuthPrivs(playername);
if(ctx->parms[0] == L"grant")
if(ctx->parms[0] == L"grant"){
privs |= newprivs;
else
actionstream<<ctx->player->getName()<<" grants "
<<wide_to_narrow(ctx->parms[2])<<" to "
<<playername<<std::endl;
std::wstring msg;
msg += narrow_to_wide(ctx->player->getName());
msg += L" granted you the privilege \"";
msg += ctx->parms[2];
msg += L"\"";
ctx->server->notifyPlayer(playername.c_str(), msg);
} else {
privs &= ~newprivs;
actionstream<<ctx->player->getName()<<" revokes "
<<wide_to_narrow(ctx->parms[2])<<" from "
<<playername<<std::endl;
std::wstring msg;
msg += narrow_to_wide(ctx->player->getName());
msg += L" revoked from you the privilege \"";
msg += ctx->parms[2];
msg += L"\"";
ctx->server->notifyPlayer(playername.c_str(), msg);
}
ctx->server->setPlayerAuthPrivs(playername, privs);
@ -123,6 +146,9 @@ void cmd_time(std::wostringstream &os,
u32 time = stoi(wide_to_narrow(ctx->parms[1]));
ctx->server->setTimeOfDay(time);
os<<L"-!- time_of_day changed.";
actionstream<<ctx->player->getName()<<" sets time "
<<time<<std::endl;
}
void cmd_shutdown(std::wostringstream &os,
@ -134,8 +160,9 @@ void cmd_shutdown(std::wostringstream &os,
return;
}
dstream<<DTIME<<" Server: Operator requested shutdown."
<<std::endl;
actionstream<<ctx->player->getName()
<<" shuts down server"<<std::endl;
ctx->server->requestShutdown();
os<<L"*** Server shutting down (operator request)";
@ -156,6 +183,9 @@ void cmd_setting(std::wostringstream &os,
std::string confline = wide_to_narrow(ctx->paramstring);
actionstream<<ctx->player->getName()
<<" sets: "<<confline<<std::endl;
g_settings->parseConfigLine(confline);
ctx->server->saveConfig();
@ -186,6 +216,11 @@ void cmd_teleport(std::wostringstream &os,
}
v3f dest(stoi(coords[0])*10, stoi(coords[1])*10, stoi(coords[2])*10);
actionstream<<ctx->player->getName()<<" teleports from "
<<PP(ctx->player->getPosition()/BS)<<" to "
<<PP(dest/BS)<<std::endl;
ctx->player->setPosition(dest);
ctx->server->SendMovePlayer(ctx->player);
@ -226,6 +261,9 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
ctx->server->setIpBanned(ip_string, player->getName());
os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|"
<<narrow_to_wide(player->getName());
actionstream<<ctx->player->getName()<<" bans "
<<player->getName()<<" / "<<ip_string<<std::endl;
}
else
{
@ -233,6 +271,9 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
std::string desc = ctx->server->getBanDescription(ip_or_name);
ctx->server->unsetIpBanned(ip_or_name);
os<<L"-!- Unbanned "<<narrow_to_wide(desc);
actionstream<<ctx->player->getName()<<" unbans "
<<ip_or_name<<std::endl;
}
}

View File

@ -73,6 +73,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "defaultsettings.h"
#include "settings.h"
#include "profiler.h"
#include "log.h"
/*
Settings.
@ -94,15 +95,15 @@ ITextureSource *g_texturesource = NULL;
// Connection
std::ostream *dout_con_ptr = &dummyout;
std::ostream *derr_con_ptr = &dstream_no_stderr;
std::ostream *derr_con_ptr = &verbosestream;
// Server
std::ostream *dout_server_ptr = &dstream;
std::ostream *derr_server_ptr = &dstream;
std::ostream *dout_server_ptr = &infostream;
std::ostream *derr_server_ptr = &errorstream;
// Client
std::ostream *dout_client_ptr = &dstream;
std::ostream *derr_client_ptr = &dstream;
std::ostream *dout_client_ptr = &infostream;
std::ostream *derr_client_ptr = &errorstream;
/*
gettime.h implementation
@ -116,12 +117,37 @@ u32 getTimeMs()
return porting::getTimeMs();
}
class DstreamLogOutput: public ILogOutput
{
public:
/* line: Full line with timestamp, level and thread */
void printLog(const std::string &line)
{
dstream<<line<<std::endl;
}
} main_dstream_log_out;
class DstreamNoStderrLogOutput: public ILogOutput
{
public:
/* line: Full line with timestamp, level and thread */
void printLog(const std::string &line)
{
dstream_no_stderr<<line<<std::endl;
}
} main_dstream_no_stderr_log_out;
int main(int argc, char *argv[])
{
/*
Initialization
*/
log_add_output_maxlev(&main_dstream_log_out, LMT_ACTION);
log_add_output_all_levs(&main_dstream_no_stderr_log_out);
log_register_thread("main");
// Set locale. This is for forcing '.' as the decimal point.
std::locale::global(std::locale("C"));
// This enables printing all characters in bitmap font
@ -149,7 +175,7 @@ int main(int argc, char *argv[])
#ifdef RUN_IN_PLACE
std::string debugfile = DEBUGFILE;
#else
std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE;
#endif
debugstreams_init(disable_stderr, debugfile.c_str());
// Initialize debug stacks
@ -164,7 +190,7 @@ int main(int argc, char *argv[])
BEGIN_DEBUG_EXCEPTION_HANDLER
// Print startup message
dstream<<DTIME<<PROJECT_NAME <<
actionstream<<PROJECT_NAME<<
" with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
<<", "<<BUILD_INFO
<<std::endl;
@ -185,6 +211,7 @@ int main(int argc, char *argv[])
allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
allowed_options.insert("info-on-stderr", ValueSpec(VALUETYPE_FLAG));
Settings cmd_args;
@ -217,6 +244,8 @@ int main(int argc, char *argv[])
return cmd_args.getFlag("help") ? 0 : 1;
}
if(cmd_args.getFlag("info-on-stderr"))
log_add_output(&main_dstream_log_out, LMT_INFO);
/*
Basic initialization
@ -241,7 +270,7 @@ int main(int argc, char *argv[])
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
if(r == false)
{
dstream<<"Could not read configuration from \""
errorstream<<"Could not read configuration from \""
<<cmd_args.get("config")<<"\""<<std::endl;
return 1;
}
@ -250,9 +279,11 @@ int main(int argc, char *argv[])
else
{
core::array<std::string> filenames;
filenames.push_back(porting::path_userdata + "/minetest.conf");
filenames.push_back(porting::path_userdata +
DIR_DELIM + "minetest.conf");
#ifdef RUN_IN_PLACE
filenames.push_back(porting::path_userdata + "/../minetest.conf");
filenames.push_back(porting::path_userdata +
DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
#endif
for(u32 i=0; i<filenames.size(); i++)
@ -318,7 +349,7 @@ int main(int argc, char *argv[])
}
// Figure out path to map
std::string map_dir = porting::path_userdata+"/world";
std::string map_dir = porting::path_userdata+DIR_DELIM+"world";
if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir");
else if(g_settings->exists("map-dir"))
@ -334,10 +365,10 @@ int main(int argc, char *argv[])
} //try
catch(con::PeerNotFoundException &e)
{
dstream<<DTIME<<"Connection timed out."<<std::endl;
errorstream<<"Connection timed out."<<std::endl;
}
END_DEBUG_EXCEPTION_HANDLER
END_DEBUG_EXCEPTION_HANDLER(errorstream)
debugstreams_deinit();

View File

@ -111,6 +111,8 @@ public:
/*
*/
virtual void rightClick(Player *player){}
virtual bool isPeaceful(){return true;}
/*
Number of players which know about this object. Object won't be

View File

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream>
#include "debug.h"
#include "utility.h"
#include "log.h"
enum ValueType
{
@ -81,7 +82,7 @@ public:
if(trimmedline[0] == '#')
return true;
//dstream<<"trimmedline=\""<<trimmedline<<"\""<<std::endl;
//infostream<<"trimmedline=\""<<trimmedline<<"\""<<std::endl;
Strfnd sf(trim(line));
@ -94,7 +95,7 @@ public:
std::string value = sf.next("\n");
value = trim(value);
/*dstream<<"Config name=\""<<name<<"\" value=\""
/*infostream<<"Config name=\""<<name<<"\" value=\""
<<value<<"\""<<std::endl;*/
m_settings[name] = value;
@ -130,7 +131,7 @@ public:
*/
std::string line;
std::getline(is, line);
//dstream<<"got line: \""<<line<<"\""<<std::endl;
//infostream<<"got line: \""<<line<<"\""<<std::endl;
return parseConfigLine(line);
}
@ -145,12 +146,12 @@ public:
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"Error opening configuration file \""
errorstream<<"Error opening configuration file \""
<<filename<<"\""<<std::endl;
return false;
}
dstream<<"Parsing configuration file: \""
infostream<<"Parsing configuration file: \""
<<filename<<"\""<<std::endl;
while(parseConfigObject(is));
@ -215,7 +216,7 @@ public:
if(newvalue != value)
{
dstream<<"Changing value of \""<<name<<"\" = \""
infostream<<"Changing value of \""<<name<<"\" = \""
<<value<<"\" -> \""<<newvalue<<"\""
<<std::endl;
}
@ -235,7 +236,7 @@ public:
*/
bool updateConfigFile(const char *filename)
{
dstream<<"Updating configuration file: \""
infostream<<"Updating configuration file: \""
<<filename<<"\""<<std::endl;
core::list<std::string> objects;
@ -246,7 +247,7 @@ public:
std::ifstream is(filename);
if(is.good() == false)
{
dstream<<"INFO: updateConfigFile():"
infostream<<"updateConfigFile():"
" Error opening configuration file"
" for reading: \""
<<filename<<"\""<<std::endl;
@ -264,7 +265,7 @@ public:
std::ofstream os(filename);
if(os.good() == false)
{
dstream<<"Error opening configuration file"
errorstream<<"Error opening configuration file"
" for writing: \""
<<filename<<"\""<<std::endl;
return false;
@ -291,7 +292,7 @@ public:
continue;
std::string name = i.getNode()->getKey();
std::string value = i.getNode()->getValue();
dstream<<"Adding \""<<name<<"\" = \""<<value<<"\""
infostream<<"Adding \""<<name<<"\" = \""<<value<<"\""
<<std::endl;
os<<name<<" = "<<value<<"\n";
}
@ -316,7 +317,7 @@ public:
std::string argname = argv[i];
if(argname.substr(0, 2) != "--")
{
dstream<<"Invalid command-line parameter \""
errorstream<<"Invalid command-line parameter \""
<<argname<<"\": --<option> expected."<<std::endl;
return false;
}
@ -328,7 +329,7 @@ public:
n = allowed_options.find(name);
if(n == NULL)
{
dstream<<"Unknown command-line parameter \""
errorstream<<"Unknown command-line parameter \""
<<argname<<"\""<<std::endl;
return false;
}
@ -345,7 +346,7 @@ public:
{
if(i >= argc)
{
dstream<<"Invalid command-line parameter \""
errorstream<<"Invalid command-line parameter \""
<<name<<"\": missing value"<<std::endl;
return false;
}
@ -354,7 +355,7 @@ public:
}
dstream<<"Valid command-line parameter: \""
infostream<<"Valid command-line parameter: \""
<<name<<"\" = \""<<value<<"\""
<<std::endl;
set(name, value);
@ -403,7 +404,7 @@ public:
n = m_defaults.find(name);
if(n == NULL)
{
dstream<<"INFO: Settings: Setting not found: \""
infostream<<"Settings: Setting not found: \""
<<name<<"\""<<std::endl;
throw SettingNotFoundException("Setting not found");
}

View File

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_mapnode.h"
#include "mapsector.h"
#include "settings.h"
#include "log.h"
/*
Asserts that the exception occurs
@ -49,9 +50,9 @@ struct TestUtilities
{
void Run()
{
/*dstream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
dstream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
dstream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
/*infostream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
infostream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
infostream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
@ -112,13 +113,13 @@ struct TestCompress
std::string str_out = os.str();
dstream<<"str_out.size()="<<str_out.size()<<std::endl;
dstream<<"TestCompress: 1,5,5,1 -> ";
infostream<<"str_out.size()="<<str_out.size()<<std::endl;
infostream<<"TestCompress: 1,5,5,1 -> ";
for(u32 i=0; i<str_out.size(); i++)
{
dstream<<(u32)str_out[i]<<",";
infostream<<(u32)str_out[i]<<",";
}
dstream<<std::endl;
infostream<<std::endl;
assert(str_out.size() == 10);
@ -139,12 +140,12 @@ struct TestCompress
decompress(is, os2, 0);
std::string str_out2 = os2.str();
dstream<<"decompress: ";
infostream<<"decompress: ";
for(u32 i=0; i<str_out2.size(); i++)
{
dstream<<(u32)str_out2[i]<<",";
infostream<<(u32)str_out2[i]<<",";
}
dstream<<std::endl;
infostream<<std::endl;
assert(str_out2.size() == fromdata.getSize());
@ -168,13 +169,13 @@ struct TestCompress
std::string str_out = os.str();
dstream<<"str_out.size()="<<str_out.size()<<std::endl;
dstream<<"TestCompress: 1,5,5,1 -> ";
infostream<<"str_out.size()="<<str_out.size()<<std::endl;
infostream<<"TestCompress: 1,5,5,1 -> ";
for(u32 i=0; i<str_out.size(); i++)
{
dstream<<(u32)str_out[i]<<",";
infostream<<(u32)str_out[i]<<",";
}
dstream<<std::endl;
infostream<<std::endl;
/*assert(str_out.size() == 10);
@ -195,12 +196,12 @@ struct TestCompress
decompress(is, os2, SER_FMT_VER_HIGHEST);
std::string str_out2 = os2.str();
dstream<<"decompress: ";
infostream<<"decompress: ";
for(u32 i=0; i<str_out2.size(); i++)
{
dstream<<(u32)str_out2[i]<<",";
infostream<<(u32)str_out2[i]<<",";
}
dstream<<std::endl;
infostream<<std::endl;
assert(str_out2.size() == fromdata.getSize());
@ -258,12 +259,12 @@ struct TestVoxelManipulator
assert(aa.size() == results.size());
dstream<<"Result of diff:"<<std::endl;
infostream<<"Result of diff:"<<std::endl;
for(core::list<VoxelArea>::Iterator
i = aa.begin(); i != aa.end(); i++)
{
i->print(dstream);
dstream<<std::endl;
i->print(infostream);
infostream<<std::endl;
s32 j = results.linear_search(*i);
assert(j != -1);
@ -277,27 +278,27 @@ struct TestVoxelManipulator
VoxelManipulator v;
v.print(dstream);
v.print(infostream);
dstream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
infostream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
v.print(dstream);
v.print(infostream);
assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
infostream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
v.print(dstream);
v.print(infostream);
dstream<<"*** Adding area ***"<<std::endl;
infostream<<"*** Adding area ***"<<std::endl;
v.addArea(a);
v.print(dstream);
v.print(infostream);
assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
@ -343,12 +344,12 @@ struct TestVoxelManipulator
p++;
}
v.print(dstream, VOXELPRINT_WATERPRESSURE);
v.print(infostream, VOXELPRINT_WATERPRESSURE);
core::map<v3s16, u8> active_nodes;
v.updateAreaWaterPressure(area, active_nodes);
v.print(dstream, VOXELPRINT_WATERPRESSURE);
v.print(infostream, VOXELPRINT_WATERPRESSURE);
//s16 highest_y = -32768;
/*
@ -365,8 +366,8 @@ struct TestVoxelManipulator
//v.flowWater(active_nodes, 0, true, 1000);
v.flowWater(active_nodes, 0, false, 1000);
dstream<<"Final result of flowWater:"<<std::endl;
v.print(dstream, VOXELPRINT_WATERPRESSURE);
infostream<<"Final result of flowWater:"<<std::endl;
v.print(infostream, VOXELPRINT_WATERPRESSURE);
#endif
//assert(0);
@ -765,15 +766,15 @@ struct TestConnection
assert(readU8(&p1.data[6]) == channel);
assert(readU8(&p1.data[7]) == data1[0]);
//dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
//infostream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
/*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
/*infostream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
<<data1.getSize()<<std::endl;
dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
infostream<<"readU8(&p2[3])="<<readU8(&p2[3])
<<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
infostream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
assert(p2.getSize() == 3 + data1.getSize());
assert(readU8(&p2[0]) == TYPE_RELIABLE);
@ -791,14 +792,14 @@ struct TestConnection
}
void peerAdded(con::Peer *peer)
{
dstream<<"Handler("<<name<<")::peerAdded(): "
infostream<<"Handler("<<name<<")::peerAdded(): "
"id="<<peer->id<<std::endl;
last_id = peer->id;
count++;
}
void deletingPeer(con::Peer *peer, bool timeout)
{
dstream<<"Handler("<<name<<")::deletingPeer(): "
infostream<<"Handler("<<name<<")::deletingPeer(): "
"id="<<peer->id
<<", timeout="<<timeout<<std::endl;
last_id = peer->id;
@ -824,11 +825,11 @@ struct TestConnection
Handler hand_server("server");
Handler hand_client("client");
dstream<<"** Creating server Connection"<<std::endl;
infostream<<"** Creating server Connection"<<std::endl;
con::Connection server(proto_id, 512, 5.0, &hand_server);
server.Serve(30001);
dstream<<"** Creating client Connection"<<std::endl;
infostream<<"** Creating client Connection"<<std::endl;
con::Connection client(proto_id, 512, 5.0, &hand_client);
assert(hand_server.count == 0);
@ -837,7 +838,7 @@ struct TestConnection
sleep_ms(50);
Address server_address(127,0,0,1, 30001);
dstream<<"** running client.Connect()"<<std::endl;
infostream<<"** running client.Connect()"<<std::endl;
client.Connect(server_address);
sleep_ms(50);
@ -852,9 +853,9 @@ struct TestConnection
{
u16 peer_id;
u8 data[100];
dstream<<"** running server.Receive()"<<std::endl;
infostream<<"** running server.Receive()"<<std::endl;
u32 size = server.Receive(peer_id, data, 100);
dstream<<"** Server received: peer_id="<<peer_id
infostream<<"** Server received: peer_id="<<peer_id
<<", size="<<size
<<std::endl;
}
@ -879,9 +880,9 @@ struct TestConnection
{
u16 peer_id;
u8 data[100];
dstream<<"** running client.Receive()"<<std::endl;
infostream<<"** running client.Receive()"<<std::endl;
u32 size = client.Receive(peer_id, data, 100);
dstream<<"** Client received: peer_id="<<peer_id
infostream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<std::endl;
}
@ -897,9 +898,9 @@ struct TestConnection
{
u16 peer_id;
u8 data[100];
dstream<<"** running server.Receive()"<<std::endl;
infostream<<"** running server.Receive()"<<std::endl;
u32 size = server.Receive(peer_id, data, 100);
dstream<<"** Server received: peer_id="<<peer_id
infostream<<"** Server received: peer_id="<<peer_id
<<", size="<<size
<<std::endl;
}
@ -912,16 +913,16 @@ struct TestConnection
u32 datasize = sizeof(data);*/
SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
dstream<<"** running client.Send()"<<std::endl;
infostream<<"** running client.Send()"<<std::endl;
client.Send(PEER_ID_SERVER, 0, data, true);
sleep_ms(50);
u16 peer_id;
u8 recvdata[100];
dstream<<"** running server.Receive()"<<std::endl;
infostream<<"** running server.Receive()"<<std::endl;
u32 size = server.Receive(peer_id, recvdata, 100);
dstream<<"** Server received: peer_id="<<peer_id
infostream<<"** Server received: peer_id="<<peer_id
<<", size="<<size
<<", data="<<*data
<<std::endl;
@ -942,7 +943,7 @@ struct TestConnection
Address client_address =
server.GetPeer(peer_id_client)->address;
dstream<<"*** Sending packets in wrong order (2,1,2)"
infostream<<"*** Sending packets in wrong order (2,1,2)"
<<std::endl;
u8 chn = 0;
@ -957,16 +958,16 @@ struct TestConnection
sleep_ms(50);
dstream<<"*** Receiving the packets"<<std::endl;
infostream<<"*** Receiving the packets"<<std::endl;
u16 peer_id;
u8 recvdata[20];
u32 size;
dstream<<"** running client.Receive()"<<std::endl;
infostream<<"** running client.Receive()"<<std::endl;
peer_id = 132;
size = client.Receive(peer_id, recvdata, 20);
dstream<<"** Client received: peer_id="<<peer_id
infostream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<", data="<<recvdata
<<std::endl;
@ -974,10 +975,10 @@ struct TestConnection
assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
assert(peer_id == PEER_ID_SERVER);
dstream<<"** running client.Receive()"<<std::endl;
infostream<<"** running client.Receive()"<<std::endl;
peer_id = 132;
size = client.Receive(peer_id, recvdata, 20);
dstream<<"** Client received: peer_id="<<peer_id
infostream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<", data="<<recvdata
<<std::endl;
@ -988,17 +989,17 @@ struct TestConnection
bool got_exception = false;
try
{
dstream<<"** running client.Receive()"<<std::endl;
infostream<<"** running client.Receive()"<<std::endl;
peer_id = 132;
size = client.Receive(peer_id, recvdata, 20);
dstream<<"** Client received: peer_id="<<peer_id
infostream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<", data="<<recvdata
<<std::endl;
}
catch(con::NoIncomingDataException &e)
{
dstream<<"** No incoming data for client"<<std::endl;
infostream<<"** No incoming data for client"<<std::endl;
got_exception = true;
}
assert(got_exception);
@ -1010,35 +1011,35 @@ struct TestConnection
data1[i] = i/4;
}
dstream<<"Sending data (size="<<datasize<<"):";
infostream<<"Sending data (size="<<datasize<<"):";
for(int i=0; i<datasize && i<20; i++){
if(i%2==0) DEBUGPRINT(" ");
DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
}
if(datasize>20)
dstream<<"...";
dstream<<std::endl;
infostream<<"...";
infostream<<std::endl;
server.Send(peer_id_client, 0, data1, true);
sleep_ms(50);
u8 recvdata[datasize + 1000];
dstream<<"** running client.Receive()"<<std::endl;
infostream<<"** running client.Receive()"<<std::endl;
u16 peer_id = 132;
u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
dstream<<"** Client received: peer_id="<<peer_id
infostream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<std::endl;
dstream<<"Received data (size="<<size<<"):";
infostream<<"Received data (size="<<size<<"):";
for(int i=0; i<size && i<20; i++){
if(i%2==0) DEBUGPRINT(" ");
DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
}
if(size>20)
dstream<<"...";
dstream<<std::endl;
infostream<<"...";
infostream<<std::endl;
assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
assert(peer_id == PEER_ID_SERVER);
@ -1057,14 +1058,14 @@ struct TestConnection
#define TEST(X)\
{\
X x;\
dstream<<"Running " #X <<std::endl;\
infostream<<"Running " #X <<std::endl;\
x.Run();\
}
void run_tests()
{
DSTACK(__FUNCTION_NAME);
dstream<<"run_tests() started"<<std::endl;
infostream<<"run_tests() started"<<std::endl;
TEST(TestUtilities);
TEST(TestSettings);
TEST(TestCompress);
@ -1078,6 +1079,6 @@ void run_tests()
TEST(TestConnection);
dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
}
dstream<<"run_tests() passed"<<std::endl;
infostream<<"run_tests() passed"<<std::endl;
}

View File

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "utility.h"
#include "settings.h"
#include <ICameraSceneNode.h>
#include "log.h"
/*
A cache from texture name to texture path
@ -117,7 +118,7 @@ std::string getTexturePath(const std::string &filename)
std::string texture_path = g_settings->get("texture_path");
if(texture_path != "")
{
std::string testpath = texture_path + '/' + filename;
std::string testpath = texture_path + DIR_DELIM + filename;
// Check all filename extensions. Returns "" if not found.
fullpath = getImagePath(testpath);
}
@ -162,7 +163,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
if(g_settings->getBool("enable_texture_atlas"))
buildMainAtlas();
else
dstream<<"INFO: Not building texture atlas."<<std::endl;
infostream<<"Not building texture atlas."<<std::endl;
}
TextureSource::~TextureSource()
@ -179,7 +180,7 @@ void TextureSource::processQueue()
GetRequest<std::string, u32, u8, u8>
request = m_get_texture_queue.pop();
dstream<<"INFO: TextureSource::processQueue(): "
infostream<<"TextureSource::processQueue(): "
<<"got texture request with "
<<"name=\""<<request.key<<"\""
<<std::endl;
@ -196,7 +197,7 @@ void TextureSource::processQueue()
u32 TextureSource::getTextureId(const std::string &name)
{
//dstream<<"INFO: getTextureId(): \""<<name<<"\""<<std::endl;
//infostream<<"getTextureId(): \""<<name<<"\""<<std::endl;
{
/*
@ -220,7 +221,7 @@ u32 TextureSource::getTextureId(const std::string &name)
}
else
{
dstream<<"INFO: getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;
// We're gonna ask the result to be put into here
ResultQueue<std::string, u32, u8, u8> result_queue;
@ -228,7 +229,7 @@ u32 TextureSource::getTextureId(const std::string &name)
// Throw a request in
m_get_texture_queue.add(name, 0, 0, &result_queue);
dstream<<"INFO: Waiting for texture from main thread, name=\""
infostream<<"Waiting for texture from main thread, name=\""
<<name<<"\""<<std::endl;
try
@ -244,12 +245,12 @@ u32 TextureSource::getTextureId(const std::string &name)
}
catch(ItemNotFoundException &e)
{
dstream<<"WARNING: Waiting for texture timed out."<<std::endl;
infostream<<"Waiting for texture timed out."<<std::endl;
return 0;
}
}
dstream<<"WARNING: getTextureId(): Failed"<<std::endl;
infostream<<"getTextureId(): Failed"<<std::endl;
return 0;
}
@ -278,12 +279,12 @@ video::IImage* generate_image_from_scratch(std::string name,
*/
u32 TextureSource::getTextureIdDirect(const std::string &name)
{
//dstream<<"INFO: getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;
//infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;
// Empty name means texture 0
if(name == "")
{
dstream<<"INFO: getTextureIdDirect(): name is empty"<<std::endl;
infostream<<"getTextureIdDirect(): name is empty"<<std::endl;
return 0;
}
@ -292,7 +293,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
*/
if(get_current_thread_id() != m_main_thread)
{
dstream<<"ERROR: TextureSource::getTextureIdDirect() "
errorstream<<"TextureSource::getTextureIdDirect() "
"called not from main thread"<<std::endl;
return 0;
}
@ -307,13 +308,13 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
n = m_name_to_id.find(name);
if(n != NULL)
{
dstream<<"INFO: getTextureIdDirect(): \""<<name
infostream<<"getTextureIdDirect(): \""<<name
<<"\" found in cache"<<std::endl;
return n->getValue();
}
}
dstream<<"INFO: getTextureIdDirect(): \""<<name
infostream<<"getTextureIdDirect(): \""<<name
<<"\" NOT found in cache. Creating it."<<std::endl;
/*
@ -348,13 +349,13 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
{
// Construct base name
base_image_name = name.substr(0, last_separator_position);
/*dstream<<"INFO: getTextureIdDirect(): Calling itself recursively"
/*infostream<<"getTextureIdDirect(): Calling itself recursively"
" to get base image of \""<<name<<"\" = \""
<<base_image_name<<"\""<<std::endl;*/
base_image_id = getTextureIdDirect(base_image_name);
}
//dstream<<"base_image_id="<<base_image_id<<std::endl;
//infostream<<"base_image_id="<<base_image_id<<std::endl;
video::IVideoDriver* driver = m_device->getVideoDriver();
assert(driver);
@ -377,7 +378,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
if(image == NULL)
{
dstream<<"WARNING: getTextureIdDirect(): NULL image in "
infostream<<"getTextureIdDirect(): NULL image in "
<<"cache: \""<<base_image_name<<"\""
<<std::endl;
}
@ -396,7 +397,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
core::rect<s32>(pos_from, dim) // from
);
/*dstream<<"INFO: getTextureIdDirect(): Loaded \""
/*infostream<<"getTextureIdDirect(): Loaded \""
<<base_image_name<<"\" from image cache"
<<std::endl;*/
}
@ -408,12 +409,12 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
*/
std::string last_part_of_name = name.substr(last_separator_position+1);
//dstream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;
//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;
// Generate image according to part of name
if(generate_image(last_part_of_name, baseimg, m_device) == false)
{
dstream<<"INFO: getTextureIdDirect(): "
infostream<<"getTextureIdDirect(): "
"failed to generate \""<<last_part_of_name<<"\""
<<std::endl;
}
@ -421,7 +422,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
// If no resulting image, print a warning
if(baseimg == NULL)
{
dstream<<"WARNING: getTextureIdDirect(): baseimg is NULL (attempted to"
infostream<<"getTextureIdDirect(): baseimg is NULL (attempted to"
" create texture \""<<name<<"\""<<std::endl;
}
@ -450,7 +451,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
m_atlaspointer_cache.push_back(nap);
m_name_to_id.insert(name, id);
/*dstream<<"INFO: getTextureIdDirect(): "
/*infostream<<"getTextureIdDirect(): "
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
return id;
@ -462,7 +463,7 @@ std::string TextureSource::getTextureName(u32 id)
if(id >= m_atlaspointer_cache.size())
{
dstream<<"WARNING: TextureSource::getTextureName(): id="<<id
infostream<<"TextureSource::getTextureName(): id="<<id
<<" >= m_atlaspointer_cache.size()="
<<m_atlaspointer_cache.size()<<std::endl;
return "";
@ -484,7 +485,7 @@ AtlasPointer TextureSource::getTexture(u32 id)
void TextureSource::buildMainAtlas()
{
dstream<<"TextureSource::buildMainAtlas()"<<std::endl;
infostream<<"TextureSource::buildMainAtlas()"<<std::endl;
//return; // Disable (for testing)
@ -500,7 +501,7 @@ void TextureSource::buildMainAtlas()
//assert(atlas_img);
if(atlas_img == NULL)
{
dstream<<"TextureSource::buildMainAtlas(): Failed to create atlas "
errorstream<<"TextureSource::buildMainAtlas(): Failed to create atlas "
"image; not building texture atlas."<<std::endl;
return;
}
@ -569,7 +570,7 @@ void TextureSource::buildMainAtlas()
video::IImage *img2 = generate_image_from_scratch(name, m_device);
if(img2 == NULL)
{
dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""<<name<<"\""<<std::endl;
infostream<<"TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""<<name<<"\""<<std::endl;
continue;
}
@ -580,7 +581,7 @@ void TextureSource::buildMainAtlas()
if(dim.Width > max_size_in_atlas.Width
|| dim.Height > max_size_in_atlas.Height)
{
dstream<<"INFO: TextureSource::buildMainAtlas(): Not adding "
infostream<<"TextureSource::buildMainAtlas(): Not adding "
<<"\""<<name<<"\" because image is large"<<std::endl;
continue;
}
@ -588,13 +589,13 @@ void TextureSource::buildMainAtlas()
// Stop making atlas if atlas is full
if(pos_in_atlas.Y + dim.Height > atlas_dim.Height)
{
dstream<<"WARNING: TextureSource::buildMainAtlas(): "
infostream<<"TextureSource::buildMainAtlas(): "
<<"Atlas is full, not adding more textures."
<<std::endl;
break;
}
dstream<<"INFO: TextureSource::buildMainAtlas(): Adding \""<<name
infostream<<"TextureSource::buildMainAtlas(): Adding \""<<name
<<"\" to texture atlas"<<std::endl;
// Tile it a few times in the X direction
@ -673,7 +674,7 @@ void TextureSource::buildMainAtlas()
if(m_name_to_id.find(name) == NULL)
continue;
u32 id = m_name_to_id[name];
//dstream<<"id of name "<<name<<" is "<<id<<std::endl;
//infostream<<"id of name "<<name<<" is "<<id<<std::endl;
m_atlaspointer_cache[id].a.atlas = t;
}
@ -687,7 +688,7 @@ void TextureSource::buildMainAtlas()
video::IImage* generate_image_from_scratch(std::string name,
IrrlichtDevice *device)
{
/*dstream<<"INFO: generate_image_from_scratch(): "
/*infostream<<"generate_image_from_scratch(): "
"\""<<name<<"\""<<std::endl;*/
video::IVideoDriver* driver = device->getVideoDriver();
@ -712,7 +713,7 @@ video::IImage* generate_image_from_scratch(std::string name,
}
}
/*dstream<<"INFO: generate_image_from_scratch(): "
/*infostream<<"generate_image_from_scratch(): "
<<"last_separator_position="<<last_separator_position
<<std::endl;*/
@ -725,7 +726,7 @@ video::IImage* generate_image_from_scratch(std::string name,
{
// Construct base name
base_image_name = name.substr(0, last_separator_position);
/*dstream<<"INFO: generate_image_from_scratch(): Calling itself recursively"
/*infostream<<"generate_image_from_scratch(): Calling itself recursively"
" to get base image of \""<<name<<"\" = \""
<<base_image_name<<"\""<<std::endl;*/
baseimg = generate_image_from_scratch(base_image_name, device);
@ -737,12 +738,12 @@ video::IImage* generate_image_from_scratch(std::string name,
*/
std::string last_part_of_name = name.substr(last_separator_position+1);
//dstream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;
//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;
// Generate image according to part of name
if(generate_image(last_part_of_name, baseimg, device) == false)
{
dstream<<"INFO: generate_image_from_scratch(): "
infostream<<"generate_image_from_scratch(): "
"failed to generate \""<<last_part_of_name<<"\""
<<std::endl;
return NULL;
@ -762,20 +763,20 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
// A normal texture; load it from a file
std::string path = getTexturePath(part_of_name.c_str());
/*dstream<<"INFO: generate_image(): Loading path \""<<path
/*infostream<<"generate_image(): Loading path \""<<path
<<"\""<<std::endl;*/
video::IImage *image = driver->createImageFromFile(path.c_str());
if(image == NULL)
{
dstream<<"WARNING: generate_image(): Could not load image \""
infostream<<"generate_image(): Could not load image \""
<<part_of_name<<"\" from path \""<<path<<"\""
<<" while building texture"<<std::endl;
//return false;
dstream<<"WARNING: generate_image(): Creating a dummy"
infostream<<"generate_image(): Creating a dummy"
<<" image for \""<<part_of_name<<"\""<<std::endl;
// Just create a dummy image
@ -800,7 +801,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
// If base image is NULL, load as base.
if(baseimg == NULL)
{
//dstream<<"INFO: Setting "<<part_of_name<<" as base"<<std::endl;
//infostream<<"Setting "<<part_of_name<<" as base"<<std::endl;
/*
Copy it this way to get an alpha channel.
Otherwise images with alpha cannot be blitted on
@ -814,7 +815,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
// Else blit on base.
else
{
//dstream<<"INFO: Blitting "<<part_of_name<<" on base"<<std::endl;
//infostream<<"Blitting "<<part_of_name<<" on base"<<std::endl;
// Size of the copied area
core::dimension2d<u32> dim = image->getDimension();
//core::dimension2d<u32> dim(16,16);
@ -835,7 +836,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
// A special texture modification
dstream<<"INFO: generate_image(): generating special "
infostream<<"generate_image(): generating special "
<<"modification \""<<part_of_name<<"\""
<<std::endl;
@ -858,7 +859,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg == NULL)
{
dstream<<"WARNING: generate_image(): baseimg==NULL "
infostream<<"generate_image(): baseimg==NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -952,7 +953,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
sf.next(":");
u32 w0 = stoi(sf.next("x"));
u32 h0 = stoi(sf.next(":"));
dstream<<"INFO: combined w="<<w0<<" h="<<h0<<std::endl;
infostream<<"combined w="<<w0<<" h="<<h0<<std::endl;
core::dimension2d<u32> dim(w0,h0);
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
while(sf.atend() == false)
@ -960,7 +961,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
u32 x = stoi(sf.next(","));
u32 y = stoi(sf.next("="));
std::string filename = sf.next(":");
dstream<<"INFO: Adding \""<<filename
infostream<<"Adding \""<<filename
<<"\" to combined ("<<x<<","<<y<<")"
<<std::endl;
video::IImage *img = driver->createImageFromFile(
@ -968,7 +969,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
if(img)
{
core::dimension2d<u32> dim = img->getDimension();
dstream<<"INFO: Size "<<dim.Width
infostream<<"Size "<<dim.Width
<<"x"<<dim.Height<<std::endl;
core::position2d<s32> pos_base(x, y);
video::IImage *img2 =
@ -983,7 +984,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
}
else
{
dstream<<"WARNING: img==NULL"<<std::endl;
infostream<<"img==NULL"<<std::endl;
}
}
}
@ -995,7 +996,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg == NULL)
{
dstream<<"WARNING: generate_image(): baseimg==NULL "
infostream<<"generate_image(): baseimg==NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -1015,7 +1016,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg != NULL)
{
dstream<<"WARNING: generate_image(): baseimg!=NULL "
infostream<<"generate_image(): baseimg!=NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -1025,14 +1026,14 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
std::string path = getTexturePath(filename.c_str());
dstream<<"INFO: generate_image(): Loading path \""<<path
infostream<<"generate_image(): Loading path \""<<path
<<"\""<<std::endl;
video::IImage *image = driver->createImageFromFile(path.c_str());
if(image == NULL)
{
dstream<<"WARNING: generate_image(): Loading path \""
infostream<<"generate_image(): Loading path \""
<<path<<"\" failed"<<std::endl;
}
else
@ -1062,7 +1063,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg != NULL)
{
dstream<<"WARNING: generate_image(): baseimg!=NULL "
infostream<<"generate_image(): baseimg!=NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -1076,14 +1077,14 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
std::string path = getTexturePath(filename.c_str());
dstream<<"INFO: generate_image(): Loading path \""<<path
infostream<<"generate_image(): Loading path \""<<path
<<"\""<<std::endl;
video::IImage *image = driver->createImageFromFile(path.c_str());
if(image == NULL)
{
dstream<<"WARNING: generate_image(): Loading path \""
infostream<<"generate_image(): Loading path \""
<<path<<"\" failed"<<std::endl;
}
else
@ -1117,7 +1118,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg != NULL)
{
dstream<<"WARNING: generate_image(): baseimg!=NULL "
infostream<<"generate_image(): baseimg!=NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -1134,14 +1135,14 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
std::string path = getTexturePath(filename.c_str());
dstream<<"INFO: generate_image(): Loading path \""<<path
infostream<<"generate_image(): Loading path \""<<path
<<"\""<<std::endl;
video::IImage *image = driver->createImageFromFile(path.c_str());
if(image == NULL)
{
dstream<<"WARNING: generate_image(): Loading path \""
infostream<<"generate_image(): Loading path \""
<<path<<"\" failed"<<std::endl;
}
else
@ -1180,7 +1181,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
{
if(baseimg != NULL)
{
dstream<<"WARNING: generate_image(): baseimg!=NULL "
infostream<<"generate_image(): baseimg!=NULL "
<<"for part_of_name=\""<<part_of_name
<<"\", cancelling."<<std::endl;
return false;
@ -1198,7 +1199,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
if(driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false)
{
dstream<<"WARNING: generate_image(): EVDF_RENDER_TO_TARGET"
infostream<<"generate_image(): EVDF_RENDER_TO_TARGET"
" not supported. Creating fallback image"<<std::endl;
baseimg = generate_image_from_scratch(
imagename_top, device);
@ -1207,7 +1208,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
u32 w0 = 64;
u32 h0 = 64;
//dstream<<"INFO: inventorycube w="<<w0<<" h="<<h0<<std::endl;
//infostream<<"inventorycube w="<<w0<<" h="<<h0<<std::endl;
core::dimension2d<u32> dim(w0,h0);
// Generate images for the faces of the cube
@ -1309,7 +1310,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
}
else
{
dstream<<"WARNING: generate_image(): Invalid "
infostream<<"generate_image(): Invalid "
" modification: \""<<part_of_name<<"\""<<std::endl;
}
}

View File

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gettime.h"
#include "sha1.h"
#include "base64.h"
#include "log.h"
TimeTaker::TimeTaker(const char *name, u32 *result)
{
@ -47,7 +48,7 @@ u32 TimeTaker::stop(bool quiet)
else
{
if(quiet == false)
std::cout<<m_name<<" took "<<dtime<<"ms"<<std::endl;
infostream<<m_name<<" took "<<dtime<<"ms"<<std::endl;
}
m_running = false;
return dtime;
@ -156,6 +157,21 @@ void mysrand(unsigned seed)
next = seed;
}
int myrand_range(int min, int max)
{
if(max-min > MYRAND_MAX)
{
errorstream<<"WARNING: myrand_range: max-min > MYRAND_MAX"<<std::endl;
assert(0);
}
if(min > max)
{
assert(0);
return max;
}
return (myrand()%(max-min+1))+min;
}
#ifndef SERVER
// Sets the color of all vertices in the mesh
void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)

View File

@ -1230,20 +1230,7 @@ int myrand(void);
void mysrand(unsigned seed);
#define MYRAND_MAX 32767
inline int myrand_range(int min, int max)
{
if(max-min > MYRAND_MAX)
{
dstream<<"WARNING: myrand_range: max-min > MYRAND_MAX"<<std::endl;
assert(0);
}
if(min > max)
{
assert(0);
return max;
}
return (myrand()%(max-min+1))+min;
}
int myrand_range(int min, int max);
/*
Miscellaneous functions