Changeset 1856


Ignore:
Timestamp:
Sep 1, 2012, 7:40:57 PM (7 years ago)
Author:
sam
Message:

neercs: create new Term and Pty classes that will contain the real stuff.

Location:
trunk/tools/neercs
Files:
4 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tools/neercs/Makefile.am

    r1836 r1856  
    88    \
    99    $(old_sources) \
     10    \
     11    term/term.cpp term/term.h \
     12    term/pty.cpp term/pty.h \
    1013    \
    1114    video/render.cpp video/render.h \
  • trunk/tools/neercs/neercs.cpp

    r1837 r1856  
    4040#include "video/render.h"
    4141
    42 #define USE_OLD_NEERCS 0
    43 
    4442extern "C"
    4543{
     
    4846
    4947Neercs::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)
     48  : m_term(new Term(ivec2(80, 25))),
     49    m_render(new Render(m_term->GetCaca())),
     50    m_ready(false)
    5451{
     52    Ticker::Ref(m_term);
    5553    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 
    66 int 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);
    6954}
    7055
     
    7257{
    7358    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 awesome */
    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, 0xfff, 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  - 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");
    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   /  \/  /  __  >  __  >  __  >  ___//  ___/ \x0a9
    110  /      /  ____/  ____/  __  <  <____\___  \
    111 /__/\__/\_______________/  \________________\ */
    112 
    113     int logo_x = (w - 46) / 2;
    114     int logo_y = h / 2 - 2;
    115 
    116     caca_set_color_argb(m_caca, 0x8ac, bg_color);
    117     //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);
    118     caca_put_str(m_caca, logo_x + 3, logo_y    ,"__  _________ ______ ______ ______ ______");
    119     //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);
    120     caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/  \\/  /  __  >  __  >  __  >  ___//  ___/ \x0a9");
    121     //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);
    122     caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/      /  ____/  ____/  __  <  <____\\___  \\");
    123     //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);
    124     caca_put_str(m_caca, logo_x    , logo_y + 3, "/__/\\__/\\_______________/  \\________________\\");
    125     caca_set_color_argb(m_caca, 0xdef, bg_color);
    126     caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
    127 
    128     caca_set_color_argb(m_caca, 0x666, bg_color);
    129     caca_printf(m_caca, 2, h - 3, "W=%i", w);
    130     caca_printf(m_caca, 2, h - 2, "H=%i", h);
    131 
    132     caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
    133     caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
    134 
    135 /*
    136   _______
    137  /      /|
    138 /______/ |
    139 |      | |
    140 |  :D  | /
    141 |______|/
    142 */
    143 
    144     int lolcube_x = w / 2 - 5 + (w - 10) * lol::cos(m_time / 2);
    145     int lolcube_y = h - 5 - abs ((h - 5) * lol::sin(m_time * 4));
    146 
    147     caca_set_color_argb(m_caca, hex_color(0.75f + 0.25f * lol::sin(m_time * 2), 0.75f + 0.25f * lol::cos(m_time * 3), 0.75f + 0.25f * lol::sin(m_time * 5)), bg_color);
    148     caca_put_str(m_caca, lolcube_x + 2, lolcube_y    , "_______");
    149     caca_put_str(m_caca, lolcube_x + 1, lolcube_y + 1, "/      /|");
    150     caca_put_str(m_caca, lolcube_x    , lolcube_y + 2, "/______/ |");
    151     caca_put_str(m_caca, lolcube_x    , lolcube_y + 3, "|      | |");
    152     caca_put_str(m_caca, lolcube_x    , lolcube_y + 4, "|  :D  | /");
    153     caca_put_str(m_caca, lolcube_x    , lolcube_y + 5, "|______|/");
    154 
    155     caca_set_color_argb(m_caca, 0xdef, bg_color);
    156     caca_put_str(m_caca, 0, 0, "rez@lol:~/ sudo -s");
    157     caca_put_str(m_caca, 0, 1, "[sudo] password for rez:");
    158     caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL");
    159     caca_put_str(m_caca, 0, 3, "LOL");
    160     caca_put_str(m_caca, 0, 4, "root@lol:~/");
    16159}
    16260
     
    16967Neercs::~Neercs()
    17068{
    171 #if USE_OLD_NEERCS
    172     free(m_buf);
    173     free_screen_list(m_screen_list);
    174 #endif
    175 
     69    Ticker::Unref(m_term);
    17670    Ticker::Unref(m_render);
    17771}
  • trunk/tools/neercs/neercs.h

    r1660 r1856  
    1111
    1212#include "video/render.h"
     13#include "term/term.h"
    1314
    1415extern "C"
     
    2526    char const *GetName() { return "<neercs>"; }
    2627
    27     int hex_color(float r, float g, float b);
    28 
    2928protected:
    3029    virtual void TickGame(float seconds);
     
    3231
    3332private:
     33    Term *m_term;
     34    Render *m_render;
     35
    3436    bool m_ready;
    35     caca_canvas_t *m_caca;
    36     Render *m_render;
    37     float m_time;
    38 
    39     /* Old neercs stuff */
    40     char *m_buf;
    41     struct screen_list *m_screen_list;
    4237};
    4338
  • trunk/tools/neercs/neercs.vcxproj

    r1836 r1856  
    4242    <ClInclude Include="old\python\py_module.h" />
    4343    <ClInclude Include="old\widgets.h" />
     44    <ClInclude Include="term\pty.h" />
     45    <ClInclude Include="term\term.h" />
    4446    <ClInclude Include="video\render.h" />
    4547    <ClInclude Include="video\text-render.h" />
     
    7072    <ClCompile Include="old\widgets.c" />
    7173    <ClCompile Include="old\wm.cpp" />
     74    <ClInclude Include="term\pty.cpp" />
     75    <ClInclude Include="term\term.cpp" />
    7276    <ClCompile Include="video\render.cpp" />
    7377    <ClCompile Include="video\text-render.cpp" />
  • trunk/tools/neercs/term/term.cpp

    r1855 r1856  
    11//
    22// Neercs
    3 //
    4 // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
    53//
    64
     
    97#endif
    108
    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 
    339#include "core.h"
    34 #include "loldebug.h"
     10#include "lolgl.h"
    3511
    3612using namespace std;
    3713using namespace lol;
    3814
    39 #include "neercs.h"
    40 #include "video/render.h"
     15#include "../neercs.h"
     16#include "term.h"
    4117
    42 #define USE_OLD_NEERCS 0
    43 
    44 extern "C"
     18Term::Term(ivec2 size)
     19  : m_time(0.f)
    4520{
    46 #include "old/neercs.h"
     21    m_caca = caca_create_canvas(size.x, size.y);
    4722}
    4823
    49 Neercs::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)
     24void Term::TickGame(float seconds)
    5425{
    55     Ticker::Ref(m_render);
     26    Entity::TickGame(seconds);
    5627
    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();
     28#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
     29    /* This is the real terminal code */
     30    /* XXX: for now we draw fancy shit */
     31    m_time += seconds;
     32    DrawFancyShit();
     33#else
     34    /* Unsupported platform - draw some fancy shit instead */
     35    m_time += seconds;
     36    DrawFancyShit();
    6337#endif
    6438}
    6539
    66 int Neercs::hex_color(float r, float g, float b)
     40void Term::TickDraw(float seconds)
    6741{
    68     return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
     42    Entity::TickDraw(seconds);
    6943}
    7044
    71 void Neercs::TickGame(float seconds)
     45Term::~Term()
    7246{
    73     WorldEntity::TickGame(seconds);
     47}
    7448
    75 #if USE_OLD_NEERCS
    76     mainloop_tick(&m_buf, m_screen_list);
    77 #endif
     49/*
     50 * XXX: fancy shit below
     51 */
    7852
    79     m_time += seconds;
     53static uint32_t hex_color(float r, float g, float b)
     54{
     55    return ((uint32_t)(r * 15.99f) << 8) |
     56           ((uint32_t)(g * 15.99f) << 4) |
     57           (uint32_t)(b * 15.99f);
     58}
    8059
     60void Term::DrawFancyShit()
     61{
    8162    /* draw something awesome */
    8263    int bg_color = 0x222;
     
    161142}
    162143
    163 
    164 void Neercs::TickDraw(float seconds)
    165 {
    166     WorldEntity::TickDraw(seconds);
    167 }
    168 
    169 Neercs::~Neercs()
    170 {
    171 #if USE_OLD_NEERCS
    172     free(m_buf);
    173     free_screen_list(m_screen_list);
    174 #endif
    175 
    176     Ticker::Unref(m_render);
    177 }
    178 
    179 int main(int argc, char **argv)
    180 {
    181     Application app("Neercs", ivec2(800, 600), 60.0f);
    182 
    183 #if defined _MSC_VER && !defined _XBOX
    184     _chdir("..");
    185 #elif defined _WIN32 && !defined _XBOX
    186     _chdir("../..");
    187 #endif
    188 
    189     new Neercs(argc, argv);
    190     new DebugFps(2, 2);
    191     app.ShowPointer(false);
    192 
    193     app.Run();
    194 
    195     return EXIT_SUCCESS;
    196 }
    197 
Note: See TracChangeset for help on using the changeset viewer.