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

passing class/function to asMETHOD

6 posts in this topic

hey all

 

I'm writing a thin wrapper for Angelscript for my game.

 

I'm a little unsure how to actually 'wrap' the asMETHOD macro.

 

I've got something like this so far:

 

 

 

void AngelScript::registerClass(Class classObject, std::vector<Method> methods)
{
registerObjectType(classObject.name.c_str(), 0, asOBJ_REF);
registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_FACTORY, classObject.factorySignature.c_str(), asFUNCTION(classObject.factoryPointer), asCALL_CDECL);
registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_ADDREF, "void f()", asMETHOD(classObject.pointer, classObject.addRefMethodPointer), asCALL_THISCALL);
registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_RELEASE, "void f()", asMETHOD(classObject.pointer, classObject.releaseRefMethodPointer), asCALL_THISCALL);


for ( Method m : methods)
{
registerMethod(classObject, m);
}
}
 

 

 
where Class and Method are defined as:
 

 

 struct Class {
std::string name;
std::string factorySignature;
void* pointer;
void* factoryPointer;
void* addRefMethodPointer;
void* releaseRefMethodPointer;
};


struct Method {
std::string name;
std::string signature;
void* pointer;
};
 

 

 
 
Unfortuantely, my compiler is giving me an error like this:

 

 src/common/as_wrapper/AngelScript.cpp: In member function ‘void as_wrapper::AngelScript::registerClass(as_wrapper::Class, std::vector<as_wrapper::Method>)’:
src/common/as_wrapper/AngelScript.cpp:100:160: error: template argument 1 is invalid
src/common/as_wrapper/AngelScript.cpp:101:165: error: template argument 1 is invalid
 

 

Where line 100 and 101 are these two lines:

 

 

...
registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_ADDREF, "void f()", asMETHOD(classObject.pointer, classObject.addRefMethodPointer), asCALL_THISCALL);
registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_RELEASE, "void f()", asMETHOD(classObject.pointer, classObject.releaseRefMethodPointer), asCALL_THISCALL);
...
 

 

 
I'm not sure how I would go about passing (whatever it is) I need to pass to the asMETHOD to get this sucker compiled.
 
Anyone have any ideas?
Edited by Chisser98
0

Share this post


Link to post
Share on other sites
asMETHOD is a macro, which means that it works on the actual text that it's passed at compile time. You can't try to pass the values of variables to macros; the macro will try to use the name of the variable instead of the value. However, the result of the asMETHOD macro is an asSFuncPtr, which you can store if you want. You can also manually create an asSFuncPtr from a pointer to member function, but there isn't really much point to that.
1

Share this post


Link to post
Share on other sites

Ok, I'm trying to actually figure out how to do it...How do you create a asSMethodPtr struct object without the Macro...?

 

I've got this:


 

auto methodPtr = asSMethodPtr<sizeof(void (classObject.pointer)())>::Convert((void (classObject.pointer)())(classObject.addRefMethodPointer));
 

 

(Where 'classObject' is a struct of type 'Class' (defined in my first post))

 

But it doesn't compile, I get:

 

 

 src/common/as_wrapper/AngelScript.cpp:98:66: error: void value not ignored as it ought to besrc/common/as_wrapper/AngelScript.cpp:98:68: error: template argument 1 is invalid
src/common/as_wrapper/AngelScript.cpp:98:107: error: void value not ignored as it ought to be
 

 

Any ideas?  I've afraid this asSMethodPtr struct is pushing the limits of my C++ abilities...

0

Share this post


Link to post
Share on other sites

You are just storing void* and expecting C++ to call correct function.

C++ can not call the correct function just with a void*.

 

There was a project called AngelBinder, google it.

What you want is doable, but require advanced c++ templates knowledge.

1

Share this post


Link to post
Share on other sites

Ah, right.  Thanks saejox, AngelBinder was a big help.

 

Well, I guess it's pretty clear by now that I have no idea what I'm doing:

i_have_no_idea_what_i_m_doing.jpg

 

 

So, after more researching, and asking around a little on stackoverflow, I have something compiling.

 

However, now I seem to be unable to create a asSMethodPtr object...

 

I define the following struct:

 

 

struct S
{
    int f()
    {
        return 5;
    }


    int x = 10;
};
 

 

and use it thusly:

 

 

 

 

asSMethodPtr pt = asSMethodPtr<sizeof( void (S::*)() )>::Convert( AS_METHOD_AMBIGUITY_CAST( int (S::*)()) (&S::f) );
 

 

However, I get the following compile time exception:

 

 

template_tests.cpp: In function ‘int main()’:
template_tests.cpp:64:15: error: missing template arguments before ‘pt’
template_tests.cpp:64:15: error: expected ‘;’ before ‘pt’
 
 
Any idea why in the world I get that?
 
 
If I try to add an integer in there as a template, like so:

 

asSMethodPtr<16> pt = asSMethodPtr<sizeof( void (S::*)() )>::Convert( AS_METHOD_AMBIGUITY_CAST( int (S::*)()) (&S::f) );
 

 

 
I get this error instead:
template_tests.cpp: In function ‘int main()’:
template_tests.cpp:66:120: error: conversion from ‘asSFuncPtr’ to non-scalar type ‘asSMethodPtr<16>’ requested
Edited by Chisser98
0

Share this post


Link to post
Share on other sites

asSFuncPtr and asMethodPtr are implemented in angelscript.h. The asMETHOD method instanciates the asMethodPtr template structure, and then call the method Convert() to return an asSFuncPtr.

 

I can understand you want to wrap the AngelScript library, but there is really no need to reimplement the code. Just take the code from angelscript.h and rename it to your liking rather than trying to implement it from zero. 

1

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