コード例 #1
0
ファイル: Window.cs プロジェクト: psryland/rylogic_code
            private readonly AnimationCB m_animation_cb;                    // A local reference to prevent the callback being garbage collected

            public Window(View3d view, HWND hwnd, bool?gdi_compatible_backbuffer = null, int?multi_sampling = null, string?dbg_name = null)
            {
                View   = view;
                Hwnd   = hwnd;
                Diag   = new Diagnostics(this);
                m_opts = new WindowOptions
                {
                    ErrorCB    = HandleError,
                    ErrorCBCtx = IntPtr.Zero,
                    GdiCompatibleBackBuffer = gdi_compatible_backbuffer ?? false,
                    Multisampling           = multi_sampling ?? 4,
                    DbgName = dbg_name ?? string.Empty,
                };

                // Create the window
                Handle = View3D_WindowCreate(hwnd, ref m_opts);
                if (Handle == null)
                {
                    throw new Exception("Failed to create View3D window");
                }
                void HandleError(IntPtr ctx, string msg, string filepath, int line, long pos) => Error?.Invoke(this, new ErrorEventArgs(msg, filepath, line, pos));

                // Set up a callback for when settings are changed
                View3D_WindowSettingsChangedCB(Handle, m_settings_cb = HandleSettingsChanged, IntPtr.Zero, true);
                void HandleSettingsChanged(IntPtr ctx, HWindow wnd, ESettings setting) => OnSettingsChanged?.Invoke(this, new SettingChangeEventArgs(setting));

                // Set up a callback for when the window is invalidated
                View3D_WindowInvalidatedCB(Handle, m_invalidated_cb = HandleInvalidated, IntPtr.Zero, true);
                void HandleInvalidated(IntPtr ctx, HWindow wnd) => OnInvalidated?.Invoke(this, EventArgs.Empty);

                // Set up a callback for when a render is about to happen
                View3D_WindowRenderingCB(Handle, m_render_cb = HandleRendering, IntPtr.Zero, true);
                void HandleRendering(IntPtr ctx, HWindow wnd) => OnRendering?.Invoke(this, EventArgs.Empty);

                // Set up a callback for when the object store for this window changes
                View3d_WindowSceneChangedCB(Handle, m_scene_changed_cb = HandleSceneChanged, IntPtr.Zero, true);
                void HandleSceneChanged(IntPtr ctx, HWindow wnd, ref View3DSceneChanged args) => OnSceneChanged?.Invoke(this, new SceneChangedEventArgs(args));

                // Set up a callback for animation events
                View3D_WindowAnimEventCBSet(Handle, m_animation_cb = HandleAnimationEvent, IntPtr.Zero, true);
                void HandleAnimationEvent(IntPtr ctx, HWindow wnd, EAnimCommand command, double clock) => OnAnimationEvent?.Invoke(this, new AnimationEventArgs(command, clock));

                // Set up the light source
                SetLightSource(v4.Origin, -v4.ZAxis, true);

                // Display the focus point
                FocusPointVisible = true;

                // Position the camera
                Camera = new Camera(this);
                Camera.Lookat(new v4(0f, 0f, -2f, 1f), v4.Origin, v4.YAxis);
            }
コード例 #2
0
        public void Invalidate()
        {
            if (!rwLock.TryEnterWriteLock(1))
            {
                //If it's already updating cache, don't update again.
                return;
            }

            value      = getValueDelegate();
            lastUpdate = DateTime.Now;
            rwLock.ExitWriteLock();

            OnInvalidated?.Invoke(this, new CachedFieldInvalidatedEventArgs(lastUpdate));
        }
コード例 #3
0
        void Invalidate(VoiceConnectionInvalidationReason reason, string errorMessage = null)
        {
            if (isValid)
            {
                isValid      = false;
                isConnecting = false;
                isConnected  = false;

                voiceState = null;

                if (!isDisposed)
                {
                    connectingCancellationSource?.Cancel();
                }

                log?.LogVerbose("[Invalidate] Invalidating voice connection...");

                Shard.Voice.RemoveVoiceConnection(guildId);

                OnInvalidated?.Invoke(this, new VoiceConnectionInvalidatedEventArgs(Shard, this, reason, errorMessage));
            }
        }