• 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

Passing large POD as reference

7 posts in this topic

Hi

Is there any method to pass POD arguments by reference without copying them around? (with safe references turned on)
This POD values have guaranteed life time, but limited to called script function only. Something similar to opaque pointer described in this topic: [url="http://www.gamedev.net/topic/611342-passing-an-opaque-pointer-to-angelscript/"]http://www.gamedev.n...to-angelscript/[/url]

For now I just registered it as reference type with dummy AddRef/Release, but this allows to store handle for use beyond scope.
Btw. why does AS reject "(const Type &in name)" declaration, with error: " Parameter type can't be 'const Type&' ", but accepts "(const Type &inout name)"? (my ver is 2.22.0 r1024)
0

Share this post


Link to post
Share on other sites
The tricky part is when you say the script must not store the pointer where it might survive beyond the call.

The only way this can be prevented is to disallow the script to store the pointer at all. The easiest way of doing it is to use the NOHANDLE flag when registering the type, then the script will only be able to access a reference given by the app but not pass it to around.

Another option could be to register the type as ordinary REF, but then add extra validation on the compilation to deny the scripts from declaring global variables or class members of that type.

I could add a flag to have the compiler verify this automatically, but I'm not sure how useful it is. Even without the flag it can quite easily be validated from the application after the compilation by enumerating class members and global variables.

Does that help?
1

Share this post


Link to post
Share on other sites
[quote name='behc' timestamp='1328104095' post='4908370']
Btw. why does AS reject "(const Type &in name)" declaration, with error: " Parameter type can't be 'const Type&' ", but accepts "(const Type &inout name)"? (my ver is 2.22.0 r1024)
[/quote]

This looks like a bug. Under which circumstance does it happen?
0

Share this post


Link to post
Share on other sites
I have tried NOHANDLE, but as I understand it works for global variables. My problematic PODs are temporary objects, created on thread memory pools, so I can't register them explicitly. Anyway your suggestion about post-compile validation is quite clever and simple in implementation, so I'll go that way. (It will be little more complicated with plug-in system, because engine does not know every registered type beforehand, but this can be solved, by attaching extra user info for registered types and building forbidden-type list each time module is compiled.)
Originally I was thinking about some run-time checks, that reset unwanted handles, but this would be over complicated (not to mention cpu time consuming).

As for possible bug. It happens with simple ref type being passed as const &in.
[code]LPCTHSTR IPC = "IContactList";
r = pScript->RegisterObjectType(IPC,0,asOBJ_REF); assert(r>=0);
r = pScript->RegisterObjectBehaviour(IPC, asBEHAVE_ADDREF, "void f()", asFUNCTION(dummy), asCALL_CDECL_OBJLAST); assert(r>=0);
r = pScript->RegisterObjectBehaviour(IPC, asBEHAVE_RELEASE, "void f()", asFUNCTION(dummy), asCALL_CDECL_OBJLAST); assert(r>=0);

r = pScript->RegisterObjectProperty(IPC, "vec3 AvgPos", offsetof(CN3EventCollide, AvgPos)); assert(r >= 0);
//and so on...[/code]

And in AS file:
[code]int OnCollide_plastic_concrete(CRigidBody@ pRB0, uint ShapeID0, CRigidBody@ pRB1, uint ShapeID1, const IContactList &in List) //error with &in but not &inout
{
return 0;
}[/code]
0

Share this post


Link to post
Share on other sites
This isn't a bug after all. The error message should just have been more explanatory.

The type is not allowed to be &in, because the type cannot be instanciated, which also means it cannot be copied.

Even though the function is declared to receive a reference, the &in means that the reference will only be used as input. The way AngelScript guarantees that the original value isn't accidentally modified by the function that said it would only use the value as input, is by making a copy and passing the reference to the copy instead.

I'll improve the error message for this.
0

Share this post


Link to post
Share on other sites
Thanks for info, I didn't know that rule also apply to reference types. Anyway, I discovered I can use standard "const Type& name" (skip the inout part) for this type, so it's ok. (inout with const looked a bit confusing)
0

Share this post


Link to post
Share on other sites
This is one of the reasons why I have future plans to change the syntax a bit, to make it less confusing.

type &in => type
type &out => out type or type out
type &inout => type &

There won't be any difference in passing by value or by &in. Behind the scenes the objects will always be passed by reference, and the primitives by value.

To the C++ application there won't be any difference, but in the script language it will be less confusion.

Regards,
Andreas
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