@@ -69,6 +69,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
69
69
70
70
#include " craftium.h"
71
71
#include " gui/mainmenumanager.h"
72
+ #include < chrono>
72
73
73
74
extern gui::IGUIEnvironment* guienv;
74
75
@@ -208,13 +209,26 @@ void Client::pyConnStep() {
208
209
u32 c; // stores the RGBA pixel color
209
210
bool kill ;
210
211
211
- frameskip_count++;
212
+ /* Clear all virtual key presses except the movement ones (WASD) */
213
+ for (int i=0 ; i<KeyType::INTERNAL_ENUM_COUNT; i++) {
214
+ if (i != KeyType::FORWARD && i != KeyType::BACKWARD
215
+ && i != KeyType::LEFT && i != KeyType::RIGHT) {
216
+ virtual_key_presses[i] = false ;
217
+ }
218
+ }
212
219
220
+ // Update and check the frameskip condition
221
+ frameskip_count++;
213
222
if (frameskip_count != frameskip)
214
223
return ;
215
-
216
224
frameskip_count = 0 ;
217
225
226
+ /* Clear missing virtual key presses (WASD) */
227
+ virtual_key_presses[KeyType::FORWARD] = false ;
228
+ virtual_key_presses[KeyType::BACKWARD] = false ;
229
+ virtual_key_presses[KeyType::LEFT] = false ;
230
+ virtual_key_presses[KeyType::RIGHT] = false ;
231
+
218
232
/* Take the screenshot */
219
233
irr::video::IVideoDriver *driver = m_rendering_engine->get_video_driver ();
220
234
irr::video::IImage* const raw_image = driver->createScreenShot ();
@@ -641,8 +655,11 @@ void Client::connect(const Address &address, const std::string &address_name,
641
655
642
656
void Client::step (float dtime)
643
657
{
644
- syncClientStep ();
658
+ syncClientStep ();
659
+
660
+ dtime -= m_craftium_lag;
645
661
662
+ // printf("client dtime: %f, LIM: %f\n", dtime, DTIME_LIMIT);
646
663
// Limit a bit
647
664
if (dtime > DTIME_LIMIT)
648
665
dtime = DTIME_LIMIT;
@@ -655,10 +672,6 @@ void Client::step(float dtime)
655
672
656
673
ReceiveAll ();
657
674
658
- /* Clear virtual key presses */
659
- for (int i=0 ; i<KeyType::INTERNAL_ENUM_COUNT; i++)
660
- virtual_key_presses[i] = false ;
661
-
662
675
/*
663
676
Packet counter
664
677
*/
@@ -760,7 +773,15 @@ void Client::step(float dtime)
760
773
*/
761
774
LocalPlayer *player = m_env.getLocalPlayer ();
762
775
763
- pyConnStep ();
776
+ auto begin = std::chrono::steady_clock::now ();
777
+ pyConnStep ();
778
+ auto end = std::chrono::steady_clock::now ();
779
+ std::chrono::duration<float > duration = end - begin;
780
+ float seconds = duration.count ();
781
+ m_craftium_lag = seconds;
782
+
783
+ // printf("dtime: %f, delta (lag): %lf\n", dtime, seconds);
784
+
764
785
765
786
// Step environment (also handles player controls)
766
787
m_env.step (dtime);
0 commit comments