Some suggestions and questions for the programmers

Archive of old Custom Edition threads.

Moderators: th15, Moderators

Locked
Lord-General Thunder
Commander
Commander
Posts: 214
Joined: Wed Feb 20, 2008 1:59 am
Location: Canada

Some suggestions and questions for the programmers

Post by Lord-General Thunder »

First off, when you're working on BSF, are you actually writing procedural code? Are you using trigonometry?

If so, then I have some suggestions that may speed the game up a bit if they haven't already been implemented in some form;

The following is the code for a class that I usually use when I'm writing 2D games. It can be used to describe an object's location and any vectors that are relevant to it. For example, a Hestia's location, velocity, and acceleration could all be described as vectors. You can find the direction that a vector is pointing in using the UnitVector property.

This class makes it easier to work using similar triangles for geometric stuff rather than slow trigonometric functions, which can greatly speed up your algorithm

Code: Select all

class Vector
{
   public float X, Y;
   public float magnitude;

   public Vector(float x_coordinate, float y_coordinate)
   {
      X = x_coordinate;
      Y = y_coordinate;
      updateMagnitude();
   }

   void updateMagnitude()
   {
      magnitude = Math.Sqrt(X * X + Y * Y);
   }

   public static Vector operator +(Vector I, Vector U)
   {
      return new Vector(I.x + U.x, I.y + U.y);
   }
   public static Vector operator -(Vector I, Vector U)
   {
      return new Vector(I.x - U.x, I.y - U.y);
   }
   public static Vector operator *(Vector I, Vector U)
   {
      return new Vector(I.x * U.x, I.y * U.y);
   }
   public static Vector operator *(Vector I, float U)
   {
      return new Vector(I.x * U, I.y * U);
   }
   public static Vector operator /(Vector I, float U)
   {
      return new Vector(I.x / U, I.y / U);
   }

   public static Vector rotate(Vector point, Vector origin, angle turn)
   {
      // Rotates "point" around "origin" by "turn", where "turn" is a multiple of 360 degrees.
      if (turn == 0)
         return point;
      else
      {
         Vector delta = point - origin;

         if (turn > 0)
            point = new Vector(
               delta.x * Math.Cos(turn) - delta.y * Math.Sin(turn), 
               delta.x * Math.Sin(turn) + delta.y * Math.Cos(turn)
            );
         else if (turn < 0)
            point = new Vector(
               delta.x * Math.Cos(turn) + delta.y * Math.Sin(turn), 
               delta.y * Math.Cos(turn) - delta.x * Math.Sin(turn)
            );
         updateMagnitude();
         return point + delta;
      }
   }

   public Vector toUnitVector
   {
      return new Vector(X / Math.Max(X, Y), Y / Math.Max(X, Y)); 
   }
}
Hope you find that helpful.
[img]http://i30.photobucket.com/albums/c348/DraTuicichNovae/BLANKcopy-6.jpg[/img]
BoVinE
Commodore
Commodore
Posts: 603
Joined: Fri Jan 18, 2008 2:37 am

Post by BoVinE »

I don't know what they're using, but when I tried pointing this out to Kaelis for rotsections, he said it was different. Probably th15's 'fault'.
Forgetting internet deadlines since 2003
Kaelis
Moderator
Posts: 1590
Joined: Fri Dec 14, 2007 4:46 am

Re: Some suggestions and questions for the programmers

Post by Kaelis »

Lord-General Thunder wrote:First off, when you're working on BSF, are you actually writing procedural code? Are you using trigonometry?
Both. Depends on the case.
Lord-General Thunder wrote:If so, then I have some suggestions that may speed the game up a bit if they haven't already been implemented in some form;
Uh... you say it 'may speed the game up a bit', 'can greatly speed up your algorithm' (algorithm? and MY algorithm?), yet from the rest of your post its apparent you didnt even see the source.
Lord-General Thunder wrote:The following is the code for a class that I usually use when I'm writing 2D games. It can be used to describe an object's location and any vectors that are relevant to it. For example, a Hestia's location, velocity, and acceleration could all be described as vectors. You can find the direction that a vector is pointing in using the UnitVector property.

This class makes it easier to work using similar triangles for geometric stuff rather than slow trigonometric functions, which can greatly speed up your algorithm
I think theres a big misconception you have here. BSF is made in GameMaker, which is basically a game engine. There is a scripting/programming language, but its much, much higher level than you seem to think. Everything youve done in that code block is handled in GM by one, maybe two functions. Handling vectors rotation around points etc is absolute basics where it comes to complete game engines. Noone expects you to do that 'by hand', there are functions for it instead.

But even disregarding that, why would i want to rewrite a significant part of BSF to implement something that is completely unnecessary? Where did you get the impression that its the vector calculations that slows down BSF?



Concluding, while i appreciate your effort and intentions, id prefer if the next time around you actually check whats going on and get some background info.


BoVinE wrote:I don't know what they're using, but when I tried pointing this out to Kaelis for rotsections, he said it was different. Probably th15's 'fault'.
You know what were using. Were using GM =|
And i don't really remember you pointing this out to me, whatever 'this' refers to. Pointing out what? Whats different, whats th15's fault?

If you mean pointing out to me that there are ready-made solutions for trig and vector calc, then im sure i didnt respond in the way you imply. Because that would be retarded.
BoVinE
Commodore
Commodore
Posts: 603
Joined: Fri Jan 18, 2008 2:37 am

Post by BoVinE »

