Compare commits
11 Commits
19890802a6
...
hans
| Author | SHA1 | Date | |
|---|---|---|---|
| 84a507da38 | |||
| 21a5e18e3b | |||
| 1b6007c323 | |||
| 6a05210aa1 | |||
| f13d50a9e1 | |||
| f65f4e3e55 | |||
| 3298623305 | |||
| f6adc18215 | |||
| 1b8d4e8c70 | |||
| 9d09b70bae | |||
| 49f45423d1 |
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@@ -1,17 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Launch",
|
||||
"program": "${workspaceFolder}/build/HansTheGatherer",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
assets/sounds/hit.raw
Normal file
BIN
assets/sounds/hit.raw
Normal file
Binary file not shown.
Binary file not shown.
BIN
assets/sounds/pickup.raw
Normal file
BIN
assets/sounds/pickup.raw
Normal file
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
115
src/assets.cpp
115
src/assets.cpp
@@ -20,104 +20,47 @@ static constexpr uint8_t BASKET_DATA[] = {
|
||||
};
|
||||
|
||||
static constexpr uint8_t BACKGROUND_MUSIC_DATA[] = {
|
||||
#embed "../assets/sounds/JamaicanSunrise.wav"
|
||||
#embed "../assets/sounds/JamaicanSunrise.raw"
|
||||
};
|
||||
|
||||
static constexpr uint8_t PICKUP_SOUND_DATA[] = {
|
||||
#embed "../assets/sounds/pickup.wav"
|
||||
#embed "../assets/sounds/pickup.raw"
|
||||
};
|
||||
|
||||
static constexpr uint8_t HIT_SOUND_DATA[] = {
|
||||
#embed "../assets/sounds/hit.wav"
|
||||
#embed "../assets/sounds/hit.raw"
|
||||
};
|
||||
|
||||
static constexpr uint8_t DEFAULT_FONT_DATA[] = {
|
||||
#embed "../assets/fonts/OpenTTD-Sans.ttf"
|
||||
};
|
||||
|
||||
// SDL_Texture* load_texture(uint8_t const* data, size_t size, SDL_Renderer* renderer)
|
||||
// {
|
||||
// auto* iostream = SDL_IOFromConstMem(data, size);
|
||||
// SDL_Surface* surface = SDL_LoadBMP_IO(iostream, false);
|
||||
// if (surface == nullptr)
|
||||
// {
|
||||
// // spdlog::error("Failed to load SDL surface!\nCause: {}", SDL_GetError());
|
||||
// }
|
||||
|
||||
// SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
// if (texture == nullptr)
|
||||
// {
|
||||
// // spdlog::error("Failed to create texture from surface!\nCause: {}", SDL_GetError());
|
||||
// }
|
||||
|
||||
// return texture;
|
||||
// }
|
||||
|
||||
// AudioAsset load_audio(uint8_t const* data, size_t size)
|
||||
// {
|
||||
// AudioAsset audio_asset;
|
||||
|
||||
// auto* iostream = SDL_IOFromConstMem(data, size);
|
||||
// bool res = SDL_LoadWAV_IO(
|
||||
// iostream, false, &audio_asset.spec, &audio_asset.buffer, &audio_asset.buffer_length);
|
||||
// if (!res)
|
||||
// {
|
||||
// // spdlog::error("Failed to load audio file!\nCause: {}", SDL_GetError());
|
||||
// }
|
||||
// return audio_asset;
|
||||
// }
|
||||
|
||||
// FontAsset load_font(uint8_t const* data, size_t size)
|
||||
// {
|
||||
// FontAsset font_asset;
|
||||
|
||||
// auto* iostream = SDL_IOFromConstMem(data, size);
|
||||
// auto* ttf = TTF_OpenFontIO(iostream, false, 20);
|
||||
|
||||
// font_asset.font = ttf;
|
||||
|
||||
// return font_asset;
|
||||
// }
|
||||
|
||||
AssetModule::AssetModule(entt::registry& registry)
|
||||
{
|
||||
// auto renderer = registry.ctx().get<SdlHandles>().renderer;
|
||||
TextureAtlasLayout background_layout{.width = 400, .height = 240, .rows = 1, .columns = 1};
|
||||
TextureAtlasLayout fruits_layout{.width = 32, .height = 32, .rows = 6, .columns = 38};
|
||||
TextureAtlasLayout spiders_layout{.width = 32, .height = 32, .rows = 2, .columns = 4};
|
||||
TextureAtlasLayout basket_layout{.width = 64, .height = 32, .rows = 1, .columns = 1};
|
||||
Texture background{.data = BACKGROUND_DATA,
|
||||
.data_length = sizeof(BACKGROUND_DATA),
|
||||
.texture_atlas_layout = background_layout};
|
||||
Texture fruits{.data = FRUITS_DATA,
|
||||
.data_length = sizeof(FRUITS_DATA),
|
||||
.texture_atlas_layout = fruits_layout};
|
||||
Texture spiders{.data = SPIDERS_DATA,
|
||||
.data_length = sizeof(SPIDERS_DATA),
|
||||
.texture_atlas_layout = spiders_layout};
|
||||
Texture basket{.data = BASKET_DATA,
|
||||
.data_length = sizeof(BASKET_DATA),
|
||||
.texture_atlas_layout = basket_layout};
|
||||
|
||||
// auto* background = load_texture(BACKGROUND_DATA, sizeof(BACKGROUND_DATA), renderer);
|
||||
TextureAtlasLayout background_layout = {.width = 400, .height = 240, .rows = 1, .columns = 1};
|
||||
registry.ctx().emplace<TextureAssets>(TextureAssets{
|
||||
.background = background, .fruits = fruits, .spiders = spiders, .basket = basket});
|
||||
|
||||
// auto* fruits = load_texture(FRUITS_DATA, sizeof(FRUITS_DATA), renderer);
|
||||
TextureAtlasLayout fruits_layout = {.width = 32, .height = 32, .rows = 6, .columns = 38};
|
||||
|
||||
// auto* spiders = load_texture(SPIDERS_DATA, sizeof(SPIDERS_DATA), renderer);
|
||||
TextureAtlasLayout spiders_layout = {.width = 32, .height = 32, .rows = 2, .columns = 4};
|
||||
|
||||
// auto* basket = load_texture(BASKET_DATA, sizeof(BASKET_DATA), renderer);
|
||||
TextureAtlasLayout basket_layout = {.width = 64, .height = 32, .rows = 1, .columns = 1};
|
||||
|
||||
// registry.ctx().emplace<TextureAssets>(TextureAssets{
|
||||
// .background = Texture{.sdl_texture = background, .texture_atlas_layout =
|
||||
// background_layout}, .fruits = Texture{.sdl_texture = fruits, .texture_atlas_layout =
|
||||
// fruits_layout}, .spiders = Texture{.sdl_texture = spiders, .texture_atlas_layout =
|
||||
// spiders_layout}, .basket = Texture{.sdl_texture = basket, .texture_atlas_layout =
|
||||
// basket_layout}});
|
||||
registry.ctx().emplace<TextureAssets>(
|
||||
TextureAssets{.background = Texture{.texture_atlas_layout = background_layout},
|
||||
.fruits = Texture{.texture_atlas_layout = fruits_layout},
|
||||
.spiders = Texture{.texture_atlas_layout = spiders_layout},
|
||||
.basket = Texture{.texture_atlas_layout = basket_layout}});
|
||||
|
||||
// auto background_music = load_audio(BACKGROUND_MUSIC_DATA, sizeof(BACKGROUND_MUSIC_DATA));
|
||||
// auto pickup_sound = load_audio(PICKUP_SOUND_DATA, sizeof(PICKUP_SOUND_DATA));
|
||||
// auto hit_sound = load_audio(HIT_SOUND_DATA, sizeof(HIT_SOUND_DATA));
|
||||
registry.ctx().emplace<AudioAssets>(AudioAssets{
|
||||
.background_music = {.buffer = BACKGROUND_MUSIC_DATA,
|
||||
.buffer_length = sizeof(BACKGROUND_MUSIC_DATA)},
|
||||
.pickup_sound = {.buffer = PICKUP_SOUND_DATA, .buffer_length = sizeof(PICKUP_SOUND_DATA)},
|
||||
.hit_sound = {.buffer = HIT_SOUND_DATA, .buffer_length = sizeof(HIT_SOUND_DATA)}});
|
||||
// registry.ctx().emplace<AudioAssets>(AudioAssets{.background_music = background_music,
|
||||
// .pickup_sound = pickup_sound,
|
||||
// .hit_sound = hit_sound});
|
||||
AudioAsset background_music{.buffer = BACKGROUND_MUSIC_DATA,
|
||||
.buffer_length = sizeof(BACKGROUND_MUSIC_DATA)};
|
||||
AudioAsset pickup_sound{.buffer = PICKUP_SOUND_DATA,
|
||||
.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 = 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});
|
||||
|
||||
@@ -14,7 +14,7 @@ struct TextureAtlasLayout
|
||||
|
||||
struct Texture
|
||||
{
|
||||
uint8_t* data;
|
||||
uint8_t const* data;
|
||||
uint32_t data_length;
|
||||
TextureAtlasLayout texture_atlas_layout;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
|
||||
enum Key : uint8_t
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
||||
struct ButtonInput
|
||||
{
|
||||
std::set<int> pressed;
|
||||
std::set<int> just_pressed;
|
||||
std::set<int> just_released;
|
||||
std::set<Key> pressed;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
#include "level.hpp"
|
||||
#include "input.hpp"
|
||||
|
||||
#include <Hall/Hall.h>
|
||||
|
||||
LevelModule::LevelModule(entt::registry& registry)
|
||||
{
|
||||
auto const* texture_assets = ®istry.ctx().get<TextureAssets>();
|
||||
auto const* audio_steams = ®istry.ctx().get<AudioStreams>();
|
||||
auto const* audio_assets = ®istry.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});
|
||||
|
||||
42
src/main.cpp
42
src/main.cpp
@@ -35,41 +35,17 @@ int main()
|
||||
bool exit_gameloop = false;
|
||||
while (!exit_gameloop)
|
||||
{
|
||||
auto* input = ®istry.ctx().get<ButtonInput>();
|
||||
|
||||
// Clear just pressed/released
|
||||
input->just_pressed.clear();
|
||||
input->just_released.clear();
|
||||
|
||||
// Input
|
||||
// SDL_Event event;
|
||||
// while (SDL_PollEvent(&event))
|
||||
// {
|
||||
// switch (event.type)
|
||||
// {
|
||||
// case SDL_EVENT_QUIT:
|
||||
// exit_gameloop = true;
|
||||
// break;
|
||||
// case SDL_EVENT_KEY_DOWN:
|
||||
// if (event.key.key == SDLK_ESCAPE)
|
||||
// {
|
||||
// exit_gameloop = true;
|
||||
// }
|
||||
// if (input->pressed.insert(event.key.key).second)
|
||||
// {
|
||||
// input->just_pressed.insert(event.key.key);
|
||||
// }
|
||||
// break;
|
||||
// case SDL_EVENT_KEY_UP:
|
||||
// if (input->pressed.erase(event.key.key) != 0)
|
||||
// {
|
||||
// input->just_released.insert(event.key.key);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
auto* input = ®istry.ctx().get<ButtonInput>();
|
||||
if (Hall::GetLeft(0))
|
||||
input->pressed.insert(Key::Left);
|
||||
else
|
||||
input->pressed.erase(Key::Left);
|
||||
|
||||
// AudioModule::FeedAudioStreams(registry);
|
||||
if (Hall::GetRight(0))
|
||||
input->pressed.insert(Key::Right);
|
||||
else
|
||||
input->pressed.erase(Key::Right);
|
||||
|
||||
if (registry.ctx().get<Game>().time != 0)
|
||||
{
|
||||
|
||||
@@ -20,13 +20,15 @@ void RenderModule::RenderSprites(entt::registry& registry)
|
||||
registry.view<Position const, Size const, Sprite const>(entt::exclude<Background>);
|
||||
auto background_view = registry.view<Position const, Size const, Sprite const, Background>();
|
||||
|
||||
auto render_sprite = [](entt::entity entity, Position const& pos, Size const& size, Sprite const&sprite){
|
||||
auto render_sprite =
|
||||
[](entt::entity entity, Position const& pos, Size const& size, Sprite const& sprite)
|
||||
{
|
||||
TextureAtlasLayout layout = sprite.texture->texture_atlas_layout;
|
||||
uint8_t row = sprite.texture_atlas_index / layout.columns;
|
||||
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*>(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,
|
||||
|
||||
Reference in New Issue
Block a user