public void RegisterComponent(IGameComponent component) { var viewComp = component as ChangeColorOnCollisionSystemView; if (viewComp) { viewComp.NewColorVector .Subscribe(vec => _color = vec) .AddTo(viewComp); } var changeColorComp = component as ChangeColorOnCollisionComponent; if (changeColorComp) { changeColorComp .OnCollisionStayAsObservable() .Subscribe(collision => ChangeColor(changeColorComp)) .AddTo(changeColorComp); changeColorComp .OnCollisionExitAsObservable() .Subscribe(collision => ChangeColorBack(changeColorComp)) .AddTo(changeColorComp); } }
public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent, IGameEntity rightEntity, IGameComponent rightComponent) { IGameEntity localEntity; localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity); if (localEntity == null) { return; } // entity存在,但是不是playback var localComponent = localEntity.GetComponent(leftComponent.GetComponentId()); if (localComponent != null) { var local = localComponent as IInterpolatableComponent; if (local.IsInterpolateEveryFrame()) { playBackInfos.Add(new PlayBackInfo(localComponent, leftComponent, rightComponent)); } try { info.BeginProfileOnlyEnableProfile(); local.Interpolate(leftComponent, rightComponent, interpolationInfo); } finally { info.EndProfileOnlyEnableProfile(); } } }
public IGameComponent GetChildByName(string name) { if (name == null) { return(null); } foreach (var component in _childComponents) { if (component.Name == name) { return(component); } } IGameComponent g = null; foreach (var component in _childComponents) { g = (component as IGameComponentContainer)?.GetChildByName(name); if (g != null) { break; } } return(g); }
public override void Run() { Canvas canvas = null; while (_running) { //if (_drawing) //{ try { canvas = _surfaceHolder.LockCanvas(null); if (canvas == null) { continue; } canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear); canvas.DrawBitmap(_fieldBitmap, 0, 0, null); for (int idx = 0; idx < _drawableObjs.Count; idx++) { _drawItem = _drawableObjs[idx]; if (_drawItem.CurPosition == null) { continue; } IDrawableComponent drawable = _drawItem as IDrawableComponent; if (drawable == null) { throw new InvalidCastException($"The drawable obj must be inherited from {nameof(IDrawableComponent)}"); } canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y, null); //var list = _drawableObjs[listIdx]; //for (int drawObjIdx = 0; drawObjIdx < list.Count; drawObjIdx++) //{ // _drawItem = list[drawObjIdx]; // if (_drawItem.CurPosition == null) continue; // IDrawableComponent drawable = _drawItem as IDrawableComponent; // if (drawable == null) // throw new InvalidCastException( // $"The drawable obj must be inherited from {nameof(IDrawableComponent)}"); // canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y, // null); //} } } catch (System.Exception e) { throw new System.Exception($"There is exception in Canvas field. {e}"); } finally { if (canvas != null) { _surfaceHolder.UnlockCanvasAndPost(canvas); } } //} } }
public void Dispose() { lock (this) { IGameComponent[] array = new IGameComponent[this.Components.Count]; this.Components.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { IDisposable disposable = array[i] as IDisposable; if (disposable != null) { disposable.Dispose(); } } IDisposable disposable2 = this.graphicsDeviceManager as IDisposable; if (disposable2 != null) { disposable2.Dispose(); } this.UnhookDeviceEvents(); if (this.Disposed != null) { this.Disposed(this, EventArgs.Empty); } } }
public static ComponentWrapper Allocate(IGameComponent component) { var rc = ObjectAllocatorHolder <ComponentWrapper> .Allocate(); rc._component = component; return(rc); }
/// <summary> /// Adds the specified key and value to the dictionary. /// </summary> /// <param name="key">The key of the element to add.</param> /// <param name="value">The value of the element to add. The value can be null for reference types.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.Dictionary`2"/>.</exception> public override void Add(string key, IGameComponent value) { base.Add(key, value); if (value is KarelComponent) ((KarelComponent)value).Parent = this; }
public GameOverState(IAnarkanoidGame arkanoidGame, IKeysConfiguration keysConfiguration) : base(arkanoidGame, keysConfiguration) { _text = new ShowText(Configuration, new Size(Configuration.ScreenSize.Width, Configuration.ScreenSize.Height)); AnarkanoidGame.ComponentManager.AddText(_text, DIE_TEXT); CommandPerKey.Add(Keys.Left, CommandsFactory.GetActionCommand(NewMatch)); }
public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent, IGameEntity rightEntity, IGameComponent rightComponent) { IGameEntity localEntity; _localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity); if (localEntity != null) // entity存在,但是不是playback { var localComponent = localEntity.GetComponent(leftComponent.GetComponentId()); if (localComponent != null) { var local = localComponent as IInterpolatableComponent; if (local.IsInterpolateEveryFrame()) { _playBackInfos.Add(new PlayBackInfo(localComponent, leftComponent, rightComponent)); } try { _info.BeginProfile(); local.Interpolate(leftComponent, rightComponent, _interpolationInfo); } finally { _info.EndProfile(); } } else { //_logger.WarnFormat("component is null while playback {0}:{1}", localEntity.EntityKey, leftComponent.GetComponentId()); } } }
public void RegisterComponent(IGameComponent component) { RegisterComponent(component as RoomRotationWallComponent); RegisterComponent(component as RotatableRoomComponent); RegisterComponent(component as RoomRotationConfig); RegisterComponent(component as GameControlHelper); }
protected virtual void Dispose(bool disposing) { if (disposing) { lock (this) { IGameComponent[] array = new IGameComponent[this.gameComponents.Count]; this.gameComponents.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { IDisposable disposable = array[i] as IDisposable; if (disposable != null) { disposable.Dispose(); } } IDisposable graphicsDeviceManager = this.graphicsDeviceManager as IDisposable; if (graphicsDeviceManager != null) { graphicsDeviceManager.Dispose(); } this.UnhookDeviceEvents(); if (this.Disposed != null) { this.Disposed(this, EventArgs.Empty); } } } }
public void RegisterComponent(IGameComponent component) { RegisterComponent(component as UISystemConfig); RegisterComponent(component as UiTriggerComponent); RegisterComponent(component as HealthComponent); RegisterComponent(component as PointsHelper); }
public static void Load(string pluginName, bool needsInit) { try { string dir = Path.Combine(Program.AppDirectory, "plugins"); string path = Path.Combine(dir, pluginName + ".dll"); Assembly lib = Assembly.LoadFrom(path); Type[] types = lib.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!IsPlugin(types[i])) { continue; } IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]); if (needsInit) { plugin.Init(game); plugin.Ready(game); } if (plugin == null) { throw new InvalidOperationException("Type " + types[i].Name + " returned null instance"); } game.Components.Add(plugin); } } catch (Exception ex) { ErrorHandler.LogError("PluginLoader.Load() - " + pluginName, ex); } }
void Load(string path, bool needsInit) { try { Assembly lib = Assembly.LoadFrom(path); Type[] types = lib.GetTypes(); for (int i = 0; i < types.Length; i++) { if (!IsPlugin(types[i])) { continue; } IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]); if (needsInit) { plugin.Init(game); plugin.Ready(game); } if (plugin == null) { throw new InvalidOperationException("Type " + types[i].Name + " returned null instance"); } game.Components.Add(plugin); } } catch (Exception ex) { path = Path.GetFileNameWithoutExtension(path); ErrorHandler.LogError("PluginLoader.Load() - " + path, ex); } }
public IGameComponent GetChildByType(Type type) { if (type == null || !type.IsSubclassOf(typeof(IGameComponent))) { return(null); } foreach (var component in _childComponents) { if (component.GetType() == type) { return(component); } } IGameComponent g = null; foreach (var component in _childComponents) { g = (component as IGameComponentContainer)?.GetChildByType(type); if (g != null) { break; } } return(g); }
public void RegisterComponent(IGameComponent component) { var comp = component as EnemyMovementComponent; if (comp) { comp .OnCollisionStayAsObservable() .Where(collision => collision.gameObject.tag == _wallTag) .Subscribe(collision => comp.IsOnWall = true) .AddTo(comp); comp .OnCollisionExitAsObservable() .Where(collision => collision.gameObject.tag == _wallTag) .Subscribe(collision => comp.IsOnWall = false) .AddTo(comp); comp .FixedUpdateAsObservable() .Where(unit => comp.IsActive && comp.IsOnWall) .Subscribe(unit => MoveEnemy(comp)) .AddTo(comp); return; } var config = component as EnemyMovementConfig; if (config) { config .Speed .Subscribe(f => _speed = f) .AddTo(config); } }
public bool IsMouseOwner(IGameComponent component) { if (MouseOwner == null || MouseOwner == component) { return(true); } return(false); }
public GameObject(IGameComponent inputComponent, IGameComponent physicComponent, IGameComponent logicComponent, IGameComponent graphicComponent) { _inputComponent = inputComponent; _physicComponent = physicComponent; _logicComponent = logicComponent; _graphicComponent = graphicComponent; }
protected void CreateGameComponent(int componentId) { if (_component != null) { GameComponentInfo.Instance.Free(_component); } _component = GameComponentInfo.Instance.Allocate(componentId); }
private Task OnOwnerDeleting(IGameComponent arg) { this.commandRequestSubscription.Unsubscribe(); IPlayer player = (IPlayer)arg; player.Deleting -= this.OnOwnerDeleting; return(Task.FromResult(0)); }
public override void Add(IGameComponent component) { base.Add(component); if (CurrentComponentIndex < 0 && Components.Count > 0) { CurrentComponentIndex = 0; } }
public void SyncTo(IGameComponent characterBoneComponent) { var boneComponent = characterBoneComponent as CharacterBoneComponent; _followRot.SyncTo(boneComponent); _weaponRot.SyncTo(boneComponent); _playerIkController.SyncTo(boneComponent); }
public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent, IGameEntity rightEntity, IGameComponent rightComponent) { _logger.DebugFormat("rewind component field {0}:{1}", leftEntity.EntityKey, rightComponent.GetType()); var left = leftComponent as IRewindableComponent; left.RewindTo(rightComponent); }
public void CreateLastGameComponent(int componentId) { if (_lastComponent != null) { GameComponentInfo.Instance.Free(_lastComponent); } _lastComponent = GameComponentInfo.Instance.Allocate(componentId); }
public void Add(IGameComponent component, Texture2D texture) { if (!_spritesByComponent.ContainsKey(component)) { var spriteBatch = new SpriteBatch(_graphicsDevice); _spritesByComponent.Add(component, new Tuple <Texture2D, SpriteBatch>(texture, spriteBatch)); } }
public override void Remove(IGameComponent component) { base.Remove(component); if (CurrentComponentIndex >= Components.Count) { CurrentComponentIndex = Components.Count - 1; } }
public static void AddComponentReadyInvoker(IGameComponent invoker) { ComponentReadyInvokers.Add(invoker); foreach (var listener in ComponentReadyListeners) { invoker.AddComponentReadyListener(listener); } }
/// <summary> /// Unregisters the given GameComponent, causing it to no longer be active. /// </summary> public void RemoveGlobalComponent(IGameComponent Component) { bool result = _Game.Components.Remove(Component); if (!result) { throw new ArgumentException("The given component was not registered."); } }
private void InitializeExistingComponents() { IGameComponent[] array = new IGameComponent[this.Components.Count]; this.Components.CopyTo(array, 0); foreach (IGameComponent gameComponent in array) { gameComponent.Initialize(); } }
public void PickUp(IGameComponent item) { if (item.Type == GameComponentType.Apple) { Apples.Remove((IFoodComponent)item); } _drawableObjs.Remove(item); }
public static DeleteComponentPatch Allocate(IGameComponent comp) { var rc = ObjectAllocatorHolder <DeleteComponentPatch> .Allocate(); rc.CreateGameComponent(comp.GetComponentId()); // ReSharper disable once PossibleNullReferenceException (rc.Component as INetworkObject).CopyFrom(comp); return(rc); }
public IGameComponent AddComponent(IGameComponent component) { if (HasComponent(component)) throw new InvalidOperationException("Cannot add the same component more than once."); Components.Add(component); component.Enable(); return component; // var comp = someState.AddComponent(new SomeComponent()); }
/// <summary> /// Adds a new component to the screen and in case its a /// ISoundableGameComponent we'll add it to a dedicated inner list /// </summary> /// <param name="i_Component">The new component we want to add /// to the screen</param> public override void Add(IGameComponent i_Component) { base.Add(i_Component); ISoundableGameComponent component = i_Component as ISoundableGameComponent; if (component != null) { component.PlayActionSoundEvent += new PlayActionSoundDelegate(Component_PlayActionSoundEvent); } }
public void RemoveGameComponent(IGameComponent component) { var res = Components.FirstOrDefault( c => { var comp = c as GameComponentWrapper; if (comp == null) return false; return comp.Component == component; }); if (res == null) return; Components.Remove(res); }
/// <summary> /// Adds a new component to the screen. /// In case it's a MenuItem, we'll save it in a dedicated list in /// addition to the parent list /// </summary> /// <param name="i_Component">The component we want to add to the screen</param> public override void Add(IGameComponent i_Component) { base.Add(i_Component); MenuItem item = i_Component as MenuItem; // Adding item and registering item selected event if (item != null) { m_MenuItems.Add(item); setItemPosition(m_MenuItems.Count - 1); item.Selected += new MenuItemSelectedEventHandler(item_Selected); if (m_MenuItems.Count == 1) { m_MenuItems[0].IsSelected = true; m_CurrentMenuItem = 0; } } }
private void objectCollision() { Player player = game.currentLevel.getPlayer(); IGameComponent[] copy = new IGameComponent[game.Components.Count]; //component list is coppied to avoid concurrent modification exceptions when a collission is detected. i.e. adding explosion effect etc. game.Components.CopyTo(copy, 0); foreach (GameComponent component in copy) { ICollidable component3D = component as ICollidable; //tests if component implements ICollidable and thus is collidable if (component3D != null) { Player componentPlayer = component3D as Player; //makes sure the component being looked at is not the player if (componentPlayer == null) { foreach (ModelMesh mesh in player.getModel().Meshes) { foreach (ModelMesh currentMesh in component3D.getModel().Meshes) { BoundingSphere otherBoundingSphere = currentMesh.BoundingSphere; // set the bounding sphere to being the mesh's bounding sphere. Planet planet = component3D as Planet; // test if the component being checked is a planet. if (planet != null) { otherBoundingSphere.Radius += 1; //if it is, its bounding sphere needs to be above the surface of the planet. } otherBoundingSphere = otherBoundingSphere.Transform(currentMesh.ParentBone.Transform * Matrix.CreateScale(component3D.getScale(), component3D.getScale(), component3D.getScale()) * Matrix.CreateTranslation(component3D.getPosition())); BoundingSphere playerBoundingSphere = mesh.BoundingSphere; // find the players bounding sphere for each mesh. playerBoundingSphere = playerBoundingSphere.Transform(mesh.ParentBone.Transform * Matrix.CreateScale(player.getScale(), player.getScale(), player.getScale()) * Matrix.CreateTranslation(player.getPosition())); if (playerBoundingSphere.Intersects(otherBoundingSphere) && component3D.isAlive()) { component3D.collision(player); player.collision(component3D); return; } } } } } } }
public void BindGameComponent( IGameComponent gameComponent ) { this.Components.Add( gameComponent ); }
public void BindGameComponent(IGameComponent gameComponent, Type serviceInterface) { this.BindGameComponent( gameComponent ); this.Services.AddService( serviceInterface, gameComponent ); }
/// <summary> /// Gets the value associated with the specified key. /// </summary> /// <returns> /// true if the <see cref="T:System.Collections.Generic.Dictionary`2"/> contains an element with the specified key; otherwise, false. /// </returns> /// <param name="key">The key of the value to get.</param><param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value"/> parameter. This parameter is passed uninitialized.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception> public bool TryGetValue(string key, out IGameComponent value) { return _children.TryGetValue(key, out value); }
/// <summary> /// コンポーネントを追加する /// Loadedがtrueの場合、Game.Componentsに追加で登録される /// Loadedがfalseの場合、RegistInitialiseComponentメソッドが実行されるまで登録されない /// </summary> /// <param name="component"></param> public void AddComponent(IGameComponent component) { GameComponent baseComponent = component as GameComponent; if (baseComponent != null) { _baseComponents.Add(baseComponent); } DrawableGameComponent drawableComponent = component as DrawableGameComponent; if (drawableComponent != null) { _drawableComponents.Add(drawableComponent); } // シーン読み込み後に追加されたコンポーネントを登録 if (Loaded) { Game.Components.Add(component); } }
/// <summary> /// Adds a key/value pair to the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key does not already exist. /// </summary> /// <returns> /// The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary. /// </returns> /// <param name="key">The key of the element to add.</param><param name="value">the value to be added, if the key does not already exist</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is a null reference (Nothing in Visual Basic).</exception><exception cref="T:System.OverflowException">The dictionary contains too many elements.</exception> public virtual IGameComponent GetOrAdd(string key, IGameComponent value) { return _children.GetOrAdd(key, value); }
private Task OnOwnerDeleting(IGameComponent arg) { this.commandRequestSubscription.Unsubscribe(); IPlayer player = (IPlayer)arg; player.Deleting -= this.OnOwnerDeleting; return Task.FromResult(0); }
public void AddGameComponent(IGameComponent component) { Components.Add(new GameComponentWrapper(component, this)); component.Initialize(); }
/// <summary> /// Event handler to disconnect the socket when the palyer is being deleted. /// </summary> /// <param name="component">The component being deleted.</param> /// <returns>Returns an awaitable Task</returns> private Task DisconnectPlayer(IGameComponent component) { if (this.outboundMessage != null) { this.outboundMessage.Unsubscribe(); } component.Deleting -= this.DisconnectPlayer; this.socket.Shutdown(SocketShutdown.Both); this.socket = null; var handler = this.Disconnected; if (handler == null) { return Task.FromResult(0); } handler(this, new ConnectionClosedArgs(this.player, this)); return Task.FromResult(0); }
public void GiveGomponent(IGameComponent component) { _components.Add(component); }
public ChatMessageBase(string message, IGameComponent sender) { this.Content = message; this.Sender = sender; }
/// <summary> /// Adds a key/value pair to the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key does not already exist, or updates a key/value pair in the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key already exists. /// </summary> /// <returns> /// The new value for the key. This will be either be addValue (if the key was absent) or the result of updateValueFactory (if the key was present). /// </returns> /// <param name="key">The key to be added or whose value should be updated</param><param name="addValue">The value to be added for an absent key</param><param name="updateValueFactory">The function used to generate a new value for an existing key based on the key's existing value</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is a null reference (Nothing in Visual Basic).-or-<paramref name="updateValueFactory"/> is a null reference (Nothing in Visual Basic).</exception><exception cref="T:System.OverflowException">The dictionary contains too many elements.</exception> public virtual IGameComponent AddOrUpdate(string key, IGameComponent addValue, Func<string, IGameComponent, IGameComponent> updateValueFactory) { return _children.AddOrUpdate(key, addValue, updateValueFactory); }
// All highscores stuff public static bool FilterHighscore(IGameComponent gc) { return gc is HighscoreComponent; }
public GameComponentWrapper(IGameComponent component, Game game) : base(game) { Component = component; }
/// <summary> /// Adds the specified key and value to the dictionary. /// </summary> /// <param name="key">The key of the element to add.</param><param name="value">The value of the element to add. The value can be null for reference types.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception><exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.Dictionary`2"/>.</exception> public virtual void Add(string key, IGameComponent value) { _children.Add(key, value); }
public bool HasComponent(IGameComponent component) { return Components.Contains(component); }
public GameComponentCollectionEventArgs(IGameComponent gameComponent) { GameComponent = gameComponent; }
public void RemoveComponent(IGameComponent component) { var match = Components.FirstOrDefault(c => c == component); if (match == null) return; Components.Remove(match); match.Disable(); }
private Task PlayerDisconnecting(IGameComponent arg) { var player = (IPlayer)arg; player.Deleting -= this.PlayerDisconnecting; this.Disconnect((IPlayer)arg); if (player.CurrentRoom == null) { return Task.FromResult(0); } IEnumerable<IPlayer> remainingPlayersInRoom = player.CurrentRoom.Occupants .Where(character => character is IPlayer && character != player) .Cast<IPlayer>(); foreach (IPlayer occupant in remainingPlayersInRoom) { this.playerConnections[occupant].SendMessage($"\r{player.Information.Name} left the realm.\r\n"); } return Task.FromResult(0); }
public void AddComponent(IGameComponent component) { Components.Add(component); }