RogueLife/src/render.h

74 lines
2.1 KiB
C

//---
// render: Rendering utilities
//---
#pragma once
#include "settings.h"
#include "map.h"
#include "pathfinding.h"
#include <stdint.h>
//---
// Camera management
//---
typedef struct {
/* Current zoom level */
int zoom;
/* Boundaries of the viewable space, in map coordinates */
struct {
map_coord_t x_min, x_max;
map_coord_t y_min, y_max;
} limits;
/* Viewport on the screen (in pixels) */
struct {
int16_t x_min, x_max;
int16_t y_min, y_max;
} viewport;
/* Width and height of the viewable area, in map coordinates */
map_coord_t width, height;
/* Current center point (position of center of screen in the map) */
map_coord_t x, y;
} camera_t;
/* Initialize camera to look at the middle of the map, and set boundaries. */
void camera_init(camera_t *c, map_t const *m);
/* Translate map coordinates to pixel coordinates on screen. */
ivec2 camera_map2screen(camera_t const *c, vec2 map_point);
/* Translate screen coordinates to map coordinates. */
vec2 camera_screen2map(camera_t const *c, ivec2 screen_point);
/* Move camera by a distance in map coordinates. */
void camera_move(camera_t *c, map_coord_t dx, map_coord_t dy);
/* Set the zoom level of the camera. */
void camera_zoom(camera_t *c, int zoom);
/* Number of pixels per unit of map. Assumes isotropic space. */
fixed_t camera_ppu(camera_t const *c);
//---
// Rendering
//---
/* Render a single layer of the map, with animated tiles.
ss_x and ss_y are additional displacement for screenshake; default 0.
layer is HORIZONTAL (floor), VERTICAL (wall), or CEILING.
map_anim is the indivual tiles' animation time, can be NULL.
flags is the flags for dsubimage() for the tiles. */
void render_map_layer(map_t const *map, camera_t const *c, int ss_x, int ss_y,
int layer, uint16_t *map_anim, int flags);
/* Render game full-screen. */
struct game;
void render_game(struct game const *g, bool show_hitboxes);
/* Render pathfinding results on the grid. */
void render_pfg_all2one(pfg_all2one_t const *paths, camera_t const *c,
uint8_t *occupation);