Jump to content
  • Advertisement

Brum87

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

156 Neutral

About Brum87

  • Rank
    Newbie

Personal Information

  • Interests
    Design
    Programming
  1. Brum87

    Writing 'floats' to a file

      I didn't realise that was this distinction in std::streams. A very short look through some online material verifies this response. I now think what I said before is not a great idea for working with binary data. What I was trying to get at in my post is the use of the raw char[] and the overcomplicated maths for indexing the array. You are probably doing it this way for speed. Using the original method I can see 2 allocs and the maths looks like an attempt to improve cache coherency.   For this particular case then, given what i have learnt about << operator, using std::stream's and aiming for simplicity, I would forget buffering up the data in raw char[]'s just use ostream.write for each element. If you want to get the speed back from creating a buffer then a custom buffer class like Irlan's would be the way I would go with it. Its the number of allocations which is going to be slow but the code is so much simpler.    I find this a very interesting topic.   I see there are a lot of different opinions on this topic with regard to std::stream's, operator misuse, code comprehension practice e.t.c. Personally I see the << and >> operators as general stream operators and thinking of them as such is a very clean way of conveying the transformation. The important factor is the target. Given what you have said about std::stream's I agree a binary_stream class would be one way to solve it without ambiguity. I like this because the target describes the method formatting applied to source data and ensures that all data pushed to the same target is formatted based on the correct scheme. It would be very strange to have some types formatted one way and other types formatted another way. 
  2. Brum87

    Writing 'floats' to a file

    I don't think the use of char is the problem. Endian shouldn't make a difference if you are writing and reading on the same platform but something to be aware of. For simplicity I would skip the 'new' buffer you have there just use the streams. Why alloc twice if you don't have to?   As you are using streams I would recommend overloading the << streams operator: std::ostream& operator <<(std::ostream&, const <yourtype>&){ //your implementation here } The code will simply become something like for (const <yourtype>& item : face) {     myfile << item; } I don't think using streams will produce the fastest code but I like that way the code fits together. The technique can be used for all types and makes everything simpler if a lot of the code looks the same.   More details here: http://www.cplusplus.com/reference/ostream/ostream/ http://stackoverflow.com/questions/476272/how-to-properly-overload-the-operator-for-an-ostream
  3. Brum87

    Question about Projectile Motion

      Hi sorry for the delay.    It's the same quadratic that you have in your original equation. Sorry I may have been confusing with my previous answer. You still have to use atan to get Theta but you can tell a lot about the answer using the quadratic part. I found that understanding how the solution resolves lets you deal with the failure conditions in a cleaner way.   For example I wrote a version of this function which wouldn't fail if the solution was further than my max range, so in that case it would return theta for the max range. For this specific case it made sense because the AI part of the problem had already decided to fire the gun but the character trying to actually perform the action of "firing a gun" couldn't reach.. but up until that moment he thought he could... 
  4. Brum87

    DLL or Static Library

      This is a good point... and probably more important to keeping compile times low than using a dynamic or static lib config. I see pro-coders do this and it bugs me. I think people coming over from C# or Java tend to be the culprits.   ...As a general rule, if a class is referenced in a header as a pointer or reference type then you don't need to include the header file with the declaration for the type. A simple forward declare is enough.   i.e. the following example would be found in header files... //header includes class CForwardDeclared; //class declarations + codes or you can do it in the code. (i personally like to do it this way) class CSomeClass { public:      CSomeClass(const class CSomeConstDataOrSomething& InData);      const class CSomeConstDataOrSomething& Data;     void SomeFunction(class CSomeOtherClass* ptr); }; Same goes for template instantiation parameters TWeakPtr<class CSomeClass> SomeClassPointer; This also means that changes to the header files wont dirty any unecussary TU's which will just result in less compiling generally.  ... but this will not help with linker times, so still better to use DLL's as well anyway.
  5. Brum87

    Question about Projectile Motion

      I see what you are doing with your method... While it might be good for what you are doing, I can see that there are two reasons why it may lead to an inaccurate targeting calculation.   The most important reason is that as the firing angle changes the velocity in the X changes, which means that the time (distance to target in frames) will change also. For fast moving projectiles over a shortish distance I don't suppose you will see this as a problem... but over a long range or slow moving projectiles this may be an issue. All projectiles will fall short of the target point by some margin using this method.   The second which is more an game engineering thing than a maths thing, is using number of frame in your calculation is just a substitution for time. If you change it to be time then your method will produce more similar results in a variable-frame rate world when compared to a fixed-frame rate world. As it stands your method may be very incorrect when using a variable-frame rate.     This relates more to lead targeting which is how far ahead do I need to aim in order to hit them. I have been finding this quite difficult to figure out the maths using a parabolic, though I'm sure an analytical solution exists. It would be awesome to learn the answer if anyone on here knows how to do it. The problem is the same as I described above (as the angle changes so does the flight time) ...In the meantime I'm getting reasonably accurate results using a linear lead target calculation. that is another quadratic calculation using these parameters:   double a = target_velocity^2 - projectile_velocity^2; double b = vector_dot_product( target_velocity_vector, target_position_vector - launch_position_vector ) * 2.0; double c = relative_distance ^ 2;   if there is a solution the result is given in time, so the lead is approx:   target_position_vector + target_velocity_vector * time   another reason to make a quadratic solver function. In this case there are also often 2 solutions, you want the smallest.
  6. Brum87

    Question about Projectile Motion

    a good summary of the maths can be found here - http://hyperphysics.phy-astr.gsu.edu/Hbase/traj.html#tra12
  7. Brum87

    Question about Projectile Motion

    The atan is correct for getting the angle...   You may be getting problems when you solve the quadratic... and in practice the quadratic solution tells you a lot about the solution here.   The quadratic itself can result in 3 cases:    *there are two solutions, one often the one you want and another which is a high angle solution.    *there is one solution which means you are firing your projectile from exactly the furthest location where hitting the target is possible.    *there are no solutions, the target is out of range.   I have a few functions to solve this in my code base depending on my needs. Using your terminology it would be something like this:    * double getBestAngleToHit(...)    * double getAlternateAngleToHit(...) //you may want to return a bool for if it can hit or not and get the angle with a refernce parameter    * bool   getBothAngleToHit(double& best, double& alt, ...)   The way I like to solve this is take the quadratic and pass in the parameters as follows -    double a = ( gravity * relative_distance^2 / velocity^2 ) * 0.5; double b = -relative_distance; double c = a + relative_height;   ...then I use various solvers depending on the function. In this case something like...   bool solveQuadraticMinimum(double a, double b, double c, double& theta); //getting shortest solution  bool solveQuadraticMaximum(double a, double b, double c, double& theta); //getting highest arc solution bool solveQuadratic(double a, double b, double c, double& theta1, double& theta2); //getting both...
  8. Brum87

    DLL or Static Library

      Sorry I think I misrepresented what I was trying to say. My point being that loading the resources in a moderate size game project can be a reason for slow iteration times. One way I've got my iteration times down was to separate the light weight gameplay code into a separate DLL and only recompile and reload that part. I leave the resource manager running the whole time so it doesn't have to reload resources. This a quick way and pretty straight forward way of getting a "hot reload" working... I don't know how you would get hot-reload using static libs.         Even without a hot reload, iteration is quicker with dlls.   I have the same problems with link times in static link mode, so I rarely build those... but I like to keep them working so that I can use it as an optimised release build (with all the bells an whistles, LTCG e.t.c) I automate this using a TeamCity server, which is free and simple to setup in-case you are interested.
  9. Brum87

    DLL or Static Library

    I would advise not to give up on using DLL's. They are tricky at first and there is a bit of learning curve... but once you start loading large amounts of data (textures, levels, audio).. your iteration times will go down. Using DLL's you can spread your project into more manageable chucks and if you are feeling adventurous you get get a simple hot-reload type system working to improve your iteration times.   Take a look at these resources if you are interested in finding out more + some good example codes:  http://runtimecompiledcplusplus.blogspot.com/ https://handmadehero.org/ http://www.3dgep.com/using-dynamic-link-libraries-dll-to-create-plug-ins/
  • 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!