Exemplo n.º 1
0
void GameManager::LoadUserData()
{
	if (mUserData.Load("profile/settings", false) == 2)
	{
		// a new settings file has been generated. Write defaults
		mUserData.SetValue("MapSettings", "Timestamps", "1");
		mUserData.SetValue("MapSettings", "PrivMsg", "1");
		mUserData.SetValue("MapSettings", "ShowNames", "0");
		mUserData.SetValue("MapSettings", "ShowAddresses", "0");
		mUserData.SetValue("MapSettings", "JoinParts", "1");

		mUserData.SetValue("System", "LowCpu", its(gui->mUseLowCpu));
		mUserData.SetValue("System", "NoLimit", its(gui->mNoFpsLimit));
		mUserData.SetValue("System", "FPS", its(gui->mFpsCap));
		mUserData.SetValue("System", "Alerts", its(gui->mSystemAlertType));

		mUserData.SetValue("Login", "Remember", "0");
		mUserData.SetValue("Login", "ID", "");
		mUserData.SetValue("Login", "Password", "");
	}
	else // configure things based on settings values
	{
		// Override gui defaults with our configs
		gui->mUseLowCpu = sti(mUserData.GetValue("System", "LowCpu"));
		gui->mNoFpsLimit = sti(mUserData.GetValue("System", "NoLimit"));
		gui->mFpsCap = sti(mUserData.GetValue("System", "FPS"));
		gui->mSystemAlertType = sti(mUserData.GetValue("System", "Alerts"));
	}
}
Exemplo n.º 2
0
void Timer::start(double f) {
    itimerspec its(to_itspec(f));

    if (timer_settime(_p->sys_timer, 0, &its, NULL) == -1) {
        perror("timer_settime");
    }
}
Exemplo n.º 3
0
void GameManager::UpdateAppTitle()
{
	string title = "fro [Build ";
	title += VER_STRING;
	title += "]";

	if (mNet && mNet->IsConnected())
	{
		title += " (" + ((mNet->mRealServerAddress.empty()) ? mNet->mHost : mNet->mRealServerAddress)
				+ ":" + its(mNet->mPort);
		//if (mNet->GetState() == ONCHANNEL && mNet->GetChannel())
		//	title += " - " + mNet->GetChannel()->mId;

		if (mMap)
			title += " - " + mMap->mId;


		if (mNet->GetState() != ONCHANNEL)
			title += " (local)";

		title += ")";
	}

	DEBUGOUT("Setting Title: " + title);

	gui->SetAppTitle(title);
}
Exemplo n.º 4
0
void Start::addMessage(String message, Color c) {
    std::pair<String, Color> completeMess = std::make_pair(message, c);
    static int forbs = 1;
    int ind = messages.size() - 1;
    if (ind > 0 && messages[ind].first.substr(0, message.size()) == message) {
        forbs++;
        messages[ind].first = message + " x" + its(forbs);
    } else {
        forbs = 1;
        Color c1, c2;
        if (messages.size() >= 2) {
            c1 = messages[ind].second;
            c2 = messages[ind - 1].second;
        }
        if (messages.size() >= 2 && c1.red == c2.red && c1.blue == c2.blue && c1.green == c2.green && messages[ind].first.size() + messages[ind - 1].first.size() < MESSAGE_LEN_LIMIT) {
            messages[ind - 1].first = messages[ind - 1].first + " " + messages[ind].first;
            messages[ind] = completeMess;
        } else {
            messages.push_back(completeMess);
            if (messages.size() > MAX_MESSAGES) {
                messages.erase(messages.begin());
            }
        }
    }
}
Exemplo n.º 5
0
int main()
{
	int db = 0;
	for (int n=2;n<=10000;n++)
	{
		int sqrtn = sqrt(n);
		if (sqrtn*sqrtn != n)
		{
			deque<Iter> its(1,Iter(1,sqrtn));
			
			bool done = false;
			
			while (!done)
			{
				C(its.size()-1)
					if (its[i] == its.back())
					{
						done = true;
						if ((its.size()-i-1)%2 == 1)
							db++;
						break;
					}
				
				its.push_back(its.back().getNext(n,sqrtn));
			}
		}
	}
Exemplo n.º 6
0
DamageIcon::DamageIcon()
{
    mType = ENTITY_DAMAGEICON;
    //mId = its(amount);

    Image* img = resman->LoadImg("assets/dmg_font.png");
    mFontImage = img->Clone(true);
    resman->Unload(img); //dereference it, since we no longer touch the original

    // Background image will be a random one from the pool
    LoadImage("assets/dmg_bg" + its(rnd(0, 4)) + ".png");

    // Determine letter sizes based on pink pixels found.
    // Create an array to store this info for quicker access later
    color c;
    for (int x = 0; x < mFontImage->Width(); ++x)
    {
        c = mFontImage->GetPixel(x, 0);
        if (c.r == 255 && c.g == 0 && c.b == 255) //pink!
            mBorders.push_back(x);
    }

    // Colorize our version to suit our needs
    //mFontImage->ColorizeGreyscale(fontRgb);
    //mImage->ColorizeGreyscale(bgRgb);

    // Add timer to destroy this entity after some constant time
    timers->Add("", DAMAGE_ICON_TTL, false,
                timer_DeleteDamageIcon, NULL, this);
    timers->Add("", DAMAGE_ICON_THINK, false,
                timer_DamageIconThink, NULL, this);

    mOrigin.y = mImage->Height();
    mOrigin.x = mImage->Width()/2;
}
Exemplo n.º 7
0
// Referenced entity is always the first parameter of the state.
// This should always return a valid entity pointer. If it's invalid, there will be a longjmp from within lua.
Entity* _getReferencedEntity(lua_State* ls, int index = 1)
{

	Entity* e = NULL;

	if (lua_istable(ls, index))
	{
		// try to pull the pointer from the table
		lua_pushstring(ls, "__centity");
		lua_gettable(ls, index);
		e = (Entity*)(lua_touserdata(ls, -1));
		lua_pop(ls, 1);
	}
	else // assume userdata
	{
		e = (Entity*)(lua_touserdata(ls, index));
		if (!_verifyEntity(e))
		{
			string err = "index " + its(index) + " not a valid entity pointer.";
			luaError(ls, "", err);
		}
	}

	return e;
}
Exemplo n.º 8
0
string page_mapper::nhp_compile(const char *f, FILE*& nhpf, FILE*& tmf)
{
	fseek(nhpf, 0, SEEK_END);
	int size = ftell(nhpf);
	rewind(nhpf);
	string com;
	com.resize(size);
	size = fread((char*)com.c_str(), 1, size, nhpf);
	fclose(nhpf);
	string out = parse_nhp(com);

	fwrite(out.c_str(), 1, out.size(), tmf);
	fclose(tmf);
	nativehttp::data::superstring pgnam(f);
	pgnam.change(".nhp", "nhp");
	pgnam.pos = pgnam.str.size() - 1;
	string pname = pgnam.back_to("/");
	srand(rand());
	pname += its(rand());
	string command = cfg->get_var("cppcmp") + " -shared -fPIC " + cfg->get_var("flags") + " -I"+http::nhpc_include_dir+" -o "+ temp_dir +"nativehttp/nhpage_" + pname + ".so /tmp/nativehttp/tmp.cpp";
	bool shw;
	if (cfg->get_int("cmpout") == 1)
	{
		shw = true;
	}
	else
	{
		shw = false;
	}
	if (shw)
	{
		cout << "Compile " << f << ":" << endl;
		cout << command.c_str() << endl;
	}
	FILE *cmp = NULL;
	if (!(cmp = popen(command.c_str(), "r")))
	{
		cerr << "CAN'T OPEN " << cfg->get_var("cppcmp").c_str() << endl;
	}
	char b[256];
	string cmout;
	while (fgets(b, 256, cmp) != NULL)
	{
        cmout+=b;
		if (shw)
		{
			cout << b;
		}
	}
	if(pclose(cmp)!=0)
	{
        nativehttp::server::err("nhp.cpp@pagemap","NHP compilation failed: "+string(f)+", output above");
        abort = true;
	}
	cmout.clear();
	return (temp_dir+"nativehttp/nhpage_" + pname + ".so");

}
Exemplo n.º 9
0
Arquivo: du.c Projeto: lovasko/libtabl
int
main(int argc, char* argv[])
{
	DIR* dir;
	FILE* output;
	int size;
	struct dirent* de;
	m_list values;
	struct stat st;
	tabl t;
	char* size_str;

	if ((dir = opendir(".")) == NULL) {
		fprintf(stderr, "Unable to open '.'.\n");
		return EXIT_FAILURE;
	}

	switch (argc) {
		case 1:
			output = NULL;
		break;

		case 2:
			if ((output = fopen(argv[1], "w")) == NULL) {
				fprintf(stderr, "Unable to open the file '%s'.\n", argv[1]);
				return EXIT_FAILURE;
			}
		break;

		default:
			fprintf(stderr, "Wrong arguments.\nUsage: du [path]\n");
		return EXIT_FAILURE;
	}
	
	tabl_init(&t, 0);
	tabl_add_column(&t, "File", NULL, TABL_ALIGN_LEFT);
	tabl_add_column(&t, "Size", NULL, TABL_ALIGN_LEFT);

	m_list_init(&values);
	do {
		if ((de = readdir(dir)) != NULL) {
			stat(de->d_name, &st);
			size = (int)st.st_size;
			size_str = its(&size, ITS_SIZE_INT, ITS_SIGNED, ITS_BASE_DEC);
					
			m_list_remove_all(&values);
			m_list_append(&values, M_LIST_COPY_DEEP, de->d_name, strlen(de->d_name)+1);
			m_list_append(&values, M_LIST_COPY_DEEP, size_str, strlen(size_str)+1);
			tabl_add_row(&t, &values);

			free(size_str);
		}
	} while (de != NULL);

	tabl_sort(&t, 0, string_compare);
	tabl_render(&t, output);
	return EXIT_SUCCESS;
}
Exemplo n.º 10
0
//Callback for node save x3d menu choice.
void H3DViewerPopupMenus::OnTreeViewSaveTrianglesX3D( wxCommandEvent& event ) {
  wxTreeItemId id = treeview_dialog->TreeViewTree->GetSelection();
  
  H3DViewerTreeViewDialog::TreeIdMap::iterator ni = treeview_dialog->node_map.find( id.m_pItem );
  if( ni == treeview_dialog->node_map.end() ) {
    wxMessageBox( wxT("Selected tree item is not a node"),
                  wxT("Error"),
                  wxOK | wxICON_EXCLAMATION);
  } else {
    wxFileDialog *file_dialog = new wxFileDialog ( this,
                                                   wxT("File to save as.."),
                                                   wxT(""),
                                                   wxT(""),
                                                   wxT("*.*"),
                                                   wxFD_SAVE,
                                                   wxDefaultPosition) ;

    if (file_dialog->ShowModal() == wxID_OK) {
      std::string filename(file_dialog->GetPath().mb_str());
      std::ofstream os( filename.c_str() );
      if( os.fail() ) {
        wxMessageBox( wxT("Unable to open selected file"), 
                      wxT("Error"),
                      wxOK | wxICON_EXCLAMATION);
      }
      
      try {
        Node *n = (*ni).second.get();

        AutoRef< IndexedTriangleSet > its( new IndexedTriangleSet );

        vector< Vec3f > triangles;
        triangles.reserve( 200 );
        treeview_dialog->collectAllTriangles( n, Matrix4f(), triangles ); 

        Coordinate *c = new Coordinate;
        c->point->setValue( triangles );
        vector< int > indices;
        indices.reserve( triangles.size() );
        for( unsigned int i = 0; i < triangles.size(); ++i ) {
          indices.push_back( i );
        }

        its->coord->setValue( c );
        its->index->setValue( indices );
       
        X3D::writeNodeAsX3D( os, its.get() );
      } catch (const Exception::H3DException &e) {
        stringstream s;
        s << e;
        wxMessageBox( wxString(s.str().c_str(),wxConvUTF8), wxT("Error"),
                      wxOK | wxICON_EXCLAMATION);
      }
      os.close();
    }
  }
}
Exemplo n.º 11
0
void output_tag_attributes(std::string& out, const TreeNode& tag) {
	std::list<TreeAttribute>::const_iterator itAtt(tag.mAttribs.begin()), itAttEnd(tag.mAttribs.end());
	bool is_anchor = (tag.mName == "a");
	
	for(; itAtt!=itAttEnd; ++itAtt) {
		const TreeAttribute& att = *itAtt;

		out += ' ';
		out += att.mName;

		if (!att.mbNoValue) {
			std::string::const_iterator its(att.mValue.begin()), itsEnd(att.mValue.end());
			for(;its!=itsEnd; ++its)
				if (!issafevaluechar(*its))
					break;

			std::string value(att.mValue);

			if (is_anchor && att.mName == "href") {
				std::list<std::pair<std::string, bool> >::const_iterator it(g_truncateURLs.begin()), itEnd(g_truncateURLs.end());

				for(; it!=itEnd; ++it) {
					const std::pair<std::string, bool>& entry = *it;

					if (value.length() >= entry.first.length() && !value.compare(0, entry.first.length(), entry.first)) {
						if (entry.second) {
							int l = value.length();

							while(l>0) {
								char c = value[--l];

								if (c == '/' || c == ':')
									break;
								if (c == '.') {
									if (value.substr(l+1, std::string::npos) == "html")
										value.erase(l, std::string::npos);
									break;
								}
							}
							printf("truncated link: %s\n", value.c_str());
						}
						break;
					}
				}
			}

			if (att.mValue.empty() || its!=itsEnd) {
				out += "=\"";
				out += value;
				out += '"';
			} else {
				out += '=';
				out += value;
			}
		}
	}
}
Exemplo n.º 12
0
char*
get_ppid(struct ps_proc* proc)
{
	if (proc->p_pptr != NULL)
		return its(&proc->p_pptr->p_pid,
			         ITS_SIZE_INTMAX,
		           ITS_SIGNED,
		           ITS_BASE_DEC);
	else
		return "-";
}
Exemplo n.º 13
0
Arquivo: Glob.cpp Projeto: 119/vdc
bool Glob::match(const std::string& subject)
{
	UTF8Encoding utf8;
	TextIterator itp(_pattern, utf8);
	TextIterator endp(_pattern);
	TextIterator its(subject, utf8);
	TextIterator ends(subject);
	
	if ((_options & GLOB_DOT_SPECIAL) && its != ends && *its == '.' && (*itp == '?' || *itp == '*'))
		return false;
	else
		return match(itp, endp, its, ends);
}
Exemplo n.º 14
0
/* entity = Entity.Create(entityInfoTable, x<nil>, y<nil>);
	Create a new entity instance and place it on the map at (x, y)
	If (x, y) are nil, it will create a new entity and return it, but NOT
	add it to the map. It's our responsibility to do Entity.Add(ent, x, y)
	later, or to do something else special with it (Such as adding to the
	players party)
*/
int entity_Create(lua_State* ls)
{
	Entity* e;
	point2d p;

	// Make sure they passed in a table as the first parameter
	if (!lua_istable(ls, 1))
	{
		return luaError(ls, "Entity.Create", "First param must be a table");
	}

	// Grab t.Type and create an entity associated with that type
	lua_pushstring(ls, "Type");
	lua_gettable(ls, 1);
	int type = (int)lua_tonumber(ls, -1);
	lua_pop(ls, 1);

	// Create the entity class based on the type provided

	e = _createEntity(type);
	if (!e)
	{
		return luaError(ls, "Entity.Create", "Invalid type: " + its(type));
	}

	// Configure the class via all the properties the class defines
	if (!_parseEntityProperties(ls, e, 1))
	{
		return luaError(ls, "Entity.Create", "Error parsing properties");
	}

	int count = lua_gettop(ls);

	if (count > 1)
	{
		//Finally, add it to the map and return a reference to it
		e->mMap = game->mMap;
		game->mMap->AddEntity(e);

		p.x = (int)lua_tonumber(ls, 2);
		p.y = (int)lua_tonumber(ls, 3);

		e->SetPosition(p);
	}

	lua_pushlightuserdata(ls, e);
	return 1;
}
void test_serialization(const MultiIndexContainer& m)
{
  typedef typename MultiIndexContainer::iterator       iterator;
  typedef typename MultiIndexContainer::const_iterator const_iterator;

  std::ostringstream oss;
  {
    boost::archive::text_oarchive oa(oss);
    oa<<m;

    std::vector<const_iterator> its(m.size());
    const_iterator              it_end=m.end();
    for(const_iterator it=m.begin();it!=it_end;++it){
      its.push_back(it);
      oa<<const_cast<const const_iterator&>(its.back());
    }
    oa<<const_cast<const const_iterator&>(it_end);
  }

  MultiIndexContainer m2;
  std::istringstream iss(oss.str());
  boost::archive::text_iarchive ia(iss);
  ia>>m2;
  BOOST_TEST(all_indices_equal(m,m2));

  iterator it_end=m2.end();
  for(iterator it=m2.begin();it!=it_end;++it){
    iterator it2;
    ia>>it2;
    BOOST_TEST(it==it2);

    /* exercise safe mode with this (unchecked) iterator */
    BOOST_TEST(*it==*it2);
    m2.erase(it,it2);
    m2.erase(it2,it2);
    m2.erase(it2,it);
    iterator it3(++it2);
    iterator it4;
    it4=--it2;
    BOOST_TEST(it==it4);
    BOOST_TEST(it==boost::multi_index::project<0>(m2,it4));
  }
  iterator it2;
  ia>>it2;
  BOOST_TEST(it_end==it2);
  BOOST_TEST(it_end==boost::multi_index::project<0>(m2,it2));
}
Exemplo n.º 16
0
int
main(int argc, char** argv)
{
	struct passwd* pwd;
	tabl t;
	m_list values;
	unsigned int width;
	char* uid_str;

	switch (argc) {
		case 1:
			width = 0;
		break;

		case 2:
			width = atoi(argv[1]);
		break;

		default:
			fprintf(stderr, "Wrong arguments.\nUsage: passwd [width]\n");
		return EXIT_FAILURE;
	}

	tabl_init(&t, width);
	tabl_add_column(&t, "UID", NULL, TABL_ALIGN_RIGHT);
	tabl_add_column(&t, "Name", NULL, TABL_ALIGN_LEFT);
	tabl_add_column(&t, "Directory", NULL, TABL_ALIGN_LEFT);
	tabl_add_column(&t, "Shell", NULL, TABL_ALIGN_LEFT);

	m_list_init(&values);
	while ((pwd = getpwent()) != NULL) {
		uid_str = its(&pwd->pw_uid, sizeof(uid_t)*8, ITS_UNSIGNED, ITS_BASE_DEC);

		m_list_remove_all(&values);
		m_list_append(&values, M_LIST_COPY_DEEP, uid_str, strlen(uid_str)+1);
		m_list_append(&values, M_LIST_COPY_DEEP, pwd->pw_name, strlen(pwd->pw_name)+1);
		m_list_append(&values, M_LIST_COPY_DEEP, pwd->pw_dir, strlen(pwd->pw_dir)+1);
		m_list_append(&values, M_LIST_COPY_DEEP, pwd->pw_shell, strlen(pwd->pw_shell)+1);
		tabl_add_row(&t, &values);

		free(uid_str);
	}
	endpwent();

	tabl_render(&t, NULL);
	return EXIT_SUCCESS;
}
Exemplo n.º 17
0
void Texture::evalGradient(const Intersection &_its, Spectrum *gradient) const {
	const Float eps = Epsilon;
	Intersection its(_its);

	Spectrum value = eval(its, false);

	its.p = _its.p + its.dpdu * eps;
	its.uv = _its.uv + Point2(eps, 0);
	Spectrum valueU = eval(its, false);

	its.p = _its.p + its.dpdv * eps;
	its.uv = _its.uv + Point2(0, eps);
	Spectrum valueV = eval(its, false);

	gradient[0] = (valueU - value)*(1/eps);
	gradient[1] = (valueV - value)*(1/eps);
}
Exemplo n.º 18
0
IntersecResult *collectIntersections(HR *h)
{
    HR::Intersections its(std::move(h->intersections()));
    IntersecResult *result = new IntersecResult;

    result->intersectsNum = its.size();
    result->intersectSize = (result->intersectsNum > 0) ? its.begin()->size() : 0;
    result->data = new ObjectID[result->intersectsNum * result->intersectSize];

    unsigned i = 0;
    for (const HR::Intersec &intersec : its)
    {
        for (ObjectID v : intersec)
        {
            result->data[i++] = v;
        }
    }
    assert(i == result->intersectsNum * result->intersectSize);

    return result;
}
Exemplo n.º 19
0
void OptionsDialog::_buildFrameGraphics()
{
	Input* i;
	Checkbox* c;
	int y = 0;

	mFrameGraphics->mSortable = false;
	
	new Label(mFrameGraphics, "", rect(0,y), "FPS Cap");
	i = new Input(mFrameGraphics, "fps", rect(95, y, 150, 20), "0123456789", 0, true, NULL);
		i->SetText( its(gui->mFpsCap) );
	y += 25;

	c = new Checkbox(mFrameGraphics, "lowcpu", rect(0,y), "Use Lower Cpu When Inactive", 0);
		c->SetState( gui->mUseLowCpu );
	y += 25;
		
	c = new Checkbox(mFrameGraphics, "nolimit", rect(0,y), "Max Speed (Not Recommended)", 0);
		c->SetState( gui->mNoFpsLimit );
		c->mHoverText = "Seriously, this is a 2D chat room. Why have 4000 FPS?";
	y += 25;	
}
Exemplo n.º 20
0
void StoneHandler::debug()
{
	qDebug("StoneHandler::debug()");
	
#if 0
	Q3IntDictIterator<Stone> its(*stones);
	Stone *s;
	
	while (its.current())
	{
		s = its.current();
		qDebug("%d -> %s", its.currentKey(), s->getColor() == stoneBlack ? "Black" : "White");
		++its;
	}
#endif
	
	Q3PtrListIterator<Group> it(*groups);
	for (; it.current(); ++it)
	{
		Group *g = it.current();
		g->debug();
	}
}
Exemplo n.º 21
0
BOOL WINAPI UIProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam) 
{
	static GPtr globals = NULL;		  // need to be static	

	switch  (wMsg)
	{

	case WM_INITDIALOG:
		{
			LV_ITEM		LvItem;
			LV_COLUMN	LstColVal, LstColProp;
			int			i;

			CenterDialog(hDlg);

			// set up globals	
			globals		= (GPtr) lParam;
			gList		= GetDlgItem(hDlg,1011); // get the ID of the ListView	
			LVProcPrev	= (WNDPROC)SetWindowLong(gList, GWL_WNDPROC, (DWORD)LVProc);    

			// Here we put the info on the Column headers
			// this is not data, only name of each header we like
			memset(&LstColVal,0,sizeof(LstColVal)); // Reset Column

			LstColVal.mask		= LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_ORDER;	// Type of mask
			LstColVal.cx		= 0x64;											// width between each coloum
			LstColVal.pszText	= "Value";										// 
			LstColVal.iOrder	= 1;											// put editable field on right side

			LstColProp			= LstColVal;
			LstColProp.pszText	= "Property";
			LstColProp.iOrder	= 0;

			// Inserting Columns as much as we want
			ListView_InsertColumn(gList, 0, &LstColVal);
			ListView_InsertColumn(gList, 1, &LstColProp);

			//  Setting common properties Of Items:
			memset(&LvItem,0,sizeof(LvItem)); // Reset Item Struct
			LvItem.mask			= LVIF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;	// Text Style
			LvItem.cchTextMax	= 256;									// Max size of test

			// allocate mem for items
			ListView_SetItemCount(gList, PI_MAX);

			// insert items
			for(i=0; i<PI_MAX; i++)
			{
				ListView_SetPair(gList, LvItem, i,its(gIntProps[i].value), gIntProps[i].name );
			}

			ShowWindow(hDlg,SW_NORMAL); 
			UpdateWindow(hDlg); 

			return FALSE;
		}

	case WM_NOTIFY:
	{
		switch( ((LPNMHDR)lParam)->code  )
		{
			case LVN_BEGINLABELEDIT: 
			{
				break;
			}

			case LVN_ENDLABELEDIT: 
			{
				int iIndex;
				char tempstr[255]="";
				HWND hEdit;

				iIndex = ListView_GetNextItem(gList,-1,LVNI_FOCUSED);
				if( iIndex != - 1 )
				{
					//save to list
					hEdit = ListView_GetEditControl(gList);
					GetWindowText(hEdit, tempstr, sizeof(tempstr));
					ListView_SetItemText(gList, iIndex,0,tempstr);

					//save to globals
					gIntProps[iIndex].value = ListView_ReadInt(gList, iIndex, 0);
				}
				break;
			}
		}
		break;
	}

	case WM_COMMAND:
	{
		int item;
		int cmd;

		item = COMMANDID (wParam);              // WIN32 Change
		cmd  = HIWORD(wParam);

		switch (item)
		{
			case ok:
				if (cmd == BN_CLICKED)
					state = STATE_AGAIN;
				break;

			case cancel:
				if (cmd == BN_CLICKED)
					state = STATE_CANCEL;
				break;
		} 
		return FALSE;
	}
	} 
	return FALSE;
}
Exemplo n.º 22
0
void TerrainTest::Render()
{
	Image* scr = Screen::Instance();
	if (!grid)
		return;
	
	color c;
	tile* t;
	tile* tt;
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			t = GetTile(x, y);
			c.r = c.g = c.b = t->height * 25;
			
			scr->DrawRect( rect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE), c, true);

			if (m_bDisplayTypeMap)
			{
				//Mark tile types
				c = color();
				switch (GetTileType(x, y))
				{
					case TILE_SOUTHEDGE:
						c.r = 255; 
						break;
					case TILE_WESTEDGE:
						c.g = 255;
						break;
					case TILE_EASTEDGE:
						c.b = 255;
						break;
					case TILE_NORTHEDGE:
						c.r = c.g = 255;
						break;
					case TILE_SWEDGE:
						c.r = 128;
						break;
					case TILE_SEEDGE:
						c.g = 128;
						break;
					case TILE_NWEDGE:
						c.b = 128;
						break;
					case TILE_NEEDGE:
						c.r = c.g = 128;
						break;
					case TILE_SWBEND:
						c.g = c.b = 255;
						break;
					case TILE_SEBEND:
						c.g = c.b = 128;
						break;
					case TILE_NEBEND:
						c.r = c.b = 255;
						break;
					case TILE_NWBEND:
						c.r = c.b = 128;
						break;
					default: break;	
				}
			
				if (!isDefaultColor(c))
					scr->DrawRound( x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE/2, c);	
			}
			
			//Render edge lines for all tiles that have too drastic a height difference between them
			tt = GetTile(x, y-1);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE+16, y*TILE_SIZE, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE+16, y*TILE_SIZE, color(0,255), 2);
			}
			
			tt = GetTile(x, y+1);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE+14, x*TILE_SIZE+16, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE+14, x*TILE_SIZE+16, y*TILE_SIZE+14, color(0,255), 2);
			}
			
			tt = GetTile(x+1, y);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE+14, y*TILE_SIZE, x*TILE_SIZE+14, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE+14, y*TILE_SIZE, x*TILE_SIZE+14, y*TILE_SIZE+14, color(0,255), 2);
			}
			
			tt = GetTile(x-1, y);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE, y*TILE_SIZE+14, color(0,255), 2);	
			}
			
			
		}
	}
	
	string msg = "m_bDisplayTypeMap: " + its(m_bDisplayTypeMap) + " (T) \\c900 m_iUpperHeight: " + its(m_iUpperHeight) + " (+Q -A). \\c090 m_iLowerHeight: " 
				+  its(m_iLowerHeight) + " (+W -S). \\c009 N to clear all";
	gui->mFont->Render(scr, 5, 5, msg, color(255,255,255));
	
	msg = "\\c090Green \\c999and \\c900red \\c999lines mark gradients too steep (Algorithm failure).";
	gui->mFont->Render(scr, 5, scr->Height() - 40, msg, color());
}
Exemplo n.º 23
0
void viewAchievements(const vector<playerinfo>& pi, bool global) {

  int basey = 0;
  
  replay:
  
  uint64_t total = 0;

  for(int i=0; i<size(pi); i++) {
    const playerinfo& Pi(pi[i]);
    if(global ? false : Pi.username != pinfo.username)
      continue;
    
    if(!Pi.curgame) total |= Pi.stats.achiev;
    }

  bool descr = false;
  
  int newscore = 0;
  int myscore = 0;
  int totscore = 0;
  
  for(int i=0; i<NUMACH; i++) {
    bool inmy = (stats.achiev >> i) & 1;
    bool intot = (total >> i) & 1;
    int sco = ach[i].score;
    if(intot || inmy) totscore += sco;
    if(inmy) myscore += sco;
    if(inmy && !intot) newscore += sco;
    }
  
  while(true) {
    erase();
    move(0, 0); col(11); addstr("Your achievements:  ");
    col(10); 
    addstr(global ? "F-global" : "F-player");
    addstr(" ");
    addstr(descr ? "D-descr" : "D-names");
    addstr(" ");
    addstr("N-numerical");
    
    col(14); move(23, 30);
    addstri("total score: " + its(totscore)+" this game: "+ its(myscore)+" new points: "+its(newscore));
    
    if(basey < 0) basey = 0;
    if(basey + 20 > NUMACH) basey = NUMACH - 20;
    
    for(int i=0; i<20; i++) {
      int y = i + basey;
      move(i+2, 0);
      if((stats.achiev >> y) & 1) {
        if((total >> y) & 1) {
          col(11); addstr("this game");
          }
        else {
          col(14); addstr("NEW!");
          }
        }
      else if((total >> y) & 1) {
        col(15); addstr("got it");
        }
      else {
Exemplo n.º 24
0
void viewNumAchievements(const vector<playerinfo>& pi, bool global) {

  bool gamewon = false;
  bool gamewon2= false;
  int minwound = 1000000;
  int minwound2= 1000000;
  int minvalue = 1000000;
  int minvalue2= 1000000;
  int minarm   = 1000000;
  int minarm2  = 1000000;
  int minbi    = 1000000;
  int maxjuice = -1;
  int maxhydra = 0;
  int maxambi  = 0;
  int maxmsl   = 0;
  int maxchrg  = 0;
  int maxswipe = 0;
  int maxcoll  = 0;
  
  int mots[MOT];
  for(int a=0; a<MOT; a++) mots[a] = 1000000;

  for(int i=0; i<size(pi); i++) {
    const playerinfo& Pi(pi[i]);
    if(global ? false : Pi.username != pinfo.username)
      continue;
    
    if(Pi.stats.endtype >= 3) {
      gamewon = true;
      minwound = min(minwound, Pi.stats.woundwin);
      minvalue = min(minvalue, Pi.stats.treasure);
      minarm   = min(minarm,   Pi.stats.armscore);
      minbi    = min(minbi,    Pi.stats.bossinv);
      if(Pi.stats.usedup[IT_PLIFE] == 0)
        setmax(maxjuice, Pi.player.inv[IT_PARMS]);
      for(int a=0; a<MOT; a++)
        mots[a] = min(mots[a], Pi.stats.motwin[a]);
      }
    
    if(Pi.stats.endtype >= 6) {
      gamewon2 = true;
      minwound2 = min(minwound2, Pi.stats.woundwin2);
      minvalue2 = min(minvalue2, Pi.stats.treasure2);
      minarm2   = min(minarm2,   Pi.stats.armscore2);
      }
    
    setmax(maxhydra, Pi.stats.hydrakill);
    setmax(maxambi,  Pi.stats.maxambi);
    setmax(maxmsl,   Pi.stats.maxmsl);
    setmax(maxchrg,  Pi.stats.maxchrg);
    setmax(maxswipe, Pi.stats.maxkill);
    setmax(maxcoll,  Pi.stats.owncrush);
    }
  
  erase(); col(7);
  
  addstr("Your achievements:\n\n");
  
  if(!gamewon) 
    addstr("You have not won the game yet.\n");
  else {
    addstri("Minimum wounds in a winning game: "+its(minwound)+"\n");
    addstri("Minimum value of used items: "+its(minvalue)+"\n");
    addstri("Best mutation score: "+its(minarm)+"\n");
    addstri("Least inventory items used against the boss: "+its(minbi)+"\n");
    if(maxjuice < 0)
      addstri("You still have to win without using the Potion of Life!\n");
    else {
      addstri("You have won without using the Potion of Life!\n");
      if(maxjuice > 0)
        addstri("... and "+its(maxjuice)+" Potions of Power Juice!\n");
      else
        addstri("... but you still have used all the Potions of Power Juice.\n");
      }
    
    addstri("You have won using blades (-) of size at most "+its(max(mots[MOT_OBSID], mots[MOT_BLADE]))+".\n");
    int nouse = 0;
    if(mots[MOT_BLUNT] == 0 && mots[MOT_SHLD] == 0)
      addstri("You have won without using blunt weapons and without shields!\n");
    else if(mots[MOT_SHLD] == 0)
      addstri("You have won using blunt weapons of size "+its(mots[MOT_BLUNT])+" and no shields.\n");
    else
      addstri("You have won using shields of size at most "+its(mots[MOT_SHLD])+".\n");
    if(mots[MOT_OBSID] == 0)
      addstri("You have won without using obsidian blades.\n"), nouse++;
    if(mots[MOT_MSL] == 0)
      addstri("You have won without using missiles.\n"), nouse++;
    if(mots[MOT_DIV] == 0)
      addstri("You have won without using divisors at all!!\n"), nouse++;
    else if(mots[MOT_DIV] <= 2)
      addstri("You have won without using divisors except the Bisector!\n"), nouse++;
    if(nouse == 0)
      addstri("You have always been using obsidian blades, missiles, and large divisors.\n");
    if(!gamewon2)
      addstri("But you still have not won the complete game!");
    }
  addstr("\n");

  if(gamewon2) {
    addstri("Minimum wounds in a complete winning game: "+its(minwound2)+"\n");
    addstri("Minimum value of items used in a complete game: "+its(minvalue2)+"\n");
    addstri("Best mutation score: "+its(minarm2)+"\n");
    }
    
  addstr("\n");

  addstri("Your best score was killing "+its(maxhydra)+" Hydras.\n");
  if(maxambi > 0)
    addstri("The biggest hydra one-shotted by you had "+its(maxambi)+" heads.\n");
  if(maxcoll > 1)
    addstri("You managed to collapse "+its(maxcoll)+" hydras in a single game!\n");
  else if(maxcoll)
    addstri("You managed to collapse a Hydra under its own weight!\n");
  if(maxmsl > 1)
    addstri("You managed to kill "+its(maxmsl)+" Hydras with one missile!\n");
  if(maxswipe > 1)
    addstri("You managed to kill "+its(maxswipe)+" Hydras with one power swipe!\n");
  if(maxchrg > 1)
    addstri("You managed to kill "+its(maxchrg)+" Hydras with one power charge!\n");
  
  ghch(IC_VIEWDESC);
  }
Exemplo n.º 25
0
int
main(int argc,
     char** argv)
{
    if (argc != 6) {
        std::cout << "This program takes in input glad.h and outputs the include and implementation files for OSMesa OpenGL function and regular OpenGL functions." << std::endl;
        std::cout << "Usage: generateGLIncludes <glad.h path> <output dir path> <namespace name> <baseFileName> <inlcude glad debug symbols>" << std::endl;
        std::cout << "Example: generateGLIncludes /Users/alexandre/development/Natron/Global/gladRel/include/glad/glad.h /Users/alexandre/development/Natron/Engine Natron OSGLFunctions 1" << std::endl;

        return 1;
    }

    QFile f(argv[1]);
    if ( !f.open(QIODevice::ReadOnly) ) {
        std::cout << "Could not open " << argv[1] << std::endl;

        return 1;
    }

    // Check that output path exists

    QDir outputDir(argv[2]);
    if ( !outputDir.exists() ) {
        std::cout << argv[2] << " does not seem to be a valid directory" << std::endl;

        return 1;
    }

    QString namespaceName(argv[3]);
    QString baseFilename(argv[4]);
    bool supportGladDebug;
    {
        QString supportDebugSymbolsStr(argv[5]);
        supportGladDebug = (bool)supportDebugSymbolsStr.toInt();
    }
    QString absoluteDirPath = outputDir.absolutePath();
    QString outputHeaderFilename = absoluteDirPath + "/" + baseFilename + ".h";
    QFile of_header(outputHeaderFilename);
    if ( !of_header.open(QIODevice::WriteOnly) ) {
        std::cout << "Could not open " << outputHeaderFilename.toStdString() << std::endl;

        return 1;
    }
    QTextStream ots_header(&of_header);
    QTextStream its(&f);
    QString definesStr;

    std::list<FunctionSignature> signatures;
    QString functionTypedefsStr;
    QString prevLine;
    while ( !its.atEnd() ) {
        // Read each line of glad.h
        QString line = its.readLine();

        {
            // Search for a define
            QString toFind = "#define GL_";
            int found = line.indexOf(toFind);
            if (found != -1) {
                definesStr += line;
                definesStr += "\n";
            }
        }

        // Search for a function
        QString typedefToken("typedef ");
        QString pfnToken("(APIENTRYP PFNGL");
        int foundFuncDef = line.indexOf(typedefToken);
        int foundPNFToken = line.indexOf(pfnToken);
        if ( (foundFuncDef != -1) && (foundPNFToken != -1) ) {
            int pos = foundPNFToken + pfnToken.size();
            int foundFirstEndParenthesis = line.indexOf(')', pos);
            assert(foundFirstEndParenthesis != -1);


            FunctionSignature signature;
            QString lastFuncNameCaps = line.mid(pos, foundFirstEndParenthesis - pos);
            signature.signature = line.mid(foundFirstEndParenthesis);
            // "near" and "far" are defined as macros in windows.h
            signature.signature.replace("GLdouble near, GLdouble far", "GLdouble nearVal, GLdouble farVal");

            signature.returnType = line.mid( foundFuncDef + typedefToken.size(), foundPNFToken - 1 - ( foundFuncDef + typedefToken.size() ) );
            QString funcTypeDefStr = "typedef ";
            funcTypeDefStr += signature.returnType;
            funcTypeDefStr += " (*PFNGL";
            funcTypeDefStr += lastFuncNameCaps;
            funcTypeDefStr += signature.signature;
            funcTypeDefStr += "\n";
            functionTypedefsStr += funcTypeDefStr;

            // Remove the extraneous ; at the end of the signature
            // Also remove the prepending )
            signature.signature.remove(0, 1);
            signature.signature.remove(signature.signature.size() - 1, 1);

            signature.funcPNType = "PFNGL";
            signature.funcPNType += lastFuncNameCaps;

            // extract parameters
            {
                int i = 1; // start after the leading (
                while ( i < signature.signature.size() ) {
                    QString param;
                    while ( signature.signature[i] != QChar(',') && signature.signature[i] != QChar(')') ) {
                        param.append(signature.signature[i]);
                        ++i;
                    }

                    // Now only keep the name of the parameter
                    {
                        int j = param.size() - 1;
                        while ( j >= 0 && param[j].isLetterOrNumber() ) {
                            --j;
                        }
                        param = param.mid(j + 1);
                    }
                    signature.parameters.append(param);

                    assert( signature.signature[i] == QChar(',') || signature.signature[i] == QChar(')') );
                    ++i; // bypass last character

                    if ( signature.signature[i] == QChar(')') ) {
                        break;
                    }
                }
            }

            // we caught a function typedef before, we expect to read the following #define glXxxx function with the appropriate case
            // in release glad.h, the next line is of the type GLAPI PFNGLCOLOR4FVPROC glad_glColor4fv;
            // the line after that is the one we want #define glColor4fv glad_glColor4fv
            line = its.readLine();
            assert( !its.atEnd() );
            line = its.readLine();

            QString toFind("#define gl");
            int foundDefine = line.indexOf(toFind);
            if (foundDefine == -1) {
                std::cout << "Parser failed to find #define glXXX statement 2 lines after a function typedef, make sure that you are running this program against a release version of glad.h" << std::endl;

                return 1;
            }

            // Check that this is the same symbol
            // Remove the PROC at the end of the func def
            lastFuncNameCaps.remove("PROC");
            int checkIndex = toFind.size();
            QString symbolStart = line.mid(checkIndex);
            assert( symbolStart.startsWith(lastFuncNameCaps, Qt::CaseInsensitive) );

            {
                int i = 8; // start on the g
                //extract the function name
                while ( i < line.size() && line.at(i) != QChar(' ') ) {
                    signature.funcName.push_back( line.at(i) );
                    ++i;
                }
            }

            signatures.push_back(signature);
        } // if (foundFuncDef != -1 && foundPNFToken != -1) {

        prevLine = line;
    }

    writeHeader(ots_header);
    writePODs(ots_header);
    ots_header <<
        definesStr << "\n"
        "\n";
    ots_header <<
        functionTypedefsStr << "\n"
        "\n";
    writeStartClass(namespaceName, ots_header);

    // Define the singleton
    ots_header <<
        "    static OSGLFunctions<USEOPENGL>& getInstance()\n"
        "    {\n"
        "        static OSGLFunctions<USEOPENGL> instance;\n"
        "\n"
        "        return instance;\n"
        "    }\n"
        "\n"
        "    // load function, implemented in _gl.h and _mesa.h\n"
        "    void load_functions();\n"
        "\n"
        "    // private constructor\n"
        "    OSGLFunctions() { load_functions(); }\n"
        "\n";

    // Declare member functions
    for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) {
        ots_header << "    " << it->funcPNType << " _" << it->funcName << ";\n";
    }

    ots_header <<
        "\n";

    ots_header <<
        "public:\n"
        "\n";


    ots_header <<
        "    // static non MT-safe load function that must be called once to initialize functions\n"
        "    static void load()\n"
        "    {\n"
        "        (void)getInstance();\n"
        "    }\n"
        "\n"
        "    static bool isGPU()\n"
        "    {\n"
        "        return USEOPENGL;\n"
        "    }\n";

    for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) {
        QString lineStart = "    static " +  it->returnType + " " + it->funcName;
        QString indentedSig = it->signature;
        indentedSig.replace( ", ", ",\n" + QString(lineStart.size() + 1, ' ') );
        ots_header << "\n" <<
            lineStart << indentedSig << "\n"
            "    {\n";
        if (it->returnType == "void") {
            ots_header << "        ";
        } else {
            ots_header << "        return ";
        }
        ots_header << "getInstance()._" << it->funcName << "(";
        QStringList::const_iterator next = it->parameters.begin();
        if ( !it->parameters.isEmpty() ) {
            ++next;
        }
        for (QStringList::const_iterator it2 = it->parameters.begin(); it2 != it->parameters.end(); ++it2) {
            ots_header << *it2;
            if ( next != it->parameters.end() ) {
                ots_header << ", ";
                ++next;
            }
        }

        ots_header <<
            ");\n"
            "    }\n";
    }
    writeEndClass(namespaceName, ots_header);

    writeFooter(ots_header);

    writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "gl", true, supportGladDebug);
    writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "mesa", false, supportGladDebug);


    return 0;
} // main
Exemplo n.º 26
0
void dlCallback_CheckInFailure(downloadData* data)
{
	string error = "Checkin Reply Error: " + its(data->errorCode);
	console->AddMessage(error);
	removeFile(data->filename);
}
Exemplo n.º 27
0
char*
get_pid(struct ps_proc* proc)
{
	return its(&proc->p_pid, ITS_SIZE_INTMAX, ITS_SIGNED, ITS_BASE_DEC);
}
Exemplo n.º 28
0
void TimeProfiler::Stage::report(const String& indent) const {
    PROFILER_LOG(info,"Stage: " << indent << name() << " -- Avg: " << avg() << " Min: " << minimum() << " Max:" << maximum() << " Sum: " << mSum << "  Its: " << its());
}
Exemplo n.º 29
0
void FastVsSlowSimRes() {

  Int_t plusTPC =0;

  gROOT->LoadMacro("~/fig_template.C"); // figure style
  myOptions(0);
  gROOT->ForceStyle();

  TCanvas *myCan = new TCanvas("myCan");
  myCan->Draw();
  myCan->cd();
  
  TPad *myPad = new TPad("myPad", "The pad",0,0,1,1);
  myPadSetUp(myPad,0.15,0.04,0.04,0.15);
  myPad->Draw();   myPad->cd();
  myPad->SetGridx();   myPad->SetGridy();  myPad->SetLogx(); 

  //  TLegend *leg = new TLegend(0.7,160,20,290,"","brCDN"); 
  TLegend *leg = new TLegend(0.44,160,1.7,290,"","brCDN"); 
 
  leg->SetFillColor(0);

  
  // Current ITS +++++++++++++++++++++++++++++++++++++++++

  DetectorK its("ALICE","ITS");
  its.MakeAliceCurrent(0,plusTPC);
  its.SetMaxRadiusOfSlowDetectors(0.1);
  its.SolveViaBilloir(0);
  Int_t color=1; Int_t linewidth=2;

  TGraph *c[6];
  TGraph *d[6];

  Int_t pi =0;
  d[pi] = its.GetGraphPointingResolution(1,color,linewidth);
  d[pi]->SetLineStyle(2);
  //  d[pi]->GetYaxis()->SetTitle("Pointing resolution #sigma [#mum]");
  //  d[pi]->SetTitle("Pointing resolution .vs. Pt");
  //  d[pi]->Draw("AC");
  
  c[pi] = its.GetGraphPointingResolution(0,color,linewidth);
  c[pi]->SetMinimum(-1);
  c[pi]->Draw("AC");

  leg->AddEntry(c[pi],"FastTool:  Current ITS","l");
  //  leg->AddEntry(d[pi],"in z  - Current ITS","l");

 

 
  // Current ITS +++++++++++++++++++++++++++++++++++++++++

  Int_t color=3; Int_t linewidth=2;
  Int_t pi =2;

  DetectorK its("ALICE","ITS");
  its.MakeAliceCurrent(0,plusTPC);
  
  its.SetRadius("bpipe",2.0);
  its.AddLayer("spd0", 2.2,1,1,1);  

  its.SetRadius("spd0",2.2); its.SetRadiationLength("spd0",X0); its.SetResolution("spd0",resRPhi,resZ);
  its.SetRadius("spd1",4.8);   its.SetRadiationLength("spd1",X0); its.SetResolution("spd1",resRPhi,resZ);
  its.SetRadius("spd2",9.1);   its.SetRadiationLength("spd2",X0); its.SetResolution("spd2",resRPhi,resZ);

  its.SetMaxRadiusOfSlowDetectors(0.1);
  its.SolveViaBilloir(0);

  d[pi] = its.GetGraphPointingResolution(1,color,linewidth);
  d[pi]->SetLineStyle(2);
  //  d[pi]->Draw("C");

  c[pi] = its.GetGraphPointingResolution(0,color,linewidth);
  c[pi]->Draw("C");

  leg->AddEntry(c[pi],"FastTool: \"New SPDs\"","l");
  //  leg->AddEntry(d[pi],"in z  - \"New SPDs\"","l");



  // ALL NEW +++++++++++++++++++++++++++++++++++++++++++

  color=2; Int_t linewidth=2;
  Int_t pi =1; 


  // for a 0.8,0.2 weight configuration
  
  DetectorK *itsU = new DetectorK((char*)"ALICE",(char*)"ITS");
  
  itsU->AddLayer((char*)"bpipe", 2.0,0.0022); // beam pipe
  itsU->AddLayer((char*)"vertex",  0,     0); // dummy vertex for matrix calculation
  
  itsU->AddLayer("ddd1",  2.2 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd2",  3.8 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd3",  6.8 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd4", 12.4 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd5", 23.5 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd6", 39.6 ,  X0, resRPhi, resZ); 
  itsU->AddLayer("ddd7", 43.0 ,  X0, resRPhi, resZ); 
 
  if(plusTPC) itsU->AddTPC(0.1,0.1);
  itsU->SetMaxRadiusOfSlowDetectors(0.1);
  itsU->SolveViaBilloir(0);
  itsU->PrintLayout();

  
  d[pi] = itsU->GetGraphPointingResolution(1,color,linewidth);
  d[pi]->SetLineStyle(2);
  //  d[pi]->Draw("C");

  c[pi] = itsU->GetGraphPointingResolution(0,color,linewidth);
  c[pi]->SetMaximum(150);
  c[pi]->Draw("C");

  leg->AddEntry(c[pi],"FastTool: \"All New\" ","l");
  //  leg->AddEntry(d[pi],"in z  - \"All New\" ","l");


  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


 
  TFile f1("root/FastVsSlow_CurrentITS-PbPb-fran.root");
  TFile f2("root/FastVsSlow_NewSPDs-PbPb-fran.root");
  TFile f3("root/FastVsSlow_AllNew-PbPb-fran.root");
  TGraphErrors *dca1 = (TGraphErrors*)f1.Get("dca");
  TGraphErrors *dca2 = (TGraphErrors*)f2.Get("dca");
  TGraphErrors *dca3 = (TGraphErrors*)f3.Get("dca");
  
  dca1->SetMarkerStyle(21); dca1->SetMarkerColor(1);
  dca2->SetMarkerStyle(21); dca2->SetMarkerColor(3);
  dca3->SetMarkerStyle(21); dca3->SetMarkerColor(2);

  leg->AddEntry(dca1,"FullMC: Current ITS","PE");
  leg->AddEntry(dca2,"FullMC: \"New SPDs\"","PE");
  leg->AddEntry(dca3,"FullMC: \"All New\" ","PE");

  dca1->Draw("APE"); dca1->SetMinimum(-1); dca1->SetMaximum(300);
  dca2->Draw("PE");
  dca3->Draw("PE");
  c[0]->Draw("C");
  c[1]->Draw("C");
  c[2]->Draw("C");

  leg->Draw();

  myCan->SaveAs(Form("FastVsSlowSim-Res-%d.pdf",plusTPC));
  myCan->SaveAs(Form("FastVsSlowSim-Res-%d.eps",plusTPC));


}
Exemplo n.º 30
0
void FastVsSlowSimEff(Int_t id=0,Int_t PbPb=0) {

  Int_t mult = 2400; // 2800  // deducted from "Frackable"
  if (PbPb) mult=2800;


  Int_t plusTPC =0;

  gROOT->LoadMacro("~/fig_template.C"); // figure style
  myOptions(0);
  gROOT->ForceStyle();

  TCanvas *myCan = new TCanvas("myCan");
  myCan->Draw();
  myCan->cd();
  
  TPad *myPad = new TPad("myPad", "The pad",0,0,1,1);
  myPadSetUp(myPad,0.15,0.04,0.04,0.15);
  myPad->Draw();   myPad->cd();
  myPad->SetGridx();   myPad->SetGridy();//  myPad->SetLogx();


  TLegend *leg = new TLegend(0.9,30,1.7,70,"","brCDN"); 
  leg->SetFillColor(0);

  TGraph *c[6];
  if (id!=2) {
  
  
    // Current ITS +++++++++++++++++++++++++++++++++++++++++
    Int_t color=1; Int_t linewidth=2;

    Int_t pi =0;
 
    DetectorK its("ALICE","ITS");
    its.MakeAliceCurrent(0,plusTPC);
    its.SetMaxRadiusOfSlowDetectors(0.01);
    its.SetAtLeastCorr(atLeastcorr);
    if (PbPb) its.SetdNdEtaCent(mult);
    its.SolveViaBilloir(0);
    Int_t color=1; Int_t linewidth=2;

    if (id==0)
      c[pi] = its.GetGraphRecoEfficiency(0,color,linewidth);
    else if (id==1)
      c[pi] = its.GetGraphRecoPurity(0,color,linewidth);
    else 
      c[pi] = its.GetGraphRecoFakes(0,color,linewidth);

    c[pi]->Draw("AC");

    leg->AddEntry(c[pi],"FastTool: Current ITS","l");


    // NEW SPD  +++++++++++++++++++++++++++++++++++++++++

    Int_t color=3; Int_t linewidth=2;
    Int_t pi =2;

    DetectorK its("ALICE","ITS");
    its.MakeAliceCurrent(0,plusTPC);
    its.SetAtLeastCorr(atLeastcorr);
    if (PbPb) its.SetdNdEtaCent(mult);
    its.SetRadius("bpipe",2.0);
    its.AddLayer("spd0", 2.2,1,1,1);  

    its.SetRadius("spd0",2.2); its.SetRadiationLength("spd0",X0); its.SetResolution("spd0",resRPhi,resZ);
    its.SetRadius("spd1",4.8);   its.SetRadiationLength("spd1",X0); its.SetResolution("spd1",resRPhi,resZ);
    its.SetRadius("spd2",9.1);   its.SetRadiationLength("spd2",X0); its.SetResolution("spd2",resRPhi,resZ);

    its.SetMaxRadiusOfSlowDetectors(0.1);
    its.SolveViaBilloir(0);

    if (id==0)
      c[pi] = its.GetGraphRecoEfficiency(0,color,linewidth);
    else if (id==1)
      c[pi] = its.GetGraphRecoPurity(0,color,linewidth);
    else 
      c[pi] = its.GetGraphRecoFakes(0,color,linewidth);
   
    c[pi]->Draw("C");

    leg->AddEntry(c[pi],"FastTool: \"New SPDs\"","l");


    // ALL NEW +++++++++++++++++++++++++++++++++++++++++++

    color=4; Int_t linewidth=2;
    Int_t pi =1; 


    // for a 0.8,0.2 weight configuration
  
    DetectorK *itsU = new DetectorK((char*)"ALICE",(char*)"ITS");
    itsU->SetAtLeastCorr(atLeastcorr);
    itsU->AddLayer((char*)"bpipe", 2.0,0.0022); // beam pipe
    itsU->AddLayer((char*)"vertex",  0,     0); // dummy vertex for matrix calculation
  
    itsU->AddLayer("ddd1",  2.2 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd2",  3.8 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd3",  6.8 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd4", 12.4 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd5", 23.5 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd6", 39.6 ,  X0, resRPhi, resZ); 
    //    itsU->AddLayer("ddd6", 42.6 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd7", 43.0 ,  X0, resRPhi, resZ); 
    //    itsU->AddLayer("ddd8", 43.4 ,  X0, resRPhi, resZ); 


    if (PbPb) itsU->SetdNdEtaCent(mult);
    if(plusTPC) itsU->AddTPC(0.1,0.1);
    itsU->SetMaxRadiusOfSlowDetectors(0.1);
    itsU->SolveViaBilloir(0);
    itsU->PrintLayout();

    if (id==0)
      c[pi] = itsU->GetGraphRecoEfficiency(0,color,linewidth);
    else if (id==1)
      c[pi] = itsU->GetGraphRecoPurity(0,color,linewidth);
    else 
      c[pi] = itsU->GetGraphRecoFakes(0,color,linewidth);
    c[pi]->Draw("C");

    leg->AddEntry(c[pi],"FastTool: \"All New\" ","l");

    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 // ALL NEW - double outer layer +++++++++++++++++++++++++++++++++++++

    color=2; Int_t linewidth=2;
    Int_t pi =3; 


    // for a 0.8,0.2 weight configuration
  
    DetectorK *itsU = new DetectorK((char*)"ALICE",(char*)"ITS");
    itsU->SetAtLeastCorr(atLeastcorr);
    itsU->AddLayer((char*)"bpipe", 2.0,0.0022); // beam pipe
    itsU->AddLayer((char*)"vertex",  0,     0); // dummy vertex for matrix calculation
  
    itsU->AddLayer("ddd1",  2.2 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd2",  3.8 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd3",  6.8 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd4", 12.4 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd5", 23.5 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd6", 39.6 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd8", 40.0 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd7", 43.0 ,  X0, resRPhi, resZ); 
    itsU->AddLayer("ddd9", 43.4 ,  X0, resRPhi, resZ); 


    if (PbPb) itsU->SetdNdEtaCent(mult);
    if(plusTPC) itsU->AddTPC(0.1,0.1);
    itsU->SetMaxRadiusOfSlowDetectors(0.1);
    itsU->SolveViaBilloir(0);
    itsU->PrintLayout();

    if (id==0)
      c[pi] = itsU->GetGraphRecoEfficiency(0,color,linewidth);
    else if (id==1)
      c[pi] = itsU->GetGraphRecoPurity(0,color,linewidth);
    else 
      c[pi] = itsU->GetGraphRecoFakes(0,color,linewidth);
    c[pi]->Draw("C");

    leg->AddEntry(c[pi],"FastTool: \"All New\" (2x double layer)","l");

    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


  }

  char h[100];
  if (PbPb==0) 
    sprintf(h,"-fran");
  else 
    sprintf(h,"-Anna");

  TFile f1(Form("root/FastVsSlow_CurrentITS-PbPb%s.root",h));
  TFile f2(Form("root/FastVsSlow_NewSPDs-PbPb%s.root",h));
  TFile f3(Form("root/FastVsSlow_AllNew-PbPb%s.root",h));
  TFile f4(Form("root/FastVsSlow_AllNew-9-PbPb%s.root",h));

  //  TFile f1(Form("root/FastVsSlow_CurrentITS%s-fran.root",h));
  //  TFile f2(Form("root/FastVsSlow_NewSPDs%s-fran.root",h));
  //  TFile f3(Form("root/FastVsSlow_AllNew%s-fran.root",h));

  TH1F *eff1 = 0;
  TH1F *eff2 = 0;
  TH1F *eff3 = 0;
  TH1F *eff4 = 0;
  if (id==0) {
    eff1 = (TH1F*)f1.Get("efficiency");
    eff2 = (TH1F*)f2.Get("efficiency");
    eff3 = (TH1F*)f3.Get("efficiency");
    eff4 = (TH1F*)f4.Get("efficiency");
    eff1->GetYaxis()->SetTitle("efficiency (%)");
  } else if (id==1) {
    eff1 = (TH1F*)f1.Get("purity");
    eff2 = (TH1F*)f2.Get("purity");
    eff3 = (TH1F*)f3.Get("purity");
    eff4 = (TH1F*)f4.Get("purity");
      eff1->GetYaxis()->SetTitle("purity (%)");
  } else if (id==2) {
    eff1 = (TH1F*)f1.Get("annaEff");
    eff2 = (TH1F*)f2.Get("annaEff");
    eff3 = (TH1F*)f3.Get("annaEff");
    eff4 = (TH1F*)f4.Get("annaEff");
    eff1->GetYaxis()->SetTitle("Overall efficiency (%)");
  } else if (id==3) {
    eff1 = (TH1F*)f1.Get("fake");
    eff2 = (TH1F*)f2.Get("fake");
    eff3 = (TH1F*)f3.Get("fake");
    eff4 = (TH1F*)f4.Get("fake");
    eff1->GetYaxis()->SetTitle("Fake ratio (%)");
  }

  eff1->SetMarkerStyle(21); eff1->SetMarkerColor(1);
  eff2->SetMarkerStyle(21); eff2->SetMarkerColor(3);
  eff3->SetMarkerStyle(21); eff3->SetMarkerColor(4);
  eff4->SetMarkerStyle(21); eff4->SetMarkerColor(2);

  leg->AddEntry(eff1,"FullMC: Current ITS","PE");
  leg->AddEntry(eff2,"FullMC: \"New SPDs\"","PE");
  leg->AddEntry(eff3,"FullMC: \"All New\" ","PE");
  leg->AddEntry(eff4,"FullMC: \"All New\" (2x double layer)","PE");

  eff1->SetMinimum(0.4); eff1->SetMaximum(100);
  eff1->DrawCopy("E");
  eff2->DrawCopy("sameE");
  eff4->DrawCopy("sameE");
  eff3->DrawCopy("sameE");
  if (id!=2) {
    c[0]->Draw("C");
    c[1]->Draw("C");
    c[2]->Draw("C");
    c[3]->Draw("C");
  }
  eff2->DrawCopy("sameE");
  eff4->DrawCopy("sameE");
  eff3->DrawCopy("sameE");

  
  leg->Draw();
 



  TPaveText *pt = 0;
  if (id!=3) 
   pt = new TPaveText(0.4,0.1,1.76,30);
  else
   pt = new TPaveText(0.4,70,1.76,100);
    
  pt->SetBorderSize(1); // no shadow
  pt->SetTextFont(12);
  TText *t1 = pt->AddText("FastTool settings: "); t1->SetTextFont(32); // bold

  pt->AddText(Form("   Tracked particles: Pions;   Average rapidity: 0.45; dN_{ch}/d#eta = %d ",mult));

  //  pt->AddText("\"New SPDs\": layer radii: r = {2.2,4.8,9.1} cm");
  //  pt->AddText("\"All New\: layer radii: r = {2.2,3.8,6.8,...} cm");
  //  pt->AddText(Form("    New layer prop.: X/X_{0}=%1.1lf%%;  #sigma_{r#phi,z}=%1.0lf#mum",X0*100,resZ*1e4));
  
  TText *t2 = pt->AddText("FullMC settings: "); t2->SetTextFont(32); // bold
  if (PbPb==0) {
    pt->AddText("   Generator: AliGenHIJINGpara (parametrized PbPb event)");
    pt->AddText("   dN_{ch.pr.}/d#eta = 2070");
    pt->AddText("   Track selection: Pions, |#eta|<0.9");
  } else {
    pt->AddText("   Generator: AliGenHijing (modified);  #sqrt{s_{NN}} = 5.5 TeV");
    pt->AddText("   dN_{ch.pr.}/d#eta = 2410; Impactparameter range: b#in(0,5)  #rightarrow central PbPb ");
    pt->AddText("   Track selection: Pions, |#eta|<0.9");
  }
  //  pt->SetLabel("Settings");
  pt->SetTextAlign(12);
  pt->SetFillColor(0);
  pt->Draw();





  if (PbPb==0) {    
    myCan->SaveAs(Form("FastVsSlowSim-Eff-%d.pdf",id));
    myCan->SaveAs(Form("FastVsSlowSim-Eff-%d.eps",id));
  }else{
    myCan->SaveAs(Form("FastVsSlowSim-Eff-PbPb-%d.pdf",id));
    myCan->SaveAs(Form("FastVsSlowSim-Eff-PbPb-%d.eps",id));
  }




}