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.47 by root, Mon Apr 17 21:52:42 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
97 mapface *face; 109 mapface *face;
98 110
99 int texs; 111 int texs;
100 maptex *tex; 112 maptex *tex;
101 113
102 uint32_t rows; 114 int32_t rows;
103 maprow *row; 115 maprow *row;
104} *CFClient__Map; 116} *CFClient__Map;
105 117
106static char * 118static char *
107prepend (char *ptr, int sze, int inc) 119prepend (char *ptr, int sze, int inc)
202 214
203static void 215static void
204map_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)
205{ 217{
206 int x, y; 218 int x, y;
219 maprow *row;
207 220
208 for (y = y0; y < y0 + h; y++) 221 for (y = y0; y < y0 + h; y++)
209 if (y >= 0) 222 if (y >= 0)
210 { 223 {
211 if (y >= self->rows) 224 if (y >= self->rows)
212 break; 225 break;
213 226
214 maprow *row = self->row + y; 227 row = self->row + y;
215 228
216 for (x = x0; x < x0 + w; x++) 229 for (x = x0; x < x0 + w; x++)
217 if (x >= row->c0) 230 if (x >= row->c0)
218 { 231 {
219 if (x >= row->c1) 232 if (x >= row->c1)
236} 249}
237 250
238void 251void
239lowdelay (int fd, int val = 1) 252lowdelay (int fd, int val = 1)
240 CODE: 253 CODE:
254#ifndef _WIN32
241 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); 255 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
256#endif
242 257
243char * 258char *
244gl_version () 259gl_version ()
245 CODE: 260 CODE:
246 RETVAL = (char *)glGetString (GL_VERSION); 261 RETVAL = (char *)glGetString (GL_VERSION);
580 { 595 {
581 Append (maptex, self->tex, self->texs, self->texs); 596 Append (maptex, self->tex, self->texs, self->texs);
582 self->texs *= 2; 597 self->texs *= 2;
583 } 598 }
584 599
600 {
585 maptex *tex = self->tex + texid; 601 maptex *tex = self->tex + texid;
586 602
587 tex->name = name; 603 tex->name = name;
588 tex->w = w; 604 tex->w = w;
589 tex->h = h; 605 tex->h = h;
590 tex->s = s; 606 tex->s = s;
591 tex->t = t; 607 tex->t = t;
592 tex->r = r; 608 tex->r = r;
593 tex->g = g; 609 tex->g = g;
594 tex->b = b; 610 tex->b = b;
595 tex->a = a; 611 tex->a = a;
612 }
596} 613}
597 614
598int 615int
599ox (CFClient::Map self) 616ox (CFClient::Map self)
600 ALIAS: 617 ALIAS:
638map1a_update (CFClient::Map self, SV *data_) 655map1a_update (CFClient::Map self, SV *data_)
639 CODE: 656 CODE:
640{ 657{
641 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 658 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
642 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;
643 662
644 while (data < data_end) 663 while (data < data_end)
645 { 664 {
646 int flags = (data [0] << 8) + data [1]; data += 2; 665 flags = (data [0] << 8) + data [1]; data += 2;
647 666
648 int x = ((flags >> 10) & 63) + self->x; 667 x = ((flags >> 10) & 63) + self->x;
649 int y = ((flags >> 4) & 63) + self->y; 668 y = ((flags >> 4) & 63) + self->y;
650 669
651 mapcell *cell = map_get_cell (self, x, y); 670 cell = map_get_cell (self, x, y);
652 671
653 if (flags & 15) 672 if (flags & 15)
654 { 673 {
655 if (cell->darkness < 0) 674 if (cell->darkness < 0)
656 { 675 {
746 765
747void 766void
748draw (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)
749 PPCODE: 768 PPCODE:
750{ 769{
770 int vx, vy;
771 int x, y, z;
772 int last_name;
773 mapface face;
751 int sw4 = (sw + 3) & ~3; 774 int sw4 = (sw + 3) & ~3;
752 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 775 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
753 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 776 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
777
754 memset (darkness, 255, sw4 * sh); 778 memset (darkness, 255, sw4 * sh);
755 SvPOK_only (darkness_sv); 779 SvPOK_only (darkness_sv);
756 SvCUR_set (darkness_sv, sw4 * sh); 780 SvCUR_set (darkness_sv, sw4 * sh);
757 781
758 int vx = self->x + (self->w - sw) / 2 - shift_x; 782 vx = self->x + (self->w - sw) / 2 - shift_x;
759 int vy = self->y + (self->h - sh) / 2 - shift_y; 783 vy = self->y + (self->h - sh) / 2 - shift_y;
760 784
761 /* 785 /*
762 int vx = self->vx = self->w >= sw 786 int vx = self->vx = self->w >= sw
763 ? self->x + (self->w - sw) / 2 787 ? self->x + (self->w - sw) / 2
764 : 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));
773 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 797 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774 glEnable (GL_BLEND); 798 glEnable (GL_BLEND);
775 glEnable (GL_TEXTURE_2D); 799 glEnable (GL_TEXTURE_2D);
776 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 800 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
777 801
778 int x, y, z;
779
780 int last_name = 0;
781
782 glBegin (GL_QUADS); 802 glBegin (GL_QUADS);
803
804 last_name = 0;
783 805
784 for (z = 0; z < 3; z++) 806 for (z = 0; z < 3; z++)
785 for (y = 0; y < sh; y++) 807 for (y = 0; y < sh; y++)
786 if (0 <= y + vy && y + vy < self->rows) 808 if (0 <= y + vy && y + vy < self->rows)
787 { 809 {
794 816
795 darkness[y * sw4 + x] = cell->darkness < 0 817 darkness[y * sw4 + x] = cell->darkness < 0
796 ? 255 - FOW_DARKNESS 818 ? 255 - FOW_DARKNESS
797 : 255 - cell->darkness; 819 : 255 - cell->darkness;
798 820
799 mapface face = cell->face [z]; 821 face = cell->face [z];
800 822
801 if (face) 823 if (face)
802 { 824 {
803 maptex tex = self->tex [face]; 825 maptex tex = self->tex [face];
804 826
864 for (x = x0; x < x1; x++) 886 for (x = x0; x < x1; x++)
865 { 887 {
866 if (row && row->c0 <= x && x < row->c1) 888 if (row && row->c0 <= x && x < row->c1)
867 { 889 {
868 mapcell *cell = row->col + (x - row->c0); 890 mapcell *cell = row->col + (x - row->c0);
869
870 uint8_t flags = 0; 891 uint8_t flags = 0;
871 892
872 if (cell->face [0]) flags |= 1; 893 if (cell->face [0]) flags |= 1;
873 if (cell->face [1]) flags |= 2; 894 if (cell->face [1]) flags |= 2;
874 if (cell->face [2]) flags |= 4; 895 if (cell->face [2]) flags |= 4;
908void 929void
909set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 930set_rect (CFClient::Map self, int x0, int y0, uint8_t *data)
910 PPCODE: 931 PPCODE:
911{ 932{
912 int x, y, z; 933 int x, y, z;
934 int w, h;
913 int x1, y1; 935 int x1, y1;
914 936
915 if (*data++ != 0) 937 if (*data++ != 0)
916 return; /* version mismatch */ 938 return; /* version mismatch */
917 939
918 int w = *data++ << 8; w |= *data++; 940 w = *data++ << 8; w |= *data++;
919 int h = *data++ << 8; h |= *data++; 941 h = *data++ << 8; h |= *data++;
920 942
921 // 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
922 // TODO: treat rows as we treat 944 // TODO: treat rows as we treat
923 map_get_row (self, y0 + self->y - self->oy);//D 945 map_get_row (self, y0 + self->y - self->oy);//D
924 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