Skip to content

Commit

Permalink
Fixed night time rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 11, 2010
1 parent 9052bc4 commit 776a651
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 91 deletions.
18 changes: 6 additions & 12 deletions src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@ void color::blend(const color &other) {

// pull color down towards black
void color::darken(uint8_t f) {
if (r - f < 0x0) r = 0x0;
else r -= f;
if (g - f < 0x0) g = 0x0;
else g -= f;
if (b - f < 0x0) b = 0x0;
else b -= f;
r = std::max((int)r - ((int)r * (int)f) / 0xff, 0x0);
g = std::max((int)g - ((int)g * (int)f) / 0xff, 0x0);
b = std::max((int)b - ((int)b * (int)f) / 0xff, 0x0);
}

void color::lighten(uint8_t f) {
if (r + f > 0xff) r = 0xff;
else r += f;
if (g + f > 0xff) g = 0xff;
else g += f;
if (b + f > 0xff) b = 0xff;
else b += f;
r = std::min((int)r + ((int)r * (int)f) / 0xff, 0xff);
g = std::min((int)g + ((int)g * (int)f) / 0xff, 0xff);
b = std::min((int)b + ((int)b * (int)f) / 0xff, 0xff);
}
17 changes: 9 additions & 8 deletions src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,14 @@ class BlockRotation {
*/
inline void apply_shading(settings_t& s, int bl, int sl, int hm, int y, color &c) {
// if night, darken all colors not emitting light
if (s.night) {
c.darken(0x40);
}

if (sl != -1 && y != s.top) {
c.darken(0x8 * (16 - sl));
if(s.night) {
c.darken(0xa * (16 - bl));
}
else if (sl != -1 && y != s.top) {
c.darken(0xa * (16 - std::max(sl, bl)));
}

//c.darken((mc::MapY - y));

// in heightmap mode, brightness = height
Expand Down Expand Up @@ -544,10 +545,10 @@ image_operations* level_file::get_obliqueangle_image(settings_t& s)
blocked[bp] = top.is_opaque();
oper->add_pixel(px, py, top);
oper->add_pixel(px + 1, py, top);
oper->add_pixel(px + 1, py + 1, side);

side.darken(0x20);
oper->add_pixel(px, py + 1, side);

side.lighten(0x20);
oper->add_pixel(px + 1, py + 1, side);
break;
case mc::HalfBlock:
oper->add_pixel(px, py, top);
Expand Down
129 changes: 58 additions & 71 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,45 +205,50 @@ inline void calc_image_partial(settings_t& s, render_result &p, image_base *all,
int diffz = world.max_z - world.min_z;

Cube c(diffx, 16, diffz);
int xoffset, yoffset;
int x, y;

point pos(p.xPos - world.min_x, 16, p.zPos - world.min_z);

switch (s.mode) {
case Top:
{
point topleft(p.xPos - world.min_x, 16, p.zPos - world.min_z);
c.project_top(topleft, xoffset, yoffset);
xoffset *= mc::MapX;
yoffset *= mc::MapZ;
all->composite(xoffset, yoffset, *p.operations);
}
break;
case Oblique:
{
point topleft(p.xPos - world.min_x, 16, p.zPos - world.min_z);
c.project_oblique(topleft, xoffset, yoffset);
xoffset *= mc::MapX;
yoffset *= mc::MapZ;
all->composite(xoffset, yoffset, *p.operations);
}
break;
case ObliqueAngle:
{
point topleft(p.xPos - world.min_x, 16, p.zPos - world.min_z);
c.project_obliqueangle(topleft, xoffset, yoffset);
xoffset *= mc::MapX;
yoffset *= mc::MapZ;
all->composite(xoffset, yoffset, *p.operations);
}
break;
case Isometric:
{
point topleft(p.xPos - world.min_x, 16, p.zPos - world.min_z);
c.project_isometric(topleft, xoffset, yoffset);
xoffset *= mc::MapX;
yoffset *= mc::MapZ;
all->composite(xoffset, yoffset, *p.operations);
case Top: c.project_top(pos, x, y); break;
case Oblique: c.project_oblique(pos, x, y); break;
case ObliqueAngle: c.project_obliqueangle(pos, x, y); break;
case Isometric: c.project_isometric(pos, x, y); break;
}

x *= mc::MapX;
y *= mc::MapZ;

all->composite(x, y, *p.operations);
}

inline void write_markers(settings_t& s, image_base *all, world_info &world, boost::ptr_vector<marker>& markers) {
int diffx = (world.max_x - world.min_x) * mc::MapX;
int diffz = (world.max_z - world.min_z) * mc::MapZ;
int min_z = world.min_z * mc::MapZ;
int min_x = world.min_x * mc::MapX;

Cube c(diffx + mc::MapX, mc::MapY, diffz + mc::MapZ);

boost::ptr_vector<marker>::iterator it;

for (it = markers.begin(); it != markers.end(); it++) {
marker m = *it;

int p_x = m.x, p_y = m.y, p_z = m.z;

transform_world_xz(p_x, p_z, s.rotation);

point pos(p_x - min_x, p_y, p_z - min_z);

int x, y;

switch (s.mode) {
case Top: c.project_top(pos, x, y); break;
case Oblique: c.project_oblique(pos, x, y); break;
case ObliqueAngle: c.project_obliqueangle(pos, x, y); break;
case Isometric: c.project_isometric(pos, x, y); break;
}
break;
}
}

Expand All @@ -254,8 +259,7 @@ inline void overlay_markers(settings_t& s, image_base *all, world_info &world, b
int min_x = world.min_x * mc::MapX;

Cube c(diffx + mc::MapX, mc::MapY, diffz + mc::MapZ);
int xoffset, yoffset;


memory_image positionmark(5, 5);
positionmark.fill(s.ttf_color);

Expand All @@ -267,41 +271,19 @@ inline void overlay_markers(settings_t& s, image_base *all, world_info &world, b
int p_x = m.x, p_y = m.y, p_z = m.z;

transform_world_xz(p_x, p_z, s.rotation);
point pos(p_x - min_x, p_y, p_z - min_z);

int x, y;

switch (s.mode) {
case Top:
{
point playerpos(p_x - min_x, p_y, p_z - min_z);
c.project_top(playerpos, xoffset, yoffset);
m.font.draw(*all, m.text, xoffset + 5, yoffset);
all->safe_composite(xoffset - 3, yoffset - 3, positionmark);
}
break;
case Oblique:
{
point playerpos(p_x - min_x, p_y, p_z - min_z);
c.project_oblique(playerpos, xoffset, yoffset);
m.font.draw(*all, m.text, xoffset + 5, yoffset);
all->safe_composite(xoffset - 3, yoffset - 3, positionmark);
}
break;
case ObliqueAngle:
{
point playerpos(p_x - min_x, p_y, p_z - min_z);
c.project_obliqueangle(playerpos, xoffset, yoffset);
m.font.draw(*all, m.text, xoffset + 5, yoffset);
all->safe_composite(xoffset - 3, yoffset - 3, positionmark);
}
break;
case Isometric:
{
point playerpos(p_x - min_x, p_y, p_z - min_z);
c.project_isometric(playerpos, xoffset, yoffset);
m.font.draw(*all, m.text, xoffset + 5, yoffset);
all->safe_composite(xoffset - 3, yoffset - 3, positionmark);
}
break;
case Top: c.project_top(pos, x, y); break;
case Oblique: c.project_oblique(pos, x, y); break;
case ObliqueAngle: c.project_obliqueangle(pos, x, y); break;
case Isometric: c.project_isometric(pos, x, y); break;
}

m.font.draw(*all, m.text, x + 5, y);
all->safe_composite(x - 3, y - 3, positionmark);
}
}

Expand Down Expand Up @@ -537,7 +519,12 @@ bool do_one_world(settings_t &s, world_info& world, players_db& pdb, const strin
}
}

overlay_markers(s, all, world, markers);
if (false) {
write_markers(s, all, world, markers);
}
else {
overlay_markers(s, all, world, markers);
}

if (!s.silent) cout << "Saving image..." << endl;

Expand Down

0 comments on commit 776a651

Please sign in to comment.