Start.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. using namespace Framework;
  13. WFenster* window;
  14. Bild* img;
  15. Vec3<int> position(0, 0, 0);
  16. int zoom = 1;
  17. bool exitF = 0;
  18. Noise* wrapper;
  19. float border = 0.5;
  20. void updateView()
  21. {
  22. Vec3<int> minP
  23. = position
  24. - Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  25. Vec3<int> maxP
  26. = position
  27. + Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  28. int counter = 0;
  29. for (int i = 0; i < img->getBreite(); i++)
  30. {
  31. for (int j = 0; j < img->getHeight(); j++)
  32. {
  33. Vec3<int> pos(i, j, 0);
  34. pos -= Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0);
  35. pos /= zoom;
  36. pos += position;
  37. if (wrapper->getNoise(pos.x, pos.y, pos.z) < border)
  38. {
  39. img->setPixelDP(i, j, 0xFFFFFFFF);
  40. counter++;
  41. }
  42. else
  43. {
  44. img->setPixelDP(i, j, 0xFF000000);
  45. }
  46. }
  47. }
  48. float percentage = ((float)counter / (img->getBreite() * img->getHeight())) * 100;
  49. std::cout << "Showing " << minP.x << " " << minP.y << " to " << maxP.x
  50. << " " << maxP.y << " at height " << position.z << " with border "
  51. << border << " true for " << percentage << "% of "
  52. << (img->getBreite() / zoom) * (img->getHeight() / zoom) << " blocks"
  53. << std::endl;
  54. }
  55. int main()
  56. {
  57. Framework::initFramework();
  58. /* FastNoiseLite* noise = new FastNoiseLite(0);
  59. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  60. noise->SetFrequency(3.f);
  61. wrapper = new FastNoiseWrapper(noise, 0);*/
  62. // FastNoiseLite* n = new FastNoiseLite(0);
  63. // n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_OpenSimplex2);
  64. //n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
  65. //n->SetFrequency(0.001f);
  66. //n->SetFractalOctaves(0);
  67. //n->SetFractalType(FastNoiseLite::FractalType::FractalType_None);
  68. //n->SetDomainWarpAmp(0.f);
  69. //wrapper = new FastNoiseWrapper(n, 0);
  70. wrapper = new RandNoise(0);
  71. img = new Bild();
  72. img->neuBild(800, 800, 0xFF000000);
  73. BildZ* view = new BildZ();
  74. view->setBildZ(img);
  75. view->setStyle(BildZ::Style::Sichtbar);
  76. view->setSize(800, 800);
  77. WNDCLASS wc = Framework::F_Normal(GetModuleHandle(NULL));
  78. wc.lpszClassName = "Fenster";
  79. window = new WFenster();
  80. window->erstellen(WS_OVERLAPPEDWINDOW, wc);
  81. window->setSize(800, 800);
  82. window->setPosition(100, 100);
  83. window->setAnzeigeModus(SW_SHOW);
  84. window->setVSchließAktion([](void* p, void* o) {
  85. StopNachrichtenSchleife(window->getFensterHandle());
  86. });
  87. Bildschirm* screen = new Bildschirm2D(window);
  88. window->setBildschirm(dynamic_cast<Bildschirm*>(screen->getThis()));
  89. screen->addMember(view);
  90. screen->setTestRend(0);
  91. screen->update();
  92. screen->render();
  93. RenderTh* rth = new RenderTh();
  94. rth->setQuiet(1);
  95. rth->setBildschirm(screen);
  96. rth->beginn();
  97. updateView();
  98. new AsynchronCall([]() {
  99. char line[256];
  100. while (!exitF)
  101. {
  102. std::cin.getline(line, 256);
  103. if (strcmp(line, "exit") == 0)
  104. {
  105. StopNachrichtenSchleife(window->getFensterHandle());
  106. break;
  107. }
  108. Text txt(line);
  109. if (txt.positionVon("show ") == 0)
  110. {
  111. Text* x = txt.getTeilText(5);
  112. position.x = (int)*x;
  113. Text* y = x->getTeilText(x->positionVon(" ") + 1);
  114. position.y = (int)*y;
  115. Text* z = y->getTeilText(y->positionVon(" ") + 1);
  116. position.z = (int)*z;
  117. updateView();
  118. z->release();
  119. y->release();
  120. x->release();
  121. }
  122. if (txt.positionVon("border ") == 0)
  123. {
  124. Text* x = txt.getTeilText(7);
  125. border = (float)*x;
  126. updateView();
  127. x->release();
  128. }
  129. if (txt.positionVon("zoom ") == 0)
  130. {
  131. Text* x = txt.getTeilText(5);
  132. zoom = (int)*x;
  133. updateView();
  134. x->release();
  135. }
  136. }
  137. });
  138. StartNachrichtenSchleife();
  139. exitF = 1;
  140. rth->beenden();
  141. window->setBildschirm(0);
  142. rth->release();
  143. img->release();
  144. Framework::releaseFramework();
  145. return 0;
  146. }