ACS dynamic parameter strings

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: ACS dynamic parameter strings

Re: ACS dynamic parameter strings

by Graf Zahl » Sat May 21, 2011 5:05 pm

FDARI wrote: However, we do not save these strings in savegames at all. With ACS_ExecuteWithResult it may be possible to create a string after the ACS thinker has executed and before a savegame occurs. That means that the savegame will not reflect the gamestate with 100% accuracy.

That can't really happen. The entire thinker setup is constructed so that the ACS thinker is always ticked last, so anything that may trigger ACS_ExecuteWithResult should have run already.

Re: ACS dynamic parameter strings

by FDARI » Sat May 21, 2011 3:41 pm

I have discovered something of minor consequence regarding this submission.

ACS scripts can run outside of the thinker's normal execution when called from outside of ACS using ExecuteWithResult. Since an ACS-tick will follow, and clear the string array, this is not an issue with great impact.

However, we do not save these strings in savegames at all. With ACS_ExecuteWithResult it may be possible to create a string after the ACS thinker has executed and before a savegame occurs. That means that the savegame will not reflect the gamestate with 100% accuracy.

I'd say "it only does", but I don't like having that inconsistency there.

To solve this there must be no chance of triggering acs-scripts inbetween string cleanup and any save-event.
It is a non-issue if no process that can trigger scripts runs inbetween the ACS ticker and the savegame.

Re: ACS dynamic parameter strings

by Graf Zahl » Mon May 16, 2011 6:00 am

The int just refers to a temporary string. The int will remain but after the ACS thinker ends its tick the string it refers to will be deleted.
ACS doesn't have any string management so this is the only way to prevent leaks.

Re: ACS dynamic parameter strings

by Nash » Mon May 16, 2011 4:42 am

So using the keyObject example in the first post, what do I have to do to make the string stored in keyObject permanent? Any examples?

The thing that really makes my head spin is, isn't assigning something to the int keyObject permanent enough? I mean, what makes arrays more permanent than the int? What if I move int keyObject outside of script 1? Will that make it permanent?

Re: ACS dynamic parameter strings

by FDARI » Mon May 16, 2011 1:47 am

I don't really care how it is done as long as it works for the intended users. My source of ACC downloads has so far been zdoom.org/Download for ACC.EXE or C++ source, and the SVN for the "zcommon" include-set.

Regarding the discussion on strcpy: The simplest design has been chosen, and I see its merit on many levels, so I am ready to make a code submission. Won't be today, though. I alternate a little on the name. Should we call it "strcpy", "stringcopy", "strcopy"...?

Re: ACS dynamic parameter strings

by Demolisher » Sun May 15, 2011 10:22 pm

FDARI wrote:It is not useless at all. In fact, it is the only way to pass a dynamic string as a parameter to a function. ACC++ will provide good means for working with dynamic strings, but there is one thing ACC++ could not have done for you on your own: Make those dynamic strings useful as function parameters. I can't say exactly how it will look, but that one thing has gone from impossible to possible with this addition.

Maybe I or somebody else should build a little demo-project to show how this function is meant to be useful.

Guys, do you know anything about uploading the modified source for acc.exe so that code for the latest version can be compiled?
Upload what? It's already up... Or maybe the 3 hours restructuring my functions to use strparam() were just imagined. To you mean uploading an SVN build? I believe Gez and Graf manage those IIRC.

Re: ACS dynamic parameter strings

by FDARI » Sun May 15, 2011 2:37 pm

It is not useless at all. In fact, it is the only way to pass a dynamic string as a parameter to a function. ACC++ will provide good means for working with dynamic strings, but there is one thing ACC++ could not have done for you on your own: Make those dynamic strings useful as function parameters. I can't say exactly how it will look, but that one thing has gone from impossible to possible with this addition.

Maybe I or somebody else should build a little demo-project to show how this function is meant to be useful.

Guys, do you know anything about uploading the modified source for acc.exe so that code for the latest version can be compiled?

Re: ACS dynamic parameter strings

by NeuralStunner » Sat May 14, 2011 10:39 am

Nash wrote:I read somewhere that say that this string will only exist for 1 tic and will not be saved into the save game.
I hope that's not the case, as that sounds largely useless. :?

Re: ACS dynamic parameter strings

by Graf Zahl » Sat May 14, 2011 10:37 am

Yes, precisely. If you want the string to persist you have to copy it to an array.

Re: ACS dynamic parameter strings

by Nash » Sat May 14, 2011 9:39 am

Quick question, I read somewhere that say that this string will only exist for 1 tic and will not be saved into the save game. Does that means if it so happens (fat chance, but it could) that the game was saved exactly 1 tic after the function is used... when the user loads the save game, that string is lost?

