コード例 #1
0
ファイル: stringutils.cpp プロジェクト: 1414648814/behaviac
        /// convert multibyte string to wide char string
        bool MBSToWCS(behaviac::wstring& resultString, const behaviac::string& str, const char* locale)
        {
            BEHAVIAC_UNUSED_VAR(resultString);
            BEHAVIAC_UNUSED_VAR(str);
            BEHAVIAC_UNUSED_VAR(locale);

            bool ret = false;

#if BEHAVIAC_COMPILER_MSVC
            const int cp = (strcmp(locale, LOCALE_CN_UTF8) == 0) ? CP_UTF8 : CP_ACP;
            const int dwNum = MultiByteToWideChar(cp, 0, str.c_str(), -1, 0, 0);
            wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum * 2 + 2, "MBSToWCS");

            if (buffer)
            {
                MultiByteToWideChar(cp, 0, str.c_str(), -1, buffer, dwNum);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);

                ret = true;
            }

#else
            uint32_t dwNum = (str.size() + 1) * 4;
            wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum, "MBSToWCS");

            if (buffer)
            {
                //remember it to restore it later
                char* currrentLocale = setlocale(LC_ALL, 0);

                char* loc = setlocale(LC_ALL, locale);

                if (loc)
                {
                    mbstowcs(buffer, str.c_str(), dwNum);
                    ret = true;
                }

                //restore
                setlocale(LC_ALL, currrentLocale);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);
            }

#endif//#if BEHAVIAC_COMPILER_MSVC

            return ret;
        }
コード例 #2
0
ファイル: filesystem_gcc.cpp プロジェクト: czfsvn/LinuxC
    bool CFileSystem::StartMonitoringDirectory(const wchar_t* dir) {
        BEHAVIAC_UNUSED_VAR(dir);

#if BEHAVIAC_CCDEFINE_GCC_LINUX

        if (!s_bThreadFinish) {
            return true;
        }

        s_bThreadFinish = false;

        behaviac::wstring dirW = dir;

        //to use static!
        static behaviac::string s_buffer = "";

        s_buffer = behaviac::StringUtils::Wide2Char(dirW);

        if (pthread_create(&s_tid, NULL, ThreadFunc, const_cast<char*>(s_buffer.c_str())) < 0) {
            return false;
        }

        //pthread_detach(tid);
#endif

        return true;
    }
コード例 #3
0
void test_stochastic_distribution_0(behaviac::string tree, behaviac::Workspace::EFileFormat format)
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();

    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);
    //ms_workspace = new BehaviacWorkspace();
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    int counts[3] = { 0, 0, 0 };
    int loopCount = STOCHASTIC_SAMPLE_COUNT;

    while (loopCount > 0)
    {
        myTestAgent->btexec();
        ++(counts[myTestAgent->testVar_0]);
        --loopCount;
    }

#if BEHAVIAC_COMPILER_MSVC

    for (int i = 0; i < 3; ++i)
    {
        int k = counts[i];
        int bias = abs(k - STOCHASTIC_SAMPLE_COUNT / 3);
        CHECK_LESS(bias, (STOCHASTIC_SAMPLE_COUNT / 20));
    }

#endif
    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}
コード例 #4
0
void test_stochastic_distribution_1(behaviac::string tree, behaviac::Workspace::EFileFormat format,
                                    int loopCount = STOCHASTIC_SAMPLE_COUNT, int referenceValue = STOCHASTIC_SAMPLE_COUNT / 3, int checkValue = STOCHASTIC_SAMPLE_COUNT / 30)
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();
    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);


    int predicateValueCount = 0;
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    while (loopCount > 0)
    {
        myTestAgent->resetProperties();
        myTestAgent->btexec();

        if (myTestAgent->testVar_0 == 0)
        {
            predicateValueCount++;
        }

        --loopCount;
    }

#if BEHAVIAC_COMPILER_MSVC
    int bias = abs(predicateValueCount - referenceValue);
    CHECK_LESS(bias, checkValue);
#endif
    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}
コード例 #5
0
ファイル: behaviortree_task.cpp プロジェクト: xfw5/behaviac
        /// Construct. begin a profiling block with the specified name and optional call count.
        AutoProfileBlockSend(Profiler* profiler, const behaviac::string& taskClassid, const Agent* agent) : profiler_(profiler)
        {
            if (Config::IsProfiling())
            {
                profiler_ = profiler;

                if (profiler_)
                {
                    profiler_->BeginBlock(taskClassid.c_str(), agent);
                }
            }
        }
コード例 #6
0
//< Selector Probability Tests
void test_stochastic_distribution_2(behaviac::string tree, behaviac::Workspace::EFileFormat format, int refs[3])
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();
    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    int counts[3] = { 0, 0, 0 };
    int loopCount = 10000;

    while (loopCount > 0)
    {
        myTestAgent->btexec();
        ++(counts[myTestAgent->testVar_0]);
        --loopCount;
    }

    for (int i = 0; i < 3; ++i)
    {
        int k = counts[i];
        int bias = abs(k - refs[i]);
        CHECK_LESS(bias, 1000);
    }

    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}
コード例 #7
0
ファイル: planner.cpp プロジェクト: Evilcoolkings/behaviac
    void Planner::LogPlanNodeEnd(Agent* a, BehaviorNode* n, const behaviac::string& result)
    {
        BEHAVIAC_UNUSED_VAR(a);
        BEHAVIAC_UNUSED_VAR(n);
        BEHAVIAC_UNUSED_VAR(result);
#if !BEHAVIAC_RELEASE

        if (Config::IsLoggingOrSocketing())
        {
            behaviac::string ni = BehaviorTask::GetTickInfo(a, n, NULL);

            LogManager::GetInstance()->Log("[plan_node_end]%s %s\n", ni.c_str(), result.c_str());
        }

#endif
    }
コード例 #8
0
ファイル: logmanager.cpp プロジェクト: 1414648814/behaviac
    void LogManager::Log(const behaviac::Agent* pAgent, const char* typeName, const char* varName, const char* value)
    {
        BEHAVIAC_UNUSED_VAR(pAgent);
        BEHAVIAC_UNUSED_VAR(typeName);
        BEHAVIAC_UNUSED_VAR(varName);
        BEHAVIAC_UNUSED_VAR(value);

        if (Config::IsLoggingOrSocketing())
        {
            //BEHAVIAC_PROFILE("LogManager::LogVar");

            if (pAgent && pAgent->IsMasked())
            {
                const char* agentClassName = pAgent->GetObjectTypeName();
                const behaviac::string agentInstanceName = pAgent->GetName();

                //[property]WorldState::World WorldState::time->276854364
                //[property]Ship::Ship_1 GameObject::HP->100
                //[property]Ship::Ship_1 GameObject::age->0
                //[property]Ship::Ship_1 GameObject::speed->0.000000
                behaviac::string buffer;

                bool bIsPar = IsParVar(varName);

                if (bIsPar)
                {
                    behaviac::string tn = typeName;
                    //filter out "signed "
                    const char* p = strstr(typeName, "signed ");

                    if (p)
                    {
                        behaviac::string tn2;

                        for (const char* pi = typeName; pi < p; ++pi)
                        {
                            tn2 += *pi;
                        }

                        tn2 += (p + 7);
                        tn = tn2;
                    }

                    buffer = FormatString("[property]%s#%s %s %s->%s\n", agentClassName, agentInstanceName.c_str(), tn.c_str(), varName, value);
                }
                else
                {
                    buffer = FormatString("[property]%s#%s %s->%s\n", agentClassName, agentInstanceName.c_str(), varName, value);
                }

                this->Output(pAgent, buffer.c_str());
                Socket::SendText(buffer.c_str());
            }
        }
    }
コード例 #9
0
ファイル: planner.cpp プロジェクト: Evilcoolkings/behaviac
    void Planner::LogPlanForEachEnd(Agent* a, DecoratorIterator* pForEach, int index, int count, const behaviac::string& result)
    {
        BEHAVIAC_UNUSED_VAR(a);
        BEHAVIAC_UNUSED_VAR(pForEach);
        BEHAVIAC_UNUSED_VAR(count);
        BEHAVIAC_UNUSED_VAR(index);
        BEHAVIAC_UNUSED_VAR(result);
#if !BEHAVIAC_RELEASE

        if (Config::IsLoggingOrSocketing())
        {
            behaviac::string ni = BehaviorTask::GetTickInfo(a, pForEach, NULL);
            LogManager::GetInstance()->Log("[plan_foreach_end]%s %d %d %s\n", ni.c_str(), index, count, result.c_str());
        }

#endif
    }
コード例 #10
0
ファイル: tagobject.cpp プロジェクト: Evilcoolkings/behaviac
        XmlNodeRef MakeXmlNodeStruct(const char* str, const behaviac::string& typeNameT)
        {
            behaviac::string src = str;

            //{color=0;id=;type={bLive=false;name=0;weight=0;};}
            //the first char is '{'
            //the last char is '}'
            behaviac::string::size_type posCloseBrackets = behaviac::StringUtils::Private::SkipPairedBrackets(src);
            BEHAVIAC_ASSERT(posCloseBrackets != behaviac::string::npos);

            bool bIsStructMember = false;
            XmlNodeRef xmlNode = CreateXmlNode(typeNameT.c_str());

            //{color=0;id=;type={bLive=false;name=0;weight=0;};}
			//{color=0;id=;type={bLive=false;name=0;weight=0;};transit_points=3:{coordX=0;coordY=0;}|{coordX=0;coordY=0;}|{coordX=0;coordY=0;};}
            behaviac::string::size_type posBegin = 1;
            behaviac::string::size_type posEnd = src.find_first_of(';', posBegin);

            while (posEnd != behaviac::string::npos)
            {
                BEHAVIAC_ASSERT(src[posEnd] == ';');

                //the last one might be empty
                if (posEnd > posBegin)
                {
                    behaviac::string::size_type posEqual = src.find_first_of('=', posBegin);
                    BEHAVIAC_ASSERT(posEqual > posBegin);

					size_t length = posEqual - posBegin;
                    behaviac::string memmberName = src.substr(posBegin, length);
                    behaviac::string memmberValue;
                    char c = src[posEqual + 1];

                    if (c != '{')
                    {
						//to check if it is an array
						if (IsArrayString(src, posEqual + 1, posEnd))
						{
							length = posEnd - posEqual - 1;
							memmberValue = src.substr(posEqual + 1, length);
						}
						else
						{
							length = posEnd - posEqual - 1;
							memmberValue = src.substr(posEqual + 1, length);
						}
                    }
                    else
                    {
                        bIsStructMember = true;

                        const char* pStructBegin = src.c_str();
                        pStructBegin += posEqual + 1;
                        const char* posCloseBrackets_ = behaviac::StringUtils::Private::SkipPairedBrackets(pStructBegin);
                        length = posCloseBrackets_ - pStructBegin + 1;

                        memmberValue = src.substr(posEqual + 1, length);

                        posEnd = posEqual + 1 + length;
                    }

                    if (bIsStructMember)
                    {
                        XmlNodeRef memberNode = MakeXmlNodeStruct(memmberValue.c_str(), memmberName);

                        xmlNode->addChild(memberNode);
                    }
                    else
                    {
                        //behaviac::string memmberNameFull = typeNameT + "::" + memmberName;
                        //xmlNode->setAttr(memmberNameFull.c_str(), memmberValue.c_str());
                        xmlNode->setAttr(memmberName.c_str(), memmberValue.c_str());
                    }
                }

                bIsStructMember = false;

                //skip ';'
                posBegin = posEnd + 1;

                //{color=0;id=;type={bLive=false;name=0;weight=0;};transit_points=3:{coordX=0;coordY=0;}|{coordX=0;coordY=0;}|{coordX=0;coordY=0;};}
                posEnd = src.find_first_of(';', posBegin);

                if (posEnd > posCloseBrackets)
                {
                    break;
                }
            }

            return xmlNode;
        }