Skip to content

Commit

Permalink
[#69] fix(light_preset): refine implementation
Browse files Browse the repository at this point in the history
This patch aims to improve compatibility with the original implementation. It changes the `colorAniList` parser of `light_preset` to correctly handle greyscale color. In addition, it changes the alpha-value reported as part of the light color to `0xff` like the original implementation does.

Reference the `zCVobLightData::Unarchive` member function at `0x00609fa0` in the original binary.
  • Loading branch information
lmichaelis committed Jul 2, 2023
1 parent 68714df commit 356647d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
35 changes: 31 additions & 4 deletions source/vobs/light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,37 @@ namespace phoenix::vobs {
std::istringstream colors {color_animation_list};
colors.setf(std::ios::skipws);

// # Original Format in ABNF:
//
// color-ani-list = *(color-ani-list-element SP)
// color-ani-list-element = greyscale-color-element | rgb-color-element
//
// greyscale-color-element = color-scalar
// rgb-color-element = "(" color-scalar SP color-scalar SP color-scalar ")"
//
// color-scalar = 1*3DIGIT

char c;
uint32_t r, g, b;
char br = ' ';
while (colors >> br >> r >> g >> b >> br) {
obj.color_animation_list.emplace_back(r, g, b, 0);
while (colors >> c) {
if (::isdigit(c)) {
colors.unget();
colors >> r;
obj.color_animation_list.emplace_back(r, r, r, 255);
continue;
}

if (c != '(') {
PX_LOGW("light_preset: failed parsing `colorAniList`: invalid char '", c, "'");
}

colors >> r >> g >> b >> c;

if (c != ')') {
PX_LOGW("light_preset: failed parsing `colorAniList`: expected ')', got '", c, "'");
}

obj.color_animation_list.emplace_back(r, g, b, 255);
}

if (version == game_version::gothic_2) {
Expand All @@ -55,4 +82,4 @@ namespace phoenix::vobs {
vob::parse(obj, ctx, version);
light_preset::parse(obj, ctx, version);
}
} // namespace phoenix::vobs
} // namespace phoenix::vobs
22 changes: 11 additions & 11 deletions tests/test_vobs_g1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,17 @@ TEST_SUITE("vobs") {

static const std::vector<float> G1_LIGHT_RANGE_ANIMATION_SCALE {};
static const std::vector<glm::u8vec4> G1_LIGHT_COLOR_ANIMATION_LIST {
glm::u8vec4 {211, 147, 107, 0}, glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {211, 147, 107, 0},
glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {223, 173, 117, 0},
glm::u8vec4 {227, 209, 106, 0}, glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {211, 147, 107, 0},
glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {227, 209, 106, 0},
glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {211, 147, 107, 0}, glm::u8vec4 {225, 197, 100, 0},
glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {211, 147, 107, 0},
glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {227, 209, 106, 0}, glm::u8vec4 {225, 197, 100, 0},
glm::u8vec4 {211, 147, 107, 0}, glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {223, 173, 117, 0},
glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {227, 209, 106, 0}, glm::u8vec4 {223, 173, 117, 0},
glm::u8vec4 {211, 147, 107, 0}, glm::u8vec4 {223, 173, 117, 0}, glm::u8vec4 {211, 147, 107, 0},
glm::u8vec4 {225, 197, 100, 0}, glm::u8vec4 {227, 209, 106, 0}, glm::u8vec4 {223, 173, 117, 0},
glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255},
glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {223, 173, 117, 255},
glm::u8vec4 {227, 209, 106, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255},
glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {227, 209, 106, 255},
glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {225, 197, 100, 255},
glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {211, 147, 107, 255},
glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {227, 209, 106, 255}, glm::u8vec4 {225, 197, 100, 255},
glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {223, 173, 117, 255},
glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {227, 209, 106, 255}, glm::u8vec4 {223, 173, 117, 255},
glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255},
glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {227, 209, 106, 255}, glm::u8vec4 {223, 173, 117, 255},
};

TEST_CASE("zCVobLight(parse:g1)") {
Expand Down

0 comments on commit 356647d

Please sign in to comment.