# ZsjaWkaos

Member

12

171 Neutral

• Rank
Member
1. ## A Dream of breaking in as a developer - Looking to build a team

What are you going to bring to the table? You either need to be a valuable member yourself or fund the rest of the team. I'm just asking out of curiosity because you haven't shared any info about yourself.

4. ## How to get the number of solid tiles between two points?

[quote name='Scienthsine' timestamp='1348420467' post='4982969'] Now, as others have said, if your really just wanting 'the number of solid tiles between two points' and your counting the tiles in red in the photo, then it is just the greater of the absolute of the difference in Y or X. (As defined by the outer loop in the algorithm.) [/quote] This algorithm wouldn't account for any missing tiles. Although it would speed it up greatly. Perhaps a switch can be implemented for people using slower computers.
5. ## How to get the number of solid tiles between two points?

You can try to use [url="http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm"]Bresenham's line algorithm[/url]. Go from the source to the destination you can then count the number of solid tiles along the way.
6. ## Passing an Opaque Pointer to AngelScript

[quote name='WitchLord' timestamp='1317257416' post='4867020'] You don't have to modify the library to disable use of global variables. Just add a simple check after the compilation, e.g. [/quote] Neat! I'll check this out tomorrow, I didn't have time to code anything today. [quote name='WitchLord' timestamp='1317257416' post='4867020'] Why do you have to disallow the declaration of a local variable of the OP type? The script cannot assign an invalid value to it anyway. It would just initialize to null, which your code is hopefully treating anyway. [/quote] That would be great. Even if it's not checked at compile time it would be enough for me to use it. If I can get both techniques working like you described I'll be using AngelCode in my next project. Thanks for your patience and help.
7. ## Passing an Opaque Pointer to AngelScript

[quote name='WitchLord' timestamp='1317173348' post='4866658']For example it should be allowed to store the OP in a local variable, but not a global variable, it must not be possible to store the OP in a class member, unless the class itself is guaranteed to die after the function returns. I'm not sure how you expect AngelScript to control this.[/quote] A class with an OP shouldn't be stored globally. To make it easier I wouldn't mind simply disallowing all global variables (it's good design anyway) I think I can easily patch this in myself with the following code (in as_compiler.cpp, after line 6269): [code] if( found ){ Error( "ERROR: NO GLOBAL VARIABLES ALLOWED!", errNode ); return -1; } [/code] All state data between calls will then be stored outside of AS. This means that I'll be running a modified version of AS. I think making a better solution will require quite some work (disallowing classes with OPs to be stored in global variables) on your end and I don't want to deliver you any more work than necessary. Unfortunately, I'm still not sure how disallow the following AS code (any pointers willbe greatly appreciated): [code] void main() { SomeData some_data; some_function( some_data ); } [/code] While still allowing: [code] void main() { SomeData some_data = some_other_function(); } [/code] The "IsVariableInitialized" returned always "true" for the code I tested it with. I placed the following code right at the beginning/end of "asCCompiler::CompileVariableAccess" hoping that it would return false for the first case of "SomeData". [code] cout << " IsVariableInitialized" << name.AddressOf() << ", " << IsVariableInitialized( &ctx->type, errNode ) << endl; [/code] [quote name='WitchLord' timestamp='1317173348' post='4866658']Alternatively you can implement a proxy class [..] [/quote] This is an interesting alternative, I'll consider it. I'm not a big fan of runtime errors when they can be found at compile time. There is also a (small?) amount of additional overhead/complexity.
8. ## Passing an Opaque Pointer to AngelScript

Does this mean that passing a pointer around (as described in my first post) is an impossible thing to do in AS? Is there any chance that this can be added in a future release (I can take a look at it myself)?
9. ## Passing an Opaque Pointer to AngelScript

I've updated the C++ code as follows: [code] void zero_ptr( void* memory ){ cout << "zero_ptr" << endl; memory = 0; } /* ... */ r = engine->RegisterObjectType( "SomeData", sizeof( SomeData* ), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( "SomeData", asBEHAVE_CONSTRUCT, "void f( )", asFUNCTION( zero_ptr ), asCALL_CDECL_OBJLAST ); assert( r >= 0 ); [/code] The AS code (this should not be allowed!): [code] void main( SomeData some_data ){ SomeData sd = SomeData(); } [/code] Unfortunately "zero_ptr" seems to be called very often instead of only for the construction of SomeData. I would like to raise an exception on the construction (or assignment) of SomeData because that shouldn't be possible. EDIT: Apparently this is also possible : [code] void main( SomeData some_data ){ SomeData sd; } [/code]
10. ## Passing an Opaque Pointer to AngelScript

The code is now greatly simplified, I hope it is also correct. [code] class SomeData{ public: int x; int y; int z; }; void print_some_data( SomeData *some_data ){ cout << "SomeData! " << some_data << ", " << some_data->x << ", " << some_data->y << ", " << some_data->z << endl; } /* ... */ r = engine->RegisterObjectType( "SomeData", sizeof( SomeData* ), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS ); assert( r >= 0 ); [/code] Instead of "asOBJ_APP_CLASS" "asOBJ_APP_PRIMITIVE" also works. However, I'm not passing an AS primitive so I think this is the right way to do it. C++ pointer types are [url="http://stackoverflow.com/questions/146452/what-are-pod-types-in-c"]plain old data[/url] types and I'm passing by value so I think this code should be correct.
11. ## Passing an Opaque Pointer to AngelScript

[quote name='SiCrane' timestamp='1316870440' post='4865466'] Did you try just registering the pointer as a value type? [/quote] Thanks, I haven't thought of treating the OP as a value itself. Here is my current solution that seems to work: [code] class SomeData{ public: int x; int y; int z; }; void print_some_data( SomeData **some_data ){ cout << "SomeData! " << *some_data << ", " << (*some_data)->x << ", " << (*some_data)->y << ", " << (*some_data)->z << endl; } static void construct_ptr( void **ptr ){ } static void copy_construct_ptr( void **other, void **ptr ){ *ptr = *other; } static void destruct_ptr( void *ptr ){ } /* ... */ r = engine->RegisterObjectType( "SomeData", sizeof( SomeData* ), asOBJ_VALUE | asOBJ_APP_CLASS_C | asOBJ_APP_CLASS_DESTRUCTOR ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( "SomeData", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION( construct_ptr ), asCALL_CDECL_OBJLAST ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( "SomeData", asBEHAVE_CONSTRUCT, "void f( const SomeData &in )", asFUNCTION( copy_construct_ptr ), asCALL_CDECL_OBJLAST ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( "SomeData", asBEHAVE_DESTRUCT, "void f()", asFUNCTION( destruct_ptr ), asCALL_CDECL_OBJLAST ); assert( r >= 0 ); [/code] AS code is same as before. Interestingly it even does not allow the value to be assigned to a global variable (no copy constructor) but it does allow it to be passed around. The C++ is a bit more verbose than I hoped for because of the double pointer maybe that can be improved somehow. On the AS side everything looks exactly like I want.
12. ## Passing an Opaque Pointer to AngelScript

Here is what I would like to do: [list][*]pass an opaque pointer (OP) from C++ to a function written in AngelScript (AS)[*]not allow AS to keep a copy around after the function has returned[*]allow AS to pass OP around to other functions (either written in C++ and registered in AS or written in AS)[*]use different types for different OPs, AS must not be able to pass the wrong OP to a function![/list] The reasons for doing it this way are: [list][*]to decouple any data stored in the OP from AS as much as possible (AS must not have any knowledge about OP's implementation details)[*]to keep any interfacing with AS very basic and simple (no need for any "tricky" reference counting, just passing a pointer around)[*]to avoid overhead from garbage collecting (AS will only keep OP around for the duration of the function call)[/list] Here is my attempt but as I'm rather new to AS and after some trial and error I still didn't succeed (hence this post ). Code snippet for C++: [code] class SomeData{ public: void release(){ } }; void print_some_data( SomeData &some_data ){ cout << "SomeData!" << endl; } /* ... */ r = engine->RegisterObjectType( "SomeData", 0, asOBJ_REF | asOBJ_SCOPED ); assert( r >= 0 ); r = engine->RegisterGlobalFunction( "void print_some_data( const SomeData &in )", asFUNCTION( print_some_data ), asCALL_CDECL ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( "SomeData", asBEHAVE_RELEASE, "void f( )", asMETHOD( SomeData, release ), asCALL_THISCALL ); assert( r >= 0 ); [/code] Code for AS (test.as): [code] void main( SomeData some_data ){ print_some_data( some_data ); } [/code] I get the error. "test.as (1, 11) : ERR : Parameter type can't be 'SomeData'". I think it is because AS wants to create a new object SomeData but does not know how. However, I just want AS to keep the OP around and not do anything with it, except pass it to some functions. Is what I want to do possible in AS and if so [i]how[/i]? It seems like an incredibly simple thing to do yet I can't figure it out. Any help will be greatly appreciated!