• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
behc

Handles, Implicit Handles and GetReturnTypeId

5 posts in this topic

Hi

After recent update, I get lots of "The operand is implicitly converted to handle in order to compare them" warnings, all from "hSth == (or !=) null".
I tried turni[font="Arial"]ng on asEP_ALLOW_IMPLICIT_HANDLE_TYPES, but that doesn't change anything. My handle types don't have copy operators (in fact, with exception of add-on array, they can't be instanced in script), so I could skip all @, and work with handles more like with pointers in c++. Does/will implicit handles work that way?[/font]

[font="Arial"]My engine uses run-time declared types that works like simplified class inheritance. Base class is defined in C++ (and can be derived from other class using single inheritance model) and run-time declared class can add extra properties and events (thanks for update with function pointers [/font][img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img][font="Arial"]), this inheritance model is exposed to AS using asBEHAVE_(IMPLICIT)_REF_CAST, and since I don't know how many classes will be declared all casting behaviors are using single function.[/font]

[font="Arial"][code]void ASClassDownCast(asIScriptGeneric* gen)
{
void* p = gen->GetObject();
gen->SetReturnObject(p);
}

void ASClassUpCast(asIScriptGeneric* gen)
{
ITHEntity* pGE = static_cast(gen->GetObject());
if(pGE == NULL)
{
gen->SetReturnObject(NULL);
return;
}

int RetType = gen->GetReturnTypeId();

const ITHClass* pCls = pGE->GetClass();
while(pCls)
{
if(pCls->GetScriptType() == RetType)
{
gen->SetReturnObject(pGE);
return;
}
pCls = pCls->GetBaseClass();
}

gen->SetReturnObject(NULL);
}
void ASRegisterClassCastOp(asIScriptEngine* engine, const CTHString& SuperCls, const CTHString& DerivedCls)
{
int r = 0;
CTHString Decl;

Decl.Empty();
Decl << SuperCls << "@ f()";
r = engine->RegisterObjectBehaviour(DerivedCls.c_str(), asBEHAVE_IMPLICIT_REF_CAST, Decl.c_str(), asFUNCTION(ASClassDownCast), asCALL_GENERIC); assert( r >= 0 );

Decl.Empty();
Decl << DerivedCls << "@ f()";
r = engine->RegisterObjectBehaviour(SuperCls.c_str(), asBEHAVE_REF_CAST, Decl.c_str(), asFUNCTION(ASClassUpCast), asCALL_GENERIC); assert( r >= 0 );
}
[/code]
[/font]

[font="Arial"]I found that DownCast is more than 10x faster (I know it does little work). After code inspection i found that [/font][font="Arial"]GetReturnTypeId (or rather GetTypeIdFromDataType) does lots of things (some loops, creating new type id's etc). And the question now. Can return type id be somewhere cashed or how can I speed things up a bit here?[/font]
0

Share this post


Link to post
Share on other sites
Handles should be compared with [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_expressions.html#identity"]the[b][font="Courier New"] is[/font][/b] or [font="Courier New"][b]!is[/b][/font] operators[/url] in order to avoid doing value comparisons by mistake. With these operators you don't need to use the @ symbol.

The asEP_ALLOW_IMPLICIT_HANDLE_TYPES engine property is experimental. It allows you to declare script classes in a way so that all variables of that class will always be treated as handles. It's not documented, but you can find examples of it in [url="https://angelscript.svn.sourceforge.net/svnroot/angelscript/trunk/sdk/tests/test_feature/source/test_implicithandle.cpp"]test_implicithandle.cpp[/url].

Yes, you can cache the return type id, for example by mapping the function id to the return type id. An faster alternative would be to create a templated version of the ASClassUpCast function where the template variables specify the desired cast. The [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_class_hierarchy.html"]class hierarchies article in the manual[/url] can probably help you with that implementation.

Regards,
Andreas
0

Share this post


Link to post
Share on other sites
I somehow missed the purpose for "is" operator, if it is preferred way for handle comparison then I should rewrite my scripts.

I can't use template functions because I don't have any info about derived classes at compile time (they are declared in some config files and loaded when app starts).
Other than that, I use pretty much the same system (but, mine is limited to single parent inheritance only).

Anyway I found quick solution for my performance problem, using Set/GetUserData from asIScriptFunction.
[code]void ASClassUpCast(asIScriptGeneric* gen)
{
ITHEntity* pGE = static_cast(gen->GetObject());
if(pGE == NULL)
{
gen->SetReturnObject(NULL);
return;
}

int RetType = (int)gen->GetFunctionDescriptor()->GetUserData();

const ITHClass* pCls = pGE->GetClass();
while(pCls)
{
if(pCls->GetScriptType() == RetType)
{
gen->SetReturnObject(pGE);
return;
}
pCls = pCls->GetBaseClass();
}

gen->SetReturnObject(NULL);
}
void ASRegisterClassCastOp(asIScriptEngine* engine, const CTHString& SuperCls, const CTHString& DerivedCls)
{
int r = 0;
CTHString Decl;

Decl.Empty();
Decl << SuperCls << "@ f()";
r = engine->RegisterObjectBehaviour(DerivedCls.c_str(), asBEHAVE_IMPLICIT_REF_CAST, Decl.c_str(), asFUNCTION(ASClassDownCast), asCALL_GENERIC); assert( r >= 0 );

Decl.Empty();
Decl << DerivedCls << "@ f()";
r = engine->RegisterObjectBehaviour(SuperCls.c_str(), asBEHAVE_REF_CAST, Decl.c_str(), asFUNCTION(ASClassUpCast), asCALL_GENERIC); assert( r >= 0 );

asIScriptFunction* sf = engine->GetFunctionDescriptorById(r);
sf->SetUserData((void*)sf->GetReturnTypeId());
}[/code]



Some numbers to prove, 100000x loop, time in [ms] (before / now)
"empty loop" 5,5 / 5,5
downcast 38,1 / 38,1
upcast 619,2 / 41,9
So I reduced time for upcasting to an order of magnitude of calling simple function (which was my goal).



The way [color=#1C2837][size=2]asEP_ALLOW_IMPLICIT_HANDLE_TYPES works, looks promising, but it doesn't work for registered objects (I got -8 'invalid name' error) yet.[/size][/color]
[color=#1C2837][size=2]I'm not convinced with skipping @ at variable declaration though. How would you know what kind of assignment "=" is, if variable type gives no context?[/size][/color]
[color=#1C2837][size=2]Basicly I'm ok with "TypeName@ Var;" or even "TypeName@ Var1, Var2; //both are handles", but "@Var1 = Var2" looks very unintuitive for me and is source of 90% of my script errors (that's why I looked at [/size][/color][color=#1C2837][size=2]implicit handles in first place). Could you consider implementing [/size][/color][color=#1C2837][size=2]asEP_ALLOW_IMPLICIT_HANDLE_TYPES as 3-levels property? (like 0 - standard handles, 1 - @ dropped at assignments, 2 - @ dropped everywhere)[/size][/color]

0

Share this post


Link to post
Share on other sites
Heh, I forgot about the userdata on the function object. It was added for this very purpose but it slipped my mind.

With implicit handles the = operator would always be a handle assignment, which in turn means that there would not be any way of doing a value assignment, except through an explicit call to an method implemented for that purpose. This is the way Java works, and I'm seriously thinking about adopting it for AngelScript 3.0 (whenever I get that far), as it removes potential ambiguities in the code.

Since asEP_ALLOW_IMPLICIT_HANDLE_TYPES is experimental anyway I can certainly experiment some more. However, I don't know if I'll have time to do anytime soon. If you want to make the changes yourself though, I'll be happy to add them to the library.
0

Share this post


Link to post
Share on other sites
Implementing [color=#1C2837][size=2]asEP_ALLOW_IMPLICIT_HANDLE_TYPES was to complex for me (especially without knowledge of how parser and compiler work). Since I'm interested in dropping @ at handle assignments only, I created new engine property which forces that behavior for all reference types. (btw. script declared types are 'value' or 'reference'?)[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2](code sent via e-mail)[/size][/color]
0

Share this post


Link to post
Share on other sites
Script declared classes are always reference types.

I'll take a look at the code you sent me and incorporate it into the SVN as soon as possible. Thanks.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0