1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*
* sprite_update.c: sprite̾ﹹ
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: sprite_update.c,v 1.1 2003/04/22 16:29:52 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include <glib.h>
#include "portab.h"
#include "system.h"
#include "counter.h"
#include "ags.h"
#include "graphics.h"
#include "sact.h"
#include "surface.h"
#include "ngraph.h"
#include "sprite.h"
// ץ饤Ⱥ֤δ֤ѹΤäץ饤Ȥΰ
static GSList *updatearea;
static void intersection(MyRectangle *r1, MyRectangle *r2, MyRectangle *rst);
static void disjunction(gpointer region, gpointer data);
static void get_updatearea();
static void do_update_each(gpointer data, gpointer userdata);
// ΰ裱ΰ裲Ѥ
static void intersection(MyRectangle *r1, MyRectangle *r2, MyRectangle *rst) {
int x1 = max(r1->x, r2->x);
int x2 = min(r1->x + r1->width, r2->x + r2->width);
int y1 = max(r1->y, r2->y);
int y2 = min(r1->y + r1->height, r2->y + r2->height);
rst->x = x1;
rst->y = y1;
rst->width = x2 - x1;
rst->height = y2 - y1;
}
// ΰ裱ΰ裲٤ƴޤΰ
static void disjunction(gpointer region, gpointer data) {
MyRectangle *r1 = (MyRectangle *)region;
MyRectangle *r2 = (MyRectangle *)data;
int x1, x2, y1, y2;
//WARNING("r1x=%d,r1y=%d,r1w=%d,r1h=%d\n", r1->x, r1->y, r1->width, r1->height);
//WARNING("r2x=%d,r2y=%d,r2w=%d,r2h=%d\n", r2->x, r2->y, r2->width, r2->height);
if (r2->width == 0) {
r2->x = r1->x;
r2->y = r1->y;
r2->width = r1->width;
r2->height = r1->height;
return;
}
x1 = min(r1->x, r2->x);
x2 = max(r1->x + r1->width, r2->x + r2->width);
y1 = min(r1->y, r2->y);
y2 = max(r1->y + r1->height, r2->y + r2->height);
r2->x = x1;
r2->y = y1;
r2->width = x2 - x1;
r2->height = y2 - y1;
//WARNING("res:r2x=%d,r2y=%d,r2w=%d,r2h=%d\n", r2->x, r2->y, r2->width, r2->height);
}
// ɬפʥץ饤Ȥΰ¤Ȥäƥåԥ
static void get_updatearea() {
MyRectangle clip = {0, 0, 0, 0};
MyRectangle rsf0 = {0, 0, sf0->width, sf0->height};
g_slist_foreach(updatearea, disjunction, &clip);
g_slist_free(updatearea);
updatearea = NULL;
// surface0ȤΰѤȤ
intersection(&rsf0, &clip, &sact.updaterect);
WARNING("clipped area x=%d y=%d w=%d h=%d\n",
sact.updaterect.x, sact.updaterect.y,
sact.updaterect.width, sact.updaterect.height);
return;
}
// updatelist ϿƤ뤹٤ƤΥץ饤Ȥ
static void do_update_each(gpointer data, gpointer userdata) {
sprite_t *sp = (sprite_t *)data;
// ɽξϤʤˤ⤷ʤ
if (!sp->show) return;
if (sp == sact.draggedsp) return; // dragΥץ饤ȤϺǸɽ
// ץ饤update롼θƤӽФ
if (sp->update) {
sp->update(sp);
}
}
/*
Τι
@param syncscreen: surface0 褷Τ Screen ȿǤ뤫ɤ
*/
int sp_update_all(boolean syncscreen) {
// ץ饤Ȱưϰư
if (sact.movelist) {
// ưϻ֤碌
sact.movestarttime = get_high_counter(SYSTEMCOUNTER_MSEC);
g_slist_foreach(sact.movelist, spev_move_setup, NULL);
g_slist_free(sact.movelist);
sact.movelist = NULL;
}
// Τΰ
sact.updaterect.x = 0;
sact.updaterect.y = 0;
sact.updaterect.width = sf0->width;
sact.updaterect.height = sf0->height;
// updatelistϿƤ륹ץ饤Ȥ
// updatelistϥץ饤Ȥֹ¤Ǥ
g_slist_foreach(sact.updatelist, do_update_each, NULL);
// Υ롼ƤФȤϥץ饤ȤϥɥåǤϤʤ
// screenƱɬפʤȤϲΤWindowž
if (syncscreen) {
ags_updateFull();
}
// ưΤ٤ƤΥץ饤ȤưλޤԤ
// ʤưƱʤ
spev_wait4moving_sp();
return OK;
}
/*
̤ΰ
updateme(_part)Ͽɬפsprite¤ΰupdate
*/
int sp_update_clipped() {
// ΰγ
get_updatearea();
// ޤϹ⤵ 0 λϤʤˤ⤷ʤ
if (sact.updaterect.width == 0 || sact.updaterect.height == 0) {
return OK;
}
// ΰäƤ륹ץ饤Ȥκ
g_slist_foreach(sact.updatelist, do_update_each, NULL);
// dragΥץ饤ȤǸ
if (sact.draggedsp) {
sact.draggedsp->update(sact.draggedsp);
}
// ΰ Window ž
ags_updateArea(sact.updaterect.x, sact.updaterect.y, sact.updaterect.width, sact.updaterect.height);
return OK;
}
/*
spriteΤιϿ
@param sp: 륹ץ饤
*/
int sp_updateme(sprite_t *sp) {
MyRectangle *r;
if (sp == NULL) return NG;
if (sp->cursize.width == 0 || sp->cursize.height == 0) return NG;
r = g_new(MyRectangle, 1);
r->x = sp->cur.x;
r->y = sp->cur.y;
r->width = sp->cursize.width;
r->height = sp->cursize.height;
updatearea = g_slist_append(updatearea, r);
WARNING("x = %d, y = %d, spno = %d w=%d,h=%d\n",
r->x, r->y, sp->no, r->width, r->height);
return OK;
}
/*
spriteΰϿ
@param sp: 륹ץ饤
@param x: ΰغɸ
@param y: ΰٺɸ
@param w: ΰ
@param h: ΰ⤵
*/
int sp_updateme_part(sprite_t *sp, int x, int y, int w, int h) {
MyRectangle *r;
if (sp == NULL) return NG;
if (w == 0 || h == 0) return NG;
r = g_new(MyRectangle, 1);
r->x = sp->cur.x + x;
r->y = sp->cur.y + y;
r->width = w;
r->height = h;
updatearea = g_slist_append(updatearea, r);
WARNING("x = %d, y = %d, spno = %d w=%d,h=%d\n",
r->x, r->y, sp->no, r->width, r->height);
return OK;
}
|