void QTVList_Cache_File_Download(void)
{
	CURL *curl;
	CURLcode res;
	FILE *f;

	curl = curl_easy_init();
	if (curl) {
		curl_easy_setopt(curl, CURLOPT_URL, sb_qtvlist_url.string);
	}
	else {
		Com_Printf_State(PRINT_FAIL, "QTVList_List_f() Can't init cURL\n");
		return;
	}

	if (!FS_FCreateFile(QTVLIST_CACHE_FILE, &f, QTVLIST_CACHE_FILE_DIR, "wb+")) {
		Com_Printf_State(PRINT_FAIL, "Can't create QTVList cache file\n");
        return;
	}

	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);

	res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
	fclose(f);

	if (res != CURLE_OK) {
		Com_Printf_State(PRINT_FAIL, "Couldn't download QTV list");
		return;
	}
}
Exemple #2
0
void NET_GetLocalAddress (int socket, netadr_t *out)
{
	char buff[512];
	struct sockaddr_storage address;
	size_t namelen;
	netadr_t adr = {0};
	qbool notvalid = false;

	strlcpy (buff, "localhost", sizeof (buff));
	gethostname (buff, sizeof (buff));
	buff[sizeof(buff) - 1] = 0;

	if (!NET_StringToAdr (buff, &adr))	//urm
		NET_StringToAdr ("127.0.0.1", &adr);

	namelen = sizeof(address);
	if (getsockname (socket, (struct sockaddr *)&address, (socklen_t *)&namelen) == -1) {
		notvalid = true;
		NET_StringToSockaddr("0.0.0.0", (struct sockaddr_storage *)&address);
//		Sys_Error ("NET_Init: getsockname:", strerror(qerrno));
	}

	SockadrToNetadr(&address, out);
	if (!*(int*)out->ip)	//socket was set to auto
		*(int *)out->ip = *(int *)adr.ip;	//change it to what the machine says it is, rather than the socket.

#ifndef SERVERONLY
	if (notvalid)
		Com_Printf_State (PRINT_FAIL, "Couldn't detect local ip\n");
	else
		Com_Printf_State (PRINT_OK, "IP address %s\n", NET_AdrToString (*out));
#endif
}
Exemple #3
0
static void SetBufferSize(void) 
{
	static DIPROPDWORD dipdw = {
		{ sizeof(dipdw), sizeof(dipdw.diph), 0, DIPH_DEVICE },
		0
	};
	HRESULT hr;
	unsigned int bufsize;

	if (in_di_bufsize.integer)
	{  // we don't wont dynamic buffer change
		Com_Printf_State(PRINT_OK, "DirectInput overflow, increasing skipped because of %s.\n", in_di_bufsize.name);
		return;
	}

	bufsize = max(dipdw.dwData, DI_BufSize()); // well, DI_BufSize() return 16, since in_di_bufsize is zero
	dipdw.dwData = bufsize + max(1, bufsize / 2);

	Com_Printf_State(PRINT_INFO, "DirectInput overflow, increasing buffer size to %u.\n", dipdw.dwData);

	IN_DeactivateMouse();

	hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);

	IN_ActivateMouse();

	if(FAILED(hr)) 
	{
		Com_Printf_State (PRINT_FAIL, "Unable to increase DirectInput buffer size.\n");
	}
}
Exemple #4
0
//Try to find a sound device to mix for.
//Returns false if nothing is found.
qbool SNDDMA_Init(void)
{
	sndinitstat stat;

	Cvar_SetCurrentGroup(CVAR_GROUP_SOUND);
	Cvar_Register (&sys_inactivesound);
	Cvar_ResetCurrentGroup ();

	if (COM_CheckParm ("-wavonly"))
		wavonly = true;

	dsound_init = wav_init = 0;

	stat = SIS_FAILURE; // assume DirectSound won't initialize

	/* Init DirectSound */
	if (!wavonly) {
		if (snd_firsttime || snd_isdirect) {
			stat = SNDDMA_InitDirect ();

			if (stat == SIS_SUCCESS) {
				snd_isdirect = true;

				if (snd_firsttime)
					Com_Printf_State (PRINT_OK, "DirectSound initialized\n");
			} else {
				snd_isdirect = false;
				Com_Printf_State (PRINT_FAIL, "DirectSound failed to init\n");
			}
		}
	}

	// if DirectSound didn't succeed in initializing, try to initialize waveOut sound
	if (!dsound_init) {
		if (snd_firsttime || snd_iswave) {
			snd_iswave = SNDDMA_InitWav ();

			if (snd_iswave) {
				if (snd_firsttime)
					Com_Printf_State (PRINT_OK, "Wave sound initialized\n");
			} else {
				Com_Printf_State (PRINT_FAIL, "Wave sound failed to init\n");
			}
		}
	}

	snd_firsttime = false;

	if (!dsound_init && !wav_init) {
		if (snd_firsttime)
			Com_Printf_State (PRINT_INFO, "No sound device initialized\n");

		return false;
	}

	return true;
}
Exemple #5
0
static void GfxInfo_f(void)
{
	SDL_DisplayMode current;

	Com_Printf_State(PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string );
	Com_Printf_State(PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string );
	Com_Printf_State(PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string );

	if (r_showextensions.value) {
		Com_Printf_State(PRINT_ALL, "GL_EXTENSIONS: %s\n", glConfig.extensions_string);
	}

	Com_Printf_State(PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n             stencil(%d-bits)\n", glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits);

	if (SDL_GetCurrentDisplayMode(VID_DisplayNumber(r_fullscreen.value), &current) != 0) {
		current.refresh_rate = 0; // print 0Hz if we run into problem fetching data
	}

	Com_Printf_State(PRINT_ALL, "MODE: %d x %d @ %d Hz ", current.w, current.h, current.refresh_rate);
	
	if (r_fullscreen.integer) {
		Com_Printf_State(PRINT_ALL, "[fullscreen]\n");
	} else {
		Com_Printf_State(PRINT_ALL, "[windowed]\n");
	}

	Com_Printf_State(PRINT_ALL, "CONRES: %d x %d\n", r_conwidth.integer, r_conheight.integer );

}
Exemple #6
0
static void Rulesets_OnChange_ruleset (cvar_t *var, char *value, qbool *cancel)
{
	extern void Cmd_ReInitAllMacro (void);

	if (cls.state != ca_disconnected) {
		Com_Printf ("%s can be changed only in disconneced mode\n", var->name);
		*cancel = true;
		return;
	}

	if (strncasecmp (value, "smackdown", 9) && strncasecmp (value, "mtfl", 4) && strncasecmp (value, "default", 7)) {
		Com_Printf_State (PRINT_INFO, "Unknown ruleset \"%s\"\n", value);
		*cancel = true;
		return;
	}

	// All checks passed  so we can remove old ruleset and set a new one
	switch (rulesetDef.ruleset) {
		case rs_smackdown:
			Rulesets_Smackdown (false);
			break;
		case rs_mtfl:
			Rulesets_MTFL (false);
			break;
		case rs_default:
			break;
		default:
			break;
	}

	// we need to mark custom textures in the memory (like for backpack and eyes) to be reloaded again
	Cache_Flush ();

	if (!strncasecmp (value, "smackdown", 9)) {
		Rulesets_Smackdown (true);
		Com_Printf_State (PRINT_OK, "Ruleset Smackdown initialized\n");
	} else if (!strncasecmp (value, "mtfl", 4)) {
		Rulesets_MTFL (true);
		Com_Printf_State (PRINT_OK, "Ruleset MTFL initialized\n");
	} else if (!strncasecmp (value, "default", 7)) {
		Rulesets_Default ();
		Com_Printf_State (PRINT_OK, "Ruleset default initialized\n");
	} else {
		Sys_Error ("OnChange_ruleset: WTF?\n");
		// this will never happen
		*cancel = true;
		return;
	}

	Cmd_ReInitAllMacro ();
}
static void SB_Update_Source_From_URL(const source_data *s, server_data *servers[],
	int *serversn)
{
	CURL *curl;
	CURLcode res;
	size_t filename_buf_len;
	char *filename;
	FILE *f;
 
	if (s->type != type_url) {
		Com_Printf_State(PRINT_FAIL, "SB_Update_Source_From_URL() Invalid argument\n");
		return;
	}

	curl = curl_easy_init();
	if (curl) {
		curl_easy_setopt(curl, CURLOPT_URL, s->address.url);
	}
	else {
		Com_Printf_State(PRINT_FAIL, "SB_Update_Source_From_URL() Can't init cURL\n");
		return;
	}
	
	filename_buf_len = SB_URL_To_Filename_Length(s->address.url);
	filename = Q_malloc(filename_buf_len);
	SB_URL_to_FileName(s->address.url, filename, filename_buf_len);
	if (!FS_FCreateFile(filename, &f, "ezquake/sb/cache", "wt+")) {
		Com_Printf_State(PRINT_FAIL, "SB_Update_Source_From_URL() Can't open cached file");
		return;
	}

	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);

	res = curl_easy_perform(curl);
	if (res != CURLE_OK) {
		Com_Printf("Error: Could not read URL %s\n", s->address.url);
	}

	fseek(f, 0, SEEK_SET);
	
	SB_Process_URL_Buffer(f, servers, serversn);
	fclose(f);
	Q_free(filename);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
}
Exemple #8
0
void *DSOUND_Capture_Init (int rate)
{
	dsndcapture_t *result;
	DSCBUFFERDESC bufdesc = {0};
	WAVEFORMATEX  wfxFormat = {0};

	Com_DPrintf("DSOUND_Capture_Init: rate %d\n", rate);

	wfxFormat.wFormatTag = WAVE_FORMAT_PCM;
    wfxFormat.nChannels = 1;
    wfxFormat.nSamplesPerSec = rate;
	wfxFormat.wBitsPerSample = 8*inputwidth;
    wfxFormat.nBlockAlign = wfxFormat.nChannels * (wfxFormat.wBitsPerSample / 8);
	wfxFormat.nAvgBytesPerSec = wfxFormat.nSamplesPerSec * wfxFormat.nBlockAlign;
    wfxFormat.cbSize = 0;

	bufdesc.dwSize = sizeof(bufdesc);
	bufdesc.dwBufferBytes = bufferbytes;
	bufdesc.dwFlags = 0;
	bufdesc.dwReserved = 0;
	bufdesc.lpwfxFormat = &wfxFormat;

	result = Z_Malloc(sizeof(*result));
	if (FAILED(DirectSoundCaptureCreate(NULL, &result->DSCapture, NULL)))
	{
		Com_Printf_State (PRINT_FAIL, "DirectSound: Couldn't create a capture device\n");
	}
	else if (FAILED(IDirectSoundCapture_CreateCaptureBuffer(result->DSCapture, &bufdesc, &result->DSCaptureBuffer, NULL)))
	{
		Com_Printf_State (PRINT_FAIL, "DirectSound: Couldn't create a capture buffer\n");	
	}
	else
	{
		Com_DPrintf("DSOUND_Capture_Init: OK\n");
		return result;	
	}

	// failure, lets clean up.

	if (result->DSCapture)
	{
		IDirectSoundCapture_Release(result->DSCapture);	
	}

	Z_Free(result);

	return NULL;
}
Exemple #9
0
void NET_InitClient(void)
{
	int port = PORT_CLIENT;
	int p;

	p = COM_CheckParm ("-clientport");
	if (p && p < COM_Argc()) {
		port = atoi(COM_Argv(p+1));
	}

	if (cls.socketip == INVALID_SOCKET)
		cls.socketip = UDP_OpenSocket (port);

	if (cls.socketip == INVALID_SOCKET)
		cls.socketip = UDP_OpenSocket (PORT_ANY); // any dynamic port

	if (cls.socketip == INVALID_SOCKET)
		Sys_Error ("Couldn't allocate client socket");

	// init the message buffer
	SZ_Init (&net_message, net_message_buffer, sizeof(net_message_buffer));

	// determine my name & address
	NET_GetLocalAddress (cls.socketip, &net_local_cl_ipadr);

	Com_Printf_State (PRINT_OK, "Client port Initialized\n");
}
Exemple #10
0
void Capture_InitACM (void)
{
    movie_acm_loaded = false;

    if (!(handle_acm = LoadLibrary("msacm32.dll")))
    {
        Com_Printf ("\x02" "ACM module not found\n");
        goto fail;
    }

    ACM_GETFUNC(DriverOpen);
    ACM_GETFUNC(DriverEnum);
    ACM_GETFUNC(StreamOpen);
    ACM_GETFUNC(StreamSize);
    ACM_GETFUNC(StreamPrepareHeader);
    ACM_GETFUNC(StreamUnprepareHeader);
    ACM_GETFUNC(StreamConvert);
    ACM_GETFUNC(StreamClose);
    ACM_GETFUNC(DriverClose);
    qacmDriverDetails = (void *)GetProcAddress (handle_acm, "acmDriverDetailsA");
    qacmFormatTagDetails = (void *)GetProcAddress (handle_acm, "acmFormatTagDetailsA");

    movie_acm_loaded = qacmDriverOpen && qacmDriverDetails && qacmDriverEnum &&
                       qacmFormatTagDetails && qacmStreamOpen && qacmStreamSize &&
                       qacmStreamPrepareHeader && qacmStreamUnprepareHeader &&
                       qacmStreamConvert && qacmStreamClose && qacmDriverClose;

    if (!movie_acm_loaded)
    {
        Com_Printf_State (PRINT_FAIL, "ACM module not initialized\n");
        goto fail;
    }

    Com_Printf_State (PRINT_OK, "ACM module initialized\n");
    return;

fail:
    if (handle_acm)
    {
        FreeLibrary (handle_acm);
        handle_acm = NULL;
    }
}
Exemple #11
0
void Capture_InitAVI (void)
{
    movie_avi_loaded = false;

    if (!(handle_avi = LoadLibrary("avifil32.dll")))
    {
        Com_Printf ("\x02" "Avi capturing module not found\n");
        goto fail;
    }

    AVI_GETFUNC(FileInit);
    AVI_GETFUNC(FileOpen);
    AVI_GETFUNC(FileCreateStream);
    AVI_GETFUNC(MakeCompressedStream);
    AVI_GETFUNC(StreamSetFormat);
    AVI_GETFUNC(StreamWrite);
    AVI_GETFUNC(StreamRelease);
    AVI_GETFUNC(FileRelease);
    AVI_GETFUNC(FileExit);

    movie_avi_loaded = qAVIFileInit && qAVIFileOpen && qAVIFileCreateStream &&
                       qAVIMakeCompressedStream && qAVIStreamSetFormat && qAVIStreamWrite &&
                       qAVIStreamRelease && qAVIFileRelease && qAVIFileExit;

    if (!movie_avi_loaded)
    {
        Com_Printf_State (PRINT_FAIL, "Avi capturing module not initialized\n");
        goto fail;
    }

    Com_Printf_State (PRINT_OK, "Avi capturing module initialized\n");
    return;

fail:
    if (handle_avi)
    {
        FreeLibrary (handle_avi);
        handle_avi = NULL;
    }
}
Exemple #12
0
void Cam_FinishMove(usercmd_t *cmd) 
{
	int i, end, inc;
	player_info_t *s;

	if (cls.state != ca_active)
		return;

	if (!cl.spectator) // only in spectator mode
		return;

	if (cmd->buttons & BUTTON_ATTACK) {
		if (!(oldbuttons & BUTTON_ATTACK)) {

			oldbuttons |= BUTTON_ATTACK;
			autocam++;

			if (autocam > CAM_TRACK) {
				Cam_Unlock();
				VectorCopy(cl.viewangles, cmd->angles);
				return;
			}
		} else
			return;
	} else {
		oldbuttons &= ~BUTTON_ATTACK;
		if (!autocam)
			return;
	}

	// cl_hightrack 
	if (autocam && cl_hightrack.value) 
	{
		Cam_CheckHighTarget();
		if (Cam_JumpCheck(cmd))
		{
			Com_Printf_State(PRINT_FAIL,"cl_hightrack enabled. Unable to switch POV.\n");
		}
		return;
	}

	if (Cam_MoveDownCheck(cmd)) {
		inc = -1;
	} else {
		inc = 1;
	}

	if (locked) {
		if (!Cam_JumpCheck(cmd) && inc == 1) {
			return;
		}
		// Swap the Multiview mvinset/main view pov when jump button is pressed.
		nSwapPov = inc;
	}

	
	if (locked && autocam)
		end = (ideal_track + MAX_CLIENTS + inc) % MAX_CLIENTS;
	else
		end = ideal_track;

	i = end;
	do {
		s = &cl.players[i];
		if (s->name[0] && !s->spectator) {
			if (cls.mvdplayback && cl.teamfortress) 
				V_TF_ClearGrenadeEffects(); // BorisU
			Cam_Lock(i);
			ideal_track = i;    
			return;
		}
		i = (i + MAX_CLIENTS + inc) % MAX_CLIENTS;
	} while (i != end);
	// stay on same guy?	

	i = ideal_track;	
	s = &cl.players[i];
	if (s->name[0] && !s->spectator) {
		Cam_Lock(i);
		return;
	}
	Com_Printf ("No target found ...\n");
	autocam = locked = false;
}
Exemple #13
0
void Movie_Demo_Capture_f(void) {
	int argc;
	double time;
	char *error;
	
#ifdef _WIN32
	error = va("Usage: %s <start time [avifile] | stop>\n", Cmd_Argv(0));
	if ((argc = Cmd_Argc()) != 2 && argc != 3 && argc != 4) {
#else
	error = va("Usage: %s <start time | stop>\n", Cmd_Argv(0));
	if ((argc = Cmd_Argc()) != 2 && argc != 3) {
#endif
		Com_Printf(error);
		return;
	}
	if (argc == 2) {
		if (strncasecmp("stop", Cmd_Argv(1), 4))
			Com_Printf(error);
		else if (Movie_IsCapturing()) 
			Movie_Stop();
		else
			Com_Printf("%s : Not capturing\n", Cmd_Argv(0));
		return;
	}
	if (strncasecmp("start", Cmd_Argv(1), 5)) {
		Com_Printf(error);
		return;
	} else if (Movie_IsCapturing()) {
		Com_Printf("%s : Already capturing\n", Cmd_Argv(0));
		return;
	}
	if (!cls.demoplayback || cls.timedemo) {
		Com_Printf("%s : Must be playing a demo to capture\n", Cmd_Argv(0));
		return;
	}
	if ((time = Q_atof(Cmd_Argv(2))) <= 0) {
		Com_Printf("%s : Time argument must be positive\n", Cmd_Argv(0));
		return;
	}
#ifdef _WIN32
	//joe: capturing to avi
	if (argc == 4) {
		avi_number = 0;

		strlcpy(movie_avi_filename, Cmd_Argv(3), sizeof(movie_avi_filename)-10);		// Store user's requested filename
		if (!movie_avi_loaded) {
			Com_Printf_State (PRINT_FAIL, "Avi capturing not initialized\n");
			return;
		}

		Movie_Start_AVI_Capture(movie_vid_maxlen.value > 0 && movie_vid_maxlen.value < time);
	}
#endif
	Movie_Start(time);
}

#ifdef _WIN32
static void Movie_Start_AVI_Capture(qbool split) 
{
	++avi_number;

	// If we're going to break up the movie, append number
	char aviname[MAX_OSPATH];
	if (split)
		snprintf (aviname, sizeof(aviname), "%s-%03d", movie_avi_filename, avi_number);
	else 
		strlcpy (aviname, movie_avi_filename, sizeof(aviname));

	if (!(Util_Is_Valid_Filename(aviname))) {
		Com_Printf(Util_Invalid_Filename_Msg(aviname));
		return;
	}
	COM_ForceExtensionEx (aviname, ".avi", sizeof (aviname));
	snprintf (avipath, sizeof(avipath), "%s/%s/%s", com_basedir, movie_dir.string, aviname);
	if (!(avifile = fopen(avipath, "wb"))) {
		FS_CreatePath (avipath);
		if (!(avifile = fopen(avipath, "wb"))) {
			Com_Printf("Error: Couldn't open %s\n", aviname);
			return;
		}
	}
}
Exemple #14
0
void S_Init (void)
{
	if (snd_initialized) { //whoops
		Com_Printf_State (PRINT_INFO, "Sound is already initialized\n");
		return;
	}

	Com_DPrintf("\nSound Initialization\n");

	Cvar_SetCurrentGroup(CVAR_GROUP_SOUND);
	Cvar_Register(&bgmvolume);
	Cvar_Register(&s_volume);
	Cvar_Register(&s_nosound);
	Cvar_Register(&s_precache);
	Cvar_Register(&s_loadas8bit);
	Cvar_Register(&s_khz);
	Cvar_Register(&s_ambientlevel);
	Cvar_Register(&s_ambientfade);
	Cvar_Register(&s_noextraupdate);
	Cvar_Register(&s_show);
	Cvar_Register(&s_mixahead);
	Cvar_Register(&s_swapstereo);
#if (defined(__linux__) || defined(__FreeBSD__))
	Cvar_Register(&s_stereo);
	Cvar_Register(&s_device);
	Cvar_Register(&s_bits);
#endif
#ifdef __linux__
	Cvar_Register(&s_noalsa);
#endif

	Cvar_ResetCurrentGroup();

	// compatibility with old configs
	Cmd_AddLegacyCommand ("nosound", "s_nosound");
	Cmd_AddLegacyCommand ("precache", "s_precache");
	Cmd_AddLegacyCommand ("loadas8bit", "s_loadas8bit");
	Cmd_AddLegacyCommand ("ambient_level", "s_ambientlevel");
	Cmd_AddLegacyCommand ("ambient_fade", "s_ambientfade");
	Cmd_AddLegacyCommand ("snd_noextraupdate", "s_noextraupdate");
	Cmd_AddLegacyCommand ("snd_show", "s_show");
	Cmd_AddLegacyCommand ("_snd_mixahead", "s_mixahead");

	if (COM_CheckParm("-nosound")) {
		Cmd_AddLegacyCommand ("play", ""); // just suppress warnings
		return;
	}

	Cmd_AddCommand("snd_restart", S_Restart_f);
	Cmd_AddLegacyCommand("s_restart", "snd_restart");	// exclusively for Disconnect
	Cmd_AddCommand("play", S_Play_f);
	Cmd_AddCommand("playvol", S_PlayVol_f);
	Cmd_AddCommand("stopsound", S_StopAllSounds_f);
	Cmd_AddCommand("soundlist", S_SoundList_f);
	Cmd_AddCommand("soundinfo", S_SoundInfo_f);

	if (!snd_initialized && host_memsize < 0x800000) {
		Cvar_Set (&s_loadas8bit, "1");
		Com_Printf ("loading all sounds as 8bit\n");
	}

	snd_initialized = true;

	SND_InitScaletable ();

	if (!S_Startup ()) {
		snd_initialized = false;
		 return;
	}

	known_sfx = (sfx_t *) Hunk_AllocName (MAX_SFX * sizeof(sfx_t), "sfx_t");
	num_sfx = 0;

	ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav");
	ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav");

	S_StopAllSounds (true);

}
Exemple #15
0
static sndinitstat SNDDMA_InitDirect (void)
{
	DSBUFFERDESC dsbuf;
	DSBCAPS dsbcaps;
	DWORD dwSize, dwWrite;
	DSCAPS dscaps;
	WAVEFORMATEX format, pformat;
	HRESULT hresult;
	int reps, temp, devicenum;

	memset((void *)shm, 0, sizeof(*shm));

	shm->format.channels = 2;
	shm->format.width = 2;
	shm->format.speed = SND_Rate((int)s_khz.value);

	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
	format.nChannels = shm->format.channels;
	format.wBitsPerSample = shm->format.width * 8;
	format.nSamplesPerSec = shm->format.speed;
	format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
	format.cbSize = 0;
	format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;

	dsdevice = NULL;
	if ((temp = COM_CheckParm("-snddev")) && temp + 1 < COM_Argc()) {
		devicenum = Q_atoi(COM_Argv(temp + 1));
		currentenum = 0;
		if ((hresult = DirectSoundEnumerate(DS_EnumDevices, &devicenum)) != DS_OK) {
			Com_Printf_State (PRINT_INFO, "Couldn't open preferred sound device. Falling back to primary sound device.\n");
			dsdevice = NULL;
		}
	}

	hresult = DirectSoundCreate(dsdevice, &pDS, NULL);
	if (hresult != DS_OK && dsdevice) {
		Com_Printf_State (PRINT_INFO, "Couldn't open preferred sound device. Falling back to primary sound device.\n");
		dsdevice = NULL;
		hresult = DirectSoundCreate(dsdevice, &pDS, NULL);
	}

	if (hresult != DS_OK) {
		if (hresult == DSERR_ALLOCATED) {
			Com_Printf_State (PRINT_FAIL, "DirectSoundCreate failed, hardware already in use\n");
			return SIS_NOTAVAIL;
		}

		Com_Printf_State (PRINT_FAIL, "DirectSound create failed\n");
		return SIS_FAILURE;
	}

	dscaps.dwSize = sizeof(dscaps);

	if (DS_OK != pDS->lpVtbl->GetCaps (pDS, &dscaps))
		Com_Printf_State (PRINT_FAIL, "Couldn't get DS caps\n");

	if (dscaps.dwFlags & DSCAPS_EMULDRIVER) {
		Com_Printf_State (PRINT_FAIL, "No DirectSound driver installed\n");
		FreeSound ();
		return SIS_FAILURE;
	}

	if (DS_OK != pDS->lpVtbl->SetCooperativeLevel (pDS, mainwindow, DSSCL_EXCLUSIVE)) {
		Com_Printf_State (PRINT_FAIL, "Set coop level failed\n");
		FreeSound ();
		return SIS_FAILURE;
	}

	// get access to the primary buffer, if possible, so we can set the sound hardware format
	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);
	dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER | (sys_inactivesound.value ? DSBCAPS_GLOBALFOCUS : 0);
	dsbuf.dwBufferBytes = 0;
	dsbuf.lpwfxFormat = NULL;

	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	primary_format_set = false;

	if (!COM_CheckParm ("-snoforceformat")) {
		if (DS_OK == pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSPBuf, NULL)) {
			pformat = format;

			if (DS_OK != pDSPBuf->lpVtbl->SetFormat (pDSPBuf, &pformat)) {
//				if (snd_firsttime)
//					Com_Printf ("Set primary sound buffer format: no\n");
			} else {
//				if (snd_firsttime)
//					Com_Printf ("Set primary sound buffer format: yes\n");
				primary_format_set = true;
			}
		}
	}

	if (!primary_format_set || !COM_CheckParm ("-primarysound")) {
		// create the secondary buffer we'll actually work with
		memset (&dsbuf, 0, sizeof(dsbuf));
		dsbuf.dwSize = sizeof(DSBUFFERDESC);
		dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCSOFTWARE | (sys_inactivesound.value ? DSBCAPS_GLOBALFOCUS : 0);
		dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
		dsbuf.lpwfxFormat = &format;

		memset(&dsbcaps, 0, sizeof(dsbcaps));
		dsbcaps.dwSize = sizeof(dsbcaps);

		if (DS_OK != pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL)) {
			Com_Printf_State (PRINT_FAIL, "DS:CreateSoundBuffer Failed");
			FreeSound ();
			return SIS_FAILURE;
		}

		shm->format.channels = format.nChannels;
		shm->format.width = format.wBitsPerSample / 8;
		shm->format.speed = format.nSamplesPerSec;

		if (DS_OK != pDSBuf->lpVtbl->GetCaps (pDSBuf, &dsbcaps)) {
			Com_Printf_State (PRINT_FAIL, "DS:GetCaps failed\n");
			FreeSound ();
			return SIS_FAILURE;
		}

//		if (snd_firsttime)
//			Com_Printf ("Using secondary sound buffer\n");
	} else {
		if (DS_OK != pDS->lpVtbl->SetCooperativeLevel (pDS, mainwindow, DSSCL_WRITEPRIMARY)) {
			Com_Printf_State (PRINT_FAIL, "Set coop level failed\n");
			FreeSound ();
			return SIS_FAILURE;
		}

		if (DS_OK != pDSPBuf->lpVtbl->GetCaps (pDSPBuf, &dsbcaps)) {
			Com_Printf_State (PRINT_FAIL, "DS:GetCaps failed\n");
			return SIS_FAILURE;
		}

		pDSBuf = pDSPBuf;
//		Com_Printf ("Using primary sound buffer\n");
	}

	// Make sure mixer is active
	pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);

/*	if (snd_firsttime)
		Com_Printf ("   %d channel(s)\n"
			"   %d bits/sample\n"
			"   %d bytes/sec\n",
		shm->format.channels, shm->format.width * , shm->format.speed);*/

	gSndBufSize = dsbcaps.dwBufferBytes;

	// initialize the buffer
	reps = 0;

	while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &lpData, &dwSize, NULL, NULL, 0)) != DS_OK) {
		if (hresult != DSERR_BUFFERLOST) {
			Com_Printf_State (PRINT_FAIL, "SNDDMA_InitDirect: DS::Lock Sound Buffer Failed\n");
			FreeSound ();
			return SIS_FAILURE;
		}

		if (++reps > 10000) {
			Com_Printf_State (PRINT_FAIL, "SNDDMA_InitDirect: DS: couldn't restore buffer\n");
			FreeSound ();
			return SIS_FAILURE;
		}

	}

	memset(lpData, 0, dwSize);
//		lpData[4] = lpData[5] = 0x7f;	// force a pop for debugging

	pDSBuf->lpVtbl->Unlock(pDSBuf, lpData, dwSize, NULL, 0);

	/* we don't want anyone to access the buffer directly w/o locking it first. */
	lpData = NULL;

	pDSBuf->lpVtbl->Stop(pDSBuf);
	pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmstarttime.u.sample, &dwWrite);
	pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);

	shm->samples = gSndBufSize/shm->format.width;
	shm->sampleframes = shm->samples / shm->format.channels;
	shm->samplepos = 0;
	shm->buffer = (unsigned char *) lpData;
	sample16 = shm->format.width - 1;

	dsound_init = true;

	return SIS_SUCCESS;
}
Exemple #16
0
void Host_Init (int argc, char **argv, int default_memsize)
{
	vfsfile_t *vf;
	cvar_t *v;

	char cfg[MAX_PATH] = {0};
	int i;
	char *cfg_name;

	COM_InitArgv (argc, argv);
	COM_StoreOriginalCmdline(argc, argv);

#ifdef WITH_DP_MEM
	Memory2_Init ();
#endif
	Host_InitMemory (default_memsize);

#ifdef WITH_TCL
	// interpreter should be initialized
	// before any cvar definitions
	TCL_InterpInit ();
#endif
	Cbuf_Init ();
	Cmd_Init ();
	Cvar_Init ();
	COM_Init ();
	Key_Init ();

#ifdef WITH_DP_MEM
	Memory2_Init_Commands ();
#endif
	Cache_Init_Commands ();

	FS_InitFilesystem ();
	NET_Init ();

	Commands_For_Configs_Init ();
	ConfigManager_Init();
	ResetBinds();

	i = COM_CheckParm("+cfg_load");

	if (i && (i + 1 < COM_Argc())) {
		cfg_name = COM_Argv(i + 1);
	}
	else {
		cfg_name = MAIN_CONFIG_FILENAME;
	}
	snprintf(cfg, sizeof(cfg), "%s", cfg_name);
	COM_ForceExtensionEx (cfg, ".cfg", sizeof (cfg));
	Cbuf_AddText(va("cfg_load %s\n", cfg));
	Cbuf_Execute();

	Cbuf_AddEarlyCommands ();
	Cbuf_Execute ();

	Con_Init ();
	NET_InitClient ();
	Netchan_Init ();

#if (!defined WITH_PNG_STATIC || !defined WITH_JPEG_STATIC || defined WITH_MP3_PLAYER)
	QLib_Init();
#endif

	Sys_Init ();
	CM_Init ();
	PM_Init ();
	Mod_Init ();

	SV_Init ();
	CL_Init ();

	Cvar_CleanUpTempVars ();

	SYSINFO_Init();

#ifdef WITH_TCL
	if (!TCL_InterpLoaded())
		Com_Printf_State (PRINT_FAIL, "Could not load "TCL_LIB_NAME", embedded Tcl disabled\n");
#endif

	Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
	host_hunklevel = Hunk_LowMark ();

	host_initialized = true;

	// walk through all vars and forse OnChange event if cvar was modified,
	// also apply that to variables which mirrored in userinfo because of cl_parsefunchars was't applyed as this moment,
	// same for serverinfo and may be this fix something also.
	for ( v = NULL; (v = Cvar_Next ( v )); ) {
		char val[2048];

//		if ( !v->modified )
//			continue; // not modified even that strange at this moment

		if ( Cvar_GetFlags( v ) & (CVAR_ROM | CVAR_INIT) )
			continue;

		snprintf(val, sizeof(val), "%s", v->string);
		Cvar_Set(v, val);
	}
	
	Hud_262LoadOnFirstStart();

	Com_Printf_State (PRINT_INFO, "Exe: "__TIME__" "__DATE__"\n");
	Com_Printf_State (PRINT_INFO, "Hunk allocation: %4.1f MB.\n", (float) host_memsize / (1024 * 1024));

	Com_Printf ("\nezQuake %s\n\n", VersionString());
	Com_Printf(Host_PrintBars("ezQuake\x9c" "SourceForge\x9c" "net", 38));
	Com_Printf(Host_PrintBars("ezQuake Initialized", 38));
	Com_Printf("\n");
	Com_Printf ("\nType /help to access the manual.\nUse /describe to learn about commands.\n", VersionString());

	if ((vf = FS_OpenVFS("autoexec.cfg", "rb", FS_ANY))) {
		Cbuf_AddText ("exec autoexec.cfg\n");
		VFS_CLOSE(vf);
	}

	Cmd_StuffCmds_f ();		// process command line arguments
	Cbuf_AddText ("cl_warncmd 1\n");

	#ifdef WIN32
	//
	// Verify that ezQuake is associated with the QW:// protocl handler.
	//
	{
		extern qbool CL_CheckIfQWProtocolHandler();
		extern cvar_t cl_verify_qwprotocol;

		if (cl_verify_qwprotocol.integer >= 2)
		{
			// Always register the qw:// protocol.
			Cbuf_AddText("register_qwurl_protocol\n");
		}
		else if (cl_verify_qwprotocol.integer == 1 && !CL_CheckIfQWProtocolHandler())
		{
			// Check if the running exe is the one associated with the qw:// protocol.

			Com_PrintVerticalBar(0.8 * vid.conwidth / 8);
			Com_Printf("\n");
			Com_Printf("This ezQuake is not associated with the "); 
			Com_Printf("\x02QW:// protocol.\n");
			Com_Printf("Register it using "); 
			Com_Printf("\x02/register_qwurl_protocol\n");
			Com_Printf("(set ");
			Com_Printf("\x02 cl_verify_qwprotocol ");
			Com_Printf("to 0 to hide this warning)\n");
			Com_PrintVerticalBar(0.8 * vid.conwidth / 8);
			Com_Printf("\n");
		}
	}
	#endif // WIN32

	// Check if a qtv/demo file is specified as the first argument, in that case play that
	// otherwise, do some more checks of what to show at startup.
	{
		char cmd[1024] = {0};

		if (COM_CheckArgsForPlayableFiles(cmd, sizeof(cmd)))
		{
			Cbuf_AddText(cmd);
		}
		else
		{
			Startup_Place();
		}
	}

#ifdef _WIN32
	SetForegroundWindow(mainwindow);
	SetActiveWindow(mainwindow);
#endif

	host_everything_loaded = true;
}
Exemple #17
0
void Movie_Demo_Capture_f(void) {
	int argc;
	double time;
	char *error;
	
#ifdef _WIN32
	error = va("Usage: %s <start time [avifile] | stop>\n", Cmd_Argv(0));
	if ((argc = Cmd_Argc()) != 2 && argc != 3 && argc != 4) {
#else
	error = va("Usage: %s <start time | stop>\n", Cmd_Argv(0));
	if ((argc = Cmd_Argc()) != 2 && argc != 3) {
#endif
		Com_Printf(error);
		return;
	}
	if (argc == 2) {
		if (strncasecmp("stop", Cmd_Argv(1), 4))
			Com_Printf(error);
		else if (Movie_IsCapturing())
			Movie_Stop();
		else
			Com_Printf("%s : Not capturing\n", Cmd_Argv(0));
		return;
	}
	if (strncasecmp("start", Cmd_Argv(1), 5)) {
		Com_Printf(error);
		return;
	} else if (Movie_IsCapturing()) {
		Com_Printf("%s : Already capturing\n", Cmd_Argv(0));
		return;
	}
	if (!cls.demoplayback || cls.timedemo) {
		Com_Printf("%s : Must be playing a demo to capture\n", Cmd_Argv(0));
		return;
	}
	if ((time = Q_atof(Cmd_Argv(2))) <= 0) {
		Com_Printf("%s : Time argument must be positive\n", Cmd_Argv(0));
		return;
	}
#ifdef _WIN32
	//joe: capturing to avi
	if (argc == 4) {
		char aviname[MAX_OSPATH];

		if (!movie_avi_loaded) {
			Com_Printf_State (PRINT_FAIL, "Avi capturing not initialized\n");
			return;
		}
		strlcpy (aviname, Cmd_Argv(3), sizeof(aviname));
		if (!(Util_Is_Valid_Filename(aviname))) {
			Com_Printf(Util_Invalid_Filename_Msg(aviname));
			return;
		}
		COM_ForceExtensionEx (aviname, ".avi", sizeof (aviname));
		snprintf (avipath, sizeof(avipath), "%s/%s/%s", com_basedir, movie_dir.string, aviname);
		if (!(avifile = fopen(avipath, "wb"))) {
			FS_CreatePath (avipath);
			if (!(avifile = fopen(avipath, "wb"))) {
				Com_Printf("Error: Couldn't open %s\n", aviname);
				return;
			}
		}
	}
#endif
	Movie_Start(time);
}

void Movie_Init(void) {
	Cvar_SetCurrentGroup(CVAR_GROUP_DEMO);
	Cvar_Register(&movie_fps);
	Cvar_Register(&movie_dir);
	Cvar_Register(&movie_steadycam);

	Cvar_ResetCurrentGroup();

	Cmd_AddCommand("demo_capture", Movie_Demo_Capture_f);

#ifdef _WIN32
	Capture_InitAVI ();		//joe: capturing to avi
	if (!movie_avi_loaded)
		return;

	captured_audio_samples = 0;
	Cvar_SetCurrentGroup(CVAR_GROUP_DEMO);
	Cvar_Register(&movie_codec);

	Cvar_ResetCurrentGroup();

	Capture_InitACM ();
	if (!movie_acm_loaded)
		return;

	Cvar_SetCurrentGroup(CVAR_GROUP_DEMO);
	Cvar_Register(&movie_mp3);
	Cvar_Register(&movie_mp3_kbps);

	Cvar_ResetCurrentGroup();
#endif
}
Exemple #18
0
void IN_StartupMouse (void) 
{
	if (in_mouse.integer == mt_none)
		return;

	mouseinitialized = true;

	in_mwheeltype = MWHEEL_UNKNOWN;

#if DIRECTINPUT_VERSION	>= 0x0700
	if (in_mouse.integer == mt_dinput) 
	{
		dinput = IN_InitDInput();

		if (dinput) 
		{
			Com_Printf_State (PRINT_OK, "DirectInput initialized\n");
			mouse_buttons = 8;
			if (use_m_smooth)				
				Com_Printf_State (PRINT_OK, "Mouse smoothing initialized\n");
		} 
		else 
		{
			Com_Printf_State (PRINT_FAIL, "DirectInput not initialized\n");
		}
	}
#endif // DIRECTINPUT_VERSION	>= 0x0700

	if (!dinput) 
	{
		mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);

		if (mouseparmsvalid) 
		{
			if (in_m_os_parameters.integer == 1)    
			{
				// Keeps the OS acceleration settings.
				newmouseparms[2] = originalmouseparms[2];
			}

			if (in_m_os_parameters.integer == 2) 
			{ 
				// Keeps the OS speed settings.
				newmouseparms[0] = originalmouseparms[0];
				newmouseparms[1] = originalmouseparms[1];
			}

            if (in_m_os_parameters.integer > 2) 
			{
				// Keeps both OS acceleration and speed settings.
				newmouseparms[0] = originalmouseparms[0];
				newmouseparms[1] = originalmouseparms[1];
				newmouseparms[2] = originalmouseparms[2];
			}
		}
		mouse_buttons = 8;

		#ifdef USINGRAWINPUT
		if (in_mouse.integer == mt_raw)
		{
			IN_RawInput_Init();
		}
		#endif // USINGRAWINPUT
	}

	// If a fullscreen video mode was set before the mouse was initialized, set the mouse state appropriately.
	if (mouseactivatetoggle)
		IN_ActivateMouse ();
}
Exemple #19
0
qbool IN_InitDInput (void) 
{
#if DIRECTINPUT_VERSION	>= 0x0700
    HRESULT hr;
	DIPROPDWORD	dipdw = {
		{
			sizeof(DIPROPDWORD),        // diph.dwSize
			sizeof(DIPROPHEADER),       // diph.dwHeaderSize
			0,                          // diph.dwObj
			DIPH_DEVICE,                // diph.dwHow
		},
		DI_BufSize(),              // dwData
	};
	DIDATAFORMAT qdf = {
		sizeof(DIDATAFORMAT),			// this structure
			sizeof(DIOBJECTDATAFORMAT),		// size of object data format
			DIDF_RELAXIS,					// absolute axis coordinates
			sizeof(MYDATA),					// device data size
			sizeof(rgodf)/sizeof(rgodf[0]),	// number of objects
			rgodf							// and here they are
	};

	if (!hInstDI)
	{
		hInstDI = LoadLibrary("dinput.dll");
		
		if (hInstDI == NULL)
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't load dinput.dll\n");
			return false;
		}
	}

	if (!pDirectInputCreateEx)
	{
		pDirectInputCreateEx = (void *)GetProcAddress(hInstDI,"DirectInputCreateEx");
		if (!pDirectInputCreateEx) 
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't get DI proc addr\n");
			return false;
		}
	}

	// register with DirectInput and get an IDirectInput to play with.
	hr = pDirectInputCreateEx(global_hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput7, (LPVOID *) &g_pdi, NULL);

	if (FAILED(hr))
		return false;

	// obtain an interface to the system mouse device.
	hr = IDirectInput7_CreateDeviceEx(g_pdi, &GUID_SysMouse, &IID_IDirectInputDevice7, (LPVOID *) &g_pMouse, NULL);

	if (FAILED(hr))
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't open DI mouse device\n");
		return false;
	}

	// set the data format to "mouse format".
	hr = IDirectInputDevice7_SetDataFormat(g_pMouse, &qdf);

	if (FAILED(hr))
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't set DI mouse format\n");
		return false;
	}

	// set the cooperativity level.
	hr = IDirectInputDevice7_SetCooperativeLevel(g_pMouse, mainwindow, DISCL_EXCLUSIVE | DISCL_FOREGROUND);

	if (FAILED(hr)) 
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't set DI coop level\n");
		return false;
	}

	// set the buffer size to DI_BufSize() elements.
	// the buffer size is a DWORD property associated with the device
	if (in_di_buffered.integer) 
	{
		hr = IDirectInputDevice7_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
		if (FAILED(hr)) 
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't set DI buffersize\n");
			return false;
		}
	}
	else 
	{
		// no properties for immediate input
	}

	IN_SMouseInit();


	return true;
#else // DIRECTINPUT_VERSION	>= 0x0700
	return false;
#endif // DIRECTINPUT_VERSION	>= 0x0700 else
}