ZScript "Standard Library" - Brainstorming

Post your example zscripts/ACS scripts/etc here.

Re: ZScript "Standard Library" - Brainstorming

Postby Xaser » Mon Jan 23, 2017 10:42 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript "Standard Library" - Brainstorming

Postby Graf Zahl » Tue Jan 24, 2017 4:28 am

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 allExpand view
// 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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Postby Ethril » Tue Jan 24, 2017 4:35 am

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
Ethril
F1
 
Joined: 16 Nov 2008
Location: Guidance Gate

Re: ZScript "Standard Library" - Brainstorming

Postby Rachael » Tue Jan 24, 2017 7:52 am

Handy Open Example Repository System

... maybe not the best, but it's a start.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript "Standard Library" - Brainstorming

Postby Major Cooke » Tue Jan 24, 2017 8:06 am

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: ZScript "Standard Library" - Brainstorming

Postby ZZYZX » Tue Jan 24, 2017 11:22 am

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
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: ZScript "Standard Library" - Brainstorming

Postby kodi » Tue Jan 24, 2017 12:16 pm

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
kodi
Proscrastinator
 
 
 
Joined: 06 May 2013

Re: ZScript "Standard Library" - Brainstorming

Postby Nash » Tue Jan 24, 2017 12:32 pm

ZZYZX wrote:It's in progress though :P
Estimating like 1 week until done, then some time for Graf review/approval


!!!!!!!!!!!
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript "Standard Library" - Brainstorming

Postby Graf Zahl » Tue Jan 24, 2017 12:35 pm

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.)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript "Standard Library" - Brainstorming

Postby Gez » Tue Jan 24, 2017 12:44 pm

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.
Gez
 
 
 
Joined: 06 Jul 2007

Re: ZScript "Standard Library" - Brainstorming

Postby ZZYZX » Tue Jan 24, 2017 12:44 pm

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
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: ZScript "Standard Library" - Brainstorming

Postby Rachael » Tue Jan 24, 2017 1:56 pm

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
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript "Standard Library" - Brainstorming

Postby ZZYZX » Tue Jan 24, 2017 2:24 pm

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
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: ZScript "Standard Library" - Brainstorming

Postby Xaser » Wed Jan 25, 2017 9:47 am

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript "Standard Library" - Brainstorming

Postby Major Cooke » Wed Jan 25, 2017 11:26 am

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?
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

PreviousNext

Return to Script Library

Who is online

Users browsing this forum: No registered users and 0 guests