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.327 by root, Sun Nov 18 12:01:50 2018 UTC vs.
Revision 1.328 by root, Sun Nov 18 12:47:55 2018 UTC

287}; 287};
288 288
289struct mapgrid { 289struct mapgrid {
290 int x, y, w, h; 290 int x, y, w, h;
291 int ox, oy; /* offset to virtual global coordinate system */ 291 int ox, oy; /* offset to virtual global coordinate system */
292 std::vector<tileid> tile; 292 int faces; tileid *face2tile; // [faceid]
293 std::vector<maptex> tex; 293 int texs; maptex *tex; // [tileid]
294 294
295 int32_t rows; 295 int32_t rows;
296 maprow *row; 296 maprow *row;
297
298 ~mapgrid ()
299 {
300 clear_cells ();
301 }
302
303 void clear_cells ();
304}; 297};
305 298
306typedef mapgrid *DC__Map; 299typedef mapgrid *DC__Map;
307 300
308static char * 301static char *
327 return ptr; 320 return ptr;
328} 321}
329 322
330#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 323#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
331#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 324#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
325
326static void
327need_facenum (struct mapgrid *self, faceid face)
328{
329 while (self->faces <= face)
330 {
331 Append (tileid, self->face2tile, self->faces, self->faces);
332 self->faces *= 2;
333 }
334}
335
336static void
337need_texid (struct mapgrid *self, int texid)
338{
339 while (self->texs <= texid)
340 {
341 Append (maptex, self->tex, self->texs, self->texs);
342 self->texs *= 2;
343 }
344}
332 345
333static maprow * 346static maprow *
334map_get_row (mapgrid *self, int y) 347map_get_row (mapgrid *self, int y)
335{ 348{
336 if (0 > y) 349 if (0 > y)
382map_get_cell (mapgrid *self, int x, int y) 395map_get_cell (mapgrid *self, int x, int y)
383{ 396{
384 return row_get_cell (map_get_row (self, y), x); 397 return row_get_cell (map_get_row (self, y), x);
385} 398}
386 399
387void mapgrid::clear_cells () 400static void
401map_clear (mapgrid *self)
388{ 402{
389 int r; 403 int r;
390 404
391 for (r = 0; r < rows; r++) 405 for (r = 0; r < self->rows; r++)
392 Safefree (row[r].col); 406 Safefree (self->row[r].col);
393 407
394 Safefree (row); 408 Safefree (self->row);
395 409
396 x = 0; 410 self->x = 0;
397 y = 0; 411 self->y = 0;
398 ox = 0; 412 self->ox = 0;
399 oy = 0; 413 self->oy = 0;
400 row = 0; 414 self->row = 0;
401 rows = 0; 415 self->rows = 0;
402} 416}
403 417
404#define CELL_CLEAR(cell) \ 418#define CELL_CLEAR(cell) \
405 do { \ 419 do { \
406 if ((cell)->player) \ 420 if ((cell)->player) \
1886PROTOTYPES: DISABLE 1900PROTOTYPES: DISABLE
1887 1901
1888DC::Map 1902DC::Map
1889new (SV *klass) 1903new (SV *klass)
1890 CODE: 1904 CODE:
1891 RETVAL = new mapgrid; 1905 New (0, RETVAL, 1, mapgrid);
1892 RETVAL->x = 0; 1906 RETVAL->x = 0;
1893 RETVAL->y = 0; 1907 RETVAL->y = 0;
1894 RETVAL->w = 0; 1908 RETVAL->w = 0;
1895 RETVAL->h = 0; 1909 RETVAL->h = 0;
1896 RETVAL->ox = 0; 1910 RETVAL->ox = 0;
1897 RETVAL->oy = 0; 1911 RETVAL->oy = 0;
1912 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1913 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1898 RETVAL->rows = 0; 1914 RETVAL->rows = 0;
1899 RETVAL->row = 0; 1915 RETVAL->row = 0;
1900 OUTPUT: 1916 OUTPUT:
1901 RETVAL 1917 RETVAL
1902 1918
1903void 1919void
1904DESTROY (DC::Map self) 1920DESTROY (DC::Map self)
1905 CODE: 1921 CODE:
1906{ 1922{
1923 map_clear (self);
1924 Safefree (self->face2tile);
1925 Safefree (self->tex);
1907 delete self; 1926 Safefree (self);
1908} 1927}
1909 1928
1910void 1929void
1911resize (DC::Map self, int map_width, int map_height) 1930resize (DC::Map self, int map_width, int map_height)
1912 CODE: 1931 CODE:
1914 self->h = map_height; 1933 self->h = map_height;
1915 1934
1916void 1935void
1917clear (DC::Map self) 1936clear (DC::Map self)
1918 CODE: 1937 CODE:
1919 self->clear_cells (); 1938 map_clear (self);
1920 1939
1921void 1940void
1922set_tileid (DC::Map self, int face, int tile) 1941set_tileid (DC::Map self, int face, int tile)
1923 CODE: 1942 CODE:
1924{ 1943{
1925 if (self->tile.size () <= face) self->tile.resize (face + 1); 1944 need_facenum (self, face); self->face2tile [face] = tile;
1926 self->tile[face] = tile; 1945 need_texid (self, tile);
1927 if (self->tex.size () <= tile) self->tex .resize (tile + 1);
1928} 1946}
1929 1947
1930void 1948void
1931set_smooth (DC::Map self, int face, int smooth, int level) 1949set_smooth (DC::Map self, int face, int smooth, int level)
1932 CODE: 1950 CODE:
1933{ 1951{
1952 tileid texid;
1953 maptex *tex;
1954
1934 if (face < 0 || face >= self->tile.size ()) 1955 if (face < 0 || face >= self->faces)
1935 return; 1956 return;
1936 1957
1937 if (smooth < 0 || smooth >= self->tile.size ()) 1958 if (smooth < 0 || smooth >= self->faces)
1938 return; 1959 return;
1939 1960
1940 tileid texid = self->tile[face]; 1961 texid = self->face2tile [face];
1941 1962
1942 if (!texid) 1963 if (!texid)
1943 return; 1964 return;
1944 1965
1945 maptex &tex = self->tex[texid]; 1966 tex = self->tex + texid;
1946 tex.smoothtile = self->tile[smooth]; 1967 tex->smoothtile = self->face2tile [smooth];
1947 tex.smoothlevel = level; 1968 tex->smoothlevel = level;
1948} 1969}
1949 1970
1950void 1971void
1951set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1972set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1952 CODE: 1973 CODE:
1953{ 1974{
1954 if (self->tex.size () < texid) self->tex.resize (texid + 1); 1975 need_texid (self, texid);
1955 1976
1956 { 1977 {
1957 maptex &tex = self->tex[texid]; 1978 maptex *tex = self->tex + texid;
1958 1979
1959 tex.name = name; 1980 tex->name = name;
1960 tex.w = w; 1981 tex->w = w;
1961 tex.h = h; 1982 tex->h = h;
1962 tex.s = s; 1983 tex->s = s;
1963 tex.t = t; 1984 tex->t = t;
1964 tex.r = r; 1985 tex->r = r;
1965 tex.g = g; 1986 tex->g = g;
1966 tex.b = b; 1987 tex->b = b;
1967 tex.a = a; 1988 tex->a = a;
1968 } 1989 }
1969 1990
1970 // somewhat hackish, but for textures that require it, it really 1991 // somewhat hackish, but for textures that require it, it really
1971 // improves the look, and most others don't suffer. 1992 // improves the look, and most others don't suffer.
1972 glBindTexture (GL_TEXTURE_2D, name); 1993 glBindTexture (GL_TEXTURE_2D, name);
1978} 1999}
1979 2000
1980void 2001void
1981expire_textures (DC::Map self, int texid, int count) 2002expire_textures (DC::Map self, int texid, int count)
1982 PPCODE: 2003 PPCODE:
1983 for (; texid < self->tex.size () && count; ++texid, --count) 2004 for (; texid < self->texs && count; ++texid, --count)
1984 { 2005 {
1985 maptex &tex = self->tex[texid]; 2006 maptex *tex = self->tex + texid;
1986 2007
1987 if (tex.name) 2008 if (tex->name)
1988 { 2009 {
1989 if (tex.unused) 2010 if (tex->unused)
1990 { 2011 {
1991 tex.name = 0; 2012 tex->name = 0;
1992 tex.unused = 0; 2013 tex->unused = 0;
1993 XPUSHs (sv_2mortal (newSViv (texid))); 2014 XPUSHs (sv_2mortal (newSViv (texid)));
1994 } 2015 }
1995 else 2016 else
1996 tex.unused = 1; 2017 tex->unused = 1;
1997 } 2018 }
1998 } 2019 }
1999 2020
2000int 2021int
2001ox (DC::Map self) 2022ox (DC::Map self)
2112 } 2133 }
2113 2134
2114 for (z = 0; z <= 2; ++z) 2135 for (z = 0; z <= 2; ++z)
2115 if (flags & (4 >> z)) 2136 if (flags & (4 >> z))
2116 { 2137 {
2117 faceid face = (data[0] << 8) + data[1]; data += 2; 2138 faceid face = (data [0] << 8) + data [1]; data += 2;
2118 if (self->tile.size () <= face) self->tile.resize (face + 1); 2139 need_facenum (self, face);
2119 cell->tile[z] = self->tile[face]; 2140 cell->tile [z] = self->face2tile [face];
2120 2141
2121 if (cell->tile[z]) 2142 if (cell->tile [z])
2122 { 2143 {
2123 maptex &tex = self->tex[cell->tile[z]]; 2144 maptex *tex = self->tex + cell->tile [z];
2124 tex.unused = 0; 2145 tex->unused = 0;
2125 if (!tex.name) 2146 if (!tex->name)
2126 av_push (missing, newSViv (cell->tile [z])); 2147 av_push (missing, newSViv (cell->tile [z]));
2127 2148
2128 if (tex.smoothtile) 2149 if (tex->smoothtile)
2129 { 2150 {
2130 maptex &smooth = self->tex[tex.smoothtile]; 2151 maptex *smooth = self->tex + tex->smoothtile;
2131 smooth.unused = 0; 2152 smooth->unused = 0;
2132 if (!smooth.name) 2153 if (!smooth->name)
2133 av_push (missing, newSViv (tex.smoothtile)); 2154 av_push (missing, newSViv (tex->smoothtile));
2134 } 2155 }
2135 } 2156 }
2136 } 2157 }
2137 } 2158 }
2138 else 2159 else
2787 2808
2788 for (z = 0; z <= 2; z++) 2809 for (z = 0; z <= 2; z++)
2789 { 2810 {
2790 tileid t = tile [z]; 2811 tileid t = tile [z];
2791 2812
2792 if (t >= self->tex.size () || (t && !self->tex[t].name)) 2813 if (t >= self->texs || (t && !self->tex [t].name))
2793 { 2814 {
2794 PUSHs (sv_2mortal (newSViv (t))); 2815 PUSHs (sv_2mortal (newSViv (t)));
2795 if (self->tex.size () <= t) self->tex.resize (t + 1); 2816 need_texid (self, t);
2796 } 2817 }
2797 2818
2798 cell->tile[z] = t; 2819 cell->tile [z] = t;
2799 } 2820 }
2800 } 2821 }
2801 } 2822 }
2802 } 2823 }
2803 } 2824 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines