Jump to content
  • Advertisement

gamer08

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

115 Neutral

About gamer08

  • Rank
    Newbie
  1. Hmm... in times of multi-core systems running multiple AIs concurrently isn't a bad idea.   I'm currently refactoring my AI system and the biggest show-stopper of multi-threaded AI is the interaction with the other entities. E.g. if unit A shots at unit B which shots at unit C while walking etc. , updating this concurrently without using standard synchronization tools (e.g. OS mutex which are often avoided in real-time games) can get messy really quickly.   To break AI a little bit up, you can divide it into decision making and action execution. The latter manipulates the world and/or other entities and is therefor more critical. The former is much easier to handle, because it often only scans the world, or better only a (partly) copy of the world (read-only access), or manipulates the according entity.   Well, a basic idea would be, to use multithreading for decision making and a single stable world on a single thread for action execution. There are really several ways to implement it, e.g. use a threadpool and a dispatcher for the AI decision making, add the actions to a lock-less array(queue) and execute the actions afterwards on a single thread.   But,mutlithreading is one of the fastest way to kill of your game, if you aren't really familiar with MT programming, AI etc., so think carefully about using it. Yes i've alreday check for parallel threadings via threadpool or something else, but to be honest i'm not an expert in multithreads. I already used it but not in a game development. Parallel AI is something i'd like acheive      My problem is that i use a message system to communicate between different type and the handling is in the state and sometimes a unit instance doesn't receive the message because " it's not is turn " to evaluate the logic so i need a way to parallelize some stuff   so any ideas is welcome       Each different state instance is singleton because i just want to save a bit of memory. But to be honest i don't check the impact or the difference if each state machine have their own state instance
  2. I everyone i have a little question about AI logic, state and thread in game in general   first of all some usefull infos,   i'm working on a rts game langage c# framework XNA   each type of unit have their own states and for the moment each state of each type is a singleton   each unit have a steering behavior and a state machine   for the moment everything is on the main thread   example :   two units of the type A are on the same state   when i update the logic i pass the owner of the state machine as a parameter to the state but the logic is updated on a unit after another (yes i know it's not great, the reason why i'm here)   What is the best way to ensure that every unit update their ai logic at the same time / almost same time ?   1. i think a thread per unit ? 2. threadpool ?   If it's not clear , i can give futher explanations   Any suggestions, ideas or anything is welcome !   thanks to help  
  3. Thanks fo the awnser. For the AI behavior that' exacly what i though. i just need a confirmation thanks !   and yes i will probably refactoring, if i have time (deadlines in coming)   and thanks for the URL
  4. You just restated your problem without really giving us any more information. My understanding is that you're storing position and rotation in some array in your main game class? Why does this prevent you from using it for the bacteria class? Why does bacteria have its own position and rotation? What language are you using? Maybe if you provided some code we could understand your problems better.   Ok first of all the langage is c# second i use XNA 4.0   my Base class abstract class Chemotaxis_GameObject { #region Constructor/Destructor protected Chemotaxis_GameObject(Texture2D texture, Vector2 origin) { this.texture = texture; this.origin = origin; } #endregion #region Attributes protected Texture2D texture; //protected Vector2 position; //protected float rotation; protected Vector2 origin; #endregion Attributes #region Functions public virtual void Update(GameTime gameTime){} public virtual void Render(SpriteBatch spriteBatch,Vector2 pos, float rot) { spriteBatch.Draw(texture, pos, null, Color.White, rot, origin, 1.0f, SpriteEffects.None, 1.0f); } #endregion }   i'll keep it simple. Normally i would set the position, rotation,... in this class but the're all state dependant (extrinsic i think)   one of my flyweight abstract class   abstract class Chemotaxis_Bacteria : Chemotaxis_GameObject { #region Constructor/Destructor protected Chemotaxis_Bacteria(Texture2D texture, Vector2 origin, Chemotaxis_Bacteria_Type type, Chemotaxis_Sensor sensor, float speed) :base(texture,origin) { this.type = type; this.sensor = sensor; this.speed = speed; } virtual ~Chemotaxis_Bacteria() { } #endregion #region Attributes //protected Chemotaxis_StateMachine stateMachine; protected Chemotaxis_Bacteria_Type type; protected Chemotaxis_Sensor sensor; protected float speed; #endregion public abstract void Update(GameTime gameTime, ref Vector2 position,float rotation); }   so i implement this class on multiples concrete flyweight and use a factory to create and return them when a flyweight client is create   a flyweight client   class Chemotaxis_BacteriaClient { #region Constructor/Destructor public Chemotaxis_BacteriaClient(Vector2 pos, float rot) { this.position = pos; this.rotation = rot; bacteria = Chemotaxis_BacteriaFactory.GetBacteria(Chemotaxis_Bacteria_Type.TYPE_A); } #endregion #region Attributes Vector2 position; float rotation; Chemotaxis_Bacteria bacteria; #endregion #region Functions public void Render(SpriteBatch spriteBatch) { bacteria.Render(spriteBatch, position, rotation); } public void Update(GameTime gameTime) { bacteria.Update(gameTime,ref position,rotation); } #endregion } as you can see this class hold the position, rotation and all state dependant properties. It's the first time i use a flyweight so i'm not sure if it's ok   so as you can see the code is split into many classes  intrasic and extrasic and doesn't fit well with my inheritance but it's probably Ok with this pattern. If someone can confirm it could be good      and my second question is : Where shoud i put the AI behavior ? Probably in a client class if a follow the logic of the pattern but i'm not sure.   Finally the game client instances are create in the game main class   Thank for any help or advices
  5. Well i'm working on a RTS bacteria game and these are the problem   1) I don't know what do to with the inheritance because i have multiple levels and normally my Game Base object should have the position the rotation,... but each instance of bacteria have their own position,rotation because this a dependant state property and my flyweight cannot handle it   so the question is : Is it normal the the inheritance can be duplicate or broken with flyweight pattern ?   2) Second, i don't yet implement the AI part and i would use probably state machine with different behavior  but i don't who should handle the machine and the behavior , is the Flyweight itselft ? or a client class ?. I mean each bacteria of the same type will have the same set of state and behavior, but they will have their own state machine or at least the current could be different. i am wrong ?   i don't know if it's more clear, i can explain with code i you want.   also if someone have a reference with example about pattern in video game, i have the GOF one's but it could be great to have an example how to implement flyweight or decorator   thanks for any help
  6. I everyone, i'm working on an indie game and i'm stuck with two problems I have many similar units on screen so i decided to implement the flightWeight pattern so there is intrinsic and extrinsic parts   Q 1 : How to manage inheritance ? If the game base class posses the object position and rotation for example and let says i have multiple inheritance level, where to put these attributes. I mean these attributes are state dependant so, it the should be the client to have these and manage it nut it the broke the inheritance. Any advices ?   Q 2 : How to manage state machine and behavior ? My basic soldier unit have all the same same Ai behavior of cource ( they can attack, move, retreat, .. ) but their current state is not probably the same, one instance is moving when another is attacking. So wich class should posses the state machine and the behavior ?   I don't know if it's clear. Feel free to ask more details, i will explain Thanks in advance for any advices or anything !  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!