Jump to content

  • Log In with Google      Sign In   
  • Create Account


landagen

Member Since 24 Jan 2007
Offline Last Active May 27 2013 02:48 PM
-----

#5053529 Is this a bad programming paradigm?

Posted by landagen on 15 April 2013 - 12:52 PM

I am not sure why you would ever want to do this.  It is like building a car with a brake pedal, but then instead of braking when you press it, the car's check engine light comes on as you barrel through a busy intersection. 




#5051195 Entity-Component Design Questions

Posted by landagen on 08 April 2013 - 08:20 AM

I have recently read the Entity-Component article on here and I got really interested in the design.  It sounds great.  Functionality through property definitions.  I have been waiting for the followup article about implementation, but it has not come yet.  I have been reading and thinking about my own implementation and have a few questions.  First, I want to start off with my assumptions/design.

 

1.  All components inherit from a base component class that contains some pure virtual functions to be overwritten.

2.  Components contain only data and do not directly have functionality.

3.  All entities will be kept in a single container as the master list of entities.

4.  Entities are a class that can contain one or more components.

5.  A system can query the master list looking for entities that contain all required components.  Once it finds one, it will then typically reference that entity by an ID number, not a pointer

 

 

Some of my design/assumptions may already be drifting away from the concept.  I am trying to stay close to the concept because I feel that if I drift away from the component, then I may end up running into the snags the design was supposed to prevent.  So without further ado, here are my questions:

 

1.  How to provide custom functionality for entities that contain the exact same components.  For instance, I may want to have different AI routines for different entities.  My thought was to have a component that is a functor to the particular AI routine I would want to run.  That would be a required component in order for the AI system to find that entity


2.  How do most people deal with changes to the component list?  Do they use the observer pattern to inform systems when an entity changes or does the system query the master list every time to find the entities that match its criteria.  The observer pattern is the way I was thinking.


3.  How do you handle shared components.  An example would be several entities using the same material.  My thought was to just have a component that contains a shared_ptr to the material. 

 

4.  Is it okay to have some inheritance at the component level or would this break the design?  Based on what I know, I can't imagine it would break the design.  I wanted for instance my graphics system to be able to find all entities that contain a VertexBuffer component, but I also want my material system to be looking for a particular type of VertexBuffer component (say one that provides texels).   

 

5.  My understanding is that most systems contain a reference to an entity by entity ID and not by pointer.  Why is that?  Is it common for the pointer to change, but the ID to remain the same?  If so, what scenarios would that occur in?  Does constant lookup not cause performance issues? 


Also, any articles that go into some specifics about an Entity-Component system would be very helpful.  Thanks. 




#5050309 Calculate spaceship's movement

Posted by landagen on 05 April 2013 - 08:50 AM

In 2D it may not be as complicated.  That does help.  I presume you are in space so this will also help.  The general steps to solving a physics problem is this:

 

1.  Identify all forces and velocities (in vector form)

2.  Determine how to apply those forces to your object

3.  Sum the forces up in each direction.  Any extra force components on an object get translated into acceleration based on mass. 

 

If you have to deal with impact forces, that can get a little more complicated.  You will have to read and learn each of the individual equations you will need yourself because it is too much material to cover in a forum. 




#5048987 Re-starting?

Posted by landagen on 01 April 2013 - 04:07 PM

I don't think the OP was asking for advice on whether or not to start over (he seems to have already decided on that), but rather which language to start over in.  To me, languages are like print versus cursive writing.  They are the same thing, they just look different.  Pick whichever one you want.  Java is going to be closer to the syntax of c++.  If that is a plus for you, then pick Java, otherwise if you fancy the syntax of Python then go for it.  Programming principles for most languages are going to be the same types of challenges in any language.  That is where programming gets hard so eventually you are probably going to run into the same problems you are running into in another language as you are currently running into in c++, it is just going to take you longer to get there.  Although, I will say the syntax of c++ is more complicated than most languages because it has so much more flexibility.




#5047985 Which is easier to program C# or Java?

Posted by landagen on 29 March 2013 - 08:06 AM

Java seems to have more libraries for it, but it feels disorganized as a language to me.  c# is my preference by far on Windows.  There are lots of niceties that c# has for UI development such as WPF and even Windows forms.  If you are going for linux though, maybe java is the better way to go.  I am not sure of how much support mono has for UI development. 

 

Edit: I should say that what I mean by disorganized is that there is always a lot of choices for any one thing and that it makes it difficult to decide how to proceed (at least for me). 




#5039211 Modified movement cost using A*

Posted by landagen on 04 March 2013 - 04:21 PM

Yes, as others have said, you need a consistent unit to calculate all of your metrics as.  For instance, in your case you may want to have time as your metric that you want to minimize.  In which case all of your path calculations should evaluate as time that way you can compare apples to apples.  Another example could be distance as your metric where you are trying to minimize distance.  I don't think this is what you want, though.  So basically, first figure out the metric you want to minimize and then have all of your formulas calculate that metric. 




#5013210 Object Management Question

Posted by landagen on 21 December 2012 - 12:45 PM

I have a design question.  Just for reference, I believe this an implementation of the composite pattern.  If not, let me know what pattern this fits into.  I have a class called Sprite, ICollidable, IController.  I also have Managers, a physics manager and a Render manager.  A Collidable object references a sprite, a controller also references a sprite.  If I want to turn on collision for a sprite, I just create a Collidable object referencing my sprite and then add it to the physics manager.  Same if I want to make it move.  I create a controller object and reference the sprite and then add it to the Physics manager (in the controller list.  I may move this to a different manager).  I would like to be able to have any one class to delete the underlying sprite and all classes referencing the sprite to be informed.  I need it to propagate upwards to inform all of the objects that reference it so it knows to not reference it anymore.  So for instance, if the Sprite object is deleted, then the ICollidable object needs to be informed who in turn needs to inform the physics manager.  The physics manager is not aware of the underlying Sprite object so it cannot be directly informed.  

 

  I am just starting down this path and worry about future performance.  I know that I should not worry about performance, but this construct is going to be used a lot and I don't want to find out when it is too late.  Has anyone used something similar or is there a different way to solve the problem above that may lead to better results? 

 

Some things I have thought of are:
 

1.  Straight inheritance -> better performance, but does not as flexible

2.  Checking the state of the object before use -> seems like it would have really bad performance since I will use way more often than I will delete it

3.  Treating each object in the hierarchy as a bi-directional linked tree node so that I can traverse up and down to delete all of the objects. -> seems to lose a lot of flexibility and will probably require that each class who wants to participate to inherit from a base class. 

 

I hope my intention is clear.  

 

 

 




#5011733 A Paranoid Programmer

Posted by landagen on 17 December 2012 - 09:18 AM

I have a similar problem as you. I cannot stay focused on one thing for too long. There are so many aspects about making a game that I want to do that I have trouble staying on one topic. It is okay to move back and forth. No one expects you to master unity from start to finish without temporarily moving onto another subject such as learning blender or 3ds max. What you need to do is set goals. Not just say them out loud, but write them down. Put them as an image on your desktop or something so you see them all the time. It should be goals that are big enough to be a good stopping point and to have a sense of accomplishment, but small enough to keep you focused until it is done. Then reward yourself by switching to the next thing you want to learn. All of the things you mentioned will make you a better game maker in the end.

At the same time you need to evaluate what you are really trying to accomplish. Do you want to be a jack of all trades game developer or do you want to make a game? What is your primary focus? What drives you? Either way, make tasks into sizes that fit you. Maybe have tasks that work towards learning unity and then have some tasks that work towards being a better modeler and some other ones that support making a 2d game engine. Then pick a task and complete it. Then pick another task, either from the same group or from a different group if you need something different. The key is to make a task and to complete it.


#5006646 How do you check collision against 1000x1000 objects?

Posted by landagen on 03 December 2012 - 09:43 AM

Also, I would say that in order for a collision to take place, one of the colliding objects must have moved. No need to test 2 objects together if neither of them moved.


#4994155 Create a Game Engine

Posted by landagen on 26 October 2012 - 08:32 AM

It seems like your primary focus on this is to learn. So with that in mind, here is my suggestion. First figure out what you want to learn exactly? whether it is 3d rendering, 3d sound, image loading, networking, etc. I would possibly start with a library like SFML. This will handle some of the details that you may not care about in the beginning. For instance, it can help you create a window on a variety of platforms with a common interface. It also does things such as loading a variety of images and can do audio. The nice thing about it is it is fully open source and free to use for commercial purposes. What you can do is use the library on things you don't want to focus on learning, but then the things you do want to focus on you can not use the library. For instance, I want to write my own 3d rendering engine so I will not be using SFML's 3d graphics library. As you go along and feel like you want to tackle other areas, you can strip out the library from your code. If you try to write everything yourself you will become frustrated with your progress.

The key to any engine making is to have a game that you develop along side of it. This gives you a good testing platform and good usage information. You may find that the interface you thought would be great for a particular functionality is actually not very good. Pick the kind of game you would like to design your engine for such as an FPS, RPG, or RTS. Developing a game alongside your engine will also give your audience a good demo.


#4886326 [C++] Need help optimizing performace of a small function

Posted by landagen on 21 November 2011 - 02:22 PM

So I think I worked out a much faster solution. I will write the pseudo code and use your example

int currentCombos[numOfBlocks]; 
int prevCombos[numOfBlocks]; //for each block that is allowed on the bottom, set it to 1 otherwise, set it to 0

for (int h=1;h<desiredHeight;h++)
{
  memset(currentCombos, 0, numOfBlocks*sizeof(int));
  for (int x=0;x<numOfBlocks;x++)
  {
    for (int i=0;i<lines[x].compatibleLines.count;i++)
    {
      currentCombos[lines[x].compatibleLines[i]] += prevCombos[x];
    }
  }
  SWAP(prevCombos, currentCombos);
}

int total = 0;
for (int x=0;x<numOfBlocks;x++)
{
  total += prevCombos[x];  
}

return total;




So basically this works because your next block only depends on the one right before it and nothing else. So let's take your example. So on the first height, there can only be 1 combination of each block so that means that if you chose a height of 1, there can only be 4 combinations, i.e. 0, 1, 2, and 3. On the second height, block 0 can feed into both 1 and 2, 1 can feed into 0 and 3, 2 can feed into 0, and 3 can feed into 1.
So currentCombos becomes 2 2 1 1. On level three current becomes 3 3 2 2 which gives you 10 altogether which is your answer. This should be a lot faster than your current algorithm. Worst case is (x*x*h) where x is the num of block lines and h is the desired height for your loop. I know I didn't explain it well. I hope the code provides enough explanation.


PARTNERS