Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Theta::IO.*;
- import Theta::Web.*;
- module Theta::Program;
- // @summary A class capable of generation OpenGL for Theta.
- public prototype Generator {
- fields
- {
- // @summary The main workspace that holds the project.
- public static String GLWorkspaceName = "Khronos.TEA";
- // @summary The project where files will be placed.
- public static String GLTargetProjectName = "OpenGL.TEA";
- // @summary The gl target path.
- public static mut String GLTargetPath;
- // @summary The project to generate code in.
- public static mut String GLTargetSourcesPath;
- // @summary The path to where to download / get OpenGL specs.
- public static mut String GLTargetSpecs;
- }
- structures
- {
- private type SpecURL<String> =
- {
- EGL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/egl.xml"),
- GL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml"),
- GLX("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/glx.xml"),
- WGL("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/wgl.xml"),
- README("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/readme.pdf"),
- }
- }
- methods
- {
- def UpdateDirPaths<private, static, void>()
- {
- IO::DirectoryInfo directoryRoot = new IO::DirectoryInfo(IO::Directory.GetCurrentDirectory());
- // Walk up to the solution file so we can then go into the project and write to the C# files directly.
- while (directoryRoot != null && !IO::File.Exists(IO::Path.Combine(directoryRoot.FullName, glWorkspaceName + ".sln")))
- {
- directoryRoot = directoryRoot.Parent;
- }
- // If the solution wasn't found (maybe its not not running from the bin directory), just write out to the current directory.
- if (directoryRoot == null)
- {
- directoryRoot = new IO::DirectoryInfo(IO::Directory.GetCurrentDirectory());
- }
- // Sets the specified gl paths.
- GLTargetPath = IO::Path.Combine(directoryRoot.FullName, glTargetProjectName);
- GLTargetSourcesPath = glTargetPath + "/" + "Sources";
- GLTargetSpecs = glTargetPath + "/" + "GLSpecs";
- }
- def DownloadSpecs<private, static, void>()
- {
- // Creates the specs path directory if it does not exist!
- if (!IO::Directory.Exists(glTargetSpecs))
- {
- IO::Directory.CreateDirectory(glTargetSpecs);
- }
- // Downloads the specs files.
- foreach (SpecURL url : SpecURL.ToList)
- {
- String[] spilit = url.Value.Split('/');
- String p = "";
- if (!IO::File.Exists((p = IO::Path.Combine(glTargetSpecs, spilit[spilit.Length - 1]))))
- {
- if (Web::HasInternet)
- {
- IO::StdOut.PrintLn("Downloading the required {0} document!", spilit[spilit.Length - 1]);
- Web::WebClient glClient = new Web::WebClient();
- glClient.DownloadFile(url.Value, p);
- }
- else
- {
- IO::StdOut.PrintLn("Could not download {0}, no internet connection!", url.Name);
- }
- }
- }
- }
- def Generate<private, static void>Generate(String xmlName, String dllPath)
- {
- // TODO: Generate to files!
- }
- // @summary Entry point to the program, can be in any prototype.
- // @params args: Arguements provided to the program.
- // @returns int: Status code of the program.
- def Main<entry, Int>(String[] args)
- {
- // Sets up the console.
- IO::StdOut.Title = "TEA OpenGL";
- IO::StdOut.BackgroundColor = IO::ConsoleColour.Black;
- IO::StdOut.ForegroundColor = IO::ConsoleColour.Green;
- // Initalize files and paths.
- UpdateDirPaths();
- DownloadSpecs();
- // Generate files! TODO: OpenAL, OpenCL & GLFS
- Generate("glfw", "");
- Generate("gl", "");
- // Generate("wgl", "");
- // Generate("glx", "");
- // Generate("egl", "");
- // Wait for the user to end the program.
- IO::StdOut.PrintLn("Press any key to exit...");
- IO::StdOut.Pause();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement