X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fhost.cpp;h=991e7741a04eb9a4acef1292992c707f08456b40;hb=69bcc0683c313b952981a50a6d66a6ee218ba755;hp=e5eafc899fd98db7bd9d851fb208b237f72b1619;hpb=f3939c5da4add9af55a26293c99f0f013052cc25;p=netvis.git diff --git a/source/host.cpp b/source/host.cpp index e5eafc8..991e774 100644 --- a/source/host.cpp +++ b/source/host.cpp @@ -28,108 +28,108 @@ Host::Host(NetVis &nv, unsigned a): throttle(0) { in_addr ina; - ina.s_addr=htonl(addr); - name=inet_ntoa(ina); - short_name=name; + ina.s_addr = htonl(addr); + name = inet_ntoa(ina); + short_name = name; } void Host::set_name(const string &n) { - name=n; + name = n; if(local) { - unsigned dot=name.find('.'); - short_name=name.substr(0, dot); + unsigned dot = name.find('.'); + short_name = name.substr(0, dot); } else { - unsigned dot=name.size(); + unsigned dot = name.size(); for(unsigned i=0; (dot>0 && dot!=string::npos); ++i) { - unsigned prev=name.rfind('.', dot-1); + unsigned prev = name.rfind('.', dot-1); if(prev+151) break; - dot=prev; + dot = prev; } if(dot==string::npos) - short_name=name; + short_name = name; else - short_name="..."+name.substr(dot+1); + short_name = "..."+name.substr(dot+1); } } void Host::set_local(bool l) { - local=l; + local = l; } void Host::set_position(const Vector2 &p) { - pos=p; + pos = p; } void Host::set_active(bool a) { - active=a; + active = a; } void Host::add_activity(unsigned bytes) { - activity+=bytes*0.06935; + activity += bytes*0.06935; } float Host::send_packet() { - float ret=throttle; + float ret = throttle; if(throttle<1) - throttle+=0.025; + throttle += 0.025; return ret; } void Host::tick(const Msp::Time::TimeDelta &td) { - float dt=td/Msp::Time::sec; + float dt = td/Msp::Time::sec; - activity*=pow(0.933f, dt); - throttle-=dt; + activity *= pow(0.933f, dt); + throttle -= dt; if(throttle<0) - throttle=0; + throttle = 0; if(!active) return; - const map &hosts=netvis.get_hosts(); - float fx=-pos.x*0.1; - float fy=-pos.y*0.1; + const map &hosts = netvis.get_hosts(); + float fx = -pos.x*0.1; + float fy = -pos.y*0.1; for(map::const_iterator i=hosts.begin(); i!=hosts.end(); ++i) { if(i->second!=this) { - const Vector2 &other_pos=i->second->get_position(); - float dx=other_pos.x-pos.x; - float dy=other_pos.y-pos.y; - float d2=dx*dx+dy*dy; - float d=sqrt(d2); - - unsigned other_addr=i->second->get_address(); - unsigned matching_bits=0; + const Vector2 &other_pos = i->second->get_position(); + float dx = other_pos.x-pos.x; + float dy = other_pos.y-pos.y; + float d2 = dx*dx+dy*dy; + float d = sqrt(d2); + + unsigned other_addr = i->second->get_address(); + unsigned matching_bits = 0; for(unsigned j=32; (j-- && !((addr^other_addr)>>j));) ++matching_bits; - float optimal_dist=100+(24-min(matching_bits, 24U))*12; - float f=5000.0*(1.0/optimal_dist-1.0/d); + float optimal_dist = 100+(24-min(matching_bits, 24U))*12; + float f = 5000.0*(1.0/optimal_dist-1.0/d); - fx+=dx/d*f; - fy+=dy/d*f; + fx += dx/d*f; + fy += dy/d*f; } } if(fx<-4 || fx>4) - pos.x+=fx*dt; + pos.x += fx*dt; if(fy<-4 || fy>4) - pos.y+=fy*dt; + pos.y += fy*dt; } void Host::render() const @@ -157,7 +157,7 @@ void Host::render_label() const if(!active) return; - const GL::Font &font=netvis.get_font(); + const GL::Font &font = netvis.get_font(); GL::push_matrix(); GL::translate(static_cast(pos.x)-static_cast(font.get_string_width(short_name)*5), static_cast(pos.y)+6, 0);