Draw image

This topic contains 31 replies, has 6 voices, and was last updated by  juliocmfj 1 year, 7 months ago.

Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #10146

    Jesse
    Participant

    I am curious, Why did you decide to use Unsigned Int?

    #10147

    juliocmfj
    Participant

    Why there is no tile with negative ID. So I found it unnecessary to use an Int.

    #10149

    Voidwalker
    Participant

    And it should. I also don’t get why using an int instead of an unsigned should make trouble in that case. It simply doesn’t make sense at all.

    #10150

    juliocmfj
    Participant

    I’m trying to understand by now why this happened. If I was drawing based on Int coordinates and not UInt. UInt is serving exclusively only to get the ID of the tiles, and nothing more. But… That’s it.

    #10151

    Mark Sibly
    Keymaster

    I recommend avoiding the use unsigned values unless you are dealing with binary ‘bit patterns’ (for example, 32 bit ARGB values) or extern APIs that use unsigned values.

    The main problem is that math works differently with unsigned, which can lead to unexpected/surprising results. For example, unsigned numbers can never be <0 as they’re always positive so you can run into trouble ‘looping backwards’ quite easily. Also, subtracting an unsigned number from any other integer will always give you an unsigned result (ie: >=0 ) as both are converted to unsigned before the subtraction.

    Even if you expect values to always be >=0, eg: the layerId variable above, I would still recommend using plain old Int just to minimize the chance of surprises. I would not expect there to be any practical use for unsigned in the stuff you are doing here. Just because a feature is there doesn’t mean you have to use it!

    Unsigned can be useful for dealing with bit masks an so on, but it should be used very sparingly IMO.

    #10152

    juliocmfj
    Participant

    Roger, Mark. I will be more cautious when using unsigned values. I’ll make the necessary changes to the code right now. And again, thanks for the explanation.

    #10175

    juliocmfj
    Participant

    I’ve been trying to do some optimizations. I rendered a 1000×1000 map with 48×48 tiles and FPS in release mode averaged 10 FPS.

    After the optimizations, I got the average between 55 and 60 FPS with the same gigantic map.

    Below is the code. I would like opinions and know if I made a mistake.

    #10176

    nerobot
    Participant

    Working with constant-sized tiles grid you can calculate starting and ending indexies for x and y outside of double for-for.

    Then your ‘for’ loops will go through visible tiles only.

    #10177

    juliocmfj
    Participant

    Did not quite understand. Would you have a simple example?

    #10178

    nerobot
    Participant

    Pseudocode:

    Note:

    • inside of FOR I removed check for visibility because now we go through visible tiles onle
    • also I removed creating New TiledTile() – why to create instance if we can just draw ‘plain’ image
    • also I replaced xy.X & xy.Y with xy.x & xy.y – because of access to fields (small chars here) is faster that to properties (properties equals to method call)
    #10204

    abakobo
    Participant

    Primitives are faster than struct fields.. So I would not use vec2 inside such loops.

    Here I use vx ans vy but you Can also put their expressions direcly in drawimage arguments.
    The image coule be passed direcly too, it might perform better.

    [/crayon]
    #10219

    juliocmfj
    Participant

    abakobo, I followed your recommendations as well.

    #10220

    juliocmfj
    Participant

    Now you have a part that I do not understand. In the map matrix, the value -1 corresponds to no tiles, that is, no tiles with this value will be rendered, just above it.

    I saw above, what you did:

    . I think that this way, it should render the tiles only value -1… What whould be the logic behind?

    #10222

    nerobot
    Participant

    Keyword ‘Continue’ inside for loop is equivalent of Next, i.e. immediately go to the next loop frame. And here – skip all with index -1.

    #10223

    juliocmfj
    Participant

    It would be the same as:

Viewing 15 posts - 16 through 30 (of 32 total)

You must be logged in to reply to this topic.