Thread: Which One Would Take Up the Least space

  1. #1
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050

    Which One Would Take Up the Least space

    Here's what I need in my structs. I need a player struct that contains x, y, exists, and frame. A bullet[#] struct that contains x, y, exists, and type. An enemy[#] struct that contains x[#], y[#], exists[#], type[#], and frame[#]. An enemy bullet struct that contains x[#], y[#], exists[#], and type[#]. My questions is out of the two examples I've shown which one is the best to use. I'm assuming that it's example 1, but the only reason for my doubt is because there are wasted integers for two structs. Both player bullets and enemy bullets aren't going to be using int frame. So which one is better to use.

    example 1
    Code:
    struct PLAYERS
     {
     int x;
     int y;
     int exists;
     int type;
     int frame;
     }bullet[PL_MAX_BULLETS], player;
     
    struct ENEMIES
     {
     int x[MAX_ENEMIES];
     int y[MAX_ENEMIES];
     int exists[MAX_ENEMIES];
     int frame[MAX_ENEMIES];
     int type[MAX_ENEMIES];
     }e_bullet[MAX_ENEMIES], enemy[MAX_ENEMIES];
    example 2
    Code:
    struct BULLETS
     {
     int x;
     int y;
     int exists;
     int type;
     }bullet[PL_MAX_BULLETS];
    
    struct PLAYERS
     {
     int x;
     int y;
     int exists;
     int frame;
     }player;
     
    struct ENEMY_BULLETS
     {
     int x[MAX_ENEMIES];
     int y[MAX_ENEMIES];
     int exists[MAX_ENEMIES];
     int type[MAX_ENEMIES];
     }e_bullet[MAX_ENEMIES];
    
    struct ENEMIES
     {
     int x[MAX_ENEMIES];
     int y[MAX_ENEMIES];
     int exists[MAX_ENEMIES];
     int type[MAX_ENEMIES];
     int frame[MAX_ENEMIES];
     }enemy[MAX_ENEMIES];
    *I'm not really sure why I'm asking this, because I already know it's example 1. I guess sometimes you just need reassurance... And btw, if anybody has a better example (idea) please feel free to share it.

  2. #2
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Code:
    struct ENEMIES
     {
     int x[MAX_ENEMIES];
     int y[MAX_ENEMIES];
     int exists[MAX_ENEMIES];
     int frame[MAX_ENEMIES];
     int type[MAX_ENEMIES];
     }e_bullet[MAX_ENEMIES], enemy[MAX_ENEMIES];
    should be
    Code:
    struct ENEMIES
     {
     int x;
     int y;
     int exists;
     int frame;
     int type;
     }e_bullet[MAX_ENEMIES], enemy[MAX_ENEMIES];
    Think about it.

  3. #3
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Think about it
    Oh yeah, you're right; I'm not sure what I was thinking.

    In fact, right now I'm trying to figure out what I was thinking. I guess that's pretty hard to do when I must have not been thinking at all...

  4. #4
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469

    Talking

    Yea, I was wondering how someone as mighty and allpowerful as you could make that mistake

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    yeah, no kidding. all the planets must be alligned or sumpin...

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Hey, 400 posts for you, now you can have that custom text stuff. What's it gonna be?

  7. #7
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    well, i still don't see the option to do that, so i'm not sure.

  8. #8
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    wait i know what i was thinking.

    the struct for the enemies is going to have to be like this (there is another method i could use but this way seems the easiest)

    Code:
    struct ENEMIES
     {
     int x[MAX_ENEMIES];
     int y[MAX_ENEMIES];
     int exists[MAX_ENEMIES];
     int type[MAX_ENEMIES];
     int frame;
     }e_bullet[MAX_ENEMIES], enemy[MAX_ENEMIES];
    Because each enemy is going to have a set of set bullets. Since I'm going to have more than one enemy at a time each enemy is going to have a set of bullets. If I don't use arrays for x, y, exists, and type then I'm going to have a huge list of bullets that will not be coordinated with each enemy. I need the sets of bullets to be linked with it's own enemy that way I can keep track of how many bullets each enemy has shot at a time. Does this make sense?

    Here's an example of what I'm saying:

    enemy one shoots

    e_bullet[0].x[0]
    e_bullet[0].y[0]
    e_bullet[0].exists[0]
    e_bullet[0].type[0]

    then enemy two shoots

    e_bullet[1].x[0]
    e_bullet[1].y[0]
    e_bullet[1].exists[0]
    e_bullet[1].type[0]

    enemy two shoots again

    e_bullet[1].x[1]
    e_bullet[1].y[1]
    e_bullet[1].exists[1]
    e_bullet[1].type[1]

    Basically there are going to be so many enemies shooting at once that I'm going to need the arrays set like that. Hey, I guess I knew what I was talking about; for some reason I couldn't figure it out after you pointed out to me that I had it like that.

  9. #9
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Why not have one pool of enemies and one pool of bullets?

    Each time an enemy shoots a bullet from the bullet pool is used.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #10
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Why not have one pool of enemies and one pool of bullets?
    Well, because each enemy is going to have a different set of information pertaining to it, and the same goes with the bullets. I soon realized after I wrote that I'm going to have to include two nested structs. One is going to be for the info for the bullets and the other is going to be for the info for the enemies; however, I might be able to combine it into one struct; I'm not sure.

    Having it set up like this is going to allow me to have a many different type of bullets and many different types of enemies that all have different values.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM