public void RegisterVariable(string name, Type type, object defaultValue, PropertyInfo property, object targetObject, MethodInfo callback = null) { void RegisterVariableInternal() { SHashedName hashedName = new SHashedName(name); if (!m_variables.ContainsKey(hashedName)) { CCVar cvar = new CCVar(hashedName, property, targetObject, defaultValue, callback); m_variables.Add(hashedName, cvar); return; } throw new ArgumentException("Passed in console variable already exists!"); } if (IsInAuthoritativeThread()) { RegisterVariableInternal(); } else { Dispatch(EConfigDispatcherPriority.Update, RegisterVariableInternal); } }
public void SetScalarParameter(SHashedName parameterName, float scalar) { foreach (CMesh mesh in m_meshes) { mesh.Material.SetScalarParameter(parameterName, scalar); } }
public CShaderResource RequestShaderResource(SHashedName shaderName) { CShaderResource resource = new CShaderResource(); resource.Shader = RequestShader(shaderName); resource.FinishLoading(); return(resource); }
public CCVar(SHashedName name, PropertyInfo property, object targetObject, object defaultValue, MethodInfo callback) { Name = name; m_property = property; TargetObject = targetObject; m_defaultValue = defaultValue; Type = property.PropertyType; m_callback = callback; Set(defaultValue); }
public bool SetVariable(string name, object value) { SHashedName hashedName = new SHashedName(name); if (m_variables.TryGetValue(hashedName, out CCVar cvar)) { cvar.Set(value); return(true); } return(false); }
public ImFontPtr GetFont(SHashedName fontFamilyName, float desiredSize) { if (m_fontCollections.ContainsKey(fontFamilyName)) { List <ImFontPtr> fonts = m_fontCollections[fontFamilyName]; return(GetFont(fonts, desiredSize)); } else { LogUtility.Log("Font {0} could not be found", fontFamilyName); return(new ImFontPtr()); } }
private void InputBox_FocusChanged(object sender, RoutedEventArgs e) { m_inspector.Lock(InputBox.IsFocused); if (!m_bLocked) { if (!InputBox.IsFocused) { SHashedName oldValue = (SHashedName)PropertyInfo.Value; SHashedName newValue = new SHashedName(InputBox.Text); SetInspectorValue(PropertyInfo, oldValue, newValue); InputBox.Text = newValue.ToString(); } } }
public void UnregisterCommand(string name) { void UnregisterCommandInternal() { SHashedName hashedName = new SHashedName(name); m_commands.Remove(hashedName); } if (IsInAuthoritativeThread()) { UnregisterCommandInternal(); } else { Dispatch(EConfigDispatcherPriority.Update, UnregisterCommandInternal); } }
private void InputBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { m_inspector.Unfocus(); } else if (e.Key == Key.Enter) { SHashedName oldValue = (SHashedName)PropertyInfo.Value; SHashedName newValue = new SHashedName(InputBox.Text); SetInspectorValue(PropertyInfo, oldValue, newValue); InputBox.Text = newValue.ToString(); m_bLocked = true; m_inspector.Unfocus(); m_bLocked = false; } }
public CShader RequestShader(SHashedName shaderName) { m_shaders.TryGetValue(shaderName, out CShader outShader); if (outShader != null) { return(outShader); } m_shaderClassMap.TryGetValue(shaderName, out Type shaderClass); if (shaderClass != null) { CShader shader = (CShader)Activator.CreateInstance(shaderClass); m_shaders.Add(shaderName, shader); Task.Run(() => shader.Init(m_device)); } throw new ArgumentException("Shader with the name " + shaderName + " was not found"); }
public void LoadFont(string fontFamily, string fontFilePath, float[] sizesToLoad) { if (File.Exists(fontFilePath)) { SHashedName fontFamilyName = new SHashedName(fontFamily); if (m_fontCollections.ContainsKey(fontFamilyName)) { // If the font is already know only load sizes we don't already loaded List <ImFontPtr> fonts = m_fontCollections[fontFamilyName]; foreach (float sizeToLoad in sizesToLoad) { if (!fonts.Any(ptr => Math.Abs(ptr.FontSize - sizeToLoad) < 0.001f)) { ImFontPtr fontPtr = m_managedFontAtlas.AddFontFromFileTTF(fontFilePath, sizeToLoad); fonts.Add(fontPtr); } } fonts.Sort((lftFont, rghFont) => lftFont.FontSize.CompareTo(rghFont.FontSize)); } else { List <ImFontPtr> fontList = new List <ImFontPtr>(); foreach (float sizeToLoad in sizesToLoad) { ImFontPtr fontPtr = m_managedFontAtlas.AddFontFromFileTTF(fontFilePath, sizeToLoad); fontList.Add(fontPtr); } fontList.Sort((lftFont, rghFont) => lftFont.FontSize.CompareTo(rghFont.FontSize)); m_fontCollections.Add(fontFamilyName, fontList); } m_fontAddedCallback(); } else { throw new FileNotFoundException("Font does not exists requested path was: " + fontFilePath); } }
public void InvokeConsoleCommand(string name, List <string> arguments) { void InvokeConsoleCommandInternal(List <string> args) { SHashedName hashedName = new SHashedName(name); if (m_commands.TryGetValue(hashedName, out CConsoleCommand command)) { command.Invoke(args); } } if (IsInAuthoritativeThread()) { InvokeConsoleCommandInternal(arguments); } else { List <string> copiedArguments = new List <string>(arguments); Dispatch(EConfigDispatcherPriority.Update, () => InvokeConsoleCommandInternal(copiedArguments)); } }
public CModel LoadModelFromFile(string fileName, SHashedName shaderName = new SHashedName()) { if (m_device.IsDisposed) { throw new Exception("Trying to load a model, but our device was disposed"); } Assimp.Scene scene = m_importer.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); string modelPath = Path.GetDirectoryName(fileName); Matrix identity = Matrix.Identity; CModel model = new CModel(); CShaderResource shaderResource = CRenderer.Instance.ResourceManager.DefaultShader; if (!shaderName.IsEmpty()) { shaderResource = CRenderer.Instance.ResourceManager.RequestShaderResource(shaderName); } AddVertexData(model, scene, scene.RootNode, m_device, ref identity, modelPath, shaderResource); ComputeBoundingBox(model, scene); return(model); }
public void RegisterCommand(string name, MethodInfo method, object targetObject) { void RegisterCommandInternal() { if (IsConsoleCommandValid(method)) { SHashedName hashedName = new SHashedName(name); if (!m_commands.ContainsKey(hashedName)) { CConsoleCommand command = new CConsoleCommand(hashedName, method, targetObject); m_commands.Add(hashedName, command); } } } if (IsInAuthoritativeThread()) { RegisterCommandInternal(); } else { Dispatch(EConfigDispatcherPriority.Update, RegisterCommandInternal); } }
public void AddParameterTarget(SHashedName name, EShaderParameterType type) { SShaderParameterTarget newParameterTarget; newParameterTarget.parameterName = name; newParameterTarget.parameterType = type; int sizeInBytes = ShaderHelpers.GetSizeFromParameterType(type); if (m_currentRegisterSizeLeft >= sizeInBytes && !m_bInArray) { m_currentRegisterSizeLeft -= sizeInBytes; newParameterTarget.offset = m_currentOffset; } else { m_currentOffset += m_currentRegisterSizeLeft; newParameterTarget.offset = m_currentOffset; m_currentRegisterSizeLeft = (16 - sizeInBytes % 16) % 16; } m_currentOffset += sizeInBytes; parameterTargets.Add(newParameterTarget); }
public SMaterialParameterEntry(SHashedName inName, SShaderParameter inParameter) { name = inName; parameter = inParameter; }
public object GetVariable(string name) { SHashedName hashedName = new SHashedName(name); return(m_variables.TryGetValue(hashedName, out CCVar cvar) ? cvar.Get() : null); }
public void SetVectorParameter(SHashedName parameterName, in Vector3 vector)
public T GetVariable <T>(string name) { SHashedName hashedName = new SHashedName(name); return(m_variables.TryGetValue(hashedName, out CCVar cvar) ? cvar.Get <T>() : default);
public CConsoleCommand(SHashedName name, MethodInfo method, object targetObject) { Name = name; m_targetMethod = method; TargetObject = targetObject; }
public void SetScalarParameter(SHashedName parameterName, float scalar) { UpdateParameter(parameterName, EShaderParameterType.Scalar, scalar); }
public CShader RequestShader(SHashedName shaderName) { return(m_shaderRegistry.RequestShader(shaderName)); }