コード例 #1
0
ファイル: Builder.cpp プロジェクト: 2asoft/xray
BOOL SceneBuilder::MakeGame( )
{
	AnsiString error_text="";
	UI->ResetBreak();
	if(UI->ContainEState(esBuildLevel)) return false;
	ELog.Msg( mtInformation, "Making started..." );

    UI->BeginEState(esBuildLevel);
    try{
        do{
	        // clear error
            Tools->ClearDebugDraw();
	        // validate scene
    	    VERIFY_COMPILE(Scene->Validate(false,false,false,false,false,false),	"Validation failed.","Invalid scene.");
        	// build
            VERIFY_COMPILE(PreparePath(),				"Failed to prepare level path.","");
            VERIFY_COMPILE(GetBounding(),				"Failed to acquire level bounding volume.","");
            VERIFY_COMPILE(RenumerateSectors(), 		"Failed to renumerate sectors","");
            VERIFY_COMPILE(BuildLTX(),					"Failed to build level description.","");
            VERIFY_COMPILE(BuildGame(),					"Failed to build game.","");
        } while(0);

        if (!error_text.IsEmpty()) 	ELog.DlgMsg(mtError,error_text.c_str());
        else if (UI->NeedAbort())	ELog.DlgMsg(mtInformation,"Making terminated.");
        else						ELog.DlgMsg(mtInformation,"Making finished.");
    }catch(...){
    	ELog.DlgMsg(mtError,"Error has occured in builder routine. Editor aborted.");
        abort();
    }
    UI->EndEState();

	return error_text.IsEmpty();
}
コード例 #2
0
ファイル: FileSaver.cpp プロジェクト: xzrunner/easyeditor
void FileSaver::StoreAsGif(const std::string& src, const std::string& dst)
{
	if (ee::SymbolFile::Instance()->Type(src) != s2::SYM_ANIMATION) {
		return;
	}

	auto sym = ee::SymbolMgr::Instance()->FetchSymbol(src);
	auto anim = std::dynamic_pointer_cast<libanim::Symbol>(sym);

	sm::vec2 sz = sym->GetBounding().Size();
	AnimatedGifSaver saver(sz.x, sz.y);
	s2::DrawRT rt(sz.x, sz.y);

	int max_frame = anim->GetMaxFrameIdx();
	for (int i = 0; i < max_frame; ++i)
	{
		rt.Draw(*sym, true);
		uint8_t* rgb = rt.StoreToMemory(-1, -1, 3);
		//		anim->setFrameIndex(i + 1);
		saver.AddFrame(rgb, 1.0f / anim->GetFPS());
		delete[] rgb;
	}
	//	anim->setFrameIndex(0);
	saver.Save(dst.c_str());
}
コード例 #3
0
ファイル: Snapshoot.cpp プロジェクト: xzrunner/easyeditor
void Snapshoot::Build(const Database& db, const std::string& dir)
{
	const std::vector<Node*>& nodes = db.GetNodes();
	for (int i = 0, n = nodes.size();  i < n; ++i)
	{
		Node* node = nodes[i];
		if (node->Type() != NODE_LEAF) {
			continue;
		}

		LeafNode* leaf = static_cast<LeafNode*>(node);
		const std::string& path = leaf->GetPath();

		std::string out_path = dir + "\\" + path;
		out_path = out_path.substr(0, out_path.find_last_of("."));
		out_path += "_ss.png";

		std::string dir = gum::FilepathHelper::Dir(out_path);
		if (!wxDir::Exists(dir)) {
			wxFileName::Mkdir(dir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
		}

		s2::DrawRT rt;
		std::string ori_path = db.GetDirPath() + "\\" + path;
		auto sym = ee::SymbolMgr::Instance()->FetchSymbol(ori_path);
		rt.Draw(*sym);

		sm::vec2 sz = sym->GetBounding().Size();
		rt.StoreToFile(out_path, sz.x, sz.y);
	}
}
コード例 #4
0
ファイル: SelectNodesOP.cpp プロジェクト: xzrunner/easyeditor
void SelectNodesOP::RectQueryVisitor::
Visit(const ee::ShapePtr& shape, bool& next)
{
	auto polyline = std::dynamic_pointer_cast<EditedPolyShape>(shape);
	if (!polyline) {
		next = true;
		return;
	}

	if (sm::is_rect_intersect_rect(polyline->GetBounding(), m_rect))
	{
		ChainSelectedNodes* result = new ChainSelectedNodes;
		result->polyline = polyline;

		auto& vertices = polyline->GetVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (sm::is_point_in_rect(vertices[i], m_rect))
				result->selectedNodes.push_back(vertices[i]);
		}

		if (result->selectedNodes.empty())
			delete result;
		else
			m_result.push_back(result);
	}

	next = true;
}
コード例 #5
0
ファイル: SelectNodesOP.cpp プロジェクト: xzrunner/easyeditor
void SelectNodesOP::PosQueryVisitor::
Visit(const ee::ShapePtr& shape, bool& next)
{
	auto polyline = std::dynamic_pointer_cast<EditedPolyShape>(shape);
	if (!polyline) {
		next = true;
		return;
	}

	if (sm::is_rect_intersect_rect(polyline->GetBounding(), m_rect))
	{
		auto& vertices = polyline->GetVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (sm::dis_pos_to_pos(m_pos, vertices[i]) < SelectNodesOP::GetThreshold())
			{
				ChainSelectedNodes* result = new ChainSelectedNodes;
				result->polyline = polyline;
				result->selectedNodes.push_back(vertices[i]);
				*m_result = result;

				next = false;
				return;
			}
		}
	}

	next = true;
}
コード例 #6
0
ファイル: Frame.cpp プロジェクト: xzrunner/easyeditor
void Frame::SaveAsPNG(const std::string& filepath) const
{
	auto sym = ((StagePanel*)(m_task->GetEditPanel()))->GetSymbol();
	sm::vec2 sz = sym->GetBounding().Size();
	s2::DrawRT rt(sz.x, sz.y);
	rt.Draw(*sym);
	rt.StoreToFile(filepath.c_str(), sz.x, sz.y);
}
コード例 #7
0
ファイル: Builder.cpp プロジェクト: OLR-xray/OLR-3.0
//------------------------------------------------------------------------------
BOOL SceneBuilder::Compile()
{
	AnsiString error_text="";
	UI->ResetBreak();
	if(UI->ContainEState(esBuildLevel)) return false;
	ELog.Msg( mtInformation, "Building started..." );

    UI->BeginEState(esBuildLevel);
    try{
        do{
//.			ExecCommand( COMMAND_RESET_ANIMATION );
	        // check debug
            bool bTestPortal = Scene->ObjCount(OBJCLASS_SECTOR)||Scene->ObjCount(OBJCLASS_PORTAL);
	        // validate scene
    	    VERIFY_COMPILE(Scene->Validate(false,bTestPortal,true,true,true,true),"Validation failed.","Invalid scene.");
			// fill simple hemi
            simple_hemi.clear	();
	        xrHemisphereBuild	(1,2.f,simple_hemi_callback,&simple_hemi);
        	// build
            VERIFY_COMPILE		(PreparePath(),				"Failed to prepare level path","");
            VERIFY_COMPILE		(PrepareFolders(),			"Failed to prepare level folders","");
            VERIFY_COMPILE		(EvictResource(),	  		"Failed to evict resource","");
            VERIFY_COMPILE		(GetBounding(),				"Failed to acquire level bounding volume","");
            VERIFY_COMPILE		(RenumerateSectors(), 		"Failed to renumerate sectors","");
            VERIFY_COMPILE		(CompileStatic(),	  		"Failed static remote build","");
            VERIFY_COMPILE		(EvictResource(),	  		"Failed to evict resource","");
            VERIFY_COMPILE		(BuildLTX(),		  		"Failed to build level description","");
            VERIFY_COMPILE		(BuildGame(),		  		"Failed to build game","");
            VERIFY_COMPILE		(BuildSceneStat(),			"Failed to build scene statistic","");
            BuildHOMModel		();
            BuildSOMModel		();
    	    // build tools
            SceneToolsMapPairIt _I 	= Scene->FirstTools();
            SceneToolsMapPairIt _E	= Scene->LastTools();
            for (; _I!=_E; _I++){
            	if (_I->first!=OBJCLASS_DUMMY){
                    if (_I->second->Valid()){                                  
                        VERIFY_COMPILE(_I->second->Export(m_LevelPath),_I->second->ClassDesc(),"export failed.");
                        ELog.Msg(mtInformation,"Process %s - done.",_I->second->ClassDesc());
                    }else{
                        ELog.Msg(mtError,"Process %s - failed.",_I->second->ClassDesc());
                    }
                }
            }
		    Clear			();
        } while(0);

        if (!error_text.IsEmpty()) 	ELog.DlgMsg(mtError,error_text.c_str());
        else if (UI->NeedAbort())	ELog.DlgMsg(mtInformation,"Building terminated.");
        else						ELog.DlgMsg(mtInformation,"Building OK.");
    }catch(...){
    	ELog.DlgMsg(mtError,"Error has occured in builder routine. Editor aborted.");
        abort();
    }
    UI->EndEState();

	return error_text.IsEmpty();
}
コード例 #8
0
ファイル: StagePanel.cpp プロジェクト: xzrunner/easyeditor
void StagePanel::StoreToFile(const char* filename) const
{
	std::string name = filename;
	name = name.substr(0, name.find_last_of('_'));

	std::string dir = ee::FileHelper::GetFileDir(filename);

	// items complex
	auto items_complex = std::make_shared<ecomplex::Symbol>();
	std::vector<ee::SprPtr> sprs;
	TraverseSprites(ee::FetchAllRefVisitor<ee::Sprite>(sprs));
	for (int i = 0, n = sprs.size(); i < n; ++i) {
		items_complex->Add(sprs[i]);
	}
	std::string items_path = name + "_items_complex[gen].json";
	items_complex->SetFilepath(items_path);
	ecomplex::FileStorer::Store(items_path, *items_complex, ee::FileHelper::GetFileDir(items_path));
//	items_complex.InitBounding();

	// wrapper complex
	auto items_sprite = std::make_shared<ecomplex::Sprite>(items_complex);
	items_sprite->SetName("anchor");
	ecomplex::Symbol wrapper_complex;
	wrapper_complex.SetScissor(m_clipbox);
	wrapper_complex.Add(items_sprite);
	std::string top_path = name + "_wrapper_complex[gen].json";
	wrapper_complex.SetFilepath(top_path);
	ecomplex::FileStorer::Store(top_path, wrapper_complex, ee::FileHelper::GetFileDir(top_path));

	// ui
	std::string ui_path = filename;
	Json::Value value;
	value["type"] = get_widget_desc(ID_WRAPPER);
	value["items filepath"] = ee::FileHelper::GetRelativePath(dir, items_path);
	value["wrapper filepath"] = ee::FileHelper::GetRelativePath(dir, top_path);
	value["user type"] = m_toolbar->GetType();
	value["tag"] = m_toolbar->GetTag();
	sm::vec2 cb_sz = m_clipbox.Size();
	value["clipbox"]["w"] = cb_sz.x;
	value["clipbox"]["h"] = cb_sz.y;
	value["clipbox"]["x"] = m_clipbox.xmin;
	value["clipbox"]["y"] = m_clipbox.ymax;
	sm::vec2 c_sz = items_sprite->GetBounding().GetSize().Size();
	value["children"]["w"] = c_sz.x;
	value["children"]["h"] = c_sz.y;
	Json::StyledStreamWriter writer;
	std::locale::global(std::locale(""));
	std::ofstream fout(ui_path.c_str());
	std::locale::global(std::locale("C"));	
	writer.write(fout, value);
	fout.close();
}
コード例 #9
0
ファイル: FileSaver.cpp プロジェクト: xzrunner/easyeditor
void FileSaver::StoreAsPng(const std::string& src, const std::string& dst)
{
	if (ee::SymbolFile::Instance()->Type(src) != s2::SYM_ANIMATION) {
		return;
	}

	auto sym = ee::SymbolMgr::Instance()->FetchSymbol(src);

	sm::vec2 sz = sym->GetBounding().Size();
	s2::DrawRT rt(sz.x, sz.y);
	rt.Draw(*sym);
	rt.StoreToFile(dst.c_str(), sz.x, sz.y);
}
コード例 #10
0
ファイル: BezierShape.cpp プロジェクト: xzrunner/easyeditor
void BezierShape::Mirror(bool x, bool y)
{
	sm::vec2 center = GetBounding().Center();
	for (int i = 0; i < CTRL_NODE_COUNT; ++i) 
	{
		if (x) {
			m_control_nodes[i].x = center.x * 2 - m_control_nodes[i].x;
		}
		if (y) {
			m_control_nodes[i].y = center.y * 2 - m_control_nodes[i].y;			
		}
	}
	UpdatePolyline();
}
コード例 #11
0
ファイル: bouyobject.cpp プロジェクト: ShowLove/Robotics_Club
bool BouyObject::GetVisionReturn(const IplImage * imgIn, Vision::Return& result, IplImage * debugOut) const
{

    std::list<CvBox2D> blobList = GetBounding(imgIn);
    result.mValid = false;
    if(blobList.size() == 0) return false;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1,1);
    for(std::list<CvBox2D>::iterator it = blobList.begin(); it != blobList.end(); it++)
    {
        result.mCenterI = it->center.x;
        result.mCenterJ = it->center.y;
        result.mArea = it->size.width * it->size.height;
        result.mValid = true;
        result.mAngle = VisionUtils::GetAngle(*it);
        result.mAngle = -result.mAngle;
        if(debugOut)
        {
            std::ostringstream s;
            s << "Area(" << result.mArea << ")";
            cvPutText(debugOut,s.str().c_str(),cvPointFrom32f(it->center),&font,mNearColor);
            Zebulon::Vision::VisionUtils::DrawSquare(debugOut,*it,mNearColor);
        }
    }
    return true;
