Skip to content

Commit 35e84a6

Browse files
author
Jon Daniel
committed
Screenshot and Input update, requires C++17
* SystemEvents in KeyChecker * ControlMenu now looks like ChasmPortable >=1.05 weapon_prev/next * SavesComment now contains time instead of LevelHealth * TGAWrite modification for screenshots
1 parent d9efad5 commit 35e84a6

25 files changed

Lines changed: 1475 additions & 346 deletions

.gitignore

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Windows binaries
22
*.exe
33
*.dll
4-
4+
*a.out
5+
*.so
56

67
# QtCreator project user settings
78
*.user
@@ -20,13 +21,32 @@ build-*
2021
*.cfg
2122

2223
# Game data
23-
csm.bin
24-
CSM.BIN
25-
CSM.bin
26-
csm.BIN
24+
*.bin
25+
*.BIN
26+
CURSED/
27+
CURSED/*
28+
cursed/
29+
cursed/*
30+
MUSIC/
31+
MUSIC/*
32+
music/
33+
music/*
34+
ADDON1/
35+
ADDON1/*
36+
addon1/
37+
addon1/*
38+
borough/
39+
borough/*
40+
BOROUGH/
41+
BOROUGH/*
2742

2843
# Game saves
2944
saves/*
45+
SAVES/*
46+
47+
# Screen shots
48+
*.tga
49+
*.TGA
3050

3151
# Build system
3252
CMakeFiles/*

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)
22

33
project(Chasm-Reverse)
44

5-
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD 17)
66

77
if(MSVC)
88
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS /MP")

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@ the command option `--csm` strings, for example:
5252

5353
`./PanzerChasm --csm CSM_RUS.BIN`
5454

55-
To run the add-on, you must additionally specify the path to it through the
56-
parameter command line `--addon`, for example:
57-
58-
`./PanzerChasm --addon ADDON1`
59-
6055
In order to execute some console command at start, use `--exec` option, for example:
6156

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

59+
#### Available add-ons:
60+
61+
* Chasm - The Shadow Zone: ADDON1
62+
* Chasm - Cursed Land : cursed
63+
* Chasm - Grim Borough : borough
64+
65+
To run the add-on, you must additionally specify the path to it through the
66+
parameter command line `--addon` or `-addon`, for example:
67+
68+
`./PanzerChasm --addon ADDON1`
6469

6570
#### Control
6671

src/client/client.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <chrono>
12
#include "../assert.hpp"
23
#include "../game_constants.hpp"
34
#include "../i_drawers_factory.hpp"
@@ -16,7 +17,7 @@
1617
#include "i_hud_drawer.hpp"
1718
#include "i_map_drawer.hpp"
1819
#include "i_minimap_drawer.hpp"
19-
20+
#include "../key_checker.hpp"
2021
#include "client.hpp"
2122

2223
namespace PanzerChasm
@@ -138,8 +139,11 @@ void Client::Save( SaveLoadBuffer& buffer, SaveComment& out_save_comment )
138139
for( const bool& wall_visibility : dynamic_walls_visibility )
139140
save_stream.WriteBool( wall_visibility );
140141

142+
143+
std::time_t timestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
144+
141145
// Write comment
142-
std::snprintf( out_save_comment.data(), sizeof(SaveComment), "Level%2d health %03d", current_map_data_->number, player_state_.health );
146+
std::snprintf( out_save_comment.data(), sizeof(SaveComment), "%s", ctime( &timestamp ) + 4);
143147
}
144148

145149
void Client::Load( const SaveLoadBuffer& buffer, unsigned int& buffer_pos )
@@ -222,43 +226,38 @@ void Client::ProcessEvents( const SystemEvents& events )
222226
event.event.mouse_move.dx );
223227
}
224228

225-
// Select weapon.
226-
if( event.type == SystemEvent::Type::Wheel && event.event.wheel.delta != 0 )
227-
{
228-
if(event.event.wheel.delta > 0) TrySwitchWeaponNext();
229-
if(event.event.wheel.delta < 0) TrySwitchWeaponPrevious();
230-
}
231-
232-
if( event.type == SystemEvent::Type::MouseKey &&
233-
event.event.mouse_key.mouse_button == SystemEvent::MouseKeyEvent::Button::Middle )
229+
if( event.type == SystemEvent::Type::Key || event.type == SystemEvent::Type::MouseKey || event.type == SystemEvent::Type::Wheel)
234230
{
235-
TrySwitchWeaponNext();
236-
}
237-
238-
if( event.type == SystemEvent::Type::Key && event.event.key.pressed )
239-
{
240-
if( event.event.key.key_code >= KeyCode::K1 &&
241-
static_cast<unsigned int>(event.event.key.key_code) < static_cast<unsigned int>(KeyCode::K1) + GameConstants::weapon_count )
231+
const KeyChecker key_pressed( settings_, event );
232+
233+
if( key_pressed( SettingsKeys::key_weapon_next, KeyCode::MouseWheelDown ) ) TrySwitchWeaponNext();
234+
if( key_pressed( SettingsKeys::key_weapon_prev, KeyCode::MouseWheelUp ) ) TrySwitchWeaponPrevious();
235+
if( key_pressed( SettingsKeys::key_weapon_change, KeyCode::Mouse3 ) ) TrySwitchWeaponNext();
236+
if( key_pressed( SettingsKeys::key_weapon_1, KeyCode::K1 ) ||
237+
key_pressed( SettingsKeys::key_weapon_2, KeyCode::K2 ) ||
238+
key_pressed( SettingsKeys::key_weapon_3, KeyCode::K3 ) ||
239+
key_pressed( SettingsKeys::key_weapon_4, KeyCode::K4 ) ||
240+
key_pressed( SettingsKeys::key_weapon_5, KeyCode::K5 ) ||
241+
key_pressed( SettingsKeys::key_weapon_6, KeyCode::K6 ) ||
242+
key_pressed( SettingsKeys::key_weapon_7, KeyCode::K7 ) ||
243+
key_pressed( SettingsKeys::key_weapon_8, KeyCode::K8 ) ||
244+
key_pressed( SettingsKeys::key_weapon_9, KeyCode::K9 ) )
242245
{
243246
unsigned int weapon_index=static_cast<unsigned int>( event.event.key.key_code ) - static_cast<unsigned int>( KeyCode::K1 );
244247
if( player_state_.ammo[ weapon_index ] > 0u && ( player_state_.weapons_mask & (1u << weapon_index) ) != 0u )
245248
requested_weapon_index_= weapon_index;
246249
}
247-
248-
if( event.event.key.key_code == KeyCode::Tab )
249-
minimap_mode_= !minimap_mode_;
250-
251-
if( event.event.key.key_code == KeyCode::Minus )
252-
settings_.SetSetting( g_small_hud_mode, false );
253-
if( event.event.key.key_code == KeyCode::Equals )
254-
settings_.SetSetting( g_small_hud_mode, true );
250+
if( key_pressed( SettingsKeys::key_minimap, KeyCode::Tab ) ) minimap_mode_= !minimap_mode_;
251+
if( key_pressed( SettingsKeys::key_small_hud_off, KeyCode::Minus ) ) settings_.SetSetting( g_small_hud_mode, false );
252+
if( key_pressed( SettingsKeys::key_small_hud_on, KeyCode::Equals ) ) settings_.SetSetting( g_small_hud_mode, true );
255253
}
256254
} // for events
257255
}
258256

259257
void Client::Loop( const InputState& input_state, const bool paused )
260258
{
261259
const Time current_real_time= Time::CurrentTime();
260+
const KeyChecker key_pressed( settings_, input_state );
262261

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

307306
{ // Scale minimap.
308307
const float log2_delta= 2.0f * tick_dt_s;
309-
if( input_state.keyboard[ static_cast<unsigned int>( SystemEvent::KeyEvent::KeyCode::SquareBrackretLeft ) ] )
308+
309+
if( key_pressed( SettingsKeys::key_minimap_scale_dec, KeyCode::SquareBracketLeft ) )
310310
minimap_scale_log2_-= log2_delta;
311-
if( input_state.keyboard[ static_cast<unsigned int>( SystemEvent::KeyEvent::KeyCode::SquareBrackretRight ) ] )
311+
if( key_pressed( SettingsKeys::key_minimap_scale_inc, KeyCode::SquareBracketRight ) )
312312
minimap_scale_log2_+= log2_delta;
313+
313314
minimap_scale_log2_= std::max( -2.0f, std::min( minimap_scale_log2_, 1.0f ) );
314315
}
315316

316-
camera_controller_.Tick( input_state.keyboard );
317+
camera_controller_.Tick( input_state );
317318

318319
if( sound_engine_ != nullptr )
319320
{
@@ -355,17 +356,17 @@ void Client::Loop( const InputState& input_state, const bool paused )
355356
}
356357
{ // Send move message
357358
float move_direction, move_acceleration;
358-
camera_controller_.GetAcceleration( input_state.keyboard, move_direction, move_acceleration );
359+
camera_controller_.GetAcceleration( input_state, move_direction, move_acceleration );
359360

360361
Messages::PlayerMove message;
361362
message.view_direction = AngleToMessageAngle( camera_controller_.GetViewAngleZ() + Constants::half_pi );
362363
message.move_direction = AngleToMessageAngle( move_direction );
363364
message.acceleration = static_cast<unsigned char>( move_acceleration * 254.5f );
364-
message.jump_pressed = input_state.mouse[ static_cast<unsigned int>( SystemEvent::MouseKeyEvent::Button::Right ) ] || camera_controller_.JumpPressed();
365+
message.jump_pressed = key_pressed( SettingsKeys::key_jump, KeyCode::Mouse2 ) || camera_controller_.JumpPressed();
365366
message.weapon_index = requested_weapon_index_;
366367
message.view_dir_angle_x = AngleToMessageAngle( camera_controller_.GetViewAngleX() );
367368
message.view_dir_angle_z = AngleToMessageAngle( camera_controller_.GetViewAngleZ() );
368-
message.shoot_pressed = input_state.mouse[ static_cast<unsigned int>( SystemEvent::MouseKeyEvent::Button::Left ) ];
369+
message.shoot_pressed = key_pressed( SettingsKeys::key_fire, KeyCode::Mouse1 );
369370
message.color = settings_.GetOrSetInt( SettingsKeys::player_color );
370371
connection_info_->messages_sender.SendUnreliableMessage( message );
371372
}

src/client/movement_controller.cpp

Lines changed: 53 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,23 @@
33
#include "game_constants.hpp"
44
#include "settings.hpp"
55
#include "shared_settings_keys.hpp"
6-
76
#include "movement_controller.hpp"
7+
#include "../key_checker.hpp"
88

99
namespace PanzerChasm
1010
{
1111

1212
static const float g_z_near= 1.0f / 12.0f; // Must be greater, then z_near in software rasterizer.
1313

14-
using KeyCode= SystemEvent::KeyEvent::KeyCode;
15-
16-
class KeyChecker
17-
{
18-
public:
19-
KeyChecker( Settings& settings, const KeyboardState& keyboard_state )
20-
: settings_(settings), keyboard_state_(keyboard_state)
21-
{}
22-
23-
bool operator()( const char* const key_setting_name, const KeyCode default_value ) const
24-
{
25-
const KeyCode key= static_cast<KeyCode>( settings_.GetOrSetInt( key_setting_name, static_cast<int>(default_value) ) );
26-
if( key > KeyCode::Unknown && key < KeyCode::KeyCount )
27-
return keyboard_state_[ static_cast<unsigned int>( key ) ];
28-
return false;
29-
}
30-
31-
private:
32-
Settings& settings_;
33-
const KeyboardState& keyboard_state_;
34-
};
35-
3614
MovementController::MovementController(
3715
Settings& settings,
3816
const m_Vec3& angle,
3917
float aspect )
4018
: settings_( settings )
4119
, angle_(angle), aspect_(aspect)
4220
, speed_(0.0f)
21+
, mouse_look_( settings_.GetOrSetBool( SettingsKeys::perm_mlook, true ) )
22+
, mouse_look_pressed_( false )
4323
, start_tick_( Time::CurrentTime() )
4424
, prev_calc_tick_( Time::CurrentTime() )
4525
{
@@ -65,28 +45,32 @@ void MovementController::UpdateParams()
6545
ClipCameraAngles();
6646
}
6747

68-
void MovementController::Tick( const KeyboardState& keyboard_state )
48+
void MovementController::Tick( const InputState& input_state )
6949
{
7050
const Time new_tick= Time::CurrentTime();
7151

7252
const float dt_s= ( new_tick - prev_calc_tick_ ).ToSeconds();
7353

7454
prev_calc_tick_= new_tick;
7555

76-
const KeyChecker key_pressed( settings_,keyboard_state );
56+
const KeyChecker key_pressed( settings_, input_state );
7757

7858
m_Vec3 rotate_vec( 0.0f ,0.0f, 0.0f );
79-
if( key_pressed( SettingsKeys::key_turn_left , KeyCode::Left ) ) rotate_vec.z+= +1.0f;
80-
if( key_pressed( SettingsKeys::key_turn_right, KeyCode::Right ) ) rotate_vec.z+= -1.0f;
81-
if( key_pressed( SettingsKeys::key_look_up , KeyCode::Up ) ) rotate_vec.x+= +1.0f;
82-
if( key_pressed( SettingsKeys::key_look_down , KeyCode::Down ) ) rotate_vec.x+= -1.0f;
59+
60+
if( key_pressed( SettingsKeys::key_perm_mlook, KeyCode::E ) ) mouse_look_ = !mouse_look_;
61+
if( key_pressed( SettingsKeys::key_turn_left , KeyCode::KP4 ) ) rotate_vec.z+= +1.0f;
62+
if( key_pressed( SettingsKeys::key_turn_right , KeyCode::KP6 ) ) rotate_vec.z+= -1.0f;
63+
if( key_pressed( SettingsKeys::key_look_up , KeyCode::KP8 ) ) rotate_vec.x+= +1.0f;
64+
if( key_pressed( SettingsKeys::key_look_down , KeyCode::KP2 ) ) rotate_vec.x+= -1.0f;
65+
if( key_pressed( SettingsKeys::key_center_view, KeyCode::KP5 ) ) angle_.x = 0.0f;
8366

8467
const float rot_speed= 1.75f;
8568
angle_+= dt_s * rot_speed * rotate_vec;
86-
69+
8770
ClipCameraAngles();
8871

89-
jump_pressed_= key_pressed( SettingsKeys::key_jump, KeyCode::Space );
72+
jump_pressed_= key_pressed( SettingsKeys::key_jump, KeyCode::Mouse2 );
73+
mouse_look_pressed_ = key_pressed( SettingsKeys::key_temp_mlook, KeyCode::Q );
9074
}
9175

9276
void MovementController::SetSpeed( const float speed )
@@ -101,12 +85,12 @@ void MovementController::SetAngles( float z_angle, float x_angle )
10185
}
10286

10387
void MovementController::GetAcceleration(
104-
const KeyboardState& keyboard_state,
88+
const InputState& input_state,
10589
float& out_dir, float& out_acceleration ) const
10690
{
10791
m_Vec3 move_vector(0.0f,0.0f,0.0f);
10892

109-
const KeyChecker key_pressed( settings_,keyboard_state );
93+
const KeyChecker key_pressed( settings_,input_state );
11094

11195
if( key_pressed( SettingsKeys::key_forward , KeyCode::W ) ) move_vector.y+= +1.0f;
11296
if( key_pressed( SettingsKeys::key_backward , KeyCode::S ) ) move_vector.y+= -1.0f;
@@ -265,41 +249,44 @@ bool MovementController::JumpPressed() const
265249

266250
void MovementController::ControllerRotate( const int delta_x, const int delta_z )
267251
{
268-
float base_sensetivity= settings_.GetOrSetFloat( SettingsKeys::mouse_sensetivity, 0.5f );
269-
base_sensetivity= std::max( 0.0f, std::min( base_sensetivity, 1.0f ) );
270-
settings_.SetSetting( SettingsKeys::mouse_sensetivity, base_sensetivity );
271-
272-
float d_x_f, d_z_f;
273-
if( settings_.GetOrSetBool( "cl_mouse_filter", true ) )
252+
if( ( mouse_look_pressed_ && !mouse_look_ ) || ( !mouse_look_pressed_ && mouse_look_) )
274253
{
275-
d_x_f= float( delta_x + prev_controller_delta_x_ ) * 0.5f;
276-
d_z_f= float( delta_z + prev_controller_delta_z_ ) * 0.5f;
254+
float base_sensetivity= settings_.GetOrSetFloat( SettingsKeys::mouse_sensetivity, 0.5f );
255+
base_sensetivity= std::max( 0.0f, std::min( base_sensetivity, 1.0f ) );
256+
settings_.SetSetting( SettingsKeys::mouse_sensetivity, base_sensetivity );
257+
258+
float d_x_f, d_z_f;
259+
if( settings_.GetOrSetBool( "cl_mouse_filter", true ) )
260+
{
261+
d_x_f= float( delta_x + prev_controller_delta_x_ ) * 0.5f;
262+
d_z_f= float( delta_z + prev_controller_delta_z_ ) * 0.5f;
263+
}
264+
else
265+
{
266+
d_x_f= float(delta_x);
267+
d_z_f= float(delta_z);
268+
}
269+
270+
if( settings_.GetOrSetBool( "cl_mouse_acceleration", true ) )
271+
{
272+
const float c_acceleration= 0.25f;
273+
const float c_max_acceleration_factor= 2.0f;
274+
d_x_f= std::min( c_acceleration * std::sqrt(std::abs(d_x_f)), c_max_acceleration_factor ) * d_x_f;
275+
d_z_f= std::min( c_acceleration * std::sqrt(std::abs(d_z_f)), c_max_acceleration_factor ) * d_z_f;
276+
}
277+
278+
const float c_max_exp_sensetivity= 8.0f;
279+
const float exp_sensetivity= std::exp( base_sensetivity * std::log(c_max_exp_sensetivity) ); // [ 1; c_max_exp_sensetivity ]
280+
281+
const float c_pix_scale= 1.0f / 1024.0f;
282+
const float z_direction= settings_.GetOrSetBool( SettingsKeys::reverse_mouse ) ? -1.0f : +1.0f;
283+
284+
angle_.x-= exp_sensetivity * c_pix_scale * d_x_f * z_direction;
285+
angle_.z-= exp_sensetivity * c_pix_scale * d_z_f * 0.5f;
286+
287+
prev_controller_delta_x_= delta_x;
288+
prev_controller_delta_z_= delta_z;
277289
}
278-
else
279-
{
280-
d_x_f= float(delta_x);
281-
d_z_f= float(delta_z);
282-
}
283-
284-
if( settings_.GetOrSetBool( "cl_mouse_acceleration", true ) )
285-
{
286-
const float c_acceleration= 0.25f;
287-
const float c_max_acceleration_factor= 2.0f;
288-
d_x_f= std::min( c_acceleration * std::sqrt(std::abs(d_x_f)), c_max_acceleration_factor ) * d_x_f;
289-
d_z_f= std::min( c_acceleration * std::sqrt(std::abs(d_z_f)), c_max_acceleration_factor ) * d_z_f;
290-
}
291-
292-
const float c_max_exp_sensetivity= 8.0f;
293-
const float exp_sensetivity= std::exp( base_sensetivity * std::log(c_max_exp_sensetivity) ); // [ 1; c_max_exp_sensetivity ]
294-
295-
const float c_pix_scale= 1.0f / 1024.0f;
296-
const float z_direction= settings_.GetOrSetBool( SettingsKeys::reverse_mouse ) ? -1.0f : +1.0f;
297-
298-
angle_.x-= exp_sensetivity * c_pix_scale * d_x_f * z_direction;
299-
angle_.z-= exp_sensetivity * c_pix_scale * d_z_f * 0.5f;
300-
301-
prev_controller_delta_x_= delta_x;
302-
prev_controller_delta_z_= delta_z;
303290
}
304291

305292
void MovementController::ClipCameraAngles()

0 commit comments

Comments
 (0)