Example #1
0
void *
flowgen_receive_thread (void * param)
{
	int sock, ret, cnt;
	char buf[2048];
	struct sockaddr_in saddr_in;

	D ("Init receive thread");

	if ((sock = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
		D ("failed to create receive UDP socket");
		perror ("socket");
		exit (1);
	}
	
	if (IS_V())
		D ("receive UDP socket is %d", sock);


	memset (&saddr_in, 0, sizeof (saddr_in));
	saddr_in.sin_family = AF_INET;
	saddr_in.sin_port = htons (DSTPORT);
	saddr_in.sin_addr.s_addr = INADDR_ANY;
	
	if (bind (sock, (struct sockaddr *)&saddr_in, sizeof (saddr_in)) < 0) {
		D ("failed to bind receive socket");
		perror ("bind");
		exit (1);
	}

	cnt = 0;

	D ("waiting packet...");
	while (1) {

		ret = recv (sock, buf, sizeof (buf), 0);
		
		if (ret < 0) {
			D ("packet recv failed");
			perror ("recv");
			exit (1);
		}

		if (IS_V())
			D ("%d: [%lu] receive %d bytes packet", 
			   ++cnt, time (NULL), ret);
	}

	return NULL;
}
bool GraphicClass29::RenderReflectionToTexture()
{
	D3DXMATRIX refview, world, proj;
	bool result;

	_reftex->SetRenderTarget(_D3D->GetDeviceContext(), _D3D->GetDepthStencilView());

	_reftex->ClearRenderTarget(_D3D->GetDeviceContext(), _D3D->GetDepthStencilView(), 0, 0, 0, 1);

	_camera->RenderReflection(_waterh);

	refview = _camera->GetReflectionViewMatrix();

	_D3D->GetWorldMatrix(world);
	_D3D->GetProjectionMatrix(proj);

	D3DXMatrixTranslation(&world, 0, 6, 8);

	_wallmodel->Render(_D3D->GetDeviceContext());

	IS_V(_lightshader->Render(_D3D->GetDeviceContext(), _wallmodel->GetIndexCount(), world, refview, proj, _wallmodel->GetTexture(), _light->GetDirection(), _light->GetAmbientColor(), _light->GetDiffuseColor(), _camera->GetPosition(), D3DXVECTOR4(1, 1, 1, 1), 0.15f));

	_D3D->SetBackBufferRenderTarget();

	return true;
}
bool GraphicClass29::RenderRefractionToTexture()
{
	D3DXVECTOR4 clipPlane;
	D3DXMATRIX world, view, proj;

	bool result;

	clipPlane = D3DXVECTOR4(0, -1, 0, _waterh + 0.1f);

	_refractex->SetRenderTarget(_D3D->GetDeviceContext(), _D3D->GetDepthStencilView());

	_refractex->ClearRenderTarget(_D3D->GetDeviceContext(), _D3D->GetDepthStencilView(),0,0,0,1);

	_camera->Render();

	_D3D->GetWorldMatrix(world);
	_camera->GetViewMatrix(view);
	_D3D->GetProjectionMatrix(proj);

	D3DXMatrixTranslation(&world, 0, 2, 0);

	_bathmodel->Render(_D3D->GetDeviceContext());

	IS_V(_refractShader->Render(_D3D->GetDeviceContext(), _bathmodel->GetIndexCount(), world, view, proj, _bathmodel->GetTexture(), _light->GetDirection(), _light->GetAmbientColor(), _light->GetDiffuseColor(), clipPlane));	

	_D3D->SetBackBufferRenderTarget();

	return true;
}
Example #4
0
void
flowgen_udp_start (void)
{
	int n, ret, len;
	char * pkt;

#ifdef POLL
	struct pollfd x[1];
	x[0].fd = flowgen.socket;
	x[0].events = POLLOUT;
#endif

	pkt = (char *) (flowgen.pkt + sizeof (struct ip) + 
			sizeof (struct udphdr));
	len = flowgen.pkt_len - sizeof (struct ip) - sizeof (struct udphdr);

	if (flowgen.count) {
		D ("xmit %d packets", flowgen.count);
	}

	while (1) {
		for (n = 0; n < flowgen.port_list_len; n++) {
#ifdef POLL
			poll (x, 1, -1);
#endif

#ifdef UDPCONNECT
			ret = write (flowgen.socket, pkt, len);
#else
			ret = sendto (flowgen.socket, pkt, len, 0,
				      (struct sockaddr *) &flowgen.saddr_in,
				      sizeof (struct sockaddr_in));
#endif

			if (IS_V()) {
				time_t now;
				now = time (NULL);
				D ("[%lu] %d: send %d bytes port %d",
				   now, ++cnt, ret, flowgen.port_list[n]);
			}

			if (flowgen.count) {
				flowgen.count--;
				if (flowgen.count == 0) 
					exit (1);
			}

			if (ret < 0) {
				perror ("send");
				break;
			}

			if (flowgen.interval)
				usleep (flowgen.interval);
		}
	}

	return;
}
Example #5
0
void
flowgen_socket_init (void)
{
	int sock, on = 1;


	/* fill sock addr */
	flowgen.saddr_in.sin_addr = flowgen.daddr;
	flowgen.saddr_in.sin_family = AF_INET;
	flowgen.saddr_in.sin_port = htons (DSTPORT);


	if (flowgen.udp_mode) {
		if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
			D ("failed to create udp socket");
			perror ("socket");
			exit (1);
		}
#ifdef UDPCONNECT
		struct sockaddr_in saddr_in;
		memset (&saddr_in, 0, sizeof (saddr_in));
		saddr_in.sin_family = AF_INET;
		saddr_in.sin_addr.s_addr = INADDR_ANY;

		D ("bind");
		if (bind (sock, (struct sockaddr *)&saddr_in,
			  sizeof (struct sockaddr_in)) < 0)
			perror ("bind");

		D ("connect");
		if (connect (sock, (struct sockaddr *)&flowgen.saddr_in, 
			     sizeof (struct sockaddr_in)) < 0)
			perror ("connect");
#endif
		flowgen.socket = sock;
		return;
	}

	/* create raw socket */
	if ((sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
		D ("failed to create raw socket");
		perror ("socket");
		exit (1);
	}

	if (setsockopt (sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on)) < 0) {
		D ("failed to set sockopt HDRINCL");
		perror ("setsockopt");
		exit (1);
	}
		
	if (IS_V()) 
		D ("raw socket is %d", sock);

	flowgen.socket = sock;

	return;
}
bool GraphicClass29::RenderScene()
{
	D3DXMATRIX world, view, proj, refmat;
	bool result = true;

	_D3D->BeginScene(0, 0, 0, 1);

	_camera->Render();

	_D3D->GetWorldMatrix(world);
	_camera->GetViewMatrix(view);
	_D3D->GetProjectionMatrix(proj);

	D3DXMatrixTranslation(&world, 0, 1, 0);

	_groundmodel->Render(_D3D->GetDeviceContext());

	IS_V(_lightshader->Render(_D3D->GetDeviceContext(), _groundmodel->GetIndexCount(), world, view, proj, _groundmodel->GetTexture(), _light->GetDirection(), _light->GetAmbientColor(), _light->GetDiffuseColor(), _camera->GetPosition(), D3DXVECTOR4(1, 1, 1, 1), 0.15f));	

	_D3D->GetWorldMatrix(world);

	D3DXMatrixTranslation(&world, 0, 6, 8);

	//_wallmodel->Render(_D3D->GetDeviceContext());

	//IS_V(_lightshader->Render(_D3D->GetDeviceContext(), _wallmodel->GetIndexCount(), world, view, proj, _wallmodel->GetTexture(), _light->GetDirection(), _light->GetAmbientColor(), _light->GetDiffuseColor(), _camera->GetPosition(), D3DXVECTOR4(1, 1, 1, 1), 0.15f));

	_D3D->GetWorldMatrix(world);

	//D3DXMatrixTranslation(&world, 0, 2, 0);

	//_bathmodel->Render(_D3D->GetDeviceContext());

	//IS_V(_lightshader->Render(_D3D->GetDeviceContext(), _bathmodel->GetIndexCount(), world, view, proj, _bathmodel->GetTexture(), _light->GetDirection(), _light->GetAmbientColor(), _light->GetDiffuseColor(), _camera->GetPosition(), D3DXVECTOR4(1, 1, 1, 1), 0.15f));


	_D3D->GetWorldMatrix(world);

	refmat = _camera->GetReflectionViewMatrix();

	D3DXMatrixTranslation(&world, 0, _waterh, 0);

	//_watermodel->Render(_D3D->GetDeviceContext());

	//result = _watershader->Render(_D3D->GetDeviceContext(), _watermodel->GetIndexCount(), world, view, proj, refmat, _reftex->GetShaderResourceView(), _refractex->GetShaderResourceView(), _watermodel->GetTexture(), _waterTrans, 0.01);

	if (!result)
	{
		return false;
	}

	_D3D->EndScene();

	return true;


}
Example #7
0
void
flowgen_start (void)
{
	int n, ret;
	struct udphdr * udp;

	udp = (struct udphdr *) (flowgen.pkt + sizeof (struct ip));

	if (flowgen.count) {
		D ("xmit %d packets", flowgen.count);
	}

	while (1) {
		for (n = 0; n < flowgen.port_list_len; n++) {
			udp->uh_sport = htons (flowgen.port_list[n]);

			ret = sendto (flowgen.socket, flowgen.pkt,
				      flowgen.pkt_len, 0,
				      (struct sockaddr *) &flowgen.saddr_in,
				      sizeof (struct sockaddr_in));

			if (IS_V()) {
				time_t now;
				now = time (NULL);
				D ("[%lu] %d: send %d bytes port %d",
				   now, ++cnt, ret, flowgen.port_list[n]);
			}

			if (flowgen.count) {
				flowgen.count--;
				if (flowgen.count == 0) 
					exit (1);
			}

			if (ret < 0) {
				perror ("send");
				break;
			}

			if (flowgen.interval)
				usleep (flowgen.interval);
		}
	}

	return;
}
Example #8
0
static void 
hangul_engine_shape (PangoEngineShape *engine,
		     PangoFont        *font,
		     const char       *text,
		     gint              length,
		     const PangoAnalysis *analysis,
		     PangoGlyphString *glyphs)
{
  int n_chars, n_glyphs;
  int i;
  const char *p, *start;

  gunichar jamos_static[8];
  gint max_jamos = G_N_ELEMENTS (jamos_static);
  gunichar *jamos = jamos_static;
  int n_jamos;

  n_chars = g_utf8_strlen (text, length);
  n_glyphs = 0;
  start = p = text;
  n_jamos = 0;

  for (i = 0; i < n_chars; i++)
    {
      gunichar wc;

      wc = g_utf8_get_char (p);

      /* Check syllable boundaries. */
      if (n_jamos)
	{
	  gunichar prev = jamos[n_jamos - 1];
	  if ((!IS_JAMO (wc) && !IS_S (wc) && !IS_M (wc)) ||
	      (!IS_L (prev) && IS_S (wc)) ||
	      (IS_T (prev) && IS_L (wc)) ||
	      (IS_V (prev) && IS_L (wc)) ||
	      (IS_T (prev) && IS_V (wc)) ||
	      IS_M (prev))
	    {
	      /* Draw a syllable with these jamos. */
	      render_syllable (font, jamos, n_jamos, glyphs,
			       &n_glyphs, start - text);
	      n_jamos = 0;
	      start = p;
	    }
	}
	  
      if (n_jamos >= max_jamos - 3)
	{
	  max_jamos += 8;	/* at most 3 for each syllable code (L+V+T) */
	  if (jamos == jamos_static)
	    {
	      jamos = g_new (gunichar, max_jamos);
	      memcpy (jamos, jamos_static, n_jamos*sizeof(gunichar));
	    }
	  else
	    jamos = g_renew (gunichar, jamos, max_jamos);
	}

      if (!IS_JAMO (wc) && !IS_S (wc) && !IS_M (wc))
	{
	  render_basic (font, wc, glyphs, &n_glyphs, start - text);
	  start = g_utf8_next_char (p);
	}
      else if (IS_S (wc))
	{
	  jamos[n_jamos++] = L_FROM_S (wc);
	  jamos[n_jamos++] = V_FROM_S (wc);
	  if (S_HAS_T (wc))
	    jamos[n_jamos++] = T_FROM_S (wc);
	}
      else if (IS_M (wc) && !n_jamos)
	{
	  /* Tone mark not following syllable */
	  render_isolated_tone (font, wc, glyphs, &n_glyphs, start - text);
	  start = g_utf8_next_char (p);
	}
      else
	jamos[n_jamos++] = wc;
      p = g_utf8_next_char (p);
    }

  if (n_jamos != 0)
    render_syllable (font, jamos, n_jamos, glyphs, &n_glyphs,
		     start - text);

  if (jamos != jamos_static)
    g_free(jamos);
}