Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

Scourage

Member Since 29 Jan 2000
Offline Last Active Yesterday, 06:44 PM
-----

#5051985 Windowed Mode Using C++ & Free GLUT ....

Posted by Scourage on 10 April 2013 - 07:02 PM

Do you have to use FreeGLUT?  Why not pick something more recent (i.e have been developed on in the last 10 years), like GLFW or SFML? 

 

Cheers, 

 

Bob




#5033105 2D Rendering Engine Architecture

Posted by Scourage on 16 February 2013 - 12:37 PM

I would start by thinking of all the abstractions you want from a high level.   Then think of the abstractions required to support those, and keep working your way down until you're hitting OpenGL.  

 

I would think for a 2D engine, you would need the concept of a layers.  Background and foreground layers.  I would guess they need to be z sorted as well.  The layers are probably bigger than the screen, so they need some dimensions, and they might need to rotate, so a layer would need a rotation parameter.  You probably want to have sprites be on the layers, so layers need to have a list of sprites and where to put them (sprite position might be part of the sprite).  You probably need some kind of container for the layers to keep them in the right order for rendering (although simply sorting the list of layers every time you render probably won't show up in a profiler).

 

Sprites probably contain some kind of graphic, a position, scale, rotation.  If its animated, it might contain an animation time, looping variable, and a list of graphics to animate between. 

 

Your renderer might take a list of layers, sort them, then iterate over each layers sprites, rendering the graphic for each one.  Try to keep each object you design have one and only one job.

 

Hope this gets you thinking in the right direction. 

 

cheers, 

 

Bob




#5009498 Game Component Architecture

Posted by Scourage on 11 December 2012 - 12:50 PM

What I think you are talking about is parameter driven models (or components). If you want to have a bunch of zombies each with different health values, they all have a health capability, just with different initial values. Same thing with size, speed, aggression, etc.

My system (also a zombie game) uses this approach. In my entity definitions (which are lua scripts) I allow for functions to be used for initialization data, which then return randomized values (within a valid range) each time a zombie is created. This gives various types of zombies, some harder to kill than others with the same game object model and initialization script.

Here's my initialization script for a zombie:

[source lang="cpp"]ENTITY{ type="zombie"; inherits="baseEntity"; attributes= { type={type="string", value="zombie"}; state={type="string", value="wander"}; }; behaviors= { RenderBehavior = { model="../data/models/zombie/zombie.ms3d"; texture="../data/models/zombie/zombie.jpg"; scale={0.2, 0.2, 0.2}; --scale={1.0, 1.0, 1.0}; translate={0.0, 0.0, 0.0}; rotate={0.0, 0.0, 0.0}; animated=true; }; AnimationBehavior= { animations={ {name="walk1", start=2, finish=20, fps=24, loop=true}, {name="walk2", start=22, finish=36, fps=24, loop=true}, {name="damage1", start=38, finish=47, fps=24, loop=false}, {name="damage2", start=48, finish=57, fps=24, loop=false}, {name="fall", start=59, finish=75, fps=24, loop=false}, {name="prone", start=78, finish=88, fps=24, loop=false}, {name="die", start=91, finish=103, fps=24, loop=false}, {name="kick", start=106, finish=115, fps=24, loop=false}, {name="punch", start=116, finish=128, fps=24, loop=false}, {name="headbutt", start=129, finish=136, fps=24, loop=false}, {name="idle1", start=137, finish=169, fps=24, loop=true}, {name="idel2", start=170, finish=200, fps=24, loop=true} } }; CollisionBehavior= { radius=1.0; }; ScriptBehavior= { script="zombieAI.cs" }; AudioBehavior= { sounds={"../data/audio/zombie-brains1.wav", "../data/audio/zombie-brains2.wav", "../data/audio/zombie-brains3.wav", "../data/audio/zombie-moan.wav", "../data/audio/zombie-gurgle.wav"}, period=10 }; SenseBehavior= { range=function() return math.random(200,500) end; acceptTypes={"player"}; }; DamageBehavior= { health=function() return math.random(25,75); end; }; }; reflected= { "RenderBehavior", "AudioBehavior", "AnimationBehavior", };}[/SOURCE]


#5008798 archtitecture with callback

Posted by Scourage on 09 December 2012 - 08:47 AM

In GLUT there is a glutPostRedisplay() function that will redraw the screen for you. I'm not sure that this will pump any user inputs (as it would in GLFW), but it may. When you get a new caputure frame, update your PBO and then then call the postRedisplay() function to ask GLUT to redraw the screen.

GLUT and FreeGLUT are pretty old. I recommend GLFW as well (full disclosure: I've contributed to it in the past). It's a great windowing framework and gives you the primitives to build your own loop around.

Cheers,

Bob


#4999888 [Pong] Debugging Ball Movement

Posted by Scourage on 11 November 2012 - 07:03 AM

I had a similar problem that only showed up when I was debugging. Its because the game timer is working off of real wall-clock time and when you pause, the timer is still going. You can can fix it by making your timer send fixed increments or looking for exceptionally large values and capping them at a normal amount. In my system, any frame times > 200ms was considered a significant lag and a 16ms was returned as the frame time. This helped me debug things as though there were happening at a normal rate, while I took my sweet time figuring out my bugs in the debugger.

Cheers,

Bob


#4999643 Item system - design patterns

Posted by Scourage on 10 November 2012 - 08:26 AM

I'd recommend an effect class that the item class has a pointer to. The effect class is the base class for all the different kinds of desired effects. You could have a list of effects in the item class instead of a single pointer to chain effects together, but that might complicate things. Either way, separate the effect from the item and make the interface for enabling the effect generic so it can be enabled in a consistent manner.

Cheers,

Bob


#4861334 Game 'Resource Manager' Design

Posted by Scourage on 13 September 2011 - 07:09 PM

They way I designed my resource manager is similar to rip-off and SpeciesUnknown have done. I have a ResourceDescriptor, Resource, and ResourceManager. The ResourceManager maintains a list of resources that have already been loaded. When you want something, create a ResourceDescriptor and use it to ask theResourceManager for the resource. If the resource doesn't exist yet, the ResourceManager uses the ResourceDescriptor to do the actual load of the resource. It's a kind of double dispatch pattern to get the resource specific loading behavior.

The nice thing about this is that the ResourceManager doesn't need to know how to load the specific types of resources since it's the resource descriptor that handles that. The resource manager probably should have some memory tracking functions and priority system, but I haven't needed them yet.


Below is how I implemented my ResourceManager, ResourceDescriptors and a texture resource descriptor in C#.


Cheers,

Bob



using System;
using System.Collections.Generic;

namespace SimEngine
{
   public static class ResourceManager
   {
      static Dictionary<String, IResource> myResources;

      static ResourceManager()
      {
 		myResources = new Dictionary<String, IResource>();
      }

      public static bool init(Initializer init)
      {
 		return true;
      }

      public static IResource getResource(ResourceDescriptor desc)
      {
 		IResource res;
 		if (myResources.TryGetValue(desc.filename, out res))
 		{
            return res;
 		}

 		//need to try and load the IResource here
 		res = load(desc);

 		return res;
      }

      static IResource load(ResourceDescriptor desc)
      {
 		IResource res;

 		if (System.IO.File.Exists(desc.filename) == false)
 		{
            Warn.print("Cannot find file {0}", desc.filename);
            return null;
 		}

 		res = desc.create();

 		if (res != null)
 		{
            myResources[desc.filename] = res;
 		}

 		return res;
      }

   }
}



using System;

namespace SimEngine
{
   public interface IResource
   {
   }

   public abstract class ResourceDescriptor
   {
      public ResourceDescriptor()
      {
      }

      public ResourceDescriptor(String name)
      {
 		filename = name;
      }

      public string filename { get; set; }

      public abstract IResource create();
   }
}



   public class TextureDescriptor : ResourceDescriptor
   {
      bool myFlip=false;

      public TextureDescriptor(string name) : this(name, false)  { }
      public TextureDescriptor(string name, bool flip)
 		: base(name)
      {
 		myFlip = flip;
      }

      public override IResource create()
      {
 		Texture t = new Texture(filename, myFlip);
 		if (t.isValid == false)
 		{
            return null;
 		}
 		return t;
      }
   }




PARTNERS