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

Last change on this file since 1660 was 1660, checked in by sam, 8 years ago

neercs: add a way to activate the old neercs code for testing purposes.

File size: 4.7 KB
Line 
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
30#include <time.h>
31#include <caca.h>
32
33#include "core.h"
34#include "loldebug.h"
35
36using namespace std;
37using namespace lol;
38
39#include "neercs.h"
40#include "video/render.h"
41
42#define USE_OLD_NEERCS 0
43
44extern "C"
45{
46#include "old/neercs.h"
47}
48
49Neercs::Neercs(int argc, char **argv)
50  : m_ready(false),
51    m_caca(caca_create_canvas(10, 10)),
52    m_render(new Render(m_caca)),
53    m_time(0.f)
54{
55    Ticker::Ref(m_render);
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
64}
65
66int Neercs::hex_color(float r, float g, float b)
67{
68    return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
69}
70
71void Neercs::TickGame(float seconds)
72{
73    WorldEntity::TickGame(seconds);
74
75#if USE_OLD_NEERCS
76    mainloop_tick(&m_buf, m_screen_list);
77#endif
78
79    m_time += seconds;
80
81    /* draw something */
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);
87    caca_clear_canvas(m_caca);
88
89    caca_set_color_argb(m_caca, 0xa46, bg_color);
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;
94        int x = w / 2  - 15 + h / 3 * lol::cos(a) + h / 4 * lol::sin(b);
95        caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ!");
96    }
97
98    caca_set_color_argb(m_caca, 0x444, bg_color);
99    for(int i = 0; i < w; i++)
100    {
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);
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);
105        caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
106    }
107
108/*
109   __  _________ ______ ______ ______ ______
110  /  \/  /  __  Y  __  Y  __  Y  ___//  ___/
111 /      /  ____/  ____/  __  <  <____\___  \
112/__/\__/\_______________/  \________________\
113*/
114
115    int logo_x = (w - 46) / 2;
116    int logo_y = h / 2 - 2;
117
118    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);
119    caca_put_str(m_caca, logo_x + 3, logo_y    ,"__  _________ ______ ______ ______ ______");
120    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);
121    caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/  \\/  /  __  Y  __  Y  __  Y  ___//  ___/");
122    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);
123    caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/      /  ____/  ____/  __  <  <____\\___  \\");
124    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);
125    caca_put_str(m_caca, logo_x    , logo_y + 3, "/__/\\__/\\_______________/  \\________________\\");
126    caca_set_color_argb(m_caca, 0xdef, bg_color);
127    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
128
129    caca_set_color_argb(m_caca, 0x666, bg_color);
130    caca_printf(m_caca, 2, h - 3, "W=%i", w);
131    caca_printf(m_caca, 2, h - 2, "H=%i", h);
132
133    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
134    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
135}
136
137
138void Neercs::TickDraw(float seconds)
139{
140    WorldEntity::TickDraw(seconds);
141}
142
143Neercs::~Neercs()
144{
145#if USE_OLD_NEERCS
146    free(m_buf);
147    free_screen_list(m_screen_list);
148#endif
149
150    Ticker::Unref(m_render);
151}
152
153int main(int argc, char **argv)
154{
155    Application app("Neercs", ivec2(800, 600), 60.0f);
156
157#if defined _MSC_VER && !defined _XBOX
158    _chdir("..");
159#elif defined _WIN32 && !defined _XBOX
160    _chdir("../..");
161#endif
162
163    new Neercs(argc, argv);
164    new DebugFps(2, 2);
165    app.ShowPointer(false);
166
167    app.Run();
168
169    return EXIT_SUCCESS;
170}
171
Note: See TracBrowser for help on using the repository browser.