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

In-game console #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Fusioon
Copy link
Contributor

@Fusioon Fusioon commented Aug 16, 2020

Overview

System allowing easy registration of commands and variables. Commands are delegates which will have arguments passed into them as StringView strArgs containing whole argument and Span<StringView> args containing arguments separated by space or in quotes. Variables support most common types (bool, int, float, enums, String). Each variable type can have their value set by string. Support for configuration variables meaning that when configuration file is parsed, it saves all values contained in this file and when variable is registered with flag CVarFlags.Config value of this variable will immediately change to match the value that was in the config file.

TODO

  • Render the console (requires working rendering system)
  • Capture input (will work on this once there is something to see)

@jamesaorson
Copy link
Contributor

Can we consider squashing multiple commits into one before merging? Generally a good rule I have come across is "Each commit should be a functioning piece of software", so if the feature is not functional/complete unless all 10 commits are in, then they should be represented as one commit with a good description.

{
protected T* _value;

public ref T Value => *_value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit dangerous if the value is null. We should have null protections or require that a CVar be non-null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't be able to register a null CVar. The GameConsole.RegisterVariable takes ref so I don't think there is way to pass null.

Comment on lines 12 to 14
case "true", "True", "TRUE", "1":
result = true;
case "false", "False", "FALSE", "0":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for the different spellings, why not convert these to lowercase and then just check for ["false", 0] and ["true", 1]?

case "false", "False", "FALSE", "0":
result = false;
default:
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most languages, all non-zero numbers are truthy. Should we do the same here rather than default to false?

Copy link
Contributor Author

@Fusioon Fusioon Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false in this contex means that we failed to parse the value and value wasn't changed. But I can add that if the value is number other than zero it will change to true.

return false;
}

public static int32 GetValueInt32(bool* val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these GetValue* functions assume the pointers are not null. Are we okay setting the precedent that we just assume all these values are non-null?

{
class CommandsHistory
{
private String[] _history ~ DeleteContainerAndItems!(_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use a List since this is expandable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see later on that we have a max history length. The array is great then for performance reasons, but we should also still consider allowing the history length to change at runtime and handle the copying of old history items to the new container if need be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add Resize method and make maximum size configurable through cvar.

Comment on lines +22 to +76
_addPos++;
_count++;
if (_addPos == _history.Count)
_addPos = 0;

if (_count > _history.Count)
_count--;

let item = _history[_addPos];
item.Set(line);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a list is used, the history can still wrap around like this, while also allowing a dynamic change in how big the history should be at runtime.

public StringView At(int index)
{
// index 0 = empty string
// index 1 = last addeded entry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change addeded to added

@Fusioon Fusioon force-pushed the in-game-console branch 3 times, most recently from 913851c to 5b32d9b Compare August 22, 2020 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants