当前位置: 首页>>代码示例>>C++>>正文


C++ C4Value类代码示例

本文整理汇总了C++中C4Value的典型用法代码示例。如果您正苦于以下问题:C++ C4Value类的具体用法?C++ C4Value怎么用?C++ C4Value使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了C4Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void C4MapScriptMatTexMask::Init(const C4Value &spec)
{
	// Mask may be initialized by a simple string or by an array of strings, of which the effects are OR'ed
	const C4ValueArray *arr = spec.getArray();
	if (arr)
	{
		// Init by array
		for (int32_t i=0; i<arr->GetSize(); ++i)
		{
			C4String *smask = arr->GetItem(i).getStr();
			if (!smask) throw C4AulExecError(FormatString("MatTexMask expected string as %dth element in array.", (int)i).getData());
			UnmaskSpec(smask);
		}
	}
	else
	{
		// Init by string
		C4String *smask = spec.getStr();
		if (smask)
			UnmaskSpec(smask);
		else
		{
			if (spec) throw C4AulExecError("MatTexMask expected string or array of strings.");
			// nil defaults to everything except index zero unmasked
			sky_mask = std::vector<bool>(256, true);
			tunnel_mask = std::vector<bool>(256, true);
			sky_mask[0] = false;
			tunnel_mask[0] = false;
		}
	}
}
开发者ID:farad91,项目名称:openclonk,代码行数:31,代码来源:C4MapScript.cpp

示例2: operator

 bool operator ()(const C4Value &v1, const C4Value &v2)
 {
     C4Value p1,p2;
     if (!v1._getPropList()->GetPropertyByS(prop_name, &p1)) p1.Set0();
     if (!v2._getPropList()->GetPropertyByS(prop_name, &p2)) p2.Set0();
     return value_sort(p1,p2);
 }
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:7,代码来源:C4ValueArray.cpp

示例3:

void C4Effect::SetPropertyByS(C4String * k, const C4Value & to)
{
	if (k >= &Strings.P[0] && k < &Strings.P[P_LAST])
	{
		switch(k - &Strings.P[0])
		{
			case P_Name:
				if (!to.getStr() || !*to.getStr()->GetCStr())
					throw C4AulExecError("effect: Name has to be a nonempty string");
				C4PropListNumbered::SetPropertyByS(k, to);
				ReAssignCallbackFunctions();
				return;
			case P_Priority:
				throw C4AulExecError("effect: Priority is readonly");
			case P_Interval: iInterval = to.getInt(); return;
			case P_CommandTarget:
				throw C4AulExecError("effect: CommandTarget is readonly");
			case P_Target:
				throw C4AulExecError("effect: Target is readonly");
			case P_Time: iTime = to.getInt(); return;
			case P_Prototype:
				throw new C4AulExecError("effect: Prototype is readonly");
		}
	}
	C4PropListNumbered::SetPropertyByS(k, to);
}
开发者ID:TheBlackJokerDevil,项目名称:openclonk,代码行数:26,代码来源:C4Effect.cpp

示例4:

bool C4MapScriptAlgo::GetXYProps(const C4PropList *props, C4PropertyName k, int32_t *out_xy, bool zero_defaults)
{
	// Evaluate property named "k" in proplist props to store two numbers in out_xy:
	// If props->k is a single integer, fill both numbers in out_xy with it
	// If props->k is an array, check that it contains two numbers and store them in out_xy
	if (!props->HasProperty(&Strings.P[k]))
	{
		if (zero_defaults) out_xy[0] = out_xy[1] = 0;
		return false;
	}
	C4Value val; C4ValueArray *arr;
	props->GetProperty(k, &val);
	if ((arr = val.getArray()))
	{
		if (arr->GetSize() != 2)
			throw C4AulExecError(FormatString("C4MapScriptAlgo: Expected either integer or array with two integer elements in property \"%s\".", Strings.P[k].GetCStr()).getData());
		out_xy[0] = arr->GetItem(0).getInt();
		out_xy[1] = arr->GetItem(1).getInt();
	}
	else
	{
		out_xy[0] = out_xy[1] = val.getInt();
	}
	return true;
}
开发者ID:TheBlackJokerDevil,项目名称:openclonk,代码行数:25,代码来源:C4MapScriptAlgo.cpp

示例5: assert

