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.223 by root, Sat Aug 11 11:07:08 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
1876 } 1916 }
1877 } 1917 }
1878 } 1918 }
1879 } 1919 }
1880 1920
1921 rc_draw (rc);
1922 rc_clear (rc);
1923
1881 // go through all smoothlevels, lowest to highest, then draw. 1924 // go through all smoothlevels, lowest to highest, then draw.
1882 // this is basically counting sort 1925 // this is basically counting sort
1883 { 1926 {
1884 int w, b; 1927 int w, b;
1885 1928
1929 glEnable (GL_TEXTURE_2D);
1930 glBegin (GL_QUADS);
1886 for (w = 0; w < 256 / 32; ++w) 1931 for (w = 0; w < 256 / 32; ++w)
1887 { 1932 {
1888 uint32_t smask = smooth_level [w]; 1933 uint32_t smask = smooth_level [w];
1889 if (smask) 1934 if (smask)
1890 for (b = 0; b < 32; ++b) 1935 for (b = 0; b < 32; ++b)
1915 { 1960 {
1916 // this time avoiding texture state changes 1961 // this time avoiding texture state changes
1917 // save gobs of state changes. 1962 // save gobs of state changes.
1918 if (key.texname != tex.name) 1963 if (key.texname != tex.name)
1919 { 1964 {
1965 glEnd ();
1920 key.texname = tex.name; 1966 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1921 arr = rc_array (rc, &key); 1967 glBegin (GL_QUADS);
1922 } 1968 }
1923 1969
1924 if (border) 1970 if (border)
1925 { 1971 {
1926 float ox = border * dx; 1972 float ox = border * dx;
1927 1973
1928 rc_t2f_v3f (arr, ox , 0.f , px , py , 0); 1974 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1929 rc_t2f_v3f (arr, ox , dy , px , py + T, 0); 1975 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1930 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); 1976 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1931 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); 1977 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1932 } 1978 }
1933 1979
1934 if (corner) 1980 if (corner)
1935 { 1981 {
1936 float ox = corner * dx; 1982 float ox = corner * dx;
1937 1983
1938 rc_t2f_v3f (arr, ox , dy , px , py , 0); 1984 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1939 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); 1985 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1940 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);
1941 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); 1987 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
1942 } 1988 }
1943 } 1989 }
1944 } 1990 }
1945 } 1991 }
1946 } 1992 }
1947 } 1993 }
1994
1995 glEnd ();
1996 glDisable (GL_TEXTURE_2D);
1997 key.texname = -1;
1948 } 1998 }
1949 1999
1950 hv_clear (smooth); 2000 hv_clear (smooth);
1951 rc_draw (rc);
1952 rc_clear (rc);
1953 } 2001 }
1954 2002
1955 glDisable (GL_BLEND); 2003 glDisable (GL_BLEND);
1956 rc_free (rc); 2004 rc_free (rc);
1957 2005
2210 int x, y, z; 2258 int x, y, z;
2211 int w, h; 2259 int w, h;
2212 int x1, y1; 2260 int x1, y1;
2213 2261
2214 if (*data++ != 0) 2262 if (*data++ != 0)
2215 return; /* version mismatch */ 2263 XSRETURN_EMPTY; /* version mismatch */
2216 2264
2217 w = *data++ << 8; w |= *data++; 2265 w = *data++ << 8; w |= *data++;
2218 h = *data++ << 8; h |= *data++; 2266 h = *data++ << 8; h |= *data++;
2219 2267
2220 // 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
2516 const_iv (GL_INTENSITY), 2564 const_iv (GL_INTENSITY),
2517 const_iv (GL_LUMINANCE), 2565 const_iv (GL_LUMINANCE),
2518 const_iv (GL_LUMINANCE_ALPHA), 2566 const_iv (GL_LUMINANCE_ALPHA),
2519 const_iv (GL_FLOAT), 2567 const_iv (GL_FLOAT),
2520 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),
2521 const_iv (GL_COMPILE), 2575 const_iv (GL_COMPILE),
2522 const_iv (GL_PROXY_TEXTURE_1D), 2576 const_iv (GL_PROXY_TEXTURE_1D),
2523 const_iv (GL_PROXY_TEXTURE_2D), 2577 const_iv (GL_PROXY_TEXTURE_2D),
2524 const_iv (GL_TEXTURE_1D), 2578 const_iv (GL_TEXTURE_1D),
2525 const_iv (GL_TEXTURE_2D), 2579 const_iv (GL_TEXTURE_2D),
2564 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2618 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2565 const_iv (GL_POINT_SMOOTH_HINT), 2619 const_iv (GL_POINT_SMOOTH_HINT),
2566 const_iv (GL_LINE_SMOOTH_HINT), 2620 const_iv (GL_LINE_SMOOTH_HINT),
2567 const_iv (GL_POLYGON_SMOOTH_HINT), 2621 const_iv (GL_POLYGON_SMOOTH_HINT),
2568 const_iv (GL_GENERATE_MIPMAP_HINT), 2622 const_iv (GL_GENERATE_MIPMAP_HINT),
2623 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2569 const_iv (GL_FASTEST), 2624 const_iv (GL_FASTEST),
2570 const_iv (GL_DONT_CARE), 2625 const_iv (GL_DONT_CARE),
2571 const_iv (GL_NICEST), 2626 const_iv (GL_NICEST),
2572 const_iv (GL_V2F), 2627 const_iv (GL_V2F),
2573 const_iv (GL_V3F), 2628 const_iv (GL_V3F),
2581 2636
2582 texture_av = newAV (); 2637 texture_av = newAV ();
2583 AvREAL_off (texture_av); 2638 AvREAL_off (texture_av);
2584} 2639}
2585 2640
2641void
2642disable_GL_EXT_blend_func_separate ()
2643 CODE:
2644 gl.BlendFuncSeparate = 0;
2645 gl.BlendFuncSeparateEXT = 0;
2646
2586char * 2647char *
2587gl_vendor () 2648gl_vendor ()
2588 CODE: 2649 CODE:
2589 RETVAL = (char *)glGetString (GL_VENDOR); 2650 RETVAL = (char *)glGetString (GL_VENDOR);
2590 OUTPUT: 2651 OUTPUT:
2711 2772
2712void glRect (float x1, float y1, float x2, float y2) 2773void glRect (float x1, float y1, float x2, float y2)
2713 CODE: 2774 CODE:
2714 glRectf (x1, y1, x2, y2); 2775 glRectf (x1, y1, x2, y2);
2715 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
2716PROTOTYPES: ENABLE 2786PROTOTYPES: ENABLE
2717 2787
2718void glBegin (int mode) 2788void glBegin (int mode)
2719 2789
2720void glEnd () 2790void glEnd ()
2821 NV x, y, w, h; 2891 NV x, y, w, h;
2822 SV *draw_x_sv = GvSV (draw_x_gv); 2892 SV *draw_x_sv = GvSV (draw_x_gv);
2823 SV *draw_y_sv = GvSV (draw_y_gv); 2893 SV *draw_y_sv = GvSV (draw_y_gv);
2824 SV *draw_w_sv = GvSV (draw_w_gv); 2894 SV *draw_w_sv = GvSV (draw_w_gv);
2825 SV *draw_h_sv = GvSV (draw_h_gv); 2895 SV *draw_h_sv = GvSV (draw_h_gv);
2826 SV *hover;
2827 double draw_x, draw_y, draw_w, draw_h; 2896 double draw_x, draw_y;
2828 2897
2829 if (!SvROK (self)) 2898 if (!SvROK (self))
2830 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 2899 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self));
2831 2900
2832 hv = (HV *)SvRV (self); 2901 hv = (HV *)SvRV (self);
2860 { 2929 {
2861 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 2930 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2862 2931
2863 if (svp && SvTRUE (*svp)) 2932 if (svp && SvTRUE (*svp))
2864 { 2933 {
2865 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);
2866 glEnable (GL_BLEND); 2935 glEnable (GL_BLEND);
2867 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 2936 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2868 glBegin (GL_QUADS); 2937 glBegin (GL_QUADS);
2869 glVertex2f (0, 0); 2938 glVertex2f (0, 0);
2870 glVertex2f (w, 0); 2939 glVertex2f (w, 0);
2873 glEnd (); 2942 glEnd ();
2874 glDisable (GL_BLEND); 2943 glDisable (GL_BLEND);
2875 } 2944 }
2876 } 2945 }
2877#if 0 2946#if 0
2878 if ($ENV{CFPLUS_DEBUG} & 1) { 2947 // draw borders, for debugging
2879 glPushMatrix; 2948 glPushMatrix ();
2880 glColor 1, 1, 0, 1; 2949 glColor4f (1., 1., 0., 1.);
2881 glTranslate 0.375, 0.375; 2950 glTranslatef (.5, .5, 0.);
2882 glBegin GL_LINE_LOOP; 2951 glBegin (GL_LINE_LOOP);
2883 glVertex 0 , 0; 2952 glVertex2f (0 , 0);
2884 glVertex $self->{w} - 1, 0; 2953 glVertex2f (w - 1, 0);
2885 glVertex $self->{w} - 1, $self->{h} - 1; 2954 glVertex2f (w - 1, h - 1);
2886 glVertex 0 , $self->{h} - 1; 2955 glVertex2f (0 , h - 1);
2887 glEnd; 2956 glEnd ();
2888 glPopMatrix; 2957 glPopMatrix ();
2889 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2890 }
2891#endif 2958#endif
2892 PUSHMARK (SP); 2959 PUSHMARK (SP);
2893 XPUSHs (self); 2960 XPUSHs (self);
2894 PUTBACK; 2961 PUTBACK;
2895 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