Ejemplo n.º 1
0
def BuildPreviewObject(inputFile, callback=None):
    def buildResult(output, message, returncode):
        WSServer.send('compilationStatus', dict(output=output, message=message, returncode=returncode))
        if callback!=None:
            callback(output, message, returncode)
            pass
        pass

    #_buildObjectFile(inputFile, Project.getProjectFolder()+'/build/nacl/', 'preview', _getFlags('DEBUG'), buildResult)
    _buildObjectFile(inputFile, Project.getProjectFolder(), 'linux', _getFlags('DEBUG'), buildResult)
    pass
Ejemplo n.º 2
0
def GetSimpleClass(relativeFileName):
    from server.project import Project
    from server.components import DefaultComponentManager
    from server.io import Utils

    Utils.Console.step('Parsing ' + relativeFileName)

    fileName = Project.getAbsProjFilePath(relativeFileName)
    parsedFile = parseCPPFile(fileName)
    simpleClass = dict()
    dependencies = []

    if parsedFile['success'] and len(parsedFile['symbols']) > 0:
        fileSymbols = parsedFile['symbols']
        if fileSymbols[0]['kind'] == 'CLASS_DECL':
            simpleClass['class'] = fileSymbols[0]['name']
            simpleClass['namespace'] = fileSymbols[0]['namespace']

            simpleClass['fields'] = {}
            simpleClass['types'] = {}
            simpleClass['pragmas'] = {}
            simpleClass['visibilities'] = {}
            for child in fileSymbols[0]['children']:
                if child['kind'] == 'FIELD_DECL' and child['visibility'] == 0:
                    simpleClass['fields'][child[
                        'name']] = DefaultComponentManager.DefaultFieldValue(
                            child['type'])
                    simpleClass['types'][child['name']] = child['type']
                    simpleClass['pragmas'][child['name']] = child['pragmas']
                    simpleClass['visibilities'][
                        child['name']] = child['visibility']
                    pass
                pass
            pass
        pass

    dependencies = parsedFile['dependencies']

    return dict(symbols=simpleClass,
                success=parsedFile['success'],
                diagnostics=parsedFile['diagnostics'],
                dependencies=dependencies)
Ejemplo n.º 3
0
def GetSimpleClass(relativeFileName):
    from server.project import Project
    from server.components import DefaultComponentManager
    from server.io import Utils

    Utils.Console.step('Parsing ' + relativeFileName)

    fileName = Project.getAbsProjFilePath(relativeFileName)
    parsedFile = parseCPPFile(fileName)
    simpleClass = dict()
    dependencies = []

    if parsedFile['success'] and len(parsedFile['symbols']) > 0:
        fileSymbols = parsedFile['symbols']
        if fileSymbols[0]['kind'] == 'CLASS_DECL':
            simpleClass['class'] = fileSymbols[0]['name']
            simpleClass['namespace']  = fileSymbols[0]['namespace']

            simpleClass['fields'] = {}
            simpleClass['types'] = {}
            simpleClass['pragmas'] = {}
            simpleClass['visibilities'] = {}
            for child in fileSymbols[0]['children']:
                if child['kind'] == 'FIELD_DECL' and child['visibility']==0:
                    simpleClass['fields'][child['name']] = DefaultComponentManager.DefaultFieldValue(child['type'])
                    simpleClass['types'][child['name']] = child['type']
                    simpleClass['pragmas'][child['name']] = child['pragmas']
                    simpleClass['visibilities'][child['name']] = child['visibility']
                    pass
                pass
            pass
        pass

    dependencies = parsedFile['dependencies']

    return dict(symbols=simpleClass,
            success=parsedFile['success'],
            diagnostics=parsedFile['diagnostics'],
            dependencies=dependencies)
