bool Configure_ChaseCam_HandlerData::VerifyAndAdjust()
{
	float Temp;
	float Damping, Spring;
	bool IsOK = true;
	
	// First, check the spring-constant factors
	if (GetFloat(DampingCtrl,Damping))
	{
		// Simple damping-factor validation
		float NewTemp = PIN(Damping, -1, 1);
		if (NewTemp != Damping)
		{
			Damping = NewTemp;
			SetFloat(DampingCtrl,Damping);
			IsOK = false;
		}
	}
	else
		IsOK = false;

	IsOK = IsOK && GetFloat(SpringCtrl,Spring);

	if (IsOK)
	{
		// Do validation: will the chase cam be unstable?			

		if (Spring >= 0)
		{
			// Oscillatory case
			float DampSq = Damping*Damping;
			if ((DampSq + Spring) >= 1)
			{
				Spring = 1 - DampSq;
				SetFloat(SpringCtrl,Spring);
				IsOK = false;
			}
		}
		else
		{
			// Overdamped case
			float DampAbs = fabs(Damping);
			if ((DampAbs + sqrt(-Spring)) >= 1)
			{
				float DACmpl = 1 - DampAbs;
				Spring = - DACmpl*DACmpl;
				SetFloat(SpringCtrl,Spring);
				IsOK = false;
			}
		}
	}
	
	// Don't really need these values here
	IsOK = IsOK && GetFloat(BehindCtrl,Temp);
	IsOK = IsOK && GetFloat(UpwardCtrl,Temp);
	IsOK = IsOK && GetFloat(RightwardCtrl,Temp);
	
	// Get the opacity to within a reasonable range
	if (GetFloat(CC_OpacityCtrl,Temp))
	{
		float NewTemp = PIN(Temp, 0, 1);
		if (NewTemp != Temp)
		{
			SetFloat(CC_OpacityCtrl, NewTemp);
			IsOK = false;
		}
	}
	else
		IsOK = false;
	
	if (!IsOK) SysBeep(30);
	
	return IsOK;
}
Ejemplo n.º 2
0
void* schedRunFunc(void* arg)
{
	pthread_mutex_lock (&gLangMutex);


	VMGlobals *g = gMainVMGlobals;
	PyrObject* inQueue = slotRawObject(&g->process->sysSchedulerQueue);
	//dumpObject(inQueue);

	gRunSched = true;
	while (true) {
		assert(inQueue->size);

		//postfl("wait until there is something in scheduler\n");
		// wait until there is something in scheduler
		while (inQueue->size == 1) {
			//postfl("wait until there is something in scheduler\n");
			pthread_cond_wait (&gSchedCond, &gLangMutex);
			if (!gRunSched) goto leave;
		}
		//postfl("wait until an event is ready\n");

		// wait until an event is ready
		double elapsed;
		do {
			elapsed = elapsedTime();
			if (elapsed >= slotRawFloat(inQueue->slots + 1)) break;
			struct timespec abstime;
			//doubleToTimespec(inQueue->slots->uf, &abstime);
			ElapsedTimeToTimespec(slotRawFloat(inQueue->slots + 1), &abstime);
			//postfl("wait until an event is ready\n");
			pthread_cond_timedwait (&gSchedCond, &gLangMutex, &abstime);
			if (!gRunSched) goto leave;
			//postfl("time diff %g\n", elapsedTime() - inQueue->slots->uf);
		} while (inQueue->size > 1);

		//postfl("perform all events that are ready %d %.9f\n", inQueue->size, elapsed);

		// perform all events that are ready
		//postfl("perform all events that are ready\n");
		while ((inQueue->size > 1) && elapsed >= slotRawFloat(inQueue->slots + 1)) {
			double schedtime, delta;
			PyrSlot task;

			//postfl("while %.6f >= %.6f\n", elapsed, inQueue->slots->uf);

			getheap(g, inQueue, &schedtime, &task);

			if (isKindOfSlot(&task, class_thread)) {
				SetNil(&slotRawThread(&task)->nextBeat);
			}

			slotCopy((++g->sp), &task);
			SetFloat(++g->sp, schedtime);
			SetFloat(++g->sp, schedtime);
			++g->sp;	SetObject(g->sp, s_systemclock->u.classobj);

			runAwakeMessage(g);
			long err = slotDoubleVal(&g->result, &delta);
			if (!err) {
				// add delta time and reschedule
				double time = schedtime + delta;

				schedAdd(g, inQueue, time, &task);
			}
		}
		//postfl("loop\n");
	}
	//postfl("exitloop\n");
leave:
	pthread_mutex_unlock (&gLangMutex);
	return 0;
}
Ejemplo n.º 3
0
Colour::Colour(float r, float g, float b, float a)
{
    SetFloat(r, g, b, a);
}
Ejemplo n.º 4
0
void Camera::Run(MOUSEHOOKSTRUCTEX * Mouse, WPARAM wParam)
{
	if( pMapNumber == 30 || pMapNumber == 31 )
	{
		this->IsActive = false;
		this->Init();
	}
	// ----
	switch(wParam)
	{
	case WM_MOUSEWHEEL:
		{
			if( !this->IsActive || gInterface.CheckWindow(MoveList) )
			{
				return;
			}
			// ----
			if( (int)Mouse->mouseData > 0 )
			{
				if( *(float*)oCam_Zoom < ZOOM_MAX )
				{
					SetFloat((LPVOID)oCam_Zoom,	*(float*)oCam_Zoom + ZOOM_INTER);
				}
				else
				{
					SetFloat((LPVOID)oCam_Zoom,	(float)ZOOM_MAX);
				}
			}
			else if( (int)Mouse->mouseData < 0 )
			{
				if( *(float*)oCam_Zoom > ZOOM_MIN )
				{
					SetFloat((LPVOID)oCam_Zoom,	*(float*)oCam_Zoom - ZOOM_INTER);
				}
				else
				{
					SetFloat((LPVOID)oCam_Zoom,	(float)ZOOM_MIN);
				}
			}
			// ----
			this->ZoomPercent = *(float*)oCam_Zoom / ((float)ZOOM_MAX / 100.0f);
			// ----
			SetDouble((LPVOID)oCam_ClipX, PERCF(PERCF(this->Default.ClipX, 500), this->ZoomPercent));
			SetFloat((LPVOID)oCam_ClipY, PERCF(PERCF(this->Default.ClipY, 285), this->ZoomPercent));
			SetDouble((LPVOID)oCam_ClipZ, PERCF(PERCF(this->Default.ClipZ, -395), this->ZoomPercent));
			SetDouble((LPVOID)oCam_ClipX2, PERCF(PERCF(this->Default.ClipX2, 235), this->ZoomPercent));
			SetFloat((LPVOID)oCam_ClipY2, PERCF(PERCF(this->Default.ClipY2, 195), this->ZoomPercent));
			SetFloat((LPVOID)oCam_ClipZ2, PERCF(PERCF(this->Default.ClipZ2, -4000), this->ZoomPercent));
			SetFloat((LPVOID)oCam_ClipGL, PERCF(PERCF(this->Default.ClipGL, 250), this->ZoomPercent));
		}
		break;
		// --
	case WM_MBUTTONDOWN:
		{
			this->InMove = true;
		}
		break;
		// --
	case WM_MBUTTONUP:
		{
			this->InMove = false;
		}
		break;
	}
}
Ejemplo n.º 5
0
    // caution: this is called from a secondary thread!
    void callback(int cube,unsigned int event,unsigned int param)
    {
        const t_symbol *sym = NULL;
        AtomListStatic<64> at;
        
        switch(event) {
            case CUBE_EVENT_USB_ATTACHED:
                sym = sym_attach; 
                at(1);
                SetInt(at[0],cube);
                break;
                
            case CUBE_EVENT_USB_DETACHED:
                sym = sym_detach; 
                at(1);
                SetInt(at[0],cube);
                break;
                
            case CUBE_EVENT_TOPOLOGY_UPDATE: {
                int topology_length;
                unsigned char topology[CUBE_MAX_TOPOLOGY_TABLE_SIZE];
                topology_length = CubeTopology(topology);

                sym = sym_topology;
                at(topology_length*4);
                for(int i = 0; i < topology_length; ++i) {
                    SetInt(at[0+i*4],topology[i*2+0]/16);
                    SetInt(at[1+i*4],topology[i*2+0]%16);
                    SetInt(at[2+i*4],topology[i*2+1]/16);
                    SetInt(at[3+i*4],topology[i*2+1]%16);
                }
                
                if(!init) {
                    // TODO: do some initialization stuff (attach flag, color, sensors etc.)
                    init = true;
                }
                
                break;
            }
            
            case CUBE_EVENT_SENSOR_UPDATE: 
                sym = sym_sensor; 
                at(3);
                SetInt(at[0],cube);
                SetInt(at[1],param); 
                SetFloat(at[2],CubeSensorValue(cube,param));
                break;
                
            case CUBE_EVENT_COLOR_CHANGED: {
                sym = sym_color; 
                at(4);
                SetInt(at[0],cube);
                CubeColor c = CubeGetColor(cube);
                SetFloat(at[1],c.red/255.);
                SetFloat(at[2],c.green/255.);
                SetFloat(at[3],c.blue/255.);
                break;
            }
            
            default: 
                FLEXT_ASSERT(false);
        }
        
        if(sym)
            // pass over to main thread
            ToQueueAnything(0,sym,at.Count(),at.Atoms());
    }
