Exemplo n.º 1
0
 protected bool TryGetVariable(ListItem selectedVariableItem, out VariableDescription variable)
 {
     variable = null;
     if (_variables != null && selectedVariableItem != null)
     {
         string name = selectedVariableItem.Label(KEY_VARIABLE_NAME, "").Evaluate();
         if (!string.IsNullOrEmpty(name))
         {
             variable = _variables.FirstOrDefault(v => v.Name == name);
         }
     }
     return(variable != null);
 }
Exemplo n.º 2
0
        protected void UpdateVariablesFromSettings()
        {
            var         sm = ServiceRegistration.Get <ISettingsManager>();
            CoreSetting coreSetting;

            if (!sm.Load <LibRetroCoreSettings>().TryGetCoreSetting(_corePath, out coreSetting) || coreSetting.Variables == null)
            {
                return;
            }
            foreach (VariableDescription variable in coreSetting.Variables)
            {
                VariableDescription coreVariable = _variables.FirstOrDefault(v => v.Name == variable.Name);
                if (coreVariable != null)
                {
                    coreVariable.SelectedOption = variable.SelectedOption;
                }
            }
        }
Exemplo n.º 3
0
 private void RegisterVariable(string name, dynamic value)
 {
     _userVariablesDescriptions[name] = new VariableDescription(name, value);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether the buffer conatins ndjango code
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns><b>true</b> if this is a ndjango buffer</returns>
        public bool IsNDjango(ITextBuffer buffer, IEnvironment context)
        {
            // we do not need to mess with the text buffers for tooltips
            var formatMap = new VariableDescription();
            formatMap.Name = "FormatMap";
            var formatMapName = context.Get(formatMap);
            if (Convert.ToString(formatMapName) == "tooltip")
                return false;

            switch (buffer.ContentType.TypeName)
            {
                case "text":
                case "HTML":
                    return true;
                default: return false;
            }
        }
Exemplo n.º 5
0
        unsafe bool retro_environment(LibRetro.RETRO_ENVIRONMENT cmd, IntPtr data)
        {
            Console.WriteLine(cmd);
            switch (cmd)
            {
            case LibRetro.RETRO_ENVIRONMENT.SET_ROTATION:
            {
                var rotation = (LibRetro.RETRO_ROTATION)(*(int *)data.ToPointer());
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_0_CCW)
                {
                    environmentInfo.Rotation_CCW = 0;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_90_CCW)
                {
                    environmentInfo.Rotation_CCW = 90;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_180_CCW)
                {
                    environmentInfo.Rotation_CCW = 180;
                }
                if (rotation == LibRetro.RETRO_ROTATION.ROTATION_270_CCW)
                {
                    environmentInfo.Rotation_CCW = 270;
                }
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.GET_OVERSCAN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_CAN_DUPE:
                //gambatte requires this
                *(bool *)data.ToPointer() = true;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_MESSAGE:
            {
                LibRetro.retro_message msg = new LibRetro.retro_message();
                Marshal.PtrToStructure(data, msg);
                if (!string.IsNullOrEmpty(msg.msg))
                {
                    Console.WriteLine("LibRetro Message: {0}", msg.msg);
                }
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.SHUTDOWN:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_PERFORMANCE_LEVEL:
                Console.WriteLine("Core suggested SET_PERFORMANCE_LEVEL {0}", *(uint *)data.ToPointer());
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_SYSTEM_DIRECTORY:
                //mednafen NGP neopop fails to launch with no system directory
                Directory.CreateDirectory(SystemDirectory);                         //just to be safe, it seems likely that cores will crash without a created system directory
                Console.WriteLine("returning system directory: " + SystemDirectory);
                *((IntPtr *)data.ToPointer()) = SystemDirectoryAtom;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_PIXEL_FORMAT:
            {
                LibRetro.RETRO_PIXEL_FORMAT fmt = 0;
                int[] tmp = new int[1];
                Marshal.Copy(data, tmp, 0, 1);
                fmt = (LibRetro.RETRO_PIXEL_FORMAT)tmp[0];
                switch (fmt)
                {
                case LibRetro.RETRO_PIXEL_FORMAT.RGB565:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB1555:
                case LibRetro.RETRO_PIXEL_FORMAT.XRGB8888:
                    pixelfmt = fmt;
                    Console.WriteLine("New pixel format set: {0}", pixelfmt);
                    return(true);

                default:
                    Console.WriteLine("Unrecognized pixel format: {0}", (int)pixelfmt);
                    return(false);
                }
            }

            case LibRetro.RETRO_ENVIRONMENT.SET_INPUT_DESCRIPTORS:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_KEYBOARD_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_DISK_CONTROL_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_HW_RENDER:
            {
                //mupen64plus needs this, as well as 3dengine
                LibRetro.retro_hw_render_callback *info = (LibRetro.retro_hw_render_callback *)data.ToPointer();
                Console.WriteLine("SET_HW_RENDER: {0}, version={1}.{2}, dbg/cache={3}/{4}, depth/stencil = {5}/{6}{7}", info->context_type, info->version_minor, info->version_major, info->debug_context, info->cache_context, info->depth, info->stencil, info->bottom_left_origin ? " (bottomleft)" : "");
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE:
            {
                void **variables = (void **)data.ToPointer();
                IntPtr pKey      = new IntPtr(*variables++);
                string key       = Marshal.PtrToStringAnsi(pKey);
                Console.WriteLine("Requesting variable: {0}", key);
                //always return default
                //TODO: cache settings atoms
                if (!Description.Variables.ContainsKey(key))
                {
                    return(false);
                }
                //HACK: return pointer for desmume mouse, i want to implement that first
                if (key == "desmume_pointer_type")
                {
                    *variables = unmanagedResources.StringToHGlobalAnsi("touch").ToPointer();
                    return(true);
                }
                *variables = unmanagedResources.StringToHGlobalAnsi(Description.Variables[key].DefaultOption).ToPointer();
                return(true);
            }

            case LibRetro.RETRO_ENVIRONMENT.SET_VARIABLES:
            {
                void **variables = (void **)data.ToPointer();
                for (; ;)
                {
                    IntPtr pKey   = new IntPtr(*variables++);
                    IntPtr pValue = new IntPtr(*variables++);
                    if (pKey == IntPtr.Zero)
                    {
                        break;
                    }
                    string key   = Marshal.PtrToStringAnsi(pKey);
                    string value = Marshal.PtrToStringAnsi(pValue);
                    var    vd    = new VariableDescription()
                    {
                        Name = key
                    };
                    var parts = value.Split(';');
                    vd.Description = parts[0];
                    vd.Options     = parts[1].TrimStart(' ').Split('|');
                    Description.Variables[vd.Name] = vd;
                }
            }
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_VARIABLE_UPDATE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_SUPPORT_NO_GAME:
                environmentInfo.SupportNoGame = true;
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_LIBRETRO_PATH:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_AUDIO_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.SET_FRAME_TIME_CALLBACK:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_RUMBLE_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_INPUT_DEVICE_CAPABILITIES:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_LOG_INTERFACE:
                *(IntPtr *)data = Marshal.GetFunctionPointerForDelegate(retro_log_printf_cb);
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_PERF_INTERFACE:
                //some builds of fmsx core crash without this set
                Marshal.StructureToPtr(retro_perf_callback, data, false);
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.GET_LOCATION_INTERFACE:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_CORE_ASSETS_DIRECTORY:
                return(false);

            case LibRetro.RETRO_ENVIRONMENT.GET_SAVE_DIRECTORY:
                //supposedly optional like everything else here, but without it ?? crashes (please write which case)
                //this will suffice for now. if we find evidence later it's needed we can stash a string with
                //unmanagedResources and CoreFileProvider
                //mednafen NGP neopop, desmume, and others, request this, and falls back on the system directory if it isn't provided
                //desmume crashes if the directory doesn't exist
                Directory.CreateDirectory(SaveDirectory);
                Console.WriteLine("returning save directory: " + SaveDirectory);
                *((IntPtr *)data.ToPointer()) = SaveDirectoryAtom;
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_CONTROLLER_INFO:
                return(true);

            case LibRetro.RETRO_ENVIRONMENT.SET_MEMORY_MAPS:
                return(false);

            default:
                Console.WriteLine("Unknkown retro_environment command {0}", (int)cmd);
                return(false);
            }
        }
Exemplo n.º 6
0
        private void VariableControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            uiPanel.Children.Clear();

            VariableDescription v = null;

            try
            {
                var kvp = (KeyValuePair <string, VariableDescription>)DataContext;
                v = kvp.Value;
            }
            catch (Exception)
            {
                return;
            }
            if (v == null)
            {
                return;            // should never happen.
            }
            v.CurrValue       = v.Init;
            v.CurrValueString = v.InitString;

            // Don't add this label; it merely duplicates the label on the slider or combo box.
            // uiPanel.Children.Add(new TextBlock() { Text = v.Label };);
            switch (v.InputType)
            {
            case UiType.Slider:
            {
                var s = new Slider()
                {
                    Header  = v.Label ?? v.Name,
                    Minimum = v.Min,
                    Maximum = v.Max,
                    Value   = v.Init,
                    Tag     = v
                };
                s.ValueChanged += S_ValueChanged;
                uiPanel.Children.Add(s);
            }
            break;

            case UiType.TextBox:
            {
                var tb = new TextBox()
                {
                    Header = v.Label ?? v.Name,
                    Text   = v.InitString,
                    Tag    = v
                };
                tb.TextChanged += Tb_TextChanged;
                uiPanel.Children.Add(tb);
                v.CurrValueIsString = true;
            }
            break;

            case UiType.ComboBox:
            {
                var cb = new ComboBox()
                {
                    Header = v.Label ?? v.Name,
                    Tag    = v
                };
                ComboBoxItem initSelected = null;
                foreach (var(name, value) in v.ValueNames)
                {
                    var cbi = new ComboBoxItem()
                    {
                        Content = name,
                        Tag     = value,
                    };
                    cb.Items.Add(cbi);
                    if (value == v.Init || initSelected == null)
                    {
                        initSelected = cbi;
                    }
                }
                cb.SelectionChanged += Cb_SelectionChanged;
                uiPanel.Children.Add(cb);
                cb.SelectedItem = initSelected;
            }
            break;
            }
        }