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.

DarkBASIC Professional Discussion / Container Inventory

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th May 2008 19:53
Hi guy's, I trying to make and container inventory for my side project Dark Morrowind. Basically every container object has it's own inventory. Now I don't have a problem coding whatever I need to code (if you give me an idea, i'll code it and post the example), but I don't know the most efficent way of doing this, does anyone have any advice?

Mods: Though this seems like a Game Theory question, it's not... trust me... please

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
The Wilderbeast
20
Years of Service
User Offline
Joined: 14th Nov 2005
Location: UK
Posted: 14th May 2008 20:08
You would use an array. So you could have an array like Container(id,obj) where Id is the unique number of the container, and obj is the object number.

So you would have something like container(1,20)=2
Therefore container number 1 has 20x item 20 which could be a sword or something.


Please say if you don't understand what I am trying to explain.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th May 2008 20:18
That wouldn't work since each container can have more than one item in the inventory. If you've played Morrowind (or Oblivion) thats what I'm going for.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th May 2008 20:39
Quote: "Therefore container number 1 has 20x item 20 which could be a sword or something."


Think I read this wrong then, OK, got it. I know most of this stuff already, gimme a sec to put something together then, i'll ask my original question: I don't know the most efficent way of doing this.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Hayer
20
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 14th May 2008 20:45


Something like that?
If you know arrays you should have enough knowledge to re-write it for your own use.

The Wilderbeast
20
Years of Service
User Offline
Joined: 14th Nov 2005
Location: UK
Posted: 14th May 2008 21:02
Sorry, my bad for not explaining clearly.

When you create the array you would have DIM CONTAINER(ID,OBJ) and so you set ID as how ever many containers you want to create, and obj as however many different items there are in your game, each item has its own unique ID number.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th May 2008 21:21 Edited at: 14th May 2008 23:53
OK guy's, proberly should of said I'm not new to this, all I wanted to know is whats the most efficent way of creating this. Really I should of given an example of what I coded to compare it to a more efficent way.

Anyway... just coded this, it does exactly what I want and I can easily add to it.



Now the question, is there a better way?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th May 2008 23:56
So i'm guessing theres not?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
RiiDii
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 15th May 2008 01:17
The way I would do it is by using a single dimension array (using Types, of course) and look up by reference which items are in which inventory you are looking in at any given time. While this may seem to be inefficient, it is fairly fast and can be made even faster with few simple tricks.

A very basic set-up:



Set the ItemList(n).Location to the ID (or index) of the Item that is the container containing the item. Something like this:

Placing Object #57 into container Object #32

ItemList(57).Location = 32

You can place any number of items now into the container object #32. Want to put a limit on it? Just set the ItemList().Container value to any number greater than 0 and that is how many objects the container can hold.

Now you might be thinking, 'what if I have 10,000 items in my game? That's a pretty long array to search for the items that are in any given container.' Truth is that DBPro can search that array pretty quickly. But do it only once by storing the container list in the TempList() array. Also, we are talking about populating an inventory list, not real-time targeting AI; so the list could be populated piece-meal. For example, 1/3rd of the list could be populated each frame. In three frames, your TempList() container inventory is populated; that's about 1/10th of a second at a very low 30 FPS.

Not that 0.1 seconds is too long to wait for an inventory to populate, but you might want to squeeze a little more out of a system like this. Another trick to speed things up would be to delete an item from the master list when it is placed into a container and add it back onto the array stack at the bottom. Then you can search the array stack from last-to-first and find items that have been more recently moved in less time.

A final time saver (and I think you have done this) is to separate the data into values and string. Keep a separate array for values and an array for strings. Searching an array with strings, I suspect, is likely to be slower than searching an array that has no strings.


Open MMORPG: It's your game!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 15th May 2008 03:18 Edited at: 15th May 2008 17:37
Cheers RiiDii for explaining it so well, interesting concept. Though I might end up ruuning into problems with that, since the containers has extra params, like weight limit, object size limit, if its a script trigger container or etc... Also, there won't ever be to many items in the array.

Whenever theres a loading scene, which is going between exterior cells(proberly remove this and opt for background loading) and exterior to interior or visa versa, this is where the arrays are populated with whatever items are in that cell, part of a region of cells or interior.

[Edit]
Created a scene using the array setup I have now, and it work's great and fast.



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 15th May 2008 17:41 Edited at: 15th May 2008 17:41
If you want to test it out, heres the exe (900 KB). Ii will run at whatever your system resolution is. Just need to sort out the text box scales at different resolutions but thats for later.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
TechLord
23
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 15th May 2008 18:39 Edited at: 15th May 2008 20:40
Wow Sasuke,

You move really fast and its looking really good. I felt like I was actually playing Morrowind for about 5 seconds. Excellent work.

How significant is weight of an item?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 15th May 2008 19:30
Thanks TechLord, I'm not to sure about weight yet, I might rework it.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
RiiDii
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 16th May 2008 08:40
Very nice indeed! I look forward to seeing more.


Open MMORPG: It's your game!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th May 2008 13:44 Edited at: 16th May 2008 13:45
I think the Morrowind UI needs an redo, it's abit dated. So i'm add a kind of World of Warcraft UI. Heres my first attempt, just added that bar at the top(don't no the name of it). Plus now you can pick up items.



The way I place items is use another array just for placing items. All it needs is the ID of the item object you want to place an the rest is handle by the engine, so it will take the ID/Pos/Rot out of a script and place it in the world(world being the load interior or exterior cell). When you pick up an item, it is added to you inventory array and deleted from the place item array.

Now it's pretty good at the moment, I did a test where I placed 1000 items in a room and it didn't really affect performance, but is this the right way of doing it, I need the engine to beable to work to it's best, and idea's?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
jinzai
19
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th May 2008 14:08 Edited at: 16th May 2008 14:10
Awesome, awesome, awesome.

I do have a complaint about that bookcase, and its only from a woodworker's point of view. The shelves are not running in the right direction, unless the woodworker was finding a use for cutoffs. I can't tell if they have brackets, but they don't really need them, either. Its very nice looking, however. I like the textures alot!

As for an engine, naturally most will want to see Lua, or something like that, but I like XML alot for this type of thing. COLLADA uses XML, but you can certainly use your own XML schema, too. The reason I like XML is that I am familiar with it already, its free and already available for use in several ways, and XML is pretty rigidly defined.

I only mean that for bringing the items into and taking them out of the program, btw.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th May 2008 14:28
HeHe, that bookcase was a rush job, just needed a prop for the scene. Hmm... XML or Lua, good idea, i'll test it out later.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th May 2008 15:45 Edited at: 16th May 2008 15:49
What if I made my own system that was more accessable to people without knowledge of XML or Lua. Like this is what I use at the moment for loading objects into a scene:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
jinzai
19
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th May 2008 16:16
Well, I was going to suggest that you use the system you posted last week! I mean, it works great, and is in native code, too.

Honestly, as long as it is not a total dog in terms of load time and init time, it is more maintainable, since you do not need to worry about the continued compatibility of the support code.

When the file I/O becomes an issue, you can still retreat to using Windows or C file I/O directly (via load dll) in DBPro, since they are buffered and have position control, too.
GatorHex
21
Years of Service
User Offline
Joined: 5th Apr 2005
Location: Gunchester, UK
Posted: 16th May 2008 17:14
LUA was designed for this, check it out.

DinoHunter (still no nVidia compo voucher!), CPU/GPU Benchmark, DarkFish Encryption DLL, War MMOG (WIP), 3D Model Viewer
RiiDii
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 16th May 2008 17:40 Edited at: 16th May 2008 17:41
We developed a parser library for the Open MMORPG, which makes reading in any script fairly straight forward. You can develop your own scripting from there. It does make use Ian M's Matrix1Util_16.dll for faster text manipulation. File attached.

The way we would use it is to create an Object Placement Script and simply script the data the same way a Function's parameters would call for the data. So a function that started like this:

Function Place_Object(File$,px#,py#,pz#,ax#,ay#,az#)

Can be scripted like this:

Media/Money/Gold.x;127.8;2.3;5534.45;0;0;0
Media/Books/ParadeOfTheDead.x;157.8;5.8;-856.95;0;0;90

This scripting can easily be exported from a world/room editor. This is how we did object placement in our RPG demo. Script reading was even scripted, so we could tell the reader which scripts to read in.


Open MMORPG: It's your game!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th May 2008 01:19
Thanks RiiDii, i'll have a play with it. At the moment, i'm using this method since theres no editor yet:



This way I (or others) can edit easier. When I have an editor to place objects, then I'd opt for your way (File$,px#,py#,pz#,ax#,ay#,az#) since I would never have to look at it again or edit it directly.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
TechLord
23
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 18th May 2008 10:12 Edited at: 18th May 2008 10:15
Sasuke,

You know how I feel about Extending the Content. I would store this data in a SQL database (preferrably a remote SQL database) and use as many tables needed to link this data together with DB Queries.

I use CattleRustler's MySQL DLL and it works great. I can also use Ian M's Matrix1Util #28 and PHP Scripts to perform DB Queries via HTTP GET/POST.

There may be slightly more work in setting this up, but, it will be way worth it once in place.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th May 2008 15:14 Edited at: 18th May 2008 15:14
Ok, added that to the list TechLord.

Currently, I'm having a bit of a problem trying to make the inventory come to life. This is what it looks like in Morrowind:



This thing is hard to work out, the inventory will autosort it's self out based on window width and height (Done that), it also adds scroll bars when there more items than the windon can contain( nearly, just need to sort out the scroll formula ), ontop of that the window can be resized(hmm... shouldn't be to hard once the damn scroll bars out of the way). Man, this could take awhile.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th May 2008 19:39
Finally got the windows working, they resize now(Only sprite used). Only have to fuse the inventory and the window together now, that may take a while.

Anyway if anyone what to see my windows in action (don't worry, i'll make them more Morrowind style soon), heres an EXE.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
TechLord
23
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 19th May 2008 01:41 Edited at: 19th May 2008 01:41
Sasuke,

I could have warned you about the GUI. GUIs are separate projects in themselves. I'm gruling away on my own. Although it was supposed to be simple as HTML ImageMap with some additional features, its taking me more time than I wanted to get it finished.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th May 2008 02:12 Edited at: 19th May 2008 02:16
TechLord,

Guess you haven't seen any of my other GUI stuff, the GUI system my level editor uses is pretty, how should I say this, up there with the greats (I think). It's completely made with DBP and took ages heres a pic:



Also so some stylish buttons I might add to it, again all made with DBP:



I wonder what I could make for this project, hmm...

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
TechLord
23
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 19th May 2008 02:30
Sasuke,

WOW, looking SWeeet! I missed that one. It appears that you already have a very nice GUI System ready for Dark Morrowind.

draknir_
19
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 19th May 2008 04:27
Wow... thats even better than the last GUI pic i saw from you. nice work sasuke, also on the inventory system
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th May 2008 15:47 Edited at: 19th May 2008 15:50
Hi guys, need some help with working out the inventory scroll bar formula. I will refine the code, turn it into functions and etc... but for now I just want to get it working. I think I've taken the right approach in simulating the Morrowind inventory system, your see what I mean. Thank in advance

I can't figure out the Scroll bit when the window increases or decrease size.

The code:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Must Program
18
Years of Service
User Offline
Joined: 22nd Nov 2007
Location:
Posted: 19th May 2008 21:35
HMmmmm i see youre problem now. the problem is ive tryed to understand what you have just written didnt and now im angry and want to strangle you for making me angry there you go there is ure problem j/k i dont know what the problem is but i do know that i dont know what to do
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th May 2008 22:49 Edited at: 19th May 2008 22:49
Must Program, lol, don't beat your self over it

I think I might drop the dynamic inventory and opt for a more modern one. Working on the window at the moment, heres what I've got so far:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Jeff032
18
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 20th May 2008 01:01
The GUI system looks really nice

Looks like your scrollbar is the same as the Windows one except with the colors inverted

Any chance that the GUI system might possibly be open source? (Though forget it if it was coded like the code you posted in your coding styles thread ) I don't really have a project to use it for, but I like learning from other peoples' code.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th May 2008 01:28 Edited at: 20th May 2008 01:28
Quote: "Any chance that the GUI system might possibly be open source? "


I'm afraid not, in the future though (once my editors done then I'll share).

