示例#1
0
std::string RamAi::GameMonteCarloTree::GetLogDetails() const
{
	return MonteCarloTreeBase::GetLogDetails() + " k: " + DoubleToString(AiSettings::GetData().partialExpansionBase, 9);
}
示例#2
0
void SpecialsPanel::Update() {
    //std::cout << "SpecialsPanel::Update" << std::endl;
    for (std::map<std::string, StatisticIcon*>::iterator it = m_icons.begin(); it != m_icons.end(); ++it)
        DeleteChild(it->second);
    m_icons.clear();


    // get specials to display
    TemporaryPtr<const UniverseObject> obj = GetUniverseObject(m_object_id);
    if (!obj) {
        ErrorLogger() << "SpecialsPanel::Update couldn't get object with id " << m_object_id;
        return;
    }
    const std::map<std::string, std::pair<int, float> >& specials = obj->Specials();


    // get specials and use them to create specials icons
    // for specials with a nonzero
    for (std::map<std::string, std::pair<int, float> >::const_iterator it = specials.begin(); it != specials.end(); ++it) {
        const Special* special = GetSpecial(it->first);
        StatisticIcon* graphic = 0;
        if (it->second.second > 0.0f)
            graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()), it->second.second, 2, false);
        else
            graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()));

        graphic->SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay"));

        std::string desc = UserString(special->Description());

        if (it->second.second > 0.0f)
            desc += "\n" + boost::io::str(FlexibleFormat(UserString("SPECIAL_CAPACITY")) % DoubleToString(it->second.second, 2, false));

        if (it->second.first > 0)
            desc += "\n" + boost::io::str(FlexibleFormat(UserString("ADDED_ON_TURN")) % boost::lexical_cast<std::string>(it->second.first));
        else
            desc += "\n" + UserString("ADDED_ON_INITIAL_TURN");

        if (GetOptionsDB().Get<bool>("UI.autogenerated-effects-descriptions") && !special->Effects().empty()) {
            desc += boost::io::str(FlexibleFormat(UserString("ENC_EFFECTS_STR")) % EffectsDescription(special->Effects()));
        }

        graphic->SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>(
            new IconTextBrowseWnd(ClientUI::SpecialIcon(special->Name()),
                                  UserString(special->Name()),
                                  desc)));
        m_icons[it->first] = graphic;

        graphic->InstallEventFilter(this);
    }

    const GG::X AVAILABLE_WIDTH = Width() - EDGE_PAD;
    GG::X x(EDGE_PAD);
    GG::Y y(EDGE_PAD);

    for (std::map<std::string, StatisticIcon*>::iterator it = m_icons.begin(); it != m_icons.end(); ++it) {
        StatisticIcon* icon = it->second;
        icon->SizeMove(GG::Pt(x, y), GG::Pt(x,y) + GG::Pt(SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT));
        AttachChild(icon);

        x += SPECIAL_ICON_WIDTH + EDGE_PAD;

        if (x + SPECIAL_ICON_WIDTH + EDGE_PAD > AVAILABLE_WIDTH) {
            x = GG::X(EDGE_PAD);
            y += SPECIAL_ICON_HEIGHT + EDGE_PAD;
        }
    }

    if (m_icons.empty()) {
        Resize(GG::Pt(Width(), GG::Y0));
    } else {
        Resize(GG::Pt(Width(), y + SPECIAL_ICON_HEIGHT + EDGE_PAD*2));
    }
}
CBCGPTextFormatDlg::CBCGPTextFormatDlg(CBCGPTextFormat& textFormat, CBCGPTextFormatDlgOptions* pOptions, CWnd* pParent /*=NULL*/)
	: CBCGPDialog(CBCGPTextFormatDlg::IDD, pParent),
	m_textFormat(textFormat)
{
	//{{AFX_DATA_INIT(CBCGPTextFormatDlg)
	m_bClipText = m_textFormat.IsClipText();
	m_strTextAngle = _T("0");
	m_nHorzAlignment = (int)m_textFormat.GetTextAlignment();
	m_strTextSize = _T("");
	m_nTextStyle = m_textFormat.GetFontStyle();
	m_nVertAlignment = m_textFormat.GetTextVerticalAlignment();
	m_nTextWeight = m_textFormat.GetFontWeight() == 950 ? 9 : m_textFormat.GetFontWeight() / 100 - 1;
	m_bWordWrap = m_textFormat.IsWordWrap();
	m_nLocaleIndex = 0;
	m_bUnderline = textFormat.IsUnderline();
	m_bStrikethrough = textFormat.IsStrikethrough();
	//}}AFX_DATA_INIT

	if (pOptions != NULL)
	{
		m_Options = *pOptions;

		if (!m_Options.m_brFill.IsEmpty())
		{
			m_wndPreview.m_brFill = m_Options.m_brFill;
		}

		if (!m_Options.m_brText.IsEmpty())
		{
			m_wndPreview.m_brText = m_Options.m_brText;
		}
	}

	double dblTextSize = m_textFormat.GetFontSize();
	m_bIsNegativeHeight = FALSE;

	if (dblTextSize < 0.0)
	{
		CWindowDC dc(NULL);

		int nLogY = dc.GetDeviceCaps(LOGPIXELSY);
		if (nLogY != 0)
		{
			dblTextSize = MulDiv(72, (int)(-100 * dblTextSize), nLogY * 100);
			m_bIsNegativeHeight = TRUE;
		}
	}

	DoubleToString(m_textFormat.GetDrawingAngle(), m_strTextAngle);
	DoubleToString(dblTextSize, m_strTextSize);

	m_bIsLocal = TRUE;

	m_wndPreview.m_pGM = CBCGPGraphicsManager::CreateInstance();
	ASSERT_VALID(m_wndPreview.m_pGM);

	m_bUseCharSet = !m_wndPreview.m_pGM->IsSupported(BCGP_GRAPHICS_MANAGER_LOCALE);

	m_wndPreview.m_pFormat = &m_textFormatPreview;

	m_wndPreview.m_HorzAlign = (CBCGPTextFormat::BCGP_TEXT_ALIGNMENT)m_nHorzAlignment;
	m_wndPreview.m_VertAlign = (CBCGPTextFormat::BCGP_TEXT_ALIGNMENT)m_nVertAlignment;

#ifndef _BCGSUITE_
	EnableVisualManagerStyle (globalData.m_bUseVisualManagerInBuiltInDialogs, TRUE);
#endif
}
示例#4
0
void SpecialsPanel::Update() {
    //std::cout << "SpecialsPanel::Update" << std::endl;
    for (std::map<std::string, StatisticIcon*>::value_type& entry : m_icons)
        DeleteChild(entry.second);
    m_icons.clear();


    // get specials to display
    std::shared_ptr<const UniverseObject> obj = GetUniverseObject(m_object_id);
    if (!obj) {
        ErrorLogger() << "SpecialsPanel::Update couldn't get object with id " << m_object_id;
        return;
    }

    // get specials and use them to create specials icons
    // for specials with a nonzero
    for (const std::map<std::string, std::pair<int, float>>::value_type& entry : obj->Specials()) {
        const Special* special = GetSpecial(entry.first);
        StatisticIcon* graphic = nullptr;
        if (entry.second.second > 0.0f)
            graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()), entry.second.second, 2, false,
                                        SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT);
        else
            graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()),
                                        SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT);

        graphic->SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay"));

        std::string desc = special->Description();

        if (entry.second.second > 0.0f)
            desc += "\n" + boost::io::str(FlexibleFormat(UserString("SPECIAL_CAPACITY")) % DoubleToString(entry.second.second, 2, false));

        if (entry.second.first > 0)
            desc += "\n" + boost::io::str(FlexibleFormat(UserString("ADDED_ON_TURN")) % entry.second.first);
        else
            desc += "\n" + UserString("ADDED_ON_INITIAL_TURN");

        if (GetOptionsDB().Get<bool>("UI.dump-effects-descriptions") && !special->Effects().empty()) {
            desc += "\n" + Dump(special->Effects());
        }

        graphic->SetBrowseInfoWnd(std::make_shared<IconTextBrowseWnd>(
            ClientUI::SpecialIcon(special->Name()), UserString(special->Name()), desc));
        m_icons[entry.first] = graphic;

        graphic->InstallEventFilter(this);
    }

    const GG::X AVAILABLE_WIDTH = Width() - EDGE_PAD;
    GG::X x(EDGE_PAD);
    GG::Y y(EDGE_PAD);

    for (std::map<std::string, StatisticIcon*>::value_type& entry : m_icons) {
        StatisticIcon* icon = entry.second;
        icon->SizeMove(GG::Pt(x, y), GG::Pt(x,y) + GG::Pt(SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT));
        AttachChild(icon);

        x += SPECIAL_ICON_WIDTH + EDGE_PAD;

        if (x + SPECIAL_ICON_WIDTH + EDGE_PAD > AVAILABLE_WIDTH) {
            x = GG::X(EDGE_PAD);
            y += SPECIAL_ICON_HEIGHT + EDGE_PAD;
        }
    }

    if (m_icons.empty()) {
        Resize(GG::Pt(Width(), GG::Y0));
    } else {
        Resize(GG::Pt(Width(), y + SPECIAL_ICON_HEIGHT + EDGE_PAD*2));
    }
}
示例#5
0
    void JSONWriter::BuildJSONString(const Value* const node,
        int depth, bool escape)
    {
        switch(node->GetType())
        {
        case Value::TYPE_NULL:
            json_string_->append("null");
            break;

        case Value::TYPE_BOOLEAN:
            {
                bool value;
                bool result = node->GetAsBoolean(&value);
                DCHECK(result);
                json_string_->append(value ? "true" : "false");
                break;
            }

        case Value::TYPE_INTEGER:
            {
                int value;
                bool result = node->GetAsInteger(&value);
                DCHECK(result);
                StringAppendF(json_string_, "%d", value);
                break;
            }

        case Value::TYPE_DOUBLE:
            {
                double value;
                bool result = node->GetAsDouble(&value);
                DCHECK(result);
                std::string real = DoubleToString(value);
                // 如果没有小数位或者'e', 为数字添加一个.0. 这样可以确保读取JSON的时候
                // 被解释为一个real而不是int.
                if(real.find('.')==std::string::npos &&
                    real.find('e')==std::string::npos &&
                    real.find('E')==std::string::npos)
                {
                    real.append(".0");
                }
                // JSON规范规定(-1,1)区间的非整数值在小数位前有一个0. ".52"是非法的,
                // "0.52"是合法的.
                if(real[0] == '.')
                {
                    real.insert(0, "0");
                }
                else if(real.length()>1 && real[0]=='-' && real[1]=='.')
                {
                    // "-.1"非法 "-0.1"合法
                    real.insert(1, "0");
                }
                json_string_->append(real);
                break;
            }

        case Value::TYPE_STRING:
            {
                std::string value;
                bool result = node->GetAsString(&value);
                DCHECK(result);
                if(escape)
                {
                    JsonDoubleQuote(UTF8ToUTF16(value), true, json_string_);
                }
                else
                {
                    JsonDoubleQuote(value, true, json_string_);
                }
                break;
            }

        case Value::TYPE_LIST:
            {
                json_string_->append("[");
                if(pretty_print_)
                {
                    json_string_->append(" ");
                }

                const ListValue* list = static_cast<const ListValue*>(node);
                for(size_t i=0; i<list->GetSize(); ++i)
                {
                    if(i != 0)
                    {
                        json_string_->append(",");
                        if(pretty_print_)
                        {
                            json_string_->append(" ");
                        }
                    }

                    Value* value = NULL;
                    bool result = list->Get(i, &value);
                    DCHECK(result);
                    BuildJSONString(value, depth, escape);
                }

                if(pretty_print_)
                {
                    json_string_->append(" ");
                }
                json_string_->append("]");
                break;
            }

        case Value::TYPE_DICTIONARY:
            {
                json_string_->append("{");
                if(pretty_print_)
                {
                    json_string_->append(kPrettyPrintLineEnding);
                }

                const DictionaryValue* dict =
                    static_cast<const DictionaryValue*>(node);
                for(DictionaryValue::key_iterator key_itr=dict->begin_keys();
                    key_itr!=dict->end_keys(); ++key_itr)
                {
                    if(key_itr != dict->begin_keys())
                    {
                        json_string_->append(",");
                        if(pretty_print_)
                        {
                            json_string_->append(kPrettyPrintLineEnding);
                        }
                    }

                    Value* value = NULL;
                    bool result = dict->GetWithoutPathExpansion(*key_itr, &value);
                    DCHECK(result);

                    if(pretty_print_)
                    {
                        IndentLine(depth+1);
                    }
                    AppendQuotedString(*key_itr);
                    if(pretty_print_)
                    {
                        json_string_->append(": ");
                    }
                    else
                    {
                        json_string_->append(":");
                    }
                    BuildJSONString(value, depth+1, escape);
                }

                if(pretty_print_)
                {
                    json_string_->append(kPrettyPrintLineEnding);
                    IndentLine(depth);
                    json_string_->append("}");
                }
                else
                {
                    json_string_->append("}");
                }
                break;
            }

        default:
            // TODO: 处理TYPE_BINARY
            NOTREACHED() << "unknown json type";
        }
    }
//-----------------------------------------------------------------------------
/// Return GPU-time in text format, to be parsed by the Client and displayed as its own timeline.
/// \return A line-delimited, ASCII-encoded, version of the GPU Trace data.
//-----------------------------------------------------------------------------
std::string VktTraceAnalyzerLayer::GetGPUTraceTXT()
{
    gtASCIIString appendString = "";

    VktFrameProfilerLayer* pProfilerLayer = VktFrameProfilerLayer::Instance();

    WaitAndFetchResults(pProfilerLayer);

    // Query the CPU clock frequency so we can accurately convert to wall clock time.
    GPS_TIMESTAMP cpuClockFrequency;
    QueryPerformanceFrequency(&cpuClockFrequency);

    // During QueueSubmit we stored ProfilerResults in mEntriesWithProfilingResults. Form a response using it here.
    ProfilerResultsMap& profiledCmdBufResultsMap = pProfilerLayer->GetCmdBufProfilerResultsMap();

    // During QueueSubmit we stored ProfilerResults in mEntriesWithProfilingResults. Form a response using it here.
    if (!profiledCmdBufResultsMap.empty())
    {
        // Keep a count of the number of lines that we'll write in the response string.
        UINT numResponseLines = 0;

        gtASCIIString profiledCommandsLinesStr;

        ProfilerResultsMap::iterator profIt;

        for (profIt = profiledCmdBufResultsMap.begin(); profIt != profiledCmdBufResultsMap.end(); ++profIt)
        {
            QueueWrapperToProfilingResultsMap::iterator queuesWithProfilingResults;

            QueueWrapperToProfilingResultsMap& resultsPerThread = profIt->second;

            for (queuesWithProfilingResults = resultsPerThread.begin(); queuesWithProfilingResults != resultsPerThread.end(); ++queuesWithProfilingResults)
            {
                VktWrappedQueue* pWrappedQueue = queuesWithProfilingResults->first;

                const double timestampFrequency = pWrappedQueue->GetTimestampFrequency();

                // This structure holds all of the profiler results that were collected at QueueSubmit. The form is LinkId->ProfilerResult.
                const SampleIdToProfilerResultMap* pQueueResults = queuesWithProfilingResults->second;

                SampleIdToProfilerResultMap::const_iterator queueResultsIterInner;

                for (queueResultsIterInner = pQueueResults->begin(); queueResultsIterInner != pQueueResults->end(); ++queueResultsIterInner)
                {
                    UINT64 sampleId = queueResultsIterInner->first;
                    const ProfilerResult* pResult = queueResultsIterInner->second;

                    // Convert timestamps to milliseconds by using the clock frequency.
#ifndef CODEXL_GRAPHICS
                    double preStartTimestamp = (pResult->timestampResult.rawClocks.preStart / timestampFrequency) * 1000.0;
                    double startTimestamp = (pResult->timestampResult.rawClocks.start / timestampFrequency) * 1000.0;
                    double endTimestamp = (pResult->timestampResult.rawClocks.end / timestampFrequency) * 1000.0;
#else
                    double startTimestamp = pResult->timestampResult.alignedMillisecondTimestamps.start;
                    double endTimestamp = pResult->timestampResult.alignedMillisecondTimestamps.end;
#endif

                    FuncId funcId = (FuncId)pResult->measurementInfo.idInfo.funcId;

                    gtASCIIString funcName = GetFunctionNameFromId(funcId);
                    gtASCIIString retVal = "void";
                    gtASCIIString params = "";

                    if (pResult->measurementInfo.idInfo.funcId != FuncId_WholeCmdBuf)
                    {
                        VktAPIEntry* pResultEntry = pProfilerLayer->FindInvocationBySampleId(sampleId);

                        if (pResultEntry != nullptr)
                        {
                            // Convert the functionID and return values from integers into full strings that we can use in the response.
                            funcName = GetFunctionNameFromId(pResultEntry->mFunctionId);
                            retVal = (pResultEntry->m_returnValue != -1) ? VktUtil::WriteResultCodeEnumAsString(pResultEntry->m_returnValue) : "void";
                            params = pResultEntry->mParameters.asCharArray();
                        }
                    }

                    // Vulkan Response line format:
                    // QueueFamilyIndex QueueIndex CommandBuffer APIType FuncId Vulkan_FuncName(Args) = ReturnValue PreStartTime StartTime EndTime SampleId

                    profiledCommandsLinesStr += IntToString(pWrappedQueue->GetQueueFamilyIndex());
                    profiledCommandsLinesStr += " ";

                    profiledCommandsLinesStr += IntToString(pWrappedQueue->GetQueueIndex());
                    profiledCommandsLinesStr += " ";

                    profiledCommandsLinesStr += "0x";
                    profiledCommandsLinesStr += UINT64ToHexString((UINT64)pResult->measurementInfo.idInfo.pWrappedCmdBuf->AppHandle());
                    profiledCommandsLinesStr += " ";

                    profiledCommandsLinesStr += IntToString(VktTraceAnalyzerLayer::Instance()->GetAPIGroupFromAPI(funcId));
                    profiledCommandsLinesStr += " ";

                    profiledCommandsLinesStr += IntToString(funcId);
                    profiledCommandsLinesStr += " ";

                    profiledCommandsLinesStr += "Vulkan_";
                    profiledCommandsLinesStr += funcName;

                    profiledCommandsLinesStr += "(";
                    profiledCommandsLinesStr += params;
                    profiledCommandsLinesStr += ") = ";

                    profiledCommandsLinesStr += retVal;

#ifndef CODEXL_GRAPHICS
                    profiledCommandsLinesStr += " ";
                    profiledCommandsLinesStr += DoubleToString(preStartTimestamp);
#endif

                    profiledCommandsLinesStr += " ";
                    profiledCommandsLinesStr += DoubleToString(startTimestamp);

                    profiledCommandsLinesStr += " ";
                    profiledCommandsLinesStr += DoubleToString(endTimestamp);

                    profiledCommandsLinesStr += " ";
                    profiledCommandsLinesStr += UINT64ToString(pResult->measurementInfo.idInfo.sampleId);

                    profiledCommandsLinesStr += "\n";

                    // We just added another line to our response buffer. Increment the count that the client will read.
                    numResponseLines++;
                }
            }
        }

        // We'll need to insert the GPU Trace section header before the response data, even if there aren't any results.
        appendString += "//==GPU Trace==";
        appendString += "\n";

        appendString += "//CommandBufEventCount=";
        appendString += DWORDToString(numResponseLines);
        appendString += "\n";

        // Include the response lines after the section header.
        if (numResponseLines > 0)
        {
            appendString += profiledCommandsLinesStr;
        }
    }
    else
    {
        appendString += "NODATA";
    }

    return appendString.asCharArray();
}
示例#7
0
TEST(StringNumber, StringToNumber)
{
    int16_t i16;
    int32_t i32;
    int64_t i64;
    long long ll;
    unsigned long long ull;
    ASSERT_FALSE(StringToNumber("223372036854775807", &i32));
    ASSERT_TRUE(StringToNumber("223372036854775807", &i64));
    ASSERT_TRUE(StringToNumber("223372036854775807", &ll));
    ASSERT_TRUE(StringToNumber("223372036854775807", &ull));
    ASSERT_EQ(i64, 223372036854775807LL);
    ASSERT_EQ(ll, 223372036854775807LL);
    ASSERT_EQ(ull, 223372036854775807ULL);
    ASSERT_FALSE(StringToNumber("1147483647", &i16));
    ASSERT_TRUE(StringToNumber("1147483647", &i32));
    ASSERT_TRUE(StringToNumber("1147483647", &i64));
    ASSERT_EQ(i32, 1147483647);
    ASSERT_EQ(i64, 1147483647);

    uint32_t u32;
    ASSERT_TRUE(StringToNumber("1147483647", &u32));

    char buffer[1024];
    double d = 1.0003;

    ASSERT_STREQ(DoubleToString(d, buffer), "1.0003");
    d = std::numeric_limits<double>::infinity();
    ASSERT_STREQ(DoubleToString(d, buffer), "inf");
    d = -std::numeric_limits<double>::infinity();
    ASSERT_STREQ(DoubleToString(d, buffer), "-inf");
#ifdef __GNUC__ // divided by zero is not allowed in msvc
    d = NAN;
    ASSERT_STREQ(DoubleToString(d, buffer), "nan");
#endif

    float f = 1e+22;
    ASSERT_STREQ(FloatToString(f, buffer), "1e+22");
    f = 0.000325;
    ASSERT_STREQ(FloatToString(f, buffer), "0.000325");
    f = std::numeric_limits<double>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "inf");
    f = -std::numeric_limits<double>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "-inf");

#ifdef __GNUC__ // divided by zero is not allowed in msvc
    f = NAN;
    ASSERT_STREQ(FloatToString(f, buffer), "nan");

    f = INFINITY;
    ASSERT_STREQ(FloatToString(f, buffer), "inf");
#endif

    f = -std::numeric_limits<float>::infinity();
    ASSERT_STREQ(FloatToString(f, buffer), "-inf");

    uint32_t i = 255;
    ASSERT_STREQ(UInt32ToHexString(i, buffer), "000000ff");

    std::string str = "1110.32505QQ";
    char* endptr;
    ASSERT_TRUE(ParseNumber(str.c_str(), &d, &endptr));
    ASSERT_TRUE(d == 1110.32505);
    ASSERT_FALSE(StringToNumber(str.c_str(), &d));

    ASSERT_TRUE(ParseNumber(str.c_str(), &f, &endptr));
    ASSERT_TRUE(f == 1110.32505f);
    ASSERT_FALSE(StringToNumber(str.c_str(), &f));

    ASSERT_TRUE(ParseNumber(str.c_str(), &i, &endptr));
    ASSERT_EQ(1110U, i);
    ASSERT_FALSE(StringToNumber(str.c_str(), &i));

    str = "1110.32505";
    d = 0;
    f = 0;
    i = 0;
    ASSERT_TRUE(StringToNumber(str.c_str(), &d));
    ASSERT_TRUE(d == 1110.32505);
    ASSERT_TRUE(StringToNumber(str.c_str(), &f));
    ASSERT_TRUE(f == 1110.32505f);
    ASSERT_FALSE(StringToNumber(str.c_str(), &i));
    str = "-1110";
    int32_t x;
    ASSERT_TRUE(StringToNumber(str.c_str(), &x));
    ASSERT_EQ(x, -1110);
}
示例#8
0
SBI gra_screen::Animate(sf::RenderWindow &App)
{
	if (Timer_c.GetElapsedTime()-osttime-korektatime>1)
	{
		korektatime=Timer_c.GetElapsedTime()-osttime;
	}
	osttime=Timer_c.GetElapsedTime()-korektatime;
	for (int i=0;i<obiekty_il;i++)
	{
		(obiekty+i)->ZasTarcie(App.GetFrameTime(),ProgTarcia);
	}
	const sf::Input& Input = App.GetInput();
	if (Input.IsKeyDown(sf::Key::B))
	{
		for (int i=0;i<obiekty_il;i++)
		{
			(obiekty+i)->SetV(0,0);
		}
	}
	for (int i=0; i<gracz_il; i++)
	{
		bool cx=false;
		bool cy=false;
		int przyspGDoc;
		bool czyuderz=(Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode));
		if (czyuderz)
		przyspGDoc=PrzyspGKop;
		else
		przyspGDoc=PrzyspG;
		if (Input.IsKeyDown(gracze_ev[i][(int)Lewo].KeyCode))
		{
			gracze_ob[i].SetVX(gracze_ob[i].GetVX()-App.GetFrameTime()*przyspGDoc);
			cx=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Prawo].KeyCode))
		{
			gracze_ob[i].SetVX(gracze_ob[i].GetVX()+App.GetFrameTime()*przyspGDoc);
			if (cx)
				cx=false;
			else
				cx=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Gora].KeyCode))
		{
			gracze_ob[i].SetVY(gracze_ob[i].GetVY()-App.GetFrameTime()*przyspGDoc);
			cy=true;
		}

		if (Input.IsKeyDown(gracze_ev[i][(int)Dol].KeyCode))
		{
			gracze_ob[i].SetVY(gracze_ob[i].GetVY()+App.GetFrameTime()*przyspGDoc);
			if (cy)
				cy=false;
			else
				cy=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode))
		{
			if (GraczPowLock[i])
			gracze_ob[i].PopV(MaxVGraczNorm);
			else
			gracze_ob[i].PopV(MaxVGraczKop);
		}
		else
		{
			gracze_ob[i].PopV(MaxVGraczNorm);
			GraczPowLock[i]=false;
		}


	}

	/*for (int i=0; i<obiekty_il; i++)
	{
		(obiekty+i)->Animate(App.GetFrameTime(),bg,bd,bl,bp,bramka);
	}
	for (int i=0; i<obiekty_il-1; i++)
		for (int j=i+1; j<obiekty_il; j++)
			if (czy&&(obiekty+i)->ZderzenieAnaliz(App.GetFrameTime(),obiekty+j,bg,bd,bl,bp,bramka))
			{
				cout << "ZDERZENIE!!!";
				czy=true;
			}*/

	double anisum=0;
	double tmp;
	double mintmp=10000000;
	double mini;
	int dodnum1,dodnum2;
    int num1,num2;
	num1=0;
	while(num1!=-1)
	{
		num1=-1;
		num2=-1;
		mini=1000000;
		for (int i=0; i<obiekty_il-1; i++)
			for (int j=i+1; j<obiekty_il; j++)
			{
				tmp=(obiekty+i)->TZderzenia(obiekty+j);
				if (tmp<mintmp)
				{
					mintmp=tmp;
					dodnum1=i;
					dodnum2=j;
				}
				if (tmp<mini&&tmp<=App.GetFrameTime()-anisum)
				{
					cout << "tmp = " << tmp << endl;
					mini=tmp;
					num1=i;
					num2=j;
				}
			}
		mini-=0.000001;
		if (mini<0)
			mini=0;
		if (num1!=-1)
		{
			anisum+=mini;
			for (int i=0; i<obiekty_il; i++)
			{
				(obiekty+i)->Animate(mini,bg,bd,bl,bp,bramka);
			}
			cout << "Przeliczanie zderzenia: " << num1 << " i " << num2 << endl;
			double mocude;
			if (num1==0&&num2>=5&&Input.IsKeyDown(gracze_ev[num2-5][(int)Uderz].KeyCode)&&!GraczPowLock[num2-5])
			{
				mocude=(obiekty+num1)->PrzeliczZderzenie(obiekty+num2,MocKop);
				GraczPowLock[num2-5]=true;
			}
			else
			mocude=(obiekty+num1)->PrzeliczZderzenie(obiekty+num2);
			if (num1==0&&num2>=5)
			{
				if (mocude>10&&(kops_p.GetStatus()==sf::Sound::Stopped||kops_p.GetPlayingOffset()>0.2))
				{
					cout << "KOPNIECIE DZWIEK";
					kops_p.SetVolume(mocude/2);
					kops_p.Play();
				}
			}
		}
	}
	for (int i=0; i<obiekty_il; i++)
	{
		(obiekty+i)->Animate(App.GetFrameTime()-anisum,bg,bd,bl,bp,bramka);
	}
	string tmpek;
	if (mintmp<100000)
	{
		tmpek+="czas do zderzenia: ";
		tmpek+=DoubleToString(mintmp);
		tmpek+=" obiektu: ";
		tmpek+=IntToString(dodnum1);
		tmpek+=" z: ";
		tmpek+=IntToString(dodnum2);
	}
	else
	{
		tmpek="brak zderzen...";
	}
	Techdata.SetText(tmpek);
	string czas;
	if ((int)(Timer_c.GetElapsedTime()-korektatime)/60<10)
		czas+="0";
	czas+=IntToString((int)(Timer_c.GetElapsedTime()-korektatime)/60);
	czas+=":";
	if ((int)(Timer_c.GetElapsedTime()-korektatime)%60<10)
		czas+="0";
	czas+=IntToString((int)(Timer_c.GetElapsedTime()-korektatime)%60);
	Timer_ob1.SetText(czas);
	//Timer_ob2.SetText(czas);
	return SBI();
}
void ImpTradeSession::exec_order(TradeAPI::OrderPtr &ord) {
    //发送委托到三方接口
    std::string program;
    KCBPCLIHANDLE handle;
    try {
        handle = connect_gateway();
        if (_creditflag == "1") {  //信用账户
            program = "420411";
            int_request(handle, program);
            // set function request parameter
            KCBPCLI_SetValue(handle, "fundid", ord->account.c_str());
            if (ord->inst.exchange == "SSE") {
                KCBPCLI_SetValue(handle, "market", _SHA.c_str());
                KCBPCLI_SetValue(handle, "secuid", _secuid[_SHA].c_str());
            }
            else if (ord->inst.exchange == "SZSE") {
                KCBPCLI_SetValue(handle, "market", _SZA.c_str());
                KCBPCLI_SetValue(handle, "secuid", _secuid[_SZA].c_str());
            }
            KCBPCLI_SetValue(handle, "stkcode", ord->inst.symbol.c_str());
            KCBPCLI_SetValue(handle, "price", DoubleToString(ord->lmtPrice, 10).c_str());
            KCBPCLI_SetValue(handle, "qty", IntToString((int) ord->ordQty).c_str());
            std::string bsflag;
            if (ord->side == "LendBuy" || ord->side == "SellRepayment" || ord->side == "Repayment") {
                KCBPCLI_SetValue(handle, "credittype", "1"); //融资交易
            }
            else if (ord->side == "BorrowSell" || ord->side == "BuyGiveBack" || ord->side == "GiveBack") {
                KCBPCLI_SetValue(handle, "credittype", "2"); //融券交易
            }
            else {
                KCBPCLI_SetValue(handle, "credittype", "0"); //普通交易
            }
            if (ord->side == "Buy" || ord->side == "LendBuy" || ord->side == "BuyGiveBack") {
                if (ord->type == "Limit") {
                    bsflag = "B";
                }
                else if (ord->type == "Market0") {
                    bsflag = "a";
                }
                else if (ord->type == "Market1") {
                    bsflag = "b";
                }
                else if (ord->type == "Market3") {
                    bsflag = "c";
                }
                else if (ord->type == "Market5") {
                    bsflag = "d";
                }
                else if (ord->type == "Market") {
                    bsflag = "e";
                }
                else {
                    bsflag = "B";
                }
            }
            else if (ord->side == "Sell" || ord->side == "SellRepayment") {
                if (ord->type == "Limit") {
                    bsflag = "S";
                }
                else if (ord->type == "Market0") {
                    bsflag = "f";
                }
                else if (ord->type == "Market1") {
                    bsflag = "g";
                }
                else if (ord->type == "Market3") {
                    bsflag = "h";
                }
                else if (ord->type == "Market5") {
                    bsflag = "i";
                }
                else if (ord->type == "Market") {
                    bsflag = "j";
                }
                else {
                    bsflag = "S";
                }
            }
            else if (ord->side == "BorrowSell") {
                if (ord->type == "Limit") {
                    bsflag = "S";
                }
            }
            KCBPCLI_SetValue(handle, "bsflag", bsflag.c_str());
        }
        else { //普通账户
            program = "410411";
            int_request(handle, program);
            // set function request parameter
            KCBPCLI_SetValue(handle, "fundid", ord->account.c_str());
            std::string bsflag;
            if (ord->side == "Buy") {
                if (ord->type == "Limit") {
                    bsflag = "B";
                }
                else if (ord->type == "Market0") {
                    bsflag = "a";
                }
                else if (ord->type == "Market1") {
                    bsflag = "b";
                }
                else if (ord->type == "Market3") {
                    bsflag = "c";
                }
                else if (ord->type == "Market5") {
                    bsflag = "d";
                }
                else if (ord->type == "Market") {
                    bsflag = "e";
                }
                else {
                    bsflag = "B";
                }
            }
            else if (ord->side == "Sell") {
                if (ord->type == "Limit") {
                    bsflag = "S";
                }
                else if (ord->type == "Market0") {
                    bsflag = "f";
                }
                else if (ord->type == "Market1") {
                    bsflag = "g";
                }
                else if (ord->type == "Market3") {
                    bsflag = "h";
                }
                else if (ord->type == "Market5") {
                    bsflag = "i";
                }
                else if (ord->type == "Market") {
                    bsflag = "j";
                }
                else {
                    bsflag = "S";
                }
            }
            else if (ord->side == "Subscribe") {
                if (ord->type == "Limit") {
                    bsflag = "1";
                }
            }
            else if (ord->side == "Redeem") {
                if (ord->type == "Limit") {
                    bsflag = "2";
                }
            }
            KCBPCLI_SetValue(handle, "bsflag", bsflag.c_str());
            if (ord->inst.exchange == "SSE") {
                KCBPCLI_SetValue(handle, "market", _SHA.c_str());
                KCBPCLI_SetValue(handle, "secuid", _secuid[_SHA].c_str());
            }
            else if (ord->inst.exchange == "SZSE") {
                KCBPCLI_SetValue(handle, "market", _SZA.c_str());
                KCBPCLI_SetValue(handle, "secuid", _secuid[_SZA].c_str());
            }
            KCBPCLI_SetValue(handle, "stkcode", ord->inst.symbol.c_str());
            KCBPCLI_SetValue(handle, "price", DoubleToString(ord->lmtPrice, 10).c_str());
            KCBPCLI_SetValue(handle, "qty", IntToString((int) ord->ordQty).c_str());
            KCBPCLI_SetValue(handle, "ordergroup", "-1");
        }
    }
    catch(std::exception &e){
        ord->text = std::string("Order rejected before send it:") + e.what();
        ord->report.ordStatus = OrderStatus::OSRejected;
        return;
    }
    // execute request
    record_set result;
    try {
        exec_request(handle, program, result);
    }
    catch(std::exception &e){
        ord->text = std::string("Order rejected in sending:") + e.what();
        ord->report.ordStatus = OrderStatus::OSRejected;
        return;
    }
    disconnect_gateway(handle);
    // process answer
    result.show_data();
    //获得委托号
    try {
        ord->ordId = result.get_field_value("ordersno");
    }
    catch(std::exception &e){
        ord->text = std::string("Order rejected after send it:") + e.what();
        ord->report.ordStatus = OrderStatus::OSRejected;
        return;
    }
    //更新状态
    ord->report.ordStatus = OrderStatus::OSPendingNew;
    std::pair<OrderDict::iterator,bool> ret;
    std::unique_lock<std::mutex> lck(_mtx_all_orders);
    ret = _working_orders.insert(std::pair<std::string, OrderPtr>(ord->ordId,ord));
    if (!ret.second) {
        //委托号已经存在,可能出现重复位委托号,覆盖旧的委托
        ord->text = "Replaced an old order with the same ordId.";
        _working_orders[ord->ordId] = ord;
    }
}
示例#10
0
void
XMLTestEnded(const char *testName, const char *suiteName,
          int testResult, time_t endTime, double totalRuntime)
{
	// Log test result
	char *output = XMLOpenElement(resultElementName);
	XMLOutputter(indentLevel++, NO, output);

	switch(testResult) {
		case TEST_RESULT_PASS:
			output = XMLAddContent("passed");
			break;
		case TEST_RESULT_FAILURE:
			output = XMLAddContent("failed");
			break;
		case TEST_RESULT_NO_ASSERT:
			output = XMLAddContent("failed");
			break;
		case TEST_RESULT_SKIPPED:
			output = XMLAddContent("skipped");
			break;
		case TEST_RESULT_KILLED:
			output = XMLAddContent("failed");
			break;
		case TEST_RESULT_SETUP_FAILURE:
			output = XMLAddContent("failed");
			break;
	}
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(resultElementName);
	XMLOutputter(--indentLevel, YES, output);

	// Log description of test result. Why the test failed,
	// if there's some specific reason
	output = XMLOpenElement(resultDescriptionElementName);
	XMLOutputter(indentLevel++, NO, output);

	switch(testResult) {
		case TEST_RESULT_PASS:
		case TEST_RESULT_FAILURE:
		case TEST_RESULT_SKIPPED:
			output = XMLAddContent("");
			break;
		case TEST_RESULT_NO_ASSERT:
			output = XMLAddContent("No assert");
			break;
		case TEST_RESULT_KILLED:
			output = XMLAddContent("Timeout exceeded");
			break;
		case TEST_RESULT_SETUP_FAILURE:
			output = XMLAddContent("Setup failure, couldn't be executed");
			break;
	}
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(resultDescriptionElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log total runtime
	output = XMLOpenElement(endTimeElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(TimestampToString(endTime));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(endTimeElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log total runtime
	output = XMLOpenElement(totalRuntimeElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(DoubleToString(totalRuntime));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(totalRuntimeElementName);
	XMLOutputter(--indentLevel, YES, output);

	output = XMLCloseElement(testElementName);
	XMLOutputter(--indentLevel, YES, output);
}
示例#11
0
void
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
			int testSkippedCount, time_t endTime, double totalRuntime)
{
	// log suite count
	char *output = XMLOpenElement(numSuitesElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(IntToString(suiteCount));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(numSuitesElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log test count
	output = XMLOpenElement(numTestElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(IntToString(testCount));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(numTestElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log passed test count
	output = XMLOpenElement(numPassedTestsElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(IntToString(testPassCount));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(numPassedTestsElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log failed test count
	output = XMLOpenElement(numFailedTestsElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(IntToString(testFailCount));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(numFailedTestsElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log skipped test count
	output = XMLOpenElement(numSkippedTestsElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(IntToString(testSkippedCount));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(numSkippedTestsElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log end tite
	output = XMLOpenElement(endTimeElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(TimestampToString(endTime));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(endTimeElementName);
	XMLOutputter(--indentLevel, YES, output);

	// log total runtime
	output = XMLOpenElement(totalRuntimeElementName);
	XMLOutputter(indentLevel++, NO, output);

	output = XMLAddContent(DoubleToString(totalRuntime));
	XMLOutputter(indentLevel, NO, output);

	output = XMLCloseElement(totalRuntimeElementName);
	XMLOutputter(--indentLevel, YES, output);

	output = XMLCloseDocument(documentRoot);
	XMLOutputter(--indentLevel, YES, output);

	// close the log file
	fclose(logFile);
}
void ViewTspCircuit(TSP_Data &tsp)
{
  ListGraph h;
  ListGraph::NodeMap<string> h_vname(h);  // node names
  ListGraph::NodeMap<Node> h_g2h(tsp.g);  // maps a node of g to a node of h
  ListGraph::NodeMap<double> h_posx(h);
  ListGraph::NodeMap<double> h_posy(h);
  ListGraph::NodeMap<int> vcolor(h);   // color of the vertices
  ListGraph::EdgeMap<int> acolor(h);  // color of edges
  ListGraph::EdgeMap<string> aname(h);  // name of edges
  for (ListGraph::NodeIt v(tsp.g); v!=INVALID; ++v) {
    Node hv;
    hv = h.addNode();
    h_g2h[v] = hv;
    h_posx[hv] = tsp.posx[v];
    h_posy[hv] = tsp.posy[v];
    h_vname[hv] = tsp.vname[v];
    vcolor[hv] = BLUE;
  }
  for (int i=0;i<tsp.NNodes;i+=2) {
    ListGraph::Node u,v;
    ListGraph::Edge a;
    u = tsp.BestCircuit[i]; 
    v = tsp.BestCircuit[(i+1)]; 
    a = h.addEdge(h_g2h[u] , h_g2h[v]);
    aname[a] = "";
    acolor[a] = BLUE;
  }
  ViewListGraph(h,h_vname,aname,h_posx,h_posy,vcolor,acolor," Emperalhamento Perfeito maxímo "+DoubleToString(tsp.BestCircuitValue));
}
示例#13
0
//-----------------------------------------------------------------------------
/// Write a DX12-specific APITrace response line into the incoming string stream.
/// \param out The stringstream instance that each trace response line is written to.
/// \param inStartTime The start time for the API call.
/// \param inEndTime The end time for the API call.
//-----------------------------------------------------------------------------
void DX12APIEntry::AppendAPITraceLine(gtASCIIString& out, double inStartTime, double inEndTime) const
{
    gtASCIIString returnValueString;
    PrintReturnValue(mReturnValue, mReturnValueFlags, returnValueString);

    // Use the database processor to get a pointer to the object database.
    DX12ObjectDatabaseProcessor* databaseProcessor = DX12ObjectDatabaseProcessor::Instance();
    DX12WrappedObjectDatabase* objectDatabase = static_cast<DX12WrappedObjectDatabase*>(databaseProcessor->GetObjectDatabase());

    // Use the object database to retrieve wrapper info for the given interface.
    IDX12InstanceBase* wrapperInfo = objectDatabase->GetMetadataObject(mWrapperInterface);

    // APIType APIFunctionId InterfacePtr D3D12Interface_FunctionName(Parameters) = ReturnValue StartMillisecond EndMillisecond SampleId
    void* handle = nullptr;
    const char* type = "\0";
    const char* parameters = GetParameterString();

    if (wrapperInfo)
    {
        handle = wrapperInfo->GetApplicationHandle();
        type = wrapperInfo->GetTypeAsString();
    }
    else
    {
        // if there's no wrapper, it's a Present call.
        // Assume type is a swap chain until the Present call is wrapped properly
        type = "IDXGISwapChain";
    }

    out += IntToString(DX12TraceAnalyzerLayer::Instance()->GetAPIGroupFromAPI(mFunctionId));
    out += " ";

    out += IntToString(mFunctionId);
    out += " ";

    out += "0x";
    out += UINT64ToHexString((UINT64)handle);
    out += " ";

    out += type;
    out += "_";

    out += GetAPIName();

    out += "(";
    out += parameters;
    out += ") = ";

    out += returnValueString.asCharArray();

    out += " ";
    out += DoubleToString(inStartTime);

    out += " ";
    out += DoubleToString(inEndTime);

    out += " ";
    out += UINT64ToString(mSampleId);

    out += "\n";
}