Skip to content

Commit

Permalink
Fixes #2: Decals are not rendered properly
Browse files Browse the repository at this point in the history
- I was wrongly assuming that decals could not have a number of frames
- RE2DRender is ok with decals that are out of bounds, so RE Edit must be as well
  • Loading branch information
ypujante committed Jan 6, 2023
1 parent b69d390 commit b0289ad
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 35 deletions.
21 changes: 12 additions & 9 deletions src/cpp/re/edit/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,19 @@ void Graphics::reset()
//------------------------------------------------------------------------
void Graphics::findErrors(AppContext &iCtx, UserError &oErrors) const
{
auto max = iCtx.getCurrentPanelSize();
auto p = getTopLeft();
if(p.x < 0 || p.y < 0 || p.x > max.x || p.y > max.y)
if(fCheckForOOBError)
{
oErrors.add("Out of bound");
}
p = getBottomRight();
if(p.x < 0 || p.y < 0 || p.x > max.x || p.y > max.y)
{
oErrors.add("Out of bound");
auto max = iCtx.getCurrentPanelSize();
auto p = getTopLeft();
if(p.x < 0 || p.y < 0 || p.x > max.x || p.y > max.y)
{
oErrors.add("Out of bound");
}
p = getBottomRight();
if(p.x < 0 || p.y < 0 || p.x > max.x || p.y > max.y)
{
oErrors.add("Out of bound");
}
}

if(hasTexture())
Expand Down
1 change: 1 addition & 0 deletions src/cpp/re/edit/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Graphics : public Attribute
bool fHitBoundariesEnabled{true};
std::variant<ImVec2, Texture::key_t> fTexture{kNoGraphics};
bool fSizeEnabled{true};
bool fCheckForOOBError{true};
std::shared_ptr<Texture> fDNZTexture{};
FilmStrip::Filter fFilter{};
int fFrameNumber{};
Expand Down
4 changes: 1 addition & 3 deletions src/cpp/re/edit/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,9 @@ std::unique_ptr<Widget> Widget::zero_snap_knob()
//------------------------------------------------------------------------
std::unique_ptr<Widget> Widget::panel_decal()
{
static const FilmStrip::Filter kGraphicsFilter{[](FilmStrip const &f) { return f.numFrames() == 1; }, "Must have exactly 1 frame"};

auto w = std::make_unique<Widget>(WidgetType::kPanelDecal);
w->fGraphics->fFilter = kGraphicsFilter;
w->fGraphics->fSizeEnabled = false;
w->fGraphics->fCheckForOOBError = false;
return w;
}

Expand Down
61 changes: 40 additions & 21 deletions src/cpp/re/edit/lua/Device2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,37 @@ void Device2D::processLuaTable(ImVec2 iOffset, std::vector<std::optional<std::st
if(maybeOffset)
iOffset += *maybeOffset;

iterateLuaTable([this, &iOffset, &iDecalNames, &oPanelNodes](lua_table_key_t const &key) {
if(std::holds_alternative<std::string>(key))
auto maybeDecal = getMaybePathOnTopOfStack();
if(maybeDecal)
{
if(maybeDecal->fPath)
{
auto name = std::get<std::string>(key);
if(name == "offset")
{
// do nothing (already handled)
}
else if(name == "path")
auto idx = oPanelNodes.fDecalNodes.size();
auto decalName = idx < iDecalNames.size() ? iDecalNames[idx] : std::nullopt;
oPanelNodes.fDecalNodes.emplace_back(gfx_decal_node{iOffset, *maybeDecal->fPath, decalName, maybeDecal->fNumFrames});
}
}
else
{
iterateLuaTable([this, &iOffset, &iDecalNames, &oPanelNodes](lua_table_key_t const &key) {
if(std::holds_alternative<std::string>(key))
{
if(lua_type(L, -1) == LUA_TSTRING)
auto name = std::get<std::string>(key);
if(name == "offset")
{
// do nothing (already handled)
}
else
{
auto idx = oPanelNodes.fDecalNodes.size();
auto decalName = idx < iDecalNames.size() ? iDecalNames[idx] : std::nullopt;
oPanelNodes.fDecalNodes.emplace_back(gfx_decal_node{iOffset, lua_tostring(L, -1), decalName});
processGfxNode(name, iOffset, oPanelNodes);
}
}
else
{
processGfxNode(name, iOffset, oPanelNodes);
processLuaTable(iOffset, iDecalNames, oPanelNodes);
}
}
else
{
processLuaTable(iOffset, iDecalNames, oPanelNodes);
}
}, true, false);
}, true, false);
}
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -193,7 +197,6 @@ void Device2D::processDecalNode(ImVec2 iOffset, panel_nodes &oPanelNodes)
//------------------------------------------------------------------------
void Device2D::processDecalNode(std::string const &iName, ImVec2 iOffset, panel_nodes &oPanelNodes)
{
RE_EDIT_LOG_DEBUG("detected named decal node %s", iName);
auto maybeOffset = getOptionalOffset();
if(maybeOffset)
iOffset += *maybeOffset;
Expand All @@ -205,7 +208,7 @@ void Device2D::processDecalNode(std::string const &iName, ImVec2 iOffset, panel_
if(p)
{
if(p->fPath)
oPanelNodes.fDecalNodes.emplace_back(gfx_decal_node{iOffset, *p->fPath, iName});
oPanelNodes.fDecalNodes.emplace_back(gfx_decal_node{iOffset, *p->fPath, iName, p->fNumFrames});
}
else
processDecalNode(iName, iOffset, oPanelNodes);
Expand Down Expand Up @@ -298,6 +301,22 @@ std::map<std::string, int> panel_nodes::getNumFrames() const
}
}
}

