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 / loading objects

Author
Message
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 25th Jan 2010 20:18
Hello guys!

i was wondering how to make huge games with alot of objects and a huge world, and an idea came across my mind, loading main objects at start with loading ( such as world map ) and then, loading secondary objects while playing, in the game loop, like one object each second.

so i made a test for loading objects in a loop, one object ( ~550 polies ) each 200 milliseconds, the game ran ok, just a little lag ( for a few milliseconds ) which destroyed my hope.

after that, i tried loading the object then cloning it, which did not affect the FPS at all! ( or a really small amount ), same with dbMakeObject* (sphere-box...), so, i think the thing that slows down the object loading is reading the file, which gave me two ideas, and i hope one of them works:

somehow:
1- distribute reading the .X file, so like, reading one part of the file every x milliseconds.
2- defining the object inside the program to avoid reading the file, like dbMakeObject*.

is there any hope that one of them work using DarkGDK? if not, is it possible using DirectX functions? if not, gotta find a new way =/

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Jan 2010 21:39 Edited at: 25th Jan 2010 21:54
Maybe multi-threading to load your objects, I've never done it but I'm pretty sure it would work.

That would be for HUGE worlds though, for a medium/large world I'm sure you could load everything then hide what you don't need until you need it.


EDIT: Just read up on threading with DGDK and its not straight forward although it does look possible.
Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 25th Jan 2010 22:57
With a huge world you should only load small segments of the map.

eg: (each number is one segment and player is ALWAYS in segment 5).

123
456
789

When he moves towards 2 then we hide segments 7 8 9 and load new segments over 1 2 3. In that way we can have so huge map you want and only loads small parts.

But the load has to be done multi-threading.

Niels Henriksen
www.tales-of-the-realms.com
if Microsoft can sell software with bugs, so can I.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 07:59
Sounds cool, ill look into multi threading

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 11:43 Edited at: 26th Jan 2010 11:58
when i first heard about multi-threading, i thought it's pretty much complicated, but this code seems really simple, but...kinda bad results =/



IMPRESSIVE speed @ loading

but..it crashes after some time (not constant time, sometimes it crashes after 10 seconds and sometime 2 seconds etc)..any ideas about why?

error message:


dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 26th Jan 2010 12:26
GDK isn't thread safe.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 12:31
so that means i can use multi-threading? at all?
ok, that's sad.

for future: why isnt it thread safe? so in the future, when i write game using directX, i keep it thread safe

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 26th Jan 2010 14:37
Quote: "so that means i can use multi-threading? at all?"


No. Just that GDK isn't thread safe, which means that calling functions that read or write data being written in another thread will quickly lead to issues, the same when dealing with multi-threaded anything. If your threads have unique data sets or don't call functions that can potentially read/write data at the same time then it'll work fine, but loading objects while rendering isn't one of these cases. As for why GDK doesn't do this, I guess because it adds a lot of complexity to the engine and overhead if only a single core is used(depending on what you're using it for), plus debugging such code isn't all that fun.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 15:19
how can dbLoadObject() be that much complicated? isnt it just D3DXLoadMeshFromX then defining the object in a vector or such?

really wanted this idea to work, but that was depressing =/

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 26th Jan 2010 15:49 Edited at: 26th Jan 2010 15:50
dbLoadObject() probably does lots of things we have no idea about, after all it does add the object to your scene automatically.

Try dbLoadMesh(), it will probably still crash but if it doesn't then you are one step closer.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 16:12
dbLoadMesh crashes faster than dbLoadObject xD
and dbCloneObject / dbMakeObject* crashes instantly

Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 26th Jan 2010 17:33
When using thread dont use GDK functions. You need to place your data in memory and set a pointer to show GDK when it can load an object.

Niels Henriksen
www.tales-of-the-realms.com
if Microsoft can sell software with bugs, so can I.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 26th Jan 2010 18:02
i dont understand what you are saying, how can i place data in memory? and then load the object from the main thread? so dbLoadObject in the main thread? ( if so, what's the second thread for )

Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 27th Jan 2010 00:27
@Hassan: You need to understand that you also need to use basic C++ commands to your game.

The GDK is only a wrapper for talking with DirectX.

The main thread (your GDK loop) is running and running. Its some times looking in some memory to see if there is a pointer to some memory.

Your loader-thread are loading the objects during gameplay. And when it has loaded an object (in memory) it activate the pointer so when GDK next time are comming to the pointer then the object will be created.

When the GDK has loaded the object it will reset the pointer so the loader-thread can see that it can load next.

I hope you understand now

Niels Henriksen
www.tales-of-the-realms.com
if Microsoft can sell software with bugs, so can I.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 27th Jan 2010 08:00
well, i kinda get it but how can i use this to solve the problem?

Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 27th Jan 2010 10:07
When you have a problem you need to analyze it to see if you can break it in parts. Each part you need to solve. Then the problem is solved.

Checklist:
1) Can you make thread?
2) Can you save a pointer in the thread and read it?
3) Can you read the pointer i GDK?

If you can do these and the program is running with it then the next step is to load the object. Also step by step.

Niels Henriksen
www.tales-of-the-realms.com
if Microsoft can sell software with bugs, so can I.

Login to post a reply

Server time is: 2024-10-01 23:41:09
Your offset time is: 2024-10-01 23:41:09