Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Nov 2004
Offline Last Active Jan 15 2012 07:26 PM

Posts I've Made

In Topic: Variable index

15 January 2012 - 07:26 PM

You can do something like this:

#define Global 5;

float g[Global];
int t = Global;
int z = Global;

In Topic: C++: alternative to std::find

15 January 2012 - 07:02 PM

Generally speaking, it's ill-advised to do any searches or in some cases sorts in a realtime application (such as a opengl application where you have a desired framerate)

When you hit an array or vector of that size, it will simply take to long to iterate through it every loop to do a search.

So i would suspect you have a design issue rather than looking for a programming solution via alternative method.

Some of the things you need to look at when iterating through alot of elements:

1) how often does this vector change size or sorted (gets re-indexed)?
2) Can you find what you are looking for once, then keep track of that element's index (inserts or deletes after the index are irrelevant, it's only changes < the index)? aka caching the results...
3) do you have to search and iterate every single loop? would every other loop suffice?
4) since your vector is sorted a binary search will be as fast as a map.

I like to deal with vectors almost exclusively and I do everything in my power to reduce the amount of searches and sorts that I possibly can.

Here is a small sample code that might assist you (this is not my code):

int value_to_find;
vector<int> cont;						 // main container
map<int, size_t> contPos;				 // position cache
// first see if the value is in cache
map<int, size_t>::const_iterator foundCache = contPos.find(value_to_find);
if (foundCache != contPos.end()) {
// not in cache, now do brute force search
vector<int>::const_iterator found = cont.find(value_to_find);
if (found != cont.end()) {
    // cache the value with its position
    contPos[value_to_find] = found - cont.begin();
} else {								  // in neither

In Topic: Holding the mouse down

28 August 2011 - 10:34 PM

Basically the menu system is looking for the menuclick event, however the menu system just looks to see if this state is true. If it's not true then your clicking wont do anything.

The input system makes menuclick true only if you are not holding down the mouse. And my event system is kinda a per loop kinda thing.


Game loop 1

detect mouse down, menuclick is true

Game loop 2

detect mouse down, it already was, menuclick is now false, mousehold is now true.


check menuclick, well it's false, no good.

Of course I could check if mousehold is true, but the problem with this is I have toggle options in the menu, I toggle the option when menuclick is true (menuclick can only be true one time as how the system is built, so if I click on a menu item, it doesn't click it 1000x times)

If I am 1:1 on the game loop and render (50 fps) I am fine, system works as it's supposed to. But if the Game Logic runs 2x before the menu/renderer (i go below 50fps), well it sets mousehold to true because I processed my input code 2 times before I hit the menu system/renderer

simple solution is to move my input code out of the fixed delta time stamp so it does input every frame, but I feel like thats a crappy solution as some computers can get 500fps etc. (checking input 500 times a second... ugly)

Other option is to do a guiclick event that triggers for this situation, but then I have 2 mouse click events, one that works per game cycle, and one that works when input gets called 2x or 3x times before the menu/renderer gets called.

Guess im looking for feedback on different input systems and/or an elegant solution to my problem.

Or I could do a mouse up event instead... would probably fix the entire problem, but even with this it still seems like I need two events, for the the game logic and one of the menus since they can possibly run at different cycles, aka game input could be read 3x before the renderer gets hit due to bad fps.

In Topic: Creating a 2D engine from scratch...

28 August 2011 - 07:14 PM

I'm actually doing it right now, I went the whole 2D from scratch. It definitely is way more work and takes way more time than I thought. 2nd go round I really would like to just use an already existing engine.

But I am learning... ALOT.... very time consuming.

Anyways, If you are totally new to this, I would start with http://nehe.gamedev.net if you want to go the opengl route.

Some people might reply his code is old and outdated, but you can still learn from it. Unfortunately, I don't know of any other active sites that has tutorials as in depth as nehe.

http://www.gametutorials.com used to be free, now you have to pay for it.

In Topic: where to start for sound

25 July 2011 - 06:49 PM

FMOD! it's free for small projects and has the most support and biggest userbase