2 #include <netinet/in.h>
4 #include <msp/gl/immediate.h>
5 #include <msp/gl/matrix.h>
6 #include <msp/gl/texture.h>
7 #include <msp/gl/transform.h>
8 #include <msp/time/units.h>
15 Host::Host(NetVis &nv, unsigned a):
20 ina.s_addr=htonl(addr);
24 void Host::set_position(const Vector2 &p)
29 void Host::add_connection(Connection &)
33 Connection *Host::get_connection(Host &)
38 void Host::tick(const Msp::Time::TimeDelta &td)
40 float dt=td/Msp::Time::sec;
42 const map<unsigned, Host *> &hosts=netvis.get_hosts();
45 for(map<unsigned, Host *>::const_iterator i=hosts.begin(); i!=hosts.end(); ++i)
49 const Vector2 &other_pos=i->second->get_position();
50 float dx=other_pos.x-pos.x;
51 float dy=other_pos.y-pos.y;
55 unsigned other_addr=i->second->get_address();
56 unsigned matching_bits=0;
57 for(unsigned j=32; (j-- && !((addr^other_addr)>>j));)
60 float nearness=24-min(matching_bits, 24U);
61 float f=10000.0*(1.0/(60+nearness*15)-1.0/d);
74 void Host::render() const
77 GL::translate(static_cast<int>(pos.x), static_cast<int>(pos.y), 0);
79 GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2));
81 imm.color(1.0f, 1.0f, 1.0f, 1.0f);
88 const GL::Font &font=netvis.get_font();
89 GL::translate(-static_cast<int>(font.get_string_width(name)*5), 6, 0);
90 GL::scale_uniform(10);
91 font.draw_string(name);
92 GL::Texture::unbind();