Start.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include <AsynchronCall.h>
  2. #include <Bild.h>
  3. #include <Bildschirm.h>
  4. #include <Fenster.h>
  5. #include <Globals.h>
  6. #include <iostream>
  7. #include <RenderThread.h>
  8. #include <string.h>
  9. #include "FastNoiseLite.h"
  10. #include "FastNoiseWrapper.h"
  11. #include "RandNoise.h"
  12. #include "ShapedNoise.h"
  13. using namespace Framework;
  14. WFenster* window;
  15. Bild* img;
  16. Vec3<int> position(0, 0, 0);
  17. int zoom = 1;
  18. bool exitF = 0;
  19. Noise* wrapper;
  20. float border = 0.5;
  21. float border2 = -1;
  22. bool showValue = 1;
  23. void updateView()
  24. {
  25. Vec3<int> minP
  26. = position
  27. - Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  28. Vec3<int> maxP
  29. = position
  30. + Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  31. int counter = 0;
  32. for (int i = 0; i < img->getBreite(); i++)
  33. {
  34. for (int j = 0; j < img->getHeight(); j++)
  35. {
  36. Vec3<int> pos(i, j, 0);
  37. pos -= Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0);
  38. pos /= zoom;
  39. pos += position;
  40. double noise = wrapper->getNoise(pos.x, pos.y, pos.z);
  41. if (showValue)
  42. {
  43. int value = (int)(noise * 255);
  44. img->setPixelDP(
  45. i, j, 0xFF000000 | (value << 16) | (value << 8) | value);
  46. }
  47. else
  48. {
  49. if (noise < border && noise > border2)
  50. {
  51. img->setPixelDP(i, j, 0xFFFFFFFF);
  52. counter++;
  53. }
  54. else
  55. {
  56. img->setPixelDP(i, j, 0xFF000000);
  57. }
  58. }
  59. }
  60. }
  61. float percentage = ((float)counter / (img->getBreite() * img->getHeight())) * 100;
  62. std::cout << "Showing " << minP.x << " " << minP.y << " to " << maxP.x
  63. << " " << maxP.y << " at height " << position.z << " with border "
  64. << border2 << " to "
  65. << border << " true for " << percentage << "% of "
  66. << (img->getBreite() / zoom) * (img->getHeight() / zoom) << " blocks"
  67. << std::endl;
  68. }
  69. int main()
  70. {
  71. Framework::initFramework();
  72. /* FastNoiseLite* noise = new FastNoiseLite(0);
  73. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  74. noise->SetFrequency(3.f);
  75. wrapper = new FastNoiseWrapper(noise, 0);*/
  76. FastNoiseLite* n = new FastNoiseLite(0);
  77. n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Cellular);
  78. n->SetFrequency(0.005f);
  79. n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
  80. n->SetCellularDistanceFunction(FastNoiseLite::CellularDistanceFunction::
  81. CellularDistanceFunction_Hybrid);
  82. n->SetCellularJitter(1.f);
  83. n->SetCellularReturnType(
  84. FastNoiseLite::CellularReturnType::CellularReturnType_CellValue);
  85. n->SetFractalType(
  86. FastNoiseLite::FractalType::FractalType_DomainWarpIndependent);
  87. n->SetDomainWarpType(
  88. FastNoiseLite::DomainWarpType::DomainWarpType_OpenSimplex2);
  89. n->SetDomainWarpAmp(100.f);
  90. n->SetFractalOctaves(3.f);
  91. n->SetFractalLacunarity(2.f);
  92. n->SetFractalGain(0.5f);
  93. wrapper = new FastNoiseWrapper(n, 0);
  94. wrapper = new ShapedNoise(wrapper);
  95. ((ShapedNoise*)wrapper)->setNeighborOffset(4.f);
  96. img = new Bild();
  97. img->neuBild(800, 800, 0xFF000000);
  98. BildZ* view = new BildZ();
  99. view->setBildZ(img);
  100. view->setStyle(BildZ::Style::Sichtbar);
  101. view->setSize(800, 800);
  102. WNDCLASS wc = Framework::F_Normal(GetModuleHandle(NULL));
  103. wc.lpszClassName = "Fenster";
  104. window = new WFenster();
  105. window->erstellen(WS_OVERLAPPEDWINDOW, wc);
  106. window->setSize(800, 800);
  107. window->setPosition(100, 100);
  108. window->setAnzeigeModus(SW_SHOW);
  109. window->setVSchließAktion([](void* p, void* o) {
  110. StopNachrichtenSchleife(window->getFensterHandle());
  111. });
  112. Bildschirm* screen = new Bildschirm2D(window);
  113. window->setBildschirm(dynamic_cast<Bildschirm*>(screen->getThis()));
  114. screen->addMember(view);
  115. screen->setTestRend(0);
  116. screen->update();
  117. screen->render();
  118. RenderTh* rth = new RenderTh();
  119. rth->setQuiet(1);
  120. rth->setBildschirm(screen);
  121. rth->beginn();
  122. updateView();
  123. new AsynchronCall([]() {
  124. char line[256];
  125. while (!exitF)
  126. {
  127. std::cin.getline(line, 256);
  128. if (strcmp(line, "exit") == 0)
  129. {
  130. StopNachrichtenSchleife(window->getFensterHandle());
  131. break;
  132. }
  133. Text txt(line);
  134. if (txt.positionVon("show ") == 0)
  135. {
  136. Text* x = txt.getTeilText(5);
  137. position.x = (int)*x;
  138. Text* y = x->getTeilText(x->positionVon(" ") + 1);
  139. position.y = (int)*y;
  140. Text* z = y->getTeilText(y->positionVon(" ") + 1);
  141. position.z = (int)*z;
  142. updateView();
  143. z->release();
  144. y->release();
  145. x->release();
  146. }
  147. if (txt.positionVon("border ") == 0)
  148. {
  149. Text* x = txt.getTeilText(7);
  150. border = (float)*x;
  151. updateView();
  152. x->release();
  153. }
  154. if (txt.positionVon("border2 ") == 0)
  155. {
  156. Text* x = txt.getTeilText(7);
  157. border2 = (float)*x;
  158. updateView();
  159. x->release();
  160. }
  161. if (txt.positionVon("zoom ") == 0)
  162. {
  163. Text* x = txt.getTeilText(5);
  164. zoom = (int)*x;
  165. updateView();
  166. x->release();
  167. }
  168. if (txt.positionVon("show value") == 0)
  169. {
  170. showValue = 1;
  171. updateView();
  172. }
  173. if (txt.positionVon("show border") == 0)
  174. {
  175. showValue = 0;
  176. updateView();
  177. }
  178. }
  179. });
  180. StartNachrichtenSchleife();
  181. exitF = 1;
  182. rth->beenden();
  183. window->setBildschirm(0);
  184. rth->release();
  185. Framework::releaseFramework();
  186. return 0;
  187. }