void DirectIP::OnKeyDown(const ::SDL_KeyboardEvent& key) { switch(key.keysym.sym) { case SDLK_UP: if(!addr.empty()) SetNextActivity(new Fade(new Game(true, addr, connection_ptr()), world, eye), true); break; case SDLK_DOWN: if(!addr.empty()) SetNextActivity(new Fade(new Game(false, addr, connection_ptr()), world, eye), true); break; case SDLK_ESCAPE: SetNextActivity(new Fade(new Menu, world, eye), true); break; default: break; } // Hantera input, sortera bort oönskade tecken. HandleInput(key, addr); addr = StripCharacters(addr, "abcdefghijklmnopqrstuvwxyz,!?+-:/ ="); if(addr.size() >= max_addr_len) addr = addr.substr(0, max_addr_len); world[0] = object_ptr(new Text(addr, Letter(Size(0.05,0.07,0.0), 0.03, 2.5, Color(0,0,0)), Point(2.4, 2, 1+MILLI), Size(1.3, 0.2,0), Color(0.3,0.3,0.3), Rotation(), false)); }
comm_server::comm_server(std::vector<std::string> zkhosts, std::string name, std::string alternate_bind_address, std::string alternate_control_address, std::string alternate_publish_address, std::string secret_key): started(false), comm_server_debug_mode(std::getenv("GRAPHLAB_COMM_SERVER_DEBUG_MODE") != NULL) { object_socket = new nanosockets::async_reply_socket( boost::bind(&comm_server::callback, this, _1, _2), 1, // 2 threads. one to handle pings, one to handle real messages alternate_bind_address); if(alternate_bind_address.size() == 0) { alternate_bind_address = object_socket->get_bound_address(); } logstream(LOG_INFO) << "my alt bind address: " << alternate_bind_address << std::endl; control_socket = new nanosockets::async_reply_socket( boost::bind(&comm_server::callback, this, _1, _2), 1, (alternate_control_address.length()==0) ? generate_aux_address(alternate_bind_address, "_control") : alternate_control_address); publishsock = new nanosockets::publish_socket( (alternate_publish_address.length()==0) ? generate_aux_address(alternate_bind_address, "_status") : alternate_publish_address); get_srv_running_command().store(0); get_cancel_bit_checked().store(false); logstream(LOG_EMPH) << "Server listening on: " << object_socket->get_bound_address() << std::endl; logstream(LOG_INFO) << "Server Control listening on: " << control_socket->get_bound_address() << std::endl; logstream(LOG_INFO) << "Server status published on: " << publishsock->get_bound_address() << std::endl; // there is a chicken and egg problem here. We can't use the object // factory to create the object factory. So, here it is: manual construction // and registration of the object factory object_factory = new object_factory_impl(*this); register_type<object_factory_base>([&]() { return new object_factory_impl(*this); } ); auto deleter = +[](void* v) { if (v != NULL) { delete reinterpret_cast<object_factory_impl*>(v); } }; std::shared_ptr<void> object_ptr(object_factory, deleter); registered_objects.insert({0, object_ptr}); std::random_device rd; lcg_seed = (size_t(rd()) << 32) + rd(); }
object_ptr object_source::extract_object(const object_handle& h, ptree_ptr metadata) const { object_ptr obj = object_ptr(new object(h.m_name, h.m_version, metadata)); bp::ptree& meta = *metadata; extract_requires(meta, obj->m_requires); // remove redundant data from metadata meta.erase(g_default_name_key); meta.erase(g_default_version_key); for(unsigned int i=0; i<m_settings.m_requires_keys.size(); ++i) meta.erase(m_settings.m_requires_keys[i]); return obj; }
DirectIP::DirectIP() { max_addr_len = 15; eye.position = Point(2.0, 2.0, 5.0); world.push_back(object_ptr(new Text())); world.push_back(object_ptr(new Body(Point(2, 3, 0.9), Size(0.9, 0.3, 0.2), Color(1,1,1), CUBE_BORDERED))); // Övre rutan world.push_back(object_ptr(new Body(Point(2, 2, 0.9), Size(2.3, 0.3, 0.2), Color(1,1,1), CUBE_BORDERED))); // Inputrutan world.push_back(object_ptr(new Body(Point(2, 1, 0.9), Size(0.9, 0.3, 0.2), Color(1,1,1), CUBE_BORDERED))); // Undre rutan world.push_back(object_ptr(new Text("PLAYER 1", Letter(Size(0.07,0.15,0.0), 0.03, 2.5, Color(0,0,0)), Point(2, 3, 1.1+MILLI)))); world.push_back(object_ptr(new Text("PLAYER 2", Letter(Size(0.07,0.15,0.0), 0.03, 2.5, Color(0,0,0)), Point(2, 1, 1.1+MILLI)))); world.push_back(object_ptr(new Text("IP:", Letter(Size(0.07,0.15,0.0), 0.03, 2.5, Color(0,0,0)), Point(1.3, 2, 1+MILLI)))); }
void DDObject::AddChild( DDObject* object, int alphaIndex) { auto deleter = DeleteAlignedClass; std::shared_ptr<DDObject> object_ptr( object, deleter ); object->SetParent( this ); if ( 0 != alphaIndex ) { object_ptr->SetAlphaIndex( alphaIndex ); m_AhphaChildList.push_back( object_ptr ); m_AhphaChildList.sort( []( std::shared_ptr<DDObject> a, std::shared_ptr<DDObject> b ) -> bool { return ( a->GetAlphaIndex() < b->GetAlphaIndex() ) ? true : false; } ); return ; } m_NormalChildList.push_back( object_ptr ); }
void world::update_missiles(int dt, const hit_hunction &on_hit) { m_missiles.erase(std::remove_if(m_missiles.begin(), m_missiles.end(), [](const missile_ptr &m){ return m.unique(); }), m_missiles.end()); for (auto &m: m_missiles) { m->update(dt); const auto pt = m->pos + m->vel * (dt * 0.001f); bool hit = pt.y < get_height(pt.x, pt.z, false) + 1.0f; if (!hit) { static std::vector<int> insts; if (m_qtree.get_objects(pt, insts)) { for (auto &i:insts) { const auto &mi = m_instances[i]; auto lpt = mi.transform_inv(pt), lpf = mi.transform_inv(m->pos); auto &m = m_meshes[mi.mesh_idx]; if (!m.bbox.test_intersect(lpt)) continue; if(!m.trace(lpf, lpt)) continue; hit = true; break; } } } if (hit) { //m->pos -= m->vel * (dt * 0.001f); m->vel = vec3(); if (on_hit) on_hit(std::static_pointer_cast<object>(m), object_ptr()); } } }
void world::update_planes(int dt, const hit_hunction &on_hit) { m_planes.erase(std::remove_if(m_planes.begin(), m_planes.end(), [](const plane_ptr &p){ return p.unique(); }), m_planes.end()); for (auto &p: m_planes) { p->update(dt); const auto pt = p->pos + p->vel * (dt * 0.001f); const auto pt_nose = pt + p->rot.rotate(p->nose_offset); auto wing_offset2 = p->wing_offset; wing_offset2.x = -wing_offset2.x; //will not work for AD-1, lol const auto pt_wing = pt + p->rot.rotate(p->wing_offset); const auto pt_wing2 = pt + p->rot.rotate(wing_offset2); const float r = nya_math::max(p->nose_offset.length(), p->wing_offset.length()) * 1.5; nya_math::aabb box; box.origin = pt; box.delta.set(r, r, r); bool hit = pt.y < get_height(pt.x, pt.z, false) + 5.0f; if (!hit) { static std::vector<int> insts; if (m_qtree.get_objects(box, insts)) { for (auto &i:insts) { const auto &mi = m_instances[i]; const auto &m = m_meshes[mi.mesh_idx]; /* box.origin = mi.transform_inv(pt); if (!m.bbox.test_intersect(box)) continue; */ auto lpt = mi.transform_inv(pt_nose), lpf = mi.transform_inv(p->pos); if (m.trace(lpf, lpt)) { hit = true; break; } auto lwt = mi.transform_inv(pt_wing), lwt2 = mi.transform_inv(pt_wing2); if (m.trace(lwt, lwt2) || m.trace(lwt2, lwt)) //trace fails near from point { hit = true; break; } } } } if (hit) { p->vel = vec3(); if (on_hit) on_hit(std::static_pointer_cast<object>(p), object_ptr()); } /* //test get_debug_draw().clear(); static std::vector<int> insts; nya_math::aabb test; test.origin = p->pos; test.delta.set(10, 10, 10); //m_qtree.get_objects(p->pos, insts); m_qtree.get_objects(test, insts); for (auto &i: insts) get_debug_draw().add_aabb(m_instances[i].bbox); */ } }
comm_server::comm_server(std::vector<std::string> zkhosts, std::string name, std::string alternate_bind_address, std::string alternate_control_address, std::string alternate_publish_address, std::string secret_key): started(false), zmq_ctx(zmq_ctx_new()), keyval(zkhosts.empty() ? // make a keyval only if zkhosts is not empty NULL : // null otherwise new graphlab::zookeeper_util::key_value(zkhosts, "cppipc", name)), comm_server_debug_mode(std::getenv("GRAPHLAB_COMM_SERVER_DEBUG_MODE") != NULL) { object_socket = new libfault::async_reply_socket(zmq_ctx, keyval, boost::bind(&comm_server::callback, this, _1, _2), 1, // 2 threads. one to handle pings, one to handle real messages alternate_bind_address, secret_key); if(alternate_bind_address.size() == 0) { alternate_bind_address = object_socket->get_bound_address(); } logstream(LOG_INFO) << "my alt bind address: " << alternate_bind_address << std::endl; control_socket = new libfault::async_reply_socket(zmq_ctx, keyval, boost::bind(&comm_server::callback, this, _1, _2), 1, (keyval==NULL && alternate_control_address.length()==0) ? generate_aux_address(alternate_bind_address, "_control") : alternate_control_address); publishsock = new libfault::publish_socket(zmq_ctx, keyval, // honestly, this syntax is *terrible*. // If Zookeeper is not used, and alternate_publish_address not // provided, we generate one based on the bind address (keyval==NULL && alternate_publish_address.length()==0) ? generate_aux_address(alternate_bind_address, "_status") : alternate_publish_address); get_srv_running_command().store(0); get_cancel_bit_checked().store(false); pollset = new libfault::socket_receive_pollset; if (keyval != NULL && !object_socket->register_key("call")) { logstream(LOG_ERROR) << "Unable to register the zookeeper key for the main server. " "Perhaps there is already a server with this name?"; throw("Unable to register with zookeeper"); } if (keyval != NULL && !control_socket->register_key("control")) { logstream(LOG_ERROR) << "Unable to register the zookeeper key for the main server's control socket. " "Perhaps there is already a server with this name?"; throw("Unable to register with zookeeper"); } if (keyval != NULL && !publishsock->register_key("status")) { logstream(LOG_ERROR) << "Unable to register the zookeeper key for the publishsock. " "Perhaps there is already a server with this name?"; throw("Unable to register with zookeeper"); } object_socket->add_to_pollset(pollset); control_socket->add_to_pollset(pollset); logstream(LOG_EMPH) << "Server listening on: " << object_socket->get_bound_address() << std::endl; logstream(LOG_INFO) << "Server Control listening on: " << control_socket->get_bound_address() << std::endl; logstream(LOG_INFO) << "Server status published on: " << publishsock->get_bound_address() << std::endl; // there is a chicken and egg problem here. We can't use the object // factory to create the object factory. So, here it is: manual construction // and registration of the object factory object_factory = new object_factory_impl(*this); register_type<object_factory_base>([&]() { return new object_factory_impl(*this); } ); auto deleter = +[](void* v) { if (v != NULL) { delete reinterpret_cast<object_factory_impl*>(v); } }; std::shared_ptr<void> object_ptr(object_factory, deleter); registered_objects.insert({0, object_ptr}); std::random_device rd; lcg_seed = (size_t(rd()) << 32) + rd(); }