libprimis icon indicating copy to clipboard operation
libprimis copied to clipboard

Mystery ternary in `rendertexturepanel()`

Open no-lex opened this issue 3 years ago • 4 comments

octaedit.cpp's rendertexturepanel has an assignment with mysteriously arbitrary values assigned to a throwaway variable, which should be commented properly.

            int s = (i == 3 ? 285 : 220),

no-lex avatar Mar 03 '21 07:03 no-lex

https://github.com/project-imprimis/libprimis/blob/main/src/engine/world/octaedit.cpp#L1869

The variable s is called into action on L1890 and L1891.

                int x = w*1800/h-s-50,
                    r = s;

Variable r is a texrotation type, while variable x goes on to be used as part of a gle::attribf call on L1942 through to L1945.

                    gle::attribf(x,   y);   gle::attrib(tc[0]);
                    gle::attribf(x+r, y);   gle::attrib(tc[1]);
                    gle::attribf(x,   y+r); gle::attrib(tc[3]);
                    gle::attribf(x+r, y+r); gle::attrib(tc[2]);

acerspyro avatar Mar 03 '21 19:03 acerspyro

Why the values of 285 and 220 though?

no-lex avatar Mar 03 '21 19:03 no-lex

No clue, may have been used to resolve an undocumented edge case?

Remove the ternary and keep the variable s at 220 at all times, and see if issues arise.

acerspyro avatar Mar 03 '21 20:03 acerspyro

The r as a texrotation type is in a different scope to the int, and it isn't clear why the value is copied from s to r, though it is likely cruft from years of modification. The ternary is simply a size value which makes the currently selected texture in the panel bigger than the rest. The panel shows 3 textures before and after the current texture, making the range [0..6] where 3 is the middle one ([0] [1] [2] [ 3 ] [4] [5] [6]).

That being said, the texture panel is a legacy thing and should probably be replaced by an appropriate UI implementation.

qreeves avatar Feb 13 '22 05:02 qreeves