source: trunk/tools/neercs/neercs.cpp @ 1683

Last change on this file since 1683 was 1683, checked in by rez, 9 years ago

moved blur after glow, tweaked a lot of parameters

File size: 4.9 KB
RevLine 
[1447]1//
2// Neercs
3//
4// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
5//
6
7#if defined HAVE_CONFIG_H
8#   include "config.h"
9#endif
10
11#if defined _WIN32
12#   include <direct.h>
13#endif
14
15#if defined _XBOX
16#   define _USE_MATH_DEFINES /* for M_PI */
17#   include <xtl.h>
18#   undef near /* Fuck Microsoft */
19#   undef far /* Fuck Microsoft again */
20#elif defined _WIN32
21#   define _USE_MATH_DEFINES /* for M_PI */
22#   define WIN32_LEAN_AND_MEAN
23#   include <windows.h>
24#   undef near /* Fuck Microsoft */
25#   undef far /* Fuck Microsoft again */
26#else
27#   include <cmath>
28#endif
29
[1486]30#include <time.h>
[1462]31#include <caca.h>
32
[1447]33#include "core.h"
34#include "loldebug.h"
35
36using namespace std;
37using namespace lol;
38
39#include "neercs.h"
[1456]40#include "video/render.h"
[1447]41
[1660]42#define USE_OLD_NEERCS 0
43
[1642]44extern "C"
45{
46#include "old/neercs.h"
47}
48
49Neercs::Neercs(int argc, char **argv)
[1462]50  : m_ready(false),
[1625]51    m_caca(caca_create_canvas(10, 10)),
[1462]52    m_render(new Render(m_caca)),
53    m_time(0.f)
[1447]54{
[1462]55    Ticker::Ref(m_render);
[1660]56
57#if USE_OLD_NEERCS
58    m_buf = NULL;
59    m_screen_list = init_neercs(argc, argv);
60    if (!m_screen_list)
61        exit(-1);
62    m_screen_list->last_key_time = get_us();
63#endif
[1447]64}
65
[1602]66int Neercs::hex_color(float r, float g, float b)
67{
[1660]68    return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
[1602]69}
70
[1447]71void Neercs::TickGame(float seconds)
72{
73    WorldEntity::TickGame(seconds);
[1462]74
[1660]75#if USE_OLD_NEERCS
76    mainloop_tick(&m_buf, m_screen_list);
77#endif
78
[1462]79    m_time += seconds;
80
[1661]81    /* draw something awesome */
[1602]82    int bg_color = 0x222;
83    int w = caca_get_canvas_width(m_caca);
84    int h = caca_get_canvas_height(m_caca);
85
86    caca_set_color_argb(m_caca, 0xfff, bg_color);
[1462]87    caca_clear_canvas(m_caca);
88
[1661]89    caca_set_color_argb(m_caca, 0x545, bg_color);
[1634]90    for(int i = 0; i < h; i++)
91    {
92        float a = M_PI / 180 * i * 16 + m_time * 4;
93        float b = M_PI / 180 * i * 12;
[1683]94        int x = w / 2  - 14 + w / 4 * lol::cos(a) + w / 4 * lol::sin(b);
95        caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ");
[1634]96    }
97
[1602]98    caca_set_color_argb(m_caca, 0x444, bg_color);
[1634]99    for(int i = 0; i < w; i++)
[1602]100    {
[1634]101        float a = m_time * 1 + M_PI / 180 * i * 8;
102        float b = m_time * -2 + M_PI / 180 * i * 5;
103        int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
[1636]104        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);
[1634]105        caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
[1602]106    }
107
[1661]108/* __  _________ ______ ______ ______ ______
109  /  \/  /  __  >  __  >  __  >  ___//  ___/ \x0a9
[1655]110 /      /  ____/  ____/  __  <  <____\___  \
[1661]111/__/\__/\_______________/  \________________\ */
[1620]112
[1655]113    int logo_x = (w - 46) / 2;
[1661]114    int logo_y = h / 2 - 2;// + h / 4 * lol::cos(m_time * 2);
[1629]115
[1636]116    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);
[1658]117    caca_put_str(m_caca, logo_x + 3, logo_y    ,"__  _________ ______ ______ ______ ______");
[1636]118    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);
[1663]119    caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/  \\/  /  __  >  __  >  __  >  ___//  ___/ \x0a9");
[1636]120    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);
[1655]121    caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/      /  ____/  ____/  __  <  <____\\___  \\");
[1636]122    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);
[1655]123    caca_put_str(m_caca, logo_x    , logo_y + 3, "/__/\\__/\\_______________/  \\________________\\");
[1602]124    caca_set_color_argb(m_caca, 0xdef, bg_color);
[1620]125    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
[1602]126
[1634]127    caca_set_color_argb(m_caca, 0x666, bg_color);
[1636]128    caca_printf(m_caca, 2, h - 3, "W=%i", w);
129    caca_printf(m_caca, 2, h - 2, "H=%i", h);
130
[1644]131    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
[1636]132    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
[1683]133
134    caca_set_color_argb(m_caca, 0xdef, bg_color);
135    caca_put_str(m_caca, 0, 0, "mdr@lol:~/ cd code/lolengine/");
136    caca_put_str(m_caca, 0, 1, "mdr@lol:~/code/lolengine/ cd /var/log/");
137    caca_put_str(m_caca, 0, 2, "mdr@lol:/var/log/");
[1447]138}
139
[1602]140
[1447]141void Neercs::TickDraw(float seconds)
142{
143    WorldEntity::TickDraw(seconds);
144}
145
146Neercs::~Neercs()
147{
[1660]148#if USE_OLD_NEERCS
149    free(m_buf);
150    free_screen_list(m_screen_list);
151#endif
152
[1462]153    Ticker::Unref(m_render);
[1447]154}
155
156int main(int argc, char **argv)
157{
[1456]158    Application app("Neercs", ivec2(800, 600), 60.0f);
[1447]159
160#if defined _MSC_VER && !defined _XBOX
161    _chdir("..");
162#elif defined _WIN32 && !defined _XBOX
163    _chdir("../..");
164#endif
165
[1642]166    new Neercs(argc, argv);
[1618]167    new DebugFps(2, 2);
[1447]168    app.ShowPointer(false);
169
170    app.Run();
171
172    return EXIT_SUCCESS;
173}
174
Note: See TracBrowser for help on using the repository browser.