android-developers
[Arriba] [Todas las Listas]

Re: [android-developers] Cuestión de diseño del juego: múltiple handl

To: android-developers@xxxxxxxxxxxxxxxx
Subject: Re: [android-developers] Cuestión de diseño del juego: múltiple handlers
From: Kostya Vasilyev <kmansoft@xxxxxxxxx>
Date: Wed, 30 Nov 2011 16:39:12 +0400
Delivery-date: Wed, 30 Nov 2011 07:39:41 -0500
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:mime-version:in-reply-to:references:date :message-id:subject:from:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=ZAKy710Z5aXXYZldWI5PmVQgr7983Pt2l+9pA4t0Jno=; b=Eti3GjIi8d5/TJptIvNXxR/C/fr7cDQDInuJoKgo3jh/PKhdNOMfxjAOH2HBXwJx4M h43FG/CwfvFuxtWxV3hUy6y2v/gvryp+fVHz2OTVzX8x3X/Vxs1AeiGCkMNCfjAZVbHI 7zyXul17HWUZWpqQGKjAxJDSP6MPSjm5e2oQg=
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <CAA_CB1KoNkpa-q0ga-DLdQrrQRQSKu7y5rZC6GyV2Z5b-2QFOQ@mail.gmail.com>
List-archive: <http://groups.google.com/group/android-developers?hl=en_US>
List-help: <http://groups.google.com/support/?hl=en_US>, <mailto:android-developers+help@googlegroups.com>
List-id: <android-developers.googlegroups.com>
List-post: <http://groups.google.com/group/android-developers/post?hl=en_US>, <mailto:android-developers@googlegroups.com>
List-subscribe: <http://groups.google.com/group/android-developers/subscribe?hl=en_US>, <mailto:android-developers+subscribe@googlegroups.com>
List-unsubscribe: <http://groups.google.com/group/android-developers/subscribe?hl=en_US>, <mailto:android-developers+unsubscribe@googlegroups.com>
Mailing-list: list android-developers@xxxxxxxxxxxxxxxx; contact android-developers+owners@xxxxxxxxxxxxxxxx
References: <CAA_CB1K07u3G6K=G=gf+RDeWRXy5qBA5iJd2JnrTL-Efq1046A@mail.gmail.com> <CANCScghHsHGMZwmdSXLm2yJr+ayeJPMe1-X5sYoUZBx6FSjp=g@mail.gmail.com> <CAA_CB1KoNkpa-q0ga-DLdQrrQRQSKu7y5rZC6GyV2Z5b-2QFOQ@mail.gmail.com>
Reply-to: android-developers@xxxxxxxxxxxxxxxx
Sender: android-developers@xxxxxxxxxxxxxxxx
El Mensaje tiene varios campos para cambiar la lógica en el recibiendo fin:

*int qué
Objeto *obj
*int *arg1
*int *arg2

*http://*developer.*android.*com/Referencia/*android/*os/Mensaje.*html

Así que podrías hacer a algo le gusta:

*void *handleMessage(Mensaje *msg)
#nom *int lo que = *msg.Qué;
cambio (qué)
#punt..
}
}

O incluso:

*void *handleMessage(Mensaje *msg)
#unknown{^*Runnable *r = (*Runnable) *msg.*obj;
*r.Carrera();
}

( o mismo con vuestra clase de base / de interfaz propia )

-- *Kostya

30 ноября 2011 г. 16:32 пользователь John *Goche
<*johngoche99@*xxxxxxxxxxxxxx>написал:

>
> *Thank tú *TreKing para vuestro consejo,
>
> Pero entonces en mi *handleMessage tendría que comprobar con si
>
> (*inst caso de *Foo)
>   *inst.*foocallback();
> Más si (*inst *instanceof Barra)
>   *inst.*barcallback();
> Más si (...)
>
> O es allí un *neater solución, quizás utilizando *polymorphism o un patrón
> de diseño de alguna clase
> de modo que mi *handleMessage  no deprisa vuelta a un desorden?
>
> *Thanks,
>
> John *Goche
>
>
>
> En *Tue, *Nov 29, 2011 en 11:02 PM, *TreKing <trekingapp@xxxxxxxxx> escribió:
>
>> En *Tue, *Nov 29, 2011 en 3:46 PM, John *Goche <*johngoche99@*xxxxxxxxxxxxxx>escribió:
>>
>>> El número de *sprites es indefinido (podría variar en número) pero cada cual
>>> necesita dirigir él individualmente. Arriba de esto el mundo tiene su
>>> propio *handler para dirigir actualiza a él.
>>>
>>
>> No necesitas separado *handlers, puedes pasar el caso del objeto
>> que está siendo actualizado en el *handler mensaje, entonces uso un solo *handler
>> para el hilo principal.
>>
>>
>> -------------------------------------------------------------------------------------------------
>> *TreKing <*http://Sitios.*google.*com/Sitio/*rezmobileapps/*treking> - *Chicago
>> *transit *tracking *app para *Android-*powered dispositivos
>>
>>  --
>> recibiste este mensaje porque eres *subscribed al *Google
>> Grupos "*Android *Developers" grupo.
>> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
>> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
>> 
>> Puesto que más opciones, visita este grupo en
>> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>
>
>  --
> Recibiste este mensaje porque eres *subscribed al *Google
> Grupos "*Android *Developers" grupo.
> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
> 
> Puesto que más opciones, visita este grupo en
> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>

-- 
Recibiste este mensaje porque eres *subscribed al *Google
Grupos "*Android *Developers" grupo.
A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx

Puesto que más opciones, visita este grupo en
*http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
Message has several fields for switching the logic on the receiving end:

int what
Object obj
int arg1
int arg2

http://developer.android.com/reference/android/os/Message.html

So you could do something like:

void handleMessage(Message msg) {
final int what = msg.what;
switch (what) {
...
}
}

Or even:

void handleMessage(Message msg) {
Runnable r = (Runnable) msg.obj;
r.run();
}

( or same with your own interface / base class )

-- Kostya

30 ноября 2011 г. 16:32 пользователь John Goche
<johngoche99@xxxxxxxxxxxxxx>написал:

>
> Thank you TreKing for your advice,
>
> But then in my handleMessage I would have to check with
>
> if (inst instance of Foo)
>   inst.foocallback();
> else if (inst instanceof Bar)
>   inst.barcallback();
> else if (...)
>
> or is there a neater solution, perhaps using polymorphism or a design
> pattern of some sort
> so that my handleMessage does not quickly turn into a mess?
>
> Thanks,
>
> John Goche
>
>
>
> On Tue, Nov 29, 2011 at 11:02 PM, TreKing <trekingapp@xxxxxxxxx> wrote:
>
>> On Tue, Nov 29, 2011 at 3:46 PM, John Goche <johngoche99@xxxxxxxxxxxxxx>wrote:
>>
>>> The number of sprites is indefinite (could vary in number) but each
>>> needs to manage itself individually. On top of this the world has its
>>> own handler to manage updates to itself.
>>>
>>
>> You don't need separate handlers, you can pass the instance of the object
>> that is being updated in the handler message, then use one single handler
>> for the main thread.
>>
>>
>> -------------------------------------------------------------------------------------------------
>> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
>> transit tracking app for Android-powered devices
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx
>> To unsubscribe from this group, send email to
>> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
android-developers+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
<Anterior por Tema] Tema Actual [Siguiente por Tema>