Skip to content

Commit 5d9e53e

Browse files
authored
Merge pull request #30 from lr8soft/dev-y
v0.32_update2
2 parents 6d6ce3d + 735ceac commit 5d9e53e

15 files changed

Lines changed: 69 additions & 38 deletions

File tree

.idea/workspace.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PythonSTG/PythonSTG.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
8484
</ClCompile>
8585
<Link>
86-
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x86\OpenAL32.lib;..\libs\x86\python36.lib;..\libs\x86\python36_d.lib;..\libs\x86\python3.lib;%(AdditionalDependencies)</AdditionalDependencies>
86+
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x86\OpenAL32.lib;..\libs\x86\python36.lib;..\libs\x86\python36_d.lib;..\libs\x86\python3.lib;..\libs\x86\alut.lib;%(AdditionalDependencies)</AdditionalDependencies>
8787
</Link>
8888
</ItemDefinitionGroup>
8989
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -96,7 +96,7 @@
9696
<AdditionalIncludeDirectories>C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include;D:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9797
</ClCompile>
9898
<Link>
99-
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x64\OpenAL32.lib;..\libs\x64\python36_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
99+
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x64\OpenAL32.lib;..\libs\x64\python36_d.lib;..\libs\x64\alut.lib;%(AdditionalDependencies)</AdditionalDependencies>
100100
</Link>
101101
</ItemDefinitionGroup>
102102
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -112,7 +112,7 @@
112112
<Link>
113113
<EnableCOMDATFolding>true</EnableCOMDATFolding>
114114
<OptimizeReferences>true</OptimizeReferences>
115-
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x86\OpenAL32.lib;..\libs\x86\python36.lib;..\libs\x86\python3.lib;%(AdditionalDependencies)</AdditionalDependencies>
115+
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x86\OpenAL32.lib;..\libs\x86\python36.lib;..\libs\x86\python3.lib;..\libs\x86\alut.lib;%(AdditionalDependencies)</AdditionalDependencies>
116116
</Link>
117117
</ItemDefinitionGroup>
118118
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -131,7 +131,7 @@
131131
<Link>
132132
<EnableCOMDATFolding>true</EnableCOMDATFolding>
133133
<OptimizeReferences>true</OptimizeReferences>
134-
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x64\OpenAL32.lib;..\libs\x64\python36.lib;..\libs\x64\python36_d.lib;..\libs\x64\python3.lib;%(AdditionalDependencies)</AdditionalDependencies>
134+
<AdditionalDependencies>glfw3.lib;freetype.lib;..\libs\x64\OpenAL32.lib;..\libs\x64\python36.lib;..\libs\x64\python36_d.lib;..\libs\x64\python3.lib;..\libs\x64\alut.lib;%(AdditionalDependencies)</AdditionalDependencies>
135135
</Link>
136136
</ItemDefinitionGroup>
137137
<ItemGroup>

PythonSTG/XCCore/Stage/Stage.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ void Stage::stageInit()
4848
int taskSize = ScriptLoader::getSingleArg<int>(taskSizeObj);
4949
int bossSize = ScriptLoader::getSingleArg<int>(bossSizeObj);
5050

51-
const char* stageName;
52-
PyArg_ParseTuple(stageInfoObj, "sii", &stageName, &stageRank, &stageBackgroundID);
53-
51+
const char* stageName, *stageMusic;
52+
PyArg_ParseTuple(stageInfoObj, "siis", &stageName, &stageRank, &stageBackgroundID, &stageMusic);
53+
bgmBuffer = AudioHelper::loadWavByAlut(stageMusic);
54+
5455
if (taskSize > 0) {
5556

5657
for (int i = 0; i < taskSize; i++) {
@@ -79,6 +80,8 @@ void Stage::stageInit()
7980
stageBackground = BackgroundHelper::getBackgroundByID(stageBackgroundID);
8081
stageBackground->BackgroundInit();
8182
isStageInit = true;
83+
84+
8285
}
8386
}
8487

