summaryrefslogtreecommitdiff
path: root/threading.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'threading.cpp')
-rw-r--r--threading.cpp97
1 files changed, 61 insertions, 36 deletions
diff --git a/threading.cpp b/threading.cpp
index ff891a6..84e5463 100644
--- a/threading.cpp
+++ b/threading.cpp
@@ -1,58 +1,83 @@
-
-static int
-MainRenderer(void *ptr)
-{
- for(;;)
- {
- SDL_SemWait(Semaphore);
- }
-}
-
-#if 0
static void
-PushRect(rectangle RenderRegion)
-{
- uint32 Q = SDL_AtomicGet(&QueuedEntries);
- render_entry *Entry = Entries + Q;
- Entry->RenderRegion = RenderRegion;
- SDL_AtomicAdd(&QueuedEntries, 1);
- SDL_SemPost(Semaphore);
-}
-
-static void
-RenderLayers(render_queue *RenderInfo, rectangle RenderRegion);
+RenderLayers(render_entry Entry);
static bool32
-CheckQueue(render_queue RenderInfo, uint16 Index)
+CheckQueue(uint16 Index)
{
bool32 Result = 0;
uint32 Q = SDL_AtomicGet(&QueuedEntries);
uint32 C = SDL_AtomicGet(&CurrentEntry);
if (Q > C)
- {
- if (SDL_AtomicCAS(&CurrentEntry, C, C + 1)) {
- render_entry *Entry = Entries + C;
- Assert(Entry->RenderRegion.Max.x != 0);
- RenderLayers(&RenderInfo, Entry->RenderRegion);
- // printf("(FINISHED) Thread %i, region X%i Y%i\n", Index, Entry->RenderRegion.Min.x/240, Entry->RenderRegion.Min.y/135);
- SDL_AtomicAdd(&CompletedEntries, 1);
- Result = 1;
- }
+ {
+ if (SDL_AtomicCAS(&CurrentEntry, C, C + 1)) {
+ // printf("C: %i START: F%i Thread %i, region X%i Y%i\n", C, Entry->FrameNumber, Index, Entry->RenderRegion.Min.x, Entry->RenderRegion.Min.y);
+ RenderLayers(Entries[C]);
+ // printf("END: F%i Thread %i, region X%i Y%i\n", Entry->FrameNumber, Index, Entry->RenderRegion.Min.x, Entry->RenderRegion.Min.y);
+ SDL_AtomicAdd(&CompletedEntries, 1);
+ Result = 1;
}
+ }
return Result;
}
static int
TestThread(void *ptr)
{
- thread_info *ThreadInfo = (thread_info *)ptr;
- uint16 Index = ThreadInfo->Index;
+ uint16 Index = *(uint16 *)ptr;
for(;;)
{
- if (!CheckQueue(*ThreadInfo->RenderInfo, Index))
+ if (!CheckQueue(Index))
{
SDL_SemWait(Semaphore);
}
}
}
-#endif
+
+static bool32
+Threading_IsActive()
+{
+ uint32 C = SDL_AtomicGet(&CompletedEntries);
+ Assert(C < 17);
+ return (C == 16) ? false : true;
+}
+
+static void
+Threading_BitmapOp(void *Data, void *OutputBuffer, rectangle InitialRenderRegion)
+{
+ uint16 TileWidth = (InitialRenderRegion.Max.x - InitialRenderRegion.Min.x) / 4;
+ uint16 TileHeight = (InitialRenderRegion.Max.y - InitialRenderRegion.Min.y) / 4;
+
+ SDL_AtomicSet(&QueuedEntries, 0);
+ SDL_AtomicSet(&CurrentEntry, 0);
+ SDL_AtomicSet(&CompletedEntries, 0);
+
+ for (int y = 0; y < 4; y++) {
+ for (int x = 0; x < 4; x++) {
+ // if (x == y) {
+ rectangle RenderRegion = { TileWidth*x, TileHeight*y, TileWidth + TileWidth*x, TileHeight + TileHeight*y };
+
+ RenderRegion.Min.x -= RenderRegion.Min.x % 8;
+ RenderRegion.Min.y -= RenderRegion.Min.y % 8;
+ RenderRegion.Max.x -= RenderRegion.Max.x % 8;
+ RenderRegion.Max.y -= RenderRegion.Max.y % 8;
+
+ if (RenderRegion.Max.x > InitialRenderRegion.Max.x)
+ RenderRegion.Max.x = InitialRenderRegion.Max.x;
+ if (RenderRegion.Max.y > InitialRenderRegion.Max.y)
+ RenderRegion.Max.y = InitialRenderRegion.Max.y;
+
+ if (x == 3)
+ RenderRegion.Max.x = InitialRenderRegion.Max.x;
+ if (y == 3)
+ RenderRegion.Max.y = InitialRenderRegion.Max.y;
+
+ render_entry Entry = { Data, OutputBuffer, RenderRegion };
+
+ uint32 Q = SDL_AtomicGet(&QueuedEntries);
+ *(Entries + Q) = Entry;
+ SDL_AtomicAdd(&QueuedEntries, 1);
+ SDL_SemPost(Semaphore);
+ }
+ // }
+ }
+}