I've created a ContactListener and a sensor fixture in box2d and would like to get a contact callback in each step. My problem is that beginContact and endContact are obviously only called when a contact begins and ends but not as long as the contact persists. In these cases it is recommended to use preSolve or postSolve but these are not implemented for sensors.
How could I get a callback for contacts with a sensor in every step? Thanks in advance for any advice.
My approach is now to not using sensors but regular fixtures in this particular case and to call contact.setEnabled(false) in ContactListener.preSolve to avoid any physical reaction and simulate a sensor.
Related
I'm new to NATS and have read all the examples for:
https://nats.io/documentation/concepts/nats-messaging/
I'm in Microservciearchitecture where in microservice-Y (MSY) need to store some information published from other microservice-X (MSX) I have 2-10 instances of MSY so when changes are made in MSX and MSX-instance publishes event I want that only 1 instance of MSY should save information so not all of them save the same data.
I have read Request-Repy:
https://nats.io/documentation/concepts/nats-req-rep/
but there seems that all of instances receives message (and will handle it) even if it is point-to-point and reply is handled just for the one instance that is quickest to reply
Is this correct or have I missunderstood example?
If I only need that 1 instance of MSY should handle given message (store data in db) what can I do to acheve this?
Use queue groups. If you have multiple subscriptions on the same subject with the same queue group, only one of the members of the group will receive the message.
Check this out: https://nats.io/documentation/concepts/nats-queueing/
I am quite new to windows 8 phone and I don't know all the life cycle methods and when what is called.
My problem is the following: I have a page that loads some data from the disk and when the user exits the program ( or suspends ) the data should be saved. As far as I can tell Page doesn't have an OnSuspending method only someOnNavigatingFrom, but those are not called when you just exit the program. So I read that I should use the OnSuspending in my App.xaml.cs, but this class doesn't have this data and also shouldn't have it, maybe only for OnSuspending. But I don't know how to get the data from my page in the OnSuspending method.
The OnSuspending event is quite fragile and you cannot expect it to run and save the state for a long time. But it depends on how long it would take for you to save. It doesn't even get triggered when you hit the home key while closing the app. If you really want an easy way. Just register a background task. While your app is in the background, the state can be saved and when you open the app again things are in place.
There are certain constraints With Background task as well, you cant do heavy lifting etc...here's a link you could use.
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977056.aspx
Implement an observer pattern (i.e. pub/sub) for your view-models to subscribe to in the event that your app is being suspended.
Your app handles the suspended event. As a result, publish a message for your view-models to respond to within your app's method handler for the suspended event.
You can use an EventAggregator or MessageBus (that I wrote).
Thanks for your reply for my question: Is this a bug of Box API v2 when getting events
This is a new problem related to this. The problem is that I cannot reliably use the next_stream_position I got from previous calls to track events.
Given this scenario:
Given the following two GET HTTP queries:
1. GET https://api.box.com/2.0/events?stream_position=1336039062458
This one returns the JSON file which contains one file entry of myfile.pdf and the next stream position = 1336039062934
2. GET https://api.box.com/2.0/events?stream_position=1336039062934
This call uses the stream position I got from the first call. However, it returns the JSON contains the exactly same file entry of myfile.pdf with the first call.
I think if the first call gives a stream position, it should be used as a mark for that exact time (say: TIme A). If I use that stream position in subsequent queries, no events before "Time A" should be returned.
Is this a bug? Or did I use the API in the wrong way?
Many thanks.
Box’s /events endpoint is focused on delivering to you a highly reliable list of all the events relevant to your Box account. Events are registered against a time-sequenced list we call the stream_position. When you hit the /events API and pass in a stream_position we respond to you with the events that happened slightly before that stream position, up to the current stream_position, or the chunk_size, whichever is lesser. Due to timing lag and our preference to make sure you don’t miss some event, you may receive duplicate events when you call the /events API. You may also receive events that look like they are ‘before’ events that you’ve already received. Our philosophy is that it is better for you to know what has happened, than to be in the dark and miss something important.
Box events currently give you a window roughly 5 seconds into the past, so that you don't miss some event.
We have considered just delaying the events we send you by about 5 seconds and de-duplicating the events on our side, but at this point we've turned the dial more towards real-time. Let us know if you'd prefer a fully de-duped stream, that was slower.
For now, (in beta) if you write your client to check for duplicate events, and discard them, that will be best. We are about to add an event_id to the payload so you can de-duplicate on that. Until then, you'll have to look at a bunch of fields, depending on the event type... It's probably more challenging that it is worth.
In order to help you be able to figure out if an event is a duplicate, we have now added to each event an event_id that will be unique. It is our intention that the event_id will allow you to de-duplicate the responses you receive from subsequent GET /events calls.
You can see this reflected in the updated documentation here, including example payloads.
how to make a game tutorial as farmville game tutorial to teach the user to play the game. i have recently involve in make that kind of game tutorial for its user by actionscript 3, can anyone give me a guide to do it? any help is appreciated~
A common way to do this is similar to the "achievements system" many games employ, which utilises the a system similar to the Observer design pattern.
You'd set up a globally-accesible receiver object, with a function to receive a data packet of some sort.
Then, every function that should effect the tutorial info being shown would message this receiver object, and tell it of it's performed action.
So, say for instance, that you have a message box up to tell the player to "Chop down 10 trees".
You could then have a Receiver object with a function like TutorialMessage(var Action:String, var Parameter:object):void
When they perform the "Chop down tree" action, then end of the chopDownTree() function would contain a call to the receiver object's messaging function Receiver.TutorialMessage("TreeChoppedDown", 1) (ie, Chopped down 1 tree).
That receiver would then, essentially, run a massive switch case to determine the nature of the action, and interpret would to do based on your logic. In this case, it would add the value of Parameter to some counter variable, and when it reached 10, would display the next tutorial message.
I have a bot in node.js and I'm wondering what logic I should use for a .tell function. The purpose of the function will be to give a message to users who are offline. So, if john was offline on freenode.net/#foo and I typed .tell john your mother was great last night, I want the bot to store this message and display it whenever john joins the channel.
If john is already in the channel, I want the bot to immediately just display the message.
I am already using mongodb as a database to store information, so I can probably store all my messages in there. Here's the logic I had in mind so far:
1. After user A types .tell john your mother was great, a listener will pickup the pattern /\.tell ([\w-]+) (.*)/ and store a variable for the message ( var msg, the user who posted the message ( var from ), and the name of the user to be messaged ( var to ). I will also have a global variable signifying the channel name and network of the server.
2. I'll store a row in mongodb such as:
to from message network channel delivered time
--------------------------------------------------------------------------------
john meder your mother was great freenode.net #foobar 0 (TS)
last night
3. Setup a listener for anyone joining a channel since the bot can live in multiple channels under one network, and detect if there any messages that are not delivered and if there are, attempt to match the to and network and channel to the stored messages, and if row(s) are found, display them.
This sounds ok, but can anyone review it and maybe offer advice? I'll be forced to have a listener listen for anyone entering any channel, right? There's no alternative to that?
This seems all fine. I don't see how you could not have a listener.
One thing I'd add is maybe a hash in the bot to keep track of who has pending messages. This way you won't be querying MongoDB every time someone joins a channel.
I.e.
messages = {};
messages['freenode.net'] = {};
messages['freenode.net']['john'] = 1;
Might be overkill, but if your monitoring a channel that has many JOINs, you might find yourself querying MongoDB a lot.
My two cents.
Christian