Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store action-specific state in ActionState #60

Closed
alice-i-cecile opened this issue Jan 30, 2022 · 11 comments
Closed

Store action-specific state in ActionState #60

alice-i-cecile opened this issue Jan 30, 2022 · 11 comments
Labels
controversial Requires a heightened standard of review enhancement New feature or request

Comments

@alice-i-cecile
Copy link
Contributor

alice-i-cecile commented Jan 30, 2022

Many actions are only meaningful in association with non-enumerable data.

A very useful pattern here is to store information in the enum variant, and then update that appropriately.

We want to be able to express:

#[derive(Actionlike, Clone)]
enum ArpgAction {
    Movement(Direction),
    Ability1,
    Ability2,
    Ability3,
    Ability4,
    Ultimate,
}

input_map.insert(ArpgAction::Movement(Direction::NORTH), KeyCode::Up);

let ArpgAction::Movement(direction) = action_state.get_value::<ArpgAction::Movement>();

Unfortunately, a reasonable API for the last step seems to be completely blocked on rust-lang/rfcs#2593, which, unsurprisingly, is postponed indefinitely 🙃

@alice-i-cecile alice-i-cecile added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 30, 2022
@alice-i-cecile alice-i-cecile added this to the 0.3 milestone Feb 9, 2022
@alice-i-cecile
Copy link
Contributor Author

Blocks #50.

@alice-i-cecile
Copy link
Contributor Author

We can eliminate the Hash bound by storing a HashMap<usize, InputAction> in InputMap, and doing likewise for ActionMap. This usize is given by Actionlike::index(), which has the desired behavior!

This may make #68 harder, but this feature is significantly more important, and serves related goals.

@alice-i-cecile alice-i-cecile changed the title Demonstrate how to store information about specific actions in ActionState Store action-specific state in ActionState Feb 10, 2022
@alice-i-cecile alice-i-cecile added blocked Nothing to do yet and removed documentation Improvements or additions to documentation labels Feb 10, 2022
@alice-i-cecile alice-i-cecile removed this from the 0.3 milestone Feb 10, 2022
@alice-i-cecile
Copy link
Contributor Author

We may be able to workaround this by generating an internal type to match those of each variant, and then requesting those in ActionState::get_value :/ It's extremely cursed though due to the high levels of magic, and will do wonky things with the imports.

@alice-i-cecile
Copy link
Contributor Author

This is fundamentally wrong-headed, and not our responsibility.

@alice-i-cecile
Copy link
Contributor Author

Changed my mind again. This is a common and interesting pattern, we should try to see if we can think up a design 😂

@alice-i-cecile alice-i-cecile reopened this Jul 7, 2022
@alice-i-cecile alice-i-cecile removed the blocked Nothing to do yet label Jul 7, 2022
@alice-i-cecile
Copy link
Contributor Author

#151 has some related mechanisms, we should figure out how to steal from the approach used to store gamepad axis values.

@alice-i-cecile alice-i-cecile added the controversial Requires a heightened standard of review label Jul 9, 2022
@alice-i-cecile
Copy link
Contributor Author

Closing this out because we can now store action state values.

@bardt
Copy link

bardt commented Aug 8, 2022

@alice-i-cecile could you (or someone else) point to an example of how to store action state value? Or at least to the feature you mean.

I want to do something similar to the example in the issue description: pass additional data with an Actionlike enum variant.

@alice-i-cecile
Copy link
Contributor Author

The feature that I've been using is the DualAxis / SingleAxis features, where we can store 2/1 f32s. Is that enough for your use case?

I'm not fully satisfied with the design here either/

@bardt
Copy link

bardt commented Aug 9, 2022

I don't think that's enough for my use case, but to be fair, I'm trying to do a pretty weird thing. I move the mouse cursor on a tile grid and wanted to model this as an action, something like:

enum Action {
	MoveTileCursor(GridCoords),
	Move, // to the tile cursor
	Shoot, // to the place under the tile cursor
}

Shoot and Move would map to mouse keys, but for MoveTileCursor I would need a custom system to listen to mouse events and translate them to the current GridCoords, and call action_state.press(MoveTileCursor(grid_coords)).

Why would I want to do this? To simplify AI. The AI opponent would do something like:

action_state.press(MoveTileCursor(human_player_grid_coords));
action_state.press(Shoot);

Am I completely off with my thinking?

@alice-i-cecile alice-i-cecile reopened this Aug 9, 2022
@alice-i-cecile
Copy link
Contributor Author

Nope, this is a very natural pattern, and something I'd considered before. Reopening this so we remember to chew on additional designs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controversial Requires a heightened standard of review enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants