//*********************************************************************************
//                          SPARK Wrapper Load Demo
//                   Demonstrates extracting loaded systems
//*********************************************************************************




// we load back the explosion as a prototype 
// textures used by this system starts from 100

explosionProto = sp load system("Explosion.spk",1,100)


// optionally we can check for errors and warnings

if explosionProto = 0
    // Error occured in loading
    // see the returned value by SP GET LAST ERROR()
    end
endif


if explosionProto > 0
    // The system is loaded but still could be some warnings
    // see the returned value by SP GET LAST ERROR()
endif    

// ok now lets extract our data ! starting with number of 
// groups in the system


groupCount = sp get group count (explosionProto)



// loop and get the id's of the SPARK elements in the system :

for groupIndex = 0 to groupCount -1
    
    currentGroupID = sp get group id (explosionProto , groupIndex)
    
    // we have our first group , now get the emitters , modifiers 
    
    emitterCount = sp get emitter count (currentGroupID)
    modifierCount = sp get modifier count (currentGroupID)
    allemitters = allemitters + emitterCount
    allmodifiers = allmodifiers + modifierCount
       
        for emitterIndex = 0 to emitterCount-1
            
            // get the id if the emitter
            currentEmitterID = sp get emitter(currentGroupID , emitterIndex)
            // lets see the type of the emitter :
            if sp get type (currentEmitterID) = SP_SPHERIC_EMITTER then emitter=1 // do something !
            if sp get type (currentEmitterID) = SP_NORMAL_EMITTER then emitter=2 // do something !
            //etc...
        next emitterIndex      

         for modifierIndex = 0 to modifierCount-1
            // get the id if the modifier 
            currentModifierID = sp get modifier(currentGroupID , modifierIndex)
            // lets see the type of the emitter :
            if sp get type (currentModifierID) = SP_GRAVITY_MODIFIER then modifier=1 // do something !
            if sp get type (currentModifierID) = SP_POINTMASS_MODIFIER then modifier=2 // do something !
            //etc...
        next modifierIndex  

        // get the interpolator data , if the parameter is not interpolatoed , 
        // 0 is returned
        scaleInterpolatorID = sp get interpolator (currentGroupID , PARAM_SCALE)
        massInterpolatorID = sp get interpolator (currentGroupID , PARAM_MASS)
        angleInterpolatorID = sp get interpolator (currentGroupID , PARAM_ANGLE)
        atlasInterpolatorID = sp get interpolator (currentGroupID , PARAM_ATLAS_DIMENSIONS)
        rotspeedInterpolatorID = sp get interpolator (currentGroupID , PARAM_ROTATION_SPEED)
        // you can use the SP GET TYPE() to get they type
       
        // calculate the number of interpolators in all groups
        if scaleInterpolatorID >0 then interpolators = interpolators + 1
        if massInterpolatorID >0 then interpolators = interpolators + 1
        if angleInterpolatorID >0 then interpolators = interpolators + 1
        if atlasInterpolatorID >0 then interpolators = interpolators + 1
        if rotspeedInterpolatorID >0 then interpolators = interpolators + 1

        colorInterpolatorID = sp get rgba interpolator (currentGroupID)
        if colorInterpolatorID>0 then colorInterpolators = colorInterpolators+1
        
        
       // Get the renderer of the current group
       
       rendererID = sp get renderer(currentGroupID)
       // to see it's type :
       if sp get type (rendererID) = SP_POINT_RENDERER then renderer = 1 // do something with it
       if sp get type (rendererID) = SP_QUAD_RENDERER then renderer = 2 // do something with it
            
            
next groups


do
    
    set cursor 0,0
    print "LOADED SYSTEM INFORMATION :"
    print ""
    print "GROUPS              : " + str$(groupCount)
    print "EMITTERS            : " + str$(allemitters)
    print "MODIFIERS           : " + str$(allmodifiers)
    print "INTERPOLATORS       : " + str$(interpolators)
    print "RGBA INTERPOLATORS  : " + str$(colorInterpolators)
    
loop






