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

Weird issue with drawing code

7 posts in this topic

Hello,

 

My angelscript programs have the ability to draw things on the screen using openGL. This works just fine usually, as the angelscript merely calls regular functions that wrap the openGL themselves.

 

For example, both the C++ and the angelscript have the ability to call void drawQuad(pos, size, color). However, in some builds it fails to work correctly. the exact same function when called from C++ always works and the result is on the screen, but if called from angelscript it fails to draw anything even though the script is executed.

 

Tested platforms:

Windows -> Generic calls -> works

Windows -> Native calls -> works

Android -> Generic calls -> works

Android -> Native calls -> fails

Linux -> Native calls -> fails

 

this is all the data I have so far... It is very weird, but i double-tested it and it is a reality. I can even call it three times: c++ then angelscript then c++, and only the first and last are effectively drawn.

 

If you have any idea of what this may be, i appreciate it.

 

EDIT: It seems to be another weird inexplicable bug with the registration of my Color type. I checked and when it comes from scripts, it comes with undefined behavior (always trash values). Must be some wicked issue with the copy constructor or something, i ll try to resolve it tomorrow and post about it then)

Edited by Grimshaw
0

Share this post


Link to post
Share on other sites

It is most likely something related to how you've registered your value types. When using native calling conventions it is very important to register the types correctly so that AngelScript will make pass the arguments to the functions exactly the way that the C++ function expects them.

 

I need to know the signature of the drawQuad function, the C++ declaration of each type involved and how you've registered them in order to help you further. Specifically the flags passed to the RegisterObjectType() have a significant chance of being the cause of the problem.

 

If you get the flags wrong, then AngelScript may attempt to push the value on the stack, where the C++ function expects to receive a reference, or vice versa. Specifically on Android and Linux there is also a high chance that C++ expects the value to be passed in the CPU registers, and if the flags are wrong AngelScript won't do that.

 

The following template function that I'm including in the next release may help in getting the correct flags:

 

#include <type_traits>
 
 
template<typename T>
asUINT GetTypeTraits()
{
  bool hasConstructor =  std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
  bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
  bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
  bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
  bool isFloat = std::is_floating_point<T>::value;
  bool isPrimitive = std::is_integral<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value;
 
  if( isFloat )
    return asOBJ_APP_FLOAT;
  if( isPrimitive )
    return asOBJ_APP_PRIMITIVE;
 
  asDWORD flags = asOBJ_APP_CLASS;
  if( hasConstructor )
    flags |= asOBJ_APP_CLASS_CONSTRUCTOR;
  if( hasDestructor )
    flags |= asOBJ_APP_CLASS_DESTRUCTOR;
  if( hasAssignmentOperator )
    flags |= asOBJ_APP_CLASS_ASSIGNMENT;
  if( hasCopyConstructor )
    flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR;
  return flags;
}

 

It will only work with compilers that support the C++11 standard, but even if your compiler doesn't support it I believe it will help you understand how the flags should be determined for the types.

0

Share this post


Link to post
Share on other sites

Okay, then here is all the steps involved:

 

The script function:

 

 

 

void onRender(Renderer@ renderer)
{
     Color c;
     c.r = 255;
     c.g = 200;
     c.b  = 100;
     //c.alpha is by default 255, so we should be able to see a shape nevertheless, but c.alpha is a trashed low value inside     drawDebugQuad(), which causes us not to see anything
     renderer.drawDebugQuad(200,200,0,200,200, c);
}
 

 

The relevant function drawDebugQuad:

 

 

 

r = asEngine->RegisterObjectMethod("Renderer", "void drawDebugQuad(float,float,float,float,float,Color)", asMETHOD(Renderer, drawDebugQuad), asCALL_THISCALL);

Signature: void Renderer::drawDebugQuad(float x, float y, float angle, float width, float height, Color color)
 

 

 

The relevant Color type:

 

 

 asEngine->RegisterObjectType("Color", sizeof(Color), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);
asEngine->RegisterObjectProperty("Color", "uint8 r", asOFFSET(Color, r));
asEngine->RegisterObjectProperty("Color", "uint8 g", asOFFSET(Color, g));
asEngine->RegisterObjectProperty("Color", "uint8 b", asOFFSET(Color, b));
asEngine->RegisterObjectProperty("Color", "uint8 a", asOFFSET(Color, a));
asEngine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ColorCTOR), asCALL_CDECL_OBJLAST);
asEngine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f(int, int, int)", asFUNCTION(ColorCTOR2), asCALL_CDECL_OBJLAST);
asEngine->RegisterObjectBehaviour("Color", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ColorDTOR), asCALL_CDECL_OBJLAST);
asEngine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f(const Color& in)", asFUNCTION(ObjectCopyConstructor<Color>), asCALL_CDECL_OBJLAST);
 

 

 

template<typename T>
void ObjectCopyConstructor(const T &in, void* address){
new(address) T(in);
}
 

 

 

 
Color class interface is simple:

 

Color();
Color(int byteRed, int byteGreen, int byteBlue, int byteAlpha = 255);
Uint8 r,g,b,a;

 

 

Also already tried using POD types to the same result. Im not sure whats wrong.

 

Note: If i register the Color type using generics it works as-is.

Edited by Grimshaw
0

Share this post


Link to post
Share on other sites
From what you're showing the color type should be registered with the flags asOBJ_APP_CLASS_C | asOBJ_APP_CLASS_ALLINTS

This definitely what is causing the error on andriod a linux.
0

Share this post


Link to post
Share on other sites

Thanks again Andreas! I was short on knowledge on this one..

 

So I only specify the asOBJ_APP_CLASS_* flags for members that I EXPLICITLY define? Or is it something else? Also, how important is that ALLINTS flag exactly? when do we not use it?

0

Share this post


Link to post
Share on other sites
Yes, that's the basic rule.

The asOBJ_APP_CLASS_ALLINTS is necessary on those platform where the value is passed in different cpu registers depending on the content of the class. Linux and Android are examples of such platforms.
0

Share this post


Link to post
Share on other sites

So, I will never need platform specific registration code as long as I use the right flags, right? Because it would simply be too much #ifdef linux , this way #ifdef windows another way #else generic calls..

 

But nevertheless, so far, so good! Thanks! This library must be one of the most incredible pieces of software I've seen! :)

0

Share this post


Link to post
Share on other sites
No you will not need any #ifdef in your code. The same flags can and should preferably be used on all platforms. The library will take care of the differences.
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