class LogFileConnection
{
std::ofstream outputFile;
public:
LogFileConnection(const char *filename)
{
outputFile.open(filename, std::ios::out | std::ios::app);
if (!outputFile.is_open())
throw FileOpenErrorException(filename);
}
~LogFileConnection()
{
outputFile.close();
}
void Write(const char *message)
{
outputFile << message << std::endl;
}
};
class TextLog
{
LogFileConnection *fileConnection;
LogFileConnection *networkConnection;
public:
TextLog()
{
fileConnection = new LogFileConnection("logfile.txt");
networkConnection = new LogFileConnection("Z:\\RunLogs\\Serverlog.txt");
}
~TextLog()
{
delete fileConnection;
delete networkConnection;
}
void Write(const char *message)
{
if (fileConnection)
fileConnection->Write(message);
if (networkConnection)
networkConnection->Write(message);
}
};
#define LOG(x) { try { TextLog log; log.Write(x); } catch(...) {} }
void World::RemoveAllInvalidGeometry()
{
for(size_t i = 0; i < this->worldObjects.size(); ++i)
if (worldObjects[i] && !worldObjects[i]->HasMaterial())
{
LOG("Removing geometry with null material.");
worldObjects.erase(worldObjects.begin() + i);
--i;
}
}