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 / Ever wanted to control how GDK loads resources?

Author
Message
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 19:43 Edited at: 22nd Apr 2011 03:38
Ever wanted to have control over how GDK loads it's resources?
Dont like how all of your files are just spread out in the directory for all of your users to tingle with?
Or you found a way to hide your files, but it involves EXTRACTING them from archives, loading them, then DELETING them from disk?
Wish you could load a file from memory but dont want to use memblocks?

Well, I am here to tell you, YOU CAN!

And to be honest its not that hard, though this requires that you have access to the source code and can compile it, this could be expanded to Darkbasic Pro also more than likely..


-Allows you to control how GDK loads resources like objects,images,sounds,music etc
-No need for working with memblocks as this is similiar to loading a .dbo file (I suggest using .dbo for all of your 3d objects because GDK converts them anyway to .dbo when it loads other formats)
-DBOs are stored as BINARY, so if you want to manipulate this and make your own file formats, or stuff your resources into single .PAK like files then this will help you
-Can be expanded to allow for other format support!

NOTE: The code I am providing is just sample code I am using atm, I have not refined this and it WILL crash if you do not use it correctly but it shows the basic principle of the operation

EDIT: Currently the supplied method I have posted, will still load your textures as if it where a file on disk, I have not added it to accept textures from a buffer yet



UDPATED SOURCE + LIBS:

Alrighty, source + zipped libs!
I used vectors and strings for handling the data, you can change this if you want, just was easier for me

DarkSDKBasic3D.h


CObjectsC.cpp


DBOFormat.cpp


DBOMesh.cpp


DBOExternals.cpp


DBOExternals.h


CommonC.cpp


CImageC.cpp


CImageC.h


DarkSDKImage.h



Making dreams possible, one line at a time...

Attachments

Login to view attachments
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 11th Mar 2011 21:02 Edited at: 20th Jun 2011 00:03
Hi Oneka.

It looks like you and I are working on similar things. I'm creating a "MakeSoundFromMemblock" function that involves similar functions.

Amazing Simulation
www.amazing-forum.com
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 21:36
It works, ive been using it now for loading my objects so it works,
The code is just trimmed code the originally comes from GDK's source to begin with

But yeah, the same concept could be applied to all of the resources that get loaded into GDK, infact it is alittle bit easier in my opinion to work with than memblocks because, all you are doing is passing a buffer to GDK and it does the rest, instead of a filename...

I know the code is messy looking but it works, I could supply my version of Basic3D.lib with the dbLoadObjectFromBuffer() command in place for you to try out


Making dreams possible, one line at a time...
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 11th Mar 2011 22:12 Edited at: 11th Mar 2011 23:14
Hi Oneka.

[EDIT] Incorrect conclusions removed

... but can you let me know:

(a) Where did you declare the functions for LoadCore2 and Load2? In DBOBlock.h, or somewhere else?

(b) can you give me an example of the code you are using to load a sound or an image? Then I can test it in the same way that you did.

Thanks!

Amazing Simulation
www.amazing-forum.com
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 22:40
@TerryRusell,

The area of code your talking about I have not modified, that is just how GDK is in itself, I merely only change where it takes a buffer as data, so thats pre-existing problems

Sample of me using said code



That code is the code that I used to test it with, this is basically the exact code that GDK used to with the regular load command, I just took it out, GDK source is not the cleanest of code in the world

If you open up the GDK source, the locations for LoadCore2 and Load2 I just copied and repasted right about the original code, so if you do a find reference for dbLoadObject() you will follow thisr route

dbLoadObject->Load->LoadCore->Which contains..




Making dreams possible, one line at a time...
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 22:42 Edited at: 11th Mar 2011 22:45
Attached my lib with this post

add this to your DarkSDKBasic3D.h header




Making dreams possible, one line at a time...

Attachments

Login to view attachments
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 11th Mar 2011 23:02 Edited at: 20th Jun 2011 00:04
Hi Oneka.

I had already added the declarations to the DarkSDKBasic3D.h header, but there were some other declarations that needed to be made. I therefore placed these declarations into the DBOblock.h header:

DARKSDK_DLL void LoadCore2(DWORD,DWORD,int,int,int);
DARKSDK_DLL void Load2(DWORD,DWORD,int);
DARKSDK_DLL bool LoadDBO2(DWORD,DWORD,sObject** ppObject );

