Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am building a tutoring application that can be used to draw objects and then one is able to drag them around. I would like to know what is the best thing to do when someone clicks on an object and starts to drag it.

I was told I should "lock" it - prevent it from being grabbed by someone else at the same time and being able to drag it. But that would require sending a request to the server (and then to all other users connected to the tutoring session) to lock it which might take a bit of time (what if a teacher is in USA and student is in Africa on dialup)? I was also told I should loop until I see that the object was locked by me. This way, the user might not be able to grab and drag and object for several seconds (UX design problem).

I proposed perhaps to only enable one to drag object you drew, but that seems short sided. Any suggestions? Thank you!

share|improve this question
    
Have you considered an 'all or nothing' approach? One person has control over all the items and can relinquish all control or not? Unless it is a requirement of the system that multiple people be able to modify it at the same time. –  MichaelT Jan 2 '13 at 20:23
    
@MichaelT Unfortunately, there are no hard specifications. There is no customer, yet. The person in charge said he would like people to have control over all objects, but I can convince him of another strategy if the new one is better. Your solution would not allow users to interact with each other efficiently if they need to compare two objects or etc. –  jsn Jan 2 '13 at 20:26

1 Answer 1

The way a lot of online real time games deal with latency is to go ahead and perform an action locally, then correct it later when the authoritative result is given by the central server. In your case, you start dragging the object locally, sending a lock request to the server as soon as your drag starts, but acting as though you already own the lock. If the lock request succeeds, you carry on as normal. If someone else beat you to it, the local client ends the drag and gives control of the drag to the winning user until the lock is released. None of the other users will see your aborted drag attempt.

You'll have to decide for yourself if having someone "steal" your drag on rare occasions is more annoying or less than having to wait for a lock every single time. In my opinion, removing the delay in the most common case is the preferred solution.

share|improve this answer
    
But it seems we need some kind of queue then? What if the lock doesn't get to the server until after I let go? And then the unlock signal gets processed faster than the lock signal? Then the lock signal will get processed and lock if forever (unless I check if the lock is already owned by me). –  jsn Jan 2 '13 at 22:02
    
Yes, you need some way to guarantee the order of packets. –  Karl Bielefeldt Jan 2 '13 at 22:16
    
Jeez, this might be worth more trouble than it is worth. –  jsn Jan 2 '13 at 22:26
2  
You could also do the dragging entirely locally, only sending a message to the server for the 'drop' part. Obviously, this means that other users won't see your dragging, and if two people drag the same object at the same time, whoever drops second wins, but I can very well imagine this to be acceptable. –  tdammers Jan 3 '13 at 0:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.