예제 #1
0
void CameraApplication::CreateCamera()
{
    if (!lastScene_)
        return;

    StringVector components;
    components.Push("Placeable");
    components.Push("Camera");
    Entity* cameraEntity = lastScene_->CreateEntity(0, components, AttributeChange::LocalOnly, false, false, true);
    if (!cameraEntity)
    {
        LogError("CameraApplication::CreateCamera: failed to create camera entity");
        return;
    }
    cameraEntity->SetName("FreeLookCamera");
    IRenderer* renderer = framework->Renderer();
    if (!renderer)
    {
        LogError("CameraApplication::CreateCamera: can not assign camera; no renderer assigned");
        return;
    }
    renderer->SetMainCamera(cameraEntity);
    TundraLogic* logic = framework->Module<TundraLogic>();
    if (logic)
        logic->SyncManager()->SetObserver(EntityPtr(cameraEntity));

    lastCamera_ = cameraEntity;

    lastScene_->EntityCreated.Connect(this, &CameraApplication::CheckCameraSpawnPos);

    CheckCameraSpawnPos(lastScene_->EntityByName("FreeLookCameraSpawnPos"), AttributeChange::Default);
}
예제 #2
0
bool BuildWindows::BuildManaged(const String& buildPath)
{
    ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
    ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    Project* project = toolSystem->GetProject();
    ProjectSettings* settings = project->GetProjectSettings();

    String projectPath = project->GetProjectPath();

#ifdef ATOMIC_DEBUG
    String config = "Debug";
#else
    String config = "Release";
#endif

    String managedBins = projectPath + ToString("AtomicNET/%s/Bin/Desktop/", config.CString());
    String managedExe = managedBins + settings->GetName() + ".exe";

    if (!fileSystem->FileExists(managedExe))
    {
        FailBuild(ToString("Error building managed project, please compile the %s binary %s before building", config.CString(), managedExe.CString()));
        return false;
    }

    StringVector results;
    StringVector filtered;

    fileSystem->ScanDir(results, managedBins, "", SCAN_FILES, false);

    StringVector filterList;

    StringVector::Iterator itr = results.Begin();
    while (itr != results.End())
    {
        unsigned i;
        for (i = 0; i < filterList.Size(); i++)
        {
            if (itr->Contains(filterList[i]))
                break;
        }

        if (i == filterList.Size())
            filtered.Push(*itr);

        itr++;
    }

    for (unsigned i = 0; i < filtered.Size(); i++)
    {
        String filename = filtered[i];

        if (!BuildCopyFile(managedBins + filename, buildPath_ + "/" + filename))
            return false;

    }

    return true;

}
StringVector WebRequest::GetResponseHeaderKeys()
{
    StringVector keys;
    for (auto it(is_->responseHeaders.Begin()),
        itEnd(is_->responseHeaders.End()); it != itEnd; ++it)
    {
        keys.Push(it->second_.first_);
    }
    return keys;
}
예제 #4
0
    NETBuild* NETBuildSystem::BuildAtomicProject(Project* project)
    {
        StringVector platforms;
        StringVector configurations;

        platforms.Push("desktop");

#ifdef ATOMIC_DEBUG
        configurations.Push("Debug");
#else
        configurations.Push("Release");
#endif

        AtomicNETCopyAssemblies(context_, project->GetProjectPath() + "AtomicNET/Lib/");

        String solutionPath = project->GetProjectPath() + "AtomicNET/Solution/" + project->GetProjectSettings()->GetName() + ".sln";

        NETBuild* build = Build(solutionPath, platforms, configurations);

        if (build)
        {
            ProjectSettings* settings = project->GetProjectSettings();

            // This path is currently only hit when refreshing for desktop
            if (settings->GetSupportsAndroid() || settings->GetSupportsIOS())
            {
                // Build the PCL, which will get copied to Resources
                build->targets_.Push(project->GetProjectSettings()->GetName());

                // Build the Desktop executable, so we can run it
                // IMPORTANT NOTE: msbuild requires replacing '.' with '_' when in project name
                build->targets_.Push(project->GetProjectSettings()->GetName() + "_Desktop");
            }

            build->project_ = project;

        }

        ATOMIC_LOGINFOF("Received build for project %s", project->GetProjectFilePath().CString());

        return build;

    }
StringVector AnimationController::ActiveAnimations() const
{
    StringVector activeList;

    for(auto i = animations_.Begin(); i != animations_.End(); ++i)
    {
        if (i->second_.phase_ != StopPhase)
            activeList.Push(i->first_);
    }
    
    return activeList;
}
예제 #6
0
StringVector XMLElement::GetStringVector() const
{
    StringVector ret;

    XMLElement stringElem = GetChild("string");
    while (stringElem)
    {
        ret.Push(stringElem.GetAttributeCString("value"));
        stringElem = stringElem.GetNext("string");
    }

    return ret;
}
예제 #7
0
void InsertAlpha(StringVector &container, const String &value)
{
    if (container.Find(value) != container.End())
        return;
    for(auto iter = container.Begin(); iter != container.End(); ++iter)
    {
        if (value.Compare((*iter), false) < 0)
        {
            container.Insert(iter, value);
            return;
        }
    }
    container.Push(value);
}
예제 #8
0
void SceneInteract::HandleMouseEvent(MouseEvent* e)
{
    // Invalidate cached raycast if mouse coordinates have changed
    if (frameRaycasted)
        if (lastX != e->x || lastY != e->y)
            frameRaycasted = false;

    lastX = e->x;
    lastY = e->y;
    itemUnderMouse = GetSubsystem<Urho3D::UI>()->GetElementAt(lastX, lastY, true) != nullptr;

    RayQueryResult *raycastResult = ExecuteRaycast();

    Entity *hitEntity = lastHitEntity;
    if (!hitEntity || !raycastResult)
        return;

    StringVector actionParams;

    if (lastHitEntity)
    {
        if(e->Type() == MouseEvent::MouseMove)
        {
            EntityMouseMove.Emit(hitEntity, e->otherButtons, raycastResult);
        }
        else if (e->Type() == MouseEvent::MouseScroll)
        {
            actionParams.Push(String(e->relativeZ));
            actionParams.Push(Urho3D::ToString("%f,%f,%f", raycastResult->pos.x, raycastResult->pos.y, raycastResult->pos.z));
            hitEntity->Exec(EntityAction::Local, "MouseScroll", actionParams);
            EntityMouseScroll.Emit(hitEntity, e->relativeZ, raycastResult);
        }
        else if (e->Type() == MouseEvent::MousePressed)
        {
            // Execute local entity action with signature:
            // Action name: "MousePress"
            // String parameters: (int)mouseButton, (float,float,float)"x,y,z"
            actionParams.Push(String((int)e->button));
            actionParams.Push(Urho3D::ToString("%f,%f,%f", raycastResult->pos.x, raycastResult->pos.y, raycastResult->pos.z));
            hitEntity->Exec(EntityAction::Local, "MousePress", actionParams);
            EntityClicked.Emit(hitEntity, (int)e->button, raycastResult);
        }
        else if (e->Type() == MouseEvent::MouseReleased)
        {
            // Execute local entity action with signature:
            // Action name: "MouseRelease"
            // String parameters: (int)mouseButton, (float,float,float)"x,y,z", (int)"submesh index"
            actionParams.Push(String((int)e->button));
            actionParams.Push(Urho3D::ToString("%f,%f,%f", raycastResult->pos.x, raycastResult->pos.y, raycastResult->pos.z));
            hitEntity->Exec(EntityAction::Local, "MouseRelease", actionParams);
            EntityClickReleased.Emit(hitEntity, (int)e->button, raycastResult);
        }
    }
}
예제 #9
0
void ParseCommand(String input, String &command, StringVector &parameters)
{
    input = input.Trimmed();
    if (input.Empty())
        return;

    uint parenPos = input.Find('(', 0);
    uint spacePos = input.Find(' ', 0);
    if (parenPos == String::NPOS && spacePos == String::NPOS)
    {
        command = input;
        return;
    }
    StringVector parts;
    if (parenPos != String::NPOS && parenPos < spacePos)
    {
        uint parenEndPos = input.FindLast(')');
        String insideParens = (parenEndPos != String::NPOS ? 
            input.Substring(parenPos+1, parenEndPos-parenPos-1).Trimmed() : input.Substring(parenPos+1).Trimmed());
        command = input.Substring(0, parenPos).Trimmed();
        // "one, two, three", "one,two,three" and "one two three"
        parts = insideParens.Contains(',') ? insideParens.Split(',') : insideParens.Split(' ');
    }
    else
    {
        command = input.Substring(0, spacePos).Trimmed();
        String remaining = input.Substring(spacePos+1).Trimmed();
        // "one, two, three", "one,two,three" and "one two three"
        parts = remaining.Contains(',') ? remaining.Split(',') : remaining.Split(' ');
    }
    for(StringVector::Iterator iter=parts.Begin(); iter!=parts.End(); ++iter)
    {
        String part = (*iter).Trimmed();
        if (part.EndsWith(","))
            part = part.Substring(0, part.Length()-1);
        if (!part.Empty())
            parameters.Push(part);
    }
}
예제 #10
0
void CSClassWriter::GenerateManagedSource(String& sourceOut)
{
    String source = "";

    if (klass_->IsNumberArray())
        return;

    Indent();

    source += "\n";
    String line;

    if (klass_->GetDocString().Length())
    {
        // monodocer -assembly:NETCore.dll -path:en -pretty
        // mdoc export-html -o htmldocs en
        source += IndentLine("/// <summary>\n");
        if (klass_->GetDocString().Contains('\n'))
            source += IndentLine("/* " + klass_->GetDocString() + "*/\n");
        else
            source += IndentLine("/// " + klass_->GetDocString() + "\n");

        source += IndentLine("/// </summary>\n");
    }

    if (klass_->GetBaseClass())
    {

        String baseString = klass_->GetBaseClass()->GetName();

        const PODVector<JSBClass*>& interfaces = klass_->GetInterfaces();

        if (interfaces.Size())
        {
            StringVector baseStrings;
            baseStrings.Push(baseString);
            for (unsigned i = 0; i < interfaces.Size(); i++)
            {
                baseStrings.Push(interfaces.At(i)->GetName());
            }

            baseString = String::Joined(baseStrings, ",");
        }

        line = ToString("public partial class %s%s : %s\n", klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "", baseString.CString());
    }
    else
    {
        String classString = "class";

        if (klass_->IsInterface())
            classString = "interface";

        line = ToString("public partial %s %s%s\n", classString.CString(), klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "");
    }


    source += IndentLine(line);
    source += IndentLine("{\n");

    Indent();

    WriteManagedProperties(source);

    JSBPackage* package = klass_->GetPackage();

    // CoreCLR has pinvoke security demand code commented out, so we do not (currently) need this optimization:
    // https://github.com/dotnet/coreclr/issues/1605
    // line = "[SuppressUnmanagedCodeSecurity]\n";
    // source += IndentLine(line);

    if (!klass_->IsInterface())
    {
        line = "[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]\n";
        source += IndentLine(line);
        line = ToString("public static extern IntPtr csb_%s_%s_GetClassIDStatic();\n", package->GetName().CString(), klass_->GetName().CString());
        source += IndentLine(line);
        source += "\n";
    }

    Dedent();

    // managed functions

    CSFunctionWriter::SetWroteConstructor(false);

    for (unsigned i = 0; i < klass_->functions_.Size(); i++)
    {
        JSBFunction* function = klass_->functions_.At(i);

        if (function->Skip())
            continue;

        if (klass_->IsInterface() && function->IsConstructor())
            continue;

        if (function->IsDestructor())
            continue;

        if (CSTypeHelper::OmitFunction(function))
            continue;

        CSFunctionWriter fwriter(function);
        fwriter.GenerateManagedSource(source);

    }

    // There are some constructors being skipped (like HTTPRequest as it uses a vector of strings in args)
    // Make sure we have at least a IntPtr version
    if (!klass_->IsInterface() && !CSFunctionWriter::GetWroteConstructor() && klass_->GetName() != "RefCounted")
    {
        ATOMIC_LOGINFOF("WARNING: %s class didn't write a constructor, filling in generated native constructor", klass_->GetName().CString());

        line = ToString("public %s (IntPtr native) : base (native)\n", klass_->GetName().CString());
        source += IndentLine(line);
        source += IndentLine("{\n");
        source += IndentLine("}\n\n");
    }

    CSFunctionWriter::SetWroteConstructor(false);

    source += IndentLine("}\n");

    Dedent();

    sourceOut += source;
}
예제 #11
0
void JSONValue::GetVariantValue(Variant& variant, VariantType type) const
{
    switch (type)
    {
    case VAR_BOOL:
        variant = GetBool();
        return;

    case VAR_INT:
        variant = GetInt();
        return;

    case VAR_FLOAT:
        variant = GetFloat();
        return;

    case VAR_DOUBLE:
        variant = GetDouble();
        return;

    case VAR_STRING:
        variant = GetString();
        return;

    case VAR_VARIANTVECTOR:
        {
            VariantVector vector;
            GetVariantVector(vector);
            variant = vector;
        }
        return;

    case VAR_VARIANTMAP:
        {
            VariantMap map;
            GetVariantMap(map);
            variant = map;
        }
        return;

    case VAR_RESOURCEREF:
        {
            ResourceRef ref;
            Vector<String> values = GetString().Split(';');
            if (values.Size() == 2)
            {
                ref.type_ = values[0];
                ref.name_ = values[1];
            }
            variant = ref;
        }
        return;

    case VAR_RESOURCEREFLIST:
        {
            ResourceRefList refList;
            Vector<String> values = GetString().Split(';');
            if (values.Size() >= 1)
            {
                refList.type_ = values[0];
                refList.names_.Resize(values.Size() - 1);
                for (unsigned i = 1; i < values.Size(); ++i)
                    refList.names_[i - 1] = values[i];
            }
            variant = refList;
        }
        return;

    case VAR_STRINGVECTOR:
        {
            StringVector vector;
            for (unsigned i = 0; i < Size(); ++i)
                vector.Push((*this)[i].GetString());
            variant = vector;
        }
        return;

    default:
        variant.FromString(type, GetString());
        return;
    }
}
예제 #12
0
    void NETBuildSystem::HandleToolUpdate(StringHash eventType, VariantMap& eventData)
    {
        if (curBuild_.Null() && !builds_.Size())
            return;

        if (curBuild_.Null())
        {
            // kick off a new build

            curBuild_ = builds_.Front();
            builds_.PopFront();


            FileSystem* fileSystem = GetSubsystem<FileSystem>();

            // Ensure solution still exists
            if (!fileSystem->FileExists(curBuild_->solutionPath_))
            {
                CurrentBuildError(ToString("Solution does not exist(%s)", curBuild_->solutionPath_.CString()));
                return;
            }

            String solutionPath = curBuild_->solutionPath_;

            String ext = GetExtension(solutionPath);

            bool requiresNuGet = true;

            if (ext == ".sln")
            {
                // TODO: handle projects that require nuget
                requiresNuGet = false;

                if (!fileSystem->FileExists(solutionPath))
                {
                    CurrentBuildError(ToString("Generated solution does not exist (%s : %s)", curBuild_->solutionPath_.CString(), solutionPath.CString()));
                    return;
                }

            }
            else if (ext == ".json")
            {
                SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));

                gen->SetSupportedPlatforms(curBuild_->platforms_);
                gen->SetRewriteSolution(true);

                if (!gen->LoadJSONProject(solutionPath))
                {
                    CurrentBuildError(ToString("Error loading project (%s)", solutionPath.CString()));
                    return;
                }

                if (!gen->Generate())
                {
                    CurrentBuildError(ToString("Error generating project (%s)", solutionPath.CString()));
                    return;
                }

                solutionPath = gen->GetSolution()->GetOutputFilename();
                requiresNuGet = gen->GetRequiresNuGet();

                if (!fileSystem->FileExists(solutionPath))
                {
                    CurrentBuildError(ToString("Generated solution does not exist (%s : %s)", curBuild_->solutionPath_.CString(), solutionPath.CString()));
                    return;
                }

            }

            ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
            const String& nugetBinary = tenv->GetAtomicNETNuGetBinary();

            if (requiresNuGet && !fileSystem->FileExists(nugetBinary))
            {
                CurrentBuildError(ToString("NuGet binary is missing (%s)", nugetBinary.CString()));
                return;
            }

            StringVector stringVector;
            String platforms;
            StringVector processedPlatforms;
            String configs;

            for (unsigned i = 0; i < curBuild_->configurations_.Size(); i++)
            {
                stringVector.Push(ToString("/p:Configuration=%s", curBuild_->configurations_[i].CString()));
            }

            configs = String::Joined(stringVector, " ");
            stringVector.Clear();

            for (unsigned i = 0; i < curBuild_->platforms_.Size(); i++)
            {
                // map platform
                String platform = curBuild_->platforms_[i];

                if (platform == "windows" || platform == "macosx" || platform == "linux")
                {
                    ATOMIC_LOGINFOF("Platform \"%s\" mapped to \"desktop\"", platform.CString());
                    platform = "desktop";
                }

                if (processedPlatforms.Contains(platform))
                {
                    ATOMIC_LOGWARNINGF("Platform \"%s\" is duplicated, skipping", platform.CString());
                    continue;
                }

                processedPlatforms.Push(platform);

                if (platform == "desktop" || platform == "android")
                {
                    platform = "\"Any CPU\"";
                }
                else if (platform == "ios")
                {

                    platform = "\"Any CPU\"";
                    // TODO
                    // platform = "iPhone";
                }
                else
                {
                    ATOMIC_LOGERRORF("Unknown platform: %s, skipping", platform.CString());
                    continue;
                }

                platform = ToString("/p:Platform=%s", platform.CString());

                if (stringVector.Contains(platform))
                {
                    // This can happen when specifying Desktop + Android for example
                    continue;
                }

                stringVector.Push(platform);
            }

            platforms = String::Joined(stringVector, " ");
            stringVector.Clear();

            Vector<String> args;

