Exemplo n.º 1
0
/* the loop itself */
void wait_for_players ()
{
    SDL_Event event;

    mw_init ();

    do {
        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                break;
            }

        /*
         * check some little things and do the network stuff
         */
        network_loop ();

        /*
         * the drawing stuff
         */
        if (mw_check_screenredraw()) {
            d_printf ("Draw Status\n");
            gfx_blitdraw ();
            draw_logo ();
            if (bman.gametype==GT_team) mw_draw_all_teams();
            else mw_draw_all_player ();
        }
        gfx_blitdraw ();

        /*
         *	input handling
         */
        keyb_loop (&event);
        mw_keys_loop ();

        chat_loop (&event);
        chat.active = 1;

        s_calctimesync ();
    } while (bman.state == GS_wait && bman.sock != -1);

    mw_shutdown ();
};
Exemplo n.º 2
0
void
game_loop ()
{
    SDL_Event event;
    int done = 0,
        eventstate;

    if (GT_MP)
        net_game_fillsockaddr ();
    if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 ) {
        fprintf ( stderr, "Unable to initialize Joystick: %s\n", SDL_GetError() );
    }
    printf ( "%i joysticks found\n", SDL_NumJoysticks () );

    menu = NULL;
    bman.updatestatusbar = 1;   // force an update
    timestamp = SDL_GetTicks (); // needed for time sync.
    d_gamedetail ("GAME START");

    gfx_blitupdaterectclear ();
    draw_logo ();
    draw_field ();
    SDL_Flip (gfx.screen);
    draw_players ();

    if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) {
        players[bman.p_nr].ready = 1;
        if (GT_MP_PTPS)
            send_playerdata (&players[bman.p_servnr].net.addr, bman.p_nr, &players[bman.p_nr]);
    }
    if (bman.p2_nr >= 0 && bman.p2_nr < MAX_PLAYERS) {
        players[bman.p2_nr].ready = 1;
        if (GT_MP_PTPS)
            send_playerdata (&players[bman.p_servnr].net.addr, bman.p2_nr, &players[bman.p2_nr]);
    }
	fire_init();
    while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
        SDL_JoystickUpdate ();
        if ((eventstate = SDL_PollEvent (&event)) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                done = 1;
                bman.state = GS_quit;
            }

        /*
         * input handling
         */
        keyb_loop (&event);

        game_keys_loop ();

        if (GT_MP)
            chat_loop (&event);

        if ((!IS_LPLAYER2) && (!chat.active))
            chat_setactive (1, 1);

        restore_players_screen ();

        player_check (bman.p_nr);
        if (IS_LPLAYER2)
            player_check (bman.p2_nr);

        dead_playerani ();

        special_loop ();

        player_move (bman.p_nr);
        if (IS_LPLAYER2)
            player_move (bman.p2_nr);

        if (GT_MP) {
            player_calcpos ();
            network_loop ();
        }

        if (bman.state == GS_running)
            single_loop ();

        bomb_loop ();
		/* wind_loop (); SOON */
		fire_loop ();
        field_loop ();
        flitems_loop ();

        draw_players ();
        game_draw_info ();      // will set the var bman.player_nr

        /* check if there is only one player left and the game is in multiplayer mode
           and if there the last dieing animation is done */
        if (game_check_endgame () && bman.timeout >= 0.0f)
            bman.timeout = 0.0f;

        if ((GT_SP || GT_MP_PTPM) && bman.timeout < -GAME_OVERTIMEOUT) {
            d_printf ("GAME: Game Over\n");
            done = 1;
        }

        stonelist_draw ();

        /* if there is any menu displayed do so */
        if (menu != NULL)
            game_menu_loop (&event, eventstate);

        gfx_blitdraw ();

        s_calctimesync ();
        bman.timeout -= timediff;

    }

    if (menu != NULL) {
        menu_delete (menu);
        menu = NULL;
    }

    gfx_blitdraw ();

    chat_show (-1, -1, -1, -1);
    draw_logo ();
    gfx_blitupdaterectclear ();
    SDL_Flip (gfx.screen);

    d_gamedetail ("GAME END");
    d_printf ("done = %d\n", done);
};
Exemplo n.º 3
0
/*
    sets up everything for the network game..
	on servers the game field will be created and the clients will wait for the game data
	within the network loop
*/
void
net_transmit_gamedata ()
{
    int done = 0,
        keypressed = 0,
        x,
        y,                      // network upload status for one step
        p,
        i,
        net_istep;              // network init step
    SDL_Event event;
    Uint8 *keys;
    Uint32 downtimestamp = 0;

    draw_logo ();

    if (GT_MP_PTPM)
        font_draw (100, 0, "Waiting for the Clients", 1, 0);
    else
        font_draw (100, 0, "Downloading Data", 1, 0);

    /* 
       prepare everything for the loop 
     */
    for (x = 0; x < MAX_PLAYERS; x++) {
        players[x].net.timestamp = 0;
        players[x].net.net_status = -1;
        if ((PS_IS_aiplayer (players[x].state)) || (x == bman.p_servnr) || (x == bman.p2_nr)
            || (players[x].net.flags & NETF_local2) == NETF_local2)
            players[x].net.net_istep = 0;
        else
            players[x].net.net_istep = 3;
    }

    y = -1;
    if (GT_MP_PTPM)
        net_istep = 0;
    else
        net_istep = 3;

    draw_netupdatestate (1);
    SDL_Flip (gfx.screen);

    downtimestamp = timestamp;
    while (!done && (bman.state == GS_update || (GT_MP_PTPS && net_istep != 0))) {
        /* the network thing */

        network_loop ();

        /* if PTPM check if all players are ready */
        if (GT_MP_PTPM) {
            if (timestamp - downtimestamp > TIME_UPDATEINFO) {
                downtimestamp = timestamp;
                net_send_updateinfo ();
            }
            for (p = 0, i = 1; p < MAX_PLAYERS; p++)
                if (PS_IS_playing (players[p].state)
                    && players[p].net.net_istep != 0)
                    i = 0;
            if (i == 1) {       /* all players are ready */
                done = 1;
                bman.state = GS_ready;
            }
        }

        /* if PTPS get all data */
        if (GT_MP_PTPS) {
            if (net_istep == 3) {
                /* 
                   get tunneldata 
                 */
                if ((y < GAME_MAX_TUNNELS - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    y++;
                    downtimestamp = timestamp;
                    send_tunneldata (&players[bman.p_servnr].net.addr, y, -1, -1);
                }
                else if (y < GAME_MAX_TUNNELS
                         && y != players[bman.p_nr].net.net_status && y >= 0
                         && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* we have got no tunnel data */
                    y--;
                }
                else if (y == GAME_MAX_TUNNELS - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all tunnel data */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                }
            }

            if (net_istep == 2) {
                /* 
                   get field data
                 */
                if ((y < map.size.y - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    /* send field data req */
                    y++;
                    downtimestamp = timestamp;
                    send_getfield (&players[bman.p_servnr].net.addr, y);
                }
                else if (y < map.size.y && y != players[bman.p_nr].net.net_status
                         && y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* getdata timed out - we have got no field data */
                    y--;
                }
                else if (y == map.size.y - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all field data */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                }
            }

            if (net_istep == 1) {
                /*
                   get player data
                 */
                if ((y < MAX_PLAYERS - 1 && y == players[bman.p_nr].net.net_status)
                    || y == -1) {
                    /* send player date req */
                    y++;
                    downtimestamp = timestamp;
                    send_getplayerdata (&players[bman.p_servnr].net.addr, y);
                }
                if (y < MAX_PLAYERS && y != players[bman.p_nr].net.net_status
                    && y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                    /* we have got no player data */
                    y--;
                }
                if (y == MAX_PLAYERS - 1 && players[bman.p_nr].net.net_status == y) {
                    /* we have got all playerdata */
                    y = -1;
                    players[bman.p_nr].net.net_istep = --net_istep;
                    players[bman.p_nr].net.net_status = -1;
                    downtimestamp = timestamp;
                    send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0);
                }
            }

            if (net_istep == 0 && players[bman.p_nr].net.net_status == -1
                && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
                /* server did not send informations back */
                downtimestamp = timestamp;
                send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0);
            }
        }

        /* do the grafik work */
        draw_netupdatestate (0);

        if (s_fetchevent (&event) != 0)
            switch (event.type) {
            case (SDL_QUIT):
                bman.state = GS_quit;
                bman.p_nr = -1;
                done = 1;
            }

        keys = SDL_GetKeyState (NULL);

        if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
            done = 1;
            bman.p_nr = -1;
            keypressed = 1;
            bman.state = GS_startup;
        }

        if (event.type == SDL_KEYUP)
            keypressed = 0;
    }

    timestamp = SDL_GetTicks (); // needed for time sync.
    SDL_Delay (1);              // we don't need here anything better

    /* player is only watching so just go after we have got everything
       go to show the field */
    if (GT_MP_PTPS && bman.state == GS_update && net_istep == 0 && players[bman.p_nr].gfx_nr == -1) {
        done = 1;
        bman.state = GS_running;
    }
};