Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

533 Good

About _for_science

  • Rank

Personal Information

  • Interests
  1. Of course, you could go all fancy and generate these unique class IDs automatically using template magic! *Applause* You want to write your classes, and you don't want to manually assign a unique id to each one of them. Luckily you can make your compiler do the class counting. First you'll need a Base class with a static variable that counts your classes: class Base { public: // Virtual function to get the unique class id (special number) virtual int getUniqueClassId(void) const = 0; private: // This static variable counts your classes (it exists exactly once in the entire program) static int uid_count; }; Next you'll need a "SpecialBase" class. A class that exists between your actual class and your base class. Via template magic, this class will automatically do the counting for you. In order for this to work, we use a basic template feature. Your compiler does not consider a class with template parameter a single class. SpecialBase<A> and SpecialBase<B> are considered completely separate classes that just happen to use the same code. So if your SpecialBase class were to have a static variable, that variable would be created once for each specialized class you use in your program. You can use that to create the following: template <class SpecialClass> class SpecialBase : public Base { public: // This function gives you the unique class id of an object int getUniqueClassId(void) const { return getUniqueClassIdStatic(); } // This function gives you the unique class id static int getUniqueClassIdStatic(void) { if (uid >= Base::uid_count) // If the unique id is invalid... uid = Base::uid_count++; // ... set the id and increment uid_count return uid; } private: // This static variable is your classes unique id (it exists once for // each of your classes) static int uid; }; // Initialize the unique id to an invalid value template <class SpecialClass> int SpecialBase<SpecialClass>::uid = INT_MAX; There now exists a static uid variable for each variation of the SpecialBase class and they are all initialized to INT_MAX. The first time anyone asks for the unique class id (by calling getUniqueClassId(), or getUniqueClassIdStatic(), a new unique id is created, based on the current uid_count we defined earlier in the Base class. The counter of the Base class (the one that exists only once in the entire program) is then incremented. Therefore, the next class that asks will automatically get a new and unique id. Keep in mind though: The order the ids are given out is based on the order they are first queried at runtime (see below for more info). Oh and in some .cpp file somewhere you'll obviously want to initialize uid_count to zero: #include "Base.h" // Initialize the unique id count to 0 int Base::uid_count = 0; How is this actually used? // Define your classes (yep, that's all) class A : public SpecialBase<A> { }; class B : public SpecialBase<B> { }; class C : public SpecialBase<C> { }; // Determine an object's class: C obj; if (obj.getUniqueId() == A::getUniqueIdStatic()) // false std::cout << "Object is of class A"; if (obj.getUniqueId() == B::getUniqueIdStatic()) // false std::cout << "Object is of class B"; if (obj.getUniqueId() == C::getUniqueIdStatic()) // true std::cout << "Object is of class C"; Note that you won't have to touch the getUniqueClassId() functions in your own code. All you have to do, is make sure that your class inherits from SpecialBase and that you use your own classes name as the template parameter. (Thus ensuring that no two classes inherit from the same specialization of SpecialBase) Oh, but I wanted control over which class gets which index, or at least some kind of order! Just forcibly query some ids, before doing anything else... int main(void) { A::getUniqueClassIdStatic(); // A is assigned 0 C::getUniqueClassIdStatic(); // C is assigned 1 B::getUniqueClassIdStatic(); // B is assigned 2 F::getUniqueClassIdStatic(); // F is assigned 3 // your stuff... } I hope this helps! Depending on your project, this may be a little much. It just happened to be what I was working on recently. (And you could probably take this even further by using enums instead of static variables... but I'll just doubt that you have several million classes for these few static vars to create any performance issue)
  2. _for_science


      Ok, this makes a lot more sense then. You could perhaps reflect Erderra's volcanic origins in the description. The myth simply states that "a ball of rock appeared" and I naturally assumed that to be granite or something. If, for example, a flame had appeared and out of it the black rock that would become Erderra, then the intended origin would have been a lot clearer.     Again, I naturally assumed that everything but the Monsterra would be similar (in some form) to our known world.   As I think about it, this is an important point to writing your creation myth: The reader should probably already know what is being created. That is after all, the way actual creation myths come about. People observe their world and then begin to speculate - trying to deduce how everything came about. If the world you are creating is not our own, then it would probably help to first establish how exactly this world is different, and use your creation myth to specifically explain those differences. That way, when we read the creation myth, everytime that we would naturally have a reaction like: "the order of these events seems all wrong", we can immediately understand "and THAT's why THIS is different in his world".
  3. _for_science


        Quote     Zeitlineal, ruler of Time I think I see what you were going for here, but I'm not sure the name means what you think it means. The german does translate to "ruler of time", but with the "ruler" being the measuring instrument, rather than the regent. The name just looks really off... Regarding the creation myth itself: The myth, as it is presented, is fairly generic, with the different Spirits doing their respective thing. Feels like there are already many variations of this around, so you may have to look into ways to make your own approach a little more interesting.   My first suggestion would be making the creation a little more condensed: Arknell (Monsterra) creates Zeitlineal (Time) and Espace (Space) Time and Space are created. from Zeitlineal and Espace spring Erderra (Earth), Aqcuasser (Water), Aeridon (Air) and Vita (Life). Earth, Water, Air and Life are created. I like that you try to add personality to your mythical Monsterra. That's something that you could expand upon. I was rather surprised to see earth being the impatient one. In my mind earth carries rather stoic properties. I would have naturally assumed air or life to be more impatient. I would also have assumed life to be the last thing created, as it requires the other elements to exist.   Reading your description I imagined Arknell as a grandfatherly figure, and Zeitlineal and Espace being the parents to four bickering siblings. I like the rivalry between earth and water, and would like to see air and maybe life added to that mix. Life would also make for a prime candidate for "being punished for impatience" (again, it would make sense if it were created last). Its punishment could have been to constantly having to renew itself, thus explaining the entire life/death thing.
  4. _for_science

    A stealth weapon that's never been done before

    Wait, isn't that the opposite of how a boomerang is supposed to work? I like the idea of simple rocks in a zombie survival scenario. Ammo conservation is an important aspect of survival and rocks are not only plentiful but also highly reusable. How about small throwable rocks or bricks? You hit an enemy and there's a (mostly silent) squishy impact. If you miss, the rock/brick causes considerably more noise (depending on the surface it lands on?). However, the noise originates from the point of impact. That way rocks can not only be used as stealthy weapons, but also to create diversions.
  5. _for_science

    Realitive size in games

    I'm not aware of any definitive standards, AFAIK it's just an arbitrary scale that has to be set depending on the project. You usually want your grid to map to a real-life unit of measurement (imperial/metric), while also keeping your floating point values from growing too high. There are workarounds for the floating point issue, but sticking to a scale in which you can rely on accuracy is always simpler. A large-scale RTS may use a scale of .1 = 1 kilometer, while an FPS may use .1 = 1meter (I just made those numbers up, so don't quote me there). It depends somewhat on the scale of what you want to display, but mostly on personal preference. As for the size difference between projects, you can always just scale your models accordingly. It's important to keep in mind that all these values are purely relative.
  6. _for_science

    Why do most FPS games have 2 teams?

    That is definitely part of it, but wouldn't that statement be true for any number of teams? A related question: Why do most (all?) sports have only two teams? (Is there a competitive sport with more than two teams at the same time? Really, I'm not a sports person at all.) I believe having only two teams is the easiest way to determine a fair winner/loser. Consider for example a match between three teams A,B,C. Team A may be objectively "better" at playing the game than either Team B or Team C and would dominate either in a one-on-one match. However, in this scenario Team B and C could gang up on Team A (knowingly or by coincidence) and thus deafeat A. This is usually not what you want for ranked competitions. Now, I'm not saying that having more than two teams isn't an interesting mechanic - it adds a tactical layer to the game and may work well, if properly implemented. I'm not that interested in the whole "games as sports/competitions" aspect anyway and would enjoy a chaotic four team FPS extravaganza. However, for the above mentioned reasons, it's probably easier/safer for developers to stick with the proven one-on-one model, especially considering the (usually more competitive) FPS audience.
  7. _for_science

    Transforming an ellipsoid

    Going by your definition, your ellipsoids are always axis-aligned (since the radii are always assumed to be along the x,y,z axes). If this is intentional, and all you want to use your transformation matrix for is translation and scaling, then it would be sufficient to multiply your center vector with the translation column of your matrix and your axial radii vector with the matrix diagonal. You wouldn't even need a matrix, just a translation- and a scale-vector. However, if you want to be able to rotate your ellipsoids, then you will probably have to refactor your definition to allow non-axis-aligned ellipsoids...
  8. _for_science

    1D Gaussian Kernel

    What you have there is the gaussian probability density function, centered (median) at x=0, which should work fine for calculating a filter kernel.
  9. _for_science

    reflexion in 2D

    haven't had time to fact check, but going by memory this looks about right.
  10. _for_science

    Find point along vector direction

    what japro said. Depending on the orientation of your direction vector w you'll end up at either point p1 or point p2, with where |w| is the length of your vector w. Since you can go along the direction vector w in either orientation, both p1 and p2 are points at a distance n from A. p2 is the point you describe in your sketch (against the orientation of w, hence the minus).
  11. _for_science

    normals and how to filter them?

    I can't say I fully understand what you're doing either, but from what I can gather you have a shape with normals at sampled positions and want to find the "floor" of this shape by finding all "floor normals"? What exactly do you use to filter these normals? Only one reference vector (1,0,0) (which is on the plane)? In this case there would of course be more than just the "floor vectors" ~(0,0,1), but also some of the wall vectors ~(0,1,0) that have 90 degree angles to that reference vector. If that is the problem, consider using the floor normal (0,0,1) and try to find all vectors that differ in angle by less than 10 degrees that should be less ambiguous. If that's not it, we really need some algorithm or visualization of your what you're doing in order to help =).
  12. _for_science

    The Immortal Ruler

    There was an old german computer game (late 80's? "Hanse"?) that had the player as a merchant in the time of the Hanseatic league. The player character would age over time. Part of the game (besides making money) involved getting married and raising children (all done very crudely of course, but the general concepts were there). IIRC you could then go on and get your daughters married for money, or send your children off to dangerous expeditions (that could either open up new harbors for you to trade with... or get them killed). At some point in the game the character you controlled would die (of old age or disease) , at which point the player chose one of the remaining children to "inherit" the family business (taking control of that character instead). The game ended when there was noone left to inherit the family business (this could happen fairly quickly when you ran the business into the ground and you and your family ended up dying from all kinds of diseases) I always liked that concept and think it could open up all kinds of new dimensions to 4x games. Especially thinking about getting your offspring married to all kinds of foreign leaders to promote stable relations (as was historically often the case). You could even go so far as to add "RPG elements" (which are popular these days) where not only your current "Leader"-character has specific stats, but also your offspring. You could then have them gain xp by going on some dangerous errands that might either benefit you greatly, or put your lineage in jeopardy. So yeah, I think there's potential there and I really enjoyed your ideas so far.
  • 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!