Using geometry to solve the turret rotation on rotsections.
Forgetting internet deadlines since 2003
Kaelis
Moderator
Posts: 1590
Joined: Fri Dec 14, 2007 4:46 am

Post by Kaelis »

Now im certain i didnt tell you its different or th15s fault. You must have misunderstood me. Because theres no other way to 'solve' it than to use geometry.
BoVinE
Commodore
Commodore
Posts: 603
Joined: Fri Jan 18, 2008 2:37 am

Post by BoVinE »

ffff
Specifically, using the rules of triangles to determine turret rotation.
Forgetting internet deadlines since 2003
Kaelis
Moderator
Posts: 1590
Joined: Fri Dec 14, 2007 4:46 am

Post by Kaelis »

Well, like i said, thats handled by GM itself, or rather, by its functions. No need to delve into proper formulas/calculations for that.
Lord-General Thunder
Commander
Commander
Posts: 214
Joined: Wed Feb 20, 2008 1:59 am
Location: Canada

Re: Some suggestions and questions for the programmers

Post by Lord-General Thunder »

Kaelis wrote:
Lord-General Thunder wrote:If so, then I have some suggestions that may speed the game up a bit if they haven't already been implemented in some form;
Uh... you say it 'may speed the game up a bit', 'can greatly speed up your algorithm' (algorithm? and MY algorithm?), yet from the rest of your post its apparent you didnt even see the source.
It wasn't meant as a knock... :?

I think it would be blatantly obvious that I haven't seen the source. If I'd seen the source, I'd have written in whatever language GameMaker uses instead of C#. :|
Lord-General Thunder wrote:The following is the code for a class that I usually use when I'm writing 2D games. It can be used to describe an object's location and any vectors that are relevant to it. For example, a Hestia's location, velocity, and acceleration could all be described as vectors. You can find the direction that a vector is pointing in using the UnitVector property.

This class makes it easier to work using similar triangles for geometric stuff rather than slow trigonometric functions, which can greatly speed up your algorithm
I think theres a big misconception you have here.
Yes, your reaction would seem to indicate as much... :P
BSF is made in GameMaker, which is basically a game engine. There is a scripting/programming language, but its much, much higher level than you seem to think. Everything youve done in that code block is handled in GM by one, maybe two functions. Handling vectors rotation around points etc is absolute basics where it comes to complete game engines. Noone expects you to do that 'by hand', there are functions for it instead.
Ah. Didn't know that.
But even disregarding that, why would i want to rewrite a significant part of BSF to implement something that is completely unnecessary? Where did you get the impression that its the vector calculations that slows down BSF?
Always seems to be the slowdown in my code. I figured that th15 had to write it from scratch, and would thus encounter the same problems I did when I started...
Concluding, while i appreciate your effort and intentions, id prefer if the next time around you actually check whats going on and get some background info.
Sure, if you'll let me. I mentioned wanting to see the code in IRC and nobody even acknowledged me. :|
[img]http://i30.photobucket.com/albums/c348/DraTuicichNovae/BLANKcopy-6.jpg[/img]
Kaelis
Moderator
Posts: 1590
Joined: Fri Dec 14, 2007 4:46 am

Re: Some suggestions and questions for the programmers

Post by Kaelis »

Lord-General Thunder wrote:I think it would be blatantly obvious that I haven't seen the source. If I'd seen the source, I'd have written in whatever language GameMaker uses instead of C#. :|
No, if you had seen the code, you wouldnt bother with this stuff at all, since you would see that there are functions for that built into GM =P
Lord-General Thunder wrote:Always seems to be the slowdown in my code.
Well, then let me tell you this - something is wrong with your code. Im a c++ coder myself, and i had no problems implementing this myself in another project of mine. No slowdowns whatsoever.

And then, there are libraries for 2d math. If you can't get your own 2d math implementations to work, use those. Whats the point of writing something from scratch if someone already did it, anyway?
Lord-General Thunder wrote:Sure, if you'll let me. I mentioned wanting to see the code in IRC and nobody even acknowledged me. :|
Ah, i see. Sent you PM with a link.
Lord-General Thunder
Commander
Commander
Posts: 214
Joined: Wed Feb 20, 2008 1:59 am
Location: Canada

Re: Some suggestions and questions for the programmers

Post by Lord-General Thunder »

Kaelis wrote:
Lord-General Thunder wrote:I think it would be blatantly obvious that I haven't seen the source. If I'd seen the source, I'd have written in whatever language GameMaker uses instead of C#. :|
No, if you had seen the code, you wouldnt bother with this stuff at all, since you would see that there are functions for that built into GM =P
Point. I probably would've tried to improve something else, though. Dunno. Maybe I'd be in over my head.
Lord-General Thunder wrote:Always seems to be the slowdown in my code.
Well, then let me tell you this - something is wrong with your code. Im a c++ coder myself, and i had no problems implementing this myself in another project of mine. No slowdowns whatsoever.
Well, that said, I suppose that it's entirely possible that it wasn't the trig... XD
And then, there are libraries for 2d math. If you can't get your own 2d math implementations to work, use those. Whats the point of writing something from scratch if someone already did it, anyway?
Also true. I'm just used to having to do things from scratch.

I'm only in my second year at U of T, after all.
Lord-General Thunder wrote:Sure, if you'll let me. I mentioned wanting to see the code in IRC and nobody even acknowledged me. :|
Ah, i see. Sent you PM with a link.
Thanks. I'll check it out tonight. :)
[img]http://i30.photobucket.com/albums/c348/DraTuicichNovae/BLANKcopy-6.jpg[/img]
Locked