mirror of
https://github.com/SFML/SFML.git
synced 2025-01-31 13:45:13 +08:00
Improved VideoMode;
Fixed thread related bug in SoundStream. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1095 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
cb511644db
commit
a14719f1cd
@ -29,28 +29,39 @@
|
||||
|
||||
bool CustomSoundStream::OnStart()
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
bool result = false;
|
||||
gstate = PyGILState_Ensure();
|
||||
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
||||
{
|
||||
PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
|
||||
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||
result = PyBool_AsBool(Result);
|
||||
Py_DECREF(OnStart);
|
||||
Py_DECREF(Result);
|
||||
if (OnStart != NULL)
|
||||
{
|
||||
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||
if (Result != NULL)
|
||||
{
|
||||
result = PyBool_AsBool(Result);
|
||||
Py_CLEAR(Result);
|
||||
}
|
||||
Py_CLEAR(OnStart);
|
||||
}
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
PyGILState_Release(gstate);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
bool result = false;
|
||||
Py_CLEAR(PyData);
|
||||
PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
||||
PyObject *Function, *PyData;
|
||||
gstate = PyGILState_Ensure();
|
||||
Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
||||
if (Function != NULL)
|
||||
{
|
||||
PyData = PyObject_CallFunction(Function, NULL);
|
||||
@ -62,15 +73,16 @@ bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||
if (Data.NbSamples > 0)
|
||||
result = true;
|
||||
}
|
||||
Py_CLEAR(PyData);
|
||||
}
|
||||
Py_DECREF(Function);
|
||||
Py_CLEAR(Function);
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
Py_CLEAR(PyData);
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
PyGILState_Release(gstate);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -94,7 +106,6 @@ PySfSoundStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new CustomSoundStream();
|
||||
self->obj->PyData = NULL;
|
||||
self->obj->SoundStream = (PyObject *)self;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
|
@ -33,7 +33,6 @@ class CustomSoundStream : public sf::SoundStream
|
||||
{
|
||||
public :
|
||||
PyObject *SoundStream;
|
||||
PyObject *PyData;
|
||||
virtual bool OnStart();
|
||||
virtual bool OnGetData(Chunk& Data);
|
||||
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
|
@ -54,25 +54,16 @@ PySfVideoMode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
if (self != NULL)
|
||||
{
|
||||
self->BitsPerPixel = 32;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|I:VideoMode.__init__", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|I:VideoMode.__new__", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
|
||||
return NULL;
|
||||
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfVideoModeUpdate(PySfVideoMode *self)
|
||||
{
|
||||
self->obj->Width = self->Width;
|
||||
self->obj->Height = self->Height;
|
||||
self->obj->BitsPerPixel = self->BitsPerPixel;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_IsValid(PySfVideoMode* self)
|
||||
{
|
||||
PySfVideoModeUpdate(self);
|
||||
return PyBool_FromLong(self->obj->IsValid());
|
||||
}
|
||||
|
||||
@ -122,16 +113,37 @@ static PyMethodDef PySfVideoMode_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
int PySfVideoMode_Compare(PyObject *o1, PyObject *o2)
|
||||
PyObject *
|
||||
PySfVideoMode_richcompare(PyObject *o1, PyObject *o2, int op)
|
||||
{
|
||||
PySfVideoModeUpdate((PySfVideoMode *)o1);
|
||||
PySfVideoModeUpdate((PySfVideoMode *)o2);
|
||||
if (*(((PySfVideoMode *)o1)->obj) == *(((PySfVideoMode *)o2)->obj))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
if (*(((PySfVideoMode *)o1)->obj) == *(((PySfVideoMode *)o2)->obj))
|
||||
{
|
||||
if (op==Py_EQ)
|
||||
Py_RETURN_TRUE;
|
||||
if (op==Py_NE)
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (op==Py_EQ)
|
||||
Py_RETURN_FALSE;
|
||||
if (op==Py_NE)
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
PyErr_SetString(PyExc_TypeError, "VideoMode comparison : only == and != make sens.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
PySfVideoMode_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
int result = PyObject_GenericSetAttr(self, attr_name, v);
|
||||
PySfVideoMode *Mode = (PySfVideoMode *)self;
|
||||
Mode->obj->Width = Mode->Width;
|
||||
Mode->obj->Height = Mode->Height;
|
||||
Mode->obj->BitsPerPixel = Mode->BitsPerPixel;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PyTypeObject PySfVideoModeType = {
|
||||
head_init
|
||||
@ -142,7 +154,7 @@ PyTypeObject PySfVideoModeType = {
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
PySfVideoMode_Compare, /*tp_compare*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
@ -159,7 +171,7 @@ Default constructor : VideoMode()\n\
|
||||
Construct the video mode with its attributes : VideoMode(ModeWidth, ModeHeight, ModeBpp = 32)\n ModeWidth : Width in pixels\n ModeHeight : Height in pixels\n ModeBpp : Pixel depths in bits per pixel (32 by default)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
PySfVideoMode_richcompare, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
|
@ -37,9 +37,6 @@ typedef struct {
|
||||
sf::VideoMode *obj;
|
||||
} PySfVideoMode;
|
||||
|
||||
void
|
||||
PySfVideoModeUpdate(PySfVideoMode *self);
|
||||
|
||||
PySfVideoMode *
|
||||
GetNewPySfVideoMode();
|
||||
|
||||
|
@ -131,8 +131,7 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &Params))
|
||||
return NULL;
|
||||
|
||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
|
||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||
|
||||
if (Params)
|
||||
{
|
||||
|
@ -294,6 +294,8 @@ initsf(void)
|
||||
PySfSoundStream_InitConst();
|
||||
PySfString_InitConst();
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
#ifdef IS_PY3K
|
||||
return m;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user