//    double mCenterI;    ///< I is like X 0 to width = left to right
//    double mCenterJ;    ///< J is like Y 0 to height  top to bottom
//    int mArea;          ///< Area in pixels, either pixel count or width*height of bounding box
//    double mAngle;      ///< Angle in degrees [-90, 90] positive to the right, negative left.

//    int mValid;         ///< Valid is an on or off (or boolean) if something is detected
//    double mConfidence; ///< Confidence in identification of target, higher is better

//    double mMinI;   ///< Bounding Box furthest left column index.
//    double mMinJ;   ///< Bounding Box lowest row value (lower value higher up).
//    double mMaxI;   ///< Bounding Box furthest right column index (higher value right).
//    double mMaxJ;   ///< Bounding Box highest row value (higher value is towards picture bottom).
}
コード例 #12
0
ファイル: pathobject.cpp プロジェクト: shening/Robotics_Club
std::vector<Vision::Return> PathObject::GetVisionReturn(const IplImage * imgIn, IplImage * debugOut) const
{

    std::list<CvBox2D> blobList = GetBounding(imgIn);
    std::vector<Vision::Return> resultList;
    Vision::Return right, left;
    CvBox2D cvright, cvleft;
    CvFont font;
    bool foundone=false;
    int count = 0;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, .5,1);
    for(std::list<CvBox2D>::iterator it = blobList.begin(); it != blobList.end(); it++)
    {
        count++;
        Vision::Return result;
        result.mCenterI = it->center.x;
        result.mCenterJ = it->center.y;
        result.mArea = it->size.width * it->size.height;
        result.mValid = true;
        result.mAngle = VisionUtils::GetAngle(*it);
        if(!foundone)
        {
            foundone = true;
            right = result;
            left = result;
            cvright = *it;
            cvleft = *it;
        }
        else
        {
            if(result.mCenterI > right.mCenterI)
            {
                right = result;
                cvright = *it;
            }
            else
            {
                left = result;
                cvleft = *it;
            }
        }
        if(count == 2) break;
    }
    if(count >= 1)
    {
        resultList.push_back(right);
        //resultList.push_back(result);
        if(debugOut)
        {
            std::ostringstream s;
            s << "Angle(" << right.mAngle << ") Area(" << right.mArea << ") " << mType << " Right";
            cvPutText(debugOut,s.str().c_str(),cvPointFrom32f(cvright.center),&font,mNearColor);
            Zebulon::Vision::VisionUtils::DrawSquare(debugOut,cvright,mNearColor);
        }
    }
    if(count >= 2)
    {
        resultList.push_back(left);
        //resultList.push_back(result);
        if(debugOut)
        {
            std::ostringstream s;
            s << "Angle(" << left.mAngle << ") Area(" << left.mArea << ") " << mType << " Left";
            cvPutText(debugOut,s.str().c_str(),cvPointFrom32f(cvleft.center),&font,mNearColor);
            Zebulon::Vision::VisionUtils::DrawSquare(debugOut,cvleft,mNearColor);
        }
    }
    return resultList;
//    double mCenterI;    ///< I is like X 0 to width = left to right
//    double mCenterJ;    ///< J is like Y 0 to height  top to bottom
//    int mArea;          ///< Area in pixels, either pixel count or width*height of bounding box
//    double mAngle;      ///< Angle in degrees [-90, 90] positive to the right, negative left.

//    int mValid;         ///< Valid is an on or off (or boolean) if something is detected
//    double mConfidence; ///< Confidence in identification of target, higher is better

//    double mMinI;   ///< Bounding Box furthest left column index.
//    double mMinJ;   ///< Bounding Box lowest row value (lower value higher up).
//    double mMaxI;   ///< Bounding Box furthest right column index (higher value right).
//    double mMaxJ;   ///< Bounding Box highest row value (higher value is towards picture bottom).
}