Quote: "Though forget it if it was coded like the code you posted in your coding styles thread"


Haha, lol. No it's not, I coded so everyone can understand it.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th May 2008 02:42 Edited at: 20th May 2008 05:00
Edit:

There are multiple inventories now, you can move the windows as a window would be moved and move the items around the inventory and exchange items between inventories.



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th May 2008 04:00
If you want to test out the new inventory it would be greatly appreciated, here's the EXE. Tell me what you think?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th May 2008 19:33 Edited at: 20th May 2008 19:33
Has anyone tested it yet?

Added a kind of Morrowind style to the UI:



Inventory system nearly done now, just adding more stuff to it plus making different styles.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Roxas
20
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 21st May 2008 16:37
Yes i did test it. From exprience i know that inventory system is hard to make. Especially one like this.

Your signature has been erased by a mod because it was too big
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st May 2008 21:55 Edited at: 21st May 2008 21:56
Yeah, took me awhile, do you think it's OK?

Still haven't figured out how to fix that other inventory system though. The code again, the scroll bit is doing my head in:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st May 2008 23:23 Edited at: 21st May 2008 23:25
Check it out, I just made my inventory system more efficent. I can now run over 200 inventories at once while tracking every item on them and exchanging items between them at over 60 fps. Since the will ever only be a max of 16(may even be less) inventories open at any time, i'm laughing.

Pic:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Roxas
20
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 22nd May 2008 08:57
Ow thats really nice

Your signature has been erased by a mod because it was too big
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 22nd May 2008 17:13
Data size of a morrowind database has 10Mbyte.
Do you implement it?
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd May 2008 18:06
pcRaider, would you be able to explain what you mean, I haven't got that deep into the specifics yet?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 22nd May 2008 18:21
I know "construction set" of morrowind.
For example, a text has 31821 lines.
Do you intend to make it the database which supposed on the scale?
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd May 2008 18:40
Sorry to say this, you must think i'm dumb, I still don't follow you. Are you saying how am I going to make a database that stores up to 31821 lines of text? or...

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 22nd May 2008 19:02
I felt casual.
You do not need to mind it.
Because I had trouble with a search of data, I thought so.
good luck for you.

Login to post a reply

Server time is: 2026-06-11 09:52:34
Your offset time is: 2026-06-11 09:52:34