Jump to content
  • Advertisement
Sign in to follow this  
Licu

Is asIScriptGeneric::Prepare necessary?

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I run the same script context multiple times. From what I understand I need to call Prepare for every Execute. This Prepare call seems to be very slow (because it is doing a lot of checks, resets etc.) My script is very simple, no arguments to the function, but still Prepare takes a lot of time to execute. Do I really need to call this function, is it a faster way to prepare a script execution?

Share this post


Link to post
Share on other sites
Advertisement
If you intend to execute the same script function, you can call Prepare() with the funcID -1, in which case the function will do less verifications since it can reuse much of the information.

Share this post


Link to post
Share on other sites
If you intend to call the same function over and over again, it is definitely worth having a dedicated context for that function, but you still need to call Prepare() before each call. Because when the Execute() method finishes it doesn't leave the context in a prepared state. There are for example return values, and parameters on the stack that the application can retrieve. Also if the execution fails for some reason Prepare() must be called to reset the state.

However, I'll see what I can do to minimize the overhead when calling the same function over and over again.

Share this post


Link to post
Share on other sites
Yes, you're right! Well... you're always right! (in terms of AngelScript, of course! :P

Anyway... thank you very much for all!

By the way, i'm programming a multiplayer action game using your script for AI, some gameplay, weapons, items, etc.

Features:
- Particles
- Multiplayer (client/server)
- Top-down perspective
- Action and sneaking

Well... there's so much to do yet, but i promess you that soon i'll show you something cool... ;)



Share this post


Link to post
Share on other sites
Since we are on the topic...which do you recommend. When doing operations on a WxH array block of pixels with a function DoSomething(float r, float g, float b, float g), do you suggest calling Prepare and executing the function for every pixel or creating a for loop in the script to call the function for every pixel?

The Prepare takes time to set up, but does calling the function from the script take more,less or the same time to execute?

I don't really have anything solid I use AS for yet, just toying around with it in a couple of areas.

Share this post


Link to post
Share on other sites
Interesting question. I don't have an obvious answer, it would be necessary to test both solutions to see which was faster.

Prepare(-1) have relatively little overhead, but you will have to call SetArgFloat() 4 times for each of the calls. It might just be that doing the loop inside the script is faster.

Calling the DoSomething() function from within the script is faster than calling Prepare(-1), SetArgFloat()x4, Execute() from the application, but doing the loop in the script and possibly updating the arguments for each pixel is slower than in the application.

Which solution is faster would depend on how much else is done in the loop, I guess.

[edit]Just noticed that the title of this thread is wrong, it should be asIScriptContext instead of asIScriptGeneric [wink][/edit]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!