mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
commit more files
This commit is contained in:
parent
bbc9af3b11
commit
a93687d2bd
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
inline bool versionFromCharArray(const char* version, int* major, int* minor,
|
inline bool VersionFromCharArray(const char* version, int* major, int* minor,
|
||||||
int* patch) {
|
int* patch) {
|
||||||
if (sscanf(version, "%d.%d.%d", major, minor, patch) != 3) {
|
if (sscanf(version, "%d.%d.%d", major, minor, patch) != 3) {
|
||||||
*major = 0;
|
*major = 0;
|
||||||
|
@ -75,7 +75,7 @@ namespace engine {
|
|||||||
RegisterResourceManager<resources::Mesh>();
|
RegisterResourceManager<resources::Mesh>();
|
||||||
|
|
||||||
// initialise the render data
|
// initialise the render data
|
||||||
render_data_.gfxdev = std::make_unique<GFXDevice>(appName, appVersion, window_->getHandle(), graphicsSettings);
|
render_data_.gfxdev = std::make_unique<GFXDevice>(appName, appVersion, window_->GetHandle(), graphicsSettings);
|
||||||
|
|
||||||
std::vector<gfx::DescriptorSetLayoutBinding> globalSetBindings;
|
std::vector<gfx::DescriptorSetLayoutBinding> globalSetBindings;
|
||||||
{
|
{
|
||||||
@ -178,12 +178,12 @@ namespace engine {
|
|||||||
auto lastTick = window_->getNanos();
|
auto lastTick = window_->getNanos();
|
||||||
|
|
||||||
// single-threaded game loop
|
// single-threaded game loop
|
||||||
while (window_->isRunning()) {
|
while (window_->IsRunning()) {
|
||||||
|
|
||||||
/* logic */
|
/* logic */
|
||||||
scene_manager_->UpdateActiveScene(window_->dt());
|
scene_manager_->UpdateActiveScene(window_->dt());
|
||||||
|
|
||||||
if(window_->getKeyPress(inputs::Key::K_F)) [[unlikely]] {
|
if(window_->GetKeyPress(inputs::Key::K_F)) [[unlikely]] {
|
||||||
window_->infoBox("fps", std::to_string(window_->getFPS()) + " fps " + std::to_string(window_->dt() * 1000.0f) + " ms");
|
window_->infoBox("fps", std::to_string(window_->getFPS()) + " fps " + std::to_string(window_->dt() * 1000.0f) + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* poll events */
|
/* poll events */
|
||||||
window_->getInputAndEvents();
|
window_->GetInputAndEvents();
|
||||||
|
|
||||||
/* fps limiter */
|
/* fps limiter */
|
||||||
if (enable_frame_limiter_) {
|
if (enable_frame_limiter_) {
|
||||||
|
@ -104,9 +104,9 @@ bool InputManager::GetDeviceButton(enum InputDevice device, int button) const
|
|||||||
{
|
{
|
||||||
switch (device) {
|
switch (device) {
|
||||||
case InputDevice::kMouse:
|
case InputDevice::kMouse:
|
||||||
return win_->getButton(static_cast<inputs::MouseButton>(button));
|
return win_->GetButton(static_cast<inputs::MouseButton>(button));
|
||||||
case InputDevice::kKeyboard:
|
case InputDevice::kKeyboard:
|
||||||
return win_->getKey(static_cast<inputs::Key>(button));
|
return win_->GetKey(static_cast<inputs::Key>(button));
|
||||||
case InputDevice::kController:
|
case InputDevice::kController:
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@ -118,9 +118,9 @@ bool InputManager::getDeviceButtonDown(enum InputDevice device, int button) cons
|
|||||||
{
|
{
|
||||||
switch (device) {
|
switch (device) {
|
||||||
case InputDevice::kMouse:
|
case InputDevice::kMouse:
|
||||||
return win_->getButtonPress(static_cast<enum inputs::MouseButton>(button));
|
return win_->GetButtonPress(static_cast<enum inputs::MouseButton>(button));
|
||||||
case InputDevice::kKeyboard:
|
case InputDevice::kKeyboard:
|
||||||
return win_->getKeyPress(static_cast<enum inputs::Key>(button));
|
return win_->GetKeyPress(static_cast<enum inputs::Key>(button));
|
||||||
case InputDevice::kController:
|
case InputDevice::kController:
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@ -132,9 +132,9 @@ bool InputManager::GetDeviceButtonUp(enum InputDevice device, int button) const
|
|||||||
{
|
{
|
||||||
switch (device) {
|
switch (device) {
|
||||||
case InputDevice::kMouse:
|
case InputDevice::kMouse:
|
||||||
return win_->getButtonRelease(static_cast<enum inputs::MouseButton>(button));
|
return win_->GetButtonRelease(static_cast<enum inputs::MouseButton>(button));
|
||||||
case InputDevice::kKeyboard:
|
case InputDevice::kKeyboard:
|
||||||
return win_->getKeyRelease(static_cast<enum inputs::Key>(button));
|
return win_->GetKeyRelease(static_cast<enum inputs::Key>(button));
|
||||||
case InputDevice::kController:
|
case InputDevice::kController:
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
|
@ -38,7 +38,7 @@ namespace engine {
|
|||||||
|
|
||||||
glm::mat4 viewMatrix = glm::inverse(cameraTransform->worldMatrix);
|
glm::mat4 viewMatrix = glm::inverse(cameraTransform->worldMatrix);
|
||||||
|
|
||||||
if (scene_->app()->window()->getWindowResized()) {
|
if (scene_->app()->window()->GetWindowResized()) {
|
||||||
uint32_t w, h;
|
uint32_t w, h;
|
||||||
m_gfx->GetViewportSize(&w, &h);
|
m_gfx->GetViewportSize(&w, &h);
|
||||||
m_viewportAspectRatio = (float)w / (float)h;
|
m_viewportAspectRatio = (float)w / (float)h;
|
||||||
|
@ -130,9 +130,9 @@ namespace engine {
|
|||||||
|
|
||||||
// get the both the engine and application versions
|
// get the both the engine and application versions
|
||||||
int appVersionMajor = 0, appVersionMinor = 0, appVersionPatch = 0;
|
int appVersionMajor = 0, appVersionMinor = 0, appVersionPatch = 0;
|
||||||
versionFromCharArray(appVersion, &appVersionMajor, &appVersionMinor, &appVersionPatch);
|
VersionFromCharArray(appVersion, &appVersionMajor, &appVersionMinor, &appVersionPatch);
|
||||||
int engineVersionMajor = 0, engineVersionMinor = 0, engineVersionPatch = 0;
|
int engineVersionMajor = 0, engineVersionMinor = 0, engineVersionPatch = 0;
|
||||||
versionFromCharArray(ENGINE_VERSION, &engineVersionMajor, &engineVersionMinor, &engineVersionPatch);
|
VersionFromCharArray(ENGINE_VERSION, &engineVersionMajor, &engineVersionMinor, &engineVersionPatch);
|
||||||
|
|
||||||
VkApplicationInfo applicationInfo{
|
VkApplicationInfo applicationInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
|
@ -171,17 +171,17 @@ namespace engine {
|
|||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
|
|
||||||
SDL_Window* Window::getHandle() const
|
SDL_Window* Window::GetHandle() const
|
||||||
{
|
{
|
||||||
return m_handle;
|
return m_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Window::getTitle() const
|
std::string Window::GetTitle() const
|
||||||
{
|
{
|
||||||
return m_title;
|
return m_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::getInputAndEvents()
|
void Window::GetInputAndEvents()
|
||||||
{
|
{
|
||||||
|
|
||||||
m_frames++;
|
m_frames++;
|
||||||
@ -197,7 +197,7 @@ namespace engine {
|
|||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
|
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
setCloseFlag();
|
SetCloseFlag();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
@ -227,53 +227,53 @@ namespace engine {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setTitle(std::string title)
|
void Window::SetTitle(std::string title)
|
||||||
{
|
{
|
||||||
SDL_SetWindowTitle(m_handle, title.c_str());
|
SDL_SetWindowTitle(m_handle, title.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::getWindowResized() const
|
bool Window::GetWindowResized() const
|
||||||
{
|
{
|
||||||
return m_justResized;
|
return m_justResized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setResizedFlag()
|
void Window::SetResizedFlag()
|
||||||
{
|
{
|
||||||
m_justResized = true;
|
m_justResized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::show()
|
void Window::Show()
|
||||||
{
|
{
|
||||||
SDL_ShowWindow(m_handle);
|
SDL_ShowWindow(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::hide()
|
void Window::Hide()
|
||||||
{
|
{
|
||||||
SDL_HideWindow(m_handle);
|
SDL_HideWindow(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::focus()
|
void Window::Focus()
|
||||||
{
|
{
|
||||||
SDL_RaiseWindow(m_handle);
|
SDL_RaiseWindow(m_handle);
|
||||||
m_keyboardFocus = true;
|
m_keyboardFocus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::hasFocus() const
|
bool Window::HasFocus() const
|
||||||
{
|
{
|
||||||
return m_keyboardFocus;
|
return m_keyboardFocus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setCloseFlag()
|
void Window::SetCloseFlag()
|
||||||
{
|
{
|
||||||
m_shouldClose = true;
|
m_shouldClose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::isRunning() const
|
bool Window::IsRunning() const
|
||||||
{
|
{
|
||||||
return !m_shouldClose;
|
return !m_shouldClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setFullscreen(bool fullscreen, bool exclusive)
|
void Window::SetFullscreen(bool fullscreen, bool exclusive)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_resizable) {
|
if (m_resizable) {
|
||||||
@ -295,17 +295,17 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::toggleFullscreen()
|
void Window::ToggleFullscreen()
|
||||||
{
|
{
|
||||||
setFullscreen(!m_fullscreen, true);
|
SetFullscreen(!m_fullscreen, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::isFullscreen() const
|
bool Window::IsFullscreen() const
|
||||||
{
|
{
|
||||||
return m_fullscreen;
|
return m_fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::setRelativeMouseMode(bool enabled)
|
bool Window::SetRelativeMouseMode(bool enabled)
|
||||||
{
|
{
|
||||||
m_mouse.captured = enabled;
|
m_mouse.captured = enabled;
|
||||||
int code = SDL_SetRelativeMouseMode(static_cast<SDL_bool>(enabled));
|
int code = SDL_SetRelativeMouseMode(static_cast<SDL_bool>(enabled));
|
||||||
@ -317,51 +317,51 @@ namespace engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::mouseCaptured()
|
bool Window::MouseCaptured()
|
||||||
{
|
{
|
||||||
return m_mouse.captured;
|
return m_mouse.captured;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting input
|
// getting input
|
||||||
|
|
||||||
bool Window::getKey(inputs::Key key) const
|
bool Window::GetKey(inputs::Key key) const
|
||||||
{
|
{
|
||||||
return m_keyboard.keys[static_cast<int>(key)];
|
return m_keyboard.keys[static_cast<int>(key)];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::getKeyPress(inputs::Key key) const
|
bool Window::GetKeyPress(inputs::Key key) const
|
||||||
{
|
{
|
||||||
return m_keyboard.deltas[static_cast<int>(key)] == ButtonDelta::PRESSED;
|
return m_keyboard.deltas[static_cast<int>(key)] == ButtonDelta::PRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::getKeyRelease(inputs::Key key) const
|
bool Window::GetKeyRelease(inputs::Key key) const
|
||||||
{
|
{
|
||||||
return m_keyboard.deltas[static_cast<int>(key)] == ButtonDelta::RELEASED;
|
return m_keyboard.deltas[static_cast<int>(key)] == ButtonDelta::RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO mouse input
|
// TODO mouse input
|
||||||
|
|
||||||
bool Window::getButton(inputs::MouseButton button) const
|
bool Window::GetButton(inputs::MouseButton button) const
|
||||||
{
|
{
|
||||||
return m_mouse.buttons[static_cast<int>(button)];
|
return m_mouse.buttons[static_cast<int>(button)];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::getButtonPress(inputs::MouseButton button) const
|
bool Window::GetButtonPress(inputs::MouseButton button) const
|
||||||
{
|
{
|
||||||
return m_mouse.deltas[static_cast<int>(button)] == ButtonDelta::PRESSED;
|
return m_mouse.deltas[static_cast<int>(button)] == ButtonDelta::PRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::getButtonRelease(inputs::MouseButton button) const
|
bool Window::GetButtonRelease(inputs::MouseButton button) const
|
||||||
{
|
{
|
||||||
return m_mouse.deltas[static_cast<int>(button)] == ButtonDelta::RELEASED;
|
return m_mouse.deltas[static_cast<int>(button)] == ButtonDelta::RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::getMouseX() const
|
int Window::GetMouseX() const
|
||||||
{
|
{
|
||||||
return static_cast<int>(m_mouse.x);
|
return static_cast<int>(m_mouse.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::getMouseY() const
|
int Window::GetMouseY() const
|
||||||
{
|
{
|
||||||
return static_cast<int>(m_mouse.y);
|
return static_cast<int>(m_mouse.y);
|
||||||
}
|
}
|
||||||
@ -453,7 +453,7 @@ namespace engine {
|
|||||||
|
|
||||||
bool Window::infoBox(const std::string& title, const std::string& msg)
|
bool Window::infoBox(const std::string& title, const std::string& msg)
|
||||||
{
|
{
|
||||||
if (isFullscreen() == false) {
|
if (IsFullscreen() == false) {
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title.c_str(), msg.c_str(), m_handle);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title.c_str(), msg.c_str(), m_handle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ void CameraControllerSystem::OnUpdate(float ts)
|
|||||||
c->dy = JUMPVEL;
|
c->dy = JUMPVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene_->app()->window()->getButton(engine::inputs::MouseButton::M_LEFT)) {
|
if (scene_->app()->window()->GetButton(engine::inputs::MouseButton::M_LEFT)) {
|
||||||
c->dy += dt * c->thrust;
|
c->dy += dt * c->thrust;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ void CameraControllerSystem::OnUpdate(float ts)
|
|||||||
|
|
||||||
/* user interface inputs */
|
/* user interface inputs */
|
||||||
|
|
||||||
if (scene_->app()->window()->getKeyPress(engine::inputs::Key::K_P)) {
|
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_P)) {
|
||||||
std::string pos_string{
|
std::string pos_string{
|
||||||
"x: " + std::to_string(t->position.x) +
|
"x: " + std::to_string(t->position.x) +
|
||||||
" y: " + std::to_string(t->position.y) +
|
" y: " + std::to_string(t->position.y) +
|
||||||
@ -158,17 +158,17 @@ void CameraControllerSystem::OnUpdate(float ts)
|
|||||||
LOG_INFO("position: " + pos_string);
|
LOG_INFO("position: " + pos_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene_->app()->window()->getKeyPress(engine::inputs::Key::K_R)) {
|
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R)) {
|
||||||
t->position = { 0.0f, 5.0f, 0.0f };
|
t->position = { 0.0f, 5.0f, 0.0f };
|
||||||
c->dy = 0.0f;
|
c->dy = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene_->app()->input_manager()->GetButtonPress("fullscreen")) {
|
if (scene_->app()->input_manager()->GetButtonPress("fullscreen")) {
|
||||||
scene_->app()->window()->toggleFullscreen();
|
scene_->app()->window()->ToggleFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene_->app()->input_manager()->GetButtonPress("exit")) {
|
if (scene_->app()->input_manager()->GetButtonPress("exit")) {
|
||||||
scene_->app()->window()->setCloseFlag();
|
scene_->app()->window()->SetCloseFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
c->justCollided = false;
|
c->justCollided = false;
|
||||||
|
@ -56,7 +56,7 @@ void playGame(GameSettings settings)
|
|||||||
app.SetFrameLimiter(settings.enableFrameLimiter);
|
app.SetFrameLimiter(settings.enableFrameLimiter);
|
||||||
|
|
||||||
// configure window
|
// configure window
|
||||||
app.window()->setRelativeMouseMode(true);
|
app.window()->SetRelativeMouseMode(true);
|
||||||
|
|
||||||
configureInputs(app.input_manager());
|
configureInputs(app.input_manager());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user