Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shayel

Member Since 22 Mar 2013
Offline Last Active Dec 28 2013 03:58 AM
-----

Topics I've Started

Strange memory allocation bug with new[]

27 December 2013 - 08:02 AM

Hi

I have ran into a strange problem..

I have this piece of code:

template <class T>
void my_vect<T>::myAlloc(size_t dim)
{
	try
	{
		dat=new T[dim];
	}
	catch(bad_alloc dat)
	{
		err::MyErrorHandler.Error(ALLOC_ERROR);
	}
}
 
Later "dat" is causing the heap corruption, even if it shouldn't. After many many many hours of figuring out why, I found out that the value of my "dat" pointer isn't the same as the value returned by the new[] operator (found it out by stepping into the new operator and looking what it returns). For example new returns 0x...e18, but "dat" is 0x...e1c. The offset is always 4 bytes long. This causes my program to fail when using for example _msize() function.
 
Why is it happening?
 
 

Using global variables - really so bad?

03 October 2013 - 12:28 PM

Hi
Ill give you an example.

g_SoundSystem;
class Game
{
  sf::RenderWindow screen;
  State* CurrentState;
public:
  void Start()
  {
     CurrentState->Logic();
  }
};

class Level1
{
  Player player;
public:
  void Logic()
  {
    if(something) g_SoungSystem->Play("shot.wav");
  }
}

CurrentState=new Level1();


I heard that global variables are bad.. but what is the other way to use things like "Soundsystems" etc. g_SoundSystem has to be global so i can use it from any place in the program. I was also thinking about setting flags in certain points but that would also require global access. In other words: Can you help me in understanding how to replace globals?


Pathfinding, graph algorithms

19 June 2013 - 01:41 AM

Hello
I am trying to understand the basics of the pathfinding, but I don't understand the main idea. I understand how the algorithms work, for example A* algorithm. The thing that confuses me is how do I actually set the vertices. Let's say I have a tile-based map in a 2D game. Do I set them manually , for example in my level editor, and store the coordinates of the vertices in the array/list/tree/anything? 


Doing things the way they should be done

11 June 2013 - 10:50 AM

Hi

When learning to create games I always wonder if my way of thinking is "correct". Yeah, I know that when it comes to programming, everything that works and is free of bugs etc is correct. But I don't like this kind of approach, because I think it limits my self-development. What's more, games seem too complex for me, to allow myself to have this kind of approach. Here is something I was thinking about:

Let's say I want to create Tanks game, with the camera from above. Just a basic 2D game. And I want to create, for example, 5 levels, loaded from file. So here is my idea: I can create an array of integers, and save it to the file. Doesn't matter if it is made with an editor or manually (another conclusion: if creating levels the way I see it is correct, I am able to create a level editor, even with my very poor programing experience, hurray :D). So let's say I have the 80x60 array of integers. Then, when the level is reached in the game, the constructor loads the array, and based on the numbers sets proper textures (10x10 px) in the right order. For example, when it finds "0" in the array[0][0], then the upper left corner will be an empty space, where the tank can move. Same with "1" for obstacle, and "2" for destroyable, for example a box. So basically, my level is just a set of 80*60 textures, positioned on the base of the array. 

 

This is just an example, one of the many things that I find complex and confusing. I have talked with my friend, who has created some simple games. He said that his first level editor was just a huge "if/else" program. And this is what I am trying to avoid, learn the game development standards :)


Code Review - Pong clone..

01 June 2013 - 11:23 AM

Hello

For the past few days I have been working on the Pong clone. I have made it before, but I wasn't satisfied with the quality of the code, so I decided to rewrite it. I guess you all are bored, because of the Pong Clones attacking you from every side, but here it is:

https://gist.github.com/Shayelxx/5691085

Well.. I think that it may be too big for such a simple game, but I am just starting to learn :)


PARTNERS