RogueLife/src/render.h

70 lines
1.8 KiB
C
Raw Normal View History

//---
// render: Rendering utilities
//---
#pragma once
#include "settings.h"
#include "map.h"
#include "pathfinding.h"
#include <stdint.h>
//---
// Camera management
//---
2021-06-04 15:14:12 +02:00
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;
2021-06-04 15:14:12 +02:00
} camera_t;
/* Initialize camera to look at the middle of the map, and set boundaries. */
2021-06-04 15:14:12 +02:00
void camera_init(camera_t *c, map_t const *m);
/* Translate map coordinates to pixel coordinates on screen. */
2021-06-04 15:14:12 +02:00
ipoint_t camera_map2screen(camera_t const *c, fpoint_t map_point);
/* Translate screen coordinates to map coordinates. */
2021-06-04 15:14:12 +02:00
fpoint_t camera_screen2map(camera_t const *c, ipoint_t screen_point);
/* Move camera by a distance in map coordinates. */
2021-06-04 15:14:12 +02:00
void camera_move(camera_t *c, map_coord_t dx, map_coord_t dy);
/* Set the zoom level of the camera. */
2021-06-04 15:14:12 +02:00
void camera_zoom(camera_t *c, int zoom);
/* Number of pixels per unit of map. Assumes isotropic space. */
2021-06-04 15:14:12 +02:00
fixed_t camera_ppu(camera_t const *c);
//---
// Rendering
//---
/* Render map for the specified camera.
TODO: render_map: Honor zoom
TODO: render_map: Clip around viewport */
2021-06-04 15:14:12 +02:00
void render_map(map_t const *m, camera_t const *c);
/* 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);