How to pack types with variables in one message to send it to another thread? [tuple]

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 7 08:02:15 PDT 2014


You can also create new types:

struct UseSprite { string s;}
struct UseAnimation { string s;}


>> It's not a class instance, it's a class type. Something like
>> `cast(Sprite) null` in parameters. It can be replaced by string
>> "Sprite", but in this case I can't use receive() as it is. E.g.
>>
>> send(tid,gameobjectId,"Sprite","reload");
>> //must call sprite.reload();

You could use:

sent(tid, gameobjectId, UseSprite("reload"));

>> send(tid,gameobjectId,"Animation","reload");
>> //must call animation.reload();

sent(tid, gameobjectId, UseAnimation("reload"));

Another way, if you have way to determine that gameobjectId points to
an animation or a sprite, would be to define a struct name Reload {}
and then:

sent(tid, gameobjectId, Reload());



Third way: if Animation.reload() and Sprite.reload() are static methods:

send(tid, gameobjectId, &Sprite.reload);



>> But both messages are (int, string, string) so they can't be separate by
>> different receiving functions. It will be better if messages was (int,
>> Sprite, string) / (int, Animation, string). And it solves my problem. :)
>> But I don't know how to achieve this.

See my proposal: define your message as types, directly, and load them
for any data necessary for the call.
UseAnimation("reload"), or whatever.


More information about the Digitalmars-d-learn mailing list