创建协作白板绘图应用程序 [英] Creating collaborative whiteboard drawing application

查看:33
本文介绍了创建协作白板绘图应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自己的绘图程序,有各种绘图工具",如钢笔、橡皮擦、矩形、圆形、选择、文本等.

I have my own drawing program in place, with a variety of "drawing tools" such as Pen, Eraser, Rectangle, Circle, Select, Text etc.

它是用 Python 和 wxPython 制作的.上面提到的每个工具都是一个类,它们都有多态方法,例如left_down()、mouse_motion()、hit_test()等.程序管理一个所有绘制形状的列表——当用户绘制一个形状时,它被添加到列表中.这也用于管理撤消/重做操作.

It's made with Python and wxPython. Each tool mentioned above is a class, which all have polymorphic methods, such as left_down(), mouse_motion(), hit_test() etc. The program manages a list of all drawn shapes -- when a user has drawn a shape, it's added to the list. This is used to manage undo/redo operations too.

所以,我有一个不错的代码库,可以将协作绘图连接到其中.每个形状都可以更改以了解其所有者——绘制它的用户,并且只允许对一个人拥有的形状执行删除/移动/重新缩放操作.

So, I have a decent codebase that I can hook collaborative drawing into. Each shape could be changed to know its owner -- the user who drew it, and to only allow delete/move/rescale operations to be performed on shapes owned by one person.

我只是想知道开发它的最佳方式.会话"中的一个人将不得不充当服务器,我没有钱提供免费的中央服务器.不知何故,用户将需要一种连接到服务器的方法,这意味着某种发现服务器"浏览器......或其他东西.如何广播对应用程序所做的更改?实时绘制并在每个鼠标移动事件上广播消息在性能方面代价高昂,而且在给定时间内用户越多情况越糟.

I'm just wondering the best way to develop this. One person in the "session" will have to act as the server, I have no money to offer free central servers. Somehow users will need a way to connect to servers, meaning some kind of "discover servers" browser...or something. How do I broadcast changes made to the application? Drawing in realtime and broadcasting a message on each mouse motion event would be costly in terms of performance and things get worse the more users there are at a given time.

欢迎提出任何想法,我不太确定从哪里开始开发(甚至如何测试)

Any ideas are welcome, I'm not too sure where to begin with developing this (or even how to test it)

推荐答案

使任何实时协作工具/游戏都归结为在客户端之间的最小共享数据结构上有效地同步更改.是瓶颈.仅发送同步共享数据绝对需要的信息.通过存储形状而不是单个像素,您走在正确的轨道上.但是,这些形状不应处理鼠标事件.正如您所指出的,广播鼠标事件将很快使网络带宽饱和!相反,传递鼠标事件如何改变形状的增量.例如,在移动形状后发送最终位置 [x,y] 而不是发送 mouse_motion().

Making any real-time collaborative tool/game boils down to efficiently synchronizing changes on a minimal shared data structure between clients. Network bandwidth is the bottleneck. Send only information absolutely needed to synchronize the shared data. You are on the right track by storing shapes instead of individual pixels. However, the shapes should not handle mouse events. As you noted, broadcasting mouse events will quickly saturate the network bandwidth! Instead, pass deltas of how the shapes are altered by the mouse events. For example, instead of sending mouse_motion() send the final position [x,y] after a shape has been moved.

我建议将您的绘图程序拆分为服务器部分和客户端部分.服务器保留共享数据的权威版本.客户端从不直接操作共享数据结构;它只向服务器发送网络消息.当客户端和服务器都在同一个进程/PC 中时,这可能看起来很愚蠢,但有一些很好的理由:

I suggest splitting your drawing program into a server part and client part. The server keeps the authoritative version of the shared data. A client never manipulates the shared data structure directly; it only sends network messages to the server. This may seem silly when both the client and server are in the same process/PC, but there are some good reasons:

  1. 单用户和多用户的共享代码路径
  2. 使用本地套接字时,同一进程中客户端和服务器之间的网络开销几乎为零

此外,编辑不一定限于该形状的所有者.由于服务器是最终权威,因此当两个人同时抓取相同的形状并将结果发送回客户端时,它会解决任何冲突.(不过,撤消有点棘手.)

In addition, editing does not have to be limited to the owner of that shape. Since the server is the final authority, it resolves any conflicts when two people grab the same shape simultaneously and send the results back to the clients. (Undo gets a little tricky, though.)

虽然集中式服务器最适合网络发现,但客户端也可以使用其他方法来查找服务器:

  1. 发送或侦听网络广播数据包.
  2. 通过 IP 地址直接连接.(必须通过其他方式传达服务器 IP 地址:聊天、手机、在房间里大喊大叫、信鸽……)

最后,看看其他多用户应用程序是如何设计的.以下是一些示例:

  • Zoidcom Multi-player game programming libary (C++). Much of this answer is based on information from Zoidcom documentation. There are even sample programs that demonstrate server discovery via network broadcast.
  • Operational Transformation algorithm behind Wave, Google Docs. (article discussion on Hacker News)
  • Etherpad Open-source real-time collaborative text editor.
  • Source Multiplayer Networking Explains how an FPS like HAlf-life is designed. Gets into tricks for reducing lag/latency.
  • Google Wave (Apparently the documentation is stil pretty poor...)

这篇关于创建协作白板绘图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