#ifdef ATOMIC_PLATFORM_WINDOWS

            String cmdToolsPath = Poco::Environment::get("VS140COMNTOOLS", "").c_str();

            if (!cmdToolsPath.Length())
            {
                CurrentBuildError("VS140COMNTOOLS environment variable not found, cannot proceed");
                return;
            }

            if (!cmdToolsPath.EndsWith("\\"))
            {
                cmdToolsPath += "\\";
            }

            String msbuildcmd = ToString("%sVsMSBuildCmd.bat", cmdToolsPath.CString());

            String cmd = "cmd";

            args.Push("/A");
            args.Push("/C");

            // vcvars bat
            String compile = ToString("\"\"%s\" ", msbuildcmd.CString());

            if (requiresNuGet)
            {
                compile += ToString("&& \"%s\" restore \"%s\" ", nugetBinary.CString(), solutionPath.CString());
            }

            compile += ToString("&& msbuild \"%s\" %s %s", solutionPath.CString(), platforms.CString(), configs.CString());

            if (curBuild_->targets_.Size()) {

                StringVector targets;

                for (unsigned i = 0; i < curBuild_->targets_.Size(); i++)
                {
                    const char* tname = curBuild_->targets_[i].CString();
                    targets.Push(ToString("/t:\"%s:Rebuild\"", tname));
                }

                compile += " " + String::Joined(targets, " ");

            }

            // close out quote
            compile += "\"";

            args.Push(compile);

#else

            String compile;

            String cmd = "bash";
            args.Push("-c");

            String xbuildBinary = tenv->GetMonoExecutableDir() + "xbuild";

            if (requiresNuGet)
            {
#ifdef ATOMIC_PLATFORM_OSX
                compile += ToString("\"%s\" restore \"%s\" && ", nugetBinary.CString(), solutionPath.CString());
#else
                compile += ToString("mono \"%s\" restore \"%s\" && ", nugetBinary.CString(), solutionPath.CString());
#endif
            }

            compile += ToString("\"%s\" \"%s\" %s %s", xbuildBinary.CString(), solutionPath.CString(), platforms.CString(), configs.CString());

            if (curBuild_->targets_.Size()) {

                StringVector targets;

                for (unsigned i = 0; i < curBuild_->targets_.Size(); i++)
                {
                    const char* tname = curBuild_->targets_[i].CString();
                    targets.Push(ToString("%s:Rebuild", tname));
                }

                compile += " /target:\"" + String::Joined(targets, ";") + "\"";

            }

            args.Push(compile);

#endif

            curBuild_->allArgs_.Join(args, " ");

            SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
            Subprocess* subprocess = nullptr;

            ATOMIC_LOGINFOF("%s : %s", cmd.CString(), curBuild_->allArgs_.CString());

            try
            {
                subprocess = subs->Launch(cmd, args, "");
            }
            catch (Poco::SystemException)
            {
                subprocess = nullptr;
            }

            if (!subprocess)
            {
                CurrentBuildError(ToString("NETCompile::Compile - Unable to launch MSBuild subprocess\n%s", curBuild_->allArgs_.CString()));
                return;
            }

            VariantMap buildBeginEventData;
            buildBeginEventData[NETBuildBegin::P_BUILD] = curBuild_;
            SendEvent(E_NETBUILDBEGIN, buildBeginEventData);

            SubscribeToEvent(subprocess, E_SUBPROCESSCOMPLETE, ATOMIC_HANDLER(NETBuildSystem, HandleCompileProcessComplete));
            SubscribeToEvent(subprocess, E_SUBPROCESSOUTPUT, ATOMIC_HANDLER(NETBuildSystem, HandleSubprocessOutput));

            curBuild_->status_ = NETBUILD_BUILDING;

        }

    }