75 |
// DISPLAY ENGINE |
// DISPLAY ENGINE |
76 |
//====================================================================== |
//====================================================================== |
77 |
|
|
78 |
DisplayEngine::DisplayEngine (px::Screen *scr) |
DisplayEngine::DisplayEngine (px::Screen *scr, int tilew, int tileh) |
79 |
: m_tilew(32), m_tileh(32), m_screen (scr), |
: m_tilew(tilew), m_tileh(tileh), |
80 |
|
m_screen (scr), |
81 |
m_offset(), |
m_offset(), |
82 |
m_area (scr->size()), |
m_area (scr->size()), |
83 |
m_width(0), m_height(0), |
m_width(0), m_height(0), |
84 |
m_fields(0,0) |
m_redrawp(0,0) |
85 |
{ |
{ |
86 |
} |
} |
87 |
|
|
157 |
m_width = w; |
m_width = w; |
158 |
m_height = h; |
m_height = h; |
159 |
m_offset = V2(); |
m_offset = V2(); |
160 |
m_fields.resize(w, h); |
m_redrawp.resize(w, h, true); |
161 |
|
|
162 |
for (unsigned i=0; i<m_layers.size(); ++i) |
for (unsigned i=0; i<m_layers.size(); ++i) |
163 |
m_layers[i]->new_world(w,h); |
m_layers[i]->new_world(w,h); |
|
|
|
|
mark_update_world(); |
|
164 |
} |
} |
165 |
|
|
166 |
|
|
221 |
int y2 = Min(m_height, wa.y+wa.h); |
int y2 = Min(m_height, wa.y+wa.h); |
222 |
for (int x=Max(0,wa.x); x <x2; x++) |
for (int x=Max(0,wa.x); x <x2; x++) |
223 |
for (int y=Max(0,wa.y); y<y2; y++) |
for (int y=Max(0,wa.y); y<y2; y++) |
224 |
m_fields(x,y).redrawp = true; |
m_redrawp(x,y) = true; |
|
} |
|
|
|
|
|
void |
|
|
DisplayEngine::mark_update_area (const WorldArea &wa) |
|
|
{ |
|
|
int x2 = Min(m_width, wa.x+wa.w); |
|
|
int y2 = Min(m_height, wa.y+wa.h); |
|
|
for (int x=Max(0,wa.x); x <x2; x++) |
|
|
for (int y=Max(0,wa.y); y<y2; y++) |
|
|
m_fields(x,y).updatep = true; |
|
|
} |
|
|
|
|
|
void |
|
|
DisplayEngine::mark_update_world() |
|
|
{ |
|
|
mark_update_area(WorldArea(0,0, m_width, m_height)); |
|
225 |
} |
} |
226 |
|
|
227 |
void |
void |
251 |
int y2 = wa.y+wa.h; |
int y2 = wa.y+wa.h; |
252 |
for (int x=wa.x; x<x2; x++) { |
for (int x=wa.x; x<x2; x++) { |
253 |
for (int y=wa.y; y<y2; y++) { |
for (int y=wa.y; y<y2; y++) { |
|
Field2 &f2 = m_fields(x,y); |
|
|
if (f2.updatep) { |
|
|
// shadow_layer->update(x,y); |
|
|
f2.redrawp = true; |
|
|
f2.updatep = false; |
|
|
} |
|
254 |
ScreenArea sa(int((x-m_offset[0])*m_tilew), |
ScreenArea sa(int((x-m_offset[0])*m_tilew), |
255 |
int((y-m_offset[1])*m_tileh), |
int((y-m_offset[1])*m_tileh), |
256 |
m_tilew, |
m_tilew, |
289 |
int y2 = Min(m_height, wa.y+wa.h); |
int y2 = Min(m_height, wa.y+wa.h); |
290 |
for (int x=Max(0, wa.x); x<x2; x++) { |
for (int x=Max(0, wa.x); x<x2; x++) { |
291 |
for (int y=Max(0,wa.y); y<y2; y++) { |
for (int y=Max(0,wa.y); y<y2; y++) { |
292 |
Field2 &f2 = m_fields(x,y); |
bool &redrawp = m_redrawp(x,y); |
293 |
if (f2.updatep) { |
if (redrawp) { |
|
// shadow_layer->update(x,y); |
|
|
f2.redrawp = true; |
|
|
f2.updatep = false; |
|
|
} |
|
|
if (f2.redrawp) { |
|
294 |
ScreenArea sa(int((x-m_offset[0])*m_tilew), |
ScreenArea sa(int((x-m_offset[0])*m_tilew), |
295 |
int((y-m_offset[1])*m_tileh), |
int((y-m_offset[1])*m_tileh), |
296 |
m_tilew, |
m_tilew, |
298 |
sa.intersect(area); |
sa.intersect(area); |
299 |
clip(gc, sa); |
clip(gc, sa); |
300 |
draw_field(gc, x,y); |
draw_field(gc, x,y); |
301 |
f2.redrawp = false; |
redrawp = false; |
302 |
m_screen->update_rect(sa); |
m_screen->update_rect(sa); |
303 |
} |
} |
304 |
} |
} |
315 |
{ |
{ |
316 |
WorldArea wa; |
WorldArea wa; |
317 |
if (m->has_changed(wa)) { |
if (m->has_changed(wa)) { |
318 |
get_engine()->mark_update_area(wa); |
get_engine()->mark_redraw_area(wa); |
319 |
} |
} |
320 |
} |
} |
321 |
|
|
382 |
} |
} |
383 |
|
|
384 |
void |
void |
385 |
DL_Grid::mark_update (int x, int y) |
DL_Grid::mark_redraw (int x, int y) |
386 |
{ |
{ |
387 |
get_engine()->mark_update_area (WorldArea (x, y, 2, 2)); |
get_engine()->mark_redraw_area (WorldArea (x, y, 2, 2)); |
388 |
} |
} |
389 |
|
|
390 |
void |
void |
394 |
(unsigned)x<m_models.width() && |
(unsigned)x<m_models.width() && |
395 |
(unsigned)y<m_models.height())) |
(unsigned)y<m_models.height())) |
396 |
{ |
{ |
|
cout << "ouch, trying to set model somewhere it doesn't belong.\n"; |
|
397 |
delete m; |
delete m; |
398 |
return; |
return; |
399 |
} |
} |
404 |
delete mm; |
delete mm; |
405 |
} |
} |
406 |
m_models(x,y) = m; |
m_models(x,y) = m; |
407 |
mark_update(x,y); |
mark_redraw (x,y); |
408 |
if (m) |
if (m) |
409 |
m->expose (this, V2(x, y)); |
m->expose (this, V2(x, y)); |
410 |
} |
} |
423 |
if (m) |
if (m) |
424 |
m->remove (this); |
m->remove (this); |
425 |
m_models(x,y) = 0; |
m_models(x,y) = 0; |
426 |
mark_update(x,y); |
mark_redraw (x,y); |
427 |
return m; |
return m; |
428 |
} |
} |
429 |
|
|
793 |
** would be to use one huge image for the whole level and keep it in |
** would be to use one huge image for the whole level and keep it in |
794 |
** memory all the time. But then the cache would consume roughly 20mb |
** memory all the time. But then the cache would consume roughly 20mb |
795 |
** for a 100x100 landscape. That is excessive, considering that there |
** for a 100x100 landscape. That is excessive, considering that there |
796 |
** are probably no more than 40 different shadow tiles in each |
** are rarely no more than 40 different shadow tiles in each |
797 |
** landscape. |
** landscape. |
798 |
|
** |
799 |
|
** |
800 |
*/ |
*/ |
801 |
|
|
802 |
namespace display |
namespace display |
834 |
else if (ImageModel *im = dynamic_cast<ImageModel*>(models[i])) |
else if (ImageModel *im = dynamic_cast<ImageModel*>(models[i])) |
835 |
q.images[i] = im->get_image(); |
q.images[i] = im->get_image(); |
836 |
else |
else |
837 |
nimages--; |
q.images[i] = 0, nimages--; |
838 |
} |
} |
839 |
return nimages==4; |
return nimages==4; |
840 |
} |
} |
1041 |
} |
} |
1042 |
|
|
1043 |
void |
void |
|
DL_Shadows::set_model (int x, int y, Model *m) |
|
|
{ |
|
|
// FieldInfo &f = m_fieldinfo(x,y); |
|
|
// if (m != f.model) { |
|
|
// f.model = m; |
|
|
// clear_flags (f.flags, HAS_SHADOW); |
|
|
// set_flags (f.flags, MUST_UPDATE | (m ? HAS_SHADOW : 0)); |
|
|
// } |
|
|
} |
|
|
|
|
|
void |
|
|
DL_Shadows::update (int x, int y) |
|
|
{ |
|
|
// set_flags (m_fieldinfo(x,y).flags, MUST_UPDATE); |
|
|
} |
|
|
|
|
|
void |
|
1044 |
DL_Shadows::draw (px::GC &gc, const WorldArea &a, int x, int y) |
DL_Shadows::draw (px::GC &gc, const WorldArea &a, int x, int y) |
1045 |
{ |
{ |
1046 |
draw (gc, x, y, a.x, a.y); |
draw (gc, x, y, a.x, a.y); |
1282 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
1283 |
CommonDisplay::CommonDisplay (const ScreenArea &a) |
CommonDisplay::CommonDisplay (const ScreenArea &a) |
1284 |
{ |
{ |
1285 |
DisplayEngine *engine = new DisplayEngine (video::GetScreen()); |
DisplayEngine *engine = new DisplayEngine (video::GetScreen(), 32, 32); |
1286 |
engine->set_screen_area (a); |
engine->set_screen_area (a); |
1287 |
|
|
1288 |
engine->add_layer (floor_layer = new DL_Grid); |
engine->add_layer (floor_layer = new DL_Grid); |
1317 |
case GRID_STONES: |
case GRID_STONES: |
1318 |
stone_layer->set_model (x, y, m); |
stone_layer->set_model (x, y, m); |
1319 |
// shadow_layer->set_model (x, y, m); |
// shadow_layer->set_model (x, y, m); |
1320 |
shadow_layer->update (x, y); |
// shadow_layer->update (x, y); |
1321 |
break; |
break; |
1322 |
case GRID_COUNT: break; |
case GRID_COUNT: break; |
1323 |
} |
} |
1374 |
void |
void |
1375 |
CommonDisplay::new_world (int w, int h) |
CommonDisplay::new_world (int w, int h) |
1376 |
{ |
{ |
|
// fields.resize(w, h); |
|
1377 |
get_engine()->new_world (w, h); |
get_engine()->new_world (w, h); |
1378 |
} |
} |
1379 |
|
|
1390 |
floor_layer->set_model (x, y, m); |
floor_layer->set_model (x, y, m); |
1391 |
} |
} |
1392 |
|
|
1393 |
|
void |
1394 |
|
CommonDisplay::set_item (int x, int y, Model *m) |
1395 |
|
{ |
1396 |
|
item_layer->set_model (x,y , m); |
1397 |
|
} |
1398 |
|
|
1399 |
|
void |
1400 |
|
CommonDisplay::set_stone (int x, int y, Model *m) |
1401 |
|
{ |
1402 |
|
stone_layer->set_model (x,y , m); |
1403 |
|
} |
1404 |
|
|
1405 |
|
|
1406 |
|
|
1407 |
|
|
1408 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
1612 |
} |
} |
1613 |
|
|
1614 |
|
|
|
void |
|
|
display::SetTileSize(int w, int h) |
|
|
{ |
|
|
TileWidth = w; |
|
|
TileHeight = h; |
|
|
// engine->set_tilesize(w,h); |
|
|
} |
|
|
|
|
1615 |
void |
void |
1616 |
display::ToggleFlag(DisplayFlags flag) |
display::ToggleFlag(DisplayFlags flag) |
1617 |
{ |
{ |