Skip to content

Commit

Permalink
Add GSC (#5634)
Browse files Browse the repository at this point in the history
* Add GSC

* Change GSC color

* Add heuristic tests

* heuristics: Fix wrong alphabetical sorting

* Put smaller GSC samples

* heuristics: fix regexes

Co-authored-by: John Gardner <gardnerjohng@gmail.com>
  • Loading branch information
Jake-NotTheMuss and Alhadis authored Feb 10, 2022
1 parent ba3451b commit 7469c79
Show file tree
Hide file tree
Showing 14 changed files with 1,349 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
[submodule "vendor/grammars/CUE-Sheet_sublime"]
path = vendor/grammars/CUE-Sheet_sublime
url = https://github.com/relikd/CUE-Sheet_sublime
[submodule "vendor/grammars/CoDT7-Sublime"]
path = vendor/grammars/CoDT7-Sublime
url = https://github.com/Jake-NotTheMuss/CoDT7-Sublime.git
[submodule "vendor/grammars/ColdFusion"]
path = vendor/grammars/ColdFusion
url = https://github.com/SublimeText/ColdFusion
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ vendor/grammars/BrightScript.tmbundle:
- source.brightscript
vendor/grammars/CUE-Sheet_sublime:
- source.cuesheet
vendor/grammars/CoDT7-Sublime:
- source.gsc
vendor/grammars/ColdFusion:
- source.cfscript
- source.cfscript.cfc
Expand Down
17 changes: 17 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ disambiguations:
pattern: '![\w\s]+methodsFor: '
- language: 'C#'
pattern: '^(\s*namespace\s*[\w\.]+\s*{|\s*\/\/)'
- extensions: ['.csc']
rules:
- language: GSC
named_pattern: gsc
- extensions: ['.csl']
rules:
- language: XML
Expand Down Expand Up @@ -229,6 +233,14 @@ disambiguations:
pattern: '^uses (java|gw)\.'
- language: Genie
pattern: '^\[indent=[0-9]+\]'
- extensions: ['.gsc']
rules:
- language: GSC
named_pattern: gsc
- extensions: ['.gsh']
rules:
- language: GSC
named_pattern: gsc
- extensions: ['.h']
rules:
- language: Objective-C
Expand Down Expand Up @@ -633,6 +645,11 @@ named_patterns:
- '^[ \t]*(private|public|protected):$'
- 'std::\w+'
fortran: '^(?i:[c*][^abd-z]| (subroutine|program|end|data)\s|\s*!)'
gsc:
- '^\s*#\s*(?:using|insert|include|define|namespace)[ \t]+\w'
- '^\s*(?>(?:autoexec|private)\s+){0,2}function\s+(?>(?:autoexec|private)\s+){0,2}\w+\s*\('
- '\b(?:level|self)[ \t]+thread[ \t]+(?:\[\[[ \t]*(?>\w+\.)*\w+[ \t]*\]\]|\w+)[ \t]*\([^\r\n\)]*\)[ \t]*;'
- '^[ \t]*#[ \t]*(?:precache|using_animtree)[ \t]*\('
key_equals_value: '^[^#!;][^=]*='
m68k:
- '(?im)\bmoveq(?:\.l)?\s+#(?:\$-?[0-9a-f]{1,3}|%[0-1]{1,8}|-?[0-9]{1,3}),\s*d[0-7]\b'
Expand Down
12 changes: 12 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,18 @@ GN:
codemirror_mode: python
codemirror_mime_type: text/x-python
language_id: 302957008
GSC:
type: programming
color: "#FF6800"
extensions:
- ".gsc"
- ".csc"
- ".gsh"
tm_scope: source.gsc
ace_mode: c_cpp
codemirror_mode: clike
codemirror_mime_type: text/x-csrc
language_id: 257856279
Game Maker Language:
type: programming
color: "#71b417"
Expand Down
48 changes: 48 additions & 0 deletions samples/GSC/_spiderbot_ride.csc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include clientscripts\_utility;
#include clientscripts\_filter;

#using_animtree("player");


init()
{
clientscripts\_driving_fx::add_vehicletype_callback( "spiderbot_large", ::drive_spiderbot );
}


//
//
drive_spiderbot( localClientNum )
{
self endon( "entityshutdown" );

while( 1 )
{
self waittill( "enter_vehicle", player );

init_filter_karma_spiderbot( player );
enable_filter_karma_spiderbot( player, 0 );
SetSavedDvar( "r_stereo3DEyeSeparationScaler", 0.01);


//TODO: Get this to work in the vehicle GDT, somehow overcoming the lack of wheels
if( isdefined( level._audio_spiderbot_override ) )
{
self thread [[level._audio_spiderbot_override]](player);
}

// This compass isn't working they way it needs to.
// Create the compass
// spider_compass = Spawn( player GetLocalClientNumber(), player GetOrigin(), "script_model" );
// spider_compass SetModel( "p6_3d_gizmo" );
// spider_compass SetViewmodelRenderflag( true );
// spider_compass LinkToCamera( 5, (16, 0, 12) ); // in/out, left/right, up/down

self waittill( "exit_vehicle" );

disable_filter_karma_spiderbot( player, 0 );
SetSavedDvar( "r_stereo3DEyeSeparationScaler", 1);

// spider_compass delete();
}
}
209 changes: 209 additions & 0 deletions samples/GSC/array_override_common.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
#using scripts\shared\array_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\flag_shared;
#using scripts\shared\util_shared;
#insert scripts\shared\shared.gsh;
#insert scripts\zm\array_override\array_override_common.gsh;

#namespace array_override;

#define NOTIFY_SELF(n_add) self notify("override_state_change",n_type,str_name,n_add,is_override_exluded_from_notif(str_name))

function register(str_name,n_type,func)
{
switch(n_type)
{
case ARRAY_RANDOM:
DEFAULT(self.array_random_override,array());
self.array_random_override[str_name] = func;
break;
case ARRAY_RANDOMIZE:
DEFAULT(self.array_randomize_override,array());
self.array_randomize_override[str_name] = func;
break;
}
NOTIFY_SELF(1);
}

function unregister(str_name,n_type)
{
switch(n_type)
{
case ARRAY_RANDOM:
ArrayRemoveIndex(self.array_random_override,str_name,1);
break;
case ARRAY_RANDOMIZE:
ArrayRemoveIndex(self.array_randomize_override,str_name,1);
break;
}
NOTIFY_SELF(-1);
}

function private reregister(str_name,n_type)
{
switch(n_type)
{
case ARRAY_RANDOM:
func = self.array_random_override[str_name];
break;
case ARRAY_RANDOMIZE:
func = self.array_randomize_override[str_name];
break;
}
if (!isdefined(func)) return;
increment_exclude_from_notif(str_name);
unregister(str_name,n_type);
register(str_name,n_type,func);
decrement_exclude_from_notif(str_name);
}

#define EXCLUDE_FROM_NOTIF_DEFAULTS MAKE_ARRAY(self.override_notif_exclude) DEFAULT(self.override_notif_exclude[str_name],0);
function increment_exclude_from_notif(str_name)
{
EXCLUDE_FROM_NOTIF_DEFAULTS
self.override_notif_exclude[str_name]++;
}

function decrement_exclude_from_notif(str_name)
{
EXCLUDE_FROM_NOTIF_DEFAULTS
self.override_notif_exclude[str_name]--;
if (self.override_notif_exclude[str_name] <= 0) ArrayRemoveIndex(self.override_notif_exclude,str_name,1);
}

function private is_override_exluded_from_notif(str_name)
{
MAKE_ARRAY(self.override_notif_exclude)
return IS_TRUE(self.override_notif_exclude[str_name]);
}

function autoexec init_player_overrides()
{
callback::on_connect(&on_player_connect);
}

function private on_player_connect()
{
self.array_random_override = array();
self.array_randomize_override = array();
}

function register_recursive(str_name,n_type,func,b_ex_notif = false)
{
switch(n_type)
{
case ARRAY_RANDOM:
DEFAULT(level.recursive_random_override,array());
level.recursive_random_override[str_name] = SpawnStruct();
struct = level.recursive_random_override[str_name];
break;
case ARRAY_RANDOMIZE:
DEFAULT(level.recursive_randomize_override,array());
level.recursive_randomize_override[str_name] = SpawnStruct();
struct = level.recursive_randomize_override[str_name];
break;
}
struct.func = func;
struct.b_ex_notif = b_ex_notif;
struct.count = 0;
struct.a_flag = array();
}

#define RECURSIVE_SWITCHBLOCK switch(n_type){\
case ARRAY_RANDOM: struct = level.recursive_random_override[str_name];break;\
case ARRAY_RANDOMIZE: struct = level.recursive_randomize_override[str_name];break;}\
if (!isdefined(struct)) return;

