diff --git a/Slang/Main.cpp b/Slang/Main.cpp index 143160f..7620b49 100644 --- a/Slang/Main.cpp +++ b/Slang/Main.cpp @@ -1,5 +1,4 @@ -#include "olcPixelGameEngine.h" #include #include #include @@ -7,6 +6,7 @@ #include #include #include +#include #include #include @@ -98,7 +98,7 @@ boost::any EvalExpression(const string& ex, unordered_map& v string expression = trim(ex); bool inQuotes = false; - CompilerLog("OLDEXPRESSION: |" + expression + "|"); + //CompilerLog("OLDEXPRESSION: |" + expression + "|"); // If no operations are applied, then return self if ((count(expression, '+') == 0 && count(expression, '-') == 0 && count(expression, '*') == 0 && count(expression, '/') == 0 && count(expression, '(') == 0 && count(expression, '^') == 0) || split(expression, '.')[0] == "CPP") @@ -115,7 +115,7 @@ boost::any EvalExpression(const string& ex, unordered_map& v y++; } - CompilerLog(split(expression, '(')[0] + " " + AnyAsString(GetVariableValue(split(argContents, ',')[0], variableValues))); + //CompilerLog(split(expression, '(')[0] + " " + AnyAsString(GetVariableValue(split(argContents, ',')[0], variableValues))); return ExecuteFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues)); } else if (split(expression, '.')[0] == "CPP" && !inQuotes) @@ -128,7 +128,7 @@ boost::any EvalExpression(const string& ex, unordered_map& v y++; } - CompilerLog(split(expression, '(')[0] + " " + argContents); + //CompilerLog(split(expression, '(')[0] + " " + argContents); return CPPFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues)); } else @@ -165,7 +165,7 @@ boost::any EvalExpression(const string& ex, unordered_map& v i++; } - CompilerLog(split(expression, '(')[0] + " " + AnyAsString(GetVariableValue(split(argContents, ',')[0], variableValues))); + //CompilerLog(split(expression, '(')[0] + " " + AnyAsString(GetVariableValue(split(argContents, ',')[0], variableValues))); string returnVal = AnyAsString(ExecuteFunction(name, VarValues(split(argContents, ','), variableValues))); newExpression += returnVal; //cout << newExpression << endl; @@ -199,7 +199,7 @@ boost::any EvalExpression(const string& ex, unordered_map& v newExpression += expression[i]; } } - CompilerLog("NEW EXPRESSION: |" + newExpression + "|"); + //CompilerLog("NEW EXPRESSION: |" + newExpression + "|"); bool addStrings = false; for (int i = 0; i < (int)newExpression.size(); i++) @@ -297,8 +297,8 @@ int varOperation(const vector& str, unordered_map& v boost::any ProcessLine(const vector>& words, int lineNum, unordered_map& variableValues) { - CompilerLog(unWrapVec(words[lineNum])); - CompilerLog(AnyAsString(GetVariableValue("out", variableValues))); + //CompilerLog(unWrapVec(words[lineNum])); + //CompilerLog(AnyAsString(GetVariableValue("out", variableValues))); if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/') return nullType; @@ -330,7 +330,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder else if (countInVector(types, trim(words[lineNum][0])) > 0) { variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(slice(words[lineNum], 3, -1)), variableValues); - CompilerLog("new var :: " + words[lineNum][1] + " = " + AnyAsString(variableValues[words[lineNum][1]])); + //CompilerLog("new var :: " + words[lineNum][1] + " = " + AnyAsString(variableValues[words[lineNum][1]])); return nullType; } @@ -524,7 +524,7 @@ int parseSlang(string script) } args = replace(args, functName + " ", ""); - CompilerLog(args); + //CompilerLog(args); functionContents.push_back(split(args, ',')); int numOfBrackets = 1; diff --git a/Slang/Slang.vcxproj b/Slang/Slang.vcxproj index 43f7cc2..9d98fee 100644 --- a/Slang/Slang.vcxproj +++ b/Slang/Slang.vcxproj @@ -80,6 +80,8 @@ true + D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_image-2.0.5\include;$(IncludePath) + D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_image-2.0.5\lib\x64;$(LibraryPath) false @@ -121,10 +123,13 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + D:\Code\boost;D:\Code\SDL2-2.0.18;D:\Code\SDL2_image-2.0.5;%(AdditionalIncludeDirectories) Console true + SDL2.lib;SDL2main.lib;%(AdditionalDependencies) + D:\Code\SDL2-2.0.18\lib\x64;D:\Code\boost\libs;D:\Code\SDL2_image-2.0.5\lib\x64;%(AdditionalLibraryDirectories) @@ -147,6 +152,7 @@ + @@ -163,6 +169,9 @@ + + + diff --git a/Slang/Slang.vcxproj.filters b/Slang/Slang.vcxproj.filters index 0800299..3accdf4 100644 --- a/Slang/Slang.vcxproj.filters +++ b/Slang/Slang.vcxproj.filters @@ -24,6 +24,9 @@ Source Files + + Source Files + @@ -52,4 +55,9 @@ + + + Source Files + + \ No newline at end of file diff --git a/Slang/builtin.h b/Slang/builtin.h index 1f58471..514b7ec 100644 --- a/Slang/builtin.h +++ b/Slang/builtin.h @@ -12,11 +12,12 @@ #include "graphics.h" #include "anyops.h" #include +#include using namespace std; using namespace boost; -vector types = { "int", "float", "string", "bool", "void", "null" }; +vector types = { "int", "float", "string", "bool", "void", "null", "Circle"}; unordered_map>> builtinFunctionValues; unordered_map builtinVarVals; @@ -28,6 +29,31 @@ public: string type = "NULL"; }; +class Circle +{ +public: + int x; + int y; + float r; +}; + +class Image +{ +public: + int x; + int y; + float r; + SDL_Surface* surface; + SDL_Texture* texture; + + /*int LoadImage(string PATH) + { + surface = IMG_Load("Path/To/Your/Image.png"); + texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + }*/ +}; + boost::any nullType; int LogWarning(const string& warningText) @@ -125,11 +151,18 @@ boost::any CPPFunction(const string& name, const vector& args) else if (name == "CPP.Graphics.Init") { cout << "\x1B[32mInit graphics\033[0m\t\t" << endl; - if (mainWindow.Construct(AnyAsInt(args[0]), AnyAsInt(args[1]), AnyAsInt(args[2]), AnyAsInt(args[2]))) - mainWindow.Start(); + mainWindow.Start(AnyAsInt(args[0]), AnyAsInt(args[1])); + } + else if (name == "CPP.Graphics.Circle") + { + Circle c; + c.x = AnyAsInt(args[0]); + c.y = AnyAsInt(args[1]); + c.r = AnyAsInt(args[2]); + boost::any a = c; + Circle d = any_cast(a); + return d; } - else if (name == "CPP.Graphics.SetPixel") - mainWindow.Draw(AnyAsInt(args[0]), AnyAsInt(args[1]), olc::Pixel(AnyAsInt(args[2]), AnyAsInt(args[3]), AnyAsInt(args[4]))); else if (name == "CPP.System.Print") cout << AnyAsString(args[0]); else if (name == "CPP.System.PrintLine") diff --git a/Slang/builtin.slg b/Slang/builtin.slg index cc542cf..7ecf14a 100644 --- a/Slang/builtin.slg +++ b/Slang/builtin.slg @@ -77,3 +77,10 @@ func Printl(in) { CPP.System.PrintLine(in) } + +// Creates new circle class +func NewCircle(x, y, r) +{ + Circle c = CPP.Graphics.Circle(x, y, r) + return c +} diff --git a/Slang/graphics.h b/Slang/graphics.h index 389efe0..540d2f9 100644 --- a/Slang/graphics.h +++ b/Slang/graphics.h @@ -2,9 +2,6 @@ #ifndef GRAPHICS_H #define GRAPHICS_H -#define OLC_PGE_APPLICATION - -#include "olcPixelGameEngine.h" #include #include #include @@ -15,33 +12,62 @@ #include "strops.h" #include "builtin.h" #include "main.h" +#include +#include +#include using namespace std; -class Parser : public olc::PixelGameEngine +class Parser { public: - Parser() + int Start(int SCREEN_W, int SCREEN_H) { - sAppName = "Parser"; + + + ////Initialize SDL + //if (SDL_Init(SDL_INIT_VIDEO) < 0) + //{ + // printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); + //} + //else + //{ + // //Create window + // window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN); + // if (window == NULL) + // { + // printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); + // } + // else + // { + // //Get window surface + // screenSurface = SDL_GetWindowSurface(window); + + // while (OnUpdate() == 0) + // { + // //Fill the surface white + // SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0x00, 0x00)); + // + // //Update the surface + // SDL_UpdateWindowSurface(window); + // } + // } + //} + + ////Destroy window + //SDL_DestroyWindow(window); + + //Quit SDL subsystems + //SDL_Quit(); + + return 0; } -public: - bool OnUserCreate() override + int OnUpdate() { - // Called once at the start - return true; - } - - bool OnUserUpdate(float fElapsedTime) override - { - ExecuteFunction("Update", vector {}); - - // Called once per frame - //for (int x = 0; x < ScreenWidth(); x++) - // for (int y = 0; y < ScreenHeight(); y++) - // Draw(x, y, olc::Pixel(rand() % 128, rand() % 128, rand() % 128)); - return true; + ExecuteFunction("Update", vector()); + //cout << "update" << endl; + return 0; } }; diff --git a/Slang/script.slg b/Slang/script.slg index d34dec2..bf0a213 100644 --- a/Slang/script.slg +++ b/Slang/script.slg @@ -19,23 +19,23 @@ func Main(input, in) x += 1 } - //CPP.Graphics.Init(64, 64, 4) - return 0 + NewCircle(0, 0, 5) + CPP.Graphics.Init(64, 64) } func Update(input) { - int x = 0 - int y = 0 - while x < 64 - { - while y < 64 - { - SetPixel(x, y, 255, 0, 0) - y += 1 - } - y = 0 - x += 1 - } + //int x = 0 + //int y = 0 + //while x < 16 + //{ + // while y < 16 + // { + // SetPixel(x, y, 255, 0, 0) + // y += 1 + // } + // y = 0 + // x += 1 + //} print "updating" } diff --git a/Slang/tut/02_getting_an_image_on_the_screen.cpp b/Slang/tut/02_getting_an_image_on_the_screen.cpp new file mode 100644 index 0000000..bc06605 --- /dev/null +++ b/Slang/tut/02_getting_an_image_on_the_screen.cpp @@ -0,0 +1,121 @@ +///*This source code copyrighted by Lazy Foo' Productions (2004-2020) +//and may not be redistributed without written permission.*/ +// +////Using SDL and standard IO +//#include +//#include +// +////Screen dimension constants +//const int SCREEN_WIDTH = 640; +//const int SCREEN_HEIGHT = 480; +// +////Starts up SDL and creates window +//bool init(); +// +////Loads media +//bool loadMedia(); +// +////Frees media and shuts down SDL +//void close(); +// +////The window we'll be rendering to +//SDL_Window* gWindow = NULL; +// +////The surface contained by the window +//SDL_Surface* gScreenSurface = NULL; +// +////The image we will load and show on the screen +//SDL_Surface* gHelloWorld = NULL; +// +//bool init() +//{ +// //Initialization flag +// bool success = true; +// +// //Initialize SDL +// if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) +// { +// printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); +// success = false; +// } +// else +// { +// //Create window +// gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); +// if( gWindow == NULL ) +// { +// printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); +// success = false; +// } +// else +// { +// //Get window surface +// gScreenSurface = SDL_GetWindowSurface( gWindow ); +// } +// } +// +// return success; +//} +// +//bool loadMedia() +//{ +// //Loading success flag +// bool success = true; +// +// //Load splash image +// gHelloWorld = SDL_LoadBMP( "./tut/hello_world.bmp" ); +// if( gHelloWorld == NULL ) +// { +// printf( "Unable to load image %s! SDL Error: %s\n", "./tut/hello_world.bmp", SDL_GetError() ); +// success = false; +// } +// +// return success; +//} +// +//void close() +//{ +// //Deallocate surface +// SDL_FreeSurface( gHelloWorld ); +// gHelloWorld = NULL; +// +// //Destroy window +// SDL_DestroyWindow( gWindow ); +// gWindow = NULL; +// +// //Quit SDL subsystems +// SDL_Quit(); +//} +// +//int main( int argc, char* args[] ) +//{ +// //Start up SDL and create window +// if( !init() ) +// { +// printf( "Failed to initialize!\n" ); +// } +// else +// { +// //Load media +// if( !loadMedia() ) +// { +// printf( "Failed to load media!\n" ); +// } +// else +// { +// //Apply the image +// SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, NULL ); +// +// //Update the surface +// SDL_UpdateWindowSurface( gWindow ); +// +// //Wait two seconds +// SDL_Delay( 2000 ); +// } +// } +// +// //Free resources and close SDL +// close(); +// +// return 0; +//} \ No newline at end of file diff --git a/Slang/tut/hello_world.bmp b/Slang/tut/hello_world.bmp new file mode 100644 index 0000000..def2531 Binary files /dev/null and b/Slang/tut/hello_world.bmp differ