Amazing Simulation
www.amazing-forum.com
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 23:13 Edited at: 11th Mar 2011 23:15
Well those are only needed if your are compiling the library, I have an already compiled library if you were interested in testing, The only thing that need to be done (other than the code being cleaned) is develop a way for the system to load x number of textures associated with the file, which could be supplied to GDK also..

Ive already started developing a format for my game where I am packing all my resources into 1 file, each model will be converted to Base64 to store as a string, for example



The long string is a 3D model, converted to Base64, my engine reads the string, decodes and runs it to GDK to convert to a model


Making dreams possible, one line at a time...
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 11th Mar 2011 23:19
I _am_ compiling the library, which is why I had to add those declarations.

I have modified the GDK quite extensively now, and I would loose many of those changes if I used anyone else's library, but thanks for the offer.

But I have now added your code to my source files and will play around with it all.

How are you actually loading the string into the engine? And into GDK?

Amazing Simulation
www.amazing-forum.com
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 11th Mar 2011 23:26
What kind of modifications have you made if you dont mind sharing?

I load the strings using basic I/O Stream functions


Yeah that code is really ugly code because I was using it as placeholder code, but it shows the usage of controlling your own loading schemes


Making dreams possible, one line at a time...
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 12th Mar 2011 00:13 Edited at: 12th Mar 2011 00:16
Here are a few fixes I've done over the past few weeks:

Added an overloaded function to dbSetCameraToImage so that it takes the DWORD dwD3DFORMAT parameter.

void dbSetCameraToImage(int,int,int,int,int,DWORD);
in
CCameraC.h and DarkSDKCarea.h

****

Also, added function
void dbSetCameraToImage ( int iID, int iImage, int iWidth, int iHeight, int iGenAlpha, DWORD dwD3DFORMAT ){
SetCameraToImageEx ( iID, iImage, iWidth, iHeight, iGenAlpha, dwD3DFORMAT );
}
in
CcameraC.cpp

****

I fixed a problem in dbMakeObjectPlane/plain. This command was modified some time ago so that both forms of the function would work (different versions of DBPro used them, it seems). The problem was that there is an overloaded function that exists in makeobjectplane. This only takes 3 inputs in GDK, but in DBPRO it takes 3 or 4.

This overloads and links to MakePlane, which is overloaded for 3 or 4 parameters already.

DARKSDK_DLL void MakePlane ( int iID, float fWidth, float fHeight, int iFlag ) (points to the 3 input version if iFlag==0)

So, I added
void dbMakeObjectPlane ( int iID, float fWidth, float fHeight,iFlag )
{
MakePlane ( iID, fWidth, fHeight, iFlag );
}

to Shared/Objects/CObjectsC.cpp

And I modified the error correction on Cobjects.cpp, (coverts calls to "plain" into "plane") by adding
void dbMakeObjectPlain ( int iID, float fWidth, float fHeight, int iFlag )
{
return dbMakeObjectPlane (iID, fWidth, fHeight, iFlag);
}

****

And added to CObjectsNew.h
void dbMakeObjectPlane ( int iID, float fWidth, float fHeight, int iFlag );

and to DarkSDKBasic3D.h
void dbMakeObjectPlane ( int iID, float fWidth, float fHeight, int iFlag );

DBLoadEffect also similarly affected!

***

I've made a lot of similar changes to correct fairly basic errors in the GDK. I have also added various missing headers so that Dark Physics works OK. In fact, that now works so well that I don't know how I would code without it!

Amazing Simulation
www.amazing-forum.com
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 12th Mar 2011 00:53
So, did you get to try it out?


Making dreams possible, one line at a time...
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 18th Mar 2011 00:39
Well, I have added a new command to my custom loading commands

dbLoadImageFromBuffer()

Basically now I can load images from memory into GDK, moving on to working with Sounds/Music and Textures for Objects


Making dreams possible, one line at a time...
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 19th Mar 2011 13:31
Oneka,
Cool stuff
May help to no to overload the GPU memory, while having resources at hand.
Looking forward to try dbLoadImageFromBuffer, is it in the libs posted above? I would like to grab the source code as well, if you don't mind...

Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 19th Mar 2011 19:49
Ok I have attached the Image lib to this post, as this is still a WIP I have not refined these functions yet, as I am still in the process of making them, but they do work for now

Good news is I have located what I have to edit to get textures to take buffers too for the dbLoadObjectFromBuffer() command!

Next
-Add Support for Texture with dbLoadObjectFromBuffer()
-Add dbLoadMusicFromBuffer()
-Add dbLoadSoundFromBuffer()

SOURCE for dbLoadImageFromBuffer()

DarkSDKImage.h



CImageC.cpp


NOTE:
The main changes in the code above that I did was allowed it to pass the buffer down to the functions that used

And simply changed them to take this


There is alot of bloat code that is in there (original code, not mine!) that I have not taken out yet, and the function still can take a filename, but it is depreciated so it really does not do much of anything other than change a few variables for alpha mapping, I will revise all said functions once I get the basic operations working with them but for now there is a raw version of it! Enjoy


Making dreams possible, one line at a time...

Attachments

Login to view attachments
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 25th Mar 2011 16:22
Quite useful, I'll be trying this when I have the time

Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 28th Mar 2011 08:00 Edited at: 28th Mar 2011 08:00
Well, I have had some time to work on it again, Ive added a new function to the mix

This function will allow you to pass an object buffer (strBuffer) and a texture array buffer (strTextureBuffer[]) to the command and it will create an object with the textures like the normal dbLoadObject() command does..

Will post source and libs soon when I finish cleaning up the functions


Making dreams possible, one line at a time...
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 29th Mar 2011 08:01 Edited at: 29th Mar 2011 08:02
Well I have finally achieved what I have longed for!

Custom Pack files for my game / engine

Sample of the format


Attached is the end result of my new system for using in my game, basically its a human readable format but it also contains 2 Objects for use within my engine, I do not have to extract anything to disk, I can read it straight from the file into GDK and use it like a normal object!


Making dreams possible, one line at a time...

Attachments

Login to view attachments
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 31st Mar 2011 14:25
Meh, is anyone interested in it? I dont know if anyone has tested it had problem with it or not...any feedback would be great!


Making dreams possible, one line at a time...
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 3rd Apr 2011 18:30 Edited at: 3rd Apr 2011 18:51
Update: I have made some more improvements to the system,
-I allowed a flag for texture modes when loading objects, this can increase load times because GDK is not converting the image to a texture, it just uses the texture as raw data, so for objects that take for example 500ms to load, time can be decreased to about under 50ms,
-made references to the buffers,
-removed const texture id
Still working on it folks to improve it's functionality but its coming along great and helps to free up some of the limitations placed by GDK's original coding




Making dreams possible, one line at a time...
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 21st Apr 2011 14:38 Edited at: 21st Apr 2011 14:41
Hi Oneka, could you please provide me some support?

I've got a linking error

This is what I did:

-Saved your 'image.lib' and 'Basic3D.lib' files to disk.

-Included the path for the above files in the Visual Studio options->VC++ Directories->Library files section.

-Declared these functions in the header of my project:



-Then I tried to use them with something like this:



and this is the linking error:



This should be working, shouldn't it? Any help would be very much appreciated

Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 21st Apr 2011 18:16
I will upload the source code and the new libs when I get home from class today, the new version has some changes to it and some parameters have been added and some removed, but I have images, and textured objects loading now will post soon!


Making dreams possible, one line at a time...
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 21st Apr 2011 18:38
Alright then

Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 22nd Apr 2011 03:37
Alrighty, source + zipped libs!
I used vectors and strings for handling the data, you can change this if you want, just was easier for me

DarkSDKBasic3D.h


CObjectsC.cpp


DBOFormat.cpp


DBOMesh.cpp


DBOExternals.cpp


DBOExternals.h


CommonC.cpp


CImageC.cpp


CImageC.h


DarkSDKImage.h



Making dreams possible, one line at a time...

Attachments

Login to view attachments
Oneka
19
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 22nd Apr 2011 03:45
This is what I used for reading an existing file into a string

NOTE: this is just hacked code from my current usage but it shows how it works



When loading objects with textures, I have made it so that it will automatically load the textures from the vector, but you need to load them in the order they are called, and if you provide less textures than the model loads, it will default to the first texture

Have fun, if you have any problems or questions just let me know!


Making dreams possible, one line at a time...

Login to post a reply

Server time is: 2024-04-23 18:01:13
Your offset time is: 2024-04-23 18:01:13