]> git.tdb.fi Git - netvis.git/blobdiff - source/host.cpp
Keep the local network in the center
[netvis.git] / source / host.cpp
index 4314d75f63714c01c5a7e3f5f1ac42f9df06c9ae..fca3a304e545d29eefafd8201958020c92b6470e 100644 (file)
@@ -24,7 +24,6 @@ Host::Host(NetVis &nv, unsigned a):
        addr(a),
        local(false),
        active(true),
-       activity(0),
        throttle(0)
 {
        in_addr ina;
@@ -77,7 +76,7 @@ void Host::set_active(bool a)
 
 void Host::add_activity(unsigned bytes)
 {
-       activity += bytes*0.06935;
+       activity.add_bytes(bytes);
 }
 
 float Host::send_packet()
@@ -92,7 +91,7 @@ void Host::tick(const Msp::Time::TimeDelta &td)
 {
        float dt = td/Msp::Time::sec;
 
-       activity *= pow(0.933f, dt);
+       activity.tick(td);
        throttle -= dt;
        if(throttle<0)
                throttle = 0;
@@ -101,8 +100,9 @@ void Host::tick(const Msp::Time::TimeDelta &td)
                return;
 
        const map<unsigned, Host *> &hosts = netvis.get_hosts();
-       float fx = -pos.x*0.1;
-       float fy = -pos.y*0.1;
+       float center_force = (local ? 0.5 : 0.1);
+       float fx = -pos.x*center_force;
+       float fy = -pos.y*center_force;
        for(map<unsigned, Host *>::const_iterator i=hosts.begin(); i!=hosts.end(); ++i)
        {
                if(i->second!=this)
@@ -142,7 +142,7 @@ void Host::render() const
 
        GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
        imm.begin(GL::QUADS);
-       imm.color(1.0f, 1.0f, 1.0f, max(min(static_cast<float>(activity/10000), 1.0f), 0.2f));
+       imm.color(1.0f, 1.0f, 1.0f, max(min(static_cast<float>(activity.get_average()/10000), 1.0f), 0.2f));
        imm.vertex(-5, -5);
        imm.vertex(5, -5);
        imm.vertex(5, 5);
@@ -156,6 +156,4 @@ void Host::render() const
        imm.color(1.0f, 1.0f, 1.0f);
        font.draw_string(short_name, imm);
        GL::Texture::unbind();
-
-       GL::pop_matrix();
 }