Can anyone see what is wrong with this game loop? It crashes most of the time when I call pWindow->Close(), can't see why:
[cpp]
//Main Game loop!
void GameController::Run()
{
//Running = true;
while (GetRunning())
{
Tick();
Draw();
// Process events
sf::Event Event;
while (pWindow->PollEvent(Event))
{
ProcessEvent(Event);
}
}
pWindow->Close();
std::cout << pWindow << "\n";
}
//Process events
void GameController::ProcessEvent(sf::Event &Event)
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
{
Terminate();
}
}
void GameController::Terminate()
{
std::cout << "terminate\n";
SetRunning(false);
std::cout << "terminateend\n";
}
[/cpp]
I forgot to say, the crash is a heap corruption error and it points me to a function in 'free.c'
The window is created in main.cpp:
[cpp]
sf::RenderWindow Window = sf::RenderWindow(sf::VideoMode(width, height, 32), title);
GameController Intergalactic(&Window);
Intergalactic.Run();
[/cpp]
[QUOTE=WhatTheEf;32106734]Nevermind. The delay is there because there are free spaces below the text and it takes a while to get at the end of the window. Here's a code that works ok:
[cpp]#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout << "\n\n\n\n\n\n\n\n\nTest";
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n";
for (int i = 1; i < 15; i ++)
{
cout << "\n";
Sleep(200);
}
cin.get();
} for (int i = 0; i < 25; i ++)
{
cout << "\n";
Sleep(150);
}
cin.get();
}[/cpp][/QUOTE]
Wow, then it's kinda strange how it worked perfectly for me...
[QUOTE=thf;32097063][cpp]
if (cEntitySwap.find(entityName) != cEntitySwap.end()) {
entityName = cEntitySwap[entityName];
}
[/cpp][/QUOTE]
That does the lookup twice, once to check whether the name is present and (if it is) a second time to actually retrieve the value. Better to do it just once:
[cpp]
std::map<std::string, std::string>::const_iterator iter = cEntitySwap.find(entityName);
if (iter != cEntitySwap.end()) {
entityName = *iter;
}
[/cpp]
[QUOTE=Wyzard;32110196]That does the lookup twice, once to check whether the name is present and (if it is) a second time to actually retrieve the value. Better to do it just once:
[cpp]
std::map<std::string, std::string>::const_iterator iter = cEntitySwap.find(entityName);
if (iter != cEntitySwap.end()) {
entityName = *iter;
}
[/cpp][/QUOTE]
Yeah, my problem was that I couldn't find a proper name for the variable that stores the iterator :v:
But I just realised how much of a difference it should make if you have lots of elements, so sorry.
Also you could use auto for the iterator type if using C++11.
Hey, I'm taking a beginners programming class in c, and my code is not compiling for some reason. I cannot for the life of me figure it out.
[CODE]#include <stdio.h>
#include <math.h>
#define PI = 3.14
int main (void)
{
double force = 0.0, acceleration = 0.0, mass = 0.0;
double volume = 0.0, radius = 0.0, height = 0.0; //PI * radius^2 * height = volume
printf ("Please enter mass and acceleration (floating point values) for use in Newton's Second Law.\n\n");
scanf ("%lf%lf", &mass, &acceleration);
force = mass * acceleration;
printf ("Force = Mass * Acceleration; %lf * %lf = %lf\n", mass, acceleration, force);
printf ("Force = %lf\n", force);
printf ("Please enter radius and height (floating point values) for use in the volume of a cylinder equation.\n\n");
scanf ("%lf%lf", &radius, &height);
volume = PI * radius * radius * height;
printf ("Volume = PI * radius^2 * height; 3.14 * %lf^2 * %lf = %lf\n", radius, height, volume);
printf ("Volume = %lf\n", volume);
}[/CODE]
the line "volume = PI * radius * radius * height;" gives the error: "error C2059: syntax error : '='"
#define PI = 3.14
PI is now "= 3.14"
[editline]5th September 2011[/editline]
Ie. remove the = from the define
[QUOTE=esalaka;32117684]#define PI = 3.14
PI is now "= 3.14"
[editline]5th September 2011[/editline]
Ie. remove the = from the define[/QUOTE]
derp.
Figures it would be something silly.
Thanks
you are also missing the return
What would be a good way to rotate the view in opengl for making a voxel engine? I am bo[del]a[/del]red
[editline]4th September 2011[/editline]
more to that idea, how would i get the block at a certain X Y and Z if its stored in a boolean array?
I need help making some simple collision in SFML 2. Its basically just a ball hitting a paddle and I need help making the ball not go through the paddle and bounce back. Any advice?
[QUOTE=Exosel;32119151]I need help making some simple collision in SFML 2. Its basically just a ball hitting a paddle and I need help making the ball not go through the paddle and bounce back. Any advice?[/QUOTE]
Generally speaking, collision programming is composed of two parts:
- Collision detection (usually easy to do)
- Collision response / handling (usually the hardest part)
In your case, you can handle the first one by checking the paddle and ball coordinates and taking into consideration the size of the paddle and the radius of the ball.
The second part can be handled pretty easily in your case, too, as the ball is a simple enough shape (you can simulate it is as point), and the paddle doesn't respond to collisions. Just find the vector that is the reflection of the movement vector of the ball based on the surface vector of the paddle. Then use this as the new movement vector of the ball.
There are possibly features in SFML that can help you with collision detection, but I don't know the library well enough to tell you.
[QUOTE=q3k;32119363]Generally speaking, collision programming is composed of two parts:
- Collision detection (usually easy to do)
- Collision response / handling (usually the hardest part)
In your case, you can handle the first one by checking the paddle and ball coordinates and taking into consideration the size of the paddle and the radius of the ball.
The second part can be handled pretty easily in your case, too, as the ball is a simple enough shape (you can simulate it is as point), and the paddle doesn't respond to collisions. Just find the vector that is the reflection of the movement vector of the ball based on the surface vector of the paddle. Then use this as the new movement vector of the ball.
There are possibly features in SFML that can help you with collision detection, but I don't know the library well enough to tell you.[/QUOTE]
Thanks, this helped a lot.
I need a little help with collision response:
I know how to detect a collision and push the player out of it. My problem is with neighboring tiles. If the ground the player is on is longer than one tile the collision response may attempt to push the player to the right or left - into another tile. What can I do to prevent this other than storing the tiles in a 2D array and check the neighboring tiles?
I'm really not sure what to do.
I just started with my game programming course. I've been doing C++ for 1 year+ now, but the problem is that each project and assignment we get will have a deadline. I'm afraid that because of C++ low level it will take too much time to finish those projects and assignments and I am thinking about picking up C# where I only have a bit of experience with.
What does FP think?
Do you know any place where I can learn Flash and ActionScript and that stuff?
[QUOTE=Asgard;32127778]I'm really not sure what to do.
I just started with my game programming course. I've been doing C++ for 1 year+ now, but the problem is that each project and assignment we get will have a deadline. I'm afraid that because of C++ low level it will take too much time to finish those projects and assignments and I am thinking about picking up C# where I only have a bit of experience with.
What does FP think?[/QUOTE]
stay with c++.
The course is aimed at people that dont know about programing I take it, so the deadlines will be plenty for someone with a year experience
Looking for any algorithm to reduce the numbers of rectangles / quads without losing the shape.
Like:
[img]http://gyazo.com/fa07a979203cc7f4efacebf8101eec66.png[/img]
Any sugestions where I can find any arcticle about this or at least a name of the algorithm?
[QUOTE=likesoursugar;32129597]Looking for any algorithm to reduce the numbers of rectangles / quads without losing the shape.
Like:
[img]http://gyazo.com/fa07a979203cc7f4efacebf8101eec66.png[/img]
Any sugestions where I can find any arcticle about this or at least a name of the algorithm?[/QUOTE]
Ask Dlaor, he did this for his spaceship game
[QUOTE=Richy19;32129690]Ask Dlaor, he did this for his spaceship game[/QUOTE]
[url]http://www.facepunch.com/threads/1099026?p=31177284&viewfull=1#post31177284[/url]
[QUOTE=thf;32129918][url]http://www.facepunch.com/threads/1099026?p=31177284&viewfull=1#post31177284[/url][/QUOTE]
I have a feeling that it's faster to do the same thing in reverse order.
i.e. Instead of having a 16x16 grid and checking all 256 cells for 'holes' in the first pass, start with 2x2 blocks, combine any that don't have holes, then go larger. This way you only ever have to compare 2x2 blocks. You're basically building a quadtree with this method, which can be a very fast operation. (also, it's not a perfect solution, just a good approximation)
Quick question time, does anyone know if there's a decent 3d physics engine for C# that's not somehow related to XNA?
[editline]5th September 2011[/editline]
Nevermind, this one seems decent:
[url]http://code.google.com/p/jitterphysics/[/url]
Jitter physics is pretty good, uses it's own matrix, vector, and quaternion classes. I just wrote a static JitterConverter class that would convert OpenTK's Vector, Matrix, and Quaternion classes into Jitter's JVector, JMatrix, and JQuaternion classes and vica versa.
It's under the zlib license, and there was an update released 2 days ago: [url]http://jitter-physics.com/phpBB3/index.php[/url]
The google code page:
[url]http://code.google.com/p/jitterphysics/[/url]
Also it recently added softbody physics, haven't tried it myself but it looks to run pretty well.
[QUOTE=Dlaor-guy;32131837]Quick question time, does anyone know if there's a decent 3d physics engine for C# that's not somehow related to XNA?
[editline]5th September 2011[/editline]
Nevermind, this one seems decent:
[url]http://code.google.com/p/jitterphysics/[/url][/QUOTE]
Look for C# Bullet bindings.
Any good c++ opensource free multiplatform(as much as SFML) network libraries?
Or should I just use SFML's network functions?
[editline]5th September 2011[/editline]
And is this a good way to round up a number to the closest int?
[code]
template <class t>
inline int roundToInt(const t& val)
{
if( (int)val == val ) return val;
if( val <= (((int)val) + 0.5f) )//number is between val and val.5
return (int)val;
else
return ((int)val)+1;
}[/code]
[QUOTE=Richy19;32133909]And is this a good way to round up a number to the closest int?[/QUOTE]
Just do (int)(val + 0.5f) for positive values.
Are there any good resources for triangle scan line conversion?
Any simple opensource games that I can learn, the desing and stuff from?
Also things like how to manage gameState transitions or cutscenes and stuff?
In c++, do you think it's a good or bad idea to do this
[code]namespace EnumName
{
enum EnumName
{
1,
2
};
}[/code]
It's always bugged me how enums just dump all their values in to that namespace.
C++11 fixes that using [b]enum classes[/b].
I'm learning c# and I'm having some trouble.
How would I go about taking player input and checking if it is a certain word, and if it is print something to the console, and if it isn't return to taking the input. I currently have..
[code] Console.WriteLine("What do you do?");
string whatdo = Console.ReadLine();
int checkInventory = whatdo.IndexOf("inventory");
if (checkInventory == 1)
{
Console.WriteLine("You have a piece of strong fiber, a rock and a woodenstick.");
}
if (checkInventory== -1)
{
Console.WriteLine("Unknown command.");
//I WANT TO GO TO LINE 1 HERE
}[/code]
What would I do?
Sorry, you need to Log In to post a reply to this thread.