• 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
robiwan

Exposing arrays

6 posts in this topic

Hi, just starting to delve into AngelScript and I have a question: I need to expose several arrays in my C++ code to the scripting engine (with type and length), which is the best way to do that ?

TIA
/R
Btw. Is there a good search feature here on gamedev (that does not use google) ?
0

Share this post


Link to post
Share on other sites
if your array is std::vector you can register it and expose you vector as a global property i think.

check this thread
[url="http://www.gamedev.net/topic/583414-stdvector-registration/page__hl__%2Bstd+%2Bvector+%2Bregister"]http://www.gamedev.net/topic/583414-stdvector-registration/page__hl__%2Bstd+%2Bvector+%2Bregister[/url]

about search:
right top of this page, click on gray google button inside search field and select "This Forum".
it is very good
0

Share this post


Link to post
Share on other sites
Are you talking about static C++ arrays, e.g. int buffer[256]? Or std::vector type of arrays?

The std::vector type can be registered like mentioned in the post linked to by saejox.

The static C++ array can also be registered, but as it doesn't contain the length in a readily available form you'll probably want to implement a light wrapper to add the proper bounds checking.

If the array is a member of a class then it is probably easiest to [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_reg_objprop.html"]register a couple of property accessor methods[/url], rather than registering the type of the array itself.

How would you like the script to be able to access the array and its elements? Perhaps if you describe that it will be a bit easier for us to give more direct advice.

Regards,
Andreas
0

Share this post


Link to post
Share on other sites
Well actually I might have several C++ arrays (const double* that is) that I'd like to expose as properties to the script as:

[source lang="cpp"]double[] in0 = getInput(0);
uint in0Length = in0.length();

double[] in1 = getInput(1);
uint in1Length = in1.length();
[/source]
Then I'd also like to be able to create arrays as:

[source lang="cpp"]double[] out0 = createOutput(0);
out0.resize(512);

double[] out1 = createOutput(1);
out1.resize(512);

[/source]
:)
0

Share this post


Link to post
Share on other sites
[quote name='Andreas Jonsson' timestamp='1340293658' post='4951389']
How would you like the script to be able to access the array and its elements? Perhaps if you describe that it will be a bit easier for us to give more direct advice.
[/quote]
See the reply to my original post for one example of how to. Maybe even cleaner would be to have the C++ arrays registered as:

double[][] input;

but the getInput(arg) would suffice well.
0

Share this post


Link to post
Share on other sites
The const double * array can be exposed to AngelScript, but you need to figure out a way to get length() working. I mean, how can the method length() know the size the array? The index operator also needs to know the length so it can make sure the script won't do bad things.

I suggest a light wrapper, e.g.

[code]
class Array
{
const double *buffer;
unsigned int length;
double at(unsigned int index)
{
if( index >= length )
{
// Raise an exception to the script
asIScriptContext *ctx = asGetActiveContext();
if( ctx )
ctx->SetException("Out of bounds");
return 0;
}

// Return by value as the array shouldn't be modified by the script
return buffer[at];
}
}
[/code]

You can then register this light wrapper with the script engine. I suggest you give it a meaningful name, for example DataBuffer or something like that depending on what you'll use it for.

Are you planning on using the script array add-on in parallel, or will this be the only type of arrays supported in your app?
0

Share this post


Link to post
Share on other sites
[quote name='Andreas Jonsson' timestamp='1340466212' post='4952025']
I suggest a light wrapper, e.g.

[code]
class Array
{
const double *buffer;
unsigned int length;
double at(unsigned int index)
{
if( index >= length )
{
// Raise an exception to the script
asIScriptContext *ctx = asGetActiveContext();
if( ctx )
ctx->SetException("Out of bounds");
return 0;
}

// Return by value as the array shouldn't be modified by the script
return buffer[at];
}
}
[/code]

You can then register this light wrapper with the script engine. I suggest you give it a meaningful name, for example DataBuffer or something like that depending on what you'll use it for.

Are you planning on using the script array add-on in parallel, or will this be the only type of arrays supported in your app?
[/quote]

Ok, I was thinking along those lines aswell, thanx. It might be the only type of array supported, but I need to be able to create arrays as well, so I'll tinker around with the array add-on, see if I can combine some ideas with the one you gave above for a lightweight wrapper.
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