Beispiel #1
0
//---------------------------------------------------------------------------
bool File::Truncate (int64u Offset)
{
    if (File_Handle==NULL)
        return false;

    #ifdef ZENLIB_USEWX
        return false; //Not supported
    #else //ZENLIB_USEWX
        #ifdef ZENLIB_STANDARD
            #if defined(WINDOWS)
                return false; //Not supported
            #else //defined(WINDOWS)
                //Need to close the file, use truncate, reopen it
                if (Offset==(int64u)-1)
                    Offset=Position_Get();
                Ztring File_Name_Sav=File_Name;
                Close();
                truncate(File_Name_Sav.To_Local().c_str(), Offset);
                if (!Open(File_Name_Sav, Access_Read_Write))
                    return false;
                GoTo(0, FromEnd);
                return true;
            #endif //!defined(WINDOWS)
        #elif defined WINDOWS
            if(Offset!=(int64u)-1 && Offset!=Position_Get())
                if (!GoTo(Offset))
                    return false;
            SetEndOfFile(File_Handle);
            return true;
        #endif
    #endif //ZENLIB_USEWX
}
Beispiel #2
0
/*!	\brief Goes to the previous leaf node.

	This method operates only at leaf node level. It finds the next leaf
	node to the left. Fails, if the current node is no leaf node.

	\param node Pointer to a pre-allocated LeafNode pointer that shall be set
		   to the found node.
	\return \c B_OK, if everything went fine
*/
status_t
TreeIterator::GoToPreviousLeaf(LeafNode **node)
{
	status_t error = InitCheck();
	if (error == B_OK) {
		if (fCurrentNode->IsLeaf()) {
			// find downmost branch on our path, that leads further left
			bool found = false;
			while (error == B_OK && !found) {
				error = GoTo(UP);
				if (error == B_OK)
					found = (GoTo(BACKWARDS) == B_OK);
			}
			// descend the branch to the rightmost leaf
			if (error == B_OK) {
				// one level down
				error = GoTo(DOWN);
				// then keep right
				while (error == B_OK && fCurrentNode->IsInternal()) {
					fIndex = fCurrentNode->CountItems();
					error = GoTo(DOWN);
				}
			}
			// set the result
			if (error == B_OK && node)
				*node = fCurrentNode->ToLeafNode();
		} else
			error = B_ENTRY_NOT_FOUND;
	}
	return error;
}
void clearLine(unsigned char x, unsigned char y){

	unsigned char max_x=20;

	GoTo(x,y);
	for (int i=x; i<max_x; i++)
	{
		lcd_data_write(0x20);
		_delay_ms(1);
	}
	GoTo(x,y);
}
JError
JDirInfo::GoUp()
{
	JString theCWD = *itsCWD;

	// strip trailing slashes

	JStripTrailingDirSeparator(&theCWD);
	if (JIsRootDirectory(theCWD))
		{
		return JNoError();
		}

	// change directory

	JString newCWD, name;
	if (JSplitPathAndName(theCWD, &newCWD, &name))
		{
		return GoTo(newCWD);
		}
	else
		{
		return JBadPath(theCWD);
		}
}
Beispiel #5
0
void showFFT(Int32 *maxIndex, Int32 *max)
{
	DATA AMP;
	Int32 tmp,tmp2;
	Uint16 n;

    *max = 0;
	*maxIndex = 512;

	//Find magnitude of X(n/2).
	GoTo(100,0);
	for (n = 0; n < FFTSIZE; n = n + 2)
	{
		tmp = ((Int32)pDONE[n]*pDONE[n]) + ((Int32)pDONE[n+1] * pDONE[n+1]);
		tmp2 = FFracSqrt(tmp);
		tmp2 = tmp2 >> 14;  // Should really be >>15.  Done for larger dynamic
						 // range.  But now we need to check for overflow.
		AMP = tmp2>32767?32767:tmp2<-32768?-32768:tmp2; // amplitude of the output sine wave
		// Reg[n >> 1] = AMP;
		Draw(BLUE,100+n/2, AMP >> 4 );

		if(AMP > *max)
		{
			*max = AMP;
			*maxIndex = n >> 1;
		}

	}
void do_GMGoto(CPC *a1, char *a2)
{
    char v4; // [sp+1Bh] [bp-Dh]@10
    float v5; // [sp+1Ch] [bp-Ch]@7
    float v6; // [sp+24h] [bp-4h]@4
    char *v7; // [sp+34h] [bp+Ch]@4
    char *v8; // [sp+34h] [bp+Ch]@7

    *g_buf = 0;
    if(a2 && *a2)
    {
        v7 = AnyOneArg(a2, g_buf, 0);
        v6 = atof(g_buf);

        if(v7 && *v7)
        {
            v8 = AnyOneArg(v7, g_buf, 0);
            v5 = atof(g_buf);

            if(v8 && *v8)
            {
                AnyOneArg(v8, g_buf, 0);
                v4 = atoi(g_buf);

                if(v4 >= 0 && v4 <= 2 * (a1->Unk408->Unk28 - 1) && v6 >= 0.0 && v5 >= 0.0 && v6 < a1->Unk408->Unk32[v4/2].Unk0 && v5 < a1->Unk408->Unk32[v4/2].Unk4) // NOT SURE -> CHECK
                    GoTo(a1, v4, v6, v5, a1->Unk412->GetHeight(v4, v6, v5), a1->Unk120.Unk12);
            }
        }
    }
}
JBoolean
JDirInfo::ForceUpdate()
{
	if (JDirectoryExists(*itsCWD))
		{
		Broadcast(ContentsWillBeUpdated());

		const JError err = BuildInfo();
		if (err.OK())
			{
			return kJTrue;
			}
		}

	if (itsSwitchIfInvalidFlag)
		{
		JString path;
		if (!JGetHomeDirectory(&path) || !OKToCreate(path))
			{
			path = JGetRootDirectory();
			}
		GoTo(path);
		}
	else
		{
		itsIsValidFlag    = kJFalse;
		itsIsWritableFlag = kJFalse;
		itsDirEntries->CleanOut();
		itsVisEntries->CleanOut();
		itsAlphaEntries->CleanOut();
		}

	return kJFalse;
}
Beispiel #8
0
void Tractor::Move()
{
	if (floor(health) > 0 && floor(fuel) > 0)
	{
		if (wasBlocked)
			GoTo(distX, distY);

		if (x == distX)
		{
			dirX = 0;
			x = distX;
		}

		if (y == distY)
		{
			dirY = 0;
			y = distY;
		}

		health -= 0.001;
		fuel -= 0.001;

		if (x == distX && y == distY)
			move = false;
	}
	else
	{
		dirX = 0;
		dirY = 0;
		wasBlocked = true;
	}
}
Beispiel #9
0
//---------------------------------------------------------------------------
void File_Pdf::startxref()
{
    //We need to find the exact begin
    Buffer_Offset=Buffer_Size-1;
    while (Buffer_Offset && (Buffer[Buffer_Offset]=='\r' || Buffer[Buffer_Offset]=='\n'))
        Buffer_Offset--;
    Buffer_Offset-=5; // "%%EOF"
    while (Buffer_Offset && (Buffer[Buffer_Offset]=='\r' || Buffer[Buffer_Offset]=='\n'))
        Buffer_Offset--;
    while (Buffer_Offset && Buffer[Buffer_Offset]>='0' && Buffer[Buffer_Offset]<='9') // Value
        Buffer_Offset--;
    while (Buffer_Offset && (Buffer[Buffer_Offset]=='\r' || Buffer[Buffer_Offset]=='\n'))
        Buffer_Offset--;

    Buffer_Offset-=8;

    //Parsing
    Element_Begin1("Cross-Reference Table Offset");

    string xrefOffsetS;
    Skip_String(SizeOfLine(),                                   "Object name");
    Get_String (SizeOfLine(), xrefOffsetS,                      "xref Offset");
    while (Buffer_Offset<Buffer_Size && (Buffer[Buffer_Offset]=='\r' || Buffer[Buffer_Offset]=='\n'))
        ++Buffer_Offset;
    int32u xref_Offset=atoi(xrefOffsetS.c_str());

    Element_End0();

    //Going to xref
    if (xref_Offset>Offsets_Max)
        Offsets_Max=xref_Offset;
    GoTo (xref_Offset);
    State=State_Parsing_xref;
}
bool CProcessConfigReader::GetConfigurationAndPreserveSpace(std::string sAppName, STRING_LIST &Params)
{
    Params.clear();

    int nBrackets = 0;
    Params.clear();

    Reset();

    std::string sKey = "PROCESSCONFIG="+sAppName;

    if(GoTo(sKey))
    {
        std::string sBracket = GetNextValidLine();
        if(sBracket.find("{")==0)
        {
            nBrackets++;
            while(!GetFile()->eof())
            {
                std::string sLine = GetNextValidLine();
                MOOSTrimWhiteSpace(sLine);

                if(sLine.find("}")!=0)
                {
                    std::string sVal(sLine);
                    std::string sTok = MOOSChomp(sVal, "=");
                    MOOSTrimWhiteSpace(sTok);
                    MOOSTrimWhiteSpace(sVal);

                    if (!sTok.empty())
                    {

                        if (!sVal.empty())
                        {
                            Params.push_back(sTok+"="+sVal);
                        }
                        else if(sLine.find("[")!=std::string::npos || sLine.find("]")!=std::string::npos)
                        {
                            Params.push_back(sLine);
                        }
                    }
                }
                else
                {
                    return true;
                }

                //quick error check - we don't allow nested { on single lines
                if(sLine.find("{")==0)
                {
                    MOOSTrace("CProcessConfigReader::GetConfiguration() missing \"}\" syntax error in mission file\n");
                }
            }
        }
    }


    return false;

}
Beispiel #11
0
bool File_Zip::end_of_central_directory()
{
    if (Element_Offset+22>Element_Size) //end_of_central_directory up to relative offset of .ZIP file comment length included
        return false; //Not enough data

    //Retrieving complete local_file_header size
    int16u zip_comment_length=LittleEndian2int16u(Buffer+(size_t)Element_Offset+20);
    if (Element_Offset+22+zip_comment_length>Element_Size) //end_of_central_directory all included
        return false; //Not enough data

    //Parsing
    int32u offset;
    Element_Begin1("End of central directory");
    Skip_C4(                                                    "end of central dir signature");
    Skip_L2(                                                    "number of this disk");
    Skip_L2(                                                    "number of the disk");// with the start of the central directory
    Skip_L2(                                                    "total number of entries on this disk");// in the central directory
    Skip_L2(                                                    "total number of entries");// in the central directory
    Skip_L4(                                                    "size of the central directory");
    Get_L4 (offset,                                             "offset of start of central directory");// with respect to the starting disk number
    Skip_L2(                                                    "zip file comment length");
    Skip_XX(zip_comment_length,                                 "zip file comment");
    Element_End0();

    //Going to first central directory (once)
    if (!end_of_central_directory_IsParsed)
    {
        end_of_central_directory_IsParsed=true;
        GoTo(offset);
    }
    return true;
}
JError
JDirInfo::GoDown
	(
	const JCharacter* dirName
	)
{
	const JString theCWD = *itsCWD + dirName;
	return GoTo(theCWD);
}
Beispiel #13
0
bool DisassemblyView::goTo(medusa::Address const& address)
{
  if (_core->GetDocument().GetCell(address) == nullptr)
    return false;

  GoTo(address);
  viewUpdated();

  return true;
}
Beispiel #14
0
//---------------------------------------------------------------------------
void File_Dpg::FileHeader_Parse()
{
    //Parsing
    int32u  FrameCount, FrameRate, SamplingRate;
    Skip_C4(                                                    "Signature");
    Get_L4 (FrameCount,                                         "Frame count");
    Get_L4 (FrameRate,                                          "Frame rate"); Param_Info2(FrameRate/0x100, " fps");
    Get_L4 (SamplingRate,                                       "Sampling rate");
    Skip_L4(                                                    "0x00000000");
    Get_L4 (Audio_Offset,                                       "Audio Offset");
    Get_L4 (Audio_Size,                                         "Audio Size");
    Get_L4 (Video_Offset,                                       "Video Offset");
    Get_L4 (Video_Size,                                         "Video Size");

    FILLING_BEGIN();
        Accept("DPG");

        Fill(Stream_General, 0, General_Format, "DPG");

        Stream_Prepare(Stream_Video);
        Fill(Stream_Video, 0, Video_FrameRate, (float)(FrameRate/0x100), 3);
        Fill(Stream_Video, 0, Video_FrameCount, FrameCount);
        Fill(Stream_Video, 0, Video_StreamSize, Video_Size);

        Stream_Prepare(Stream_Audio);
        Fill(Stream_Audio, 0, Audio_SamplingRate, SamplingRate);
        Fill(Stream_Audio, 0, Audio_StreamSize, Audio_Size);

        //Positionning
        #if defined(MEDIAINFO_MPEGA_YES)
            Parser=new File_Mpega();
            Open_Buffer_Init(Parser);
            GoTo(Audio_Offset, "DPG");
        #elif defined(MEDIAINFO_MPEGV_YES)
            Audio_Size=0;
            Parser=new File_Mpegv();
            Open_Buffer_Init(Parser);
            GoTo(Video_Offset, "DPG");
        #else
            Finish("DPG");
        #endif
    FILLING_END();
}
void
JDirInfo::GoToClosest
	(
	const JCharacter* origDirName
	)
{
	const JString dirName = JGetClosestDirectory(origDirName);
	const JError err      = GoTo(dirName);
	assert_ok( err );
}
Beispiel #16
0
void GoForKick:: Play()
{
	if (1) //ball1.center.y>360
	{
		std::string g = "State == GoForKick y=";
		stringstream p;
		p << (int) ball1.center.y;
		g += p.str();
		writeToLog(logFile, g);

		if (ball1.x_ball_spot > 3 && ball1.x_ball_spot < 7) {
			GoTo(0, StateList[State].stateString, ball1.x_ball_spot); //forward
			writeToLog(logFile, "GoForKick forward");
		} else if (ball1.x_ball_spot < 4) {
			GoTo(6, StateList[State].stateString, ball1.x_ball_spot);  //right
			writeToLog(logFile, "GoForKick right");
		} else if (ball1.x_ball_spot > 6) {
			GoTo(-6, StateList[State].stateString, ball1.x_ball_spot);  //left
			writeToLog(logFile, "GoForKick left");
		}

		sleep(4);

		GoTo(0, StateList[State].stateString, ball1.x_ball_spot);

		//				if (ball1.center.y<420)
		//					sleep(15);
		//				sleep(11)
		sleep(20);

		GoStop();
		writeToLog(logFile, "Kick");

		Action::GetInstance()->Start(4);
		while (Action::GetInstance()->IsRunning())
			usleep(8 * 1000);
	}

	State = GoToBall;

}
Beispiel #17
0
//---------------------------------------------------------------------------
void File_Tiff::FileHeader_Parse()
{
    //The only IFD that is known at forehand is the first one, it's offset is placed byte 4-7 in the file.
    int32u IFDOffset;
    Skip_B4(                                                    "Magic");
    Get_X4 (IFDOffset,                                          "IFDOffset");

    FILLING_BEGIN();
        //Initial IFD
        GoTo(IFDOffset, "TIFF");
    FILLING_END();
}
Beispiel #18
0
void TBackend::RestoreState(void)
{
    pToken = pSaveToken;
    token  = saveToken;
    pIcode = pSaveIcode;
    pNode  = pSaveNode;
    GoTo(saveLocation);
    currentLineNumber = saveLineNumber;

    strcpy(pToken->String(), pSaveTokenString);
    delete[] pSaveTokenString;
}
Beispiel #19
0
//---------------------------------------------------------------------------
void File_Tiff::Data_Parse()
{
    int32u IFDOffset=0;
    if (IfdItems.empty())
    {
        //Default values
        Infos.clear();
        Infos[Tiff_Tag::BitsPerSample]=__T("1");

        //Parsing new IFD
        while (Element_Offset+8+4<Element_Size)
            Read_Directory();
        Get_X4 (IFDOffset,                                          "IFDOffset");
    }
    else
    {
        //Handling remaining IFD data from a previous IFD
        GetValueOffsetu(IfdItems.begin()->second); //Parsing the IFD item
        IfdItems.erase(IfdItems.begin()->first); //Removing IFD item from the list of IFD items to parse
    }

    //Some items are not inside the directory, jumping to the offset
    if (!IfdItems.empty())
        GoTo(IfdItems.begin()->first, "TIFF");
    else
    {
        //This IFD is finished, filling data then going to next IFD
        Data_Parse_Fill();
        if (IFDOffset)
            GoTo(IFDOffset, "TIFF");
        else
        {
            Finish(); //No more IFDs
            GoToFromEnd(0);
        }
    }
}
Beispiel #20
0
point_gotoset LRParsing::makeGotoGraph(point_itemnode IS_0){
	//지역변수 선언
	int i_0, i_1, i_max;
	grammer sym_temp;
	point_gotoset result = NULL;
	point_statenode State_Node_List_Header = NULL, state_cursor, To_state_node;

	point_arcnode Arc_List_Header = NULL;
	point_itemnode To_item_list=NULL;

	//스테이트 0를 스테이트 리스트에 넣도록 함.(맨 처음으로 넣는 것임.)
	state_cursor = State_Node_List_Header = Add_A_State_Node(State_Node_List_Header, IS_0);
	//itemListPrint(IS_0);

	while(state_cursor){
		//단말기호, 비단말기호
		for(i_0 = 0; i_0 < 2; i_0++){//i_0 = 0이면 단말기호에 대한 처리이고, 1이면 비단말기호에 대한 처리임
			//i_max는 각 경우 (단말/비단말)가 가진 총 기호의 수를 가지게함.
			i_max = i_0 ? 9 : 22-2;//-2을 한 이유는 $단말기호와 입실론을 무시하기 위함.

			for(i_1 = 0; i_1 < i_max; i_1++){//i_1은 단말/비단말 각경우에서 기호의 번호를 나타냄.
				//문법 심볼 하나를 만듬.
				sym_temp.select = i_0;
				sym_temp.location = i_1;

				//현재 스테이트에서 문법심볼 sym_temp에 의해 goto할 아이템 리스트를 알아 옴.
				To_item_list = GoTo(state_cursor->item_start, sym_temp);//goto를 하여 결과를 알아 옴.
				
				if(To_item_list){
					//goto할 아이템리스트를 스테이트 노드에 없으면 등록하고,
					//있으면 어느것인지 판별함. 그리고 그 스테이트 노드를 알아옴.
					To_state_node = Add_A_State_Node(State_Node_List_Header, To_item_list);

					//알아낸 아크에 대하여 이것이 없으면 새로운 아크로 추가함.
					Add_An_Arc(&Arc_List_Header, state_cursor->id, To_state_node->id, sym_temp);
				}//if: To_item_list
			}//for: i_1: 모든기호에 대해 goto 수행
		}//for: i_0: 단말기호->비단말기호
		state_cursor = state_cursor->next;
	}//while: state_cursor

	//반환할 변수에값을 입력합니다.
	result = (point_gotoset)malloc(sizeof(gotoset));

	result->State_Node_List = State_Node_List_Header;
	result->Arc_list = Arc_List_Header;

	return result;
}//:makeGotoGraph()
Beispiel #21
0
/*!	\brief Goes to the next leaf node.

	This method operates only at leaf node level. It finds the next leaf
	node to the right. Fails, if the current node is no leaf node.

	\param node Pointer to a pre-allocated LeafNode pointer that shall be set
		   to the found node.
	\return \c B_OK, if everything went fine
*/
status_t
TreeIterator::GoToNextLeaf(LeafNode **node)
{
	status_t error = InitCheck();
	if (error == B_OK) {
		if (fCurrentNode->IsLeaf()) {
			// find downmost branch on our path, that leads further right
			bool found = false;
			while (error == B_OK && !found) {
				error = GoTo(UP);
				if (error == B_OK)
					found = (GoTo(FORWARD) == B_OK);
			}
			// descend the branch to the leftmost leaf
			while (error == B_OK && fCurrentNode->IsInternal())
				error = GoTo(DOWN);
			// set the result
			if (error == B_OK && node)
				*node = fCurrentNode->ToLeafNode();
		} else
			error = B_ENTRY_NOT_FOUND;
	}
	return error;
}
Beispiel #22
0
//---------------------------------------------------------------------------
void File_Pdf::Data_Parse()
{
    Element_Name("Object");

    string Line;
    Get_String(SizeOfLine(), Line,                              "Header");

    size_t Space_Pos=Line.find(' ');
    int32u ObjectNumber=Ztring().From_UTF8(Line.substr(0, Space_Pos)).To_int32u();
    Element_Info1(ObjectNumber);
    objects::iterator Object=Objects.find(ObjectNumber);
    if (Object==Objects.end())
        Skip_XX(Element_Size-Element_Offset,                    "Data");
    else
        switch(Object->second.Type)
        {
            case Type_Root      : Object_Root(); break;
            case Type_Info      : Object_Info(); break;
            case Type_Metadata  : Object_Metadata(); break;
            default             : Skip_XX(Element_Size-Element_Offset, "Data");
        }

    for (;;)
    {
        if (Objects_Current==Objects.end())
            break;

        Objects_Current->second.BottomPos++;
        if (Objects_Current->second.BottomPos>=Objects_Current->second.Bottoms.size())
        {
            if (Objects_Current->first==(int32u)-1)
            {
                //No more to parse
                Objects_Current=Objects.end();
                Objects.clear();
                Finish();
                break;
            }

            Objects_Current=Objects.find(Objects_Current->second.TopObject);
            continue;
        }

         Objects_Current=Objects.find(Objects_Current->second.Bottoms[Objects_Current->second.BottomPos]);
         GoTo(Objects_Current->second.Offset);
         break;
    }
}
void MazeFinder::ReceiveMessage(Message *message)
{
	if (message->GetMessageName() == "MazeFinderPathPointReached")
	{
		if (_pathIndex < _pathPoints.size() - 1)
		{
			GetToNextPoint();
		}
	}
	else if (message->GetMessageName() == "MouseDown")
	{
		TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
		Vec2i screenCoordinates = m->GetValue();
		Vector2 worldCoordinates = MathUtil::ScreenToWorld(screenCoordinates);
		GoTo(worldCoordinates);
	}
}
Beispiel #24
0
//---------------------------------------------------------------------------
void File_Dpx::Data_Parse()
{
    if (!IsDpx) // Is Cineon
    {
        switch (Element_Code)
        {
            case Pos_GenericSection   : GenericSectionHeader_Cineon(); break;
            case Pos_IndustrySpecific : IndustrySpecificHeader_Cineon(); break;
            case Pos_UserDefined      : UserDefinedHeader_Cineon(); break;
            case Pos_Padding          : Padding(); break;
            case Pos_ImageData        : ImageData(); break;
            default                   : ;
        }
    }
    else
    {
        switch (Element_Code)
        {
            case Pos_GenericSection   : GenericSectionHeader_Dpx(); break;
            case Pos_IndustrySpecific : IndustrySpecificHeader_Dpx(); break;
            case Pos_UserDefined      : UserDefinedHeader_Dpx(); break;
            case Pos_Padding          : Padding(); break;
            case Pos_ImageData        : ImageData(); break;
            default                   : ;
        }
    }

    do
        Sizes_Pos++; //We go automaticly to the next block
    while (Sizes_Pos<Sizes.size() && Sizes[Sizes_Pos]==0);
    if (Sizes_Pos>=Sizes.size())
    {
        Sizes.clear();
        Sizes_Pos=0;

        if (!Status[IsFilled])
            Fill();
        if (File_Offset+Buffer_Offset+Element_Size<Config->File_Current_Size)
            GoTo(Config->File_Current_Size);
    }
}
Beispiel #25
0
void 
BNavigator::MessageReceived(BMessage *message)
{
	switch (message->what) {
		case kNavigatorCommandBackward:
			GoBackward((modifiers() & B_OPTION_KEY) == B_OPTION_KEY);
			break;

		case kNavigatorCommandForward:
			GoForward((modifiers() & B_OPTION_KEY) == B_OPTION_KEY);
			break;

		case kNavigatorCommandUp:
			GoUp((modifiers() & B_OPTION_KEY) == B_OPTION_KEY);
			break;

		case kNavigatorCommandLocation:
			GoTo();
			break;
				
		default:
			{
				// Catch any dropped refs and try 
				// to switch to this new directory
				entry_ref ref;
				if (message->FindRef("refs", &ref) == B_OK) {
					BMessage message(kSwitchDirectory);
					BEntry entry(&ref, true);
					if (!entry.IsDirectory()) {
						entry.GetRef(&ref);
						BPath path(&ref);
							path.GetParent(&path);
							get_ref_for_path(path.Path(), &ref);
					}
					message.AddRef("refs", &ref);
					message.AddInt32("action", kActionSet);
					Window()->PostMessage(&message);
				}
			}
	}
}
Beispiel #26
0
/*!	\brief Finds the rightmost leaf node that may contain the supplied key.

	The method starts at the current node and only goes downwards.
	In the spanned subtree it finds the rightmost leaf node whose left
	delimiting key is not greater than the supplied key.

	\param key The key to be found.
	\param node Pointer to a pre-allocated LeafNode pointer that shall be set
		   to the found node.
	\return \c B_OK, if everything went fine.
*/
status_t
TreeIterator::FindRightMostLeaf(const VKey *k, LeafNode **node)
{
//printf("TreeIterator::FindRightMostLeaf()\n");
	status_t error = (k ? InitCheck() : B_BAD_VALUE);
	while (error == B_OK && fCurrentNode->IsInternal()) {
		int32 index = 0;
		error = _SearchRightMost(fCurrentNode->ToInternalNode(), k, &index);
		if (error == B_OK) {
			fIndex = index;
			error = GoTo(DOWN);
		}
	}
//if (error == B_OK)
//printf("found node: index: %ld\n", fIndex);
	// set the result
	if (error == B_OK && node)
		*node = fCurrentNode->ToLeafNode();
//printf("TreeIterator::FindRightMostLeaf() done: %s\n", strerror(error));
	return error;
}
void do_GMGoPC(CPC *a1, char *a2)
{
    CPC *v5; // [sp+20h] [bp-8h]@7

    if(a2 && *a2)
    {
        TrimString(a2);
        if(strcmp(a2, a1->Unk8))
        {
            for(int i = 0; i < gserver.Unk24.Unk32768; ++i)
            {
                v5 = gserver.Unk24.Unk0[i]; // gserver.Unk20[i + 1]
                if(v5 && !strcmp(v5->Unk8, a2))
                {
                    if(v5->Unk408 == a1->Unk408)
                    {
                        GoTo(a1, v5->Unk120.Unk16, v5->Unk120.Unk0, v5->Unk120.Unk4, a1->Unk412->GetHeight(v5->Unk120.Unk16, v5->Unk120.Unk0, v5->Unk120.Unk4), a1->Unk120.Unk12);
                    }
                    else
                    {
                        if(v5->Unk408->Unk0 != 2 && v5->Unk408->Unk0 != 5 && v5->Unk408->Unk0 != 6)
                        {
                            GoZone(a1, v5->Unk408->Unk0, v5->Unk120.Unk16, v5->Unk120.Unk0, v5->Unk120.Unk4);
                        }
                    }

                    return;
                }
            }

            CNetMsg v4;

            SayMsg(v4, 6, 0, "", "", "Not Found the PC");

            if(a1->Unk768)
                a1->Unk768->WriteToOutput(v4);
        }
    }
}
bool AgentControlComponent::OnGoTo(const BE::MouseButtonEvent& e)
{
	//! @hanstar17 : Temp!!
	//! entity/component's active state should be automatically considered.
	if (!GetOwner()->IsActive() || !IsActive())
		return false;

	if (e.action != BE::MouseAction::PRESSED)
		return false;

	BE::ICamera* cam = GetOwner()->GetLayer()
		->FindEntity("maincam")->GetC<BE::CameraComponent>()->GetCamera();
	if (!cam) return false;
	auto gtc = GetOwner()->GetLayer()
		->FindEntity("terrain")->GetC<GridTerrainComponent>();
	if (!gtc) return false;
	auto ac = GetOwner()->GetC<AgentComponent>();
	if (!ac) return false;

	glm::vec3 goalPos = gtc->GetMouseTerrainPos(cam);
	ac->GoTo(goalPos);
	return false;
}
//---------------------------------------------------------------------------
bool File::Open (const tstring &File_Name_, access_t Access)
{
    File_Name=File_Name_;

    #ifdef ZENLIB_USEWX
        File_Handle=(void*)new wxFile();
        if (((wxFile*)File_Handle)->Open(File_Name.c_str(), (wxFile::OpenMode)Access)==0)
        {
            //Sometime the file is locked for few milliseconds, we try again later
            wxMilliSleep(1000);
            if (((wxFile*)File_Handle)->Open(File_Name.c_str(), (wxFile::OpenMode)Access)==0)
                //File is not openable
                return false;
        }
        return true;
    #else //ZENLIB_USEWX
        #ifdef ZENLIB_STANDARD
            /*
            int access;
            switch (Access)
            {
                case Access_Read         : access=O_BINARY|O_RDONLY          ; break;
                case Access_Write        : access=O_BINARY|O_WRONLY|O_CREAT|O_TRUNC  ; break;
                case Access_Read_Write   : access=O_BINARY|O_RDWR  |O_CREAT  ; break;
                case Access_Write_Append : access=O_BINARY|O_WRONLY|O_CREAT|O_APPEND ; break;
                default                  : access=0                          ; break;
            }
            #ifdef UNICODE
                File_Handle=open(File_Name.To_Local().c_str(), access);
            #else
                File_Handle=open(File_Name.c_str(), access);
            #endif //UNICODE
            return File_Handle!=-1;
            */
            ios_base::openmode mode;
            switch (Access)
            {
                case Access_Read         : mode=ios_base::binary|ios_base::in; break;
                case Access_Write        : mode=ios_base::binary|ios_base::out; break;
                case Access_Read_Write   : mode=ios_base::binary|ios_base::in|ios_base::out; break;
                case Access_Write_Append : if (!Exists(File_Name))
                                                mode=ios_base::binary|ios_base::out;
                                           else
                                                mode=ios_base::binary|ios_base::out|ios_base::app;
                                           break;
                default                  : ;
            }
            #ifdef UNICODE
                File_Handle=new fstream(File_Name.To_Local().c_str(), mode);
            #else
                File_Handle=new fstream(File_Name.c_str(), mode);
            #endif //UNICODE
            if (!((fstream*)File_Handle)->is_open())
            {
                delete (fstream*)File_Handle; File_Handle=NULL;
                return false;
            }
            return true;
        #elif defined WINDOWS
            DWORD dwDesiredAccess, dwShareMode, dwCreationDisposition;
            switch (Access)
            {
                case Access_Read         : dwDesiredAccess=IsWin9X()?GENERIC_READ:FILE_READ_DATA; dwShareMode=FILE_SHARE_READ|FILE_SHARE_WRITE; dwCreationDisposition=OPEN_EXISTING; break;
                case Access_Write        : dwDesiredAccess=GENERIC_WRITE;   dwShareMode=0;                                 dwCreationDisposition=OPEN_ALWAYS;   break;
                case Access_Read_Write   : dwDesiredAccess=(IsWin9X()?GENERIC_READ:FILE_READ_DATA)|GENERIC_WRITE;   dwShareMode=0; dwCreationDisposition=OPEN_ALWAYS;   break;
                case Access_Write_Append : dwDesiredAccess=GENERIC_WRITE;   dwShareMode=0;                                 dwCreationDisposition=OPEN_ALWAYS;   break;
                default                  : dwDesiredAccess=0;               dwShareMode=0;                                 dwCreationDisposition=0;             break;
            }

            #ifdef UNICODE
                if (IsWin9X())
                    File_Handle=CreateFileA(File_Name.To_Local().c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
                else
                    File_Handle=CreateFileW(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
            #else
                File_Handle=CreateFile(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
            #endif //UNICODE
            if (File_Handle==INVALID_HANDLE_VALUE)
            {
                /*
                //Sometime the file is locked for few milliseconds, we try again later
                char lpMsgBuf[1000];
                DWORD dw = GetLastError();
                FormatMessageA(
                FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                dw,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                lpMsgBuf,
                1000, NULL );
                */
                Sleep(1000);
                #ifdef UNICODE
                    if (IsWin9X())
                        File_Handle=CreateFileA(Ztring(File_Name).To_Local().c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
                    else
                        File_Handle=CreateFileW(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
                #else
                    File_Handle=CreateFile(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
                #endif //UNICODE
            }
            if (File_Handle==INVALID_HANDLE_VALUE)
                //File is not openable
                return false;

            //Append
            if (Access==Access_Write_Append)
                GoTo(0, FromEnd);

            return true;
        #endif
    #endif //ZENLIB_USEWX
}
void do_GMGoNPC(CPC *a1, char *a2)
{
    float v10; // [sp+28h] [bp-40h]@31
    CNPC *v11; // [sp+2Ch] [bp-3Ch]@14
    CNPC *v12; // [sp+30h] [bp-38h]@27
    int v14; // [sp+38h] [bp-30h]@14
    float v15; // [sp+3Ch] [bp-2Ch]@14
    int v16; // [sp+40h] [bp-28h]@12
    int v17; // [sp+44h] [bp-24h]@12
    int v18; // [sp+48h] [bp-20h]@12
    int v19; // [sp+4Ch] [bp-1Ch]@12
    CArea *v22; // [sp+58h] [bp-10h]@12
    int v23; // [sp+5Ch] [bp-Ch]@10
    char v24; // [sp+63h] [bp-5h]@5
    char *s; // [sp+64h] [bp-4h]@4

    if(a2)
    {
        if(*a2)
        {
            TrimString(a2);
            s = a2;

            if(strlen(a2))
            {
                v24 = 0;
                while(*s)
                {
                    if(!(*(short *)(_ctype_b + 2 * *s) & 0x800))
                    {
                        v24 = 1;
                        break;
                    }
                    ++s;
                }

                v23 = -1;
                if(!v24)
                    v23 = atoi(a2);

                v22 = a1->Unk412;
                v19 = 0;
                v18 = v22->Unk12 - 1;
                v17 = 0;
                v16 = v22->Unk16 - 1;
                v14 = (v22->Unk16 < v22->Unk12) ? v22->Unk12 : v22->Unk16;
                v15 = v14 * 12.0;
                v11 = 0;

                CNetMsg v9;

                for(int i = v19; i <= v18; ++i)
                {
                    if(i >= 0 && i < v22->Unk12)
                    {
                        for(int j = v17; j <= v16; ++j)
                        {
                            if(j >= 0 && j < v22->Unk16)
                            {
                                for(CCharacter *k = v22->Unk28[i][j].Unk0; k; k = k->Unk404)
                                {
                                    if(k->Unk0 == 1)
                                    {
                                        if((v12 = (CNPC *)k, v23 == -1) && !strcmp(v12->Unk8, a2) || v23 != -1 && v12->Unk468 == v23)
                                        {
                                            v10 = GetDistance(a1, v12);

                                            //UNDEF(v3);
                                            //v4 = v10 < (long double)v15;
                                            //v5 = 0;
                                            //v6 = v10 == v15;

                                            //if((HIBYTE(v3) & 0x45) == 1)
                                            if(v15 > v10)
                                            {
                                                v15 = v10;
                                                v11 = v12;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if(v11)
                {
                    GoTo(a1, v11->Unk120.Unk16, v11->Unk120.Unk0, v11->Unk120.Unk4, a1->Unk412->GetHeight(v11->Unk120.Unk16, v11->Unk120.Unk0, v11->Unk120.Unk4), a1->Unk120.Unk12);
                }
                else
                {
                    SayMsg(v9, 6, 0, "", "", "Not Found the NPC");
                    if(a1->Unk768)
                        a1->Unk768->WriteToOutput(v9);
                }
            }
        }
    }
}