Python、Pygame、Pyro:如何通过网络发送表面?
我正在使用 pygame 和pyro 在 python 中开发一个项目。我可以轻松发送数据、函数、类等。然而,我无法通过电线发送表面,而不会在运输过程中它在我身上死亡。
服务器在通过网络访问的类的 def __init__
中创建一个表面:
self.screen = pygame.display.set_mode(SCREENRECT.size, NOFRAME)
在服务器上,屏幕打印为 Surface(800x800x32 SW)
但当由客户端是Surface(Dead Display)
。
不过有一点需要注意。当我使用访问器函数获取屏幕时,我的屏幕显示死机。如果我使用 print Player.screen 来获取变量,我会得到似乎是指向屏幕的 Pyro 指针:
。也许我可以取消引用这个?
很可能是我太厚了,有人有见解吗?谢谢。 :)
I am working on a project in python using pygame and pyro. I can send data, functions, classes, and the like easily. However, I cannot send a surface across the wire without it dying on me in transit.
The server makes a surface in the def __init__
of the class being accessed across the wire:
self.screen = pygame.display.set_mode(SCREENRECT.size, NOFRAME)
On the server, the screen prints as Surface(800x800x32 SW)
but when retrieved by the client it is Surface(Dead Display)
.
Something to note though. I get a dead display when I use an accessor function to get my screen. If I use print Player.screen
to get the variable I instead get what seems to be a pyro pointer to the screen: <Pyro.core._RemoteMethod instance at 0x02B7B7B0>
. Maybe I can dereference this?
More than likely I am being thick, does anyone have some insight? Thanks. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
pygame Surface 是底层 SDL Surface 的包装器,我怀疑 Pyro 无法对其进行序列化。如果你想通过网络复制它的内容,你最好这样做:
访问底层像素。
编辑:
我只是觉得我把事情搞得太复杂了。要序列化 Surface,请使用 pygame.image.tostring(),并重新加载它,使用 pygame.image.fromstring( )。
A pygame Surface is a wrapper around an underlying SDL surface, which I suspect can't be serialized by Pyro. If you want to copy its contents across the wire, you would be better off doing something like this:
access to the underlying pixels.
Edit:
It just occurred to me that I'm overcomplicating it. To serialise your Surface, use pygame.image.tostring(), and to reload it, use pygame.image.fromstring().
一般来说,您不想通过网络发送 Surface(我假设 Surface 是设备相关的显示器)。大多数时候,您的客户端将负责管理其本地 Surface 上的绘图,而您的服务器负责告诉客户端需要绘制什么。服务器甚至可能没有能够显示图形的显示器!
Generally speaking, you don't want to send a Surface (I'm assuming that a Surface is a device-dependent display) across the network. Most of the time, your client will be responsible for managing the drawing on its local Surface, and your server is responsible for telling the client what it needs to draw. A server may not even have a display that's capable of showing graphics!
尝试酸洗对象并发送文件...
Try pickling the object and send the file...