ZScript "Standard Library" - Brainstorming

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Xaser »

Major Cooke wrote:I tried escaping that responsibility with my trusty steed.
Image

But he got into the horse nip. I'm going nowhere except a hospital if I even try to get on him.
On the plus side, I think we've found the standard library's mascot.
Arctangent wrote:hey don't let everyone just use my signature move like it was nothing
Quasi-ironically, we've all gone on a tangent before I had time to respond. :P
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Post by Graf Zahl »

Major Cooke wrote:
Xaser wrote:As a quick word of warning, I'd advise folks interested in actually writing such a library to exercise caution before jumping headlong into things. Doing this correctly is a non-trivial undertaking -- there needs to be a clean, well-documented API and sane versioning/release scheduling, else folks will try and axe-murder you when you publish a version that breaks everything. :P
Structs and/or classes with static functions aught to be fine. For example I use the struct TIterator to ease creation of ThinkerIterator so I can stop looking it up so much.

Note this is moreso tailed towards what I need it for so a lot of stuff can be left out.

Code: Select all

// Contains the iterator flags and instructions.
Struct TIteratorProperties
{
    enum EItFlags
    {
        ITF_EXACT =         1,        // Disregard inheritance.
        ITF_NOTID =            1 << 1,    // Ignore actors with a TID.
        ITF_NOSPECIAL =        1 << 2, // Ignore actors with a special.
        
        ITF_SAFE =            ITF_NOTID|ITF_NOSPECIAL,
    };
    
    enum EItInstructions
    {
        ITN_DESTROY =        1,        // Destroy all actors found.
        ITN_LOGCOUNT =        2,        // Displays how many of the actors were found.
    };
}

//------------------------------------------------------------------------------
// TIterator
//
// -- Properties --
// * p             - Contains a copy of accessible flags.
// * caller        - The actor doing the distance check.
//
// -- Functions --
// * (!)ErrorMessage (count)
//        Logs a problem message to console.
//        
// * (!)FindActors (ActorType, instructions, flags, maxcount, dist);
//        Looks for ActorType based on flags and distance, then executes the given
//        instruction.
//
// * Setup (mo)
//        Inserts the caller into the struct so it may run properly.
// 
// * DoFindActors
//        A wrapper function which sets up the iterator itself, and calls 
//        FindActors inside the TIterator struct.
//
// (!) - Private function. Must be called on by another.
//------------------------------------------------------------------------------

Struct TIterator
{
    TIteratorProperties p;
    private Actor caller;
//------------------------------------------------------------------------------
    private void ErrorMessage (int count)
    {
        if (!caller)    return;
        String msg = "";
        Switch (count)
        {
            Case -1:
            {
                msg = "Iterator error: No ActorType specified";
                break;
            }
            Case -3:
            {
                msg = "Iterator error: No instructions passed";
                break;
            }
            Default:    break;
        }
        caller.A_Log(msg);
    }
    
//------------------------------------------------------------------------------
    void Setup(Actor mo)
    {
        if (mo)    caller = mo;
    }
//------------------------------------------------------------------------------
    void DoFindActors (Class<Actor> ActorType, int instructions, int flags = 0, int maxcount = 0, double dist = 0.0)
    {
        if (caller)
        {
            int count = FindActors(ActorType, instructions, flags, maxcount, dist);
            
            if (count < 0)
            {
                ErrorMessage (count);
                return;
            }
            
            if (flags & p.ITN_LOGCOUNT)
                caller.A_LogInt(count);
        }
    }
//------------------------------------------------------------------------------
    private int FindActors (Class<Actor> ActorType, int instructions, int flags = 0, int maxcount = 0, double dist = 0.0)
    {
        // Indicate something went wrong or its not set up properly.            
        if (!ActorType)        return -1;    // Actor type doesn't exist
        if (!caller)        return -2;    // No caller was passed
        if (!instructions)    return -3;    // No instructions were passed
        
        ThinkerIterator it = ThinkerIterator.Create(ActorType);
        Actor mo;
        int count = 0;
        while (mo = Actor(it.Next(flags & p.ITF_EXACT)))
        {
            if (((flags & p.ITF_EXACT) && mo.GetClass() != ActorType) || !(mo is ActorType))
                continue;
                
            // Ignore actors with special and/or tids unless specified.
            if ((flags & p.ITF_NOTID) && mo.tid)
                continue;
            if ((flags & p.ITF_NOSPECIAL) && mo.special)
                continue;
            
            // Don't take owned items.
            if (mo is "Inventory")
            {
                let inv = Inventory(mo);
                if (inv.Owner != null)
                    continue;
            }
            
            // Make sure it's in range.
            if (dist <= 0.0 || caller.Distance3D(mo) <= dist)
            {
                count++;
                
                // Now perform the instructions.
                if (instructions & p.ITN_DESTROY)
                {
                    mo.Destroy();
                    continue;
                }
            }
        }
        return count;
    }
}

//------------------------------------------------------------------------------
// IteratorBase
//
// Houses all the setup materials for inheriting from. 
// Don't spawn it directly -- Inherit from it and replace
// PostBeginPlay instead.
//------------------------------------------------------------------------------

Class IteratorBase : Actor
{
    TIterator finder;
    TIteratorProperties p;

    override void PostBeginPlay()
    {
        Destroy();
        return;
    }
    
    Default
    {
        +NOSECTOR
        +NOINTERACTION
        +THRUACTORS
        +NOBLOCKMAP
    }
}

//==============================================================================
//==============================================================================
//    Examples
//==============================================================================
//==============================================================================

// Removes ammo on the map and prints the number of actors removed, but only if
// they have no tid or special.
Class AmmoRemover : IteratorBase
{
    override void PostBeginPlay()
    {   
        int instructions = p.ITN_DESTROY|p.ITN_LOGCOUNT;
        int flags = p.ITF_SAFE;
        int maxcount = 0;
        double dist = 0.0;
        
        finder.Setup(self);
        finder.DoFindActors("Ammo",instructions, flags, maxcount, dist);
        Destroy();
        return;
    }
} 
Virtual checkers are your friend, actually - you can make such an iterator a lot more powerful if the checks for what gets iterated are offloaded to a virtual function that can be overridden in a subclass instead of creating a mess of flags and options.
User avatar
Ethril
Posts: 2677
Joined: Sun Nov 16, 2008 2:59 am
Location: with you in the dark

Re: ZScript "Standard Library" - Brainstorming

Post by Ethril »

Xaser wrote:On the plus side, I think we've found the standard library's mascot.
Now we just need a name that can be acronym'd into HOERS.
User avatar
Rachael
Posts: 13530
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Rachael »

Handy Open Example Repository System

... maybe not the best, but it's a start.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript "Standard Library" - Brainstorming

Post by Major Cooke »

LMAO @ the horse business.

@Eruanna: I like it!

@Xaser: YES!!!
Last edited by Major Cooke on Wed Jan 25, 2017 11:27 am, edited 1 time in total.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ZZYZX »

Just saying it's a bad idea to "draw something on the screen" until the ZScript UI system is implemented.
It's in progress though :P
Estimating like 1 week until done, then some time for Graf review/approval.
All that after he answers my question on the esoteric GZDoom crash though because it currently blocks any events development.
User avatar
kodi
 
 
Posts: 1355
Joined: Mon May 06, 2013 8:02 am

Re: ZScript "Standard Library" - Brainstorming

Post by kodi »

ZZYZX wrote:Just saying it's a bad idea to "draw something on the screen" until the ZScript UI system is implemented.
It's in progress though :P
Estimating like 1 week until done, then some time for Graf review/approval.
All that after he answers my question on the esoteric GZDoom crash though because it currently blocks any events development.
I'm really hyped about this. I've used and abused hudmessages for things they weren't meant to do enough that I've grown incredibly sick of them (though some of the more esoteric tricks were fun to come up with)
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Nash »

ZZYZX wrote: It's in progress though :P
Estimating like 1 week until done, then some time for Graf review/approval
!!!!!!!!!!!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Post by Graf Zahl »

ZZYZX wrote: All that after he answers my question on the esoteric GZDoom crash though because it currently blocks any events development.

What question on what esoteric crash? Don't expect me to see everything occuring here in every thread. Unfortunately I'm rather busy with work right now (got a new project started on Friday that's taking up most of my time.)
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: ZScript "Standard Library" - Brainstorming

Post by Gez »

Xaser wrote:Yeah, I'd absolutely advocate using a prefix -- or a namespace if that indeed becomes a proper thing following Graf's type system overhaul.

Speaking of, even though this is the bikesheddiest sub-topic, I'm thinking of what to name such a thing. I'd originally imagined calling the library "XT" (for XTended or some shiz) just to give all the functions a nice "XT_" prefix, but something like ZTL (reference to C++'s STL) or SZL (Standard ZScript Library) are obvious-maybes as well.
It wouldn't about about templates, so ZTL wouldn't make much sense. SZL for Standard ZScript Library sounds good because you can pronounce it sizzle and that just seems somehow appropriate.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ZZYZX »

Graf Zahl wrote:
ZZYZX wrote: All that after he answers my question on the esoteric GZDoom crash though because it currently blocks any events development.

What question on what esoteric crash? Don't expect me to see everything occuring here in every thread. Unfortunately I'm rather busy with work right now (got a new project started on Friday that's taking up most of my time.)
You certainly saw that and asked me for function disassembly. I provided it, then you forgot about it apparently.
It's in the ZScript discussion thread.
User avatar
Rachael
Posts: 13530
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Rachael »

Well he DID say he was busy. Humans are nowhere near as good with context switching when multitasking as machines are. :P He probably just forgot.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by ZZYZX »

Eruanna wrote:Well he DID say he was busy. Humans are nowhere near as good with context switching when multitasking as machines are. :P He probably just forgot.
Hence "apparently" :) No side meanings there. I'm totally ok with reminding people about stuff as long as someone like wildweasel doesn't tell me to STFU, which is why I refrained from bumping my message even though Graf didn't reply.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript "Standard Library" - Brainstorming

Post by Xaser »

Gez wrote:It wouldn't about about templates, so ZTL wouldn't make much sense. SZL for Standard ZScript Library sounds good because you can pronounce it sizzle and that just seems somehow appropriate.
"Sizzle" is super-catchy, though Blzut3 suggested "ZBoost" over IRC, which I'm quite fond of as well. It's a fitting analogy for this hypothetical undertaking.

Speaking of undertaking, are there any devs interested in collabing on this (beyond a pull-request contributor role)? I'm probably going to break down and start this silly thing myself, but knowing me, I'm gonna need a partner in crime on this or I'll wander off track for long stretches of time.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript "Standard Library" - Brainstorming

Post by Major Cooke »

Count me in.
Graf Zahl wrote:Virtual checkers are your friend, actually - you can make such an iterator a lot more powerful if the checks for what gets iterated are offloaded to a virtual function that can be overridden in a subclass instead of creating a mess of flags and options.
So use a class not inheriting an actor instead of a struct?
Post Reply

Return to “Script Library”