Laurens Posted January 10, 2010 Share Posted January 10, 2010 Hi, Tonight I took a new approach at handling both input and AI and was hoping you guys could give me some feedback on it. I'll explain how it works by using a Pong example. I have a class called Paddle and a class called Controller (not a Leadwerks TController). The Paddle class keeps a reference to the actual TEntity (the paddle model) and a reference to a Controller. Additionally it has an "Update" method. class Paddle { public: Paddle(TVec3 startPosition, Controller *controller); void Update(); private: Controller *controller; }; The Controller keeps a TEntity called target and has a virtual method "Update". class Controller { public: void SetTarget(TEntity target); virtual void Update() = 0; protected: TEntity target; }; When the Paddle is constructed, it loads the model and calls the SetTarget method on the supplied Controller passing in the entity it just loaded. Now, every time the "Update" method is called on the Paddle class (from the main loop) it subsequently calls the "Update" method in the Controller class. Then I create a Player class that inherits from Controller and only overrides the "Update" method. class Player : public Controller { public: void Update(); }; The "Update" method from the Player class contains code that checks which key is down and calls the appropriate position and commands on the TEntity target. Next I was planning on creating an AI class that overrides the "Update" method and positions the target based on the position of the ball. That way I could basically plug a Controller in any object and have a player or AI control it. So, what do you think? All constructive criticism appreciated! Quote Link to comment Share on other sites More sharing options...
fuego Posted January 11, 2010 Share Posted January 11, 2010 I thikn you are planning to extend this approach with adding native path finding and some other application specific AI stuff support. Why do you intend to put a different controller than engine's? Or am I being confused because both things have the same name but a different meaning? I am considering you are speaking about a same type of controller like we have in LE. Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 11, 2010 Author Share Posted January 11, 2010 You are being confused with the fact the names are the same Replace all instances of "Controller" with "PaddleController" or something. I do not intent to code a replacement for Leadwerks's TController. I do intent to extend the functionality of with specific AI algorithms, correct Cheers! Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 11, 2010 Author Share Posted January 11, 2010 Quick class diagram attached: Main loop calls Update, which calls the paddle's Update, which class the Controllers Update, which controls the paddle based on code in either the Player or AI class. Quote Link to comment Share on other sites More sharing options...
fuego Posted January 11, 2010 Share Posted January 11, 2010 Having specific AI capabilities for a player controller, which interacts with integrated AI capabilities in an engine (like path finding, etc.) would be incredible! I have never seen such an engine and if one would have it, I believe it would start a new age like crysis did. Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 11, 2010 Share Posted January 11, 2010 That's basically how the player controller works in gamelib. You can steer it with keyboard or movement commands. The zombie AI which is just following waypoints, is using the same TPLayer class as the player, but it's controlled by the computer. The player entity which the player controls, can be changed on the fly to any other player entity too, so you could step into the AI zombie and take over the controls, then your old corpse would stay dead unless you assign it's corpse to the AI engine. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
fuego Posted January 11, 2010 Share Posted January 11, 2010 In gamelib can zombie evaluate the complex paths and decide which path would be the best to follow or is it a planned feature in the near future? Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 11, 2010 Share Posted January 11, 2010 That can be easily added, since the zombie follows just a vector of waypoints. So an complex AI only needs to place new entries in the waypoint vector, which is very simple in C++. You can also move waypoints on the fly. You can also add your own AI the same way right now, so you don't have to wait until I write some A* class. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
fuego Posted January 11, 2010 Share Posted January 11, 2010 We have made our path finding system almost complete (only few optimizations remained), I think it is not something "simple" as you said. Or may be we are not very capable, I don't know. Something which works flawlessly for the evaluation for 5 nodes may become a nightmare when evaluating a thousand nodes. Anyway, we use the gamelib 0.16 for the time being and I believe it made us gaining speed and time. We will certainly put a thank to you in our game's contributors list. Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 11, 2010 Share Posted January 11, 2010 You can put "Thanks to the Leadwerks Community for GameLib", as lots of code and ideas in it is donated by different people from the LE community I think the video player should be also part of it, but I need to ask Niosop for permission; and Tyler's web browser. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
fuego Posted January 11, 2010 Share Posted January 11, 2010 I will certainly do that, I believe people who contribute to those forums deserve big thanks Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 11, 2010 Author Share Posted January 11, 2010 Thanks for in the input all! I will continue to pursue this system and see if I can improve and expand on it. Cheers! Quote Link to comment Share on other sites More sharing options...
DaDonik Posted January 11, 2010 Share Posted January 11, 2010 You could also use the callback functions. The UpdateCallback will be called once per loop and even delivers you the entity for which the callback is called. I use this approach and have no problems so far. Due to the fact that the game loop does not know anything about the game entities, you have to send informaton via messages, but that works fine. Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Niosop Posted January 11, 2010 Share Posted January 11, 2010 You can put "Thanks to the Leadwerks Community for GameLib", as lots of code and ideas in it is donated by different people from the LE community I think the video player should be also part of it, but I need to ask Niosop for permission; and Tyler's web browser. Feel free, my code really isn't anything, it's the libraries that do all the work. I got the sound sync'd a lot better last night, I'll post an updated example project later. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.