Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mellkor

Member Since 04 Nov 2009
Offline Last Active Jun 01 2014 06:10 AM
-----

Topics I've Started

C++ XML Serialization

31 May 2014 - 10:42 AM

As a learning exercise to get more familiar with C++, I'm trying to Serialize a class to xml but finding its quite intimidating than what i'm used to with c#..

 

Header File for the "Model".

class Level : public DrawableObject {
public:
	std::vector<Sprite> spritelist;
	int sizeX;
	int sizeY;
	int tileSize;
	Level();
};

What would be ideal is to have a library come in and have a look at the class and convert each field it to xml. (which apparently would be to much to hope for lol).

 

My major concern with trying to manually specify what to serialize is when it comes to the spritelist vector that it wont serialize the Sprite Classes.

 

Does anyone have any suggestions to frameworks and implementations?.


Pointer, array and struct problem?..

10 February 2014 - 05:36 PM

Hi, 

 

Experimenting more with c++, but have encountered a problem i cant solve. (driving me mad lol)

The program runs perfectly with this code, Drawing a Triangle.

struct Vertex
{
   unsigned int color;
   float x, y, z;
};


struct Vertex vertices[3]= 
{
       {0xFF0000FF, -0.0f, -0.0f, 0.0f}, 
       {0xffffff00, 0.0f, 50.0f, 0.0f}, 
       {0xFF00FF00, 50.0f, 0.0f, 0.0f}, 
       
       //{0xffffff00, 0.0f, 50.0f, 0.0f},
       //{0xffffff00, 50.0f, 50.0f, 0.0f},
       //{0xffffff00, 50.0f, 00.0f, 0.0f}
};

vertices are passed off to the drawcall at the end, Everything works fine.

 

But i'm trying to "build" the verticies in a loop. The goal is to eventually build a tilegrid out of the vertices, and push them all at the drawcall. 

 

I Can get the solution to compile but, alas no triangle.

struct Vertex
{
   unsigned int color;
   float x, y, z;
};


struct Vertex vertices[3]; 
struct Vertex *pVerticies = &vertices[0];

void BuildVerts(struct Vertex *pVerticies)
{
	int i;
	for (i = 0; i < 1; i++)
	{
		
		(pVerticies+i)->color = 0xFF0000FF;
		(pVerticies+i)->x = 0.0f;
		(pVerticies+i)->y = 0.0f;
		(pVerticies+i)->z = 0.0f;
		
		(pVerticies+i)->color = 0xFF0000FF;
		(pVerticies+i)->x = 0.0f;
		(pVerticies+i)->y = 50.0f;
		(pVerticies)->z = 0.0f;

		(pVerticies+i)->color = 0xFF0000FF;
		(pVerticies+i)->x = 50.0f;
		(pVerticies+i)->y = 0.0f;
		(pVerticies+i)->z = 0.0f;
	}
}


int main(int argc, char* argv[])
{
	
	BuildVerts(pVerticies);
...

I suspect that i'm not using pointers correctly or i need to initialize array elements 'inline' like ie verticies = {..,}; ?


2D tilemaps "Chunk Theory".

06 February 2014 - 05:46 PM

Hello!

 

I'm looking to get as much theory as possible on this subject, I have a hobby project i'm working on: a 2D orthographic game which i have used the standard tile grid array technique to render in XNA. But would like to implement dynamic loading of groups of tiles (chunks) so i can implement larger worlds then a standard grid.

 

The part of the theory i most understand is when the camera, or object gets close to the edge of a chunk the new one is loaded in the direction the camera is traveling and the chunk behind is unloaded. I guess the theory is to have an array that tracks chunks, then another array inside the chunk to track tiles?

 

Things I don't understand:

  • Loading an adjacent chunk that "lines up" with the old one.
  • Best way to "signal" a new chunk should be loaded.
  • General Implementation details

 

I would like to heavy research this topic as i want it to be a center point of any other 2d games i make in the future.

So i welcome any and all recommended:

  • Books
  • Tutorials
  • Videos

And of course code snippets and comments would be very valuable to me. (most proficient with XNA)

 

Thanks.

 

Edit: (Also had another question on general tile maps, should i ask here or start a new thread)?


From C# to C++ concept questions..

18 December 2013 - 09:11 AM

Hi,

 

I Know my way around the C# language fairly well and am looking to try and 'break into' doing some c++ but have a few conceptual questions to ask.

 

My main questions are about pointers and memory management, I believe i have researched and understood what pointers are, and how to use and manipulate them but i do not clearly understand why to use them.

 

C# Example:

 

class Program
    {
        static void Main(string[] args)
        {
            List<int> numberArray = new List<int>();
            Random rnd = new Random();
 
            for (int i = 0; i < 10000000; i++)
            {
                numberArray.Add(rnd.Next());
            }
        }
    }
 
Now, this code should fill a dynamic array allocating memory as needed but when the variable goes out of scope it should be sent to the GC and eventually destroyed correct? 
 
Now, if the same program were to be written in c++ using 'identical code' (ie not pointers) then that array would fill up the stack and the program should crash right?
 
That's why you need pointers? to send large or persistent data to the heap and not overload the stack?

2D octagonal tile map?

13 October 2013 - 08:43 AM

Looking at different types of tile arrays, Seems like an octagonal array would be the most flexible for a 2d rpg but i cant see any articles on people implementing them. Why is this? 


PARTNERS