Page 1 of 1

Some newbish C++ questions

PostPosted: Feb 17, 2004 @ 7:16pm
by Volte6
I'm just looking for some direction. I have no problem researching the answers, but don't really know what to look for or where to start.

1.) What is the standard method for dynamically allocating memory. For example, if I don't know how much memory will be needed for a string (Do I just cap it somewhere and assume that to be the max?), or if I don't know how many players, how do I dynamically add another object, and track it? Do I ALWAYS pre-allocate the maximum amount, or is there a way I can deal with the unknown?

2.) What about stuff that is only around some of the time? For example, I've created a demo of some balls bouncing around the screen. I know upon compile time that I want 100 balls bouncing. I do a for-loop through an array, and call the move() method on each one. BUT, what if those balls aren't going to exist until 20 minutes into the game... I shouldn't be calling a for loop, right? Is there some sort of convention regarding 'registering' created objects with a 'master' controller object of some sort? Or what if I want a custom SIP? I don't want it waiting for input constantly... but only when applicable.

3.) Finally, what is a standard way to accept input from a user (character/integer wise)? If I want to create a custom SIP (For a full screen app), I think I need to know how to GET that info from them... I'm guessing this is actually directly related to the SIP object though.

Thanks tons! :)

PostPosted: Feb 17, 2004 @ 8:15pm
by fast_rx
Using the STL vector or list is one way to handle the second part of #1 and #2.

It will allow you to add and delete your "objects" as needed...

This post http://www.pocketmatrix.com/forums/view ... hp?t=14968
was just talking about loading a string from a file when you don't know how long it is.

PostPosted: Feb 17, 2004 @ 8:27pm
by Volte6

PostPosted: Feb 17, 2004 @ 8:46pm
by fast_rx
I don't quite follow why you're concerned about the adding and deleting when that's what you want... You only add and delete when you need to.

There's not as much overhead as you think... I'm using a vector of structures for particle effects that constantly goes from a few to hundreds and back constantly and have great performance.

PostPosted: Feb 17, 2004 @ 8:57pm
by Volte6
You're probably right. I'm [USED] to Actionscript where every bit counts ;) I've been turned completely paranoid of wasting processing power hehe.

Conceptual question

PostPosted: Feb 18, 2004 @ 12:45am
by Volte6
Okay, in terms of concepts and organization, here is what i'm thinking... can anyone tell me what is wrong with this, or if there is a more standard method? Is this acceptable for a game program?
I am excluding the processing of input, background drawing, etc.,.. I'm more interested in knowing if I have this conceptually correct.
Objects:

1.) My Application object. It manages everything from the highest level. It calls the maintaining methods from the following internal objects:
1a.) My Game object. It manages things like bullets, bad guys, player, animation, etc.
1b.) My Menu object. It manages menus, Popups, buttons, and so on.

The game objects maintenance method checks if any objects are in action, and calls THEIR maintaining functions (Enemy AI, drawing, movement, whatever).

The Menu object does the same, for menus. It can also disable processing of the game object (For example, if game action should pause when a menu displays).

The main application loop will call those methods in those objects each frame.

This may be pretty basic stuff, I don't know. This is how i'm thinking it over in my head, but I don't want to get crazy going in this direction if I've got it all wrong... Is this acceptable?

PostPosted: Feb 18, 2004 @ 4:18am
by mlepage
You should probably take a look at the source code to some exisitng Pocket PC games. There is some floating around. It may not be perfect but it is one way of doing it and that's a start.

PostPosted: Feb 18, 2004 @ 7:31pm
by Volte6
Well, since nobody has really OBJECTED to my structure, I'll assume it's sound enough, thanks :)

PostPosted: Feb 19, 2004 @ 5:16pm
by angedelamort
Usually, when I make a game, it's really simple:

main Loop
{
- check inputs
- update all timer
- Draw on the screen
}

For the rest, like your structures, it's developper specific... If you think it will works, go for it. I don't see any problems right now with it. But like someone suggest, you may have a look at some ppc source code to see how it's done.