static void sv_net_send_entities(client_t *cl) { netmsg msg; entity *ent; animation_t *ani; /* Send each entitiy the client can see */ for( ent = root ; ent != NULL ; ent = ent->next ) { if( ent->mode == LIMBO ) continue; /* Only the client can see their own invisible entity */ if( ent->visible == 0 && cl->ent != ent ) continue; ani = entity_type_animation( ent->type_info, ent->mode ); /* Skip if X is out of range */ if( ent->x + ani->img_w < cl->screenpos.x ) continue; if( ent->x > cl->screenpos.x + cl->view_w ) continue; /* Skip if Y is out of range */ if( ent->y + ani->img_h < cl->screenpos.y ) continue; if( ent->y > cl->screenpos.y + cl->view_h ) continue; msg = entity_to_netmsg(ent); if( cl->ent == ent ) { msg.type = NETMSG_MYENTITY; } else msg.type = NETMSG_ENTITY; net_put_message(cl->nc, msg); } }
/* Preload images for entities that could be found on this map and gamemode. This was basically cut & paste from bits of ../server/sv_map.c */ void preload_entities(char *filename, int gamemode) { char buf[MAXLINE], name[32], *line; ent_type_t *et; FILE *file; int entity_section, i, skipline; /* Open the map file */ if( !(file = open_data_file("maps", filename) ) ) { printf("%s: Couldn't open %s\n", __FILE__, filename); return; } if( !ent_img_loaded[client.entity_type] ) { /* Load clients entity image */ if( (et = entity_type(client.entity_type)) == NULL ) return; image(entity_type_animation(et, ALIVE)->pixmap, MASKED); ent_img_loaded[client.entity_type] = 1; } /* Scan map for entities that will be loaded */ entity_section = 0; /* Found section yet? */ while( !feof(file) ) { if( !fgets(buf, MAXLINE, file) ) break; CHOMP(buf); if( buf[0] == '#' || buf[0] == '\0' ) continue; /* skip line */ if( entity_section ) { line = buf; skipline = 0; /* check for gamemode specific line prefix characters */ for(i=0 ; i<NUM_GAME_MODES ; i++ ) { if( buf[0] == gamemodechar[i] ) { if( gamemode == i ) line = buf + 1; else skipline = 1; } } if( skipline ) continue; /* Not in our mode */ if( sscanf(line, "%s", name) && strcasecmp(name, "SPAWN") != 0 ) { for( i=0 ; i < num_entity_types ; i++ ) { if( (et = entity_type(i)) == NULL ) continue; if( !ent_img_loaded[i] && !strcasecmp( et->name, name ) ) { ent_img_loaded[i] = 1; image(entity_type_animation(et,ALIVE)->pixmap, MASKED); } } } } else if( !strcasecmp("ENTITY", buf) ) entity_section = 1; } fclose(file); }