Skip to content

Conversation

@shacknetisp
Copy link
Contributor

@shacknetisp shacknetisp commented Jul 12, 2020

This PR adds cubescript-defined variables to replace faux-variable aliases.

There are three commands and one alias added and described in usage.cfg:

// Integers
defintvar <name> <min> <current/default> <max> [<flags>] [<on_change>]
// Floats
deffloatvar <name> <min> <current/default> <max> [<flags>] [<on_change>]
// Strings
defstringvar <name> <current/default> [<flags>] [<on_change>]
// Booleans (integer from 0 to 1)
defboolvar <name> <current/default> [<flags>] [<on_change>]

on_change is CubeScript that will be executed when the variable is changed.

This also adds variables for the IDF_* flags that are useful and allowed for cubescript-defined variables:

$idfbithex
$idfbitpersist // especially useful
$idfbitreadonly
$idfbittexture

Under the hood, this adds additional functionality to idents so that they may store cubescript to be executed on change.
I am working within the existing system here, so there is a bit of hackishness especially for allowing on_change callbacks, but I think that giving cubescript proper variable support now is more useful than revamping the entire cubescript engine.

I have converted the new faux-variable aliases to variables.

@shacknetisp shacknetisp added the enhancement New feature or request label Jul 12, 2020
@shacknetisp shacknetisp force-pushed the dev-0-cubescript-variables branch from 390d2fd to 8ba22b3 Compare July 12, 2020 01:16
@MoonPadUSer
Copy link
Contributor

I'd like it if tbhey were called defint deffloat and devstring

@MoonPadUSer
Copy link
Contributor

MoonPadUSer commented Jul 12, 2020

Ok, so in summary what I would like to change is:
defvar to defint
deffvar to deffloat
defsvar to defstring
idfbitpersist, etc to IDF_PERSIST (since IDF stands for identifier flag)
maybe you could even add defbool which has min val 0 and max val 1 by default

@shacknetisp
Copy link
Contributor Author

I chose these names to be consistent with the current CS name convention, e.g. getfvarmax, getsvardef, and $mutsbitffa. Maintaining the current convention is important, we'd have to change the entire naming system for variables types and bit field flags to be consistent with the new naming.

defbool or perhaps defbvar could be defined in cubescript: defbool = [ defvar $arg1 0 $arg2 1 $arg3 $arg4 ]

@MoonPadUSer
Copy link
Contributor

hum, ok I see. then please add defbvar and we're done here.

@shacknetisp
Copy link
Contributor Author

shacknetisp commented Jul 12, 2020

Added defbvar. This will still need a c++ style review before merging, to confirm my implementation is acceptable.

Copy link
Contributor

@MoonPadUSer MoonPadUSer left a comment

Choose a reason for hiding this comment

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

eh, I guess the case isn't really important in debug messages

Copy link
Member

@TheAssassin TheAssassin left a comment

Choose a reason for hiding this comment

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

I only performed a functional and semantic review of the changes, focusing on the C++ code. Will happily re-review once my questions are answered.

@shacknetisp shacknetisp force-pushed the dev-0-cubescript-variables branch from def9ef5 to d3fbe4a Compare July 13, 2020 21:00
Replaced COMMAND with ICOMMAND and made storage explicit.
Made checks in ident::changed() explicit.
Used proper style for debug messages.
@shacknetisp shacknetisp force-pushed the dev-0-cubescript-variables branch from d3fbe4a to cbe5b47 Compare July 13, 2020 21:18
ushort filtered_flags = ((*flags) & EXPOSED_FLAGS);

// Allocate storage for the variable.
int *storage = new int(*cur);
Copy link
Member

Choose a reason for hiding this comment

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

This cries "potential memory leak" all over the place. I'll have to look into ident resp. addident to see whether this is ever cleaned up.

Copy link
Contributor Author

@shacknetisp shacknetisp Jul 14, 2020

Choose a reason for hiding this comment

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

These never get deleted; C++ variables use global variables as storage. Variables exist forever.

@TheAssassin TheAssassin added the CubeScript Improvement Improvements for CubeScript language label Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CubeScript Improvement Improvements for CubeScript language enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants