예제 #1
0
        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);
            }
        }
예제 #2
0
 public void SetScalarParameter(SHashedName parameterName, float scalar)
 {
     foreach (CMesh mesh in m_meshes)
     {
         mesh.Material.SetScalarParameter(parameterName, scalar);
     }
 }
예제 #3
0
        public CShaderResource RequestShaderResource(SHashedName shaderName)
        {
            CShaderResource resource = new CShaderResource();

            resource.Shader = RequestShader(shaderName);
            resource.FinishLoading();
            return(resource);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 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());
     }
 }
예제 #7
0
        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();
                }
            }
        }
예제 #8
0
        public void UnregisterCommand(string name)
        {
            void UnregisterCommandInternal()
            {
                SHashedName hashedName = new SHashedName(name);

                m_commands.Remove(hashedName);
            }

            if (IsInAuthoritativeThread())
            {
                UnregisterCommandInternal();
            }
            else
            {
                Dispatch(EConfigDispatcherPriority.Update, UnregisterCommandInternal);
            }
        }
예제 #9
0
        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;
            }
        }
예제 #10
0
        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");
        }
예제 #11
0
        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);
            }
        }
예제 #12
0
        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));
            }
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
            }
        }
예제 #15
0
        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);
        }
예제 #16
0
 public SMaterialParameterEntry(SHashedName inName, SShaderParameter inParameter)
 {
     name      = inName;
     parameter = inParameter;
 }
예제 #17
0
        public object GetVariable(string name)
        {
            SHashedName hashedName = new SHashedName(name);

            return(m_variables.TryGetValue(hashedName, out CCVar cvar) ? cvar.Get() : null);
        }
예제 #18
0
 public void SetVectorParameter(SHashedName parameterName, in Vector3 vector)
예제 #19
0
        public T GetVariable <T>(string name)
        {
            SHashedName hashedName = new SHashedName(name);

            return(m_variables.TryGetValue(hashedName, out CCVar cvar) ? cvar.Get <T>() : default);
예제 #20
0
 public CConsoleCommand(SHashedName name, MethodInfo method, object targetObject)
 {
     Name           = name;
     m_targetMethod = method;
     TargetObject   = targetObject;
 }
예제 #21
0
 public void SetScalarParameter(SHashedName parameterName, float scalar)
 {
     UpdateParameter(parameterName, EShaderParameterType.Scalar, scalar);
 }
예제 #22
0
 public CShader RequestShader(SHashedName shaderName)
 {
     return(m_shaderRegistry.RequestShader(shaderName));
 }