Start.cpp 6.4 KB

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