Giter VIP home page Giter VIP logo

Comments (9)

GregoryLundberg avatar GregoryLundberg commented on April 27, 2024 1

Near as I can tell, all this junk is being used in stuff having to do with pixel values R G B and Alpha. The idea is to do some of the math in a fixed-point representation where we have an int32_t holding a 24 bits left of the decimal and 8 bits to the right. Of course, it's sorta lame to be doing signed math on unsigned values, but whatever. Most of the uses are creating the values 0x00000000 and 0x00000100 (0.0 and 1.0).

In at least one place, the int32_t value is stored in an int16_t so I hope whoever did that made very sure to avoid any implicit sign extension errors.

Is this a code smell? Yes.

Is it screaming to be fixed? No. It doesn't seem to be causing any problems.

Is it premature optimization? Probably. But, considering where it's used, in the few places it actually does anything, it's probably actually speeding things up enough to be warranted.

My recommendation would be to hold our noses, leave things as they are and put the entire src/utils/math.hpp file on the list of good projects for a new programmer to work on because it's probably not causing issues, but it's just asking for cleanup and/or elimination.

from wesnoth.

GregoryLundberg avatar GregoryLundberg commented on April 27, 2024

Can this be closed?

  • the OP is from 2005
  • there is no src/utils.hpp any more.
  • src/display.cpp has no display::draw_bar any more.

from wesnoth.

CelticMinstrel avatar CelticMinstrel commented on April 27, 2024

I seem to recall those macros being removed, as well.

from wesnoth.

jyrkive avatar jyrkive commented on April 27, 2024

These macros still exist:

wesnoth/src/utils/math.hpp

Lines 312 to 335 in d78ed1c

#if 1
typedef int32_t fixed_t;
# define fxp_shift 8
# define fxp_base (1 << fxp_shift)
/** IN: float or int - OUT: fixed_t */
# define ftofxp(x) (fixed_t((x) * fxp_base))
/** IN: unsigned and fixed_t - OUT: unsigned */
# define fxpmult(x,y) (((x)*(y)) >> fxp_shift)
/** IN: unsigned and int - OUT: fixed_t */
# define fxpdiv(x,y) (((x) << fxp_shift) / (y))
/** IN: fixed_t - OUT: int */
# define fxptoi(x) ( ((x)>0) ? ((x) >> fxp_shift) : (-((-(x)) >> fxp_shift)) )
#else
typedef float fixed_t;
# define ftofxp(x) (x)
# define fxpmult(x,y) ((x)*(y))
# define fxpdiv(x,y) (static_cast<float>(x) / static_cast<float>(y))
# define fxptoi(x) ( static_cast<int>(x) )
#endif

And they are still being used by scale_surface().

from wesnoth.

CelticMinstrel avatar CelticMinstrel commented on April 27, 2024

Ah, okay. Well, presumably we can just remove the #if and stuff, then. I think changing it ti #if 1 satisfied the issue though.

from wesnoth.

GregoryLundberg avatar GregoryLundberg commented on April 27, 2024

Um. WTF? We seriously were doing a de-normalizing floating-point implementation? What, did one of the target machines lack a working floating-point unit?

I'd strongly suggest change #if 1 to #if 0, debug, then reduce until the macros meet their long-overdue demise.

from wesnoth.

CelticMinstrel avatar CelticMinstrel commented on April 27, 2024

I believe one of the target machines actually did lack a floating-point unit - OpenPandora possibly? Support for that has been dropped now, though.

from wesnoth.

jyrkive avatar jyrkive commented on April 27, 2024

My guess would be that the fixed-point implementation is used for performance.

from wesnoth.

GregoryLundberg avatar GregoryLundberg commented on April 27, 2024

Well, take the junk out and see if the game crawls.

While I agree, it's possible someone's attempt at an optimization, but if so it smells highly of premature optimization. I'd want a comment block with A/B test results proving a significant improvement. Otherwise, this is just an obscure way to hide basic errors.

from wesnoth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.