ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.224 by root, Sat Aug 11 11:21:46 2007 UTC vs.
Revision 1.235 by root, Tue Aug 28 01:23:47 2007 UTC

150typedef struct cf_layout { 150typedef struct cf_layout {
151 PangoLayout *pl; 151 PangoLayout *pl;
152 float r, g, b, a; // default color for rgba mode 152 float r, g, b, a; // default color for rgba mode
153 int base_height; 153 int base_height;
154 CFPlus__Font font; 154 CFPlus__Font font;
155 rc_t *rc;
155} *CFPlus__Layout; 156} *CFPlus__Layout;
156 157
157static CFPlus__Font default_font; 158static CFPlus__Font default_font;
158static PangoContext *opengl_context; 159static PangoContext *opengl_context;
159static PangoFontMap *opengl_fontmap; 160static PangoFontMap *opengl_fontmap;
202 203
203typedef uint16_t tileid; 204typedef uint16_t tileid;
204typedef uint16_t faceid; 205typedef uint16_t faceid;
205 206
206typedef struct { 207typedef struct {
207 int name; 208 GLuint name;
208 int w, h; 209 int w, h;
209 float s, t; 210 float s, t;
210 uint8_t r, g, b, a; 211 uint8_t r, g, b, a;
211 tileid smoothtile; 212 tileid smoothtile;
212 uint8_t smoothlevel; 213 uint8_t smoothlevel;
437 n |= n >> 4; 438 n |= n >> 4;
438 n |= n >> 8; 439 n |= n >> 8;
439 n |= n >> 16; 440 n |= n >> 16;
440 441
441 return n + 1; 442 return n + 1;
443}
444
445static unsigned int
446popcount (unsigned int n)
447{
448 n -= (n >> 1) & 0x55555555U;
449 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
450 n = ((n >> 4) + n) & 0x0f0f0f0fU;
451 n *= 0x01010101U;
452
453 return n >> 24;
442} 454}
443 455
444/* SDL should provide this, really. */ 456/* SDL should provide this, really. */
445#define SDLK_MODIFIER_MIN 300 457#define SDLK_MODIFIER_MIN 300
446#define SDLK_MODIFIER_MAX 314 458#define SDLK_MODIFIER_MAX 314
524 536
525 const_iv (SDL_APPINPUTFOCUS), 537 const_iv (SDL_APPINPUTFOCUS),
526 const_iv (SDL_APPMOUSEFOCUS), 538 const_iv (SDL_APPMOUSEFOCUS),
527 const_iv (SDL_APPACTIVE), 539 const_iv (SDL_APPACTIVE),
528 540
541 const_iv (SDLK_FIRST),
542 const_iv (SDLK_LAST),
529 const_iv (SDLK_KP0), 543 const_iv (SDLK_KP0),
530 const_iv (SDLK_KP1), 544 const_iv (SDLK_KP1),
531 const_iv (SDLK_KP2), 545 const_iv (SDLK_KP2),
532 const_iv (SDLK_KP3), 546 const_iv (SDLK_KP3),
533 const_iv (SDLK_KP4), 547 const_iv (SDLK_KP4),
632 646
633NV floor (NV x) 647NV floor (NV x)
634 648
635NV ceil (NV x) 649NV ceil (NV x)
636 650
651IV minpot (UV n)
652
653IV popcount (UV n)
654
637void 655void
638pango_init () 656pango_init ()
639 CODE: 657 CODE:
640{ 658{
641 opengl_fontmap = pango_opengl_font_map_new (); 659 opengl_fontmap = pango_opengl_font_map_new ();
714 732
715 if (RETVAL) 733 if (RETVAL)
716 { 734 {
717 av_clear (texture_av); 735 av_clear (texture_av);
718 736
719 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 737 SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT");
720#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 738#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
721#include "glfunc.h" 739#include "glfunc.h"
722#undef GL_FUNC 740#undef GL_FUNC
723 } 741 }
724} 742}
1036 RETVAL->g = 1.; 1054 RETVAL->g = 1.;
1037 RETVAL->b = 1.; 1055 RETVAL->b = 1.;
1038 RETVAL->a = 1.; 1056 RETVAL->a = 1.;
1039 RETVAL->base_height = MIN_FONT_HEIGHT; 1057 RETVAL->base_height = MIN_FONT_HEIGHT;
1040 RETVAL->font = 0; 1058 RETVAL->font = 0;
1059 RETVAL->rc = rc_alloc ();
1041 1060
1042 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1061 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1043 layout_update_font (RETVAL); 1062 layout_update_font (RETVAL);
1044 OUTPUT: 1063 OUTPUT:
1045 RETVAL 1064 RETVAL
1046 1065
1047void 1066void
1048DESTROY (CFPlus::Layout self) 1067DESTROY (CFPlus::Layout self)
1049 CODE: 1068 CODE:
1050 g_object_unref (self->pl); 1069 g_object_unref (self->pl);
1070 rc_free (self->rc);
1051 Safefree (self); 1071 Safefree (self);
1052 1072
1053void 1073void
1054set_text (CFPlus::Layout self, SV *text_) 1074set_text (CFPlus::Layout self, SV *text_)
1055 CODE: 1075 CODE:
1307 } 1327 }
1308} 1328}
1309 1329
1310void 1330void
1311render (CFPlus::Layout self, float x, float y, int flags = 0) 1331render (CFPlus::Layout self, float x, float y, int flags = 0)
1312 PPCODE: 1332 CODE:
1333 rc_clear (self->rc);
1313 pango_opengl_render_layout_subpixel ( 1334 pango_opengl_render_layout_subpixel (
1314 self->pl, 1335 self->pl,
1336 self->rc,
1315 x * PANGO_SCALE, y * PANGO_SCALE, 1337 x * PANGO_SCALE, y * PANGO_SCALE,
1316 self->r, self->g, self->b, self->a, 1338 self->r, self->g, self->b, self->a,
1317 flags 1339 flags
1318 ); 1340 );
1341 // we assume that context_change actually clears/frees stuff
1342 // and does not do any recomputation...
1343 pango_layout_context_changed (self->pl);
1344
1345void
1346draw (CFPlus::Layout self)
1347 CODE:
1348{
1349 glEnable (GL_TEXTURE_2D);
1350 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1351 glEnable (GL_BLEND);
1352 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1353 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1354 glEnable (GL_ALPHA_TEST);
1355 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1356
1357 rc_draw (self->rc);
1358
1359 glDisable (GL_ALPHA_TEST);
1360 glDisable (GL_BLEND);
1361 glDisable (GL_TEXTURE_2D);
1362}
1319 1363
1320MODULE = CFPlus PACKAGE = CFPlus::Texture 1364MODULE = CFPlus PACKAGE = CFPlus::Texture
1321 1365
1322PROTOTYPES: ENABLE 1366PROTOTYPES: ENABLE
1323
1324int minpot (int n)
1325 1367
1326void 1368void
1327pad (SV *data_, int ow, int oh, int nw, int nh) 1369pad (SV *data_, int ow, int oh, int nw, int nh)
1328 CODE: 1370 CODE:
1329{ 1371{
1718{ 1760{
1719 int x, y, z; 1761 int x, y, z;
1720 1762
1721 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1763 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1722 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1764 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1723 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1765 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1724 smooth_key skey; 1766 smooth_key skey;
1725 1767
1726 rc_t *rc = rc_alloc (); 1768 rc_t *rc = rc_alloc ();
1727 rc_key_t key; 1769 rc_key_t key;
1728 rc_array_t *arr; 1770 rc_array_t *arr;
1790 if (tile) 1832 if (tile)
1791 { 1833 {
1792 maptex tex = self->tex [tile]; 1834 maptex tex = self->tex [tile];
1793 int px, py; 1835 int px, py;
1794 1836
1795 // suppressing texture state switches here
1796 // is only moderately effective, but worth the extra effort
1797 if (key.texname != tex.name) 1837 if (key.texname != tex.name)
1798 { 1838 {
1799 if (!tex.name) 1839 if (!tex.name)
1800 tex = self->tex [2]; /* missing, replace by noface */ 1840 tex = self->tex [2]; /* missing, replace by noface */
1801 1841
1884 // go through all smoothlevels, lowest to highest, then draw. 1924 // go through all smoothlevels, lowest to highest, then draw.
1885 // this is basically counting sort 1925 // this is basically counting sort
1886 { 1926 {
1887 int w, b; 1927 int w, b;
1888 1928
1929 glEnable (GL_TEXTURE_2D);
1930 glBegin (GL_QUADS);
1889 for (w = 0; w < 256 / 32; ++w) 1931 for (w = 0; w < 256 / 32; ++w)
1890 { 1932 {
1891 uint32_t smask = smooth_level [w]; 1933 uint32_t smask = smooth_level [w];
1892 if (smask) 1934 if (smask)
1893 for (b = 0; b < 32; ++b) 1935 for (b = 0; b < 32; ++b)
1918 { 1960 {
1919 // this time avoiding texture state changes 1961 // this time avoiding texture state changes
1920 // save gobs of state changes. 1962 // save gobs of state changes.
1921 if (key.texname != tex.name) 1963 if (key.texname != tex.name)
1922 { 1964 {
1965 glEnd ();
1923 key.texname = tex.name; 1966 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1924 arr = rc_array (rc, &key); 1967 glBegin (GL_QUADS);
1925 } 1968 }
1926 1969
1927 if (border) 1970 if (border)
1928 { 1971 {
1929 float ox = border * dx; 1972 float ox = border * dx;
1930 1973
1931 rc_t2f_v3f (arr, ox , 0.f , px , py , 0); 1974 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1932 rc_t2f_v3f (arr, ox , dy , px , py + T, 0); 1975 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1933 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); 1976 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1934 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); 1977 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1935 } 1978 }
1936 1979
1937 if (corner) 1980 if (corner)
1938 { 1981 {
1939 float ox = corner * dx; 1982 float ox = corner * dx;
1940 1983
1941 rc_t2f_v3f (arr, ox , dy , px , py , 0); 1984 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1942 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); 1985 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1943 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); 1986 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1944 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); 1987 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
1945 } 1988 }
1946 } 1989 }
1947 } 1990 }
1948 } 1991 }
1949 } 1992 }
1950 } 1993 }
1994
1995 glEnd ();
1996 glDisable (GL_TEXTURE_2D);
1997 key.texname = -1;
1951 } 1998 }
1952 1999
1953 hv_clear (smooth); 2000 hv_clear (smooth);
1954 rc_draw (rc);
1955 rc_clear (rc);
1956 } 2001 }
1957 2002
1958 glDisable (GL_BLEND); 2003 glDisable (GL_BLEND);
1959 rc_free (rc); 2004 rc_free (rc);
1960 2005
2213 int x, y, z; 2258 int x, y, z;
2214 int w, h; 2259 int w, h;
2215 int x1, y1; 2260 int x1, y1;
2216 2261
2217 if (*data++ != 0) 2262 if (*data++ != 0)
2218 return; /* version mismatch */ 2263 XSRETURN_EMPTY; /* version mismatch */
2219 2264
2220 w = *data++ << 8; w |= *data++; 2265 w = *data++ << 8; w |= *data++;
2221 h = *data++ << 8; h |= *data++; 2266 h = *data++ << 8; h |= *data++;
2222 2267
2223 // we need to do this 'cause we don't keep an absolute coord system for rows 2268 // we need to do this 'cause we don't keep an absolute coord system for rows
2519 const_iv (GL_INTENSITY), 2564 const_iv (GL_INTENSITY),
2520 const_iv (GL_LUMINANCE), 2565 const_iv (GL_LUMINANCE),
2521 const_iv (GL_LUMINANCE_ALPHA), 2566 const_iv (GL_LUMINANCE_ALPHA),
2522 const_iv (GL_FLOAT), 2567 const_iv (GL_FLOAT),
2523 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2568 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2569 const_iv (GL_COMPRESSED_ALPHA_ARB),
2570 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2571 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2572 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2573 const_iv (GL_COMPRESSED_RGB_ARB),
2574 const_iv (GL_COMPRESSED_RGBA_ARB),
2524 const_iv (GL_COMPILE), 2575 const_iv (GL_COMPILE),
2525 const_iv (GL_PROXY_TEXTURE_1D), 2576 const_iv (GL_PROXY_TEXTURE_1D),
2526 const_iv (GL_PROXY_TEXTURE_2D), 2577 const_iv (GL_PROXY_TEXTURE_2D),
2527 const_iv (GL_TEXTURE_1D), 2578 const_iv (GL_TEXTURE_1D),
2528 const_iv (GL_TEXTURE_2D), 2579 const_iv (GL_TEXTURE_2D),
2567 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2618 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2568 const_iv (GL_POINT_SMOOTH_HINT), 2619 const_iv (GL_POINT_SMOOTH_HINT),
2569 const_iv (GL_LINE_SMOOTH_HINT), 2620 const_iv (GL_LINE_SMOOTH_HINT),
2570 const_iv (GL_POLYGON_SMOOTH_HINT), 2621 const_iv (GL_POLYGON_SMOOTH_HINT),
2571 const_iv (GL_GENERATE_MIPMAP_HINT), 2622 const_iv (GL_GENERATE_MIPMAP_HINT),
2623 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2572 const_iv (GL_FASTEST), 2624 const_iv (GL_FASTEST),
2573 const_iv (GL_DONT_CARE), 2625 const_iv (GL_DONT_CARE),
2574 const_iv (GL_NICEST), 2626 const_iv (GL_NICEST),
2575 const_iv (GL_V2F), 2627 const_iv (GL_V2F),
2576 const_iv (GL_V3F), 2628 const_iv (GL_V3F),
2584 2636
2585 texture_av = newAV (); 2637 texture_av = newAV ();
2586 AvREAL_off (texture_av); 2638 AvREAL_off (texture_av);
2587} 2639}
2588 2640
2641void
2642disable_GL_EXT_blend_func_separate ()
2643 CODE:
2644 gl.BlendFuncSeparate = 0;
2645 gl.BlendFuncSeparateEXT = 0;
2646
2589char * 2647char *
2590gl_vendor () 2648gl_vendor ()
2591 CODE: 2649 CODE:
2592 RETVAL = (char *)glGetString (GL_VENDOR); 2650 RETVAL = (char *)glGetString (GL_VENDOR);
2593 OUTPUT: 2651 OUTPUT:
2714 2772
2715void glRect (float x1, float y1, float x2, float y2) 2773void glRect (float x1, float y1, float x2, float y2)
2716 CODE: 2774 CODE:
2717 glRectf (x1, y1, x2, y2); 2775 glRectf (x1, y1, x2, y2);
2718 2776
2777void glRect_lineloop (float x1, float y1, float x2, float y2)
2778 CODE:
2779 glBegin (GL_LINE_LOOP);
2780 glVertex2f (x1, y1);
2781 glVertex2f (x2, y1);
2782 glVertex2f (x2, y2);
2783 glVertex2f (x1, y2);
2784 glEnd ();
2785
2719PROTOTYPES: ENABLE 2786PROTOTYPES: ENABLE
2720 2787
2721void glBegin (int mode) 2788void glBegin (int mode)
2722 2789
2723void glEnd () 2790void glEnd ()
2824 NV x, y, w, h; 2891 NV x, y, w, h;
2825 SV *draw_x_sv = GvSV (draw_x_gv); 2892 SV *draw_x_sv = GvSV (draw_x_gv);
2826 SV *draw_y_sv = GvSV (draw_y_gv); 2893 SV *draw_y_sv = GvSV (draw_y_gv);
2827 SV *draw_w_sv = GvSV (draw_w_gv); 2894 SV *draw_w_sv = GvSV (draw_w_gv);
2828 SV *draw_h_sv = GvSV (draw_h_gv); 2895 SV *draw_h_sv = GvSV (draw_h_gv);
2829 SV *hover;
2830 double draw_x, draw_y, draw_w, draw_h; 2896 double draw_x, draw_y;
2831 2897
2832 if (!SvROK (self)) 2898 if (!SvROK (self))
2833 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 2899 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self));
2834 2900
2835 hv = (HV *)SvRV (self); 2901 hv = (HV *)SvRV (self);
2863 { 2929 {
2864 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 2930 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2865 2931
2866 if (svp && SvTRUE (*svp)) 2932 if (svp && SvTRUE (*svp))
2867 { 2933 {
2868 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 2934 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2869 glEnable (GL_BLEND); 2935 glEnable (GL_BLEND);
2870 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 2936 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2871 glBegin (GL_QUADS); 2937 glBegin (GL_QUADS);
2872 glVertex2f (0, 0); 2938 glVertex2f (0, 0);
2873 glVertex2f (w, 0); 2939 glVertex2f (w, 0);
2876 glEnd (); 2942 glEnd ();
2877 glDisable (GL_BLEND); 2943 glDisable (GL_BLEND);
2878 } 2944 }
2879 } 2945 }
2880#if 0 2946#if 0
2881 if ($ENV{CFPLUS_DEBUG} & 1) { 2947 // draw borders, for debugging
2882 glPushMatrix; 2948 glPushMatrix ();
2883 glColor 1, 1, 0, 1; 2949 glColor4f (1., 1., 0., 1.);
2884 glTranslate 0.375, 0.375; 2950 glTranslatef (.5, .5, 0.);
2885 glBegin GL_LINE_LOOP; 2951 glBegin (GL_LINE_LOOP);
2886 glVertex 0 , 0; 2952 glVertex2f (0 , 0);
2887 glVertex $self->{w} - 1, 0; 2953 glVertex2f (w - 1, 0);
2888 glVertex $self->{w} - 1, $self->{h} - 1; 2954 glVertex2f (w - 1, h - 1);
2889 glVertex 0 , $self->{h} - 1; 2955 glVertex2f (0 , h - 1);
2890 glEnd; 2956 glEnd ();
2891 glPopMatrix; 2957 glPopMatrix ();
2892 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2893 }
2894#endif 2958#endif
2895 PUSHMARK (SP); 2959 PUSHMARK (SP);
2896 XPUSHs (self); 2960 XPUSHs (self);
2897 PUTBACK; 2961 PUTBACK;
2898 call_method ("_draw", G_VOID | G_DISCARD); 2962 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines