mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-16 18:32:11 +00:00
Compare commits
No commits in common. "master" and "v2.0.2" have entirely different histories.
46
README.md
46
README.md
@ -1,16 +1,7 @@
|
|||||||
<img src="https://raw.githubusercontent.com/sam-astro/Z-Sharp/master/ExtraResources/ZS-Gem-Icon-Small.png"/><img src="https://raw.githubusercontent.com/sam-astro/Z-Sharp/master/ExtraResources/ZS-Logo-Light-Small.png"/>
|
<img src="https://raw.githubusercontent.com/sam-astro/Z-Sharp/master/ExtraResources/ZS-Gem-Icon-Small.png"/><img src="https://raw.githubusercontent.com/sam-astro/Z-Sharp/master/ExtraResources/ZS-Logo-Light-Small.png"/>
|
||||||
|
|
||||||
> Z-Sharp is no longer in development! This project was never meant to go beyond the scope of a simple thing I could make pong in, yet people continue to ask for features and fixes, and I continue to oblige. So sadly, even though this was a cool project in which I learned a lot, it will be ending now. I will eventually make some docs and standards for the syntax, and will still leave this repository open. This way anybody can make their own interpreter or compiler for it. I will also still accept pull requests for any changes to this repository.
|
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
Z-Sharp is a custom programming language I made because I don't like c++ very much (Z-Sharp's interpreter is written in c++ though). Z-Sharp scripts have the file extension .ZS. The base syntax and formatting I would say is quite similar to C# or Python, but differs as task complexity increases. It also has support for graphics using SDL2.
|
Z-Sharp is a custom programming language I made because I don't like c++ very much (Z-Sharp's interpreter is written in c++ though). It used to be called Slang, standing for "Stupid Lang", but another programming language called Slang already exists :(. Z-Sharp scripts have the file extension .zs. The base syntax and formatting I would say is quite similar to C#, but differs as task complexity increases. It has support for graphics using SDL2, and by default is not enabled.
|
||||||
|
|
||||||
Before using Z#:
|
|
||||||
There is ***no documentation***, ***strings*** barely work, ***performance*** isn't great, the syntax is ***very specific***, and most errors just cause it to ***crash without warning***. I am just a *single developer* working on this during my free time; between school, other projects, and YouTube. Z-Sharp will most likely never be finished, since it was really supposed to end when the video was published about it.
|
|
||||||
If you are trying to use a common programming language feature, ask yourself this: ***Is this feature required to play pong?*** If not, then most likely that feature ***has not been implemented yet***. I initially only made the language so I could create pong and make a video about it, so it really is the ***bare minimum***.
|
|
||||||
|
|
||||||
## Documentation and getting started:
|
|
||||||
[The docs and tutorial](https://spazelectro.github.io/ZSharpDocs/#/README)
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Downloading or installing is very simple, here is how depending on your version and operating system:
|
Downloading or installing is very simple, here is how depending on your version and operating system:
|
||||||
@ -18,35 +9,20 @@ Downloading or installing is very simple, here is how depending on your version
|
|||||||
1. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Win-Installer.zip`.
|
1. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Win-Installer.zip`.
|
||||||
2. Unzip `ZSharp-Win-Installer.zip` and open the unzipped folder.
|
2. Unzip `ZSharp-Win-Installer.zip` and open the unzipped folder.
|
||||||
3. Inside is a single file titled `ZSharp-Setup.exe`. Run it, and follow the setup instructions.
|
3. Inside is a single file titled `ZSharp-Setup.exe`. Run it, and follow the setup instructions.
|
||||||
4. If it fails to run, make sure the `MS Visual Runtime and MSVC C++ Redistribute` are installed. You can download them [here from Microsoft](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist)
|
4. Now that it is installed, there are a few ways to use it:
|
||||||
5. Now that it is installed, there are a few ways to use it:
|
|
||||||
* (recommended) Any ZSharp file that ends with .ZS will automatically be associated with the interpreter. Just double-click it, and the interpreter will run.
|
* (recommended) Any ZSharp file that ends with .ZS will automatically be associated with the interpreter. Just double-click it, and the interpreter will run.
|
||||||
* Drag and drop any .ZS script directly onto the executable.
|
* Drag and drop any .ZS script directly onto the executable.
|
||||||
* Use command line, providing path to interpreter and then to script like so:
|
* Use command line, providing path to interpreter and then to script like so:
|
||||||
`> ./ZSharp.exe ./Pong-Example-Project/script.zs`
|
`> ./ZSharp.exe ./Pong-Example-Project/script.zs`
|
||||||
6. Feel free to use and edit the `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above. It is also located on the releases page.
|
5. Feel free to use and edit the `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above. It is also located on the releases page.
|
||||||
> If you don't want to install ZSharp on your device, or you want easier acces to the executable and .DLLs, another version is provided called `ZS_Win_Base_Raw.zip`. This just contains all of the files the installer puts on your computer.
|
> If you don't want to install ZSharp on your device, or you want easier acces to the executable and .DLLs, another version is provided called `ZS-Win-x64-Base.zip`. This just contains all of the files the installer puts on your computer.
|
||||||
### Linux
|
### Linux
|
||||||
1. Install requirements: `SDL2, SDL2 Image, SDL2 TTF` Commands for `apt` and `pacman` below:
|
1. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Linux.zip`.
|
||||||
|
2. Unzip `ZSharp-Linux.zip` and open the unzipped folder.
|
||||||
#### Debian
|
3. You will see some files. The Z# interpreter is `ZSharp`. Any time you want to execute a script, this is the program that will be used. You can use it like so:
|
||||||
|
|
||||||
```
|
|
||||||
$ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Arch
|
|
||||||
|
|
||||||
```
|
|
||||||
$ sudo pacman -S sdl2 sdl2_image sdl2_ttf
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Linux.zip`.
|
|
||||||
3. Unzip `ZSharp-Linux.zip` and open the unzipped folder.
|
|
||||||
4. You will see some files. The Z# interpreter is `ZSharp`. Any time you want to execute a script, this is the program that will be used. You can use it like so:
|
|
||||||
* Use terminal, providing path to executable and then to script like so:
|
* Use terminal, providing path to executable and then to script like so:
|
||||||
`$ ./ZSharp ./Pong-Example-Project/script.zs`
|
`$ ./ZSharp ./Pong-Example-Project/script.zs`
|
||||||
5. Feel free to use and edit the included `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above.
|
4. Feel free to use and edit the included `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above.
|
||||||
|
|
||||||
|
|
||||||
## Here is some example code:
|
## Here is some example code:
|
||||||
@ -73,7 +49,7 @@ func Main()
|
|||||||
|
|
||||||
if s == "r"
|
if s == "r"
|
||||||
{
|
{
|
||||||
Printl(s + " is r")
|
print s + " is r"
|
||||||
}
|
}
|
||||||
|
|
||||||
int functionNumber = ExampleFunction("A", s)
|
int functionNumber = ExampleFunction("A", s)
|
||||||
@ -87,8 +63,8 @@ func Main()
|
|||||||
/// be assigned at all on execute and can be left blank
|
/// be assigned at all on execute and can be left blank
|
||||||
func ExampleFunction(inputA, inputB)
|
func ExampleFunction(inputA, inputB)
|
||||||
{
|
{
|
||||||
Printl("In A is: " + inputA)
|
print "In A is: " + inputA
|
||||||
Printl("In B is: " + inputB)
|
print "In B is: " + inputB
|
||||||
|
|
||||||
// Return a value to the valling location
|
// Return a value to the valling location
|
||||||
return 4
|
return 4
|
||||||
|
|||||||
627
ZSharp/Main.cpp
627
ZSharp/Main.cpp
@ -2,10 +2,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
//bool DEVELOPER_MESSAGES = true;
|
|
||||||
#define DEVELOPER_MESSAGES false
|
#define DEVELOPER_MESSAGES false
|
||||||
#define EXAMPLE_PROJECT false
|
#define EXAMPLE_PROJECT false
|
||||||
#define NAMEVERSION "ZSharp v2.1.3-alpha"
|
#define NAMEVERSION "ZSharp v2.0.2"
|
||||||
|
|
||||||
#if defined(__unix__)
|
#if defined(__unix__)
|
||||||
#define UNIX true
|
#define UNIX true
|
||||||
@ -24,7 +23,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#if UNIX
|
#if UNIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -78,12 +76,9 @@ boost::any GetVariableValue(const string& varName, const unordered_map<string, b
|
|||||||
// Check if there is a variable with the specified name
|
// Check if there is a variable with the specified name
|
||||||
bool IsVar(const string& varName, const unordered_map<string, boost::any>& variableValues)
|
bool IsVar(const string& varName, const unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
if (split(varName, '.')[0] == "ZS")
|
if (variableValues.find(split(varName, '.')[0]) != variableValues.end() && split(varName, '.')[0] != "ZS")
|
||||||
return false;
|
|
||||||
|
|
||||||
if (variableValues.find(split(varName, '.')[0]) != variableValues.end())
|
|
||||||
return true;
|
return true;
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,20 +110,6 @@ vector<boost::any> VarValues(const vector<string>& varNames, unordered_map<strin
|
|||||||
return realValues;
|
return realValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printVarValues(const vector<string>& vec, unordered_map<string, boost::any>& variableValues)
|
|
||||||
{
|
|
||||||
cout << "<";
|
|
||||||
for (int i = 0; i < vec.size(); i++)
|
|
||||||
{
|
|
||||||
cout << AnyAsString(GetVariableValue(vec.at(i), globalVariableValues));
|
|
||||||
cout << AnyAsString(GetVariableValue(vec.at(i), variableValues));
|
|
||||||
cout << " | ";
|
|
||||||
}
|
|
||||||
cout << ">";
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool IsFunction(const string& funcName)
|
bool IsFunction(const string& funcName)
|
||||||
{
|
{
|
||||||
if (functionValues.find(funcName) != functionValues.end())
|
if (functionValues.find(funcName) != functionValues.end())
|
||||||
@ -138,7 +119,10 @@ bool IsFunction(const string& funcName)
|
|||||||
}
|
}
|
||||||
bool IsZSFunction(const string& funcName)
|
bool IsZSFunction(const string& funcName)
|
||||||
{
|
{
|
||||||
return startsWith(funcName, "ZS.");
|
if (funcName[0] == 'Z' && funcName[1] == 'S' && funcName[2] == '.')
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& variableValues)
|
boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& variableValues)
|
||||||
@ -155,32 +139,31 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
// If no operations are applied, then return self
|
// If no operations are applied, then return self
|
||||||
if ((countOutsideParenthesis(expression, '+') == 0 && countOutsideParenthesis(expression, '-') == 0 && countOutsideParenthesis(expression, '*') == 0 && countOutsideParenthesis(expression, '/') == 0 && countOutsideParenthesis(expression, '^') == 0) || split(expression, '.')[0] == "ZS")
|
if ((countOutsideParenthesis(expression, '+') == 0 && countOutsideParenthesis(expression, '-') == 0 && countOutsideParenthesis(expression, '*') == 0 && countOutsideParenthesis(expression, '/') == 0 && countOutsideParenthesis(expression, '^') == 0) || split(expression, '.')[0] == "ZS")
|
||||||
{
|
{
|
||||||
//bool isFunc = IsFunction(split(expression, '(')[0]);
|
bool isFunc = IsFunction(split(expression, '(')[0]);
|
||||||
if (isFunc && !inQuotes)
|
if (isFunc && !inQuotes)
|
||||||
{
|
{
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
//cout << split(expression, '(')[0] << endl;
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
string argContents = "";
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
int y = indexInStr(expression, '(') + 1;
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
while (y < expression.size() && expression[y] != ')')
|
||||||
#if DEVELOPER_MESSAGES == true
|
|
||||||
cout << split(expression, '(')[0] << " [" << unWrapVec(argList) << "]" << endl;
|
|
||||||
printVarValues(argList, variableValues);
|
|
||||||
#endif
|
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
|
||||||
return ExecuteFunction(split(expression, '(')[0], funcArgs);
|
|
||||||
}
|
|
||||||
else if (isZS && !inQuotes)
|
|
||||||
{
|
{
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
argContents += expression[y];
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
y++;
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
}
|
||||||
#if DEVELOPER_MESSAGES == true
|
return ExecuteFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues));
|
||||||
cout << split(expression, '(')[0] << " [" << unWrapVec(argList) << "]" << endl;
|
}
|
||||||
printVarValues(argList, variableValues);
|
else if (split(expression, '.')[0] == "ZS" && !inQuotes)
|
||||||
#endif
|
{
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
string argContents = "";
|
||||||
return ZSFunction(split(expression, '(')[0], funcArgs);
|
int y = indexInStr(expression, '(') + 1;
|
||||||
|
while (y < expression.size() && expression[y] != ')')
|
||||||
|
{
|
||||||
|
argContents += expression[y];
|
||||||
|
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
return ZSFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return GetVariableValue(expression, variableValues);
|
return GetVariableValue(expression, variableValues);
|
||||||
@ -194,11 +177,11 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
if (expression[i] == '\"' && !isEscaped(newExpression, i))
|
if (expression[i] == '\"' && !isEscaped(newExpression, i))
|
||||||
inQuotes = !inQuotes;
|
inQuotes = !inQuotes;
|
||||||
|
|
||||||
if (isalpha(expression[i]) || expression[i] == '_')
|
if (isalpha(expression[i]))
|
||||||
{
|
{
|
||||||
string name = "";
|
string name = "";
|
||||||
|
|
||||||
while (i < expression.size() && (isalpha(expression[i]) || expression[i] == '.' || expression[i] == '_'))
|
while (i < expression.size() && (isalpha(expression[i]) || expression[i] == '.'))
|
||||||
{
|
{
|
||||||
name += expression[i];
|
name += expression[i];
|
||||||
i++;
|
i++;
|
||||||
@ -208,30 +191,29 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
bool isFunc = IsFunction(name);
|
bool isFunc = IsFunction(name);
|
||||||
if (isFunc && !inQuotes)
|
if (isFunc && !inQuotes)
|
||||||
{
|
{
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
string argContents = "";
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
i++;
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
while (i < expression.size() && expression[i] != ')')
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
{
|
||||||
#if DEVELOPER_MESSAGES == true
|
argContents += expression[i];
|
||||||
cout << "[" << unWrapVec(argList) << "]" << endl;
|
|
||||||
printVarValues(argList, variableValues);
|
i++;
|
||||||
#endif
|
}
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
string returnVal = AnyAsString(ExecuteFunction(name, VarValues(split(argContents, ','), variableValues)));
|
||||||
string returnVal = AnyAsString(ExecuteFunction(split(expression, '(')[0], funcArgs));
|
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
}
|
}
|
||||||
else if (split(name, '.')[0] == "ZS" && !inQuotes)
|
else if (split(name, '.')[0] == "ZS" && !inQuotes)
|
||||||
{
|
{
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
string argContents = "";
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
int y = indexInStr(expression, '(') + 1;
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
while (y < expression.size() && expression[y] != ')')
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
{
|
||||||
#if DEVELOPER_MESSAGES == true
|
argContents += expression[y];
|
||||||
cout << "[" << unWrapVec(argList) << "]" << endl;
|
|
||||||
printVarValues(argList, variableValues);
|
y++;
|
||||||
#endif
|
}
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
//cout << split(expression, '(')[0] << " " << argContents << endl;
|
||||||
string returnVal = AnyAsString(ZSFunction(split(expression, '(')[0], funcArgs));
|
string returnVal = AnyAsString(ZSFunction(split(name, '(')[0], VarValues(split(argContents, ','), variableValues)));
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -284,33 +266,27 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
return evaluate(newExpression);
|
return evaluate(newExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BooleanLogic(const string& valA, const string& comparer, const string& valB, unordered_map<string, boost::any>& variableValues)
|
bool BooleanLogic(const string& valA, const string& determinant, const string& valB, unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
boost::any valARealValue;
|
boost::any valARealValue = EvalExpression(valA, variableValues);
|
||||||
boost::any valBRealValue;
|
boost::any valBRealValue = EvalExpression(valB, variableValues);
|
||||||
if (valA != "")
|
|
||||||
valARealValue = EvalExpression(valA, variableValues);
|
|
||||||
if (valB != "")
|
|
||||||
valBRealValue = EvalExpression(valB, variableValues);
|
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog(AnyAsString(valARealValue) + " " + comparer + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + comparer + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
InterpreterLog(AnyAsString(valARealValue) + " " + determinant + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + determinant + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
||||||
#endif
|
#endif
|
||||||
if (comparer == "==")
|
if (determinant == "==")
|
||||||
return any_compare(valARealValue, valBRealValue);
|
return any_compare(valARealValue, valBRealValue);
|
||||||
else if (comparer == "!=")
|
else if (determinant == "!=")
|
||||||
return !any_compare(valARealValue, valBRealValue);
|
return !any_compare(valARealValue, valBRealValue);
|
||||||
else if (comparer == ">=")
|
else if (determinant == ">=")
|
||||||
return AnyAsFloat(valARealValue) >= AnyAsFloat(valBRealValue);
|
return AnyAsFloat(valARealValue) >= AnyAsFloat(valBRealValue);
|
||||||
else if (comparer == "<=")
|
else if (determinant == "<=")
|
||||||
return AnyAsFloat(valARealValue) <= AnyAsFloat(valBRealValue);
|
return AnyAsFloat(valARealValue) <= AnyAsFloat(valBRealValue);
|
||||||
else if (comparer == ">")
|
else if (determinant == ">")
|
||||||
return AnyAsFloat(valARealValue) > AnyAsFloat(valBRealValue);
|
return AnyAsFloat(valARealValue) > AnyAsFloat(valBRealValue);
|
||||||
else if (comparer == "<")
|
else if (determinant == "<")
|
||||||
return AnyAsFloat(valARealValue) < AnyAsFloat(valBRealValue);
|
return AnyAsFloat(valARealValue) < AnyAsFloat(valBRealValue);
|
||||||
else if (comparer == "")
|
|
||||||
return AnyAsBool(valARealValue) == true;
|
|
||||||
else
|
else
|
||||||
LogWarning("unrecognized comparer \'" + comparer + "\'");
|
LogWarning("unrecognized determinant \'" + determinant + "\'");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -395,85 +371,48 @@ int varOperation(const vector<string>& str, unordered_map<string, boost::any>& v
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unordered_map<string, boost::any>& variableValues)
|
boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
//// Check if the first two chars are '//', which would make it a comment
|
if (words.at(lineNum).at(0)[0] == '/' && words.at(lineNum).at(0)[1] == '/')
|
||||||
//if (startsWith(words.at(lineNum).at(0), "//"))
|
return nullType;
|
||||||
// return nullType;
|
|
||||||
|
|
||||||
// If print statement (deprecated, now use ZS.System.Print() function)
|
// If print statement (deprecated, now use ZS.System.Print() function)
|
||||||
if (words.at(lineNum).at(0) == "print")
|
else if (words.at(lineNum).at(0) == "print")
|
||||||
{
|
{
|
||||||
cout << StringRaw(AnyAsString(EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues))) << endl;
|
cout << StringRaw(AnyAsString(EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues))) << endl;
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it is a function return
|
// Check if function return
|
||||||
else if (words.at(lineNum).at(0) == "return")
|
else if (words.at(lineNum).at(0) == "return")
|
||||||
return EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues);
|
return EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues);
|
||||||
|
|
||||||
// Check if it is ZS Builtin function call
|
// Check if it is ZS Builtin function
|
||||||
else if (startsWith(words.at(lineNum).at(0), "ZS."))
|
else if (words.at(lineNum).at(0)[0] == 'Z' && words.at(lineNum).at(0)[1] == 'S' && words.at(lineNum).at(0)[2] == '.')
|
||||||
return EvalExpression(unWrapVec(words.at(lineNum)), variableValues);
|
return EvalExpression(unWrapVec(words.at(lineNum)), variableValues);
|
||||||
|
|
||||||
// Check if it is function call
|
// Check if it is function
|
||||||
else if (IsFunction(split(words.at(lineNum).at(0), '(')[0]))
|
else if (IsFunction(trim(split(words.at(lineNum).at(0), '(')[0])))
|
||||||
{
|
{
|
||||||
// start -> FuncCall(0, x, OtherFunc(a))
|
if (count(words.at(lineNum).at(0), '(') > 0 && count(words.at(lineNum).at(0), ')') > 0)
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
ExecuteFunction(trim(split(words.at(lineNum).at(0), '(')[0]), vector<boost::any>());
|
||||||
string insideFunArgs = betweenChars(unWrapVec(words.at(lineNum)), '(', ')');
|
else
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
ExecuteFunction(trim(split(words.at(lineNum).at(0), '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(words.at(lineNum), 0, (int)words.at(lineNum).size() - 1)), '(')[1]), ','), variableValues));
|
||||||
#if DEVELOPER_MESSAGES == true
|
|
||||||
cout << unWrapVec(argList) << endl;
|
|
||||||
printVarValues(argList, variableValues);
|
|
||||||
#endif
|
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
|
||||||
ExecuteFunction(split(words.at(lineNum).at(0), '(')[0], funcArgs);
|
|
||||||
return nullType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it is a SplitThread call
|
|
||||||
else if (startsWith(words.at(lineNum).at(0), "SplitThread"))
|
|
||||||
{
|
|
||||||
vector<string> lineContents = words.at(lineNum);
|
|
||||||
cout << "New Thread: " << words.at(lineNum).at(0) << endl;
|
|
||||||
//lineContents.at(0) = betweenChars(lineContents.at(0), '(', ')');
|
|
||||||
|
|
||||||
//cout << "debug: " << lineContents.at(0) << endl;
|
|
||||||
|
|
||||||
//if (betweenChars(lineContents.at(0), '(', ')') == "")
|
|
||||||
// std::thread thread_obj(ExecuteFunction, trim(split(lineContents.at(0), '(')[0]), vector<boost::any>());
|
|
||||||
//else
|
|
||||||
// std::thread thread_obj(ExecuteFunction, trim(split(lineContents.at(0), '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(lineContents, 0, (int)lineContents.size() - 2)), '(')[1]), ','), variableValues));
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if global variable declaration
|
// Check if global variable declaration
|
||||||
else if (words.at(lineNum).at(0) == "global")
|
else if (trim(words.at(lineNum).at(0)) == "global")
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
globalVariableValues[words.at(lineNum).at(2)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 4, -1)), variableValues);
|
globalVariableValues[words.at(lineNum).at(2)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 4, -1)), variableValues);
|
||||||
}
|
|
||||||
catch (const std::exception&)
|
|
||||||
{
|
|
||||||
LogCriticalError("Error at line: " + to_string(lineNum) + ", " + unWrapVec(words.at(lineNum)) + ", couldn't initialize variable.");
|
|
||||||
}
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through all types to see if line inits or
|
// Iterate through all types to see if line inits or
|
||||||
// re-inits a variable then store it with it's value
|
// re-inits a variable then store it with it's value
|
||||||
else if (countInVector(types, words.at(lineNum).at(0)) > 0)
|
else if (countInVector(types, trim(words.at(lineNum).at(0))) > 0)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
variableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues);
|
variableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues);
|
||||||
}
|
|
||||||
catch (const std::exception&)
|
|
||||||
{
|
|
||||||
LogCriticalError("Error at line: " + to_string(lineNum) + ", " + unWrapVec(words.at(lineNum)) + ", couldn't initialize variable.");
|
|
||||||
}
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +425,7 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check existing variables: To see if accessing class sub component
|
// Check existing variables: To see if class sub component matches
|
||||||
else if (count(words.at(lineNum).at(0), '.') > 0 && IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues) || IsVar(split(words.at(lineNum).at(0), '.')[0], globalVariableValues))
|
else if (count(words.at(lineNum).at(0), '.') > 0 && IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues) || IsVar(split(words.at(lineNum).at(0), '.')[0], globalVariableValues))
|
||||||
{
|
{
|
||||||
if (IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues))
|
if (IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues))
|
||||||
@ -496,112 +435,49 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If declaring a while loop, loop until false
|
// Gathers while loop contents
|
||||||
else if (words.at(lineNum).at(0) == "while")
|
else if (words.at(lineNum).at(0) == "while")
|
||||||
{
|
{
|
||||||
vector<vector<string>> whileContents;
|
vector<vector<string>> whileContents;
|
||||||
vector<string> whileParameters;
|
vector<string> whileParameters;
|
||||||
|
|
||||||
// Gather the parameters that must be == true for the loop to run
|
for (int w = 1; w < (int)words.at(lineNum).size(); w++)
|
||||||
int numOfBrackets = 0;
|
|
||||||
for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
|
|
||||||
if (count(words.at(lineNum).at(w), '{') == 0)
|
|
||||||
whileParameters.push_back(words.at(lineNum)[w]);
|
whileParameters.push_back(words.at(lineNum)[w]);
|
||||||
else
|
|
||||||
{
|
|
||||||
whileParameters.push_back(replace(words.at(lineNum)[w], "{", ""));
|
|
||||||
numOfBrackets = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the statement is already false, don't bother gathering the contents
|
int numOfBrackets = 1;
|
||||||
if (BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues) == false) {
|
for (int p = lineNum + 2; p < (int)words.size(); p++)
|
||||||
lineNum++;
|
|
||||||
while (lineNum < (int)words.size())
|
|
||||||
{
|
{
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
|
||||||
if (numOfBrackets == 0)
|
if (numOfBrackets == 0)
|
||||||
break;
|
break;
|
||||||
lineNum++;
|
whileContents.push_back(words.at(p));
|
||||||
}
|
|
||||||
return nullType;
|
|
||||||
}
|
}
|
||||||
|
whileContents = removeTabsWdArry(whileContents, 1);
|
||||||
|
|
||||||
// Gather the contents
|
|
||||||
lineNum++;
|
|
||||||
while (lineNum < (int)words.size())
|
|
||||||
{
|
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
|
||||||
if (numOfBrackets == 0)
|
|
||||||
break;
|
|
||||||
whileContents.push_back(words.at(lineNum));
|
|
||||||
lineNum++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//whileContents = removeTabsWdArry(whileContents, 1);
|
|
||||||
|
|
||||||
// Loop while true
|
|
||||||
while (BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues))
|
while (BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues))
|
||||||
{
|
{
|
||||||
//Iterate through all lines in while loop
|
//Iterate through all lines in while loop
|
||||||
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
||||||
{
|
{
|
||||||
if (whileContents.at(lineNum).at(0) == "continue")
|
|
||||||
break; // Stops iterating through lines and return to beginning
|
|
||||||
if (whileContents.at(lineNum).at(0) == "break")
|
|
||||||
return nullType; // Stops iterating through lines and leave while loop
|
|
||||||
boost::any returnVal = ProcessLine(whileContents, lineNum, variableValues);
|
boost::any returnVal = ProcessLine(whileContents, lineNum, variableValues);
|
||||||
if (!returnVal.empty()) {
|
if (!returnVal.empty())
|
||||||
try
|
|
||||||
{
|
|
||||||
BREAK t = any_cast<BREAK>(returnVal);
|
|
||||||
return nullType;
|
|
||||||
}
|
|
||||||
catch (boost::bad_any_cast)
|
|
||||||
{
|
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If declaring an if statement, only execute if true
|
// Gathers if statement contents
|
||||||
else if (words.at(lineNum).at(0) == "if")
|
else if (words.at(lineNum).at(0) == "if")
|
||||||
{
|
{
|
||||||
vector<vector<string>> ifContents;
|
vector<vector<string>> ifContents;
|
||||||
vector<string> ifParameters;
|
vector<string> ifParameters;
|
||||||
|
|
||||||
// Gather the parameters that must be == true for the loop to run
|
for (int w = 1; w < (int)words.at(lineNum).size(); w++)
|
||||||
int numOfBrackets = 0;
|
ifParameters.push_back(words.at(lineNum).at(w));
|
||||||
for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
|
|
||||||
if (count(words.at(lineNum).at(w), '{') == 0)
|
|
||||||
ifParameters.push_back(words.at(lineNum)[w]);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ifParameters.push_back(replace(words.at(lineNum)[w], "{", ""));
|
|
||||||
numOfBrackets = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the statement is already false, don't bother gathering the contents
|
int numOfBrackets = 1;
|
||||||
if (BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues) == false) {
|
lineNum += 2;
|
||||||
lineNum++;
|
|
||||||
while (lineNum < (int)words.size())
|
|
||||||
{
|
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
|
||||||
if (numOfBrackets == 0)
|
|
||||||
break;
|
|
||||||
lineNum++;
|
|
||||||
}
|
|
||||||
return nullType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gather the contents
|
|
||||||
lineNum++;
|
|
||||||
while (lineNum < (int)words.size())
|
while (lineNum < (int)words.size())
|
||||||
{
|
{
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
||||||
@ -610,80 +486,78 @@ boost::any ProcessLine(const vector<vector<string>>& words, int& lineNum, unorde
|
|||||||
ifContents.push_back(words.at(lineNum));
|
ifContents.push_back(words.at(lineNum));
|
||||||
lineNum++;
|
lineNum++;
|
||||||
}
|
}
|
||||||
//ifContents = removeTabsWdArry(ifContents, 1);
|
ifContents = removeTabsWdArry(ifContents, 1);
|
||||||
|
|
||||||
// Execute if true
|
|
||||||
if (BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues))
|
if (BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues))
|
||||||
{
|
{
|
||||||
//Iterate through all lines in if statement
|
//Iterate through all lines in if statement
|
||||||
for (int l = 0; l < (int)ifContents.size(); l++)
|
for (int l = 0; l < (int)ifContents.size(); l++)
|
||||||
{
|
{
|
||||||
if (ifContents.at(l).at(0) == "break")
|
|
||||||
return breakReOp; // Stops iterating through lines and leave while loop
|
|
||||||
boost::any returnVal = ProcessLine(ifContents, l, variableValues);
|
boost::any returnVal = ProcessLine(ifContents, l, variableValues);
|
||||||
if (!returnVal.empty())
|
if (!returnVal.empty())
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (words.size() > lineNum)
|
//else if (words.size() > lineNum + 1)
|
||||||
{
|
// if (words[lineNum + 1][0] == "else")
|
||||||
if (words[lineNum].at(0) == "else")
|
// {
|
||||||
{
|
// lineNum += 1;
|
||||||
vector<vector<string>> elseContents;
|
|
||||||
vector<string> elseParameters;
|
|
||||||
|
|
||||||
int numOfBrackets = 0;
|
// vector<string> elseContents;
|
||||||
for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
|
|
||||||
if (count(words.at(lineNum).at(w), '{') != 0)
|
|
||||||
{
|
|
||||||
numOfBrackets = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lineNum++;
|
// int numOfBrackets = 1;
|
||||||
while (lineNum < (int)words.size())
|
// while (lineNum < (int)words.size())
|
||||||
{
|
// {
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
// numOfBrackets += countInVector(words[lineNum], "{") - countInVector(words[lineNum], "}");
|
||||||
if (numOfBrackets == 0)
|
// if (numOfBrackets == 0)
|
||||||
break;
|
// break;
|
||||||
elseContents.push_back(words.at(lineNum));
|
// elseContents.push_back("");
|
||||||
lineNum++;
|
// for (int w = 0; w < (int)words[lineNum].size(); w++)
|
||||||
}
|
// {
|
||||||
|
// elseContents[(int)elseContents.size() - 1] += words[lineNum][w] + " ";
|
||||||
|
// }
|
||||||
|
// lineNum++;
|
||||||
|
// }
|
||||||
|
// elseContents = removeTabs(elseContents, 2);
|
||||||
|
|
||||||
//elseContents = removeTabsWdArry(elseContents, 1);
|
// vector<vector<string>> innerWords;
|
||||||
|
// for (int i = 0; i < (int)elseContents.size(); i++)
|
||||||
|
// innerWords.push_back(split(elseContents[i], ' '));
|
||||||
|
|
||||||
//Iterate through all lines in else statement
|
// //Iterate through all lines in else statement
|
||||||
for (int l = 0; l < (int)elseContents.size(); l++)
|
// for (int lineNum = 0; lineNum < (int)elseContents.size(); lineNum++)
|
||||||
{
|
// {
|
||||||
boost::any returnVal = ProcessLine(elseContents, l, variableValues);
|
// ProcessLine(innerWords, lineNum, variableValues);
|
||||||
if (!returnVal.empty())
|
// }
|
||||||
return returnVal;
|
// return nullType;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
//// Gathers else statement contents
|
||||||
|
//if (words[lineNum][0] == "else")
|
||||||
|
//{
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals)
|
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals)
|
||||||
{
|
{
|
||||||
// Get contents of function from global function map
|
// Get contents of function
|
||||||
std::vector<std::vector<std::string>> words = functionValues[functionName];
|
std::vector<std::vector<std::string>> words = functionValues[functionName];
|
||||||
|
|
||||||
unordered_map<string, boost::any> variableValues = {};
|
unordered_map<string, boost::any> variableValues = {};
|
||||||
|
|
||||||
std::vector<std::string> funcArgs = words.at(0);
|
std::vector<std::string> funcArgs = words.at(0);
|
||||||
// Set function variables equal to whatever inputs were provided
|
|
||||||
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
||||||
{
|
{
|
||||||
if (i < funcArgs.size())
|
if (i < funcArgs.size())
|
||||||
{
|
{
|
||||||
variableValues[funcArgs[i]] = inputVarVals[i];
|
variableValues[funcArgs[i]] = inputVarVals[i];
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
cout << "in " << functionName + " " << funcArgs[i] << " == " << AnyAsString(inputVarVals[i]) << endl;
|
cout << functionName + " \x1B[33m" << funcArgs[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -699,7 +573,6 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
|||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
LogCriticalError("Error at line: " + to_string(lineNum) + ", " + unWrapVec(words.at(lineNum)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullType;
|
return nullType;
|
||||||
@ -707,33 +580,20 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
|||||||
|
|
||||||
int parseZSharp(string script)
|
int parseZSharp(string script)
|
||||||
{
|
{
|
||||||
//script = replace(script, " ", "\t"); // Replace spaces with tabs (not really required, and will break purposefull whitespace in strings etc.)
|
script = replace(script, " ", "\t");
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
InterpreterLog("Contents:\n" + script);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Split the script by newline, signifying a line ending
|
vector<string> lines = split(script, '\n');
|
||||||
vector<string> beforeProcessLines = split(script, '\n');
|
|
||||||
vector<string> lines;
|
|
||||||
for (int i = 0; i < (int)beforeProcessLines.size(); i++) { // Then split said lines into indiviual words
|
|
||||||
if (!startsWith(trim(beforeProcessLines.at(i)), "//") && trim(beforeProcessLines.at(i)) != "")
|
|
||||||
{ // dont include line if it is a comment or if it is blank
|
|
||||||
lines.push_back(trim(beforeProcessLines.at(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if DEVELOPER_MESSAGES
|
|
||||||
InterpreterLog("Contents:\n");
|
|
||||||
#endif
|
|
||||||
vector<vector<string>> words;
|
vector<vector<string>> words;
|
||||||
for (int i = 0; i < (int)lines.size(); i++) // Then split said lines into indiviual words
|
for (int i = 0; i < (int)lines.size(); i++)
|
||||||
{
|
|
||||||
words.push_back(split(lines.at(i), ' '));
|
words.push_back(split(lines.at(i), ' '));
|
||||||
#if DEVELOPER_MESSAGES
|
|
||||||
cout << unWrapVec(words.at(i)) << endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Gather variables & functions...");
|
InterpreterLog("Gather variables & functions...");
|
||||||
#endif
|
#endif
|
||||||
// Go through entire script and iterate through all types to see if line is a variable
|
// First go through entire script and iterate through all types to see if line is a variable
|
||||||
// or function declaration, then store it with it's value
|
// or function declaration, then store it with it's value
|
||||||
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
||||||
{
|
{
|
||||||
@ -747,133 +607,75 @@ int parseZSharp(string script)
|
|||||||
InterpreterLog("Load script function " + functName + "...");
|
InterpreterLog("Load script function " + functName + "...");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//string args = "";
|
string args = "";
|
||||||
//if (indexInStr(unWrapVec(words.at(lineNum)), ')') - indexInStr(unWrapVec(words.at(lineNum)), '(') > 1)
|
if (indexInStr(unWrapVec(words.at(lineNum)), ')') - indexInStr(unWrapVec(words.at(lineNum)), '(') > 1)
|
||||||
// for (int w = 0; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
|
for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
|
||||||
// {
|
|
||||||
// if (count(words.at(lineNum).at(w), '{') == 0)
|
|
||||||
// args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
|
|
||||||
// }
|
|
||||||
string args = betweenChars(unWrapVec(words.at(lineNum)), '(', ')');
|
|
||||||
//cout << functName << "<" << args << ">" << endl;
|
|
||||||
|
|
||||||
//args = trim(replace(args, functName, ""));
|
|
||||||
functionContents.push_back(split(replace(args, " ", ""), ','));
|
|
||||||
|
|
||||||
|
|
||||||
int numOfBrackets = countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
|
||||||
// Gather the contents
|
|
||||||
lineNum++;
|
|
||||||
while (lineNum < (int)words.size())
|
|
||||||
{
|
{
|
||||||
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
|
args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
|
||||||
if (numOfBrackets == 0)
|
|
||||||
break;
|
|
||||||
functionContents.push_back(words.at(lineNum));
|
|
||||||
//cout << functName << "<" << args << ">" << endl;
|
|
||||||
lineNum++;
|
|
||||||
}
|
|
||||||
//functionContents = removeTabsWdArry(functionContents, 1);
|
|
||||||
|
|
||||||
/*int numOfBrackets = 0;
|
|
||||||
for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
|
|
||||||
if (count(words.at(lineNum).at(w), '{') != 0) {
|
|
||||||
numOfBrackets = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int p = lineNum + 1; p < (int)words.size(); p++)
|
args = trim(replace(args, functName + " ", ""));
|
||||||
|
functionContents.push_back(split(args, ','));
|
||||||
|
|
||||||
|
int numOfBrackets = 1;
|
||||||
|
for (int p = lineNum + 2; p < (int)words.size(); p++)
|
||||||
{
|
{
|
||||||
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
|
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
|
||||||
if (numOfBrackets == 0)
|
if (numOfBrackets == 0)
|
||||||
break;
|
break;
|
||||||
functionContents.push_back(removeTabs(words.at(p), 1));
|
functionContents.push_back(removeTabs(words.at(p), 1));
|
||||||
}*/
|
}
|
||||||
functionValues[functName] = functionContents;
|
functionValues[functName] = functionContents;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (words.at(lineNum).at(0) == "include")
|
if (words.at(lineNum).at(0) == "string") {
|
||||||
{
|
|
||||||
string scriptPath = StringRaw(words.at(lineNum).at(1));
|
|
||||||
string scriptTextContents;
|
|
||||||
#if DEVELOPER_MESSAGES == true
|
|
||||||
InterpreterLog("Including from " + words.at(lineNum).at(1) + "...");
|
|
||||||
#endif
|
|
||||||
#if UNIX
|
|
||||||
// Get script contents as single string
|
|
||||||
auto ss = ostringstream{};
|
|
||||||
ifstream input_file(scriptPath);
|
|
||||||
ss << input_file.rdbuf();
|
|
||||||
scriptTextContents = ss.str();
|
|
||||||
#if DEVELOPER_MESSAGES
|
|
||||||
InterpreterLog("Gather script contents...");
|
|
||||||
#endif
|
|
||||||
#elif WINDOWS
|
|
||||||
// Get script contents as single string
|
|
||||||
ifstream script(scriptPath);
|
|
||||||
stringstream scriptString;
|
|
||||||
scriptString << script.rdbuf();
|
|
||||||
scriptTextContents = scriptString.str();
|
|
||||||
#if DEVELOPER_MESSAGES
|
|
||||||
InterpreterLog("Gather script contents...");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
parseZSharp(scriptTextContents);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
else if (words.at(lineNum).at(0) == "string") {
|
|
||||||
globalVariableValues[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
|
globalVariableValues[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "int") {
|
||||||
|
globalVariableValues[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "float") {
|
||||||
|
globalVariableValues[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "bool") {
|
||||||
|
globalVariableValues[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
/*else
|
||||||
|
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate through all types to see if line inits or
|
#if DEVELOPER_MESSAGES
|
||||||
// re-inits a variable then store it with it's value
|
InterpreterLog("Start Main()");
|
||||||
else if (countInVector(types, trim(words.at(lineNum).at(0))) > 0)
|
#endif
|
||||||
{
|
// Executes main, which is the starting function
|
||||||
//cout << words.at(lineNum).at(1) << "=" << unWrapVec(slice(words.at(lineNum), 3, -1)) << "=" << AnyAsString(EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues)) << endl;
|
ExecuteFunction("Main", vector<boost::any> {});
|
||||||
globalVariableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), globalVariableValues);
|
|
||||||
}
|
|
||||||
// else if (words.at(lineNum).at(0) == "int") {
|
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// else if (words.at(lineNum).at(0) == "float") {
|
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// else if (words.at(lineNum).at(0) == "bool") {
|
|
||||||
// globalVariableValues[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
else
|
|
||||||
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Print the name of the interpreter and it's version in inverted black on white text
|
|
||||||
PrintColored(NAMEVERSION, blackFGColor, whiteBGColor, false);
|
PrintColored(NAMEVERSION, blackFGColor, whiteBGColor, false);
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
|
|
||||||
// Gathers builtin functions and variables
|
// Gathers builtin functions and variables
|
||||||
parseZSharp(ZSContents);
|
GetBuiltins(ZSContents);
|
||||||
//functionValues = builtinFunctionValues;
|
functionValues = builtinFunctionValues;
|
||||||
//globalVariableValues = builtinVarVals;
|
globalVariableValues = builtinVarVals;
|
||||||
|
|
||||||
std::string scriptTextContents;
|
std::string scriptTextContents;
|
||||||
|
|
||||||
@ -882,18 +684,16 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
std::string scriptPath;
|
std::string scriptPath;
|
||||||
if (EXAMPLE_PROJECT)
|
if (EXAMPLE_PROJECT)
|
||||||
scriptPath = "D:\\Code\\Z-Sharp\\examples\\Platformer\\script.zs";
|
scriptPath = "D:\\Code\\Z-Sharp\\Releases\\ZS-Win-x64-Base\\Pong-Example-Project\\script.zs";
|
||||||
else
|
else
|
||||||
scriptPath = argv[1];
|
scriptPath = argv[1];
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
cout << scriptPath << endl;
|
cout << scriptPath << endl;
|
||||||
#endif
|
#endif
|
||||||
if (!fileExists(scriptPath))
|
|
||||||
LogCriticalError("Failed to load script from path: \"" + scriptPath + "\"");
|
|
||||||
|
|
||||||
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||||
#if UNIX
|
#if UNIX
|
||||||
// Get script contents as single string
|
// Get script contents
|
||||||
auto ss = ostringstream{};
|
auto ss = ostringstream{};
|
||||||
ifstream input_file(scriptPath);
|
ifstream input_file(scriptPath);
|
||||||
ss << input_file.rdbuf();
|
ss << input_file.rdbuf();
|
||||||
@ -902,17 +702,16 @@ int main(int argc, char* argv[])
|
|||||||
InterpreterLog("Gather script contents...");
|
InterpreterLog("Gather script contents...");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Change the current working directory to that of the script
|
chdir(projectDirectory.c_str());
|
||||||
int chErr = chdir(projectDirectory.c_str());
|
|
||||||
if (chErr < 0)
|
|
||||||
LogCriticalError("Failed to change directory to: \"" + projectDirectory + "\", error num: " + to_string(chErr));
|
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Changed directory to " + projectDirectory + "...");
|
InterpreterLog("Change directory to " + projectDirectory + "...");
|
||||||
|
#endif
|
||||||
|
#if DEVELOPER_MESSAGES
|
||||||
|
string newPath = filesystem::current_path();
|
||||||
|
InterpreterLog("Current working directory is " + newPath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif WINDOWS
|
#elif WINDOWS
|
||||||
// Get script contents as single string
|
// Get script contents
|
||||||
ifstream script(scriptPath);
|
ifstream script(scriptPath);
|
||||||
stringstream scriptString;
|
stringstream scriptString;
|
||||||
scriptString << script.rdbuf();
|
scriptString << script.rdbuf();
|
||||||
@ -921,67 +720,35 @@ int main(int argc, char* argv[])
|
|||||||
InterpreterLog("Gather script contents...");
|
InterpreterLog("Gather script contents...");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Change the current working directory to that of the script
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
std::wstring wide = converter.from_bytes(projectDirectory);
|
std::wstring wide = converter.from_bytes(projectDirectory);
|
||||||
LPCWSTR s = wide.c_str();
|
LPCWSTR s = wide.c_str();
|
||||||
SetCurrentDirectory(s);
|
SetCurrentDirectory(s);
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Changed directory to " + projectDirectory + "...");
|
InterpreterLog("Change directory to " + projectDirectory + "...");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // If no script is provided as an argument throw error
|
{
|
||||||
LogWarning("No script provided! Please drag and drop .ZS file over interpreter executable file, or provide it's path as a command-line argument.");
|
LogWarning("No script provided! Please drag and drop .ZS file over interpreter executable file, or provide it's path as a command-line argument. If you are on Windows, just double-click any .ZS file, and it will automatically be opened with ZSharp.");
|
||||||
InterpreterLog("Press Enter to Exit...");
|
cout << "Press Enter to Continue";
|
||||||
cin.ignore();
|
cin.ignore();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system("pause");
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Parsing...");
|
InterpreterLog("Parsing...");
|
||||||
#endif
|
#endif
|
||||||
// Parse the script
|
|
||||||
parseZSharp(scriptTextContents);
|
parseZSharp(scriptTextContents);
|
||||||
|
|
||||||
|
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Start Main()");
|
cout << "Press Enter to Continue";
|
||||||
|
cin.ignore();
|
||||||
|
exit(1);
|
||||||
#endif
|
#endif
|
||||||
try
|
|
||||||
{
|
|
||||||
// Executes main, which is the entry point function
|
|
||||||
ExecuteFunction("Main", vector<boost::any> {});
|
|
||||||
}
|
|
||||||
catch (const std::exception&)
|
|
||||||
{
|
|
||||||
//Failed with error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entire script has been run, exit.
|
|
||||||
#if DEVELOPER_MESSAGES // If built with developer messages, then verify exit
|
|
||||||
InterpreterLog("Press Enter to Exit...");
|
|
||||||
cin.ignore();
|
|
||||||
exit(1);
|
|
||||||
#else
|
|
||||||
if (argc > 2)
|
|
||||||
{
|
|
||||||
string a = argv[2];
|
|
||||||
std::transform(a.begin(), a.end(), a.begin(),
|
|
||||||
[](unsigned char c) { return std::tolower(c); });
|
|
||||||
|
|
||||||
if (a == "-ve") // If the '-ve' (verify exit) option is used, ask for verification on exit
|
|
||||||
{
|
|
||||||
InterpreterLog("Press Enter to Exit...");
|
|
||||||
cin.ignore();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (AnyAsBool(GetVariableValue("EXIT_WHEN_DONE", globalVariableValues)) == false)
|
|
||||||
{
|
|
||||||
InterpreterLog("Press Enter to Exit...");
|
|
||||||
cin.ignore();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif // Else exit automatically
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
90
ZSharp/ZS.h
90
ZSharp/ZS.h
@ -3,18 +3,11 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
std::string ZSContents = R"(
|
std::string ZSContents = R"(
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// BUILTIN
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Default variables, can be overwritten
|
// Default variables, can be overwritten
|
||||||
// if re-initialized or changed
|
// if re-initialized or changed
|
||||||
float PI = 3.14159265358979323846264338
|
float PI = 3.14159265358979323846264338
|
||||||
float EulersNumber = 2.71828183
|
float EulersNumber = 2.71828183
|
||||||
|
|
||||||
// This variable tells the interpreter if it should close the console window when the program has finished running.
|
|
||||||
bool EXIT_WHEN_DONE = true
|
|
||||||
|
|
||||||
// Trigonometric function Sin
|
// Trigonometric function Sin
|
||||||
func Sin(input)
|
func Sin(input)
|
||||||
{
|
{
|
||||||
@ -107,15 +100,15 @@ func SetPixel(x, y, r, g, b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prints input value to console
|
// Prints input value to console
|
||||||
func Print(strToPrint)
|
func Print(in)
|
||||||
{
|
{
|
||||||
ZS.System.Print(strToPrint)
|
ZS.System.Print(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints input value to console with appended newline '\n'
|
// Prints input value to console with appended newline '\n'
|
||||||
func Printl(strToPrint)
|
func Printl(in)
|
||||||
{
|
{
|
||||||
ZS.System.PrintLine(strToPrint)
|
ZS.System.PrintLine(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates new sprite class
|
// Creates new sprite class
|
||||||
@ -144,80 +137,5 @@ func GetKey(keyName)
|
|||||||
bool b = ZS.Input.GetKey(keyName)
|
bool b = ZS.Input.GetKey(keyName)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////
|
|
||||||
// ↓ MADE BY KAPUTCHINO ↓ //
|
|
||||||
////////////////////////////
|
|
||||||
|
|
||||||
// Return the number of combinations
|
|
||||||
func Comb(n, r)
|
|
||||||
{
|
|
||||||
return Perm(n, r) / Fac(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the factorial of a number
|
|
||||||
func Fac(x)
|
|
||||||
{
|
|
||||||
int r = 1
|
|
||||||
while x > 1
|
|
||||||
{
|
|
||||||
r = r * x
|
|
||||||
x = x - 1
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return exp(x) by using the taylor method, not extremly accurate
|
|
||||||
func TaylorExp(x)
|
|
||||||
{
|
|
||||||
float sum = 0
|
|
||||||
float term = 1
|
|
||||||
int i = 1
|
|
||||||
float sumterm = 1
|
|
||||||
while sum != sumterm
|
|
||||||
{
|
|
||||||
sum = sumterm
|
|
||||||
term = term * x / i
|
|
||||||
i = i + 1
|
|
||||||
sumterm = sumterm + term
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the number of permutations
|
|
||||||
func Perm(n, r)
|
|
||||||
{
|
|
||||||
if n < 0
|
|
||||||
{
|
|
||||||
ZS.System.PrintLine("n must be superior or equal to 0")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if r < 0
|
|
||||||
{
|
|
||||||
ZS.System.PrintLine("r must be superior or equal to 0")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if r > n
|
|
||||||
{
|
|
||||||
ZS.System.PrintLine("r must be inferior or equal to n")
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return Fac(n) / Fac(n - r)
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////
|
|
||||||
// ↓ MADE BY CONCHETUMARE_PRODUCTIONS ↓ //
|
|
||||||
//////////////////////////////////////////
|
|
||||||
func GetPercent(value, percent)
|
|
||||||
{
|
|
||||||
float temp = value * percent / 100
|
|
||||||
return temp
|
|
||||||
}
|
|
||||||
//gets 100% of number
|
|
||||||
func PercentToHundred(value, percent)
|
|
||||||
{
|
|
||||||
float temp = value * 100 / percent
|
|
||||||
return temp
|
|
||||||
}
|
|
||||||
)"
|
)"
|
||||||
;
|
;
|
||||||
@ -83,13 +83,13 @@
|
|||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<IncludePath>D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_image-2.0.5\include;D:\Code\SDL2_ttf-2.0.15\include;$(IncludePath)</IncludePath>
|
<IncludePath>D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_image-2.0.5\include;D:\Code\SDL2_ttf-2.0.15\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>D:\Code\SDL2_ttf-2.0.15\lib\x64;D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_image-2.0.5\lib\x64;$(LibraryPath)</LibraryPath>
|
<LibraryPath>D:\Code\SDL2_ttf-2.0.15\lib\x64;D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_image-2.0.5\lib\x64;$(LibraryPath)</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)\Releases\ZS_Win_Base_Raw</OutDir>
|
<OutDir>$(SolutionDir)\Releases\ZS-Win-x64-Base</OutDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
<IncludePath>D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_image-2.0.5\include;D:\Code\SDL2_ttf-2.0.15\include;$(IncludePath)</IncludePath>
|
<IncludePath>D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_image-2.0.5\include;D:\Code\SDL2_ttf-2.0.15\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>D:\Code\SDL2_ttf-2.0.15\lib\x64;D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_image-2.0.5\lib\x64;$(LibraryPath)</LibraryPath>
|
<LibraryPath>D:\Code\SDL2_ttf-2.0.15\lib\x64;D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_image-2.0.5\lib\x64;$(LibraryPath)</LibraryPath>
|
||||||
<OutDir>$(SolutionDir)\Releases\ZS_Win_Base_Raw</OutDir>
|
<OutDir>$(SolutionDir)\Releases\ZS-Win-x64-Base</OutDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
||||||
|
|
||||||
#define MyAppName "Z-Sharp"
|
#define MyAppName "Z-Sharp"
|
||||||
#define MyAppVersion "2.1.3-alpha"
|
#define MyAppVersion "2.0.2"
|
||||||
#define MyAppPublisher "AstroSam"
|
#define MyAppPublisher "AstroSam"
|
||||||
#define MyAppURL "https://github.com/sam-astro/Z-Sharp"
|
#define MyAppURL "https://github.com/sam-astro/Z-Sharp"
|
||||||
#define MyAppExeName "ZSharp.exe"
|
#define MyAppExeName "ZSharp.exe"
|
||||||
@ -25,7 +25,6 @@ DefaultDirName={autopf}\ZSharp
|
|||||||
DisableDirPage=yes
|
DisableDirPage=yes
|
||||||
ChangesAssociations=yes
|
ChangesAssociations=yes
|
||||||
DisableProgramGroupPage=yes
|
DisableProgramGroupPage=yes
|
||||||
ChangesEnvironment=true
|
|
||||||
LicenseFile=D:\Code\Z-Sharp\LICENSE
|
LicenseFile=D:\Code\Z-Sharp\LICENSE
|
||||||
; Uncomment the following line to run in non administrative install mode (install for current user only.)
|
; Uncomment the following line to run in non administrative install mode (install for current user only.)
|
||||||
;PrivilegesRequired=lowest
|
;PrivilegesRequired=lowest
|
||||||
@ -37,21 +36,6 @@ Compression=lzma
|
|||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
|
|
||||||
[Tasks]
|
|
||||||
Name: modifypath; Description: Add application directory to your environmental path (This allows you to easily use from command line); Flags: unchecked
|
|
||||||
|
|
||||||
[Code]
|
|
||||||
const
|
|
||||||
ModPathName = 'modifypath';
|
|
||||||
ModPathType = 'system';
|
|
||||||
|
|
||||||
function ModPathDir(): TArrayOfString;
|
|
||||||
begin
|
|
||||||
setArrayLength(Result, 1)
|
|
||||||
Result[0] := ExpandConstant('{app}');
|
|
||||||
end;
|
|
||||||
#include "modpath.iss"
|
|
||||||
|
|
||||||
[Languages]
|
[Languages]
|
||||||
Name: "english"; MessagesFile: "compiler:Default.isl"
|
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||||
Name: "armenian"; MessagesFile: "compiler:Languages\Armenian.isl"
|
Name: "armenian"; MessagesFile: "compiler:Languages\Armenian.isl"
|
||||||
@ -80,16 +64,16 @@ Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
|
|||||||
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
|
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
|
||||||
|
|
||||||
[Files]
|
[Files]
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\libfreetype-6.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\libfreetype-6.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\libjpeg-9.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\libjpeg-9.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\libpng16-16.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\libpng16-16.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\libtiff-5.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\libtiff-5.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\libwebp-7.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\libwebp-7.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\SDL2.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\SDL2.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\SDL2_image.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\SDL2_image.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\SDL2_ttf.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\SDL2_ttf.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "D:\Code\Z-Sharp\Releases\ZS_Win_Base_Raw\zlib1.dll"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "D:\Code\Z-Sharp\Releases\ZSharp-Win-x64\zlib1.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||||
|
|
||||||
[Registry]
|
[Registry]
|
||||||
|
|||||||
265
ZSharp/builtin.h
265
ZSharp/builtin.h
@ -1,14 +1,6 @@
|
|||||||
#ifndef BUILTIN_H
|
#ifndef BUILTIN_H
|
||||||
#define BUILTIN_H
|
#define BUILTIN_H
|
||||||
|
|
||||||
#if defined(__unix__)
|
|
||||||
#define UNIX true
|
|
||||||
#define WINDOWS false
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
#define UNIX false
|
|
||||||
#define WINDOWS true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -20,8 +12,6 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <cstdlib> // for console command printing
|
|
||||||
|
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
@ -37,8 +27,8 @@ using namespace boost;
|
|||||||
|
|
||||||
vector<string> types = { "int", "float", "string", "bool", "void", "null", "Sprite", "Vec2", "Text" };
|
vector<string> types = { "int", "float", "string", "bool", "void", "null", "Sprite", "Vec2", "Text" };
|
||||||
|
|
||||||
//unordered_map<string, vector<vector<string>>> builtinFunctionValues;
|
unordered_map<string, vector<vector<string>>> builtinFunctionValues;
|
||||||
//unordered_map<string, boost::any> builtinVarVals;
|
unordered_map<string, boost::any> builtinVarVals;
|
||||||
|
|
||||||
// Foreground colors
|
// Foreground colors
|
||||||
const std::string blackFGColor = "\x1B[30m";
|
const std::string blackFGColor = "\x1B[30m";
|
||||||
@ -81,13 +71,8 @@ class NullType {
|
|||||||
public:
|
public:
|
||||||
string type = "NULL";
|
string type = "NULL";
|
||||||
};
|
};
|
||||||
class BREAK {
|
|
||||||
public:
|
|
||||||
string type = "BREAK";
|
|
||||||
};
|
|
||||||
|
|
||||||
boost::any nullType;
|
boost::any nullType;
|
||||||
boost::any breakReOp;
|
|
||||||
|
|
||||||
float clamp(float v, float min, float max)
|
float clamp(float v, float min, float max)
|
||||||
{
|
{
|
||||||
@ -101,10 +86,6 @@ float lerp(float a, float b, float f)
|
|||||||
return a + f * (b - a);
|
return a + f * (b - a);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool fileExists(const std::string& name) {
|
|
||||||
struct stat buffer;
|
|
||||||
return (stat(name.c_str(), &buffer) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintColored(std::string text, std::string fgColor, std::string bgColor, bool isError)
|
void PrintColored(std::string text, std::string fgColor, std::string bgColor, bool isError)
|
||||||
{
|
{
|
||||||
@ -155,7 +136,7 @@ void PrintColored(std::string text, std::string fgColor, std::string bgColor, bo
|
|||||||
int LogWarning(const string& warningText)
|
int LogWarning(const string& warningText)
|
||||||
{
|
{
|
||||||
PrintColored("WARNING: ", yellowFGColor, "", true);
|
PrintColored("WARNING: ", yellowFGColor, "", true);
|
||||||
PrintColored(escaped(warningText), yellowFGColor, "", true);
|
PrintColored(warningText, yellowFGColor, "", true);
|
||||||
cerr << std::endl;
|
cerr << std::endl;
|
||||||
//cout << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl;
|
//cout << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -171,15 +152,7 @@ int InterpreterLog(const string& logText)
|
|||||||
|
|
||||||
tm bt{};
|
tm bt{};
|
||||||
#if UNIX
|
#if UNIX
|
||||||
time_t currentTime;
|
//localtime_r(&timer, &bt);
|
||||||
struct tm* localTime;
|
|
||||||
|
|
||||||
time(¤tTime); // Get the current time
|
|
||||||
localTime = localtime(¤tTime); // Convert the current time to the local time
|
|
||||||
|
|
||||||
Hour = localTime->tm_hour;
|
|
||||||
Min = localTime->tm_min;
|
|
||||||
Sec = localTime->tm_sec;
|
|
||||||
#elif WINDOWS
|
#elif WINDOWS
|
||||||
localtime_s(&bt, &timer);
|
localtime_s(&bt, &timer);
|
||||||
Hour = bt.tm_hour;
|
Hour = bt.tm_hour;
|
||||||
@ -193,7 +166,7 @@ int InterpreterLog(const string& logText)
|
|||||||
|
|
||||||
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
||||||
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
||||||
PrintColored(escaped(logText), greenFGColor, "", true);
|
PrintColored(logText, greenFGColor, "", true);
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
//cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[32m" << logText << "\033[0m\t\t" << endl;
|
//cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[32m" << logText << "\033[0m\t\t" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -207,17 +180,9 @@ int LogCriticalError(const string& errorText)
|
|||||||
time_t timer = time(0);
|
time_t timer = time(0);
|
||||||
|
|
||||||
tm bt{};
|
tm bt{};
|
||||||
#if UNIX
|
#if defined(__unix__)
|
||||||
time_t currentTime;
|
//localtime_r(&timer, &bt);
|
||||||
struct tm* localTime;
|
#elif defined(_MSC_VER)
|
||||||
|
|
||||||
time(¤tTime); // Get the current time
|
|
||||||
localTime = localtime(¤tTime); // Convert the current time to the local time
|
|
||||||
|
|
||||||
Hour = localTime->tm_hour;
|
|
||||||
Min = localTime->tm_min;
|
|
||||||
Sec = localTime->tm_sec;
|
|
||||||
#elif WINDOWS
|
|
||||||
localtime_s(&bt, &timer);
|
localtime_s(&bt, &timer);
|
||||||
Hour = bt.tm_hour;
|
Hour = bt.tm_hour;
|
||||||
Min = bt.tm_min;
|
Min = bt.tm_min;
|
||||||
@ -230,13 +195,10 @@ int LogCriticalError(const string& errorText)
|
|||||||
|
|
||||||
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true);
|
||||||
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
PrintColored("ZSharp: ", yellowFGColor, "", true);
|
||||||
PrintColored(escaped(errorText), redFGColor, "", true);
|
PrintColored(errorText, redFGColor, "", true);
|
||||||
cerr << std::endl;
|
cerr << std::endl;
|
||||||
InterpreterLog("Press Enter to Exit...");
|
|
||||||
cin.ignore();
|
|
||||||
exit(1);
|
|
||||||
//cerr << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[31mERROR: " << errorText << "\033[0m\t\t" << endl;
|
//cerr << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[31mERROR: " << errorText << "\033[0m\t\t" << endl;
|
||||||
//exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,90 +268,90 @@ bool AxisAlignedCollision(const Sprite& a, const Sprite& b) // AABB - AABB colli
|
|||||||
return collisionX && collisionY;
|
return collisionX && collisionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Initial script processing, which loads variables and functions from builtin
|
// Initial script processing, which loads variables and functions from builtin
|
||||||
//int GetBuiltins(std::string s)
|
int GetBuiltins(std::string s)
|
||||||
//{
|
{
|
||||||
// std::string script = replace(s, " ", "\t");
|
std::string script = replace(s, " ", "\t");
|
||||||
//
|
|
||||||
// vector<string> lines = split(script, '\n');
|
vector<string> lines = split(script, '\n');
|
||||||
// vector<vector<string>> words;
|
vector<vector<string>> words;
|
||||||
// for (int i = 0; i < (int)lines.size(); i++)
|
for (int i = 0; i < (int)lines.size(); i++)
|
||||||
// {
|
{
|
||||||
// words.push_back(split(lines.at(i), ' '));
|
words.push_back(split(lines.at(i), ' '));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // Go through entire script and iterate through all types to see if line is a
|
// Go through entire script and iterate through all types to see if line is a
|
||||||
// // function declaration, then store it with it's value
|
// function declaration, then store it with it's value
|
||||||
// for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
||||||
// {
|
{
|
||||||
// //Checks if it is function
|
//Checks if it is function
|
||||||
// if (words.at(lineNum).at(0) == "func")
|
if (words.at(lineNum).at(0) == "func")
|
||||||
// {
|
{
|
||||||
// vector<vector<string>> functionContents;
|
vector<vector<string>> functionContents;
|
||||||
//
|
|
||||||
// string functName = split(words.at(lineNum).at(1), '(')[0];
|
string functName = split(words.at(lineNum).at(1), '(')[0];
|
||||||
//
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
// InterpreterLog("Load builtin function " + functName + "...");
|
InterpreterLog("Load builtin function " + functName + "...");
|
||||||
//#endif
|
#endif
|
||||||
//
|
|
||||||
// string args = "";
|
string args = "";
|
||||||
// for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
|
for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
|
||||||
// {
|
{
|
||||||
// args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
|
args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// args = replace(args, functName + " ", "");
|
args = replace(args, functName + " ", "");
|
||||||
// functionContents.push_back(split(args, ','));
|
functionContents.push_back(split(args, ','));
|
||||||
//
|
|
||||||
// int numOfBrackets = 1;
|
int numOfBrackets = 1;
|
||||||
// for (int p = lineNum + 2; p < (int)words.size(); p++)
|
for (int p = lineNum + 2; p < (int)words.size(); p++)
|
||||||
// {
|
{
|
||||||
// numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
|
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
|
||||||
// if (numOfBrackets == 0)
|
if (numOfBrackets == 0)
|
||||||
// break;
|
break;
|
||||||
// functionContents.push_back(removeTabs(words.at(p), 1));
|
functionContents.push_back(removeTabs(words.at(p), 1));
|
||||||
// }
|
}
|
||||||
// builtinFunctionValues[functName] = functionContents;
|
builtinFunctionValues[functName] = functionContents;
|
||||||
// //cout << functName << " is \n" << Vec2Str(functionContents) << endl << endl;
|
//cout << functName << " is \n" << Vec2Str(functionContents) << endl << endl;
|
||||||
// }
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (words.at(lineNum).at(0) == "string")
|
||||||
|
{
|
||||||
|
builtinVarVals[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "int")
|
||||||
|
{
|
||||||
|
builtinVarVals[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "float")
|
||||||
|
{
|
||||||
|
builtinVarVals[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (words.at(lineNum).at(0) == "bool")
|
||||||
|
{
|
||||||
|
builtinVarVals[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
//else
|
//else
|
||||||
// {
|
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
||||||
// if (words.at(lineNum).at(0) == "string")
|
}
|
||||||
// {
|
}
|
||||||
// builtinVarVals[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
return 0;
|
||||||
// InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
}
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// else if (words.at(lineNum).at(0) == "int")
|
|
||||||
// {
|
|
||||||
// builtinVarVals[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// else if (words.at(lineNum).at(0) == "float")
|
|
||||||
// {
|
|
||||||
// builtinVarVals[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// else if (words.at(lineNum).at(0) == "bool")
|
|
||||||
// {
|
|
||||||
// builtinVarVals[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
|
|
||||||
//#if DEVELOPER_MESSAGES == true
|
|
||||||
// InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// //else
|
|
||||||
// // LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Executes
|
// Executes
|
||||||
boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
||||||
@ -411,52 +373,22 @@ boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
|||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Init graphics");
|
InterpreterLog("Init graphics");
|
||||||
#endif
|
#endif
|
||||||
if (args.size() <= 3)
|
initGraphics(StringRaw(AnyAsString(args.at(0))), AnyAsInt(args.at(1)), AnyAsInt(args.at(2)));
|
||||||
initGraphics(StringRaw(AnyAsString(args.at(0))), AnyAsInt(args.at(1)), AnyAsInt(args.at(2)), 1);
|
|
||||||
else
|
|
||||||
initGraphics(StringRaw(AnyAsString(args.at(0))), AnyAsInt(args.at(1)), AnyAsInt(args.at(2)), AnyAsInt(args.at(3)));
|
|
||||||
}
|
}
|
||||||
else if (name == "ZS.Graphics.Sprite")
|
else if (name == "ZS.Graphics.Sprite")
|
||||||
{
|
{
|
||||||
string path = StringRaw(AnyAsString(args.at(0)));
|
|
||||||
if (count(path, '/') == 0)
|
|
||||||
path = "./" + path;
|
|
||||||
if (!fileExists(path))
|
|
||||||
LogCriticalError("Failed to create 'Sprite' object: \"" + path + "\"");
|
|
||||||
|
|
||||||
Sprite s(StringRaw(AnyAsString(args.at(0))), any_cast<Vec2>(args.at(1)), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)));
|
Sprite s(StringRaw(AnyAsString(args.at(0))), any_cast<Vec2>(args.at(1)), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)));
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
else if (name == "ZS.Graphics.DrawPixel")
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(gRenderer, AnyAsInt(args.at(2)), AnyAsInt(args.at(3)), AnyAsInt(args.at(4)), 255);
|
|
||||||
SDL_RenderDrawPoint(gRenderer, AnyAsInt(args.at(0)), AnyAsInt(args.at(1)));
|
|
||||||
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
//DrawPixel(AnyAsInt(args.at(0)), AnyAsInt(args.at(1)), AnyAsInt(args.at(2)), AnyAsInt(args.at(3)), AnyAsInt(args.at(4)));
|
|
||||||
else if (name == "ZS.Graphics.Draw")
|
else if (name == "ZS.Graphics.Draw")
|
||||||
any_cast<Sprite>(args.at(0)).Draw();
|
any_cast<Sprite>(args.at(0)).Draw();
|
||||||
else if (name == "ZS.Graphics.Load")
|
else if (name == "ZS.Graphics.Load")
|
||||||
any_cast<Sprite>(args.at(0)).Load();
|
any_cast<Sprite>(args.at(0)).Load();
|
||||||
else if (name == "ZS.Graphics.Text")
|
else if (name == "ZS.Graphics.Text")
|
||||||
{
|
{
|
||||||
string path = StringRaw(AnyAsString(args.at(1)));
|
Text t(StringRaw(AnyAsString(args.at(0))), StringRaw(AnyAsString(args.at(1))), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)));
|
||||||
if (count(path, '/') == 0)
|
|
||||||
path = "./" + path;
|
|
||||||
if (!fileExists(path))
|
|
||||||
LogCriticalError("Failed to create 'Text' object: \"" + path + "\"");
|
|
||||||
|
|
||||||
if (args.size() <= 8)
|
|
||||||
{
|
|
||||||
Text t(StringRaw(AnyAsString(args.at(0))), path, any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), true);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Text t(StringRaw(AnyAsString(args.at(0))), path, any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)), AnyAsBool(args.at(8)));
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (name == "ZS.Graphics.DrawText")
|
else if (name == "ZS.Graphics.DrawText")
|
||||||
any_cast<Text>(args.at(0)).Draw();
|
any_cast<Text>(args.at(0)).Draw();
|
||||||
else if (name == "ZS.Graphics.LoadText")
|
else if (name == "ZS.Graphics.LoadText")
|
||||||
@ -476,13 +408,6 @@ boost::any ZSFunction(const string& name, const vector<boost::any>& args)
|
|||||||
Vec2 v(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1)));
|
Vec2 v(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1)));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
else if (name == "ZS.System.Command"){
|
|
||||||
string command = StringRaw(AnyAsString(args.at(0)));
|
|
||||||
//int command_len = command.length();
|
|
||||||
//char* command_char_arr=new char[command_len + 1];
|
|
||||||
//strcpy(command_char_arr, command.c_str()); // string into char arr
|
|
||||||
int k = system(command.c_str());
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
LogWarning("ZS function \'" + name + "\' does not exist.");
|
LogWarning("ZS function \'" + name + "\' does not exist.");
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,6 @@ using namespace boost;
|
|||||||
|
|
||||||
int WINDOW_WIDTH = 1280;
|
int WINDOW_WIDTH = 1280;
|
||||||
int WINDOW_HEIGHT = 720;
|
int WINDOW_HEIGHT = 720;
|
||||||
int PIXEL_SCALE = 1;
|
|
||||||
|
|
||||||
unordered_map<string, int> KEYS =
|
unordered_map<string, int> KEYS =
|
||||||
{
|
{
|
||||||
@ -392,8 +391,6 @@ public:
|
|||||||
{
|
{
|
||||||
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
||||||
// Centers
|
// Centers
|
||||||
rect.w = scale.x;
|
|
||||||
rect.h = scale.y;
|
|
||||||
rect.x = position.x - (rect.w / 2);
|
rect.x = position.x - (rect.w / 2);
|
||||||
rect.y = position.y - (rect.h / 2);
|
rect.y = position.y - (rect.h / 2);
|
||||||
return 0;
|
return 0;
|
||||||
@ -504,8 +501,6 @@ public:
|
|||||||
scale.y /= AnyAsFloat(otherVal);
|
scale.y /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
// Centers
|
// Centers
|
||||||
rect.w = scale.x;
|
|
||||||
rect.h = scale.y;
|
|
||||||
rect.x = position.x - (rect.w / 2);
|
rect.x = position.x - (rect.w / 2);
|
||||||
rect.y = position.y - (rect.h / 2);
|
rect.y = position.y - (rect.h / 2);
|
||||||
return *this;
|
return *this;
|
||||||
@ -523,8 +518,8 @@ public:
|
|||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Text(std::string content, std::string pathToFont, Vec2 position, float fontSize, double angle, Uint8 r, Uint8 g, Uint8 b, bool antialias)
|
Text(std::string content, std::string pathToFont, Vec2 position, float fontSize, double angle, Uint8 r, Uint8 g, Uint8 b)
|
||||||
: position(position), angle(angle), content(content), pathToFont(pathToFont), fontSize(fontSize), r(r), g(g), b(b), antialias(antialias)
|
: position(position), angle(angle), content(content), pathToFont(pathToFont), fontSize(fontSize), r(r), g(g), b(b)
|
||||||
{
|
{
|
||||||
rect.x = position.x;
|
rect.x = position.x;
|
||||||
rect.y = position.y;
|
rect.y = position.y;
|
||||||
@ -538,11 +533,7 @@ public:
|
|||||||
{
|
{
|
||||||
SDL_Color color = { r, g, b };
|
SDL_Color color = { r, g, b };
|
||||||
|
|
||||||
SDL_Surface* surface;
|
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||||
if (antialias)
|
|
||||||
surface = TTF_RenderText_Blended(font, content.c_str(), color);
|
|
||||||
else
|
|
||||||
surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
|
||||||
|
|
||||||
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
|
||||||
@ -563,11 +554,7 @@ public:
|
|||||||
{
|
{
|
||||||
SDL_Color color = { r, g, b };
|
SDL_Color color = { r, g, b };
|
||||||
|
|
||||||
SDL_Surface* surface;
|
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||||
if (antialias)
|
|
||||||
surface = TTF_RenderText_Blended(font, content.c_str(), color);
|
|
||||||
else
|
|
||||||
surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
|
||||||
|
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
@ -612,8 +599,6 @@ public:
|
|||||||
return content;
|
return content;
|
||||||
if (componentName == "pathToFont")
|
if (componentName == "pathToFont")
|
||||||
return pathToFont;
|
return pathToFont;
|
||||||
if (componentName == "antialias")
|
|
||||||
return antialias;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,19 +706,12 @@ public:
|
|||||||
else if (oper == "+=")
|
else if (oper == "+=")
|
||||||
content += AnyAsString(otherVal);
|
content += AnyAsString(otherVal);
|
||||||
}
|
}
|
||||||
else if (componentName == "antialias")
|
|
||||||
{
|
|
||||||
if (oper == "=")
|
|
||||||
antialias = AnyAsBool(otherVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updates changes to text
|
// Updates changes to text
|
||||||
Update();
|
Update();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool antialias = true;
|
|
||||||
|
|
||||||
Vec2 position;
|
Vec2 position;
|
||||||
Vec2 scale;
|
Vec2 scale;
|
||||||
float fontSize;
|
float fontSize;
|
||||||
@ -761,12 +739,6 @@ int cleanupGraphics()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void DrawPixel(int x, int y, int r, int g, int b) {
|
|
||||||
// SDL_SetRenderDrawColor(gRenderer, r, g, b, 255);
|
|
||||||
// SDL_RenderDrawPoint(gRenderer, x, y);
|
|
||||||
// SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
int updateLoop()
|
int updateLoop()
|
||||||
{
|
{
|
||||||
@ -1045,21 +1017,17 @@ int updateLoop()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initGraphics(std::string windowTitle, int width, int height, int pixelScale)
|
int initGraphics(std::string windowTitle, int width, int height)
|
||||||
{
|
{
|
||||||
WINDOW_WIDTH = width;
|
WINDOW_WIDTH = width;
|
||||||
WINDOW_HEIGHT = height;
|
WINDOW_HEIGHT = height;
|
||||||
PIXEL_SCALE = pixelScale;
|
|
||||||
|
|
||||||
// Initialize SDL components
|
// Initialize SDL components
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
|
|
||||||
gWindow = SDL_CreateWindow(windowTitle.c_str(), 40, 40, WINDOW_WIDTH * PIXEL_SCALE, WINDOW_HEIGHT * PIXEL_SCALE, SDL_WINDOW_SHOWN | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
gWindow = SDL_CreateWindow(windowTitle.c_str(), 40, 40, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
|
gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
|
||||||
SDL_RenderSetLogicalSize(gRenderer, WINDOW_WIDTH * PIXEL_SCALE, WINDOW_HEIGHT * PIXEL_SCALE);
|
|
||||||
SDL_RenderSetScale(gRenderer, PIXEL_SCALE, PIXEL_SCALE);
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0);
|
|
||||||
|
|
||||||
//Get window surface
|
//Get window surface
|
||||||
gScreenSurface = SDL_GetWindowSurface(gWindow);
|
gScreenSurface = SDL_GetWindowSurface(gWindow);
|
||||||
|
|||||||
@ -110,26 +110,6 @@ utility
|
|||||||
windows.h
|
windows.h
|
||||||
-
|
-
|
||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/eval.cpp
|
|
||||||
iostream
|
|
||||||
-
|
|
||||||
fstream
|
|
||||||
-
|
|
||||||
string
|
|
||||||
-
|
|
||||||
regex
|
|
||||||
-
|
|
||||||
limits
|
|
||||||
-
|
|
||||||
stack
|
|
||||||
-
|
|
||||||
eval.h
|
|
||||||
/home/sam/Z-Sharp/ZSharp/eval.h
|
|
||||||
strops.h
|
|
||||||
/home/sam/Z-Sharp/ZSharp/strops.h
|
|
||||||
math.h
|
|
||||||
-
|
|
||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/eval.h
|
/home/sam/Z-Sharp/ZSharp/eval.h
|
||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/graphics.h
|
/home/sam/Z-Sharp/ZSharp/graphics.h
|
||||||
@ -172,22 +152,6 @@ any
|
|||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/main.h
|
/home/sam/Z-Sharp/ZSharp/main.h
|
||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/strops.cpp
|
|
||||||
iostream
|
|
||||||
-
|
|
||||||
fstream
|
|
||||||
-
|
|
||||||
string
|
|
||||||
-
|
|
||||||
regex
|
|
||||||
-
|
|
||||||
limits
|
|
||||||
-
|
|
||||||
boost/any.hpp
|
|
||||||
-
|
|
||||||
strops.h
|
|
||||||
/home/sam/Z-Sharp/ZSharp/strops.h
|
|
||||||
|
|
||||||
/home/sam/Z-Sharp/ZSharp/strops.h
|
/home/sam/Z-Sharp/ZSharp/strops.h
|
||||||
boost/any.hpp
|
boost/any.hpp
|
||||||
-
|
-
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,219 +0,0 @@
|
|||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Inno Setup Ver: 5.4.2
|
|
||||||
// Script Version: 1.4.2
|
|
||||||
// Author: Jared Breland <jbreland@legroom.net>
|
|
||||||
// Homepage: http://www.legroom.net/software
|
|
||||||
// License: GNU Lesser General Public License (LGPL), version 3
|
|
||||||
// http://www.gnu.org/licenses/lgpl.html
|
|
||||||
//
|
|
||||||
// Script Function:
|
|
||||||
// Allow modification of environmental path directly from Inno Setup installers
|
|
||||||
//
|
|
||||||
// Instructions:
|
|
||||||
// Copy modpath.iss to the same directory as your setup script
|
|
||||||
//
|
|
||||||
// Add this statement to your [Setup] section
|
|
||||||
// ChangesEnvironment=true
|
|
||||||
//
|
|
||||||
// Add this statement to your [Tasks] section
|
|
||||||
// You can change the Description or Flags
|
|
||||||
// You can change the Name, but it must match the ModPathName setting below
|
|
||||||
// Name: modifypath; Description: &Add application directory to your environmental path; Flags: unchecked
|
|
||||||
//
|
|
||||||
// Add the following to the end of your [Code] section
|
|
||||||
// ModPathName defines the name of the task defined above
|
|
||||||
// ModPathType defines whether the 'user' or 'system' path will be modified;
|
|
||||||
// this will default to user if anything other than system is set
|
|
||||||
// setArrayLength must specify the total number of dirs to be added
|
|
||||||
// Result[0] contains first directory, Result[1] contains second, etc.
|
|
||||||
// const
|
|
||||||
// ModPathName = 'modifypath';
|
|
||||||
// ModPathType = 'user';
|
|
||||||
//
|
|
||||||
// function ModPathDir(): TArrayOfString;
|
|
||||||
// begin
|
|
||||||
// setArrayLength(Result, 1);
|
|
||||||
// Result[0] := ExpandConstant('{app}');
|
|
||||||
// end;
|
|
||||||
// #include "modpath.iss"
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
procedure ModPath();
|
|
||||||
var
|
|
||||||
oldpath: String;
|
|
||||||
newpath: String;
|
|
||||||
updatepath: Boolean;
|
|
||||||
pathArr: TArrayOfString;
|
|
||||||
aExecFile: String;
|
|
||||||
aExecArr: TArrayOfString;
|
|
||||||
i, d: Integer;
|
|
||||||
pathdir: TArrayOfString;
|
|
||||||
regroot: Integer;
|
|
||||||
regpath: String;
|
|
||||||
|
|
||||||
begin
|
|
||||||
// Get constants from main script and adjust behavior accordingly
|
|
||||||
// ModPathType MUST be 'system' or 'user'; force 'user' if invalid
|
|
||||||
if ModPathType = 'system' then begin
|
|
||||||
regroot := HKEY_LOCAL_MACHINE;
|
|
||||||
regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
|
|
||||||
end else begin
|
|
||||||
regroot := HKEY_CURRENT_USER;
|
|
||||||
regpath := 'Environment';
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Get array of new directories and act on each individually
|
|
||||||
pathdir := ModPathDir();
|
|
||||||
for d := 0 to GetArrayLength(pathdir)-1 do begin
|
|
||||||
updatepath := true;
|
|
||||||
|
|
||||||
// Modify WinNT path
|
|
||||||
if UsingWinNT() = true then begin
|
|
||||||
|
|
||||||
// Get current path, split into an array
|
|
||||||
RegQueryStringValue(regroot, regpath, 'Path', oldpath);
|
|
||||||
oldpath := oldpath + ';';
|
|
||||||
i := 0;
|
|
||||||
|
|
||||||
while (Pos(';', oldpath) > 0) do begin
|
|
||||||
SetArrayLength(pathArr, i+1);
|
|
||||||
pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);
|
|
||||||
oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath));
|
|
||||||
i := i + 1;
|
|
||||||
|
|
||||||
// Check if current directory matches app dir
|
|
||||||
if pathdir[d] = pathArr[i-1] then begin
|
|
||||||
// if uninstalling, remove dir from path
|
|
||||||
if IsUninstaller() = true then begin
|
|
||||||
continue;
|
|
||||||
// if installing, flag that dir already exists in path
|
|
||||||
end else begin
|
|
||||||
updatepath := false;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Add current directory to new path
|
|
||||||
if i = 1 then begin
|
|
||||||
newpath := pathArr[i-1];
|
|
||||||
end else begin
|
|
||||||
newpath := newpath + ';' + pathArr[i-1];
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Append app dir to path if not already included
|
|
||||||
if (IsUninstaller() = false) AND (updatepath = true) then
|
|
||||||
newpath := newpath + ';' + pathdir[d];
|
|
||||||
|
|
||||||
// Write new path
|
|
||||||
RegWriteStringValue(regroot, regpath, 'Path', newpath);
|
|
||||||
|
|
||||||
// Modify Win9x path
|
|
||||||
end else begin
|
|
||||||
|
|
||||||
// Convert to shortened dirname
|
|
||||||
pathdir[d] := GetShortName(pathdir[d]);
|
|
||||||
|
|
||||||
// If autoexec.bat exists, check if app dir already exists in path
|
|
||||||
aExecFile := 'C:\AUTOEXEC.BAT';
|
|
||||||
if FileExists(aExecFile) then begin
|
|
||||||
LoadStringsFromFile(aExecFile, aExecArr);
|
|
||||||
for i := 0 to GetArrayLength(aExecArr)-1 do begin
|
|
||||||
if IsUninstaller() = false then begin
|
|
||||||
// If app dir already exists while installing, skip add
|
|
||||||
if (Pos(pathdir[d], aExecArr[i]) > 0) then
|
|
||||||
updatepath := false;
|
|
||||||
break;
|
|
||||||
end else begin
|
|
||||||
// If app dir exists and = what we originally set, then delete at uninstall
|
|
||||||
if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then
|
|
||||||
aExecArr[i] := '';
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// If app dir not found, or autoexec.bat didn't exist, then (create and) append to current path
|
|
||||||
if (IsUninstaller() = false) AND (updatepath = true) then begin
|
|
||||||
SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d], True);
|
|
||||||
|
|
||||||
// If uninstalling, write the full autoexec out
|
|
||||||
end else begin
|
|
||||||
SaveStringsToFile(aExecFile, aExecArr, False);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Split a string into an array using passed delimeter
|
|
||||||
procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
i := 0;
|
|
||||||
repeat
|
|
||||||
SetArrayLength(Dest, i+1);
|
|
||||||
if Pos(Separator,Text) > 0 then begin
|
|
||||||
Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1);
|
|
||||||
Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text));
|
|
||||||
i := i + 1;
|
|
||||||
end else begin
|
|
||||||
Dest[i] := Text;
|
|
||||||
Text := '';
|
|
||||||
end;
|
|
||||||
until Length(Text)=0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure CurStepChanged(CurStep: TSetupStep);
|
|
||||||
var
|
|
||||||
taskname: String;
|
|
||||||
begin
|
|
||||||
taskname := ModPathName;
|
|
||||||
if CurStep = ssPostInstall then
|
|
||||||
if IsTaskSelected(taskname) then
|
|
||||||
ModPath();
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
|
||||||
var
|
|
||||||
aSelectedTasks: TArrayOfString;
|
|
||||||
i: Integer;
|
|
||||||
taskname: String;
|
|
||||||
regpath: String;
|
|
||||||
regstring: String;
|
|
||||||
appid: String;
|
|
||||||
begin
|
|
||||||
// only run during actual uninstall
|
|
||||||
if CurUninstallStep = usUninstall then begin
|
|
||||||
// get list of selected tasks saved in registry at install time
|
|
||||||
appid := '{#emit SetupSetting("AppId")}';
|
|
||||||
if appid = '' then appid := '{#emit SetupSetting("AppName")}';
|
|
||||||
regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1');
|
|
||||||
RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring);
|
|
||||||
if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring);
|
|
||||||
|
|
||||||
// check each task; if matches modpath taskname, trigger patch removal
|
|
||||||
if regstring <> '' then begin
|
|
||||||
taskname := ModPathName;
|
|
||||||
MPExplode(aSelectedTasks, regstring, ',');
|
|
||||||
if GetArrayLength(aSelectedTasks) > 0 then begin
|
|
||||||
for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin
|
|
||||||
if comparetext(aSelectedTasks[i], taskname) = 0 then
|
|
||||||
ModPath();
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function NeedRestart(): Boolean;
|
|
||||||
var
|
|
||||||
taskname: String;
|
|
||||||
begin
|
|
||||||
taskname := ModPathName;
|
|
||||||
if IsTaskSelected(taskname) and not UsingWinNT() then begin
|
|
||||||
Result := True;
|
|
||||||
end else begin
|
|
||||||
Result := False;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
@ -8,8 +8,7 @@
|
|||||||
//#include "builtin.h"
|
//#include "builtin.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const string WHITESPACE = " \t\f";
|
const string WHITESPACE = " \n\r\t\f\v";
|
||||||
//const string WHITESPACE = " \n\r\t\f\v";
|
|
||||||
|
|
||||||
|
|
||||||
bool isNumber(const string& str)
|
bool isNumber(const string& str)
|
||||||
@ -26,51 +25,6 @@ bool stob(const string& str)
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
string unescape(const string& s)
|
|
||||||
{
|
|
||||||
string res;
|
|
||||||
string::const_iterator it = s.begin();
|
|
||||||
while (it != s.end())
|
|
||||||
{
|
|
||||||
char c = *it++;
|
|
||||||
if (c == '\\' && it != s.end())
|
|
||||||
{
|
|
||||||
switch (*it++) {
|
|
||||||
case '\\': c = '\\'; break;
|
|
||||||
case 'n': c = '\n'; break;
|
|
||||||
case 't': c = '\t'; break;
|
|
||||||
// all other escapes
|
|
||||||
default:
|
|
||||||
// invalid escape sequence - skip it. alternatively you can copy it as is, throw an exception...
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string escaped(const std::string& input)
|
|
||||||
{
|
|
||||||
std::string output;
|
|
||||||
output.reserve(input.size());
|
|
||||||
for (const char c : input) {
|
|
||||||
switch (c) {
|
|
||||||
case '\a': output += "\\a"; break;
|
|
||||||
case '\b': output += "\\b"; break;
|
|
||||||
case '\f': output += "\\f"; break;
|
|
||||||
case '\n': output += "\\n"; break;
|
|
||||||
case '\r': output += "\\r"; break;
|
|
||||||
case '\t': output += "\\t"; break;
|
|
||||||
case '\v': output += "\\v"; break;
|
|
||||||
default: output += c; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
string StringRaw(const string& s)
|
string StringRaw(const string& s)
|
||||||
{
|
{
|
||||||
string str = trim(s);
|
string str = trim(s);
|
||||||
@ -88,7 +42,7 @@ string StringRaw(const string& s)
|
|||||||
if (str[str.size() - 1] != '\"')
|
if (str[str.size() - 1] != '\"')
|
||||||
withoutQuotes += str[str.size() - 1];
|
withoutQuotes += str[str.size() - 1];
|
||||||
|
|
||||||
return unescape(withoutQuotes);
|
return withoutQuotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Quoted(const string& s)
|
string Quoted(const string& s)
|
||||||
@ -196,81 +150,6 @@ int countNoOverlap(const string& str, const char& searchFor, const char& ch1, co
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> splitNoOverlap(const string& str, const char& splitBy, const char& openChar, const char& closeChar)
|
|
||||||
{
|
|
||||||
vector<string> newStr;
|
|
||||||
|
|
||||||
int openCount = 0;
|
|
||||||
|
|
||||||
string tmpStr = "";
|
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
|
||||||
{
|
|
||||||
if (i == (int)str.size() - 1)
|
|
||||||
{
|
|
||||||
newStr.push_back(trim(tmpStr + str[i]));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[i] == splitBy && openCount == 0)
|
|
||||||
{
|
|
||||||
newStr.push_back(trim(tmpStr));
|
|
||||||
tmpStr = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (str[i] == openChar) {
|
|
||||||
tmpStr += str[i];
|
|
||||||
openCount += 1;
|
|
||||||
}
|
|
||||||
else if (str[i] == closeChar) {
|
|
||||||
tmpStr += str[i];
|
|
||||||
openCount -= 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tmpStr += str[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return newStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
string betweenChars(const string& str, const char& openChar, const char& closeChar)
|
|
||||||
{
|
|
||||||
string content = "";
|
|
||||||
|
|
||||||
int startPos = 0;
|
|
||||||
int endPos = (int)str.size();
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
|
||||||
{
|
|
||||||
if (str[i] == openChar){
|
|
||||||
startPos = i+1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = (int)str.size()-1; i >=0; i--)
|
|
||||||
{
|
|
||||||
if (str[i] == closeChar){
|
|
||||||
endPos = i-(startPos); // or startPos-1 idk I cant do math right now
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.substr(startPos, endPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool startsWith(const string& str, const string& lookFor)
|
|
||||||
{
|
|
||||||
if (str.empty() || lookFor.size() > str.size())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)lookFor.size(); i++)
|
|
||||||
{
|
|
||||||
if (str[i] != lookFor[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int countOutsideParenthesis(const string& str, const char& searchFor)
|
int countOutsideParenthesis(const string& str, const char& searchFor)
|
||||||
{
|
{
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|||||||
@ -12,7 +12,6 @@ int AnyAsInt(const boost::any& val);
|
|||||||
bool AnyAsBool(const boost::any& val);
|
bool AnyAsBool(const boost::any& val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool isNumber(const string& str);
|
bool isNumber(const string& str);
|
||||||
|
|
||||||
bool stob(const string& str);
|
bool stob(const string& str);
|
||||||
@ -31,10 +30,6 @@ string trim(const string& s);
|
|||||||
|
|
||||||
vector<string> split(const string& str, const char& del);
|
vector<string> split(const string& str, const char& del);
|
||||||
|
|
||||||
string betweenChars(const string& str, const char& openChar, const char& closeChar);
|
|
||||||
|
|
||||||
vector<string> splitNoOverlap(const string& str, const char& splitBy, const char& openChar, const char& closeChar);
|
|
||||||
|
|
||||||
int count(const string& str, const char& ch);
|
int count(const string& str, const char& ch);
|
||||||
|
|
||||||
int countNoOverlap(const string& str, const char& searchFor, const char& ch1, const char& ch2);
|
int countNoOverlap(const string& str, const char& searchFor, const char& ch1, const char& ch2);
|
||||||
@ -67,8 +62,4 @@ string replace(const string& str, const string& strToReplace, const string& repl
|
|||||||
|
|
||||||
bool isEscaped(const string& str, int curChar);
|
bool isEscaped(const string& str, int curChar);
|
||||||
|
|
||||||
bool startsWith(const string& str, const string& lookFor);
|
|
||||||
|
|
||||||
std::string escaped(const std::string& input);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 297 B |
@ -1,157 +0,0 @@
|
|||||||
int g_screenw = 256
|
|
||||||
int g_screenh = 224
|
|
||||||
int g_resolutionScale = 3
|
|
||||||
|
|
||||||
float g_playerWalkSpeed = 150
|
|
||||||
float g_playerRunSpeed = 210
|
|
||||||
float g_jumpHeight = 200
|
|
||||||
float g_currPlayerSpeed = 400
|
|
||||||
|
|
||||||
bool g_running = false
|
|
||||||
bool g_colliding = false
|
|
||||||
|
|
||||||
float g_gravitySpeed = 86
|
|
||||||
|
|
||||||
bool g_jumping = false
|
|
||||||
float g_jumpingTime = 0
|
|
||||||
|
|
||||||
//include "./extra-include.zs"
|
|
||||||
|
|
||||||
func Main()
|
|
||||||
{
|
|
||||||
//SplitThread(ThreadedFunction())
|
|
||||||
EXIT_WHEN_DONE = false
|
|
||||||
|
|
||||||
// Immediately creates the window, then runs Start(), then the game loop. The game loop calls Update() every frame
|
|
||||||
ZS.Graphics.Init("Platformer game", g_screenw, g_screenh, g_resolutionScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start()
|
|
||||||
{
|
|
||||||
float centerX = g_screenw / 2
|
|
||||||
float centerY = g_screenh / 2
|
|
||||||
|
|
||||||
|
|
||||||
global Vec2 v_aa = NVec2(g_screenw / 2 + -40, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_aa = ZS.Graphics.Sprite("./mariostill.png", v_aa, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ab = NVec2(g_screenw / 2 + -30, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ab = ZS.Graphics.Sprite("./mariostill.png", v_ab, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ac = NVec2(g_screenw / 2 + -20, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ac = ZS.Graphics.Sprite("./mariostill.png", v_ac, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ad = NVec2(g_screenw / 2 + -10, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ad = ZS.Graphics.Sprite("./mariostill.png", v_ad, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ae = NVec2(g_screenw / 2 + -0, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ae = ZS.Graphics.Sprite("./mariostill.png", v_ae, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_af = NVec2(g_screenw / 2 + 10, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_af = ZS.Graphics.Sprite("./mariostill.png", v_af, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ag = NVec2(g_screenw / 2 + 20, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ag = ZS.Graphics.Sprite("./mariostill.png", v_ag, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ah = NVec2(g_screenw / 2 + 30, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ah = ZS.Graphics.Sprite("./mariostill.png", v_ah, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ai = NVec2(g_screenw / 2 + 40, g_screenh / 2 + -40)
|
|
||||||
global Sprite s_ai = ZS.Graphics.Sprite("./mariostill.png", v_ai, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_aj = NVec2(g_screenw / 2 + -40, g_screenh / 2 + -30)
|
|
||||||
global Sprite s_aj = ZS.Graphics.Sprite("./mariostill.png", v_aj, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_ak = NVec2(g_screenw / 2 + -30, g_screenh / 2 + -30)
|
|
||||||
global Sprite s_ak = ZS.Graphics.Sprite("./mariostill.png", v_ak, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Vec2 v_al = NVec2(g_screenw / 2 + -20, g_screenh / 2 + -30)
|
|
||||||
global Sprite s_al = ZS.Graphics.Sprite("./mariostill.png", v_al, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func Update(deltaTime)
|
|
||||||
{
|
|
||||||
float fps = 1 / deltaTime
|
|
||||||
Printl("FPS: " + fps)
|
|
||||||
|
|
||||||
// // Shift key lets you sprint
|
|
||||||
// g_running = GetKey("SHIFT_L")
|
|
||||||
|
|
||||||
// if g_running == true
|
|
||||||
// {
|
|
||||||
// g_currPlayerSpeed = g_playerRunSpeed
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if g_running == false
|
|
||||||
// {
|
|
||||||
// g_currPlayerSpeed = g_playerWalkSpeed
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Move Left And Right
|
|
||||||
// if GetKey("D") == true
|
|
||||||
// {
|
|
||||||
// g_playerTargetPosition.x += g_currPlayerSpeed * deltaTime
|
|
||||||
// }
|
|
||||||
// if GetKey("A") == true
|
|
||||||
// {
|
|
||||||
// g_playerTargetPosition.x -= g_currPlayerSpeed * deltaTime
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// // Apply gravity
|
|
||||||
// g_colliding = Colliding(g_playerSprite, g_groundSprite)
|
|
||||||
// if g_colliding == false
|
|
||||||
// {
|
|
||||||
// if g_jumping == false
|
|
||||||
// {
|
|
||||||
// g_playerTargetPosition.y += deltaTime * g_gravitySpeed
|
|
||||||
// }
|
|
||||||
// if g_jumping == true
|
|
||||||
// {
|
|
||||||
// g_playerTargetPosition.y -= (g_jumpHeight * deltaTime) + (deltaTime * g_gravitySpeed * -g_jumpingTime * 5)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if g_colliding == true
|
|
||||||
// {
|
|
||||||
// if GetKey("SPACE") == false
|
|
||||||
// {
|
|
||||||
// if g_jumpingTime > 1
|
|
||||||
// {
|
|
||||||
// g_jumping = false
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if GetKey("SPACE") == true
|
|
||||||
// {
|
|
||||||
// g_jumping = true
|
|
||||||
// g_jumpingTime = 0
|
|
||||||
// g_playerTargetPosition.y -= 2
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Lerps from old position to destination smoothly
|
|
||||||
// float stopSpeed = deltaTime * 15
|
|
||||||
// float lerpedX = Lerp(g_playerSprite.position.x, g_playerTargetPosition.x, stopSpeed)
|
|
||||||
// s_aa.position = NVec2(lerpedX, g_playerTargetPosition.y)
|
|
||||||
|
|
||||||
// Finally draws all of the sprites
|
|
||||||
ZS.Graphics.Draw(s_aa)
|
|
||||||
ZS.Graphics.Draw(s_ab)
|
|
||||||
ZS.Graphics.Draw(s_ac)
|
|
||||||
ZS.Graphics.Draw(s_ad)
|
|
||||||
ZS.Graphics.Draw(s_ae)
|
|
||||||
ZS.Graphics.Draw(s_af)
|
|
||||||
ZS.Graphics.Draw(s_ag)
|
|
||||||
ZS.Graphics.Draw(s_ah)
|
|
||||||
ZS.Graphics.Draw(s_ai)
|
|
||||||
ZS.Graphics.Draw(s_aj)
|
|
||||||
ZS.Graphics.Draw(s_ak)
|
|
||||||
ZS.Graphics.Draw(s_al)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Colliding(a, b)
|
|
||||||
{
|
|
||||||
bool bo = ZS.Physics.AxisAlignedCollision(a, b)
|
|
||||||
return bo
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,103 +0,0 @@
|
|||||||
// This is an "included" ZS file, which can keep your main script
|
|
||||||
// tidier and more organized or easily share the same functions
|
|
||||||
// across multiple programs.
|
|
||||||
|
|
||||||
|
|
||||||
func TestInclude()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Benchmark, to check if performance suffers from too many functions/variables
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
func b1()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b2()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b3()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b4()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b5()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b6()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b7()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b8()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b9()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b10()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b11()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b12()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b13()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b14()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b15()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
func b16()
|
|
||||||
{
|
|
||||||
Printl("Hello World!")
|
|
||||||
}
|
|
||||||
|
|
||||||
int a = 4
|
|
||||||
int b = 4
|
|
||||||
int c = 4
|
|
||||||
int d = 4
|
|
||||||
int e = 4
|
|
||||||
int f = 4
|
|
||||||
int g = 4
|
|
||||||
int h = 4
|
|
||||||
int i = 4
|
|
||||||
int j = 4
|
|
||||||
int k = 4
|
|
||||||
int l = 4
|
|
||||||
int m = 4
|
|
||||||
int n = 4
|
|
||||||
int o = 4
|
|
||||||
int p = 4
|
|
||||||
int q = 4
|
|
||||||
int r = 4
|
|
||||||
int s = 4
|
|
||||||
int t = 4
|
|
||||||
int u = 4
|
|
||||||
int v = 4
|
|
||||||
int w = 4
|
|
||||||
int x = 4
|
|
||||||
int y = 4
|
|
||||||
int z = 4
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 297 B |
@ -1,128 +0,0 @@
|
|||||||
int g_screenw = 256
|
|
||||||
int g_screenh = 224
|
|
||||||
int g_resolutionScale = 3
|
|
||||||
|
|
||||||
float g_playerWalkSpeed = 150
|
|
||||||
float g_playerRunSpeed = 210
|
|
||||||
float g_jumpHeight = 200
|
|
||||||
float g_currPlayerSpeed = 400
|
|
||||||
|
|
||||||
bool g_running = false
|
|
||||||
bool g_colliding = false
|
|
||||||
|
|
||||||
float g_gravitySpeed = 86
|
|
||||||
|
|
||||||
bool g_jumping = false
|
|
||||||
float g_jumpingTime = 0
|
|
||||||
|
|
||||||
//include "./extra-include.zs"
|
|
||||||
|
|
||||||
func Main()
|
|
||||||
{
|
|
||||||
//SplitThread(ThreadedFunction())
|
|
||||||
EXIT_WHEN_DONE = false
|
|
||||||
|
|
||||||
// Immediately creates the window, then runs Start(), then the game loop. The game loop calls Update() every frame
|
|
||||||
ZS.Graphics.Init("Platformer game", g_screenw, g_screenh, g_resolutionScale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ThreadedFunction()
|
|
||||||
{
|
|
||||||
Printl("threaded:")
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start()
|
|
||||||
{
|
|
||||||
float centerX = g_screenw / 2
|
|
||||||
float centerY = g_screenh / 2
|
|
||||||
global Vec2 g_screencenter = NVec2(g_screenw / 2, g_screenh / 2)
|
|
||||||
|
|
||||||
global Sprite g_playerSprite = ZS.Graphics.Sprite("./mariostill.png", g_screencenter, NVec2(16, 16), 0)
|
|
||||||
|
|
||||||
global Sprite g_groundSprite = ZS.Graphics.Sprite("./square.png", NVec2(g_screencenter.x, 192), NVec2(256, 16), 0)
|
|
||||||
|
|
||||||
global Text g_instructionsText = ZS.Graphics.Text("Use Arrow Keys or WASD to Move and Spacebar to Jump", "./arial.ttf", NVec2(g_screencenter.x, g_screencenter.y), 8, 0, 255, 255, 255)
|
|
||||||
g_instructionsText.antialias = false
|
|
||||||
|
|
||||||
global Vec2 g_playerTargetPosition = g_screencenter
|
|
||||||
}
|
|
||||||
|
|
||||||
func Update(deltaTime)
|
|
||||||
{
|
|
||||||
float fps = 1 / deltaTime
|
|
||||||
g_jumpingTime += deltaTime
|
|
||||||
Printl("FPS: " + fps)
|
|
||||||
//TestInclude()
|
|
||||||
|
|
||||||
// Shift key lets you sprint
|
|
||||||
g_running = GetKey("SHIFT_L")
|
|
||||||
|
|
||||||
if g_running == true
|
|
||||||
{
|
|
||||||
g_currPlayerSpeed = g_playerRunSpeed
|
|
||||||
}
|
|
||||||
|
|
||||||
if g_running == false
|
|
||||||
{
|
|
||||||
g_currPlayerSpeed = g_playerWalkSpeed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move Left And Right
|
|
||||||
if GetKey("D") == true
|
|
||||||
{
|
|
||||||
g_playerTargetPosition.x += g_currPlayerSpeed * deltaTime
|
|
||||||
}
|
|
||||||
if GetKey("A") == true
|
|
||||||
{
|
|
||||||
g_playerTargetPosition.x -= g_currPlayerSpeed * deltaTime
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Apply gravity
|
|
||||||
g_colliding = Colliding(g_playerSprite, g_groundSprite)
|
|
||||||
if g_colliding == false
|
|
||||||
{
|
|
||||||
if g_jumping == false
|
|
||||||
{
|
|
||||||
g_playerTargetPosition.y += deltaTime * g_gravitySpeed
|
|
||||||
}
|
|
||||||
if g_jumping == true
|
|
||||||
{
|
|
||||||
g_playerTargetPosition.y -= (g_jumpHeight * deltaTime) + (deltaTime * g_gravitySpeed * -g_jumpingTime * 5)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if g_colliding == true
|
|
||||||
{
|
|
||||||
if GetKey("SPACE") == false
|
|
||||||
{
|
|
||||||
if g_jumpingTime > 1
|
|
||||||
{
|
|
||||||
g_jumping = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if GetKey("SPACE") == true
|
|
||||||
{
|
|
||||||
g_jumping = true
|
|
||||||
g_jumpingTime = 0
|
|
||||||
g_playerTargetPosition.y -= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lerps from old position to destination smoothly
|
|
||||||
float stopSpeed = deltaTime * 15
|
|
||||||
float lerpedX = Lerp(g_playerSprite.position.x, g_playerTargetPosition.x, stopSpeed)
|
|
||||||
g_playerSprite.position = NVec2(lerpedX, g_playerTargetPosition.y)
|
|
||||||
|
|
||||||
// Finally draws all of the sprites
|
|
||||||
ZS.Graphics.Draw(g_playerSprite)
|
|
||||||
ZS.Graphics.Draw(g_groundSprite)
|
|
||||||
|
|
||||||
// Draw the text
|
|
||||||
ZS.Graphics.DrawText(g_instructionsText)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Colliding(a, b)
|
|
||||||
{
|
|
||||||
bool bo = ZS.Physics.AxisAlignedCollision(a, b)
|
|
||||||
return bo
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 82 B |
Binary file not shown.
|
Before Width: | Height: | Size: 403 B |
@ -16,8 +16,6 @@ bool aiOn = false
|
|||||||
// so if you never call ZS.Graphics.Init, then Start won't run
|
// so if you never call ZS.Graphics.Init, then Start won't run
|
||||||
func Main()
|
func Main()
|
||||||
{
|
{
|
||||||
EXIT_WHEN_DONE = false
|
|
||||||
|
|
||||||
// Immediately creates the window, then Start(), then the game loop. The game loop calls Update() every frame
|
// Immediately creates the window, then Start(), then the game loop. The game loop calls Update() every frame
|
||||||
ZS.Graphics.Init("This is a pong game", SCREENW, SCREENH)
|
ZS.Graphics.Init("This is a pong game", SCREENW, SCREENH)
|
||||||
}
|
}
|
||||||
@ -41,7 +39,7 @@ func Start()
|
|||||||
Vec2 rPaddlePosition = NVec2(rOffset, yPosPaddle)
|
Vec2 rPaddlePosition = NVec2(rOffset, yPosPaddle)
|
||||||
global Vec2 rPaddleTargetPosition = NVec2(rOffset, yPosPaddle)
|
global Vec2 rPaddleTargetPosition = NVec2(rOffset, yPosPaddle)
|
||||||
|
|
||||||
global Sprite ballSpr = ZS.Graphics.Sprite("./ball.png", ballPos, ballScale, 0)
|
global Sprite ballSpr = ZS.Graphics.Sprite("./square.png", ballPos, ballScale, 0)
|
||||||
global Sprite lPaddle = ZS.Graphics.Sprite("./square.png", lPaddlePosition, paddleScale, 0)
|
global Sprite lPaddle = ZS.Graphics.Sprite("./square.png", lPaddlePosition, paddleScale, 0)
|
||||||
global Sprite rPaddle = ZS.Graphics.Sprite("./square.png", rPaddlePosition, paddleScale, 0)
|
global Sprite rPaddle = ZS.Graphics.Sprite("./square.png", rPaddlePosition, paddleScale, 0)
|
||||||
|
|
||||||
@ -63,66 +61,75 @@ func Start()
|
|||||||
|
|
||||||
func Update(deltaTime)
|
func Update(deltaTime)
|
||||||
{
|
{
|
||||||
//float FPS = 1 / deltaTime
|
float FPS = 1 / deltaTime
|
||||||
//Printl("FPS: " + FPS)
|
print "FPS: " + FPS
|
||||||
|
|
||||||
// Handles Left Paddle Movement
|
// Handles Left Paddle Movement
|
||||||
//
|
//
|
||||||
if GetKey("W") == true
|
if GetKey("W") == true
|
||||||
{
|
{
|
||||||
|
float newX = lPaddle.position.x
|
||||||
// Subtract from Y to move up, because vertical coordinates are reversed
|
// Subtract from Y to move up, because vertical coordinates are reversed
|
||||||
float newY = lPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
float newY = lPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
||||||
lPaddleTargetPosition.y = newY
|
lPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
if GetKey("S") == true
|
if GetKey("S") == true
|
||||||
{
|
{
|
||||||
|
float newX = lPaddle.position.x
|
||||||
// Add to Y to move down, because vertical coordinates are reversed
|
// Add to Y to move down, because vertical coordinates are reversed
|
||||||
float newY = lPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
float newY = lPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
||||||
lPaddleTargetPosition.y = newY
|
lPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
// Lerps from old position to destination smoothly
|
// Lerps from old position to destination smoothly
|
||||||
float oldY = lPaddle.position.y
|
float oldY = lPaddle.position.y
|
||||||
float stopSpeed = deltaTime * lerpSpeed
|
float stopSpeed = deltaTime * lerpSpeed
|
||||||
float newY = lPaddleTargetPosition.y
|
float newY = lPaddleTargetPosition.y
|
||||||
float lerpedY = Lerp(oldY, newY, stopSpeed)
|
float lerpedY = Lerp(oldY, newY, stopSpeed)
|
||||||
lPaddle.position = NVec2(lPaddle.position.x, lerpedY)
|
lPaddle.position = NVec2(newX, lerpedY)
|
||||||
|
|
||||||
// Handles Right Paddle Movement
|
// Handles Right Paddle Movement
|
||||||
//
|
//
|
||||||
if aiOn == false
|
|
||||||
{
|
|
||||||
if GetKey("UP") == true
|
if GetKey("UP") == true
|
||||||
{
|
{
|
||||||
|
if aiOn == false
|
||||||
|
{
|
||||||
|
float newX = rPaddle.position.x
|
||||||
// Subtract from Y to move up, because vertical coordinates are reversed
|
// Subtract from Y to move up, because vertical coordinates are reversed
|
||||||
float newY = rPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
float newY = rPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition.y = newY
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if GetKey("DOWN") == true
|
if GetKey("DOWN") == true
|
||||||
{
|
{
|
||||||
|
if aiOn == false
|
||||||
|
{
|
||||||
|
float newX = rPaddle.position.x
|
||||||
// Add to Y to move down, because vertical coordinates are reversed
|
// Add to Y to move down, because vertical coordinates are reversed
|
||||||
float newY = rPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
float newY = rPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition.y = newY
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if aiOn == true
|
if aiOn == true
|
||||||
{
|
{
|
||||||
if rPaddle.position.y < ballSpr.position.y
|
if rPaddle.position.y < ballSpr.position.y
|
||||||
{
|
{
|
||||||
|
float newX = rPaddle.position.x
|
||||||
// Add to Y to move down, because vertical coordinates are reversed
|
// Add to Y to move down, because vertical coordinates are reversed
|
||||||
float newY = rPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
float newY = rPaddleTargetPosition.y + paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition.y = newY
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
if rPaddle.position.y > ballSpr.position.y
|
if rPaddle.position.y > ballSpr.position.y
|
||||||
{
|
{
|
||||||
|
float newX = rPaddle.position.x
|
||||||
// Subtract from Y to move up, because vertical coordinates are reversed
|
// Subtract from Y to move up, because vertical coordinates are reversed
|
||||||
float newY = rPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
float newY = rPaddleTargetPosition.y - paddleMoveSpeed * deltaTime
|
||||||
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition.y = newY
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Lerps from old position to destination smoothly
|
// Lerps from old position to destination smoothly
|
||||||
@ -130,20 +137,18 @@ func Update(deltaTime)
|
|||||||
float stopSpeed = deltaTime * lerpSpeed
|
float stopSpeed = deltaTime * lerpSpeed
|
||||||
float newY = rPaddleTargetPosition.y
|
float newY = rPaddleTargetPosition.y
|
||||||
float lerpedY = Lerp(oldY, newY, stopSpeed)
|
float lerpedY = Lerp(oldY, newY, stopSpeed)
|
||||||
rPaddle.position = NVec2(rPaddle.position.x, lerpedY)
|
rPaddle.position = NVec2(newX, lerpedY)
|
||||||
|
|
||||||
if GetKey("ENTER") == true
|
if GetKey("ENTER") == true
|
||||||
{
|
{
|
||||||
bool changeTo = false
|
|
||||||
if aiOn == true
|
if aiOn == true
|
||||||
{
|
{
|
||||||
changeTo = false
|
aiOn = false
|
||||||
}
|
}
|
||||||
if aiOn == false
|
if aiOn == false
|
||||||
{
|
{
|
||||||
changeTo = true
|
aiOn = true
|
||||||
}
|
}
|
||||||
aiOn = changeTo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 scaledVelocity = ballVelocity
|
Vec2 scaledVelocity = ballVelocity
|
||||||
@ -239,7 +244,7 @@ func HandleBallBounce()
|
|||||||
difference -= ballY
|
difference -= ballY
|
||||||
float paddleHeight = rPaddle.scale.y
|
float paddleHeight = rPaddle.scale.y
|
||||||
float normalizedRelativeIntersectionY = difference / (paddleHeight / 2)
|
float normalizedRelativeIntersectionY = difference / (paddleHeight / 2)
|
||||||
float bounceAngle = normalizedRelativeIntersectionY * -0.523599
|
float bounceAngle = normalizedRelativeIntersectionY * 0.523599
|
||||||
float ballVx = ballSpeed
|
float ballVx = ballSpeed
|
||||||
ballVx *= Cos(bounceAngle)
|
ballVx *= Cos(bounceAngle)
|
||||||
ballVx *= -1
|
ballVx *= -1
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
func Main()
|
|
||||||
{
|
|
||||||
Printl("this is a test:")
|
|
||||||
ZS.System.Command("cls")
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user