Ejemplo n.º 4
0
def ExportGame(platform, buildAndRun, compilationMode, outputFolder, cleanObjects=True):
    from distutils import dir_util
    import shutil, os
    # Create folder for temporary .o files
    dir_util.mkpath(outputFolder + '/build')
    if BuildProject(platform, buildAndRun, compilationMode, outputFolder)['returncode'] != 0:
        return False
    else:
        # Copy scenes to destination folder
        projectFolder = Project.getProjectFolder()
        #dir_util.copy_tree(projectFolder + '/scenes', outputFolder+'/scenes')
        Utils.CopyFilesOfTypes(projectFolder+'/scenes', outputFolder, ['.json'], projectFolder)
        # Copy assets to destination folder
        Utils.CopyFilesOfTypes(projectFolder+'/assets', outputFolder, Config.env('exportable_asset_extensions'), projectFolder)
        Utils.CopyFilesOfTypes(projectFolder+'/default_assets', outputFolder, Config.env('exportable_asset_extensions'), projectFolder)
        # Platform specific post-build steps
        _PostExportStep(platform, outputFolder)
        # Remove temporary build folder
        if cleanObjects:
            dir_util.remove_tree(outputFolder + '/build')
            pass
        return True
    pass
Ejemplo n.º 5
0
def RenderFactorySources(componentFiles):
    from mako.template import Template

    projectFolder = Project.getProjectFolder()
    templatePath = projectFolder+'/default_assets/factories/FactoryTemplates.cpy'
    outputPaths = []

    for component in componentFiles:
        renderParameters = dict(component=component,
                                isVecType=_isVecType,
                                vecIterations=dict(v4f=4, v3f=3, v2f=2))
        fname = component['path'] + '.cpp'
        outputRelativePath = 'default_assets/factories/'+fname
        outputPath = projectFolder + '/' + outputRelativePath
        outputPaths.append(outputRelativePath)

        componentFactoryTemplate = open(templatePath).read()
        Utils.Console.step('Generating factory '+outputPath)
        with Utils.OpenRec(outputPath, 'w') as outputHandle:
            outputHandle.write(Template(componentFactoryTemplate).render(**renderParameters))
            pass
        pass
    return outputPaths
Ejemplo n.º 6
0
    def buildObjectFile(self, sourceFile, outputFolder, platform, compilationFlags):
        import subprocess
        outputFilePath = os.path.normpath(outputFolder+'/build/'+sourceFile+'.o')
        compilationMessage = ''
        returncode=0

        # Create recursive folders, if necessary
        Utils.CreateFoldersRec(os.path.dirname(outputFilePath))

        try:
            # Only build the object file if it is older than any of its dependencies
            if Project.isFileOlderThanDependency(outputFilePath, sourceFile):
                Utils.Console.step('Building '+outputFilePath)
                compilationMessage = subprocess.check_output(cxx_compiler[platform] + ' -c ' + Project.getAbsProjFilePath(sourceFile) +' -o '+outputFilePath +' '+ platform_preprocessors[platform] + ' ' + compilationFlags['cxx_flags'][platform], shell=True, stderr=subprocess.STDOUT)
                if returncode == 0:
                    Utils.Console.ok('Built '+outputFilePath)
                    pass
                pass
        except subprocess.CalledProcessError as e:
            Utils.Console.fail('Error building '+outputFilePath)
            compilationMessage = e.output
            returncode = e.returncode
            pass

        fileSetLock.acquire()
        callbacks = fileCallbacks[sourceFile]
        del fileCallbacks[sourceFile]
        fileSet.remove(sourceFile)
        fileSetLock.release()

        for callback in callbacks:
            if callback!=None:
                callback(output=outputFilePath, message=compilationMessage, returncode=returncode)
                pass
            pass
        pass
Ejemplo n.º 7
0
 def process_IN_DELETE(self, event):
     evPath = os.path.relpath(event.pathname, Project.getProjectFolder())
     Project.removeAsset(evPath, saveProject=True)
     if Utils.IsTrackableAsset(evPath) and Project.isUserAsset(evPath):
         WSServer.send('AssetWatch', dict(event="delete", path=evPath))
     pass
Ejemplo n.º 8
0
 def process_IN_CLOSE_WRITE(self, event):
     evPath = os.path.relpath(event.pathname, Project.getProjectFolder())
     asset = Project.processAsset(evPath, saveProject=True)
     if asset != None and Project.isUserAsset(evPath):
         WSServer.send('AssetWatch', dict(event="update", asset=asset))
     pass
Ejemplo n.º 9
0
def save(sceneData):
    # TODO define the scene name from the editor
    return Project.saveCurrentScene(sceneData)
Ejemplo n.º 10
0
def getAssetList(evData):
    # Load list of assets
    return Project.getAssetList()
Ejemplo n.º 11
0
def loadCurrentScene(e):
    return Project.loadCurrentScene()
Ejemplo n.º 12
0
def savePrefab(prefab):
    return Project.savePrefab(prefab)
Ejemplo n.º 13
0
#!/usr/bin/python
import os, sys

from server import Config, HTTPServer, WSServer
from server.build import BuildEventHandler
from server.io import IOEventHandler
from server.project import Project, ProjectEventHandler, AssetFolderWatcher
from server.components import DefaultComponentManager


try:
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))+'/editor')
    Project.initialize()
    WSServer.serve(blocking = False)
    HTTPServer.serve()
except KeyboardInterrupt:
    exit()
    pass
Ejemplo n.º 14
0
def parseCPPFile(fileName):
    import re
    from server import Config
    from server.project import Project
    from server.io import Utils

    global _clangIndex
    global _translationUnits
    global _parserLock
    global _filesBeingParsed

    # Remove #include's from source files, to prevent clang
    # from parsing them. I know this is a horrible solution,
    # but clang will take forever to parse the files if they
    # have headers, and it doesn't have an option for disabling
    # recursive parsing.
    while True:
        _parserLock.acquire()
        if not fileName in _filesBeingParsed:
            _filesBeingParsed.add(fileName)
            _parserLock.release()
            break
        _parserLock.release()
        time.sleep(0.1)
        pass

    if fileName in _translationUnits:
        tu = _translationUnits[fileName]
        tu.reparse([(fileName, open(fileName, 'r'))])
    else:
        try:
            # TODO maybe get the flags from BuildEventHandler?
            ####
            # TODO documentar q foi gerado com:
            # clang++ -x c++-header -std=c++11 Eigen -relocatable-pch -o Eigen.pch
            # (dentro da pasta Eigen)
            ####
            tu = _clangIndex.parse(
                fileName, [
                    '-std=c++11', '-Wall', '-x', 'c++', '-DLINUX', '-DDESKTOP',
                    '-DDEBUG', '-I',
                    Config.get('export', 'third_party_folder') +
                    '/rapidjson/include', '-I',
                    Config.get('export', 'third_party_folder') + '/Eigen',
                    '-I',
                    Project.getProjectFolder() + '/default_assets/',
                    '-include-pch',
                    Config.get('export', 'third_party_folder') +
                    '/Eigen/Eigen/Eigen.pch'
                ],
                options=TranslationUnit.PARSE_SKIP_FUNCTION_BODIES)
            _translationUnits[fileName] = tu
        except Exception as err:
            Utils.Console.error('Error processing translation unit!')
            _filesBeingParsed.remove(fileName)
            return dict(symbols=[],
                        success=False,
                        diagnostics=[str(err)],
                        dependencies=[])
        pass

    # Check for diagnostic messages
    diagnostics = []
    success = True
    for diag in tu.diagnostics:
        diagnostics.append(diag.spelling)
        if diag.severity == clang.cindex.Diagnostic.Error or diag.severity == clang.cindex.Diagnostic.Fatal:
            success = False
        pass

    # Get list of pragmas
    # TODO use custom c++11 attributes in the form [[hidden]] [[visible]] etc.
    dependencies = set()
    parseResult = dict(symbols=[])
    if success:
        prevToken = None
        nextIsPragma = False
        pragmaList = []
        for token in tu.cursor.get_tokens():
            if token.kind == TokenKind.IDENTIFIER and prevToken.kind == TokenKind.PUNCTUATION and token.spelling == 'pragma':
                nextIsPragma = True
            elif nextIsPragma:
                if token.kind == TokenKind.IDENTIFIER:
                    pragmaList.append(
                        dict(line=token.extent.start.line,
                             identifier=token.spelling))
                nextIsPragma = False
            prevToken = token

        parseContext = dict(depth=0,
                            withinClassContext=False,
                            requestedFileName=fileName,
                            currentNameSpace='')
        parseResult['symbols'] = parseCPPFileRec(tu.cursor, pragmaList,
                                                 parseContext)

        # Get dependencies
        projFolder = Project.getProjectFolder()
        for dep in tu.get_includes():
            dependency = os.path.normpath(str(dep.include))
            if Utils.IsSubdir(dependency, projFolder):
                dependencies.add(Project.getRelProjFilePath(dependency))
                pass
            pass
        pass

    parseResult['diagnostics'] = diagnostics
    parseResult['success'] = success
    parseResult['dependencies'] = list(dependencies)

    _filesBeingParsed.remove(fileName)

    return parseResult
Ejemplo n.º 15
0
def save(sceneData):
    # TODO define the scene name from the editor
    return Project.saveCurrentScene(sceneData)
Ejemplo n.º 16
0
 def process_IN_DELETE(self, event):
     evPath = os.path.relpath(event.pathname, Project.getProjectFolder())
     Project.removeAsset(evPath, saveProject=True)
     if Utils.IsTrackableAsset(evPath) and Project.isUserAsset(evPath):
         WSServer.send('AssetWatch', dict(event="delete", path=evPath))
     pass
Ejemplo n.º 17
0
 def process_IN_CLOSE_WRITE(self, event):
     evPath = os.path.relpath(event.pathname, Project.getProjectFolder())
     asset = Project.processAsset(evPath, saveProject=True)
     if asset != None and Project.isUserAsset(evPath):
         WSServer.send('AssetWatch', dict(event="update", asset=asset))
     pass
Ejemplo n.º 18
0
def _getFlags(compilationMode):
    cxxModeFlags = {
        'DEBUG': '-g -DDEBUG',
        'RELEASE': '-O3 -DRELEASE'
    }
    modeFolder = {
        'DEBUG': 'Debug',
        'RELEASE': 'Release'
    }
    thirdPartyFolder = Config.get('export', 'third_party_folder')
    naclFolder = Config.get('export', 'nacl')['pepper_folder']
    return {
        'link_flags': {
            'linux': '-rdynamic -lglfw3 -lrt -lXrandr -lXinerama -lXi -lXcursor -lGL -lm -ldl -lXrender -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp -lGLEW',
            # TODO check licenses of libraries so I can determine if I can install their binaries with the engine (which means these folders could be specified as relatives to the instalation folder instead of having to set them in the config)
            'windows': '-lglew32 -lglfw3 -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 -mwindows -L '+thirdPartyFolder+'/cross_compiling/windows/glew-1.12.0/lib/ -L '+thirdPartyFolder+'/cross_compiling/windows/glfw-3.1.1/build/src/',
            # TODO Add the Native Client target to the export menu on the editor
            'nacl': '-L'+naclFolder+'/lib/pnacl/'+modeFolder[compilationMode]+' -lppapi_cpp -lppapi -lppapi_gles2 -lm -fms-extensions',
            'preview': '-L'+naclFolder+'/lib/pnacl/'+modeFolder[compilationMode]+' -lppapi_cpp -lppapi -lppapi_gles2 -lm -fPIC',
            'javascript': '--bind -s USE_SDL=2 -s ALLOW_MEMORY_GROWTH=1 -g3 -O1'
        },
        'cxx_flags': {
            'linux': ' -I'+thirdPartyFolder+'/Eigen -I'+thirdPartyFolder+'/rapidjson/include -std=c++11 -I'+Project.getProjectFolder()+' -I'+Project.getProjectFolder()+'/default_assets/ ' + cxxModeFlags[compilationMode],
            'windows': ' -I'+thirdPartyFolder+'/Eigen -I'+thirdPartyFolder+'/rapidjson/include -I '+thirdPartyFolder+'/cross_compiling/windows/glfw-3.1.1/include/ -I '+thirdPartyFolder+'/cross_compiling/windows/glew-1.12.0/include/ -std=c++11 -I'+Project.getProjectFolder()+' -I'+Project.getProjectFolder()+'/default_assets/',
            'nacl': ' -I'+thirdPartyFolder+'/Eigen -I'+thirdPartyFolder+'/rapidjson/include -std=gnu++11 -I'+Project.getProjectFolder()+' -I'+Project.getProjectFolder()+'/default_assets/ -I' + naclFolder+'/include -fms-extensions ' + cxxModeFlags[compilationMode] + ' -fPIC',
            'preview': ' -I'+thirdPartyFolder+'/Eigen -I'+thirdPartyFolder+'/rapidjson/include -std=gnu++11 -I'+Project.getProjectFolder()+' -I'+Project.getProjectFolder()+'/default_assets/ -I' + naclFolder+'/include -fPIC -O1',
            'javascript': '--bind -s USE_SDL=2'+' -I'+thirdPartyFolder+'/Eigen -I'+thirdPartyFolder+'/rapidjson/include -std=c++11 -I'+Project.getProjectFolder()+' -I'+Project.getProjectFolder()+'/default_assets/ -O1 -g3'
        },
        'output_extension': {
            'linux': '',
            'windows': '.exe',
            'nacl': '.pexe',
            'preview': '.pexe',
            'javascript': '.js',
        }
    }
Ejemplo n.º 19
0
def previewGame(event_msg):
    ExportGame('preview', False, 'DEBUG', Project.getProjectFolder()+'/build/nacl/', cleanObjects=False)
    return True
Ejemplo n.º 20
0
def loadCurrentScene(e):
    return Project.loadCurrentScene()
Ejemplo n.º 21
0
#!/usr/bin/python
import os, sys

from server import Config, HTTPServer, WSServer
from server.build import BuildEventHandler
from server.io import IOEventHandler
from server.project import Project, ProjectEventHandler, AssetFolderWatcher
from server.components import DefaultComponentManager

try:
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])) + '/editor')
    Project.initialize()
    WSServer.serve(blocking=False)
    HTTPServer.serve()
except KeyboardInterrupt:
    exit()
    pass
Ejemplo n.º 22
0
def savePrefab(prefab):
    return Project.savePrefab(prefab)
Ejemplo n.º 23
0
def BuildProject(platform = 'linux', runGame = True, compilationMode='DEBUG', outputFolder = None):
    import subprocess, time
    compilationFlags=_getFlags(compilationMode)

    projectFolder = Project.getProjectFolder()

    if outputFolder == None:
        outputFolder = projectFolder

    compilationStatus = dict(returncode=0, message='')
    try:
        # Generate build list
        sourceFiles = []
        componentScripts = Utils.ListFilesFromFolder(projectFolder)
        # Append component scripts to the list of build files
        for componentScript in componentScripts:
            if Utils.IsImplementationFile(componentScript):
                sourceFiles.append(Project.getRelProjFilePath(componentScript))
                pass
            pass

        # Compile
        internalCompStatus = dict(precompiledFiles = [])
        resultLock = threading.Lock()
        def threadResult(output, message, returncode):
            resultLock.acquire()
            if compilationStatus['returncode'] == 0:
                compilationStatus['returncode'] = returncode
                compilationStatus['message'] += message
                internalCompStatus['precompiledFiles'].append(output)
                pass

            resultLock.release()
            pass

        for sourceFile in sourceFiles:
            _buildObjectFile(sourceFile, outputFolder, platform, compilationFlags, threadResult)
            if compilationStatus['returncode'] != 0:
                break
            pass

        workQueue.join()

        # Link
        Utils.Console.info('Linking '+outputFolder+'...')
        startTime = time.time()
        outputFile = outputFolder+'/game'+compilationFlags['output_extension'][platform]
        if compilationStatus['returncode'] == 0 and isOutputOutdated(outputFile, internalCompStatus['precompiledFiles']):
            print cxx_compiler[platform] + ' ' + (' '.join(internalCompStatus['precompiledFiles'])) +' -o '+outputFile+' ' + compilationFlags['link_flags'][platform]
            compilationStatus['message'] += subprocess.check_output(cxx_compiler[platform] + ' ' + (' '.join(internalCompStatus['precompiledFiles'])) +' -o '+outputFile+' ' + compilationFlags['link_flags'][platform], shell=True, stderr=subprocess.STDOUT)
            Utils.Console.info('Linking done ('+str(time.time()-startTime)+'s)')
        else:
            Utils.Console.info('Linking not necessary')
            pass

    except subprocess.CalledProcessError as e:
        compilationStatus['message'] = e.output
        compilationStatus['returncode'] = e.returncode
        Utils.Console.error('Could not link program')
        pass

    WSServer.send('compilationStatus', compilationStatus)

    if compilationStatus['returncode'] == 0 and runGame:
        # TODO use threads
        _runGame(outputFolder+'/game', outputFolder)
        pass

    return compilationStatus
    pass
Ejemplo n.º 24
0
def getAssetList(evData):
    # Load list of assets
    return Project.getAssetList()
Ejemplo n.º 25
0
def parseCPPFile(fileName):
    import re
    from server import Config
    from server.project import Project
    from server.io import Utils

    global _clangIndex
    global _translationUnits
    global _parserLock
    global _filesBeingParsed

    # Remove #include's from source files, to prevent clang
    # from parsing them. I know this is a horrible solution,
    # but clang will take forever to parse the files if they
    # have headers, and it doesn't have an option for disabling
    # recursive parsing.
    while True:
        _parserLock.acquire()
        if not fileName in _filesBeingParsed:
            _filesBeingParsed.add(fileName)
            _parserLock.release()
            break
        _parserLock.release()
        time.sleep(0.1)
        pass

    if fileName in _translationUnits:
        tu = _translationUnits[fileName]
        tu.reparse([(fileName, open(fileName,'r'))])
    else:
        try :
            # TODO maybe get the flags from BuildEventHandler?
            ####
            # TODO documentar q foi gerado com:
            # clang++ -x c++-header -std=c++11 Eigen -relocatable-pch -o Eigen.pch
            # (dentro da pasta Eigen)
            ####
            tu = _clangIndex.parse(fileName, ['-std=c++11',
                                        '-Wall',
                                        '-x', 'c++',
                                        '-DLINUX',
                                        '-DDESKTOP',
                                        '-DDEBUG',
                                        '-I',Config.get('export', 'third_party_folder')+'/rapidjson/include',
                                        '-I',Config.get('export', 'third_party_folder')+'/Eigen',
                                        '-I',Project.getProjectFolder()+'/default_assets/',
                                        '-include-pch',Config.get('export', 'third_party_folder')+'/Eigen/Eigen/Eigen.pch'],
                                        options=TranslationUnit.PARSE_SKIP_FUNCTION_BODIES)
            _translationUnits[fileName] = tu
        except Exception as err:
            Utils.Console.error('Error processing translation unit!')
            _filesBeingParsed.remove(fileName)
            return dict(symbols=[], success=False, diagnostics=[str(err)], dependencies=[])
        pass

    # Check for diagnostic messages
    diagnostics = []
    success = True
    for diag in tu.diagnostics:
        diagnostics.append(diag.spelling)
        if diag.severity==clang.cindex.Diagnostic.Error or diag.severity==clang.cindex.Diagnostic.Fatal:
            success = False
        pass

    # Get list of pragmas
    # TODO use custom c++11 attributes in the form [[hidden]] [[visible]] etc.
    dependencies = set()
    parseResult = dict(symbols=[])
    if success:
        prevToken = None
        nextIsPragma = False
        pragmaList = []
        for token in tu.cursor.get_tokens():
            if token.kind==TokenKind.IDENTIFIER and prevToken.kind == TokenKind.PUNCTUATION and token.spelling=='pragma':
                nextIsPragma = True
            elif nextIsPragma:
                if token.kind==TokenKind.IDENTIFIER:
                    pragmaList.append(dict(line=token.extent.start.line, identifier=token.spelling))
                nextIsPragma=False
            prevToken = token

        parseContext=dict(depth=0,withinClassContext=False,requestedFileName=fileName,currentNameSpace='')
        parseResult['symbols'] = parseCPPFileRec(tu.cursor, pragmaList, parseContext)

        # Get dependencies
        projFolder = Project.getProjectFolder()
        for dep in tu.get_includes():
            dependency = os.path.normpath(str(dep.include))
            if Utils.IsSubdir(dependency, projFolder):
                dependencies.add(Project.getRelProjFilePath(dependency))
                pass
            pass
        pass

    parseResult['diagnostics'] = diagnostics
    parseResult['success'] = success
    parseResult['dependencies'] = list(dependencies)

    _filesBeingParsed.remove(fileName)

    return parseResult