Game.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. #include "Game.h"
  2. #include "Zeit.h"
  3. #include "Player.h"
  4. #include "OverworldDimension.h"
  5. #include "AddChunkUpdate.h"
  6. #include "NoBlock.h"
  7. #include "AsynchronCall.h"
  8. #include "Entity.h"
  9. #include "AddEntityUpdate.h"
  10. using namespace Framework;
  11. GameClient::GameClient(Player* zPlayer, FCKlient* client)
  12. : ReferenceCounter(),
  13. zPlayer(zPlayer),
  14. client(client),
  15. viewDistance(DEFAULT_VIEW_DISTANCE),
  16. first(1),
  17. online(1),
  18. finished(0)
  19. {
  20. new AsynchronCall("Game Client", [this]()
  21. {
  22. while (online)
  23. {
  24. other.lock();
  25. if (updateQueue.hat(0))
  26. {
  27. WorldUpdate* update = updateQueue.get(0);
  28. updateQueue.remove(0);
  29. other.unlock();
  30. background.lock();
  31. this->client->zBackgroundWriter()->schreibe((char*)&Message::WORLD_UPDATE, 1);
  32. update->writeAndCheck(this->client->zBackgroundWriter());
  33. background.unlock();
  34. update->release();
  35. }
  36. else
  37. {
  38. other.unlock();
  39. updateSync.wait();
  40. }
  41. }
  42. finished = 1;
  43. });
  44. }
  45. GameClient::~GameClient()
  46. {
  47. online = 0;
  48. updateSync.notify();
  49. while (!finished)
  50. Sleep(100);
  51. client->release();
  52. }
  53. void GameClient::sendWorldUpdate(WorldUpdate* update)
  54. {
  55. bool add = 0;
  56. if (zPlayer->getCurrentDimensionId() == update->getAffectedDimension())
  57. {
  58. auto pos = (Vec3<int>)zPlayer->getPosition();
  59. int dist = update->distanceTo(pos.x, pos.y);
  60. if (dist < viewDistance * CHUNK_SIZE)
  61. {
  62. other.lock();
  63. int index = 0;
  64. for (auto update2 : updateQueue)
  65. {
  66. int dist2 = update2->distanceTo(pos.x, pos.y);
  67. if (dist2 > dist)
  68. break;
  69. index++;
  70. }
  71. if (update->getType() == AddChunkUpdateType::ID)
  72. ((AddChunkUpdate*)update)->zChunk()->addView(zPlayer);
  73. updateQueue.add(update, index);
  74. other.unlock();
  75. updateSync.notify();
  76. add = 1;
  77. }
  78. }
  79. if (!add)
  80. update->release();
  81. }
  82. void GameClient::reply()
  83. {
  84. other.lock();
  85. for (auto req : requests)
  86. Game::INSTANCE->api(req, this);
  87. requests.leeren();
  88. other.unlock();
  89. int x = (int)floor(zPlayer->getPosition().x);
  90. int y = (int)floor(zPlayer->getPosition().y);
  91. int d = zPlayer->getCurrentDimensionId();
  92. // send world to client
  93. if (first)
  94. {
  95. foreground.lock();
  96. int id = zPlayer->getId();
  97. client->zForegroundWriter()->schreibe((char*)&Message::POSITION_UPDATE, 1);
  98. client->zForegroundWriter()->schreibe((char*)&id, 4);
  99. foreground.unlock();
  100. first = 0;
  101. Dimension* dim = Game::INSTANCE->zDimension(d);
  102. if (dim)
  103. {
  104. for (int xP = x - CHUNK_SIZE * viewDistance; xP <= x + CHUNK_SIZE * viewDistance; xP += CHUNK_SIZE)
  105. {
  106. for (int yP = y - CHUNK_SIZE * viewDistance; yP <= y + CHUNK_SIZE * viewDistance; yP += CHUNK_SIZE)
  107. {
  108. Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
  109. if (chunk)
  110. sendWorldUpdate(new AddChunkUpdate(dynamic_cast<Chunk*>(chunk->getThis())));
  111. }
  112. }
  113. }
  114. Game::INSTANCE->requestArea({ x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance, x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance, d });
  115. }
  116. else
  117. {
  118. Punkt lastMin = Game::INSTANCE->getChunkCenter((int)floor(lastPos.x) - CHUNK_SIZE * viewDistance, (int)floor(lastPos.y) - CHUNK_SIZE * viewDistance);
  119. Punkt curMin = Game::INSTANCE->getChunkCenter(x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance);
  120. Punkt lastMax = Game::INSTANCE->getChunkCenter((int)floor(lastPos.x) + CHUNK_SIZE * viewDistance, (int)floor(lastPos.y) + CHUNK_SIZE * viewDistance);
  121. Punkt curMax = Game::INSTANCE->getChunkCenter(x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance);
  122. Dimension* dim = Game::INSTANCE->zDimension(d);
  123. if (dim)
  124. {
  125. for (int xP = curMin.x; xP <= curMax.x; xP += CHUNK_SIZE)
  126. {
  127. for (int yP = curMin.y; yP <= curMax.y; yP += CHUNK_SIZE)
  128. {
  129. if (xP < lastMin.x || xP > lastMax.x || yP < lastMin.y || yP > lastMax.y)
  130. {
  131. Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
  132. if (chunk)
  133. sendWorldUpdate(new AddChunkUpdate(dynamic_cast<Chunk*>(chunk->getThis())));
  134. else
  135. Game::INSTANCE->requestArea(Game::INSTANCE->getChunckArea(Game::INSTANCE->getChunkCenter(xP, yP)));
  136. }
  137. }
  138. }
  139. for (int xP = lastMin.x; xP <= lastMax.x; xP += CHUNK_SIZE)
  140. {
  141. for (int yP = lastMin.y; yP <= lastMax.y; yP += CHUNK_SIZE)
  142. {
  143. if (xP < curMin.x || xP > curMax.x || yP < curMin.y || yP > curMax.y)
  144. {
  145. Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
  146. if (chunk)
  147. chunk->removeView(zPlayer);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. lastPos = zPlayer->getPosition();
  154. }
  155. void GameClient::logout()
  156. {
  157. online = 0;
  158. }
  159. void GameClient::addMessage(StreamReader* reader)
  160. {
  161. short len = 0;
  162. reader->lese((char*)&len, 2);
  163. InMemoryBuffer* buffer = new InMemoryBuffer();
  164. char* tmp = new char[len];
  165. reader->lese(tmp, len);
  166. buffer->schreibe(tmp, len);
  167. delete[]tmp;
  168. other.lock();
  169. requests.add(buffer);
  170. other.unlock();
  171. }
  172. bool GameClient::isOnline() const
  173. {
  174. return online;
  175. }
  176. void GameClient::sendResponse(NetworkMessage* zResponse)
  177. {
  178. if (zResponse->isAreaAffected({ lastPos.x - (float)CHUNK_SIZE * (float)viewDistance, lastPos.y - (float)CHUNK_SIZE * (float)viewDistance, 0.f }, { lastPos.x + (float)CHUNK_SIZE * (float)viewDistance, lastPos.y + (float)CHUNK_SIZE * (float)viewDistance, (float)WORLD_HEIGHT }, zPlayer->getCurrentDimensionId()))
  179. {
  180. if (zResponse->isUseBackground())
  181. {
  182. background.lock();
  183. zResponse->writeTo(client->zBackgroundWriter());
  184. background.unlock();
  185. }
  186. else
  187. {
  188. foreground.lock();
  189. zResponse->writeTo(client->zForegroundWriter());
  190. foreground.unlock();
  191. }
  192. }
  193. }
  194. Player* GameClient::zEntity() const
  195. {
  196. return zPlayer;
  197. }
  198. void GameClient::sendTypes()
  199. {
  200. foreground.lock();
  201. int count = StaticRegistry<BlockType>::INSTANCE.getCount();
  202. client->zForegroundWriter()->schreibe((char*)&count, 4);
  203. for (int i = 0; i < count; i++)
  204. {
  205. BlockType* t = StaticRegistry<BlockType>::INSTANCE.zElement(i);
  206. int id = t->getId();
  207. client->zForegroundWriter()->schreibe((char*)&id, 4);
  208. bool inst = t->doesNeedClientInstance();
  209. client->zForegroundWriter()->schreibe((char*)&inst, 1);
  210. int maxHp = t->getInitialMaxHP();
  211. client->zForegroundWriter()->schreibe((char*)&maxHp, 4);
  212. t->getModel().writeTo(client->zForegroundWriter());
  213. }
  214. count = StaticRegistry<ItemType>::INSTANCE.getCount();
  215. client->zForegroundWriter()->schreibe((char*)&count, 4);
  216. for (int i = 0; i < count; i++)
  217. {
  218. ItemType* t = StaticRegistry<ItemType>::INSTANCE.zElement(i);
  219. int id = t->getId();
  220. client->zForegroundWriter()->schreibe((char*)&id, 4);
  221. t->getModel().writeTo(client->zForegroundWriter());
  222. }
  223. count = StaticRegistry<EntityType>::INSTANCE.getCount();
  224. client->zForegroundWriter()->schreibe((char*)&count, 4);
  225. for (int i = 0; i < count; i++)
  226. {
  227. EntityType* t = StaticRegistry<EntityType>::INSTANCE.zElement(i);
  228. int id = t->getId();
  229. client->zForegroundWriter()->schreibe((char*)&id, 4);
  230. t->getModel().writeTo(client->zForegroundWriter());
  231. }
  232. foreground.unlock();
  233. }
  234. Game::Game(Framework::Text name, Framework::Text worldsDir)
  235. : Thread(),
  236. name(name),
  237. dimensions(new RCArray<Dimension>()),
  238. updates(new RCArray<WorldUpdate>()),
  239. clients(new RCArray<GameClient>()),
  240. ticker(new TickOrganizer()),
  241. path((const char*)(worldsDir + "/" + name)),
  242. stop(0),
  243. tickId(0),
  244. nextEntityId(0),
  245. generator(0),
  246. loader(0),
  247. totalTickTime(0),
  248. tickCounter(0)
  249. {
  250. if (!DateiExistiert(worldsDir + "/" + name))
  251. DateiPfadErstellen(worldsDir + "/" + name + "/");
  252. Datei d;
  253. d.setDatei(path + "/eid");
  254. if (d.existiert())
  255. {
  256. d.open(Datei::Style::lesen);
  257. d.lese((char*)&nextEntityId, 4);
  258. d.close();
  259. }
  260. start();
  261. }
  262. Game::~Game()
  263. {
  264. dimensions->release();
  265. updates->release();
  266. clients->release();
  267. generator->release();
  268. loader->release();
  269. }
  270. void Game::initialize()
  271. {
  272. int seed = 0;
  273. int index = 0;
  274. for (char* n = name; *n; n++)
  275. seed += (int)pow((float)*n * 31, (float)++index);
  276. generator = new WorldGenerator(seed);
  277. loader = new WorldLoader();
  278. recipies.loadRecipies("data/recipies");
  279. }
  280. void Game::thread()
  281. {
  282. ZeitMesser m;
  283. while (!stop)
  284. {
  285. m.messungStart();
  286. ticker->nextTick();
  287. Array<int> removed;
  288. cs.lock();
  289. int index = 0;
  290. for (auto player : *clients)
  291. {
  292. if (!player->isOnline())
  293. {
  294. Datei pFile;
  295. pFile.setDatei(path + "/player/" + player->zEntity()->getName());
  296. if (pFile.open(Datei::Style::schreiben))
  297. PlayerEntityType::INSTANCE->saveEntity(player->zEntity(), &pFile);
  298. removed.add(index, 0);
  299. }
  300. index++;
  301. }
  302. for (auto i : removed)
  303. clients->remove(i);
  304. cs.unlock();
  305. for (auto dim : *dimensions)
  306. dim->tickEntities();
  307. cs.lock();
  308. while (updates->hat(0))
  309. {
  310. WorldUpdate* update = updates->z(0);
  311. for (auto client : *clients)
  312. client->sendWorldUpdate(dynamic_cast<WorldUpdate*>(update->getThis()));
  313. if (!zDimension(update->getAffectedDimension()))
  314. addDimension(new Dimension(update->getAffectedDimension()));
  315. update->onUpdate(zDimension(update->getAffectedDimension()));
  316. updates->remove(0);
  317. }
  318. cs.unlock();
  319. for (auto client : *clients)
  320. client->reply();
  321. cs.lock();
  322. for (auto dim : *dimensions)
  323. dim->removeOldChunks();
  324. cs.unlock();
  325. m.messungEnde();
  326. double sec = m.getSekunden();
  327. tickCounter++;
  328. totalTickTime += sec;
  329. if (tickCounter >= 1000)
  330. {
  331. std::cout << "Average Tick time: " << (totalTickTime / 1000) << "\n";
  332. if ((totalTickTime / 1000) * 30 > 1)
  333. {
  334. std::cout << "The game runns slower than normal.\n";
  335. }
  336. else
  337. {
  338. std::cout << "No performance issues detected.\n";
  339. }
  340. totalTickTime = 0;
  341. tickCounter = 0;
  342. }
  343. if (sec < 0.05)
  344. Sleep((int)((0.05 - sec) * 1000));
  345. else
  346. {
  347. std::cout << "WARNING: tick needed " << sec << " seconds. The game will run sower then normal.\n";
  348. }
  349. }
  350. save();
  351. }
  352. void Game::api(Framework::StreamReader* zRequest, GameClient* zOrigin)
  353. {
  354. char type;
  355. zRequest->lese(&type, 1);
  356. NetworkMessage response;
  357. switch (type)
  358. {
  359. case 1: // world
  360. {
  361. int dimensionId;
  362. zRequest->lese((char*)&dimensionId, 4);
  363. Dimension* dim = zDimension(dimensionId);
  364. if (!dim)
  365. {
  366. dim = new Dimension(dimensionId);
  367. addDimension(dim);
  368. }
  369. dim->api(zRequest, &response);
  370. break;
  371. }
  372. case 2: // player
  373. zOrigin->zEntity()->playerApi(zRequest, &response);
  374. break;
  375. case 3: // entity
  376. {
  377. int id;
  378. zRequest->lese((char*)&id, 4);
  379. for (Dimension* dim : *dimensions)
  380. {
  381. Entity* entity = dim->zEntity(id);
  382. if (entity)
  383. {
  384. entity->api(zRequest, &response);
  385. break;
  386. }
  387. }
  388. break;
  389. }
  390. case 4:
  391. { // inventory
  392. bool isEntity;
  393. zRequest->lese((char*)&isEntity, 1);
  394. Inventory* target;
  395. if (isEntity)
  396. {
  397. int id;
  398. zRequest->lese((char*)&id, 4);
  399. target = zEntity(id);
  400. }
  401. else
  402. {
  403. int dim;
  404. Vec3<int> pos;
  405. zRequest->lese((char*)&dim, 4);
  406. zRequest->lese((char*)&pos.x, 4);
  407. zRequest->lese((char*)&pos.y, 4);
  408. zRequest->lese((char*)&pos.z, 4);
  409. target = zBlockAt(pos, dim);
  410. }
  411. if (target)
  412. target->inventoryApi(zRequest, &response, zOrigin->zEntity());
  413. }
  414. default:
  415. std::cout << "received unknown api request in game with type " << (int)type << "\n";
  416. }
  417. if (!response.isEmpty())
  418. {
  419. if (response.isBroadcast())
  420. broadcastMessage(&response);
  421. else
  422. zOrigin->sendResponse(&response);
  423. }
  424. }
  425. void Game::broadcastMessage(NetworkMessage* zResponse)
  426. {
  427. for (auto client : *clients)
  428. client->sendResponse(zResponse);
  429. }
  430. void Game::sendMessage(NetworkMessage* zResponse, Entity* zTargetPlayer)
  431. {
  432. for (auto client : *clients)
  433. {
  434. if (client->zEntity() == zTargetPlayer)
  435. {
  436. client->sendResponse(zResponse);
  437. break;
  438. }
  439. }
  440. }
  441. bool Game::requestWorldUpdate(WorldUpdate* update)
  442. {
  443. cs.lock();
  444. for (WorldUpdate* u : *updates)
  445. {
  446. if (u->getMaxAffectedPoint().x >= update->getMinAffectedPoint().x && u->getMinAffectedPoint().x <= update->getMaxAffectedPoint().x &&
  447. u->getMaxAffectedPoint().y >= update->getMinAffectedPoint().y && u->getMinAffectedPoint().y <= update->getMaxAffectedPoint().y &&
  448. u->getMaxAffectedPoint().z >= update->getMinAffectedPoint().z && u->getMinAffectedPoint().z <= update->getMaxAffectedPoint().z && u->getType() == update->getType())
  449. {
  450. cs.unlock();
  451. update->release();
  452. return 0;
  453. }
  454. }
  455. updates->add(update);
  456. cs.unlock();
  457. return 1;
  458. }
  459. GameClient* Game::addPlayer(FCKlient* client, Framework::Text name)
  460. {
  461. cs.lock();
  462. Datei pFile;
  463. pFile.setDatei(path + "/player/" + name);
  464. Player* player;
  465. bool isNew = 0;
  466. if (!pFile.existiert() || !pFile.open(Datei::Style::lesen))
  467. {
  468. player = (Player*)PlayerEntityType::INSTANCE->createEntityAt(Vec3<float>(0.5, 0.5, 0), OverworldDimension::ID);
  469. player->setName(name);
  470. isNew = 1;
  471. }
  472. else
  473. {
  474. player = (Player*)PlayerEntityType::INSTANCE->loadEntity(&pFile);
  475. pFile.close();
  476. }
  477. GameClient* gameClient = new GameClient(player, client);
  478. gameClient->sendTypes();
  479. clients->add(gameClient);
  480. requestArea(getChunckArea(getChunkCenter((int)player->getPosition().x, (int)player->getPosition().y)));
  481. while (!zDimension(player->getCurrentDimensionId()) || (isNew && !zDimension(player->getCurrentDimensionId())->zChunk(getChunkCenter((int)player->getPosition().x, (int)player->getPosition().y))))
  482. {
  483. cs.unlock();
  484. Sleep(1000);
  485. cs.lock();
  486. }
  487. if (isNew)
  488. {
  489. Either<Block*, int> b = AirBlockBlockType::ID;
  490. int h = WORLD_HEIGHT;
  491. while (((b.isA() && (!(Block*)b || ((Block*)b)->isPassable())) || (b.isB() && StaticRegistry<BlockType>::INSTANCE.zElement(b)->zDefault()->isPassable())) && h > 0)
  492. b = zBlockAt({ (int)player->getPosition().x, (int)player->getPosition().y, --h }, player->getCurrentDimensionId());
  493. player->setPosition({ player->getPosition().x, player->getPosition().y, (float)h + 1.f });
  494. }
  495. requestWorldUpdate(new AddEntityUpdate(player, player->getCurrentDimensionId()));
  496. cs.unlock();
  497. return dynamic_cast<GameClient*>(gameClient->getThis());
  498. }
  499. bool Game::isChunkLoaded(int x, int y, int dimension) const
  500. {
  501. Dimension* dim = zDimension(dimension);
  502. return (dim && dim->hasChunck(x, y));
  503. }
  504. bool Game::doesChunkExist(int x, int y, int dimension)
  505. {
  506. cs.lock();
  507. bool result = isChunkLoaded(x, y, dimension) || loader->existsChunk(x, y, dimension);
  508. if (!result)
  509. {
  510. for (WorldUpdate* update : *updates)
  511. {
  512. if (update->getType() == AddChunkUpdateType::ID)
  513. result |= ((AddChunkUpdate*)update)->zChunk()->getCenter() == Framework::Punkt(x, y);
  514. }
  515. }
  516. cs.unlock();
  517. return result;
  518. }
  519. Framework::Either<Block*, int> Game::zBlockAt(Framework::Vec3<int> location, int dimension) const
  520. {
  521. Dimension* dim = zDimension(dimension);
  522. if (dim)
  523. return dim->zBlock(location);
  524. return 0;
  525. }
  526. Block* Game::zRealBlockInstance(Framework::Vec3<int> location, int dimension)
  527. {
  528. Dimension* dim = zDimension(dimension);
  529. if (dim)
  530. return dim->zRealBlockInstance(location);
  531. return 0;
  532. }
  533. Dimension* Game::zDimension(int id) const
  534. {
  535. for (auto dim : *dimensions)
  536. {
  537. if (dim->getDimensionId() == id)
  538. return dim;
  539. }
  540. return 0;
  541. }
  542. Framework::Punkt Game::getChunkCenter(int x, int y)
  543. {
  544. return Punkt(((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);
  545. }
  546. Area Game::getChunckArea(Punkt center) const
  547. {
  548. return { center.x - CHUNK_SIZE / 2, center.y - CHUNK_SIZE / 2, center.x + CHUNK_SIZE / 2 - 1, center.y + CHUNK_SIZE / 2 - 1, 0 };
  549. }
  550. Framework::Text Game::getWorldDirectory() const
  551. {
  552. return path;
  553. }
  554. void Game::requestArea(Area area)
  555. {
  556. generator->requestGeneration(area);
  557. loader->requestLoading(area);
  558. }
  559. void Game::save() const
  560. {
  561. Datei d;
  562. d.setDatei(path + "/eid");
  563. d.open(Datei::Style::schreiben);
  564. d.schreibe((char*)&nextEntityId, 4);
  565. d.close();
  566. for (auto dim : *dimensions)
  567. dim->save(path);
  568. }
  569. void Game::requestStop()
  570. {
  571. stop = 1;
  572. warteAufThread(1000000);
  573. }
  574. void Game::addDimension(Dimension* d)
  575. {
  576. dimensions->add(d);
  577. }
  578. int Game::getNextEntityId()
  579. {
  580. cs.lock();
  581. int result = nextEntityId++;
  582. cs.unlock();
  583. return result;
  584. }
  585. WorldGenerator* Game::zGenerator() const
  586. {
  587. return generator;
  588. }
  589. Game* Game::INSTANCE = 0;
  590. void Game::initialize(Framework::Text name, Framework::Text worldsDir)
  591. {
  592. if (!Game::INSTANCE)
  593. {
  594. Game::INSTANCE = new Game(name, worldsDir);
  595. Game::INSTANCE->initialize();
  596. }
  597. }
  598. Entity* Game::zEntity(int id, int dimensionId) const
  599. {
  600. Dimension* d = zDimension(dimensionId);
  601. if (d)
  602. return d->zEntity(id);
  603. return 0;
  604. }
  605. Entity* Game::zEntity(int id) const
  606. {
  607. for (Dimension* d : *dimensions)
  608. {
  609. Entity* e = d->zEntity(id);
  610. if (e)
  611. return e;
  612. }
  613. return 0;
  614. }
  615. Entity* Game::zNearestEntity(int dimensionId, Framework::Vec3<float> pos, std::function<bool(Entity*)> filter)
  616. {
  617. Dimension* d = zDimension(dimensionId);
  618. if (!d)
  619. return 0;
  620. return d->zNearestEntity(pos, filter);
  621. }
  622. const RecipieLoader& Game::getRecipies() const
  623. {
  624. return recipies;
  625. }