Kehom / GodotAddonPack

A collection of pure GDScript addons for Godot
http://kehomsforge.com
MIT License
189 stars 15 forks source link

Network: Input is just pressed #5

Closed fairhat closed 4 years ago

fairhat commented 4 years ago

Hey,

is it possible to get a just_pressed function for input events? For example in a 2d platformer game there's no need to continously trigger jump events even if the player keeps holding the jump key down.

thx for the addon btw, looks great so far!

Kehom commented 4 years ago

Hello,

OK, I have set the input system the way it is because it make things easier to deal with the synchronization, reducing the amount of verification that must be done to ensure the input data will indeed reach the server.

That said, one of the first concerns comes to bandwidth usage. Please note that boolean data in this addon becomes packed into the smallest integer possible, using bitmasking. In other words, if you have between 1 and 8 boolean input "buttons" configured, only a single byte will be used per input object. That would be the exact same for pure input data if I had changed into "just_pressed" instead of the actual state.

Now, to avoid the character from constantly jumping if the button remains pressed, you can just use a flag (maybe named can_jump or something like that) within the character code. You set it to false when the character jumps and reset it to "true" only when the character is on the floor AND the jump button is not pressed. If you check the mega demo you will see I have done this exact same strategy.

Does this solve the problem?

fairhat commented 4 years ago

I was talking about sending data to the network multiple times even when its not necessary. But I guess you're sending everything on every tick anyways (at least it sounds like that)?

I'm already using a variable to jump only once.

Thx for the fast reply.

Kehom commented 4 years ago

OK, I wasn't entirely sure about what you were seeking, that's why I answered that way! ;)

Regarding the network bandwidth concerns, I'm trying to find a reasonable way to perform some kind of reduction on the input data usage while still keeping the system as generic as it is now.