Skip to content

Commit

Permalink
editor mode switch with pressing P
Browse files Browse the repository at this point in the history
  • Loading branch information
YasirNacak committed Oct 22, 2018
1 parent 5e4de95 commit 498a4f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
12 changes: 11 additions & 1 deletion src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace s3d {
bool Engine::Initialize(HINSTANCE hInstance, std::string windowTitle, std::string windowClass, int width, int height)
{
_keyboard.DisableAutoRepeatChars();
_keyboard.DisableAutoRepeatKeys();
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);

Expand All @@ -13,6 +13,8 @@ namespace s3d {

_timer.Start();

IsInDebugMode = false;

if(!this->_renderWindow.Initialize(
this,
hInstance,
Expand Down Expand Up @@ -42,6 +44,9 @@ namespace s3d {
float dt = static_cast<float>(_timer.GetMillisecondsElapsed());
_timer.Restart();

_entityManager.Refresh();
_entityManager.Update(dt);

while(!_keyboard.IsCharBufferEmpty())
{
const auto ch = _keyboard.ReadChar();
Expand All @@ -51,6 +56,11 @@ namespace s3d {
{
auto kbe = _keyboard.ReadKey();
const auto keycode = kbe.GetKeyCode();

if(keycode == '0' && kbe.IsPress())
{
IsInDebugMode = !IsInDebugMode;
}
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace s3d {

void ShowDebugPanels();

bool IsInDebugMode;

private:
utility::Timer _timer;
entitysystem::Manager _entityManager;
Expand Down
37 changes: 24 additions & 13 deletions src/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,33 @@ namespace s3d { namespace graphics {

this->_deviceContext->DrawIndexed(_indexBuffer.GetBufferSize(), 0, 0);
}
#if _DEBUG
static int fpsCounter = 0;
static std::string fpsString = "FPS: 0";
fpsCounter += 1;
if (_fpsTimer.GetMillisecondsElapsed() > 1000.0)
if(engine.IsInDebugMode)
{
fpsString = "FPS: " + std::to_string(fpsCounter);
fpsCounter = 0;
_fpsTimer.Restart();
static int fpsCounter = 0;
static std::string fpsString = "FPS: 0";
fpsCounter += 1;

if (_fpsTimer.GetMillisecondsElapsed() > 1000.0)
{
fpsString = "FPS: " + std::to_string(fpsCounter);
fpsCounter = 0;
_fpsTimer.Restart();
}

engine.ShowDebugPanels();

_spriteBatch->Begin();
_spriteFont->DrawString(
_spriteBatch.get(),
utility::StringConverter::StringToWide(fpsString).c_str(),
DirectX::XMFLOAT2(_windowWidth - 100, -2.5f),
DirectX::Colors::White, 0.0f,
DirectX::XMFLOAT2(0.0f, 0.0f),
DirectX::XMFLOAT2(1.0f, 1.0f));
_spriteBatch->End();
}
engine.ShowDebugPanels();
#endif

_spriteBatch->Begin();
#if _DEBUG
_spriteFont->DrawString(_spriteBatch.get(), utility::StringConverter::StringToWide(fpsString).c_str(), DirectX::XMFLOAT2(_windowWidth - 100, 0), DirectX::Colors::Lime, 0.0f, DirectX::XMFLOAT2(0.0f, 0.0f), DirectX::XMFLOAT2(1.0f, 1.0f));
#endif
_spriteBatch->End();

this->_swapChain->Present(0, NULL);
Expand Down

1 comment on commit 498a4f4

@YasirNacak
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, it is actually pressing 0

Please sign in to comment.