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 / Cannot find field 'n' in type Integer

Author
Message
Darkhog
13
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 4th Dec 2012 01:05 Edited at: 4th Dec 2012 02:13
I've packed my block data for my minecraft clone project into following UDT:


It uses words and bytes in order to save memory which is pain in this type of games. However when I try to assign some values, like

chunk(x,y,z).blocktype = 6 it gives me error mentioned in topic. How can I fix it without changing variables into integers? It would be bad for my game and its memory if I'd do so.

//edit: Turns out that even after changing field types to integer it still doesn't work. Here's exact code I'm using:


//edit: Just realized how dumb I was, Fix'd.

//edit: Now I have another problem. When building level with following loop:

after some time I get Invalid object number runtime error.

Mind you all those cubes won't be visible at once, those which have blocktype of 0 (air) will be hidden, for performance reasons but I need to prepare level somehow, needn't I?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Dec 2012 10:49 Edited at: 4th Dec 2012 10:49
Well, you're trying to make 255^3 objects. No game engine these days can handle that.

MineCraft doesn't use cube objects anyway. It uses a deformable mesh for every chunk. You can imagine it as cubes, but what's really happening is surfaces are created where none intersect. For example, if you have two cubes next to each other, two surfaces, namely the ones touching each other, would be intersecting, so you'd have to remove that surface.

Also a heads up on DBP variables, they use 32 bits of memory regardless of how you declare them. This can be seen with the following test code:



And when disassembling it, you'll see that it's using up 32 bits:



This means that for every "chunk" (256x256x256) array you'll be using 256 MB of RAM. There's no way you will be able to create large worlds with that.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2012 11:13
Indeed. It would be better to use a much smaller number of cubes and re-use them such as in the Huge Dungeons tutorial demo.
Darkhog
13
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 4th Dec 2012 17:03
Huge Dungeons? I don't believe I have this demo. Also is there any block-building demo, so I can base my game off it?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Dec 2012 18:30
Quote: "Huge Dungeons? I don't believe I have this demo."


TGC Tutorials

It's a few down in the list. Well worth trying. I used it as the basis of a talk to our local computer club.

It might need tweaking to get working with current versions of DBPro. Try it and post back if you get stuck.
Darkhog
13
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 4th Dec 2012 23:39 Edited at: 4th Dec 2012 23:40
Thanks, I've read it through but I think method shown there is good for dungeon crawlers/wolf3d clones, but not for chunk-based blockbuilding game. Heh... If only there would be block-building game demo out there or easy non-language or toolkit specific tutorial out there... I.e. how to properly update chunks, make blocks use proper textures, etc. But there's isn't any, is it?
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Dec 2012 00:35 Edited at: 5th Dec 2012 00:35
Quote: "Well, you're trying to make 255^3 objects. "

Well, your array only allocates about 66MB. Large, but completely fine really. However, your error is most likely because you're attempting to assign values to a variable that does not exist. You didn't create the array with your data type, leaving it as the default integer type.



dim gamearea(255,255,255) as TElement

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Dec 2012 00:39
Quote: "You didn't create the array with your data type, leaving it as the default integer type."


I think you'll find he fixed that. Read his edits again - and read between the lines.
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 6th Dec 2012 22:25
As a corollary to this, I messed around with different data types for storing numbers recently, and found that loops where datatypes other than integers were used, the code actually ran a little bit slower.

HTH,

James
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Dec 2012 08:39
Quote: "66MB"


You'll find it allocates more, see my first post.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Dec 2012 17:25
I make it "about" 67.1 M bytes for the array, i.e. 256^3*4. What's your calculation? It'll certainly be many times more for the objects.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Dec 2012 19:18
Oh, I made a mistake in my calculation. It is exactly 64 MiB, i.e. 256^3*4/1024/1024 = 64

My point is though that the type word, byte, and boolean all use 32 bytes of memory.

TheComet

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Dec 2012 19:43 Edited at: 7th Dec 2012 19:43
Quote: "My point is though that the type word, byte, and boolean all use 32 bytes of memory."


, just great!

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Dec 2012 20:00
Quote: "32 bytes of memory"


Bytes and words will generally aligned to 32bit, so 4 bytes for a byte and 4 bytes for word.

Potentially making the structure TElement 12 bytes per allocated item.



Assuming another long per look up (the pointer to the type structure from the array container) and that's a pretty fat $30000000 byte array.

size=256
print HEx$((size*size*size*4)*12)
sync
wait key

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Dec 2012 20:52
Quote: "Potentially making the structure TElement 12 bytes per allocated item."


Yes, "Potentially" is indeed the right word - his first snippet omitted the type from the dim statement.

Quote: "My point is though that the type word, byte, and boolean all use 32 bytes of memory."


But surely that pales into insignificance compared to the object itself (from his third snippet reproduced below)?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Dec 2012 22:01
Quote: "Potentially making the structure TElement 12 bytes per allocated item."


I tested and checked this with a disassembler, and I found that you are right. This structure here uses 12 bytes of memory:



So 256^3*12 = 192 MiB.

Quote: "But surely that pales into insignificance compared to the object itself (from his third snippet reproduced below)?"


The way I understand it, he's going to allocate 12 bytes of memory per object, discounting the amount of memory each object will use.

I think it's going to be rather significant, because he'll only be able to support ~1.6 GB of RAM before the application will crash.

Also, the first snippet is incorrect. This is how you should handle the object IDs, if DBP will even allow such ridiculously high object numbers.



TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2012 00:59
Indeed. Perhaps he was anticipating the error in your first post?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Dec 2012 12:09


@ Darkhog

You will be interested in this.

http://forum.thegamecreators.com/?m=forum_view&t=187219&b=1

He uses the method I described in my first post. That might be a good starting point.

TheComet

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Dec 2012 07:52
Quote: "- his first snippet omitted the type from the dim statement."

Which is what I was pointing out.

Quote: "[quote]66MB"

You'll find it allocates more, see my first post.[/quote]
Quote: "Oh, I made a mistake in my calculation."


Quote: "I tested and checked this with a disassembler, and I found that you are right."


You gotta quit doubting us old-timers, buddy

Quote: "if DBP will even allow such ridiculously high object numbers"

After some guess n' check, the highest possible number I could get DBP to let me use as an object number was 22,000,000.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 10th Dec 2012 11:44 Edited at: 10th Dec 2012 12:27
Quote: "You gotta quit doubting us old-timers, buddy "


Not doubting, just backing you up

Quote: "After some guess n' check, the highest possible number I could get DBP to let me use as an object number was 22,000,000."


That's insane.

The most objects I've ever used in DBP was around 10'000 in my game Lightship, and that was possible because you only ever had a small amount of objects on your screen at any point. It doesn't make sense to use object numbers that high, unless that's some kind of ye oldie technique us newborns aren't aware of.

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2012 12:23
Quote: "After some guess n' check, the highest possible number I could get DBP to let me use as an object number was 22,000,000."


Was that for animated models or something simpler?
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Dec 2012 22:04
I tested it with make object cube. Any larger number and it'd fail stating the object number was invalid.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Dec 2012 17:25
I also did that 22 million check.

Login to post a reply

Server time is: 2026-07-07 07:36:09
Your offset time is: 2026-07-07 07:36:09