mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Finished pong clone, added full text functionality, added icon, and completed v1.0.0 of Slang
This commit is contained in:
parent
c1dda8efd8
commit
3f6e04b751
247
Slang/Main.cpp
247
Slang/Main.cpp
@ -9,6 +9,14 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/any.hpp>
|
#include <boost/any.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
|
#if defined(__unix__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
@ -16,6 +24,11 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "anyops.h"
|
#include "anyops.h"
|
||||||
|
|
||||||
|
#include "SLB.h"
|
||||||
|
|
||||||
|
#define DEVELOPER_MESSAGES false
|
||||||
|
#define EXAMPLE_PROJECT false
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
@ -80,7 +93,6 @@ vector<boost::any> VarValues(const vector<string>& varNames, unordered_map<strin
|
|||||||
else
|
else
|
||||||
realValues.push_back(EvalExpression(varName, variableValues));
|
realValues.push_back(EvalExpression(varName, variableValues));
|
||||||
}
|
}
|
||||||
//InterpreterLog(varName + " " + AnyAsString(realValues[realValues.size() - 1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return realValues;
|
return realValues;
|
||||||
@ -106,7 +118,9 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
string expression = trim(ex);
|
string expression = trim(ex);
|
||||||
bool inQuotes = false;
|
bool inQuotes = false;
|
||||||
|
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("OLDEXPRESSION: |" + expression + "|");
|
InterpreterLog("OLDEXPRESSION: |" + expression + "|");
|
||||||
|
#endif
|
||||||
|
|
||||||
bool isFunc = IsFunction(split(expression, '(')[0]);
|
bool isFunc = IsFunction(split(expression, '(')[0]);
|
||||||
bool isSLB = split(expression, '.')[0] == "SLB";
|
bool isSLB = split(expression, '.')[0] == "SLB";
|
||||||
@ -173,10 +187,8 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
//InterpreterLog(split(expression, '(')[0] + " " + AnyAsString(GetVariableValue(split(argContents, ',')[0], variableValues)));
|
|
||||||
string returnVal = AnyAsString(ExecuteFunction(name, VarValues(split(argContents, ','), variableValues)));
|
string returnVal = AnyAsString(ExecuteFunction(name, VarValues(split(argContents, ','), variableValues)));
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
//cout << newExpression << endl;
|
|
||||||
}
|
}
|
||||||
else if (split(name, '.')[0] == "SLB" && !inQuotes)
|
else if (split(name, '.')[0] == "SLB" && !inQuotes)
|
||||||
{
|
{
|
||||||
@ -207,7 +219,9 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
newExpression += expression[i];
|
newExpression += expression[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("NEW EXPRESSION: |" + newExpression + "|");
|
InterpreterLog("NEW EXPRESSION: |" + newExpression + "|");
|
||||||
|
#endif
|
||||||
|
|
||||||
bool addStrings = false;
|
bool addStrings = false;
|
||||||
for (int i = 0; i < (int)newExpression.size(); i++)
|
for (int i = 0; i < (int)newExpression.size(); i++)
|
||||||
@ -244,7 +258,9 @@ bool BooleanLogic(const string& valA, const string& determinant, const string& v
|
|||||||
{
|
{
|
||||||
boost::any valARealValue = EvalExpression(valA, variableValues);
|
boost::any valARealValue = EvalExpression(valA, variableValues);
|
||||||
boost::any valBRealValue = EvalExpression(valB, variableValues);
|
boost::any valBRealValue = EvalExpression(valB, variableValues);
|
||||||
//InterpreterLog(AnyAsString(valARealValue) + " " + determinant + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + determinant + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
InterpreterLog(AnyAsString(valARealValue) + " " + determinant + " " + AnyAsString(valBRealValue) + " : " + AnyAsString(valA) + " " + determinant + " " + AnyAsString(valB) + " : " + to_string(AnyAsString(valARealValue) == AnyAsString(valBRealValue)));
|
||||||
|
#endif
|
||||||
if (determinant == "==")
|
if (determinant == "==")
|
||||||
return any_compare(valARealValue, valBRealValue);
|
return any_compare(valARealValue, valBRealValue);
|
||||||
else if (determinant == "!=")
|
else if (determinant == "!=")
|
||||||
@ -265,89 +281,86 @@ bool BooleanLogic(const string& valA, const string& determinant, const string& v
|
|||||||
|
|
||||||
int varOperation(const vector<string>& str, unordered_map<string, boost::any>& variableValues)
|
int varOperation(const vector<string>& str, unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
if (IsVar(str[0], variableValues))
|
if (IsVar(str[0], variableValues))
|
||||||
|
{
|
||||||
|
// Checks if type is simple, like int or string
|
||||||
|
if (any_type(variableValues[str[0]]) <= 3)
|
||||||
{
|
{
|
||||||
// Checks if type is simple, like int or string
|
if (str[1] == "=")
|
||||||
if (any_type(variableValues[str[0]]) <= 3)
|
variableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
||||||
{
|
else if (str[1] == "+=")
|
||||||
if (str[1] == "=")
|
variableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
|
||||||
variableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
else if (str[1] == "-=")
|
||||||
else if (str[1] == "+=")
|
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
variableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
|
else if (str[1] == "*=")
|
||||||
else if (str[1] == "-=")
|
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
else if (str[1] == "/=")
|
||||||
else if (str[1] == "*=")
|
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
else
|
||||||
else if (str[1] == "/=")
|
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
||||||
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
|
||||||
else
|
|
||||||
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
|
||||||
}
|
|
||||||
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
|
|
||||||
else if(any_type(variableValues[str[0]]) == 5)
|
|
||||||
{
|
|
||||||
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
|
||||||
if (str[1] == "=")
|
|
||||||
variableValues[str[0]] = otherExpression;
|
|
||||||
else if (str[1] == "+=")
|
|
||||||
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) + AnyAsVec2(otherExpression);
|
|
||||||
else if (str[1] == "-=")
|
|
||||||
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) - AnyAsVec2(otherExpression);
|
|
||||||
else if (str[1] == "*=")
|
|
||||||
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) * AnyAsFloat(otherExpression);
|
|
||||||
else if (str[1] == "/=")
|
|
||||||
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) / AnyAsFloat(otherExpression);
|
|
||||||
else
|
|
||||||
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else if (IsVar(str[0], globalVariableValues))
|
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
|
||||||
|
else if (any_type(variableValues[str[0]]) == 5)
|
||||||
{
|
{
|
||||||
// Checks if type is simple, like int or string
|
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
||||||
if (any_type(globalVariableValues[str[0]]) <= 3)
|
if (str[1] == "=")
|
||||||
{
|
variableValues[str[0]] = otherExpression;
|
||||||
if (str[1] == "=")
|
else if (str[1] == "+=")
|
||||||
globalVariableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) + AnyAsVec2(otherExpression);
|
||||||
else if (str[1] == "+=")
|
else if (str[1] == "-=")
|
||||||
globalVariableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
|
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) - AnyAsVec2(otherExpression);
|
||||||
else if (str[1] == "-=")
|
else if (str[1] == "*=")
|
||||||
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) * AnyAsFloat(otherExpression);
|
||||||
else if (str[1] == "*=")
|
else if (str[1] == "/=")
|
||||||
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) / AnyAsFloat(otherExpression);
|
||||||
else if (str[1] == "/=")
|
else
|
||||||
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
||||||
else
|
|
||||||
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
|
||||||
}
|
|
||||||
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
|
|
||||||
else if (any_type(globalVariableValues[str[0]]) == 5)
|
|
||||||
{
|
|
||||||
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
|
||||||
if (str[1] == "=")
|
|
||||||
globalVariableValues[str[0]] = otherExpression;
|
|
||||||
else if (str[1] == "+=")
|
|
||||||
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) + AnyAsVec2(otherExpression);
|
|
||||||
else if (str[1] == "-=")
|
|
||||||
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) - AnyAsVec2(otherExpression);
|
|
||||||
else if (str[1] == "*=")
|
|
||||||
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) * AnyAsFloat(otherExpression);
|
|
||||||
else if (str[1] == "/=")
|
|
||||||
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) / AnyAsFloat(otherExpression);
|
|
||||||
else
|
|
||||||
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
LogWarning("uninitialized variable or typo in \'" + str[0] + "\'");
|
return 0;
|
||||||
return 1;
|
}
|
||||||
|
else if (IsVar(str[0], globalVariableValues))
|
||||||
|
{
|
||||||
|
// Checks if type is simple, like int or string
|
||||||
|
if (any_type(globalVariableValues[str[0]]) <= 3)
|
||||||
|
{
|
||||||
|
if (str[1] == "=")
|
||||||
|
globalVariableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
||||||
|
else if (str[1] == "+=")
|
||||||
|
globalVariableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
|
||||||
|
else if (str[1] == "-=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
|
else if (str[1] == "*=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
|
else if (str[1] == "/=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
|
||||||
|
else
|
||||||
|
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
||||||
|
}
|
||||||
|
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
|
||||||
|
else if (any_type(globalVariableValues[str[0]]) == 5)
|
||||||
|
{
|
||||||
|
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
|
||||||
|
if (str[1] == "=")
|
||||||
|
globalVariableValues[str[0]] = otherExpression;
|
||||||
|
else if (str[1] == "+=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) + AnyAsVec2(otherExpression);
|
||||||
|
else if (str[1] == "-=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) - AnyAsVec2(otherExpression);
|
||||||
|
else if (str[1] == "*=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) * AnyAsFloat(otherExpression);
|
||||||
|
else if (str[1] == "/=")
|
||||||
|
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) / AnyAsFloat(otherExpression);
|
||||||
|
else
|
||||||
|
LogWarning("unrecognized operator \'" + str[1] + "\'");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LogWarning("uninitialized variable or typo in \'" + str[0] + "\'");
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
//InterpreterLog(unWrapVec(words[lineNum]));
|
|
||||||
//InterpreterLog(AnyAsString(GetVariableValue("out", variableValues)));
|
|
||||||
|
|
||||||
if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/')
|
if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/')
|
||||||
return nullType;
|
return nullType;
|
||||||
|
|
||||||
@ -369,10 +382,10 @@ boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unorder
|
|||||||
// Check if it is function
|
// Check if it is function
|
||||||
else if (IsFunction(trim(split(words[lineNum][0], '(')[0])))
|
else if (IsFunction(trim(split(words[lineNum][0], '(')[0])))
|
||||||
{
|
{
|
||||||
if(count(words[lineNum][0], '(') >0 && count(words[lineNum][0], ')') > 0)
|
if (count(words[lineNum][0], '(') > 0 && count(words[lineNum][0], ')') > 0)
|
||||||
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), vector<boost::any>());
|
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), vector<boost::any>());
|
||||||
else
|
else
|
||||||
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(words[lineNum], 0, (int)words[lineNum].size()-1)), '(')[1]), ','), variableValues));
|
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(words[lineNum], 0, (int)words[lineNum].size() - 1)), '(')[1]), ','), variableValues));
|
||||||
return nullType;
|
return nullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +540,9 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
|||||||
for (int i = 0; i < (int)inputVarVals.size(); i++) {
|
for (int i = 0; i < (int)inputVarVals.size(); i++) {
|
||||||
|
|
||||||
variableValues[args[i]] = inputVarVals[i];
|
variableValues[args[i]] = inputVarVals[i];
|
||||||
//cout << functionName + " \x1B[33m" << args[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << functionName + " \x1B[33m" << args[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//Iterate through all lines in function
|
//Iterate through all lines in function
|
||||||
@ -575,7 +590,6 @@ int parseSlang(string script)
|
|||||||
}
|
}
|
||||||
|
|
||||||
args = trim(replace(args, functName + " ", ""));
|
args = trim(replace(args, functName + " ", ""));
|
||||||
//InterpreterLog(args);
|
|
||||||
functionContents.push_back(split(args, ','));
|
functionContents.push_back(split(args, ','));
|
||||||
|
|
||||||
int numOfBrackets = 1;
|
int numOfBrackets = 1;
|
||||||
@ -605,32 +619,71 @@ int parseSlang(string script)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executes main, which is the starting function
|
// Executes main, which is the starting function
|
||||||
ExecuteFunction("Main", vector<boost::any> {"hi", 0});
|
ExecuteFunction("Main", vector<boost::any> {});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Get builtin script contents
|
|
||||||
ifstream builtin("../Slang/builtin.slg");
|
|
||||||
stringstream builtinString;
|
|
||||||
builtinString << builtin.rdbuf();
|
|
||||||
|
|
||||||
// Gathers builtin functions and variables
|
// Gathers builtin functions and variables
|
||||||
GetBuiltins(builtinString.str());
|
GetBuiltins(SLBContents);
|
||||||
functionValues = builtinFunctionValues;
|
functionValues = builtinFunctionValues;
|
||||||
globalVariableValues = builtinVarVals;
|
globalVariableValues = builtinVarVals;
|
||||||
|
|
||||||
// Get default script contents
|
|
||||||
ifstream script("../Slang/script.slg");
|
|
||||||
stringstream scriptString;
|
stringstream scriptString;
|
||||||
scriptString << script.rdbuf();
|
#if EXAMPLE_PROJECT == false
|
||||||
|
// If scriptname is supplied and not in developer mode
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
std::string scriptPath = argv[1];
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << scriptPath << endl;
|
||||||
|
#endif
|
||||||
|
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||||
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
|
std::wstring wide = converter.from_bytes(projectDirectory);
|
||||||
|
|
||||||
while (true) {
|
#if defined(__unix__)
|
||||||
system("pause");
|
chdir(projectDirectory);
|
||||||
break;
|
#elif defined(_MSC_VER)
|
||||||
|
LPCWSTR s = wide.c_str();
|
||||||
|
SetCurrentDirectory(s);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Get script contents
|
||||||
|
ifstream script(scriptPath);
|
||||||
|
scriptString << script.rdbuf();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogCriticalError("No script provided! Please drag and drop .SLG file over interpreter executable file, or provide it's path as a command-line argument.");
|
||||||
|
system("pause");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// If in developer mode
|
||||||
|
std::string scriptPath = "./script.slg";
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << scriptPath << endl;
|
||||||
|
#endif
|
||||||
|
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||||
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
|
std::wstring wide = converter.from_bytes(projectDirectory);
|
||||||
|
|
||||||
|
#if defined(__unix__)
|
||||||
|
chdir(projectDirectory);
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
LPCWSTR s = wide.c_str();
|
||||||
|
SetCurrentDirectory(s);
|
||||||
|
#endif
|
||||||
|
// Get script contents
|
||||||
|
ifstream script(scriptPath);
|
||||||
|
scriptString << script.rdbuf();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
system("pause");
|
||||||
|
|
||||||
parseSlang(scriptString.str());
|
parseSlang(scriptString.str());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 802 B After Width: | Height: | Size: 802 B |
BIN
Slang/Pong-Project/net.png
Normal file
BIN
Slang/Pong-Project/net.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 93 B |
@ -10,7 +10,7 @@ float paddleMoveSpeed = 16
|
|||||||
|
|
||||||
// Main is always run at the VERY BEGINNING. Start() is the start of GRAPHICS
|
// Main is always run at the VERY BEGINNING. Start() is the start of GRAPHICS
|
||||||
// so if you never call SLB.Grapgics.Init, then Start won't run
|
// so if you never call SLB.Grapgics.Init, then Start won't run
|
||||||
func Main(input, in)
|
func Main()
|
||||||
{
|
{
|
||||||
// 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
|
||||||
SLB.Graphics.Init("This is a pong game", SCREENW, SCREENH)
|
SLB.Graphics.Init("This is a pong game", SCREENW, SCREENH)
|
||||||
@ -27,12 +27,13 @@ func Start()
|
|||||||
ballPos -= ballScale
|
ballPos -= ballScale
|
||||||
|
|
||||||
Vec2 paddleScale = NVec2(4, 70)
|
Vec2 paddleScale = NVec2(4, 70)
|
||||||
float yPosPaddle = ballPos.y - (paddleScale.y / 2)
|
float yPosPaddle = centerOfScreen.y
|
||||||
|
yPosPaddle -= paddleScale.y / 2
|
||||||
|
|
||||||
Vec2 lPaddlePosition = NVec2(15, yPosPaddle)
|
Vec2 lPaddlePosition = NVec2(15, yPosPaddle)
|
||||||
global Vec2 lPaddleTargetPosition = NVec2(15, yPosPaddle)
|
global Vec2 lPaddleTargetPosition = NVec2(15, yPosPaddle)
|
||||||
|
|
||||||
float rOffset = SCREENW - (paddleScale.x + 15)
|
float rOffset = SCREENW - 15
|
||||||
Vec2 rPaddlePosition = NVec2(rOffset, yPosPaddle)
|
Vec2 rPaddlePosition = NVec2(rOffset, yPosPaddle)
|
||||||
global Vec2 rPaddleTargetPosition = NVec2(rOffset, yPosPaddle)
|
global Vec2 rPaddleTargetPosition = NVec2(rOffset, yPosPaddle)
|
||||||
|
|
||||||
@ -40,12 +41,15 @@ func Start()
|
|||||||
global Sprite lPaddle = SLB.Graphics.Sprite("./square.png", lPaddlePosition, paddleScale, 0)
|
global Sprite lPaddle = SLB.Graphics.Sprite("./square.png", lPaddlePosition, paddleScale, 0)
|
||||||
global Sprite rPaddle = SLB.Graphics.Sprite("./square.png", rPaddlePosition, paddleScale, 0)
|
global Sprite rPaddle = SLB.Graphics.Sprite("./square.png", rPaddlePosition, paddleScale, 0)
|
||||||
|
|
||||||
|
Vec2 netScale = NVec2(1, SCREENH)
|
||||||
|
global Sprite net = SLB.Graphics.Sprite("./net.png", centerOfScreen, netScale, 0)
|
||||||
|
|
||||||
float leftOffset = SCREENW / 4
|
float leftOffset = SCREENW / 4
|
||||||
Vec2 scoreOnePos = NVec2(leftOffset - 40, 30)
|
Vec2 scoreOnePos = NVec2(leftOffset, 30)
|
||||||
global Text scoreTextOne = SLB.Graphics.Text("score", "./arial.ttf", scoreOnePos, 40, 0, 255, 255, 255)
|
global Text scoreTextOne = SLB.Graphics.Text("0", "./arial.ttf", scoreOnePos, 60, 0, 255, 255, 255)
|
||||||
float rightOffset = SCREENW - (SCREENW / 4)
|
float rightOffset = SCREENW - (SCREENW / 4)
|
||||||
Vec2 scoreTwoPos = NVec2(rightOffset - 40, 30)
|
Vec2 scoreTwoPos = NVec2(rightOffset, 30)
|
||||||
global Text scoreTextTwo = SLB.Graphics.Text("score", "./arial.ttf", scoreTwoPos, 40, 0, 255, 255, 255)
|
global Text scoreTextTwo = SLB.Graphics.Text("0", "./arial.ttf", scoreTwoPos, 60, 0, 255, 255, 255)
|
||||||
|
|
||||||
global Vec2 ballVelocity = NVec2(ballSpeed, ballSpeed)
|
global Vec2 ballVelocity = NVec2(ballSpeed, ballSpeed)
|
||||||
}
|
}
|
||||||
@ -62,18 +66,16 @@ func Update(deltaTime)
|
|||||||
float newX = lPaddle.position.x
|
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
|
float newY = lPaddleTargetPosition.y - paddleMoveSpeed
|
||||||
newY = Clamp(newY, 0, SCREENH - 70)
|
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
||||||
lPaddleTargetPosition = NVec2(newX, newY)
|
lPaddleTargetPosition = NVec2(newX, newY)
|
||||||
print "MOVE UP"
|
|
||||||
}
|
}
|
||||||
if GetKey("S") == true
|
if GetKey("S") == true
|
||||||
{
|
{
|
||||||
float newX = lPaddle.position.x
|
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
|
float newY = lPaddleTargetPosition.y + paddleMoveSpeed
|
||||||
newY = Clamp(newY, 0, SCREENH - 70)
|
newY = Clamp(newY, 0 + lPaddle.scale.y / 2, SCREENH - lPaddle.scale.y / 2)
|
||||||
lPaddleTargetPosition = NVec2(newX, newY)
|
lPaddleTargetPosition = NVec2(newX, newY)
|
||||||
print "MOVE DOWN"
|
|
||||||
}
|
}
|
||||||
// Lerps from old position to destination smoothly
|
// Lerps from old position to destination smoothly
|
||||||
float oldY = lPaddle.position.y
|
float oldY = lPaddle.position.y
|
||||||
@ -89,7 +91,7 @@ func Update(deltaTime)
|
|||||||
float newX = rPaddle.position.x
|
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
|
float newY = rPaddleTargetPosition.y - paddleMoveSpeed
|
||||||
newY = Clamp(newY, 0, SCREENH - 70)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition = NVec2(newX, newY)
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
if GetKey("DOWN") == true
|
if GetKey("DOWN") == true
|
||||||
@ -97,7 +99,7 @@ func Update(deltaTime)
|
|||||||
float newX = rPaddle.position.x
|
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
|
float newY = rPaddleTargetPosition.y + paddleMoveSpeed
|
||||||
newY = Clamp(newY, 0, SCREENH - 70)
|
newY = Clamp(newY, 0 + rPaddle.scale.y / 2, SCREENH - rPaddle.scale.y / 2)
|
||||||
rPaddleTargetPosition = NVec2(newX, newY)
|
rPaddleTargetPosition = NVec2(newX, newY)
|
||||||
}
|
}
|
||||||
// Lerps from old position to destination smoothly
|
// Lerps from old position to destination smoothly
|
||||||
@ -114,6 +116,8 @@ func Update(deltaTime)
|
|||||||
SLB.Graphics.Draw(lPaddle)
|
SLB.Graphics.Draw(lPaddle)
|
||||||
SLB.Graphics.Draw(rPaddle)
|
SLB.Graphics.Draw(rPaddle)
|
||||||
|
|
||||||
|
SLB.Graphics.Draw(net)
|
||||||
|
|
||||||
SLB.Graphics.DrawText(scoreTextOne)
|
SLB.Graphics.DrawText(scoreTextOne)
|
||||||
SLB.Graphics.DrawText(scoreTextTwo)
|
SLB.Graphics.DrawText(scoreTextTwo)
|
||||||
|
|
||||||
@ -126,7 +130,7 @@ func HandleBallBounce()
|
|||||||
float ballY = ballSpr.position.y
|
float ballY = ballSpr.position.y
|
||||||
float scaleY = ballSpr.scale.y
|
float scaleY = ballSpr.scale.y
|
||||||
|
|
||||||
float topEdge = ballY - scaleY
|
float topEdge = ballY - scaleY/2
|
||||||
// Checks if the ball is touching the ceiling
|
// Checks if the ball is touching the ceiling
|
||||||
if topEdge <= 0
|
if topEdge <= 0
|
||||||
{
|
{
|
||||||
@ -136,7 +140,7 @@ func HandleBallBounce()
|
|||||||
ballVelocity = NVec2(vX, vY)
|
ballVelocity = NVec2(vX, vY)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
float bottomEdge = ballY + scaleY
|
float bottomEdge = ballY + scaleY/2
|
||||||
// Checks if the ball is touching the floor
|
// Checks if the ball is touching the floor
|
||||||
if bottomEdge >= SCREENH
|
if bottomEdge >= SCREENH
|
||||||
{
|
{
|
||||||
@ -157,8 +161,6 @@ func HandleBallBounce()
|
|||||||
ballSpr.position = ballPos
|
ballSpr.position = ballPos
|
||||||
ballVelocity = NVec2(ballSpeed, 0)
|
ballVelocity = NVec2(ballSpeed, 0)
|
||||||
scoreTextTwo.content = Round(scoreTwo)
|
scoreTextTwo.content = Round(scoreTwo)
|
||||||
print scoreTextTwo.content
|
|
||||||
SLB.Graphics.LoadText(scoreTextTwo)
|
|
||||||
}
|
}
|
||||||
// Checks if ball is in player 2 goal
|
// Checks if ball is in player 2 goal
|
||||||
if ballX > SCREENW
|
if ballX > SCREENW
|
||||||
@ -170,8 +172,6 @@ func HandleBallBounce()
|
|||||||
ballSpr.position = ballPos
|
ballSpr.position = ballPos
|
||||||
ballVelocity = NVec2(-ballSpeed, 0)
|
ballVelocity = NVec2(-ballSpeed, 0)
|
||||||
scoreTextOne.content = Round(scoreOne)
|
scoreTextOne.content = Round(scoreOne)
|
||||||
print scoreTextOne.content
|
|
||||||
SLB.Graphics.LoadText(scoreTextOne)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if colliding with left paddle
|
// Checks if colliding with left paddle
|
||||||
|
Before Width: | Height: | Size: 82 B After Width: | Height: | Size: 82 B |
@ -1,3 +1,8 @@
|
|||||||
|
#include<string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
std::string SLBContents = R"(
|
||||||
// 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
|
||||||
@ -27,14 +32,14 @@ func Tan(input)
|
|||||||
// Sigmoid activation function
|
// Sigmoid activation function
|
||||||
func Sigmoid(input)
|
func Sigmoid(input)
|
||||||
{
|
{
|
||||||
float out = 1 / (1+EulersNumber^-input)
|
float out = 1 / (1 + EulersNumber ^ -input)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hyperbolic tangent activation function
|
// Hyperbolic tangent activation function
|
||||||
func Tanh(input)
|
func Tanh(input)
|
||||||
{
|
{
|
||||||
float out = ((EulersNumber^input)-(EulersNumber^-input))/((EulersNumber^input)+(EulersNumber^-input))
|
float out = ((EulersNumber ^ input) - (EulersNumber ^ -input)) / ((EulersNumber ^ input) + (EulersNumber ^ -input))
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,3 +137,5 @@ func GetKey(keyName)
|
|||||||
bool b = SLB.Input.GetKey(keyName)
|
bool b = SLB.Input.GetKey(keyName)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
)"
|
||||||
|
;
|
||||||
71
Slang/Slang.rc
Normal file
71
Slang/Slang.rc
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// Microsoft Visual C++ generated resource script.
|
||||||
|
//
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
|
//
|
||||||
|
#include "winres.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// English (United States) resources
|
||||||
|
|
||||||
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||||
|
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||||
|
#pragma code_page(1252)
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// TEXTINCLUDE
|
||||||
|
//
|
||||||
|
|
||||||
|
1 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"resource.h\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
2 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"#include ""winres.h""\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
3 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Icon
|
||||||
|
//
|
||||||
|
|
||||||
|
// Icon with lowest ID value placed first to ensure application icon
|
||||||
|
// remains consistent on all systems.
|
||||||
|
IDI_ICON1 ICON "icon.ico"
|
||||||
|
|
||||||
|
#endif // English (United States) resources
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif // not APSTUDIO_INVOKED
|
||||||
|
|
||||||
@ -158,19 +158,23 @@
|
|||||||
<ClInclude Include="eval.h" />
|
<ClInclude Include="eval.h" />
|
||||||
<ClInclude Include="graphics.h" />
|
<ClInclude Include="graphics.h" />
|
||||||
<ClInclude Include="main.h" />
|
<ClInclude Include="main.h" />
|
||||||
<ClInclude Include="olcPixelGameEngine.h" />
|
<ClInclude Include="resource.h" />
|
||||||
|
<ClInclude Include="SLB.h" />
|
||||||
<ClInclude Include="strops.h" />
|
<ClInclude Include="strops.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="builtin.slg" />
|
|
||||||
<None Include="script.slg" />
|
<None Include="script.slg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="CMakeLists.txt" />
|
<Text Include="CMakeLists.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Image Include="icon.ico" />
|
||||||
<Image Include="tut\hello_world.bmp" />
|
<Image Include="tut\hello_world.bmp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="Slang.rc" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@ -26,9 +26,6 @@
|
|||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="olcPixelGameEngine.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="eval.h">
|
<ClInclude Include="eval.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -44,10 +41,15 @@
|
|||||||
<ClInclude Include="main.h">
|
<ClInclude Include="main.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="SLB.h">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="resource.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="script.slg" />
|
<None Include="script.slg" />
|
||||||
<None Include="builtin.slg" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="CMakeLists.txt" />
|
<Text Include="CMakeLists.txt" />
|
||||||
@ -56,5 +58,13 @@
|
|||||||
<Image Include="tut\hello_world.bmp">
|
<Image Include="tut\hello_world.bmp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
|
<Image Include="icon.ico">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</Image>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="Slang.rc">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</ResourceCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -15,6 +15,8 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
#define DEVELOPER_MESSAGES false
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
@ -144,11 +146,11 @@ boost::any EditClassSubComponent(boost::any value, string oper, boost::any other
|
|||||||
bool AxisAlignedCollision(const Sprite& a, const Sprite& b) // AABB - AABB collision
|
bool AxisAlignedCollision(const Sprite& a, const Sprite& b) // AABB - AABB collision
|
||||||
{
|
{
|
||||||
// collision x-axis?
|
// collision x-axis?
|
||||||
bool collisionX = a.position.x + a.scale.x >= b.position.x &&
|
bool collisionX = a.position.x + a.scale.x / 2 >= b.position.x - b.scale.x / 2 &&
|
||||||
b.position.x + b.scale.x >= a.position.x;
|
b.position.x + b.scale.x / 2 >= a.position.x - a.scale.x;
|
||||||
// collision y-axis?
|
// collision y-axis?
|
||||||
bool collisionY = a.position.y + a.scale.y >= b.position.y &&
|
bool collisionY = a.position.y + a.scale.y / 2 >= b.position.y - b.scale.y / 2 &&
|
||||||
b.position.y + b.scale.y >= a.position.y;
|
b.position.y + b.scale.y / 2 >= a.position.y - a.scale.y / 2;
|
||||||
|
|
||||||
//// collision x-axis?
|
//// collision x-axis?
|
||||||
//bool collisionX = a.position.x - a.scale.x / 2 >= b.position.x + b.scale.x / 2 ||
|
//bool collisionX = a.position.x - a.scale.x / 2 >= b.position.x + b.scale.x / 2 ||
|
||||||
@ -162,9 +164,9 @@ bool AxisAlignedCollision(const Sprite& a, const Sprite& b) // AABB - AABB colli
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initial script processing, which loads variables and functions from builtin
|
// Initial script processing, which loads variables and functions from builtin
|
||||||
int GetBuiltins(const string& s)
|
int GetBuiltins(std::string s)
|
||||||
{
|
{
|
||||||
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;
|
||||||
@ -184,7 +186,9 @@ int GetBuiltins(const string& s)
|
|||||||
|
|
||||||
string functName = split(words[lineNum][1], '(')[0];
|
string functName = split(words[lineNum][1], '(')[0];
|
||||||
|
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load builtin function " + functName);
|
InterpreterLog("Load builtin function " + functName);
|
||||||
|
#endif
|
||||||
|
|
||||||
string args = "";
|
string args = "";
|
||||||
for (int w = 1; w < (int)words[lineNum].size(); w++) // Get all words from the instantiation line: these are the args
|
for (int w = 1; w < (int)words[lineNum].size(); w++) // Get all words from the instantiation line: these are the args
|
||||||
@ -211,22 +215,30 @@ int GetBuiltins(const string& s)
|
|||||||
if (words[lineNum][0] == "string")
|
if (words[lineNum][0] == "string")
|
||||||
{
|
{
|
||||||
builtinVarVals[words[lineNum][1]] = StringRaw(words[lineNum][3]);
|
builtinVarVals[words[lineNum][1]] = StringRaw(words[lineNum][3]);
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (words[lineNum][0] == "int")
|
else if (words[lineNum][0] == "int")
|
||||||
{
|
{
|
||||||
builtinVarVals[words[lineNum][1]] = stoi(words[lineNum][3]);
|
builtinVarVals[words[lineNum][1]] = stoi(words[lineNum][3]);
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (words[lineNum][0] == "float")
|
else if (words[lineNum][0] == "float")
|
||||||
{
|
{
|
||||||
builtinVarVals[words[lineNum][1]] = stof(words[lineNum][3]);
|
builtinVarVals[words[lineNum][1]] = stof(words[lineNum][3]);
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (words[lineNum][0] == "bool")
|
else if (words[lineNum][0] == "bool")
|
||||||
{
|
{
|
||||||
builtinVarVals[words[lineNum][1]] = stob(words[lineNum][3]);
|
builtinVarVals[words[lineNum][1]] = stob(words[lineNum][3]);
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
InterpreterLog("Load builtin variable " + words[lineNum][1]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//else
|
//else
|
||||||
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
|
||||||
@ -253,7 +265,9 @@ boost::any SLBFunction(const string& name, const vector<boost::any>& args)
|
|||||||
return abs(AnyAsFloat(args[0]));
|
return abs(AnyAsFloat(args[0]));
|
||||||
else if (name == "SLB.Graphics.Init")
|
else if (name == "SLB.Graphics.Init")
|
||||||
{
|
{
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
InterpreterLog("Init graphics");
|
InterpreterLog("Init graphics");
|
||||||
|
#endif
|
||||||
initGraphics(StringRaw(AnyAsString(args[0])), AnyAsInt(args[1]), AnyAsInt(args[2]));
|
initGraphics(StringRaw(AnyAsString(args[0])), AnyAsInt(args[1]), AnyAsInt(args[2]));
|
||||||
}
|
}
|
||||||
else if (name == "SLB.Graphics.Sprite")
|
else if (name == "SLB.Graphics.Sprite")
|
||||||
|
|||||||
@ -372,11 +372,20 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Update()
|
||||||
|
{
|
||||||
|
SDL_Surface* surface = loadSurface(path);
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Draw()
|
int Draw()
|
||||||
{
|
{
|
||||||
// rect.x = static_cast<int>(position.x);
|
// Centers
|
||||||
rect.x = position.x;
|
rect.x = position.x - (rect.w / 2);
|
||||||
rect.y = position.y;
|
rect.y = position.y - (rect.h / 2);
|
||||||
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -504,25 +513,52 @@ public:
|
|||||||
{
|
{
|
||||||
rect.x = position.x;
|
rect.x = position.x;
|
||||||
rect.y = position.y;
|
rect.y = position.y;
|
||||||
// rect.y = static_cast<int>(position.y);
|
|
||||||
|
font = TTF_OpenFont(pathToFont.c_str(), fontSize);
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Load()
|
int Load()
|
||||||
{
|
{
|
||||||
TTF_Font* font = TTF_OpenFont(pathToFont.c_str(), fontSize);
|
SDL_Color color = { r, g, b };
|
||||||
|
|
||||||
SDL_Color color = {r, g, b};
|
|
||||||
|
|
||||||
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||||
|
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
|
||||||
TTF_SizeText(font, content.c_str(), &rect.w, &rect.h);
|
TTF_SizeText(font, content.c_str(), &rect.w, &rect.h);
|
||||||
|
|
||||||
scale.x = rect.w;
|
scale.x = rect.w;
|
||||||
scale.y = rect.h;
|
scale.y = rect.h;
|
||||||
|
|
||||||
|
// Centers
|
||||||
|
position.x = rect.x - (rect.w / 2);
|
||||||
|
position.y = rect.y - (rect.h / 2);
|
||||||
|
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Update()
|
||||||
|
{
|
||||||
|
SDL_Color color = { r, g, b };
|
||||||
|
|
||||||
|
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
|
||||||
|
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
|
||||||
|
TTF_SizeText(font, content.c_str(), &rect.w, &rect.h);
|
||||||
|
|
||||||
|
scale.x = rect.w;
|
||||||
|
scale.y = rect.h;
|
||||||
|
|
||||||
|
// Centers
|
||||||
|
position.x = rect.x - (rect.w / 2);
|
||||||
|
position.y = rect.y - (rect.h / 2);
|
||||||
|
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -612,7 +648,7 @@ public:
|
|||||||
else if (oper == "/=")
|
else if (oper == "/=")
|
||||||
fontSize /= AnyAsFloat(otherVal);
|
fontSize /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (componentName == "r")
|
else if (componentName == "r")
|
||||||
{
|
{
|
||||||
if (oper == "=")
|
if (oper == "=")
|
||||||
@ -652,7 +688,7 @@ public:
|
|||||||
else if (oper == "/=")
|
else if (oper == "/=")
|
||||||
b /= AnyAsFloat(otherVal);
|
b /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (componentName == "content")
|
else if (componentName == "content")
|
||||||
{
|
{
|
||||||
if (oper == "=")
|
if (oper == "=")
|
||||||
@ -660,6 +696,9 @@ public:
|
|||||||
else if (oper == "+=")
|
else if (oper == "+=")
|
||||||
content += AnyAsString(otherVal);
|
content += AnyAsString(otherVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates changes to text
|
||||||
|
Update();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,6 +712,8 @@ public:
|
|||||||
std::string content;
|
std::string content;
|
||||||
std::string pathToFont;
|
std::string pathToFont;
|
||||||
|
|
||||||
|
TTF_Font* font;
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
SDL_Rect rect{};
|
SDL_Rect rect{};
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
@ -980,7 +1021,7 @@ int initGraphics(std::string windowTitle, int width, int height)
|
|||||||
|
|
||||||
//Get window surface
|
//Get window surface
|
||||||
gScreenSurface = SDL_GetWindowSurface(gWindow);
|
gScreenSurface = SDL_GetWindowSurface(gWindow);
|
||||||
|
|
||||||
ExecuteFunction("Start", vector<boost::any> {});
|
ExecuteFunction("Start", vector<boost::any> {});
|
||||||
|
|
||||||
updateLoop();
|
updateLoop();
|
||||||
|
|||||||
BIN
Slang/icon.ico
Normal file
BIN
Slang/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 800 KiB |
File diff suppressed because it is too large
Load Diff
16
Slang/resource.h
Normal file
16
Slang/resource.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Visual C++ generated include file.
|
||||||
|
// Used by Slang.rc
|
||||||
|
//
|
||||||
|
#define IDI_ICON1 101
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user