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.49 by root, Tue Apr 18 01:36:12 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);
292 croak ("load_image: %s", SDL_GetError ()); 307 croak ("load_image: %s", SDL_GetError ());
293 308
294 fmt.palette = NULL; 309 fmt.palette = NULL;
295 fmt.BitsPerPixel = 32; 310 fmt.BitsPerPixel = 32;
296 fmt.BytesPerPixel = 4; 311 fmt.BytesPerPixel = 4;
312#if SDL_BYTEORDER == SDL_LIL_ENDIAN
297 fmt.Rmask = 0x000000ff; 313 fmt.Rmask = 0x000000ff;
298 fmt.Gmask = 0x0000ff00; 314 fmt.Gmask = 0x0000ff00;
299 fmt.Bmask = 0x00ff0000; 315 fmt.Bmask = 0x00ff0000;
300 fmt.Amask = 0xff000000; 316 fmt.Amask = 0xff000000;
317#else
318 fmt.Rmask = 0xff000000;
319 fmt.Gmask = 0x00ff0000;
320 fmt.Bmask = 0x0000ff00;
321 fmt.Amask = 0x000000ff;
322#endif
301 fmt.Rloss = 0; 323 fmt.Rloss = 0;
302 fmt.Gloss = 0; 324 fmt.Gloss = 0;
303 fmt.Bloss = 0; 325 fmt.Bloss = 0;
304 fmt.Aloss = 0; 326 fmt.Aloss = 0;
305 fmt.Rshift = 0; 327 fmt.Rshift = 0;
319 SDL_LockSurface (surface2); 341 SDL_LockSurface (surface2);
320 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); 342 PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch)));
321 SDL_UnlockSurface (surface2); 343 SDL_UnlockSurface (surface2);
322 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); 344 PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB)));
323 PUSHs (sv_2mortal (newSViv (GL_RGBA))); 345 PUSHs (sv_2mortal (newSViv (GL_RGBA)));
324 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); 346 PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE)));
325 347
326 SDL_FreeSurface (surface); 348 SDL_FreeSurface (surface);
327 SDL_FreeSurface (surface2); 349 SDL_FreeSurface (surface2);
328} 350}
329 351
580 { 602 {
581 Append (maptex, self->tex, self->texs, self->texs); 603 Append (maptex, self->tex, self->texs, self->texs);
582 self->texs *= 2; 604 self->texs *= 2;
583 } 605 }
584 606
607 {
585 maptex *tex = self->tex + texid; 608 maptex *tex = self->tex + texid;
586 609
587 tex->name = name; 610 tex->name = name;
588 tex->w = w; 611 tex->w = w;
589 tex->h = h; 612 tex->h = h;
590 tex->s = s; 613 tex->s = s;
591 tex->t = t; 614 tex->t = t;
592 tex->r = r; 615 tex->r = r;
593 tex->g = g; 616 tex->g = g;
594 tex->b = b; 617 tex->b = b;
595 tex->a = a; 618 tex->a = a;
619 }
596} 620}
597 621
598int 622int
599ox (CFClient::Map self) 623ox (CFClient::Map self)
600 ALIAS: 624 ALIAS:
638map1a_update (CFClient::Map self, SV *data_) 662map1a_update (CFClient::Map self, SV *data_)
639 CODE: 663 CODE:
640{ 664{
641 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 665 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
642 uint8_t *data_end = (uint8_t *)SvEND (data_); 666 uint8_t *data_end = (uint8_t *)SvEND (data_);
667 mapcell *cell;
668 int x, y, flags;
643 669
644 while (data < data_end) 670 while (data < data_end)
645 { 671 {
646 int flags = (data [0] << 8) + data [1]; data += 2; 672 flags = (data [0] << 8) + data [1]; data += 2;
647 673
648 int x = ((flags >> 10) & 63) + self->x; 674 x = ((flags >> 10) & 63) + self->x;
649 int y = ((flags >> 4) & 63) + self->y; 675 y = ((flags >> 4) & 63) + self->y;
650 676
651 mapcell *cell = map_get_cell (self, x, y); 677 cell = map_get_cell (self, x, y);
652 678
653 if (flags & 15) 679 if (flags & 15)
654 { 680 {
655 if (cell->darkness < 0) 681 if (cell->darkness < 0)
656 { 682 {
746 772
747void 773void
748draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) 774draw (CFClient::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh)
749 PPCODE: 775 PPCODE:
750{ 776{
777 int vx, vy;
778 int x, y, z;
779 int last_name;
780 mapface face;
751 int sw4 = (sw + 3) & ~3; 781 int sw4 = (sw + 3) & ~3;
752 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 782 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh));
753 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 783 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv);
784
754 memset (darkness, 255, sw4 * sh); 785 memset (darkness, 255, sw4 * sh);
755 SvPOK_only (darkness_sv); 786 SvPOK_only (darkness_sv);
756 SvCUR_set (darkness_sv, sw4 * sh); 787 SvCUR_set (darkness_sv, sw4 * sh);
757 788
758 int vx = self->x + (self->w - sw) / 2 - shift_x; 789 vx = self->x + (self->w - sw) / 2 - shift_x;
759 int vy = self->y + (self->h - sh) / 2 - shift_y; 790 vy = self->y + (self->h - sh) / 2 - shift_y;
760 791
761 /* 792 /*
762 int vx = self->vx = self->w >= sw 793 int vx = self->vx = self->w >= sw
763 ? self->x + (self->w - sw) / 2 794 ? self->x + (self->w - sw) / 2
764 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); 795 : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx));
773 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 804 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774 glEnable (GL_BLEND); 805 glEnable (GL_BLEND);
775 glEnable (GL_TEXTURE_2D); 806 glEnable (GL_TEXTURE_2D);
776 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 807 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
777 808
778 int x, y, z;
779
780 int last_name = 0;
781
782 glBegin (GL_QUADS); 809 glBegin (GL_QUADS);
810
811 last_name = 0;
783 812
784 for (z = 0; z < 3; z++) 813 for (z = 0; z < 3; z++)
785 for (y = 0; y < sh; y++) 814 for (y = 0; y < sh; y++)
786 if (0 <= y + vy && y + vy < self->rows) 815 if (0 <= y + vy && y + vy < self->rows)
787 { 816 {
794 823
795 darkness[y * sw4 + x] = cell->darkness < 0 824 darkness[y * sw4 + x] = cell->darkness < 0
796 ? 255 - FOW_DARKNESS 825 ? 255 - FOW_DARKNESS
797 : 255 - cell->darkness; 826 : 255 - cell->darkness;
798 827
799 mapface face = cell->face [z]; 828 face = cell->face [z];
800 829
801 if (face) 830 if (face)
802 { 831 {
803 maptex tex = self->tex [face]; 832 maptex tex = self->tex [face];
804 833
864 for (x = x0; x < x1; x++) 893 for (x = x0; x < x1; x++)
865 { 894 {
866 if (row && row->c0 <= x && x < row->c1) 895 if (row && row->c0 <= x && x < row->c1)
867 { 896 {
868 mapcell *cell = row->col + (x - row->c0); 897 mapcell *cell = row->col + (x - row->c0);
869
870 uint8_t flags = 0; 898 uint8_t flags = 0;
871 899
872 if (cell->face [0]) flags |= 1; 900 if (cell->face [0]) flags |= 1;
873 if (cell->face [1]) flags |= 2; 901 if (cell->face [1]) flags |= 2;
874 if (cell->face [2]) flags |= 4; 902 if (cell->face [2]) flags |= 4;
908void 936void
909set_rect (CFClient::Map self, int x0, int y0, uint8_t *data) 937set_rect (CFClient::Map self, int x0, int y0, uint8_t *data)
910 PPCODE: 938 PPCODE:
911{ 939{
912 int x, y, z; 940 int x, y, z;
941 int w, h;
913 int x1, y1; 942 int x1, y1;
914 943
915 if (*data++ != 0) 944 if (*data++ != 0)
916 return; /* version mismatch */ 945 return; /* version mismatch */
917 946
918 int w = *data++ << 8; w |= *data++; 947 w = *data++ << 8; w |= *data++;
919 int h = *data++ << 8; h |= *data++; 948 h = *data++ << 8; h |= *data++;
920 949
921 // we need to do this 'cause we don't keep an absolute coord system for rows 950 // we need to do this 'cause we don't keep an absolute coord system for rows
922 // TODO: treat rows as we treat 951 // TODO: treat rows as we treat
923 map_get_row (self, y0 + self->y - self->oy);//D 952 map_get_row (self, y0 + self->y - self->oy);//D
924 map_get_row (self, y0 + self->y - self->oy + h - 1);//D 953 map_get_row (self, y0 + self->y - self->oy + h - 1);//D

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines