DEADSOFTWARE

032aa613e897e21c377eb20385896986825bfc16
[flatwaifu.git] / src / redraw.c
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 /*
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <string.h>
26 //#include "..\averr.h"
27 #include "vga.h"
28 #include "glob.h"
30 #define MAXRECT 500
32 typedef struct{short x,w,y,h;}rect;
34 static rect *rt,*rp;
35 static redraw_f *fn;
36 static short sl,st,sr,sb;
39 void *RD_init(short x,short w,short y,short h) {
40 rect *p;
42 if(!(p=malloc((MAXRECT*2+1)*sizeof(rect))))
43 {error(0,0,ENOMEM,NULL,NULL);return NULL;}//{error(EZ_VGALIB,ET_STD,ENOMEM,NULL,NULL);return NULL;}
44 p->x=x;p->w=x+w-1;p->y=y;p->h=y+h-1;
45 memset(p+1,0,MAXRECT*2*sizeof(rect));
46 return p;
47 }
49 void RD_start(void *p,redraw_f *f) {
50 rt=p;fn=f;
51 sl=rt->x;sr=rt->w;
52 st=rt->y;sb=rt->h;
53 ++rt;
54 rp=rt;
55 }
57 static void add(short x,short r,short y,short b) {
58 int i;
59 short rx,rr,ry,rb;
61 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
62 if(x>(rr=(rx=rp[i].x)+rp[i].w-1)) continue;
63 if(r<rx) continue;
64 if(y>(rb=(ry=rp[i].y)+rp[i].h-1)) continue;
65 if(b<ry) continue;
66 if(x<rx) add(x,rx-1,y,b);
67 if(r>rr) add(rr+1,r,y,b);
68 if(y<ry) add(max(rx,x),min(rr,r),y,ry-1);
69 if(b>rb) add(max(rx,x),min(rr,r),rb+1,b);
70 return;
71 }
72 for(i=0;i<MAXRECT;++i) if(!rp[i].w) {
73 rp[i].x=x;rp[i].y=y;rp[i].w=r-x+1;rp[i].h=b-y+1;
74 return;
75 }
76 }
78 void RD_rect(short x,short w,short y,short h) {
79 if(x>sr) return;
80 if(x+w<=sl) return;
81 if(y>sb) return;
82 if(y+h<=st) return;
83 w+=x-1;h+=y-1;
84 if(x<sl) x=sl;
85 if(y<st) y=st;
86 if(w>sr) w=sr;
87 if(h>sb) h=sb;
88 add(x,w,y,h);
89 }
91 void RD_spr(short x,short y,vgaimg *v) {
92 RD_rect(x-v->sx,v->w,y-v->sy,v->h);
93 }
95 void RD_spr2(short x,short y,vgaimg *v) {
96 RD_rect(x-v->w+v->sx,v->w,y-v->sy,v->h);
97 }
99 void RD_end(void) {
100 int i;
102 V_setscr(scrbuf);
103 rp=rt+MAXRECT;
104 for(i=0;i<MAXRECT;++i) if(rt[i].w) {
105 add(rt[i].x,rt[i].x+rt[i].w-1,rt[i].y,rt[i].y+rt[i].h-1);
107 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
108 scrx=rp[i].x;scrw=rp[i].w;scry=rp[i].y;scrh=rp[i].h;
109 fn();
111 for(i=0;i<MAXRECT;++i) if(rp[i].w) {
112 V_copytoscr(rp[i].x,rp[i].w,rp[i].y,rp[i].h);
114 memcpy(rp,rt,MAXRECT*sizeof(rect));
115 memset(rt,0,MAXRECT*sizeof(rect));
117 */