Ejemplo n.º 1
0
s_res		heart_dst(s_geo sp, s_cam cam, s_res prev)
{
	vec4	p;
	s_res	ret;
	int		i;
	float	step;

	step = 0.2 / 5;
	ret.dst = length(cam.pos - sp.pos) <= sp.bounds ?
		0 : sphere_dst(sp, cam, prev).dst;
	if (ret.dst == prev.dst)
		return (prev);
	p.xyz = cam.pos + ret.dst * cam.ray;
	p.w = heart((p.xyz - sp.pos) * 5 / sp.bounds);
	i = -1;
	while (++i < INT(30 * sp.bounds) && p.w <= 0)
	{
		p.w = heart((p.xyz - sp.pos) * 5 / sp.bounds);
		ret.dst += 0.2 / 5;
		p.xyz = cam.pos + ret.dst * cam.ray;
	}
	if (p.w < 0)
		return (prev);
	ret = end_heart(geo_cam(sp, cam), step, ret, p);
	if (prev.dst > 0 && ret.dst > prev.dst)
		return (prev);
	return (ret);
}
Ejemplo n.º 2
0
void GUI::draw(sf::RenderTarget* renderer)
{
    sf::Texture* heartTex = ResourceManager<Sprite>::instance().get("heart")->tex();
    sf::Sprite heart(*heartTex); heart.setOrigin(25, 22);
    for (int life(0); life<_player->getLife(); ++life)
    {
        heart.setPosition(_width-29, _height-29*(life+1));
        renderer->draw(heart);
    }

    _text.setPosition(10, _height-100);
    _text.setString(numberToString(_player->getScore()));
    _text.setColor(sf::Color::White);
    renderer->draw(_text);

    _text.setPosition(10, _height-40);
    _text.setString(numberToString(_player->getAccuracy())+" %");
    _text.setColor(sf::Color::White);
    renderer->draw(_text);

    if (_paused)
    {
        sf::RectangleShape hide(sf::Vector2f(_width, _height));
        hide.setFillColor(sf::Color(0, 0, 0, 200));
        _text.setString("PAUSE");
        _text.setPosition(_width/2-_text.getGlobalBounds().width/2, 200);

        renderer->draw(hide);
        renderer->draw(_text);
    }
}
Ejemplo n.º 3
0
	void App::timer()
	{
		if(m_conn_state.connect_daemon != Client_State_t::CONNECT)
		{
			if(!m_pDaemonClient.get()) throw Exception("m_pDaemonClient is null");

			m_pDaemonClient->connect();
			return;
		}

		if(m_conn_state.connect_master_daemon != Client_State_t::CONNECT)
		{
			updateMasterDeamon();
			return;
		}

		if(m_conn_state.regMasterDaemon != Client_State_t::OK)
		{
			register_to_daemonserver();
			return;
		}

		heart();

		printf("%s ,%s\n",__FUNCTION__,"runing");
	}
