示例#1
1
void StartGameWidget::SetBodyText()
{
	if (sectors.Empty()) return;

	const SectorData* sd = sectors[currentSector];
	Weather* weather = Weather::Instance();
	Vector2I pos = sd->CoreLoc();
	Vector2F pos2 = ToWorld2F(pos);
	GLASSERT(weather);
	const float AREA = float(SECTOR_SIZE*SECTOR_SIZE);
	int nPorts = 0;
	for (int i = 0; i < 4; ++i) {
		if ((1 << i) & sd->ports) {
			nPorts++;
		}
	}

	int bioFlora = 0;
	int flowers = 0;
	Rectangle2I bi = sd->InnerBounds();
	for (Rectangle2IIterator it(bi); !it.Done(); it.Next()) {
		const WorldGrid& wg = worldMap->GetWorldGrid(it.Pos().x, it.Pos().y);
		if (wg.Plant() >= 7) {
			flowers++;
		}
		else if (wg.Plant()) {
			bioFlora++;
		}
	}

	CStr<400> str;
	str.Format("%s\nTemperature=%d%%  Rain=%d%%  Land=%d%%  Water=%d%%  nPorts=%d\n"
		"bioFlora=%d%%  flowers=%d%%",
		sd->name.c_str(),
		LRint(weather->Temperature(pos2.x, pos2.y) * 100.0f),
		LRint(weather->RainFraction(pos2.x, pos2.y) * 100.0f),
		LRint(100.0f*float(sd->area) / AREA),
		LRint(100.0f*float(AREA - sd->area) / AREA),
		nPorts,
		LRint(100.0f*float(bioFlora) / AREA),
		LRint(100.0f*float(flowers) / AREA));

	bodyLabel.SetText(str.c_str());

	str.Format("%d/%d", currentSector+1, sectors.Size());
	countLabel.SetText(str.c_str());
}
示例#2
0
文件: db.C 项目: AresTao/xframe
int CDB::count(const char* tableName, const char* condition)
{
    CStr sql;
    sql << "select count(*) from " << tableName;
    if(condition != NULL)
        sql << "  where " << condition;

    struct Field* field = selectOneField(sql.c_str());
    if(field == NULL)
    {
        UniERROR("EXEC SQL: '%s', no valid field selected ", sql.c_str());
        return -1;
    }

    int count;
    switch(field->type)
    {
        case T_INT:
            count = field->value.intValue;
            break;
        case T_UINT:
            count = field->value.uintValue;
            break;
        case T_LONGLONG:
            count = field->value.longlongValue;
            break;
        case T_FLOAT:
            count = (int)field->value.floatValue;
            break;
        default:
            UniERROR("EXEC SQL: '%s' field type is %d", sql.c_str(), field->type);
            return -1;
    }
    return count;
}
示例#3
0
void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI)
{
	if(!GetGUI())
		throw PSERROR_GUI_OperationNeedsGUIObject();

	JSContext* cx = pGUI->GetScriptInterface()->GetContext();
	JSAutoRequest rq(cx);
	JS::RootedValue globalVal(cx, pGUI->GetGlobalObject());
	JS::RootedObject globalObj(cx, &globalVal.toObject());

	const int paramCount = 1;
	const char* paramNames[paramCount] = { "mouse" };

	// Location to report errors from
	CStr CodeName = GetName()+" "+Action;

	// Generate a unique name
	static int x = 0;
	char buf[64];
	sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str());

	JS::CompileOptions options(cx);
	options.setFileAndLine(CodeName.c_str(), 0);
	options.setCompileAndGo(true);

	JS::RootedFunction func(cx, JS_CompileFunction(cx, globalObj,
		buf, paramCount, paramNames, Code.c_str(), Code.length(), options));

	if (!func)
		return; // JS will report an error message

	JS::RootedObject funcObj(cx, JS_GetFunctionObject(func));
	SetScriptHandler(Action, funcObj);
}
示例#4
0
	bool Convert(const VfsPath& daeFilename, const VfsPath& pmdFilename, CColladaManager::FileType type)
	{
		// To avoid always loading the DLL when it's usually not going to be
		// used (and to do the same on Linux where delay-loading won't help),
		// and to avoid compile-time dependencies (because it's a minor pain
		// to get all the right libraries to build the COLLADA DLL), we load
		// it dynamically when it is required, instead of using the exported
		// functions and binding at link-time.
		if (!dll.IsLoaded())
		{
			if (!TryLoadDLL())
				return false;

			if (!LoadSkeletonDefinitions())
			{
				dll.Unload(); // Error should have been logged already
				return false;
			}
		}

		// Set the filename for the logger to report
		set_logger(ColladaLog, const_cast<void*>(static_cast<const void*>(&daeFilename)));

		// We need to null-terminate the buffer, so do it (possibly inefficiently)
		// by converting to a CStr
		CStr daeData;
		{
			CVFSFile daeFile;
			if (daeFile.Load(m_VFS, daeFilename) != PSRETURN_OK)
				return false;
			daeData = daeFile.GetAsString();
		}

		// Do the conversion into a memory buffer
		// We need to check the result, as archive builder needs to know if the source dae
		//	was sucessfully converted to .pmd/psa
		int result = -1;
		WriteBuffer writeBuffer;
		switch (type)
		{
		case CColladaManager::PMD:
			result = convert_dae_to_pmd(daeData.c_str(), ColladaOutput, &writeBuffer);
			break;
		case CColladaManager::PSA:
			result = convert_dae_to_psa(daeData.c_str(), ColladaOutput, &writeBuffer);
			break;
		}

		// don't create zero-length files (as happens in test_invalid_dae when
		// we deliberately pass invalid XML data) because the VFS caching
		// logic warns when asked to load such.
		if (writeBuffer.Size())
		{
			Status ret = m_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
			ENSURE(ret == INFO::OK);
		}

		return (result == 0);
	}
