Jump to content

Davaris

Members
  • Posts

    285
  • Joined

  • Last visited

Everything posted by Davaris

  1. Davaris

    Component prefabs

    >Is that how it works? Since Rick isn't around I'll answer. Yes and many more components than you mention. The idea is each entity has a list of components and it iterates through them one at a time, during its update cycle.
  2. Davaris

    C# SVN

    Thanks for that.
  3. C# and C++ are very similar except for the pointers and destructors. Just replace the '->' with '.', the '*' with nothing, and anything with a '~' in front of it with nothing and you are set.
  4. Davaris

    C# SVN

    seven, when you find out how to do it, please post the steps. I have no idea about using these things.
  5. I think what I've posted above explains it pretty well. At least I hope it does. As soon as I get it working in LWs I'll post it. It shouldn't be more than a week or so, if I stick with it. Anyway, what I love about this system, is you can use it to write glorious spaghetti code!
  6. I'm much closer to finishing now. I've wrapped my property class in a decorator class that stores a second parent pointer, so I can have different hierarchies of property bags that share the same property bags (if that makes any sense ). I've also written some messy classes (they won't win any beauty contests) that watch and interact with the property bags, using the Observer Pattern. Pointers are shared between these classes, however if one or the other is deleted, they tell each other to Detach immediately (this area needs more testing). After that, it is just XML and dlls and I'll be ready to start trying to do things in LWs. If you are worried that this will run slow, I don't think it will. In fact, I think it will be super fast, if used correctly because it is event driven. This is where the bulk of work is done in my Action class. There will be one Action class for any action I invent for my games. As you can see, nothing happens until a variable it is listening for, changes in one of the property bags it is linked to. // The property bags send you messages when the // variables in them you are watching change. // You can also read or change the bags contents. // You can create new actions from here as well. public override void OnNotify<T>(string owner_name, string opcode, string key, object val) { if (opcode != "Put") return; Console.WriteLine("{0} {1} has changed to {2}", owner_name, key, val); if (key == "uintKey2") // a message from bag1 { float float_val = 0; // Get Speed from bag 2 if (mSubject2.Get<float>("Speed", ref float_val)) { Console.WriteLine("{0} Speed is {1}", mSubject2.Name, float_val); // Change Speed in bag 2 mSubject2.Put<float>("Speed", float_val + 100); } } if (key == "Strength") { } if (key == "Speed") { } if (key == "JUNK") { } if (key == "JUNK2") { } if (key == "JUNK3") { } } My action class also has an Update member, so if you need to you can keep a copy of the variable changes from OnNotify, so there is no need for costly lookups every tick or frame, or whatever they call it. public void OnUpdate() { } Output: child1 unitKey2 has changed to 123 child1 Speed is 101 child2 Speed has changed to 201 Explanation: child1, child2 are the names of the property bags mSubject1, mSubject2. 1) I changed the value of 'unitKey2' in 'mSubject1' (bag1) in my main loop and my action object was notified and received the changed variable in OnNotify<T>. 2) My Action object then reads the value of 'Speed' from 'mSubject2' (bag2) and adds 100 to it. 3) My action class is notified of the change it just made to 'Speed' in 'mSubject2', as are any other Action objects that are also watching it. EDIT: It just occurred to me that I may need to stop the action class, from being notified of the changes it makes to any property bags it is watching.
  7. Reload Weapon, Quaff potion. Another one you may not have though of is Effects. Say you are given a short term boost, you don't want to alter your main stats, you want to keep the boost in a separate object and add it to your main stat when you check it. When the effect wears off, it is deleted from your system. These kinds of effects can be used for many things from spells, potions, magic weapons and injuries that can be healed or can wear off by themselves.
  8. >Looking good Davaris. Have you tried to get an real world example working yet? Thanks. Its still early days yet. I have to add a few features (XML, a variable watcher and event sender, a way to share the parent's data with the whole system), before I'll be ready to start on the action objects that use it. I am also thinking of making it accessible from LUA, so I can use LUA scripts for my actions instead of C#, but I don't know if that is possible in Leadwerks. I have a question, do you think we should make these property bags thread safe? BTW you can get the source for the LinkedHashMap here: http://gforge.opensource-sw.net/gf/project/flexsdk/scmsvn/?action=browse&path=%2Ftrunk%2Fswfutils%2FJavaCompatibleClasses%2FLinkedHashMap.cs&revision=2&view=markup&pathrev=34 It is a C# port taken from part of Adobe's FlexSDK, however I think there is a bug in it which can be fixed by doing the following: // (search for) m_Tail.m_Next = node; // (add this line underneath) node.m_Previous = m_Tail; The reason LinkedHashMap is so useful for our purposes, is everything is maintained in its original insertion order.
  9. This is what I have so far with my C# property container. I'm copying Steve Yegge's Universal Design pattern, so it will work differently to Rick's and may be too slow in the end (I hope not). I haven't posted the code yet, because it might have a minor bug or two that I can't see. So if anyone thinks of some good tests that might break something like this, please post them. public class StateData { private string mName; private LinkedHashMap List; private bool mIsReadOnly; private StateData mParent; private const string cBlank = "$_Blank_$"; public StateData(string name) public void SetParent(StateData parent) // If the key in your parent exists, create a new key here public void Put<T>(string key, T val) public bool Get<T>(string key, ref T ret_val) public bool Has<T>(string key) public void Remove<T>(string key) public void SetIsBlank<T>(string key) public void PrintContents() } Sample usage: StateData state_parent = new StateData("parent"); // **************************** // state_parent // **************************** state_parent.Put<float>("floatKey1", 6.0f); state_parent.Put<string>("stringKey1", "this is a string"); state_parent.Put<int>("intKey1", 1); state_parent.Put<uint>("uintKey1", 1); // **************************** // state_child // **************************** StateData state_child = new StateData("child"); state_child.SetParent(state_parent); state_child.Put<uint>("uintKey2", 122); state_child.Put<uint>("uintKey1", 7); state_child.Put<uint>("uintKey1", 99); state_child.SetIsBlank<int>("intKey1"); //state_child.Remove<int>("intKey1"); int int_val = 0; if (state_child.Get<int>("intKey1", ref int_val)) { Console.WriteLine("intKey1 = " + int_val); Console.WriteLine(""); } else { Console.WriteLine("Get intKey1 failed "); Console.WriteLine(""); } state_child.PrintContents(); Once you give the child a parent, the parent's data becomes read only. If the child wants to Put a variable (create or set) that already exists in the parent, it creates a copy in itself and henceforth accesses it instead of the one in the parent. Setting a variable as blank, forces the child class to read it (as null) instead of an identically named variable that may exist in the parent. That way you can get a 'variable does not exist' message back, even if an identically named one exists in the parent. If you Remove a variable, it will be removed from the child list completely and from then on a call to Get will search for the same named variable in the parent. Yes I know its a very odd way of doing things. You would have to read Steve Yegge's article to understand the reasons for it.
  10. I'm not sure how Rick's code works, but you are supposed to be able to have more than one component of a type, as long as you think up a unique name for each one. The container class stores a list of components, each of which is addressed by a string label that you give it.
  11. The only downside to components that I have heard of, is some people say they can run a little slower due to the searching to get components. However I have also read there are ways to solve the speed issues. Also the major dev houses have been successfully using them for 5-10 years, so they must have overcome these problems. The speed issue will be something I'll have to deal with as there are a lot of variables per entity in my game, so there will be a lot of searching.
  12. Since you're trolling now. Here's a link just for you: The Flat Earth Society http://www.alaska.net/~clund/e_djublonskopf/Flatearthsociety.htm
  13. Thanks! I'll be using the techniques from the last two articles I linked on Object-Oriented Game Design, to refactor my huge inheritance based RPG engine, to the action-entity-data model, which really is a data driven Object Component model. My first goal will be to get it outputting its commands and results entirely in text and then I'll use the other techniques discussed in the articles to rapidly swap in Leadwerks, a 2D engine or almost any other 3D engine, if I wanted to do so. I also expect this structure to make it trivial, to add networking. So yeah, this will probably take a while... I'll post again on this subject, when I get the text version working.
  14. http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy
  15. Hey Guys, I found a few more articles with source that relate to this topic. If you are new to this kind of coding, they will increase your understanding. This is really long, but explains how actions, states and entities can work together to make an engine that can be used again and again for different types of games. It ties in with the code Rick wrote. Object-Oriented Game Design A modular and logical method of designing games http://www.devmaster.net/articles/oo-game-design/ This blog entry explains the actions, states and entity relationship the above article introduces in simpler terms and once you understand it, you will see how powerful this kind of system is. Object-Oriented Game Design http://gbgames.com/blog/2006/03/object-oriented-game-design/ Both articles have source, one is in C# and one C++. The monopoly example in C++ is more clear IMO, but both are worth a look. This guy wrote the code for the article "Game Object Component System" - Chris Stoy, from Game Programming Gems 6. It is mislabeled in the link below, as being from GPG 5. This is a C++ implementation. http://www.unseen-academy.de/componentSystem.html And finally a GameDev page of links: component-based design resources http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=443615&cmonth=9&cyear=2008
  16. Just downloaded and had a look at your stuff and was very impressed. I'll be buying for sure. BTW I noticed in your GDC Tech Demo, you have some nice looking cliff faces and roads. Were they done with special textures? If so will you be offering those for sale as well?
  17. Davaris

    WIP-Ragdoll

    The poor guy is in a world of hurt.
  18. Can't download any of the files. I just get 1 or 2 kb and it stops. EDIT: Now I get 404.
  19. Have a look at the article I linked to in comment #10. It makes Object Components go from cool, to very cool. Dynamic Game Object Component System for Mutable behavior Characters Also there are some behaviors you may want to turn on and off. For instance: sparkly effects, a twitch or a limp, a sound playing, a skill or ability earned or lost, a weapon equipped, armor that affects your stats and so on.
  20. If components can be added and removed during run time, then you would have to send a message to a component manager class, which in turn will tell all of its components what was removed. Then for the components that are missing a dependency, we have two options: 1 A component that is a missing a dependency, tells the component manager to remove itself from the component list. 2 If components are not deleted when removed (they are still in the list, but are not updated, or rendered anymore) you can let the component continue to access its "missing" dependency, as if nothing happened. As I don't know what should be the standard, perhaps it should be offered as a user selectable option for each component?
  21. I think events are a logical method for sending messages to other components to preserve loose coupling. But if you need to check values from another component, or call its functions, the component is not independent and needs another component to function, as your CheckDependencies function shows. So if you don't want to give a component too much information, why not use C# style interfaces as contracts, that the injected components must fulfill? Does C++ have an equivalent? If you use this method, you can swap the required component for another dynamically. EDIT: Or perhaps this only works in C#?
  22. I'm curious as to what you mean by bloated. According to this it should be lean and fast. http://gameprogrammingpatterns.com/component.html
  23. Try this: www.infoway-pi.com.br/erick/gcore.zip I have to admit that his article has made me like object components a little more.
×
×
  • Create New...