Files
tetris_clone/src/window/renderer.h
Quinn 60ae11de10 synchronise with the template
- use the version of audio management which doesn't crash the
application if something goes wrong
- include colour32
- update error management to be more reflective of the one defined in
the template
- modify the renderer functions to be more reflective of the template
- modify the game functions to be more reflective of the template (& use
a more failproof method of initializing)
- add gametime
- remove set_gamestatus logic and just use a run boolean in gamedata
- remove emscripten preprocessors as those haven't really been used
2025-03-22 15:29:42 +01:00

37 lines
1.5 KiB
C

#pragma once
#include <SDL_render.h>
#include <SDL_ttf.h>
#include <SDL_video.h>
#include "../game/game.h"
#define PX_DENS 25 // pixel density; pixels per block
#define TET_PADDING 10 // padding around the tetris playing field
#define TET_WIDTH (COLUMNS * PX_DENS - TET_PADDING) // tetris playing field width
#define TET_HEIGHT (TET_WIDTH / COLUMNS * ROWS) // tetris playing field height
#define SCREEN_WIDTH ((COLUMNS + 6) * PX_DENS) // window width
#define SCREEN_HEIGHT ((COLUMNS) * PX_DENS / COLUMNS * ROWS) // window height
#define BLOCK_WIDTH (TET_WIDTH / COLUMNS) // width of a block
#define BLOCK_HEIGHT (TET_HEIGHT / ROWS) // height of a block
// contains the data that's cached between renders
struct render_cache {
SDL_Texture* score_texture;
SDL_Surface* score_surface;
uint16_t prevscore;
};
// contains the data necessary for rendering
typedef struct {
gamedata const* game_dat;
SDL_Window* window;
SDL_Renderer* renderer;
TTF_Font* font;
struct render_cache* cache;
} renderdata;
void render_init(renderdata*, gamedata const*); // initializes the renderer, outputs to render_data
void render_update(renderdata const*); // causes a draw to occur, will also determine update rate
void render_free(renderdata*); // frees the memory allocated to the renderer in render_data