Performance Increase

This commit is contained in:
2026-02-05 01:04:52 -06:00
parent 269e06dae5
commit 536087b7c7

40
main.c
View File

@@ -9,21 +9,6 @@
int startw=1900;
int starth=1100;
void putPixelRGB(SDL_Renderer* renderer, int x, int y, unsigned char r,unsigned char g,unsigned char b){
SDL_SetRenderDrawColor(renderer,(Uint8)r,(Uint8)g,(Uint8)b,255);
SDL_RenderDrawPoint(renderer,x,y);
}
void putRectRGB(SDL_Renderer* renderer, int x, int y, int size, unsigned char r,unsigned char g,unsigned char b){
SDL_Rect tmp_rect;
tmp_rect.w = tmp_rect.h = size;
tmp_rect.x=x;
tmp_rect.y=y;
SDL_SetRenderDrawColor(renderer,(Uint8)r,(Uint8)g,(Uint8)b,255);
SDL_RenderFillRect(renderer,&tmp_rect);
}
void iterate_game(int **grid, int** nextgrid, int cols, int rows){
for (int i=0; i<cols; i++){
for(int j=0;j<rows; j++){
@@ -56,20 +41,18 @@ void iterate_game(int **grid, int** nextgrid, int cols, int rows){
}
}
void draw(SDL_Renderer* renderer,SDL_Window* window,int cols, int rows, float mX, float mY, int boxsize, int **grid, int **nextgrid, int width, int height){
for (int i=0; i<width; i++){
for(int j=0;j<height; j++){
putPixelRGB(renderer,i,j,0,0,0);
}
}
void draw(SDL_Renderer* renderer,SDL_Window* window,int cols, int rows, float mX, float mY, int boxsize, int **grid, int **nextgrid, int width, int height, SDL_Rect *box_rect){
SDL_SetRenderDrawColor(renderer,0,0,0,255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer,150,50,255,255);
for (int i=0; i<cols; i++){
for(int j=0;j<rows; j++){
if(grid[i][j]==1){
putRectRGB(renderer,i*boxsize,j*boxsize,boxsize-1,150,50,255);
box_rect->x=i*boxsize;
box_rect->y=j*boxsize;
SDL_RenderFillRect(renderer,box_rect);
}
}
}
@@ -105,7 +88,7 @@ int main(int argc, char *argv[])
SDL_GetWindowSize(window, &w, &h);
printf("Window dimensions: %dx%d\n", w, h);
int boxsize=15;
int boxsize=8;
int cols=w/boxsize;
int rows=h/boxsize;
SDL_Log("cols %d rows %d\n\n\n\n",cols,rows);
@@ -127,8 +110,11 @@ int main(int argc, char *argv[])
}
}
SDL_Rect box_rect;
box_rect.w = box_rect.h = boxsize-1;
draw(renderer,window,cols,rows,0,0,boxsize,grid,nextgrid,w,h);
draw(renderer,window,cols,rows,0,0,boxsize,grid,nextgrid,w,h,&box_rect);
bool quit = false;
SDL_Event e;
@@ -171,7 +157,7 @@ int main(int argc, char *argv[])
}
float mouseoutX=gmouseX;
float mouseoutY=gmouseY;
draw(renderer,window,cols,rows,mouseoutX,mouseoutY,boxsize,grid,nextgrid,w,h);
draw(renderer,window,cols,rows,mouseoutX,mouseoutY,boxsize,grid,nextgrid,w,h,&box_rect);
//SDL_Delay(10);
}