Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

211 lignes
6.7 KiB

  1. //
  2. // Neercs
  3. //
  4. #if defined HAVE_CONFIG_H
  5. # include "config.h"
  6. #endif
  7. #if defined _XBOX
  8. # define _USE_MATH_DEFINES /* for M_PI */
  9. # include <xtl.h>
  10. #elif defined _WIN32
  11. # define _USE_MATH_DEFINES /* for M_PI */
  12. # define WIN32_LEAN_AND_MEAN
  13. # include <windows.h>
  14. #endif
  15. #include "core.h"
  16. using namespace std;
  17. using namespace lol;
  18. #include "../neercs.h"
  19. #include "term.h"
  20. Term::Term(ivec2 size)
  21. : m_pty(0),
  22. m_caca(caca_create_canvas(size.x, size.y)),
  23. m_size(size),
  24. m_title(0),
  25. m_time(0.f)
  26. {
  27. #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
  28. m_pty = new Pty();
  29. char const *shell = getenv("SHELL");
  30. if (!shell)
  31. shell = "/bin/sh";
  32. m_pty->Run(shell, size);
  33. #endif
  34. }
  35. void Term::TickGame(float seconds)
  36. {
  37. Entity::TickGame(seconds);
  38. #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
  39. bool have_ctrl = Input::GetStatus(Key::LeftCtrl)
  40. || Input::GetStatus(Key::RightCtrl);
  41. bool have_shift = Input::GetStatus(Key::LeftShift)
  42. || Input::GetStatus(Key::RightShift);
  43. for (int i = 0x0; i < 0x7f; ++i)
  44. {
  45. if (Input::WasPressed((Key::Value)i))
  46. {
  47. if (have_ctrl && i >= 'a' && i <= 'z')
  48. {
  49. char c = i + 1 - 'a';
  50. m_pty->WriteData(&c, 1);
  51. }
  52. else if (have_shift && i >= 'a' && i <= 'z')
  53. {
  54. char c = i + 'A' - 'a';
  55. m_pty->WriteData(&c, 1);
  56. }
  57. else
  58. {
  59. char c = i;
  60. m_pty->WriteData(&c, 1);
  61. }
  62. }
  63. }
  64. /* This is the real terminal code */
  65. /* XXX: for now we draw fancy shit */
  66. m_time += seconds;
  67. m_pty->SetWindowSize(ivec2(caca_get_canvas_width(m_caca),
  68. caca_get_canvas_height(m_caca)));
  69. size_t total = 0;
  70. for (;;)
  71. {
  72. char buf[BUFSIZ];
  73. size_t current = m_pty->ReadData(buf, BUFSIZ);
  74. if (current <= 0)
  75. break;
  76. total += current;
  77. size_t processed = ReadAnsi(buf, current);
  78. if (processed < current)
  79. m_pty->UnreadData(buf + processed, current - processed);
  80. if (current < BUFSIZ)
  81. break;
  82. // if (total > 10000)
  83. // break;
  84. }
  85. #else
  86. /* Unsupported platform - draw some fancy shit instead */
  87. m_time += seconds;
  88. DrawFancyShit();
  89. #endif
  90. }
  91. void Term::TickDraw(float seconds)
  92. {
  93. Entity::TickDraw(seconds);
  94. }
  95. Term::~Term()
  96. {
  97. #if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
  98. delete m_pty;
  99. #endif
  100. caca_free_canvas(m_caca);
  101. }
  102. /*
  103. * XXX: fancy shit below
  104. */
  105. static uint32_t hex_color(float r, float g, float b)
  106. {
  107. return ((uint32_t)(r * 15.99f) << 8) |
  108. ((uint32_t)(g * 15.99f) << 4) |
  109. (uint32_t)(b * 15.99f);
  110. }
  111. void Term::DrawFancyShit()
  112. {
  113. /* draw something awesome */
  114. int bg_color = 0x222;
  115. int w = caca_get_canvas_width(m_caca);
  116. int h = caca_get_canvas_height(m_caca);
  117. caca_set_color_argb(m_caca, 0xfff, bg_color);
  118. caca_clear_canvas(m_caca);
  119. caca_set_color_argb(m_caca, 0xfff, bg_color);
  120. for(int i = 0; i < h; i++)
  121. {
  122. float a = M_PI / 180 * i * 16 + m_time * 4;
  123. float b = M_PI / 180 * i * 12;
  124. int x = w / 2 - 14 + w / 4 * lol::cos(a) + w / 4 * lol::sin(b);
  125. caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ");
  126. }
  127. caca_set_color_argb(m_caca, 0x444, bg_color);
  128. for(int i = 0; i < w; i++)
  129. {
  130. float a = m_time * 1 + M_PI / 180 * i * 8;
  131. float b = m_time * -2 + M_PI / 180 * i * 5;
  132. int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
  133. caca_set_color_argb(m_caca, hex_color(0.25f + 0.5f / w * i - 0.25f / h * y, 0.25f, 0.25f + 0.25f / w * i + 0.25f / h * y), bg_color);
  134. caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
  135. }
  136. /* __ _________ ______ ______ ______ ______
  137. / \/ / __ > __ > __ > ___// ___/ \x0a9
  138. / / ____/ ____/ __ < <____\___ \
  139. /__/\__/\_______________/ \________________\ */
  140. int logo_x = (w - 46) / 2;
  141. int logo_y = h / 2 - 2;
  142. caca_set_color_argb(m_caca, 0xbac, bg_color);
  143. //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 ), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color);
  144. caca_put_str(m_caca, logo_x + 3, logo_y ,"__ _________ ______ ______ ______ ______");
  145. //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 1), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color);
  146. caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/ \\/ / __ > __ > __ > ___// ___/ \x0a9");
  147. //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 2), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color);
  148. caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/ / ____/ ____/ __ < <____\\___ \\");
  149. //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 3), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color);
  150. caca_put_str(m_caca, logo_x , logo_y + 3, "/__/\\__/\\_______________/ \\________________\\");
  151. caca_set_color_argb(m_caca, 0x269, bg_color);
  152. caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
  153. caca_set_color_argb(m_caca, 0x777, bg_color);
  154. caca_printf(m_caca, 2, h - 3, "W=%i", w);
  155. caca_printf(m_caca, 2, h - 2, "H=%i", h);
  156. caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
  157. caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
  158. /*
  159. _______
  160. / /|
  161. /______/ |
  162. | | |
  163. | :D | /
  164. |______|/
  165. */
  166. int lolcube_x = w / 2 - 5 + (w - 10) * lol::cos(m_time / 2);
  167. int lolcube_y = h - 5 - abs ((h - 5) * lol::sin(m_time * 4));
  168. caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::sin(m_time * 2), 0.5f + 0.5f * lol::cos(m_time * 3), 0.5f + 0.5f * lol::sin(m_time * 5)), bg_color);
  169. caca_put_str(m_caca, lolcube_x + 2, lolcube_y , "_______");
  170. caca_put_str(m_caca, lolcube_x + 1, lolcube_y + 1, "/ /|");
  171. caca_put_str(m_caca, lolcube_x , lolcube_y + 2, "/______/ |");
  172. caca_put_str(m_caca, lolcube_x , lolcube_y + 3, "| | |");
  173. caca_put_str(m_caca, lolcube_x , lolcube_y + 4, "| :D | /");
  174. caca_put_str(m_caca, lolcube_x , lolcube_y + 5, "|______|/");
  175. caca_set_color_argb(m_caca, 0x777, bg_color);
  176. caca_put_str(m_caca, 0, 0, "rez@lol:~/ sudo -s");
  177. caca_put_str(m_caca, 0, 1, "[sudo] password for rez:");
  178. caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL");
  179. caca_put_str(m_caca, 0, 3, "LOL");
  180. caca_put_str(m_caca, 0, 4, "root@lol:~/");
  181. }