示例#5
0
void CmColorQua::TestColorQuantize(CStr &inImgs, CStr &outDir)
{
	printf("Quantize images '%s' and  save results to '%s'\n", inImgs.c_str(), outDir.c_str());
	CmFile::MkDir(outDir);
	string inDir;
	vecS names;
	int imgNum = CmFile::GetNames(inImgs, names, inDir);

#pragma omp parallel for
	for (int i = 0; i < imgNum; i++){
		printf("Processing %-40s\r", names[i].c_str());
		string nameNE = CmFile::GetNameNE(names[i]);
		Mat img = imread(inDir + names[i]);
		imwrite(outDir + nameNE + ".jpg", img);
		img.convertTo(img, CV_32FC3, 1/255.f);
		Mat idx, rImg3f;

		for (int j = 0; j < S_Q_NUM; j++){
			S_Quantize(img, idx, j);
			S_Recover(idx, rImg3f, j);
			imwrite(outDir + nameNE + descr[j] + ".jpg", rImg3f * 255);

			S_Quantize(img, idx, j);
			S_Recover(idx, rImg3f, j, img);
			imwrite(outDir + nameNE + descr[j] + "2.jpg", rImg3f * 255);
		}

		//Mat avgColor, colorNum;
		//D_Quantize(img, idx, avgColor, colorNum, 256);
		//D_Recover(idx, rImg3f, avgColor);
		//imwrite(outDir + nameNE + "D_BGR.jpg", rImg3f*255);
	}
	printf("Test color quantization finished\t\t\t\n");

	/*
	Vec3f color;
	Mat org(100, 200, CV_32FC3), dst(100, 200, CV_32FC3), idx;
	while (scanf("%f %f %f", &color[0], &color[1], &color[2]))
	{
		printf("Org: %f, %f, %f\t", color[0], color[1], color[2]);
		org = Scalar(color);
		S_Quantize(org, idx);
		S_Recover(idx, dst);
		color = dst.at<Vec3f>(0, 0);
		printf("Dst: %f, %f, %f\n", color[0], color[1], color[2]);
		cvtColor(org, org, CV_Lab2BGR);
		cvtColor(dst, dst, CV_Lab2BGR);
		imshow("Org", org);
		imshow("Dst", dst);
		waitKey(1);
	}
	//*/
}
示例#6
0
void SFX::readIgniteRetract()
{
  uint8_t nChannels = 0;
  uint32_t samples = 0;
  CStr<25> path;

  if (m_location[SFX_POWER_ON].InUse()) {
    filePath(&path, m_location[SFX_POWER_ON].start);
    readHeader(path.c_str(), &nChannels, &samples, &m_igniteTime);
  }
  if (m_location[SFX_POWER_OFF].InUse())
    filePath(&path, m_location[SFX_POWER_OFF].start);
  readHeader(path.c_str(), &nChannels, &samples, &m_retractTime);
}
示例#7
0
void LumosGame::ItemToButton( const GameItem* item, gamui::Button* button )
{
	CStr<64> text;

	// Set the text to the proper name, if we have it.
	// Then an icon for what it is, and a check
	// mark if the object is in use.
	int value = item->GetValue();
	const char* name = item->ProperName() ? item->ProperName() : item->Name();
	if ( value ) {
		text.Format( "%s\n%d", name, value );
	}
	else {
		text.Format( "%s\n ", name );
	}
	button->SetText( text.c_str() );

	IString decoName = item->keyValues.GetIString( "uiIcon" );
	RenderAtom atom  = LumosGame::CalcUIIconAtom( decoName.c_str(), true );
	atom.renderState = (const void*) UIRenderer::RENDERSTATE_UI_DECO_DISABLED;
	RenderAtom atomD = LumosGame::CalcUIIconAtom( decoName.c_str(), false );
	atomD.renderState = (const void*) UIRenderer::RENDERSTATE_UI_DECO_DISABLED;

	button->SetDeco( atom, atomD );
}
示例#8
0
bool CNetClientSession::Connect(u16 port, const CStr& server)
{
	ENSURE(!m_Host);
	ENSURE(!m_Server);

	// Create ENet host
	ENetHost* host = enet_host_create(NULL, 1, CHANNEL_COUNT, 0, 0);
	if (!host)
		return false;

	// Bind to specified host
	ENetAddress addr;
	addr.port = port;
	if (enet_address_set_host(&addr, server.c_str()) < 0)
		return false;

	// Initiate connection to server
	ENetPeer* peer = enet_host_connect(host, &addr, CHANNEL_COUNT, 0);
	if (!peer)
		return false;

	m_Host = host;
	m_Server = peer;

	m_Stats = new CNetStatsTable(m_Server);
	if (CProfileViewer::IsInitialised())
		g_ProfileViewer.AddRootTable(m_Stats);

	return true;
}
示例#9
0
	bool Compile(GLuint target, const char* targetName, GLuint program, const VfsPath& file, const CStr& code)
	{
		ogl_WarnIfError();

		pglBindProgramARB(target, program);

		ogl_WarnIfError();

		pglProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)code.length(), code.c_str());

		if (ogl_SquelchError(GL_INVALID_OPERATION))
		{
			GLint errPos = 0;
			glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
			int errLine = std::count(code.begin(), code.begin() + std::min((int)code.length(), errPos + 1), '\n') + 1;
			char* errStr = (char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
			LOGERROR(L"Failed to compile %hs program '%ls' (line %d):\n%hs", targetName, file.string().c_str(), errLine, errStr);
			return false;
		}

		pglBindProgramARB(target, 0);

		ogl_WarnIfError();

		return true;
	}
示例#10
0
JSBool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
{
    UNUSED2(argc);

    CStr buffer;

    try
    {
        ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
        double val, valr;
#define SIDE(side) \
		pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), #side, val); \
		pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "r"#side, valr); \
		buffer += ToPercentString(val, valr);
        SIDE(left);
        buffer += " ";
        SIDE(top);
        buffer += " ";
        SIDE(right);
        buffer += " ";
        SIDE(bottom);
#undef SIDE
    }
    catch (PSERROR_Scripting_ConversionFailed&)
    {
        JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, "<Error converting value to numbers>")));
        return JS_TRUE;
    }

    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer.c_str())));
    return JS_TRUE;
}
示例#11
0
void MapScene::EnableButtons()
{
	Vector2I v = data->destSector;
	CoreScript* cs = CoreScript::GetCore(v);
	CoreScript* homeCore = lumosChitBag->GetHomeCore();

	if (!homeCore) {
		warButton.SetEnabled(false);
		peaceButton.SetEnabled(false);
		peaceButton.SetText("Peace Treaty");
		return;
	}

	warButton.SetEnabled(Team::Instance()->War(cs, homeCore, false, &lumosChitBag->GetSim()->GetCachedWeb()));
	int peace = Team::Instance()->Peace(cs, homeCore, false, &lumosChitBag->GetSim()->GetCachedWeb());
	const Wallet* wallet = homeCore->ParentChit()->GetWallet();

	if (peace > 0 && wallet->HasGold(peace)) {
		CStr<64> str;
		str.Format("Peace Treaty %d Au", peace);
		peaceButton.SetEnabled(true);
		peaceButton.SetText(str.c_str());
	}
	else {
		peaceButton.SetEnabled(false);
		peaceButton.SetText("Peace Treaty");
	}
}
示例#12
0
void CmEvaluation::PrintVector(FILE *f, const vecD &v, CStr &name)
{
	fprintf(f, "%s = [", name.c_str());
	for (size_t i = 0; i < v.size(); i++)
		fprintf(f, "%g ", v[i]);
	fprintf(f, "];\n");
}
示例#13
0
// Reads Custom Color
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
{
	// Read the color and stor in m_PreDefinedColors

	XMBAttributeList attributes = Element.GetAttributes();

	//IGUIObject* object = new CTooltip;
	CColor color;
	CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));

	// Try parsing value 
	CStr value (Element.GetText());
	if (! value.empty())
	{
		// Try setting color to value
		if (!color.ParseString(value, 255.f))
		{
			LOGERROR(L"GUI: Unable to create custom color '%hs'. Invalid color syntax.", name.c_str());
		}
		else
		{
			// input color
			m_PreDefinedColors[name] = color;
		}
	}
}
示例#14
0
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value)
{
	ENSURE(pObject != NULL);

	std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting);
	if (it == pObject->m_Settings.end())
	{
		LOGWARNING("setting %s was not found on object %s",
			Setting.c_str(),
			pObject->GetPresentableName().c_str());
		return PSRETURN_GUI_InvalidSetting;
	}

	if (it->second.m_pSetting == NULL)
		return PSRETURN_GUI_InvalidSetting;

#ifndef NDEBUG
	CheckType<T>(pObject, Setting);
#endif

	// Get value
	Value = (T*)(it->second.m_pSetting);

	return PSRETURN_OK;
}
示例#15
0
void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
{
	// Ignore attempts to use tooltip ""
	if (style.empty())
		return;

	IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
	if (! tooltipobj)
	{
		LOGERROR(L"Cannot find tooltip named '%hs'", style.c_str());
		return;
	}

	CStr usedObjectName;
	if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK
		&& !usedObjectName.empty())
	{
		IGUIObject* usedobj = gui->FindObjectByName(usedObjectName);
		if (! usedobj)
		{
			LOGERROR(L"Cannot find object named '%hs' used by tooltip '%hs'", usedObjectName.c_str(), style.c_str());
			return;
		}

		// Clear the caption
		usedobj->SetSetting("caption", L"");
		SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption");
		usedobj->HandleMessage(msg);

		bool hideobject = true;
		GUI<bool>::GetSetting(tooltipobj, "hide_object", hideobject);

		// If hide_object was enabled, hide it
		if (hideobject)
			GUI<bool>::SetSetting(usedobj, "hidden", true);
	}
	else
	{
		GUI<bool>::SetSetting(tooltipobj, "hidden", true);
	}

}
示例#16
0
int EvaluateMain(int argc, char* argv[])
{
	int fId = atoi(argv[1]);
	CStr wkDir = argv[2];
	CStr imgFolder = argv[3];
	CStr rstFolder = argv[4];
	CStr methodNam = argv[5];
	vecS des;
	des.push_back(methodNam);

	if (argc == 7)
	{
		int nr = atoi(argv[6]);
		vecS rstDirs;
		for (int i = 0; i < nr; i++)
		{
			char outFile[50];
			sprintf_s(outFile, "%s%d", rstFolder.c_str(), i);
			rstDirs.push_back(std::string(outFile));
		}
		
		CmEvaluation::EvalueMaskProposals(wkDir, imgFolder, rstDirs, des, wkDir + "\\Results.m");
	}
	else
	{
		switch (fId)
		{
		case 0:
			CmEvaluation::EvalueMask(wkDir + imgFolder + "\\*.png", wkDir + "\\" + rstFolder + "\\", des, wkDir + "\\Results.m");
			break;
		case 1:
			CmEvaluation::DebugEvalueMask(wkDir, imgFolder, rstFolder, des, wkDir + "CutRes.m");
			break;
		case 2:
			CmEvaluation::EvalueMaskProposals(wkDir, imgFolder, rstFolder, des, wkDir + "CutRes.m");
			break;
		case 3:
			ChooseWeight();
			break;

		default:
			break;
		}
	}

	
	//des.push_back("HC");  
	//des.push_back("RC");
	//des.push_back("SF"); des.push_back("SalPIF");
	//CmEvaluation::EvalueMask(wkDir + imgFolder + "\\*.png", wkDir + "\\" + rstFolder+"\\", des, wkDir + "\\Results.m");
	//CmEvaluation::EvalueMaskProposals(wkDir, imgFolder, rstFolder, des, wkDir + "CutRes.m");
	//CmEvaluation::DebugEvalueMask(wkDir, imgFolder, rstFolder, des, wkDir + "CutRes.m");
	return 1;
}
示例#17
0
void Surface::Load( const gamedb::Item* node )
{
	GLASSERT( node->GetBool( "isImage" ) == true );
	if ( !node->GetBool( "isImage" ) )
			return;

	name = node->Name();
	
	CStr<16> formatBuf = node->GetString( "format" ); 
	format = QueryFormat( formatBuf.c_str() );

	w = node->GetInt( "width" );
	h = node->GetInt( "height" );

	Set( Surface::QueryFormat( formatBuf.c_str() ), w, h );
		
	int size = node->GetDataSize( "pixels" );
	GLASSERT( size == BytesInImage() );

	node->GetData( "pixels", Pixels(), size );
}
示例#18
0
InReaction IGUIObject::SendEvent(EGUIMessageType type, const CStr& EventName)
{
	PROFILE2_EVENT("gui event");
	PROFILE2_ATTR("type: %s", EventName.c_str());
	PROFILE2_ATTR("object: %s", m_Name.c_str());

	SGUIMessage msg(type);
	HandleMessage(msg);

	ScriptEvent(EventName);

	return (msg.skipped ? IN_PASS : IN_HANDLED);
}
示例#19
0
const GameItem* PlantScript::PlantDef(int plant0Based)
{
	GLASSERT(plant0Based >= 0 && plant0Based < NUM_EXTENDED_PLANT_TYPES);
	if (plantDef[0] == 0) {
		for (int i = 0; i < NUM_EXTENDED_PLANT_TYPES; ++i) {
			CStr<32> str;
			str.Format("plant%d", i);
			plantDef[i] = &ItemDefDB::Instance()->Get(str.c_str());
		}
	}
	GLASSERT(plantDef[plant0Based]);
	return plantDef[plant0Based];
}
示例#20
0
static int GetTooltipDelay(CStr& style, CGUI* gui)
{
	int delay = 500; // default value (in msec)

	IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
	if (! tooltipobj)
	{
		LOGERROR(L"Cannot find tooltip object named '%hs'", style.c_str());
		return delay;
	}
	GUI<int>::GetSetting(tooltipobj, "delay", delay);
	return delay;
}
示例#21
0
const char* Game::GamePath( const char* type, int slot, const char* extension ) const
{	
	CStr<256> str;
	//str = "save/";
	str += type;

	if ( slot > 0 ) {
		str += "-";
		str += '0' + slot;
	}
	str += ".";
	str += extension;
	return StringPool::Intern( str.c_str() ).c_str();
}
示例#22
0
//------------------------------------------------------------------------------
/// \brief
//------------------------------------------------------------------------------
void NativeExpMf6Nam::WriteChdFile ()
{
  MfGlobal *g = m_pack->GetGlobal();
  if (!g) return;
  Mf2kNative* n = m_pack->GetNative();
  if (!n) return;
  CStr baseName = n->FileName();
  util::StripExtensionFromFilename(baseName, baseName);
  baseName += ".chd";

  std::vector<CStr> fieldStrings;
  int MAXBOUND(0);
  CStr chdStr = MfExportUtil::Mf6IboundToChd(g, MAXBOUND, fieldStrings);

  std::vector<CStr> lines;

  lines.push_back(MfExportUtil::GetMf6CommentHeader());
  lines.push_back("BEGIN OPTIONS");
  int saveFlows(0);
  if (g->GetIntVar("MF6_SAVE_FLOWS", saveFlows) && saveFlows)
  {
    lines.push_back("  SAVE_FLOWS");
  }
  lines.push_back("END OPTIONS");
  lines.push_back("");

  lines.push_back("BEGIN DIMENSIONS");
  CStr dimStr;
  dimStr.Format("  MAXBOUND %d", MAXBOUND);
  lines.push_back(dimStr);
  lines.push_back("END DIMENSIONS");
  lines.push_back("");

  lines.push_back("BEGIN PERIOD 1");
  lines.push_back(chdStr);
  lines.push_back("END PERIOD 1");

  FILE *fp = fopen(baseName.c_str(), "w");
  if (fp)
  {
    for (size_t i=0; i<lines.size(); ++i)
    {
      fprintf(fp, "%s\n", lines[i].c_str());
    }
    fclose(fp);
  }
} // NativeExpMf6Nam::WriteChdFile
示例#23
0
CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const VfsPath& pathname)
{
	CXeromyces XeroFile;
	if (XeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
		return CTerrainPropertiesPtr();

	XMBElement root = XeroFile.GetRoot();
	CStr rootName = XeroFile.GetElementString(root.GetNodeName());

	// Check that we've got the right kind of xml document
	if (rootName != "Terrains")
	{
		LOGERROR(
			L"TerrainProperties: Loading %ls: Root node is not terrains (found \"%hs\")",
			pathname.string().c_str(),
			rootName.c_str());
		return CTerrainPropertiesPtr();
	}
	
	#define ELMT(x) int el_##x = XeroFile.GetElementID(#x)
	ELMT(terrain);
	#undef ELMT
	
	// Ignore all non-terrain nodes, loading the first terrain node and
	// returning it.
	// Really, we only expect there to be one child and it to be of the right
	// type, though.
	XERO_ITER_EL(root, child)
	{
		if (child.GetNodeName() == el_terrain)
		{
			CTerrainPropertiesPtr ret (new CTerrainProperties(parent));
			ret->LoadXml(child, &XeroFile, pathname);
			return ret;
		}
		else
		{
			LOGWARNING(
				L"TerrainProperties: Loading %ls: Unexpected node %hs\n",
				pathname.string().c_str(),
				XeroFile.GetElementString(child.GetNodeName()).c_str());
			// Keep reading - typos shouldn't be showstoppers
		}
	}
	
	return CTerrainPropertiesPtr();
}
示例#24
0
//------------------------------------------------------------------------------
/// \brief
//------------------------------------------------------------------------------
bool NativeExpMf6Nam::ValidPackage (const CStr& a_ftype)
{
  const int NUMTYPES = 21;
  std::string types[NUMTYPES] =
    { "DIS", "DISV", "DISU", "IC", "OC", "NPF", "HFB", "STO", "CHD", "WEL",
      "DRN", "RIV", "GHB", "RCH", "EVT", "MAW", "SFR", "LAK", "UZF", "MVR",
      "GNC" };
  std::set<std::string> setTypes(&types[0], &types[NUMTYPES]);
  if (setTypes.find(a_ftype) != setTypes.end())
  {
    return true;
  }
  CStr msg;
  msg.Format("WARNING: Package %s is not supported for conversion to MF6.", a_ftype);
  printf("%s\n", msg.c_str());
  return false;
} // NativeExpMf6Nam::ValidPackage
示例#25
0
文件: GUIutil.cpp 项目: Marlinc/0ad
PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, 
							 const T &Value, const bool& SkipMessage)
{
	ENSURE(pObject != NULL);

	if (!pObject->SettingExists(Setting))
	{
		LOGWARNING(L"setting %hs was not found on object %hs", 
			Setting.c_str(),
			pObject->GetPresentableName().c_str());
		return PSRETURN_GUI_InvalidSetting;
	}

#ifndef NDEBUG
	CheckType<T>(pObject, Setting);
#endif

	// Set value
	*(T*)pObject->m_Settings[Setting].m_pSetting = Value;

	//
	//	Some settings needs special attention at change
	//

	// If setting was "size", we need to re-cache itself and all children
	if (Setting == "size")
	{
		RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
	}
	else
	if (Setting == "hidden")
	{
		// Hiding an object requires us to reset it and all children
		if (IsBoolTrue(Value))
			QueryResetting(pObject);
	}

	if (!SkipMessage)
	{
		SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting);
		HandleMessage(pObject, msg);
	}

	return PSRETURN_OK;
}
示例#26
0
Chit* LumosChitBag::NewLawnOrnament(const Vector2I& pos, const char* name, int team)
{
	const ChitContext* context = Context();
	Chit* chit = NewChit();

	GameItem* rootItem = ItemDefDB::Instance()->Get(name).Clone();

	// Hack...how to do this better??
	if (rootItem->IResourceName() == "ruins1.0") {
		CStr<32> str;
		str.Format("ruins1.%d", random.Rand(2));
		rootItem->SetResource(str.c_str());
	}

	int size = 1;
	rootItem->keyValues.Get(ISC::size, &size);

	MapSpatialComponent* msc = new MapSpatialComponent();
	msc->SetBuilding(size, false, 0);
	msc->SetBlocks((rootItem->flags & GameItem::PATH_NON_BLOCKING) ? false : true);
	chit->Add(msc);
	MapSpatialComponent::SetMapPosition(chit, pos.x, pos.y);


	chit->Add(new RenderComponent(rootItem->ResourceName()));
	chit->Add(new HealthComponent());
	AddItem(rootItem, chit, context->engine, team, 0);

	IString proc = rootItem->keyValues.GetIString("procedural");
	if (!proc.empty()) {
		ProcRenderInfo info;
		AssignProcedural(chit->GetItem(), &info);
		chit->GetRenderComponent()->SetProcedural(0, info);
	}
	
	context->engine->particleSystem->EmitPD(ISC::constructiondone, ToWorld3F(pos), V3F_UP, 0);

	if (XenoAudio::Instance()) {
		Vector3F pos3 = ToWorld3F(pos);
		XenoAudio::Instance()->PlayVariation(ISC::rezWAV, random.Rand(), &pos3);
	}

	return chit;
}
示例#27
0
void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValue Argument)
{
	auto it = m_ScriptHandlers.find(Action);
	if (it == m_ScriptHandlers.end())
		return;

	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
	JSAutoRequest rq(cx);
	JS::AutoValueVector paramData(cx);
	paramData.append(Argument.get());
	JS::RootedObject obj(cx, GetJSObject());
	JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
	JS::RootedValue result(cx);
	bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
	if (!ok)
	{
		JS_ReportError(cx, "Errors executing script action \"%s\"", Action.c_str());
	}
}
示例#28
0
const ModelResource* PlantScript::PlantRes(int plant0Based, int stage)
{
	GLASSERT(plant0Based >= 0 && plant0Based < NUM_EXTENDED_PLANT_TYPES);
	GLASSERT(stage >= 0 && stage < MAX_PLANT_STAGES);

	if (plantResource[0][0] == 0) {
		for (int i = 0; i < NUM_EXTENDED_PLANT_TYPES; ++i) {
			const int nStage = PlantIsFlower(i) ? PLANT_BLOCKING_STAGE : MAX_PLANT_STAGES;
			for (int j = 0; j < nStage; ++j) {
				CStr<32> str;
				str.Format("plant%d.%d", i, j);
				plantResource[i][j] = ModelResourceManager::Instance()->GetModelResource(str.c_str(), false);
				GLASSERT(plantResource[i][j]);
			}
		}
	}
	GLASSERT(plantResource[plant0Based][stage]);
	return plantResource[plant0Based][stage];
}
示例#29
0
文件: CGUI.cpp 项目: 2asoft/0ad
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
{
	XMBAttributeList attributes = Element.GetAttributes();

	CColor color;
	CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));

	// Try parsing value
	CStr value(Element.GetText());
	if (value.empty())
		return;

	// Try setting color to value
	if (!color.ParseString(value))
	{
		LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
		return;
	}

	m_PreDefinedColors[name] = color;
}
示例#30
0
	bool Compile(GLhandleARB shader, const VfsPath& file, const CStr& code)
	{
		TIMER_ACCRUE(tc_ShaderGLSLCompile);

		ogl_WarnIfError();

		const char* code_string = code.c_str();
		GLint code_length = code.length();
		pglShaderSourceARB(shader, 1, &code_string, &code_length);

		pglCompileShaderARB(shader);

		GLint ok = 0;
		pglGetShaderiv(shader, GL_COMPILE_STATUS, &ok);

		GLint length = 0;
		pglGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);

		// Apparently sometimes GL_INFO_LOG_LENGTH is incorrectly reported as 0
		// (http://code.google.com/p/android/issues/detail?id=9953)
		if (!ok && length == 0)
			length = 4096;

		if (length > 1)
		{
			char* infolog = new char[length];
			pglGetShaderInfoLog(shader, length, NULL, infolog);

			if (ok)
				LOGMESSAGE(L"Info when compiling shader '%ls':\n%hs", file.string().c_str(), infolog);
			else
				LOGERROR(L"Failed to compile shader '%ls':\n%hs", file.string().c_str(), infolog);

			delete[] infolog;
		}

		ogl_WarnIfError();

		return (ok ? true : false);
	}