Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Lactose!

Member Since 16 Oct 2013
Offline Last Active Yesterday, 08:30 PM

#5242996 SFML + Box2D Camera (Or just "Camera" Concept in general)

Posted by Lactose! on Yesterday, 10:34 AM


Or does anyone know if there is a way to track specific variables and act like a breakpoint when their value changes?

 

If you're using Visual Studio, you can set a breakpoint, and then set a Data Breakpoint (Debug --> New Breakpoint --> New Data Breakpoint...).

Set your address and it should notify you when the memory is written to.

 

That said, it sounds like maybe your not actually using the same camera as you're constructing.I would guess that your camera instance goes out of scope, and you're using a different (not correctly initialized) camera instance later on, or something like that...




#5242626 Calculating points of rectangle after rotation (Trig) help!

Posted by Lactose! on 25 July 2015 - 11:21 AM


It seems like maybe it's rotating around (0,0) instead of the players pos

I don't have time to read through in more depth right now, but if that's the case...

 

When rotating around a point, you want to subtract the rotation point, do the sin/cos stuff, and then add the rotation point back in.

You might, as you say, also need to verify if your functions expect radians or degrees.




#5242415 Vector cast

Posted by Lactose! on 24 July 2015 - 09:11 AM


You mean sample code that compiles only if you have Microsoft language extensions enabled (i.e. no /Za).
Else you're gonna have to change that to a const reference, like Brother Bob already mentioned.

Good catch. Thanks for the correction :)




#5242404 Vector cast

Posted by Lactose! on 24 July 2015 - 08:31 AM

EDIT: See other responses in thread for more information.

 

Assuming C++...

Ensure that your Vector class has a constructor that fits. In your example, it seems like it would Vector::Vector(int x, int y, int z). Doing that should make it work.

 

Sample code that compiles (in Visual Studio, your mileage may vary -- see Mona2000's reply):

class Vector
{
public:
	Vector(int a, int b, int c) { x = a; y = b; z = c; }
private:
	int x, y, z;
};

void Add(Vector &data)
{
	//Stuff here
}

void test()
{
	Add(Vector(1, 2, 3));
}



#5241997 Custom environment macro

Posted by Lactose! on 22 July 2015 - 01:46 PM

You can create a new solution configuration, and add the define to the preprocessor for that configuration:

1. From the Solution Configurations drop-down (by default containing Release, Debug and Configuration Manager...), select Configuration Manager....

2. In the Active Solution Configuration drop-down, select <New...>.

3. Name your solution configuration something appropriate, e.g. MemLeak Debug or MemLeak Release.

4. Copy settings from an existing solution configuration if appropriate.

5. Close the Configuration Manager.

6. Go to Properties on your project (e.g. right click your project in the Solution Explorer and select Properties).

7. Ensure your new solution configuration is selected as the configuration to be edited.

8. Go to Configuration properties --> C/C++ --> Preprocessor.

9. Under Preprocessor Definitions, add the wanted preprocessor definition -- in your case KHATBOX.

10. Select OK, and you should be good to go.

 

#ifdef KHATBOX will now be true for your newly created solution configuration, and false for the other ones.




#5241133 New Game Programmer!

Posted by Lactose! on 17 July 2015 - 06:59 PM


I have a for loop.

Yes, but in that for loop, you have a piece of code that will essentially restart the current iteration of the for loop if the randomly chosen card has already been randomly chosen.

As you keep choosing unused cards, the chance of choosing an already chosen card will increase, which means constantly trying to select a new card, taking more and more time.

 

Other than the issue mentioned above, there's also an issue with how you randomly select a card. You currently choose a card between 1 and 52.

However, your arrays are only initialized to [51], so if card 52 is chosen (which will try to index into your arrays at [52]), you'll be comparing against uninitialized values, which might be what's causing your code to never finish.

Arrays are zero-indexed -- meaning that the first item in an array is at [0], not [1].

 

The fix for this issue is to simply remove the + 1 part of the random number generation.

Math.Rand() returns a number from 0 (0 is included) up to 1 (1 is not included).

Math.Floor(Math.Rand() * 52) -- this includeds the fix I mentioned -- yields a minimum of 0 and a maximum of 51. This is exactly what we want for indexing into our arrays.




#5240839 How do you write this down?

Posted by Lactose! on 16 July 2015 - 11:07 AM

My attempt at shortening it... Not really pretty, but should be equivalent. This is starting to feel like a coding horror post.

while (true)
{
	if !((v > 0) && (x < 0))
		if !((v <= 0) && x > 0))
			break;
		
	int n = (x < 0) ? 1 : -1;

	y += x;
	z += y + n;
	x += n;
	
	if ((x - n) < 0)
		if (doA())
			doB();
	else
		if (doB())
			doA();
}

If the second clause only happens if v is negative (instead of not negative AND zero, as is currently the case), it could be condensed further:

while ((x * v) < 0)
{
	int n = (x < 0) ? 1 : -1;

	y += x;
	z += y + n;
	x += n;
	
	if ((x - n) < 0)
		if (doA())
			doB();
	else
		if (doB())
			doA();
}



#5240833 How do you write this down?

Posted by Lactose! on 16 July 2015 - 10:54 AM

I may be wrong, but isn't this equivalent?
 

while(x)
{
	int n = (v > 0 ? 1 : -1);

	x += n;
	y += (x - n);
	z += (y - n);

	if(doA()) doB();
}
Very hard to be sure without understanding what this does.

 

