Skip to content

Commit 75d3394

Browse files
committed
cleaned up code a bit
1 parent 37cef59 commit 75d3394

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/data_block.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
#include "include/data_block.h"
21
#include <search.h>
32
#include <math.h>
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
#include <malloc.h>
6+
7+
#include "include/data_block.h"
48
#include "include/simd_common.h"
59

610
/* ====================| Public facing DataBlock functions |==================== */
@@ -113,10 +117,9 @@ draw_data_block(DataBlock *block, pgSurfaceObject *dest, const int blend_flag)
113117

114118
/* ====================| Internal DataBlock functions |==================== */
115119

116-
int
117-
calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
120+
void
121+
calculate_surface_index_occurrences(DataBlock *block)
118122
{
119-
/* CALCULATE THE SURFACE INDEX OCCURRENCES */
120123
block->frag_map.used_f = 0;
121124

122125
int const *indices = block->animation_indices;
@@ -148,8 +151,13 @@ calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
148151
clamp_int(current_value, 0, block->num_frames - 1);
149152
fragment->length = current_count;
150153
}
154+
}
151155

152-
/* POPULATE THE DESTINATIONS ARRAY */
156+
int
157+
populate_destinations_array(pgSurfaceObject *dest, DataBlock *block)
158+
{
159+
FragmentationMap *frag_map = &block->frag_map;
160+
Fragment *fragments = frag_map->fragments;
153161

154162
BlitDestination *destinations = frag_map->destinations;
155163
float *positions_x = block->positions_x.data;
@@ -173,6 +181,7 @@ calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
173181
}
174182

175183
SDL_Surface const *src_surf = src_obj->surf;
184+
const int src_pitch = src_surf->pitch / 4;
176185
SDL_Rect src_rect = {0, 0, src_surf->w, src_surf->h};
177186

178187
for (int j = 0; j < length; j++) {
@@ -193,7 +202,7 @@ calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
193202
destination->src_offset =
194203
(src_rect.x < dest_clip->x ? dest_clip->x - src_rect.x : 0) +
195204
(src_rect.y < dest_clip->y ? dest_clip->y - src_rect.y : 0) *
196-
src_surf->pitch / 4;
205+
src_pitch;
197206
}
198207

199208
positions_x += length;
@@ -203,6 +212,17 @@ calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
203212
return 1;
204213
}
205214

215+
int
216+
calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
217+
{
218+
calculate_surface_index_occurrences(block);
219+
220+
if (!populate_destinations_array(dest, block))
221+
return 0;
222+
223+
return 1;
224+
}
225+
206226
void
207227
blit_fragments(pgSurfaceObject *dest, FragmentationMap *frag_map, DataBlock *block,
208228
int blend_flags)

0 commit comments

Comments
 (0)