Array(const Array& src) { _data=new T*[src.Count()]; int i; for(i=0;i<src.Count();i++) { _data[i]=new T(src[i]); } _size=src.Count(); _count=_size; _empty=0; }
void operator=(const Array& src) { if(this==&src)return; Clean(); _data=new T*[src.Count()]; int i; for(i=0;i<src.Count();i++) { _data[i]=new T(src[i]); } _size=src.Count(); _count=_size; }
int Insert(int index,const Array& src) { if(index<0)index+=_count; if(index<0)return -1; if(index>_count) { Resize(index+src.Count()); int i; InitRange(_count,index); for(i=0;i<src.Count();i++) { _data[index+i]=new T(src[i]); } _count=index+src.Count(); }else { Resize(_count+src.Count()); Copy(index,index+src.Count(),src.Count()); int i; for(i=0;i<src.Count();i++) { _data[index+i]=new T(src[i]); } _count+=src.Count(); } return _count; }
bool isLoadBase(const String& path) { for(int i=0;i<loadBases.Count();i++) { if(path.StartWith(loadBases[i]))return true; } return false; }
void addToLoadBases(const String& base) { String path=base; path.ToLower(); for(int i=0;i<loadBases.Count();i++) { if(loadBases[i]==path)return; } loadBases.Push(path); }
BOOL CALLBACK GeneralProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { // port char port[256]; wsprintf(port, "%d", ConfigDialog::Get()->GetConfig()->GetPort()); SendDlgItemMessage(hwndDlg, ID_GENERAL_PORT, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)port); // password const char *pass = ConfigDialog::Get()->GetConfig()->GetPassword(); SendDlgItemMessage(hwndDlg, ID_GENERAL_PASSWORD, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)pass); // set all unasigned ip char *defip = Server::Get()->ConvertToAddress(DEFAULT_IP_ADDRESS, Server::ByteOrder::Host); SendDlgItemMessage(hwndDlg, ID_GENERAL_IP_ADDRESS, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)defip); SendDlgItemMessage(hwndDlg, ID_GENERAL_IP_ADDRESS, CB_SETCURSEL, 0, 0); // set ip list Array<DWORD> ipList; Server::Get()->GetIpAddressList(ipList); for(unsigned int i=0; i<ipList.Count(); i++) { char *tmp = Server::Get()->ConvertToAddress(ipList[i], Server::ByteOrder::Host); int cur = SendDlgItemMessage(hwndDlg, ID_GENERAL_IP_ADDRESS, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)tmp); if (ConfigDialog::Get()->GetConfig()->GetIpAddress() == ipList[i]) SendDlgItemMessage(hwndDlg, ID_GENERAL_IP_ADDRESS, CB_SETCURSEL, cur, 0); } // auto start if (ConfigDialog::Get()->GetConfig()->IsAutoStartEnabled()) CheckDlgButton(hwndDlg, ID_GENERAL_AUTO_SERVICE, BST_CHECKED); else CheckDlgButton(hwndDlg, ID_GENERAL_AUTO_SERVICE, BST_UNCHECKED); break; } // WM_INITDIALOG case WM_APP_SERIALIZE: { char tmp[256]; // port SendDlgItemMessage(hwndDlg, ID_GENERAL_PORT, WM_GETTEXT, (WPARAM)sizeof(tmp), (LPARAM)&tmp); ConfigDialog::Get()->GetConfig()->SetPort(atoi(tmp)); // password SendDlgItemMessage(hwndDlg, ID_GENERAL_PASSWORD, WM_GETTEXT, (WPARAM)sizeof(tmp), (LPARAM)&tmp); ConfigDialog::Get()->GetConfig()->SetPassword(tmp); // ip SendDlgItemMessage(hwndDlg, ID_GENERAL_IP_ADDRESS, WM_GETTEXT, (WPARAM)sizeof(tmp), (LPARAM)&tmp); DWORD ipaddr = Server::Get()->ConvertToIp(tmp); ConfigDialog::Get()->GetConfig()->SetIpAddress(ipaddr); // auto start bool start = (IsDlgButtonChecked(hwndDlg, ID_GENERAL_AUTO_SERVICE) == BST_CHECKED); ConfigDialog::Get()->GetConfig()->SetAutoStart(start); break; } // WM_APP_SERIALIZE } return FALSE; }
Void CharEntity::_PathTracking_Update( const Array<WorldPathWaypoint*> & arrPath ) { // Destroy path tracking _PathTracking_End(); // Find which waypoint we need to go to next Vertex3 vPosition = GetPosition(); Scalar fSqrDistance, fPrevSqrDistance = SCALAR_INFINITE; //Scalar fPrevPrevSqrDistance; Assert( m_iLastPassedWaypoint != INVALID_OFFSET ); UInt iNextWaypoint = m_iLastPassedWaypoint; while( iNextWaypoint < arrPath.Count() ) { // Detect if the path stops getting closer from our position fSqrDistance = ( arrPath[iNextWaypoint]->GetPosition() - vPosition ).NormSqr(); if ( fSqrDistance > fPrevSqrDistance ) { // Either one of those 2 cases : we allways choose i // -----*--X--|-----*----------*---- // i-1 i // -----*-----|--X--*----------*---- where i is iNextWaypoint // i-2 i-1 i //if ( iNextWaypoint >= 2 ) { // fPrevPrevSqrDistance = ( arrPath[iNextWaypoint-2]->GetPosition() - vPosition ).NormSqr(); // if ( fPrevPrevSqrDistance < fSqrDistance ) // --iNextWaypoint; //} break; } fPrevSqrDistance = fSqrDistance; ++iNextWaypoint; } // This is a safe assumption ... // We allways have the last call to this made way before // path tracking is finished, timing is obviously enforced here. Assert( iNextWaypoint < arrPath.Count() ); m_iLastPassedWaypoint = ( iNextWaypoint - 1 ); WorldPathFinder * pPathFinder = WorldFn->GetPathFinder(); Bool bFinished = pPathFinder->IsFinished( m_idPathTracking ); // Recreate path tracking EntityFn->SelectMemory( TEXT("Scratch") ); UInt iControlPointCount = ( arrPath.Count() - iNextWaypoint + 1 ); UInt iDegree = Min<UInt>( iControlPointCount - 1, 3 ); Vertex3 * arrControlPoints = New Vertex3[iControlPointCount]; Scalar * arrParameters = New Scalar[iControlPointCount]; Vertex2 * arrTravelPoints = New Vertex2[iControlPointCount]; arrControlPoints[0] = vPosition; for( UInt i = 1; i < iControlPointCount - 1; ++i ) arrControlPoints[i] = arrPath[iNextWaypoint + (i-1)]->GetPosition(); if ( bFinished ) arrControlPoints[iControlPointCount - 1] = m_vPathTarget; else arrControlPoints[iControlPointCount - 1] = arrPath[iNextWaypoint + (iControlPointCount - 2)]->GetPosition(); m_pLinearPath = New BSplinePatch3( arrControlPoints, iControlPointCount, iDegree, false, false ); m_pLinearPath->SubDivideByParameter( arrParameters, iControlPointCount ); for( UInt i = 0; i < iControlPointCount; ++i ) { Vector3 vTangent = m_pLinearPath->Tangent( arrParameters[i] ); arrControlPoints[i].X = 0.0f; arrControlPoints[i].Y = 0.0f; arrControlPoints[i].Z = MathFn->ArcCos( vTangent * Vector3::eI ); } m_pAngularPath = New BSplinePatch3( arrControlPoints, iControlPointCount, iDegree, false, false ); Scalar fLength = m_pLinearPath->Curve3::Length(); Scalar fTime = ( fLength / m_pCharacter->GetMovementSpeed() ); Scalar fLengthInterval = ( fLength / (Scalar)(iControlPointCount - 1) ); Scalar fTimeInterval = ( fTime / (Scalar)(iControlPointCount - 1) ); Scalar fX = 0.0f, fY = 0.0f; for( UInt i = 0; i < iControlPointCount; ++i ) { arrTravelPoints[i].X = fX; arrTravelPoints[i].Y = fY; fX += fLengthInterval; fY += fTimeInterval; } m_pLinearTravel = New BSplinePatch2( arrTravelPoints, iControlPointCount, iDegree, false, false ); m_pAngularTravel = New BSplinePatch2( arrTravelPoints, iControlPointCount, iDegree, false, false ); DeleteA( arrTravelPoints ); arrTravelPoints = NULL; DeleteA( arrParameters ); arrParameters = NULL; DeleteA( arrControlPoints ); arrControlPoints = NULL; EntityFn->UnSelectMemory(); // Disable character controller m_pController->SetStanding(); KinematicBody * pBody = (KinematicBody*)m_pBody; m_pController->Enabled = false; pBody->DetachMotionController(); // Enable path controller m_pPathController = PhysicsFn->CreatePathController( TEXT("PathController"), m_pLinearPath, m_pLinearTravel, m_pAngularPath, m_pAngularTravel, EULER_ANGLES_ZYX ); m_pPathController->Enabled = true; m_pPathController->MaxTime = fTime; pBody->AttachController( m_pPathController ); }
Void CharEntity::_PathTracking_Start( const Array<WorldPathWaypoint*> & arrPath ) { Assert( m_pPathController == NULL ); WorldPathFinder * pPathFinder = WorldFn->GetPathFinder(); Bool bFinished = pPathFinder->IsFinished( m_idPathTracking ); // Create path data EntityFn->SelectMemory( TEXT("Scratch") ); Bool bBias = false; UInt iControlPointCount = arrPath.Count(); if ( iControlPointCount == 1 ) { Assert( bFinished ); ++iControlPointCount; bBias = true; } UInt iDegree = Min<UInt>( iControlPointCount - 1, 3 ); Vertex3 * arrControlPoints = New Vertex3[iControlPointCount]; Scalar * arrParameters = New Scalar[iControlPointCount]; Vertex2 * arrTravelPoints = New Vertex2[iControlPointCount]; arrControlPoints[0] = GetPosition(); if ( bBias ) arrControlPoints[1] = m_vPathTarget; else { for( UInt i = 1; i < iControlPointCount - 1; ++i ) arrControlPoints[i] = arrPath[i]->GetPosition(); if ( bFinished ) arrControlPoints[iControlPointCount - 1] = m_vPathTarget; else arrControlPoints[iControlPointCount - 1] = arrPath[iControlPointCount - 1]->GetPosition(); } m_pLinearPath = New BSplinePatch3( arrControlPoints, iControlPointCount, iDegree, false, false ); m_pLinearPath->SubDivideByParameter( arrParameters, iControlPointCount ); for( UInt i = 0; i < iControlPointCount; ++i ) { Vector3 vTangent = m_pLinearPath->Tangent( arrParameters[i] ); arrControlPoints[i].X = 0.0f; arrControlPoints[i].Y = 0.0f; arrControlPoints[i].Z = MathFn->ArcCos( vTangent * Vector3::eI ); } m_pAngularPath = New BSplinePatch3( arrControlPoints, iControlPointCount, iDegree, false, false ); Scalar fLength = m_pLinearPath->Curve3::Length(); Scalar fTime = ( fLength / m_pCharacter->GetMovementSpeed() ); Scalar fLengthInterval = ( fLength / (Scalar)(iControlPointCount - 1) ); Scalar fTimeInterval = ( fTime / (Scalar)(iControlPointCount - 1) ); Scalar fX = 0.0f, fY = 0.0f; for( UInt i = 0; i < iControlPointCount; ++i ) { arrTravelPoints[i].X = fX; arrTravelPoints[i].Y = fY; fX += fLengthInterval; fY += fTimeInterval; } m_pLinearTravel = New BSplinePatch2( arrTravelPoints, iControlPointCount, iDegree, false, false ); m_pAngularTravel = New BSplinePatch2( arrTravelPoints, iControlPointCount, iDegree, false, false ); DeleteA( arrTravelPoints ); arrTravelPoints = NULL; DeleteA( arrParameters ); arrParameters = NULL; DeleteA( arrControlPoints ); arrControlPoints = NULL; EntityFn->UnSelectMemory(); // Disable character controller m_pController->SetStanding(); KinematicBody * pBody = (KinematicBody*)m_pBody; m_pController->Enabled = false; pBody->DetachMotionController(); // Enable path controller m_pPathController = PhysicsFn->CreatePathController( TEXT("PathController"), m_pLinearPath, m_pLinearTravel, m_pAngularPath, m_pAngularTravel, EULER_ANGLES_ZYX ); m_pPathController->Enabled = true; m_pPathController->MaxTime = fTime; pBody->AttachController( m_pPathController ); }
FARAPI(HANDLE) OpenPlugin(int OpenFrom,int Item) { UpdateConfig(); if(OpenFrom==OPEN_EDITOR) { //DebugBreak(); EditorInfo ei; I.EditorControl(ECTL_GETINFO,&ei); Autoload(ei.FileName); if(Count()==0) { Msg(MENotLoaded); return INVALID_HANDLE_VALUE; } MenuList ml; enum{ miFindSymbol,miUndo,miResetUndo, miComplete,miBrowseFile,miBrowseClass, }; ml<<MI(MFindSymbol,miFindSymbol) <<MI(MCompleteSymbol,miComplete) <<MI(MUndoNavigation,miUndo) <<MI(MResetUndo,miResetUndo) <<MI(MBrowseSymbolsInFile,miBrowseFile) <<MI(MBrowseClass,miBrowseClass); int res=Menu(GetMsg(MPlugin),ml,0); if(res==-1)return INVALID_HANDLE_VALUE; switch(res) { case miFindSymbol: { String word=GetWord(); if(word.Length()==0)return INVALID_HANDLE_VALUE; //Msg(word); PTagArray ta=Find(word,ei.FileName); if(!ta) { Msg(GetMsg(MNotFound)); return INVALID_HANDLE_VALUE; } TagInfo *ti; if(ta->Count()==1) { ti=(*ta)[0]; }else { ti=TagsMenu(ta); } if(ti)NavigateTo(ti); FreeTagsArray(ta); }break; case miUndo: { if(UndoArray.Count()==0)return INVALID_HANDLE_VALUE; /*char b[32]; sprintf(b,"%d",ei.CurState); Msg(b);*/ if(ei.CurState==ECSTATE_SAVED) { I.EditorControl(ECTL_QUIT,NULL); I.AdvControl(I.ModuleNumber,ACTL_COMMIT,(void*)-1); } SUndoInfo ui; UndoArray.Pop(ui); SetPos(ui.file,ui.line,ui.pos,ui.top,ui.left); }break; case miResetUndo: { UndoArray.Clean(); }break; case miComplete: { EditorInfo ei; I.EditorControl(ECTL_GETINFO,&ei); String word=GetWord(1); if(word.Length()==0)return INVALID_HANDLE_VALUE; StrList lst; FindParts(ei.FileName,word,lst); if(lst.Count()==0) { Msg(MNothingFound); return INVALID_HANDLE_VALUE; } int res; if(lst.Count()>1) { MenuList ml; for(int i=0;i<lst.Count();i++) { ml<<MI(lst[i],i); } res=Menu(GetMsg(MSelectSymbol),ml,0,MF_FILTER|MF_SHOWCOUNT,(void*)word.Str()); if(res==-1)return INVALID_HANDLE_VALUE; }else { res=0; } EditorGetString egs; egs.StringNumber=-1; I.EditorControl(ECTL_GETSTRING,&egs); while(isident(egs.StringText[ei.CurPos]))ei.CurPos++; EditorSetPosition esp; esp.CurLine=-1; esp.CurPos=ei.CurPos; esp.CurTabPos=-1; esp.TopScreenLine=-1; esp.LeftPos=-1; esp.Overtype=-1; I.EditorControl(ECTL_SETPOSITION,&esp); I.EditorControl(ECTL_INSERTTEXT,(void*)lst[res].Substr(word.Length()).Str()); }break; case miBrowseFile: { EditorInfo ei; I.EditorControl(ECTL_GETINFO,&ei); PTagArray ta=FindFileSymbols(ei.FileName); if(!ta) { Msg(MNothingFound); return INVALID_HANDLE_VALUE; } TagInfo *ti=TagsMenu(ta); if(ti)NavigateTo(ti); FreeTagsArray(ta); }break; case miBrowseClass: { #ifdef DEBUG //DebugBreak(); #endif String word=GetWord(); if(word.Length()==0) { char buf[256]; if(!I.InputBox(GetMsg(MBrowseClassTitle),GetMsg(MInputClassToBrowse),NULL, "",buf,sizeof(buf),NULL,0))return INVALID_HANDLE_VALUE; word=buf; } EditorInfo ei; I.EditorControl(ECTL_GETINFO,&ei); PTagArray ta=FindClassSymbols(ei.FileName,word); if(!ta) { Msg(MNothingFound); return INVALID_HANDLE_VALUE; } TagInfo *ti=TagsMenu(ta); if(ti)NavigateTo(ti); FreeTagsArray(ta); }break; } } else { int load=OpenFrom==OPEN_COMMANDLINE; if(OpenFrom==OPEN_PLUGINSMENU) { MenuList ml; enum {miLoadTagsFile,miUnloadTagsFile, miUpdateTagsFile,miCreateTagsFile}; ml<<MI(MLoadTagsFile,miLoadTagsFile) <<MI(MUnloadTagsFile,miUnloadTagsFile) <<MI(MCreateTagsFile,miCreateTagsFile) <<MI(MUpdateTagsFile,miUpdateTagsFile); int rc=Menu(GetMsg(MPlugin),ml,0); switch(rc) { case miLoadTagsFile: { load=1; }break; case miUnloadTagsFile: { ml.Clean(); ml<<MI(MAll,0); StrList l; GetFiles(l); for(int i=0;i<l.Count();i++) { ml<<MI(l[i],i+1); } int rc=Menu(GetMsg(MUnloadTagsFile),ml,0); if(rc==-1)return INVALID_HANDLE_VALUE; UnloadTags(rc-1); }break; case miCreateTagsFile: { HANDLE hScreen=I.SaveScreen(0,0,-1,-1); const char *msg[]={GetMsg(MPlugin),GetMsg(MTagingCurrentDirectory)}; I.Message(I.ModuleNumber,0,NULL,msg,2,0); int rc=TagCurrentDir(); I.RestoreScreen(hScreen); }break; case miUpdateTagsFile: { HANDLE hScreen=I.SaveScreen(0,0,-1,-1); const char *msg[]={GetMsg(MPlugin),GetMsg(MUpdatingTagsFile)}; StrList changed; PanelInfo pi; String file; I.Control(INVALID_HANDLE_VALUE,FCTL_GETPANELINFO,&pi); file=pi.CurDir; if(file[-1]!='\\')file+="\\"; file+=pi.PanelItems[pi.CurrentItem].FindData.cFileName; I.Message(I.ModuleNumber,0,NULL,msg,2,0); if(!UpdateTagsFile(file)) { I.RestoreScreen(hScreen); Msg(MUnableToUpdate); return INVALID_HANDLE_VALUE; } I.RestoreScreen(hScreen); }break; } } if(load) { //DebugBreak(); PanelInfo pi; I.Control(INVALID_HANDLE_VALUE,FCTL_GETPANELINFO,&pi); tagfile=pi.CurDir; if(tagfile[-1]!='\\')tagfile+="\\"; if(OpenFrom==OPEN_PLUGINSMENU) { tagfile+=pi.PanelItems[pi.CurrentItem].FindData.cFileName; }else if(OpenFrom==OPEN_COMMANDLINE) { char *cmd=(char*)Item; if(cmd[1]==':') { tagfile=cmd; }else { if(cmd[0]=='\\') { tagfile.Delete(2); tagfile+=cmd; }else { tagfile+=cmd; } } } int rc=Load(tagfile,"",true); if(rc>1) { Msg(GetMsg(rc)); return INVALID_HANDLE_VALUE; } String msg; msg.Sprintf("%s:%d",GetMsg(MLoadOk),Count()); Msg(msg); } } return INVALID_HANDLE_VALUE; }