farmlands/src/components/DebugController.cpp

70 lines
1.3 KiB
C++

/*
* DebugController.cpp
*
* Created on: Nov 30, 2016
* Author: tibi
*/
#include <GameState.h>
#include <components/basic/Camera.h>
#include <components/DebugController.h>
#include <input/Input.h>
#include <iostream>
using namespace farmlands::input;
namespace farmlands {
namespace components {
static const float ScaleVelocity = 0.5f;
static const float ScaleShiftVelocity = 2.0f;
DebugController::DebugController()
: m_camera(nullptr)
{
}
DebugController::~DebugController()
{
}
model::Component* DebugController::clone()
{
return new DebugController();
}
void DebugController::onInitialize()
{
m_camera = GameState::current().renderContext.camera();
}
void DebugController::onUpdateLogic()
{
// Compute velocity
float vel = ScaleVelocity;
if (Input::instance().pressed(GameKey::Run))
vel = ScaleShiftVelocity;
// Time independent
vel *= GameState::current().elapsedTime;
if (Input::instance().pressed(GameKey::Debug_ZoomIn))
m_camera->scale *= 1 + vel;
if (Input::instance().pressed(GameKey::Debug_ZoomOut))
m_camera->scale *= 1 - vel;
}
void DebugController::dump(unsigned level)
{
for (unsigned i = 0; i < level; i++)
std::cout<<" ";
std::cout << " .Component: DebugController\n";
}
} /* namespace controller */
} /* namespace farmlands */