"How do I ZScript?"
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
How do I get width/height of a TextureID?
-
kodi
-

- Posts: 1361
- Joined: Mon May 06, 2013 8:02 am
Re: "How do I ZScript?"
Thanks man, I'll try it out right away! No longer will my bullets bounce around the inside of a monster like a supersonic hornet in a jar.Major Cooke wrote: @kodi: Override CanCollideWith. Do a check for non-passive on the actor with the pointer, see if it's that pointer and return false. True for all other cases.
Edit: worked perfectly, yay
Last edited by kodi on Thu Mar 23, 2017 5:28 pm, edited 1 time in total.
-
Nash
-

- Posts: 17514
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
AFADoomer / Major Cooke / ZZYZX : Thanks, you just prevented my mod from leaking memory. :3
ZZYZX: TexMan.GetSize(tex) ? Returns 2 ints.
ZZYZX: TexMan.GetSize(tex) ? Returns 2 ints.
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
Thanks. I knew it's something obvious but failed to remember instantly.
-
Nash
-

- Posts: 17514
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
Code: Select all
// Take an item from an Actor
static void _TakeItemFromActor(Actor a, class<LADgameItem> cls, int amount)
{
if (!a || !cls || amount <= 0)
{
return;
}
else
{
int i, ii;
if (a is "LADgamePlayer")
{
for (i = 0; i < amount; i++)
{
// find the item
for (ii = 0; ii < LADgamePlayer(a).myItems.Size(); ii++)
{
if (LADgamePlayer(a).myItems[ii].GetClass() == cls)
{
// completely destroy it from memory
LADgamePlayer(a).myItems[ii].Destroy();
LADgamePlayer(a).myItems.Delete(ii, 1);
break;
}
}
// no more left
if (LADgamePlayer(a).myItems.Find(cls) == 0)
{
break;
}
}
}
}
}
Is there any way to make it faster?
In real-life gameplay situations, the player won't be able to accumulate a million copies of the item, at least not in such a short span of time, and of course I will implement some book keeping to regularly destroy items in that list, but I'm just curious if my for loops in this particular method is unoptimized.
-
Major Cooke
- Posts: 8221
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: "How do I ZScript?"
Don't do the Delete function there. Wait until after the loop is done and then perform ShrinkToFit. Hopefully will cut at least half the time off of it, but that's just hoping.
-
AFADoomer
- Posts: 1346
- Joined: Tue Jul 15, 2003 4:18 pm
Re: "How do I ZScript?"
Will that work? Does calling Destroy on the actor delete/null the pointer in the array?Major Cooke wrote:Don't do the Delete function there. Wait until after the loop is done and then perform ShrinkToFit. Hopefully will cut at least half the time off of it, but that's just hoping.
Also, based on what I can decipher from the code, ShrinkToFit just shrinks the array to the size of the last index with a value - it doesn't collapse empty values that occur earlier in the array. Delete removes an index's (or range's) value, then shifts the entire rest of the array left to fill the slot.
-
Major Cooke
- Posts: 8221
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: "How do I ZScript?"
Graf confirmed it shrinks everything down and removes all empty spaces.
Graf Zahl wrote:ShrinkToFit reallocates the memory buffer to hold the exact amount of entries used. To avoid fequent reallocation the array class reallocates in larger chunks, this is for freeing that unused space once you know the array won't grow any further.
-
AFADoomer
- Posts: 1346
- Joined: Tue Jul 15, 2003 4:18 pm
Re: "How do I ZScript?"
It shrinks the array by finding the last entry where there is a value and resizing the array to that size. It only removes empty spaces from the end of the array, not inside of the array. If you've destroyed an object (which could well lead to the pointer now pointing to random memory) or if you manually set an index value to null, it'll stay in the array as such.Major Cooke wrote:Graf confirmed it shrinks everything down and removes all empty spaces.
Graf Zahl wrote:ShrinkToFit reallocates the memory buffer to hold the exact amount of entries used. To avoid fequent reallocation the array class reallocates in larger chunks, this is for freeing that unused space once you know the array won't grow any further.
Simplified example, where 1 means there is a value there, and 0 means no value:
Code: Select all
This before ShrinkToFit:
{ 0, 0, 1, 0, 1, 1, 1, 1, 0, 0 }
becomes:
{ 0, 0, 1, 0, 1, 1, 1, 1 }It basically says: If the max allocated index (Most) is greater than the actual highest used index (Count), then set Most equal to Count and call DoReSize() (or blank the whole array if Count/Most is now zero). DoResize is on line 433 - It just allocates the new, smaller "Most" amount of space for the array, nothing more.
EDIT: And, went to update the wiki, and it's already done...
Last edited by AFADoomer on Thu Mar 23, 2017 11:17 pm, edited 2 times in total.
-
Nash
-

- Posts: 17514
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
AFADoomer is right, it doesn't get rid of the empty slots that's not at the end.
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
It's probably a bug that it deletes anything at the end.
If I'm reading Graf correctly, ShrinkToFit should not affect the part visible to the user at all, it should only make two internal values match (real size of array and returned size of array), while normally real size of array can be slightly larger than the value returned by Size().
If I'm reading Graf correctly, ShrinkToFit should not affect the part visible to the user at all, it should only make two internal values match (real size of array and returned size of array), while normally real size of array can be slightly larger than the value returned by Size().
-
Major Cooke
- Posts: 8221
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: "How do I ZScript?"
Also, I knew this was going to happen. Hopefully no one invested in that...
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
DrawPowerup seems to still be there.
-
Major Cooke
- Posts: 8221
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: "How do I ZScript?"
Does nothing though. Used your code too.
Code: Select all
class TestItem : Inventory
{
override bool DrawPowerup(int x, int y)
{
Console.Printf("DRAWPOWERUP");
return true;
}
}-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
Everything is broken! Don't use the devbuilds (tm)
RenderOverlay when?
(I might as well try to understand how the new status bar code works, and try to put drawing there, but I'm already suspicious about althud checks here and there, as well as existing idea that titlemap should never have any statusbar...)
RenderOverlay when?
(I might as well try to understand how the new status bar code works, and try to put drawing there, but I'm already suspicious about althud checks here and there, as well as existing idea that titlemap should never have any statusbar...)
Last edited by ZZYZX on Fri Mar 24, 2017 5:07 pm, edited 1 time in total.