void BuildAndroid::RunADBStartActivity()
{

    SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
    String adbCommand = platformAndroid_->GetADBCommand();

    ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
    Project* project = toolSystem->GetProject();
    AndroidBuildSettings* settings = project->GetBuildSettings()->GetAndroidBuildSettings();

    String stringArgs;
    const char* cpackage = settings->GetPackageName().CString();
    stringArgs.AppendWithFormat("shell am start -n %s/%s.AtomicGameEngine",cpackage, cpackage);

    Vector<String> args = stringArgs.Split(' ');

    currentBuildPhase_ = ADBStartActivity;
    Subprocess* subprocess = subs->Launch(adbCommand, args, buildPath_);
    if (!subprocess)
    {
        FailBuild("StartActivity operation did not launch successfully.");
        return;
    }

    VariantMap buildOutput;
    buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Starting Android Activity</color>\n\n";
    SendEvent(E_BUILDOUTPUT, buildOutput);

    SubscribeToEvent(subprocess, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(BuildAndroid, HandleADBStartActivityComplete));
    SubscribeToEvent(subprocess, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(BuildBase, HandleSubprocessOutputEvent));

}
void BuildAndroid::RunADBListDevices()
{
    ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
    SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();

    String adbCommand = platformAndroid_->GetADBCommand();

    deviceListText_.Clear();

    Vector<String> args = String("devices").Split(' ');

    currentBuildPhase_ = ADBListDevices;
    Subprocess* subprocess = subs->Launch(adbCommand, args, "");

    if (!subprocess)
    {
        FailBuild("Android List Device operation did not launch successfully.");
        return;
    }

    VariantMap buildOutput;
    buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Listing Android Devices</color>\n\n";
    SendEvent(E_BUILDOUTPUT, buildOutput);

    SubscribeToEvent(subprocess, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(BuildAndroid, HandleADBListDevicesComplete));
    SubscribeToEvent(subprocess, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(BuildAndroid, HandleADBListDevicesOutputEvent));

}
void BuildAndroid::RunADBInstall()
{
    ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
    ToolPrefs* prefs = tenv->GetToolPrefs();
    SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
    String adbCommand = platformAndroid_->GetADBCommand();

    Vector<String> args;

    if ( prefs->GetReleaseCheck() > 2 ) // install release apk
        args = String("install -r ./bin/Atomic-release.apk").Split(' ');
    else
        args = String("install -r ./bin/Atomic-debug.apk").Split(' ');

    currentBuildPhase_ = ADBInstall;
    Subprocess* subprocess = subs->Launch(adbCommand, args, buildPath_);
    if (!subprocess)
    {
        FailBuild("APK Device Installation operation did not launch successfully.");
        return;
    }

    VariantMap buildOutput;
    buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Installing on Android Device</color>\n\n";
    SendEvent(E_BUILDOUTPUT, buildOutput);

    SubscribeToEvent(subprocess, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(BuildAndroid, HandleRunADBInstallComplete));
    SubscribeToEvent(subprocess, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(BuildBase, HandleSubprocessOutputEvent));

}
bool LicenseSystem::Deactivate()
{
    if (deactivate_.NotNull())
    {
        VariantMap eventData;
        eventData[LicenseDeactivationError::P_MESSAGE] = "LicenseSystem::Deactivate - request already exists";
        SendEvent(E_LICENSE_DEACTIVATIONERROR, eventData);
        return false;
    }

    if (!key_.Length())
    {
        VariantMap eventData;
        eventData[LicenseDeactivationError::P_MESSAGE] = "LicenseSystem::Deactivate - zero length key";
        SendEvent(E_LICENSE_DEACTIVATIONERROR, eventData);
        return false;
    }

    CurlManager* cm = GetSubsystem<CurlManager>();
    String post;
    String id = GenerateMachineID();
    post.AppendWithFormat("key=%s&id=%s", key_.CString(), id.CString());

    deactivate_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_deactivate.php", post);

    SubscribeToEvent(deactivate_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleDeactivate));

    return true;

}
Beispiel #5
0
Player::Player(Context* context) :
    Object(context)
{
    viewport_ = new Viewport(context_);
    GetSubsystem<Renderer>()->SetViewport(0, viewport_);

    SubscribeToEvent(E_EXITREQUESTED, ATOMIC_HANDLER(Player, HandleExitRequested));
}
// usage: project <projectPath> [cache (-clean)]
bool ProjectCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
{
    String argument = arguments[startIndex].ToLower();
    if (argument != "project")
    {
        errorMsg = "Unable to parse project command";
        return false;
    }

    command_ = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
    if (command_ == "cache")
    {
        requiresProjectLoad_ = true;
        SubscribeToEvent(E_PROJECTLOADED, ATOMIC_HANDLER(ProjectCmd, HandleProjectLoaded));

        for (unsigned i = startIndex + 3; i < arguments.Size(); i++)
        {
            if (arguments[i].Length() > 1 && arguments[i][0] == '-')
            {
                String argument = arguments[i].Substring(1).ToLower();
                String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;

                if (argument == "clean")
                {
                    options_ = options_ | PROJECTCMD_CACHE_CLEAN;
                    SubscribeToEvent(E_PROJECTBEGINLOAD, ATOMIC_HANDLER(ProjectCmd, HandleProjectBeginLoad));
                    i++;
                }
            }
        }
    }
    else
    {
        errorMsg = "Unknown project command";
        return false;
    }

    projectPath_ = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;

    return true;
}
void StaticModel::SetModel(Model* model)
{
    if (model == model_)
        return;

    // If script erroneously calls StaticModel::SetModel on an AnimatedModel, warn and redirect
    if (GetType() == AnimatedModel::GetTypeStatic())
    {
        ATOMIC_LOGWARNING("StaticModel::SetModel() called on AnimatedModel. Redirecting to AnimatedModel::SetModel()");
        AnimatedModel* animatedModel = static_cast<AnimatedModel*>(this);
        animatedModel->SetModel(model);
        return;
    }

    // Unsubscribe from the reload event of previous model (if any), then subscribe to the new
    if (model_)
        UnsubscribeFromEvent(model_, E_RELOADFINISHED);

    model_ = model;

    if (model)
    {
        SubscribeToEvent(model, E_RELOADFINISHED, ATOMIC_HANDLER(StaticModel, HandleModelReloadFinished));

        // Copy the subgeometry & LOD level structure
        SetNumGeometries(model->GetNumGeometries());
        const Vector<Vector<SharedPtr<Geometry> > >& geometries = model->GetGeometries();
        const PODVector<Vector3>& geometryCenters = model->GetGeometryCenters();
        const Matrix3x4* worldTransform = node_ ? &node_->GetWorldTransform() : (const Matrix3x4*)0;
        for (unsigned i = 0; i < geometries.Size(); ++i)
        {
            batches_[i].worldTransform_ = worldTransform;
            geometries_[i] = geometries[i];
            geometryData_[i].center_ = geometryCenters[i];

            // ATOMIC BEGIN
            geometryData_[i].enabled_ = true;
            geometryData_[i].batchGeometry_ = 0;
            // ATOMIC END

        }

        SetBoundingBox(model->GetBoundingBox());
        ResetLodLevels();
    }
    else
    {
        SetNumGeometries(0);
        SetBoundingBox(BoundingBox());
    }

    MarkNetworkUpdate();
}
void PlatformAndroid::RefreshAndroidTargets()
{
    if (refreshAndroidTargetsProcess_.NotNull())
        return;

    ToolPrefs* prefs = GetSubsystem<ToolEnvironment>()->GetToolPrefs();
    FileSystem* fileSystem = GetSubsystem<FileSystem>();

    String androidSDKPath = prefs->GetAndroidSDKPath();

    if (!fileSystem->DirExists(androidSDKPath))
    {
        ATOMIC_LOGERRORF("The Android SDK path %s does not exist", androidSDKPath.CString());
        return;
    }

    SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();

    String androidCommand = GetAndroidCommand();

    Vector<String> args;
    PrependAndroidCommandArgs(args);
    args.Push("list");
    args.Push("targets");

    targetOutput_.Clear();
    refreshAndroidTargetsProcess_ = subs->Launch(androidCommand, args);

    if (refreshAndroidTargetsProcess_.NotNull())
    {

        SubscribeToEvent(refreshAndroidTargetsProcess_, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(PlatformAndroid, HandleRefreshAndroidTargetsEvent));
        SubscribeToEvent(refreshAndroidTargetsProcess_, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(PlatformAndroid, HandleRefreshAndroidTargetsEvent));


    }

}
bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
{
    if (size <= 0)
    {
        ATOMIC_LOGERROR("Zero or negative cube texture size");
        return false;
    }
    if (usage == TEXTURE_DEPTHSTENCIL)
    {
        ATOMIC_LOGERROR("Depth-stencil usage not supported for cube maps");
        return false;
    }

    // Delete the old rendersurfaces if any
    for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
    {
        renderSurfaces_[i].Reset();
        faceMemoryUse_[i] = 0;
    }

    usage_ = usage;

    if (usage == TEXTURE_RENDERTARGET)
    {
        for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
        {
            renderSurfaces_[i] = new RenderSurface(this);
#ifdef ATOMIC_OPENGL
            renderSurfaces_[i]->target_ = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
#endif
        }

        // Nearest filtering and mipmaps disabled by default
        filterMode_ = FILTER_NEAREST;
        requestedLevels_ = 1;
    }

    if (usage == TEXTURE_RENDERTARGET)
        SubscribeToEvent(E_RENDERSURFACEUPDATE, ATOMIC_HANDLER(TextureCube, HandleRenderSurfaceUpdate));
    else
        UnsubscribeFromEvent(E_RENDERSURFACEUPDATE);

    width_ = size;
    height_ = size;
    format_ = format;

    return Create();
}
void LicenseSystem::RequestServerActivation(const String& key)
{
    if (serverActivation_.NotNull())
    {
        ATOMIC_LOGERROR("UIActivation::RequestServerActivation - request already exists");
        return;
    }
    key_ = key;
    CurlManager* cm = GetSubsystem<CurlManager>();
    String post;
    String id = GenerateMachineID();
    post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());

    // todo, this should be a verify url (shouldn't auto add id)
    serverActivation_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_activate.php", post);

    SubscribeToEvent(serverActivation_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleActivationResult));
}
void LicenseSystem::RequestServerVerification(const String& key)
{
    if (serverVerification_.NotNull())
    {
        ATOMIC_LOGERROR("LicenseSystem::RequestServerLicense - request already exists");
        return;
    }

    FileSystem* fileSystem = GetSubsystem<FileSystem>();

    if (fileSystem->FileExists(licenseCachePath_))
    {
        Time* time = GetSubsystem<Time>();
        unsigned currentTime = time->GetTimeSinceEpoch();
        unsigned fileTime = fileSystem->GetLastModifiedTime(licenseCachePath_);
        unsigned deltaMinutes = (currentTime - fileTime)/60;
        if (deltaMinutes < 1)
        {
            ATOMIC_LOGINFOF("%u minutes, using cached license", deltaMinutes);
            SendEvent(E_LICENSE_SUCCESS);
            return;
        }
    }

    ATOMIC_LOGINFO("LicenseSystem::RequestServerLicense - requesting verification");

    key_ = key;
    CurlManager* cm = GetSubsystem<CurlManager>();
    String post;
    String id = GenerateMachineID();
    post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());

    serverVerification_ = cm->MakeRequest("https://store.atomicgameengine.com/licenses/license_verify.php", post);

    SubscribeToEvent(serverVerification_, E_CURLCOMPLETE, ATOMIC_HANDLER(LicenseSystem, HandleVerification));
}
void BuildCmd::Run()
{
    ATOMIC_LOGINFOF("Building project for: %s", buildPlatform_.CString());

    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
    Project* project = tsystem->GetProject();

    Platform* platform = NULL;

    platform = tsystem->GetPlatformByName(buildPlatform_);

    if (!platform)
    {
        Error(ToString("Unknown build platform: %s", buildPlatform_.CString()));
        return;
    }

    // create the build
    BuildBase* buildBase = platform->NewBuild(project);
    if (!assetsBuildTag_.Empty())
    {
        buildBase->SetAssetBuildTag(assetsBuildTag_);
    }
    buildBase->SetAutoLog(autoLog_);

    // add it to the build system
    BuildSystem* buildSystem = GetSubsystem<BuildSystem>();

    buildSystem->QueueBuild(buildBase);

    SubscribeToEvent(E_BUILDCOMPLETE, ATOMIC_HANDLER(BuildCmd, HandleBuildComplete));

    // TODO: parallel/serial builds
    buildSystem->StartNextBuild();

}
 AtomicGlowApp::AtomicGlowApp(Context* context) :
     IPCClientApp(context)
 {
     SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(AtomicGlowApp, HandleUpdate));
 }
WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
{

    const Vector<String>& arguments = GetArguments();

#ifdef ATOMIC_PLATFORM_LINUX
    XSetErrorHandler(XErrorHandlerImpl);
    XSetIOErrorHandler(XIOErrorHandlerImpl);

    // Install a signal handler so we clean up after ourselves.
    signal(SIGINT, TerminationSignalHandler);
    signal(SIGTERM, TerminationSignalHandler);

#endif

    // IMPORTANT: See flags being set in implementation of void WebAppBrowser::OnBeforeCommandLineProcessing
    // these include "--enable-media-stream", "--enable-usermedia-screen-capturing", "--off-screen-rendering-enabled", "--transparent-painting-enabled"

#ifdef ATOMIC_PLATFORM_LINUX
    static const char* _argv[2] = { "AtomicWebView", "--disable-setuid-sandbox" };
    CefMainArgs args(2, (char**) &_argv);
#else
    CefMainArgs args;
#endif

    CefSettings settings;
    settings.windowless_rendering_enabled = 1;    

    FileSystem* fs = GetSubsystem<FileSystem>();

    // Set CEF log file to existing log folder if any avoid attempting to write
    // to executable folder, which is likely not writeable

    Log* log = GetSubsystem<Log>();
    if (log && log->GetLogFile())
    {
        const File* logFile = log->GetLogFile();
        String logPath = logFile->GetName ();
        if (logPath.Length())
        {
            String pathName, fileName, ext;
            SplitPath(logPath, pathName, fileName, ext);
            if (pathName.Length())
            {
                pathName = AddTrailingSlash(pathName) + "CEF.log";
                CefString(&settings.log_file).FromASCII(GetNativePath(pathName).CString());
            }
            
        }
        
    }        

    // default background is white, add a setting
    // settings.background_color = 0;

    if (productVersion_.Length())
    {
        CefString(&settings.product_version).FromASCII(productVersion_.CString());
    }

    if (userAgent_.Length())
    {
        CefString(&settings.user_agent).FromASCII(userAgent_.CString());
    }

    String fullPath;

    // If we've specified the absolute path to a root cache folder, use it
    if (rootCacheFolder_.Length() && cacheName_.Length())
    {        
        fullPath = rootCacheFolder_ + "/" + cacheName_;
        CefString(&settings.cache_path).FromASCII(fullPath.CString());
    }
    else
    {
        fullPath = fs->GetAppPreferencesDir(cacheName_.CString(), "WebCache");
    }


    CefString(&settings.cache_path).FromASCII(fullPath.CString());

    settings.remote_debugging_port = debugPort_;

    d_ = new WebBrowserHostPrivate(this);

    // If losing OSX system menu, it means we're calling this
    // before initializing graphics subsystem
    if (!CefInitialize(args, settings, d_->app_, nullptr))
    {
        ATOMIC_LOGERROR("CefInitialize - Error");
    }

    RegisterWebSchemeHandlers(this);

    // Ensure cookie manager is created
    CefCookieManager::GetGlobalManager(nullptr);

    SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(WebBrowserHost, HandleUpdate));

    instance_ = this;

}
void BuildAndroid::RunAntDebug()
{
    ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
    SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
    ToolPrefs* tprefs = tenv->GetToolPrefs();

    Poco::Process::Env env;

    String buildApk = "debug";  // the default

    if ( tprefs->GetReleaseCheck() > 2 ) // create release apk
        buildApk = "release";


#ifdef ATOMIC_PLATFORM_OSX
    String antCommand = tprefs->GetAntPath();
    Vector<String> args;
    args.Push(buildApk);
#endif
#ifdef ATOMIC_PLATFORM_WINDOWS
    // C:\ProgramData\Oracle\Java\javapath;
    Vector<String> args;
    String antCommand = "cmd";
    String antPath = tprefs->GetAntPath() + "/ant.bat";
    env["JAVA_HOME"] = tprefs->GetJDKRootPath().CString();
    // ant is a batch file on windows, so have to run with cmd /c
    args.Push("/c");
    args.Push("\"" + antPath + "\"");
    args.Push(buildApk);
#endif
#ifdef ATOMIC_PLATFORM_LINUX 

    String antCommand = tprefs->GetAntPath();
    if ( antCommand.Empty() ) // user didnt fill it out, use installed one
    {
        antCommand = "/usr/bin/ant"; // system default if installed
    }
    else
    {
        antCommand.Append("/ant"); 
    }
    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    if ( !fileSystem->FileExists ( antCommand) ) 
    {
        FailBuild("The ant program can not be found, check the Ant Path in Build Settings.");
    }
    Vector<String> args;
    args.Push(buildApk);
#endif

    currentBuildPhase_ = AntBuildDebug;
    Subprocess* subprocess = subs->Launch(antCommand, args, buildPath_, env);

    if (!subprocess)
    {
        FailBuild("The ant build operation did not launch successfully.");
        return;
    }

    VariantMap buildOutput;
    buildOutput[BuildOutput::P_TEXT] = "<color #D4FB79>Starting Android " + buildApk + " Deployment</color>\n\n";
    SendEvent(E_BUILDOUTPUT, buildOutput);

    SubscribeToEvent(subprocess, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(BuildAndroid, HandleAntDebugComplete));
    SubscribeToEvent(subprocess, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(BuildBase, HandleSubprocessOutputEvent));

}