Changeset 1462


Ignore:
Timestamp:
Jun 12, 2012, 11:47:33 PM (11 years ago)
Author:
sam
Message:

neercs: use a libcaca canvas instead of a character string.

Location:
trunk/neercs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/neercs/Makefile.am

    r1456 r1462  
    11
     2if USE_CACA
    23noinst_PROGRAMS = neercs
     4endif
    35
    46neercs_SOURCES = \
     
    1113neercs_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    1214neercs_LDADD =
    13 neercs_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
     15neercs_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ @CACA_LIBS@
    1416neercs_DEPENDENCIES = $(top_builddir)/src/liblol.a
    1517
  • trunk/neercs/neercs.cpp

    r1456 r1462  
    3232#endif
    3333
     34#include <caca.h>
     35
    3436#include "core.h"
    3537#include "loldebug.h"
     
    4244
    4345Neercs::Neercs()
    44   : m_ready(false)
     46  : m_ready(false),
     47    m_caca(caca_create_canvas(43, 14)),
     48    m_render(new Render(m_caca)),
     49    m_time(0.f)
    4550{
     51    Ticker::Ref(m_render);
    4652}
    4753
     
    4955{
    5056    WorldEntity::TickGame(seconds);
     57
     58    m_time += seconds;
     59
     60    caca_set_color_ansi(m_caca, CACA_DEFAULT, CACA_DEFAULT);
     61    caca_clear_canvas(m_caca);
     62
     63    caca_fill_ellipse(m_caca, 0, 0, 30, 10, '+');
     64
     65    caca_set_color_ansi(m_caca, 2, CACA_DEFAULT);
     66    int x1 = 12 + 10 * cos(m_time * 5.f);
     67    int y1 = 6 + 5 * sin(m_time * 5.f);
     68    int x2 = 30 + 5 * cos(m_time * 8.f);
     69    int y2 = 8 + 5 * sin(m_time * 8.f);
     70    int y3 = 8 + 5 * cos(m_time * 5.f);
     71    caca_draw_thin_line(m_caca, x1, y1, x2, y2);
     72    caca_draw_thin_line(m_caca, 40, y3, x2, y2);
     73    caca_draw_thin_line(m_caca, x1, y1, 40, y3);
     74
     75    int x3 = 13 + 7 * cos(m_time * 3.f);
     76    caca_set_color_ansi(m_caca, CACA_CYAN, CACA_BLUE);
     77    caca_printf(m_caca, x3, 3, " LOL WUT ");
     78
     79    int x4 = 6 + 5 * cos(m_time * 2.f);
     80    caca_set_color_ansi(m_caca, CACA_YELLOW, CACA_RED);
     81    caca_printf(m_caca, x4, 12, "Le Caca C'Est Surpuissant");
    5182}
    5283
     
    5889Neercs::~Neercs()
    5990{
     91    Ticker::Unref(m_render);
    6092}
    6193
     
    71103
    72104    new Neercs();
    73     new Render();
    74105    new DebugFps(5, 5);
    75106    app.ShowPointer(false);
  • trunk/neercs/neercs.h

    r1447 r1462  
    77#if !defined __NEERCS_H__
    88#define __NEERCS_H__
     9
     10#include <caca.h>
    911
    1012#include "video/render.h"
     
    2426private:
    2527    bool m_ready;
     28    caca_canvas_t *m_caca;
     29    Render *m_render;
     30    float m_time;
    2631};
    2732
  • trunk/neercs/video/render.cpp

    r1461 r1462  
    5252int active = true;         // window active flag
    5353bool fullscreen = DEBUG?false:true;    // fullscreen flag
    54 bool pause = false;        // pause flag
     54bool paused = false;       // pause flag
    5555float nearplane = 0.1f;    // nearplane
    5656float farplane = 1000.0f;  // farplane
     
    7070float part_angle;          // part angle
    7171float fx_angle;            // current angle
    72 /* liner variable */
    73 int car;                   // ascii code
    74 int car_cursor = 126;      // cursor ascii code
    75 int liner_length;          // text length
    76 int liner_line_n;          // line number
    77 int liner_line;            // line increment
    78 int liner_max;             // line max length
    79 int liner_i;               // char increment
    80 int liner_count;           // counter
    8172/* text variable */
    8273char const *name = "cacaShell";
    83 std::string txt("");
    8474/* fs_quad variable */
    8575float fs_quad_vtx[] = {-1.0f, 1.0f, 0, 1.0f, -1.0f, -1.0f, 0, 1.0f, 1.0f, -1.0f, 0, 1.0f, 1.0f, 1.0f, 0, 1.0f};
     
    128118int key_code = 0;          // keyboard code
    129119/* common variable */
    130 int i, j, k, l;
    131 float x, y, z, w, h;
    132 float r, g, b, c;
    133120float value, angle, radius, scale, speed;
    134121TileSet *tex_map;
     
    228215#endif
    229216
    230 void calc_txt()
    231 {
    232     liner_length = txt.length();
    233     liner_count = 0;
    234     liner_line_n = 0;
    235     liner_max = 0;
    236     liner_i = 0;
    237     for(i = 0;i<liner_length;i++)
    238     {
    239         if((unsigned char)txt[i] != 13)
    240         {
    241             liner_i++;
    242         }
    243         else
    244         {
    245             if(liner_i>liner_max) liner_max = liner_i;
    246             liner_line_n++;
    247             liner_i = 0;
    248         }
    249     }
    250     if(liner_i>liner_max) liner_max = liner_i;
    251 }
    252 
    253217void rectangle(int x, int y, int w, int h)
    254218{
     
    267231    vertex[0] = 0;
    268232    vertex[1] = 0;
    269     for(i = 1;i<corner_n+1;i++)
    270     {
    271         j = i*2;
     233    for (int i = 1; i < corner_n + 1; i++)
     234    {
     235        int j = i*2;
    272236        float a = PID*90.0f/(corner_n-1)*(i-1);
    273237        vertex[j  ] = corner_w-corner_w*cosf(a);
    274238        vertex[j+1] = corner_w-corner_w*sinf(a);
    275239    }
    276     for(i = 0;i<corner_n;i++)
    277     {
    278         j = i*6;
    279         k = i*2;
     240    for (int i = 0; i < corner_n; i++)
     241    {
     242        int j = i*6;
     243        int k = i*2;
    280244        corner_vtx[j  ] = (int)vertex[0];
    281245        corner_vtx[j+1] = (int)vertex[1];
     
    293257    dos_color = CR * vec3(48, 56, 64);
    294258    screen_color = dos_color;
    295     txt = "\rCopyright \x05e 2012 cacaShell v0.1\r ";
    296     calc_txt();
    297259    /*-------------------------*/
    298260    shader_effect_flag = true;
     
    430392}
    431393
    432 Render::Render()
     394Render::Render(caca_canvas_t *caca)
     395  : m_caca(caca)
    433396{
    434397}
     
    451414
    452415    // timer
    453     if(!pause)
     416    if(!paused)
    454417        main_angle += seconds * 100.0f * PID;
    455418    if(sync_flag)
     
    569532        // draw dos text
    570533        glVertexPointer(2, GL_INT, 0, dos_vtx);
    571         j=0;
    572         liner_line=-1;
    573         for(i=1;i<liner_length+1;i++)
     534        float x = dos_m + (float)(dos_w + 2 * ratio_2d);
     535        float y = dos_m + (float)(15 * ratio_2d);
     536
     537        for (int j = 0; j < caca_get_canvas_height(m_caca); j++)
     538        for (int i = 0; i < caca_get_canvas_width(m_caca); i++)
    574539        {
    575             j++;
    576             car=(unsigned char)txt[i-1];
    577             if(i==liner_length) car=car_cursor;
    578             if(car>32)
     540            uint32_t car = caca_get_char(m_caca, i, j);
     541            uint32_t att = caca_get_attr(m_caca, i, j);
     542
     543            glLoadIdentity();
     544            glTranslated(x+i*(dos_w+2*ratio_2d), y+j*(dos_h+4*ratio_2d), 0);
     545
     546            glDisable(GL_TEXTURE_2D);
     547            uint16_t bg = caca_attr_to_rgb12_bg(att);
     548            glColor3f((float)(bg >> 8) / 16.f,
     549                      (float)((bg & 0xf0) >> 4) / 16.f,
     550                      (float)(bg & 0xf) / 16.f);
     551            glDrawArrays(GL_QUADS, 0, 4);
     552            glEnable(GL_TEXTURE_2D);
     553
     554            if (car > 32 && car < 127)
    579555            {
    580                 glLoadIdentity();
    581                 glTranslated(x+j*(dos_w+2*ratio_2d), y, 0);
    582556                float l_w=(car%16)*0.03125f;
    583557                float l_h=(car-car%16)*0.001953125f;
    584558                float dos_tex[]={l_w+0.03125f, 0.5f+l_h+0.03125f, l_w+0.03125f, 0.5f+l_h, l_w, 0.5f+l_h, l_w, 0.5f+l_h+0.03125f};
    585559                glTexCoordPointer(2, GL_FLOAT, 0, dos_tex);
    586                 if(car==car_cursor) glColor3f(CR*(dos_color.r+64), CR*(dos_color.g+48), CR*(dos_color.b+48));
     560                uint16_t fg = caca_attr_to_rgb12_fg(att);
     561                glColor3f((float)(fg >> 8) / 16.f,
     562                          (float)((fg & 0xf0) >> 4) / 16.f,
     563                          (float)(fg & 0xf) / 16.f);
     564                // FIXME: draw cursor!
     565                //if(car==car_cursor) glColor3f(CR*(dos_color.r+64), CR*(dos_color.g+48), CR*(dos_color.b+48));
    587566                glDrawArrays(GL_QUADS, 0, 4);
    588                 if(car==car_cursor) glColor3f(1.0f, 1.0f, 1.0f);
    589             }
    590             if(car==13)
    591             {
    592                 j=0;
    593                 liner_line++;
    594                 x=dos_m;
    595                 y=dos_m+(float)(15*ratio_2d+liner_line*(dos_h+4*ratio_2d));
    596                 if(y+dos_h>screen_size.y-dos_m) break;
     567                //if(car==car_cursor) glColor3f(1.0f, 1.0f, 1.0f);
    597568            }
    598569        }
    599570    }
    600     // draw debug
    601     //#if DEBUG
    602     if(debug_flag)
    603     {
    604         char debug[512];
    605         sprintf(debug, "width=%d\rheight=%d\rratio=%dx\rbeat=%-02.1f\rsync=%-02.1f\rkey code=%03d\r", screen_size.x, screen_size.y, ratio_2d, beat_value, sync_value, key_code);
    606         float l_v=0.0390625f;
    607         float l_j=0.001953125f;
    608         glVertexPointer(2, GL_INT, 0, debug_vtx);
    609         glLoadIdentity();
    610         glBlendFunc(GL_ONE, GL_ONE);
    611         glColor3f(0.625f, 0.25f, 0.0f);
    612         glTranslated(debug_x, debug_y, 0);
    613         j=0;
    614         for(i=0;i<(int)strlen(debug);i++)
    615         {
    616             j++;
    617             car=(unsigned char)debug[i];
    618             if(car==13)
    619             {
    620                 glTranslated(-j*(debug_w-ratio_2d)*2, (debug_h-ratio_2d)*2, 0);
    621                 j=0;
    622             }
    623             glTranslated((debug_w-ratio_2d)*2, 0, 0);
    624             if(car>32)
    625             {
    626                 float l_w=(car%16)*0.03515625f;
    627                 float l_h=(car-car%16)*0.00244140625f;
    628                 float debug_tex[]={l_w+l_v-l_j, 1.0f-l_h-l_v, l_w+l_v-l_j, 1.0f-l_h, l_w-l_j, 1.0f-l_h, l_w-l_j, 1.0f-l_h-l_v};
    629                 glTexCoordPointer(2, GL_FLOAT, 0, debug_tex);
    630                 glDrawArrays(GL_QUADS, 0, 4);
    631             }
    632         }
    633     }
    634     //#endif
    635571    // draw corner
    636572    glDisable(GL_TEXTURE_2D);
  • trunk/neercs/video/render.h

    r1461 r1462  
    88{
    99public:
    10     Render();
     10    Render(caca_canvas_t *caca);
    1111    virtual ~Render();
    1212
     
    2121
    2222private:
     23    caca_canvas_t *m_caca;
    2324};
    2425
Note: See TracChangeset for help on using the changeset viewer.