Skip to content

Commit 5fd9cff

Browse files
committed
Added a keyboard character input type, and a "1 only" value type to Inpution.
- These go together, and might be used for the editors one day.
1 parent 815e222 commit 5fd9cff

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
lines changed

source/documents/todo.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33

44
Current tasks (tasks being worked on, but not yet committed)
5-
Add a menu option to each editor that allows you to edit the file externally with a text editor
6-
Make the analog-to-digital threshold customizable, as well as other magic numbers if any
7-
Spatial navigation loop options per axis
8-
Each GUI definition should say whether it allows looping in either direction
95

106

117
Next tasks (roughly sorted most important first)
128
--- To fix ---
139
Binding the zoom button to the Deck's right trigger STILL causes a bunch of actions when pressed
1410
It's impossible to go on the inner triangle on DEV Lab at 1465, 370
15-
Smaller enemies go for Winged Pikmin in vain
1611

1712
--- 1.1.0 ---
1813
Swarming jingle
@@ -459,6 +454,7 @@ Small tasks (for when I'm feeling lazy)
459454
Remove magic numbers and magic strings (make numbers and strings into constants)
460455
Try to refactor the mission strategy patterns to also work for the area editor logic
461456
Clean up some coupling problems using https://github.com/larspensjo/SimpleSignal
457+
Organize named enums better. Maybe using some smart macros. Some use EnumNameDatabase, some use readEnumProp, some do things their own way by themselves
462458

463459

464460
Misc things (so I don't forget)
@@ -535,6 +531,7 @@ Misc things (so I don't forget)
535531
Water depth (thanks ThyCheshireCat)
536532
Either way, consider giving water surfaces their own Z. Not just for drawing, but for the purposes of considering something submerged, too
537533
Enemies could have individual territories -- a circle that can be anywhere (detached from the mob) and have any radius, and the mob has to be confined to that
534+
Smaller enemies try to chase Winged Pikmin in vain since they'll never reach them. Should they ignore them? How do the canon games do it?
538535
Objects falling from the sky
539536
When a leader approaches, when a Pikmin approaches, when carrying, etc.
540537
Game config parameters:
@@ -718,7 +715,7 @@ Misc things (so I don't forget)
718715
This would allow mobs to cast light, which would just lighten up that zone of the lightmap
719716
Base content to add
720717
Enemies
721-
Add Helodity's Plasm Wraith
718+
x Add Helodity's Plasm Wraith
722719
Burrowing Snagret
723720
Bulbears
724721
Scuttlebug?

source/source/lib/inpution/inpution.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool Manager::areBindRequirementsMet(const Bind& bind) const {
3535
bind.modifiers.end(),
3636
m.first
3737
) != bind.modifiers.end();
38-
38+
3939
if(needsDown != modIsDown) return false;
4040
}
4141

@@ -90,6 +90,9 @@ float Manager::convertActionValue(int actionTypeId, float value) const {
9090
} case ACTION_VALUE_TYPE_DIGITAL: {
9191
return value >= options.digitalThreshold ? 1.0f : 0.0f;
9292
break;
93+
} case ACTION_VALUE_TYPE_1_ONLY: {
94+
return 1.0f;
95+
break;
9396
}
9497
}
9598
}
@@ -175,19 +178,22 @@ void Manager::handleCleanInput(
175178
vector<int> actionTypesIds = getActionTypesFromInput(input);
176179

177180
for(size_t a = 0; a < actionTypesIds.size(); a++) {
178-
if(
179-
!actionTypes[actionTypesIds[a]].directEvents &&
180-
!forceDirectEvent
181-
) {
182-
continue;
181+
const ActionType& actionType = actionTypes[actionTypesIds[a]];
182+
bool mustAddDirectly =
183+
forceDirectEvent ||
184+
actionType.directEvents ||
185+
actionType.valueType == ACTION_VALUE_TYPE_1_ONLY;
186+
187+
if(mustAddDirectly) {
188+
//Add it to the action queue directly.
189+
Action newAction;
190+
newAction.actionTypeId = actionTypesIds[a];
191+
newAction.value =
192+
convertActionValue(actionTypesIds[a], input.value);
193+
newAction.reinsertionLifetime =
194+
actionTypes[actionTypesIds[a]].reinsertionTTL;
195+
actionQueue.push_back(newAction);
183196
}
184-
//Add it to the action queue directly.
185-
Action newAction;
186-
newAction.actionTypeId = actionTypesIds[a];
187-
newAction.value = convertActionValue(actionTypesIds[a], input.value);
188-
newAction.reinsertionLifetime =
189-
actionTypes[actionTypesIds[a]].reinsertionTTL;
190-
actionQueue.push_back(newAction);
191197
}
192198
}
193199

@@ -268,6 +274,13 @@ bool Manager::handleInput(const Input& input) {
268274
handleCleanInput(singleInput, true);
269275
}
270276

277+
} else if(
278+
input.source.type == INPUT_SOURCE_TYPE_KEYBOARD_CHAR
279+
) {
280+
//Written characters are stateless. For instance, the user can insert
281+
//the a-with-a-tilde character, but can't "release" that character.
282+
handleCleanInput(input, true);
283+
271284
} else {
272285
//Regular input.
273286
handleCleanInput(input, false);

source/source/lib/inpution/inpution.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ enum INPUT_SOURCE_TYPE {
3333
//Keyboard key.
3434
INPUT_SOURCE_TYPE_KEYBOARD_KEY,
3535

36+
//Written character via keyboard.
37+
INPUT_SOURCE_TYPE_KEYBOARD_CHAR,
38+
3639
//Mouse button.
3740
INPUT_SOURCE_TYPE_MOUSE_BUTTON,
3841

@@ -79,11 +82,17 @@ enum ACTION_FLAG {
7982
enum ACTION_VALUE_TYPE {
8083

8184
//A float in the range [0 - 1].
85+
//e.g. Forward movement amount.
8286
ACTION_VALUE_TYPE_ANALOG,
8387

8488
//Either 0 or 1 (basically up or down).
89+
//e.g. jump button pressed or released.
8590
ACTION_VALUE_TYPE_DIGITAL,
8691

92+
//Just 1.
93+
//e.g. Save command in the editor.
94+
ACTION_VALUE_TYPE_1_ONLY,
95+
8796
};
8897

8998

@@ -132,7 +141,7 @@ struct Input {
132141
//Hardware source.
133142
InputSource source;
134143

135-
//Value associated, if applicable.
144+
//Value associated, if applicable, [0 - 1].
136145
float value = 0.0f;
137146

138147
};
@@ -156,10 +165,11 @@ struct Bind {
156165
InputSource inputSource;
157166

158167
//If true, the modifiers have to be respected.
168+
//See Manager::modifiers.
159169
bool requireModifiers = false;
160170

161171
//List of modifiers that need to be on for the bind to work.
162-
//See Manager::modifiers;
172+
//See Manager::modifiers.
163173
vector<int> modifiers;
164174

165175
};
@@ -233,7 +243,7 @@ struct Action {
233243
//Player number, starting at 1. 0 if N/A.
234244
int playerNr = 0;
235245

236-
//Value associated. [0 - 1].
246+
//Value associated, if applicable, [0 - 1].
237247
float value = 0.0f;
238248

239249
//Flags. Use ACTION_FLAG.
@@ -251,7 +261,7 @@ struct Action {
251261
struct ManagerOptions {
252262

253263
//--- Members ---
254-
264+
255265
//Threshold for converting analog values to digital.
256266
//If the value is equal to or higher than this, it will convert to 1.
257267
//Otherwise to 0.

source/source/lib/inpution/readme.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,34 @@ int main() {
3838
myGame.setup();
3939

4040
// 1. Teach Inpution what action types exist.
41-
inpution.actionTypes[PLAYER_ACTION_MOVE_LEFT] = {
41+
inpution.actionTypes[MyGame::PLAYER_ACTION_MOVE_LEFT] = {
4242
.id = PLAYER_ACTION_MOVE_LEFT,
4343
};
44-
inpution.actionTypes[PLAYER_ACTION_MOVE_RIGHT] = {
44+
inpution.actionTypes[MyGame::PLAYER_ACTION_MOVE_RIGHT] = {
4545
.id = PLAYER_ACTION_MOVE_RIGHT,
4646
};
47-
inpution.actionTypes[PLAYER_ACTION_JUMP] = {
47+
inpution.actionTypes[MyGame::PLAYER_ACTION_JUMP] = {
4848
.id = PLAYER_ACTION_JUMP,
49-
.valueType = Inpution::ACTION_VALUE_TYPE_BOOLEAN,
49+
.valueType = Inpution::ACTION_VALUE_TYPE_DIGITAL,
5050
};
5151

5252
// 2. Teach Inpution what control binds the player has.
5353
inpution.binds.push_back({
54-
.actionTypeId = PLAYER_ACTION_MOVE_LEFT,
54+
.actionTypeId = MyGame::PLAYER_ACTION_MOVE_LEFT,
5555
.inputSource = {
5656
.type = Inpution::INPUT_SOURCE_TYPE_CONTROLLER_AXIS_NEG,
5757
.stickNr = MyGame::LEFT_STICK
5858
}
5959
});
6060
inpution.binds.push_back({
61-
.actionTypeId = PLAYER_ACTION_MOVE_RIGHT,
61+
.actionTypeId = MyGame::PLAYER_ACTION_MOVE_RIGHT,
6262
.inputSource = {
6363
.type = Inpution::INPUT_SOURCE_TYPE_CONTROLLER_AXIS_POS,
6464
.stickNr = MyGame::LEFT_STICK
6565
}
6666
});
6767
inpution.binds.push_back({
68-
.actionTypeId = PLAYER_ACTION_JUMP,
68+
.actionTypeId = MyGame::PLAYER_ACTION_JUMP,
6969
.inputSource = {
7070
.type = Inpution::INPUT_SOURCE_TYPE_CONTROLLER_BUTTON,
7171
.buttonNr = MyGame::A_BUTTON
@@ -109,13 +109,13 @@ int main() {
109109
std::vector<Inpution::Action> actions = inpution.newFrame(myGame.deltaT);
110110
for(const auto& a : actions) {
111111
switch(a.actionTypeId) {
112-
case PLAYER_ACTION_MOVE_LEFT:
112+
case MyGame::PLAYER_ACTION_MOVE_LEFT:
113113
character.horizontalSpeed = a.value * 100;
114114
break;
115-
case PLAYER_ACTION_MOVE_RIGHT:
115+
case MyGame::PLAYER_ACTION_MOVE_RIGHT:
116116
character.horizontalSpeed = -a.value * 100;
117117
break;
118-
case PLAYER_ACTION_JUMP:
118+
case MyGame::PLAYER_ACTION_JUMP:
119119
character.verticalSpeed = 100;
120120
break;
121121
}
@@ -130,7 +130,7 @@ int main() {
130130
## Features
131131

132132
* Many settings:
133-
* Analog (range [0 - 1]) and digital (just 0 or 1) input values, and conversions between them (see `ActionType::valueType`).
133+
* Analog (range [0 - 1]), digital (just 0 or 1), and "down-only" (just 1) input values, and conversions between them (see `ActionType::valueType`).
134134
* Auto-repeated action events as long as the input is held (see `ActionType::autoRepeat`).
135135
* Actions can be generated directly from input events, or from the total combined internal hardware state (see `ActionType::directEvents`).
136136
* Reinserting actions into the queue for a buffer effect (see `ActionType::reinsertionTTL`).
@@ -139,7 +139,7 @@ int main() {
139139
* Varied support:
140140
* Support for multiple controllers at once.
141141
* Support for the input source triggering multiple actions, and for multiple input sources triggering the same action.
142-
* Support for stateful input sources (buttons, keys, analog sticks, etc.) and stateless sources (mouse wheel spins).
142+
* Support for stateful input sources (buttons, keys, analog sticks, etc.) and stateless sources (mouse wheel spins, typed characters).
143143
* Support for binds with modifiers (e.g. pressing Ctrl before pressing S) (see `Manager::modifiers`).
144144
* Specific features:
145145
* Game states logic (see `Manager::setGameState()`).
@@ -151,13 +151,13 @@ int main() {
151151
## Key terms
152152

153153
* **Action**:
154-
* An abstract representation of a specific action in the game that the player performed. The exact real-life movement the player made for this is not relevant.
154+
* An abstract representation of a specific action in the game that the player performed. The exact real-life movement the player made for this is not relevant. This is essentially an event.
155155
* e.g. Move aiming reticle right, with a strength of 0.75.
156156
* **Action type**:
157157
* A type of action the player can perform in the game.
158158
* e.g. Crouch (and un-crouch).
159159
* **Bind**:
160-
* Information about a bind between an action type and an input source.
160+
* Information about a bind between an action type and an input source. Typically the player can customize these in the options menu.
161161
* e.g. The bind between the A button on the controller and the jump action.
162162
* **Input**:
163163
* A specific movement made by a human being, on a specific source, on a specific hardware device.

0 commit comments

Comments
 (0)