Sending a control signal?
I am working on making a client and a server with windows, c++
the design what I decided is
server is just sending what client have to render depends on client's sending message.
sort of tiles and objects, picture, line, rectangle, circle... could be drawn on client side
and a client just receive a command from server and render something
if server send a message like "draw picture.png srcX srcY width height destX destY". (picture.png is there on client side) then client just parse string and do what I want to.
but. I want to send a control signal as well
as like below "for(y = 0; y<30; y++){ for(x = 0; x<30; x++) { draw tile.png 0 0 16 16 x*16 y*16 }}"
I realize that sending a function is not a good idea (thanks for all replies.)
is there any good idea to solve this problem?
sending
"draw tile.png 0 0 16 16 0 0"
"draw tile.png 0 0 16 16 0 16"
"draw tile.png 0 0 16 16 0 32"
"draw tile.png 0 0 开发者_运维知识库16 16 0 48"
"draw tile.png 0 0 16 16 0 64"
"draw tile.png 0 0 16 16 0 96"
"draw tile.png 0 0 16 16 0 112"
"draw tile.png 0 0 16 16 0 128"
"draw tile.png 0 0 16 16 0 132"
...for 30*30 time would be overkill
I am searching for efficient way for sending a message "what client have to draw" drawing is not limited to just tile and object but it may contain drawing effect picture command on any coordinates.
thanks for reading.
Well, if you don't want to send and execute scripts, try to find some simple solution. For example, message format can be defined as:
draw file name srcX srcY width height destX destY [srcX srcY width height destX destY ...]
Some optimization may be applied, for example, you can pass only the difference between previous and current image:
draw tile.png 0 0 16 16 0 0 (5 16)
That means: increase member #5 of previous packet by 16.
I know this is quite primitive, but simple for implementation.
Define a language, implement the parser on the client and send the commands as pure text. You'll have to implement the reverse parser in the server to send optimized messages too.
精彩评论