Ejemplo n.º 6
0
bool CScValue::DbgSetVal(double Value) {
	SetFloat(Value);
	return true;
}
Ejemplo n.º 7
0
 static void write( PyrSlot *slot, const float val )
 {
   SetFloat(slot, val);
 }
Ejemplo n.º 8
0
void RenderingEngine::Render(const Entity& object)
{
	m_renderProfileTimer.StartInvocation();
	GetTexture("displayTexture").BindAsRenderTarget();
	//m_window->BindAsRenderTarget();
	//m_tempTarget->BindAsRenderTarget();

	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	object.RenderAll(m_defaultShader, *this, *m_mainCamera);
	
	for(unsigned int i = 0; i < m_lights.size(); i++)
	{
		m_activeLight = m_lights[i];
		ShadowInfo shadowInfo = m_activeLight->GetShadowInfo();
		
		int shadowMapIndex = 0;
		if(shadowInfo.GetShadowMapSizeAsPowerOf2() != 0)
			shadowMapIndex = shadowInfo.GetShadowMapSizeAsPowerOf2() - 1;
		
		assert(shadowMapIndex >= 0 && shadowMapIndex < NUM_SHADOW_MAPS);
		
		SetTexture("shadowMap", m_shadowMaps[shadowMapIndex]);
		m_shadowMaps[shadowMapIndex].BindAsRenderTarget();
		glClearColor(1.0f,1.0f,0.0f,0.0f);
		glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
		
		if(shadowInfo.GetShadowMapSizeAsPowerOf2() != 0)
		{
			m_altCamera.SetProjection(shadowInfo.GetProjection());
			ShadowCameraTransform shadowCameraTransform = m_activeLight->CalcShadowCameraTransform(m_mainCamera->GetTransform().GetTransformedPos(), 
				m_mainCamera->GetTransform().GetTransformedRot());
			m_altCamera.GetTransform()->SetPos(shadowCameraTransform.GetPos());
			m_altCamera.GetTransform()->SetRot(shadowCameraTransform.GetRot());
			
			m_lightMatrix = BIAS_MATRIX * m_altCamera.GetViewProjection();
			
			SetFloat("shadowVarianceMin", shadowInfo.GetMinVariance());
			SetFloat("shadowLightBleedingReduction", shadowInfo.GetLightBleedReductionAmount());
			bool flipFaces = shadowInfo.GetFlipFaces();
			
//			const Camera* temp = m_mainCamera;
//			m_mainCamera = m_altCamera;
			
			if(flipFaces)
			{
				glCullFace(GL_FRONT);
			}
			
			glEnable(GL_DEPTH_CLAMP);
			object.RenderAll(m_shadowMapShader, *this, m_altCamera);
			glDisable(GL_DEPTH_CLAMP);
			
			if(flipFaces) 
			{
				glCullFace(GL_BACK);
			}
			
//			m_mainCamera = temp;
			
			float shadowSoftness = shadowInfo.GetShadowSoftness();
			if(shadowSoftness != 0)
			{
				BlurShadowMap(shadowMapIndex, shadowSoftness);
			}
		}
		else
		{
			m_lightMatrix = Matrix4f().InitScale(Vector3f(0,0,0));
			SetFloat("shadowVarianceMin", 0.00002f);
			SetFloat("shadowLightBleedingReduction", 0.0f);
		}
	
		GetTexture("displayTexture").BindAsRenderTarget();
		//m_window->BindAsRenderTarget();
		
//		glEnable(GL_SCISSOR_TEST);
//		TODO: Make use of scissor test to limit light area
//		glScissor(0, 0, 100, 100);
		
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		glDepthMask(GL_FALSE);
		glDepthFunc(GL_EQUAL);

		object.RenderAll(m_activeLight->GetShader(), *this, *m_mainCamera);
		
		glDepthMask(GL_TRUE);
		glDepthFunc(GL_LESS);
		glDisable(GL_BLEND);
		
//		glDisable(GL_SCISSOR_TEST);
	}
	
	float displayTextureAspect = (float)GetTexture("displayTexture").GetWidth()/(float)GetTexture("displayTexture").GetHeight();
	float displayTextureHeightAdditive = displayTextureAspect * GetFloat("fxaaAspectDistortion");
	SetVector3f("inverseFilterTextureSize", Vector3f(1.0f/(float)GetTexture("displayTexture").GetWidth(), 
	                                                 1.0f/((float)GetTexture("displayTexture").GetHeight() + displayTextureHeightAdditive), 0.0f));
	m_renderProfileTimer.StopInvocation();
	
	m_windowSyncProfileTimer.StartInvocation();
	ApplyFilter(m_fxaaFilter, GetTexture("displayTexture"), 0);
	m_windowSyncProfileTimer.StopInvocation();
}
Ejemplo n.º 9
0
void flext_base::px_object::px_float(px_object *obj,t_float f)
{
    t_atom a; SetFloat(a,f);
    Locker lock(obj->base);
    obj->base->CbMethodHandler(obj->index,sym_float,1,&a);
}
Ejemplo n.º 10
0
PyrObject* ConvertOSCMessage(int inSize, char *inData)
{
	char *cmdName = inData;
	int cmdNameLen = OSCstrlen(cmdName);
	sc_msg_iter msg(inSize - cmdNameLen, inData + cmdNameLen);

	int numElems;
	if (inSize == cmdNameLen) {
		numElems = 0;
	} else {
		if (!msg.tags) {
			numElems = 0;
			error("OSC messages must have type tags.  %s\n", cmdName);
		} else {
			numElems = strlen(msg.tags);
		}
	}
	//post("tags %s %d\n", msg.tags, numElems);

	VMGlobals *g = gMainVMGlobals;
	PyrObject *obj = newPyrArray(g->gc, numElems + 1, 0, false);
	PyrSlot *slots = obj->slots;

	SetSymbol(slots+0, getsym(cmdName));

	for (int i=0; i<numElems; ++i) {
		char tag = msg.nextTag();
		//post("%d %c\n", i, tag);
		switch (tag) {
		case 'i' :
			SetInt(slots+i+1, msg.geti());
			break;
		case 'f' :
			SetFloat(slots+i+1, msg.getf());
			break;
		case 'd' :
			SetFloat(slots+i+1, msg.getd());
			break;
		case 's' :
			SetSymbol(slots+i+1, getsym(msg.gets()));
			//post("sym '%s'\n", slots[i+1].us->name);
			break;
		case 'b' : // fall through
		case 'm' :
			SetObject(slots+i+1, (PyrObject*)MsgToInt8Array(msg));
			break;
		case 'c':
			SetChar(slots+i+1, (char)msg.geti());
			break;
		case 't' :
			SetFloat(slots+i+1, OSCToElapsedTime(msg.gett()));
			break;

			// argument tags without any associated value
		case 'T' :
			SetTrue(slots+i+1);
			msg.count ++;
			break;
		case 'F' :
			SetFalse(slots+i+1);
			msg.count ++;
			break;
		case 'I' :
			SetFloat(slots+i+1, dInfinity);
			msg.count ++;
			break;
		case 'N' :
			SetNil(slots+i+1);
			msg.count ++;
			break;
			// else add the type tag as a char (jrhb 2009)
		default:
			SetChar(slots+i+1, tag);
			msg.gets();
		}
	}
	obj->size = numElems + 1;
	return obj;
}
Ejemplo n.º 11
0
TBValue::TBValue(float value)
	: m_packed_init(0)
{
	SetFloat(value);
}
Ejemplo n.º 12
0
bool AnimaMappedValues::ReadObject(const ptree& objectTree, AnimaScene* scene, bool readName)
{
	try
	{
		if(readName)
			SetName(objectTree.get<AnimaString>("AnimaMappedValues.Name"));
		
		for (auto& property : objectTree.get_child("AnimaMappedValues.Properties"))
		{
			if (property.first == "Property")
			{
				AnimaString name = property.second.get<AnimaString>("Name");
				AnimaString type = property.second.get<AnimaString>("Type");
				
				if(type == "bool")
				{
					bool value = property.second.get<bool>("Value");
					SetBoolean(name, value);
				}
				else if(type == "float")
				{
					AFloat value = property.second.get<AFloat>("Value");
					SetFloat(name, value);
				}
				else if(type == "integer")
				{
					AInt value = property.second.get<AInt>("Value");
					SetInteger(name, value);
				}
				else if(type == "matrix")
				{
					AnimaMatrix value = property.second.get<AnimaMatrix>("Value");
					SetMatrix(name, value);
				}
				else if(type == "vector")
				{
					for(auto& valueTree : property.second.get_child("Value"))
					{
						if(valueTree.first == "AnimaVectorGenerator")
						{
							ptree generatorTree;
							generatorTree.add_child("AnimaVectorGenerator", valueTree.second);
							
							AnimaString generatorName = _uniqueName + generatorTree.get<AnimaString>("AnimaVectorGenerator.Name");
							
							AnimaVectorGenerator* generator = _dataGeneratorManager->GetDataGeneratorOfTypeFromName<AnimaVectorGenerator>(generatorName);

							if(generator == nullptr)
								generator = _dataGeneratorManager->CreateVectorGenerator(generatorName);
							
							if(generator)
							{
								if(!generator->ReadObject(generatorTree, scene, false))
									return false;
								generator->SetGeneratedFromMappedValues(true);
								
								SetVector(name, generator);
							}
						}
					}
				}
				else if(type == "color")
				{
					for(auto& valueTree : property.second.get_child("Value"))
					{
						if(valueTree.first == "AnimaColorGenerator")
						{
							ptree generatorTree;
							generatorTree.add_child("AnimaColorGenerator", valueTree.second);
							
							AnimaString generatorName = _uniqueName + generatorTree.get<AnimaString>("AnimaColorGenerator.Name");
							
							AnimaColorGenerator* generator = _dataGeneratorManager->GetDataGeneratorOfTypeFromName<AnimaColorGenerator>(generatorName);
							
							if(generator == nullptr)
								generator = _dataGeneratorManager->CreateColorGenerator(generatorName);
							
							if(generator)
							{
								if(!generator->ReadObject(generatorTree, scene, false))
									return false;
								generator->SetGeneratedFromMappedValues(true);
								
								SetColor(name, generator);
							}
						}
					}
				}
				else if(type == "texture")
				{
					for(auto& valueTree : property.second.get_child("Value"))
					{
						if(valueTree.first == "AnimaTextureGenerator")
						{
							ptree generatorTree;
							generatorTree.add_child("AnimaTextureGenerator", valueTree.second);
							
							AnimaString generatorName = _uniqueName + generatorTree.get<AnimaString>("AnimaTextureGenerator.Name");
							
							AnimaTextureGenerator* generator = _dataGeneratorManager->GetDataGeneratorOfTypeFromName<AnimaTextureGenerator>(generatorName);
							
							if(generator == nullptr)
								generator = _dataGeneratorManager->CreateTextureGenerator(generatorName);
							
							if(generator)
							{
								if(!generator->ReadObject(generatorTree, scene, false))
									return false;
								generator->SetGeneratedFromMappedValues(true);
								
								SetTexture(name, generator);
							}
						}
					}
				}
			}
		}
		
		ptree namedObjectTree = objectTree.get_child("AnimaMappedValues.NamedObject");
		
		return AnimaNamedObject::ReadObject(namedObjectTree, scene, false);
	}
	catch (boost::property_tree::ptree_bad_path& exception)
	{
		AnimaLogger::LogMessageFormat("ERROR - Error parsing mapped values: %s", exception.what());
		return false;
	}
	catch (boost::property_tree::ptree_bad_data& exception)
	{
		AnimaLogger::LogMessageFormat("ERROR - Error parsing mapped values: %s", exception.what());
		return false;
	}
}
// True for OK, false for cancel
bool Configure_ChaseCam(ChaseCamData &Data)
{
	short ItemType;
	Rect Bounds;
	
	DialogPtr Dialog = myGetNewDialog(ChaseCam_Dialog, NULL, (WindowPtr)(-1), 0);
	assert(Dialog);
	
	ControlHandle Behind_CHdl;
	GetDialogItem(Dialog, Behind_Item, &ItemType, (Handle *)&Behind_CHdl, &Bounds);
	SetFloat(Behind_CHdl,Data.Behind/FLOAT_WORLD_ONE);
	
	ControlHandle Upward_CHdl;
	GetDialogItem(Dialog, Upward_Item, &ItemType, (Handle *)&Upward_CHdl, &Bounds);
	SetFloat(Upward_CHdl,Data.Upward/FLOAT_WORLD_ONE);
	
	ControlHandle Rightward_CHdl;
	GetDialogItem(Dialog, Rightward_Item, &ItemType, (Handle *)&Rightward_CHdl, &Bounds);
	SetFloat(Rightward_CHdl,Data.Rightward/FLOAT_WORLD_ONE);
	
	MacCheckbox PassThruWall_CB(Dialog, PassThruWall_Item, TEST_FLAG(Data.Flags,_ChaseCam_ThroughWalls));
	MacCheckbox NeverActive_CB(Dialog, NeverActive_Item, TEST_FLAG(Data.Flags,_ChaseCam_NeverActive));
	MacCheckbox OnWhenEntering_CB(Dialog, OnWhenEntering_Item, TEST_FLAG(Data.Flags,_ChaseCam_OnWhenEntering));
	
	ControlHandle Damping_CHdl;
	GetDialogItem(Dialog, Damping_Item, &ItemType, (Handle *)&Damping_CHdl, &Bounds);
	SetFloat(Damping_CHdl,Data.Damping);
	
	ControlHandle Spring_CHdl;
	GetDialogItem(Dialog, Spring_Item, &ItemType, (Handle *)&Spring_CHdl, &Bounds);
	SetFloat(Spring_CHdl,Data.Spring);
	
	ControlHandle Opacity_CHdl;
	GetDialogItem(Dialog, CC_Opacity_Item, &ItemType, (Handle *)&Opacity_CHdl, &Bounds);
	SetFloat(Opacity_CHdl,Data.Opacity);
	
	// Where to make the color picker
	Point Center = {-1,-1};
	RGBColor NewColor;
	// Get void color from OpenGL-parameters data
	OGL_ConfigureData& OGLData = Get_OGL_ConfigureData();
	MacCheckbox VoidColorOnOff_CB(Dialog, VoidColorOnOff_Item, TEST_FLAG(OGLData.Flags,OGL_Flag_VoidColor));
	
	// Reveal it
#if USE_SHEETS
	SetThemeWindowBackground(GetDialogWindow(Dialog), kThemeBrushSheetBackgroundTransparent, false);
	ShowSheetWindow(GetDialogWindow(Dialog), ActiveNonFloatingWindow());
#else
	SelectWindow(GetDialogWindow(Dialog));
	ShowWindow(GetDialogWindow(Dialog));
#endif
	
	bool WillQuit = false;
	bool IsOK = false;
	short New_Behind = 0, New_Upward = 0, New_Rightward = 0;
	float FloatTemp = 0;
	bool BadValue;
	float New_Damping, New_Spring, New_Opacity;
	while(!WillQuit)
	{
		short ItemHit;
		ModalDialog(NULL, &ItemHit);
		
		switch(ItemHit)
		{
		case OK_Item:
		// Check before quitting
			BadValue = false;
			
			// Now doing roundoff correctly
			// Using a modification of AlexJLS's corrected version
			
			if (GetFloat(Behind_CHdl,FloatTemp))
				New_Behind = FloatRoundoff(WORLD_ONE * FloatTemp);
			else
				BadValue = true;
			
			if (GetFloat(Upward_CHdl,FloatTemp))
				New_Upward = FloatRoundoff(WORLD_ONE * FloatTemp);
			else
				BadValue = true;
			
			if (GetFloat(Rightward_CHdl,FloatTemp))
				New_Rightward = FloatRoundoff(WORLD_ONE * FloatTemp);
			else
				BadValue = true;
			
			if (GetFloat(Damping_CHdl,FloatTemp))
			{
				// Simple validation of the damping factor
				New_Damping = PIN(FloatTemp,-1,1);
				if (New_Damping != FloatTemp)
				{
					BadValue = true;
					SetFloat(Damping_CHdl,New_Damping);
				}
			}
			else
				BadValue = true;
			
			if (GetFloat(Spring_CHdl,FloatTemp))
			{
				New_Spring = FloatTemp;
			}
			else
				BadValue = true;
			
			if (GetFloat(Opacity_CHdl,FloatTemp))
			{
				New_Opacity = PIN(FloatTemp,0,1);
				if (New_Opacity != FloatTemp)
				{
					BadValue = true;
					SetFloat(Opacity_CHdl,New_Opacity);
				}
			}
			else
				BadValue = true;
			
			// Do validation: will the chase cam be unstable?			
			if (!BadValue)
			{
				if (New_Spring >= 0)
				{
					// Oscillatory case
					float NewDampSq = New_Damping*New_Damping;
					BadValue = ((NewDampSq + New_Spring) >= 1);
					if (BadValue)
					{
						New_Spring = 1 - NewDampSq;
						SetFloat(Spring_CHdl,New_Spring);
					}
				}
				else
				{
					// Overdamped case
					float NewDampAbs = fabs(New_Damping);
					BadValue = ((NewDampAbs + sqrt(-New_Spring)) >= 1);
					if (BadValue)
					{
						float Temp = 1 - NewDampAbs;
						New_Spring = - Temp*Temp;
						SetFloat(Spring_CHdl,New_Spring);
					}
				}	
			}
			
			if (BadValue)
			{
				SysBeep(30);
				break;
			}
		
			IsOK = true;
			WillQuit = true;
			break;
			
		case Cancel_Item:
			IsOK = false;
			WillQuit = true;
			break;
			
		case VoidColorSelect_Item:
			// Need to set color here so the preview can work properly
			if (GetColor(Center,"\pWhat color for the void?",&OGLData.VoidColor,&NewColor))
				OGLData.VoidColor = NewColor;
			break;
		
		default:
			if (PassThruWall_CB.ToggleIfHit(ItemHit)) break;
			if (NeverActive_CB.ToggleIfHit(ItemHit)) break;
			if (OnWhenEntering_CB.ToggleIfHit(ItemHit)) break;
			if (VoidColorOnOff_CB.ToggleIfHit(ItemHit)) break;
			break;
		}
	}
	
	if (IsOK)
	{
		Data.Behind = New_Behind;
		Data.Upward = New_Upward;
		Data.Rightward = New_Rightward;
		SET_FLAG(Data.Flags,_ChaseCam_ThroughWalls,PassThruWall_CB.GetState());
		SET_FLAG(Data.Flags,_ChaseCam_NeverActive,NeverActive_CB.GetState());
		SET_FLAG(Data.Flags,_ChaseCam_OnWhenEntering,OnWhenEntering_CB.GetState());
		SET_FLAG(OGLData.Flags,OGL_Flag_VoidColor,VoidColorOnOff_CB.GetState());
		Data.Damping = New_Damping;
		Data.Spring = New_Spring;
		Data.Opacity = New_Opacity;
	}
	
	// Clean up
#if USE_SHEETS
	HideSheetWindow(GetDialogWindow(Dialog));
#else
	HideWindow(GetDialogWindow(Dialog));
#endif
	DisposeDialog(Dialog);
	
	return IsOK;
}
// True for OK, false for cancel
bool Configure_ChaseCam(ChaseCamData &Data)
{
	// Get the window
	AutoNibReference Nib (Window_Prefs_ChaseCam);
	AutoNibWindow Window (Nib.nibReference (), Window_Prefs_ChaseCam);

	// Get the controls
	Configure_ChaseCam_HandlerData HandlerData;
	
	HandlerData.BehindCtrl = GetCtrlFromWindow(Window(), 0, Behind_Item);
	SetFloat(HandlerData.BehindCtrl,Data.Behind/FLOAT_WORLD_ONE);
	
	HandlerData.UpwardCtrl = GetCtrlFromWindow(Window(), 0, Upward_Item);
	SetFloat(HandlerData.UpwardCtrl,Data.Upward/FLOAT_WORLD_ONE);
	
	HandlerData.RightwardCtrl = GetCtrlFromWindow(Window(), 0, Rightward_Item);
	SetFloat(HandlerData.RightwardCtrl,Data.Rightward/FLOAT_WORLD_ONE);
	
	HandlerData.DampingCtrl = GetCtrlFromWindow(Window(), 0, Damping_Item);
	SetFloat(HandlerData.DampingCtrl,Data.Damping);
	
	HandlerData.SpringCtrl = GetCtrlFromWindow(Window(), 0, Spring_Item);
	SetFloat(HandlerData.SpringCtrl,Data.Spring);
	
	HandlerData.CC_OpacityCtrl = GetCtrlFromWindow(Window(), 0, CC_Opacity_Item);
	SetFloat(HandlerData.CC_OpacityCtrl,Data.Opacity);
	
	ControlRef PassThruWall_Ctrl = GetCtrlFromWindow(Window(), 0, PassThruWall_Item);
	SetControl32BitValue(PassThruWall_Ctrl, !!TEST_FLAG(Data.Flags,_ChaseCam_ThroughWalls));
	
	ControlRef NeverActive_Ctrl = GetCtrlFromWindow(Window(), 0, NeverActive_Item);
	SetControl32BitValue(NeverActive_Ctrl, !!TEST_FLAG(Data.Flags,_ChaseCam_NeverActive));
	
	ControlRef OnWhenEntering_Ctrl = GetCtrlFromWindow(Window(), 0, OnWhenEntering_Item);
	SetControl32BitValue(OnWhenEntering_Ctrl, !!TEST_FLAG(Data.Flags,_ChaseCam_OnWhenEntering));
	
	// Get void color from OpenGL-parameters data
	OGL_ConfigureData& OGLData = Get_OGL_ConfigureData();
	
	ControlRef VoidColorOnOff_Ctrl = GetCtrlFromWindow(Window(), 0, VoidColorOnOff_Item);
	SetControl32BitValue(VoidColorOnOff_Ctrl, !!TEST_FLAG(OGLData.Flags,OGL_Flag_VoidColor));
		
	HandlerData.VoidColor = OGLData.VoidColor;

	// For making the swatch drawable and hittable
	AutoDrawability Drawability;
	AutoHittability Hittability;
	
	ControlRef VoidSwatchCtrl = GetCtrlFromWindow(Window(), 0, VoidColorSelect_Item);
	
	Drawability(VoidSwatchCtrl, SwatchDrawer, &HandlerData.VoidColor);
	Hittability(VoidSwatchCtrl);
		
	bool IsOK = RunModalDialog(Window(), true, Configure_ChaseCam_Handler, &HandlerData);
	
	if (IsOK)
	{
		HandlerData.VerifyAndAdjust();
		
		float Temp;
		
		if (GetFloat(HandlerData.BehindCtrl,Temp))
			Data.Behind = FloatRoundoff(FLOAT_WORLD_ONE*Temp);
		
		if (GetFloat(HandlerData.UpwardCtrl,Temp));
			Data.Upward = FloatRoundoff(FLOAT_WORLD_ONE*Temp);
		
		if (GetFloat(HandlerData.RightwardCtrl,Temp));
			Data.Rightward = FloatRoundoff(FLOAT_WORLD_ONE*Temp);
		
		GetFloat(HandlerData.DampingCtrl, Data.Damping);
		
		GetFloat(HandlerData.SpringCtrl, Data.Spring);
		
		GetFloat(HandlerData.CC_OpacityCtrl, Data.Opacity);
		
		SET_FLAG(Data.Flags,_ChaseCam_ThroughWalls,GetControl32BitValue(PassThruWall_Ctrl));
		
		SET_FLAG(Data.Flags,_ChaseCam_NeverActive,GetControl32BitValue(NeverActive_Ctrl));
		
		SET_FLAG(Data.Flags,_ChaseCam_OnWhenEntering,GetControl32BitValue(OnWhenEntering_Ctrl));
	
		SET_FLAG(OGLData.Flags,OGL_Flag_VoidColor,GetControl32BitValue(VoidColorOnOff_Ctrl));
		
		OGLData.VoidColor = HandlerData.VoidColor;
	}
	
	return IsOK;
}
Ejemplo n.º 15
0
	void CControlUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
	{
		// ÊÇ·ñÑùʽ±í
		if(m_pManager != NULL) {
			LPCTSTR pStyle = m_pManager->GetStyle(pstrValue);
			if( pStyle != NULL) {
				ApplyAttributeList(pStyle);
				return;
			}
		}
		if( _tcsicmp(pstrName, _T("pos")) == 0 ) {
			RECT rcPos = { 0 };
			LPTSTR pstr = NULL;
			rcPos.left = _tcstol(pstrValue, &pstr, 10);  ASSERT(pstr);    
			rcPos.top = _tcstol(pstr + 1, &pstr, 10);    ASSERT(pstr);    
			rcPos.right = _tcstol(pstr + 1, &pstr, 10);  ASSERT(pstr);    
			rcPos.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);    
			SIZE szXY = {rcPos.left >= 0 ? rcPos.left : rcPos.right, rcPos.top >= 0 ? rcPos.top : rcPos.bottom};
			SetFixedXY(szXY);
			SetFixedWidth(rcPos.right - rcPos.left);
			SetFixedHeight(rcPos.bottom - rcPos.top);
		}
		else if( _tcsicmp(pstrName, _T("float")) == 0 ) {
			CDuiString nValue = pstrValue;
			// ¶¯Ì¬¼ÆËãÏà¶Ô±ÈÀý
			if(nValue.Find(',') < 0) {
				SetFloat(_tcsicmp(pstrValue, _T("true")) == 0);
			}
			else {
				TPercentInfo piFloatPercent = { 0 };
				LPTSTR pstr = NULL;
				piFloatPercent.left = _tcstod(pstrValue, &pstr);  ASSERT(pstr);
				piFloatPercent.top = _tcstod(pstr + 1, &pstr);    ASSERT(pstr);
				piFloatPercent.right = _tcstod(pstr + 1, &pstr);  ASSERT(pstr);
				piFloatPercent.bottom = _tcstod(pstr + 1, &pstr); ASSERT(pstr);
				SetFloatPercent(piFloatPercent);
				SetFloat(true);
			}
		}
		else if( _tcsicmp(pstrName, _T("padding")) == 0 ) {
			RECT rcPadding = { 0 };
			LPTSTR pstr = NULL;
			rcPadding.left = _tcstol(pstrValue, &pstr, 10);  ASSERT(pstr);    
			rcPadding.top = _tcstol(pstr + 1, &pstr, 10);    ASSERT(pstr);    
			rcPadding.right = _tcstol(pstr + 1, &pstr, 10);  ASSERT(pstr);    
			rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);    
			SetPadding(rcPadding);
		}
		else if( _tcsicmp(pstrName, _T("bkcolor")) == 0 || _tcsicmp(pstrName, _T("bkcolor1")) == 0 ) {
			while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetBkColor(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("bkcolor2")) == 0 ) {
			while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetBkColor2(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("bkcolor3")) == 0 ) {
			while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetBkColor3(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("forecolor")) == 0 ) {
			while( *pstrValue > _T('\0') && *pstrValue <= _T(' ') ) pstrValue = ::CharNext(pstrValue);
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetForeColor(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("bordercolor")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetBorderColor(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("focusbordercolor")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetFocusBorderColor(clrColor);
		}
		else if( _tcsicmp(pstrName, _T("colorhsl")) == 0 ) SetColorHSL(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("bordersize")) == 0 ) {
			CDuiString nValue = pstrValue;
			if(nValue.Find(',') < 0) {
				SetBorderSize(_ttoi(pstrValue));
				RECT rcPadding = {0};
				SetBorderSize(rcPadding);
			}
			else {
				RECT rcPadding = { 0 };
				LPTSTR pstr = NULL;
				rcPadding.left = _tcstol(pstrValue, &pstr, 10);  ASSERT(pstr);
				rcPadding.top = _tcstol(pstr + 1, &pstr, 10);    ASSERT(pstr);
				rcPadding.right = _tcstol(pstr + 1, &pstr, 10);  ASSERT(pstr);
				rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
				SetBorderSize(rcPadding);
			}
		}
		else if( _tcsicmp(pstrName, _T("leftbordersize")) == 0 ) SetLeftBorderSize(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("topbordersize")) == 0 ) SetTopBorderSize(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("rightbordersize")) == 0 ) SetRightBorderSize(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("bottombordersize")) == 0 ) SetBottomBorderSize(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("borderstyle")) == 0 ) SetBorderStyle(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("borderround")) == 0 ) {
			SIZE cxyRound = { 0 };
			LPTSTR pstr = NULL;
			cxyRound.cx = _tcstol(pstrValue, &pstr, 10);  ASSERT(pstr);    
			cxyRound.cy = _tcstol(pstr + 1, &pstr, 10);    ASSERT(pstr);
			SetBorderRound(cxyRound);
		}
		else if( _tcsicmp(pstrName, _T("bkimage")) == 0 ) SetBkImage(pstrValue);
		else if( _tcsicmp(pstrName, _T("foreimage")) == 0 ) SetForeImage(pstrValue);
		else if( _tcsicmp(pstrName, _T("width")) == 0 ) SetFixedWidth(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("height")) == 0 ) SetFixedHeight(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("minwidth")) == 0 ) SetMinWidth(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("minheight")) == 0 ) SetMinHeight(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("maxwidth")) == 0 ) SetMaxWidth(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("maxheight")) == 0 ) SetMaxHeight(_ttoi(pstrValue));
		else if( _tcsicmp(pstrName, _T("name")) == 0 ) SetName(pstrValue);
		else if( _tcsicmp(pstrName, _T("drag")) == 0 ) SetDragEnable(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("drop")) == 0 ) SetDropEnable(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("resourcetext")) == 0 ) SetResourceText(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("text")) == 0 ) SetText(pstrValue);
		else if( _tcsicmp(pstrName, _T("tooltip")) == 0 ) SetToolTip(pstrValue);
		else if( _tcsicmp(pstrName, _T("userdata")) == 0 ) SetUserData(pstrValue);
		else if( _tcsicmp(pstrName, _T("enabled")) == 0 ) SetEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("mouse")) == 0 ) SetMouseEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("keyboard")) == 0 ) SetKeyboardEnabled(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("visible")) == 0 ) SetVisible(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("float")) == 0 ) SetFloat(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("shortcut")) == 0 ) SetShortcut(pstrValue[0]);
		else if( _tcsicmp(pstrName, _T("menu")) == 0 ) SetContextMenuUsed(_tcsicmp(pstrValue, _T("true")) == 0);
		else if( _tcsicmp(pstrName, _T("cursor")) == 0 && pstrValue) {
			if( _tcsicmp(pstrValue, _T("arrow")) == 0 )			SetCursor(DUI_ARROW);
			else if( _tcsicmp(pstrValue, _T("ibeam")) == 0 )	SetCursor(DUI_IBEAM);
			else if( _tcsicmp(pstrValue, _T("wait")) == 0 )		SetCursor(DUI_WAIT);
			else if( _tcsicmp(pstrValue, _T("cross")) == 0 )	SetCursor(DUI_CROSS);
			else if( _tcsicmp(pstrValue, _T("uparrow")) == 0 )	SetCursor(DUI_UPARROW);
			else if( _tcsicmp(pstrValue, _T("size")) == 0 )		SetCursor(DUI_SIZE);
			else if( _tcsicmp(pstrValue, _T("icon")) == 0 )		SetCursor(DUI_ICON);
			else if( _tcsicmp(pstrValue, _T("sizenwse")) == 0 )	SetCursor(DUI_SIZENWSE);
			else if( _tcsicmp(pstrValue, _T("sizenesw")) == 0 )	SetCursor(DUI_SIZENESW);
			else if( _tcsicmp(pstrValue, _T("sizewe")) == 0 )	SetCursor(DUI_SIZEWE);
			else if( _tcsicmp(pstrValue, _T("sizens")) == 0 )	SetCursor(DUI_SIZENS);
			else if( _tcsicmp(pstrValue, _T("sizeall")) == 0 )	SetCursor(DUI_SIZEALL);
			else if( _tcsicmp(pstrValue, _T("no")) == 0 )		SetCursor(DUI_NO);
			else if( _tcsicmp(pstrValue, _T("hand")) == 0 )		SetCursor(DUI_HAND);
		}
		else if( _tcsicmp(pstrName, _T("virtualwnd")) == 0 ) SetVirtualWnd(pstrValue);
		else if( _tcsicmp(pstrName, _T("innerstyle")) == 0 ) {
			CDuiString sXmlData = pstrValue;
			sXmlData.Replace(_T("&quot;"), _T("\""));
			LPCTSTR pstrList = sXmlData.GetData();
			CDuiString sItem;
			CDuiString sValue;
			while( *pstrList != _T('\0') ) {
				sItem.Empty();
				sValue.Empty();
				while( *pstrList != _T('\0') && *pstrList != _T('=') ) {
					LPTSTR pstrTemp = ::CharNext(pstrList);
					while( pstrList < pstrTemp) {
						sItem += *pstrList++;
					}
				}
				ASSERT( *pstrList == _T('=') );
				if( *pstrList++ != _T('=') ) return;
				ASSERT( *pstrList == _T('\"') );
				if( *pstrList++ != _T('\"') ) return;
				while( *pstrList != _T('\0') && *pstrList != _T('\"') ) {
					LPTSTR pstrTemp = ::CharNext(pstrList);
					while( pstrList < pstrTemp) {
						sValue += *pstrList++;
					}
				}
				ASSERT( *pstrList == _T('\"') );
				if( *pstrList++ != _T('\"') ) return;
				SetAttribute(sItem, sValue);
				if( *pstrList++ != _T(' ') && *pstrList++ != _T(',') ) return;
			}
		}
	}
