Example #1
0
/**
 * @sa Qcommon_Frame
 */
void CL_Frame (int now, void* data)
{
	static int lastFrame = 0;
	int delta;

	if (sys_priority->modified || sys_affinity->modified)
		Sys_SetAffinityAndPriority();

	/* decide the simulation time */
	delta = now - lastFrame;
	if (lastFrame)
		cls.frametime = delta / 1000.0;
	else
		cls.frametime = 0;
	cls.realtime = Sys_Milliseconds();
	cl.time = now;
	lastFrame = now;

	/* frame rate calculation */
	if (delta)
		cls.framerate = 1000.0 / delta;

	if (cls.state == ca_connected) {
		/* we run full speed when connecting */
		CL_RunHTTPDownloads();
	}

	/* fetch results from server */
	CL_ReadPackets();

	CL_SendCommand();

	IN_Frame();

	GAME_Frame();

	/* update camera position */
	CL_CameraMove();

	if (cls.state == ca_active)
		CL_ParticleRun();

	/* update the screen */
	SCR_UpdateScreen();

	/* advance local effects for next frame */
	SCR_RunConsole();

	/* LE updates */
	LE_Think();

	/* sound frame */
	S_Frame();

	/* send a new command message to the server */
	CL_SendCommand();
}
Example #2
0
/*
==================
Host_ClientFrame

==================
*/
void Host_ClientFrame( void )
{
	// if client is not active, do nothing
	if( !cls.initialized ) return;

	// decide the simulation time
	cl.oldtime = cl.time;
	cl.time += host.frametime;

	if( menu.hInstance )
	{
		// menu time (not paused, not clamped)
		menu.globals->time = host.realtime;
		menu.globals->frametime = host.realframetime;
		menu.globals->demoplayback = cls.demoplayback;
		menu.globals->demorecording = cls.demorecording;
	}

	// if in the debugger last frame, don't timeout
	if( host.frametime > 5.0f ) cls.netchan.last_received = Sys_DoubleTime();

	VGui_RunFrame ();

	clgame.dllFuncs.pfnFrame( host.frametime );

	// fetch results from server
	CL_ReadPackets();

	VID_CheckChanges();

	// allow sound and video DLL change
	if( cls.state == ca_active )
	{
		if( !cl.video_prepped ) CL_PrepVideo();
		if( !cl.audio_prepped ) CL_PrepSound();
	}

	// update the screen
	SCR_UpdateScreen ();

	// update audio
	S_RenderFrame( &cl.refdef );

	// send a new command message to the server
	CL_SendCommand();

	// predict all unacknowledged movements
	CL_PredictMovement();

	// decay dynamic lights
	CL_DecayLights ();

	SCR_RunCinematic();
	Con_RunConsole();

	cls.framecount++;
}
Example #3
0
/* 
  FIXME dont run every time, only if dlqueue is full!!!
 */