// handle decals
for(auto &node: fDecalNodes)
{
auto key = node.fKey;
if(!key.empty() && node.fNumFrames)
{
auto numFrame2 = numFrames.find(key);
if(numFrame2 != numFrames.end())
{
if(*node.fNumFrames != numFrame2->second)
RE_EDIT_LOG_WARNING("Inconsistent number of frames for %s : %d and %d", key, numFrame2->second, *node.fNumFrames);
}
numFrames[key] = *node.fNumFrames;
}
}
return numFrames;
}

Expand Down
1 change: 1 addition & 0 deletions src/cpp/re/edit/lua/Device2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct gfx_decal_node
ImVec2 fPosition{};
std::string fKey{};
std::optional<std::string> fName{};
std::optional<int> fNumFrames{};
};

struct panel_nodes
Expand Down
1 change: 1 addition & 0 deletions test/cpp/re/edit/lua/TestDevice2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ TEST(Device2D, All)
ASSERT_TRUE(Eq(label_for_Knob4Offset, n.fPosition));
ASSERT_EQ("label_for_Knob4_path", n.fKey);
ASSERT_EQ("label_for_Knob4", *n.fName);
ASSERT_EQ(2, *n.fNumFrames);
}

auto foldedBack = d2d->folded_back();
Expand Down
4 changes: 2 additions & 2 deletions test/resources/re/edit/lua/all-device_2D.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ front = {
{
Knob2 = { offset = { 30, 40 }, { path = "Knob2_path", frames = 32 } }
},
{ offset = { 100, 110 }, path = "Decal2_path" },
{ offset = { 100, 110 }, { path = "Decal2_path" } },
{
offset = { 50, 60 },
Knob3 = { { size = { 5, 15 } } }
Expand All @@ -38,7 +38,7 @@ front = {
{
offset = {-110, 105},
label_for_Knob4 = {
{path="label_for_Knob4_path"},
{path="label_for_Knob4_path", frames = 2},
},
},
}
Expand Down

0 comments on commit b0289ad

Please sign in to comment.