Ejemplo n.º 16
0
void flext_base::cb_float(flext_hdr *c,t_float f)
{
    t_atom a; SetFloat(a,f);
    Locker lock(c);
    thisObject(c)->CbMethodHandler(0,sym_float,1,&a);
}
Ejemplo n.º 17
0
bool ConfVarNumber::Assign(lua_State *L)
{
	SetFloat( (float) lua_tonumber(L, -1) );
	return true;
}
Ejemplo n.º 18
0
void AnimaRenderer::SetFloat(const char* propertyName, AFloat value)
{
	AnimaString str(propertyName, _allocator);
	SetFloat(str, value);
}
Ejemplo n.º 19
0
bool NFCRecord::SetFloat(const int nRow, const std::string& strColTag, const double value)
{
    int nCol = GetCol(strColTag);
    return SetFloat(nRow, nCol, value);
}
Ejemplo n.º 20
0
//-----------------------------------------------------------------------------
// Purpose: Converts the variant to a new type. This function defines which I/O
//			types can be automatically converted between. Connections that require
//			an unsupported conversion will cause an error message at runtime.
// Input  : newType - the type to convert to
// Output : Returns true on success, false if the conversion is not legal
//-----------------------------------------------------------------------------
bool variant_t::Convert( fieldtype_t newType )
{
	if ( newType == fieldType )
	{
		return true;
	}

	//
	// Converting to a null value is easy.
	//
	if ( newType == FIELD_VOID )
	{
		Set( FIELD_VOID, NULL );
		return true;
	}

	//
	// FIELD_INPUT accepts the variant type directly.
	//
	if ( newType == FIELD_INPUT )
	{
		return true;
	}

	switch ( fieldType )
	{
		case FIELD_INTEGER:
		{
			switch ( newType )
			{
				case FIELD_FLOAT:
				{
					SetFloat( (float) iVal );
					return true;
				}

				case FIELD_BOOLEAN:
				{
					SetBool( iVal != 0 );
					return true;
				}
			}
			break;
		}

		case FIELD_FLOAT:
		{
			switch ( newType )
			{
				case FIELD_INTEGER:
				{
					SetInt( (int) flVal );
					return true;
				}

				case FIELD_BOOLEAN:
				{
					SetBool( flVal != 0 );
					return true;
				}
			}
			break;
		}

		//
		// Everyone must convert from FIELD_STRING if possible, since
		// parameter overrides are always passed as strings.
		//
		case FIELD_STRING:
		{
			switch ( newType )
			{
				case FIELD_INTEGER:
				{
					if (iszVal != NULL_STRING)
					{
						SetInt(atoi(STRING(iszVal)));
					}
					else
					{
						SetInt(0);
					}
					return true;
				}

				case FIELD_FLOAT:
				{
					if (iszVal != NULL_STRING)
					{
						SetFloat(atof(STRING(iszVal)));
					}
					else
					{
						SetFloat(0);
					}
					return true;
				}

				case FIELD_BOOLEAN:
				{
					if (iszVal != NULL_STRING)
					{
						SetBool( atoi(STRING(iszVal)) != 0 );
					}
					else
					{
						SetBool(false);
					}
					return true;
				}

				case FIELD_VECTOR:
				{
					Vector tmpVec = vec3_origin;
					if (sscanf(STRING(iszVal), "[%f %f %f]", &tmpVec[0], &tmpVec[1], &tmpVec[2]) == 0)
					{
						// Try sucking out 3 floats with no []s
						sscanf(STRING(iszVal), "%f %f %f", &tmpVec[0], &tmpVec[1], &tmpVec[2]);
					}
					SetVector3D( tmpVec );
					return true;
				}

				case FIELD_COLOR32:
				{
					int nRed = 0;
					int nGreen = 0;
					int nBlue = 0;
					int nAlpha = 255;

					sscanf(STRING(iszVal), "%d %d %d %d", &nRed, &nGreen, &nBlue, &nAlpha);
					SetColor32( nRed, nGreen, nBlue, nAlpha );
					return true;
				}

				case FIELD_EHANDLE:
				{
					// convert the string to an entity by locating it by classname
					CBaseEntity *ent = NULL;
					if ( iszVal != NULL_STRING )
					{
						// FIXME: do we need to pass an activator in here?
						ent = gEntList.FindEntityByName( NULL, iszVal );
					}
					SetEntity( ent );
					return true;
				}
			}
		
			break;
		}

		case FIELD_EHANDLE:
		{
			switch ( newType )
			{
				case FIELD_STRING:
				{
					// take the entities targetname as the string
					string_t iszStr = NULL_STRING;
					if ( eVal != NULL )
					{
						SetString( eVal->GetEntityName() );
					}
					return true;
				}
			}
			break;
		}
	}

	// invalid conversion
	return false;
}
Ejemplo n.º 21
0
 static void write( PyrSlot *slot, const double val )
 {
   // NOTE: the signature actually reads SetFloat(PyrSlot*, double):
   SetFloat(slot, val);
 }
