@name HSYS/FIGURES/MISC/GIR_HSLOAD
@inputs 
@outputs 
@persist 

if (first())    {
    #-Initialize
    #include "2015_october/GIR_HSINJ"

    DELAY = TABLE:count()
    interval(DELAY), print("Spawning " + DELAY + " holograms at " + min(round(1000/DELAY),DELAY) + " holograms per second.")
    runOnLast(1)

    #-Hologram Setup
    FACTOR = 1
    SHADING = 1
    STATUS = "spawning"
    MODE = "load"
    
    ENTITY = entity()
    OWNER = owner()
} elseif (MODE == "load") {
    if (STATUS == "spawning")   {
        interval(DELAY)
        if (HINDEX < TABLE:count() & holoCanCreate()) {
            HINDEX++
    
            #PAR = holoEntity(TABLE[HINDEX, array][1, number]) ?: entity(TABLE[HINDEX, array][1, number])
            PAR = TABLE[HINDEX, array][1, number] == SEED ? ENTITY : holoEntity(TABLE[HINDEX, array][1, number])

            holoCreate(HINDEX)
            holoParent(HINDEX, PAR)
            holoPos(HINDEX, PAR:toWorld(FACTOR * TABLE[HINDEX, array][3, vector]))
            holoAng(HINDEX, PAR:toWorld(TABLE[HINDEX, array][4, angle]))
            holoModel(HINDEX, TABLE[HINDEX, array][6, string])
            holoMaterial(HINDEX, TABLE[HINDEX, array][7, string])
            holoColor(HINDEX, TABLE[HINDEX, array][8, vector])
    
            if (TABLE[HINDEX, array][2, number] == 0)    { holoScale(HINDEX, FACTOR * TABLE[HINDEX, array][5, vector]) }
            if (TABLE[HINDEX, array][2, number] == 1)    { holoScaleUnits(HINDEX, FACTOR * TABLE[HINDEX, array][5, vector]) }
            if (SHADING == 1) { holoDisableShading(HINDEX, 1) }
    
            setName("HoloLoader -- Spawning " + toString((HINDEX / TABLE:count()) * 100) + "% complete.")
            if (HINDEX == TABLE:count())   { 
                STATUS = CLIP:count() ? "clipping" : "finished"
                print("Spawning of " + TABLE:count() + " holograms finished.")
            }
        }
    } elseif (STATUS == "clipping") {
        interval(DELAY)
        if (CINDEX < CLIP:count()) {
            CINDEX++
            
            CLIPHOL = CLIP[CINDEX, array][1, number]
            CLIPNUM = CLIP[CINDEX, array][2, number]
            CLIPPOS = CLIP[CINDEX, array][3, vector]
            CLIPDIR = CLIP[CINDEX, array][4, vector]
    
            holoClipEnabled(CLIPHOL, CLIPNUM, 1)
            holoClip(CLIPHOL, CLIPNUM, CLIPPOS*FACTOR, CLIPDIR, 0)
            
            if (CINDEX == CLIP:count())   { STATUS = "finished", print(CLIP:count() + " clips created.") }
        }
    } elseif (STATUS == "finished")   {
        MODE = "run", print("Script is now live!")
    }
} elseif (MODE == "run")    {
    
    #MAIN RUNNING CODE GOES HERE
    
    #if (clk()) {}
    #if (tickClk()) {}

}