function increment_register(str_name,n_type)
{
RECURSIVE_SWITCHBLOCK
if (struct.count <= 0)
{
struct.count = 0;
if (struct.b_ex_notif) level increment_exclude_from_notif(str_name);
level register(str_name,n_type,struct.func);
}
struct.count++;
thread update_recursive_flags(struct);
}

function decrement_register(str_name,n_type,b_unregister = false)
{
RECURSIVE_SWITCHBLOCK
struct.count--;
if (b_unregister || struct.count <= 0)
{
level unregister(str_name,n_type);
if (struct.b_ex_notif) level decrement_exclude_from_notif(str_name);
struct.count = 0;
}
thread update_recursive_flags(struct);
}

function run_recursive_override_instance(str_name,n_type,func)
{
//fix this
id = self GetEntityNumber() + 1;
wait(.05 * id);
//
increment_register(str_name,n_type);
[[func]]();
decrement_register(str_name,n_type);
}

function add_recursive_override_flag(str_name,n_type,a_flags)
{
RECURSIVE_SWITCHBLOCK
DEFAULT(struct.a_flag,array());
foreach (flag in a_flags)
{
if (!IsArray(flag)) flag_array = array(flag);
else flag_array = flag;
str_flag = flag_array[0];
if (!IsString(str_flag)) continue;
n_count = VAL(flag_array[1],0);
flag_struct = SpawnStruct();
flag_struct.flag = str_flag;
flag_struct.required_count = n_count;
flag_struct.comparison = flag_array[2];
struct.a_flag[struct.a_flag.size] = flag_struct;
level flag::init(str_flag);
update_specific_flag(flag_struct,struct.count);
}
}