Doesn't seem equivalent to me. Firstly, x is never stated to have to reach 0. E.g. if v is positive and x is positive, nothing should happen (in the original code).

Additionally, the x, y and z things also seem wrong. I got this for the stuff inside the while loops:

int n = (x < 0) ? 1 : -1;
 
y += x;
z += y + n;
x += n;

I rejigged the order the variables are adjusted, so if the order is important in the actual code (it isn't in the posted snippet), then this wouldn't work.




#5240830 How do you write this down?

Posted by Lactose! on 16 July 2015 - 10:40 AM

 

[…] how do you solve the while clause?

if( v > 0 )

    while( x < 0 );

else

    whle( x > 0 );

while( abs(x + v) > 0) {
    // blah
}

What on earth are you doing?

 

That seems wrong to me.

v might be positive/negative 10000, while x might be positive/negative 5 -- the actual value of v doesn't matter, just whether it's positive or not.

In the posted code, v is never adjusted, while x is. In my example, the while loop should execute 5 times (given valid signs for x and v), which your abs version would not.




#5240650 Broken code

Posted by Lactose! on 15 July 2015 - 07:18 PM


Why?

If you have errors with your code, post the actual code that gives the error. Posting "cleaned up" code which doesn't contain the errors or show the full picture just makes everything harder when trying to help.

What you've posted omits too much to point to specific code other than guessing a lot.

 

That said, my guess is that "final" isn't a valid index for your deck_array. Why it isn't is a whole different question, which requires more information.




#5239708 Visual Studio Not Recognizing #include for SDL?

Posted by Lactose! on 11 July 2015 - 04:35 AM


Hey guys, issue was resolved. 

How?

Posting your solution might help others :)




#5239156 Bugs in code?

Posted by Lactose! on 09 July 2015 - 02:27 AM


but it's not working again..

Define "not working".

Helping someone is a lot harder when you don't know what the problem is.

 

EDIT:

That said, you're currently clearing the screen right before presenting it, which will essentially discard all rendering you've done before the clear.

 

You should also separate updating and rendering better than you do. Currently, you render the snake, then update it, then render other stuff -- I'd suggest updating everything that needs to be updated first, and then rendering everything that needs to be rendered after.

Additionally, your snake seems to have a lot of responsibilities -- updating time and input, spawning food, etc. For future projects, I would suggest splitting these responsibilities up further into additional classes. (See also: Single Responsibility Principle).




#5239076 Circular Header-Include Problem

Posted by Lactose! on 08 July 2015 - 04:23 PM


(Didn't want to post it because it's not the cleanest code).

If you have errors in your code, post your actual code. Sometimes posting a "cleaned up" version will remove the source of the error.

Also post the exact error messages you get, don't paraphrase them, etc. Simply saying "then the errors started appearing" doesn't give us enough information.

 

Don't be too worried about the quality level of your code. We all have code we can look back on and shudder at :)




#5238668 Collision detection and response

Posted by Lactose! on 06 July 2015 - 03:14 PM


2. Okay, so I now I basically know how to deal with a collision of an ellipsoid and a polygon (triangle, quad). Now what? Am I supposed to run the collision routine on every polygon in a mesh? If yes, it means I have to save the mesh data and not dump it after I upload it to the gpu, right? I really have no idea where to start.

Collision geometry can (and probably should) be different from render geometry. Collision geometry can in a lot of cases be made very simple compared to render geometry, which will reduce the amount of processing you need to do.

Additionally, there are ways of avoiding testing all polygons -- e.g. by partitioning areas in discrete chunks. A relevant search term here might be "Binary Space Partitioning (BSP)".

Optimizations here will depend on the type of games/level structure you need to have, though. A game like Metroid Prime (where you load and unload rooms as you traverse through them) can make a different set of assumptions and optimizations than an open world game like e.g. GTA V.




#5238486 optimisations for batch cartesian to polar?

Posted by Lactose! on 05 July 2015 - 04:38 PM

While not directly providing you with knowledge, I think answers to the below will help guide further replies to this post :)

 


i have a single core system and have a strong affectation for using optimisations, it's one of the things i enjoy most about coding.
 
for example a taylor series approximation may be sufficient if only a rough idea of angle is needed.

(Emphasis added)

 

Is only a rough idea of angle needed?

In other words, what are your current results, and what is your target? The more specific, the better.

 

You acknowledge that some optimizations can make your results less accurate, but potentially more performant. In the extreme ends of the spectrum, we've got A) Calculating everything with as much accuracy as is feasible and B) Returning a constant value regardless of input.

Where on that spectrum do you need to be? While there are probably tricks to maintain a specific accuracy while still increasing performance, knowing what your requirements are will help inform the choices and algorithms.

If the current accuracy is needed, have you considered profiling the amount of calls and see if you can reduce it? After all, the most performant code is the code that is never invoked!

You might just be converting a lot more than you need to do; this kind of conversion doesn't sound all to expensive to me.

 

On the other hand, it also sounds like you want this highly performant just because you want it to be (for the sake of enjoyment from optimazation), not because it needs to be. That's also valid, but keep in mind a lot of optimizations improve 1 or 2 of the following aspects, while decreasing the others:

1. Time to process.

2. Storage space.

3. Life-time spent on implementing.

 

Even in this case you'd need to decide how accurate it needs to be, while also having some sort of performance goal in mind.






PARTNERS