int curlFetch(struct url *ptr, int dlnum)
{

  CURLM *cm;
  CURLMsg *msg;
  long L=100;
  unsigned int C=0;
  int M, Q, U = -1;
  fd_set R, W, E;
  struct timeval T;
  CURLMcode	ret;
  qboolean got404=false;

  if (!cls.downloadServer)
	  return 0;

  curl_global_init(CURL_GLOBAL_ALL);

  cm = curl_multi_init();
  
  curl_easy_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX);

  for (C = 0; C < dlnum; ++C)
      init(cm, C);
  

  while (U) 
  {
      ret = curl_multi_perform(cm, &U);

      if (U)
	  {
        FD_ZERO(&R);
        FD_ZERO(&W);
        FD_ZERO(&E);

		if (ret != CURLM_OK)
		{
			Com_Printf ("curl_multi_perform error, Aborting HTTP downloads.\n");
			return 1;
		}

      if (curl_multi_fdset(cm, &R, &W, &E, &M)) {
        Com_Printf("E: curl_multi_fdset\n");
        return 1;
      }
      if (L == -1)
        L = 100;

      if (M == -1) {
		  /* obviously we need to sleep a 
		  short while so we DO NOT RUN OUT OF FDs! */
#ifdef WIN32
        Sleep(L);
#else
        sleep(L / 1000);
#endif
      } else {
        T.tv_sec = L/1000;
        T.tv_usec = (L%1000)*1000;
		//T.tv_sec = 5;
        //T.tv_usec = 0;
        if (0 > select(M+1, &R, &W, &E, &T)) {
          Com_Printf("E: select(%i,,,,%li): %i: %s\n",
              M+1, L, errno, strerror(errno));
          return 1;
        }
	  }
      
    }

    while ((msg = curl_multi_info_read(cm, &Q))) {

	  // allow user to use console
	  CL_SendCommand ();

      if (msg->msg == CURLMSG_DONE)
	  {
		long responseCode;
        extern struct MemoryStruct *memPtr;
		char *url;
		double recvsize;
		double totaltime;
		char *localfile;
		char *fullurl;
		int remainingFiles;
		static int finishcnt;
		
        CURL *e = msg->easy_handle;
		curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &responseCode);
        curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);
		curl_easy_getinfo(msg->easy_handle, CURLINFO_SIZE_DOWNLOAD, &recvsize);
		curl_easy_getinfo(msg->easy_handle, CURLINFO_TOTAL_TIME, &totaltime);
		curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &localfile);
		curl_easy_getinfo(msg->easy_handle, CURLINFO_EFFECTIVE_URL, &fullurl);

		remainingFiles=0;

		if (responseCode == 404)
		{
			//Com_Printf("[HTTP] %s [404 Not Found] [x remaining files]\n", 
				//localfile, recvsize/1000,recvsize/(1000*totaltime),remainingFiles);

			// dont show 404 error in some cases, prettier console...
			#if HTTP404ERROR
			Com_Printf("[HTTP] %s [404 Not Found]\n", 
				localfile, recvsize/1000,recvsize/(1000*totaltime),remainingFiles);
				got404=true;
				cls.downloadnow=false; // dont download over http again...
			#endif
		}
		else if (responseCode == 200)
		{
			/*
			Com_Printf("[HTTP] %s [%.f kB, %.0f kB/sec] [x remaining files]\n", 
				localfile, recvsize/1000,recvsize/(1000*totaltime),remainingFiles);
			*/
			Com_Printf("[HTTP] %s [%.f kB, %.0f kB/sec]\n", 
				localfile, recvsize/1000,recvsize/(1000*totaltime),remainingFiles);
			binaryWrite(localfile, memPtr->memory, memPtr->size);
		}
		
		finishcnt++;

		if (memPtr && memPtr->memory)
		free(memPtr->memory);

        curl_multi_remove_handle(cm, e);
        curl_easy_cleanup(e);
      }
      else {
        Com_Printf("E: CURLMsg (%d)\n", msg->msg);
		return 1;
      }

      if (C < dlnum) 
	  {
        init(cm, C++);
        U++; 
      }
    }
  }

  curl_multi_cleanup(cm);
  curl_global_cleanup();

  return got404 ? 1:0;  
}
Example #4
0
void
CL_Frame(int msec)
{
	static int extratime;
	static int lasttimecalled;

	if (dedicated->value)
	{
		return;
	}

	extratime += msec;

	if (!cl_timedemo->value)
	{
		if ((cls.state == ca_connected) && (extratime < 100))
		{
			return; /* don't flood packets out while connecting */
		}

		if (extratime < 1000 / cl_maxfps->value)
		{
			return; /* framerate is too high */
		}
	}

	/* decide the simulation time */
	cls.frametime = extratime / 1000.0;

	cl.time += extratime;

	cls.realtime = curtime;

	extratime = 0;

	if (cls.frametime > (1.0 / 5))
	{
		cls.frametime = (1.0 / 5);
	}

	/* if in the debugger last frame, don't timeout */
	if (msec > 5000)
	{
		cls.netchan.last_received = Sys_Milliseconds();
	}

	/* fetch results from server */
	CL_ReadPackets();

	/* send a new command message to the server */
	CL_SendCommand();

	/* predict all unacknowledged movements */
	CL_PredictMovement();

	/* allow renderer DLL change */
	VID_CheckChanges();

	if (!cl.refresh_prepped && (cls.state == ca_active))
	{
		CL_PrepRefresh();
	}

	/* update the screen */
	if (host_speeds->value)
	{
		time_before_ref = Sys_Milliseconds();
	}

	SCR_UpdateScreen();

	if (host_speeds->value)
	{
		time_after_ref = Sys_Milliseconds();
	}

	/* update audio */
	S_Update(cl.refdef.vieworg, cl.v_forward, cl.v_right, cl.v_up);
#ifdef CDA
	CDAudio_Update();
#endif

	/* advance local effects for next frame */
	CL_RunDLights();

	CL_RunLightStyles();

	SCR_RunCinematic();

	SCR_RunConsole();

	cls.framecount++;

	if (log_stats->value)
	{
		if (cls.state == ca_active)
		{
			if (!lasttimecalled)
			{
				lasttimecalled = Sys_Milliseconds();

				if (log_stats_file)
				{
					fprintf(log_stats_file, "0\n");
				}
			}

			else
			{
				int now = Sys_Milliseconds();

				if (log_stats_file)
				{
					fprintf(log_stats_file, "%d\n", now - lasttimecalled);
				}

				lasttimecalled = now;
			}
		}
	}
}