function update_recursive_flags(struct)
{
foreach (flag_struct in struct.a_flag)
{
update_specific_flag(flag_struct,struct.count);
}
}

function private update_specific_flag(flag_struct,n_count)
{
if (IsFunctionPtr(flag_struct.required_count)) required_count = [[flag_struct.required_count]]();
else required_count = flag_struct.required_count;

if (IsFunctionPtr(flag_struct.comparison)) b_val = [[flag_struct.comparison]](n_count,required_count);
else b_val = n_count === required_count;

if (isdefined(b_val)) level flag::set_val(flag_struct.flag,b_val);
}

function link_to_recursive_flag(str_name,n_type,a_flag,b_waitForAll = false)
{
level endon("end_game");
if (!isdefined(a_flag)) return;
if (!IsArray(a_flag)) a_flag = array(a_flag);
if (b_waitForAll) {waitFunc = &flag::wait_till_all; waitClearFunc = &flag::wait_till_clear_all;}
else {waitFunc = &flag::wait_till_any; waitClearFunc = &flag::wait_till_clear_all;}

while(1)
{
level [[waitFunc]](a_flag);
level [[waitClearFunc]](a_flag);
wait .05;
level reregister(str_name,n_type);
}
}
Loading

0 comments on commit 7469c79

Please sign in to comment.