Пример #1
0
/*
================
Sys_GetEvent

================
*/
sysEvent_t Sys_GetEvent( void ) {
	sysEvent_t	ev;
	char		*s;
	msg_t		netmsg;
	netadr_t	adr;

	// return if we have data
	if ( eventHead > eventTail ) {
		eventTail++;
		return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
	}

	// pump the message loop
	// in vga this calls KBD_Update, under X, it calls GetEvent
	Sys_SendKeyEvents ();

	// check for console commands
	s = Sys_ConsoleInput();
	if ( s ) {
		char	*b;
		int		len;

		len = strlen( s ) + 1;
		b = (char *)malloc( len );
		strcpy( b, s );
		Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
	}

	// check for other input devices
	IN_Frame();

	// check for network packets
	MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
#if 0
	if ( Sys_GetPacket ( &adr, &netmsg ) ) {
		netadr_t		*buf;
		int				len;

		// copy out to a seperate buffer for qeueing
		len = sizeof( netadr_t ) + netmsg.cursize;
		buf = malloc( len );
		*buf = adr;
		memcpy( buf+1, netmsg.data, netmsg.cursize );
		Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
	}
#endif

	// return if we have data
	if ( eventHead > eventTail ) {
		eventTail++;
		return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
	}

	// create an empty event to return

	memset( &ev, 0, sizeof( ev ) );
	ev.evTime = Sys_Milliseconds();

	return ev;
}
Пример #2
0
sysEvent_t Sys_GetEvent( void ) {
    sysEvent_t	ev;
    char		*s;
    msg_t		netmsg;
    netadr_t	adr;

    // return if we have data
    if ( eventHead > eventTail ) {
        eventTail++;
        return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }

    // check for console commands
    s = Sys_ConsoleInput();
    if ( s ) {
        char	*b;
        int		len;

        len = strlen( s ) + 1;
        b = (char *)Z_Malloc( len,TAG_EVENT,qfalse );
        strcpy( b, s );
        Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
    }

    // check for network packets
    MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
    if ( Sys_GetPacket ( &adr, &netmsg ) ) {
        netadr_t		*buf;
        int				len;

        // copy out to a seperate buffer for qeueing
        len = sizeof( netadr_t ) + netmsg.cursize;
        buf = (netadr_t *)Z_Malloc( len,TAG_EVENT,qfalse );
        *buf = adr;
        memcpy( buf+1, netmsg.data, netmsg.cursize );
        Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
    }

    // return if we have data
    if ( eventHead > eventTail ) {
        eventTail++;
        return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }

    // create an empty event to return

    memset( &ev, 0, sizeof( ev ) );
    ev.evTime = Sys_Milliseconds();

    return ev;
}
Пример #3
0
sysEvent_t Sys_GetEvent( void ) {
    sysEvent_t        ev;

    // return if we have data
    if ( eventHead > eventTail ) {
            eventTail++;
            return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }

    // check for network packets
	msg_t                netmsg;
	netadr_t	adr;

	for (int poll = 0; poll < MAX_POLL_RATE; ++poll)
	{
		MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
		if ( Sys_GetPacket ( &adr, &netmsg ) ) {
			netadr_t		*buf;
			int				len;

			// copy out to a seperate buffer for qeueing
			// the readcount stepahead is for SOCKS support
			len = sizeof( netadr_t ) + netmsg.cursize - netmsg.readcount;
			//buf = (netadr_t *)GG_Malloc( len, MemoryBlock::kEventTag, qtrue );
			buf = (netadr_t *) Z_Malloc(len, TAG_EVENT, qfalse, 4);
			*buf = adr;
			memcpy( buf+1, &netmsg.data[netmsg.readcount], netmsg.cursize - netmsg.readcount );
			Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
		}
		else
		{
			// Bail out if there's no more data
			break;
		}
	}

#if 0	// Removed as in SOF2
	// return if we have data
    if ( eventHead > eventTail ) {
            eventTail++;
            return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }
#endif

	// create an empty event to return
    memset( &ev, 0, sizeof( ev ) );
    ev.evTime = Sys_Milliseconds();

    return ev;
}
Пример #4
0
/*
=================
Sys_PumpEvents
=================
*/
void Sys_PumpEvents( void ) {
	char		*s;
	msg_t		netmsg;
	netadr_t	adr;

   // pump the message loop
	Sys_SendKeyEvents();
   
   // check for console commands
   s = Sys_ConsoleInput();
   if ( s ) {
       char	*b;
       int		len;

       len = strlen( s ) + 1;
       b = malloc( len );
	   if ( !b ) {
		   Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" );
	   }
       strcpy( b, s );
       Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
   }

   // check for other input devices
   Sys_Input();

   // check for network packets
   MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
   if ( Sys_GetPacket ( &adr, &netmsg ) ) {
       netadr_t		*buf;
       int				len;

       // copy out to a seperate buffer for qeueing
       len = sizeof( netadr_t ) + netmsg.cursize;
       buf = malloc( len );
	   if ( !buf ) {
		   Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" );
	   }
       *buf = adr;
       memcpy( buf+1, netmsg.data, netmsg.cursize );
       Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
   }
}
Пример #5
0
/*
================
Sys_GetEvent

================
*/
sysEvent_t Sys_GetEvent( void ) {
    MSG			msg;
    sysEvent_t	ev;
    char		*s;
    msg_t		netmsg;
    netadr_t	adr;

    // return if we have data
    if ( eventHead > eventTail ) {
        eventTail++;
        return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }

    // pump the message loop
    while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
        if ( !GetMessage (&msg, NULL, 0, 0) ) {
            Com_Quit_f();
        }

        // save the msg time, because wndprocs don't have access to the timestamp
        g_wv.sysMsgTime = msg.time;

        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    // check for console commands
    s = Sys_ConsoleInput();
    if ( s ) {
        char	*b;
        int		len;

        len = strlen( s ) + 1;
        b = (char *)Z_Malloc( len );
        Q_strncpyz( b, s, len-1 );
        Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
    }

    // check for network packets
    MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
    if ( Sys_GetPacket ( &adr, &netmsg ) ) {
        netadr_t		*buf;
        int				len;

        // copy out to a seperate buffer for qeueing
        // the readcount stepahead is for SOCKS support
        len = sizeof( netadr_t ) + netmsg.cursize - netmsg.readcount;
        buf = (netadr_t *)Z_Malloc( len );
        *buf = adr;
        memcpy( buf+1, &netmsg.data[netmsg.readcount], netmsg.cursize - netmsg.readcount );
        Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
    }

    // return if we have data
    if ( eventHead > eventTail ) {
        eventTail++;
        return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
    }

    // create an empty event to return

    memset( &ev, 0, sizeof( ev ) );
    ev.evTime = timeGetTime();

    return ev;
}