有没有办法使用真正的数据库(SQLite,Mysql,甚至一些非关系数据库)作为开发的数据存储,而不是提供的内存/文件数据存储.
我看到很少的项目,GAE-SQLite(似乎没有工作)以及关于使用远程api访问生产数据存储区的一个提示(对于大型数据集来说仍然相当慢).
我想为游戏存储不同对象的图形,它们的类可能相关也可能不相关,它们可能包含也可能不包含简单结构的向量.
通过序列化我的意思是,让对象自己序列化,这是有效的,但我需要为不同的对象编写不同的序列化方法.
通过二进制解析/组合我的意思是,创建一个新的解析器/组合器树,它保存和读取这些对象的数据,并传递它以让我的对象推/拉他们的数据.
我也可以使用json,但它的读取速度可能相当慢,而且当涉及到相当大的矩阵和数字时它的效果不是很大.
我正在尝试使用GLSL进行阴影映射.不幸的是,即使我有相当不错的深度缓冲精度,我的深度渲染结果也无法使用.它呈现像线框,下面的图像可能是一个更好的描述.
我还包括一个测试用例(包含着色器的单个文件),只有依赖是pyopengl.
# shadow mapping test
# utkualtinkaya at gmail
# shader is from http://www.fabiensanglard.net/shadowmapping/index.php
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import *
from OpenGL.GL.framebufferobjects import *
import math
class Camera:
def __init__(self):
self.rotx, self.roty = math.pi/4, math.pi/4
self.distance = 100
self.moving = False
self.ex, self.ey = 0, 0
self.size = (800, 600)
def load_matrices(self):
glViewport(0, 0, *self.size)
y = math.cos(self.roty) * self.distance
x = math.sin(self.roty) * math.cos(self.rotx) * self.distance
z = …
Run Code Online (Sandbox Code Playgroud) 遍历树数据结构的首选方法是什么,因为在某些情况下递归方法调用可能效率很低.我只是使用像上面那样的发电机.你有什么提示让它更快吗?
def children(self):
stack = [self.entities]
while stack:
for e in stack.pop():
yield e
if e.entities:
stack.append(e.entities)
Run Code Online (Sandbox Code Playgroud)
这是一些测试数据.第一个是递归的,第二个使用生成器:
s = time.time()
for i in range(100000):
e.inc_counter()
print time.time() - s
s = time.time()
for i in range(100000):
for e in e.children():
e.inc_counter_s()
print time.time() - s
Run Code Online (Sandbox Code Playgroud)
结果:
0.416000127792
0.298999786377
Run Code Online (Sandbox Code Playgroud)
测试代码:
import random
class Entity():
def __init__(self, name):
self.entities = []
self.name = name
self.counter = 1
self.depth = 0
def add_entity(self, e):
e.depth = self.depth + 1
self.entities.append(e)
def inc_counter_r(self): …
Run Code Online (Sandbox Code Playgroud) 要尽快关闭应用程序,我是否可以中断来自另一个线程的requests.post调用并立即终止连接?
我玩适配器,但到目前为止没有运气:
for ad in self.client.session.adapters.values():
ad.close()
Run Code Online (Sandbox Code Playgroud)