bool C4FindObjectProcedure::Check(C4Object *pObj)
{
	assert(pObj);
	if (!pObj->GetAction()) return false;
	C4Value v;
	pObj->GetAction()->GetProperty(P_Procedure, &v);
	return v != C4VNull && v.getStr() == procedure;
}
开发者ID:772,项目名称:openclonk,代码行数:8,代码来源:C4FindObject.cpp

示例6:

void C4ParticleValueProvider::Set(const C4Value &value)
{
	C4ValueArray *valueArray= value.getArray();

	if (valueArray != 0)
		Set(*valueArray);
	else
		Set((float)value.getInt());
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:9,代码来源:C4Particles.cpp

示例7: FnLayerSetPixel

static bool FnLayerSetPixel(C4PropList * _this, int32_t x, int32_t y, const C4Value& fg_value_c4v, const C4Value& bg_value_c4v)
{
	// Layer script function: Set pixel at position x,y to to_value in _this layer
	C4MapScriptLayer *layer = _this->GetMapScriptLayer();
	if (!layer) return false;
	uint8_t fg, bg;

	if (fg_value_c4v.GetType() == C4V_Nil)
	{
		fg = layer->GetPix(x,y,0);
	}
	else
	{
		const C4Value& val = fg_value_c4v;
		C4String *str = val.getStr();
		if (str != NULL)
		{
			if (!TexColSingle(str->GetCStr(), fg))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
		}
		else
		{
			if (!Inside(val.getInt(), 0, 255))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
			fg = val.getInt();
		}
	}

	if (bg_value_c4v.GetType() == C4V_Nil)
	{
		bg = layer->GetBackPix(x,y,0);
	}
	else
	{
		const C4Value& val = bg_value_c4v;
		C4String *str = val.getStr();
		if (str != NULL)
		{
			if (!TexColSingle(str->GetCStr(), bg))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
		}
		else
		{
			if (!Inside(val.getInt(), 0, 255))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
			bg = val.getInt();
		}
	}
			
	return layer->SetPix(x,y,fg,bg);
}
开发者ID:farad91,项目名称:openclonk,代码行数:51,代码来源:C4MapScript.cpp

示例8: Call

int32_t C4Def::GetValue(C4Object *pInBase, int32_t iBuyPlayer)
{
	C4Value r = Call(PSF_CalcDefValue, &C4AulParSet(pInBase, iBuyPlayer));
	int32_t iValue = Value;
	if (r != C4VNull)
		iValue = r.getInt();
	// do any adjustments based on where the item is bought
	if (pInBase)
	{
		r = pInBase->Call(PSF_CalcBuyValue, &C4AulParSet(this, iValue));
		if (r != C4VNull)
			iValue = r.getInt();
	}
	return iValue;
}
开发者ID:farad91,项目名称:openclonk,代码行数:15,代码来源:C4Def.cpp

示例9: FnLayerGetDefaultBackgroundIndex

static int32_t FnLayerGetDefaultBackgroundIndex(C4PropList * _this, const C4Value &value)
{
	uint8_t fg;
	C4String* str;

	if ((str = value.getStr()))
	{
		if (!TexColSingle(str->GetCStr(), fg))
			return -1;
	}
	else
	{
		if (!Inside(value.getInt(), 0, 255))
			return -1;
		fg = value.getInt();
	}

	return ::MapScript.pTexMap->DefaultBkgMatTex(fg);
}
开发者ID:farad91,项目名称:openclonk,代码行数:19,代码来源:C4MapScript.cpp

示例10: FnParAlgo

C4MapScriptAlgoModifier::C4MapScriptAlgoModifier(const C4PropList *props, int32_t min_ops, int32_t max_ops)
{
	// Evaluate "Op" property of all algos that take another algo or layer as an operand
	// Op may be a proplist or an array of proplists
	C4Value vops; int32_t n; C4ValueArray temp_ops;
	props->GetProperty(P_Op, &vops);
	C4ValueArray *ops = vops.getArray();
	if (!ops)
	{
		C4PropList *op = vops.getPropList();
		if (op)
		{
			temp_ops.SetItem(0, vops);
			ops = &temp_ops;
			n = 1;
		}
	}
	else
	{
		n = ops->GetSize();
	}
	if (!ops || n<min_ops || (max_ops && n>max_ops))
		throw C4AulExecError(FormatString("C4MapScriptAlgo: Expected between %d and %d operands in property \"Op\".", (int)min_ops, (int)max_ops).getData());
	operands.resize(n);
	try
	{
		// can easily crash this by building a recursive prop list
		// unfortunately, protecting against that is not trivial
		for (int32_t i=0; i<n; ++i)
		{
			C4MapScriptAlgo *new_algo = FnParAlgo(ops->GetItem(i).getPropList());
			if (!new_algo) throw C4AulExecError(FormatString("C4MapScriptAlgo: Operand %d in property \"Op\" not valid.", (int)i).getData());
			operands[i] = new_algo;
		}
	}
	catch (...)
	{
		Clear();
		throw;
	}
}
开发者ID:TheBlackJokerDevil,项目名称:openclonk,代码行数:41,代码来源:C4MapScriptAlgo.cpp

示例11: QDialog

C4ConsoleQtLocalizeStringDlg::C4ConsoleQtLocalizeStringDlg(class QMainWindow *parent_window, const C4Value &translations)
	: QDialog(parent_window, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
	, translations(translations)
{
	ui.setupUi(this);
	// Add language editors
	int32_t lang_index = 0;
	C4LanguageInfo *lang_info;
	while (lang_info = ::Languages.GetInfo(lang_index++))
	{
		AddEditor(lang_info->Code, lang_info->Name);
	}
	// Fill in values
	C4PropList *translations_proplist = translations.getPropList();
	assert(translations_proplist);
	for (C4String *lang_str : translations_proplist->GetSortedLocalProperties(false))
	{
		if (lang_str->GetData().getLength() == 2)
		{
			C4Value text_val;
			if (translations_proplist->GetPropertyByS(lang_str, &text_val))
			{
				C4String *text = text_val.getStr();
				if (text)
				{
					QLineEdit *editor = GetEditorByLanguage(lang_str->GetCStr());
					if (!editor)
					{
						// Unknown language. Just add an editor without language name.
						editor = AddEditor(lang_str->GetCStr(), nullptr);
					}
					editor->setText(QString(text->GetCStr()));
				}
			}
		}
	}
	// Size
	adjustSize();
	setMinimumSize(size());
	// Focus on first empty editor
	if (edited_languages.size())
	{
		edited_languages.front().value_editor->setFocus(); // fallback to first editor
		for (const auto & langs : edited_languages)
		{
			if (!langs.value_editor->text().length())
			{
				langs.value_editor->setFocus();
				break;
			}
		}
	}
}
开发者ID:Fulgen301,项目名称:openclonk,代码行数:53,代码来源:C4ConsoleQtLocalizeString.cpp

示例12: assert

C4PropList *C4Def::GetActionByName(C4String *actname)
{
	assert(actname);
	// If we get the null string or ActIdle by name, return NULL action
	if (!actname || actname == &Strings.P[P_Idle]) return NULL;
	// otherwise, query actmap
	C4Value ActMap; GetProperty(P_ActMap, &ActMap);
	if (!ActMap.getPropList()) return NULL;
	C4Value Action; ActMap.getPropList()->GetPropertyByS(actname, &Action);
	if (!Action.getPropList()) return NULL;
	return Action.getPropList();
}
开发者ID:farad91,项目名称:openclonk,代码行数:12,代码来源:C4Def.cpp

示例13: if

void C4PropList::SetPropertyByS(C4String * k, const C4Value & to)
{
	assert(!constant);
	if (k == &Strings.P[P_Prototype])
	{
		C4PropList * newpt = to.getPropList();
		for(C4PropList * it = newpt; it; it = it->GetPrototype())
			if(it == this)
				throw C4AulExecError("Trying to create cyclic prototype structure");
		prototype.SetPropList(newpt);
	}
	else if (Properties.Has(k))
	{
		Properties.Get(k).Value = to;
	}
	else
	{
		Properties.Add(C4Property(k, to));
	}
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:20,代码来源:C4PropList.cpp

示例14: if

void C4ParticleValueProvider::SetParameterValue(int type, const C4Value &value, float C4ParticleValueProvider::*floatVal, int C4ParticleValueProvider::*intVal, size_t keyFrameIndex)
{
	// just an atomic data type
	if (value.GetType() == C4V_Int)
	{
		if (type == VAL_TYPE_FLOAT)
			this->*floatVal = (float)value.getInt();
		else if (type == VAL_TYPE_INT)
			this->*intVal = value.getInt();
		else if (type == VAL_TYPE_KEYFRAMES)
			this->keyFrames[keyFrameIndex] = (float)value.getInt();
	}
	else if (value.GetType() == C4V_Array)
	{
		//  might be another value provider!
		C4ParticleValueProvider *child = new C4ParticleValueProvider();
		childrenValueProviders.push_back(child);

		child->Set(*value.getArray());
		child->typeOfValueToChange = type;

		if (type == VAL_TYPE_FLOAT)
		{
			child->floatValueToChange = floatVal;
		}
		else if (type == VAL_TYPE_INT)
		{
			child->intValueToChange = intVal;
		}
		else if (type == VAL_TYPE_KEYFRAMES)
		{
			child->keyFrameIndex = keyFrameIndex;
		}

	}
	else // invalid
	{
		if (type == VAL_TYPE_FLOAT)
			this->*floatVal = 0.f;
		else if (type == VAL_TYPE_INT)
			this->*intVal = 0;
		else if (type == VAL_TYPE_KEYFRAMES)
			this->keyFrames[keyFrameIndex] = 0.f;
	}
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:45,代码来源:C4Particles.cpp

示例15: assert

void C4GraphicsOverlay::UpdateFacet()
{
	// special: Nothing to update for object and pSourceGfx may be NULL
	// If there will ever be something to init here, UpdateFacet() will also need to be called when objects have been loaded
	if (eMode == MODE_Object) return;
	// otherwise, source graphics must be specified
	if (!pSourceGfx) return;
	C4Def *pDef = pSourceGfx->pDef;
	assert(pDef);
	fZoomToShape = false;
	// Clear old mesh instance, if any
	delete pMeshInstance; pMeshInstance = NULL;
	// update by mode
	switch (eMode)
	{
	case MODE_None:
		break;

	case MODE_Base: // def base graphics
		if (pSourceGfx->Type == C4DefGraphics::TYPE_Bitmap)
			fctBlit.Set(pSourceGfx->GetBitmap(), 0, 0, pDef->Shape.Wdt, pDef->Shape.Hgt, pDef->Shape.x+pDef->Shape.Wdt/2, pDef->Shape.y+pDef->Shape.Hgt/2);
		else if (pSourceGfx->Type == C4DefGraphics::TYPE_Mesh)
			pMeshInstance = new StdMeshInstance(*pSourceGfx->Mesh, 1.0f);
		break;

	case MODE_Action: // graphics of specified action
	{
		// Clear old facet
		fctBlit.Default();

		// Ensure there is actually an action set
		if (!Action[0])
			return;

		C4Value v;
		pDef->GetProperty(P_ActMap, &v);
		C4PropList *actmap = v.getPropList();
		if (!actmap)
			return;

		actmap->GetPropertyByS(::Strings.RegString(Action), &v);
		C4PropList *action = v.getPropList();
		if (!action)
			return;

		if (pSourceGfx->Type == C4DefGraphics::TYPE_Bitmap)
		{
			fctBlit.Set(pSourceGfx->GetBitmap(),
			            action->GetPropertyInt(P_X), action->GetPropertyInt(P_Y),
			            action->GetPropertyInt(P_Wdt), action->GetPropertyInt(P_Hgt));
			// FIXME: fctBlit.TargetX has to be set here
		}
		else if (pSourceGfx->Type == C4DefGraphics::TYPE_Mesh)
		{
			C4String* AnimationName = action->GetPropertyStr(P_Animation);
			if (!AnimationName) return;

			pMeshInstance = new StdMeshInstance(*pSourceGfx->Mesh, 1.0f);
			const StdMeshAnimation* Animation = pSourceGfx->Mesh->GetSkeleton().GetAnimationByName(AnimationName->GetData());
			if (!Animation) return;

			pMeshInstance->PlayAnimation(*Animation, 0, NULL, new C4ValueProviderRef<int32_t>(iPhase, ftofix(Animation->Length / action->GetPropertyInt(P_Length))), new C4ValueProviderConst(itofix(1)), true);
		}

		break;
	}
	case MODE_ObjectPicture: // ingame picture of object
		// calculated at runtime
		break;

	case MODE_IngamePicture:
	case MODE_Picture: // def picture
		fZoomToShape = true;
		// drawn at runtime
		break;

	case MODE_ExtraGraphics: // like ColorByOwner-sfc
		// calculated at runtime
		break;

	case MODE_Rank:
		// drawn at runtime
		break;

	case MODE_Object:
		// TODO
		break;
	}
}
开发者ID:TheBlackJokerDevil,项目名称:openclonk,代码行数:89,代码来源:C4DefGraphics.cpp


注:本文中的C4Value类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。