Chunk.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. #include "Chunk.h"
  2. #include <Shader.h>
  3. #include "ChunkFluidModel.h"
  4. #include "ChunkGroundModel.h"
  5. #include "Constants.h"
  6. #include "CustomDX12API.h"
  7. #include "FactoryCraftModel.h"
  8. #include "Globals.h"
  9. #include "TransparentChunkGroundModel.h"
  10. Chunk::Chunk(Framework::Point location)
  11. : ReferenceCounter(),
  12. location(location),
  13. isLoading(0),
  14. lightChanged(0),
  15. modelChanged(0),
  16. bLock(),
  17. vLock(),
  18. aLock()
  19. {
  20. blocks = new Block*[CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT];
  21. memset(blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof(Block*));
  22. // FactoryCraftModel* ground = new FactoryCraftModel();
  23. // Model3DData* chunkModel
  24. // = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
  25. // Text("chunk_ground_") + location.x + location.y);
  26. // if (!chunkModel)
  27. // {
  28. // chunkModel
  29. // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
  30. // Text("chunk_ground_") + location.x + location.y);
  31. // }
  32. // chunkModel->setAmbientFactor(0.f);
  33. // chunkModel->setDiffusFactor(1.f);
  34. // chunkModel->setSpecularFactor(0.f);
  35. // chunkModel->setVertecies(0, 0);
  36. // ground->setModelData(chunkModel);
  37. // ground->setPosition(
  38. // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
  39. // ground->tick(0);
  40. // ChunkModelBuilder* groundModel = new ChunkGroundModel(ground, this);
  41. // modelBuilders.add(groundModel);
  42. // FactoryCraftModel* transparentGround = new FactoryCraftModel();
  43. // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
  44. // Text("transparent_chunk_ground_") + location.x + location.y);
  45. // if (!chunkModel)
  46. //{
  47. // chunkModel
  48. // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
  49. // Text("transparent_chunk_ground_") + location.x + location.y);
  50. //}
  51. // chunkModel->setAmbientFactor(0.f);
  52. // chunkModel->setDiffusFactor(1.f);
  53. // chunkModel->setSpecularFactor(0.f);
  54. // chunkModel->setVertecies(0, 0);
  55. // transparentGround->setModelData(chunkModel);
  56. // transparentGround->setPosition(
  57. // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
  58. // transparentGround->tick(0);
  59. // ChunkModelBuilder* transparentGroundModel
  60. // = new TransparentChunkGroundModel(transparentGround, this);
  61. // modelBuilders.add(transparentGroundModel);
  62. // FactoryCraftModel* fluids = new FactoryCraftModel();
  63. // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
  64. // Text("chunk_fluids_") + location.x + location.y);
  65. // if (!chunkModel)
  66. //{
  67. // chunkModel
  68. // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
  69. // Text("chunk_fluids_") + location.x + location.y);
  70. //}
  71. // chunkModel->setAmbientFactor(0.f);
  72. // chunkModel->setDiffusFactor(1.f);
  73. // chunkModel->setSpecularFactor(0.f);
  74. // chunkModel->setVertecies(0, 0);
  75. // fluids->setModelData(chunkModel);
  76. // fluids->setPosition(
  77. // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
  78. // fluids->tick(0);
  79. // ChunkModelBuilder* fluidModel = new ChunkFluidModel(fluids, this);
  80. // modelBuilders.add(fluidModel);
  81. }
  82. Chunk::Chunk(Framework::Point location, Framework::StreamReader* zReader)
  83. : Chunk(location)
  84. {
  85. load(zReader);
  86. // for (ChunkModelBuilder* builder : modelBuilders)
  87. //{
  88. // buildModel(builder);
  89. // }
  90. }
  91. Chunk::~Chunk()
  92. {
  93. char msg = 1; // remove observer
  94. if (World::INSTANCE)
  95. {
  96. World::INSTANCE->zClient()->chunkAPIRequest(location, &msg, 1);
  97. }
  98. bLock.lockWrite();
  99. for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
  100. {
  101. if (blocks[i])
  102. {
  103. blocks[i]->release();
  104. blocks[i] = 0;
  105. }
  106. }
  107. delete[] blocks;
  108. bLock.unlockWrite();
  109. }
  110. void Chunk::appendAnimation(
  111. Block* zB, int boneId, double time, Vec3<float> pos, Vec3<float> rot)
  112. {
  113. if (!zB->zSkeleton() || !zB->zSkeleton()->zBone(boneId)) return;
  114. aLock.lockRead();
  115. for (BlockAnimation* animation : animations)
  116. {
  117. if (animation->zBlock() == zB)
  118. {
  119. animation->appendAnimation(boneId, time, pos, rot);
  120. aLock.unlockRead();
  121. return;
  122. }
  123. }
  124. aLock.unlockRead();
  125. SkeletonAnimation* sa = new SkeletonAnimation();
  126. Bone* bone = zB->zSkeleton()->zBone(boneId);
  127. sa->addAnimation(boneId, bone->getPosition(), bone->getRotation());
  128. sa->addKeyFrame(boneId, time, pos, rot);
  129. aLock.lockWrite();
  130. animations.add(new BlockAnimation(dynamic_cast<Block*>(zB->getThis()), sa));
  131. aLock.unlockWrite();
  132. }
  133. void Chunk::load(Framework::StreamReader* zReader)
  134. {
  135. bLock.lockWrite();
  136. for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
  137. {
  138. if (blocks[i])
  139. {
  140. blocks[i]->release();
  141. blocks[i] = 0;
  142. }
  143. }
  144. bLock.unlockWrite();
  145. isLoading = 1;
  146. Framework::Vec3<int> pos = {0, 0, 0};
  147. unsigned short id;
  148. zReader->read((char*)&id, 2);
  149. int count = 0;
  150. while (id)
  151. {
  152. int index;
  153. zReader->read((char*)&index, 4);
  154. char state = 0;
  155. zReader->read(&state, 1);
  156. char flowOptions = 0;
  157. char distanceToSource = 0;
  158. if (state & 1)
  159. {
  160. zReader->read(&flowOptions, 1);
  161. zReader->read(&distanceToSource, 1);
  162. }
  163. bool passable = 0;
  164. float speedModifier = 1.f;
  165. if (state & 2)
  166. {
  167. passable = 1;
  168. zReader->read((char*)&speedModifier, 4);
  169. }
  170. pos = Vec3<int>((index / WORLD_HEIGHT) / CHUNK_SIZE,
  171. (index / WORLD_HEIGHT) % CHUNK_SIZE,
  172. index % WORLD_HEIGHT);
  173. Direction dir = blockTypes[id]->getDefaultFrontDirection();
  174. if (state & 4)
  175. {
  176. zReader->read((char*)&dir, 1);
  177. }
  178. if (blockTypes[id]->doesNeedInstance())
  179. {
  180. Block* b = blockTypes[id]->createBlock(
  181. {pos.x + location.x - CHUNK_SIZE / 2,
  182. pos.y + location.y - CHUNK_SIZE / 2,
  183. pos.z},
  184. passable,
  185. speedModifier,
  186. dir);
  187. b->setFlow(flowOptions, distanceToSource);
  188. bLock.lockWrite();
  189. blocks[index] = b;
  190. bLock.unlockWrite();
  191. if (b->isVisible())
  192. {
  193. if (!blockTypes[id]->getModelInfo().getModelName().isEqual(
  194. "cube")
  195. && !blockTypes[id]->getModelInfo().getModelName().isEqual(
  196. "grass"))
  197. {
  198. b->tick(0);
  199. vLock.lockWrite();
  200. visibleBlocks.add(b);
  201. vLock.unlockWrite();
  202. }
  203. }
  204. count++;
  205. }
  206. zReader->read((char*)&id, 2);
  207. }
  208. std::cout << "Loaded " << count << " blocks\n";
  209. int index = 0;
  210. // light
  211. zReader->read((char*)&index, 4);
  212. char lightData[6];
  213. while (index >= -1)
  214. {
  215. if (index == -1)
  216. {
  217. int x = 0;
  218. int y = 0;
  219. int z = 0;
  220. zReader->read((char*)&x, 4);
  221. zReader->read((char*)&y, 4);
  222. zReader->read((char*)&z, 4);
  223. zReader->read(lightData, 6);
  224. if (x == -1)
  225. {
  226. int cacheIndex = y * WORLD_HEIGHT + z;
  227. bLock.lockRead();
  228. Block* zB = blocks[cacheIndex];
  229. if (zB)
  230. {
  231. zB->setLightData(WEST, (unsigned char*)lightData, 0);
  232. }
  233. bLock.unlockRead();
  234. }
  235. else if (y == -1)
  236. {
  237. int cacheIndex = (x * CHUNK_SIZE) * WORLD_HEIGHT + z;
  238. bLock.lockRead();
  239. Block* zB = blocks[cacheIndex];
  240. if (zB)
  241. {
  242. zB->setLightData(NORTH, (unsigned char*)lightData, 0);
  243. }
  244. bLock.unlockRead();
  245. }
  246. else if (x == CHUNK_SIZE)
  247. {
  248. int cacheIndex
  249. = ((CHUNK_SIZE - 1) * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
  250. bLock.lockRead();
  251. Block* zB = blocks[cacheIndex];
  252. if (zB)
  253. {
  254. zB->setLightData(EAST, (unsigned char*)lightData, 0);
  255. }
  256. bLock.unlockRead();
  257. }
  258. else if (y == CHUNK_SIZE)
  259. {
  260. int cacheIndex
  261. = (x * CHUNK_SIZE + (CHUNK_SIZE - 1)) * WORLD_HEIGHT + z;
  262. bLock.lockRead();
  263. Block* zB = blocks[cacheIndex];
  264. if (zB)
  265. {
  266. zB->setLightData(SOUTH, (unsigned char*)lightData, 0);
  267. }
  268. bLock.unlockRead();
  269. }
  270. }
  271. else
  272. {
  273. zReader->read(lightData, 6);
  274. Framework::Vec3<int> location((index / WORLD_HEIGHT) / CHUNK_SIZE,
  275. (index / WORLD_HEIGHT) % CHUNK_SIZE,
  276. index % WORLD_HEIGHT);
  277. for (int i = 0; i < 6; i++)
  278. {
  279. Framework::Vec3<int> pos
  280. = location + getDirection(getDirectionFromIndex(i));
  281. if (pos.z >= 0 && pos.z < WORLD_HEIGHT)
  282. {
  283. if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
  284. && pos.y < CHUNK_SIZE)
  285. {
  286. int cacheIndex
  287. = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT
  288. + pos.z;
  289. bLock.lockRead();
  290. Block* zB = blocks[cacheIndex];
  291. if (zB)
  292. {
  293. bool visible = zB->isVisible();
  294. zB->setLightData(
  295. getOppositeDirection(getDirectionFromIndex(i)),
  296. (unsigned char*)lightData,
  297. 0);
  298. if (zB->isVisible() && !visible)
  299. {
  300. zB->tick(0);
  301. vLock.lockWrite();
  302. visibleBlocks.add(zB);
  303. vLock.unlockWrite();
  304. }
  305. }
  306. bLock.unlockRead();
  307. }
  308. else
  309. {
  310. pos.x += this->location.x - CHUNK_SIZE / 2;
  311. pos.y += this->location.y - CHUNK_SIZE / 2;
  312. World::INSTANCE->getChunkReadLock().lock();
  313. Chunk* c = World::INSTANCE->zChunk(
  314. World::INSTANCE->getChunkCenter(pos.x, pos.y));
  315. if (c)
  316. {
  317. c->getBlockReadLock().lock();
  318. Block* zB = c->zBlockAt(pos);
  319. if (zB)
  320. {
  321. bool visible = zB->isVisible();
  322. zB->setLightData(getOppositeDirection(
  323. getDirectionFromIndex(i)),
  324. (unsigned char*)lightData,
  325. c);
  326. if (zB->isVisible() && !visible)
  327. {
  328. zB->tick(0);
  329. vLock.lockWrite();
  330. c->visibleBlocks.add(zB);
  331. vLock.unlockWrite();
  332. }
  333. }
  334. c->getBlockReadLock().unlock();
  335. }
  336. World::INSTANCE->getChunkReadLock().unlock();
  337. }
  338. }
  339. }
  340. }
  341. zReader->read((char*)&index, 4);
  342. }
  343. isLoading = 0;
  344. }
  345. // void Chunk::buildModel(ChunkModelBuilder* builder)
  346. //{
  347. // modelChanged &= ~builder->getType();
  348. // lightChanged &= ~builder->getType();
  349. // builder->buildModel();
  350. // }
  351. // void Chunk::updateLight(ChunkModelBuilder* builder)
  352. //{
  353. // lightChanged &= ~builder->getType();
  354. // builder->updateLightning();
  355. // }
  356. void Chunk::forAll(std::function<void(Model3D*)> f)
  357. {
  358. // for (ChunkModelBuilder* builder : modelBuilders)
  359. //{
  360. // f(builder->zModel());
  361. // }
  362. vLock.lockRead();
  363. for (Block* b : visibleBlocks)
  364. {
  365. f(b);
  366. }
  367. vLock.unlockRead();
  368. }
  369. bool Chunk::tick(std::function<void(Model3D*)> f, double time)
  370. {
  371. // for (ChunkModelBuilder* builder : modelBuilders)
  372. //{
  373. // if ((modelChanged | builder->getType()) == modelChanged)
  374. // buildModel(builder);
  375. // }
  376. // for (ChunkModelBuilder* builder : modelBuilders)
  377. //{
  378. // if ((lightChanged | builder->getType()) == lightChanged)
  379. // updateLight(builder);
  380. // }
  381. bool res = 0;
  382. // for (ChunkModelBuilder* builder : modelBuilders)
  383. //{
  384. // res |= builder->zModel()->tick(time);
  385. // }
  386. aLock.lockRead();
  387. auto iterator = animations.begin();
  388. while (iterator)
  389. {
  390. if (iterator->tick(time))
  391. {
  392. res |= iterator->zBlock()->tick(time);
  393. if (iterator->isFinished())
  394. {
  395. aLock.lockWrite();
  396. iterator.remove();
  397. aLock.unlockWrite();
  398. continue;
  399. }
  400. }
  401. else
  402. {
  403. aLock.lockWrite();
  404. iterator.remove();
  405. aLock.unlockWrite();
  406. continue;
  407. }
  408. ++iterator;
  409. }
  410. aLock.unlockRead();
  411. return 1;
  412. }
  413. void Chunk::destroy()
  414. {
  415. // for (ChunkModelBuilder* builder : modelBuilders)
  416. //{
  417. // Model3DData* chunkModel = builder->zModel()->zModelData();
  418. // // remove old model
  419. // while (chunkModel->getPolygonCount() > 0)
  420. // {
  421. // chunkModel->removePolygon(0);
  422. // }
  423. // chunkModel->setVertecies(0, 0);
  424. // }
  425. }
  426. void Chunk::api(char* message)
  427. {
  428. switch (message[0])
  429. {
  430. case 0: // set block
  431. {
  432. unsigned short id = *(int*)(message + 1);
  433. int index = *(int*)(message + 3);
  434. char state = message[7];
  435. char flowOptions = 0;
  436. char distanceToSource = 0;
  437. int i = 8;
  438. if (state & 1)
  439. {
  440. flowOptions = message[i++];
  441. distanceToSource = message[i++];
  442. }
  443. bool passable = 0;
  444. float speedModifier = 1.f;
  445. if (state & 2)
  446. {
  447. passable = 1;
  448. speedModifier = *(float*)(message + i);
  449. i += 4;
  450. }
  451. Direction dir = blockTypes[id]->getDefaultFrontDirection();
  452. if (state & 4)
  453. {
  454. dir = (Direction)message[i++];
  455. }
  456. Framework::Vec3<int> location((index / WORLD_HEIGHT) / CHUNK_SIZE,
  457. (index / WORLD_HEIGHT) % CHUNK_SIZE,
  458. index % WORLD_HEIGHT);
  459. location.x += this->location.x - CHUNK_SIZE / 2;
  460. location.y += this->location.y - CHUNK_SIZE / 2;
  461. if (blockTypes[id]->doesNeedInstance())
  462. {
  463. Block* zB = blockTypes[id]->createBlock(
  464. location, passable, speedModifier, dir);
  465. zB->setFlow(flowOptions, distanceToSource);
  466. setBlock(zB);
  467. }
  468. else
  469. {
  470. bLock.lockRead();
  471. Block* zB = zBlockAt(location);
  472. if (zB) removeBlock(zB);
  473. bLock.unlockRead();
  474. }
  475. break;
  476. }
  477. case 1: // animate block
  478. {
  479. int index = *(int*)(message + 1);
  480. int boneId = *(int*)(message + 5);
  481. double time = *(double*)(message + 9);
  482. Framework::Vec3<float> pos;
  483. pos.x = *(float*)(message + 17);
  484. pos.y = *(float*)(message + 21);
  485. pos.z = *(float*)(message + 25);
  486. Framework::Vec3<float> rot;
  487. rot.x = *(float*)(message + 29);
  488. rot.y = *(float*)(message + 33);
  489. rot.z = *(float*)(message + 37);
  490. Framework::Vec3<int> location((index / WORLD_HEIGHT) / CHUNK_SIZE,
  491. (index / WORLD_HEIGHT) % CHUNK_SIZE,
  492. index % WORLD_HEIGHT);
  493. location.x += this->location.x - CHUNK_SIZE / 2;
  494. location.y += this->location.y - CHUNK_SIZE / 2;
  495. bLock.lockRead();
  496. Block* zB = zBlockAt(location);
  497. if (zB) appendAnimation(zB, boneId, time, pos, rot);
  498. bLock.unlockRead();
  499. break;
  500. }
  501. }
  502. }
  503. Block* Chunk::zBlockAt(Framework::Vec3<int> location)
  504. {
  505. if (location.z < 0 || location.z >= WORLD_HEIGHT) return 0;
  506. location.x = location.x % CHUNK_SIZE;
  507. location.y = location.y % CHUNK_SIZE;
  508. if (location.x < 0) location.x += CHUNK_SIZE;
  509. if (location.y < 0) location.y += CHUNK_SIZE;
  510. int index
  511. = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
  512. return blocks[index];
  513. }
  514. void Chunk::setBlock(Block* block)
  515. {
  516. Framework::Vec3<int> pos = block->getLocation();
  517. pos.x = pos.x % CHUNK_SIZE;
  518. pos.y = pos.y % CHUNK_SIZE;
  519. if (pos.x < 0) pos.x += CHUNK_SIZE;
  520. if (pos.y < 0) pos.y += CHUNK_SIZE;
  521. int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
  522. int affectsGround = 0;
  523. int newAffectsGround = 0;
  524. bLock.lockWrite();
  525. // for (ChunkModelBuilder* builder : modelBuilders)
  526. //{
  527. // if (block && builder->isPartOfModel(block))
  528. // {
  529. // newAffectsGround |= builder->getType();
  530. // }
  531. // if (blocks[index] && builder->isPartOfModel(blocks[index]))
  532. // {
  533. // affectsGround |= builder->getType();
  534. // }
  535. // }
  536. if (blocks[index])
  537. {
  538. vLock.lockWrite();
  539. for (Framework::ArrayIterator<Block*> vi = visibleBlocks.begin(); vi;
  540. vi++)
  541. {
  542. if (blocks[index] == (Block*)vi)
  543. {
  544. vi.remove();
  545. break;
  546. }
  547. }
  548. vLock.unlockWrite();
  549. blocks[index]->copyLightTo(block);
  550. blocks[index]->release();
  551. blocks[index] = block;
  552. bLock.unlockWrite();
  553. modelChanged |= affectsGround | newAffectsGround;
  554. if (block && block->isVisible() && !newAffectsGround)
  555. {
  556. block->tick(0);
  557. vLock.lockWrite();
  558. visibleBlocks.add(block);
  559. vLock.unlockWrite();
  560. }
  561. return;
  562. }
  563. blocks[index] = block;
  564. bLock.unlockWrite();
  565. modelChanged |= affectsGround | newAffectsGround;
  566. if (block && block->isVisible() && !newAffectsGround)
  567. {
  568. block->tick(0);
  569. vLock.lockWrite();
  570. visibleBlocks.add(block);
  571. vLock.unlockWrite();
  572. }
  573. }
  574. void Chunk::removeBlock(Block* zBlock)
  575. {
  576. vLock.lockWrite();
  577. for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
  578. iterator;
  579. iterator++)
  580. {
  581. if (zBlock == (Block*)iterator)
  582. {
  583. iterator.remove();
  584. break;
  585. }
  586. }
  587. vLock.unlockWrite();
  588. Vec3<int> pos = zBlock->getLocation();
  589. pos.x = pos.x % CHUNK_SIZE;
  590. pos.y = pos.y % CHUNK_SIZE;
  591. if (pos.x < 0) pos.x += CHUNK_SIZE;
  592. if (pos.y < 0) pos.y += CHUNK_SIZE;
  593. int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
  594. bLock.lockWrite();
  595. if (blocks[index])
  596. {
  597. modelChanged |= blocks[index]->getPartOfModels();
  598. blocks[index]->release();
  599. blocks[index] = 0;
  600. }
  601. bLock.unlockWrite();
  602. }
  603. void Chunk::blockVisibilityChanged(Block* zB)
  604. {
  605. if (zB->isVisible())
  606. {
  607. zB->tick(0);
  608. vLock.lockWrite();
  609. visibleBlocks.add(zB);
  610. vLock.unlockWrite();
  611. }
  612. else
  613. {
  614. vLock.lockWrite();
  615. for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
  616. iterator;
  617. iterator++)
  618. {
  619. if (zB == (Block*)iterator)
  620. {
  621. iterator.remove();
  622. break;
  623. }
  624. }
  625. vLock.unlockWrite();
  626. }
  627. }
  628. Framework::Point Chunk::getCenter() const
  629. {
  630. return location;
  631. }
  632. Framework::Vec3<int> Chunk::getMin() const
  633. {
  634. return {location.x - CHUNK_SIZE / 2, location.y - CHUNK_SIZE / 2, 0};
  635. }
  636. Framework::Vec3<int> Chunk::getMax() const
  637. {
  638. return {
  639. location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
  640. }
  641. void Chunk::setModelChanged(int type)
  642. {
  643. modelChanged |= type;
  644. }
  645. void Chunk::setLightChanged(int type)
  646. {
  647. lightChanged |= type;
  648. }
  649. Lock& Chunk::getBlockReadLock() const
  650. {
  651. return bLock.getReadLock();
  652. }