Ejemplo n.º 22
0
int prEvent_Delta(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, key, dur, stretch, delta;
	double fdur, fstretch;
	int err;
	PyrClass *restClass = getsym("Rest")->u.classobj;
	PyrSlot *slot;

	a = g->sp;  // dict

	SetSymbol(&key, s_delta);
	identDict_lookup(slotRawObject(a), &key, calcHash(&key), &delta);

	if (NotNil(&delta)) {
		if (isKindOfSlot(&delta, restClass)) {
			slot = slotRawObject(&delta)->slots;
			err = slotDoubleVal(slot, &fdur);
		} else {
			err = slotDoubleVal(&delta, &fdur);
		}
		if (err) {
			return err;
		} else {
			SetFloat(a, fdur);
			return errNone;
		}
	} else {
		SetSymbol(&key, s_dur);
		identDict_lookup(slotRawObject(a), &key, calcHash(&key), &dur);
		err = slotDoubleVal(&dur, &fdur);
		if (err) {
			if (IsNil(&dur)) {
				SetNil(g->sp);
				return errNone;
			} else if (isKindOfSlot(&dur, restClass)) {
				slot = slotRawObject(&dur)->slots;
				err = slotDoubleVal(slot, &fdur);
				if (err)
					return err;
			} else {
				return errWrongType;
			}
		}
		SetSymbol(&key, s_stretch);
		identDict_lookup(slotRawObject(a), &key, calcHash(&key), &stretch);

		err = slotDoubleVal(&stretch, &fstretch);
		if (err) {
			if (NotNil(&stretch)) {
				if (isKindOfSlot(&stretch, restClass)) {
					slot = slotRawObject(&stretch)->slots;
					err = slotDoubleVal(slot, &fstretch);
					if (err) return err;
				} else {
					return errWrongType;
				}
			} else {
				SetFloat(a, fdur);
				return errNone;
			}
		}

		SetFloat(a, fdur * fstretch);
	}

	return errNone;
}
Ejemplo n.º 23
0
int processident(char *token)
{
	char c;
	PyrSymbol *sym;

	PyrSlot slot;
	PyrParseNode *node;

	c = token[0];
	zzval = -1;

#if DEBUGLEX
	if (gDebugLexer) postfl("word: '%s'\n",token);
#endif
	/*
	strcpy(uptoken, token);
	for (str = uptoken; *str; ++str) {
		if (*str >= 'a' && *str <= 'z') *str += 'A' - 'a';
	}*/

	if (token[0] == '_') {
		if (token[1] == 0) {
			node = newPyrCurryArgNode();
			zzval = (long)node;
			return CURRYARG;
		} else {
			sym = getsym(token);
			SetSymbol(&slot, sym);
			node = newPyrSlotNode(&slot);
			zzval = (long)node;
			return PRIMITIVENAME;
		}
	}
	if (token[0] >= 'A' && token[0] <= 'Z') {
		sym = getsym(token);
		SetSymbol(&slot, sym);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
#if DEBUGLEX
	if (gDebugLexer) postfl("CLASSNAME: '%s'\n",token);
#endif
		return CLASSNAME;
	}
	if (strcmp("var",token) ==0) return VAR;
	if (strcmp("arg",token) ==0) return ARG;
	if (strcmp("classvar",token) ==0) return CLASSVAR;
	if (strcmp("const",token) ==0) return SC_CONST;

	if (strcmp("while",token) ==0) {

		sym = getsym(token);
		SetSymbol(&slot, sym);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return WHILE;
	}
	if (strcmp("pi",token) ==0) {
		SetFloat(&slot, pi);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return PIE;
	}
	if (strcmp("true",token) ==0) {
		SetTrue(&slot);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return TRUEOBJ;
	}
	if (strcmp("false",token) ==0) {
		SetFalse(&slot);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return FALSEOBJ;
	}
	if (strcmp("nil",token) ==0) {
		SetNil(&slot);
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return NILOBJ;
	}
	if (strcmp("inf",token) ==0) {
		SetFloat(&slot, std::numeric_limits<double>::infinity());
		node = newPyrSlotNode(&slot);
		zzval = (long)node;
		return SC_FLOAT;
	}

	sym = getsym(token);

	SetSymbol(&slot, sym);
	node = newPyrSlotNode(&slot);
	zzval = (long)node;
	return NAME;
}
Ejemplo n.º 24
0
    void mlp::map(int argc, const t_atom *argv)
    {
        const data_type data_type = get_data_type();

        GRT::UINT numSamples = data_type == LABELLED_CLASSIFICATION ? classification_data.getNumSamples() : regression_data.getNumSamples();

        if (numSamples == 0)
        {
            flext::error("no observations added, use 'add' to add training data");
            return;
        }

        if (grt_mlp.getTrained() == false)
        {
            flext::error("model has not been trained, use 'train' to train the model");
            return;
        }
        
        GRT::UINT numInputNeurons = grt_mlp.getNumInputNeurons();
        GRT::VectorDouble query(numInputNeurons);
        
        if (argc < 0 || (unsigned)argc != numInputNeurons)
        {
            flext::error("invalid input length, expected %d, got %d", numInputNeurons, argc);
        }

        for (uint32_t index = 0; index < (uint32_t)argc; ++index)
        {
            double value = GetAFloat(argv[index]);
            query[index] = value;
        }
        
        bool success = grt_mlp.predict(query);
        
        if (success == false)
        {
            flext::error("unable to map input");
            return;
        }
        
        // TODO: add probs to attributes
        if (grt_mlp.getClassificationModeActive())
        {
            GRT::VectorDouble likelihoods = grt_mlp.getClassLikelihoods();
            GRT::vector<GRT::UINT> labels = classification_data.getClassLabels();
            GRT::UINT classification = grt_mlp.getPredictedClassLabel();
            
            if (likelihoods.size() != labels.size())
            {
                flext::error("labels / likelihoods size mismatch");
            }
            else
            {
                AtomList probs;

                for (uid_t count = 0; count < labels.size(); ++count)
                {
                    t_atom label_a;
                    t_atom likelihood_a;
                    
                    // Need to call SetDouble() first or label_a gets corrupted. Bug in Flext?
                    SetDouble(&likelihood_a, likelihoods[count]);
                    SetInt(label_a, labels[count]);
                    
                    probs.Append(label_a);
                    probs.Append(likelihood_a);
                }
                ToOutAnything(1, s_probs, probs);
            }
                 
            ToOutInt(0, classification);
        }
        else if (grt_mlp.getRegressionModeActive())
        {
            GRT::VectorDouble regression_data = grt_mlp.getRegressionData();
            GRT::VectorDouble::size_type numOutputDimensions = regression_data.size();
            
            if (numOutputDimensions != grt_mlp.getNumOutputNeurons())
            {
                flext::error("invalid output dimensions: %d", numOutputDimensions);
                return;
            }
            
            AtomList result;
            
            for (uint32_t index = 0; index < numOutputDimensions; ++index)
            {
                t_atom value_a;
                double value = regression_data[index];
                SetFloat(value_a, value);
                result.Append(value_a);
            }
            
            ToOutList(0, result);
        }
    }
