mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Immediately stop music instead of taking 3 seconds, when exiting game or turning off music
This commit is contained in:
parent
65eee13695
commit
44173bb36e
@ -32,8 +32,11 @@ namespace OpenTK.Audio.OpenAL {
|
||||
public static extern void alSourcef(uint sid, ALSourcef param, float value);
|
||||
[DllImport(lib, CallingConvention = style)]
|
||||
public static extern void alGetSourcei(uint sid, ALGetSourcei param, int* value);
|
||||
|
||||
[DllImport(lib, CallingConvention = style)]
|
||||
public static extern void alSourcePlay(uint sid);
|
||||
[DllImport(lib, CallingConvention = style)]
|
||||
public static extern void alSourceStop(uint sid);
|
||||
|
||||
[DllImport(lib, CallingConvention = style)]
|
||||
public static extern void alSourceQueueBuffers(uint sid, int numEntries, uint* bids);
|
||||
|
@ -29,6 +29,8 @@ namespace SharpWave {
|
||||
public abstract void SetFormat(AudioFormat format);
|
||||
public abstract void BufferData(int index, AudioChunk chunk);
|
||||
public abstract void Play();
|
||||
public abstract void Stop();
|
||||
|
||||
public abstract bool IsCompleted(int index);
|
||||
public abstract bool IsFinished();
|
||||
|
||||
@ -90,6 +92,7 @@ namespace SharpWave {
|
||||
end = BufferBlock(next, tmp, secondSize, chunks);
|
||||
}
|
||||
|
||||
if (pendingStop) Stop();
|
||||
while (!IsFinished()) { Thread.Sleep(10); }
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,11 @@ namespace SharpWave {
|
||||
CheckError("SourcePlay");
|
||||
}
|
||||
|
||||
public override void Stop() {
|
||||
AL.alSourceStop(source);
|
||||
CheckError("SourceStop");
|
||||
}
|
||||
|
||||
void CheckError(string location) {
|
||||
ALError error = AL.alGetError();
|
||||
if (error == ALError.NoError) return;
|
||||
|
@ -8,13 +8,16 @@ namespace SharpWave {
|
||||
internal static class WinMM {
|
||||
const string lib = "winmm.dll";
|
||||
|
||||
[DllImport(lib, SetLastError = true)]
|
||||
internal static extern uint waveOutGetNumDevs();
|
||||
|
||||
[DllImport(lib, SetLastError = true)]
|
||||
internal static extern uint waveOutOpen(out IntPtr handle, IntPtr deviceID, ref WaveFormatEx format,
|
||||
IntPtr callback, UIntPtr callbackInstance, uint flags);
|
||||
[DllImport(lib, SetLastError = true)]
|
||||
internal static extern uint waveOutClose(IntPtr handle);
|
||||
internal static extern uint waveOutReset(IntPtr handle);
|
||||
[DllImport(lib, SetLastError = true)]
|
||||
internal static extern uint waveOutGetNumDevs();
|
||||
internal static extern uint waveOutClose(IntPtr handle);
|
||||
|
||||
[DllImport(lib, SetLastError = true)]
|
||||
internal static extern uint waveOutPrepareHeader(IntPtr handle, IntPtr header, int hdrSize);
|
||||
|
@ -99,6 +99,11 @@ namespace SharpWave {
|
||||
|
||||
public override void Play() { }
|
||||
|
||||
public override void Stop() {
|
||||
uint result = WinMM.waveOutReset(devHandle);
|
||||
CheckError(result, "Reset");
|
||||
}
|
||||
|
||||
void ApplyVolume(IntPtr handle, AudioChunk chunk) {
|
||||
if (volumePercent == 100) return;
|
||||
|
||||
|
@ -386,6 +386,7 @@ static ReturnCode Music_PlayOgg(struct Stream* source) {
|
||||
if (res) break;
|
||||
}
|
||||
|
||||
if (music_pendingStop) Audio_Stop(music_out);
|
||||
/* Wait until the buffers finished playing */
|
||||
while (!Audio_IsFinished(music_out)) { Thread_Sleep(10); }
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "ExtMath.h"
|
||||
#include "Block.h"
|
||||
#include "TerrainAtlas.h"
|
||||
#include "Block.h"
|
||||
|
||||
Real32 iso_scale;
|
||||
VertexP3fT2fC4b* iso_vertices;
|
||||
@ -14,10 +15,10 @@ GfxResourceID iso_vb;
|
||||
|
||||
bool iso_cacheInitalisesd;
|
||||
PackedCol iso_colNormal, iso_colXSide, iso_colZSide, iso_colYBottom;
|
||||
#define iso_cosX (0.86602540378443864f) /* Math_Cos(30.0 * MATH_DEG2RAD); */
|
||||
#define iso_sinX (0.50000000000000000f) /* Math_Sin(30.0 * MATH_DEG2RAD); */
|
||||
#define iso_cosY (0.70710678118654752f) /* Math_Cos(-45.0 * MATH_DEG2RAD); */
|
||||
#define iso_sinY (-0.70710678118654752f) /* Math_Sin(-45.0 * MATH_DEG2RAD); */
|
||||
#define iso_cosX (0.86602540378443864f) /* cos(30 * MATH_DEG2RAD) */
|
||||
#define iso_sinX (0.50000000000000000f) /* sin(30 * MATH_DEG2RAD) */
|
||||
#define iso_cosY (0.70710678118654752f) /* cos(-45 * MATH_DEG2RAD) */
|
||||
#define iso_sinY (-0.70710678118654752f) /* sin(-45 * MATH_DEG2RAD) */
|
||||
|
||||
struct Matrix iso_transform;
|
||||
Vector3 iso_pos;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef CC_ISOMETRICDRAWER_H
|
||||
#define CC_ISOMETRICDRAWER_H
|
||||
#include "VertexStructs.h"
|
||||
#include "Block.h"
|
||||
/* Draws 2D isometric blocks for the hotbar and inventory UIs.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
@ -1215,6 +1215,12 @@ void Audio_BufferData(AudioHandle handle, Int32 idx, void* data, UInt32 dataSize
|
||||
|
||||
void Audio_Play(AudioHandle handle) { }
|
||||
|
||||
void Audio_Stop(AudioHandle handle) {
|
||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
||||
ReturnCode result = waveOutReset(ctx->Handle);
|
||||
ErrorHandler_CheckOrFail(result, "Audio - resetting device");
|
||||
}
|
||||
|
||||
bool Audio_IsCompleted(AudioHandle handle, Int32 idx) {
|
||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
||||
WAVEHDR* hdr = &ctx->Headers[idx];
|
||||
@ -1379,6 +1385,12 @@ void Audio_Play(AudioHandle handle) {
|
||||
Audio_CheckError("SourcePlay");
|
||||
}
|
||||
|
||||
void Audio_Stop(AudioHandle handle) {
|
||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
||||
alSourceStop(ctx->Source);
|
||||
Audio_CheckError("SourceStop");
|
||||
}
|
||||
|
||||
void Audio_Free(AudioHandle handle) {
|
||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
||||
if (!ctx->Count) return;
|
||||
|
@ -119,6 +119,7 @@ struct AudioFormat* Audio_GetFormat(AudioHandle handle);
|
||||
void Audio_SetFormat(AudioHandle handle, struct AudioFormat* format);
|
||||
void Audio_BufferData(AudioHandle handle, Int32 idx, void* data, UInt32 dataSize);
|
||||
void Audio_Play(AudioHandle handle);
|
||||
void Audio_Stop(AudioHandle handle);
|
||||
bool Audio_IsCompleted(AudioHandle handle, Int32 idx);
|
||||
bool Audio_IsFinished(AudioHandle handle);
|
||||
#endif
|
||||
|
@ -64,8 +64,8 @@ int main(int argc, char** argv) {
|
||||
String args[PROGRAM_MAX_CMDARGS];
|
||||
Int32 argsCount = Platform_GetCommandLineArgs(argc, argv, args);
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
String rawArgs = String_FromConst("UnknownShadow200 fff 127.0.0.1 25565");
|
||||
argsCount = 4; String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
|
||||
// String rawArgs = String_FromConst("UnknownShadow200 fff 127.0.0.1 25565");
|
||||
// argsCount = 4; String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
|
||||
|
||||
if (argsCount == 0) {
|
||||
String name = String_FromConst("Singleplayer");
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "Game.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Bitmap.h"
|
||||
#include "Block.h"
|
||||
|
||||
#define WIDGET_UV(u1,v1, u2,v2) u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f
|
||||
static void Widget_NullFunc(void* widget) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user