Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Palette overhaul; replaces the old hardcoded numeric id based palette … #308

Merged
merged 2 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,651 changes: 3,651 additions & 0 deletions palette.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/altitude_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ void AltitudeGraph::createGraph()
for(int i = 0; i < mc::MapY; i++)
{
x = BORDER_X + x_step*i;
y = _h - (int)( ( (float)altitudeRegistry[i] / (float)maxVal ) * (_h-BORDER_Y) );
if (maxVal == 0) {
y = _h;
} else {
y = _h - (int)( ( (float)altitudeRegistry[i] / (float)maxVal ) * (_h-BORDER_Y) );
}
graphImg->draw_line(x, y, x0, y0, fgcolor);
x0 = x;
y0 = y;
Expand Down Expand Up @@ -90,8 +94,7 @@ void AltitudeGraph::createGraph()
graphImg->save<png_format>(s.statistics_path.string() + "_graph.png", opts);
}


void AltitudeGraph::registerBloc(Byte value, int altitude)
void AltitudeGraph::registerBloc(mc::MaterialT *material, int altitude)
{
altitudeRegistry[altitude] += 1;
}
Expand All @@ -101,7 +104,7 @@ long AltitudeGraph::getMax()
long max = 0;
for(int i = 0; i < mc::MapY; i++)
{
if(max<altitudeRegistry[i])
if(max < altitudeRegistry[i])
max = altitudeRegistry[i];
}
return max;
Expand Down
2 changes: 1 addition & 1 deletion src/altitude_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AltitudeGraph
void createGraph();

/* call this to register block information */
void registerBloc(Byte value, int altitude);
void registerBloc(mc::MaterialT *material, int altitude);

long getMax();
private:
Expand Down
1 change: 0 additions & 1 deletion src/engine/engine_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct engine_settings {
bool cavemode;
int top;
int bottom;
boost::shared_array<bool> excludes;
};

