Minimal optimization

This commit is contained in:
Amine B. Hassouna
2018-12-01 12:20:10 +01:00
parent d3c9c890d4
commit 3fdbc57d88
2 changed files with 24 additions and 18 deletions

View File

@@ -63,7 +63,7 @@ struct Grid
SDL_Color backgroundColor; SDL_Color backgroundColor;
// Grid border thickness and color // Grid border thickness and color
int border; unsigned int border;
SDL_Color borderColor; SDL_Color borderColor;
// Number of cells over the x axis // Number of cells over the x axis
@@ -72,7 +72,7 @@ struct Grid
int yCells; int yCells;
// Cells boder thickness and color // Cells boder thickness and color
int cellsBorder; unsigned int cellsBorder;
SDL_Color cellsBorderColor; SDL_Color cellsBorderColor;
// Matrix of Cells // Matrix of Cells

View File

@@ -113,6 +113,8 @@ void Grid_initCell(Grid *grid, Cell *cell, int i, int j, SDL_Color color, SDL_Co
} }
void Grid_render(Grid *grid, SDL_Renderer *renderer) void Grid_render(Grid *grid, SDL_Renderer *renderer)
{
if(grid->border != 0) // Grid border thickness different from 0
{ {
// Set renderer color to draw the grid border // Set renderer color to draw the grid border
SDL_SetRenderDrawColor(renderer, SDL_SetRenderDrawColor(renderer,
@@ -123,6 +125,7 @@ void Grid_render(Grid *grid, SDL_Renderer *renderer)
// Render grid border // Render grid border
SDL_RenderFillRect(renderer, &(grid->rect)); SDL_RenderFillRect(renderer, &(grid->rect));
}
// Render all cells // Render all cells
for(int i = 0; i < grid->xCells; ++i) for(int i = 0; i < grid->xCells; ++i)
@@ -135,6 +138,8 @@ void Grid_render(Grid *grid, SDL_Renderer *renderer)
} }
void Grid_renderCell(Cell *cell, SDL_Renderer *renderer) void Grid_renderCell(Cell *cell, SDL_Renderer *renderer)
{
if(cell->border.x != cell->rect.x) // Cells border thickness different from 0
{ {
// Set renderer color to cell color // Set renderer color to cell color
SDL_SetRenderDrawColor(renderer, SDL_SetRenderDrawColor(renderer,
@@ -145,6 +150,7 @@ void Grid_renderCell(Cell *cell, SDL_Renderer *renderer)
// Render filled cell // Render filled cell
SDL_RenderFillRect(renderer, &(cell->border)); SDL_RenderFillRect(renderer, &(cell->border));
}
// Set renderer color to cell color // Set renderer color to cell color
SDL_SetRenderDrawColor(renderer, SDL_SetRenderDrawColor(renderer,