Skip to content

Commit f2feff4

Browse files
committed
CODE: Do not store passenger destination statuses as colours
This halves required memory for storing pax destination statuses per city, and also avoids calling color_idx_to_rgb() during (sync_)step git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11708 8aca7d54-2c30-db11-9de9-000461428c89
1 parent a5153d6 commit f2feff4

File tree

5 files changed

+66
-34
lines changed

5 files changed

+66
-34
lines changed

src/simutrans/gui/city_info.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class gui_city_minimap_t : public gui_world_component_t
3737
uint32 pax_destinations_last_change;
3838

3939
void init_pax_dest( array2d_tpl<PIXVAL> &pax_dest );
40-
void add_pax_dest( array2d_tpl<PIXVAL> &pax_dest, const sparse_tpl<PIXVAL>* city_pax_dest );
40+
void add_pax_dest( array2d_tpl<PIXVAL> &pax_dest, const sparse_tpl<pax_dest_status_t> &city_pax_dest);
4141

4242
public:
4343
gui_city_minimap_t(stadt_t* city) : city(city),
@@ -335,21 +335,30 @@ void gui_city_minimap_t::init_pax_dest( array2d_tpl<PIXVAL> &pax_dest )
335335
}
336336

337337

338-
void gui_city_minimap_t::add_pax_dest( array2d_tpl<PIXVAL> &pax_dest, const sparse_tpl<PIXVAL>* city_pax_dest )
338+
void gui_city_minimap_t::add_pax_dest( array2d_tpl<PIXVAL> &pax_dest, const sparse_tpl<pax_dest_status_t> &city_pax_dest)
339339
{
340-
PIXVAL color;
340+
pax_dest_status_t dst_status;
341341
koord pos;
342342
// how large the box in the world?
343343
const sint16 dd_x = 1+(minimaps_size.w-1)/PAX_DESTINATIONS_SIZE;
344344
const sint16 dd_y = 1+(minimaps_size.h-1)/PAX_DESTINATIONS_SIZE;
345345

346-
for( uint16 i = 0; i < city_pax_dest->get_data_count(); i++ ) {
347-
city_pax_dest->get_nonzero(i, pos, color);
346+
const PIXVAL city_dest_color_lut[4] = {
347+
color_idx_to_rgb(pax_dest_status_colors[0]),
348+
color_idx_to_rgb(pax_dest_status_colors[1]),
349+
color_idx_to_rgb(pax_dest_status_colors[2]),
350+
color_idx_to_rgb(pax_dest_status_colors[3])
351+
};
352+
353+
for( uint16 i = 0; i < city_pax_dest.get_data_count(); i++ ) {
354+
city_pax_dest.get_nonzero(i, pos, dst_status);
348355

349356
// calculate display position according to minimap size
350357
const sint16 x0 = (pos.x*minimaps_size.w)/PAX_DESTINATIONS_SIZE;
351358
const sint16 y0 = (pos.y*minimaps_size.h)/PAX_DESTINATIONS_SIZE;
352359

360+
const PIXVAL color = city_dest_color_lut[dst_status];
361+
353362
for( sint32 y=0; y<dd_y && y+y0<minimaps_size.h; y++ ) {
354363
for( sint32 x=0; x<dd_x && x+x0<minimaps_size.w; x++ ) {
355364
pax_dest.at( x+x0, y+y0 ) = color;

src/simutrans/gui/minimap.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,19 +1312,20 @@ void minimap_t::draw(scr_coord pos)
13121312
}
13131313
else if( pax_destinations_last_change < current_pax_destinations ) {
13141314
// new pax_dest in city.
1315-
const sparse_tpl<PIXVAL> *pax_dests = selected_city->get_pax_destinations_new();
1315+
const sparse_tpl<pax_dest_status_t> &pax_dests = selected_city->get_pax_destinations_new();
13161316
koord pos, min, max;
1317-
PIXVAL color;
1318-
for( uint16 i = 0; i < pax_dests->get_data_count(); i++ ) {
1319-
pax_dests->get_nonzero( i, pos, color );
1317+
pax_dest_status_t dst_status;
1318+
1319+
for( uint16 i = 0; i < pax_dests.get_data_count(); i++ ) {
1320+
pax_dests.get_nonzero( i, pos, dst_status);
13201321
min = koord((pos.x*world->get_size().x)/PAX_DESTINATIONS_SIZE,
13211322
(pos.y*world->get_size().y)/PAX_DESTINATIONS_SIZE);
13221323
max = koord(((pos.x+1)*world->get_size().x)/PAX_DESTINATIONS_SIZE,
13231324
((pos.y+1)*world->get_size().y)/PAX_DESTINATIONS_SIZE);
13241325
pos = min;
13251326
do {
13261327
do {
1327-
set_map_color(pos, color);
1328+
set_map_color(pos, pax_dest_status_colors[dst_status]);
13281329
pos.y++;
13291330
} while(pos.y < max.y);
13301331
pos.x++;

src/simutrans/tpl/sparse_tpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class sparse_tpl
9292
void get_nonzero( uint16 index, koord& pos, T& value ) const {
9393
if( index > data_count ) {
9494
pos = koord::invalid;
95-
value = 0;
95+
value = T(0);
9696
return;
9797
}
9898
value = data[index];

src/simutrans/world/simcity.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,25 +1357,27 @@ void stadt_t::rotate90( const sint16 y_size )
13571357
best_strasse.reset(pos);
13581358
best_haus.reset(pos);
13591359
// townhall position may be changed a little!
1360-
sparse_tpl<PIXVAL> pax_destinations_temp(koord( PAX_DESTINATIONS_SIZE, PAX_DESTINATIONS_SIZE ));
1360+
sparse_tpl<pax_dest_status_t> pax_destinations_temp(koord( PAX_DESTINATIONS_SIZE, PAX_DESTINATIONS_SIZE ));
13611361

1362-
PIXVAL color;
13631362
koord pos;
13641363
for( uint16 i = 0; i < pax_destinations_new.get_data_count(); i++ ) {
1365-
pax_destinations_new.get_nonzero(i, pos, color);
1366-
assert( color != 0 );
1367-
pax_destinations_temp.set( PAX_DESTINATIONS_SIZE-1-pos.y, pos.x, color );
1364+
pax_dest_status_t dst_status;
1365+
pax_destinations_new.get_nonzero(i, pos, dst_status);
1366+
assert( dst_status != 0 );
1367+
pax_destinations_temp.set( PAX_DESTINATIONS_SIZE-1-pos.y, pos.x, dst_status );
13681368
}
1369-
swap<PIXVAL>( pax_destinations_temp, pax_destinations_new );
1369+
swap<pax_dest_status_t>( pax_destinations_temp, pax_destinations_new );
13701370

13711371
pax_destinations_temp.clear();
13721372
for( uint16 i = 0; i < pax_destinations_old.get_data_count(); i++ ) {
1373-
pax_destinations_old.get_nonzero(i, pos, color);
1374-
assert( color != 0 );
1375-
pax_destinations_temp.set( PAX_DESTINATIONS_SIZE-1-pos.y, pos.x, color );
1373+
pax_dest_status_t dst_status;
1374+
pax_destinations_old.get_nonzero(i, pos, dst_status);
1375+
assert( dst_status != 0 );
1376+
pax_destinations_temp.set( PAX_DESTINATIONS_SIZE-1-pos.y, pos.x, dst_status );
13761377
}
1378+
swap<pax_dest_status_t>( pax_destinations_temp, pax_destinations_old );
1379+
13771380
pax_destinations_new_change ++;
1378-
swap<PIXVAL>( pax_destinations_temp, pax_destinations_old );
13791381
}
13801382

13811383

@@ -1634,7 +1636,7 @@ void stadt_t::city_growth_monthly(uint32 const month)
16341636

16351637
void stadt_t::new_month( bool recalc_destinations )
16361638
{
1637-
swap<PIXVAL>( pax_destinations_old, pax_destinations_new );
1639+
swap<pax_dest_status_t>( pax_destinations_old, pax_destinations_new );
16381640
pax_destinations_new.clear();
16391641
pax_destinations_new_change = 0;
16401642

@@ -1904,7 +1906,7 @@ void stadt_t::step_passagiere()
19041906
city_history_month[0][history_type + HIST_OFFSET_TRANSPORTED] += pax_left_to_do;
19051907

19061908
// destination logged
1907-
merke_passagier_ziel(dest_pos, color_idx_to_rgb(COL_YELLOW));
1909+
merke_passagier_ziel(dest_pos, PAX_DEST_STATUS_REACHABLE);
19081910
}
19091911
else if( route_result==haltestelle_t::ROUTE_WALK ) {
19101912
if( factory_entry ) {
@@ -1932,21 +1934,20 @@ void stadt_t::step_passagiere()
19321934
// all routes to goal are overcrowded -> register at first stop (closest)
19331935
for(halthandle_t const s : start_halts) {
19341936
s->add_pax_unhappy(pax_left_to_do);
1935-
merke_passagier_ziel(dest_pos, color_idx_to_rgb(COL_ORANGE));
19361937
break;
19371938
}
19381939
}
19391940

19401941
// destination logged
1941-
merke_passagier_ziel(dest_pos, color_idx_to_rgb(COL_ORANGE));
1942+
merke_passagier_ziel(dest_pos, PAX_DEST_STATUS_ROUTE_OVERCROWDED);
19421943
}
19431944
else if ( route_result == haltestelle_t::NO_ROUTE ) {
19441945
// since there is no route from any start halt -> register no route at first halts (closest)
19451946
for(halthandle_t const s : start_halts) {
19461947
s->add_pax_no_route(pax_left_to_do);
19471948
break;
19481949
}
1949-
merke_passagier_ziel(dest_pos, color_idx_to_rgb(COL_DARK_ORANGE));
1950+
merke_passagier_ziel(dest_pos, PAX_DEST_STATUS_NO_ROUTE);
19501951
#ifdef DESTINATION_CITYCARS
19511952
//citycars with destination
19521953
generate_private_cars( origin_pos, dest_pos );
@@ -2129,7 +2130,7 @@ void stadt_t::step_passagiere()
21292130
//citycars with destination
21302131
generate_private_cars( origin_pos, ziel );
21312132
#endif
2132-
merke_passagier_ziel(ziel, color_idx_to_rgb(COL_ORANGE));
2133+
merke_passagier_ziel(ziel, PAX_DEST_STATUS_ROUTE_OVERCROWDED);
21332134
// we show unhappy instead no route for destination stop
21342135
}
21352136
}
@@ -2231,14 +2232,14 @@ koord stadt_t::find_destination(factory_set_t &target_factories, const sint64 ge
22312232
}
22322233

22332234

2234-
void stadt_t::merke_passagier_ziel(koord k, PIXVAL color)
2235+
void stadt_t::merke_passagier_ziel(koord k, pax_dest_status_t status)
22352236
{
22362237
const koord p = koord(
22372238
((k.x * PAX_DESTINATIONS_SIZE) / welt->get_size().x) & (PAX_DESTINATIONS_SIZE-1),
22382239
((k.y * PAX_DESTINATIONS_SIZE) / welt->get_size().y) & (PAX_DESTINATIONS_SIZE-1)
22392240
);
22402241
pax_destinations_new_change ++;
2241-
pax_destinations_new.set(p, color);
2242+
pax_destinations_new.set(p, status);
22422243
}
22432244

22442245

src/simutrans/world/simcity.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ static const uint32 GENERATE_RATIO_PASS = 3;
7272
// Mail generation ratio. This many parts to passenger generation ratio parts.
7373
static const uint32 GENERATE_RATIO_MAIL = 1;
7474

75+
76+
/// When a passenger attempts to travel from a city,
77+
/// this is the reachability status of the desination
78+
/// (as shown in the city info window)
79+
/// @sa haltestelle_t::routing_result_flags
80+
enum pax_dest_status_t : uint8
81+
{
82+
PAX_DEST_STATUS_REACHABLE = 1,
83+
PAX_DEST_STATUS_ROUTE_OVERCROWDED = 2,
84+
PAX_DEST_STATUS_NO_ROUTE = 3
85+
};
86+
87+
88+
static const uint8 pax_dest_status_colors[4] = {
89+
0,
90+
COL_YELLOW, // OK/reachable
91+
COL_ORANGE, // route overcrowded
92+
COL_DARK_ORANGE, // no route
93+
};
94+
95+
7596
/**
7697
* Die Objecte der Klasse stadt_t bilden die Staedte in Simu. Sie
7798
* wachsen automatisch.
@@ -127,8 +148,8 @@ class stadt_t
127148

128149
weighted_vector_tpl <gebaeude_t *> buildings;
129150

130-
sparse_tpl<PIXVAL> pax_destinations_old;
131-
sparse_tpl<PIXVAL> pax_destinations_new;
151+
sparse_tpl<pax_dest_status_t> pax_destinations_old;
152+
sparse_tpl<pax_dest_status_t> pax_destinations_new;
132153

133154
// this counter will increment by one for every change => dialogs can question, if they need to update map
134155
uint32 pax_destinations_new_change;
@@ -346,7 +367,7 @@ class stadt_t
346367
/**
347368
* ein Passagierziel in die Zielkarte eintragen
348369
*/
349-
void merke_passagier_ziel(koord ziel, PIXVAL color);
370+
void merke_passagier_ziel(koord ziel, pax_dest_status_t status);
350371

351372
/**
352373
* baut Spezialgebaeude, z.B Stadion
@@ -465,10 +486,10 @@ class stadt_t
465486
koord get_zufallspunkt() const;
466487

467488
/// @returns passenger destination statistics for the last month
468-
const sparse_tpl<PIXVAL>* get_pax_destinations_old() const { return &pax_destinations_old; }
489+
const sparse_tpl<pax_dest_status_t> &get_pax_destinations_old() const { return pax_destinations_old; }
469490

470491
/// @returns passenger destination statistics for the current month
471-
const sparse_tpl<PIXVAL>* get_pax_destinations_new() const { return &pax_destinations_new; }
492+
const sparse_tpl<pax_dest_status_t> &get_pax_destinations_new() const { return pax_destinations_new; }
472493

473494
/* this counter will increment by one for every change
474495
* => dialogs can question, if they need to update map

0 commit comments

Comments
 (0)