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.225 by root, Sat Aug 11 12:07:54 2007 UTC vs.
Revision 1.238 by root, Sat Nov 3 12:08:43 2007 UTC

203 203
204typedef uint16_t tileid; 204typedef uint16_t tileid;
205typedef uint16_t faceid; 205typedef uint16_t faceid;
206 206
207typedef struct { 207typedef struct {
208 int name; 208 GLuint name;
209 int w, h; 209 int w, h;
210 float s, t; 210 float s, t;
211 uint8_t r, g, b, a; 211 uint8_t r, g, b, a;
212 tileid smoothtile; 212 tileid smoothtile;
213 uint8_t smoothlevel; 213 uint8_t smoothlevel;
438 n |= n >> 4; 438 n |= n >> 4;
439 n |= n >> 8; 439 n |= n >> 8;
440 n |= n >> 16; 440 n |= n >> 16;
441 441
442 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;
443} 454}
444 455
445/* SDL should provide this, really. */ 456/* SDL should provide this, really. */
446#define SDLK_MODIFIER_MIN 300 457#define SDLK_MODIFIER_MIN 300
447#define SDLK_MODIFIER_MAX 314 458#define SDLK_MODIFIER_MAX 314
525 536
526 const_iv (SDL_APPINPUTFOCUS), 537 const_iv (SDL_APPINPUTFOCUS),
527 const_iv (SDL_APPMOUSEFOCUS), 538 const_iv (SDL_APPMOUSEFOCUS),
528 const_iv (SDL_APPACTIVE), 539 const_iv (SDL_APPACTIVE),
529 540
541 const_iv (SDLK_FIRST),
542 const_iv (SDLK_LAST),
530 const_iv (SDLK_KP0), 543 const_iv (SDLK_KP0),
531 const_iv (SDLK_KP1), 544 const_iv (SDLK_KP1),
532 const_iv (SDLK_KP2), 545 const_iv (SDLK_KP2),
533 const_iv (SDLK_KP3), 546 const_iv (SDLK_KP3),
534 const_iv (SDLK_KP4), 547 const_iv (SDLK_KP4),
606 const_iv (KMOD_LMETA), 619 const_iv (KMOD_LMETA),
607 const_iv (KMOD_RMETA), 620 const_iv (KMOD_RMETA),
608 const_iv (KMOD_NUM), 621 const_iv (KMOD_NUM),
609 const_iv (KMOD_CAPS), 622 const_iv (KMOD_CAPS),
610 const_iv (KMOD_MODE), 623 const_iv (KMOD_MODE),
624
625 const_iv (MIX_DEFAULT_FORMAT),
611# undef const_iv 626# undef const_iv
612 }; 627 };
613 628
614 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 629 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
615 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 630 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
632 RETVAL 647 RETVAL
633 648
634NV floor (NV x) 649NV floor (NV x)
635 650
636NV ceil (NV x) 651NV ceil (NV x)
652
653IV minpot (UV n)
654
655IV popcount (UV n)
637 656
638void 657void
639pango_init () 658pango_init ()
640 CODE: 659 CODE:
641{ 660{
681 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); 700 m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL);
682 701
683 if (m && m != (SDL_Rect **)-1) 702 if (m && m != (SDL_Rect **)-1)
684 while (*m) 703 while (*m)
685 { 704 {
686 if ((*m)->w >= 640 && (*m)->h >= 480) 705 if ((*m)->w >= 800 && (*m)->h >= 600)
687 { 706 {
688 AV *av = newAV (); 707 AV *av = newAV ();
689 av_push (av, newSViv ((*m)->w)); 708 av_push (av, newSViv ((*m)->w));
690 av_push (av, newSViv ((*m)->h)); 709 av_push (av, newSViv ((*m)->h));
691 av_push (av, newSViv (rgb)); 710 av_push (av, newSViv (rgb));
715 734
716 if (RETVAL) 735 if (RETVAL)
717 { 736 {
718 av_clear (texture_av); 737 av_clear (texture_av);
719 738
720 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 739 SDL_WM_SetCaption ("Deliantra MORPG Client " VERSION, "Deliantra");
721#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 740#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
722#include "glfunc.h" 741#include "glfunc.h"
723#undef GL_FUNC 742#undef GL_FUNC
724 } 743 }
725} 744}
811 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); 830 XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1))));
812 } 831 }
813} 832}
814 833
815int 834int
816Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) 835Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096)
817 POSTCALL: 836 POSTCALL:
818 Mix_HookMusicFinished (music_finished); 837 Mix_HookMusicFinished (music_finished);
819 Mix_ChannelFinished (channel_finished); 838 Mix_ChannelFinished (channel_finished);
839
840void
841Mix_QuerySpec ()
842 PPCODE:
843{
844 int freq, channels;
845 Uint16 format;
846
847 if (Mix_QuerySpec (&freq, &format, &channels))
848 {
849 EXTEND (SP, 3);
850 PUSHs (sv_2mortal (newSViv (freq)));
851 PUSHs (sv_2mortal (newSViv (format)));
852 PUSHs (sv_2mortal (newSViv (channels)));
853 }
854}
820 855
821void 856void
822Mix_CloseAudio () 857Mix_CloseAudio ()
823 858
824int 859int
1346 1381
1347MODULE = CFPlus PACKAGE = CFPlus::Texture 1382MODULE = CFPlus PACKAGE = CFPlus::Texture
1348 1383
1349PROTOTYPES: ENABLE 1384PROTOTYPES: ENABLE
1350 1385
1351int minpot (int n)
1352
1353void 1386void
1354pad (SV *data_, int ow, int oh, int nw, int nh) 1387pad (SV *data_, int ow, int oh, int nw, int nh)
1355 CODE: 1388 CODE:
1356{ 1389{
1357 if ((nw != ow || nh != oh) && SvOK (data_)) 1390 if ((nw != ow || nh != oh) && SvOK (data_))
1745{ 1778{
1746 int x, y, z; 1779 int x, y, z;
1747 1780
1748 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1781 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1749 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1782 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1750 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1783 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1751 smooth_key skey; 1784 smooth_key skey;
1752 1785
1753 rc_t *rc = rc_alloc (); 1786 rc_t *rc = rc_alloc ();
1754 rc_key_t key; 1787 rc_key_t key;
1755 rc_array_t *arr; 1788 rc_array_t *arr;
1817 if (tile) 1850 if (tile)
1818 { 1851 {
1819 maptex tex = self->tex [tile]; 1852 maptex tex = self->tex [tile];
1820 int px, py; 1853 int px, py;
1821 1854
1822 // suppressing texture state switches here
1823 // is only moderately effective, but worth the extra effort
1824 if (key.texname != tex.name) 1855 if (key.texname != tex.name)
1825 { 1856 {
1826 if (!tex.name) 1857 if (!tex.name)
1827 tex = self->tex [2]; /* missing, replace by noface */ 1858 tex = self->tex [2]; /* missing, replace by noface */
1828 1859
1911 // go through all smoothlevels, lowest to highest, then draw. 1942 // go through all smoothlevels, lowest to highest, then draw.
1912 // this is basically counting sort 1943 // this is basically counting sort
1913 { 1944 {
1914 int w, b; 1945 int w, b;
1915 1946
1947 glEnable (GL_TEXTURE_2D);
1948 glBegin (GL_QUADS);
1916 for (w = 0; w < 256 / 32; ++w) 1949 for (w = 0; w < 256 / 32; ++w)
1917 { 1950 {
1918 uint32_t smask = smooth_level [w]; 1951 uint32_t smask = smooth_level [w];
1919 if (smask) 1952 if (smask)
1920 for (b = 0; b < 32; ++b) 1953 for (b = 0; b < 32; ++b)
1945 { 1978 {
1946 // this time avoiding texture state changes 1979 // this time avoiding texture state changes
1947 // save gobs of state changes. 1980 // save gobs of state changes.
1948 if (key.texname != tex.name) 1981 if (key.texname != tex.name)
1949 { 1982 {
1983 glEnd ();
1950 key.texname = tex.name; 1984 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1951 arr = rc_array (rc, &key); 1985 glBegin (GL_QUADS);
1952 } 1986 }
1953 1987
1954 if (border) 1988 if (border)
1955 { 1989 {
1956 float ox = border * dx; 1990 float ox = border * dx;
1957 1991
1958 rc_t2f_v3f (arr, ox , 0.f , px , py , 0); 1992 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1959 rc_t2f_v3f (arr, ox , dy , px , py + T, 0); 1993 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1960 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); 1994 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1961 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); 1995 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1962 } 1996 }
1963 1997
1964 if (corner) 1998 if (corner)
1965 { 1999 {
1966 float ox = corner * dx; 2000 float ox = corner * dx;
1967 2001
1968 rc_t2f_v3f (arr, ox , dy , px , py , 0); 2002 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1969 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); 2003 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1970 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); 2004 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1971 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); 2005 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
1972 } 2006 }
1973 } 2007 }
1974 } 2008 }
1975 } 2009 }
1976 } 2010 }
1977 } 2011 }
2012
2013 glEnd ();
2014 glDisable (GL_TEXTURE_2D);
2015 key.texname = -1;
1978 } 2016 }
1979 2017
1980 hv_clear (smooth); 2018 hv_clear (smooth);
1981 rc_draw (rc);
1982 rc_clear (rc);
1983 } 2019 }
1984 2020
1985 glDisable (GL_BLEND); 2021 glDisable (GL_BLEND);
1986 rc_free (rc); 2022 rc_free (rc);
1987 2023
2240 int x, y, z; 2276 int x, y, z;
2241 int w, h; 2277 int w, h;
2242 int x1, y1; 2278 int x1, y1;
2243 2279
2244 if (*data++ != 0) 2280 if (*data++ != 0)
2245 return; /* version mismatch */ 2281 XSRETURN_EMPTY; /* version mismatch */
2246 2282
2247 w = *data++ << 8; w |= *data++; 2283 w = *data++ << 8; w |= *data++;
2248 h = *data++ << 8; h |= *data++; 2284 h = *data++ << 8; h |= *data++;
2249 2285
2250 // we need to do this 'cause we don't keep an absolute coord system for rows 2286 // we need to do this 'cause we don't keep an absolute coord system for rows
2546 const_iv (GL_INTENSITY), 2582 const_iv (GL_INTENSITY),
2547 const_iv (GL_LUMINANCE), 2583 const_iv (GL_LUMINANCE),
2548 const_iv (GL_LUMINANCE_ALPHA), 2584 const_iv (GL_LUMINANCE_ALPHA),
2549 const_iv (GL_FLOAT), 2585 const_iv (GL_FLOAT),
2550 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2586 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2587 const_iv (GL_COMPRESSED_ALPHA_ARB),
2588 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2589 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2590 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2591 const_iv (GL_COMPRESSED_RGB_ARB),
2592 const_iv (GL_COMPRESSED_RGBA_ARB),
2551 const_iv (GL_COMPILE), 2593 const_iv (GL_COMPILE),
2552 const_iv (GL_PROXY_TEXTURE_1D), 2594 const_iv (GL_PROXY_TEXTURE_1D),
2553 const_iv (GL_PROXY_TEXTURE_2D), 2595 const_iv (GL_PROXY_TEXTURE_2D),
2554 const_iv (GL_TEXTURE_1D), 2596 const_iv (GL_TEXTURE_1D),
2555 const_iv (GL_TEXTURE_2D), 2597 const_iv (GL_TEXTURE_2D),
2594 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2636 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2595 const_iv (GL_POINT_SMOOTH_HINT), 2637 const_iv (GL_POINT_SMOOTH_HINT),
2596 const_iv (GL_LINE_SMOOTH_HINT), 2638 const_iv (GL_LINE_SMOOTH_HINT),
2597 const_iv (GL_POLYGON_SMOOTH_HINT), 2639 const_iv (GL_POLYGON_SMOOTH_HINT),
2598 const_iv (GL_GENERATE_MIPMAP_HINT), 2640 const_iv (GL_GENERATE_MIPMAP_HINT),
2641 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2599 const_iv (GL_FASTEST), 2642 const_iv (GL_FASTEST),
2600 const_iv (GL_DONT_CARE), 2643 const_iv (GL_DONT_CARE),
2601 const_iv (GL_NICEST), 2644 const_iv (GL_NICEST),
2602 const_iv (GL_V2F), 2645 const_iv (GL_V2F),
2603 const_iv (GL_V3F), 2646 const_iv (GL_V3F),
2611 2654
2612 texture_av = newAV (); 2655 texture_av = newAV ();
2613 AvREAL_off (texture_av); 2656 AvREAL_off (texture_av);
2614} 2657}
2615 2658
2659void
2660disable_GL_EXT_blend_func_separate ()
2661 CODE:
2662 gl.BlendFuncSeparate = 0;
2663 gl.BlendFuncSeparateEXT = 0;
2664
2616char * 2665char *
2617gl_vendor () 2666gl_vendor ()
2618 CODE: 2667 CODE:
2619 RETVAL = (char *)glGetString (GL_VENDOR); 2668 RETVAL = (char *)glGetString (GL_VENDOR);
2620 OUTPUT: 2669 OUTPUT:
2741 2790
2742void glRect (float x1, float y1, float x2, float y2) 2791void glRect (float x1, float y1, float x2, float y2)
2743 CODE: 2792 CODE:
2744 glRectf (x1, y1, x2, y2); 2793 glRectf (x1, y1, x2, y2);
2745 2794
2795void glRect_lineloop (float x1, float y1, float x2, float y2)
2796 CODE:
2797 glBegin (GL_LINE_LOOP);
2798 glVertex2f (x1, y1);
2799 glVertex2f (x2, y1);
2800 glVertex2f (x2, y2);
2801 glVertex2f (x1, y2);
2802 glEnd ();
2803
2746PROTOTYPES: ENABLE 2804PROTOTYPES: ENABLE
2747 2805
2748void glBegin (int mode) 2806void glBegin (int mode)
2749 2807
2750void glEnd () 2808void glEnd ()
2851 NV x, y, w, h; 2909 NV x, y, w, h;
2852 SV *draw_x_sv = GvSV (draw_x_gv); 2910 SV *draw_x_sv = GvSV (draw_x_gv);
2853 SV *draw_y_sv = GvSV (draw_y_gv); 2911 SV *draw_y_sv = GvSV (draw_y_gv);
2854 SV *draw_w_sv = GvSV (draw_w_gv); 2912 SV *draw_w_sv = GvSV (draw_w_gv);
2855 SV *draw_h_sv = GvSV (draw_h_gv); 2913 SV *draw_h_sv = GvSV (draw_h_gv);
2856 SV *hover;
2857 double draw_x, draw_y, draw_w, draw_h; 2914 double draw_x, draw_y;
2858 2915
2859 if (!SvROK (self)) 2916 if (!SvROK (self))
2860 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 2917 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self));
2861 2918
2862 hv = (HV *)SvRV (self); 2919 hv = (HV *)SvRV (self);
2890 { 2947 {
2891 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 2948 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2892 2949
2893 if (svp && SvTRUE (*svp)) 2950 if (svp && SvTRUE (*svp))
2894 { 2951 {
2895 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 2952 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2896 glEnable (GL_BLEND); 2953 glEnable (GL_BLEND);
2897 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 2954 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2898 glBegin (GL_QUADS); 2955 glBegin (GL_QUADS);
2899 glVertex2f (0, 0); 2956 glVertex2f (0, 0);
2900 glVertex2f (w, 0); 2957 glVertex2f (w, 0);
2903 glEnd (); 2960 glEnd ();
2904 glDisable (GL_BLEND); 2961 glDisable (GL_BLEND);
2905 } 2962 }
2906 } 2963 }
2907#if 0 2964#if 0
2908 if ($ENV{CFPLUS_DEBUG} & 1) { 2965 // draw borders, for debugging
2909 glPushMatrix; 2966 glPushMatrix ();
2910 glColor 1, 1, 0, 1; 2967 glColor4f (1., 1., 0., 1.);
2911 glTranslate 0.375, 0.375; 2968 glTranslatef (.5, .5, 0.);
2912 glBegin GL_LINE_LOOP; 2969 glBegin (GL_LINE_LOOP);
2913 glVertex 0 , 0; 2970 glVertex2f (0 , 0);
2914 glVertex $self->{w} - 1, 0; 2971 glVertex2f (w - 1, 0);
2915 glVertex $self->{w} - 1, $self->{h} - 1; 2972 glVertex2f (w - 1, h - 1);
2916 glVertex 0 , $self->{h} - 1; 2973 glVertex2f (0 , h - 1);
2917 glEnd; 2974 glEnd ();
2918 glPopMatrix; 2975 glPopMatrix ();
2919 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
2920 }
2921#endif 2976#endif
2922 PUSHMARK (SP); 2977 PUSHMARK (SP);
2923 XPUSHs (self); 2978 XPUSHs (self);
2924 PUTBACK; 2979 PUTBACK;
2925 call_method ("_draw", G_VOID | G_DISCARD); 2980 call_method ("_draw", G_VOID | G_DISCARD);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines