181
SFML projects / Cool Runnings...
« on: November 03, 2010, 07:49:42 am »
Apparently there's only a Windows release and no source code, so I can't try it.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
PySFML needs a lot of work to make it maintainable again. It should be redone using SWIG instead of direct Python ctypes.
This revisit is planned for SFML 2 and at least I am not going to rebuild SFML 1 from svn to fix this bug.
You should consider helping out with SWIG if you want a working PySFML 2.
Also sf::Image::SetSmooth() and sf::Image::Copy() are not working. This will be fixed with the next revision.
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(640, 480, 32), "Tile test");
app.SetFramerateLimit(10);
sf::Image image;
bool running = image.LoadFromFile("grass.png");
std::vector<sf::Sprite> sprites;
sf::Sprite s1(image);
s1.SetPosition(0, 0);
sprites.push_back(s1);
sf::Sprite s2(image);
s2.SetPosition(64, 0);
sprites.push_back(s2);
sf::Sprite s3(image);
s3.SetPosition(32, 15);
sprites.push_back(s3);
while (running)
{
sf::Event event;
while (app.GetEvent(event))
{
switch (event.Type)
{
case sf::Event::Closed:
running = false;
break;
default:
break;
}
}
app.Clear(sf::Color(255, 255, 255));
for (std::vector<sf::Sprite>::const_iterator it = sprites.begin();
it != sprites.end();
++it)
{
app.Draw(*it);
}
std::cout << 1.0 / app.GetFrameTime() << " FPS\n";
app.Display();
}
app.Close();
return EXIT_SUCCESS;
}
I made a test wrapping the Display call between python ALLOW_THREADS macros, but I don't have a very deep understanding on how the GIL works, and how extension modules can be safely threaded.
def __init__(self, path=None, buf=None):
if path is None and buf is None:
raise SomeException
if path is not None:
# ...
if buf is not None:
# ...
Image(path='/some/path')
Image(buf=[])
Image() # Raises an exception
class Image(object):
def __init__(self):
# don't do anything, or raise NotImplementedError to make it somewhat private
@staticmethod
def load_from_file(self, path):
# ...
@staticmethod
def load_from_memory(self, buf):
# ...