c++ - 即使使用相同的键,如何进行有效的顺序输入和键状态?
问题描述
我正在制作一个游戏,我希望有一个系统可以检查输入组合以形成命令。我的输入适用于单次按键,同时按下多个按键,并且在某一点上使用不同的按键进行顺序输入。
我的输入系统是一个特定长度的键状态,以及 4 个相同长度的缓冲区。
int length;
const Uint8* keystate;
Uint8 *firstInput;
Uint8* secondInput;
Uint8* thirdInput;
Uint8* fourthInput;
然后当键盘类初始化时,我将它们设置为相同的长度并初始化我的键状态
keystate = SDL_GetKeyboardState(&length);
firstInput = new Uint8[length]; //all of them like this.
然后在更新期间我检查关键状态和发布这样
if(keystate[Left] && keystate[lPunch])
{
//example
}
if(keystate[lPunch] && !keystate[Crouch] && firstInput[Crouch])
{
//example of checking for release
}
//Outside of if statements I have the buffers mem copied, if I am doing that wrong please do tell me
//I wish for this system to be efficient
SDL_PumpEvents();
std::memcpy(firstInput, keystate, length);
std::memcpy(secondInput, keystate, length);
std::memcpy(thirdInput, keystate, length);
std::memcpy(fourthInput, keystate, length);
keystate = SDL_GetKeyboardState(&length);
系统在不使用相同键时工作,所以我如何更有效地使用它并重复键
//here's my attempt at using the same key, note nothing happens even with code inside
if(keystate[Left] && !secondInput[Left] && firstInput[Left]
{
//Do dash
}
编辑一个:添加 memcpy 的顺序似乎确实会在处理一个在另一个前面时改变结果,例如
memcpy(secondInput, firstInput, length);
memcpy(firstInput, keystate, length);
这与我的破折号配对似乎让玩家不断冲刺
解决方案
推荐阅读
- sql - 如何在 SQL Server 中使用 SELECT 语句同时更改 where 子句和追加?
- go - 将 yaml 文件注入 Argo 工作流程步骤的最佳方法是什么?
- wordpress - 古腾堡侧边栏中的 DateTimePicker
- regex - Google 表格双精度值的条件格式规则
- python - 在 broswerstack 上运行 python 代码的问题
- javascript - 用正则表达式求解方程
- string - 有没有办法找到一个字符串的算法来生成更多相同算法的字符串?
- windows - 如何从 PowerShell 打开 url
- autodesk-forge - Autodesk forge 查看器通过 svf 路径获取 AEC 模型数据
- css - 试图以角度创建一个css类但嵌套.getting错误(在我在主类中编写另一个类之前使用'}'))