使用sfml,出于某些原因,我想将顶点存储在这样的列表中:
std::list<sf::Vertex> shape{};
shape.push_back(sf::Vertex(...);
但是我真的不知道如何拨打电话
window.draw(...);
我想它应该类似于这样:
window.draw(shape.begin(), shape.size(), sf::LineStrip);
现在我想它行不通的原因是因为列表不支持随机访问...有人知道吗?
答案 0 :(得分:2)
SFML希望在连续存储中给出顶点。您可以这样做:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if contactList != nil {
return contactList.count
}
if inSearchMode {
return filteredData.count
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
let contact: CNContact!
contact = contactList[indexPath.row]
cell.textLabel?.text = "\(contact.givenName) \(contact.familyName)"
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let contact = contactList[indexPath.row]
let controller = CNContactViewController(for: contact)
navigationController?.pushViewController(controller, animated: true)
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchBar.text == nil || searchBar.text == "" {
inSearchMode = false
view.endEditing(true)
tableView.reloadData()
} else{
inSearchMode = true
filteredData = contactList.filter {
$0.givenName.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive ]) != nil ||
$0.familyName.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive ]) != nil
}
tableView.reloadData()
}
}
当然,首先使用std::vector<sf::Vertex> vec(shape.begin(), shape.end()); // copy
window.draw(vec.data, vec.size(), sf::LineStrip);
(或vector
)会更有效率。