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.103 by root, Sun Jun 4 23:05:05 2006 UTC vs.
Revision 1.113 by root, Wed Jun 14 16:20:21 2006 UTC

10#include "XSUB.h" 10#include "XSUB.h"
11 11
12#include <math.h> 12#include <math.h>
13#include <string.h> 13#include <string.h>
14#include <stdio.h> 14#include <stdio.h>
15#include <stdlib.h>
15 16
16#include <SDL.h> 17#include <SDL.h>
17#include <SDL_endian.h> 18#include <SDL_endian.h>
18#include <SDL_image.h> 19#include <SDL_image.h>
19#include <SDL_mixer.h> 20#include <SDL_mixer.h>
85static PangoFontMap *ft2_fontmap, *cairo_fontmap; 86static PangoFontMap *ft2_fontmap, *cairo_fontmap;
86 87
87static void 88static void
88substitute_func (FcPattern *pattern, gpointer data) 89substitute_func (FcPattern *pattern, gpointer data)
89{ 90{
90 FcPatternAddBool (pattern, FC_HINTING , 1); 91 FcPatternAddBool (pattern, FC_HINTING, 1);
92#ifdef FC_HINT_STYLE
93 FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL);
94#endif
91#ifdef _WIN32 95#ifdef _WIN32
92 FcPatternAddBool (pattern, FC_AUTOHINT, 1); 96 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
93#else 97#else
94 FcPatternAddBool (pattern, FC_AUTOHINT, 0); 98 FcPatternAddBool (pattern, FC_AUTOHINT, 0);
95#endif 99#endif
296 ev.code = 1; 300 ev.code = 1;
297 ev.data1 = (void *)(long)channel; 301 ev.data1 = (void *)(long)channel;
298 ev.data2 = 0; 302 ev.data2 = 0;
299 303
300 SDL_PushEvent ((SDL_Event *)&ev); 304 SDL_PushEvent ((SDL_Event *)&ev);
305}
306
307static unsigned int
308minpot (unsigned int n)
309{
310 if (!n)
311 return 0;
312
313 --n;
314
315 n |= n >> 1;
316 n |= n >> 2;
317 n |= n >> 4;
318 n |= n >> 8;
319 n |= n >> 16;
320
321 return n + 1;
301} 322}
302 323
303MODULE = CFClient PACKAGE = CFClient 324MODULE = CFClient PACKAGE = CFClient
304 325
305PROTOTYPES: ENABLE 326PROTOTYPES: ENABLE
418} 439}
419 440
420void 441void
421pango_init () 442pango_init ()
422 CODE: 443 CODE:
423{
424 // delayed, so it can pick up new fonts added by AddFontResourceEx 444 // delayed, so it can pick up new fonts added by AddFontResourceEx
445{
446 {
425 ft2_fontmap = pango_ft2_font_map_new (); 447 ft2_fontmap = pango_ft2_font_map_new ();
426 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); 448 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0);
427 ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); 449 ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap);
428 450 }
451 {
452 cairo_font_options_t *fopt = cairo_font_options_create ();
429 cairo_fontmap = pango_cairo_font_map_get_default (); 453 cairo_fontmap = pango_cairo_font_map_get_default ();
430 cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); 454 cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap);
455#ifdef _WIN32
456 // cairo looks like shit eaten twice on windows
457 cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE);
458#else
459 cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY);
460#endif
461 cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL);
462 cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON);
463 pango_cairo_context_set_font_options (cairo_context, fopt);
464 cairo_font_options_destroy (fopt);
465 }
431} 466}
432 467
433int 468int
434SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) 469SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO)
435 470
686 CODE: 721 CODE:
687 fprintf (stderr, "FATAL: %s\n", message); 722 fprintf (stderr, "FATAL: %s\n", message);
688#ifdef _WIN32 723#ifdef _WIN32
689 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); 724 MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR);
690#endif 725#endif
691 exit (1); 726 _exit (1);
727
728void
729_exit (int retval)
730 CODE:
731 _exit (retval);
692 732
693MODULE = CFClient PACKAGE = CFClient::Font 733MODULE = CFClient PACKAGE = CFClient::Font
694 734
695CFClient::Font 735CFClient::Font
696new_from_file (SV *class, char *path, int id = 0) 736new_from_file (SV *class, char *path, int id = 0)
717MODULE = CFClient PACKAGE = CFClient::Layout 757MODULE = CFClient PACKAGE = CFClient::Layout
718 758
719CFClient::Layout 759CFClient::Layout
720new (SV *class, int rgba = 0) 760new (SV *class, int rgba = 0)
721 CODE: 761 CODE:
722#if _WIN32
723 //rgba = 0;//D makes text nicer, breaks TextView
724#endif
725 New (0, RETVAL, 1, struct cf_layout); 762 New (0, RETVAL, 1, struct cf_layout);
726 763
727 RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); 764 RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context);
728 RETVAL->rgba = rgba; 765 RETVAL->rgba = rgba;
729 RETVAL->r = 1.; 766 RETVAL->r = 1.;
773 810
774SV * 811SV *
775get_text (CFClient::Layout self) 812get_text (CFClient::Layout self)
776 CODE: 813 CODE:
777 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); 814 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
778 SvUTF8_on (RETVAL); 815 sv_utf8_decode (RETVAL);
779 OUTPUT: 816 OUTPUT:
780 RETVAL 817 RETVAL
781 818
782void 819void
783set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.) 820set_foreground (CFClient::Layout self, float r, float g, float b, float a = 1.)
964} 1001}
965 1002
966MODULE = CFClient PACKAGE = CFClient::Texture 1003MODULE = CFClient PACKAGE = CFClient::Texture
967 1004
968void 1005void
1006pad2pot (SV *data_, SV *w_, SV *h_)
1007 CODE:
1008{
1009 int ow = SvIV (w_);
1010 int oh = SvIV (h_);
1011
1012 if (ow && oh)
1013 {
1014 int nw = minpot (ow);
1015 int nh = minpot (oh);
1016
1017 if (nw != ow || nh != oh)
1018 {
1019 if (SvOK (data_))
1020 {
1021 STRLEN datalen;
1022 char *data = SvPVbyte (data_, datalen);
1023 int bpp = datalen / (ow * oh);
1024 SV *result_ = sv_2mortal (newSV (nw * nh * bpp));
1025
1026 SvPOK_only (result_);
1027 SvCUR_set (result_, nw * nh * bpp);
1028
1029 memset (SvPVX (result_), 0, nw * nh * bpp);
1030 while (oh--)
1031 memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp);
1032
1033 sv_setsv (data_, result_);
1034 }
1035
1036 sv_setiv (w_, nw);
1037 sv_setiv (h_, nh);
1038 }
1039 }
1040}
1041
1042void
969draw_quad (SV *self, float x, float y, float w = 0, float h = 0) 1043draw_quad (SV *self, float x, float y, float w = 0, float h = 0)
970 PROTOTYPE: $$$;$$ 1044 PROTOTYPE: $$$;$$
971 ALIAS: 1045 ALIAS:
972 draw_quad_alpha = 1 1046 draw_quad_alpha = 1
973 draw_quad_alpha_premultiplied = 2 1047 draw_quad_alpha_premultiplied = 2
990 1064
991 if (ix == 2) 1065 if (ix == 2)
992 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 1066 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
993 else 1067 else
994 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1068 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
995 GL_ONE_MINUS_DST_ALPHA, GL_ONE); 1069 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
996 1070
997 glEnable (GL_ALPHA_TEST); 1071 glEnable (GL_ALPHA_TEST);
998 glAlphaFunc (GL_GREATER, 0.01f); 1072 glAlphaFunc (GL_GREATER, 0.01f);
999 } 1073 }
1000 1074
1039DESTROY (CFClient::Map self) 1113DESTROY (CFClient::Map self)
1040 CODE: 1114 CODE:
1041{ 1115{
1042 map_clear (self); 1116 map_clear (self);
1043 Safefree (self->face); 1117 Safefree (self->face);
1118 Safefree (self->tex);
1044 Safefree (self); 1119 Safefree (self);
1045} 1120}
1046 1121
1047void 1122void
1048clear (CFClient::Map self) 1123clear (CFClient::Map self)
1557 const_iv (GL_RESCALE_NORMAL), 1632 const_iv (GL_RESCALE_NORMAL),
1558 const_iv (GL_AND), 1633 const_iv (GL_AND),
1559 const_iv (GL_ONE), 1634 const_iv (GL_ONE),
1560 const_iv (GL_ZERO), 1635 const_iv (GL_ZERO),
1561 const_iv (GL_SRC_ALPHA), 1636 const_iv (GL_SRC_ALPHA),
1562 const_iv (GL_SRC_ALPHA_SATURATE), 1637 const_iv (GL_DST_ALPHA),
1563 const_iv (GL_ONE_MINUS_SRC_ALPHA), 1638 const_iv (GL_ONE_MINUS_SRC_ALPHA),
1564 const_iv (GL_ONE_MINUS_DST_ALPHA), 1639 const_iv (GL_ONE_MINUS_DST_ALPHA),
1640 const_iv (GL_SRC_ALPHA_SATURATE),
1565 const_iv (GL_RGB), 1641 const_iv (GL_RGB),
1566 const_iv (GL_RGBA), 1642 const_iv (GL_RGBA),
1567 const_iv (GL_UNSIGNED_BYTE), 1643 const_iv (GL_UNSIGNED_BYTE),
1568 const_iv (GL_UNSIGNED_SHORT), 1644 const_iv (GL_UNSIGNED_SHORT),
1569 const_iv (GL_UNSIGNED_INT), 1645 const_iv (GL_UNSIGNED_INT),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines