Skip to content
Browse files

Wrong change

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@5613 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information...
1 parent fea73e2 commit 431670243f3a23f97748d33faaa77540996509a0 Markus Pristovsek committed Apr 5, 2012
Showing with 346 additions and 150 deletions.
  1. +10 −14 dings/gebaeude.cc
  2. +3 −3 dings/wolke.cc
  3. +4 −4 simfab.cc
  4. +1 −1 simhalt.cc
  5. +6 −5 simtools.cc
  6. +24 −0 simtools.h
  7. +162 −16 simworld.cc
  8. +20 −2 simworld.h
  9. +4 −2 tpl/vector_tpl.h
  10. +74 −2 vehicle/simpeople.cc
  11. +7 −3 vehicle/simpeople.h
  12. +13 −8 vehicle/simvehikel.cc
  13. +17 −88 vehicle/simverkehr.cc
  14. +1 −2 vehicle/simverkehr.h
View
24 dings/gebaeude.cc
@@ -76,7 +76,7 @@ gebaeude_t::gebaeude_t(karte_t *welt, loadsave_t *file) : ding_t(welt)
set_yoff(0);
}
if(tile && tile->get_phasen()>1) {
- welt->sync_add( this );
+ welt->sync_eyecandy_add( this );
sync = true;
}
}
@@ -115,7 +115,7 @@ gebaeude_t::~gebaeude_t()
if(sync) {
sync = false;
- welt->sync_remove(this);
+ welt->sync_eyecandy_remove(this);
}
// tiles might be invalid, if no description is found during loading
@@ -260,16 +260,16 @@ void gebaeude_t::set_tile(const haus_tile_besch_t *new_tile)
if(sync) {
if(new_tile->get_phasen()<=1 && !zeige_baugrube) {
// need to stop animation
- welt->sync_remove(this);
+ welt->sync_eyecandy_remove(this);
sync = false;
count = 0;
}
}
else if(new_tile->get_phasen()>1 || zeige_baugrube) {
// needs now animation
- count = simrand(new_tile->get_phasen());
+ count = sim_async_rand(new_tile->get_phasen());
anim_time = 0;
- welt->sync_add(this);
+ welt->sync_eyecandy_add(this);
sync = true;
}
tile = new_tile;
@@ -278,8 +278,6 @@ void gebaeude_t::set_tile(const haus_tile_besch_t *new_tile)
}
-
-
/**
* Methode für Echtzeitfunktionen eines Objekts.
* @return false wenn Objekt aus der Liste der synchronen
@@ -295,7 +293,7 @@ bool gebaeude_t::sync_step(long delta_t)
mark_image_dirty(get_bild(),0);
zeige_baugrube = false;
if(tile->get_phasen()<=1) {
- welt->sync_remove( this );
+ welt->sync_eyecandy_remove( this );
sync = false;
}
}
@@ -341,7 +339,6 @@ bool gebaeude_t::sync_step(long delta_t)
}
-
void gebaeude_t::calc_bild()
{
grund_t *gr = welt->lookup(get_pos());
@@ -589,7 +586,6 @@ DBG_MESSAGE("gebaeude_t::zeige_info()", "at %d,%d - name is '%s'", get_pos().x,
}
-
void gebaeude_t::info(cbuffer_t & buf) const
{
ding_t::info(buf);
@@ -857,7 +853,6 @@ void gebaeude_t::rdwr(loadsave_t *file)
}
-
/**
* Wird nach dem Laden der Welt aufgerufen - üblicherweise benutzt
* um das Aussehen des Dings an Boden und Umgebung anzupassen
@@ -885,15 +880,15 @@ void gebaeude_t::laden_abschliessen()
}
-
void gebaeude_t::entferne(spieler_t *sp)
{
// DBG_MESSAGE("gebaeude_t::entferne()","gb %i");
// remove costs
sint64 cost = welt->get_settings().cst_multiply_remove_haus;
// tearing down halts is always single costs only
- if (tile->get_besch()->get_utyp() < haus_besch_t::bahnhof)
+ if (tile->get_besch()->get_utyp() < haus_besch_t::bahnhof) {
cost *= tile->get_besch()->get_level() + 1;
+ }
spieler_t::accounting(sp, cost, get_pos().get_2d(), COST_CONSTRUCTION);
// may need to update next buildings, in the case of start, middle, end buildings
@@ -951,6 +946,7 @@ void gebaeude_t::entferne(spieler_t *sp)
mark_images_dirty();
}
+
void gebaeude_t::mark_images_dirty() const
{
// remove all traces from the screen
@@ -964,6 +960,6 @@ void gebaeude_t::mark_images_dirty() const
img = tile->get_hintergrund(count, 0, snow) ;
}
for( int i=0; img!=IMG_LEER; img=get_bild(++i) ) {
- mark_image_dirty( img, -(i<<6) );
+ mark_image_dirty( img, -(i*get_tile_raster_width()) );
}
}
View
6 dings/wolke.cc
@@ -34,8 +34,6 @@ bool wolke_t::register_besch(const skin_besch_t* besch)
-
-
wolke_t::wolke_t(karte_t *welt, koord3d pos, sint8 x_off, sint8 y_off, const skin_besch_t* besch ) :
ding_no_info_t(welt, pos)
{
@@ -52,7 +50,9 @@ wolke_t::wolke_t(karte_t *welt, koord3d pos, sint8 x_off, sint8 y_off, const ski
wolke_t::~wolke_t()
{
mark_image_dirty( get_bild(), 0 );
- welt->sync_remove(this);
+ if( !welt->sync_way_eyecandy_remove( this ) ) {
+ welt->sync_eyecandy_remove( this );
+ }
}
View
8 simfab.cc
@@ -1191,13 +1191,13 @@ void fabrik_t::smoke() const
const koord size = besch->get_haus()->get_groesse(0)-koord(1,1);
const uint8 rot = rotate%besch->get_haus()->get_all_layouts();
koord ro = rada->get_pos_off(size,rot);
- grund_t *gr=welt->lookup_kartenboden(pos.get_2d()+ro);
+ grund_t *gr = welt->lookup_kartenboden(pos.get_2d()+ro);
// to get same random order on different compilers
- const sint8 offsetx = ((rada->get_xy_off(rot).x+simrand(7)-3)*OBJECT_OFFSET_STEPS)/16;
- const sint8 offsety = ((rada->get_xy_off(rot).y+simrand(7)-3)*OBJECT_OFFSET_STEPS)/16;
+ const sint8 offsetx = ((rada->get_xy_off(rot).x+sim_async_rand(7)-3)*OBJECT_OFFSET_STEPS)/16;
+ const sint8 offsety = ((rada->get_xy_off(rot).y+sim_async_rand(7)-3)*OBJECT_OFFSET_STEPS)/16;
wolke_t *smoke = new wolke_t(welt, gr->get_pos(), offsetx, offsety, rada->get_bilder() );
gr->obj_add(smoke);
- welt->sync_add( smoke );
+ welt->sync_eyecandy_add( smoke );
}
}
View
2 simhalt.cc
@@ -1959,7 +1959,7 @@ dbg->warning("haltestelle_t::liefere_an()","%d %s delivered to %s have no longer
}
else if( ware.get_besch() == warenbauer_t::passagiere ) {
// arriving passenger may create pedestrians
- if( umgebung_t::has_pedestrians_at_stops ) {
+ if( welt->get_settings().get_show_pax() ) {
int menge = ware.menge;
FOR( slist_tpl<tile_t>, const& i, tiles ) {
if (menge <= 0) {
View
11 simtools.cc
@@ -1,6 +1,7 @@
#include <assert.h>
#include <math.h>
#include "simtools.h"
+#include "simsys.h"
/* This is the mersenne random generator: More random and faster! */
@@ -119,18 +120,18 @@ uint16 get_random_mode()
}
-static uint32 rand_seed = 12345678;
+static uint32 async_rand_seed = 12345678+dr_time();
// simpler simrand for anything not game critical (like UI)
uint32 sim_async_rand( uint32 max )
{
if( max==0 ) {
return 0;
}
- rand_seed *= 3141592621u;
- rand_seed ++;
+ async_rand_seed *= 3141592621u;
+ async_rand_seed ++;
- return (rand_seed >> 8) % max;
+ return (async_rand_seed >> 8) % max;
}
@@ -143,7 +144,7 @@ uint32 setsimrand(uint32 seed,uint32 ns)
if(seed!=0xFFFFFFFF) {
init_genrand( seed );
- rand_seed = seed;
+ async_rand_seed = seed+dr_time();
random_origin = 0;
}
if(noise_seed!=0xFFFFFFFF) {
View
24 simtools.h
@@ -57,6 +57,30 @@ template<typename T, typename U> T const& pick_any_weighted_subset(U const& cont
return container.at_weight(simrand(container.get_sum_weight()));
}
+/* Randomly select an entry from the given array. */
+template<typename T, size_t N> T const& pick_any_async(T const (&array)[N])
+{
+ return array[sim_async_rand(N)];
+}
+
+/* Randomly select an entry from the given container. */
+template<typename T, template<typename> class U> T const& pick_any_async(U<T> const& container)
+{
+ return container[sim_async_rand(container.get_count())];
+}
+
+/* Randomly select an entry from the given weighted container. */
+template<typename T, template<typename> class U> T const& pick_any_weighted_async(U<T> const& container)
+{
+ return container.at_weight(sim_async_rand(container.get_sum_weight()));
+}
+
+/* Randomly select an entry from the given subset of a weighted container. */
+template<typename T, typename U> T const& pick_any_weighted_subset_async(U const& container)
+{
+ return container.at_weight(sim_async_rand(container.get_sum_weight()));
+}
+
// compute integer log10
uint32 log10(uint32 v);
View
178 simworld.cc
@@ -100,6 +100,7 @@
#include "player/ai_goods.h"
+
// advance 201 ms per sync_step in fast forward mode
#define MAGIC_STEP (201)
@@ -582,6 +583,8 @@ DBG_MESSAGE("karte_t::destroy()", "towns destroyed");
display_progress( old_progress, max_display_progress );
old_progress += cached_groesse_karte_x*cached_groesse_karte_y;
+
+ // removes all moving stuff from the sync_step
while(!sync_list.empty()) {
#ifndef SYNC_VECTOR
sync_steppable *ss = sync_list.remove_first();
@@ -590,8 +593,19 @@ DBG_MESSAGE("karte_t::destroy()", "towns destroyed");
delete sync_list.back();
#endif
}
- // entfernt alle synchronen objekte aus der liste
sync_list.clear();
+
+ // now remove all pedestrians too ...
+ while(!sync_eyecandy_list.empty()) {
+ sync_steppable *ss = sync_eyecandy_list.remove_first();
+ delete ss;
+ }
+
+ while(!sync_way_eyecandy_list.empty()) {
+ sync_steppable *ss = sync_way_eyecandy_list.remove_first();
+ delete ss;
+ }
+
display_progress( old_progress, max_display_progress );
DBG_MESSAGE("karte_t::destroy()", "sync list cleared");
@@ -2692,42 +2706,158 @@ stadt_t *karte_t::suche_naechste_stadt(const koord pos) const
// -------- Verwaltung von synchronen Objekten ------------------
-static bool sync_step_running = false;
+static volatile bool sync_step_running = false;
+static volatile bool sync_step_eyecandy_running = false;
+static volatile bool sync_way_eyecandy_running = false;
-bool karte_t::sync_add(sync_steppable *obj)
+// handling animations and the like
+bool karte_t::sync_eyecandy_add(sync_steppable *obj)
{
- if( sync_step_running ) {
- sync_add_list.insert( obj );
+ if( sync_step_eyecandy_running ) {
+ sync_eyecandy_add_list.insert( obj );
}
else {
- sync_list.append( obj );
+ sync_eyecandy_list.put( obj, obj );
}
return true;
}
-bool karte_t::sync_remove(sync_steppable *obj) // entfernt alle dinge == obj aus der Liste
+bool karte_t::sync_eyecandy_remove(sync_steppable *obj) // entfernt alle dinge == obj aus der Liste
{
- if( sync_step_running ) {
- if(sync_add_list.remove(obj)) {
- return true;
+ if(sync_eyecandy_add_list.remove(obj)) {
+ return true;
+ }
+ if( sync_step_eyecandy_running ) {
+ sync_eyecandy_remove_list.append(obj);
+ }
+ else {
+ return sync_eyecandy_list.remove(obj)!=NULL;
+ }
+ return false;
+}
+
+
+void karte_t::sync_eyecandy_step(long delta_t)
+{
+ sync_step_eyecandy_running = true;
+ // first add everything
+ while( !sync_eyecandy_add_list.empty() ) {
+ sync_steppable *obj = sync_eyecandy_add_list.remove_first();
+ sync_eyecandy_list.put( obj, obj );
+ }
+ // now remove everything from last time
+ while( !sync_eyecandy_remove_list.empty() ) {
+ sync_eyecandy_list.remove( sync_eyecandy_remove_list.remove_first() );
+ }
+ // now step ...
+ for( ptrhashtable_tpl<sync_steppable*,sync_steppable*>::iterator iter = sync_eyecandy_list.begin(); iter != sync_eyecandy_list.end(); ) {
+ // if false, then remove
+ sync_steppable *ss = iter->key;
+ if(!ss->sync_step(delta_t)) {
+ iter = sync_eyecandy_list.erase(iter);
+ delete ss;
}
else {
- sync_remove_list.append(obj);
+ ++iter;
}
}
+ // now remove everything from last time
+ while( !sync_eyecandy_remove_list.empty() ) {
+ sync_eyecandy_list.remove( sync_eyecandy_remove_list.remove_first() );
+ }
+ sync_step_eyecandy_running = false;
+}
+
+
+// and now the same for pedestrians
+bool karte_t::sync_way_eyecandy_add(sync_steppable *obj)
+{
+ if( sync_way_eyecandy_running ) {
+ sync_way_eyecandy_add_list.insert( obj );
+ }
else {
- if(sync_add_list.remove(obj)) {
- return true;
+ sync_way_eyecandy_list.put( obj, obj );
+ }
+ return true;
+}
+
+
+bool karte_t::sync_way_eyecandy_remove(sync_steppable *obj) // entfernt alle dinge == obj aus der Liste
+{
+ if( sync_way_eyecandy_add_list.remove(obj )) {
+ return true;
+ }
+ if( sync_way_eyecandy_running ) {
+ sync_way_eyecandy_remove_list.append(obj);
+ }
+ else {
+ return sync_way_eyecandy_list.remove(obj);
+ }
+ return false;
+}
+
+
+void karte_t::sync_way_eyecandy_step(long delta_t)
+{
+ sync_way_eyecandy_running = true;
+ // first add everything
+ while( !sync_way_eyecandy_add_list.empty() ) {
+ sync_steppable *obj = sync_way_eyecandy_add_list.remove_first();
+ sync_way_eyecandy_list.put( obj, obj );
+ }
+ // now remove everything from last time
+ while( !sync_way_eyecandy_remove_list.empty() ) {
+ sync_way_eyecandy_list.remove( sync_way_eyecandy_remove_list.remove_first() );
+ }
+ // now step ...
+ for( ptrhashtable_tpl<sync_steppable*,sync_steppable*>::iterator iter = sync_way_eyecandy_list.begin(); iter != sync_way_eyecandy_list.end(); ) {
+ // if false, then remove
+ sync_steppable *ss = iter->key;
+ if(!ss->sync_step(delta_t)) {
+ iter = sync_way_eyecandy_list.erase(iter);
+ delete ss;
}
else {
- sync_list.remove(obj);
+ ++iter;
}
}
- return false;
+ // now remove everything from last time
+ while( !sync_way_eyecandy_remove_list.empty() ) {
+ sync_way_eyecandy_list.remove( sync_way_eyecandy_remove_list.remove_first() );
+ }
+ sync_way_eyecandy_running = false;
}
+// ... and now all regular stuff, which needs to are in the same order on any plattform
+// Thus we are using (slower) lists/vectors and no pointerhashtables
+bool karte_t::sync_add(sync_steppable *obj)
+{
+ if( sync_step_running ) {
+ sync_add_list.insert( obj );
+ }
+ else {
+ sync_list.append( obj );
+ }
+ return true;
+}
+
+
+bool karte_t::sync_remove(sync_steppable *obj) // entfernt alle dinge == obj aus der Liste
+{
+ if(sync_add_list.remove(obj)) {
+ return true;
+ }
+ if( sync_step_running ) {
+ sync_remove_list.append(obj);
+ }
+ else {
+ return sync_list.remove(obj);
+ }
+ return false;
+}
+
/*
* this routine is called before an image is displayed
@@ -2740,11 +2870,27 @@ void karte_t::sync_step(long delta_t, bool sync, bool display )
set_random_mode( SYNC_STEP_RANDOM );
if(sync) {
// only omitted, when called to display a new frame during fast forward
- sync_step_running = true;
// just for progress
ticks += delta_t;
+ set_random_mode( INTERACTIVE_RANDOM );
+
+ /* animations do not require exact sync
+ * foundations etc are added removed freuently during city growth
+ * => they are now in a hastable!
+ */
+ sync_eyecandy_step( delta_t );
+
+ /* pedestrians do not require exact sync and are added/removed frequently
+ * => they are now in a hastable!
+ */
+ sync_way_eyecandy_step( delta_t );
+
+ clear_random_mode( INTERACTIVE_RANDOM );
+
+ /* and now the rest for the other moving stuff */
+ sync_step_running = true;
#ifndef SYNC_VECTOR
// insert new objects created during last sync_step (eg vehicle smoke)
if(!sync_add_list.empty()) {
View
22 simworld.h
@@ -21,6 +21,7 @@
#include "halthandle_t.h"
#include "tpl/weighted_vector_tpl.h"
+#include "tpl/ptrhashtable_tpl.h"
#include "tpl/vector_tpl.h"
#include "tpl/slist_tpl.h"
@@ -209,12 +210,20 @@ class karte_t
zeiger_t *zeiger;
slist_tpl<sync_steppable *> sync_add_list; // these objects are move to the sync_list (but before next sync step, so they do not interfere!)
+ slist_tpl<sync_steppable *> sync_remove_list;
#ifndef SYNC_VECTOR
slist_tpl<sync_steppable *> sync_list;
#else
vector_tpl<sync_steppable *> sync_list;
#endif
- slist_tpl<sync_steppable *> sync_remove_list;
+
+ slist_tpl<sync_steppable *> sync_eyecandy_add_list; // these objects are move to the sync_list (but before next sync step, so they do not interfere!)
+ slist_tpl<sync_steppable *> sync_eyecandy_remove_list;
+ ptrhashtable_tpl<sync_steppable *,sync_steppable *> sync_eyecandy_list;
+
+ slist_tpl<sync_steppable *> sync_way_eyecandy_add_list; // these objects are move to the sync_list (but before next sync step, so they do not interfere!)
+ slist_tpl<sync_steppable *> sync_way_eyecandy_remove_list;
+ ptrhashtable_tpl<sync_steppable *,sync_steppable *> sync_way_eyecandy_list;
vector_tpl<convoihandle_t> convoi_array;
@@ -953,9 +962,18 @@ class karte_t
bool sync_add(sync_steppable *obj);
bool sync_remove(sync_steppable *obj);
-
void sync_step(long delta_t, bool sync, bool display ); // advance also the timer
+ bool sync_eyecandy_add(sync_steppable *obj);
+ bool sync_eyecandy_remove(sync_steppable *obj);
+ void sync_eyecandy_step(long delta_t); // all stuff, which does not need explicit order (factory smoke, buildings)
+
+ bool sync_way_eyecandy_add(sync_steppable *obj);
+ bool sync_way_eyecandy_remove(sync_steppable *obj);
+ void sync_way_eyecandy_step(long delta_t); // currently one smoke from vehicles on ways
+
+
+ // for all stuff, that needs long and can be done less frequently
void step();
inline planquadrat_t *access(int i, int j) const {
View
6 tpl/vector_tpl.h
@@ -191,23 +191,25 @@ template<class T> class vector_tpl
}
/** removes element, if contained */
- void remove(const T& elem)
+ bool remove(const T& elem)
{
for (uint32 i = 0; i < count; i++) {
if (data[i] == elem) {
return remove_at(i);
}
}
+ return false;
}
/** removes element at position */
- void remove_at(const uint32 pos)
+ bool remove_at(const uint32 pos)
{
assert(pos<count);
for (uint i = pos; i < count - 1; i++) {
data[i] = data[i + 1];
}
count--;
+ return true;
}
void pop_back()
View
76 vehicle/simpeople.cc
@@ -73,14 +73,21 @@ fussgaenger_t::fussgaenger_t(karte_t *welt, loadsave_t *file)
fussgaenger_t::fussgaenger_t(karte_t* const welt, koord3d const pos) :
- verkehrsteilnehmer_t(welt, pos),
+ verkehrsteilnehmer_t(welt, pos, simrand(65535)),
besch(pick_any_weighted(liste))
{
time_to_life = pick_any(strecke);
calc_bild();
}
+fussgaenger_t::~fussgaenger_t()
+{
+ if( time_to_life>0 ) {
+ welt->sync_remove( this );
+ }
+}
+
void fussgaenger_t::calc_bild()
{
@@ -140,7 +147,8 @@ void fussgaenger_t::erzeuge_fussgaenger_an(karte_t *welt, const koord3d k, int &
}
welt->sync_add(fg);
anzahl--;
- } else {
+ }
+ else {
// delete it, if we could not put it on the map
fg->set_flag(ding_t::not_on_map);
delete fg;
@@ -160,3 +168,67 @@ bool fussgaenger_t::sync_step(long delta_t)
weg_next -= fahre_basis( weg_next );
return time_to_life>0;
}
+
+
+void fussgaenger_t::hop()
+{
+ // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
+ grund_t *from = welt->lookup(pos_next);
+ grund_t *to;
+
+ if(!from) {
+ time_to_life = 0;
+ return;
+ }
+
+ grund_t *liste[4];
+ int count = 0;
+
+ // 1) find the allowed directions
+ const weg_t *weg = from->get_weg(road_wt);
+ if(weg==NULL) {
+ // no gound here any more?
+ pos_next = get_pos();
+ from = welt->lookup(pos_next);
+ if(!from || !from->hat_weg(road_wt)) {
+ // destroy it
+ time_to_life = 0;
+ }
+ return;
+ }
+
+ // add all good ribis here
+ ribi_t::ribi gegenrichtung = ribi_t::rueckwaerts( get_fahrtrichtung() );
+ int ribi = weg->get_ribi_unmasked();
+ for(int r = 0; r < 4; r++) {
+ if( (ribi & ribi_t::nsow[r])!=0 && (ribi_t::nsow[r]&gegenrichtung)==0 &&
+ from->get_neighbour(to, road_wt, ribi_t::nsow[r])
+ ) {
+ // check, if this is just a single tile deep
+ int next_ribi = to->get_weg(road_wt)->get_ribi_unmasked();
+ if((ribi&next_ribi)!=0 || !ribi_t::ist_einfach(next_ribi)) {
+ liste[count++] = to;
+ }
+ }
+ }
+
+ if(count > 1) {
+ pos_next = liste[simrand(count)]->get_pos();
+ fahrtrichtung = calc_set_richtung(get_pos().get_2d(), pos_next.get_2d());
+ }
+ else if(count==1) {
+ pos_next = liste[0]->get_pos();
+ fahrtrichtung = calc_set_richtung(get_pos().get_2d(), pos_next.get_2d());
+ }
+ else {
+ fahrtrichtung = gegenrichtung;
+ dx = -dx;
+ dy = -dy;
+ pos_next = get_pos();
+ }
+
+ verlasse_feld();
+ set_pos(from->get_pos());
+ calc_bild();
+ betrete_feld();
+}
View
10 vehicle/simpeople.h
@@ -24,9 +24,12 @@ class fussgaenger_t : public verkehrsteilnehmer_t
void calc_bild();
+ fussgaenger_t(karte_t *welt, koord3d pos);
+
public:
fussgaenger_t(karte_t *welt, loadsave_t *file);
- fussgaenger_t(karte_t *welt, koord3d pos);
+
+ virtual ~fussgaenger_t();
const fussgaenger_besch_t *get_besch() const { return besch; }
@@ -36,8 +39,9 @@ class fussgaenger_t : public verkehrsteilnehmer_t
bool sync_step(long delta_t);
// prissi: always free
- virtual bool ist_weg_frei() { return 1; }
- virtual bool hop_check() { return 1; }
+ virtual bool ist_weg_frei() { return true; }
+ virtual bool hop_check() { return true; }
+ virtual void hop();
// class register functions
static bool register_besch(const fussgaenger_besch_t *besch);
View
21 vehicle/simvehikel.cc
@@ -71,6 +71,8 @@
#include "simvehikel.h"
#include "simverkehr.h"
+
+
/* get dx and dy from dir (just to remind you)
* any vehikel (including city cars and pedestrians)
* will go this distance per sync step.
@@ -559,13 +561,15 @@ sint8 vehikel_basis_t::calc_height()
vehikel_basis_t *vehikel_basis_t::no_cars_blocking( const grund_t *gr, const convoi_t *cnv, const uint8 current_fahrtrichtung, const uint8 next_fahrtrichtung, const uint8 next_90fahrtrichtung )
{
// suche vehikel
- const uint8 top = gr->get_top();
- for( uint8 pos=1; pos<top; pos++ ) {
+ for( uint8 pos=1; pos<(volatile uint8)gr->get_top(); pos++ ) {
if (vehikel_basis_t* const v = ding_cast<vehikel_basis_t>(gr->obj_bei(pos))) {
- uint8 other_fahrtrichtung=255;
- bool other_moving = false;
+ if( v->get_typ()==ding_t::fussgaenger ) {
+ continue;
+ }
// check for car
+ uint8 other_fahrtrichtung=255;
+ bool other_moving = false;
if (automobil_t const* const at = ding_cast<automobil_t>(v)) {
// ignore ourself
if(cnv==at->get_convoi()) {
@@ -575,7 +579,7 @@ vehikel_basis_t *vehikel_basis_t::no_cars_blocking( const grund_t *gr, const con
other_moving = at->get_convoi()->get_akt_speed() > kmh_to_speed(1);
}
// check for city car
- else if(v->get_waytype()==road_wt && v->get_typ()!=ding_t::fussgaenger) {
+ else if( v->get_waytype()==road_wt ) {
other_fahrtrichtung = v->get_fahrtrichtung();
if(stadtauto_t const* const sa = ding_cast<stadtauto_t>(v)){
other_moving = sa->get_current_speed() > 1;
@@ -602,7 +606,7 @@ vehikel_basis_t *vehikel_basis_t::no_cars_blocking( const grund_t *gr, const con
const bool other_straight = other_fahrtrichtung == other_90fahrtrichtung; // other is driving straight
const bool other_exit_same_side = current_90fahrtrichtung == other_90fahrtrichtung; // other is exiting same side as we're entering
const bool other_exit_opposite_side = ribi_t::rueckwaerts(current_90fahrtrichtung) == other_90fahrtrichtung; // other is exiting side across from where we're entering
- if( across && ((ribi_t::ist_orthogonal(current_90fahrtrichtung,other_fahrtrichtung) && other_moving) || (other_across && other_exit_opposite_side) || ((other_across||other_straight) && other_exit_same_side && other_moving) ) ) {
+ if( across && ((ribi_t::ist_orthogonal(current_90fahrtrichtung,other_fahrtrichtung) && other_moving) || (other_across && other_exit_opposite_side) || ((other_across||other_straight) && other_exit_same_side && other_moving) ) ) {
// other turning across in front of us from orth entry dir'n ~4%
return v;
}
@@ -612,7 +616,8 @@ vehikel_basis_t *vehikel_basis_t::no_cars_blocking( const grund_t *gr, const con
if( straight && (ribi_t::ist_orthogonal(current_90fahrtrichtung,other_fahrtrichtung) || (other_across && other_moving && (other_exit_across || (other_exit_same_side && !headon))) ) ) {
// other turning across in front of us, but allow if other is stopped - duplicating historic behaviour ~2%
return v;
- } else if( other_fahrtrichtung==current_fahrtrichtung && current_90fahrtrichtung==ribi_t::keine ) {
+ }
+ else if( other_fahrtrichtung==current_fahrtrichtung && current_90fahrtrichtung==ribi_t::keine ) {
// entering same diagonal waypoint as other ~1%
return v;
}
@@ -1167,7 +1172,7 @@ void vehikel_t::rauche() const
delete abgas;
}
else {
- welt->sync_add( abgas );
+ welt->sync_way_eyecandy_add( abgas );
}
}
}
View
105 vehicle/simverkehr.cc
@@ -61,20 +61,10 @@ verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt) :
verkehrsteilnehmer_t::~verkehrsteilnehmer_t()
{
mark_image_dirty( get_bild(), 0 );
- // first: release crossing
- grund_t *gr = welt->lookup(get_pos());
- if(gr && gr->ist_uebergang()) {
- gr->find<crossing_t>(2)->release_crossing(this);
- }
-
- // just to be sure we are removed from this list!
- if(time_to_life>0) {
- welt->sync_remove(this);
- }
}
-verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt, koord3d pos) :
+verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt, koord3d pos, uint16 random) :
vehikel_basis_t(welt, pos)
{
// V.Meyer: weg_position_t changed to grund_t::get_neighbour()
@@ -85,7 +75,7 @@ verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt, koord3d pos) :
ribi_t::ribi liste[4];
int count = 0;
- weg_next = simrand(65535);
+ weg_next = random;
hoff = 0;
// verfügbare ribis in liste eintragen
@@ -94,7 +84,7 @@ verkehrsteilnehmer_t::verkehrsteilnehmer_t(karte_t *welt, koord3d pos) :
liste[count++] = ribi_t::nsow[r];
}
}
- fahrtrichtung = count ? liste[simrand(count)] : pick_any(ribi_t::nsow);
+ fahrtrichtung = count ? liste[random%count] : ribi_t::nsow[random%4];
switch(fahrtrichtung) {
case ribi_t::nord:
@@ -137,70 +127,6 @@ void verkehrsteilnehmer_t::zeige_info()
}
-void verkehrsteilnehmer_t::hop()
-{
- // V.Meyer: weg_position_t changed to grund_t::get_neighbour()
- grund_t *from = welt->lookup(pos_next);
- grund_t *to;
-
- if(!from) {
- time_to_life = 0;
- return;
- }
-
- grund_t *liste[4];
- int count = 0;
-
- // 1) find the allowed directions
- const weg_t *weg = from->get_weg(road_wt);
- if(weg==NULL) {
- // no gound here any more?
- pos_next = get_pos();
- from = welt->lookup(pos_next);
- if(!from || !from->hat_weg(road_wt)) {
- // destroy it
- time_to_life = 0;
- }
- return;
- }
-
- // add all good ribis here
- ribi_t::ribi gegenrichtung = ribi_t::rueckwaerts( get_fahrtrichtung() );
- int ribi = weg->get_ribi_unmasked();
- for(int r = 0; r < 4; r++) {
- if( (ribi & ribi_t::nsow[r])!=0 && (ribi_t::nsow[r]&gegenrichtung)==0 &&
- from->get_neighbour(to, road_wt, ribi_t::nsow[r])
- ) {
- // check, if this is just a single tile deep
- int next_ribi = to->get_weg(road_wt)->get_ribi_unmasked();
- if((ribi&next_ribi)!=0 || !ribi_t::ist_einfach(next_ribi)) {
- liste[count++] = to;
- }
- }
- }
-
- if(count > 1) {
- pos_next = liste[simrand(count)]->get_pos();
- fahrtrichtung = calc_set_richtung(get_pos().get_2d(), pos_next.get_2d());
- } else if(count==1) {
- pos_next = liste[0]->get_pos();
- fahrtrichtung = calc_set_richtung(get_pos().get_2d(), pos_next.get_2d());
- }
- else {
- fahrtrichtung = gegenrichtung;
- dx = -dx;
- dy = -dy;
- pos_next = get_pos();
- }
-
- verlasse_feld();
- set_pos(from->get_pos());
- calc_bild();
- betrete_feld();
-}
-
-
-
void verkehrsteilnehmer_t::rdwr(loadsave_t *file)
{
xml_tag_t t( file, "verkehrsteilnehmer_t" );
@@ -370,6 +296,16 @@ bool stadtauto_t::list_empty()
stadtauto_t::~stadtauto_t()
{
+ // first: release crossing
+ grund_t *gr = welt->lookup(get_pos());
+ if(gr && gr->ist_uebergang()) {
+ gr->find<crossing_t>(2)->release_crossing(this);
+ }
+
+ // just to be sure we are removed from this list!
+ if(time_to_life>0) {
+ welt->sync_remove(this);
+ }
welt->buche( -1, karte_t::WORLD_CITYCARS );
}
@@ -387,7 +323,7 @@ stadtauto_t::stadtauto_t(karte_t *welt, loadsave_t *file) :
stadtauto_t::stadtauto_t(karte_t* const welt, koord3d const pos, koord const target) :
- verkehrsteilnehmer_t(welt, pos),
+ verkehrsteilnehmer_t(welt, pos, simrand(65535)),
besch(liste_timeline.empty() ? 0 : pick_any_weighted(liste_timeline))
{
pos_next_next = koord3d::invalid;
@@ -404,10 +340,9 @@ stadtauto_t::stadtauto_t(karte_t* const welt, koord3d const pos, koord const tar
}
-
-
bool stadtauto_t::sync_step(long delta_t)
{
+return false;
time_to_life -= delta_t;
if( time_to_life<=0 ) {
return false;
@@ -420,7 +355,7 @@ bool stadtauto_t::sync_step(long delta_t)
// check only every 1.024 s if stopped
if( (ms_traffic_jam>>10) != (old_ms_traffic_jam>>10) ) {
pos_next_next = koord3d::invalid;
- if( hop_check( )) {
+ if( hop_check() ) {
ms_traffic_jam = 0;
current_speed = 48;
}
@@ -677,13 +612,7 @@ void stadtauto_t::betrete_feld()
if(target!=koord::invalid && koord_distance(pos_next.get_2d(),target)<10) {
// delete it ...
time_to_life = 0;
-
- fussgaenger_t *fg = new fussgaenger_t(welt, pos_next);
- bool ok = welt->lookup(pos_next)->obj_add(fg) != 0;
- for(int i=0; i<(fussgaenger_t::count & 3); i++) {
- fg->sync_step(64*24);
- }
- welt->sync_add( fg );
+ fussgaenger_t::erzeuge_fussgaenger_an(welt, get_pos(), 2);
}
#endif
vehikel_basis_t::betrete_feld();
View
3 vehicle/simverkehr.h
@@ -42,10 +42,9 @@ class verkehrsteilnehmer_t : public vehikel_basis_t, public sync_steppable
virtual waytype_t get_waytype() const { return road_wt; }
virtual bool hop_check() {return true;}
- virtual void hop();
verkehrsteilnehmer_t(karte_t *welt);
- verkehrsteilnehmer_t(karte_t *welt, koord3d pos);
+ verkehrsteilnehmer_t(karte_t *welt, koord3d pos, uint16 random);
public:
virtual ~verkehrsteilnehmer_t();

0 comments on commit 4316702

Please sign in to comment.
Something went wrong with that request. Please try again.