@@ -88,6 +91,7 @@ void Stage::stageWork()
8891
timer.Tick();
8992
bool allTaskWaitTarget = true;
9093
GameInfoInterface::getInstance()->setRank(stageRank);
94+
AudioHelper::playFromBuffer(bgmBuffer);
9195
for (auto task = stageTaskGroup.begin(); task != stageTaskGroup.end(); task++) {
9296
if (!task->second->getTaskInit())
9397
task->second->TaskInit();
@@ -121,14 +125,17 @@ void Stage::stageWork()
121125
stageTaskGroup.clear();
122126
}
123127
if (stageTaskGroup.empty()) {
128+
AudioHelper::stopByBuffer(bgmBuffer);
124129
stageFinish = true;
125130
}
126131
}
127132
}
128133

129134
void Stage::stageRelease()
130135
{
136+
alDeleteBuffers(1, &bgmBuffer);
131137
if (stageBackground != nullptr) {
138+
132139
stageBackground->BackgroundRelease();
133140
delete stageBackground;
134141
}

PythonSTG/XCCore/Stage/Stage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <list>
88
#include <map>
99
#include <atomic>
10+
#include "../XCAudio/AudioHelper.h"
1011
#include "../Task/Task.h"
1112
#include "../../util/GameTimer.h"
1213
#include "../Background/BackgroundHelper.h"
@@ -17,6 +18,7 @@ class Stage {
1718

1819
std::string stageUuid;
1920
std::map<std::string, Task*> stageTaskGroup;
21+
ALuint bgmBuffer = 0;
2022

2123
XCGameTimer timer;
2224
PyObject* itemStage;

PythonSTG/XCCore/XCAudio/AudioHelper.cpp

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22
#include <iostream>
33
#include <string>
44
#include <thread>
5+
#include <AL/alut.h>
56
bool AudioHelper::isEvonInit = false;
67
float AudioHelper::audioVolume = 0.08f;
7-
ALCdevice* AudioHelper::device = nullptr;
8-
ALCcontext* AudioHelper::context = nullptr;
8+
//ALCdevice* AudioHelper::device = nullptr;
9+
//ALCcontext* AudioHelper::context = nullptr;
910

1011
std::map<std::string, XCWavFile> AudioHelper::wavSourceGroup;
1112
std::map<ALuint, ALuint> AudioHelper::effectPlayingList;
1213

1314
void AudioHelper::EvonInit()
1415
{
1516
if (!isEvonInit) {
16-
device = alcOpenDevice(NULL);
17-
if (device==nullptr) {
18-
std::cout << "[ERROR]Failed to init openal device.\n";
19-
}
20-
else {
21-
ALCcontext* context = alcCreateContext(device, NULL);
22-
if (context == nullptr) {
23-
std::cout << "[ERROR]Failed to create openal context.\n";
24-
}
25-
else {
26-
alcMakeContextCurrent(context);
27-
std::cout << "[INFO]Now OpenAL environment init.\n";
28-
isEvonInit = true;
29-
}
30-
}
31-
alGetError(); //clear all error
17+
//device = alcOpenDevice(NULL);
18+
//if (device==nullptr) {
19+
// std::cout << "[ERROR]Failed to init openal device.\n";
20+
//}
21+
//else {
22+
// ALCcontext* context = alcCreateContext(device, NULL);
23+
// if (context == nullptr) {
24+
// std::cout << "[ERROR]Failed to create openal context.\n";
25+
// }
26+
// else {
27+
// alcMakeContextCurrent(context);
28+
// std::cout << "[INFO]Now OpenAL environment init.\n";
29+
// isEvonInit = true;
30+
// }
31+
//}
32+
//alGetError(); //clear all error
33+
alutInit(NULL, NULL);
3234
}
3335

3436
}
@@ -46,12 +48,13 @@ void AudioHelper::UnloadEvon()
4648
alDeleteSources(1, &work->second);
4749
}
4850

49-
alcMakeContextCurrent(NULL);
50-
alcDestroyContext(context);
51-
alcCloseDevice(device);
51+
//alcMakeContextCurrent(NULL);
52+
//alcDestroyContext(context);
53+
//alcCloseDevice(device);
5254

53-
context = nullptr;
54-
device = nullptr;
55+
//context = nullptr;
56+
//device = nullptr;
57+
alutExit();
5558

5659
std::cout << "[INFO]Now OpenAL environment unloaded.\n";
5760
isEvonInit = false;
@@ -77,6 +80,18 @@ XCWavFile AudioHelper::loadWavFromFile(const std::string& filename)
7780
return wavFile;
7881
}
7982

