mirror of
https://github.com/SFML/SFML.git
synced 2025-01-31 21:55: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()
|
bool CustomSoundStream::OnStart()
|
||||||
{
|
{
|
||||||
|
PyGILState_STATE gstate;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
gstate = PyGILState_Ensure();
|
||||||
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
||||||
{
|
{
|
||||||
PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
|
PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
|
||||||
|
if (OnStart != NULL)
|
||||||
|
{
|
||||||
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||||
|
if (Result != NULL)
|
||||||
|
{
|
||||||
result = PyBool_AsBool(Result);
|
result = PyBool_AsBool(Result);
|
||||||
Py_DECREF(OnStart);
|
Py_CLEAR(Result);
|
||||||
Py_DECREF(Result);
|
}
|
||||||
|
Py_CLEAR(OnStart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
{
|
{
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
return false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
PyGILState_Release(gstate);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomSoundStream::OnGetData(Chunk& Data)
|
bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||||
{
|
{
|
||||||
|
PyGILState_STATE gstate;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
Py_CLEAR(PyData);
|
PyObject *Function, *PyData;
|
||||||
PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
gstate = PyGILState_Ensure();
|
||||||
|
Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
||||||
if (Function != NULL)
|
if (Function != NULL)
|
||||||
{
|
{
|
||||||
PyData = PyObject_CallFunction(Function, NULL);
|
PyData = PyObject_CallFunction(Function, NULL);
|
||||||
@ -62,15 +73,16 @@ bool CustomSoundStream::OnGetData(Chunk& Data)
|
|||||||
if (Data.NbSamples > 0)
|
if (Data.NbSamples > 0)
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
Py_CLEAR(PyData);
|
||||||
}
|
}
|
||||||
Py_DECREF(Function);
|
Py_CLEAR(Function);
|
||||||
}
|
}
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
{
|
{
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
Py_CLEAR(PyData);
|
result = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
PyGILState_Release(gstate);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +106,6 @@ PySfSoundStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
{
|
||||||
self->obj = new CustomSoundStream();
|
self->obj = new CustomSoundStream();
|
||||||
self->obj->PyData = NULL;
|
|
||||||
self->obj->SoundStream = (PyObject *)self;
|
self->obj->SoundStream = (PyObject *)self;
|
||||||
}
|
}
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
@ -33,7 +33,6 @@ class CustomSoundStream : public sf::SoundStream
|
|||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
PyObject *SoundStream;
|
PyObject *SoundStream;
|
||||||
PyObject *PyData;
|
|
||||||
virtual bool OnStart();
|
virtual bool OnStart();
|
||||||
virtual bool OnGetData(Chunk& Data);
|
virtual bool OnGetData(Chunk& Data);
|
||||||
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||||
|
@ -54,25 +54,16 @@ PySfVideoMode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
{
|
||||||
self->BitsPerPixel = 32;
|
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;
|
return NULL;
|
||||||
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
||||||
}
|
}
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
PySfVideoModeUpdate(PySfVideoMode *self)
|
|
||||||
{
|
|
||||||
self->obj->Width = self->Width;
|
|
||||||
self->obj->Height = self->Height;
|
|
||||||
self->obj->BitsPerPixel = self->BitsPerPixel;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfVideoMode_IsValid(PySfVideoMode* self)
|
PySfVideoMode_IsValid(PySfVideoMode* self)
|
||||||
{
|
{
|
||||||
PySfVideoModeUpdate(self);
|
|
||||||
return PyBool_FromLong(self->obj->IsValid());
|
return PyBool_FromLong(self->obj->IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,16 +113,37 @@ static PyMethodDef PySfVideoMode_methods[] = {
|
|||||||
{NULL} /* Sentinel */
|
{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))
|
if (*(((PySfVideoMode *)o1)->obj) == *(((PySfVideoMode *)o2)->obj))
|
||||||
return 0;
|
{
|
||||||
|
if (op==Py_EQ)
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
if (op==Py_NE)
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return 1;
|
{
|
||||||
|
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 = {
|
PyTypeObject PySfVideoModeType = {
|
||||||
head_init
|
head_init
|
||||||
@ -142,7 +154,7 @@ PyTypeObject PySfVideoModeType = {
|
|||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
PySfVideoMode_Compare, /*tp_compare*/
|
0, /*tp_compare*/
|
||||||
0, /*tp_repr*/
|
0, /*tp_repr*/
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
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 */
|
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_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
PySfVideoMode_richcompare, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
|
@ -37,9 +37,6 @@ typedef struct {
|
|||||||
sf::VideoMode *obj;
|
sf::VideoMode *obj;
|
||||||
} PySfVideoMode;
|
} PySfVideoMode;
|
||||||
|
|
||||||
void
|
|
||||||
PySfVideoModeUpdate(PySfVideoMode *self);
|
|
||||||
|
|
||||||
PySfVideoMode *
|
PySfVideoMode *
|
||||||
GetNewPySfVideoMode();
|
GetNewPySfVideoMode();
|
||||||
|
|
||||||
|
@ -132,7 +132,6 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||||
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
|
|
||||||
|
|
||||||
if (Params)
|
if (Params)
|
||||||
{
|
{
|
||||||
|
@ -294,6 +294,8 @@ initsf(void)
|
|||||||
PySfSoundStream_InitConst();
|
PySfSoundStream_InitConst();
|
||||||
PySfString_InitConst();
|
PySfString_InitConst();
|
||||||
|
|
||||||
|
PyEval_InitThreads();
|
||||||
|
|
||||||
#ifdef IS_PY3K
|
#ifdef IS_PY3K
|
||||||
return m;
|
return m;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user