Announcement

Collapse
No announcement yet.

Raffle Rarity System - Is this method efficient?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Raffle Rarity System - Is this method efficient?

    Hello,

    I've programmed a raffle-style rarity system for my obstacle spawning and I want to run it by the community to see if the method I devised is efficient or not. Please have a look.

    ~~~~~ ~~~~~ ~~~~~

    1) Create a data table drawing from a structure with a map of actors keyed to integers (commonalities).

    Click image for larger version  Name:	Screen-Shot-20191031-at-12.32.17-PM.png Views:	0 Size:	48.9 KB ID:	1680146

    2) Retrieve commonality map from data table using the name of the current level as the row name.

    3) Loop through all the actors in the commonality map, adding up their commonality (as if they were raffle tickets), and storing them in a new map where each obstacle is paired with an Int32Range.

    4) Store the total number of "tickets".

    Click image for larger version  Name:	Screen-Shot-20191031-at-12.37.10-PM.png Views:	0 Size:	235.9 KB ID:	1680147
    5) Get a random integer between 1 and the total number of tickets counted.

    6) Loop through all the actors in the new commonality map, checking if the random integer exists in any of their paired ranges.

    7) Spawn the actor whose range includes the random integer.

    Click image for larger version  Name:	Screen-Shot-20191031-at-12.38.13-PM.png Views:	0 Size:	228.2 KB ID:	1680148
    ~~~~~ ~~~~~ ~~~~~

    Is this a good method for object rarity? I like that it allows me to tune the rarity in one place inside the data table.
    I plan on executing SpawnObjects multiple times a second during play. Will looping through maps of actors and structs like this be inefficient?

    Any advice would be appreciated.

    Cheers.
    Last edited by MC1RScorpion; 10-31-2019, 01:24 PM.

    #2
    I'd recommend using a soft reference to an actor rather than a hard one because hard references must be loaded to iterate on them. Use a soft reference to the path of the actor then if its ticket is chosen you can manually load it using the Asset Registry then spawn it. Otherwise your memory usage might skyrocket.

    Your math is good and lean, I don't see any issues with running this multiple times per second as long as you aren't running it every tick or something crazy
    iTween For UE4
    Procedural pathed animation for actors, components & UMG - $0
    Runtime DataTable
    DataTables dynamically loaded from text or Google Sheets while your game is running!
    easyCSV
    Fast, cheap, and accurate CSV parsing at runtime!

    Comment


      #3
      Thanks for your response

      I've only read about soft references. How do you mean I should use them in this case? Should the map inside the data table be to only soft references? Or do I convert them to soft references after retrieving the row?

      Do soft references make a large difference in performance that I should revise my game and make this change wherever I can?

      Thanks for your time.

      Comment


        #4
        They should be soft reference sin the data table and in the struct. If you use soft references, you're just storing string data + meta and those don't become 'real' objects until you load them manually. If you have all hard references then you have them all stored in live memory the whole time.

        It's a trade off. With soft references you have to manually load which has a tiny performance cost during the game; if you use hard references everything is loaded at the beginning but that means taking up valuable memory. In the prototype stage that's fine but in a completed game you're loading every reference in every loaded object as well including things like textures. It depends on where you want to go with this in the end.
        iTween For UE4
        Procedural pathed animation for actors, components & UMG - $0
        Runtime DataTable
        DataTables dynamically loaded from text or Google Sheets while your game is running!
        easyCSV
        Fast, cheap, and accurate CSV parsing at runtime!

        Comment

        Working...
        X