Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 18 May 2011
Offline Last Active Today, 03:40 PM

Posts I've Made

In Topic: Projectiles in a video game

22 January 2015 - 12:00 AM

As Nypyren linked, it's really good to use an object pool. Projectiles and particle systems can create lots of short-lifetime objects that are constantly going in and out of existence. Dynamic memory allocation is actually pretty expensive compared to logic and math. It takes time for the requested memory to be allocated and handed back to you, and over time lots of dynamic memory allocation can cause memory fragmentation. Fragmented memory slows things down because memory relevant to an algorithm is spread out through the memory in random locations. It is faster to read through contiguous memory in a straight line, or nearby memory, than to jump around between random memory addresses. Pool allocation is awesome for cache coherency because you can allocate the space for many objects at one time, which puts them close together in memory. It's faster than dynamic allocation because your pool can immediately hand you back an object that was already allocated. Memory allocators are a pretty fun topic with a lot of internet resources.

The best idea would be to write a pool to hold your projectiles. When a bullet is shot you grab an object from the pool, and when it hits something you return that object to the pool to be reused later. Done correctly there will be no allocation/deallocation to slow the processing of your bullets down.

In Topic: How do triangle strips improve cache coherency ?

04 November 2014 - 09:41 AM


They improve cache coherency by reading straight through the vertex buffer. There are a minimized number of cache-misses because it's reading through the vertex buffer memory in a straight line. Every triangle after the first one only needs to read in one additional vertex (the next vertex in the vertex buffer) to form a full triangle. When you index vertices you are potentially jumping between random vertex locations anywhere inside the vertex buffer memory depending on how the mesh verts are connected.

In Topic: What is a lobby server?

30 October 2014 - 01:20 PM

Don't forget about RakNet either! It was just open sourced with a BSD license after Oculus bought it. It takes care of a lot of networking stuff including packet priority/reliability, data-replication across client/server, events, and it all uses a nice "TCP-over-UDP" algorithm that keeps things fast. It can also communicate between 32/64 bit clients/servers with no issue. It's a pretty mature library.


It is only free on computers, however. It will cost you money if you want to branch into consoles.

In Topic: "Expanding" a bezier curve to a "pipe"

29 October 2014 - 03:16 PM

Off the top of my head I would probably try to generate circles that can be connected/triangulated together to define the cylinders for the pipes.


To generate one of the circles I would sample two positions on the curve; one to get the point where the circle sits around, and then another one a small increment forward on the curve. Then subtract the second from the first and normalize to get a forward vector to orient the circle. Then use some cross products to get curve oriented up/right vectors from the forward vector. Then with cylinder right/up vectors you can generate a circle of points in 2D (that you would probably just re-use), and then multiply the XY of those points by the right/up vectors for oriented circle.


After you generate several of the oriented-circles to outline the shape of the pipe, you can figure out a triangulation to connect together two of the oriented circles into a pipe.

The geometry will probably act weird if the pipes take sharp turns. Also you will have to triangulate the two endpoint circles so the pipe isn't open-ended.


If you want to generate a half-pipe you can design an outline of the half-pipe shape and then do the same steps as with the circle. Multiplying those 2D shape-outline coords by the oriented-bezier axis' will orient them along the curve. This is pretty much like an extrusion.


You might could just search for a shape extrusion algorithm, actually.

In Topic: Quick Multitexturing Question - Why is it necessary here to divide by the num...

21 August 2014 - 08:01 PM

Also, don't let color averaging stop you there with texture blending!

If you use a linear interpolation you can blend any amount of a texture into another. With a lerp you can blend more or less of a texture in to taste as long as the interpolate value is between 0 and 1.

vec3 red = vec3(1,0,0);
vec3 black = vec3(0,0,0);
vec3 mixedColor = mix(red, black, 0.25);

// This gives you 75% Red and 25% Black.

Another cool application is smooth texture blending. You can use color lerping on outdoor terrain to seamlessly blend different textures together, like grass and dirt, in irregular ways that break up the texture on a mesh so that it isn't solid. You give different vertices on a mesh different lerp parameters, and vertex interpolation will give you all of the interpolation values in between so it fades from one blend percentage to the other. Check out the screenshot of the day and notice the texture blending on the ground in the back. http://www.gamedev.net/page/showdown/view.html/_/slush-games-r46850


Texture blending is pretty handy.