30static std::random_device
rd;
32static std::uniform_real_distribution<float>
shakeDist(-1.0f, 1.0f);
81 catch (
const std::exception&
e)
83 std::cerr <<
"CameraSystem Error for Entity " << entity <<
": " <<
e.what() <<
"\n";
116 cam.targetZoom = 1.0f;
117 cam.currentZoomLevelIndex = 3;
119 cam.targetRotation = 0.0f;
120 cam.currentRotationLevel = 0;
128 cam.viewportRect = viewportRect;
139 target.smoothFactor = 5.0f;
140 target.allowManualControl =
true;
141 target.manualControlDecay = 2.0f;
148 effects.shakeTimeRemaining = 0.0f;
221 binding.joystickId = joystickId;
246 target.followTarget =
true;
266 target.followTarget =
false;
290 binding.resetRequested =
false;
309 if (
binding.inputDirection.x != 0.0f ||
binding.inputDirection.y != 0.0f)
331 cam.currentZoomLevelIndex++;
339 if (
cam.currentZoomLevelIndex > 0)
341 cam.currentZoomLevelIndex--;
343 SYSTEM_LOG <<
"Zoom out to level " <<
cam.targetZoom <<
"\n";
349 if (
binding.rotationInput != 0.0f)
351 if (
binding.rotationInput > 0.0f)
356 SYSTEM_LOG <<
"Rotate clockwise to " <<
cam.targetRotation <<
"°\n";
363 SYSTEM_LOG <<
"Rotate counter-clockwise to " <<
cam.targetRotation <<
"°\n";
380 Vector direction(0.f, 0.f, 0.f);
388 else if (
kb.IsKeyHeld(
binding.key_up_right))
393 else if (
kb.IsKeyHeld(
binding.key_down_left))
398 else if (
kb.IsKeyHeld(
binding.key_down_right))
417 if (direction.
x != 0.0f && direction.
y != 0.0f)
419 float length = std::sqrt(direction.
x * direction.
x + direction.
y * direction.
y);
428 if (
kb.IsKeyPressed(
binding.key_rotate_left))
430 if (
kb.IsKeyPressed(
binding.key_rotate_right))
434 if (
kb.IsKeyPressed(
binding.key_zoom_in))
436 if (
kb.IsKeyPressed(
binding.key_zoom_out))
443 SYSTEM_LOG <<
"Camera reset requested (numpad 5)\n";
452 if (!
joy.IsJoystickConnected(
binding.joystickId))
486 SYSTEM_LOG <<
"Camera reset requested (joystick button " <<
binding.button_reset <<
")\n";
493 if (std::abs(value) < deadzone)
497 float sign = (value > 0.0f) ? 1.0f : -1.0f;
546 cam.controlOffset =
Vector(0.f, 0.f, 0.f);
554 if (
target.allowManualControl &&
target.manualControlDecay > 0.0f)
560 if (
cam.controlOffset.Length() < 0.1f)
562 cam.controlOffset =
Vector(0.f, 0.f, 0.f);
577 if (std::abs(
cam.zoom -
cam.targetZoom) > 0.01f)
584 cam.zoom =
cam.targetZoom;
600 while (
diff > 180.0f)
diff -= 360.0f;
601 while (
diff < -180.0f)
diff += 360.0f;
604 if (std::abs(
diff) > 1.0f)
609 while (
cam.rotation > 360.0f)
cam.rotation -= 360.0f;
610 while (
cam.rotation < -360.0f)
cam.rotation += 360.0f;
615 cam.rotation =
cam.targetRotation;
636 if (
effects.shakeTimeRemaining <= 0.0f)
641 effects.shakeTimeRemaining = 0.0f;
708 cam.currentZoomLevelIndex = 3;
710 cam.targetZoom = 1.0f;
713 cam.currentRotationLevel = 0;
715 cam.targetRotation = 0.0f;
726 SYSTEM_LOG <<
"Camera " << entity <<
" resuming target follow\n";
742 effects.shakeTimeRemaining = 0.0f;
745 SYSTEM_LOG <<
"Camera " << entity <<
" controls reset (zoom=1.0, rotation=0.0, following="
786 static_cast<int>(
cam.viewportRect.x),
787 static_cast<int>(
cam.viewportRect.y),
788 static_cast<int>(
cam.viewportRect.w),
789 static_cast<int>(
cam.viewportRect.h)
813 SYSTEM_LOG <<
"Auto-created ECS camera for player " <<
playerID <<
" (event-driven)\n";
821 switch (
msg.msg_type)
827 cam.position.y =
msg.param2;
832 cam.targetZoom =
msg.param1;
833 cam.targetZoom = std::max(
cam.minZoom, std::min(
cam.maxZoom,
cam.targetZoom));
840 cam.targetRotation =
msg.param1;
Core ECS component definitions.
ComponentTypeID GetComponentTypeID_Static()
const EntityID INVALID_ENTITY_ID
static std::uniform_real_distribution< float > shakeDist(-1.0f, 1.0f)
static std::mt19937 gen(rd())
static std::random_device rd
static SDL_Renderer * renderer
World and ECS Manager for Olympe Engine.
void BindCameraToJoystick(EntityID cameraEntity, short playerID, SDL_JoystickID joystickId)
EntityID GetCameraEntityForPlayer(short playerID)
EntityID CreateCameraForPlayer(short playerID, bool bindToKeyboard=false)
void BindCameraToKeyboard(EntityID cameraEntity)
void ProcessJoystickInput(EntityID entity, CameraInputBinding_data &binding)
void UpdateCameraFollow(EntityID entity, float dt)
void ClearCameraTarget(EntityID cameraEntity)
virtual void Process() override
void OnEvent(const Message &msg)
void ApplyCameraBounds(EntityID entity)
float ApplyDeadzone(float value, float deadzone)
void ApplyCameraToRenderer(SDL_Renderer *renderer, short playerID)
void SetCameraTarget_ECS(EntityID cameraEntity, EntityID targetEntity)
void UpdateCameraRotation(EntityID entity, float dt)
void ProcessKeyboardInput(EntityID entity, CameraInputBinding_data &binding)
void SyncZoomLevelIndex(Camera_data &cam)
void UnbindCameraKeyboard(EntityID cameraEntity)
std::unordered_map< short, EntityID > m_playerCameras
void ResetCameraControls(EntityID entity)
virtual void Render() override
void UpdateCameraInput(EntityID entity, float dt)
void RemoveCameraForPlayer(short playerID)
EntityID m_defaultKeyboardCamera
void UpdateCameraShake(EntityID entity, float dt)
void UpdateCameraZoom(EntityID entity, float dt)
std::set< EntityID > m_entities
ComponentSignature requiredSignature
static int screenWidth
Screen width in pixels.
static float fDt
Delta time between frames in seconds.
static int screenHeight
Screen height in pixels.
static JoystickManager & Get()
static KeyboardManager & Get()
static ViewportManager & Get()
static World & Get()
Get singleton instance (short form)
T & AddComponent(EntityID entity, Args &&... args)
bool HasComponent(EntityID entity) const
bool IsEntityValid(EntityID entity) const
T & GetComponent(EntityID entity)
void DestroyEntity(EntityID entity)
static constexpr int ROTATION_LEVELS
static constexpr float ZOOM_LEVELS[]
CameraControlMode controlMode
static constexpr float GetRotationFromLevel(int level)
static constexpr size_t ZOOM_LEVEL_COUNT
Position component for spatial location.
Vector position
2D/3D position vector
@ Olympe_EventType_Camera_Mode_2D
@ Olympe_EventType_Camera_RotateTo
@ Olympe_EventType_Camera_Teleport
@ Olympe_EventType_Camera_MoveToPosition
@ Olympe_EventType_Camera_ZoomTo
@ Olympe_EventType_Camera_Mode_2_5D
@ Olympe_EventType_Camera_Reset
@ Olympe_EventType_Camera_Target_Unfollow
@ Olympe_EventType_Camera_Target_Follow
@ Olympe_EventType_Camera_Mode_Isometric
@ Olympe_EventType_Camera_Shake
Vector vBlend(Vector &_v1, Vector &_v2, float _fc)