Skip to content

Commit

Permalink
WIP: async preview
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Aug 17, 2023
1 parent 9140fb6 commit 712830c
Show file tree
Hide file tree
Showing 10 changed files with 963 additions and 473 deletions.
37 changes: 37 additions & 0 deletions src/drawdance/libcommon/dpcommon/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ static size_t resize(DP_Queue *queue, size_t old_capacity, size_t element_size)
return new_capacity;
}

void *DP_queue_unshift(DP_Queue *queue, size_t element_size)
{
DP_ASSERT(queue);
DP_ASSERT(element_size > 0);
DP_ASSERT(queue->capacity > 0);
DP_ASSERT(queue->used <= queue->capacity);
size_t used = queue->used;
size_t capacity = queue->capacity;
if (used == capacity) {
capacity = resize(queue, capacity, element_size);
}
size_t head = queue->head;
size_t new_head = head == 0 ? capacity - 1 : head - 1;
queue->head = new_head;
queue->used = used + 1;
return element_at(queue, new_head, element_size);
}

void *DP_queue_push(DP_Queue *queue, size_t element_size)
{
DP_ASSERT(queue);
Expand Down Expand Up @@ -196,3 +214,22 @@ size_t DP_queue_search_index(DP_Queue *queue, size_t element_size,
}
return used;
}

size_t DP_queue_search_last_index(DP_Queue *queue, size_t element_size,
bool (*predicate)(void *element, void *user),
void *user)
{
DP_ASSERT(queue);
DP_ASSERT(predicate);
size_t capacity = queue->capacity;
size_t used = queue->used;
size_t head = queue->head;
for (size_t i = 0; i < used; ++i) {
size_t j = used - i - 1;
void *element = element_at(queue, (head + j) % capacity, element_size);
if (predicate(element, user)) {
return j;
}
}
return used;
}
6 changes: 6 additions & 0 deletions src/drawdance/libcommon/dpcommon/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void DP_queue_dispose(DP_Queue *queue);
void DP_queue_clear(DP_Queue *queue, size_t element_size,
void (*dispose_element)(void *));

void *DP_queue_unshift(DP_Queue *queue, size_t element_size);

void *DP_queue_push(DP_Queue *queue, size_t element_size);

void *DP_queue_peek(DP_Queue *queue, size_t element_size);
Expand All @@ -71,5 +73,9 @@ size_t DP_queue_search_index(DP_Queue *queue, size_t element_size,
bool (*predicate)(void *element, void *user),
void *user);

size_t DP_queue_search_last_index(DP_Queue *queue, size_t element_size,
bool (*predicate)(void *element, void *user),
void *user);


#endif
2 changes: 2 additions & 0 deletions src/drawdance/libengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dp_target_sources(dpengine
dpengine/paint_engine.c
dpengine/pixels.c
dpengine/player.c
dpengine/preview.c
dpengine/recorder.c
dpengine/renderer.c
dpengine/snapshots.c
Expand Down Expand Up @@ -72,6 +73,7 @@ dp_target_sources(dpengine
dpengine/paint_engine.h
dpengine/pixels.h
dpengine/player.h
dpengine/preview.h
dpengine/recorder.h
dpengine/renderer.h
dpengine/snapshots.h
Expand Down
Loading

0 comments on commit 712830c

Please sign in to comment.