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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines