Subversion Repositories Kolibri OS

Rev

Rev 5237 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "rs/rsplatform.h"
  2.  
  3. #include "rsgametext.h"
  4.  
  5. #include "rsgame.h"
  6. #include "rsgentex.h"
  7.  
  8. #include "rskos.h"
  9.  
  10.  
  11.  
  12. #ifdef RS_USE_C_LIBS
  13.     #include <math.h>
  14.     #include <stdlib.h>
  15.     #include <string.h>
  16. #endif
  17.  
  18.  
  19. signed short pp_seg[32*8] = {
  20.  
  21.     // 0
  22.     16,     6-16,
  23.     16,     6+16,
  24.     16,     6,
  25.     13,     0,
  26.  
  27.     // 1
  28.     26-16,   16,
  29.     26+16,   16,
  30.     26,      11,
  31.     8,       0,
  32.  
  33.     // 2
  34.     26-16,   16,
  35.     26+16,   16,
  36.     26,      21,
  37.     8,     0,
  38.  
  39.     // 3
  40.     16,     26-16,
  41.     16,     26+16,
  42.     16,     26,
  43.     13,     0,
  44.  
  45.     // 4
  46.     6-16,   16,
  47.     6+16,   16,
  48.     6,      21,
  49.     8,     0,
  50.  
  51.     // 5
  52.     6-16,   16,
  53.     6+16,   16,
  54.     6,      11,
  55.     8,       0,
  56.  
  57.     // 6
  58.     16,     16-16,
  59.     16,     16+16,
  60.     16,     16,
  61.     13,     0,
  62.  
  63.     // 7
  64.     16,     4-22,
  65.     16,     4+22,
  66.     16,     4,
  67.     4,     0,
  68.  
  69.  
  70.  
  71.  
  72.     // 8
  73.     16-16,   16,
  74.     16+16,   16,
  75.     16,      11,
  76.     8,       0,
  77.  
  78.     // 9
  79.     16-16,   16,
  80.     16+16,   16,
  81.     16,      21,
  82.     8,     0,
  83.  
  84.     // 10
  85.     21-16,   11+16,
  86.     21+16,   11-16,
  87.     21,      11,
  88.     9,       0,
  89.  
  90.     // 11 modified
  91.     16-16,   16+16,
  92.     16+16,   16-16,
  93.     21,      21,
  94.     9,       0,
  95.  
  96.     // 12
  97.     16-16,   16-16,
  98.     16+16,   16+16,
  99.     21,      11,
  100.     9,       0,
  101.  
  102.     // 13
  103.     21-16,   21-16,
  104.     21+16,   21+16,
  105.     21,      21,
  106.     9,       0,
  107.  
  108.     // 14
  109.     16,     16-16,
  110.     16,     16+16,
  111.     10,     16,
  112.     7,     0,
  113.  
  114.     // 15
  115.     16,     16-16,
  116.     16,     16+16,
  117.     22,     16,
  118.     7,      0,
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.     // 16
  126.     16-16,   16+16,
  127.     16+16,   16-16,
  128.     11,      11,
  129.     8,       0,
  130.  
  131.     // 17
  132.     11-16,   21+16,
  133.     11+16,   21-16,
  134.     11,      21,
  135.     9,       0,
  136.  
  137.     // 18
  138.     11-16,   11-16,
  139.     11+16,   11+16,
  140.     11,      11,
  141.     9,       0,
  142.  
  143.     // 19
  144.     16-16,   16-16,
  145.     16+16,   16+16,
  146.     11,      21,
  147.     9,       0,
  148.  
  149.     // 20 == copy 11 modified
  150.     21-22,   21+22,
  151.     21+22,   21-22,
  152.     21,      21,
  153.     9,       0,
  154.  
  155.     // 21 - right
  156.     27-12,   28-9,
  157.     27+12,   28+9,
  158.     27,     27,
  159.     4,     0,
  160.  
  161.     // 22 - left
  162.     5-12,   28+9,
  163.     5+12,   28-9,
  164.     5,      27,
  165.     4,     0,
  166.  
  167.  
  168.     // 23
  169.     6-16,   16,
  170.     6+16,   16,
  171.     6,      8,
  172.     5,     0,
  173.  
  174.  
  175.  
  176.     // 24
  177.     16-33,   16,
  178.     16+33,   16,
  179.     16,      13,
  180.     4,     0,
  181.  
  182.  
  183.     // 25
  184.     16-33,   16,
  185.     16+33,   16,
  186.     16,      26,
  187.     4,     0,
  188.  
  189.     // 26
  190.     16,     6-16,
  191.     16,     6+16,
  192.     11,     6,
  193.     7,     0,
  194.  
  195.     // 27
  196.     16,     26-16,
  197.     16,     26+16,
  198.     11,     26,
  199.     7,     0,
  200.  
  201.     // 28
  202.     16,     6-16,
  203.     16,     6+16,
  204.     21,     6,
  205.     7,     0,
  206.  
  207.     // 29
  208.     16,     26-16,
  209.     16,     26+16,
  210.     21,     26,
  211.     7,     0,
  212.  
  213.  
  214.     // 30 ,
  215.     11-22,   27-22,
  216.     11+22,   27+22,
  217.     11,     25,
  218.     6,     0,
  219.  
  220.     // 31 not implemented - need to create up-left DOT for percent(%) sign
  221.     16,     26-16,
  222.     16,     26+16,
  223.     16,     26,
  224.     13,     0,
  225.  
  226.  
  227. };
  228.  
  229. unsigned int ch_seg[64] = {
  230.     0b00111111 /* | 1<<12 | 1<<19 */, // 0 or O
  231.     1<<26 | 1<<8 | 1<<9 | 1<<3, // 1
  232.     0b01011011, // 2
  233.     1<<0 | 1<<12 | 1<<15 | 1<<2 | 1<<3, // 3
  234.     0b01100110, // 4
  235.     0b01101101, // 5
  236.     1<<0 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6, // 6 // old: 1<<6 | 1<<2 | 1<<3 | 1<<4 | 1<<18 | 1<<28, // 6
  237.     1<<23 | 1<<0 | 1<<1 | 1<<13 ,  //0b00000111   , // 7
  238.  
  239.     0b01111111, // 8
  240.     1<<6 | 1<<5 | 1<<0 | 1<<1 | 1<<2 | 1<<3, // 9
  241.     1<<24 | 1<<25, // :
  242.     1<<8 | 1<<25, // ;
  243.     1<<12 | 1<<11, // <
  244.     1<<6, // = (-)
  245.     1<<16 | 1<<19, // >
  246.     1<<23 | 1<<0 | 1<<1 | 1<<15 | 1<<25 | 1<<9, //  ?
  247.  
  248.     1<<19 | 1<<12, // @ (/)
  249.     1<<0 | 1<<1 | 1<<2 | 1<<6 | 1<<4 | 1<<5, // A
  250.     1<<26 | 1<<10 | 1<<6 | 1<<11 | 1<<3 | 1<<4 | 1<<5, // B
  251.     1<<0 | 1<<5 | 1<<4 | 1<<3, // C // corners: 1<<28 | 1<<18 | 1<<17 | 1<<29,
  252.     1<<26 | 1<<27 | 1<<5 | 1<<4 | 1<<10 | 1<<13 , // D
  253.     1<<0 | 1<<14 | 1<<3 | 1<<5 | 1<<4, // E
  254.     1<<0 | 1<<14 | 1<<5 | 1<<4, // F
  255.     1<<0 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<15, // G
  256.  
  257.     1<<1 | 1<<2 | 1<<5 | 1<<4 | 1<<6, // H
  258.     1<<0 | 1<<8 | 1<<9 | 1<<3, // I
  259.     1<<1 | 1<<2 | 1<<3 | 1<<4, // J
  260.     1<<5 | 1<<4 | 1<<14 | 1<<12 | 1<<11, // K
  261.     1<<5 | 1<<4 | 1<<3, // L
  262.     1<<5 | 1<<4 | 1<<1 | 1<<2 | 1<<16 | 1<<12, // M
  263.     1<<5 | 1<<4 | 1<<16 | 1<<11 | 1<<1 | 1<<2, // N
  264.     1<<16 | 1<<11 | 1<<19 | 1<<12 | 1<<6 | 1<<8 | 1<<9, // O - FREE SYMBOL
  265.  
  266.     1<<4 | 1<<5 | 1<<0 | 1<<1 | 1<<6, // P
  267.     1<<0 | 1<<1 | 1<<13 | 1<<27 | 1<<4 | 1<<5 | 1<<11, // Q // old: 0b00111111 | 1<<11, // Q
  268.     1<<0 | 1<<1 | 1<<6 | 1<<5 | 1<<4 | 1<<11, // R
  269.     (1 << 18 | 1 << 13) | (1 << 29  | 1 << 26) | (1 << 5 | 1 << 2) | (1 << 19 | 1 << 12),  // percent(%) sign,  s == 5 -> // 0b01101101, // S
  270.     1<<0 | 1<<8 | 1<<9, // T
  271.     1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5, // U
  272.     1<<1 | 1<<13 | 1<<17 | 1<<5, // V
  273.     1<<5 | 1<<4 | 1<<19 | 1<<11 | 1<<2 | 1<<1, // W
  274.  
  275.     1<<16 | 1<<11 | 1<<19 | 1<<12, // X
  276.     1<<5 | 1<<6 | 1<<1 | 1<<2 | 1<<3, // Y
  277.     1<<0 | 1<<12 | 1<<19 | 1<<3, // Z
  278.     1<<26 | 1<<8 | 1<<9 | 1<<29 | 1<<2 | 1<<15, // [Ъ
  279.     1<<5 | 1<<4 | 1<<27 | 1<<9 | 1<<14 | 1<<1 | 1<<2, // \Ы
  280.     1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<6, // ]Ь
  281.     1<<7 | 1<<5 | 1<<4 | 1<<19 | 1<<12 | 1<<1 | 1<<2, // ^Й
  282.     1<<30, // _ (,comma)
  283.  
  284.     1<<25, // ` dot
  285.     1<<5 | 1<<0 | 1<<1 | 1<<6 | 1<<2 | 1<<19, // aЯ
  286.     1<<0 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<6, // bБ
  287.     1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<2 | 1<<21, // cЦ
  288.     0b011001000000010000011100, // dД
  289.     1<<0 | 1<<1 | 1<<15 | 1<<2 | 1<<3, // eЭ // with corners: 1<<26 | 1<<10 | 1<<6 | 1<<13 | 1<<27, // eЭ
  290.     1<<0 | 1<<1 | 1<<6 | 1<<5 | 1<<8 | 1<<9, // fФ
  291.     1<<4 | 1<<5 | 1<<0, // gГ
  292.     1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<2 | 1<<9, // hШ,
  293.     1<<5 | 1<<4 | 1<<19 | 1<<12 | 1<<1 | 1<<2, // iИ
  294.     1<<5 | 1<<8 | 1<<1 | 1<<6 | 1<<4 | 1<<9 | 1<<2, // old: 1<<16 | 1<<8 | 1<<12 | 1<<19 | 1<<9 | 1<<11, // jЖ
  295.     1<<5 | 1<<4 | 1<<14 | 1<<8 | 1<<9 | 1<<1 | 1<<2 | 1<<28 | 1<<29, // k_Ю
  296.     1<<4 | 1<<18 | 1<<28 | 1<<1 | 1<<2, // l  // old symmetric: 1<<4 | 1<<18 | 1<<10 | 1<<2, // l // old: 1<<19 | 1<<12 | 1<<1 | 1<<2, // lЛ
  297.     1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<2 | 1<<9 | 1<<21, // mЩ,
  298.     1<<4 | 1<<5 | 1<<0 | 1<<1 | 1<<2, // n
  299.     (1<<8 | 1<<9) | 1<<10 | 1<<18,  // 'o' for arrow up ^
  300.  
  301. };
  302.  
  303.  
  304. void game_font_init() {
  305.  
  306.     DEBUG30(":: font init start");
  307.  
  308.     float scale = 1.0;
  309.  
  310.     int seg;
  311.     int ch;
  312.     int ch_bit;
  313.  
  314. //  // FAT FONT #1 (OK)
  315. //    float scales[4] = { 0.4, 0.6, 0.2, 2 }; // 2,1,1,1
  316. //    float pows[4] = { 15.0, 19.0, 200.0, 22.0 };
  317. //    float ks1[4] = { 1.2, 1.0, 1.2, 0.90 }; // 0.75 straight
  318. //    float ks2[4] = { -1.0, -1.0, -1.0, -1.0 };
  319. //    float pows1[4] = { 1.0, 0.79, 1.0, 1.0 };
  320. //    float pows2[4] = { 1.0, 0.79, 1.0, 1.0 };
  321. //    float clamp1[4] = { 0.8, 0.75, 0.65, 0.87 }; // 0.8 to 0.86
  322. //    float clamp2[4] = { 0.85, 0.85, 0.85, 0.92 };
  323. //    float radiuses[4] = { 1.0, 1.1, 1.2, 0.87 };
  324.    
  325.    
  326.     float scales[4] = { 0.69, 2.0, 0.2, 0.5 }; // 2,1,1,1
  327.     //float pows[4] = { 45.0, 100.0, 200.0, 22.0 };
  328.     float pows[4] = { 8.0, 7.0, 15.0, 22.0 };
  329.     float ks1[4] = { 0.01, 0.05, 1.2, 0.90 }; // 0.75 straight
  330.     float ks2[4] = { -3.75, -2.75, -1.0, -1.0 };
  331.     float pows1[4] = { 1.0, 1.0, 1.0, 1.0 };
  332.     float pows2[4] = { 0.6,  0.6, 1.0, 1.0 };
  333.     float clamp1[4] = { 0.65, 0.69, 0.65, 0.87 }; // 0.8 to 0.86
  334.     float clamp2[4] = { 0.85, 0.75, 0.85, 0.92 };
  335.     float radiuses[4] = { 0.9667, 0.997, 1.2, 0.87 };
  336.    
  337.     float colors_r[4] = { 0.15, 0.997, 1.0, 0.4 };
  338.     float colors_g[4] = { 0.10, 0.875, 1.0, 0.6 };
  339.     float colors_b[4] = { 0.05, 0.763, 1.0, 0.8 };
  340.     // 1: 0.5, 0.74, 0.79
  341.  
  342.     DEBUG20(":: font init label-a");
  343.  
  344.     int font_index = 0;
  345.     int font_index_color = 0;
  346.    
  347.     for (font_index_color = 0; font_index_color < FONTS_COUNT; font_index_color++) {
  348.            
  349.         font_index = font_index_color % 3;
  350.  
  351.         DEBUG30f(":: font init label-b (font index %d) \n", font_index);
  352.  
  353.         scale = scales[font_index];
  354.  
  355.         rs_gen_reg.cell_scale = scale;
  356.  
  357.         int char_tex_size = scale*32;
  358.        
  359. //        DEBUG10f("char_tex_size %d \n", char_tex_size);
  360.        
  361.         rs_gen_init(97, char_tex_size);
  362.  
  363.         for (seg = 0; seg < 32; seg++) {
  364.             rs_gen_func_cell(seg, 1, 2, &pp_seg[8*seg], ks1[font_index], pows1[font_index], ks2[font_index], pows2[font_index], 0.0, 0.0);
  365.             //rs_gen_func_cell(seg, 1, 2, &pp_seg[8*seg], 1.2, 1.0, -1.0, 1.0, 0.0, 0.0);
  366.             //rs_gen_func_cell(seg, 1, 2, &pp_seg[8*seg], 0.48450032, 1.0, -1.0, 2.20, 0.0, 0.0); // toon
  367.             rs_gen_func_normalize(seg, 0.0, 1.0); // 0.1 to 1.0
  368.  
  369.             rs_gen_func_clamp(seg, clamp1[font_index], clamp2[font_index]); //  0.8, 0.86); // toon 0.775, 0.839889
  370.             rs_gen_func_normalize(seg, 0.0, 1.0); // 0.1 to 1.0
  371.  
  372.             rs_gen_func_set(96, 0.0);
  373.             rs_gen_func_radial(96, (float)pp_seg[8*seg + 4]/32.0, (float)pp_seg[8*seg + 5]/32.0, (float)pp_seg[8*seg + 6]/32.0*radiuses[font_index], 1.0, pows[font_index]);
  374.             rs_gen_func_mult(seg, seg, 96);
  375.         };
  376.  
  377.  
  378.  
  379.         for (ch = 0; ch < 64; ch++) {
  380.             rs_gen_func_set(32+ch, 0.0);
  381.             for (ch_bit = 0; ch_bit < 32; ch_bit++) {
  382.                 if ( (1<<ch_bit) & (ch_seg[ch]) ) {
  383.                     rs_gen_func_add_lerped(32+ch, 32+ch, ch_bit, 1.0, 1.0);
  384.                 }
  385.             }
  386.             rs_gen_func_clamp(32+ch, (ch+ch/8)%2 ? 0.0 : 0.0, 1.0);
  387.     //        rs_gen_func_set(32+ch, (ch+ch/8)%2 ? 0.5 : 0.0);
  388.  
  389.             rs_gen_func_set(96, 1.0);
  390.            
  391.             rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
  392.             //rs_gen_tex_out_rgba(32+ch, 32+ch, 32+ch, 32+ch, colors_b[font_index_color], colors_g[font_index_color], colors_r[font_index_color], 1.0);
  393.             rs_gen_tex_out_rgba(96, 96, 96, 32+ch, colors_b[font_index_color], colors_g[font_index_color], colors_r[font_index_color], 1.0);
  394.            
  395.             texture_init(&game.tex_font[font_index_color*64 + ch], char_tex_size, char_tex_size);
  396.             memcpy(game.tex_font[font_index_color*64 + ch].data, rs_gen_reg.tex_out, char_tex_size*char_tex_size*4 );
  397.    
  398.         }
  399.        
  400.        
  401.        
  402.         /*
  403.  
  404.         float *fontdata = malloc(256*scale*256*scale*4);
  405.  
  406.         int i, j, k;
  407.         for (i = 0; i < 8; i++) {
  408.             for (j = 0; j < 8; j++) {
  409.                 for (k = 0; k < 32*scale; k++) {
  410.                     memcpy( &(fontdata[i*256*(32*scale)*scale + k*256*scale + (j)*(32*scale)]), &(rs_gen_reg.tex[k*(32*scale) + (32+j+i*8)*(32*scale)*(32*scale)] ), 32*4*scale );
  411.                 };
  412.             };
  413.         };
  414.  
  415.         rs_gen_term();
  416.  
  417.         int font_tex_size = 256*scale;
  418.         rs_gen_init(2, font_tex_size);
  419.         memcpy( rs_gen_reg.tex, fontdata, 256*256 * 4 *scale*scale);
  420.         rs_gen_func_set(1, 1.0);
  421.         rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
  422.         rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0);
  423.        
  424.         //game.font_texture[font_index] = rs_tx_create_from_data(font_tex_size, font_tex_size, 4, 1, 0, rs_gen_reg.tex_out);
  425.         game_loader_create_texture( &(game.font_texture[font_index]), font_tex_size, font_tex_size, 4, 1, 0, rs_gen_reg.tex_out );
  426.        
  427.  
  428.         save_image(0, rs_gen_reg.tex_out, 256*scale, 256*scale, 4);
  429.        
  430.         */
  431.  
  432.         rs_gen_term();
  433.  
  434. //        free(fontdata);  
  435. //        
  436. //        game.loader_progress = font_index+2;
  437.  
  438.     };
  439.  
  440.     rs_gen_reg.cell_scale = 1;
  441.  
  442. };
  443.  
  444. void game_font_term() {
  445.  
  446.     int i;
  447.     for (i = 0; i < 64*FONTS_COUNT; i++) {
  448.         texture_free(&game.tex_font[i]);
  449.     };
  450.  
  451.  
  452. };
  453.  
  454.  
  455.  
  456. //float game_colors[4*7] = {
  457. //    0.0, 0.0, 0.0, 1.0,
  458. //    1.0, 1.0, 1.0, 1.0,
  459. //    1.0, 0.9, 0.3, 1.0,
  460. //    1.0, 0.4, 0.3, 1.0,
  461. //    0.6, 0.8, 1.0, 1.0,
  462. //    1.0, 0.8, 0.6, 1.0,
  463. //    0.6, 0.6, 0.6, 0.9,
  464. //};
  465.  
  466.  
  467. void game_textout(int x, int y, int font_index, char* s) {
  468.     game_textout_adv(&game.framebuffer, x, y, font_index, DRAW_MODE_ALPHA, s);
  469. };
  470.  
  471. void game_textout_at_center(int x, int y, int font_index, char *s) {
  472.     x += (GAME_WIDTH - game.tex_font[font_index*64].w*strlen(s))/2;
  473.     game_textout_adv(&game.framebuffer, x, y, font_index, DRAW_MODE_ALPHA, s);
  474. };
  475.  
  476. void game_textout_adv(rs_texture_t *dest, int x, int y, int font_index, int draw_mode, char* s) {
  477.    
  478.  
  479.     int i = 0;
  480.     while (*s) {
  481.         if (*s != ' ') {
  482.             texture_draw(dest, &game.tex_font[ 64*font_index + ((*s - 48) % 64) ], x+i*game.tex_font[64*font_index+0].w, y, draw_mode);
  483.         };
  484.         s++;
  485.         i++;
  486.     };
  487.    
  488.  
  489. };
  490.  
  491.  
  492.