Ejemplo n.º 4
0
void psNetConnection::CheckLinkDead (csTicks currenttime)
{
    if (currenttime - server->lastRecvPacketTime > LINKDEAD_TIMEOUT)
    {
        if (server->heartbeat < LINKDEAD_ATTEMPTS)
        {
            server->heartbeat++;
            psHeartBeatMsg heart((uint32_t)0);
            SendMessage(heart.msg);  // This should cause an ack to update the timestamp
        }
        else
        {
            // Simulate message to self to inform user of quitting.
            psSystemMessage quit(0,MSG_INFO,"Server is not responding, try again in 5 minutes. Exiting PlaneShift...");
            HandleCompletedMessage(quit.msg, server, &server->addr,NULL);
            
            csSleep(1000);
            
            // If no packets received ever, then use -1 to indicate cannot connect
            psDisconnectMessage msgb(0,server->pcknumin?0:-1,
                                     server->pcknumin?
                                     "Server is not responding, try again in 5 minutes. "
                                     "Check http://laanx.fragnetics.com/ for status.":
                                     "The server is not running or is not reachable.  "
                                     "Please check http://laanx.fragnetics.com/ or forums for more info.");
            HandleCompletedMessage(msgb.msg, server, &server->addr,NULL);
        }
    }
    else
    {
        server->heartbeat = 0;
    }
}
Ejemplo n.º 5
0
//--------------------------------------------------------------
void testApp::draw(){
    ofFill();
    ofSetColor(100, 10, 10, 10);
    ofRect(0, 0, ofGetWidth(), ofGetHeight());
    
    int numb_of_objects = NUM_SIDES;
    int dist = 150;
    angle_inc = TWO_PI / numb_of_objects;


    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

    //CENTRAL HEART
    ofPushMatrix();
        ofScale(2, 2);
        heart(0, 0, 60, 60);
    ofPopMatrix();
    
    //DRAWING A LOT OF MyShapes01
    ofRotate(myRotation);
    for (int i=0; i<numb_of_objects; i++) {

        float offsetX = cos(angle_inc * i) * dist;
        float offsetY = sin(angle_inc * i) * dist;
    
        ofPushMatrix();
            myShape01(offsetX, offsetY, 50, 50*i);
        ofPopMatrix();
    
    }

    
    
}
Ejemplo n.º 6
0
void airbear::listen(){
  connection();
  heart();
  cross();
  circle();
  cancelbutton();
  spirit(10,10,10);
  loop();
}
Ejemplo n.º 7
0
TYPED_TEST_P(HeartBeatTest, BrokenConnection) 
{
    typedef TypeParam socket;
    auto log = redhorn::logging::get_logger("main");

    redhorn::signals signals;
    redhorn::iopool pool(redhorn::logging::get_logger("iopool"));
    redhorn::heart_beat heart(redhorn::logging::get_logger("heart"),
                              std::chrono::milliseconds(20),
                              std::chrono::milliseconds(20));
    
    signals.set_handler(SIGPIPE, [](){});
    signals.start();
    pool.start(2);
    heart.start();

    redhorn::listener listener(port);

    socket conn_sock;
    std::thread connect_thread(connect_pong_thread<socket>,
                               redhorn::logging::get_logger("connect_thread"),
                               std::ref(conn_sock));

    log.info("accepting");
    socket sock = listener.accept<socket>();
    connect_thread.join();
    
    ASSERT_TRUE(static_cast<bool>(sock));

    log.info("accepted");

    pool.bind(sock);
    heart.bind(sock, 
               std::chrono::milliseconds(20),
               std::function<message()>(drummer));

    conn_sock.close();
    EXPECT_THROW(sock.recv(), std::exception);
    log.info("before assert");
    ASSERT_FALSE(static_cast<bool>(sock));
    log.info("after assert");


    heart.unbind(sock);
    pool.unbind(sock);
    
    heart.stop();
    pool.stop();
    signals.stop();
    heart.wait();
    pool.wait();
    signals.wait();
    
}
Ejemplo n.º 8
0
vec3		heart_grad(vec3 p)
{
	vec2	q;

	q = VEC2(0.0, 0.006);
	return (VEC3(heart(p + q.yxx) - heart(p - q.yxx),
			heart(p + q.xyx) - heart(p - q.xyx),
			heart(p + q.xxy) - heart(p - q.xxy)));
}
Ejemplo n.º 9
0
s_res		end_heart(s_geo_cam gc, float step, s_res ret, vec4 p)
{
	float	tmp;
	int		i;

	i = 0;
	step = -step / 2;
	while (++i < 20)
	{
		ret.dst += step;
		p.xyz = gc.cam.pos + ret.dst * gc.cam.ray;
		tmp = p.w;
		p.w = heart((p.xyz - gc.sp.pos) * 5 / gc.sp.bounds);
		if (sign(tmp) != sign(p.w))
			step = -step / 2;
	}
	ret.cam = gc.cam;
	ret.mat = gc.sp.mat;
	ret.normal = normalize(-heart_grad((p.xyz - gc.sp.pos) * 5 / gc.sp.bounds));
	return (ret);
}
Ejemplo n.º 10
0
TYPED_TEST_P(HeartBeatTest, Ping) 
{
    typedef TypeParam socket;
    auto log = redhorn::logging::get_logger("main");

    redhorn::iopool pool(redhorn::logging::get_logger("iopool"));
    redhorn::heart_beat heart(redhorn::logging::get_logger("heart"),
                              std::chrono::milliseconds(20),
                              std::chrono::milliseconds(20));
    
    pool.start(2);
    heart.start();

    redhorn::listener listener(port);

    std::thread connect_thread(connect_ping_thread<socket>, redhorn::logging::get_logger("connect_thread"));

    log.info("accepting");
    socket sock = listener.accept<socket>();
    ASSERT_TRUE(static_cast<bool>(sock));

    log.info("accepted");

    pool.bind(sock);
    heart.bind(sock, 
               std::chrono::milliseconds::zero(),
               std::function<message()>(drummer));

    log.info("joining");
    connect_thread.join();
    log.info("joined");
    heart.unbind(sock);

    heart.stop();
    pool.stop();
    heart.wait();
    pool.wait();
    
}
Ejemplo n.º 11
0
int main(void)
{
	int status;
	int sd;
	struct packet_st pkt;
	struct sockaddr_in myend, hisend;
	socklen_t hislen;
	int val;
	int ret;
	int recv_len;

	database_init();

	sd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sd == -1) {
		perror("socket()");
		goto socket_err;
	}

	val = 1;
	setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

	myend.sin_family = AF_INET;
	myend.sin_port = SERVER_PORT;
	myend.sin_addr.s_addr = INADDR_ANY;
	ret = bind(sd, (struct sockaddr *)&myend, sizeof(myend));
	if (ret == -1) {
		perror("bind()");
		goto bind_err;
	}

	hislen = sizeof(hisend);
	status = ST_RECV;
	while (status != ST_QUIT) {
		switch (status) {
		case ST_RECV:
			recv_len = recvfrom(sd, &pkt, sizeof(pkt), 0, (struct sockaddr *)&hisend, &hislen);
			if (recv_len == -1) {
				status = ST_ERROR;
				break;
			}
			if (pkt.major == MAJOR_LOGIN) {
				status = ST_LOGIN;
			} else if (pkt.major == MAJOR_MESSAGE) {
				status = ST_MSG;
			} else if (pkt.major == MAJOR_LIST) {
				status = ST_LIST;
			} else if (pkt.major == MAJOR_HEART) {
				status = ST_HEART;
			} else if (pkt.major == MAJOR_MANAGE) {
				/* fix me */
				status = ST_RECV;
			} else if (pkt.major == MAJOR_ERROR) {
				status = ST_ERROR;
			} else {
				status = ST_ERROR;
			}
			break;
		case ST_LOGIN:
			ret = login(sd, &pkt, recv_len, &hisend);
			if (ret == 0) {
				status = ST_RECV;
			} else {
				status = ST_ERROR;
			}
			break;
		case ST_MSG:
			message(sd, &pkt, recv_len, &hisend);
			status = ST_RECV;
			break;
		case ST_LIST:
			list(sd, &pkt, recv_len, &hisend);
			status = ST_RECV;
			break;
		case ST_HEART:
			heart(sd, &pkt, recv_len, &hisend);
                        status = ST_RECV;
			break;
		case ST_ERROR:
			/* fix me */
			status = ST_QUIT;
			break;
		}
	}

	close(sd);
	database_destroy();

	return 0;




bind_err:
	close(sd);
socket_err:
	database_destroy();
	return 1;
}