moved textures into their own classes, better tilemapping
This commit is contained in:
+13
-13
@@ -5,16 +5,16 @@
|
||||
#include "../datatypes.cpp"
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shaders/shaders.h"
|
||||
#include "../mappers/mappers.h"
|
||||
#include "../textures/textures.h"
|
||||
|
||||
namespace UwU {
|
||||
// line
|
||||
class Line {
|
||||
private:
|
||||
// plot lines if m <= 1
|
||||
template <class MapperT, class ShaderT>
|
||||
void lineLow(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
||||
template <class MapperT, class TextureT>
|
||||
void lineLow(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, MapperBase<MapperT>& mapper, TextureBase<TextureT>& texture) {
|
||||
int16_t dx = ix1 - ix0;
|
||||
int16_t dy = iy1 - iy0;
|
||||
int16_t yi = 1;
|
||||
@@ -29,7 +29,7 @@ namespace UwU {
|
||||
|
||||
for (int16_t x = ix0; x < ix1; x++) {
|
||||
uv = mapper.map(ix0, iy0, x, y);
|
||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, texture.texel(uv.x, uv.y));
|
||||
if (d > 0) {
|
||||
y += yi;
|
||||
d += (2 * (dy - dx));
|
||||
@@ -41,8 +41,8 @@ namespace UwU {
|
||||
}
|
||||
|
||||
// plot lines if m >1
|
||||
template <class MapperT, class ShaderT>
|
||||
void lineHigh(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
||||
template <class MapperT, class TextureT>
|
||||
void lineHigh(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, MapperBase<MapperT>& mapper, TextureBase<TextureT>& texture) {
|
||||
int16_t dx = ix1 - ix0;
|
||||
int16_t dy = iy1 - iy0;
|
||||
int16_t xi = 1;
|
||||
@@ -57,7 +57,7 @@ namespace UwU {
|
||||
|
||||
for (int16_t y = iy0; y < iy1; y++) {
|
||||
uv = mapper.map(ix0, iy0, x, y);
|
||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, texture.texel(uv.x, uv.y));
|
||||
if (d > 0) {
|
||||
x += xi;
|
||||
d += (2 * (dx - dy));
|
||||
@@ -82,8 +82,8 @@ namespace UwU {
|
||||
uint16_t y1;
|
||||
|
||||
// Uses Bresenham's line algorithm to draw line of any slope
|
||||
template <class MapperT, class ShaderT>
|
||||
void draw (Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
||||
template <class MapperT, class TextureT>
|
||||
void draw (Buffer buffer, MapperBase<MapperT>& mapper, TextureBase<TextureT>& texture) {
|
||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||
int16_t ix0 = x0;
|
||||
int16_t iy0 = y0;
|
||||
@@ -91,15 +91,15 @@ namespace UwU {
|
||||
int16_t iy1 = y1;
|
||||
if (abs(iy1 - iy0) < abs(ix1 - ix0)) {
|
||||
if (ix0 > ix1) {
|
||||
lineLow(ix1, iy1, ix0, iy0, buffer, mapper, shader);
|
||||
lineLow(ix1, iy1, ix0, iy0, buffer, mapper, texture);
|
||||
} else {
|
||||
lineLow(ix0, iy0, ix1, iy1, buffer, mapper, shader);
|
||||
lineLow(ix0, iy0, ix1, iy1, buffer, mapper, texture);
|
||||
}
|
||||
} else {
|
||||
if (iy0 > iy1) {
|
||||
lineHigh(ix1, iy1, ix0, iy0, buffer, mapper, shader);
|
||||
lineHigh(ix1, iy1, ix0, iy0, buffer, mapper, texture);
|
||||
} else {
|
||||
lineHigh(ix0, iy0, ix1, iy1, buffer, mapper, shader);
|
||||
lineHigh(ix0, iy0, ix1, iy1, buffer, mapper, texture);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user