Multiple struct > Struct array members?

XeNiM666

I lurk for pizza
Reaction score
138
Its a simple question, supposed i am to create a nova of 16 fireballs. Should i use 16 multiple structs to handle each fireball? or should i use 1 struct with 16 multiple array members to handle the fireballs? in terms of efficiency and speed.
TIA. :)
 

tooltiperror

Super Moderator
Reaction score
231
I don't understand the question. What are you trying to achieve?
 

XeNiM666

I lurk for pizza
Reaction score
138
the nova is just an example... let me explain...
supposed i am to create a nova of 16 fireballs in my location. What should i use to achieve more efficiency and speed.
Should i use multiple structs:
JASS:
    private struct Fire
        unit u
        real x
        real y
        bla bla bla
        
        static method create takes bla bla bal
        endmethod
    endstruct
    
    function Action takes nothing returns nothing
        local integer i = 0
        local Fire f
        loop
            set i = i + 1
            
            set f = Fire.create( x, y, bla bla bla )
            
            exitwhen i >= 16
        endloop
    endfunction

Or should i use 1 struct with array members:
JASS:
    private struct Fire
        unit u
        real x
        real y
        
        unit array fire [ 16 ]
        real array cos [ 16 ]
        real array sin [ 16 ]
        bla bla bla
        
        static method create takes bla bla bla
            local Fire f = Fire.allocate()
            local integer i = 0
            loop
                set i = i + 1
                set f.fire[ i ] = CreateUnit( ... )
                set f.sin[ i ] = Sin( ang )
                set f.cos[ i ] = Cos( ang )
                
                exitwhen i >= 16
            endloop
            
            return f
        endmethod
    endstruct
    
    function Action takes nothing returns nothing
        local Fire f = Fire.create( x, y, bla bla bla )
    endfunction
 

tooltiperror

Super Moderator
Reaction score
231
So you are creating fire effects? Why do you need to use a struct at all? Why don't you just create them directly?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
In terms of efficiency and speed, it's going to be negligible. However, in terms of what's "best", it depends on what your fireballs are.

If they are simply projectiles or units, it might be best to have a struct for the general definition of projectile or unit.

If you plan on having MANY of these spell instances going up at once, it should be noted that having an array as a member of a struct limits the number of instances of the struct to 512 (8192/16).

Also, using a separate struct for the fireballs would allow you to use a linked-list style method of iterating over the fireballs, which may or may not be favorable to you. If you only iterate in order from fireball 1 to 16, then it won't make any difference whether you use linked lists or arrays. However, if you happen to need a specific fireball at any point in time, it will be less efficient to use the linked list.

All in all, it should just be whatever you think is the best way to do it.
 

XeNiM666

I lurk for pizza
Reaction score
138
no. im using struct to do something with them... in my case, revolving them around the caster and move them to the casters position after some duration.. so?

EDIT:
I see.. Im not fond of linked lists so array will do. Since they are almost the same right?
Thanks for the quick replies! :)
 

saw792

Is known to say things. That is all.
Reaction score
280
Ah but linked lists are so beautiful... and don't reduce your instance limit!

Lame :(
 

LurkerAspect

Now officially a Super Lurker
Reaction score
118
I've made several nova abilities like this before - what I do is create a struct system for a single projectile, then I use a loop to generate as many "projectiles" as I need, and the struct works fine even with ~100 instances, and 0.02 interval, no lag whatsoever (aside from first cast lag of course). So I say make 16 separate fireballs, this makes it easier if the fireballs are supposed to hit other objects.
 

saw792

Is known to say things. That is all.
Reaction score
280
Of course, but then you can always recycle your instances :) I just like the flexibility of trees and linked lists :p
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I don't like the sized-array crap introduced by vJass.

JASS:

struct foo
 integer array guy[16]
 set this.guy[5] = 1

// Change that to...

integer array guy
set guy[this * 16 + 5] = 1

? What's wrong with it? I think that's what vJass does.

If you don't like it, the alternative is manually typing out that [ljass]this*16 + 5[/ljass] stuff.

JASS:
struct foo
    integer array bar[16]
    ...
    set this.bar[5] = 1
    ...
endstruct

//Alternatively:

globals
    integer array bar
endglobals

struct foo
    ...
    set bar[this * 16 + 5] = 1
    ...
endstruct


Almost a direct quote from you, but this is almost essentially what vJass does with structs, what syntax did you want? vJass arrays are limited by the same things as Jass.
 

Bribe

vJass errors are legion
Reaction score
67
vJass compiles it differently than what I posted, and I don't know why. It uses twice the array lookups.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top