83+
ALuint AudioHelper::loadWavByAlut(const std::string & filename)
84+
{
85+
ALuint buffer = alutCreateBufferFromFile(filename.c_str());
86+
if (!alIsBuffer(buffer)) {
87+
std::cout << "[ERROR]Failed to load audio file " << filename << '\n';
88+
}
89+
else {
90+
std::cout << "[INFO] Load audio from file " << filename << std::endl;
91+
}
92+
return buffer;
93+
}
94+
8095
void AudioHelper::setVolume(float volume)
8196
{
8297
audioVolume = volume;

PythonSTG/XCCore/XCAudio/AudioHelper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct XCWavFile {
3939
class AudioHelper {
4040
private:
4141
static bool isEvonInit;
42-
static ALCdevice* device;
43-
static ALCcontext* context;
42+
//static ALCdevice* device;
43+
//static ALCcontext* context;
4444
static float audioVolume;
4545

4646
static std::map<std::string, XCWavFile> wavSourceGroup;
@@ -53,6 +53,7 @@ class AudioHelper {
5353
static void UnloadEvon();
5454

5555
static XCWavFile loadWavFromFile(const std::string& filename);
56+
static ALuint loadWavByAlut(const std::string& filename);
5657
static void setVolume(float volume);
5758

5859
static void playFromBuffer(ALuint buffer);

PythonSTG/XCCore/XCRender/RenderManager.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <chrono>
2+
#include <future>
13
#include "RenderManager.h"
24
#include "../../XCFrame.h"
35
#include <GL3/gl3w.h>
@@ -14,7 +16,6 @@ RenderManager* RenderManager::pRenderManager = nullptr;
1416
RenderManager::RenderManager() {
1517
auto coverInterface = CoverInterface::getInstance();
1618
AddUserInterface("0", coverInterface);
17-
1819
}
1920

2021

@@ -28,6 +29,7 @@ RenderManager * RenderManager::getInstance()
2829

2930
void RenderManager::AddRenderObject(const std::string& parentUuid, RenderObject * object, bool isAsyncio)
3031
{
32+
//addToInitList(parentUuid, object);
3133
if (!isAsyncio) {
3234
renderObjectList.insert(std::make_pair(parentUuid, object));
3335
object->Init();
@@ -239,10 +241,7 @@ void RenderManager::solveAsyncCommand()
239241
void RenderManager::solveAsyncObject()
240242
{
241243
if (asyncRenderObjectList.empty()) return;
242-
std::unordered_multimap<std::string, RenderObject*>::iterator obegin = asyncRenderObjectList.begin();
243-
std::unordered_multimap<std::string, RenderObject*>::iterator oend = asyncRenderObjectList.end();
244-
245-
for (auto object = obegin; object != oend; object++) {
244+
for (auto object = asyncRenderObjectList.begin(); object != asyncRenderObjectList.end(); object++) {
246245
renderObjectList.insert(std::make_pair(object->first, object->second));
247246
if (object->first == StrikeRenderGroupUuid) {
248247
strikeCollisionHelperGroup.push_back(object->second);

PythonSTG/alut.dll

-1 KB
Binary file not shown.

PythonSTG/assets/Media/stage1.wav

26.2 MB
Binary file not shown.

PythonSTG/script/Stage/XCStage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, stageName="Stage 0 No name"):
2626
self.__uuid = str(uuid.uuid1())
2727
self.__background = StageBackGround.lake
2828
self.__rank = StageRank.Normal
29+
self.__music = ""
2930

3031
def addTask(self, task):
3132
if isinstance(task, Task):
@@ -42,11 +43,14 @@ def addBoss(self, boss):
4243
def setBackGround(self, background):
4344
self.__background = background
4445

46+
def setBackGroundMusic(self, musicPath):
47+
self.__music = musicPath
48+
4549
def setStageRank(self, rank = StageRank.Normal):
4650
self.__rank = rank
4751

4852
def _cpp_getStageInfo(self):
49-
return self.__stageName, self.__rank.value, self.__background.value
53+
return self.__stageName, self.__rank.value, self.__background.value, self.__music
5054

5155
def _cpp_getTaskSize(self):
5256
return self.__stageTask.qsize()

0 commit comments

Comments
 (0)