Skip to content

Instantly share code, notes, and snippets.

@milesrout
Created March 29, 2015 21:12
Show Gist options
  • Save milesrout/f04b3cf740de7f1a286b to your computer and use it in GitHub Desktop.
Save milesrout/f04b3cf740de7f1a286b to your computer and use it in GitHub Desktop.
class renderer {
public:
enum class action {
view_add, view_remove, view_activate,
model_matrix_add, model_matrix_remove,
vb_add, vb_remove,
};
private:
static std::atomic<std::queue<std::pair<action, entity_id>>*> global_queue;
std::queue<std::pair<action, entity_id>>* local_queue;
void process_queue() {
global_queue.exchange(this->local_queue);
while (!this->local_queue->empty()) {
auto action_to_perform = this->local_queue->front();
this->local_queue->pop();
switch (action_to_perform.first) {
case action::view_add:
update_view_matrix(action_to_perform.second);
break;
case action::view_remove:
this->views.erase(action_to_perform.second);
break;
case action::view_activate:
this->current_view = action_to_perform.second;
break;
case action::model_matrix_add:
add_model_matrix(action_to_perform.second);
break;
case action::model_matrix_remove:
remove_model_matrix(action_to_perform.second);
break;
}
}
}
void update(double time_delta) {
process_queue();
}
void add_view(entity_id eid) {
renderer::global_queue->push(std::make_pair(action::view_add, entity_id));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment