AngelScript performance

Started by
13 comments, last by WitchLord 19 years, 7 months ago
Quote:Original post by abrken
I don't know what you're meaning when your saying *safely*


I meant situation like this:

Say, I have two (C++) classes, CChild and CParent, CChild : public CParent, which are exported to Angel Script (as unrelated types, alas).

Suppose I have an instance of CChild (in AngelScript) and I want to call a function which takes CParent &. How do I cast CChild to CParent?

To illustrate this:

void SomeFunc( CParent & p );...CChild c;SomeFunc( c ); // fails to compile - unrelated typesSomeFunc( (CParent &) c ); // fails to compile - expected expression value


Right now it seems like no such typecast is possible in AngelScript.
Advertisement
Ok, I see now what your meaning by *safely* cast.

In such situation you've got two choices :
1/ Wait for AngelScript to have inheritance.
2/ Provide some extra code with the algo I have explained and change a little your script function.
bool RegisterObjectHierarchy(char *TypeParent, char *TypeChild)

should be changed to
bool RegisterObjectHierarchy(char *TypeParent, char *TypeChild, asUPtr funcPointerToCast)


funcPointerToCast is a C++ function that could be like this
CParent *castCChildToCCparent(CChild *p){  if p is kind of CParent    return (CParent*)p;   else    return NULL;}



in your RegisterObjectHierarchy you can then RegisterGlobalFunction with a preformated name ("%s_cast_%s", TypeChild, TypeParent) that point to the C++ cast function.

Next in your're script :
void SomeFunc( CParent *p );

CChild *c;

SomeFunc(CChild_casst_CParent(c));

This should work !

Of course, your're speaking about non pointer vars, so you can insert function dedicated to give a pointer in RegisterObjectHierarchy.

Does it sound good for you ?
To add on what abrken said.

AngelScript doesn't have inheritance yet, which of course you already know. It also doesn't support any kind of typecasting for registered objects or pointers.

In your situation I would register a function that takes a pointer to CChild, and returns a pointer to CParent. Note that if the CChild has multiple inheritance then the actual value of the pointers are not guaranteed to be the same.

Object inheritance, and classes declared in the script is something that I'm delaying for a future version. Perhaps 2.x. There are many other things that I want to implement first, like arrays, exception handling, data structures, etc.

To go back to the subject of performance in AngelScript.

I've done some experimenting and believe I have figured out a way to improve performance with at least 30%. Still doesn't make it as fast as Lua, but at least it will be closer. I'll put some effort in making these performance improvements already for version 1.9.1.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote:Original post by WitchLord
To add on what abrken said.

AngelScript doesn't have inheritance yet, which of course you already know. It also doesn't support any kind of typecasting for registered objects or pointers.

In your situation I would register a function that takes a pointer to CChild, and returns a pointer to CParent. Note that if the CChild has multiple inheritance then the actual value of the pointers are not guaranteed to be the same.

Object inheritance, and classes declared in the script is something that I'm delaying for a future version. Perhaps 2.x. There are many other things that I want to implement first, like arrays, exception handling, data structures, etc.


Well, I already considered using such functions, but it seemed like inconvenient and somewhat slow (additional calls) solution to me.

However, bigger issue here is inconvenience. I want to automate binding to AS by wrapping Register*() calls with macros (I know about AngelScriptBind, but I dislike the idea of maintaining separate *.pkg files), and things get more complicated with 'casting' functions. Nevertheless, I admit those can solve the problem, although in somewhat clumsy way.

By the way, in my humble opinion, arrays won't be as useful as class hierarchy would (especially considering the fact that arrays can already be simulated by operator[], which is sufficient in most cases) :)

Quote:Original post by WitchLord
To go back to the subject of performance in AngelScript.

I've done some experimenting and believe I have figured out a way to improve performance with at least 30%. Still doesn't make it as fast as Lua, but at least it will be closer. I'll put some effort in making these performance improvements already for version 1.9.1.


That's a good news. I believe that AngelScript should actually work *faster* than Lua, for it is not dynamically-typed, has no garbage collection, does not need wrappers for calling C++ funcs etc etc :-)

Cheers,
RCL
All I can say is that I will investigate inheritance for a future version, but I can't guarantee anything. I recognize the need for automatic binding and I can assure you that I will do what's possible to support it.

I agree with you that AngelScript should theoretically be faster than Lua, but it seems that I'm far from there. I'll have to take a look at the source for Lua to see what they do to make it so fast. Maybe then I can get some further ideas for optimizations. But most likely it is that they are using specialized bytecodes to join many instructions in one.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement