Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Content Manager

Author
Message
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 26th Feb 2010 21:47
I am trying to create a content manager fro my game so I don't have to worry about the sprite ID's when I am making my game. I have done some suedo code on it but I don't really know what would be the best way to go about doing this content manager.



Now I would also need something that will get the ID of the sprite to make sure none of the ID's are the same but I'm really just wondering if this would be the best way to create sprites without having to hard code all of the ID's.

Has anyone done this before that could help me put it into my project?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Feb 2010 22:50
Here's an approach that I'm taking, overly simplified but should illustrate the point.



My reasoning for this approach is this:

KEY_ID has a range of 2.1billion values before it rolls over (or goes negative). If I use that many images, then I have truely out-grown GDK - and probably any other engine for that matter - so I won't worry too much about re-using any free-d up images.

However, in the off chance that KEY_ID does roll over, in my code I have it resetting to 0 and start over. Of course, there is the possibility that every possible id is in use, to which I say that I've out-grown GDK - until then, this is my approach.

JTK
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 26th Feb 2010 23:56
Here is a sprite and image class written by isocadia a few threads below this one, the way he handles ID numbers may help you.

Sprite and image classes

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 27th Feb 2010 01:29
Thanks,
also is there a way to do a list like how I had it in my pseudo code.

I know in C# that's kind of how it's done but I couldn't really find much on it for C++. Anyone used this before?
Carlos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 27th Feb 2010 04:55
I think the most simplest method is to get the next available free id by a function like:

And use the id found to load the image and store the id somewhere for later reference.
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 27th Feb 2010 07:06 Edited at: 27th Feb 2010 08:50
Heres some code to setup a ResourceManagement System for any type object that uses Integer IDs. One day I will rewrite it using templates - hehe. The system manages integer IDs using a LIFO stack, which reuses IDs more efficiently for resources created/destroyed often (ie: particles) during run-time. Need a new ID? Pop it off. Finished with an old one? Push it on. It also use STL Map to map keys (string labels) to the integer IDs. This is useful when you want to use string keys (ie: imagenames, filenames, etc) to reference IDs.

ResourceManagement.h

Using ResourceManager in your code.



You will find yourself using ResourceManagers for DGDKs Memblocks, Bitmaps, Cameras, Lights, Objects(3D), Sounds, Music, Vectors.

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 27th Feb 2010 09:45
Wow once again really helpful TechLord. I am going to try and recreate what you have done in my project so I can understand it better. Also how is the Box2D implementation going for you. I don't know if you remember but you helped me put it in my project a little while ago.

I'm thinking about creating a little level editor with it so people will be able to quickly place box 2d physics items into their games.

One last thing have you tried creating your own shapes in box2D yet?
If so what are you using to represent those shapes? I.E Sprites dbLine().
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 27th Feb 2010 12:09
Glad to help. Box2D is coming along nicely. I'm using it to power high-performance 2D collision and physics simulation for gizmo sprites in the Super 3D Game Engine's UI System. I intend to provide editing for physics within the UI Editor.

Quote: "One last thing have you tried creating your own shapes in box2D yet?
If so what are you using to represent those shapes? I.E Sprites dbLine(). "

I have yet to do so, however, I will mostly likely use Sprites when I cross that juncture. One could use DGDK's drawing function if their going to draw shapes internally. Ofcourse, pre-drawn images should closely match your b2Shape visa versa.

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 27th Feb 2010 22:10
Awesome I am going to have to check out that engine and start coding on that content manager. good luck with your project.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 9th Mar 2010 02:04
Any one know why I would be getting this error:



.H file



Main .cpp


Not entirely sure what I am doing wrong I have tried to change a bunch of things and I'm sure it's something real stupid but I haven't been able to find a solution on Google. At least one that is relevant to my problem.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 9th Mar 2010 03:15
Try this: (I haven't exactly tested it)...




Basically, your definitions called for a single character, not a string as you were expecting. By changing the parameters (and map<> key) your definitions now match what you are expecting...

Enjoy,
JTK
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Mar 2010 03:16 Edited at: 9th Mar 2010 03:17
You're mapping chars to ints, "man" isn't a char, it's a char array which is stored in a const char*. Even if you changed it, it probably wouldn't work because then you're comparing array pointers, you can still have two separate arrays that contain the data "man", you want to use std::string which will actually compare the contents of the string(the same pretty much goes for every single string used in your application).

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 9th Mar 2010 03:38
Okay, I'm still a little new to programming and using templates but basically your saying that I can't use chars right? I need to use a string for this to work?

Also so I have a better understanding of what your saying. If I were to say change my code so load image looked like this:


and then for every load image if I just used a single char like so:




Would that technically work since it is a single character. and since my map is taking a char I would be able to do this? (just learning purposes)
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Mar 2010 04:16
Anything you enclose in double quotes will become a char array(const char* pointing to an array of chars), if you want to retrieve the ASCII value of a character then you must use a single quite, like 'a', but this probably isn't what you want. The issue is this part: void LoadImage(char name,char* image). You take a char as an argument, a char is just a value between -128 and 127. Whereas a char* is a pointer to an array of chars(which can be used to store a string).

The better approach would be something like this:



Note that when passing a std::string to GDK functions you have to access the c-style string format, as well as cast away the constness, the latter is required because GDK is very poorly coded.

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 9th Mar 2010 08:26
Hey thanks for the explanation that cleared some things up for me.

I tried doing what you posted and I kept getting linker errors. Is there anyway you could help me get that to work?

I have tried messing with the code and commenting certain things out but it just doesn't seem to like it.

the linker error is a: LNK2019 unresolved external symbol
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Mar 2010 09:48
Search this board with the term 'linker'.

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 9th Mar 2010 23:25
I have searched the forums but my problem is with #include <string> not the code. I have used this before in many other projects but I have never had a problem with it until now. Is there something in the project options that I need to mess with?

Login to post a reply

Server time is: 2024-05-09 03:00:34
Your offset time is: 2024-05-09 03:00:34