Skip to content

Commit

Permalink
CODE: dr_time() returns uint32, make time arithmetic robust against o…
Browse files Browse the repository at this point in the history
…verflow

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@7151 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Apr 20, 2014
1 parent 59a86ca commit 02e0e6f
Show file tree
Hide file tree
Showing 39 changed files with 101 additions and 99 deletions.
4 changes: 2 additions & 2 deletions dataobj/powernet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void powernet_t::neue_karte()
}


void powernet_t::step_all(long delta_t)
void powernet_t::step_all(uint32 delta_t)
{
FOR(slist_tpl<powernet_t*>, const p, powernet_list) {
p->step(delta_t);
Expand Down Expand Up @@ -67,7 +67,7 @@ powernet_t::~powernet_t()
}


void powernet_t::step(long delta_t)
void powernet_t::step(uint32 delta_t)
{
if( delta_t==0 ) {
return;
Expand Down
4 changes: 2 additions & 2 deletions dataobj/powernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class powernet_t
static void neue_karte();

/// Steps all powernets
static void step_all(long delta_t);
static void step_all(uint32 delta_t);

private:
static slist_tpl<powernet_t *> powernet_list;
Expand All @@ -47,7 +47,7 @@ class powernet_t
uint64 this_demand;

/// Just transfers power demand and supply to current step
void step(long delta_t);
void step(uint32 delta_t);

public:
powernet_t();
Expand Down
2 changes: 1 addition & 1 deletion gui/display_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void color_gui_t::draw(scr_coord pos, scr_size size)
// Update label buffers
hide_buildings_label.set_text( env_t::hide_buildings==0 ? "no buildings hidden" : (env_t::hide_buildings==1 ? "hide city building" : "hide all building") );
convoy_tooltip_label.set_text( env_t::show_vehicle_states==0 ? "convoi error tooltips" : (env_t::show_vehicle_states==1 ? "convoi mouseover tooltips" : "all convoi tooltips") );
sprintf(frame_time_buf," %ld ms", get_frame_time() );
sprintf(frame_time_buf," %d ms", get_frame_time() );
sprintf(idle_time_buf, " %d ms", welt->get_schlaf_zeit() );

// fps_label
Expand Down
3 changes: 2 additions & 1 deletion ifc/sync_steppable.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef sync_steppable_h
#define sync_steppable_h

#include "../simtypes.h"

/**
* All synchronously moving things must implement this interface.
Expand All @@ -16,7 +17,7 @@ class sync_steppable
* Objekte entfernt werden sol
* @author Hj. Malthaner
*/
virtual bool sync_step(long delta_t) = 0;
virtual bool sync_step(uint32 delta_t) = 0;

virtual ~sync_steppable() {}
};
Expand Down
4 changes: 2 additions & 2 deletions obj/gebaeude.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void gebaeude_t::set_tile( const haus_tile_besch_t *new_tile, bool start_with_co
* Objekte entfernt werden sol
* @author Hj. Malthaner
*/
bool gebaeude_t::sync_step(long delta_t)
bool gebaeude_t::sync_step(uint32 delta_t)
{
if(zeige_baugrube) {
// still under construction?
Expand All @@ -308,7 +308,7 @@ bool gebaeude_t::sync_step(long delta_t)
}
else {
// normal animated building
anim_time += (uint16)delta_t;
anim_time += delta_t;
if(anim_time>tile->get_besch()->get_animation_time()) {
if(!zeige_baugrube) {

Expand Down
2 changes: 1 addition & 1 deletion obj/gebaeude.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class gebaeude_t : public obj_t, sync_steppable
* @return true
* @author Hj. Malthaner
*/
bool sync_step(long delta_t);
bool sync_step(uint32 delta_t);

/**
* @return Den level (die Ausbaustufe) des Gebaudes
Expand Down
10 changes: 5 additions & 5 deletions obj/leitung2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void pumpe_t::neue_karte()
}


void pumpe_t::step_all(long delta_t)
void pumpe_t::step_all(uint32 delta_t)
{
FOR(slist_tpl<pumpe_t*>, const p, pumpe_list) {
p->step(delta_t);
Expand Down Expand Up @@ -476,7 +476,7 @@ pumpe_t::~pumpe_t()
}


void pumpe_t::step(long delta_t)
void pumpe_t::step(uint32 delta_t)
{
if(fab==NULL) {
return;
Expand Down Expand Up @@ -567,7 +567,7 @@ void senke_t::neue_karte()
}


void senke_t::step_all(long delta_t)
void senke_t::step_all(uint32 delta_t)
{
FOR(slist_tpl<senke_t*>, const s, senke_list) {
s->step(delta_t);
Expand Down Expand Up @@ -615,7 +615,7 @@ senke_t::~senke_t()
}


void senke_t::step(long delta_t)
void senke_t::step(uint32 delta_t)
{
if(fab==NULL) {
return;
Expand Down Expand Up @@ -660,7 +660,7 @@ void senke_t::step(long delta_t)
}


bool senke_t::sync_step(long delta_t)
bool senke_t::sync_step(uint32 delta_t)
{
if(fab==NULL) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions obj/leitung2.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class pumpe_t : public leitung_t
{
public:
static void neue_karte();
static void step_all(long delta_t);
static void step_all(uint32 delta_t);

private:
static slist_tpl<pumpe_t *> pumpe_list;

fabrik_t *fab;
uint32 supply;

void step(long delta_t);
void step(uint32 delta_t);

public:
pumpe_t(loadsave_t *file);
Expand All @@ -166,7 +166,7 @@ class senke_t : public leitung_t, public sync_steppable
{
public:
static void neue_karte();
static void step_all(long delta_t);
static void step_all(uint32 delta_t);

private:
static slist_tpl<senke_t *> senke_list;
Expand All @@ -179,7 +179,7 @@ class senke_t : public leitung_t, public sync_steppable
uint32 last_power_demand;
uint32 power_load;

void step(long delta_t);
void step(uint32 delta_t);

public:
senke_t(loadsave_t *file);
Expand All @@ -190,7 +190,7 @@ class senke_t : public leitung_t, public sync_steppable

// used to alternate between displaying power on and power off images at a frequency determined by the percentage of power supplied
// gives players a visual indication of a power network with insufficient generation
bool sync_step(long delta_t);
bool sync_step(uint32 delta_t);

const char *get_name() const {return "Abspanntransformator";}

Expand Down
2 changes: 1 addition & 1 deletion obj/roadsign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void roadsign_t::calc_bild()


// only used for traffic light: change the current state
bool roadsign_t::sync_step(long /*delta_t*/)
bool roadsign_t::sync_step(uint32 /*delta_t*/)
{
if( besch->is_private_way() ) {
uint8 image = 1-(dir&1);
Expand Down
2 changes: 1 addition & 1 deletion obj/roadsign.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class roadsign_t : public obj_t, public sync_steppable
bool is_free_route(uint8 check_dir) const { return besch->is_choose_sign() && check_dir == dir; }

// changes the state of a traffic light
bool sync_step(long);
bool sync_step(uint32);

// change the phases of the traffic lights
uint8 get_ticks_ns() const { return ticks_ns; }
Expand Down
4 changes: 2 additions & 2 deletions obj/wolke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ void wolke_t::rdwr(loadsave_t *file)



bool wolke_t::sync_step(long delta_t)
bool wolke_t::sync_step(uint32 delta_t)
{
insta_zeit += (uint16)delta_t;
insta_zeit += delta_t;
if(insta_zeit>=2499) {
// delete wolke ...
insta_zeit = 2499;
Expand Down
2 changes: 1 addition & 1 deletion obj/wolke.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class wolke_t : public obj_no_info_t, public sync_steppable
wolke_t(koord3d pos, sint8 xoff, sint8 yoff, const skin_besch_t *cloud );
~wolke_t();

bool sync_step(long delta_t);
bool sync_step(uint32 delta_t);

const char* get_name() const { return "Wolke"; }
typ get_typ() const { return sync_wolke; }
Expand Down
2 changes: 1 addition & 1 deletion player/simplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void spieler_t::display_messages()
* Age messages (move them upwards), delete too old ones
* @author prissi
*/
void spieler_t::age_messages(long /*delta_t*/)
void spieler_t::age_messages(uint32 /*delta_t*/)
{
for(slist_tpl<income_message_t *>::iterator iter = messages.begin(); iter != messages.end(); ) {
income_message_t *m = *iter;
Expand Down
2 changes: 1 addition & 1 deletion player/simplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class spieler_t
* Age messages (move them upwards)
* @author Hj. Malthaner
*/
void age_messages(long delta_t);
void age_messages(uint32 delta_t);

/* Handles player colors ...
* @author prissi
Expand Down
2 changes: 1 addition & 1 deletion simcity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ void stadt_t::change_size( sint64 delta_citizen, bool new_town)
}


void stadt_t::step(long delta_t)
void stadt_t::step(uint32 delta_t)
{
settings_t const& s = welt->get_settings();
// recalculate factory going ratios where necessary
Expand Down
2 changes: 1 addition & 1 deletion simcity.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class stadt_t
void set_citygrowth_yesno( bool ng ) { allow_citygrowth = ng; }
bool get_citygrowth() const { return allow_citygrowth; }

void step(long delta_t);
void step(uint32 delta_t);

void neuer_monat( bool recalc_destinations );

Expand Down
4 changes: 2 additions & 2 deletions simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void convoi_t::add_running_cost( const weg_t *weg )
/* Calculates (and sets) new akt_speed
* needed for driving, entering and leaving a depot)
*/
void convoi_t::calc_acceleration(long delta_t)
void convoi_t::calc_acceleration(uint32 delta_t)
{
if( !recalc_data && abs( akt_speed_soll-akt_speed) < 24 ) {
// very close to max speed => go with max speed and finish calculation here
Expand Down Expand Up @@ -794,7 +794,7 @@ int convoi_t::get_vehicle_at_length(uint16 length)


// moves all vehicles of a convoi
bool convoi_t::sync_step(long delta_t)
bool convoi_t::sync_step(uint32 delta_t)
{
// still have to wait before next action?
wait_lock -= delta_t;
Expand Down
4 changes: 2 additions & 2 deletions simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class convoi_t : public sync_steppable, public overtaker_t
/* Calculates (and sets) akt_speed
* needed for driving, entering and leaving a depot)
*/
void calc_acceleration(long delta_t);
void calc_acceleration(uint32 delta_t);

/*
* struct holds new financial history for convoi
Expand Down Expand Up @@ -605,7 +605,7 @@ class convoi_t : public sync_steppable, public overtaker_t
* all other stuff => convoi_t::step()
* @author Hj. Malthaner
*/
bool sync_step(long delta_t);
bool sync_step(uint32 delta_t);

/**
* All things like route search or laoding, that may take a little
Expand Down
12 changes: 6 additions & 6 deletions simevent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ void change_drag_start(int x, int y)
static void fill_event(event_t* const ev)
{
// Knightly : variables for detecting double-clicks and triple-clicks
const unsigned long interval = 400;
const uint32 interval = 400;
static unsigned int prev_ev_class = EVENT_NONE;
static unsigned int prev_ev_code = 0;
static unsigned long prev_ev_time = 0;
static uint32 prev_ev_time = 0;
static unsigned char repeat_count = 0; // number of consecutive sequences of click-release

// for autorepeat buttons we track button state, press time and a repeat time
// code by Niels Roest and Hj. Maltahner

static int pressed_buttons = 0; // assume: at startup no button pressed (needed for some backends)
static unsigned long lb_time = 0;
static long repeat_time = 500;
static uint32 lb_time = 0;
static uint32 repeat_time = 500;

ev->ev_class = EVENT_NONE;

Expand Down Expand Up @@ -155,7 +155,7 @@ static void fill_event(event_t* const ev)
}

// Knightly : check for double-clicks and triple-clicks
const unsigned long curr_time = dr_time();
const uint32 curr_time = dr_time();
if( ev->ev_class==EVENT_CLICK ) {
if( prev_ev_class==EVENT_RELEASE && prev_ev_code==ev->ev_code && curr_time-prev_ev_time<=interval ) {
// case : a mouse click which forms an unbroken sequence with the previous clicks and releases
Expand Down Expand Up @@ -210,7 +210,7 @@ static void fill_event(event_t* const ev)
* disabling the repeat feature for non-left buttons
*/
if (pressed_buttons == MOUSE_LEFTBUTTON) {
if (curr_time > lb_time + repeat_time) {
if (curr_time - lb_time > repeat_time) {
repeat_time = 100;
lb_time = curr_time;
ev->ev_class = EVENT_REPEAT;
Expand Down
2 changes: 1 addition & 1 deletion simfab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ bool fabrik_t::is_active_lieferziel( koord k ) const



void fabrik_t::step(long delta_t)
void fabrik_t::step(uint32 delta_t)
{
if( delta_t==0 ) {
return;
Expand Down
2 changes: 1 addition & 1 deletion simfab.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class fabrik_t

sint32 liefere_an(const ware_besch_t *, sint32 menge);

void step(long delta_t); // fabrik muss auch arbeiten
void step(uint32 delta_t); // fabrik muss auch arbeiten
void neuer_monat();

char const* get_name() const;
Expand Down
Loading

0 comments on commit 02e0e6f

Please sign in to comment.