|
@@ -1,5 +1,7 @@
|
|
#include "Game.h"
|
|
#include "Game.h"
|
|
|
|
|
|
|
|
+#include <Logging.h>
|
|
|
|
+
|
|
#include "AddEntityUpdate.h"
|
|
#include "AddEntityUpdate.h"
|
|
#include "AsynchronCall.h"
|
|
#include "AsynchronCall.h"
|
|
#include "Chat.h"
|
|
#include "Chat.h"
|
|
@@ -25,6 +27,9 @@
|
|
|
|
|
|
using namespace Framework;
|
|
using namespace Framework;
|
|
|
|
|
|
|
|
+Framework::ConsoleHandler* Game::consoleHandler = 0;
|
|
|
|
+Framework::InputLine* Game::consoleInput = 0;
|
|
|
|
+
|
|
GameClient::GameClient(Player* zPlayer, FCKlient* client)
|
|
GameClient::GameClient(Player* zPlayer, FCKlient* client)
|
|
: Thread(),
|
|
: Thread(),
|
|
zPlayer(zPlayer),
|
|
zPlayer(zPlayer),
|
|
@@ -158,7 +163,7 @@ void GameClient::reply()
|
|
other.unlock();
|
|
other.unlock();
|
|
if (first)
|
|
if (first)
|
|
{
|
|
{
|
|
- foreground.lock();
|
|
|
|
|
|
+ foreground.lock();
|
|
int id = zPlayer->getId();
|
|
int id = zPlayer->getId();
|
|
client->zForegroundWriter()->schreibe(
|
|
client->zForegroundWriter()->schreibe(
|
|
(char*)&Message::POSITION_UPDATE, 1);
|
|
(char*)&Message::POSITION_UPDATE, 1);
|
|
@@ -231,8 +236,9 @@ void GameClient::sendResponse(NetworkMessage* response)
|
|
if (foregroundQueue.getEintragAnzahl() > 100)
|
|
if (foregroundQueue.getEintragAnzahl() > 100)
|
|
{
|
|
{
|
|
queueCs.unlock();
|
|
queueCs.unlock();
|
|
- std::cout << "WARNING: Game paused because nework connection to "
|
|
|
|
- << zPlayer->getName() << " is to slow.\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "Game paused because nework connection to "
|
|
|
|
+ << zPlayer->getName() << " is to slow.";
|
|
ZeitMesser m;
|
|
ZeitMesser m;
|
|
m.messungStart();
|
|
m.messungStart();
|
|
while (foregroundQueue.getEintragAnzahl() > 0)
|
|
while (foregroundQueue.getEintragAnzahl() > 0)
|
|
@@ -241,8 +247,8 @@ void GameClient::sendResponse(NetworkMessage* response)
|
|
emptyForegroundQueueSync.wait(100);
|
|
emptyForegroundQueueSync.wait(100);
|
|
}
|
|
}
|
|
m.messungEnde();
|
|
m.messungEnde();
|
|
- std::cout << "WARNING: Game resumed after " << m.getSekunden()
|
|
|
|
- << " seconds.\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "Game resumed after " << m.getSekunden() << " seconds.";
|
|
queueCs.lock();
|
|
queueCs.lock();
|
|
}
|
|
}
|
|
foregroundQueue.add(response);
|
|
foregroundQueue.add(response);
|
|
@@ -411,7 +417,7 @@ void Game::initialize()
|
|
{
|
|
{
|
|
// TODO load mods libraries
|
|
// TODO load mods libraries
|
|
// load block types
|
|
// load block types
|
|
- std::cout << "Loading block types\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Loading block types";
|
|
Framework::Array<BlockType*> blockTypeArray;
|
|
Framework::Array<BlockType*> blockTypeArray;
|
|
Framework::JSON::Validator::JSONValidator* validator
|
|
Framework::JSON::Validator::JSONValidator* validator
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
@@ -428,7 +434,7 @@ void Game::initialize()
|
|
for (Framework::JSON::Validator::JSONValidationResult* result :
|
|
for (Framework::JSON::Validator::JSONValidationResult* result :
|
|
validationResults)
|
|
validationResults)
|
|
{
|
|
{
|
|
- result->printInvalidInfo();
|
|
|
|
|
|
+ Framework::Logging::error() << result->getInvalidInfo();
|
|
}
|
|
}
|
|
if (validParts)
|
|
if (validParts)
|
|
{
|
|
{
|
|
@@ -445,8 +451,8 @@ void Game::initialize()
|
|
}
|
|
}
|
|
});
|
|
});
|
|
validator->release();
|
|
validator->release();
|
|
- std::cout << "Loaded " << blockTypeArray.getEintragAnzahl()
|
|
|
|
- << " block types from data/blocks\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Loaded " << blockTypeArray.getEintragAnzahl()
|
|
|
|
+ << " block types from data/blocks";
|
|
blockTypes = new BlockType*[2 + blockTypeArray.getEintragAnzahl()];
|
|
blockTypes = new BlockType*[2 + blockTypeArray.getEintragAnzahl()];
|
|
blockTypes[0]
|
|
blockTypes[0]
|
|
= new NoBlockBlockType(&NoBlock::INSTANCE, "__not_yet_generated");
|
|
= new NoBlockBlockType(&NoBlock::INSTANCE, "__not_yet_generated");
|
|
@@ -460,7 +466,7 @@ void Game::initialize()
|
|
{
|
|
{
|
|
blockTypes[i]->setTypeId(i);
|
|
blockTypes[i]->setTypeId(i);
|
|
}
|
|
}
|
|
- std::cout << "Loading item types\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Loading item types";
|
|
Framework::Array<ItemType*> itemTypeArray;
|
|
Framework::Array<ItemType*> itemTypeArray;
|
|
validator
|
|
validator
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
@@ -477,7 +483,7 @@ void Game::initialize()
|
|
for (Framework::JSON::Validator::JSONValidationResult* result :
|
|
for (Framework::JSON::Validator::JSONValidationResult* result :
|
|
validationResults)
|
|
validationResults)
|
|
{
|
|
{
|
|
- result->printInvalidInfo();
|
|
|
|
|
|
+ Framework::Logging::error() << result->getInvalidInfo();
|
|
}
|
|
}
|
|
if (validParts)
|
|
if (validParts)
|
|
{
|
|
{
|
|
@@ -494,8 +500,8 @@ void Game::initialize()
|
|
}
|
|
}
|
|
});
|
|
});
|
|
validator->release();
|
|
validator->release();
|
|
- std::cout << "Loaded " << itemTypeArray.getEintragAnzahl()
|
|
|
|
- << " item types from data/items\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Loaded " << itemTypeArray.getEintragAnzahl()
|
|
|
|
+ << " item types from data/items";
|
|
itemTypes
|
|
itemTypes
|
|
= new ItemType*[blockTypeCount + itemTypeArray.getEintragAnzahl()];
|
|
= new ItemType*[blockTypeCount + itemTypeArray.getEintragAnzahl()];
|
|
itemTypes[0] = new PlayerHandItemType();
|
|
itemTypes[0] = new PlayerHandItemType();
|
|
@@ -516,7 +522,7 @@ void Game::initialize()
|
|
{
|
|
{
|
|
itemTypes[i]->setTypeId(i);
|
|
itemTypes[i]->setTypeId(i);
|
|
}
|
|
}
|
|
- std::cout << "Loading entity types\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Loading entity types";
|
|
Framework::Array<EntityType*> entityTypeArray;
|
|
Framework::Array<EntityType*> entityTypeArray;
|
|
/* validator
|
|
/* validator
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
= Framework::JSON::Validator::JSONValidator::buildForArray()
|
|
@@ -550,8 +556,9 @@ void Game::initialize()
|
|
}
|
|
}
|
|
});
|
|
});
|
|
validator->release();*/
|
|
validator->release();*/
|
|
- std::cout << "Loaded " << entityTypeArray.getEintragAnzahl()
|
|
|
|
- << " entity types from data/entities\n";
|
|
|
|
|
|
+ Framework::Logging::info()
|
|
|
|
+ << "Loaded " << entityTypeArray.getEintragAnzahl()
|
|
|
|
+ << " entity types from data/entities";
|
|
entityTypes = new EntityType*[2 + entityTypeArray.getEintragAnzahl()];
|
|
entityTypes = new EntityType*[2 + entityTypeArray.getEintragAnzahl()];
|
|
entityTypes[0] = new PlayerEntityType();
|
|
entityTypes[0] = new PlayerEntityType();
|
|
entityTypes[1] = new ItemEntityType();
|
|
entityTypes[1] = new ItemEntityType();
|
|
@@ -573,8 +580,9 @@ void Game::initialize()
|
|
{
|
|
{
|
|
if (blockTypes[i] && !blockTypes[i]->initialize(this))
|
|
if (blockTypes[i] && !blockTypes[i]->initialize(this))
|
|
{
|
|
{
|
|
- std::cout << "ERROR: Could not initialize Block Type '"
|
|
|
|
- << blockTypes[i]->getName() << "'.\n";
|
|
|
|
|
|
+ Framework::Logging::error()
|
|
|
|
+ << "Could not initialize Block Type '"
|
|
|
|
+ << blockTypes[i]->getName() << "'.";
|
|
blockTypes[i]->release();
|
|
blockTypes[i]->release();
|
|
blockTypes[i] = 0;
|
|
blockTypes[i] = 0;
|
|
allInitialized = false;
|
|
allInitialized = false;
|
|
@@ -589,8 +597,9 @@ void Game::initialize()
|
|
{
|
|
{
|
|
if (itemTypes[i] && !itemTypes[i]->initialize(this))
|
|
if (itemTypes[i] && !itemTypes[i]->initialize(this))
|
|
{
|
|
{
|
|
- std::cout << "ERROR: Could not initialize Item Type '"
|
|
|
|
- << itemTypes[i]->getName() << "'.\n";
|
|
|
|
|
|
+ Framework::Logging::error()
|
|
|
|
+ << "Could not initialize Item Type '"
|
|
|
|
+ << itemTypes[i]->getName() << "'.";
|
|
itemTypes[i]->release();
|
|
itemTypes[i]->release();
|
|
itemTypes[i] = 0;
|
|
itemTypes[i] = 0;
|
|
allInitialized = false;
|
|
allInitialized = false;
|
|
@@ -605,8 +614,9 @@ void Game::initialize()
|
|
{
|
|
{
|
|
if (entityTypes[i] && !entityTypes[i]->initialize(this))
|
|
if (entityTypes[i] && !entityTypes[i]->initialize(this))
|
|
{
|
|
{
|
|
- std::cout << "ERROR: Could not initialize Entity Type '"
|
|
|
|
- << entityTypes[i]->getName() << "'.\n";
|
|
|
|
|
|
+ Framework::Logging::error()
|
|
|
|
+ << "Could not initialize Entity Type '"
|
|
|
|
+ << entityTypes[i]->getName() << "'.";
|
|
entityTypes[i]->release();
|
|
entityTypes[i]->release();
|
|
entityTypes[i] = 0;
|
|
entityTypes[i] = 0;
|
|
allInitialized = false;
|
|
allInitialized = false;
|
|
@@ -752,9 +762,10 @@ void Game::thread()
|
|
addDimension(dim);
|
|
addDimension(dim);
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- std::cout << "ERROR: could not create dimension "
|
|
|
|
- << update->getAffectedDimension()
|
|
|
|
- << ". No Factory was provided.\n";
|
|
|
|
|
|
+ Framework::Logging::error()
|
|
|
|
+ << "could not create dimension "
|
|
|
|
+ << update->getAffectedDimension()
|
|
|
|
+ << ". No Factory was provided.";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (zDimension(update->getAffectedDimension()))
|
|
if (zDimension(update->getAffectedDimension()))
|
|
@@ -796,19 +807,19 @@ void Game::thread()
|
|
totalTickTime = 0;
|
|
totalTickTime = 0;
|
|
tickCounter = 0;
|
|
tickCounter = 0;
|
|
totalTime = 0;
|
|
totalTime = 0;
|
|
- std::cout << std::flush; // update info in console
|
|
|
|
}
|
|
}
|
|
else if (sec > 1)
|
|
else if (sec > 1)
|
|
{
|
|
{
|
|
- std::cout << "WARNING: tick needed " << sec
|
|
|
|
- << " seconds. The game will run sower then normal.\n";
|
|
|
|
- std::cout << "waiting: " << waitTotal << "\nremoveOldClients: "
|
|
|
|
- << removeOldClients.getSekunden()
|
|
|
|
- << "\ntickEntities:" << tickEntities.getSekunden()
|
|
|
|
- << "\nworldUpdates: " << worldUpdates.getSekunden()
|
|
|
|
- << "\nclientReply: " << clientReply.getSekunden()
|
|
|
|
- << "\nremoveOldChunks:" << removeOldChunks.getSekunden()
|
|
|
|
- << "\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "tick needed " << sec
|
|
|
|
+ << " seconds. The game will run sower then normal.\n";
|
|
|
|
+ Framework::Logging::trace()
|
|
|
|
+ << "waiting: " << waitTotal
|
|
|
|
+ << "\nremoveOldClients: " << removeOldClients.getSekunden()
|
|
|
|
+ << "\ntickEntities:" << tickEntities.getSekunden()
|
|
|
|
+ << "\nworldUpdates: " << worldUpdates.getSekunden()
|
|
|
|
+ << "\nclientReply: " << clientReply.getSekunden()
|
|
|
|
+ << "\nremoveOldChunks:" << removeOldChunks.getSekunden();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
save();
|
|
save();
|
|
@@ -817,7 +828,7 @@ void Game::thread()
|
|
ticker->exitAndWait();
|
|
ticker->exitAndWait();
|
|
for (Dimension* dim : *dimensions)
|
|
for (Dimension* dim : *dimensions)
|
|
dim->requestStopAndWait();
|
|
dim->requestStopAndWait();
|
|
- std::cout << "Game thread exited\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Game thread exited";
|
|
}
|
|
}
|
|
|
|
|
|
void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
@@ -836,9 +847,10 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
zOrigin->zEntity()->getDimensionId());
|
|
zOrigin->zEntity()->getDimensionId());
|
|
if (!dim)
|
|
if (!dim)
|
|
{
|
|
{
|
|
- std::cout << "ERROR: could not create dimension "
|
|
|
|
- << zOrigin->zEntity()->getDimensionId()
|
|
|
|
- << ". No Factory was provided.\n";
|
|
|
|
|
|
+ Framework::Logging::error()
|
|
|
|
+ << "could not create dimension "
|
|
|
|
+ << zOrigin->zEntity()->getDimensionId()
|
|
|
|
+ << ". No Factory was provided.";
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
addDimension(dim);
|
|
addDimension(dim);
|
|
@@ -923,8 +935,8 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
- std::cout << "received unknown api request in game with type "
|
|
|
|
- << (int)type << "\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "received unknown api request in game with type " << (int)type;
|
|
}
|
|
}
|
|
if (!response->isEmpty())
|
|
if (!response->isEmpty())
|
|
{
|
|
{
|
|
@@ -986,8 +998,9 @@ bool Game::checkPlayer(Framework::Text name, Framework::Text secret)
|
|
return 1;
|
|
return 1;
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- std::cout << "player " << name.getText()
|
|
|
|
- << " tryed to connect with an invalid secret.\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "player " << name.getText()
|
|
|
|
+ << " tryed to connect with an invalid secret.";
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1036,9 +1049,9 @@ GameClient* Game::addPlayer(FCKlient* client, Framework::Text name)
|
|
Dimension* dim = generator->createDimension(player->getDimensionId());
|
|
Dimension* dim = generator->createDimension(player->getDimensionId());
|
|
if (!dim)
|
|
if (!dim)
|
|
{
|
|
{
|
|
- std::cout << "ERROR: could not create dimension "
|
|
|
|
- << (int)player->getDimensionId()
|
|
|
|
- << ". No Factory was provided.\n";
|
|
|
|
|
|
+ Framework::Logging::error() << "could not create dimension "
|
|
|
|
+ << (int)player->getDimensionId()
|
|
|
|
+ << ". No Factory was provided.";
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
@@ -1218,7 +1231,7 @@ void Game::save() const
|
|
for (auto dim : *dimensions)
|
|
for (auto dim : *dimensions)
|
|
dim->save(path);
|
|
dim->save(path);
|
|
chat->save();
|
|
chat->save();
|
|
- std::cout << "Game was saved\n";
|
|
|
|
|
|
+ Framework::Logging::info() << "Game was saved";
|
|
}
|
|
}
|
|
|
|
|
|
void Game::requestStop()
|
|
void Game::requestStop()
|
|
@@ -1394,7 +1407,8 @@ int Game::getBlockTypeId(const char* name) const
|
|
return i;
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- std::cout << "WARNING: no block type with name '" << name << "' found.\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "no block type with name '" << name << "' found.";
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1408,7 +1422,8 @@ int Game::getItemTypeId(const char* name) const
|
|
return i;
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- std::cout << "WARNING: no item type with name '" << name << "' found.\n";
|
|
|
|
|
|
+ Framework::Logging::warning()
|
|
|
|
+ << "no item type with name '" << name << "' found.";
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|