Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

IGSoundEffectsSubsystem.ActorBank


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
class ActorBank extends Engine.Actor
    native;

// =============================================================================
//  ActorBank
//   
//  An actor bank allows you to deposit and withdraw actors, allowing you to pool 
//  them to save on the costs of creating and deleting actors constantly.  Depositing
//  the actor will by default cause the actor to disappear, and stop ticking, making
//  it fairly low cost.  The only real cost of a deposited actor will be that it takes
//  up a spot in the actor list.  When an actor is withdrawn, it will reappear by 
//  default, and be removed from the banked actors list.  What happens to the actor
//  when deposited or withdrawn is handled by a delegate, so clients of this class 
//  can override the behaviour to do whatever was necessary.  The default behavior 
//  is simply to show and hide them respectively.
//
//  Note: Initialize MUST be called before being able to use this ActorBank
//
// ==============================================================================

var private array<Actor>        BankedActors;       // fifo list of banked actors
var private class<Actor>        ActorClassType;     // Class type for banked actors
var private bool                bInitialized;       // True if initialized

//  carlos: set this to 1 to debug actor bank deposits/withdrawls
#define BANK_DEBUG 0

// Overridable delegate for withdrawn behavior 
delegate OnWithdrawn(Actor inActorWithdrawn)
{
    inActorWithdrawn.OptimizeIn();
}

// Overridable delegate for deposited behavior 
delegate OnDeposited(Actor inActorDeposited)
{
    inActorDeposited.OptimizeOut();
}

// Initialize this actor bank, Note: This MUST be called before using this actor bank.
simulated function Initialize(class<Actor> inClassType)
{
    ActorClassType = inClassType;
    bInitialized = true;
}

// Withdraw an actor from the bank.  If there are no actors in the banked list, it will create a 
// new one.  Wish real banks were that generous.
simulated event Actor Withdraw()
{
    local Actor WithdrawnActor; 

    assertWithDescription(bInitialized, "You MUST call Initialize before using an ActorBank.");

    if (BankedActors.Length > 0)
    {
        WithdrawnActor = BankedActors[0];
        BankedActors.Remove(0,1);
    }  
    else 
    {
        WithdrawnActor = Spawn(ActorClassType);
#if BANK_DEBUG
        log( "New actor "$WithdrawnActor$" created during soundeffects subsystem ActorBank withdrawl!" );
#endif
    }
    
#if BANK_DEBUG 
    log( "Actor "$WithdrawnActor$" withdrawn, Number of actors in Bank: "$BankedActors.Length );
#endif 
    OnWithdrawn(WithdrawnActor);
    return WithdrawnActor;
}

// Deposit and actor into the banked list.  
simulated event Deposit(Actor inActor)
{
    local int ct;

    assertWithDescription(bInitialized, "You MUST call Initialize before using an ActorBank.");
    assertWithDescription(inActor.IsA(ActorClassType.Name), "You can only deposit actors of class "$ActorClassType$", you're trying to deposit a "$inActor.Class);

    // Only deposit unique entries, script dynamic arrays don't have the AddUniqueItem exposed
    for ( ct = 0; ct < BankedActors.Length; ++ct )
    {
        if ( inActor == BankedActors[ct] )
        {
            return;
        }
    }

    // Add to the end 
    BankedActors[BankedActors.Length] = inActor;
#if BANK_DEBUG
    log( "Actor "$inActor$" deposited, Number of actors in Bank: "$BankedActors.Length );
#endif
    OnDeposited(inActor);
}

defaultproperties
{
    bHidden=true
    bStasis=true
    bCollideActors=false
    bCollideWorld=false
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 16:02:12.000 - Creation time: st 23.5.2018 00:10:40.823 - Created with UnCodeX