• 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
Jason Goepel

Finding matching Operators

5 posts in this topic

I have two classes registered with an implicit value cast:

engine->RegisterObjectBehaviour("TypeA", asBEHAVE_IMPLICIT_VALUE_CAST, "double f() const", ...);
engine->RegisterObjectBehaviour("TypeB", asBEHAVE_IMPLICIT_VALUE_CAST, "double f() const", ...);

The idea behind these classes is that the script writer may use them, in most cases, interchangeably with doubles.  Math operators, in particular, need to work.

TypeA x;
TypeB y;
double z;

z = x * y; 

However, asCCompiler::CompileOperator fails to find a matching operator.  I encountered the following comment in "as_compiler.cpp", line 10814:

// If both operands are objects, then we shouldn't continue
if( lctx->type.dataType.IsObject() && rctx->type.dataType.IsObject() )
{
    asCString str;
    str.Format(TXT_NO_MATCHING_OP_FOUND_FOR_TYPES_s_AND_s, lctx->type.dataType.Format().AddressOf(), rctx->type.dataType.Format().AddressOf());
    Error(str, node);
    ctx->type.SetDummy();
    return -1;
} 

Is there a reason we "shouldn't" continue?  It seems like if both the left and right types objects one could examine all implicit value casts and attempt to find an operator match for those.  Obviously, if one didn't limit the examination to primitive types that search could be infinite.  I was going to attempt such a search.  Do you have any thoughts or reservations?

 

In this particular case I could derive TypeA and TypeB from a "DoubleValue" class which would register all math operations in which I would be interested for the derived types.

 

I would like to clarify.  I am not insisting on this feature, I am just "thinking out loud".  I haven't given this a tremendous amount of thought, and my first impression is that there would be many complications that could arise from such a change. C++ does identify operators from casts though, so I suppose there shouldn't be any fundamental issues.

Edited by Jason Goepel
0

Share this post


Link to post
Share on other sites

I took a stab at it and found this change to give me what I want.  I search for implicit value casts to the same primitive type.  I don't think would work an the official implementation, but in general it captures what I am seeking.  What do you think?

0

Share this post


Link to post
Share on other sites

I think it would be a bit too drastic. What if someone wants to have the implicit cast but don't want the operators to work? It wouldn't be possible to disable the operators if the compiler automatically searches for a possible cast to primitives.

0

Share this post


Link to post
Share on other sites

You may be correct about it being too drastic, but I don't think it's quite as bad as you think.  C++ already allows this sort of thing.  This simple example compiles:

class ClassA
{
    short x;
public:
    ClassA(short a) : x(a) {}

    operator double() const { return (double)x; }
};

class ClassB
{
    int x;

public:
    ClassB(int b) : x(b) {}

    operator double() const { return (double)x; }
};

ClassA x(1);
ClassB y(2);

double z = x + y;

AngelScript already doesn't really allow one do disable operators if one has registered an implicit value cast.  Even though TypeA does not provide an opMul method, nor does it provide an implicit cast to an integer, the following will still compile and run:

TypeA x;

int y = x * 5;

It seems like once somebody has registered an implicit value cast, he can no longer expect to restrict any use where that type could be converted to value-cast type.  Registering an implicit value cast currently allows all the binary operators to work as long as the other type is a primitive type.

0

Share this post


Link to post
Share on other sites

I'll take this into consideration.

 

I've put this on my to-do list for a time when I can sit down for a while to think about the implications better.

 

Thanks,

Andreas

0

Share this post


Link to post
Share on other sites
i thinking about this when i use Vec3 and convert to string class.
 
r = en->RegisterObjectBehaviour("Vec3", asBEHAVE_IMPLICIT_VALUE_CAST, "string f()", asMETHOD(Vec3,ToString), asCALL_THISCALL ); nu_assert( r >= 0 );
this code work fine:

Vec3 my_vec;
string str = my_vec; ( Vec3 can convert to string )
But, this code wrong:
 
Vec3 vec;
string s1;
string s2 = s1 + vec3; // for this case be best if AS automaticly find variant when he can append to string
Edited by FDsagizi
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