Skip to content

Commit

Permalink
Add Game::isNoCrosshairAllowed()
Browse files Browse the repository at this point in the history
The rule about allowing no crosshair is moved into a method.
The (X, Y) calculation for updating shootline when using crosshair is removed for a specific case.
  • Loading branch information
srifqi committed Sep 21, 2022
1 parent c04a418 commit 0b5cc38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ class Game {
#ifdef HAVE_TOUCHSCREENGUI
bool m_cache_hold_aux1;
bool m_touch_use_crosshair;
inline bool isNoCrosshairAllowed() {
return !m_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST;
}
#endif
#ifdef __ANDROID__
bool m_android_chat_open;
Expand Down Expand Up @@ -3094,8 +3097,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
shootline.end = shootline.start + camera_direction * BS * d;

#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui && !m_touch_use_crosshair &&
camera->getCameraMode() == CAMERA_MODE_FIRST) {
if (g_touchscreengui && isNoCrosshairAllowed()) {
shootline = g_touchscreengui->getShootline();
// Scale shootline to the acual distance the player can reach
shootline.end = shootline.start +
Expand Down Expand Up @@ -3993,7 +3995,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
(camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
#ifdef HAVE_TOUCHSCREENGUI
if (!m_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST)
if (isNoCrosshairAllowed())
draw_crosshair = false;
#endif
m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud,
Expand Down
5 changes: 1 addition & 4 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);

// update shootline
if (m_draw_crosshair) {
X = m_screensize.X / 2;
Y = m_screensize.Y / 2;
}
// no need to update (X, Y) when using crosshair since the shootline is not used
m_shootline = m_device
->getSceneManager()
->getSceneCollisionManager()
Expand Down

0 comments on commit 0b5cc38

Please sign in to comment.