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

@@ -114,15 +114,18 @@ 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)
{ {
// Set renderer color to draw the grid border if(grid->border != 0) // Grid border thickness different from 0
SDL_SetRenderDrawColor(renderer, {
grid->borderColor.r, // Set renderer color to draw the grid border
grid->borderColor.g, SDL_SetRenderDrawColor(renderer,
grid->borderColor.b, grid->borderColor.r,
grid->borderColor.a); grid->borderColor.g,
grid->borderColor.b,
grid->borderColor.a);
// 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)
@@ -136,15 +139,18 @@ void Grid_render(Grid *grid, SDL_Renderer *renderer)
void Grid_renderCell(Cell *cell, SDL_Renderer *renderer) void Grid_renderCell(Cell *cell, SDL_Renderer *renderer)
{ {
// Set renderer color to cell color if(cell->border.x != cell->rect.x) // Cells border thickness different from 0
SDL_SetRenderDrawColor(renderer, {
cell->borderColor.r, // Set renderer color to cell color
cell->borderColor.g, SDL_SetRenderDrawColor(renderer,
cell->borderColor.b, cell->borderColor.r,
cell->borderColor.a); cell->borderColor.g,
cell->borderColor.b,
cell->borderColor.a);
// 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,