Skip to content

Commit

Permalink
Screenshot and input update, requires C++17
Browse files Browse the repository at this point in the history
* SystemEvents in KeyChecker
* ControlMenu now looks like ChasmPortable
* add remappable keys present in original portable release like center_view and weapon_next/prev
* SavesComment now contains time instead of LevelHealth
* TGAWrite modification for screenshots
* use strcasestr and strcasecmp
* switch from KeyboardState to InputState allowing other input device type states
* use char32_t instead of unsigned int for KeyCode
* allow mouse control remap
* allow rotate/wrap for msaa and pixel_size
* fix character input in window resolution video menu
* modify WriteTGA to support RGBA32 flipped input if palette equals nullptr
* add SystemEvent support to KeyChecker
* add screenshot implementation
* use timestamp for saves instead of Level and Health
* add LICENSE
* add add-on list in README.md
* allow load of addon_path without csm.bin
  • Loading branch information
Jon Daniel committed Jul 21, 2023
1 parent d9efad5 commit e4ea1ae
Show file tree
Hide file tree
Showing 30 changed files with 1,713 additions and 488 deletions.
54 changes: 49 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
# Source temporaries
*.cpp~
*.hpp~
src/.*.cpp.swp*
src/.*.hpp.swp*
src/*.cpp~
src/*.hpp~
src/common/*.cpp.swp*
src/common/*.hpp.swp*
src/common/*.cpp~
src/common/*.hpp~
src/sound/*.cpp.swp*
src/sound/*.hpp.swp*
src/sound/*.cpp~
src/sound/*.hpp~
src/server/*.cpp.swp*
src/server/*.hpp.swp*
src/server/*.cpp~
src/server/*.hpp~
src/net/*.cpp.swp*
src/net/*.hpp.swp*
src/net/*.cpp~
src/net/*.hpp~

# Windows binaries
*.exe
*.dll

*a.out
*.so

# QtCreator project user settings
*.user
Expand All @@ -20,13 +45,32 @@ build-*
*.cfg

# Game data
csm.bin
CSM.BIN
CSM.bin
csm.BIN
*.bin
*.BIN
CURSED/
CURSED/*
cursed/
cursed/*
MUSIC/
MUSIC/*
music/
music/*
ADDON1/
ADDON1/*
addon1/
addon1/*
borough/
borough/*
BOROUGH/
BOROUGH/*

# Game saves
saves/*
SAVES/*

# Screen shots
*.tga
*.TGA

# Build system
CMakeFiles/*
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.1)

project(Chasm-Reverse)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS /MP")
Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ the command option `--csm` strings, for example:

`./PanzerChasm --csm CSM_RUS.BIN`

To run the add-on, you must additionally specify the path to it through the
parameter command line `--addon`, for example:

`./PanzerChasm --addon ADDON1`

In order to execute some console command at start, use `--exec` option, for example:

`./PanzerChasm --exec "load saves/save_00.pcs"` to start game and immediately load first saved game.

#### Available add-ons:

* Chasm - The Shadow Zone: ADDON1
* Chasm - Cursed Land : cursed
* Chasm - Grim Borough : borough

To run the add-on, you must additionally specify the path to it through the
parameter command line `--addon` or `-addon`, for example:

`./PanzerChasm --addon ADDON1`

#### Control

Expand Down
75 changes: 42 additions & 33 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <chrono>
#include "../assert.hpp"
#include "../game_constants.hpp"
#include "../i_drawers_factory.hpp"
Expand All @@ -16,8 +17,9 @@
#include "i_hud_drawer.hpp"
#include "i_map_drawer.hpp"
#include "i_minimap_drawer.hpp"

#include "../key_checker.hpp"
#include "client.hpp"
#include "../common/str.hpp"

namespace PanzerChasm
{
Expand Down Expand Up @@ -138,8 +140,18 @@ void Client::Save( SaveLoadBuffer& buffer, SaveComment& out_save_comment )
for( const bool& wall_visibility : dynamic_walls_visibility )
save_stream.WriteBool( wall_visibility );

// Write comment
std::snprintf( out_save_comment.data(), sizeof(SaveComment), "Level%2d health %03d", current_map_data_->number, player_state_.health );


// Write timestamp or level/health to comment
if( StringEquals(settings_.GetString( SettingsKeys::save_comment, "time" ), "time") )
{
std::time_t timestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::snprintf( out_save_comment.data(), sizeof(SaveComment), "%s", ctime( &timestamp ) + 4);
}
else
{
std::snprintf( out_save_comment.data(), sizeof(SaveComment), "Level%2d health %03d", current_map_data_->number, player_state_.health );
}
}

void Client::Load( const SaveLoadBuffer& buffer, unsigned int& buffer_pos )
Expand Down Expand Up @@ -222,43 +234,38 @@ void Client::ProcessEvents( const SystemEvents& events )
event.event.mouse_move.dx );
}

// Select weapon.
if( event.type == SystemEvent::Type::Wheel && event.event.wheel.delta != 0 )
if( event.type == SystemEvent::Type::Key || event.type == SystemEvent::Type::MouseKey || event.type == SystemEvent::Type::Wheel)
{
if(event.event.wheel.delta > 0) TrySwitchWeaponNext();
if(event.event.wheel.delta < 0) TrySwitchWeaponPrevious();
}

if( event.type == SystemEvent::Type::MouseKey &&
event.event.mouse_key.mouse_button == SystemEvent::MouseKeyEvent::Button::Middle )
{
TrySwitchWeaponNext();
}

if( event.type == SystemEvent::Type::Key && event.event.key.pressed )
{
if( event.event.key.key_code >= KeyCode::K1 &&
static_cast<unsigned int>(event.event.key.key_code) < static_cast<unsigned int>(KeyCode::K1) + GameConstants::weapon_count )
const KeyChecker key_pressed( settings_, event );

if( key_pressed( SettingsKeys::key_weapon_next, KeyCode::MouseWheelDown ) ) TrySwitchWeaponNext();
if( key_pressed( SettingsKeys::key_weapon_prev, KeyCode::MouseWheelUp ) ) TrySwitchWeaponPrevious();
if( key_pressed( SettingsKeys::key_weapon_change, KeyCode::Mouse3 ) ) TrySwitchWeaponNext();
if( key_pressed( SettingsKeys::key_weapon_1, KeyCode::K1 ) ||
key_pressed( SettingsKeys::key_weapon_2, KeyCode::K2 ) ||
key_pressed( SettingsKeys::key_weapon_3, KeyCode::K3 ) ||
key_pressed( SettingsKeys::key_weapon_4, KeyCode::K4 ) ||
key_pressed( SettingsKeys::key_weapon_5, KeyCode::K5 ) ||
key_pressed( SettingsKeys::key_weapon_6, KeyCode::K6 ) ||
key_pressed( SettingsKeys::key_weapon_7, KeyCode::K7 ) ||
key_pressed( SettingsKeys::key_weapon_8, KeyCode::K8 ) ||
key_pressed( SettingsKeys::key_weapon_9, KeyCode::K9 ) )
{
unsigned int weapon_index=static_cast<unsigned int>( event.event.key.key_code ) - static_cast<unsigned int>( KeyCode::K1 );
if( player_state_.ammo[ weapon_index ] > 0u && ( player_state_.weapons_mask & (1u << weapon_index) ) != 0u )
requested_weapon_index_= weapon_index;
}

if( event.event.key.key_code == KeyCode::Tab )
minimap_mode_= !minimap_mode_;

if( event.event.key.key_code == KeyCode::Minus )
settings_.SetSetting( g_small_hud_mode, false );
if( event.event.key.key_code == KeyCode::Equals )
settings_.SetSetting( g_small_hud_mode, true );
if( key_pressed( SettingsKeys::key_minimap, KeyCode::Tab ) ) minimap_mode_= !minimap_mode_;
if( key_pressed( SettingsKeys::key_small_hud_off, KeyCode::Minus ) ) settings_.SetSetting( g_small_hud_mode, false );
if( key_pressed( SettingsKeys::key_small_hud_on, KeyCode::Equals ) ) settings_.SetSetting( g_small_hud_mode, true );
}
} // for events
}

void Client::Loop( const InputState& input_state, const bool paused )
{
const Time current_real_time= Time::CurrentTime();
const KeyChecker key_pressed( settings_, input_state );

// Calculate time, which we spend in pause.
// Subtract time, spended in pauses, from real time.
Expand Down Expand Up @@ -306,14 +313,16 @@ void Client::Loop( const InputState& input_state, const bool paused )

{ // Scale minimap.
const float log2_delta= 2.0f * tick_dt_s;
if( input_state.keyboard[ static_cast<unsigned int>( SystemEvent::KeyEvent::KeyCode::SquareBrackretLeft ) ] )

if( key_pressed( SettingsKeys::key_minimap_scale_dec, KeyCode::SquareBracketLeft ) )
minimap_scale_log2_-= log2_delta;
if( input_state.keyboard[ static_cast<unsigned int>( SystemEvent::KeyEvent::KeyCode::SquareBrackretRight ) ] )
if( key_pressed( SettingsKeys::key_minimap_scale_inc, KeyCode::SquareBracketRight ) )
minimap_scale_log2_+= log2_delta;

minimap_scale_log2_= std::max( -2.0f, std::min( minimap_scale_log2_, 1.0f ) );
}

camera_controller_.Tick( input_state.keyboard );
camera_controller_.Tick( input_state );

if( sound_engine_ != nullptr )
{
Expand Down Expand Up @@ -355,17 +364,17 @@ void Client::Loop( const InputState& input_state, const bool paused )
}
{ // Send move message
float move_direction, move_acceleration;
camera_controller_.GetAcceleration( input_state.keyboard, move_direction, move_acceleration );
camera_controller_.GetAcceleration( input_state, move_direction, move_acceleration );

Messages::PlayerMove message;
message.view_direction = AngleToMessageAngle( camera_controller_.GetViewAngleZ() + Constants::half_pi );
message.move_direction = AngleToMessageAngle( move_direction );
message.acceleration = static_cast<unsigned char>( move_acceleration * 254.5f );
message.jump_pressed = input_state.mouse[ static_cast<unsigned int>( SystemEvent::MouseKeyEvent::Button::Right ) ] || camera_controller_.JumpPressed();
message.jump_pressed = key_pressed( SettingsKeys::key_jump, KeyCode::Mouse2 ) || camera_controller_.JumpPressed();
message.weapon_index = requested_weapon_index_;
message.view_dir_angle_x = AngleToMessageAngle( camera_controller_.GetViewAngleX() );
message.view_dir_angle_z = AngleToMessageAngle( camera_controller_.GetViewAngleZ() );
message.shoot_pressed = input_state.mouse[ static_cast<unsigned int>( SystemEvent::MouseKeyEvent::Button::Left ) ];
message.shoot_pressed = key_pressed( SettingsKeys::key_fire, KeyCode::Mouse1 );
message.color = settings_.GetOrSetInt( SettingsKeys::player_color );
connection_info_->messages_sender.SendUnreliableMessage( message );
}
Expand Down
Loading

0 comments on commit e4ea1ae

Please sign in to comment.