From d31c682f30f76ff76e6d298b1b1a1fb352c394c1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 6 Sep 2017 17:06:26 -0400 Subject: [PATCH] Version 1.4.0 Tweaked some methods Working on better thread management Removed useless methods Added a pause and resume method (does not work on the main thread) Added method randomseed(seed) Invoking internal methods from c# is now supported... May have bugs haven't done much testing yet! --- parseManager/Program.cs | 13 +--- parseManager/bin/Debug/choiceTest.txt | 15 ++-- parseManager/bin/Debug/savedata.dat | Bin 0 -> 3850 bytes parseManager/parseManager.cs | 98 +++++++++++++++++++------- 4 files changed, 81 insertions(+), 45 deletions(-) diff --git a/parseManager/Program.cs b/parseManager/Program.cs index a55d8ae..a7de23b 100644 --- a/parseManager/Program.cs +++ b/parseManager/Program.cs @@ -71,15 +71,4 @@ namespace parseManagerCS } } } -} -/* - - New Block structure! - -NOTE: If you have an error within the catch block you will not be a happy coder! -```lua --- This Blcok will catch any errors that take place! This may cause an un recoverable error however! -[BLOCKNAME:event("catch",err)]{ - -} -``` - */ \ No newline at end of file +} \ No newline at end of file diff --git a/parseManager/bin/Debug/choiceTest.txt b/parseManager/bin/Debug/choiceTest.txt index caa1820..58e9cdd 100644 --- a/parseManager/bin/Debug/choiceTest.txt +++ b/parseManager/bin/Debug/choiceTest.txt @@ -1,4 +1,4 @@ -VERSION 1.2 +VERSION 1.3.2 THREAD testthread.txt [PLAYGAME]{ print("Welcome to my game!") @@ -29,9 +29,7 @@ THREAD testthread.txt snd_select=loadSong("Audio/select.mp3") playSong(bgm_song) setFancyForm("left") - str="!" - "Lets do this$str*3$" - LOAD() + LOAD("savedata.dat") write("Name: ") name=getInput() clear() @@ -39,10 +37,10 @@ THREAD testthread.txt "So your name is $name$, thats cool!" pos=1 sleep(200) - SAVE() + SAVE("savedata.dat") ::loop:: clear() - SAVE() + SAVE("savedata.dat") setFG(Color_Blue) fancy(" What to do $name$? Time plsyed $hours_played$:$mins_played$:$secs_played$,/l, Play Game, View Stats, View Credits, Quit Game") keyUP=isDown("{UP}") @@ -52,7 +50,7 @@ THREAD testthread.txt if keyDOWN==true then setVarPlay("pos",pos+1)|SKIP(0) if keyENTER==true then GOTO("choicemade")|SKIP(0) writeAt("->",1,pos+2) - sleep(50) + sleep(75) GOTO("loop") ::choicemade:: playSong(snd_select) @@ -71,6 +69,9 @@ THREAD testthread.txt if keyENTER==true then SKIP(0)|GOTO("loop") print(" ") } +[testFunc:function(a)]{ + "Invoke Test: $a$!" +} [setVarPlay:function(var,val)]{ setVar(var,val) if pos<1 then GOTO("toolittle")|SKIP(0) diff --git a/parseManager/bin/Debug/savedata.dat b/parseManager/bin/Debug/savedata.dat index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8648d1d2d90eaeb52de12a031fddf1cb3cd7aeb5 100644 GIT binary patch literal 3850 zcmd^C{c9sd7@oO&?Y8M%ucx9Y8bwhwhNhp1SdC3$FCI-p5?e|Mdz*A@*KB6%ew?m< zfxqe>AtHz%f{2KS2!bF8f*=TfaUckaAo!cU&n9E8hxQPzaM}&K*=L?--+gE1eczd7 zoH6zX9r(wQK1G+tf$4f;-IV5@aNEN3g`3T63fHq7xsuP#=9U%~3%R*Mu~5in%7N_% zu2_*G@Lki+W*R})wt5#t*mn9tuE@Z)6EHt>rPXpPSFLX*sX1=eV}j9rtm8`bfWPcdombEk9KDF6NIl{yW;`qnx_35C7>*-08eDL-CoQ zDZ7tOJ*s4wz!Q+7$j5(U{I22 zLKBJ(ggyoKSH+$gv*pl~`ZU;|6-z~mogO}0G2Q+uy-+^~#ZO9c^I=6~;}$4>REk>< zE7n{y)Nh00vQpem=*;*nYpxJdzXOu*mE=xBXUCFt+FDBA)bE1m8zs7%(9~Ge6ubI8 z5PYo!_Y#^O3$}%AJJ0K=!2Bzvxu4KzxFS~{0Q;q4A0#vy>!F(uf&N0#4-*=Bpj^yB z@VOGq64Hkrz`Z=k&lEXNXk>hA-|~gN0Qyr!FA+))pB;I=4E__v7YU^{tIbwzqn><( zKq8-;&&~0VmEcjxU(llZz}R+)f25elz=VpamH3B>DG@X2iJoU1*k&kpm8MwYA1KW# zGy_Xst@-6~{=U*wNR!@o0{3bWz4$#PdXhw1cW+>Lj@(mkBEh>#aGnGcp4_EPKQ`$~ zLN9tpNuDA}T$%%synwqV1vP(Lk?YhHJ8(Sp;B<+>|t$#tZFw=JAXr|+Jw@EQ4!D3Cd#J|79CZYzpnT#LJ7*`ryCk) z{593QP0cB4u54`8LA>omkfV@s6d-^}0Mr_QXxva%0I-4Js2~8az)>pzqTN4g0sz)%j{FC}-ijm9 p0gwP3c@2Ou08Z06`6qvB<>mkY literal 0 HcmV?d00001 diff --git a/parseManager/parseManager.cs b/parseManager/parseManager.cs index 7c01f2f..fa171d5 100644 --- a/parseManager/parseManager.cs +++ b/parseManager/parseManager.cs @@ -24,10 +24,11 @@ namespace parseManagerCS /// This also has very flexible flow control meaning you can use it for chat logic and such public class parseManager { - public string _VERSION = "1.3.1"; + public string _VERSION = "1.4.0"; standardDefine _invoke = new standardDefine(); string _filepath; bool _active = true; + int _pauseRate = 100; string _define = "NO_DEFINE"; string _entry = "START"; bool _isInternal; @@ -39,6 +40,7 @@ namespace parseManagerCS chunk _currentChunk; chunk _lastChunk = null; ENV _mainENV = new ENV(); + bool _paused; public ENV _defualtENV; Stack _fStack = new Stack(); Dictionary _flags = new Dictionary(); @@ -46,7 +48,7 @@ namespace parseManagerCS Dictionary _methods = new Dictionary(); void INITENV() { - GLOBALS.SetPM(this); + _mainENV.SetSen(GetFlag("casesensitive")); _mainENV["Color_Black"] = ConsoleColor.Black; _mainENV["Color_Blue"] = ConsoleColor.Blue; _mainENV["Color_Cyan"] = ConsoleColor.Cyan; @@ -69,6 +71,14 @@ namespace parseManagerCS { _mainENV = env; } + public void Pause() + { + _paused = true; + } + public void Resume() + { + _paused = false; + } public void makeThread() { isThread = true; @@ -163,7 +173,10 @@ namespace parseManagerCS if (_flags["debugging"]) Console.WriteLine("DEBUGGING: " + msg); } - + public void SetPauseRate(int r) + { + _pauseRate = r; + } void _Parse(string data, string hFile) { foreach (Match m in Regex.Matches(data, @"LOAD ([a-zA-Z0-9_\./]+)")) { @@ -279,6 +292,7 @@ namespace parseManagerCS var ccN = _currentChunk.GetName(); var argsN = c.GetArgs(); var fEnv = new ENV(); + fEnv.SetSen(GetFlag("casesensitive")); fEnv.SetParent(_defualtENV); if (!(argsN.Length == 1 && argsN[0] == "")) { for (int i = 0; i < argsN.Length; i++) { @@ -301,6 +315,15 @@ namespace parseManagerCS return null; } } + public object Invoke(string method, object[] args) + { + chunk c; + if (isRegisteredFunction(method, out c)) { + return InvokeI(method, args, c, true); + } + PushError("Attempt to invoke a non existing method!"); + return null; + } public object InvokeR(string method, object[] args) { chunk c; @@ -434,8 +457,13 @@ namespace parseManagerCS } public nextType Next() { - GLOBALS.SetPM(this); var tempReturn = new nextType(); + if (_paused) { + if (_pauseRate != 0) { + Thread.Sleep(_pauseRate); + } + return tempReturn; + } if (_currentChunk == null) { SetBlock(); } @@ -573,7 +601,7 @@ namespace parseManagerCS var test = Regex.Match(str, @"(.+?)\*(.+)"); var spart = test.Groups[1].Value; var ipart = test.Groups[2].Value; - if(!isVar(spart, out temp)){ + if (!isVar(spart, out temp)) { } if (int.TryParse(ipart, out testnum)) { @@ -1035,7 +1063,10 @@ namespace parseManagerCS [Serializable] public class ENV { + bool _sen; ENV _Parent; + bool _busyI; + bool _busyS; Dictionary _vars = new Dictionary(); Dictionary _varsI = new Dictionary(); public void SetParent(ENV other) @@ -1076,6 +1107,10 @@ namespace parseManagerCS obj = null; return false; } + public void SetSen(bool s) + { + _sen = s; + } public bool TryGetValue(int ind, out object obj) { if (this[ind] != null) { @@ -1088,7 +1123,7 @@ namespace parseManagerCS public object this[string ind] { get { object obj; - if (!GLOBALS.GetFlag("casesensitive")) { + if (!_sen) { ind = ind.ToLower(); } if (_vars.TryGetValue(ind, out obj)) { @@ -1100,10 +1135,15 @@ namespace parseManagerCS return null; } set { - if (!GLOBALS.GetFlag("casesensitive")) { + while(_busyS){ + // wait + } + _busyS=true; + if (!_sen) { ind = ind.ToLower(); } _vars[ind] = value; + _busyS=false; } } public object this[int ind] { @@ -1118,7 +1158,12 @@ namespace parseManagerCS return null; } set { + while(_busyI){ + // wait + } + _busyI=true; _varsI[ind] = value; + _busyI=false; } } } @@ -1185,11 +1230,14 @@ namespace parseManagerCS static class GLOBALS { static standardDefine _define = new standardDefine(); - static parseManager _current; static parseManager _main; static readonly ENV _env = new ENV(); static List _numvars = new List(); static List _Threads = new List(); + public static parseManager[] GetThreads() + { + return _Threads.ToArray(); + } public static void AddThread(parseManager PM) { _Threads.Add(PM); @@ -1229,27 +1277,14 @@ namespace parseManagerCS { _env[ind] = data; } - public static void SetPM(parseManager o) - { - _current = o; - } public static void SetMainPM(parseManager o) { _main = o; } - public static parseManager GetPM() - { - return _current; - } public static parseManager GetMainPM() { return _main; } - public static bool GetFlag(string flag) - { - var PM = GetPM(); - return PM.GetFlag(flag); - } public static void Add_Var(string var) { if (!_numvars.Contains(var)) { @@ -1373,7 +1408,7 @@ public class standardDefine next = PM.Next(); } } - public void SAVE(parseManager PM) + public void SAVE(parseManager PM, string name) { if (PM.isAThread()) { GLOBALS.GetMainPM().PushError("Cannot Call SAVE() in a thread!"); @@ -1383,15 +1418,15 @@ public class standardDefine env["__CurrentChunkName"] = c.GetName(); env["__CurrentChunkPos"] = c.GetPos(); env["__DefualtENV"] = PM.GetENV(); - GLOBALS.WriteToBinaryFile("savedata.dat", env); + GLOBALS.WriteToBinaryFile(name, env); } - public bool LOAD(parseManager PM) + public bool LOAD(parseManager PM, string _name) { if (PM.isAThread()) { GLOBALS.GetMainPM().PushError("Cannot Call LOAD() in a thread!"); } try { - ENV env = GLOBALS.ReadFromBinaryFile("savedata.dat"); + ENV env = GLOBALS.ReadFromBinaryFile(_name); var name = (string)env["__CurrentChunkName"]; var pos = (int)env["__CurrentChunkPos"]; var denv = (ENV)env["__DefualtENV"]; @@ -1558,7 +1593,15 @@ public class standardDefine } public void pause(parseManager PM) { - Console.ReadLine(); + if (!PM.isAThread()) { + PM.Pause(); + } else { + PM.debug("WARNING: Calling pause with the main thread is not allowed!"); + } + } + public void resume(parseManager PM) + { + PM.Resume(); } public void print(parseManager PM, object o) { @@ -1572,6 +1615,9 @@ public class standardDefine { return rnd.NextDouble(); } + public void randomseed(parseManager PM,double seed){ + rnd = new Random((int)seed); + } public double round(parseManager PM, double num, double n) { return Math.Round(num, (int)n);