Skip to content

Commit 0aec7fe

Browse files
committed
CHG: move multitile height drawing to building in preparation of new pillar type
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11639 8aca7d54-2c30-db11-9de9-000461428c89
1 parent 4137da5 commit 0aec7fe

File tree

4 files changed

+102
-34
lines changed

4 files changed

+102
-34
lines changed

src/simutrans/obj/gebaeude.cc

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,90 @@ FLAGGED_PIXVAL gebaeude_t::get_outline_colour() const
424424
}
425425

426426

427-
image_id gebaeude_t::get_image(int nr) const
427+
void gebaeude_t::display(int xpos, int ypos CLIP_NUM_DEF) const
428428
{
429-
if(zeige_baugrube || env_t::hide_buildings) {
430-
return IMG_EMPTY;
429+
430+
const int raster_width = get_current_tile_raster_width();
431+
const bool is_dirty = get_flag(obj_t::dirty);
432+
uint8 owner_n = get_owner_nr();
433+
434+
if (env_t::hide_buildings != 0 && env_t::hide_with_transparency && !zeige_baugrube) {
435+
// transparent building
436+
image_id img = tile->get_background(anim_frame, 0, season);
437+
if (img == IMG_EMPTY) {
438+
return;
439+
}
440+
uint8 colours[] = { COL_BLACK, COL_YELLOW, COL_YELLOW, COL_PURPLE, COL_RED, COL_GREEN };
441+
FLAGGED_PIXVAL disp_colour = 0;
442+
if (is_city_building()) {
443+
disp_colour = color_idx_to_rgb(colours[0]) | TRANSPARENT50_FLAG | OUTLINE_FLAG;
444+
}
445+
else if (env_t::hide_buildings == env_t::ALL_HIDDEN_BUILDING && tile->get_desc()->get_type() < building_desc_t::others) {
446+
// special building
447+
disp_colour = color_idx_to_rgb(colours[tile->get_desc()->get_type()]) | TRANSPARENT50_FLAG | OUTLINE_FLAG;
448+
}
449+
450+
if (image_id ground = get_image()) {
451+
if (owner_n != PLAYER_UNOWNED) {
452+
if (obj_t::show_owner) {
453+
display_blend(ground, xpos, ypos, owner_n, color_idx_to_rgb(welt->get_player(owner_n)->get_player_color1() + 2) | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
454+
}
455+
else {
456+
display_color(ground, xpos, ypos, owner_n, true, is_dirty CLIP_NUM_PAR);
457+
}
458+
}
459+
else {
460+
display_normal(ground, xpos, ypos, 0, true, is_dirty CLIP_NUM_PAR);
461+
}
462+
}
463+
464+
if (TRANSPARENT_FLAGS & disp_colour) {
465+
// only transparent outline
466+
display_blend(get_outline_image(), xpos, ypos, owner_n, disp_colour, 0, is_dirty CLIP_NUM_PAR);
467+
}
468+
else if (obj_t::get_flag(highlight)) {
469+
// highlight this tile
470+
display_blend(get_image(), xpos, ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
471+
}
472+
// finish
473+
return;
431474
}
432-
else {
433-
return tile->get_background( anim_frame, nr, season );
475+
476+
// not hidden
477+
image_id image = get_image();
478+
if (image != IMG_EMPTY) {
479+
const int raster_width = get_current_tile_raster_width();
480+
const bool is_dirty = get_flag(obj_t::dirty);
481+
482+
const int start_ypos = ypos;
483+
for (int j = 0; image != IMG_EMPTY; ) {
484+
485+
if (owner_n != PLAYER_UNOWNED) {
486+
if (obj_t::show_owner) {
487+
display_blend(image, xpos, ypos, owner_n, color_idx_to_rgb(welt->get_player(owner_n)->get_player_color1() + 2) | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
488+
}
489+
else {
490+
display_color(image, xpos, ypos, owner_n, true, is_dirty CLIP_NUM_PAR);
491+
}
492+
}
493+
else {
494+
display_normal(image, xpos, ypos, 0, true, is_dirty CLIP_NUM_PAR);
495+
}
496+
497+
if (obj_t::get_flag(highlight)) {
498+
// highlight this tile
499+
display_blend(image, xpos, start_ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
500+
}
501+
502+
// this obj has another image on top (e.g. skyscraper)
503+
ypos -= raster_width;
504+
505+
if (zeige_baugrube || env_t::hide_buildings) {
506+
// finish
507+
return;
508+
}
509+
image = tile->get_background(anim_frame, ++j, season);
510+
}
434511
}
435512
}
436513

@@ -1071,11 +1148,13 @@ void gebaeude_t::mark_images_dirty() const
10711148
(!env_t::hide_with_transparency &&
10721149
env_t::hide_buildings>(is_city_building() ? env_t::NOT_HIDE : env_t::SOME_HIDDEN_BUILDING)) ) {
10731150
img = skinverwaltung_t::construction_site->get_image_id(0);
1151+
mark_image_dirty(img, 0);
10741152
}
10751153
else {
10761154
img = tile->get_background( anim_frame, 0, season ) ;
1077-
}
1078-
for( int i=0; img!=IMG_EMPTY; img=get_image(++i) ) {
1079-
mark_image_dirty( img, -(i*get_tile_raster_width()) );
1155+
for (int i = 0; img != IMG_EMPTY; ) {
1156+
mark_image_dirty(img, -(i * get_tile_raster_width()));
1157+
img = tile->get_background(anim_frame, ++i, season);
1158+
}
10801159
}
10811160
}

src/simutrans/obj/gebaeude.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ class gebaeude_t : public obj_t
9595
waytype_t get_waytype() const OVERRIDE;
9696

9797
image_id get_image() const OVERRIDE;
98-
image_id get_image(int nr) const OVERRIDE;
9998
image_id get_front_image() const OVERRIDE;
10099
void mark_images_dirty() const;
101100

102101
image_id get_outline_image() const OVERRIDE;
103102
FLAGGED_PIXVAL get_outline_colour() const OVERRIDE;
104103

104+
void display(int xpos, int ypos CLIP_NUM_DEF) const OVERRIDE;
105+
105106
// caches image at height 0
106107
void calc_image() OVERRIDE;
107108

src/simutrans/obj/simobj.cc

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,40 +206,33 @@ void obj_t::display(int xpos, int ypos CLIP_NUM_DEF) const
206206
xpos += tile_raster_scale_x(get_xoff(), raster_width);
207207
ypos += tile_raster_scale_y(get_yoff(), raster_width);
208208

209-
const int start_ypos = ypos;
210-
for( int j=0; image!=IMG_EMPTY; ) {
211-
212-
if( owner_n != PLAYER_UNOWNED ) {
213-
if( obj_t::show_owner ) {
214-
display_blend( image, xpos, ypos, owner_n, color_idx_to_rgb(welt->get_player(owner_n)->get_player_color1()+2) | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
215-
}
216-
else {
217-
display_color( image, xpos, ypos, owner_n, true, is_dirty CLIP_NUM_PAR);
218-
}
209+
if( owner_n != PLAYER_UNOWNED ) {
210+
if( obj_t::show_owner ) {
211+
display_blend( image, xpos, ypos, owner_n, color_idx_to_rgb(welt->get_player(owner_n)->get_player_color1()+2) | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
219212
}
220213
else {
221-
display_normal( image, xpos, ypos, 0, true, is_dirty CLIP_NUM_PAR);
214+
display_color( image, xpos, ypos, owner_n, true, is_dirty CLIP_NUM_PAR);
222215
}
223-
// this obj has another image on top (e.g. skyscraper)
224-
ypos -= raster_width;
225-
image = get_image(++j);
216+
}
217+
else {
218+
display_normal( image, xpos, ypos, 0, true, is_dirty CLIP_NUM_PAR);
226219
}
227220

228221
if( outline_image != IMG_EMPTY ) {
229222
// transparency?
230223
const FLAGGED_PIXVAL transparent = get_outline_colour();
231224
if( TRANSPARENT_FLAGS&transparent ) {
232225
// only transparent outline
233-
display_blend( get_outline_image(), xpos, start_ypos, owner_n, transparent, 0, is_dirty CLIP_NUM_PAR);
226+
display_blend( get_outline_image(), xpos, ypos, owner_n, transparent, 0, is_dirty CLIP_NUM_PAR);
234227
}
235228
else if( obj_t::get_flag( highlight ) ) {
236229
// highlight this tile
237-
display_blend( get_image(), xpos, start_ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
230+
display_blend( get_image(), xpos, ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
238231
}
239232
}
240233
else if( obj_t::get_flag( highlight ) ) {
241234
// highlight this tile
242-
display_blend( get_image(), xpos, start_ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
235+
display_blend( get_image(), xpos, ypos, owner_n, SYSCOL_OBJECT_HIGHLIGHT | OUTLINE_FLAG | TRANSPARENT75_FLAG, 0, is_dirty CLIP_NUM_PAR);
243236
}
244237
}
245238
}

src/simutrans/obj/simobj.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,6 @@ class obj_t
231231
*/
232232
virtual image_id get_image() const = 0;
233233

234-
/**
235-
* give image for height > 0 (max. height currently 3)
236-
* IMG_EMPTY is no images
237-
*/
238-
virtual image_id get_image(int /*height*/) const {return IMG_EMPTY;}
239-
240234
/**
241235
* this image is drawn after all get_image() on this tile
242236
* Currently only single height is supported for this feature
@@ -296,10 +290,11 @@ class obj_t
296290
virtual const char *get_removal_error(const player_t *player);
297291

298292
/**
299-
* Draw background image of object
293+
* Draw background image of object (but only single height)
300294
* (everything that could be potentially behind vehicles)
295+
* override for multi imge objects
301296
*/
302-
void display(int xpos, int ypos CLIP_NUM_DEF) const;
297+
virtual void display(int xpos, int ypos CLIP_NUM_DEF) const;
303298

304299
/**
305300
* Draw foreground image

0 commit comments

Comments
 (0)