|
|
@@ -1,6 +1,6 @@
|
|
|
#include "Game.h"
|
|
|
|
|
|
-#include <Datei.h>
|
|
|
+#include <File.h>
|
|
|
#include <Logging.h>
|
|
|
|
|
|
#include "Chat.h"
|
|
|
@@ -21,7 +21,7 @@
|
|
|
#include "UIController.h"
|
|
|
#include "WorldGenerator.h"
|
|
|
#include "WorldLoader.h"
|
|
|
-#include "Zeit.h"
|
|
|
+#include "Timer.h"
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
|
|
@@ -67,13 +67,13 @@ Game::Game(Framework::Text name, Framework::Text worldsDir)
|
|
|
typeRegistry->registerType(
|
|
|
ItemTypeNameFactory::TYPE_ID, itemTypeNameFactory);
|
|
|
|
|
|
- if (!DateiExistiert(path)) DateiPfadErstellen(path + "/");
|
|
|
- Datei d;
|
|
|
- d.setDatei(path + "/eid");
|
|
|
- if (d.existiert())
|
|
|
+ if (!FileExists(path)) FilePathCreate(path + "/");
|
|
|
+ File d;
|
|
|
+ d.setFile(path + "/eid");
|
|
|
+ if (d.exists())
|
|
|
{
|
|
|
- d.open(Datei::Style::lesen);
|
|
|
- d.lese((char*)&nextEntityId, 4);
|
|
|
+ d.open(File::Style::read);
|
|
|
+ d.read((char*)&nextEntityId, 4);
|
|
|
d.close();
|
|
|
}
|
|
|
start();
|
|
|
@@ -150,9 +150,9 @@ void Game::initialize()
|
|
|
}
|
|
|
});
|
|
|
validator->release();
|
|
|
- Framework::Logging::info() << "Loaded " << blockTypeArray.getEintragAnzahl()
|
|
|
+ Framework::Logging::info() << "Loaded " << blockTypeArray.getEntryCount()
|
|
|
<< " block types from data/blocks";
|
|
|
- blockTypes = new BlockType*[2 + blockTypeArray.getEintragAnzahl()];
|
|
|
+ blockTypes = new BlockType*[2 + blockTypeArray.getEntryCount()];
|
|
|
blockTypes[0] = new NoBlockBlockType(
|
|
|
dynamic_cast<Block*>(NoBlock::INSTANCE.getThis()),
|
|
|
"__not_yet_generated");
|
|
|
@@ -205,10 +205,10 @@ void Game::initialize()
|
|
|
}
|
|
|
});
|
|
|
validator->release();
|
|
|
- Framework::Logging::info() << "Loaded " << itemTypeArray.getEintragAnzahl()
|
|
|
+ Framework::Logging::info() << "Loaded " << itemTypeArray.getEntryCount()
|
|
|
<< " item types from data/items";
|
|
|
itemTypes
|
|
|
- = new ItemType*[blockTypeCount + itemTypeArray.getEintragAnzahl()];
|
|
|
+ = new ItemType*[blockTypeCount + itemTypeArray.getEntryCount()];
|
|
|
itemTypes[0] = new PlayerHandItemType();
|
|
|
itemTypeCount = 1;
|
|
|
for (int i = 0; i < blockTypeCount; i++)
|
|
|
@@ -266,9 +266,9 @@ void Game::initialize()
|
|
|
});
|
|
|
validator->release();
|
|
|
Framework::Logging::info()
|
|
|
- << "Loaded " << entityTypeArray.getEintragAnzahl()
|
|
|
+ << "Loaded " << entityTypeArray.getEntryCount()
|
|
|
<< " entity types from data/entities";
|
|
|
- entityTypes = new EntityType*[2 + entityTypeArray.getEintragAnzahl()];
|
|
|
+ entityTypes = new EntityType*[2 + entityTypeArray.getEntryCount()];
|
|
|
entityTypes[0] = new PlayerEntityType();
|
|
|
entityTypes[1] = new ItemEntityType();
|
|
|
entityTypeCount = 2;
|
|
|
@@ -343,7 +343,7 @@ void Game::initialize()
|
|
|
multiblockStructureTypes[0] = new MultiblockTreeStructureType();
|
|
|
multiblockStructureTypeCount = 1;
|
|
|
// save syntax info
|
|
|
- Framework::DateiRemove("data/syntax");
|
|
|
+ Framework::FileRemove("data/syntax");
|
|
|
// typeRegistry->writeSyntaxInfo("data/syntax");
|
|
|
|
|
|
validator
|
|
|
@@ -351,11 +351,11 @@ void Game::initialize()
|
|
|
->addAcceptedTypeInArray(typeRegistry->getValidator<BlockType>())
|
|
|
->finishArray();
|
|
|
Framework::JSON::JSONObject* schema = validator->getJsonSchema();
|
|
|
- Framework::Datei syntaxFile;
|
|
|
- syntaxFile.setDatei("data/syntax/schema/blocks.json");
|
|
|
- syntaxFile.erstellen();
|
|
|
- syntaxFile.open(Framework::Datei::Style::schreiben);
|
|
|
- syntaxFile.schreibe(schema->toString(), schema->toString().getLength());
|
|
|
+ Framework::File syntaxFile;
|
|
|
+ syntaxFile.setFile("data/syntax/schema/blocks.json");
|
|
|
+ syntaxFile.create();
|
|
|
+ syntaxFile.open(Framework::File::Style::write);
|
|
|
+ syntaxFile.write(schema->toString(), schema->toString().getLength());
|
|
|
syntaxFile.close();
|
|
|
schema->release();
|
|
|
validator->release();
|
|
|
@@ -365,10 +365,10 @@ void Game::initialize()
|
|
|
->addAcceptedTypeInArray(typeRegistry->getValidator<ItemType>())
|
|
|
->finishArray();
|
|
|
schema = validator->getJsonSchema();
|
|
|
- syntaxFile.setDatei("data/syntax/schema/items.json");
|
|
|
- syntaxFile.erstellen();
|
|
|
- syntaxFile.open(Framework::Datei::Style::schreiben);
|
|
|
- syntaxFile.schreibe(schema->toString(), schema->toString().getLength());
|
|
|
+ syntaxFile.setFile("data/syntax/schema/items.json");
|
|
|
+ syntaxFile.create();
|
|
|
+ syntaxFile.open(Framework::File::Style::write);
|
|
|
+ syntaxFile.write(schema->toString(), schema->toString().getLength());
|
|
|
syntaxFile.close();
|
|
|
schema->release();
|
|
|
validator->release();
|
|
|
@@ -377,10 +377,10 @@ void Game::initialize()
|
|
|
->addAcceptedTypeInArray(typeRegistry->getValidator<EntityType>())
|
|
|
->finishArray();
|
|
|
schema = validator->getJsonSchema();
|
|
|
- syntaxFile.setDatei("data/syntax/schema/entities.json");
|
|
|
- syntaxFile.erstellen();
|
|
|
- syntaxFile.open(Framework::Datei::Style::schreiben);
|
|
|
- syntaxFile.schreibe(schema->toString(), schema->toString().getLength());
|
|
|
+ syntaxFile.setFile("data/syntax/schema/entities.json");
|
|
|
+ syntaxFile.create();
|
|
|
+ syntaxFile.open(Framework::File::Style::write);
|
|
|
+ syntaxFile.write(schema->toString(), schema->toString().getLength());
|
|
|
syntaxFile.close();
|
|
|
schema->release();
|
|
|
validator->release();
|
|
|
@@ -402,13 +402,13 @@ void Game::initialize()
|
|
|
|
|
|
void Game::thread()
|
|
|
{
|
|
|
- ZeitMesser waitForLock;
|
|
|
- ZeitMesser removeOldClients;
|
|
|
- ZeitMesser clientReply;
|
|
|
- ZeitMesser removeOldChunks;
|
|
|
- ZeitMesser m;
|
|
|
- ZeitMesser total;
|
|
|
- total.messungStart();
|
|
|
+ Timer waitForLock;
|
|
|
+ Timer removeOldClients;
|
|
|
+ Timer clientReply;
|
|
|
+ Timer removeOldChunks;
|
|
|
+ Timer m;
|
|
|
+ Timer total;
|
|
|
+ total.measureStart();
|
|
|
double tickTime = 0;
|
|
|
double sleepTime = 0;
|
|
|
int nextTimeSync = MAX_TICKS_PER_SECOND;
|
|
|
@@ -421,10 +421,10 @@ void Game::thread()
|
|
|
questManager->processEvent(new QuestEventTimeUpdate());
|
|
|
ticktToNextUpdate = MAX_TICKS_PER_SECOND * 5;
|
|
|
}
|
|
|
- m.messungStart();
|
|
|
+ m.measureStart();
|
|
|
ticker->nextTick();
|
|
|
actionsCs.lock();
|
|
|
- while (actions.getEintragAnzahl() > 0)
|
|
|
+ while (actions.getEntryCount() > 0)
|
|
|
{
|
|
|
actions.get(0)();
|
|
|
actions.remove(0);
|
|
|
@@ -432,11 +432,11 @@ void Game::thread()
|
|
|
actionsCs.unlock();
|
|
|
Array<int> removed;
|
|
|
double waitTotal = 0;
|
|
|
- waitForLock.messungStart();
|
|
|
+ waitForLock.measureStart();
|
|
|
cs.lock();
|
|
|
- waitForLock.messungEnde();
|
|
|
+ waitForLock.measureEnd();
|
|
|
waitTotal += waitForLock.getSekunden();
|
|
|
- removeOldClients.messungStart();
|
|
|
+ removeOldClients.measureStart();
|
|
|
int index = 0;
|
|
|
nextTimeSync--;
|
|
|
for (auto player : *clients)
|
|
|
@@ -449,11 +449,11 @@ void Game::thread()
|
|
|
Framework::Text(player->zEntity()->getName())
|
|
|
+ " left the game.",
|
|
|
Chat::CHANNEL_INFO);
|
|
|
- Datei pFile;
|
|
|
- pFile.setDatei(path + "/player/"
|
|
|
+ File pFile;
|
|
|
+ pFile.setFile(path + "/player/"
|
|
|
+ getPlayerId(player->zEntity()->getName()));
|
|
|
- pFile.erstellen();
|
|
|
- if (pFile.open(Datei::Style::schreiben))
|
|
|
+ pFile.create();
|
|
|
+ if (pFile.open(File::Style::write))
|
|
|
{
|
|
|
zEntityType(EntityTypeEnum::PLAYER)
|
|
|
->saveEntity(player->zEntity(), &pFile);
|
|
|
@@ -498,26 +498,26 @@ void Game::thread()
|
|
|
}
|
|
|
for (auto i : removed)
|
|
|
clients->remove(i);
|
|
|
- removeOldClients.messungEnde();
|
|
|
+ removeOldClients.measureEnd();
|
|
|
for (Dimension* dim : *dimensions)
|
|
|
{
|
|
|
dim->tick();
|
|
|
}
|
|
|
cs.unlock();
|
|
|
- clientReply.messungStart();
|
|
|
+ clientReply.measureStart();
|
|
|
for (auto client : *clients)
|
|
|
client->reply();
|
|
|
- clientReply.messungEnde();
|
|
|
- waitForLock.messungStart();
|
|
|
+ clientReply.measureEnd();
|
|
|
+ waitForLock.measureStart();
|
|
|
cs.lock();
|
|
|
- waitForLock.messungEnde();
|
|
|
+ waitForLock.measureEnd();
|
|
|
waitTotal += waitForLock.getSekunden();
|
|
|
- removeOldChunks.messungStart();
|
|
|
+ removeOldChunks.measureStart();
|
|
|
for (auto dim : *dimensions)
|
|
|
dim->removeOldChunks();
|
|
|
- removeOldChunks.messungEnde();
|
|
|
+ removeOldChunks.measureEnd();
|
|
|
cs.unlock();
|
|
|
- m.messungEnde();
|
|
|
+ m.measureEnd();
|
|
|
double sec = m.getSekunden();
|
|
|
tickCounter++;
|
|
|
totalTickTime += sec;
|
|
|
@@ -526,8 +526,8 @@ void Game::thread()
|
|
|
{
|
|
|
Sleep((int)(sleepTime * 1000));
|
|
|
}
|
|
|
- total.messungEnde();
|
|
|
- total.messungStart();
|
|
|
+ total.measureEnd();
|
|
|
+ total.measureStart();
|
|
|
tickTime = total.getSekunden();
|
|
|
totalTime += tickTime;
|
|
|
if (totalTime >= 1)
|
|
|
@@ -562,7 +562,7 @@ void Game::thread()
|
|
|
void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
|
{
|
|
|
char type;
|
|
|
- zRequest->lese(&type, 1);
|
|
|
+ zRequest->read(&type, 1);
|
|
|
NetworkMessage* response = new NetworkMessage();
|
|
|
switch (type)
|
|
|
{
|
|
|
@@ -592,7 +592,7 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
|
case 3: // entity
|
|
|
{
|
|
|
int id;
|
|
|
- zRequest->lese((char*)&id, 4);
|
|
|
+ zRequest->read((char*)&id, 4);
|
|
|
for (Dimension* dim : *dimensions)
|
|
|
{
|
|
|
Entity* entity = dim->zEntity(id);
|
|
|
@@ -607,22 +607,22 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
|
case 4:
|
|
|
{ // inventory
|
|
|
bool isEntity;
|
|
|
- zRequest->lese((char*)&isEntity, 1);
|
|
|
+ zRequest->read((char*)&isEntity, 1);
|
|
|
Inventory* target;
|
|
|
if (isEntity)
|
|
|
{
|
|
|
int id;
|
|
|
- zRequest->lese((char*)&id, 4);
|
|
|
+ zRequest->read((char*)&id, 4);
|
|
|
target = zEntity(id);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
int dim;
|
|
|
Vec3<int> pos;
|
|
|
- zRequest->lese((char*)&dim, 4);
|
|
|
- zRequest->lese((char*)&pos.x, 4);
|
|
|
- zRequest->lese((char*)&pos.y, 4);
|
|
|
- zRequest->lese((char*)&pos.z, 4);
|
|
|
+ zRequest->read((char*)&dim, 4);
|
|
|
+ zRequest->read((char*)&pos.x, 4);
|
|
|
+ zRequest->read((char*)&pos.y, 4);
|
|
|
+ zRequest->read((char*)&pos.z, 4);
|
|
|
target = zBlockAt(pos, dim, 0);
|
|
|
}
|
|
|
if (target)
|
|
|
@@ -632,7 +632,7 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
|
case 5:
|
|
|
{ // crafting uiml request
|
|
|
int id;
|
|
|
- zRequest->lese((char*)&id, 4);
|
|
|
+ zRequest->read((char*)&id, 4);
|
|
|
Framework::XML::Element* uiml = recipies->getCrafingUIML(id);
|
|
|
Text dialogId = "crafting_";
|
|
|
dialogId += id;
|
|
|
@@ -648,7 +648,7 @@ void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
|
|
|
case 7: // other dimension
|
|
|
{
|
|
|
int dimensionId;
|
|
|
- zRequest->lese((char*)&dimensionId, 4);
|
|
|
+ zRequest->read((char*)&dimensionId, 4);
|
|
|
Dimension* dim = zDimension(dimensionId);
|
|
|
if (dim)
|
|
|
{
|
|
|
@@ -738,11 +738,11 @@ GameClient* Game::addPlayer(FCKlient* client, Framework::Text name)
|
|
|
{
|
|
|
cs.lock();
|
|
|
int id = playerRegister->getPlayerId(name);
|
|
|
- Datei pFile;
|
|
|
- pFile.setDatei(path + "/player/" + id);
|
|
|
+ File pFile;
|
|
|
+ pFile.setFile(path + "/player/" + id);
|
|
|
Player* player;
|
|
|
bool isNew = 0;
|
|
|
- if (!pFile.existiert() || !pFile.open(Datei::Style::lesen))
|
|
|
+ if (!pFile.exists() || !pFile.open(File::Style::read))
|
|
|
{
|
|
|
player = (Player*)zEntityType(EntityTypeEnum::PLAYER)
|
|
|
->createEntityAt(
|
|
|
@@ -784,12 +784,12 @@ GameClient* Game::addPlayer(FCKlient* client, Framework::Text name)
|
|
|
// subscribe the new player as an observer of the new chunk
|
|
|
Dimension* dim = zDimension(player->getDimensionId());
|
|
|
InMemoryBuffer* buffer = new InMemoryBuffer();
|
|
|
- buffer->schreibe("\0", 1);
|
|
|
- Punkt center = getChunkCenter(
|
|
|
+ buffer->write("\0", 1);
|
|
|
+ Point center = getChunkCenter(
|
|
|
(int)player->getPosition().x, (int)player->getPosition().y);
|
|
|
- buffer->schreibe((char*)¢er.x, 4);
|
|
|
- buffer->schreibe((char*)¢er.y, 4);
|
|
|
- buffer->schreibe("\0", 1);
|
|
|
+ buffer->write((char*)¢er.x, 4);
|
|
|
+ buffer->write((char*)¢er.y, 4);
|
|
|
+ buffer->write("\0", 1);
|
|
|
dim->api(buffer, 0, player);
|
|
|
buffer->release();
|
|
|
while (!dim->zChunk(getChunkCenter(
|
|
|
@@ -886,7 +886,7 @@ void Game::spawnItem(
|
|
|
Dimension* dim = zDimension(dimensionId);
|
|
|
if (dim)
|
|
|
{
|
|
|
- Punkt center = Game::getChunkCenter(
|
|
|
+ Point center = Game::getChunkCenter(
|
|
|
(int)itemEntity->getLocation().x, (int)itemEntity->getLocation().y);
|
|
|
dim->zChunk(center)
|
|
|
->onEntityEnters(itemEntity, 0);
|
|
|
@@ -943,15 +943,15 @@ Dimension* Game::zDimension(int id) const
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-Framework::Punkt Game::getChunkCenter(int x, int y)
|
|
|
+Framework::Point Game::getChunkCenter(int x, int y)
|
|
|
{
|
|
|
- return Punkt(((x < 0 ? x + 1 : x) / CHUNK_SIZE) * CHUNK_SIZE
|
|
|
+ return Point(((x < 0 ? x + 1 : x) / CHUNK_SIZE) * CHUNK_SIZE
|
|
|
+ (x < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2,
|
|
|
((y < 0 ? y + 1 : y) / CHUNK_SIZE) * CHUNK_SIZE
|
|
|
+ (y < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2);
|
|
|
}
|
|
|
|
|
|
-Area Game::getChunckArea(Punkt center) const
|
|
|
+Area Game::getChunckArea(Point center) const
|
|
|
{
|
|
|
return {center.x - CHUNK_SIZE / 2,
|
|
|
center.y - CHUNK_SIZE / 2,
|
|
|
@@ -974,10 +974,10 @@ void Game::requestArea(Area area)
|
|
|
void Game::save() const
|
|
|
{
|
|
|
questManager->saveQuests();
|
|
|
- Datei d;
|
|
|
- d.setDatei(path + "/eid");
|
|
|
- d.open(Datei::Style::schreiben);
|
|
|
- d.schreibe((char*)&nextEntityId, 4);
|
|
|
+ File d;
|
|
|
+ d.setFile(path + "/eid");
|
|
|
+ d.open(File::Style::write);
|
|
|
+ d.write((char*)&nextEntityId, 4);
|
|
|
d.close();
|
|
|
playerRegister->save();
|
|
|
for (auto dim : *dimensions)
|
|
|
@@ -989,7 +989,7 @@ void Game::save() const
|
|
|
void Game::requestStop()
|
|
|
{
|
|
|
stop = 1;
|
|
|
- warteAufThread(1000000);
|
|
|
+ waitForThread(1000000);
|
|
|
}
|
|
|
|
|
|
void Game::addDimension(Dimension* d)
|
|
|
@@ -1129,7 +1129,7 @@ int Game::getTicksPerSecond() const
|
|
|
|
|
|
int Game::getPlayerCount() const
|
|
|
{
|
|
|
- return clients->getEintragAnzahl();
|
|
|
+ return clients->getEntryCount();
|
|
|
}
|
|
|
|
|
|
int Game::getChunkCount() const
|
|
|
@@ -1162,7 +1162,7 @@ int Game::getEntityTypeId(const char* name) const
|
|
|
for (int i = 0; i < entityTypeCount; i++)
|
|
|
{
|
|
|
if (entityTypes[i]
|
|
|
- && Framework::Text(entityTypes[i]->getName()).istGleich(name))
|
|
|
+ && Framework::Text(entityTypes[i]->getName()).isEqual(name))
|
|
|
{
|
|
|
return i;
|
|
|
}
|
|
|
@@ -1177,7 +1177,7 @@ int Game::getBlockTypeId(const char* name) const
|
|
|
for (int i = 0; i < blockTypeCount; i++)
|
|
|
{
|
|
|
if (blockTypes[i]
|
|
|
- && Framework::Text(blockTypes[i]->getName()).istGleich(name))
|
|
|
+ && Framework::Text(blockTypes[i]->getName()).isEqual(name))
|
|
|
{
|
|
|
return i;
|
|
|
}
|
|
|
@@ -1192,7 +1192,7 @@ int Game::getItemTypeId(const char* name) const
|
|
|
for (int i = 0; i < itemTypeCount; i++)
|
|
|
{
|
|
|
if (itemTypes[i]
|
|
|
- && Framework::Text(itemTypes[i]->getName()).istGleich(name))
|
|
|
+ && Framework::Text(itemTypes[i]->getName()).isEqual(name))
|
|
|
{
|
|
|
return i;
|
|
|
}
|