ResourceManager
This commit is contained in:
2
Dependencies/IACore
vendored
2
Dependencies/IACore
vendored
Submodule Dependencies/IACore updated: 89d9217b29...b2f276a491
2
Dependencies/IAMath
vendored
2
Dependencies/IAMath
vendored
Submodule Dependencies/IAMath updated: 536e9d0e58...77314b62b7
@ -1,6 +1,9 @@
|
||||
|
||||
set(IAESandbox_Sources
|
||||
imp/cpp/Main.cpp
|
||||
imp/cpp/Game.cpp
|
||||
imp/cpp/Map.cpp
|
||||
imp/cpp/Player.cpp
|
||||
)
|
||||
|
||||
add_executable(IAESandbox ${IAESandbox_Sources})
|
||||
|
||||
34
Src/IAESandbox/imp/cpp/Game.cpp
Normal file
34
Src/IAESandbox/imp/cpp/Game.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <Game.hpp>
|
||||
#include <Player.hpp>
|
||||
#include <Map.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
RefPtr<iae::Scene> scene;
|
||||
|
||||
VOID Game::Initialize()
|
||||
{
|
||||
const auto player = MakeRefPtr<Player>(m_engine);
|
||||
player->SetLocalPosition({200, 150, 0});
|
||||
|
||||
const auto map = MakeRefPtr<TiledMap>(m_engine);
|
||||
|
||||
scene = m_engine->CreateScene();
|
||||
scene->AddNode(map);
|
||||
scene->AddNode(player);
|
||||
|
||||
m_engine->ChangeScene(scene);
|
||||
|
||||
|
||||
}
|
||||
|
||||
VOID Game::Terminate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VOID Game::Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,118 +1,20 @@
|
||||
#include <IAEngine/Components/SoundEmitter.hpp>
|
||||
#include <IAEngine/Components/SpriteRenderer.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <Game.hpp>
|
||||
|
||||
#include <IAEngine/Audio.hpp>
|
||||
|
||||
#include <iacore/file.hpp>
|
||||
|
||||
namespace ia
|
||||
{
|
||||
SIZE_T Find(IN CONST Vector<UINT8> &vec, IN SIZE_T start)
|
||||
{
|
||||
UINT8 Sig[5] = {0x89, 0x50, 0x4E, 0x47, 0x0D};
|
||||
for (SIZE_T i = start; i < vec.size(); i++)
|
||||
{
|
||||
if (!memcmp(&vec[i], Sig, sizeof(Sig)))
|
||||
return i;
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
iae::Engine g_engine;
|
||||
|
||||
RefPtr<iae::Scene> scene;
|
||||
RefPtr<iae::Node> sprite;
|
||||
|
||||
VOID InitializeGame()
|
||||
{
|
||||
auto s = iae::Audio::CreateSound(File::ReadToVector("Res/Audio/SFX/gunshot.wav"));
|
||||
s.LoopTimes() = 0;
|
||||
|
||||
sprite = MakeRefPtr<iae::Node>();
|
||||
const auto spriteRenderer = sprite->AddComponent<iae::SpriteRendererComponent>();
|
||||
|
||||
{
|
||||
const auto data = File::ReadToVector("Res/Graphics/iae/010_1.iae");
|
||||
IA_RELEASE_ASSERT(!memcmp(&data[0], "iae.", 4));
|
||||
const auto frameCount = *reinterpret_cast<CONST UINT32 *>(&data[6]);
|
||||
INT32 off = 10;
|
||||
for (INT32 i = 0; i < frameCount; i++)
|
||||
{
|
||||
const auto t = g_engine.CreateTexture(&data[off], data.size() - off);
|
||||
spriteRenderer->AddTexture(t);
|
||||
off = Find(data, off + 1);
|
||||
if (off == SIZE_MAX)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iae::SpriteRendererComponent::Animation anim;
|
||||
anim.ShouldLoop = false;
|
||||
|
||||
anim.Keys.pushBack(
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame{.Duration = 500,
|
||||
.ColorOverlay = iam::Vec4f{0.25f, 0.0f, 0.0f, 1.0f},
|
||||
.ShouldInterpolate = true,
|
||||
.TextureHandle = 0});
|
||||
anim.Keys.pushBack(
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame{.Duration = 500,
|
||||
.ColorOverlay = iam::Vec4f{0.5f, 0.0f, 0.0f, 1.0f},
|
||||
.ShouldInterpolate = true,
|
||||
.TextureHandle = 1});
|
||||
anim.Keys.pushBack(
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame{.Duration = 500,
|
||||
.ColorOverlay = iam::Vec4f{0.75f, 0.0f, 0.0f, 1.0f},
|
||||
.ShouldInterpolate = true,
|
||||
.TextureHandle = 2});
|
||||
anim.Keys.pushBack(
|
||||
iae::SpriteRendererComponent::AnimationKeyFrame{.Duration = 500,
|
||||
.ColorOverlay = iam::Vec4f{1.0f, 0.0f, 0.0f, 1.0f},
|
||||
.ShouldInterpolate = true,
|
||||
.TextureHandle = 3});
|
||||
|
||||
spriteRenderer->AddAnimation(anim);
|
||||
|
||||
spriteRenderer->BakeAnimations();
|
||||
|
||||
// const auto soundEmitter = sprite->AddComponent<iae::SoundEmitterComponent>();
|
||||
// soundEmitter->SetSound(s);
|
||||
|
||||
sprite->SetLocalPosition({100, 100, 0});
|
||||
|
||||
scene = g_engine.CreateScene();
|
||||
scene->AddNode(sprite);
|
||||
|
||||
g_engine.ChangeScene(scene);
|
||||
}
|
||||
|
||||
VOID UpdateGame()
|
||||
{
|
||||
}
|
||||
|
||||
VOID TerminateGame()
|
||||
{
|
||||
}
|
||||
} // namespace ia
|
||||
ia::iae::Engine g_engine;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ia::g_engine.Initialize({.GameName = "IAE Sandbox", .WindowWidth = 800, .WindowHeight = 600});
|
||||
|
||||
ia::InitializeGame();
|
||||
|
||||
while (!ia::g_engine.ShouldClose())
|
||||
g_engine.Initialize({.GameName = "IAE Sandbox", .WindowWidth = 800, .WindowHeight = 600});
|
||||
const auto game = new ia::iae::game::Game(&g_engine);
|
||||
game->Initialize();
|
||||
while (!g_engine.ShouldClose())
|
||||
{
|
||||
ia::g_engine.BeginFrame();
|
||||
|
||||
ia::UpdateGame();
|
||||
|
||||
ia::g_engine.EndFrame();
|
||||
g_engine.BeginFrame();
|
||||
game->Update();
|
||||
g_engine.EndFrame();
|
||||
}
|
||||
|
||||
ia::TerminateGame();
|
||||
|
||||
ia::g_engine.Terminate();
|
||||
|
||||
game->Terminate();
|
||||
delete game;
|
||||
g_engine.Terminate();
|
||||
return 0;
|
||||
}
|
||||
30
Src/IAESandbox/imp/cpp/Map.cpp
Normal file
30
Src/IAESandbox/imp/cpp/Map.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <Map.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
TiledMap::TiledMap(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
m_musicEmitter = AddComponent<SoundEmitterComponent>();
|
||||
m_atlasRenderer = AddComponent<AtlasRendererComponent>();
|
||||
}
|
||||
|
||||
VOID TiledMap::OnAdded(IN Scene *scene)
|
||||
{
|
||||
Node::OnAdded(scene);
|
||||
}
|
||||
|
||||
VOID TiledMap::OnRemoved()
|
||||
{
|
||||
Node::OnRemoved();
|
||||
}
|
||||
|
||||
VOID TiledMap::Draw()
|
||||
{
|
||||
Node::Draw();
|
||||
}
|
||||
|
||||
VOID TiledMap::Update()
|
||||
{
|
||||
Node::Update();
|
||||
}
|
||||
} // namespace ia::iae::game
|
||||
34
Src/IAESandbox/imp/cpp/Player.cpp
Normal file
34
Src/IAESandbox/imp/cpp/Player.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <Player.hpp>
|
||||
|
||||
#include <IAEngine/Input.hpp>
|
||||
|
||||
#include <IACore/File.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
Player::Player(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
m_spriteRenderer = AddComponent<SpriteRendererComponent>();
|
||||
}
|
||||
|
||||
VOID Player::OnAdded(IN Scene *scene)
|
||||
{
|
||||
Node::OnAdded(scene);
|
||||
}
|
||||
|
||||
VOID Player::OnRemoved()
|
||||
{
|
||||
|
||||
Node::OnRemoved();
|
||||
}
|
||||
|
||||
VOID Player::Draw()
|
||||
{
|
||||
Node::Draw();
|
||||
}
|
||||
|
||||
VOID Player::Update()
|
||||
{
|
||||
Node::Update();
|
||||
}
|
||||
} // namespace ia::iae::game
|
||||
19
Src/IAESandbox/imp/hpp/Game.hpp
Normal file
19
Src/IAESandbox/imp/hpp/Game.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game(IN Engine* engine): m_engine(engine) {}
|
||||
|
||||
VOID Initialize();
|
||||
VOID Terminate();
|
||||
VOID Update();
|
||||
|
||||
private:
|
||||
Engine* CONST m_engine;
|
||||
};
|
||||
}
|
||||
24
Src/IAESandbox/imp/hpp/Map.hpp
Normal file
24
Src/IAESandbox/imp/hpp/Map.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/SoundEmitter.hpp>
|
||||
#include <IAEngine/Components/AtlasRenderer.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
class TiledMap : public Node
|
||||
{
|
||||
public:
|
||||
TiledMap(IN Engine* engine);
|
||||
|
||||
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
|
||||
VIRTUAL VOID OnRemoved() OVERRIDE;
|
||||
VIRTUAL VOID Draw() OVERRIDE;
|
||||
VIRTUAL VOID Update() OVERRIDE;
|
||||
|
||||
private:
|
||||
Engine* CONST m_engine;
|
||||
RefPtr<SoundEmitterComponent> m_musicEmitter;
|
||||
RefPtr<AtlasRendererComponent> m_atlasRenderer;
|
||||
};
|
||||
}
|
||||
27
Src/IAESandbox/imp/hpp/Player.hpp
Normal file
27
Src/IAESandbox/imp/hpp/Player.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/SoundEmitter.hpp>
|
||||
#include <IAEngine/Components/SpriteRenderer.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
|
||||
namespace ia::iae::game
|
||||
{
|
||||
class Player : public Node
|
||||
{
|
||||
public:
|
||||
Player(IN Engine *engine);
|
||||
|
||||
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
|
||||
VIRTUAL VOID OnRemoved() OVERRIDE;
|
||||
VIRTUAL VOID Draw() OVERRIDE;
|
||||
VIRTUAL VOID Update() OVERRIDE;
|
||||
|
||||
private:
|
||||
INT32 m_speed{};
|
||||
UINT8 m_direction{};
|
||||
|
||||
private:
|
||||
Engine *CONST m_engine;
|
||||
RefPtr<SpriteRendererComponent> m_spriteRenderer;
|
||||
};
|
||||
} // namespace ia::iae::game
|
||||
@ -7,9 +7,11 @@ set(IAEngine_Sources
|
||||
imp/cpp/Input.cpp
|
||||
imp/cpp/Scene.cpp
|
||||
imp/cpp/Random.cpp
|
||||
imp/cpp/ResourceManager.cpp
|
||||
imp/cpp/Events/Event.cpp
|
||||
imp/cpp/Nodes/Transform.cpp
|
||||
imp/cpp/Nodes/Node.cpp
|
||||
imp/cpp/Components/AtlasRenderer.cpp
|
||||
imp/cpp/Components/SpriteRenderer.cpp
|
||||
imp/cpp/Components/SoundEmitter.cpp
|
||||
)
|
||||
|
||||
@ -77,7 +77,7 @@ namespace ia::iae
|
||||
|
||||
VOID Audio::ClearTrack(IN INT64 trackHandle)
|
||||
{
|
||||
MIX_StopTrack(g_tracks[trackHandle], 0);
|
||||
//MIX_StopTrack(g_tracks[trackHandle], 0);
|
||||
}
|
||||
|
||||
VOID Audio::PauseTrack(IN INT64 trackHandle)
|
||||
|
||||
50
Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp
Normal file
50
Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <IAEngine/Components/AtlasRenderer.hpp>
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
AtlasRendererComponent::AtlasRendererComponent(IN Node *node) : IComponent(node)
|
||||
{
|
||||
}
|
||||
|
||||
Handle AtlasRendererComponent::AddTexture(IN RefPtr<Texture> texture)
|
||||
{
|
||||
m_textures.pushBack(texture);
|
||||
return m_textures.size() - 1;
|
||||
}
|
||||
|
||||
VOID AtlasRendererComponent::SetGrid(IN CONST TileGrid &grid)
|
||||
{
|
||||
m_tileGrid = grid;
|
||||
m_tileGrid.m_tileTextures.resize(grid.TileCountX * grid.TileCountY);
|
||||
for (auto &t : m_tileGrid.m_tileTextures)
|
||||
t = INVALID_HANDLE;
|
||||
}
|
||||
|
||||
VOID AtlasRendererComponent::SetGridTileTexture(IN INT32 x, IN INT32 y, IN Handle textureHandle)
|
||||
{
|
||||
m_tileGrid.m_tileTextures[x + (y * m_tileGrid.TileCountX)] = textureHandle;
|
||||
}
|
||||
|
||||
VOID AtlasRendererComponent::Update()
|
||||
{
|
||||
}
|
||||
|
||||
VOID AtlasRendererComponent::Draw()
|
||||
{
|
||||
iam::Vec3f p{m_node->GetPosition().X, m_node->GetPosition().Y, m_node->GetPosition().Z};
|
||||
for (INT32 y = 0; y < m_tileGrid.TileCountY; y++)
|
||||
{
|
||||
for (INT32 x = 0; x < m_tileGrid.TileCountX; x++)
|
||||
{
|
||||
const auto t = m_tileGrid.m_tileTextures[x + (y * m_tileGrid.TileCountX)];
|
||||
if (t != INVALID_HANDLE)
|
||||
m_textures[t]->Draw(p, {1.0f, 1.0f, 1.0f}, 0.0f, false, false, {1.0f, 1.0f, 1.0f, 1.0f});
|
||||
p.X += m_tileGrid.TileWidth;
|
||||
}
|
||||
p.X = m_node->GetPosition().X;
|
||||
p.Y += m_tileGrid.TileHeight;
|
||||
}
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -36,7 +36,7 @@ namespace ia::iae
|
||||
VOID SoundEmitterComponent::SetSound(IN CONST Sound &sound)
|
||||
{
|
||||
m_activeSound = sound;
|
||||
if(m_trackHandle == INVALID_HANDLE) return;
|
||||
if((m_trackHandle == INVALID_HANDLE) || (m_activeSound.DataHandle() == INVALID_HANDLE)) return;
|
||||
Audio::QueueTrackData(m_trackHandle, sound.DataHandle());
|
||||
Audio::PlayTrack(m_trackHandle, sound.LoopTimes(), sound.LoopDelay());
|
||||
}
|
||||
|
||||
@ -31,9 +31,17 @@ namespace ia::iae
|
||||
Animation anim;
|
||||
anim.ShouldLoop = shouldLoop;
|
||||
for (const auto &idx : frames)
|
||||
{
|
||||
anim.Keys.pushBack(AnimationKeyFrame{.Duration = frameDuration, .TextureHandle = idx});
|
||||
}
|
||||
return AddAnimation(anim);
|
||||
}
|
||||
|
||||
Handle SpriteRendererComponent::AddAnimation(IN INT32 startFrame, IN INT32 endFrame, IN INT32 frameDuration,
|
||||
IN BOOL shouldLoop)
|
||||
{
|
||||
Animation anim;
|
||||
anim.ShouldLoop = shouldLoop;
|
||||
for (INT32 i = startFrame; i < endFrame; i++)
|
||||
anim.Keys.pushBack(AnimationKeyFrame{.Duration = frameDuration, .TextureHandle = i});
|
||||
return AddAnimation(anim);
|
||||
}
|
||||
|
||||
@ -47,21 +55,26 @@ namespace ia::iae
|
||||
}
|
||||
if (m_animations.size())
|
||||
SetActiveAnimation(0);
|
||||
else
|
||||
SetActiveTexture(0);
|
||||
}
|
||||
|
||||
VOID SpriteRendererComponent::SetActiveTexture(IN Handle texture)
|
||||
{
|
||||
IA_RELEASE_ASSERT((texture != INVALID_HANDLE) && (texture < m_textures.size()));
|
||||
m_currentAnimationState.TextureHandle = texture;
|
||||
}
|
||||
|
||||
VOID SpriteRendererComponent::SetActiveAnimation(IN Handle animation)
|
||||
{
|
||||
if(animation == m_activeAnimationHandle) return;
|
||||
IA_RELEASE_ASSERT((animation != INVALID_HANDLE) && (animation < m_animations.size()));
|
||||
m_prevAnimationKeyFrameIndex = 0;
|
||||
m_activeAnimation = m_animations[animation];
|
||||
m_prevAnimationKeyFrame = m_activeAnimation.Keys[m_prevAnimationKeyFrameIndex + 0];
|
||||
m_nextAnimationKeyFrame = m_activeAnimation.Keys[m_prevAnimationKeyFrameIndex + 1];
|
||||
m_currentAnimationState = m_prevAnimationKeyFrame;
|
||||
m_activeAnimationHandle = animation;
|
||||
}
|
||||
|
||||
VOID SpriteRendererComponent::Update()
|
||||
@ -75,7 +88,7 @@ namespace ia::iae
|
||||
if (animFrame.TextureHandle == INVALID_HANDLE)
|
||||
return;
|
||||
m_textures[animFrame.TextureHandle]->Draw(
|
||||
m_node->GetPosition() + animFrame.Position, m_node->GetScale() + animFrame.Scale,
|
||||
m_node->GetPosition() + animFrame.Position, m_node->GetScale() * animFrame.Scale,
|
||||
m_node->GetRotation().Z + animFrame.Rotation.Z, m_isFlippedH, m_isFlippedV, animFrame.ColorOverlay);
|
||||
}
|
||||
|
||||
@ -90,7 +103,7 @@ namespace ia::iae
|
||||
const auto t = m_timelinePosition / m_prevAnimationKeyFrame.Duration;
|
||||
#define INTERP_PROPERTY(name) \
|
||||
m_currentAnimationState.name = iam::Lerp(m_prevAnimationKeyFrame.name, m_nextAnimationKeyFrame.name, t);
|
||||
|
||||
|
||||
INTERP_PROPERTY(Position);
|
||||
INTERP_PROPERTY(Rotation);
|
||||
INTERP_PROPERTY(Scale);
|
||||
@ -103,7 +116,7 @@ namespace ia::iae
|
||||
if (m_timelinePosition >= m_prevAnimationKeyFrame.Duration)
|
||||
{
|
||||
m_prevAnimationKeyFrameIndex = (m_prevAnimationKeyFrameIndex + 1) % (keyCount - 1);
|
||||
if(!m_prevAnimationKeyFrameIndex && !m_activeAnimation.ShouldLoop)
|
||||
if (!m_prevAnimationKeyFrameIndex && !m_activeAnimation.ShouldLoop)
|
||||
{
|
||||
m_activeAnimation = {};
|
||||
return;
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
#include <IAEngine/Events/Event.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,12 +1,9 @@
|
||||
#include <IAEngine/Audio.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <IAEngine/Random.hpp>
|
||||
#include <IAEngine/Input.hpp>
|
||||
#include <IAEngine/Time.hpp>
|
||||
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
@ -78,6 +75,7 @@ namespace ia::iae
|
||||
|
||||
Time::Initialize();
|
||||
Random::Initialize();
|
||||
Input::Initialize();
|
||||
Audio::Initialize();
|
||||
|
||||
return true;
|
||||
@ -142,6 +140,7 @@ namespace ia::iae
|
||||
|
||||
VOID Engine::ProcessEvents()
|
||||
{
|
||||
Input::OnEvent(&m_context->Event);
|
||||
}
|
||||
|
||||
VOID Engine::UpdateGame()
|
||||
@ -171,42 +170,3 @@ namespace ia::iae
|
||||
return m_context->Renderer;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
RefPtr<Texture> Engine::CreateTexture(IN CONST Span<CONST UINT8> &encodedData)
|
||||
{
|
||||
return CreateTexture(encodedData.data(), encodedData.size());
|
||||
}
|
||||
|
||||
RefPtr<Texture> Engine::CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
||||
{
|
||||
INT32 w, h, nrChannels;
|
||||
const auto pixels =
|
||||
stbi_load_from_memory(encodedData, encodedDataSize, &w, &h, &nrChannels, STBI_rgb_alpha);
|
||||
if (!pixels)
|
||||
THROW_INVALID_DATA("Failed to decode the provided image data");
|
||||
const auto result = CreateTexture((PCUINT8) pixels, w, h);
|
||||
STBI_FREE(pixels);
|
||||
return result;
|
||||
}
|
||||
|
||||
RefPtr<Texture> Engine::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
|
||||
{
|
||||
const auto result = MakeRefPtr<Texture>(this);
|
||||
|
||||
result->m_width = width;
|
||||
result->m_height = height;
|
||||
|
||||
SDL_Surface *surface =
|
||||
SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, (void *) rgbaData, width << 2);
|
||||
if (!surface)
|
||||
THROW_UNKNOWN("Failed to create SDL surface: ", SDL_GetError());
|
||||
result->m_handle = SDL_CreateTextureFromSurface(m_context->Renderer, surface);
|
||||
if (!result->m_handle)
|
||||
THROW_UNKNOWN("Failed to create SDL Texture: ", SDL_GetError());
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -0,0 +1,69 @@
|
||||
#include <IAEngine/Input.hpp>
|
||||
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
struct InputDirection
|
||||
{
|
||||
iam::Vec2f Velocity{};
|
||||
Input::DirectionalInput Direction{Input::DirectionalInput::NONE};
|
||||
};
|
||||
|
||||
STATIC CONSTEXPR InputDirection INPUT_TO_DIRECTION_MAP[] = {
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* 0 */
|
||||
{iam::Vec2f{1.0f, 0.0f}, Input::DirectionalInput::RIGHT}, /* D */
|
||||
{iam::Vec2f{-1.0f, 0.0f}, Input::DirectionalInput::LEFT}, /* A */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* A, D */
|
||||
{iam::Vec2f{0.0f, 1.0f}, Input::DirectionalInput::DOWN}, /* S */
|
||||
{iam::Vec2f{1.0f, 1.0f}, Input::DirectionalInput::DOWN_RIGHT}, /* S, D */
|
||||
{iam::Vec2f{-1.0f, 1.0f}, Input::DirectionalInput::DOWN_LEFT}, /* S, A */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* S, A, D */
|
||||
{iam::Vec2f{0.0f, -1.0f}, Input::DirectionalInput::UP}, /* W */
|
||||
{iam::Vec2f{1.0f, -1.0f}, Input::DirectionalInput::UP_RIGHT}, /* W, D */
|
||||
{iam::Vec2f{-1.0f, -1.0f}, Input::DirectionalInput::UP_LEFT}, /* W, A */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* W, A, D */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* W, S */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* W, S, D */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* W, S, A */
|
||||
{iam::Vec2f{0.0f, 0.0f}, Input::DirectionalInput::NONE}, /* W, S, A, D */
|
||||
};
|
||||
|
||||
BOOL Input::s_keys[256];
|
||||
BOOL Input::s_prevKeys[256];
|
||||
|
||||
VOID Input::Initialize()
|
||||
{
|
||||
memset(s_keys, 0, sizeof(s_keys));
|
||||
memset(s_prevKeys, 0, sizeof(s_prevKeys));
|
||||
}
|
||||
|
||||
VOID Input::OnEvent(IN PVOID _event)
|
||||
{
|
||||
const auto event = (SDL_Event *) _event;
|
||||
if (event->type == SDL_EVENT_KEY_DOWN)
|
||||
{
|
||||
s_keys[event->key.scancode] = true;
|
||||
}
|
||||
else if (event->type == SDL_EVENT_KEY_UP)
|
||||
{
|
||||
s_keys[event->key.scancode] = false;
|
||||
}
|
||||
memcpy(s_prevKeys, s_keys, sizeof(s_prevKeys));
|
||||
}
|
||||
|
||||
iam::Vec2f Input::GetDirectionalInput()
|
||||
{
|
||||
return INPUT_TO_DIRECTION_MAP[(IsKeyDown(Input::KEY_W) << 3) | (IsKeyDown(Input::KEY_S) << 2) |
|
||||
(IsKeyDown(Input::KEY_A) << 1) | (IsKeyDown(Input::KEY_D) << 0)]
|
||||
.Velocity;
|
||||
}
|
||||
|
||||
iam::Vec2f Input::GetDirectionalInput(OUT DirectionalInput &direction)
|
||||
{
|
||||
const auto dir = INPUT_TO_DIRECTION_MAP[(IsKeyDown(Input::KEY_W) << 3) | (IsKeyDown(Input::KEY_S) << 2) |
|
||||
(IsKeyDown(Input::KEY_A) << 1) | (IsKeyDown(Input::KEY_D) << 0)];
|
||||
direction = dir.Direction;
|
||||
return dir.Velocity;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
49
Src/IAEngine/imp/cpp/ResourceManager.cpp
Normal file
49
Src/IAEngine/imp/cpp/ResourceManager.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <IAEngine/ResourceManager.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
ResourceManager::ResourceManager(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<Texture> ResourceManager::CreateTexture(IN CONST Span<CONST UINT8> &encodedData)
|
||||
{
|
||||
return CreateTexture(encodedData.data(), encodedData.size());
|
||||
}
|
||||
|
||||
RefPtr<Texture> ResourceManager::CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
||||
{
|
||||
INT32 w, h, nrChannels;
|
||||
const auto pixels = stbi_load_from_memory(encodedData, encodedDataSize, &w, &h, &nrChannels, STBI_rgb_alpha);
|
||||
if (!pixels)
|
||||
THROW_INVALID_DATA("Failed to decode the provided image data");
|
||||
const auto result = CreateTexture((PCUINT8) pixels, w, h);
|
||||
STBI_FREE(pixels);
|
||||
return result;
|
||||
}
|
||||
|
||||
RefPtr<Texture> ResourceManager::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
|
||||
{
|
||||
const auto result = MakeRefPtr<Texture>(m_engine);
|
||||
|
||||
result->m_width = width;
|
||||
result->m_height = height;
|
||||
|
||||
SDL_Surface *surface =
|
||||
SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, (void *) rgbaData, width << 2);
|
||||
if (!surface)
|
||||
THROW_UNKNOWN("Failed to create SDL surface: ", SDL_GetError());
|
||||
result->m_handle = SDL_CreateTextureFromSurface((SDL_Renderer *) m_engine->GetRendererHandle(), surface);
|
||||
if (!result->m_handle)
|
||||
THROW_UNKNOWN("Failed to create SDL Texture: ", SDL_GetError());
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -64,11 +64,6 @@ namespace ia::iae
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID Terminate();
|
||||
|
||||
STATIC Sound CreateSound(IN CONST Vector<UINT8> &audioData)
|
||||
{
|
||||
return CreateSound(audioData.data(), audioData.size());
|
||||
}
|
||||
|
||||
STATIC Sound CreateSound(IN PCUINT8 audioData, IN SIZE_T audioDataSize);
|
||||
|
||||
STATIC INT64 CreateTrack();
|
||||
|
||||
@ -16,10 +16,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iacore/vector.hpp>
|
||||
#include <iacore/memory.hpp>
|
||||
#include <iacore/string.hpp>
|
||||
#include <iacore/exception.hpp>
|
||||
#include <IACore/Vector.hpp>
|
||||
#include <IACore/Memory.hpp>
|
||||
#include <IACore/String.hpp>
|
||||
#include <IACore/Exception.hpp>
|
||||
|
||||
#include <IAMath/Vec.hpp>
|
||||
|
||||
|
||||
56
Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp
Normal file
56
Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class AtlasRendererComponent : public IComponent
|
||||
{
|
||||
public:
|
||||
struct TileGrid
|
||||
{
|
||||
INT32 TileWidth{};
|
||||
INT32 TileHeight{};
|
||||
INT32 TileCountX{};
|
||||
INT32 TileCountY{};
|
||||
|
||||
Vector<Handle> m_tileTextures{};
|
||||
|
||||
friend class AtlasRendererComponent;
|
||||
};
|
||||
|
||||
public:
|
||||
AtlasRendererComponent(IN Node *node);
|
||||
|
||||
public:
|
||||
Handle AddTexture(IN RefPtr<Texture> texture);
|
||||
|
||||
VOID SetGrid(IN CONST TileGrid &grid);
|
||||
VOID SetGridTileTexture(IN INT32 x, IN INT32 y, IN Handle textureHandle);
|
||||
|
||||
public:
|
||||
VOID Draw();
|
||||
VOID Update();
|
||||
|
||||
private:
|
||||
TileGrid m_tileGrid{};
|
||||
Vector<RefPtr<Texture>> m_textures;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -47,6 +47,7 @@ namespace ia::iae
|
||||
Handle AddTexture(IN RefPtr<Texture> texture);
|
||||
Handle AddAnimation(IN CONST Animation &animation);
|
||||
Handle AddAnimation(IN initializer_list<INT32> frames, IN INT32 frameDuration, IN BOOL shouldLoop);
|
||||
Handle AddAnimation(IN INT32 startFrame, IN INT32 endFrame, IN INT32 frameDuration, IN BOOL shouldLoop);
|
||||
|
||||
VOID BakeAnimations();
|
||||
|
||||
@ -65,6 +66,7 @@ namespace ia::iae
|
||||
BOOL m_isFlippedH{false};
|
||||
FLOAT32 m_timelinePosition{};
|
||||
Animation m_activeAnimation{};
|
||||
Handle m_activeAnimationHandle{INVALID_HANDLE};
|
||||
Vector<Animation> m_animations;
|
||||
Vector<RefPtr<Texture>> m_textures;
|
||||
AnimationKeyFrame m_currentAnimationState{};
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
}
|
||||
@ -45,15 +45,10 @@ namespace ia::iae
|
||||
VOID EndFrame();
|
||||
BOOL ShouldClose();
|
||||
|
||||
public:
|
||||
VOID ChangeScene(IN RefPtr<Scene> scene);
|
||||
|
||||
public:
|
||||
RefPtr<Scene> CreateScene();
|
||||
|
||||
RefPtr<Texture> CreateTexture(IN CONST Span<CONST UINT8> &encodedData);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||
VOID ChangeScene(IN RefPtr<Scene> scene);
|
||||
|
||||
public:
|
||||
PVOID GetRendererHandle() CONST;
|
||||
|
||||
@ -0,0 +1,295 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
enum Key: UINT8
|
||||
{
|
||||
KEY_UNKNOWN = 0,
|
||||
KEY_A = 4,
|
||||
KEY_B = 5,
|
||||
KEY_C = 6,
|
||||
KEY_D = 7,
|
||||
KEY_E = 8,
|
||||
KEY_F = 9,
|
||||
KEY_G = 10,
|
||||
KEY_H = 11,
|
||||
KEY_I = 12,
|
||||
KEY_J = 13,
|
||||
KEY_K = 14,
|
||||
KEY_L = 15,
|
||||
KEY_M = 16,
|
||||
KEY_N = 17,
|
||||
KEY_O = 18,
|
||||
KEY_P = 19,
|
||||
KEY_Q = 20,
|
||||
KEY_R = 21,
|
||||
KEY_S = 22,
|
||||
KEY_T = 23,
|
||||
KEY_U = 24,
|
||||
KEY_V = 25,
|
||||
KEY_W = 26,
|
||||
KEY_X = 27,
|
||||
KEY_Y = 28,
|
||||
KEY_Z = 29,
|
||||
|
||||
KEY_1 = 30,
|
||||
KEY_2 = 31,
|
||||
KEY_3 = 32,
|
||||
KEY_4 = 33,
|
||||
KEY_5 = 34,
|
||||
KEY_6 = 35,
|
||||
KEY_7 = 36,
|
||||
KEY_8 = 37,
|
||||
KEY_9 = 38,
|
||||
KEY_0 = 39,
|
||||
|
||||
KEY_RETURN = 40,
|
||||
KEY_ESCAPE = 41,
|
||||
KEY_BACKSPACE = 42,
|
||||
KEY_TAB = 43,
|
||||
KEY_SPACE = 44,
|
||||
|
||||
KEY_MINUS = 45,
|
||||
KEY_EQUALS = 46,
|
||||
KEY_LEFTBRACKET = 47,
|
||||
KEY_RIGHTBRACKET = 48,
|
||||
KEY_BACKSLASH = 49,
|
||||
KEY_NONUSHASH = 50,
|
||||
KEY_SEMICOLON = 51,
|
||||
KEY_APOSTROPHE = 52,
|
||||
KEY_GRAVE = 53,
|
||||
KEY_COMMA = 54,
|
||||
KEY_PERIOD = 55,
|
||||
KEY_SLASH = 56,
|
||||
|
||||
KEY_CAPSLOCK = 57,
|
||||
|
||||
KEY_F1 = 58,
|
||||
KEY_F2 = 59,
|
||||
KEY_F3 = 60,
|
||||
KEY_F4 = 61,
|
||||
KEY_F5 = 62,
|
||||
KEY_F6 = 63,
|
||||
KEY_F7 = 64,
|
||||
KEY_F8 = 65,
|
||||
KEY_F9 = 66,
|
||||
KEY_F10 = 67,
|
||||
KEY_F11 = 68,
|
||||
KEY_F12 = 69,
|
||||
|
||||
KEY_PRINTSCREEN = 70,
|
||||
KEY_SCROLLLOCK = 71,
|
||||
KEY_PAUSE = 72,
|
||||
KEY_INSERT = 73,
|
||||
KEY_HOME = 74,
|
||||
KEY_PAGEUP = 75,
|
||||
KEY_DELETE = 76,
|
||||
KEY_END = 77,
|
||||
KEY_PAGEDOWN = 78,
|
||||
KEY_RIGHT = 79,
|
||||
KEY_LEFT = 80,
|
||||
KEY_DOWN = 81,
|
||||
KEY_UP = 82,
|
||||
|
||||
KEY_NUMLOCKCLEAR = 83,
|
||||
KEY_KP_DIVIDE = 84,
|
||||
KEY_KP_MULTIPLY = 85,
|
||||
KEY_KP_MINUS = 86,
|
||||
KEY_KP_PLUS = 87,
|
||||
KEY_KP_ENTER = 88,
|
||||
KEY_KP_1 = 89,
|
||||
KEY_KP_2 = 90,
|
||||
KEY_KP_3 = 91,
|
||||
KEY_KP_4 = 92,
|
||||
KEY_KP_5 = 93,
|
||||
KEY_KP_6 = 94,
|
||||
KEY_KP_7 = 95,
|
||||
KEY_KP_8 = 96,
|
||||
KEY_KP_9 = 97,
|
||||
KEY_KP_0 = 98,
|
||||
KEY_KP_PERIOD = 99,
|
||||
|
||||
KEY_NONUSBACKSLASH = 100,
|
||||
KEY_APPLICATION = 101,
|
||||
KEY_POWER = 102,
|
||||
KEY_KP_EQUALS = 103,
|
||||
KEY_F13 = 104,
|
||||
KEY_F14 = 105,
|
||||
KEY_F15 = 106,
|
||||
KEY_F16 = 107,
|
||||
KEY_F17 = 108,
|
||||
KEY_F18 = 109,
|
||||
KEY_F19 = 110,
|
||||
KEY_F20 = 111,
|
||||
KEY_F21 = 112,
|
||||
KEY_F22 = 113,
|
||||
KEY_F23 = 114,
|
||||
KEY_F24 = 115,
|
||||
KEY_EXECUTE = 116,
|
||||
KEY_HELP = 117,
|
||||
KEY_MENU = 118,
|
||||
KEY_SELECT = 119,
|
||||
KEY_STOP = 120,
|
||||
KEY_AGAIN = 121,
|
||||
KEY_UNDO = 122,
|
||||
KEY_CUT = 123,
|
||||
KEY_COPY = 124,
|
||||
KEY_PASTE = 125,
|
||||
KEY_FIND = 126,
|
||||
KEY_MUTE = 127,
|
||||
KEY_VOLUMEUP = 128,
|
||||
KEY_VOLUMEDOWN = 129,
|
||||
|
||||
KEY_KP_COMMA = 133,
|
||||
KEY_KP_EQUALSAS400 = 134,
|
||||
|
||||
KEY_INTERNATIONAL1 = 135,
|
||||
KEY_INTERNATIONAL2 = 136,
|
||||
KEY_INTERNATIONAL3 = 137,
|
||||
KEY_INTERNATIONAL4 = 138,
|
||||
KEY_INTERNATIONAL5 = 139,
|
||||
KEY_INTERNATIONAL6 = 140,
|
||||
KEY_INTERNATIONAL7 = 141,
|
||||
KEY_INTERNATIONAL8 = 142,
|
||||
KEY_INTERNATIONAL9 = 143,
|
||||
KEY_LANG1 = 144,
|
||||
KEY_LANG2 = 145,
|
||||
KEY_LANG3 = 146,
|
||||
KEY_LANG4 = 147,
|
||||
KEY_LANG5 = 148,
|
||||
KEY_LANG6 = 149,
|
||||
KEY_LANG7 = 150,
|
||||
KEY_LANG8 = 151,
|
||||
KEY_LANG9 = 152,
|
||||
|
||||
KEY_ALTERASE = 153,
|
||||
KEY_SYSREQ = 154,
|
||||
KEY_CANCEL = 155,
|
||||
KEY_CLEAR = 156,
|
||||
KEY_PRIOR = 157,
|
||||
KEY_RETURN2 = 158,
|
||||
KEY_SEPARATOR = 159,
|
||||
KEY_OUT = 160,
|
||||
KEY_OPER = 161,
|
||||
KEY_CLEARAGAIN = 162,
|
||||
KEY_CRSEL = 163,
|
||||
KEY_EXSEL = 164,
|
||||
|
||||
KEY_KP_00 = 176,
|
||||
KEY_KP_000 = 177,
|
||||
KEY_THOUSANDSSEPARATOR = 178,
|
||||
KEY_DECIMALSEPARATOR = 179,
|
||||
KEY_CURRENCYUNIT = 180,
|
||||
KEY_CURRENCYSUBUNIT = 181,
|
||||
KEY_KP_LEFTPAREN = 182,
|
||||
KEY_KP_RIGHTPAREN = 183,
|
||||
KEY_KP_LEFTBRACE = 184,
|
||||
KEY_KP_RIGHTBRACE = 185,
|
||||
KEY_KP_TAB = 186,
|
||||
KEY_KP_BACKSPACE = 187,
|
||||
KEY_KP_A = 188,
|
||||
KEY_KP_B = 189,
|
||||
KEY_KP_C = 190,
|
||||
KEY_KP_D = 191,
|
||||
KEY_KP_E = 192,
|
||||
KEY_KP_F = 193,
|
||||
KEY_KP_XOR = 194,
|
||||
KEY_KP_POWER = 195,
|
||||
KEY_KP_PERCENT = 196,
|
||||
KEY_KP_LESS = 197,
|
||||
KEY_KP_GREATER = 198,
|
||||
KEY_KP_AMPERSAND = 199,
|
||||
KEY_KP_DBLAMPERSAND = 200,
|
||||
KEY_KP_VERTICALBAR = 201,
|
||||
KEY_KP_DBLVERTICALBAR = 202,
|
||||
KEY_KP_COLON = 203,
|
||||
KEY_KP_HASH = 204,
|
||||
KEY_KP_SPACE = 205,
|
||||
KEY_KP_AT = 206,
|
||||
KEY_KP_EXCLAM = 207,
|
||||
KEY_KP_MEMSTORE = 208,
|
||||
KEY_KP_MEMRECALL = 209,
|
||||
KEY_KP_MEMCLEAR = 210,
|
||||
KEY_KP_MEMADD = 211,
|
||||
KEY_KP_MEMSUBTRACT = 212,
|
||||
KEY_KP_MEMMULTIPLY = 213,
|
||||
KEY_KP_MEMDIVIDE = 214,
|
||||
KEY_KP_PLUSMINUS = 215,
|
||||
KEY_KP_CLEAR = 216,
|
||||
KEY_KP_CLEARENTRY = 217,
|
||||
KEY_KP_BINARY = 218,
|
||||
KEY_KP_OCTAL = 219,
|
||||
KEY_KP_DECIMAL = 220,
|
||||
KEY_KP_HEXADECIMAL = 221,
|
||||
|
||||
KEY_LCTRL = 224,
|
||||
KEY_LSHIFT = 225,
|
||||
KEY_LALT = 226,
|
||||
KEY_LGUI = 227,
|
||||
KEY_RCTRL = 228,
|
||||
KEY_RSHIFT = 229,
|
||||
KEY_RALT = 230,
|
||||
KEY_RGUI = 231,
|
||||
};
|
||||
|
||||
enum class DirectionalInput: UINT8
|
||||
{
|
||||
NONE = 0,
|
||||
DOWN,
|
||||
DOWN_LEFT,
|
||||
LEFT,
|
||||
UP_LEFT,
|
||||
UP,
|
||||
UP_RIGHT,
|
||||
RIGHT,
|
||||
DOWN_RIGHT
|
||||
};
|
||||
|
||||
public:
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID OnEvent(IN PVOID event);
|
||||
|
||||
STATIC BOOL IsKeyDown(IN Key key)
|
||||
{
|
||||
return s_keys[(UINT8)key];
|
||||
}
|
||||
|
||||
STATIC BOOL WasKeyPressed(IN Key key)
|
||||
{
|
||||
return !s_prevKeys[key] && s_keys[key];
|
||||
}
|
||||
|
||||
STATIC BOOL WasKeyReleased(IN Key key)
|
||||
{
|
||||
return s_prevKeys[key] && !s_keys[key];
|
||||
}
|
||||
|
||||
STATIC iam::Vec2f GetDirectionalInput();
|
||||
STATIC iam::Vec2f GetDirectionalInput(OUT DirectionalInput& direction);
|
||||
|
||||
private:
|
||||
STATIC BOOL s_keys[256];
|
||||
STATIC BOOL s_prevKeys[256];
|
||||
};
|
||||
} // namespace ia::iae
|
||||
52
Src/IAEngine/inc/IAEngine/ResourceManager.hpp
Normal file
52
Src/IAEngine/inc/IAEngine/ResourceManager.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Audio.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Engine;
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
RefPtr<Texture> CreateTexture(IN CONST Span<CONST UINT8> &encodedData);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
RefPtr<Texture> CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||
|
||||
public:
|
||||
Sound CreateSound(IN PCUINT8 audioData, IN SIZE_T audioDataSize)
|
||||
{
|
||||
return Audio::CreateSound(audioData, audioDataSize);
|
||||
}
|
||||
|
||||
Sound CreateSound(IN CONST Vector<UINT8> &audioData)
|
||||
{
|
||||
return CreateSound(audioData.data(), audioData.size());
|
||||
}
|
||||
|
||||
protected:
|
||||
Engine *CONST m_engine;
|
||||
|
||||
private:
|
||||
ResourceManager(IN Engine *engine);
|
||||
|
||||
friend class Engine;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -50,5 +50,6 @@ namespace ia::iae
|
||||
|
||||
private:
|
||||
friend class Engine;
|
||||
friend class ResourceManager;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user