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.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top