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.

AppGameKit Classic Chat / Best way to organize a lot of models in RAM with aditional infos?

Author
Message
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 3rd Jun 2017 21:04
In PureBasic with Gadgets (UI) it was possible to GetGadgetData(#Gadget) or SetGadgetData(#Gadget, Value)

For what? It was so possible, to add e.g. a structure (Type) or an ID from a List, Array, Map, Pointer, what ever you wanted and save there more informationen about "your" "gadget".

In AppGameKit I think of the following:

objID = CreateObjectBox ...
...

Maybe 100 times, But I don't know, with objIDs I will have. Because it could be there are some objects created inbetween and so on.

So how would I save aditional information in an array without complicated hashing?

On idea is, I get the objID from a RayCast .. okay, that the easy part.

Now what?

1. -> An array from 1..100000 and the objectID would be the ID in the Array
or
2. -> I know, that I only have 100 Boxes created and have an Array 1..100 and have to cycle and search eachtime for the specific ID.
or
3. -> I could SetObjectData = ID from my Array and with GetObjectData, I have the index of my Array without the need of a realy big array or to cycle to all positions everytime
or
4. ? I don't know, how to make it easy in AppGameKit, but it could be worst decition, if I would have more objects and types. So maybe, you have some experience or best practise?


>> I can't use "SetObjectName" for that, because there is no function like that, but I could use GetObjectName(), if I could set it before
>> I could use SetObjectTransparency, because there is GetObjectTransparency, but that would influence the visuals of the object

What if I wanted to build an easy simple "Minecraft-Clone" with tousends of boxes, but I have to know, which box is which matirial, or health or something?
I know, Minecraft and Boxes is maybe not the best example, that could be done in an three-dimensional-Array for the complete world.

But what is with complex scenes or trigger boxes. Do I have to cycle every frame throu all objects?

Maybe I am thinking to complicated, or I am to simple. I have an idea, how I would realise that in an object orientated programming language. I also know, how I would do it with LinkedLists and cycleing throu all the objects, but maybe there is a much better way, and I don't think of that yet.

I found two threads:
https://forum.thegamecreators.com/thread/204334 (Hashtables)

https://forum.thegamecreators.com/thread/218176(Nearly same wish I have, but it's DarkBasic, and maybe there are other options now)

Thanks for help. Kind regards.


MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 3rd Jun 2017 21:13
HashTables is definitely what you need. I used them in AppGameKit Tier1 and had a very good results.

But there is certainly a lot of other solutions !
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Jun 2017 23:15 Edited at: 3rd Jun 2017 23:22
Your goner kick yourself, I was looping through type arrays to find the id then discovered the array.find() function, create an array of types for your objects and simply call myarray.find with the object id and it will return the array index.

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 3rd Jun 2017 23:26
There are lots of approaches: all more or less relevant to the design.

For instance, you could use a focusing check model. Only check the things you need to based on some criteria (nearness, type or whatever) based on a matrix or dataset you created for that purpose (like a lower resolution grid / array)
An example of this is something I'm doing now. I have the game area divided up into squares (like a chessboard) and have an occupation system which maintains what is in that "square". This works well for dynamic or moving objects, but you could have a special one for statics.

You don't have to check everything on every frame. You could group your checks to "every n frame", so in the easiest implementation you check half one frame, half the other. Some things need checking more/less than others and this would be completely dependent on what you were trying to do.

It's all in the design. Each idea or concept requires an appropriate application of the myriad possible ways. As MikeMax says, there's lots of solutions. The key is getting the right solution to the right problem.

I think you would get a more specific answer with a more specific question, although I hope what I have said here will give you a decent generic idea.

It's definitely the right idea to plan this out *first*. Having to change the core of your game processing later will be a nightmare if you don't get it at least partially right at the start.

OO is the way I approach this and AppGameKit Tier 1 is well adjusted for this now. Type and constructor implementations make everything easy. Once you create the OO object, it just does it's thing. The array additions are excellent and complement the way you will want to work - embrace them

I don't usually work in the 1000's of items. If that was a thing for me, I would consider a recycle system straight away in the design (e.g. set a manageable maximum and recycle the oldest/furthest away items back into use).

Test performance with the max values before adding more stuff.
If it's no good, then consider optimization or reduce the maximums. Give the user options to set max values etc.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 3rd Jun 2017 23:29
Quote: "Your goner kick yourself, I was looping through type arrays to find the id then discovered the array.find() function, create an array of types for your objects and simply call myarray.find with the object id and it will return the array index.
"


Find is excellent and highly beneficial in this regard, as long as you are maintaining sorted arrays.
Remember as well, that for a typed element, only the first listed variable in the typed item will be sortable (and thus findable*)

* not an actual word

Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 4th Jun 2017 09:54 Edited at: 4th Jun 2017 09:54
@PartTimeCoder, maybe that was exaclty what I was looking for.
@nz0, I also hope, that I can ensure, that my IDs are sorted.

@MikeMax, I also think, that Hastable could be an overhead with unknown issues later, e.g. when creating a bigger array on the fly and have to recalculate all values or so.
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 4th Jun 2017 22:03
Yes, what you need is a hashtable. Unfortunately, to my knowledge AppGameKit Tier 1 does not support hashtables. And I have not seen a good implementation around and been too lazy to do it myself.

So my solutions is to use little tricks for this type of features. Here is one possibility.

I am not sure what ID's your boxes have, or what they are. But let's pretend you can assign ID's to them. For sprites that is at least possible.




It does not compile or anything but maybe you get the idea.



PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Jun 2017 00:06
I have a hashtable solution that uses a string as the key but could easily be adapted to use a integer, in my case I needed string indices but I allowed for string, float and integer values

the include


example usage
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 5th Jun 2017 00:40 Edited at: 5th Jun 2017 01:29
i have also a hashTable library (someone has posted this lib few years ago and i have customized it a little for my needs).

i've done a little example with 20000 sprites with additional datas. when you move your mouse over a sprite, it shows the datas of this sprite.

@PartTimeCoder, it could be good to compare performance between your hashtable solution and the one i'm providing here (see the attached zip file)

edit: as nz0 said, it seems array "find" method is indeed as fast as the hash table. But yes, it needs to be sorted and your key need to be in first place for Typed elements.
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-09-30 03:30:13
Your offset time is: 2024-09-30 03:30:13