Compare commits

...

2 Commits

Author SHA1 Message Date
21a5e18e3b (theoretically) Port audio system 2025-06-09 11:43:56 +02:00
1b6007c323 Reintroduce const correctness 2025-06-09 11:33:34 +02:00
8 changed files with 38 additions and 42 deletions

View File

@@ -16,7 +16,7 @@ namespace Hall
/// <param name="width">The width of the excerpt</param>
/// <param name="height">The height of the excerpt</param>
/// <param name="dataWidth">The width of the image (NOT EXCERPT)</param>
void Draw(unsigned short* data, unsigned short xOffset, unsigned short yOffset, unsigned short screenX, unsigned short screenY, unsigned short width, unsigned short height, unsigned short dataWidth);
void Draw(const unsigned short* data, unsigned short xOffset, unsigned short yOffset, unsigned short screenX, unsigned short screenY, unsigned short width, unsigned short height, unsigned short dataWidth);
/// <summary>
/// Clears the whole screen with the given color
@@ -24,7 +24,7 @@ namespace Hall
/// <param name="color">The format is R5G5B5A1, with the alpha bit being lsb</param>
void Clear(unsigned short color);
void SetData(unsigned short* data);
void SetData(const unsigned short* data);
void SetXOffset(unsigned short xOffset);
void SetYOffset(unsigned short yOffset);
void SetImageWidth(unsigned short imageWidth);

View File

@@ -1,7 +1,7 @@
#include <Hall/Video.h>
volatile char* GPU_START = (char*)0x02000000;
volatile unsigned short** GPU_IMAGE_START = (volatile unsigned short**)(GPU_START + 0);
volatile unsigned short const** GPU_IMAGE_START = (volatile unsigned short const**)(GPU_START + 0);
volatile unsigned short* GPU_IMAGE_X_OFFSET = (volatile unsigned short*)(GPU_START + 4);
volatile unsigned short* GPU_IMAGE_Y_OFFSET = (volatile unsigned short*)(GPU_START + 8);
volatile unsigned short* GPU_IMAGE_WIDTH = (volatile unsigned short*)(GPU_START + 12);
@@ -19,7 +19,7 @@ volatile bool* GPU_COMMAND_SWAP_BUFFERS = (volatile bool*)(GPU_START + 56);
volatile bool* VSYNC_BUFFER_SWAP = (volatile bool*)(GPU_START + 60);
void Hall::Draw(unsigned short* data, unsigned short xOffset, unsigned short yOffset, unsigned short screenX, unsigned short screenY, unsigned short width, unsigned short height, unsigned short dataWidth)
void Hall::Draw(const unsigned short* data, unsigned short xOffset, unsigned short yOffset, unsigned short screenX, unsigned short screenY, unsigned short width, unsigned short height, unsigned short dataWidth)
{
*GPU_IMAGE_START = data;
*GPU_IMAGE_X_OFFSET = xOffset;
@@ -39,7 +39,7 @@ void Hall::Clear(unsigned short color)
*GPU_COMMAND_CLEAR = true;
}
void Hall::SetData(unsigned short* data)
void Hall::SetData(const unsigned short* data)
{
*GPU_IMAGE_START = data;
}

View File

@@ -59,8 +59,8 @@ AssetModule::AssetModule(entt::registry& registry)
.buffer_length = sizeof(PICKUP_SOUND_DATA)};
AudioAsset hit_sound{.buffer = HIT_SOUND_DATA, .buffer_length = sizeof(HIT_SOUND_DATA)};
registry.ctx().emplace<AudioAssets>(AudioAssets{.background_music = background_music,
.pickup_sound =.buffer = pickup_sound,
.hit_sound =.buffer = hit_sound});
.pickup_sound = pickup_sound,
.hit_sound = hit_sound});
// auto font = load_font(DEFAULT_FONT_DATA, sizeof(DEFAULT_FONT_DATA));
// registry.ctx().emplace<FontAssets>(FontAssets{.default_font = font});

View File

@@ -3,29 +3,8 @@
AudioModule::AudioModule(entt::registry& registry)
{
// auto const& audio_assets = registry.ctx().get<AudioAssets>();
// auto* music_stream = SDL_OpenAudioDeviceStream(
// SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets.background_music.spec, NULL, NULL);
// auto* sound_stream = SDL_OpenAudioDeviceStream(
// SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets.pickup_sound.spec, NULL, NULL);
auto const& audio_assets = registry.ctx().get<AudioAssets>();
// SDL_ResumeAudioStreamDevice(music_stream);
// SDL_ResumeAudioStreamDevice(sound_stream);
// registry.ctx().emplace<AudioStreams>(
// AudioStreams{.music_stream = music_stream, .sound_stream = sound_stream});
registry.ctx().emplace<AudioStreams>(AudioStreams{.music_stream = {.id_left = 0, .id_right = 1},
.sound_stream = {.id_mono = 2}});
}
// void AudioModule::FeedAudioStreams(entt::registry& registry)
// {
// auto audio_streams = registry.ctx().get<AudioStreams>();
// auto audio_assets = registry.ctx().get<AudioAssets>();
// if (SDL_GetAudioStreamQueued(audio_streams.music_stream) <
// static_cast<int>(audio_assets.background_music.buffer_length))
// {
// SDL_PutAudioStreamData(audio_streams.music_stream,
// audio_assets.background_music.buffer,
// audio_assets.background_music.buffer_length);
// }
// }

View File

@@ -5,19 +5,28 @@
struct AudioAsset
{
// SDL_AudioSpec spec;
uint8_t const* buffer;
uint32_t buffer_length;
};
// struct AudioStreams
// {
// SDL_AudioStream* music_stream;
// SDL_AudioStream* sound_stream;
// };
struct MonoChannel
{
int id_mono;
};
struct StereoChannel
{
int id_left;
int id_right;
};
struct AudioStreams
{
StereoChannel music_stream;
MonoChannel sound_stream;
};
struct AudioModule
{
AudioModule(entt::registry& registry);
// static void FeedAudioStreams(entt::registry& registry);
};

View File

@@ -1,9 +1,20 @@
#include "level.hpp"
#include "input.hpp"
#include <Hall/Hall.h>
LevelModule::LevelModule(entt::registry& registry)
{
auto const* texture_assets = &registry.ctx().get<TextureAssets>();
auto const* audio_steams = &registry.ctx().get<AudioStreams>();
auto const* audio_assets = &registry.ctx().get<AudioAssets>();
// Hall::SetupStereo(audio_steams->music_stream.id_left,
// audio_steams->music_stream.id_right,
// audio_assets->background_music.buffer,
// audio_assets->background_music.buffer_length / (2 * 2),
// 0,
// audio_assets->background_music.buffer_length / (2 * 2));
auto background = registry.create();
registry.emplace<Position>(background, Position{.x = 0, .y = 0});

View File

@@ -69,8 +69,6 @@ int main()
// }
// }
// AudioModule::FeedAudioStreams(registry);
if (registry.ctx().get<Game>().time != 0)
{
increment_ticks(registry);

View File

@@ -28,8 +28,7 @@ void RenderModule::RenderSprites(entt::registry& registry)
uint8_t column = sprite.texture_atlas_index % layout.columns;
// Problemchen: Wir können die Sprites nicht strecken... hat keiner Interpolation
// implementiert?
Hall::Draw(reinterpret_cast<unsigned short*>(
const_cast<uint8_t*>(sprite.texture->data)), // Das ist 100% UB
Hall::Draw(reinterpret_cast<unsigned short const*>(sprite.texture->data), // Das ist 100% UB
column * layout.width,
row * layout.height,
pos.x,