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.221 by root, Fri Aug 10 04:02:13 2007 UTC vs.
Revision 1.224 by root, Sat Aug 11 11:21:46 2007 UTC

17#include "perl.h" 17#include "perl.h"
18#include "XSUB.h" 18#include "XSUB.h"
19 19
20#ifdef _WIN32 20#ifdef _WIN32
21# undef pipe 21# undef pipe
22// microsoft vs. C
23# define sqrtf(x) sqrt(x)
24# define roundf(x) (int)(x)
25# define atan2f(x,y) atan2(x,y)
26# define M_PI 3.14159265f
22#endif 27#endif
23 28
24#include <assert.h> 29#include <assert.h>
25#include <math.h> 30#include <math.h>
26#include <string.h> 31#include <string.h>
109 av_push (texture_av, (SV *)(size_t)name); 114 av_push (texture_av, (SV *)(size_t)name);
110 glDeleteTextures (1, &name); 115 glDeleteTextures (1, &name);
111} 116}
112 117
113#include "texcache.c" 118#include "texcache.c"
119#include "rendercache.c"
114 120
115#include "pango-font.c" 121#include "pango-font.c"
116#include "pango-fontmap.c" 122#include "pango-fontmap.c"
117#include "pango-render.c" 123#include "pango-render.c"
118 124
1708 1714
1709void 1715void
1710draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) 1716draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T)
1711 CODE: 1717 CODE:
1712{ 1718{
1719 int x, y, z;
1720
1713 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1721 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1714 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1722 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1715 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1723 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k)
1716 smooth_key skey; 1724 smooth_key skey;
1717 int x, y, z; 1725
1718 int last_name; 1726 rc_t *rc = rc_alloc ();
1727 rc_key_t key;
1728 rc_array_t *arr;
1719 1729
1720 // thats current max. sorry. 1730 // thats current max. sorry.
1721 if (sw > 255) sw = 255; 1731 if (sw > 255) sw = 255;
1722 if (sh > 255) sh = 255; 1732 if (sh > 255) sh = 255;
1723 1733
1724 // clear key, in case of extra padding 1734 // clear key, in case of extra padding
1725 memset (&skey, 0, sizeof (skey)); 1735 memset (&skey, 0, sizeof (skey));
1726 1736
1727 glColor4ub (255, 255, 255, 255); 1737 memset (&key, 0, sizeof (key));
1728 1738 key.r = 255;
1729 glEnable (GL_BLEND); 1739 key.g = 255;
1730 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1740 key.b = 255;
1731 glEnable (GL_TEXTURE_2D); 1741 key.a = 255;
1732 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 1742 key.mode = GL_QUADS;
1733 1743 key.format = GL_T2F_V3F;
1734 glBegin (GL_QUADS);
1735
1736 last_name = -1; 1744 key.texname = -1;
1737 1745
1738 mx += self->x; 1746 mx += self->x;
1739 my += self->y; 1747 my += self->y;
1740 1748
1741 // first pass: determine smooth_max 1749 // first pass: determine smooth_max
1757 MAX (self->tex [cell->tile [0]].smoothlevel, 1765 MAX (self->tex [cell->tile [0]].smoothlevel,
1758 MAX (self->tex [cell->tile [1]].smoothlevel, 1766 MAX (self->tex [cell->tile [1]].smoothlevel,
1759 self->tex [cell->tile [2]].smoothlevel)); 1767 self->tex [cell->tile [2]].smoothlevel));
1760 } 1768 }
1761 } 1769 }
1770
1771 glEnable (GL_BLEND);
1772 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1773 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1762 1774
1763 for (z = 0; z <= 2; z++) 1775 for (z = 0; z <= 2; z++)
1764 { 1776 {
1765 memset (smooth_level, 0, sizeof (smooth_level)); 1777 memset (smooth_level, 0, sizeof (smooth_level));
1766 1778
1780 maptex tex = self->tex [tile]; 1792 maptex tex = self->tex [tile];
1781 int px, py; 1793 int px, py;
1782 1794
1783 // suppressing texture state switches here 1795 // suppressing texture state switches here
1784 // is only moderately effective, but worth the extra effort 1796 // is only moderately effective, but worth the extra effort
1785 if (last_name != tex.name) 1797 if (key.texname != tex.name)
1786 { 1798 {
1787 if (!tex.name) 1799 if (!tex.name)
1788 tex = self->tex [2]; /* missing, replace by noface */ 1800 tex = self->tex [2]; /* missing, replace by noface */
1789 1801
1790 glEnd (); 1802 key.texname = tex.name;
1791 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1803 arr = rc_array (rc, &key);
1792 glBegin (GL_QUADS);
1793 } 1804 }
1794 1805
1795 px = (x + 1) * T - tex.w; 1806 px = (x + 1) * T - tex.w;
1796 py = (y + 1) * T - tex.h; 1807 py = (y + 1) * T - tex.h;
1797 1808
1798 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1809 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1799 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1810 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0);
1800 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1811 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0);
1801 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1812 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0);
1802 1813
1803 if (cell->flags && z == 2) 1814 if (cell->flags && z == 2)
1804 { 1815 {
1816 // overlays such as the speech bubble, probably more to come
1805 if (cell->flags & 1) 1817 if (cell->flags & 1)
1806 { 1818 {
1807 maptex tex = self->tex [1]; 1819 maptex tex = self->tex [1];
1808 int px = x * T + T * 2 / 32; 1820 int px = x * T + T * 2 / 32;
1809 int py = y * T - T * 6 / 32; 1821 int py = y * T - T * 6 / 32;
1810 1822
1823 if (tex.name)
1811 glEnd (); 1824 {
1812 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1825 if (key.texname != tex.name)
1826 {
1827 key.texname = tex.name;
1828 arr = rc_array (rc, &key);
1829 }
1830
1831 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
1832 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
1833 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
1834 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
1813 glBegin (GL_QUADS); 1835 }
1814
1815 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1816 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1817 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1818 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1819 } 1836 }
1820 } 1837 }
1821 1838
1822 // update smooth hash 1839 // update smooth hash
1823 if (tex.smoothtile) 1840 if (tex.smoothtile)
1858 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 1875 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800);
1859 } 1876 }
1860 } 1877 }
1861 } 1878 }
1862 } 1879 }
1880
1881 rc_draw (rc);
1882 rc_clear (rc);
1863 1883
1864 // go through all smoothlevels, lowest to highest, then draw. 1884 // go through all smoothlevels, lowest to highest, then draw.
1865 // this is basically counting sort 1885 // this is basically counting sort
1866 { 1886 {
1867 int w, b; 1887 int w, b;
1892 int border = bits & 15; 1912 int border = bits & 15;
1893 int corner = (bits >> 8) & ~(bits >> 4) & 15; 1913 int corner = (bits >> 8) & ~(bits >> 4) & 15;
1894 float dx = tex.s * .0625f; // 16 images/row 1914 float dx = tex.s * .0625f; // 16 images/row
1895 float dy = tex.t * .5f ; // 2 images/column 1915 float dy = tex.t * .5f ; // 2 images/column
1896 1916
1897 // this time naively avoiding texture state changes
1898 // save gobs of state changes.
1899 if (last_name != tex.name) 1917 if (tex.name)
1900 { 1918 {
1919 // this time avoiding texture state changes
1920 // save gobs of state changes.
1901 if (!tex.name) 1921 if (key.texname != tex.name)
1902 continue; // smoothing not yet available
1903
1904 glEnd (); 1922 {
1905 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1923 key.texname = tex.name;
1906 glBegin (GL_QUADS); 1924 arr = rc_array (rc, &key);
1907 } 1925 }
1908 1926
1909 if (border) 1927 if (border)
1910 { 1928 {
1911 float ox = border * dx; 1929 float ox = border * dx;
1912 1930
1913 glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); 1931 rc_t2f_v3f (arr, ox , 0.f , px , py , 0);
1914 glTexCoord2f (ox , dy ); glVertex2f (px , py + T); 1932 rc_t2f_v3f (arr, ox , dy , px , py + T, 0);
1915 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); 1933 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0);
1916 glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); 1934 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0);
1917 } 1935 }
1918 1936
1919 if (corner) 1937 if (corner)
1920 { 1938 {
1921 float ox = corner * dx; 1939 float ox = corner * dx;
1922 1940
1923 glTexCoord2f (ox , dy ); glVertex2f (px , py ); 1941 rc_t2f_v3f (arr, ox , dy , px , py , 0);
1924 glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); 1942 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0);
1925 glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); 1943 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0);
1926 glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); 1944 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0);
1945 }
1927 } 1946 }
1928 } 1947 }
1929 } 1948 }
1930 } 1949 }
1931 } 1950 }
1932 } 1951 }
1933 1952
1934 hv_clear (smooth); 1953 hv_clear (smooth);
1954 rc_draw (rc);
1955 rc_clear (rc);
1935 } 1956 }
1936 1957
1937 glEnd ();
1938
1939 glDisable (GL_TEXTURE_2D);
1940 glDisable (GL_BLEND); 1958 glDisable (GL_BLEND);
1959 rc_free (rc);
1941 1960
1942 // top layer: overlays such as the health bar 1961 // top layer: overlays such as the health bar
1943 for (y = 0; y < sh; y++) 1962 for (y = 0; y < sh; y++)
1944 if (0 <= y + my && y + my < self->rows) 1963 if (0 <= y + my && y + my < self->rows)
1945 { 1964 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines