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.43 by root, Mon Apr 17 06:50:26 2006 UTC vs.
Revision 1.48 by root, Tue Apr 18 00:14:16 2006 UTC

1#ifdef _WIN32
2# include <malloc.h>
3#endif
4
1#include "EXTERN.h" 5#include "EXTERN.h"
2#include "perl.h" 6#include "perl.h"
3#include "XSUB.h" 7#include "XSUB.h"
4 8
5#include <string.h> 9#include <string.h>
13 17
14#include <pango/pango.h> 18#include <pango/pango.h>
15#include <pango/pangofc-fontmap.h> 19#include <pango/pangofc-fontmap.h>
16#include <pango/pangoft2.h> 20#include <pango/pangoft2.h>
17 21
22#ifndef _WIN32
18#include <sys/types.h> 23# include <sys/types.h>
19#include <sys/socket.h> 24# include <sys/socket.h>
20#include <netinet/in.h> 25# include <netinet/in.h>
21#include <netinet/tcp.h> 26# include <netinet/tcp.h>
22
23#include <inttypes.h> 27# include <inttypes.h>
28#else
29 typedef unsigned char uint8_t;
30 typedef unsigned short uint16_t;
31 typedef unsigned int uint32_t;
32 typedef signed char int8_t;
33 typedef signed short int16_t;
34 typedef signed int int32_t;
35#endif
24 36
25#define FOW_DARKNESS 32 37#define FOW_DARKNESS 32
26 38
27#define MAP_EXTEND_X 32 39#define MAP_EXTEND_X 32
28#define MAP_EXTEND_Y 512 40#define MAP_EXTEND_Y 512
47{ 59{
48 /* use a random scale factor to account for unknown descenders, 0.8 works 60 /* use a random scale factor to account for unknown descenders, 0.8 works
49 * reasonably well with bitstream vera 61 * reasonably well with bitstream vera
50 */ 62 */
51 PangoFontDescription *font = pango_context_get_font_description (context); 63 PangoFontDescription *font = pango_context_get_font_description (context);
52 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); 64
65 int height = self->base_height * (PANGO_SCALE * 8 / 10);
66
67 if (pango_font_description_get_size (font) != height)
68 {
69 pango_font_description_set_absolute_size (font, height);
70 pango_layout_context_changed (self->pl);
71 }
53} 72}
54 73
55static void 74static void
56layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 75layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
57{ 76{
83 mapcell *col; 102 mapcell *col;
84} maprow; 103} maprow;
85 104
86typedef struct map { 105typedef struct map {
87 int x, y, w, h; 106 int x, y, w, h;
88 int dx, dy; /* delayed map scrolling */
89 int ox, oy; /* offset to virtual global coordinate system */ 107 int ox, oy; /* offset to virtual global coordinate system */
90 int faces; 108 int faces;
91 mapface *face; 109 mapface *face;
92 110
93 int texs; 111 int texs;
94 maptex *tex; 112 maptex *tex;
95 113
96 uint32_t rows; 114 int32_t rows;
97 maprow *row; 115 maprow *row;
98} *CFClient__Map; 116} *CFClient__Map;
99 117
100static char * 118static char *
101prepend (char *ptr, int sze, int inc) 119prepend (char *ptr, int sze, int inc)
196 214
197static void 215static void
198map_blank (CFClient__Map self, int x0, int y0, int w, int h) 216map_blank (CFClient__Map self, int x0, int y0, int w, int h)
199{ 217{
200 int x, y; 218 int x, y;
219 maprow *row;
201 220
202 for (y = y0; y < y0 + h; y++) 221 for (y = y0; y < y0 + h; y++)
203 if (y >= 0) 222 if (y >= 0)
204 { 223 {
205 if (y >= self->rows) 224 if (y >= self->rows)
206 break; 225 break;
207 226
208 maprow *row = self->row + y; 227 row = self->row + y;
209 228
210 for (x = x0; x < x0 + w; x++) 229 for (x = x0; x < x0 + w; x++)
211 if (x >= row->c0) 230 if (x >= row->c0)
212 { 231 {
213 if (x >= row->c1) 232 if (x >= row->c1)
230} 249}
231 250
232void 251void
233lowdelay (int fd, int val = 1) 252lowdelay (int fd, int val = 1)
234 CODE: 253 CODE:
254#ifndef _WIN32
235 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 255 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
256#endif
236 257
237char * 258char *
238gl_version () 259gl_version ()
239 CODE: 260 CODE:
240 RETVAL = (char *)glGetString (GL_VERSION); 261 RETVAL = (char *)glGetString (GL_VERSION);
392 char *text = SvPVutf8 (text_, textlen); 413 char *text = SvPVutf8 (text_, textlen);
393 414
394 pango_layout_set_markup (self->pl, text, textlen); 415 pango_layout_set_markup (self->pl, text, textlen);
395} 416}
396 417
418SV *
419get_text (CFClient::Layout self)
420 CODE:
421 RETVAL = newSVpv (pango_layout_get_text (self->pl), 0);
422 SvUTF8_on (RETVAL);
423 OUTPUT:
424 RETVAL
425
397void 426void
398set_height (CFClient::Layout self, int base_height) 427set_height (CFClient::Layout self, int base_height)
399 CODE: 428 CODE:
400 self->base_height = base_height; 429 self->base_height = base_height;
401 430
566 { 595 {
567 Append (maptex, self->tex, self->texs, self->texs); 596 Append (maptex, self->tex, self->texs, self->texs);
568 self->texs *= 2; 597 self->texs *= 2;
569 } 598 }
570 599
600 {
571 maptex *tex = self->tex + texid; 601 maptex *tex = self->tex + texid;
572 602
573 tex->name = name; 603 tex->name = name;
574 tex->w = w; 604 tex->w = w;
575 tex->h = h; 605 tex->h = h;
576 tex->s = s; 606 tex->s = s;
577 tex->t = t; 607 tex->t = t;
578 tex->r = r; 608 tex->r = r;
579 tex->g = g; 609 tex->g = g;
580 tex->b = b; 610 tex->b = b;
581 tex->a = a; 611 tex->a = a;
612 }
582} 613}
583 614
584int 615int
585ox (CFClient::Map self) 616ox (CFClient::Map self)
586 ALIAS: 617 ALIAS:
596 627
597void 628void
598scroll (CFClient::Map self, int dx, int dy) 629scroll (CFClient::Map self, int dx, int dy)
599 CODE: 630 CODE:
600{ 631{
601 self->dx += dx; self->ox += dx;
602 self->dy += dy; self->oy += dy;
603}
604
605void
606map1a_update (CFClient::Map self, SV *data_)
607 CODE:
608{
609 if (self->dx > 0) 632 if (dx > 0)
610 map_blank (self, self->x, self->y, self->dx - 1, self->h); 633 map_blank (self, self->x, self->y, dx - 1, self->h);
611 else if (self->dx < 0) 634 else if (dx < 0)
612 map_blank (self, self->x + self->w + self->dx + 1, self->y, 1 - self->dx, self->h); 635 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h);
613 636
614 if (self->dy > 0) 637 if (dy > 0)
615 map_blank (self, self->x, self->y, self->w, self->dy - 1); 638 map_blank (self, self->x, self->y, self->w, dy - 1);
616 else if (self->dy < 0) 639 else if (dy < 0)
617 map_blank (self, self->x, self->y + self->h + self->dy + 1, self->w, 1 - self->dy); 640 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy);
618 641
619 self->x += self->dx; self->dx = 0; 642 self->ox += dx; self->x += dx;
620 self->y += self->dy; self->dy = 0; 643 self->oy += dy; self->y += dy;
621 644
622 while (self->y < 0) 645 while (self->y < 0)
623 { 646 {
624 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 647 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y);
625 648
626 self->rows += MAP_EXTEND_Y; 649 self->rows += MAP_EXTEND_Y;
627 self->y += MAP_EXTEND_Y; 650 self->y += MAP_EXTEND_Y;
628 } 651 }
652}
629 653
654void
655map1a_update (CFClient::Map self, SV *data_)
656 CODE:
657{
630 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 658 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
631 uint8_t *data_end = (uint8_t *)SvEND (data_); 659 uint8_t *data_end = (uint8_t *)SvEND (data_);
660 mapcell *cell;
661 int x, y, flags;
632 662
633 while (data < data_end) 663 while (data < data_end)
634 { 664 {
635 int flags = (data [0] << 8) + data [1]; data += 2; 665 flags = (data [0] << 8) + data [1]; data += 2;
636 666
637 int x = ((flags >> 10) & 63) + self->x; 667 x = ((flags >> 10) & 63) + self->x;
638 int y = ((flags >> 4) & 63) + self->y; 668 y = ((flags >> 4) & 63) + self->y;
639 669
640 mapcell *cell = map_get_cell (self, x, y); 670 cell = map_get_cell (self, x, y);
641 671
642 if (flags & 15) 672 if (flags & 15)
643 { 673 {
644 if (cell->darkness < 0) // && x < self->w && y < self->h) 674 if (cell->darkness < 0)
645 { 675 {
646 cell->darkness = 0; 676 cell->darkness = 0;
647 cell->face [0] = 0; 677 cell->face [0] = 0;
648 cell->face [1] = 0; 678 cell->face [1] = 0;
649 cell->face [2] = 0; 679 cell->face [2] = 0;
650 } 680 }
651 681
652 cell->darkness = flags & 8 ? *data++ : 255; 682 cell->darkness = flags & 8 ? *data++ : 255;
653 683
654 //TODO: don't trust server data to be in-range(!) 684 //TODO: don't trust server data to be in-range(!)
655 685
656 if (flags & 4) 686 if (flags & 4)
735 765
736void 766void
737draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 767draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
738 PPCODE: 768 PPCODE:
739{ 769{
770 int vx, vy;
771 int x, y, z;
772 int last_name;
773 mapface face;
740 int sw4 = (sw + 3) & ~3; 774 int sw4 = (sw + 3) & ~3;
741 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 775 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
742 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 776 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
777
743 memset (darkness, 255, sw4 * sh); 778 memset (darkness, 255, sw4 * sh);
744 SvPOK_only (darkness_sv); 779 SvPOK_only (darkness_sv);
745 SvCUR_set (darkness_sv, sw4 * sh); 780 SvCUR_set (darkness_sv, sw4 * sh);
746 781
747 int vx = self->x + (self->w - sw) / 2 - shift_x; 782 vx = self->x + (self->w - sw) / 2 - shift_x;
748 int vy = self->y + (self->h - sh) / 2 - shift_y; 783 vy = self->y + (self->h - sh) / 2 - shift_y;
749 784
750 /* 785 /*
751 int vx = self->vx = self->w >= sw 786 int vx = self->vx = self->w >= sw
752 ? self->x + (self->w - sw) / 2 787 ? self->x + (self->w - sw) / 2
753 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); 788 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
762 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 797 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
763 glEnable (GL_BLEND); 798 glEnable (GL_BLEND);
764 glEnable (GL_TEXTURE_2D); 799 glEnable (GL_TEXTURE_2D);
765 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 800 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
766 801
767 int x, y, z;
768
769 int last_name = 0;
770
771 glBegin (GL_QUADS); 802 glBegin (GL_QUADS);
803
804 last_name = 0;
772 805
773 for (z = 0; z < 3; z++) 806 for (z = 0; z < 3; z++)
774 for (y = 0; y < sh; y++) 807 for (y = 0; y < sh; y++)
775 if (0 <= y + vy && y + vy < self->rows) 808 if (0 <= y + vy && y + vy < self->rows)
776 { 809 {
783 816
784 darkness[y * sw4 + x] = cell->darkness < 0 817 darkness[y * sw4 + x] = cell->darkness < 0
785 ? 255 - FOW_DARKNESS 818 ? 255 - FOW_DARKNESS
786 : 255 - cell->darkness; 819 : 255 - cell->darkness;
787 820
788 mapface face = cell->face [z]; 821 face = cell->face [z];
789 822
790 if (face) 823 if (face)
791 { 824 {
792 maptex tex = self->tex [face]; 825 maptex tex = self->tex [face];
793 826
853 for (x = x0; x < x1; x++) 886 for (x = x0; x < x1; x++)
854 { 887 {
855 if (row && row->c0 <= x && x < row->c1) 888 if (row && row->c0 <= x && x < row->c1)
856 { 889 {
857 mapcell *cell = row->col + (x - row->c0); 890 mapcell *cell = row->col + (x - row->c0);
858
859 uint8_t flags = 0; 891 uint8_t flags = 0;
860 892
861 if (cell->face [0]) flags |= 1; 893 if (cell->face [0]) flags |= 1;
862 if (cell->face [1]) flags |= 2; 894 if (cell->face [1]) flags |= 2;
863 if (cell->face [2]) flags |= 4; 895 if (cell->face [2]) flags |= 4;
897void 929void
898set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 930set_rect (CFClient::Map self, int x0, int y0, uint8_t *data)
899 PPCODE: 931 PPCODE:
900{ 932{
901 int x, y, z; 933 int x, y, z;
934 int w, h;
902 int x1, y1; 935 int x1, y1;
903 936
904 if (*data++ != 0) 937 if (*data++ != 0)
905 return; /* version mismatch */ 938 return; /* version mismatch */
906 939
907 int w = *data++ << 8; w |= *data++; 940 w = *data++ << 8; w |= *data++;
908 int h = *data++ << 8; h |= *data++; 941 h = *data++ << 8; h |= *data++;
909 942
910 // we need to do this 'cause we don't keep an absolute coord system for rows 943 // we need to do this 'cause we don't keep an absolute coord system for rows
911 // TODO: treat rows as we treat 944 // TODO: treat rows as we treat
912 map_get_row (self, y0 + self->y - self->oy);//D 945 map_get_row (self, y0 + self->y - self->oy);//D
913 map_get_row (self, y0 + self->y - self->oy + h - 1);//D 946 map_get_row (self, y0 + self->y - self->oy + h - 1);//D

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines