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. wrapper = new RandNoise(34255);
  97. img = new Bild();
  98. img->neuBild(800, 800, 0xFF000000);
  99. BildZ* view = new BildZ();
  100. view->setBildZ(img);
  101. view->setStyle(BildZ::Style::Sichtbar);
  102. view->setSize(800, 800);
  103. WNDCLASS wc = Framework::F_Normal(GetModuleHandle(NULL));
  104. wc.lpszClassName = "Fenster";
  105. window = new WFenster();
  106. window->erstellen(WS_OVERLAPPEDWINDOW, wc);
  107. window->setSize(800, 800);
  108. window->setPosition(100, 100);
  109. window->setAnzeigeModus(SW_SHOW);
  110. window->setVSchließAktion([](void* p, void* o) {
  111. StopNachrichtenSchleife(window->getFensterHandle());
  112. });
  113. Bildschirm* screen = new Bildschirm2D(window);
  114. window->setBildschirm(dynamic_cast<Bildschirm*>(screen->getThis()));
  115. screen->addMember(view);
  116. screen->setTestRend(0);
  117. screen->update();
  118. screen->render();
  119. RenderTh* rth = new RenderTh();
  120. rth->setQuiet(1);
  121. rth->setBildschirm(screen);
  122. rth->beginn();
  123. updateView();
  124. new AsynchronCall([]() {
  125. char line[256];
  126. while (!exitF)
  127. {
  128. std::cin.getline(line, 256);
  129. if (strcmp(line, "exit") == 0)
  130. {
  131. StopNachrichtenSchleife(window->getFensterHandle());
  132. break;
  133. }
  134. Text txt(line);
  135. if (txt.positionVon("show ") == 0)
  136. {
  137. Text* x = txt.getTeilText(5);
  138. position.x = (int)*x;
  139. Text* y = x->getTeilText(x->positionVon(" ") + 1);
  140. position.y = (int)*y;
  141. Text* z = y->getTeilText(y->positionVon(" ") + 1);
  142. position.z = (int)*z;
  143. updateView();
  144. z->release();
  145. y->release();
  146. x->release();
  147. }
  148. if (txt.positionVon("border ") == 0)
  149. {
  150. Text* x = txt.getTeilText(7);
  151. border = (float)*x;
  152. updateView();
  153. x->release();
  154. }
  155. if (txt.positionVon("border2 ") == 0)
  156. {
  157. Text* x = txt.getTeilText(7);
  158. border2 = (float)*x;
  159. updateView();
  160. x->release();
  161. }
  162. if (txt.positionVon("zoom ") == 0)
  163. {
  164. Text* x = txt.getTeilText(5);
  165. zoom = (int)*x;
  166. updateView();
  167. x->release();
  168. }
  169. if (txt.positionVon("show value") == 0)
  170. {
  171. showValue = 1;
  172. updateView();
  173. }
  174. if (txt.positionVon("show border") == 0)
  175. {
  176. showValue = 0;
  177. updateView();
  178. }
  179. }
  180. });
  181. StartNachrichtenSchleife();
  182. exitF = 1;
  183. rth->beenden();
  184. window->setBildschirm(0);
  185. rth->release();
  186. Framework::releaseFramework();
  187. return 0;
  188. }