void sTextControl::Log(sChar *s) { sInt tl,sl,stat; stat = Static; Static = 0; tl = sGetStringLen(Text); sl = sGetStringLen(s); Engine(tl,sl,s); Cursor = tl+sl; ScrollToCursor(); Static = stat; RecalcSize = sTRUE; }
sChar *sGetClipboard() { sChar *result=0; OpenClipboard(sHWND); HANDLE hmem = GetClipboardData(CF_UNICODETEXT); if(hmem) { sChar *s = (sChar *)GlobalLock(hmem); sInt size = sGetStringLen(s)+1; result = new sChar[size]; sInt i = 0; while(*s) { if(*s!='\r') result[i++] = *s; s++; } result[i++] = 0; GlobalUnlock(hmem); } else { result = new sChar[1]; result[0] = 0; } CloseClipboard(); return result; }
void sSetClipboard(const sChar *text,sInt len) { OpenClipboard(sHWND); EmptyClipboard(); if(len==-1) len = sGetStringLen(text); sInt size = len+1; for(sInt i=0;text[i];i++) if(text[i]=='\n') size++; HANDLE hmem = GlobalAlloc(GMEM_MOVEABLE,size*2); sChar *d = (sChar *) GlobalLock(hmem); for(sInt i=0;i<len;i++) { if(text[i]=='\n') *d++ = '\r'; *d++ = text[i]; } *d++ = 0; GlobalUnlock(hmem); SetClipboardData(CF_UNICODETEXT,hmem); CloseClipboard(); }
void sFont2D::PrintBasic(sInt flags,const sRect *r,sInt x,sInt y,const sChar *text,sInt len) { UINT opt; if(len==-1) len=sGetStringLen(text); opt = 0; if(r) { opt |= ETO_CLIPPED; } if((flags & sF2P_OPAQUE) && r) { SetBkColor(sGDIDC,prv->BackColor); opt |= ETO_OPAQUE; SetBkMode(sGDIDC,OPAQUE); } else { SetBkMode(sGDIDC,TRANSPARENT); } SetTextColor(sGDIDC,prv->TextColor); SelectObject(sGDIDC,prv->Font); ExtTextOutW(sGDIDC,x,y,opt,(CONST RECT *)r,text,len,0); }
sInt sFont2D::GetWidth(const sChar *text,sInt len) { SIZE out; if(len==-1) len=sGetStringLen(text); if(len==0) return 0; SelectObject(sGDIDCOffscreen,prv->Font); GetTextExtentPoint32W(sGDIDCOffscreen,text,len,&out); sInt width = out.cx; if(1) // exact calculation, usefull for italics { sInt abcC; sInt ch = text[len-1]; if(ch < NUMABC) abcC = prv->Widths[ch].abcC; else { ABC abc; GetCharABCWidths(sGDIDCOffscreen,ch,ch,&abc); abcC = abc.abcC; } if(abcC<0) width -= abcC; } return width; }
// helpers static sChar *BStrToString( BSTR str, sChar *defString = "", bool stripWhitespace = false ) { if(!str) { sInt len = sGetStringLen(defString); sChar *buffer = new sChar[len+1]; sCopyString(buffer,defString,len+1); return buffer; } else { sInt len = SysStringLen(str); sChar *buffer = new sChar[len+1]; sInt j = 0; for( sInt i=0;i<len;i++ ) { if( stripWhitespace && isspace(str[i]) ) continue; buffer[j] = (str[i] >= 32 && str[i] < 128) ? str[i] : '?'; ++j; } buffer[j] = 0; return buffer; } }
sInt sTextControl::ClickToPos(sInt mx,sInt my) { sInt i,j,x,y,h,pos; h = sPainter->GetHeight(sGui->FixedFont); y = Client.y0+2; x = Client.x0+2; pos = 0; for(;;) { i = 0; while(Text[pos+i]!=0 && Text[pos+i]!='\n') i++; if(my<y+h) { for(j=1;j<i;j++) { if(mx<Client.x0+2+sPainter->GetWidth(sGui->FixedFont,Text+pos,j)) return pos+j-1; } return pos+i; } y+=h; pos+=i; if(Text[pos]==0) break; if(Text[pos]=='\n') pos++; } return sGetStringLen(Text); }
void sSystem_::PrintF(sChar *format,...) { sChar buffer[2048]; DWORD written; sFormatString(buffer,2048,format,&format); WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),buffer, sGetStringLen(buffer),&written,0); }
sInt sFont2D::GetAdvance(const sChar *text,sInt len) { SIZE out; if(len==-1) len=sGetStringLen(text); SelectObject(sGDIDCOffscreen,prv->Font); GetTextExtentPoint32W(sGDIDCOffscreen,text,len,&out); return out.cx; }
void sBrowserApp::GetPath(sChar *buffer,sInt size) { sInt i; GetDirName(buffer,size); i = sGetStringLen(buffer); buffer+=i; *buffer++ = '/'; size-=i+1; GetFileName(buffer,size); if(*buffer==0) buffer[-1] = 0; }
void sTextControl::SetSelection(sInt cursor,sInt sel) { sInt len; len = sGetStringLen(Text); if(cursor>=0 && sel>=0 && cursor<=len && sel<=len) { Cursor = cursor; SelPos = sel; SelMode = 1; ScrollToCursor(); } }
sInt sFont2D::GetCharCountFromWidth(sInt width,const sChar *text,sInt len) { SIZE out; INT count; if(width<0) return 0; if(len==-1) len=sGetStringLen(text); SelectObject(sGDIDCOffscreen,prv->Font); GetTextExtentExPointW(sGDIDCOffscreen,text,len,width,&count,0,&out); return count; }
sBool sFileWindow::ChangeExtension(sChar *path,sChar *newext) { sInt len,pos,i; GetPath(path,sDI_PATHSIZE); len = sGetStringLen(path); pos = len; for(i=0;i<len;i++) if(path[i]=='.') pos = i; path[pos] = 0; sAppendString(path,newext,sDI_PATHSIZE); return sTRUE; }
void sSetClipboard(const sChar *text,sInt len) { if(len==-1) len=sGetStringLen(text); char *dest = new char[(len*4)+1]; sU32 *convBuffer = new sU32[len+1]; for(sInt i=0;i<len;i++) // fake-wchar16-to-wchar32 (argh!) convBuffer[i] = text[i]; convBuffer[len] = 0; wcstombs(dest,(wchar_t *)convBuffer,len*4+1); dest[len*4] = 0; XStoreBytes(sXDisplay(),dest,strlen(dest)); delete[] dest; delete[] convBuffer; }
void sBasicPainter::Print(sInt /*fontid*/,sF32 x,sF32 y,sU32 col,const sChar *text,sInt len,sF32 zoom) { sVertexSingle *vp; if(len==-1) len = sGetStringLen(text); if(!len) return; #if sCONFIG_QUADRICS Geo->BeginQuad((void **)&vp,len); #else vp = Vertices + Used*4; len = sMin(len,Alloc-Used); Used += len; #endif for(sInt i=0;i<len;i++) { sInt c = text[i]; sInt u = (c&15)*8; sInt v = (c/16)*8; #if sRENDERER==sRENDER_DX9 || sRENDERER==sRENDER_DX11 sF32 uvo = UVOffset; sF32 xyo = XYOffset; #else sF32 uvo = 0.0f; sF32 xyo = 0.0f; #endif sFRect r(x+xyo,y+xyo,x+xyo+6*zoom,y+xyo+8*zoom); sFRect uv((u+uvo)/128.0f,(v+uvo)/128.0f,(u+6+uvo)/128.0f,(v+8+uvo)/128.0f); vp[0].Init(r.x0,r.y0,0,col,uv.x0,uv.y0); vp[1].Init(r.x1,r.y0,0,col,uv.x1,uv.y0); vp[2].Init(r.x1,r.y1,0,col,uv.x1,uv.y1); vp[3].Init(r.x0,r.y1,0,col,uv.x0,uv.y1); vp+=4; x+=6*zoom; } #if sCONFIG_QUADRICS Geo->EndQuad(); #endif }
void sTextControl::SetText(sChar *t) { sChar *d; Realloc(sGetStringLen(t)+1); d = Text; while(*t) { if(*t!='\r') *d++ = *t; t++; } *d++ = 0; Cursor = 0; SelPos = 0; SelMode = 0; OnCalcSize(); }
sBool sMiniFTPClient::SendCommand(sInt command,const sChar *filename,sSize extra) { static const sInt maxFilenameLen = 1024; sVERIFY(filename != 0); Error = sMFE_OK; sInt filenameLen = sGetStringLen(filename); sVERIFY(filenameLen < maxFilenameLen); sVERIFYSTATIC(sizeof(sChar) == 2); sU8 header[16]; sUnalignedLittleEndianStore32(header+ 0,command); sUnalignedLittleEndianStore32(header+ 4,filenameLen); sUnalignedLittleEndianStore64(header+ 8,extra); if(!WriteAll(header,16)) return sFALSE; sU8 *stringBuf = (sU8*) sALLOCSTACK(sChar,filenameLen*2); for(sInt i=0;i<filenameLen;i++) sUnalignedLittleEndianStore16(stringBuf + i*2,filename[i]); if(!WriteAll(stringBuf,filenameLen*2)) return sFALSE; // read answer code sU8 answer; if(!ReadAll(&answer,1)) return sFALSE; if(answer == sMFE_OK) // no error return sTRUE; else { Error = (sMiniFTPError) answer; return sFALSE; } }
// helpers static sChar *BStrToString(BSTR str,sChar *defString="") { if(!str) { sInt len = sGetStringLen(defString); sChar *buffer = new sChar[len+1]; sCopyString(buffer,defString,len+1); return buffer; } else { sInt len = SysStringLen(str); sChar *buffer = new sChar[len+1]; for(sInt i=0; i<len; i++) buffer[i] = (str[i] >= 32 && str[i] < 128) ? str[i] : '?'; buffer[len] = 0; return buffer; } }
void sTextControl::Engine(sInt pos,sInt count,sChar *insert) { sInt len; sInt i; if(Static) return; Post(DoneCmd); Changed = 1; len = sGetStringLen(Text); if(insert) { Realloc(len+count+1); for(i=len;i>=pos;i--) Text[i+count] = Text[i]; sCopyMem(Text+pos,insert,count); } else { if(pos+count<=len) sCopyMem(Text+pos,Text+pos+count,len-pos-count+1); } }
void sDiskItem::SetString(sInt attr,sChar *buffer) { if(sDiskItemTypes[attr][0]==sDIT_STRING && Support(attr)) SetAttr(attr,buffer,sGetStringLen(buffer)+1); }
void sLog(const char *system,const char *msg) { sDPrintF("[%s]%_%s\n",system,10-sGetStringLen(system),msg); }
sBool wDocument::HlslType() { if(Scan->Token!=sTOK_Name) return 0; // already known type? for(auto &pstr : Typenames) { if(pstr == Scan->Name) { OutPtr->PrintF("%s",Scan->Name); Scan->Scan(); return 1; } } if(Scan->IfToken(TokMatrix)) { Scan->Match('<'); OutPtr->Print("matrix<"); HlslType(); Scan->Match(','); OutPtr->PrintF(",%d",Scan->ScanInt()); Scan->Match(','); OutPtr->PrintF(",%d>",Scan->ScanInt()); Scan->Match('>'); return 1; } if(Scan->IfToken(TokVector)) { Scan->Match('<'); OutPtr->Print("vector"); HlslType(); Scan->Match(','); OutPtr->PrintF(",%d>",Scan->ScanInt()); Scan->Match('>'); return 1; } // parse normal type. sBool ok = 0; if(Scan->IfName("snorm")) { ok = 1; OutPtr->Print("snorm "); } else if(Scan->IfName("unorm")) { ok = 1; OutPtr->Print("unorm "); } if(Scan->Token!=sTOK_Name) return ok; sString<64> buffer = (const sChar *) Scan->Name; sInt len = sGetStringLen(buffer); if(len>1 && buffer[len-1]>='1' && buffer[len-1]<='4') { len--; if(len>2 && buffer[len-1]=='x' && buffer[len-2]>='1' && buffer[len-2]<='4') len-=2; buffer[len] = 0; } const sChar *typenames[] = { "void","bool","int","uint","float","double", "min16float","min10float","min16int","min12int","min16uint", "TriangleStream","LineStream","PointStream","InputPatch","OutputPatch", }; sBool found = 0; for(sInt i=0;i<sCOUNTOF(typenames) && !found;i++) if(sCmpString(typenames[i],buffer)==0) found = 1; if(!found) return ok; OutPtr->Print(Scan->Name); Scan->Scan(); HlslTemplateArgs(); return 1; }
sBool sTextApp::OnCommand(sU32 cmd) { sMenuFrame *mf; sDiskItem *di; sInt len; sChar buffer[sDI_PATHSIZE]; switch(cmd) { case 1: // popup FILE mf = new sMenuFrame; mf->SendTo = Edit; mf->AddBorder(new sNiceBorder); mf->AddMenu("New",sTCC_CLEAR,0); mf->AddMenu("Open...",sTCC_OPEN,0); mf->AddMenu("Save",sTCC_SAVE,0); mf->AddMenu("Save As...",sTCC_SAVEAS,0); mf->AddSpacer(); mf->AddMenu("Browser",12,0); mf->AddMenu("Exit",sTCC_EXIT,0); sGui->AddPulldown(mf); return sTRUE; case 2: // popup EDIT mf = new sMenuFrame; mf->SendTo = Edit; mf->AddBorder(new sNiceBorder); mf->AddMenu("Cut",sTCC_CUT,'x'|sKEYQ_CTRL); mf->AddMenu("Copy",sTCC_COPY,'c'|sKEYQ_CTRL); mf->AddMenu("Paste",sTCC_PASTE,'v'|sKEYQ_CTRL); mf->AddMenu("Mark Block",sTCC_BLOCK,'b'|sKEYQ_CTRL); sGui->AddPulldown(mf); return sTRUE; case 3: // Cancel File Requester if(File) { File->Parent->RemChild(File); File = 0; } return sTRUE; case sTCC_OPEN: if(!File) { File = new sFileWindow; File->AddTitle("Open File"); sGui->AddApp(File); } sGui->SetFocus(File); File->OkCmd = 4; File->CancelCmd = 3; File->SendTo = this; Modal = File; File->SetPath(Edit->PathName); return sTRUE; case 4: if(File) { File->GetPath(buffer,sizeof(buffer)); OnCommand(3); if(!Edit->LoadFile(buffer)) { Edit->SetText(""); (new sDialogWindow)->InitOk(this,"Open File","Load failed",0); } } return sTRUE; case sTCC_CLEAR: Edit->SetText(""); return sTRUE; case sTCC_SAVEAS: if(!File) { File = new sFileWindow; File->AddTitle("Open File"); sGui->AddApp(File); } sGui->SetFocus(File); File->OkCmd = 5; File->CancelCmd = 3; File->SendTo = this; Modal = File; File->SetPath(Edit->PathName); return sTRUE; case 5: if(File) { File->GetPath(Edit->PathName,sizeof(Edit->PathName)); OnCommand(3); OnCommand(sTCC_SAVE); } return sTRUE; case sTCC_SAVE: di = sDiskRoot->Find(Edit->PathName,sDIF_CREATE); if(di) { len = sGetStringLen(Edit->TextBuffer->Text); if(di->SetBinary(sDIA_DATA,(sU8 *)Edit->TextBuffer->Text,len)) { UpdateStatus(); Changed = 0; } else { (new sDialogWindow)->InitOk(this,"Save File","Save failed",0); } } return sTRUE; case 10: UpdateStatus(); return sTRUE; case 11: UpdateStatus(); return sTRUE; case 12: di = sDiskRoot->Find("Programms/Browser"); if(di) di->Cmd(sDIC_EXECUTE,0,0); return sTRUE; case sTCC_EXIT: Parent->RemChild(this); return sTRUE; case sTCC_CUT: Edit->CmdCut(); return sTRUE; case sTCC_COPY: Edit->CmdCopy(); return sTRUE; case sTCC_PASTE: Edit->CmdPaste(); return sTRUE; case sTCC_BLOCK: Edit->CmdBlock(); return sTRUE; default: return sFALSE; } }
sF32 sBasicPainter::GetWidth(sInt /*fontid*/,const sChar *text,sInt len) { if(len==-1) len = sGetStringLen(text); return (sF32)(len*6); }
sBitmap *sLoadBitmap(sChar *name) { sInt len; sChar *ext; sU8 *data,*mem; sInt size; sBitmap *bm; sBool ok; // static sChar jpath[sMAX_PATHNAME]; len = sGetStringLen(name); if(len<4) return 0; ext = name + len - 4; /* if(len<sizeof(jpath)-5 && ext[0]=='.') { sCopyMem(jpath,name,len); sCopyMem(jpath+len-4,".jpg",5); mem = data = sSystem->LoadFile(jpath,size); if(data!=0) { bm = new sBitmap; bm->Init(256,256); if(sSystem->LoadJPG(bm,mem,size)) { bm->CompressedData = data; bm->CompressedSize = size; return bm; } else { delete[] data; } } } */ ok = sTRUE; bm = new sBitmap; mem = data = sSystem->LoadFile(name,size); if(data==0) ok = sFALSE; if(ok && sCmpStringI(ext,".bmp")==0) { BMPHeader *hdr; sInt x,y; sU8 *d,*s; sU8 val; hdr = (BMPHeader *) data; if(hdr->XSize<1 || hdr->YSize<1 || hdr->Planes!=1 || hdr->Magic != 'B'+'M'*256 || hdr->Compression != 0) { ok = sFALSE; } bm->Init(hdr->XSize,hdr->YSize); s = data+hdr->Offset; switch(hdr->BitCount) { case 8: for(y=0;y<bm->YSize;y++) { d = (sU8*)(bm->Data + (bm->YSize-1-y)*bm->XSize); for(x=0;x<bm->XSize;x++) { val = *s++; *d++ = hdr->Color[val]; *d++ = hdr->Color[val]>>8; *d++ = hdr->Color[val]>>16; *d++ = 255; } } break; case 24: for(y=0;y<bm->YSize;y++) { d = (sU8*)(bm->Data + (bm->YSize-1-y)*bm->XSize); for(x=0;x<bm->XSize;x++) { *d++ = s[0]; *d++ = s[1]; *d++ = s[2]; *d++ = 255; s+=3; } } break; default: ok = sFALSE; break; } }
sBool sShaderCompileDX(const sChar *source,const sChar *profile,const sChar *main,sU8 *&data,sInt &size,sInt flags,sTextBuffer *errors) { #if sCOMP_DX9_ENABLE ID3D10Blob *bytecode; ID3D10Blob *dxerrors; sBool result; // unicode -> ansi conversion (cheap) sChar8 profile8[16]; sCopyString(profile8,profile,sCOUNTOF(profile8)); sChar8 main8[256]; sCopyString(main8,main,sCOUNTOF(main8)); sInt len = sGetStringLen(source); sChar8 *src8 = new sChar8[len+1]; sCopyString(src8,source,len+1); // figure out flags UINT flags1 = 0; UINT flags2 = 0; if(flags&sSCF_DEBUG) flags1 |= D3D10_SHADER_DEBUG; //#ifdef D3DXSHADER_USE_LEGACY_D3DX9_31_DLL // if(sGetShellSwitch(L"-d3dold") || sMatchWildcard(L"ps_1_*",profile)) // flags1 |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; //#endif // result = (D3DXCompileShader(src8,len,0,0,main8,profile8,d3dflags,&bytecode,&dxerrors,0)==D3D_OK); result = !FAILED(D3DCompile(src8,len,0,0,0,main8,profile8,flags1,flags2,&bytecode,&dxerrors)); // print errors and warnings // errors->Clear(); // do not clear, this will overwrite old errors if(dxerrors) { sInt elen = dxerrors->GetBufferSize(); const sChar8 *estr = (const sChar8*)dxerrors->GetBufferPointer(); for(sInt i=0;i<elen;i++) if(estr[i]) errors->PrintChar(estr[i]); dxerrors->Release(); } // get bytecode if(bytecode) { size = bytecode->GetBufferSize(); data = new sU8[size]; sCopyMem(data,bytecode->GetBufferPointer(),size); bytecode->Release(); } else { result = 0; data = 0; size = 0; } // done delete[] src8; return result; #else return sFALSE; #endif // sCOMP_DX9_ENABLE }
void wDocument::AscMemberSingle(wAscBuffer *buffer,sBool allowpif) { if(Scan->IfName("pif")) { if(!allowpif) Scan->Error("pifs are not allowed in this type"); Scan->Match('('); wPredicate *pred = _Predicate(); Scan->Match(')'); wPredicate *old = Predicate; Predicate = Combine(pred,old); AscMemberBlock(buffer,allowpif); if(Scan->IfName("pelse")) { Predicate = Combine(Negate(pred),old); AscMemberBlock(buffer,allowpif); } Predicate = old; } else { wAscMember *mem = new wAscMember(); wAscType *type = new wAscType(); moreflags: if(Scan->Token==TokExtern) { Scan->Scan(); mem->Flags |= wMF_Extern; goto moreflags; } if(Scan->Token==TokStatic) { Scan->Scan(); mem->Flags |= wMF_Static; goto moreflags; } if(Scan->Token==TokUniform) { Scan->Scan(); mem->Flags |= wMF_Uniform; goto moreflags; } if(Scan->Token==TokVolatile) { Scan->Scan(); mem->Flags |= wMF_Volatile; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="nointerpolation") { Scan->Scan(); mem->Flags |= wMF_NoInterpolation; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="precise") { Scan->Scan(); mem->Flags |= wMF_Precise; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="groupshared") { Scan->Scan(); mem->Flags |= wMF_GroupShared; goto moreflags; } if(Scan->Token==sTOK_Name && Scan->Name=="shared") { Scan->Scan(); mem->Flags |= wMF_Shared; goto moreflags; } if(Scan->IfName("row_major")) { } else if(Scan->IfName("column_major")) { type->ColumnMajor = 1; } sString<64> tname; Scan->ScanName(tname); sInt len = sGetStringLen(tname); if(len>0 && tname[len-1]>='1' && tname[len-1]<='4') { type->Columns = tname[len-1]-'0'; len--; if(len>1 && tname[len-1]=='x' && tname[len-2]>='1' && tname[len-2]<='4') { type->Rows = tname[len-2]-'0'; len-=2; } tname[len] = 0; } if(tname=="bool") type->Base = wTB_Bool; else if(tname=="int") type->Base = wTB_Int; else if(tname=="uint") type->Base = wTB_UInt; else if(tname=="float") type->Base = wTB_Float; else if(tname=="double") type->Base = wTB_Double; else if(tname=="min16float") type->Base = wTB_Min16Float; else if(tname=="min10float") type->Base = wTB_Min10Float; else if(tname=="min16int") type->Base = wTB_Min16Int; else if(tname=="min12int") type->Base = wTB_Min12Int; else if(tname=="min16uint") type->Base = wTB_Min16UInt; else Scan->Error("unknown type %q",tname); mem->Name = Scan->ScanName(); mem->Type = type; mem->Predicate = Predicate; if(Scan->IfToken('[')) { type->Array = Scan->ScanInt(); Scan->Match(']'); } if(Scan->IfToken(':')) mem->Binding = Scan->ScanName(); Scan->Match(';'); buffer->Members.AddTail(mem); } }
void sXSILoader::ScanMesh(sInt indent,sXSIModel *model) { sChar buffer[256]; sChar chunk[XSISIZE]; sChar name[XSISIZE]; sChar *cmd; sInt supports,i,j,k,max; sInt fcount; sInt vcount; sXSICluster *cluster; sInt cr,cg,cb,ca; sInt set,set2; sInt PosCount; sVector *Pos; sInt NormCount; sVector *Norm; sInt ColorCount; sU32 *Color; sInt UVCount[sXSI_MAXUV]; sF32 *UV[sXSI_MAXUV]; sChar UVName[sXSI_MAXUV][XSISIZE]; // init shape holder PosCount = 0; Pos = 0; NormCount = 0; Norm = 0; ColorCount = 0; Color = 0; for(i=0;i<sXSI_MAXUV;i++) { UVCount[i] = 0; UV[i] = 0; } while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent,chunk,name); if(sCmpString(chunk,"SI_Shape")==0) { supports = ScanInt(); ScanString(buffer,sizeof(buffer)); if(sCmpString(buffer,"ORDERED")!=0) Error = sTRUE; for(i=0;i<supports && !Error;i++) { max = ScanInt(); ScanString(buffer,sizeof(buffer)); if(sCmpString(buffer,"POSITION")==0) { sVERIFY(Pos==0); PosCount = max; Pos = new sVector[max]; for(j=0;j<max;j++) { Pos[j].x = ScanFloat(); Pos[j].y = ScanFloat(); Pos[j].z = ScanFloat(); } } else if(sCmpString(buffer,"NORMAL")==0) { sVERIFY(Norm==0); NormCount = max; Norm = new sVector[max]; for(j=0;j<max;j++) { Norm[j].x = ScanFloat(); Norm[j].y = ScanFloat(); Norm[j].z = ScanFloat(); } } else if(sCmpString(buffer,"COLOR")==0) { sVERIFY(Color==0); ColorCount = max; Color = new sU32[max]; for(j=0;j<max;j++) { cr = sRange<sInt>(ScanFloat()*255,255,0); cg = sRange<sInt>(ScanFloat()*255,255,0); cb = sRange<sInt>(ScanFloat()*255,255,0); ca = sRange<sInt>(ScanFloat()*256,255,0); Color[j] = (ca<<24)|(cb<<16)|(cg<<8)|(cr); } } else if(sCmpString(buffer,"TEX_COORD_UV")==0) { set = 0; sVERIFY(UV[set]==0); UVCount[set] = max; UV[set] = new sF32[max*2]; for(j=0;j<max;j++) { UV[set][j*2+0] = ScanFloat(); UV[set][j*2+1] = 1.0f-ScanFloat(); } } else if(sCmpMem(buffer,"TEX_COORD_UV",12)==0) { j=12; set = 0; while(buffer[j]>='0' && buffer[j]<='9') set = set*10 + (buffer[j++]-'0'); sVERIFY(set>=0 && set<sXSI_MAXUV); sVERIFY(UV[set]==0); ScanString(UVName[set],sizeof(UVName[set])); UVCount[set] = max; UV[set] = new sF32[max*2]; for(j=0;j<max;j++) { UV[set][j*2+0] = ScanFloat(); UV[set][j*2+1] = 1.0f-ScanFloat(); } } else { Error = sTRUE; } } EndChunk(); } else if(sCmpString(chunk,"SI_PolygonList")==0) { cluster = new sXSICluster; fcount = ScanInt(); sCopyString(buffer,"|POSITION|",sizeof(buffer)); i = sGetStringLen(buffer); ScanString(buffer+i,sizeof(buffer)-i); #if DUMPCHUNK sDPrintF(" %s",buffer); #endif ScanString(name,sizeof(name)); cluster->Material = FindMaterial(name); vcount = ScanInt(); cluster->VertexCount = vcount; cluster->IndexCount = vcount; cluster->Vertices = new sXSIVertex[vcount]; cluster->Faces = new sInt[vcount*2]; model->Clusters->Add(cluster); j = 0; for(i=0;i<fcount;i++) { max = ScanInt(); cluster->Vertices[j].Init(); cluster->Faces[j*2+0] = max; cluster->Faces[j*2+1] = j; j++; for(k=1;k<max;k++) { cluster->Vertices[j].Init(); cluster->Faces[j*2+0] = 0; cluster->Faces[j*2+1] = j; j++; } } sVERIFY(j==vcount); cmd = buffer; while(!Error && *cmd) { if(sCmpMem(cmd,"|POSITION",9)==0) { cmd+=9; sVERIFY(Pos); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Pos = Pos[j]; cluster->Vertices[i].Index = j; } } else if(sCmpMem(cmd,"|NORMAL",7)==0) { cmd+=7; sVERIFY(Norm); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Normal = Norm[j]; cluster->Vertices[i].Normal.Init(0,0,0,1); } } else if(sCmpMem(cmd,"|COLOR",6)==0) { cmd+=6; sVERIFY(Color); for(i=0;i<vcount;i++) { j = ScanInt(); cluster->Vertices[i].Color = Color[j]; } } else if(sCmpMem(cmd,"|TEX_COORD_UV",13)==0) { cmd+=13; set = 0; if(*cmd>='0' && *cmd<='9') { while(*cmd>='0' && *cmd<='9') set = set*10 + ((*cmd++)-'0'); sVERIFY(set>=0 && set<sXSI_MAXUV); sVERIFY(UV[set]) for(set2=0;set2<4;set2++) if(sCmpString(TSName[cluster->Material->TUV[set2]],UVName[set])==0) break; } else { set2 = 0; } for(i=0;i<vcount;i++) { j = ScanInt(); if(set2>=0 && set2<2) { cluster->Vertices[i].UV[set2][0] = 0.0f;// UV[set][j*2+0]; cluster->Vertices[i].UV[set2][1] = 0.0f;// UV[set][j*2+1]; } } } else {
sChar *DebugInfo::WriteReport() { sChar *Report; sInt i,j; sU32 size; sF32 pSize; Report = ReportBuffer; sSPrintF(Report,512,sAPPNAME " " sVERSION " >> pack ratio report\n\n"); Report += sGetStringLen(Report); sSPrintF(Report,512,"Functions by packed size:\n"); Report += sGetStringLen(Report); std::sort(&Symbols[0],&Symbols[Symbols.Count],symPackedSizeComp); for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nData by packed size:\n"); Report += sGetStringLen(Report); for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_DATA) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nFunctions by object file and packed size:\n"); Report += sGetStringLen(Report); for(i=1;i<Symbols.Count;i++) for(j=i;j>0;j--) { sInt f1 = Symbols[j].FileNum; sInt f2 = Symbols[j-1].FileNum; if(f1 == -1 || f2 != -1 && sCmpStringI(Files[f1].Name.String,Files[f2].Name.String) < 0) sSwap(Symbols[j],Symbols[j-1]); } for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { sSPrintF(Report,512,"%5d.%02d/%8d: %-50s %s\n", (sInt) Symbols[i].PackedSize,sInt(Symbols[i].PackedSize*100)%100, Symbols[i].Size,Symbols[i].Name,Files[Symbols[i].FileNum].Name); Report += sGetStringLen(Report); } } sSPrintF(Report,512,"\nClasses/Namespaces by packed size:\n"); Report += sGetStringLen(Report); std::sort(&NameSps[0],&NameSps[NameSps.Count],namePackedSizeComp); for(i=0;i<NameSps.Count;i++) { sSPrintF(Report,512,"%5d.%02d/%8d: %s\n",sInt(NameSps[i].PackedSize), sInt(NameSps[i].PackedSize*100)%100,NameSps[i].Size,NameSps[i].Name); Report += sGetStringLen(Report); } sSPrintF(Report,512,"\nObject files by packed size:\n"); Report += sGetStringLen(Report); std::sort(&Files[0],&Files[Files.Count],filePackedSizeComp); for(i=0;i<Files.Count;i++) { sSPrintF(Report,512,"%5d.%02d/%8d: %s\n",sInt(Files[i].PackedSize), sInt(Files[i].PackedSize*100)%100,Files[i].Size,Files[i].Name); Report += sGetStringLen(Report); } size = 0; pSize = 0.0f; for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_CODE) { size += Symbols[i].Size; pSize += Symbols[i].PackedSize; } } sSPrintF(Report,512,"\nOverall code: %5d.%02d/%8d\n",sInt(pSize), sInt(pSize*100)%100,size); Report += sGetStringLen(Report); size = 0; pSize = 0.0f; for(i=0;i<Symbols.Count;i++) { if(Symbols[i].Class == DIC_DATA) { size += Symbols[i].Size; pSize += Symbols[i].PackedSize; } } sSPrintF(Report,512,"Overall data: %5d.%02d/%8d\n",sInt(pSize), sInt(pSize*100)%100,size); Report += sGetStringLen(Report); return sDupString(ReportBuffer,1); }
sBool MAPFileReader::ReadDebugInfo(sChar *fileName,DebugInfo &to) { PUnDecorateSymbolName UnDecorateSymbolName = 0; // determine map file name sChar fileBuf[260]; sChar *text; sInt i; sCopyString(fileBuf,fileName,256); for(i=sGetStringLen(fileBuf)-1;i>=0 && fileBuf[i] != '.';i--); if(i > 0) sCopyString(fileBuf + i,".map",260-i); else sAppendString(fileBuf,".map",260); text = (sChar *) sSystem->LoadFile(fileBuf); if(!text) return sFALSE; // load dbghelp.dll to resolve symbol names if available void *module = LoadLibraryA("dbghelp.dll"); if(module) UnDecorateSymbolName = (PUnDecorateSymbolName) GetProcAddress(module,"UnDecorateSymbolName"); // actual reading code sChar *line,buffer[2048]; sInt j,code,data; sInt snum,offs,type,name,VA,fname; sInt symStart = to.Symbols.Count; Section *sec; DISymbol *sym; Sections.Init(); code = to.MakeString("CODE"); data = to.MakeString("DATA"); while(*text) { // find end of line line = text; while(*text && *text != '\n') text++; if(text[-1] == '\r' && text[0] == '\n') text[-1] = 0; if(*text) *text++ = 0; // parse this line of text if(line[0]==' ' && IsHexString(line+1,4) && line[5]==':' && IsHexString(line+6,8) && line[14]==' ') { if(IsHexString(line+15,8)) // section definition { sec = Sections.Add(); line += 1; sec->Num = sScanHex(line); line += 1; sec->Start = sScanHex(line); line += 1; sec->Length = sScanHex(line); line += 2; sec->Name.Index = ScanString(line,to); sScanSpace(line); type = ScanString(line,to); if(type == code) sec->Class = DIC_CODE; else if(type == data) sec->Class = DIC_DATA; else sec->Class = DIC_UNKNOWN; sec->Seen = sFALSE; } else // assume name definition { line += 1; snum = sScanHex(line); line += 1; offs = sScanHex(line); sec = GetSection(snum,offs); if(sec) { sScanSpace(line); name = ScanString(line,to); sScanSpace(line); VA = sScanHex(line); line += 5; fname = ScanString(line,to); if(!sec->Seen) { sym = to.Symbols.Add(); sSPrintF(buffer,2048,"__end%s",to.GetStringPrep(sec->Name.Index)); sym->Name.Index = to.MakeString(buffer); sym->FileNum = -1; sym->VA = VA-offs+sec->Start+sec->Length; sym->Size = 0; sym->Class = DIC_END; sec->Seen = sTRUE; } if(UnDecorateSymbolName) UnDecorateSymbolName(to.GetStringPrep(name),buffer,2048,0x1800); else sCopyString(buffer,to.GetStringPrep(name),2048); // add symbol sym = to.Symbols.Add(); sym->Name.Index = to.MakeString(buffer); sym->MangledName.Index = name; sym->FileNum = to.GetFile(fname); sym->VA = VA; sym->Size = 0; sym->Class = sec->Class; sym->NameSpNum = to.GetNameSpaceByName(buffer); } } } else if(!sCmpMem(line," Preferred load address is ",28) && IsHexString(line+28,8)) { line += 28; sU32 base = sScanHex(line); to.SetBaseAddress(base); } } // sort symbols by virtual address for(i=symStart+1;i<to.Symbols.Count;i++) for(j=i;j>symStart;j--) if(to.Symbols[j].VA<to.Symbols[j-1].VA) sSwap(to.Symbols[j],to.Symbols[j-1]); // calc sizes for(i=symStart;i<to.Symbols.Count;i++) { sym = &to.Symbols[i]; if(sym->Class!=DIC_END) { sVERIFY(i != to.Symbols.Count-1); sym->Size = sym[1].VA - sym->VA; } } // cleanup Sections.Exit(); delete[] text; return sTRUE; }