Jump to content

  • Log In with Google      Sign In   
  • Create Account

Andreas Jonsson

Member Since 26 Mar 2000
Offline Last Active Today, 08:16 AM

#5198171 Casting value objects.

Posted by Andreas Jonsson on 14 December 2014 - 01:27 PM

Polymorphic value types is tricky in a "safe" language like AngelScript. In order to be able to send a value type by reference to a function AngelScript sometimes has to make a copy of the value type in order to guarantee that the reference will stay safe throughout the function call. When this is done on the base type, the data from the derived type is lost in the copy, which is probably why you see the object as empty.


With reference types AngelScript does not have to make the copy of the object, since the lifetime is guaranteed by the existing references, so here it is perfectly OK to use polymorphic types.


asOBJ_REF | asOBJ_NOCOUNT with no factory behaviour is a valid combination. asOBJ_NOCOUNT tells AngelScript that it is not necessary to count the references to the object, since the lifetime of the object is managed by the application. no factory behaviour tells AngelScript that no instances of the type can be created by the scripts, any instances that should be created has to be created by the application.




#5193033 Compiler warnings with latest stable version

Posted by Andreas Jonsson on 15 November 2014 - 05:09 PM

I've fixed the compiler warnings you mentioned in revision 2059. 

#5191978 Array trailing comma

Posted by Andreas Jonsson on 09 November 2014 - 08:30 PM

I've added the engine property asEP_DISALLOW_EMPTY_LIST_ELEMENTS in revision 2050. Set it to true to tell the compiler to give an error on empty elements (but ignore the last comma in lists with variable length).




#5190999 Unexpected behavior when registering a global property

Posted by Andreas Jonsson on 03 November 2014 - 03:26 PM

If your declaration is "Schedule @slIdleStand", i.e. you want the script to be able to reassign the handle to point to a different object, then the second argument must be a pointer to a pointer to a Schedule object, e.g. 


static Schedule *g_slIdleStandHandle = &slidleStand[0];  // Declared globally so the address of the variable is valid while the engine is valid
pEngine->RegisterGlobalProperty( "Schedule@ slIdleStand", &g_slIdleStandHandle );


Unfortunately there is no way for AngelScript to see the difference between one pointer to another, otherwise I would make AngelScript return an error if the property is registered incorrectly.

#5189006 Issue with implicit const qualifier on member handle vs object

Posted by Andreas Jonsson on 24 October 2014 - 06:29 PM

I've fixed this in revision 2026. Thanks.

#5188977 Issue with implicit const qualifier on member handle vs object

Posted by Andreas Jonsson on 24 October 2014 - 02:50 PM

This is clearly a bug in the AngelScript compiler. I'll have it fixed a.s.a.p.


Thanks for taking the time to create a small test for reproducing the problem. It will make it much faster to find and fix the cause.

#5188921 Relaxing script section is empty warning

Posted by Andreas Jonsson on 24 October 2014 - 09:37 AM

I'll look into this. Perhaps only warning about empty sections if all are empty might be better as you suggested.

The warning was added because there were a couple of developers that accidentally tried to compile empty sections and obviously the result wasn't what they expected. So rather than giving an error when the application couldn't find the expected function or class, which may not be too clear about why the function or class is missing, I felt it better to give a warning when the section was empty. smile.png

#5188658 odd behavior with globally declared scoped reference types, is this normal?

Posted by Andreas Jonsson on 22 October 2014 - 07:50 PM

It was indeed a bug in the library. I've fixed this in revision 2023.



Observe, that the new operator is not guaranteed to allocate the memory with the necessary alignment. I assume you're using a __m128 type in your vec class, thus you would need an alignment of 16 bytes. To get the proper alignment you need to use _aligned_malloc to allocate the memory and then the placement new operator to initialize it. The memory must then be freed with _aligned_free.

// Allocate memory with proper alignment then initialize it
r = engine->RegisterObjectBehaviour("vec", asBEHAVE_FACTORY, "vec @f()",  WRAPEXPR(vec*, (), new(_aligned_malloc(sizeof(vec), std::alignment_of<vec>().value)) vec()), asCALL_CDECL); assert(r >= 0);
// Manually call destructor then free the memory
r = engine->RegisterObjectBehaviour("vec", asBEHAVE_RELEASE, "void f()",  WRAPFUNC(void, (vec* t), {if(t) { t->~vec(); _aligned_free(t); }}), asCALL_CDECL_OBJLAST); assert(r >= 0);



#5188431 AngelScript 2.29.2 is out

Posted by Andreas Jonsson on 21 October 2014 - 07:17 PM

This incremental release brings a few minor improvements along with the usual batch of bug fixes.


Perhaps the most exciting new feature is the ability for script classes to implement type conversions, by including methods named opConv for explicit conversions or opImplConv implicit conversions. The compiler will find the correct overload to call by examining the return type, so even though these methods do not take any arguments it is still possible to allow classes to be converted to multiple different types.


The rest of the improvements are quite minor and should be transparent to the application developers.


I'd also like to take the opportunity to advertise the recently released AngelScript Add-on Template Library by Sami Vuorela. This library complements the standard add-ons in the SDK with 6 new templated container classes. If you feel the standard add-ons are a bit limited, then you should definitely take a look at these.




#5185872 BitmapFont - looking for atlas-packing-function

Posted by Andreas Jonsson on 08 October 2014 - 04:58 PM

I'm not sure if the algorithm that I use in BMFont is suitable for uv map packing. It works well for bitmap fonts since there is little variation between the sizes of each glyph, but when the sizes vary a lot the algorithm tend to leave a lot of unused space in the texture.


Anyway, the starting point for the packing algorithm I use is in the method CFontPage::AddCharsToPage that you'll find here: http://svn.code.sf.net/p/bmfont/code/trunk/source/fontpage.cpp.




#5185126 Array trailing comma

Posted by Andreas Jonsson on 05 October 2014 - 09:09 AM

I'll add an engine property to allow the application developer to decide how empty elements in initialization lists should be treated by the compiler. 




#5184200 ActiveContext for Context and Module Cleanup

Posted by Andreas Jonsson on 30 September 2014 - 08:02 PM

There is no use in providing a context to the asCModule::Discard or asCContext::Unprepare to do what you want, since there may still be objects that are not destroyed directly by these calls. If the objects are garbage collected they will only be destroyed when the garbage collector is certain that they are dead, which may not be immediately upon Discard or Unprepare.


However, with the release of 2.29.0 I implemented support for exactly what you need with the addition of SetContextCallbacks to the engine interface. Through these callbacks the application has the means to provide user data and initial settings even for script contexts used internally by the engine (for example to call the destructor during garbage collection). 


Not only will these callbacks be used when the engine internally needs a context, but the add-ons also request their contexts through the same callback by calling RequestContext on the engine and then return it with ReturnContext. Thus, by using these callbacks you can easily provide a single source of contexts with correct configuration for all executions.




#5183518 'is_trivially_default_constructible' is not a member of 'std'

Posted by Andreas Jonsson on 28 September 2014 - 12:55 PM

Try revision 2015. I've added a special case for gnuc 4.8 and later.




#5180090 Variable parameter type "?" to accept only handles during compile -...

Posted by Andreas Jonsson on 13 September 2014 - 11:26 AM

I've been thinking in similar lines. ?@ would be a nice way telling the compiler only to accept handles. Another option that I've thought about would be to have some callback so the application can decide at compile time whether the passed in type should be allowed or not. The latter would require more work by the application developer, but would provide exact control.




The problem with the constructor sounds like a bug in the library. I'll investigate it.

#5178142 Integer Division

Posted by Andreas Jonsson on 04 September 2014 - 02:18 PM

I think the use of an engine property to treat the result of / and /= as float/double would be acceptable, as long as the impact in the code is relatively isolated (which ought to be possible).


I don't see the need for an additional operator to force integer division in this case, as the user can explicitly convert the result to integer with int(expr) if desired. Explicit conversions would be more readable than have a backslash or double-slash as integer division in my opinion.