1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
5 This file is part of the Doom2D:Rembo project.
7 Doom2D:Rembo is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 Doom2D:Rembo is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/> or
18 write to the Free Software Foundation, Inc.,
19 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 //#include "..\averr.h"
28 /*
29 #define MAXRECT 500
31 typedef struct{short x,w,y,h;}rect;
33 static rect *rt,*rp;
34 static redraw_f *fn;
35 static short sl,st,sr,sb;
38 void *RD_init(short x,short w,short y,short h) {
39 rect *p;
41 if(!(p=malloc((MAXRECT*2+1)*sizeof(rect))))
42 {error(0,0,ENOMEM,NULL,NULL);return NULL;}//{error(EZ_VGALIB,ET_STD,ENOMEM,NULL,NULL);return NULL;}
43 p->x=x;p->w=x+w-1;p->y=y;p->h=y+h-1;
44 memset(p+1,0,MAXRECT*2*sizeof(rect));
45 return p;
46 }
48 void RD_start(void *p,redraw_f *f) {
49 rt=p;fn=f;
50 sl=rt->x;sr=rt->w;
51 st=rt->y;sb=rt->h;
52 ++rt;
53 rp=rt;
54 }
56 static void add(short x,short r,short y,short b) {
57 int i;
58 short rx,rr,ry,rb;
60 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
61 if(x>(rr=(rx=rp[i].x)+rp[i].w-1)) continue;
62 if(r<rx) continue;
63 if(y>(rb=(ry=rp[i].y)+rp[i].h-1)) continue;
64 if(b<ry) continue;
65 if(x<rx) add(x,rx-1,y,b);
66 if(r>rr) add(rr+1,r,y,b);
67 if(y<ry) add(max(rx,x),min(rr,r),y,ry-1);
68 if(b>rb) add(max(rx,x),min(rr,r),rb+1,b);
69 return;
70 }
71 for(i=0;i<MAXRECT;++i) if(!rp[i].w) {
72 rp[i].x=x;rp[i].y=y;rp[i].w=r-x+1;rp[i].h=b-y+1;
73 return;
74 }
75 }
77 void RD_rect(short x,short w,short y,short h) {
78 if(x>sr) return;
79 if(x+w<=sl) return;
80 if(y>sb) return;
81 if(y+h<=st) return;
82 w+=x-1;h+=y-1;
83 if(x<sl) x=sl;
84 if(y<st) y=st;
85 if(w>sr) w=sr;
86 if(h>sb) h=sb;
87 add(x,w,y,h);
88 }
90 void RD_spr(short x,short y,vgaimg *v) {
91 RD_rect(x-v->sx,v->w,y-v->sy,v->h);
92 }
94 void RD_spr2(short x,short y,vgaimg *v) {
95 RD_rect(x-v->w+v->sx,v->w,y-v->sy,v->h);
96 }
98 void RD_end(void) {
99 int i;
101 V_setscr(scrbuf);
102 rp=rt+MAXRECT;
103 for(i=0;i<MAXRECT;++i) if(rt[i].w) {
104 add(rt[i].x,rt[i].x+rt[i].w-1,rt[i].y,rt[i].y+rt[i].h-1);
105 }
106 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
107 scrx=rp[i].x;scrw=rp[i].w;scry=rp[i].y;scrh=rp[i].h;
108 fn();
109 }
110 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
111 V_copytoscr(rp[i].x,rp[i].w,rp[i].y,rp[i].h);
112 }
113 memcpy(rp,rt,MAXRECT*sizeof(rect));
114 memset(rt,0,MAXRECT*sizeof(rect));
115 }
116 */