Fixes
This commit is contained in:
@ -40,7 +40,7 @@ namespace ia::iae
|
||||
CONST Mat4 *CameraComponent::GetViewMatrix()
|
||||
{
|
||||
const auto pos = (m_node->GetPosition() + m_positionOffset) * Engine::GetSceneScalingFactor();
|
||||
m_viewMatrix = glm::lookAtLH(glm::vec3{pos, -2.0f}, {pos, 0.0f}, {0.0f, 1.0f, 0.0f});
|
||||
m_viewMatrix = glm::lookAtLH(glm::vec3{pos, -1.0f}, {pos, 0.0f}, {0.0f, 1.0f, 0.0f});
|
||||
return &m_viewMatrix;
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
namespace ia::iae
|
||||
{
|
||||
EXTERN SDL_Window *g_windowHandle;
|
||||
SIZE_T g_resourceNameCounter {1};
|
||||
SIZE_T g_resourceNameCounter{1};
|
||||
|
||||
Vec2 g_sceneScalingFactor{1.0f};
|
||||
Vec2 g_sceneDesignViewport{1.0f};
|
||||
@ -72,6 +72,11 @@ namespace ia::iae
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec2 Engine::CalculatePercentPosition(IN Vec2 percent)
|
||||
{
|
||||
return Vec2{Renderer::s_activeSceneDesignViewport.x/100.0f, Renderer::s_activeSceneDesignViewport.y/100.0f} * percent;
|
||||
}
|
||||
|
||||
Direction Engine::GetVectorPointingDirection(IN Vec2 v)
|
||||
{
|
||||
STATIC CONSTEXPR Direction DIRECTION_MAP[] = {Direction::RIGHT, Direction::DOWN_RIGHT, Direction::DOWN,
|
||||
@ -105,7 +110,8 @@ namespace ia::iae
|
||||
return handle;
|
||||
const auto extent = GetImageExtent(handle);
|
||||
const auto newHandle = ResourceManager::RescaleImage(
|
||||
handle, {(FLOAT32) resizeToWidth / (FLOAT32) extent.x, (FLOAT32) resizeToHeight / (FLOAT32) extent.y}, true);
|
||||
handle, {(FLOAT32) resizeToWidth / (FLOAT32) extent.x, (FLOAT32) resizeToHeight / (FLOAT32) extent.y},
|
||||
true);
|
||||
return newHandle;
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,13 @@
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
struct OnScreenGamepadState
|
||||
{
|
||||
Vec2 KnobPosition;
|
||||
Vec2 ThumbstickPosition{};
|
||||
FLOAT32 ThumbstickRadius{};
|
||||
} g_onScreenGamepadState{};
|
||||
|
||||
EXTERN SDL_Window *g_windowHandle;
|
||||
|
||||
BOOL InputManager::s_keys[256];
|
||||
@ -42,6 +49,9 @@ namespace ia::iae
|
||||
{
|
||||
memset(s_keys, 0, sizeof(s_keys));
|
||||
memset(s_prevKeys, 0, sizeof(s_prevKeys));
|
||||
|
||||
g_onScreenGamepadState.KnobPosition = {};
|
||||
g_onScreenGamepadState.ThumbstickRadius = 64.0f;
|
||||
}
|
||||
|
||||
VOID InputManager::Terminate()
|
||||
@ -119,7 +129,10 @@ namespace ia::iae
|
||||
|
||||
VOID InputManager::SetupOnScreenGamePad()
|
||||
{
|
||||
s_onScreenGamePadEnabled = true;
|
||||
// Initialize
|
||||
|
||||
// Disable till manually enabled by calling Input_EnableOnScreenGamePad
|
||||
s_onScreenGamePadEnabled = false;
|
||||
}
|
||||
|
||||
VOID InputManager::SetupKeyboardGamePad(IN CONST KeyboardGamePadMapping &mapping)
|
||||
@ -197,16 +210,15 @@ namespace ia::iae
|
||||
{
|
||||
if (s_onScreenGamePadEnabled)
|
||||
{
|
||||
// Engine::SetRenderState_Texture(0);
|
||||
// Engine::SetRenderState_FlippedH(false);
|
||||
// Engine::SetRenderState_FlippedV(false);
|
||||
// Engine::SetRenderState_ColorOverlay({0xFF, 0xFF, 0xFF, 0xFF});
|
||||
// Engine::SetRenderState_TextureOffset({0, 0});
|
||||
// Engine::SetRenderState_CameraRelative(false);
|
||||
// Engine::SetRenderState_Transform({300.0f, 500.0f},
|
||||
// {100.0f, 100.0f},
|
||||
// 0);
|
||||
// Engine::DrawGeometry(Engine::GetGeometry_Circle(), 0xFF, 0);
|
||||
g_onScreenGamepadState.ThumbstickPosition =
|
||||
Engine::CalculatePercentPosition({92.5f, 90.0f}) - Vec2{0, 32.0f};
|
||||
Engine::SetRenderState_CameraRelative(false);
|
||||
Engine::SetRenderState_ColorOverlay({0x80, 0x80, 0x80, 0x80});
|
||||
Engine::DrawCircle(g_onScreenGamepadState.ThumbstickPosition, 0, g_onScreenGamepadState.ThumbstickRadius, 0,
|
||||
0xFF, 0);
|
||||
Engine::SetRenderState_ColorOverlay({0x20, 0x20, 0x20, 0xB0});
|
||||
Engine::DrawCircle(g_onScreenGamepadState.ThumbstickPosition + g_onScreenGamepadState.KnobPosition, 0, 16,
|
||||
0, 0xFF, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,6 +233,30 @@ namespace ia::iae
|
||||
|
||||
if (s_onScreenGamePadEnabled)
|
||||
{
|
||||
STATIC CONSTEXPR INT16 DIRECTION_MAP_VERTICAL[] = {0, 1, 1, 1, 0, -1, -1, -1};
|
||||
STATIC CONSTEXPR INT16 DIRECTION_MAP_HORIZONTAL[] = {1, 1, 0, -1, -1, -1, 0, 1};
|
||||
|
||||
if (Engine::Input_IsPointerDown(g_onScreenGamepadState.ThumbstickPosition,
|
||||
g_onScreenGamepadState.ThumbstickRadius))
|
||||
g_onScreenGamepadState.KnobPosition =
|
||||
Engine::Input_GetPointerPosition() - g_onScreenGamepadState.ThumbstickPosition;
|
||||
else
|
||||
g_onScreenGamepadState.KnobPosition = {};
|
||||
|
||||
auto verticalAxis = abs(g_onScreenGamepadState.KnobPosition.y);
|
||||
auto horizontalAxis = abs(g_onScreenGamepadState.KnobPosition.x);
|
||||
verticalAxis = (verticalAxis > FLOAT32_EPSILON) ? g_onScreenGamepadState.KnobPosition.y / ((FLOAT32)g_onScreenGamepadState.ThumbstickRadius) : 0;
|
||||
horizontalAxis = (horizontalAxis > FLOAT32_EPSILON) ? g_onScreenGamepadState.KnobPosition.x / ((FLOAT32)g_onScreenGamepadState.ThumbstickRadius) : 0;
|
||||
|
||||
if ((abs(verticalAxis) > FLOAT32_EPSILON) || (abs(horizontalAxis) > FLOAT32_EPSILON))
|
||||
{
|
||||
auto angle = glm::degrees(atan2(verticalAxis, horizontalAxis));
|
||||
if (angle < 0)
|
||||
angle += 360;
|
||||
const auto t = INT32((angle + 22.5) / 45) % 8;
|
||||
s_verticalAxis = DIRECTION_MAP_VERTICAL[t];
|
||||
s_horizontalAxis = DIRECTION_MAP_HORIZONTAL[t];
|
||||
}
|
||||
}
|
||||
|
||||
if (s_keyboardGamePadEnabled)
|
||||
@ -238,15 +274,31 @@ namespace ia::iae
|
||||
|
||||
BOOL InputManager::IsPointerDown(IN CONST Vec2 &start, IN CONST Vec2 &end)
|
||||
{
|
||||
if(!s_pointerState) return false;
|
||||
if (!s_pointerState)
|
||||
return false;
|
||||
return (s_pointerPosition.x >= start.x) && (s_pointerPosition.x <= end.x) && (s_pointerPosition.y >= start.y) &&
|
||||
(s_pointerPosition.y <= end.y);
|
||||
}
|
||||
|
||||
BOOL InputManager::IsPointerDown(IN CONST Vec2 ¢er, IN FLOAT32 radius)
|
||||
{
|
||||
if (!s_pointerState)
|
||||
return false;
|
||||
const auto dx = s_pointerPosition.x - center.x;
|
||||
const auto dy = s_pointerPosition.y - center.y;
|
||||
const auto d = (dx * dx) + (dy * dy);
|
||||
return d <= (radius * radius);
|
||||
}
|
||||
|
||||
BOOL InputManager::DidPointerClick(IN CONST Vec2 &start, IN CONST Vec2 &end)
|
||||
{
|
||||
return IsPointerDown(start, end) && !s_pointerPrevState;
|
||||
}
|
||||
|
||||
BOOL InputManager::DidPointerClick(IN CONST Vec2 ¢er, IN FLOAT32 radius)
|
||||
{
|
||||
return IsPointerDown(center, radius) && !s_pointerPrevState;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
@ -372,4 +424,24 @@ namespace ia::iae
|
||||
{
|
||||
InputManager::SetHorizontalAxis(value);
|
||||
}
|
||||
|
||||
BOOL Engine::Input_DidPointerClick(IN CONST Vec2 ¢er, IN FLOAT32 radius)
|
||||
{
|
||||
return InputManager::DidPointerClick(center, radius);
|
||||
}
|
||||
|
||||
BOOL Engine::Input_IsPointerDown(IN CONST Vec2 ¢er, IN FLOAT32 radius)
|
||||
{
|
||||
return InputManager::IsPointerDown(center, radius);
|
||||
}
|
||||
|
||||
VOID Engine::Input_EnableOnScreenGamePad()
|
||||
{
|
||||
InputManager::s_onScreenGamePadEnabled = true;
|
||||
}
|
||||
|
||||
VOID Engine::Input_DisableOnScreenGamePad()
|
||||
{
|
||||
InputManager::s_onScreenGamePadEnabled = false;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -50,6 +50,7 @@ namespace ia::iae
|
||||
|
||||
g_sceneDesignViewport.x = config->DesignWidth;
|
||||
g_sceneDesignViewport.y = config->DesignHeight;
|
||||
Engine::SetSceneDesignViewport({});
|
||||
|
||||
IAE_LOG_INFO("Booting IAEngine for ", g_gameName);
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ namespace ia::iae
|
||||
BOOL Renderer::s_ySortingEnabled{false};
|
||||
SDL_Rect Renderer::s_defaultScissor{};
|
||||
SDL_GPUViewport Renderer::s_defaultViewport{};
|
||||
Vec2 Renderer::s_activeSceneDesignViewport{};
|
||||
|
||||
EXTERN Vec2 g_sceneScalingFactor;
|
||||
EXTERN Vec2 g_sceneDesignViewport;
|
||||
@ -112,117 +113,43 @@ namespace ia::iae
|
||||
|
||||
s_circleGeometry = CreateGeometry(
|
||||
{
|
||||
{{0.0000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.0000000f},
|
||||
{0.5000000f, 0.5000000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 0 Center
|
||||
{{1.0000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.0000000f},
|
||||
{1.0000000f, 0.5000000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 1
|
||||
{{0.9848078f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.1736482f},
|
||||
{0.9924039f, 0.5868241f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 2
|
||||
{{0.9396926f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.3420201f},
|
||||
{0.9698463f, 0.6710101f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 3
|
||||
{{0.8660254f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.5000000f},
|
||||
{0.9330127f, 0.7500000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 4
|
||||
{{0.7660444f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.6427876f},
|
||||
{0.8830222f, 0.8213938f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 5
|
||||
{{0.6427876f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.7660444f},
|
||||
{0.8213938f, 0.8830222f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 6
|
||||
{{0.5000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.8660254f},
|
||||
{0.7500000f, 0.9330127f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 7
|
||||
{{0.3420201f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.9396926f},
|
||||
{0.6710101f, 0.9698463f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 8
|
||||
{{0.1736482f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.9848078f},
|
||||
{0.5868241f, 0.9924039f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 9
|
||||
{{0.0000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 1.0000000f},
|
||||
{0.5000000f, 1.0000000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 10
|
||||
{{-0.1736482f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.9848078f},
|
||||
{0.4131759f, 0.9924039f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 11
|
||||
{{-0.3420201f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.9396926f},
|
||||
{0.3289899f, 0.9698463f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 12
|
||||
{{-0.5000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.8660254f},
|
||||
{0.2500000f, 0.9330127f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 13
|
||||
{{-0.6427876f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.7660444f},
|
||||
{0.1786062f, 0.8830222f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 14
|
||||
{{-0.7660444f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.6427876f},
|
||||
{0.1169778f, 0.8213938f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 15
|
||||
{{-0.8660254f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.5000000f},
|
||||
{0.0669873f, 0.7500000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 16
|
||||
{{-0.9396926f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.3420201f},
|
||||
{0.0301537f, 0.6710101f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 17
|
||||
{{-0.9848078f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.1736482f},
|
||||
{0.0075961f, 0.5868241f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 18
|
||||
{{-1.0000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * 0.0000000f},
|
||||
{0.0000000f, 0.5000000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 19
|
||||
{{-0.9848078f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.1736482f},
|
||||
{0.0075961f, 0.4131759f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 20
|
||||
{{-0.9396926f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.3420201f},
|
||||
{0.0301537f, 0.3289899f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 21
|
||||
{{-0.8660254f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.5000000f},
|
||||
{0.0669873f, 0.2500000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 22
|
||||
{{-0.7660444f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.6427876f},
|
||||
{0.1169778f, 0.1786062f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 23
|
||||
{{-0.6427876f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.7660444f},
|
||||
{0.1786062f, 0.1169778f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 24
|
||||
{{-0.5000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.8660254f},
|
||||
{0.2500000f, 0.0669873f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 25
|
||||
{{-0.3420201f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.9396926f},
|
||||
{0.3289899f, 0.0301537f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 26
|
||||
{{-0.1736482f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.9848078f},
|
||||
{0.4131759f, 0.0075961f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 27
|
||||
{{-0.0000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -1.0000000f},
|
||||
{0.5000000f, 0.0000000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 28
|
||||
{{0.1736482f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.9848078f},
|
||||
{0.5868241f, 0.0075961f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 29
|
||||
{{0.3420201f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.9396926f},
|
||||
{0.6710101f, 0.0301537f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 30
|
||||
{{0.5000000f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.8660254f},
|
||||
{0.7500000f, 0.0669873f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 31
|
||||
{{0.6427876f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.7660444f},
|
||||
{0.8213938f, 0.1169778f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 32
|
||||
{{0.7660444f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.6427876f},
|
||||
{0.8830222f, 0.1786062f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 33
|
||||
{{0.8660254f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.5000000f},
|
||||
{0.9330127f, 0.2500000f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 34
|
||||
{{0.9396926f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.3420201f},
|
||||
{0.9698463f, 0.3289899f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}, // 35
|
||||
{{0.9848078f, (1.0f / Engine::GetDisplayAspectRatio()) * 0.75f * -0.1736482f},
|
||||
{0.9924039f, 0.4131759f},
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}} // 36
|
||||
{{0.0000000f, 1 * 0.0000000f}, {0.5000000f, 0.5000000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 0 Center
|
||||
{{1.0000000f, 1 * 0.0000000f}, {1.0000000f, 0.5000000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 1
|
||||
{{0.9848078f, 1 * 0.1736482f}, {0.9924039f, 0.5868241f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 2
|
||||
{{0.9396926f, 1 * 0.3420201f}, {0.9698463f, 0.6710101f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 3
|
||||
{{0.8660254f, 1 * 0.5000000f}, {0.9330127f, 0.7500000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 4
|
||||
{{0.7660444f, 1 * 0.6427876f}, {0.8830222f, 0.8213938f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 5
|
||||
{{0.6427876f, 1 * 0.7660444f}, {0.8213938f, 0.8830222f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 6
|
||||
{{0.5000000f, 1 * 0.8660254f}, {0.7500000f, 0.9330127f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 7
|
||||
{{0.3420201f, 1 * 0.9396926f}, {0.6710101f, 0.9698463f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 8
|
||||
{{0.1736482f, 1 * 0.9848078f}, {0.5868241f, 0.9924039f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 9
|
||||
{{0.0000000f, 1 * 1.0000000f}, {0.5000000f, 1.0000000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 10
|
||||
{{-0.1736482f, 1 * 0.9848078f}, {0.4131759f, 0.9924039f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 11
|
||||
{{-0.3420201f, 1 * 0.9396926f}, {0.3289899f, 0.9698463f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 12
|
||||
{{-0.5000000f, 1 * 0.8660254f}, {0.2500000f, 0.9330127f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 13
|
||||
{{-0.6427876f, 1 * 0.7660444f}, {0.1786062f, 0.8830222f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 14
|
||||
{{-0.7660444f, 1 * 0.6427876f}, {0.1169778f, 0.8213938f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 15
|
||||
{{-0.8660254f, 1 * 0.5000000f}, {0.0669873f, 0.7500000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 16
|
||||
{{-0.9396926f, 1 * 0.3420201f}, {0.0301537f, 0.6710101f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 17
|
||||
{{-0.9848078f, 1 * 0.1736482f}, {0.0075961f, 0.5868241f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 18
|
||||
{{-1.0000000f, 1 * 0.0000000f}, {0.0000000f, 0.5000000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 19
|
||||
{{-0.9848078f, 1 * -0.1736482f}, {0.0075961f, 0.4131759f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 20
|
||||
{{-0.9396926f, 1 * -0.3420201f}, {0.0301537f, 0.3289899f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 21
|
||||
{{-0.8660254f, 1 * -0.5000000f}, {0.0669873f, 0.2500000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 22
|
||||
{{-0.7660444f, 1 * -0.6427876f}, {0.1169778f, 0.1786062f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 23
|
||||
{{-0.6427876f, 1 * -0.7660444f}, {0.1786062f, 0.1169778f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 24
|
||||
{{-0.5000000f, 1 * -0.8660254f}, {0.2500000f, 0.0669873f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 25
|
||||
{{-0.3420201f, 1 * -0.9396926f}, {0.3289899f, 0.0301537f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 26
|
||||
{{-0.1736482f, 1 * -0.9848078f}, {0.4131759f, 0.0075961f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 27
|
||||
{{-0.0000000f, 1 * -1.0000000f}, {0.5000000f, 0.0000000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 28
|
||||
{{0.1736482f, 1 * -0.9848078f}, {0.5868241f, 0.0075961f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 29
|
||||
{{0.3420201f, 1 * -0.9396926f}, {0.6710101f, 0.0301537f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 30
|
||||
{{0.5000000f, 1 * -0.8660254f}, {0.7500000f, 0.0669873f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 31
|
||||
{{0.6427876f, 1 * -0.7660444f}, {0.8213938f, 0.1169778f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 32
|
||||
{{0.7660444f, 1 * -0.6427876f}, {0.8830222f, 0.1786062f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 33
|
||||
{{0.8660254f, 1 * -0.5000000f}, {0.9330127f, 0.2500000f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 34
|
||||
{{0.9396926f, 1 * -0.3420201f}, {0.9698463f, 0.3289899f}, {1.0f, 1.0f, 1.0f, 1.0f}}, // 35
|
||||
{{0.9848078f, 1 * -0.1736482f}, {0.9924039f, 0.4131759f}, {1.0f, 1.0f, 1.0f, 1.0f}} // 36
|
||||
},
|
||||
{0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8, 0, 8, 9, 0, 9, 10,
|
||||
0, 10, 11, 0, 11, 12, 0, 12, 13, 0, 13, 14, 0, 14, 15, 0, 15, 16, 0, 16, 17, 0, 17, 18, 0, 18, 19,
|
||||
@ -365,8 +292,13 @@ namespace ia::iae
|
||||
if (s_activeCamera)
|
||||
s_activeCamera->SetViewport(newWidth, newHeight);
|
||||
|
||||
g_sceneScalingFactor = {(FLOAT32) newWidth / g_sceneDesignViewport.x,
|
||||
(FLOAT32) newHeight / g_sceneDesignViewport.y};
|
||||
UpdateSceneScalingFactor();
|
||||
}
|
||||
|
||||
VOID Renderer::UpdateSceneScalingFactor()
|
||||
{
|
||||
g_sceneScalingFactor = {(FLOAT32) s_screenWidth / s_activeSceneDesignViewport.x,
|
||||
(FLOAT32) s_screenHeight / s_activeSceneDesignViewport.y};
|
||||
IAE_LOG_INFO("Updated Scene Scale Factor: (", g_sceneScalingFactor.x, ", ", g_sceneScalingFactor.y, ")");
|
||||
}
|
||||
|
||||
@ -544,4 +476,16 @@ namespace ia::iae
|
||||
{
|
||||
return (Handle) Renderer::s_circleGeometry;
|
||||
}
|
||||
|
||||
VOID Engine::SetSceneDesignViewport(IN Vec2 value)
|
||||
{
|
||||
if (!value.x || !value.y)
|
||||
{
|
||||
Renderer::s_activeSceneDesignViewport = g_sceneDesignViewport;
|
||||
Renderer::UpdateSceneScalingFactor();
|
||||
return;
|
||||
}
|
||||
Renderer::s_activeSceneDesignViewport = value;
|
||||
Renderer::UpdateSceneScalingFactor();
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -40,19 +40,20 @@ namespace ia::iae
|
||||
return writer.result;
|
||||
};
|
||||
// -----------------------------------------------
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
SceneManager::SceneManager(IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> getCustomNode,
|
||||
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource):
|
||||
m_customNodeGetter(getCustomNode), m_resourceGetter(getResource)
|
||||
SceneManager::SceneManager(
|
||||
IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> getCustomNode,
|
||||
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource)
|
||||
: m_customNodeGetter(getCustomNode), m_resourceGetter(getResource)
|
||||
{
|
||||
}
|
||||
|
||||
SceneManager::~SceneManager()
|
||||
{
|
||||
for(const auto& t: m_scenes)
|
||||
for (const auto &t : m_scenes)
|
||||
delete t->Value;
|
||||
}
|
||||
|
||||
@ -101,6 +102,21 @@ namespace ia::iae
|
||||
{
|
||||
auto t = propRoot.child("Extent");
|
||||
scene->Extent() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
|
||||
|
||||
t = propRoot.child("DesignViewport");
|
||||
if(t)
|
||||
scene->DesignViewport() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
|
||||
else
|
||||
scene->DesignViewport() = Vec2{};
|
||||
|
||||
scene->EnableOnScreenGamePad() = false;
|
||||
t = propRoot.child("GamePad");
|
||||
if(t)
|
||||
{
|
||||
const auto t2 = t.attribute("enableOnScreen");
|
||||
if(t2 && t2.as_bool())
|
||||
scene->EnableOnScreenGamePad() = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Process Nodes
|
||||
@ -110,7 +126,7 @@ namespace ia::iae
|
||||
{
|
||||
for (const auto &t : nodeRoot)
|
||||
{
|
||||
Node2D* n{};
|
||||
Node2D *n{};
|
||||
if (!strcmp(t.name(), "TextureNode"))
|
||||
{
|
||||
const auto node = MakeRefPtr<TextureNode>(Engine::GetUniqueResourceName());
|
||||
@ -125,14 +141,10 @@ namespace ia::iae
|
||||
n = node.get();
|
||||
}
|
||||
|
||||
if(!n) continue;
|
||||
if(t.attribute("X") && t.attribute("Y"))
|
||||
{
|
||||
n->SetLocalPosition({
|
||||
t.attribute("X").as_float(),
|
||||
t.attribute("Y").as_float()
|
||||
});
|
||||
}
|
||||
if (!n)
|
||||
continue;
|
||||
if (t.attribute("X") && t.attribute("Y"))
|
||||
n->SetLocalPosition({t.attribute("X").as_float(), t.attribute("Y").as_float()});
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,17 +152,23 @@ namespace ia::iae
|
||||
const auto uiRoot = sceneRoot.child("UI");
|
||||
if (!uiRoot)
|
||||
THROW_INVALID_DATA("Scene file is missing 'UI' tag");
|
||||
{
|
||||
if (uiRoot.child("CSS") && uiRoot.child("HTML"))
|
||||
{
|
||||
scene->UIMarkupStyles() = getInnerXML(uiRoot.child("CSS")).c_str();
|
||||
auto html = String(getInnerXML(uiRoot.child("HTML")).c_str());
|
||||
html =
|
||||
Utils::RegexReplaceGroups(html, "<img(.*?)src=\"(.*?)\"", [&](IN INT32 index, IN CONST String &match) {
|
||||
if(index == 1)
|
||||
html = Utils::RegexReplaceGroups(html, "<img(.*?)src=\"(.*?)\"",
|
||||
[&](IN INT32 index, IN CONST String &match) {
|
||||
if (index == 1)
|
||||
return BuildString("$H$", resources[match]);
|
||||
return match;
|
||||
});
|
||||
scene->UIMarkup() = html;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_scenes[name] = scene;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ namespace ia::iae
|
||||
{
|
||||
RefPtr<Scene> g_defaultScene;
|
||||
|
||||
Scene* WorldManager::s_activeScene{};
|
||||
Scene *WorldManager::s_activeScene{};
|
||||
|
||||
VOID WorldManager::Initialize()
|
||||
{
|
||||
@ -53,7 +53,7 @@ namespace ia::iae
|
||||
s_activeScene->FixedUpdate();
|
||||
}
|
||||
|
||||
VOID WorldManager::ChangeActiveScene(IN Scene* scene)
|
||||
VOID WorldManager::ChangeActiveScene(IN Scene *scene)
|
||||
{
|
||||
s_activeScene = scene;
|
||||
scene->OnActivate();
|
||||
@ -87,9 +87,14 @@ namespace ia::iae
|
||||
return WorldManager::GetActiveScene();
|
||||
}
|
||||
|
||||
VOID Engine::ChangeActiveScene(IN Scene* scene)
|
||||
VOID Engine::ChangeActiveScene(IN Scene *scene)
|
||||
{
|
||||
Engine::SetSceneDesignViewport(scene->DesignViewport());
|
||||
WorldManager::ChangeActiveScene(scene);
|
||||
if (scene->EnableOnScreenGamePad())
|
||||
Engine::Input_EnableOnScreenGamePad();
|
||||
else
|
||||
Engine::Input_DisableOnScreenGamePad();
|
||||
}
|
||||
|
||||
VOID Engine::AddNodeToActiveScene(IN RefPtr<INode> node)
|
||||
|
||||
@ -43,8 +43,11 @@ namespace ia::iae
|
||||
|
||||
STATIC BOOL IsPointerDown();
|
||||
STATIC Vec2 GetPointerPosition();
|
||||
|
||||
STATIC BOOL IsPointerDown(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
STATIC BOOL DidPointerClick(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
STATIC BOOL DidPointerClick(IN CONST Vec2& center, IN FLOAT32 radius);
|
||||
STATIC BOOL IsPointerDown(IN CONST Vec2& center, IN FLOAT32 radius);
|
||||
|
||||
STATIC BOOL IsKeyDown(IN InputKey key);
|
||||
STATIC BOOL WasKeyPressed(IN InputKey key);
|
||||
@ -93,6 +96,7 @@ namespace ia::iae
|
||||
|
||||
STATIC VOID OnSDLEvent(IN SDL_Event *event);
|
||||
|
||||
friend class Engine;
|
||||
friend class __Internal_Engine;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -67,6 +67,8 @@ namespace ia::iae
|
||||
|
||||
STATIC VOID OnScreenResize(IN INT32 newWidth, IN INT32 newHeight);
|
||||
|
||||
STATIC VOID UpdateSceneScalingFactor();
|
||||
|
||||
public:
|
||||
STATIC Geometry *CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices);
|
||||
STATIC VOID DestroyGeometry(IN Geometry *handle);
|
||||
@ -102,6 +104,7 @@ namespace ia::iae
|
||||
STATIC BOOL s_ySortingEnabled;
|
||||
STATIC SDL_Rect s_defaultScissor;
|
||||
STATIC SDL_GPUViewport s_defaultViewport;
|
||||
STATIC Vec2 s_activeSceneDesignViewport;
|
||||
|
||||
friend class Engine;
|
||||
};
|
||||
|
||||
@ -54,6 +54,7 @@ namespace ia::iae
|
||||
STATIC VOID DrawQuad(IN Vec2 position, IN Handle texture, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
|
||||
STATIC VOID DrawCircle(IN Vec2 position, IN Handle texture, IN FLOAT32 radius, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
|
||||
STATIC VOID DrawText(IN CONST String& text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
|
||||
STATIC VOID SetSceneDesignViewport(IN Vec2 value);
|
||||
|
||||
// Renderer State Functions
|
||||
STATIC VOID SetRenderState_Scissor(IN IVec4 rect);
|
||||
@ -107,18 +108,25 @@ namespace ia::iae
|
||||
STATIC VOID Input_SwitchModeToText();
|
||||
STATIC VOID Input_SwitchModeToAction();
|
||||
|
||||
STATIC BOOL Input_IsPointerDown();
|
||||
STATIC Vec2 Input_GetPointerPosition();
|
||||
STATIC BOOL Input_DidPointerClick(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
STATIC BOOL Input_IsPointerDown(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
|
||||
STATIC BOOL Input_IsKeyDown(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyPressed(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyReleased(IN InputKey key);
|
||||
STATIC VOID Input_SetupOnScreenGamePad();
|
||||
STATIC VOID Input_SetupKeyboardGamePad(IN InputKey axisLeft, IN InputKey axisRight, IN InputKey axisDown,
|
||||
IN InputKey axisUp, IN InputKey buttonA, IN InputKey buttonB,
|
||||
IN InputKey buttonC, IN InputKey buttonD);
|
||||
STATIC VOID Input_EnableOnScreenGamePad();
|
||||
STATIC VOID Input_DisableOnScreenGamePad();
|
||||
|
||||
STATIC BOOL Input_IsPointerDown();
|
||||
STATIC Vec2 Input_GetPointerPosition();
|
||||
|
||||
STATIC BOOL Input_DidPointerClick(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
STATIC BOOL Input_IsPointerDown(IN CONST Vec2& start, IN CONST Vec2& end);
|
||||
STATIC BOOL Input_DidPointerClick(IN CONST Vec2& center, IN FLOAT32 radius);
|
||||
STATIC BOOL Input_IsPointerDown(IN CONST Vec2& center, IN FLOAT32 radius);
|
||||
|
||||
STATIC BOOL Input_IsKeyDown(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyPressed(IN InputKey key);
|
||||
STATIC BOOL Input_WasKeyReleased(IN InputKey key);
|
||||
|
||||
STATIC BOOL Input_GetButtonA();
|
||||
STATIC BOOL Input_GetButtonB();
|
||||
STATIC BOOL Input_GetButtonC();
|
||||
@ -137,6 +145,7 @@ namespace ia::iae
|
||||
STATIC String ReadTextAsset(IN CONST String& path);
|
||||
STATIC Direction GetVectorPointingDirection(IN Vec2 v);
|
||||
STATIC Vector<UINT8> ReadBinaryAsset(IN CONST String& path);
|
||||
STATIC Vec2 CalculatePercentPosition(IN Vec2 percent);
|
||||
|
||||
// Random Functions
|
||||
STATIC FLOAT32 GetRandomFloat();
|
||||
|
||||
@ -48,18 +48,30 @@ namespace ia::iae
|
||||
return m_extent;
|
||||
}
|
||||
|
||||
Vec2& DesignViewport()
|
||||
{
|
||||
return m_designViewport;
|
||||
}
|
||||
|
||||
Color &BackgroundColor()
|
||||
{
|
||||
return m_backgroundColor;
|
||||
}
|
||||
|
||||
BOOL& EnableOnScreenGamePad()
|
||||
{
|
||||
return m_enableOnScreenGamePad;
|
||||
}
|
||||
|
||||
private:
|
||||
String m_uiMarkup{};
|
||||
String m_uiMarkupStyles{};
|
||||
IVec2 m_extent{100, 100};
|
||||
Vec2 m_designViewport{};
|
||||
CameraComponent *m_camera{};
|
||||
Color m_backgroundColor{0, 0, 0, 255};
|
||||
Map<String, RefPtr<INode>> m_nodes;
|
||||
BOOL m_enableOnScreenGamePad{false};
|
||||
|
||||
public:
|
||||
VIRTUAL VOID Draw();
|
||||
|
||||
Reference in New Issue
Block a user