Re: ACS dynamic parameter strings

by Graf Zahl » Sat May 14, 2011 9:08 am

Don't bother with strcpy.

Since in all cases you are copying from a byte array to an integer array any attempt to 'optimize' by using strcpy will cost you more than you might ever save.

Re: ACS dynamic parameter strings

by FDARI » Sat May 14, 2011 4:03 am

I do not insist on the nonsense itself. However, I persist in reiterating it until I am certain that the answer entails no misconception about what I am suggesting. I am now convinced, as there is no incorrect assumption in your reply.
Spoiler: Still...
"Return the number of copied characters for all 3 versions and be done with it."

Noted. Moving on.

The next question: What would we use internally in zdoom? How much is this function worth if it works by copying characters from a string to a an array of 32-bit integers through a C++ loop? Fewer pcodes (light reduction on memory use and evaluations)?

What are our chances and benefits of using a real strcpy or memcpy?

I'm taking a look at the array storage types now, to see what answers I myself come up with. If we find a means to use real strcpy, we also need to make the data usable afterwards. Array printing assumes one character per int.

EDIT: World/global array is TMap sorted on integer key? We'll probably have to stick to the iterated assignment of char to int. Level-arrays seem more workable, but that doesn't mean there's a good way to use actual strcpy.

Re: ACS dynamic parameter strings

by Graf Zahl » Fri May 13, 2011 3:03 pm

FDARI wrote:I have no intention of writing code that goes through with a function that could corrupt memory. ZDoom.exe will require internal checks for that. And the compiler knows what you instruct it to know.

The compiler knows the context of the call (expression that must provide a value, statement), and therefore knows whether a return value is required or unwanted.

The compiler can branch based on this knowledge, and knowledge of which pcode it has applied. Example post processing for token "strcpy":

Code: Select all

switch (pcode) // this would be in ACC.exe
{
    case PCD_STRCOPY_LEVEL:
        // PCD_STRCOPY_LEVEL is known by the programmer, and therefore the program, to have a return value
        if (!returnValue) PC_AppendCmd(PCD_DROP);
        // if no return value is required, add instruction to drop the returned value
        break;
    default:
        // remaining functions are known not to have return values
        if (returnValue) { PC_AppendCmd(PCD_PUSHBYTE); PC_AppendByte(1); }
}
The post-processing would look different if it were split into the general statement-evaluator and the general expression-evaluator, instead of merged into the above segment, but I just wanted to demonstrate what my english can't get across.

In short: The only people who will be concerned with the difference between the underlying pcodes are the programmers of Zdoom.exe and ACC.exe. The common interface presented by ACC.exe is specifically designed not to involve scripters in this process.

Why do you so persistently insist on this nonsense? The code you posted alone is proof enough for me that this is needlessly wonky. You even have to make the compiler more complicated and what for?
Return the number of copied characters for all 3 versions and be done with it.

Re: ACS dynamic parameter strings

by Blzut3 » Fri May 13, 2011 2:18 pm

FDARI wrote:I have no intention of writing code that goes through with a function that could corrupt memory. ZDoom.exe will require internal checks for that. And the compiler knows what you instruct it to know.
I was referring to ACS++'s implementation of malloc/free which if you recall I'm doing without any modifications to ZDoom.

Re: ACS dynamic parameter strings

by FDARI » Fri May 13, 2011 1:58 pm

I have no intention of writing code that goes through with a function that could corrupt memory. ZDoom.exe will require internal checks for that. And the compiler knows what you instruct it to know.

The compiler knows the context of the call (expression that must provide a value, statement), and therefore knows whether a return value is required or unwanted.

The compiler can branch based on this knowledge, and knowledge of which pcode it has applied. Example post processing for token "strcpy":

Code: Select all

switch (pcode) // this would be in ACC.exe
{
    case PCD_STRCOPY_LEVEL:
        // PCD_STRCOPY_LEVEL is known by the programmer, and therefore the program, to have a return value
        if (!returnValue) PC_AppendCmd(PCD_DROP);
        // if no return value is required, add instruction to drop the returned value
        break;
    default:
        // remaining functions are known not to have return values
        if (returnValue) { PC_AppendCmd(PCD_PUSHBYTE); PC_AppendByte(1); }
}
The post-processing would look different if it were split into the general statement-evaluator and the general expression-evaluator, instead of merged into the above segment, but I just wanted to demonstrate what my english can't get across.

In short: The only people who will be concerned with the difference between the underlying pcodes are the programmers of Zdoom.exe and ACC.exe. The common interface presented by ACC.exe is specifically designed not to involve scripters in this process.

Top