Ejemplo n.º 25
0
int prElapsedTime(struct VMGlobals *g, int numArgsPushed)
{
	SetFloat(g->sp, elapsedTime());
	return errNone;
}
Ejemplo n.º 26
0
CCharVariable& CCharVariable::operator =(const double Value)
{
 SetFloat(Value);
 return *this;
}
Ejemplo n.º 27
0
void* TempoClock::Run()
{
	//printf("->TempoClock::Run\n");
	pthread_mutex_lock (&gLangMutex);
	while (mRun) {
		assert(mQueue->size);
		//printf("tempo %g  dur %g  beats %g\n", mTempo, mBeatDur, mBeats);
		//printf("wait until there is something in scheduler\n");
		// wait until there is something in scheduler
		while (mQueue->size == 1) {
			//printf("wait until there is something in scheduler\n");
			pthread_cond_wait (&mCondition, &gLangMutex);
			//printf("mRun a %d\n", mRun);
			if (!mRun) goto leave;
		}
		//printf("wait until an event is ready\n");

		// wait until an event is ready
		double elapsedBeats;
		do {
			elapsedBeats = ElapsedBeats();
			if (elapsedBeats >= slotRawFloat(mQueue->slots)) break;
			struct timespec abstime;
			//doubleToTimespec(mQueue->slots->uf, &abstime);
			//printf("event ready at %g . elapsed beats %g\n", mQueue->slots->uf, elapsedBeats);
			double wakeTime = BeatsToSecs(slotRawFloat(mQueue->slots));
			ElapsedTimeToTimespec(wakeTime, &abstime);
			//printf("wait until an event is ready. wake %g  now %g\n", wakeTime, elapsedTime());
			pthread_cond_timedwait (&mCondition, &gLangMutex, &abstime);
			//printf("mRun b %d\n", mRun);
			if (!mRun) goto leave;
			//printf("time diff %g\n", elapsedTime() - mQueue->slots->uf);
		} while (mQueue->size > 1);
		//printf("perform all events that are ready %d %.9f\n", mQueue->size, elapsedBeats);

		// perform all events that are ready
		//printf("perform all events that are ready\n");
		while (mQueue->size > 1 && elapsedBeats >= slotRawFloat(mQueue->slots)) {
			double delta;
			PyrSlot task;

			//printf("while %.6f >= %.6f\n", elapsedBeats, mQueue->slots->uf);

			getheap(g, (PyrObject*)mQueue, &mBeats, &task);

			if (isKindOfSlot(&task, class_thread)) {
				SetNil(&slotRawThread(&task)->nextBeat);
			}

			slotCopy((++g->sp), &task);
			SetFloat(++g->sp, mBeats);
			SetFloat(++g->sp, BeatsToSecs(mBeats));
			++g->sp;	SetObject(g->sp, mTempoClockObj);

			runAwakeMessage(g);
			long err = slotDoubleVal(&g->result, &delta);
			if (!err) {
				// add delta time and reschedule
				double beats = mBeats + delta;
				Add(beats, &task);
			}
		}
	}
leave:
	//printf("<-TempoClock::Run\n");
	pthread_mutex_unlock (&gLangMutex);
	return 0;
}
Ejemplo n.º 28
0
  optixu::Context Scene::GetContext()
  {
    // Context is not valid without a model, as we don't know which extension
    // specific code to load until
    // the model is selected.
    if (!m_model) return m_context;
    try
    {
      if (!m_context.get())
      {
        GLenum err = glewInit();
        if (GLEW_OK != err)
        {
          std::cout << "Error initializing GLEW: " << glewGetErrorString(err)
                    << std::endl;
        }

        unsigned int deviceCount = 0;
        rtDeviceGetDeviceCount(&deviceCount);

        m_context = optixu::Context::create();

        PtxManager::SetupContext(m_model->GetPTXPrefix(), m_context);

        unsigned int optixVersion;
        rtGetVersion(&optixVersion);
        std::cout << "OptiX Version: " << optixVersion << std::endl;

        // Ray Type 0 - Primary rays that intersect actual geometry.  Closest
        // hit programs determine exactly how the geometry is handled.
        // Ray Type 1 - Rays that find the current element and evaluate the
        // scalar
        // value at a point.
        // Ray Type 2 - Rays that perform volume rendering.
        m_context->setRayTypeCount(3);

        // Setup Lighting
        // TODO - Move this into the base
        // Overall goal will be to have an OptixScene, which handles setting up
        // the
        // context and the lighting.  OptixSceneViews will allow different
        // access to the
        // same scene.
        m_context["ambientColor"]->setFloat(m_ambientLightColor.Red(),
                                            m_ambientLightColor.Green(),
                                            m_ambientLightColor.Blue());

//        std::list<boost::shared_ptr<DirectionalLight>> allDirectionalLights;
//        std::list<boost::shared_ptr<PointLight>> allPointLights;
//        std::cout << "Total Lights: " << m_allLights.size() << std::endl;
//        for (std::list<boost::shared_ptr<Light>>::iterator iter =
//               m_allLights.begin();
//             iter != m_allLights.end(); ++iter)
//        {
//          auto asDirectional =
//            boost::dynamic_pointer_cast<DirectionalLight>(*iter);
//          auto asPointLight = boost::dynamic_pointer_cast<PointLight>(*iter);

//          if (asDirectional)
//          {
//            allDirectionalLights.push_back(asDirectional);
//          }
//          else if (asPointLight)
//          {
//            allPointLights.push_back(asPointLight);
//          }
//        }

        // Setup Directional Lights.

        // Setup Point Lights.
        optixu::Buffer lightPositionBuffer = m_context->createBuffer(
          RT_BUFFER_INPUT, RT_FORMAT_FLOAT, m_allLights.size() * 3);
        m_context["lightPosition"]->set(lightPositionBuffer);
        float* positionData = static_cast<float*>(lightPositionBuffer->map());

        optixu::Buffer lightColorBuffer = m_context->createBuffer(
          RT_BUFFER_INPUT, RT_FORMAT_FLOAT, m_allLights.size() * 3);
        m_context["lightColor"]->set(lightColorBuffer);
        float* colorData = static_cast<float*>(lightColorBuffer->map());

        int i = 0;
        for (std::list<boost::shared_ptr<Light>>::const_iterator iter =
               m_allLights.begin();
             iter != m_allLights.end(); ++iter)
        {
          positionData[i] = static_cast<float>((*iter)->Position().x());
          positionData[i + 1] = static_cast<float>((*iter)->Position().y());
          positionData[i + 2] = static_cast<float>((*iter)->Position().z());

          colorData[i] = (*iter)->GetColor().Red();
          colorData[i + 1] = (*iter)->GetColor().Green();
          colorData[i + 2] = (*iter)->GetColor().Blue();
          i += 3;
        }

        lightPositionBuffer->unmap();
        lightColorBuffer->unmap();

        if (GetModel())
        {

          GetModel()->CalculateExtents();
          SetFloat(m_context["VolumeMinExtent"], GetModel()->MinExtent());
          SetFloat(m_context["VolumeMaxExtent"], GetModel()->MaxExtent());
          m_context["ModelDimension"]->setInt(GetModel()->GetModelDimension());

          // Version 2.0 Interface.
          GetModel()->CopyToOptiX(m_context);
        }


        m_context->setPrintLaunchIndex(-1, -1, -1);

        //// Miss program
        // m_context->setMissProgram( 0, PtxManager::LoadProgram(m_context,
        // "ElVis.cu.ptx", "miss" ) );
        // m_context["bg_color"]->setFloat( 1.0f, 1.0f, 1.0f );

        m_optixDataDirty = true;
        SynchronizeWithOptiXIfNeeded();
        OnSceneInitialized(*this);
      }
    }
    catch (optixu::Exception& e)
    {
      std::cout << "Exception encountered setting up the scene." << std::endl;
      std::cerr << e.getErrorString() << std::endl;
      std::cout << e.getErrorString().c_str() << std::endl;
    }
    return m_context;
  }
Ejemplo n.º 29
0
PListValue::PListValue(float value) :
    type_(PLVT_NONE)
{
    SetFloat(value);
}
Ejemplo n.º 30
0
 inline MsgBundle &Add(flext_base *th,int o,float dt) 
 { 
     t_atom at; 
     SetFloat(at,dt);
     return Add(th,o,sym_float,1,&at);
 }