No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

11_fractal.cpp 19 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. //
  2. // Lol Engine - Fractal tutorial
  3. //
  4. // Copyright: (c) 2011-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #include <cstdio>
  15. #include <lol/engine.h>
  16. #include "loldebug.h"
  17. using namespace lol;
  18. LOLFX_RESOURCE_DECLARE(11_fractal);
  19. class Fractal : public WorldEntity
  20. {
  21. public:
  22. Fractal(ivec2 const &size)
  23. {
  24. /* Ensure texture size is a multiple of 16 for better aligned
  25. * data access. Store the dimensions of a texel for our shader,
  26. * as well as the half-size of the screen. */
  27. m_size = size;
  28. m_size.x = (m_size.x + 15) & ~15;
  29. m_size.y = (m_size.y + 15) & ~15;
  30. m_texel_settings = vec4(1.0, 1.0, 2.0, 2.0) / (vec4)m_size.xyxy;
  31. m_screen_settings = vec4(1.0, 1.0, 0.5, 0.5) * (vec4)m_size.xyxy;
  32. /* Window size decides the world aspect ratio. For instance, 640×480
  33. * will be mapped to (-0.66,-0.5) - (0.66,0.5). */
  34. #if !defined __native_client__
  35. m_window_size = Video::GetSize();
  36. #else
  37. /* FIXME: it's illegal to call this on the game thread! */
  38. m_window_size = ivec2(640, 480);
  39. #endif
  40. if (m_window_size.y < m_window_size.x)
  41. m_window2world = 0.5 / m_window_size.y;
  42. else
  43. m_window2world = 0.5 / m_window_size.x;
  44. m_texel2world = (dvec2)m_window_size / (dvec2)m_size * m_window2world;
  45. m_oldmouse = ivec2(0, 0);
  46. m_pixels.Resize(m_size.x * m_size.y);
  47. m_frame = -1;
  48. m_slices = 4;
  49. for (int i = 0; i < 4; i++)
  50. {
  51. m_deltashift[i] = real("0");
  52. m_deltascale[i] = real("1");
  53. m_dirty[i] = 2;
  54. }
  55. #if defined __CELLOS_LV2__ || defined _XBOX
  56. //m_center = rcmplx(-.22815528839841, -1.11514249704382);
  57. //m_center = rcmplx(0.001643721971153, 0.822467633298876);
  58. m_center = rcmplx("-0.65823419062254", "0.50221777363480");
  59. m_zoom_speed = -0.025;
  60. #else
  61. m_center = rcmplx(-0.75, 0.0);
  62. m_zoom_speed = 0.0;
  63. #endif
  64. m_translate = rcmplx(0.0, 0.0);
  65. m_radius = 5.0;
  66. m_ready = false;
  67. m_drag = false;
  68. for (int i = 0; i < (MAX_ITERATIONS + 1) * PALETTE_STEP; i++)
  69. {
  70. double f = (double)i / PALETTE_STEP;
  71. double r = 0.5 * lol::sin(f * 0.27 + 2.0) + 0.5;
  72. double g = 0.5 * lol::sin(f * 0.17 - 1.8) + 0.5;
  73. double b = 0.5 * lol::sin(f * 0.21 - 2.6) + 0.5;
  74. if (f < 7.0)
  75. {
  76. f = f < 1.0 ? 0.0 : (f - 1.0) / 6.0;
  77. r *= f;
  78. g *= f;
  79. b *= f;
  80. }
  81. uint8_t red = r * 255.99f;
  82. uint8_t green = g * 255.99f;
  83. uint8_t blue = b * 255.99f;
  84. #if defined __CELLOS_LV2__ || defined _XBOX
  85. m_palette.Push(u8vec4(255, red, green, blue));
  86. #elif defined __native_client__
  87. m_palette.Push(u8vec4(red, green, blue, 255));
  88. #else
  89. m_palette.Push(u8vec4(blue, green, red, 255));
  90. #endif
  91. }
  92. #if !defined __native_client__
  93. m_centertext = new Text(NULL, "data/font/ascii.png");
  94. m_centertext->SetPos(vec3(5, m_window_size.y - 15, 1));
  95. Ticker::Ref(m_centertext);
  96. m_mousetext = new Text(NULL, "data/font/ascii.png");
  97. m_mousetext->SetPos(vec3(5, m_window_size.y - 29, 1));
  98. Ticker::Ref(m_mousetext);
  99. m_zoomtext = new Text(NULL, "data/font/ascii.png");
  100. m_zoomtext->SetPos(vec3(5, m_window_size.y - 43, 1));
  101. Ticker::Ref(m_zoomtext);
  102. #endif
  103. m_position = vec3::zero;
  104. m_bbox[0] = m_position;
  105. m_bbox[1] = vec3((vec2)m_window_size, 0);
  106. //Input::TrackMouse(this);
  107. #if LOL_FEATURE_THREADS
  108. /* Spawn worker threads and wait for their readiness. */
  109. for (int i = 0; i < MAX_THREADS; i++)
  110. m_threads[i] = new Thread(DoWorkHelper, this);
  111. for (int i = 0; i < MAX_THREADS; i++)
  112. m_spawnqueue.Pop();
  113. #endif
  114. }
  115. ~Fractal()
  116. {
  117. #if LOL_FEATURE_THREADS
  118. /* Signal worker threads for completion and wait for
  119. * them to quit. */
  120. for (int i = 0; i < MAX_THREADS; i++)
  121. m_jobqueue.Push(-1);
  122. for (int i = 0; i < MAX_THREADS; i++)
  123. m_donequeue.Pop();
  124. #endif
  125. //Input::UntrackMouse(this);
  126. #if !defined __native_client__
  127. Ticker::Unref(m_centertext);
  128. Ticker::Unref(m_mousetext);
  129. Ticker::Unref(m_zoomtext);
  130. #endif
  131. }
  132. inline dcmplx TexelToWorldOffset(vec2 texel)
  133. {
  134. double dx = (0.5 + texel.x - m_size.x / 2) * m_texel2world.x;
  135. double dy = (0.5 + m_size.y / 2 - texel.y) * m_texel2world.y;
  136. return m_radius * dcmplx(dx, dy);
  137. }
  138. inline dcmplx ScreenToWorldOffset(vec2 pixel)
  139. {
  140. /* No 0.5 offset here, because we want to be able to position the
  141. * mouse at (0,0) exactly. */
  142. double dx = pixel.x - m_window_size.x / 2;
  143. double dy = m_window_size.y / 2 - pixel.y;
  144. return m_radius * m_window2world * dcmplx(dx, dy);
  145. }
  146. virtual void TickGame(float seconds)
  147. {
  148. WorldEntity::TickGame(seconds);
  149. ivec2 mousepos = ivec2::zero; /* FIXME: input */
  150. int prev_frame = (m_frame + 4) % 4;
  151. m_frame = (m_frame + 1) % 4;
  152. rcmplx worldmouse = m_center
  153. + rcmplx(ScreenToWorldOffset((vec2)mousepos));
  154. uint32_t buttons = 0;
  155. //uint32_t buttons = Input::GetMouseButtons();
  156. #if !defined __CELLOS_LV2__ && !defined _XBOX
  157. if (buttons & 0x2)
  158. {
  159. if (!m_drag)
  160. {
  161. m_oldmouse = mousepos;
  162. m_drag = true;
  163. }
  164. m_translate = rcmplx(ScreenToWorldOffset((vec2)m_oldmouse)
  165. - ScreenToWorldOffset((vec2)mousepos));
  166. /* XXX: the purpose of this hack is to avoid translating by
  167. * an exact number of pixels. If this were to happen, the step()
  168. * optimisation for i915 cards in our shader would behave
  169. * incorrectly because a quarter of the pixels in the image
  170. * would have tied rankings in the distance calculation. */
  171. m_translate *= real(1023.0 / 1024.0);
  172. m_oldmouse = mousepos;
  173. }
  174. else
  175. {
  176. m_drag = false;
  177. if (m_translate != rcmplx(0.0, 0.0))
  178. {
  179. m_translate *= real(std::pow(2.0, -seconds * 5.0));
  180. if ((double)norm(m_translate) < m_radius * 1e-4)
  181. m_translate = rcmplx(0.0, 0.0);
  182. }
  183. }
  184. if (buttons & 0x5 && mousepos.x != -1)
  185. {
  186. double zoom = (buttons & 0x1) ? -0.5 : 0.5;
  187. m_zoom_speed += zoom * seconds;
  188. if (m_zoom_speed / zoom > 5e-3f)
  189. m_zoom_speed = zoom * 5e-3f;
  190. }
  191. else if (m_zoom_speed)
  192. {
  193. m_zoom_speed *= std::pow(2.0, -seconds * 5.0);
  194. if (lol::abs(m_zoom_speed) < 1e-5 || m_drag)
  195. m_zoom_speed = 0.0;
  196. }
  197. #endif
  198. if (m_zoom_speed || m_translate != rcmplx(0.0, 0.0))
  199. {
  200. rcmplx oldcenter = m_center;
  201. double oldradius = m_radius;
  202. double zoom = std::pow(2.0, seconds * 1e3f * m_zoom_speed);
  203. if (m_radius * zoom > 8.0)
  204. {
  205. m_zoom_speed *= -1.0;
  206. zoom = 8.0 / m_radius;
  207. }
  208. else if (m_radius * zoom < 1e-14)
  209. {
  210. m_zoom_speed *= -1.0;
  211. zoom = 1e-14 / m_radius;
  212. }
  213. m_radius *= zoom;
  214. #if !defined __CELLOS_LV2__ && !defined _XBOX
  215. m_center += m_translate;
  216. m_center = (m_center - worldmouse) * real(zoom) + worldmouse;
  217. worldmouse = m_center
  218. + rcmplx(ScreenToWorldOffset((vec2)mousepos));
  219. #endif
  220. /* Store the transformation properties to go from m_frame - 1
  221. * to m_frame. */
  222. m_deltashift[prev_frame] = (m_center - oldcenter) / real(oldradius);
  223. m_deltashift[prev_frame].x /= m_size.x * m_texel2world.x;
  224. m_deltashift[prev_frame].y /= m_size.y * m_texel2world.y;
  225. m_deltascale[prev_frame] = m_radius / oldradius;
  226. m_dirty[0] = m_dirty[1] = m_dirty[2] = m_dirty[3] = 2;
  227. }
  228. else
  229. {
  230. /* If settings didn't change, set transformation from previous
  231. * frame to identity. */
  232. m_deltashift[prev_frame] = real::R_0();
  233. m_deltascale[prev_frame] = real::R_1();
  234. }
  235. /* Transformation from current frame to current frame is always
  236. * identity. */
  237. m_zoom_settings[m_frame][0] = 0.0f;
  238. m_zoom_settings[m_frame][1] = 0.0f;
  239. m_zoom_settings[m_frame][2] = 1.0f;
  240. /* Compute transformation from other frames to current frame */
  241. for (int i = 0; i < 3; i++)
  242. {
  243. int prev_index = (m_frame + 4 - i) % 4;
  244. int cur_index = (m_frame + 3 - i) % 4;
  245. m_zoom_settings[cur_index][0] = (real)m_zoom_settings[prev_index][0] * m_deltascale[cur_index] + m_deltashift[cur_index].x;
  246. m_zoom_settings[cur_index][1] = (real)m_zoom_settings[prev_index][1] * m_deltascale[cur_index] + m_deltashift[cur_index].y;
  247. m_zoom_settings[cur_index][2] = (real)m_zoom_settings[prev_index][2] * m_deltascale[cur_index];
  248. }
  249. /* Precompute texture offset change instead of doing it in GLSL */
  250. for (int i = 0; i < 4; i++)
  251. {
  252. m_zoom_settings[i][0] += 0.5 * (1.0 - m_zoom_settings[i][2]);
  253. m_zoom_settings[i][1] -= 0.5 * (1.0 - m_zoom_settings[i][2]);
  254. }
  255. #if !defined __native_client__
  256. char buf[256];
  257. std::sprintf(buf, "center: ");
  258. m_center.x.sprintf(buf + strlen(buf), 30);
  259. std::sprintf(buf + strlen(buf), " ");
  260. m_center.y.sprintf(buf + strlen(buf), 30);
  261. m_centertext->SetText(buf);
  262. std::sprintf(buf, " mouse: ");
  263. worldmouse.x.sprintf(buf + strlen(buf), 30);
  264. std::sprintf(buf + strlen(buf), " ");
  265. worldmouse.y.sprintf(buf + strlen(buf), 30);
  266. m_mousetext->SetText(buf);
  267. std::sprintf(buf, " zoom: %g", 1.0 / m_radius);
  268. m_zoomtext->SetText(buf);
  269. #endif
  270. if (m_dirty[m_frame])
  271. {
  272. m_dirty[m_frame]--;
  273. for (int i = 0; i < m_size.y; i += MAX_LINES * 2)
  274. {
  275. #if LOL_FEATURE_THREADS
  276. m_jobqueue.Push(i);
  277. #else
  278. DoWork(i);
  279. #endif
  280. }
  281. }
  282. }
  283. #if LOL_FEATURE_THREADS
  284. static void *DoWorkHelper(void *data)
  285. {
  286. Fractal *that = (Fractal *)data;
  287. that->m_spawnqueue.Push(0);
  288. for ( ; ; )
  289. {
  290. int line = that->m_jobqueue.Pop();
  291. if (line == -1)
  292. break;
  293. that->DoWork(line);
  294. that->m_donequeue.Push(0);
  295. }
  296. that->m_donequeue.Push(0);
  297. return NULL;
  298. };
  299. #endif
  300. void DoWork(int line)
  301. {
  302. double const maxsqlen = 1024;
  303. double const k1 = 1.0 / (1 << 10) / (std::log(maxsqlen) / std::log(2.0));
  304. int jmin = ((m_frame + 1) % 4) / 2 + line;
  305. int jmax = jmin + MAX_LINES * 2;
  306. if (jmax > m_size.y)
  307. jmax = m_size.y;
  308. u8vec4 *m_pixelstart = &m_pixels[0]
  309. + m_size.x * (m_size.y / 4 * m_frame + line / 4);
  310. dcmplx c = (dcmplx)m_center;
  311. for (int j = jmin; j < jmax; j += 2)
  312. for (int i = m_frame % 2; i < m_size.x; i += 2)
  313. {
  314. double xr, yr, x0, y0, x1, y1, x2, y2, x3, y3;
  315. dcmplx z0 = c + TexelToWorldOffset(vec2(i, j));
  316. //dcmplx r0(0.28693186889504513, 0.014286693904085048);
  317. //dcmplx r0(0.001643721971153, 0.822467633298876);
  318. //dcmplx r0(-1.207205434596, 0.315432814901);
  319. //dcmplx r0(-0.79192956889854, -0.14632423080102);
  320. //dcmplx r0(0.3245046418497685, 0.04855101129280834);
  321. dcmplx r0 = z0;
  322. x0 = z0.x; y0 = z0.y;
  323. xr = r0.x; yr = r0.y;
  324. int iter = MAX_ITERATIONS - 4;
  325. for (;;)
  326. {
  327. /* Unroll the loop: tests are more expensive to do at each
  328. * iteration than the few extra multiplications. */
  329. x1 = x0 * x0 - y0 * y0 + xr;
  330. y1 = x0 * y0 + x0 * y0 + yr;
  331. x2 = x1 * x1 - y1 * y1 + xr;
  332. y2 = x1 * y1 + x1 * y1 + yr;
  333. x3 = x2 * x2 - y2 * y2 + xr;
  334. y3 = x2 * y2 + x2 * y2 + yr;
  335. x0 = x3 * x3 - y3 * y3 + xr;
  336. y0 = x3 * y3 + x3 * y3 + yr;
  337. if (x0 * x0 + y0 * y0 >= maxsqlen)
  338. break;
  339. iter -= 4;
  340. if (iter < 4)
  341. break;
  342. }
  343. if (iter)
  344. {
  345. double n = x0 * x0 + y0 * y0;
  346. if (x1 * x1 + y1 * y1 >= maxsqlen)
  347. {
  348. iter += 3; n = x1 * x1 + y1 * y1;
  349. }
  350. else if (x2 * x2 + y2 * y2 >= maxsqlen)
  351. {
  352. iter += 2; n = x2 * x2 + y2 * y2;
  353. }
  354. else if (x3 * x3 + y3 * y3 >= maxsqlen)
  355. {
  356. iter += 1; n = x3 * x3 + y3 * y3;
  357. }
  358. if (n > maxsqlen * maxsqlen)
  359. n = maxsqlen * maxsqlen;
  360. /* Approximate log(sqrt(n))/log(sqrt(maxsqlen)) */
  361. double f = iter;
  362. union { double n; uint64_t x; } u = { n };
  363. double k = (u.x >> 42) - (((1 << 10) - 1) << 10);
  364. k *= k1;
  365. /* Approximate log2(k) in [1,2]. */
  366. f += (- 0.344847817623168308695977510213252644185 * k
  367. + 2.024664188044341212602376988171727038739) * k
  368. - 1.674876738008591047163498125918330313237;
  369. *m_pixelstart++ = m_palette[(int)(f * PALETTE_STEP)];
  370. }
  371. else
  372. {
  373. #if defined __CELLOS_LV2__ || defined _XBOX
  374. *m_pixelstart++ = u8vec4(255, 0, 0, 0);
  375. #else
  376. *m_pixelstart++ = u8vec4(0, 0, 0, 255);
  377. #endif
  378. }
  379. }
  380. }
  381. virtual void TickDraw(float seconds, Scene &scene)
  382. {
  383. WorldEntity::TickDraw(seconds, scene);
  384. static float const vertices[] =
  385. {
  386. 1.0f, 1.0f,
  387. -1.0f, 1.0f,
  388. -1.0f, -1.0f,
  389. -1.0f, -1.0f,
  390. 1.0f, -1.0f,
  391. 1.0f, 1.0f,
  392. };
  393. static float const texcoords[] =
  394. {
  395. 1.0f, 1.0f,
  396. 0.0f, 1.0f,
  397. 0.0f, 0.0f,
  398. 0.0f, 0.0f,
  399. 1.0f, 0.0f,
  400. 1.0f, 1.0f,
  401. };
  402. if (!m_ready)
  403. {
  404. /* Create a texture of half the width and twice the height
  405. * so that we can upload four different subimages each frame. */
  406. m_texture = new Texture(ivec2(m_size.x / 2, m_size.y * 2),
  407. PixelFormat::RGBA_8);
  408. /* Ensure the texture data is complete at least once, otherwise
  409. * uploading subimages will not work. */
  410. m_texture->SetData(&m_pixels[0]);
  411. m_shader = Shader::Create(LOLFX_RESOURCE_NAME(11_fractal));
  412. m_vertexattrib = m_shader->GetAttribLocation(VertexUsage::Position, 0);
  413. m_texattrib = m_shader->GetAttribLocation(VertexUsage::TexCoord, 0);
  414. m_texeluni = m_shader->GetUniformLocation("u_TexelSize");
  415. m_screenuni = m_shader->GetUniformLocation("u_ScreenSize");
  416. m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings");
  417. m_vdecl =
  418. new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
  419. VertexStream<vec2>(VertexUsage::TexCoord));
  420. m_vbo = new VertexBuffer(sizeof(vertices));
  421. m_tbo = new VertexBuffer(sizeof(texcoords));
  422. void *tmp = m_vbo->Lock(0, 0);
  423. memcpy(tmp, vertices, sizeof(vertices));
  424. m_vbo->Unlock();
  425. tmp = m_tbo->Lock(0, 0);
  426. memcpy(tmp, texcoords, sizeof(texcoords));
  427. m_tbo->Unlock();
  428. /* FIXME: this object never cleans up */
  429. m_ready = true;
  430. }
  431. m_texture->Bind();
  432. if (m_dirty[m_frame])
  433. {
  434. #if LOL_FEATURE_THREADS
  435. for (int i = 0; i < m_size.y; i += MAX_LINES * 2)
  436. m_donequeue.Pop();
  437. #endif
  438. m_dirty[m_frame]--;
  439. #if defined __CELLOS_LV2__
  440. /* glTexSubImage2D is extremely slow on the PS3, to the point
  441. * that uploading the whole texture is 40 times faster. */
  442. m_texture->SetData(&m_pixels[0]);
  443. #else
  444. m_texture->SetSubData(ivec2(0, m_frame * m_size.y / 2),
  445. m_size / 2,
  446. &m_pixels[m_size.x * m_size.y / 4 * m_frame]);
  447. #endif
  448. }
  449. m_shader->Bind();
  450. m_shader->SetUniform(m_texeluni, m_texel_settings);
  451. m_shader->SetUniform(m_screenuni, m_screen_settings);
  452. m_shader->SetUniform(m_zoomuni, m_zoom_settings);
  453. m_vdecl->Bind();
  454. m_vdecl->SetStream(m_vbo, m_vertexattrib);
  455. m_vdecl->SetStream(m_tbo, m_texattrib);
  456. m_texture->Bind();
  457. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
  458. m_vdecl->Unbind();
  459. }
  460. private:
  461. static int const MAX_ITERATIONS = 340;
  462. static int const PALETTE_STEP = 32;
  463. static int const MAX_THREADS = 8;
  464. static int const MAX_LINES = 8;
  465. ivec2 m_size, m_window_size, m_oldmouse;
  466. double m_window2world;
  467. dvec2 m_texel2world;
  468. array<u8vec4> m_pixels, m_palette;
  469. Shader *m_shader;
  470. ShaderAttrib m_vertexattrib, m_texattrib;
  471. ShaderUniform m_texeluni, m_screenuni, m_zoomuni;
  472. VertexDeclaration *m_vdecl;
  473. VertexBuffer *m_vbo, *m_tbo;
  474. Texture *m_texture;
  475. int m_frame, m_slices, m_dirty[4];
  476. bool m_ready, m_drag;
  477. rcmplx m_deltashift[4], m_center, m_translate;
  478. real m_deltascale[4];
  479. double m_zoom_speed, m_radius;
  480. vec4 m_texel_settings, m_screen_settings;
  481. mat4 m_zoom_settings;
  482. #if LOL_FEATURE_THREADS
  483. /* Worker threads */
  484. Thread *m_threads[MAX_THREADS];
  485. Queue<int> m_spawnqueue, m_jobqueue, m_donequeue;
  486. #endif
  487. #if !defined __native_client__
  488. /* Debug information */
  489. Text *m_centertext, *m_mousetext, *m_zoomtext;
  490. #endif
  491. };
  492. int main(int argc, char **argv)
  493. {
  494. ivec2 window_size(640, 480);
  495. System::Init(argc, argv);
  496. Application app("Tutorial 3: Fractal", window_size, 60.0f);
  497. new DebugFps(5, 5);
  498. new Fractal(window_size);
  499. //new DebugRecord("fractalol.ogm", 60.0f);
  500. app.Run();
  501. return EXIT_SUCCESS;
  502. }