void render_entity( entity_t* ent ) { int i, j; coord_t x = ent->r.v1.x; coord_t y = ent->r.v1.y; if( ent->ent_type == ET_WALL ) { for( i = 0; i < ent->size.x; i++ ) for( j = 0; j < ent->size.y; j++ ) wall_model->render( x+i,y+j ); } if( ent->ent_type == ET_APPLE ) { value_t food = ent->attrs[AP_FOOD]; apple_model->render( x, y, (0.3 + 0.1 * food)*ent->size.x ); } if( ent->ent_type == ET_PLAYER ) { value_t dir = ent->attrs[PL_DIR]; value_t life = ent->attrs[PL_LIFE]; value_t hit = ent->attrs[PL_HIT]; float pfx2,pfy2; /* interpolated player position */ updatePositionForPlayer( ent->ent_id, x, y, &pfx2, &pfy2 ); if( !hit ) player_model->render( pfx2, pfy2, (0.5 + 0.7*life/100)*ent->size.x, dir*90 ); else player_model->render( pfx2, pfy2, (0.5 + 0.7*life/100)*ent->size.x,-dir*90, -90); } }
void ClientRenderModule::renderSingleFrame() { int i,j,ii,jj; MapCell *m; /* local copy for share data */ int px,py; /* player position */ int dir,life,attr; /* player attributes */ int x1,x2,y1,y2; /* map coordinates */ float pfx,pfy; /* interpolated player position (for main player) */ float pfx2,pfy2; /* interpolated player position (for another player) */ MapCell map[CLIENT_MATRIX_SIZE][CLIENT_MATRIX_SIZE]; OglObject *player_model;/* type of player */ /* create local copy for shared data */ SDL_LockMutex(client_data->game_mutex); px = client_data->xpos; py = client_data->ypos; x1 = client_data->x1; x2 = client_data->x2; y1 = client_data->y1; y2 = client_data->y2; dir = client_data->dir; life = client_data->life; attr = client_data->attr; for ( i = 0; i < CLIENT_MATRIX_SIZE; i++ ) for ( j = 0; j < CLIENT_MATRIX_SIZE; j++ ) memcpy( &map[i][j], &client_data->map[i][j], sizeof(MapCell) ); SDL_UnlockMutex(client_data->game_mutex); /* begin rendering */ w.beginRender(); /* get new player position */ updatePosition(&pmd, px,py); pfx = pmd.pfx; pfy = pmd.pfy; /* set camera and lights */ gluLookAt(pfx-4.0,6.0,pfy-4.0, /* position */ pfx-0.5,0.0,pfy-0.5, /* look at */ 0,1,0); /* up direction */ /* draw floor */ for ( i = max( 0, px - MAX_CLIENT_VIEW ); i <= min( client_data->mapx, px + MAX_CLIENT_VIEW ); i++ ) for ( j = max( 0, py - MAX_CLIENT_VIEW ); j <= min( client_data->mapy, py + MAX_CLIENT_VIEW ); j++ ) //for ( i = x1; i < x2; i++ ) // for ( j = y1; j < y2; j++ ) wfloor->render(i,j); /* draw map */ for ( i = x1; i < x2; i++ ) for ( j = y1; j < y2; j++ ) { ii = MAX_CLIENT_VIEW - ( px - i ); jj = MAX_CLIENT_VIEW - ( py - j ); m = &map[ii][jj]; if ( m->terrain != 0 ) obstacle->render( i,j ); if ( m->type == CELL_OBJECT ) resource->render( i,j, 0.3 + 0.1 * m->quantity ); if ( m->type == CELL_PLAYER ) { player_model = player[ m->p_attr % nplayer_models ]; updatePositionForPlayer( m->id, i,j, &pfx2, &pfy2); if ( m->dir >= 0 ) player_model->render( pfx2,pfy2, 0.5 + 0.7 * m->life / 100, m->dir*90 ); else player_model->render( pfx2,pfy2, 0.5 + 0.7 * m->life / 100, -m->dir*90, -90); } if ( m->type == CELL_OBJ_PLAYER ) { resource->render( i,j, 0.3 + 0.1 * m->quantity ); player_model = player[ m->p_attr % nplayer_models ]; updatePositionForPlayer( m->id, i,j, &pfx2, &pfy2); if ( m->dir >= 0 ) player_model->render( pfx2,pfy2, 0.5 + 0.7 * m->life / 100, m->dir*90 ); else player_model->render( pfx2,pfy2, 0.5 + 0.7 * m->life / 100, -m->dir*90, -90); } } /* draw player */ player_model = player[ attr % nplayer_models ]; if ( dir >= 0 ) player_model->render( pfx,pfy, 0.5 + 0.7 * life / 100 , dir * 90 ); else player_model->render( pfx,pfy, 0.5 + 0.7 * life / 100, -dir * 90, -90); /* get coordinates for the status area */ SDL_Surface *screen = w.getScreen(); SDL_Rect rect; rect.w = client_data->resx; rect.h = 40; rect.x = 0; rect.y = client_data->resy - rect.h; /* display status */ SDL_FillRect( screen, &rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) ); SDL_UpdateRect(screen, rect.x,rect.y, rect.w,rect.h); char sbuffer[256]; SDL_WM_SetCaption( client_data->name, NULL); if ( client_data->state != PLAYING ) sprintf(sbuffer, "%s", client_states[client_data->state]); else sprintf(sbuffer, "playing -> %s ( coord = %d,%d life = %d )", AI_state_names[client_data->purpose], px,py, life); font->render(rect.x + 9, rect.y + 2, sbuffer, screen); sprintf(sbuffer, "update interval: average = %.1lfms, last = %.1lfms, fps = %.1f", client_data->average_update_interval, client_data->last_update_interval, 1000.0 / frame_render_interval ); font->render(rect.x + 9, rect.y + 21, sbuffer, screen); SDL_UpdateRect(screen, rect.x,rect.y, rect.w,rect.h); /* finish frame rendering */ updateMovementDataVectors(); w.endRender(); }