#endif /* _ENGINE_ENGINE_SETTINGS_HPP */
2 changes: 1 addition & 1 deletion src/engine/fatiso_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void fatiso_engine::render_block(
color toplight(top);
color sidelight(side);

if (bt == mc::Grass) {
if (bt == mc::LegacyBlocks::Grass) {
topdark.darken(0x20);
toplight.darken(0x10);
sidelight.lighten(0x20);
Expand Down
104 changes: 84 additions & 20 deletions src/engine/flat_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class flat_base : public engine_base<C> {
}

// block type

BOOST_REVERSE_FOREACH(mc::Section_Compound Section, L->Sections) {
block_rotation br_blocks(s.rotation, Section.Blocks);
block_rotation br_data(s.rotation, Section.Data);
block_rotation br_block_light(s.rotation, Section.BlockLight);
block_rotation br_sky_light(s.rotation, Section.SkyLight);
//block_rotation br_block_light(s.rotation, Section.BlockLight);
//block_rotation br_sky_light(s.rotation, Section.SkyLight);

for (int y = 15; y >= 0; y--) {
int abs_y = (Section.Y * 16) + y;
Expand All @@ -57,19 +57,31 @@ class flat_base : public engine_base<C> {

br_blocks.set_xz(x, z);
br_data.set_xz(x, z);
br_block_light.set_xz(x, z);
br_sky_light.set_xz(x, z);
//br_block_light.set_xz(x, z);
//br_sky_light.set_xz(x, z);

// do incremental color fill until color is opaque
int block_type = br_blocks.get8(y);
int block_data = br_data.get4(y);

if (block_type >=0 && s.excludes[block_type]) {
continue;
}
mc::MaterialMode mode;
color top;
color side;

color top = mc::get_color(block_type, block_data);
color side = mc::get_side_color(block_type, block_data);
boost::optional<mc::MaterialT*> material = mc::get_material_legacy(block_type, block_data);
if (material) {
mc::MaterialT *m = material.get();
if (!m->enabled) {
continue;
}
mode = m->mode;
top = m->top;
side = m->side;
} else {
mode = mc::MaterialMode::Block;
top = mc::SharedDefaultColor;
side = mc::SharedDefaultColor;
}

blocked[blocked_position] = top.is_opaque();

Expand All @@ -85,33 +97,85 @@ class flat_base : public engine_base<C> {

flat_base<C>::project_position(p, px, py);

switch(mc::MaterialModes[block_type]) {
case mc::Block:
int log_rotation;

switch(mode) {
case mc::MaterialMode::Block:
render_block(oper, block_type, px, py, top, side);
case mc::HalfBlock:
render_halfblock(oper, block_type, px, py, top, side);
break;
case mc::TorchBlock:
case mc::MaterialMode::HalfBlock:
render_halfblock(oper, block_type, px, py, top, side);
break;
case mc::MaterialMode::TorchBlock:
render_torchblock(oper, block_type, px, py, top, side);
break;
case mc::LargeFlowerBlock:
case mc::MaterialMode::LargeFlowerBlock:
// Check if the requested block is the top block
if(block_data & 0x08) {
// Small sanity check
if(y > 0 && br_blocks.get8(y-1) == block_type) {
// Minecraft currently doesn't set the lower bits to the
// corresponding type so we have to do this here.
block_data = br_data.get4(y-1) | 0x08;
top = mc::get_color(block_type, block_data);
side = mc::get_side_color(block_type, block_data);
}
else {
block_data = br_data.get4(y-1) & 0x07;
top = mc::get_color_legacy(block_type, block_data);
side = mc::get_side_color_legacy(block_type, block_data);
} else {
// Top block not placed on a correct bottom block.
// The expected LargeFlower multi block structure is invalid, skip it.
continue;
}
} else {
// Force the top of the lower block to also be the side color.
top = side;
}
render_block(oper, block_type, px, py, top, side);
render_halfblock(oper, block_type, px, py, top, side);
break;
case mc::MaterialMode::LogBlock:
// Log blocks are just a regular block that may differ in orientation. Top
// color is considered the inner material. Because some bits of metadata are
// used both for variant and rotation state, block type needs to be fetched again.
log_rotation = (block_data & 0x0C) >> 2;
switch(log_rotation) {
case 0:
// Up/down
top = mc::get_color_legacy(block_type, block_data & 0x3);
side = mc::get_side_color_legacy(block_type, block_data & 0x3);
break;
case 1:
// East/west
case 2:
// North/south
// TODO: Actually implement render rotation, for now simply swap top and side.
side = mc::get_color_legacy(block_type, block_data & 0x3);
top = mc::get_side_color_legacy(block_type, block_data & 0x3);
break;
case 3:
// Only sides, thus no top color.
side = mc::get_side_color_legacy(block_type, block_data & 0x3);
top = side;
break;
}
render_block(oper, block_type, px, py, top, side);
render_halfblock(oper, block_type, px, py, top, side);
break;
case mc::MaterialMode::LegacySlab:
// Legacy slab is just a half block; but is sometimes a full block.
// The first legacy id is the full block version.
if (block_type == material.get()->legacy_ids[0]) {
render_block(oper, block_type, px, py, top, side);
}
render_halfblock(oper, block_type, px, py, top, side);
break;
case mc::MaterialMode::LegacyLeaves:
// Legacy leaves is just a regular block; however some bits of the metadata
// are used for other block states, only the two first bits are used for block
// type therefore we need to re-fetch the block type now.
top = mc::get_color_legacy(block_type, block_data & 0x3);
side = mc::get_side_color_legacy(block_type, block_data & 0x3);
render_block(oper, block_type, px, py, top, side);
render_halfblock(oper, block_type, px, py, top, side);
break;
}
}
Expand Down
26 changes: 18 additions & 8 deletions src/engine/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,55 @@ void apply_shading(
const engine_settings& engine_s,
int bl, int sl, int hm, int y, color &c);

inline bool is_open(mc::MaterialT*& m) {
if (!m) {
return false;
}

return m->top.is_transparent();
}

inline bool is_open(int bt) {
if (bt == -1) {
return false;
}

switch(bt) {
case mc::Air: return true;
case mc::Leaves: return true;
case mc::LegacyBlocks::Air: return true;
case mc::LegacyBlocks::Leaves: return true;
default: return false;
}
}

// this functions is currently unused
inline bool cave_ignore_block(int y, int bt, block_rotation& b_r, bool &cave_initial) {
if (cave_initial) {
if (!is_open(bt)) {
cave_initial = false;
return true;
}

return true;
}

if (!is_open(bt) && is_open(b_r.get8(y + 1))) {
return false;
}

return true;
}

// this functions is currently unused
inline bool hell_ignore_block(int y, int bt, block_rotation& b_r, bool &hell_initial) {
if (hell_initial) {
if (is_open(bt)) {
hell_initial = false;
return false;
}

return true;
}

return false;
}

Expand Down
Loading