[gameprogrammer] Re: [ANNOUNCE] NewI\O Alpha Version 0.07 (Build 043)

  • From: Chris Nystrom <cnystrom@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Tue, 27 Sep 2005 23:54:45 -0500

On 9/27/05, Jake Briggs <jacob_briggs@xxxxxxxxxxxxxxx> wrote:
>
> Well maybe painful was to strong a word to use, you can notice the lag
> between when you, say, change colours, and quick mouse clicks seem to be
> ignored. I seem to have to hold down the button for a fraction of a
> second longer than I normally would in both the paint_demo and the
> mouse_test to register a click. These things are merely superficial
> though, this project is really cool!

This is actually good news. Latency may be causing the problem to show
up, but it is not the primary problem, it is the way I am handling the
mouse events. Before I explain what is wrong and how I can fix it, I
will answer your second part below.

> How about a brief overview of what happening behind the scenes sometime?
> I figure that the client is sending events to the server (mouse click,
> mouse movement, keyboard events) and that those events are basically SDL
> events, but what does the server send back? It cant be a bitmap of what
> to show, is it things like "put a red pixel at position foo", "put the
> character 'X' somewhere"?

Both the browser and the application are multithreaded so that the can
both communicate bi-directionally with messages. I originally used
RPC, and it worked but it was too slow, as a procedure queried the
other side, and then had to wait for the answer. As you can image, as
the distance got longer and longer the communication got slower and
slower.

So instead I use messages. Whenever either the client or server needs
to communicate it just sends a message and does not wait on an answer.
Not only that, but since it does not have to wait for an answer, it is
free to send the next message also, before the other side has even
gotten the first message.

The messages consist of an integer to indicate data length, and then
another integer to indicate messages number. Each event or message has
a distinct number. Once I know the message number, then I know what
data follows, which can be either more integers, or strings. Strings
consist of an integer length, and then the string itself. There is no
floating point as I have not needed that in any messages so far.

You are correct about the events. Each time there is an SDL keyboard
or mouse event it sends a message. It does not wait to be asked, it
just sends it when it happens. NIO_lib gets the messages and maintains
a state of the browser, so when you ask the API for a key or mouse
event, it queries the local state so it does not have to communicate
all the way back to the browser.

Display messages work the same way. The program running on the server
works through the logic and when it does I/O it sends a message to the
browser. You are correct in that there is no binary data. There are
only message to tell the browser what to do. That is why the resources
(sound, images, etc) are copied to the client browser. Once they are
there then I just send a message to play the sound, or draw the image,
etc.

Now what is happening above with the paint program is very simple.
Your mouse clicks are getting to the library on the server, but the
program is polling for the mouse state, and it is missing some of
them. This is the nio_mouse_state() procedure call. And, of course, it
misses some of the clicks because it is in a different part of the
program when you click.

I did create another procedure that solves this problem called
nio_mouse_click(). I used a circular buffer to collect the mouse
clicks, and so if you call it you will get the last click even if the
mouse is not actually clicked at that millisecond. It is used in other
programs and seems to work well.

However, I could not use this new function in the paint_demo program
because if only returns one click. You would not be able to hold down
the mouse button and drag it across the canvas and pick up all of the
pixels.

The information that I need is there at the library. I just need to
make my mouse API a little more capable, perhaps a large circular
buffer for both the mouse clicks and the mouse movement together.

Or I need to implement an event system in the API on the server.

Chris

--
E-Mail: Chris Nystrom <cnystrom@xxxxxxxxx>
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: