inline sU8 *allocate(sU32 id, sU32 size) { sInt pos; while ((pos = findAllocationSpace(size)) == -1) { handleList::reverse_iterator it; for (it = m_accesses.rbegin(); it != m_accesses.rend(); it++) { bufferInfo& inf = m_buffers[*it]; if (inf.ptr && inf.locks == 0) { freeMemoryOf(inf); tidyUp(); break; } } if (it == m_accesses.rend()) // nothing found? this is fatal, but print some info first { fr::debugOut("poolBufferMemoryManager::<internal>::allocate failed. stats dump:\n"); fr::debugOut("buffers:\n"); sInt bufCount=0; for (sUInt bind = 0; bind < m_buffers.size(); ++bind) { if (m_buffers[bind].size != sU32(-1)) fr::debugOut(" %4d. id=%d, size=%d, ptr=%08x, %d locks\n", ++bufCount, bind, m_buffers[bind].size, m_buffers[bind].ptr, m_buffers[bind].locks); else fr::debugOut(" xxxx. free id %d\n", bind); } fr::debugOut("\nallocs:\n"); for (allocVectorCIt it = m_allocations.begin(); it != m_allocations.end(); ++it) fr::debugOut(" start=%d size=%d buffer=%d\n", it->start, it->len, it->id); fr::errorExit("poolBufferMemoryManager::<internal>::allocate failed! (buf %d, size %d)", id, size); } } addAllocation(pos, size, id); return m_pool + pos; }
void App::OnPaint() { sInt time = sGetTimeMS(); sTargetPara tp(sTAR_ClearAll,0xff405060,Screen); sViewport view; Context->BeginTarget(tp); view.Mode = sVM_Pixels; view.Prepare(tp); cbv0->Map(); cbv0->Data->Set(view); cbv0->Unmap(); // draw sInt vc = 0; Vertex *vp; Geo->VB(0)->MapBuffer(&vp,sRMM_Discard); for(auto &cl : Clicks) { sF32 f = 1.0f-(time-cl.Time)*0.002f; sF32 s = 50.0f*(1-f); sF32 x = sF32(cl.ScreenX); sF32 y = sF32(cl.ScreenY); if(vc+3<=MaxVertex && f>0) { if(!cl.Make) s *= -1; sU32 col = cl.Color; col += (sU32(f*255)<<24); vp[vc+0].Init(x-s,y-s*0.5f,0.5f,col); vp[vc+1].Init(x+s,y-s*0.5f,0.5f,col); vp[vc+2].Init(x ,y+s ,0.5f,col); vc += 3; } else { cl.Color = 0; } } if(DragActive) { sU32 col = 0xffffffff; sFRect r; r.Init(sF32(StartX),sF32(StartY),sF32(EndX),sF32(EndY)); sVector2 tn = sNormalize(sVector2(r.SizeY(),-r.SizeX())); vp[vc+0].Init(r.x0+tn.x,r.y0+tn.y,0.5f,col); // 00 vp[vc+1].Init(r.x0-tn.x,r.y0-tn.y,0.5f,col); // 01 vp[vc+2].Init(r.x1-tn.x,r.y1-tn.y,0.5f,col); // 11 vp[vc+3].Init(r.x0+tn.x,r.y0+tn.y,0.5f,col); // 00 vp[vc+4].Init(r.x1-tn.x,r.y1-tn.y,0.5f,col); // 11 vp[vc+5].Init(r.x1+tn.x,r.y1+tn.y,0.5f,col); // 10 vc+=6; } Geo->VB(0)->Unmap(); if(vc>0) { sDrawPara dp(Geo,Mtrl,cbv0); sDrawRange dr; dr.Start = 0; dr.End = vc; dp.Flags |= sDF_Ranges; dp.RangeCount = 1; dp.Ranges = &dr; Context->Draw(dp); } // remove unused clicks sInt max = Clicks.GetCount(); for(sInt i=0; i<max;) { if(Clicks[i].Color == 0) Clicks[i] = Clicks[--max]; else i++; } Clicks.SetSize(max); // debug DPaint->PrintFPS(); DPaint->PrintStats(); DPaint->Draw(tp); Context->EndTarget(); }
void TestFormat() { sCheckModule(L"String Formatting"); // some tests fail because of inaccuracy and rounding for float output! sString<64> str; sString<64> a; sString<6> five; a = L"123"; sSPrintF(str,L"|%x|",0xabc); CHECK(str==L"|abc|"); sSPrintF(str,L"|%x|",-0xabc); CHECK(str==L"|-abc|"); sSPrintF(str,L"|%x|",sU32(-0xabc)); CHECK(str==L"|fffff544|"); sSPrintF(str,L"|%d|",123); CHECK(str==L"|123|"); sSPrintF(str,L"|%d|",-123); CHECK(str==L"|-123|"); sSPrintF(str,L"|%_|",3); CHECK(str==L"| |"); sSPrintF(str,L"|%x|",sU64(0x0123456789abcdefULL)); CHECK(str==L"|123456789abcdef|"); sSPrintF(str,L"|%x|",sS64(0x0123456789abcdefULL)); CHECK(str==L"|123456789abcdef|"); sSPrintF(str,L"|%x|",sS64(-0x0123456789abcdefLL)); CHECK(str==L"|-123456789abcdef|"); sSPrintF(str,L"|%d|",sU64(1234567812345678ULL)); CHECK(str==L"|1234567812345678|"); sSPrintF(str,L"|%d|",sS64(1234567812345678ULL)); CHECK(str==L"|1234567812345678|"); sSPrintF(str,L"|%d|",sS64(-1234567812345678LL)); CHECK(str==L"|-1234567812345678|"); sSPrintF(str,L"|%6d|",123); CHECK(str==L"| 123|"); sSPrintF(str,L"|%6d|",-123); CHECK(str==L"| -123|"); sSPrintF(str,L"|%06d|",123); CHECK(str==L"|000123|"); sSPrintF(str,L"|%06d|",-123); CHECK(str==L"|-00123|"); sSPrintF(str,L"|%-6d|",123); CHECK(str==L"|123 |"); sSPrintF(str,L"|%-6d|",-123); CHECK(str==L"|-123 |"); sSPrintF(str,L"|%-06d|",123); CHECK(str==L"|000123|"); sSPrintF(str,L"|%-06d|",-123); CHECK(str==L"|-00123|"); sSPrintF(str,L"|%5.2r|",1 ); CHECK(str==L"| 0.01|"); sSPrintF(str,L"|%5.2r|",12 ); CHECK(str==L"| 0.12|"); sSPrintF(str,L"|%5.2r|",123 ); CHECK(str==L"| 1.23|"); sSPrintF(str,L"|%5.2r|",1234); CHECK(str==L"|12.34|"); sSPrintF(str,L"|%05.2r|",1 ); CHECK(str==L"|00.01|"); sSPrintF(str,L"|%05.2r|",12 ); CHECK(str==L"|00.12|"); sSPrintF(str,L"|%05.2r|",123 ); CHECK(str==L"|01.23|"); sSPrintF(str,L"|%05.2r|",1234); CHECK(str==L"|12.34|"); sSPrintF(str,L"|%.2r|",1 ); CHECK(str==L"|0.01|"); sSPrintF(str,L"|%.2r|",12 ); CHECK(str==L"|0.12|"); sSPrintF(str,L"|%.2r|",123 ); CHECK(str==L"|1.23|"); sSPrintF(str,L"|%.2r|",1234); CHECK(str==L"|12.34|"); sSPrintF(str,L"|%8.3f|",12.3f); CHECK(str==L"| 12.300|"); sSPrintF(str,L"|%8.3f|",-12.3f); CHECK(str==L"| -12.300|"); sSPrintF(str,L"|%8.3f|",0.123f); CHECK(str==L"| 0.123|"); sSPrintF(str,L"|%8.3f|",123.0f); CHECK(str==L"| 123.000|"); // sSPrintF(str,L"|%24.8f|",12.3456f ); CHECK(str==L"| 12.34560000|"); // sSPrintF(str,L"|%24.8f|",12.3456789f); CHECK(str==L"| 12.34567890|"); // sSPrintF(str,L"|%24.8f|",12.3f); CHECK(str==L"| 12.30000000|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.004f,1.004f); CHECK(str==L"| 1.00| 1.0040|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.005f,1.005f); CHECK(str==L"| 1.01| 1.0050|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.006f,1.006f); CHECK(str==L"| 1.01| 1.0060|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.009f,1.009f); CHECK(str==L"| 1.01| 1.0090|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.010f,1.010f); CHECK(str==L"| 1.01| 1.0100|"); sSPrintF(str,L"|%8.2f|%8.4f|",1.011f,1.011f); CHECK(str==L"| 1.01| 1.0110|"); sSPrintF(str,L"|%8f|",12.345f); CHECK(str==L"|12.34500|"); sSPrintF(str,L"|%6f|",12.345f); CHECK(str==L"|12.345|"); sSPrintF(str,L"|%5f|",12.345f); CHECK(str==L"|12.35|"); sSPrintF(str,L"|%8f|",-12.34f); CHECK(str==L"|-12.3400|"); sSPrintF(str,L"|%6f|",-12.34f); CHECK(str==L"|-12.34|"); sSPrintF(str,L"|%5f|",-12.34f); CHECK(str==L"|-12.3|"); sSPrintF(str,L"|%8.3f|",64.0f); CHECK(str==L"| 64.000|"); sSPrintF(str,L"|%8.3f|",99.0f-0.0001f); CHECK(str==L"| 99.000|"); sSPrintF(str,L"|%8.3f|",100.0f-0.0001f); CHECK(str==L"| 100.000|"); sSPrintF(str,L"|%5f|",100000.0f); CHECK(str==L"|100000|"); sSPrintF(str,L"|%5f|",10000.0f); CHECK(str==L"|10000|"); sSPrintF(str,L"|%5f|",1000.0f); CHECK(str==L"| 1000|"); sSPrintF(str,L"|%5f|",100.0f); CHECK(str==L"|100.0|"); sSPrintF(str,L"|%5f|",10.0f); CHECK(str==L"|10.00|"); sSPrintF(str,L"|%5f|",1.0f); CHECK(str==L"|1.000|"); sSPrintF(str,L"|%5f|",0.1f); CHECK(str==L"|0.100|"); sSPrintF(str,L"|%5f|",0.01f); CHECK(str==L"|0.010|"); sSPrintF(str,L"|%5f|",0.001f); CHECK(str==L"|0.001|"); sSPrintF(str,L"|%5f|",0.0001f); CHECK(str==L"|0.000|"); sSPrintF(str,L"|%5f|",0.00001f); CHECK(str==L"|0.000|"); sSPrintF(str,L"|%5f|",0.000001f); CHECK(str==L"|0.000|"); sSPrintF(str,L"|%5.2f|",100000.0f); CHECK(str==L"|100000.00|"); sSPrintF(str,L"|%5.2f|",10000.0f); CHECK(str==L"|10000.00|"); sSPrintF(str,L"|%5.2f|",1000.0f); CHECK(str==L"|1000.00|"); sSPrintF(str,L"|%5.2f|",100.0f); CHECK(str==L"|100.00|"); sSPrintF(str,L"|%5.2f|",10.0f); CHECK(str==L"|10.00|"); sSPrintF(str,L"|%5.2f|",1.0f); CHECK(str==L"| 1.00|"); sSPrintF(str,L"|%5.2f|",0.1f); CHECK(str==L"| 0.10|"); sSPrintF(str,L"|%5.2f|",0.01f); CHECK(str==L"| 0.01|"); sSPrintF(str,L"|%5.2f|",0.001f); CHECK(str==L"| 0.00|"); sSPrintF(str,L"|%s|",L"abc"); CHECK(str==L"|abc|"); sSPrintF(str,L"|%6s|",L"abc"); CHECK(str==L"| abc|"); sSPrintF(str,L"|%-6s|",L"abc"); CHECK(str==L"|abc |"); sSPrintF(str,L"|%s|",a); CHECK(str==L"|123|"); sSPrintF(str,L"|%6s|",a); CHECK(str==L"| 123|"); sSPrintF(str,L"|%-6s|",a); CHECK(str==L"|123 |"); sVector30 v30; v30.Init(1.42f,1.52f,1.25f); sVector31 v31; v31.Init(1.42f,1.52f,1.25f); sVector4 v4; v4 .Init(1.42f,1.52f,1.25f,1.26f); sSPrintF(str,L"|%6.3f|",v30); CHECK(str==L"|[ 1.420, 1.520, 1.250,0]|"); sSPrintF(str,L"|%6.3f|",v31); CHECK(str==L"|[ 1.420, 1.520, 1.250,1]|"); sSPrintF(str,L"|%6.3f|",v4); CHECK(str==L"|[ 1.420, 1.520, 1.250, 1.260]|"); // buffer overflow tests five.PrintF(L"abcd"); CHECK(five==L"abcd"); five.PrintF(L"abcde"); CHECK(five==L"abcde"); five.PrintF(L"abcdef"); CHECK(five==L"abcd?"); five.PrintF(L"a%db",10); CHECK(five==L"a10b"); five.PrintF(L"a%db",100); CHECK(five==L"a100b"); five.PrintF(L"a%db",1000); CHECK(five==L"a100?"); five.PrintF(L"a%db%dc",1,2); CHECK(five==L"a1b2c"); five.PrintF(L"a%db%dc",10,2); CHECK(five==L"a10b?"); five.PrintF(L"a%db%dc",10,20); CHECK(five==L"a10b?"); }
adc eax, 0 mov ecx, [smpldelta] mov [ecx], eax } #else long temp = nexttime - time; temp *= usecs; temp /= td2; long temp2 = *smpldelta; temp2 <<= 32; temp2 |= *smplrem; temp += temp2; *smplrem = sU32( temp & 0xFFFFFFFF ); temp >>= 32L; *smpldelta = sU32( temp ); #endif } } sBool V2MPlayer::InitBase(const void *a_v2m) /////////////////////////////////////// { const sU8 *d=(const sU8*)a_v2m; m_base.timediv=(*((sU32*)(d)));
sBool sMiniFTPClient::ListFiles(const sChar *basepath,sArray<sChar> &listing) { listing.Clear(); if(State == CS_NOTARGET) return sFALSE; for(;;) { if(State != CS_CONNECTED && !TryReconnect(RetryCount)) break; sU8 sizeBuf[8]; if(SendCommand(sMFC_LIST,basepath,0) && ReadAll(sizeBuf,8)) { sSize totalSize; sUnalignedLittleEndianLoad64(sizeBuf,(sU64&) totalSize); if((totalSize & 1) // we expect 16bit chars || totalSize > 16*1024*1024) // 16MB limit for directory listings (for now) return sFALSE; if(!Progress(basepath,0,totalSize,ProgressUser)) return MaybeNextTime(); sFixedArray<sU8> ioBuf((sInt) totalSize); sSize currentPos = 0; while(currentPos < totalSize) { sDInt size = (sDInt) (totalSize-currentPos); sDInt read; if(!Socket.Read(&ioBuf[(sInt) currentPos],size,read) || !read) { MaybeNextTime(); break; } currentPos += read; if(!Progress(basepath,currentPos,totalSize,ProgressUser)) return MaybeNextTime(); } if(currentPos == totalSize) { listing.HintSize(sU32(totalSize/2)); listing.AddMany(sU32(totalSize/2)); for(sInt i=0;i<totalSize/2;i++) { sU16 v; sUnalignedLittleEndianLoad16(&ioBuf[i*2],v); listing[i] = v; } return sTRUE; } } else if(Error == sMFE_OK) MaybeNextTime(); else break; } return sFALSE; }