• Advertisement

vtchill

Member
  • Content count

    51
  • Joined

  • Last visited

Community Reputation

180 Neutral

About vtchill

  • Rank
    Member
  1. Polymorphic Smart Pointers

    Just to add to the above post, it is potentially dangerous to use an unnamed temporary shared_ptr as it has the potential to cause a memory leak. Something like this would be a better alternative. boost::shared_ptr<Base> obj(new Derived(/*constructor arguments here*/)); stack.push(obj);
  2. Just a word of caution. In your AddWeapon function you should create the shared_ptr in a variable first and then call push_back on that variable. The shared_ptr documentation mentions the possible problems with constructing a temporary unnamed shared_ptr object.
  3. I also thought starUML was clunky and a bit slow when reverse engineering. I am currently using Bouml. It is free and it runs on all major platforms. It also runs much faster than starUML on reverse engineering code. It has the ability to do code generation and it supports a couple of languages including java and c++. It can also generate pretty nice HTML documentation. The project is very active and the developer regularly posts updates. The documentation for the program could be a little better, but the author is French so I can't really fault him on pretty decent documentation in English. After the initial learning curve I have found things are pretty intuitive and it seems to handle pretty much anything I have wanted it to do. Hope you find it useful.
  4. The function HeaderFileFunction is trying to use a CObject instance called Object but it does not know about Object. If you are going to try and call a non member function and use an existing class object inside the function then it has to know about the instantiated object somehow. So try passing the object into the function like so: void HeaderFileFunction(const CObject& Object) { //Call the objects member function Object.GetNumberFromObject(); } then call the function from main() like this: CObject Object; int main() { HeaderFileFunction(Object); return 0; }
  5. Quote:Original post by supagu using the observer pattern, just wondering how people are handling this notify subject changed callback. eg. *** Source Snippet Removed *** supposed ComponetB is an observer of ComponentA, but component B want to know different information based on if SomeFunction or SomeOtherFunction was called on ComponentA. hence, some additional event info needs to be sent, i guess this should be an event id. It would be nice if i could just send through the pointer of the function that was called but c++ you cant just cast function pointers to void* unfortunately. any one have any good ideas what to do here? Well my quickest solution would be to create event classes inherited from a base event class and pass the base event class around to Notify objects of changes. I don't think you should have to pass the entire component for every change. class BaseEvent { BaseEvent(int type, int source, int dest); int eventType; int senderId; int receiverId; }; class DerivedEvent1 : public BaseEvent { DerivedEvent(double information); double derivedInformation; }; class DerivedEvent2 : public BaseEvent { DerivedEvent(double information1, double information2); double information1; double information2; }; class ComponentA { void SomeFunction() { BaseEvent *event = new DerivedEvent1(some_info); NotifyListeners(event); } void SomeOtherFunction() { BaseEvent *event = new DerivedEvent2(some_info, some_other_info); NotifyListeners(event); } }; class ComponentB { void NotifySubjectChanged(BaseEvent *event) { switch(event->eventType) case EVENT_FLY: { // cast to specific event here DerivedEvent1 devent = static_cast<DerivedEvent1*>(event); // use information contained in derived event here break; } ... } };
  6. which is the best alternative

    I think the best option if you don't get into a 4-year college is to take classes at a local community college to earn credits that will transfer to a 4-year university. I would take all the basics to get them out of the way like your maths (couple semesters of calculus), english, history, sciences (couple semesters of physics at least). If introduction to programming type of classes are offered they are good to have to, but in my experience are less likely to transfer over so you have to be careful to check before hand. Most community colleges will work with you to make sure your classes will carry over to the local 4-year schools in the area. 2 years worth of credits at a community college is a great bargain and as long as you are careful they should transfer over and you will only be left with ~2 years of upper level classes at a 4-year university for a degree. Not sure of the community colleges in your area, but the ones around here work closely with the larger 4-year schools to help students out with transferring.
  7. Non-static member functions have an implicit this parameter as its first parameter. Therefore your function pointer signatures do not match. the standard does provide std::mem_fun and std::mem_fun_ref for binding to member functions. Also the boost bind library provides some good binding classes that are fairly easy to use instead of normal function pointers.
  8. Quote:Original post by ZealousEngine Ah touche' I wasnt too familiar with the observer pattern but youre right. A good article can be found here... http://www.codeproject.com/cpp/observer.asp So instead... The Position Component would be a Subject, and as Visual or Physical Components are attached, they register to the Position as Observers. Then when Physical changes the Position, Visual will be notified indirectly. And like youre already doing, I think its smart to just toss Position into the entity itself (since 99% of entities will have a position). No need for it to be a Component. *edit So im curious to hear more about how you implemented this. Are the components/observers polling their subjects? How do you control when this polling takes place? Or are you just having subjects notify all registered observers on a change? Subjects notify all registered observers on the change that is the beauty of the observer pattern. It would be a pain if observers had to poll. Usually a subject has register and unregister functions along with a Notify function which just loops through registered observers and calls their action function which can either be a polymorphic function or a function pointer style callback.
  9. Both of the UML programs I mention below are free and I have only used them myself to design and document programs I have done at home and for design docs at work. I started with starUML but thought it was a little rough around the edges and a little slow with a lot of classes. I then tried Bouml which I found to be a much better program. There is a little learning curve to it, but it is pretty good with code generation in c++ and java. Bouml is also pretty configurable so you can change the generation settings, display settings, etc. It can also do pretty decent Html documentation. Although I have never tried it Bouml claims to offer XMI compatibility. I have used the reverse engineering for a decently large c++ project and it worked pretty well and quickly. Bouml also provides all the common UML views (4+1 view). It seems to be a pretty active project with new releases and bug fixes coming relatively quickly. It may not be industrial strength, but it has always got the job done for me. [edit] I just wanted to add that I am not sure anything out of the box is that great at code generation. Besides the wow factor of generation I have never really used the feature extensively. I prefer to only design with tools and then I find the coding to go extremely fast once a good design is laid out. I do however like the reverse engineering aspect and think it is a good tool that can give a quick overview of architecture when you inherit a large code base from others.
  10. You could try starUML which can generate UML diagrams based on c++ source files. It seems to do a pretty decent job of coming up with the class dependencies and hierarchy. I have used it a number of times to see the overall layout of the code bases I have had to work with.
  11. What is a good compiler?

    All of the above mentioned IDE's/compilers by jpetrie are free.
  12. school recomendation?

    I am of the same opinion as the others definitely favor a good 4-year accredited computer science degree over a "game development" specific school. Also remember that there are a ton of other jobs out there that are not game programming that you will be qualified for with a true computer science degree. Most people (at least the ones I knew) in computer science had dreams of programming games and they stayed awake all night playing world of warcraft. The reality is that there just is not enough game programming jobs to satisfy the demand. It is a very competitive field and a degree and school alone will probably not be enough to get you there. You have to do some projects on your own, and learn programming technologies on your own time to give you an advantage. At most I would say to employers a degree shows that you have the ability to learn and have the ability to start some difficult and complete it. With all that said I went to Virginia Tech and graduated with a computer engineering degree and the school is great, I learned a lot about programming among other things and would recommend it to anyone.
  13. For this type of system I would say that a collision component would be good to have and it can be used to test for collisions with other entities in the game world. It could probably store the entities bounding box for collision testing. I think audio would also be a nice component to include and it should handle the entities interaction (i.e. request sound load/play) from the audio subsystem. Level loading and end of level celebrations should be handled above the entities possibly by something like the overall game world/application class. The game world should also probably in some way store all the entities created and perhaps store a pointer to a class that handles the event dispatching so the entities can register with the event dispatcher for the messages they are interested in receiving such as user input, game state changes, etc. A scripting component is definitely not necessary for any type of design. It is simply another form of data-driven design and it allows for very dynamic loading and changing of an entities composition and/or actions at runtime. Check this thread where others are discussing the pros/cons of component-based design
  14. You need the typename keyword. template <class T, class NUMERIC=float> class SequenceEvent; template <class T, class NUMERIC=float> class Sequence { typedef std::vector<SequenceEvent<T, NUMERIC> > SequenceContainer; //compiles fine typedef typename std::vector<SequenceEvent<T, NUMERIC> >::iterator SequenceIter; //Compiler Error // typedef std::vector<int>::iterator SequenceIter; //would compile fine.... };
  15. turning a char * into different tokens(c++)

    JohnBolton is right strtok is a dangerous function to use, it has a lot of potential pitfalls that just make it difficult to use. In fact if you are using c++ I would advice against using any c style file reading/parsing (fscanf, sscanf, etc.) and instead use the easier and safer standard c++ iostreams functionality. jyk has given you good advice about using getline and strings to parse the file. You can also use the extraction operator (>>) to grab a token at a time out of the file skipping whitespace and parse the file that way. Bottom line there are better ways to parse/read files in c++ than using c functionality.
  • Advertisement