Skip to content

Commit

Permalink
checks for rendering within the handlers view + switched to explicit …
Browse files Browse the repository at this point in the history
…vector accesses
  • Loading branch information
LucAlexander committed Aug 27, 2022
1 parent 3e5be04 commit a170b07
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
6 changes: 3 additions & 3 deletions collision_mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vu32_t get_pixel_color_data(int32_t bpp, uint8_t* pixels, int32_t w, int32_t h){
}

spacial_quadtree_node_t* partition_pixel_color_data_to_quadtree(uint32_t x_start, uint32_t y_start, uint32_t w, uint32_t h, vu32_t pixel_colors, uint32_t depth, uint32_t absw){
uint32_t color = vu32_tGet(&pixel_colors, x_start + (y_start*absw));
uint32_t color = pixel_colors.data[x_start + (y_start*absw)];
spacial_quadtree_node_t* node = spacial_quadtree_node_init(color);
node->depth = depth;
node->mask.x = x_start;
Expand All @@ -51,7 +51,7 @@ spacial_quadtree_node_t* partition_pixel_color_data_to_quadtree(uint32_t x_start
for (y=y_start;y<y_start+h;++y){
offset = y*absw;
for (x=x_start;x<x_start+w;++x){
if (vu32_tGet(&pixel_colors, x+offset) != color){
if (pixel_colors.data[x+offset] != color){
node->state = INTERNAL_NODE;
uint32_t w2 = w/2;
uint32_t h2 = h/2;
Expand Down Expand Up @@ -170,7 +170,7 @@ spacial_quadtree_node_t* retrieve_quadtree_node(spacial_quadtree_node_t* root, u

uint8_t collides_with_mask(v4 calling, vv4_t* parts){
for (uint32_t i = 0;i<parts->size;++i){
v4 mask = vv4_tGet(parts, i);
v4 mask = parts->data[i];
mask.w += mask.x;
mask.h += mask.y;
if (rectCollidesB(calling, mask)){
Expand Down
49 changes: 36 additions & 13 deletions graphicsutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ float scaleOnY(GraphicsHandler* ghandle, float val){
return val/ghandle->spriteScaleY;
}

uint8_t render_in_view(GraphicsHandler* ghandle, float x, float y, float w, float h){
v4 rect = {x, y, w, h};
return render_in_view_v4(ghandle, rect);
}

uint8_t render_in_view_v4(GraphicsHandler* ghandle, v4 rect){
v4 v = {
ghandle->renderView.px,
ghandle->renderView.py,
ghandle->renderView.pw,
ghandle->renderView.ph,
};
return rectCollides(v, rect);
}

void renderSetView(GraphicsHandler* ghandle, view v){
ghandle->renderView = v;
const SDL_Rect port = {v.px, v.py, v.pw, v.ph};
Expand Down Expand Up @@ -336,21 +351,34 @@ void progress_animation(GraphicsHandler* ghandle, animator_t* animator){
}

void blitSurface(GraphicsHandler* ghandle, SDL_Texture* texture, SDL_Rect* srcRect, SDL_Rect destRect){
if (!render_in_view(ghandle, destRect.x, destRect.y, destRect.w, destRect.h)){
return;
}
formatDestRectToView(ghandle, &destRect);
SDL_RenderCopy(ghandle->renderer, texture, srcRect, &destRect);
}

void blitSurfaceEX(GraphicsHandler* ghandle, SDL_Texture* texture, SDL_Rect* srcRect, SDL_Rect destRect, double angle, SDL_Point* center, SDL_RendererFlip flip){
if (!render_in_view(ghandle, destRect.x, destRect.y, destRect.w, destRect.h)){
return;
}
formatDestRectToView(ghandle, &destRect);
SDL_RenderCopyEx(ghandle->renderer, texture, srcRect, &destRect, angle, center, flip);
}

void blitSurfaceF(GraphicsHandler* ghandle, SDL_Texture* texture, SDL_Rect* srcRect, SDL_FRect destRect){
if (!render_in_view(ghandle, destRect.x, destRect.y, destRect.w, destRect.h)){
return;
}
formatDestFRectToView(ghandle, &destRect);

SDL_RenderCopyF(ghandle->renderer, texture, srcRect, &destRect);
}

void blitSurfaceEXF(GraphicsHandler* ghandle, SDL_Texture* texture, SDL_Rect* srcRect, SDL_FRect destRect, double angle, SDL_FPoint* center, SDL_RendererFlip flip){
if (!render_in_view(ghandle, destRect.x, destRect.y, destRect.w, destRect.h)){
return;
}
formatDestFRectToView(ghandle, &destRect);
SDL_RenderCopyExF(ghandle->renderer, texture, srcRect, &destRect, angle, center, flip);
}
Expand Down Expand Up @@ -395,18 +423,13 @@ void drawRectV4B(GraphicsHandler* ghandle, v4 r, uint8_t p){
}

void drawRectB(GraphicsHandler* ghandle, float x1, float y1, float x2, float y2, uint8_t p){
SDL_FRect bound = {
x1-ghandle->renderView.x,
y1-ghandle->renderView.y,
x2-x1-ghandle->renderView.x,
y2-y1-ghandle->renderView.y
};
if (p & FILL){
SDL_RenderFillRectF(ghandle->renderer, &bound);
}
if (p & OUTLINE){
SDL_RenderDrawRectF(ghandle->renderer, &bound);
}
drawRect(
ghandle,
x1,
y1,
x2-x1-ghandle->renderView.x,
y2-y1-ghandle->renderView.y,
p);
}

void fontHandlerInit(GraphicsHandler* ghandle){
Expand Down Expand Up @@ -519,6 +542,6 @@ void queryTextSize(GraphicsHandler* ghandle, const char* text, int32_t* w, int32
void texture_arena_release(GraphicsHandler* ghandle){
uint32_t i;
for (i = 0;i<ghandle->texture_arena.size;++i){
SDL_DestroyTexture(vecT_tGet(&ghandle->texture_arena, i));
SDL_DestroyTexture(ghandle->texture_arena.data[i]);
}
}
3 changes: 3 additions & 0 deletions graphicsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void renderSetView(GraphicsHandler* ghandle, view v);
view renderGetView(GraphicsHandler* ghandle);
void renderSetViewAbsolute(GraphicsHandler* ghandle);

uint8_t render_in_view(GraphicsHandler* ghandle, float x, float y, float x2, float y2);
uint8_t render_in_view_v4(GraphicsHandler* ghandle, struct v4 rect);

void renderSetSpriteScale(GraphicsHandler* ghandle, float scaleX, float scaleY);
float scaleOnX(GraphicsHandler* ghandle, float val);
float scaleOnY(GraphicsHandler* ghandle, float val);
Expand Down
4 changes: 2 additions & 2 deletions xi.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void xi_run_system_group(program_state* state, uint32_t group){
vsys_t system_list = state->system_group[group];
xi_utils xi = construct_xi_utils(state);
for (i = 0;i<system_list.size;++i){
system_run(vsys_tGet(&system_list, i), &xi);
system_run(system_list.data[i], &xi);
}
}

Expand All @@ -123,7 +123,7 @@ void xi_run_system_group_queued(program_state* state, uint32_t group){
vsys_t system_list = state->system_group[group];
xi_utils xi = construct_xi_utils(state);
for (i = 0;i<system_list.size;++i){
system_run_queued(vsys_tGet(&system_list, i), &xi, &xi.graphics->render_order);
system_run_queued(system_list.data[i], &xi, &xi.graphics->render_order);
}
}

Expand Down

0 comments on commit a170b07

Please sign in to comment.