WYRDYSM GAMES

Home of Battleships Forever
It is currently Thu Oct 19, 2017 5:13 pm

All times are UTC + 8 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
PostPosted: Fri Oct 24, 2008 8:14 am 
Offline
Commander
Commander
User avatar

Joined: Wed Feb 20, 2008 1:59 am
Posts: 214
Location: Canada
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:
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 9:23 am 
Offline
Commodore
Commodore
User avatar

Joined: Fri Jan 18, 2008 2:37 am
Posts: 603
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


Top
 Profile  
 
PostPosted: Fri Oct 24, 2008 9:55 am 
Offline
Moderator
User avatar

Joined: Fri Dec 14, 2007 4:46 am
Posts: 1590
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 10:03 am 
Offline
Commodore
Commodore
User avatar

Joined: Fri Jan 18, 2008 2:37 am
Posts: 603
Using geometry to solve the turret rotation on rotsections.

_________________
Forgetting internet deadlines since 2003


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 10:35 am 
Offline
Moderator
User avatar

Joined: Fri Dec 14, 2007 4:46 am
Posts: 1590
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 10:39 am 
Offline
Commodore
Commodore
User avatar

Joined: Fri Jan 18, 2008 2:37 am
Posts: 603
ffff
Specifically, using the rules of triangles to determine turret rotation.

_________________
Forgetting internet deadlines since 2003


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 10:43 am 
Offline
Moderator
User avatar

Joined: Fri Dec 14, 2007 4:46 am
Posts: 1590
Well, like i said, thats handled by GM itself, or rather, by its functions. No need to delve into proper formulas/calculations for that.


Top
 Profile  
 
PostPosted: Fri Oct 24, 2008 11:18 am 
Offline
Commander
Commander
User avatar

Joined: Wed Feb 20, 2008 1:59 am
Posts: 214
Location: Canada
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#. :|

Quote:
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

Quote:
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.

Quote:
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...

Quote:
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. :|

_________________
Image


Top
 Profile  
 
PostPosted: Sat Oct 25, 2008 1:52 am 
Offline
Moderator
User avatar

Joined: Fri Dec 14, 2007 4:46 am
Posts: 1590
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.


Top
 Profile  
 
PostPosted: Sat Oct 25, 2008 6:23 am 
Offline
Commander
Commander
User avatar

Joined: Wed Feb 20, 2008 1:59 am
Posts: 214
Location: Canada
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.

Quote:
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

Quote:
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.

Quote:
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. :)

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC + 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group