RogueLife/src/render.h

61 lines
1.6 KiB
C
Raw Normal View History

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