Remove threading, not supported in WinRT

This commit is contained in:
Greentwip
2020-11-07 18:38:50 -07:00
parent acbf837756
commit 74c3192c9e
5 changed files with 47 additions and 14 deletions
+6 -5
View File
@@ -5,11 +5,11 @@
#include "Python.h"
#include "structmember.h" /* offsetof */
#ifndef WITH_THREAD
#error "Error! The rest of Python is not compiled with thread support."
#error "Rerun configure, adding a --with-threads option."
#error "Then run `make clean' followed by `make'."
#endif
#ifdef WITH_THREAD
//#error "Error! The rest of Python is not compiled with thread support."
//#error "Rerun configure, adding a --with-threads option."
//#error "Then run `make clean' followed by `make'."
#include "pythread.h"
@@ -1404,3 +1404,4 @@ PyInit__thread(void)
PyThread_init_thread();
return m;
}
#endif
+29 -3
View File
@@ -56,6 +56,20 @@ def load_image(file):
return surface.convert()
def load_sound(file):
""" because pygame can be be compiled without mixer.
"""
if not pg.mixer:
return None
file = os.path.join(main_dir, "data", file)
try:
sound = pg.mixer.Sound(file)
return sound
except pg.error:
print("Warning, unable to load, %s" % file)
return None
# Each type of game object gets an init and an update function.
# The update function is called once per frame, and it is when each object should
# change it's current position and state.
@@ -225,9 +239,12 @@ class Score(pg.sprite.Sprite):
def main(winstyle=0):
# Initialize pygame
if pg.get_sdl_version()[0] == 2:
pg.mixer.pre_init(44100, 32, 2, 1024)
pg.init()
pg.mixer = None
if pg.mixer and not pg.mixer.get_init():
print("Warning, no sound")
pg.mixer = None
fullscreen = False
# Set the display mode
@@ -259,6 +276,14 @@ def main(winstyle=0):
screen.blit(background, (0, 0))
pg.display.flip()
# load the sound effects
boom_sound = load_sound("boom.wav")
shoot_sound = load_sound("car_door.wav")
if pg.mixer:
music = os.path.join(main_dir, "data", "house_lo.wav")
pg.mixer.music.load(music)
pg.mixer.music.play(-1)
# Initialize Game Groups
aliens = pg.sprite.Group()
shots = pg.sprite.Group()
@@ -374,7 +399,8 @@ def main(winstyle=0):
# cap the framerate at 40fps. Also called 40HZ or 40 times per second.
clock.tick(40)
if pg.mixer:
pg.mixer.music.fadeout(1000)
pg.time.wait(1000)
pg.quit()
+8 -5
View File
@@ -99,6 +99,7 @@ public:
PyErr_Print();
}
/*PyEval_InitThreads();
metrosetup = PyImport_ImportModule("metrosetup");
@@ -110,13 +111,13 @@ public:
}
void deinitialize() {
PyGILState_STATE s = PyGILState_Ensure();
//PyGILState_STATE s = PyGILState_Ensure();
Py_Finalize();
}
PyObject* try_compile(const std::wstring& string_code)
{
PyGILState_STATE s = PyGILState_Ensure();
//PyGILState_STATE s = PyGILState_Ensure();
PyObject* code = PyObject_CallMethod(metrosetup, "compile", "u", string_code.c_str());
if (code == NULL) {
PyErr_Print();
@@ -126,13 +127,13 @@ public:
Py_DECREF(code);
}
PyGILState_Release(s);
//PyGILState_Release(s);
return code;
}
void run_code(PyObject* code)
{
PyGILState_STATE s = PyGILState_Ensure();
//PyGILState_STATE s = PyGILState_Ensure();
PyObject* result = PyObject_CallMethod(metrosetup, "eval", "O", code);
if (result == NULL) {
PyErr_Print();
@@ -141,7 +142,7 @@ public:
Py_DECREF(result);
}
Py_CLEAR(code);
PyGILState_Release(s);
//PyGILState_Release(s);
}
void run_string(const std::wstring& code) {
@@ -193,6 +194,8 @@ int main(int argc, char** argv)
//python_shell->run_string(L"import pygame");
python_shell->run_string(aliens_sample);
//PyEval_ReleaseThread(PyThreadState_Get());
python_shell->deinitialize();
Binary file not shown.
@@ -113,8 +113,9 @@ font = unbulk_dyn_load("font")
#font = unbulk_dyn_load_package_name("pygame.font", "pygame._freetype", "_freetype.pyd")
mixer = unbulk_dyn_load("mixer")
mixer_music = unbulk_dyn_load("mixer_music")
mixer = unbulk_dyn_load("mixer")
scrap = unbulk_dyn_load("scrap")
gfxdraw = unbulk_dyn_load("gfxdraw")
@@ -175,6 +176,8 @@ Vector3 = math.Vector3
import pygame.sprite
#import pygame.mixer
__version__ = ver