void _update_position(int v, int tl, int tr, int pos, const T& val) { if (tl == tr) { t[v] = val; } else { int tm = (tl + tr)>>1; if (pos <= tm) _update_position(v*2, tl, tm, pos, val); else _update_position(v*2+1, tm+1, tr, pos, val); t[v] = op(t[v*2], t[v*2+1]); } }
void Mouse::update() { if (locked) { _update_position(); if (lock_updated && active) { pos -= glm::vec2(center_x, center_y); SDL_WarpMouse(center_x, center_y); } else { pos = glm::vec2(0.0f, 0.0f); lock_updated = true; } } else { _update_position(); } }
void p3d_emitter_update(struct p3d_emitter* et, float dt, float* mat) { if (et->active) { float rate = et->cfg->emission_time / et->cfg->count; et->emit_counter += dt; if (et->loop) { while (et->emit_counter > rate) { _add_particle_random(et, mat); et->emit_counter -= rate; } } else { if (!et->cfg->static_mode) { while (et->emit_counter > rate && et->particle_count < et->cfg->count) { _add_particle_random(et, mat); ++et->particle_count; et->emit_counter -= rate; } } else { if (!et->static_mode_finished) { _add_particle_static(et, mat); et->static_mode_finished = true; } } } } struct p3d_particle* prev = NULL; struct p3d_particle* curr = et->head; while (curr) { if (curr->ud) { struct ps_vec2 pos; ps_vec3_projection(&curr->pos, &pos); UPDATE_FUNC(curr->ud, pos.x + mat[4], pos.y + mat[5]); } curr->life -= dt; if (curr->life > 0) { _update_speed(et, dt, curr); _update_angle(et, dt, curr); _update_position(et, dt, curr); prev = curr; curr = curr->next; } else { struct p3d_particle* next = curr->next; if (prev) { prev->next = next; } _remove_particle(et, curr); if (et->head == curr) { et->head = next; if (!next) { et->tail = NULL; } } curr = next; } } et->tail = prev; }