[Rename] Object-oriented programming simulation for a virtual object manager

Just starting out? Need help? Post your questions and find answers here.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

mk-soft wrote: Thu Feb 13, 2025 11:05 pm Without OOP but with Object.

It is too complex and makes no sense.
But shows that you can manage different substructures with Maps and AllocateMemory in an Object Structure.
Thank you very much,

what do you mean by:

"It is too complex and makes no sense.
But shows that you can manage different substructures with Maps and AllocateMemory in an Object Structure."

I understand better this code you made, which is much better structured and clear for me, I see the principle.
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
miso
Enthusiast
Enthusiast
Posts: 410
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: A virtual object manager code

Post by miso »

I understand this, but not really the original code. I'm not flaming though, might be good for something I'm not even aware. Seems like a lot of work has been put into the original code, but maybe worth to take some advice from the previous posts, because I think they (SMaag/MKsoft) are on the good path. I hope I did not offend anyone, thats not my goal.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

miso wrote: Fri Feb 14, 2025 9:24 am I understand this, but not really the original code. I'm not flaming though, might be good for something I'm not even aware. Seems like a lot of work has been put into the original code, but maybe worth to take some advice from the previous posts, because I think they (SMaag/MKsoft) are on the good path. I hope I did not offend anyone, thats not my goal.
"I understand this" > That is to say ?

@miso, there’s no problem, don’t worry, and you’re absolutely right.

SMaag/MKsoft, They shared their opinions and some code, and I thank them for that. I don’t have their level of programming expertise, so understanding their examples is challenging for me.
But yes, I should take their advice into account. However, I first need to understand how their code works.
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
miso
Enthusiast
Enthusiast
Posts: 410
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: A virtual object manager code

Post by miso »

"I understand this" > That is to say ?
I was started to write my post after mk-soft, but was slow to finish. After your answer to him, mine became a bit obsolate.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

It’s obvious that I don’t understand your code at all because I can’t even modify it to adapt it to what I want to do. Managing parent-child relationships seems very difficult for me, especially with recursive elements.

In my code, the type of an object was simply a string, not a real type. It was used to determine the type of an object in order to perform certain actions. For example, if Type = "Button", then do something.

If I have to integrate real object types into my code, it might become a jungle! But it could still be useful, I suppose.
Do you think I should integrate this into my Object Manager anyway?
Do you think it could be useful, especially for other people?

Because if you look at all the structure fields I’ve integrated into my object structure, and if every type of object has to have all these fields… interesting, but I don’t know.

It’s quite possible that once again, I’m failing to explain correctly what I want. That’s what happened with Editors Factory, where almost no one understood what it was for. I must admit, I have a lot of trouble explaining things.

To try, as best I can, to explain what I want: imagine you have lockers that represent objects, where I can store things and retrieve data. For example: “Hey, I want to store the value "24" in the locker called "Object 1", in the slot called "X". ”

Ah, ok. Maybe everyone already understood that. You don’t have to be a genius to get it. But what is it useful for? That’s another question. Well, so that I don’t have to redo everything, this management system could be useful if someone needs something ready-made for their project.
And since I need it myself, I want to create something that will be useful to others.

Code: Select all

Structure Object
  *Parent.Object
  ID.i
  Type.s
  Name.s
  Texte.s
  X.i
  Y.i
  Width.i
  Height.i
  Flags.i
EndStructure

Global NewMap MapObject.Object()

Procedure CreateObject(ParentID.i, ID.i, Type.s, Name.s, X.i, Y.i, Width.i, Height.i, Flags.i = 0)
  Protected *Parent.Object
  
  If FindMapElement(MapObject(), Str(ID))
    ProcedureReturn 0
  EndIf
  
  If Not FindMapElement(MapObject(), Str(ParentID))
    ProcedureReturn 0
  EndIf
  
  *Parent = MapObject()
  
  AddMapElement(MapObject(), Str(ID))
  
  MapObject()\Type = Type.s
  MapObject()\ID = ID
  MapObject()\Name = Name.s
  MapObject()\Parent = *Parent
  MapObject()\X = X
  MapObject()\Y = Y
  MapObject()\Width = Width
  MapObject()\Height = Height
  MapObject()\Flags = Flags
  
  ProcedureReturn @MapObject()
EndProcedure

Procedure DeleteObject(ID)
  If FindMapElement(MapObject(), Str(ID))
    PushMapPosition(MapObject())  
    ForEach MapObject()
      If MapObject()\Parent
        If MapObject()\Parent\ID = ID
          DeleteMapElement(MapObject())
        EndIf
      EndIf
    Next
    PopMapPosition(MapObject())  
    DeleteMapElement(MapObject())
  EndIf
EndProcedure

Enumeration 1
  #Object1
  #Object2
  #Child1_Object2
  #Child1_Child1_Object2
  #Child2_Object2
  #Child1_Child2_Object2
  #Child1_Child1_Child2_Object2
EndEnumeration

; Pas de parent.
*Object1.Object = CreateObject(0, #Object1, "Virtual", "Object 1", 0, 0, 200, 200)

; Pas de parent.
*Object2.Object = CreateObject(0, #Object2, "Virtual", "Object 2", 10, 10, 180, 25)

  ; #Object2 recoit un enfant: #Child1_Object2.
  *Object3.Object = CreateObject(#Object2, #Child1_Object2, "Virtual", "Object 3", 10, 45, 180, 25)
  
    ; #Child1_Object2 recoit un enfant: #Child1_Child1_Object2.
    *Object4.Object = CreateObject(#Child1_Object2, #Child1_Child1_Object2, "Virtual", "Object 4", 0, 0, 200, 200)
  
  ; #Object2 recoit un enfant: #Child2_Object2.
  *Object5.Object = CreateObject(#Object2, #Child2_Object2, "Virtual", "Object 5", 10, 45, 180, 25)
  
    ; #Child2_Object2 recoit un enfant: #Child1_Child2_Object2.
    *Object6.Object = CreateObject(#Child2_Object2, #Child1_Child2_Object2, "Virtual", "Object 6", 0, 0, 200, 200)
    
      ; #Child1_Child2_Object2 recoit un enfant: #Child1_Child1_Child2_Object2.
      *Object7.Object = CreateObject(#Child1_Child2_Object2, #Child1_Child1_Child2_Object2, "Virtual", "Object 7", 0, 0, 200, 200)
    
Debug *Object5\Texte

If *Object2\Parent And *Object2\Parent\Name = "Virtual"
  Debug *Object2\Parent\Name
EndIf

Debug ""
ForEach MapObject()
  Debug MapObject()\Name + " ID " + MapObject()\ID
Next

Debug "Delete ..."
DeleteObject(1)

ForEach MapObject()
  Debug MapObject()\Name + " ID " + MapObject()\ID
Next
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
mk-soft
Always Here
Always Here
Posts: 6203
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: A virtual object manager code

Post by mk-soft »

For puzzles ...

Code: Select all

;-TOP

; Module DataSet by mk-soft, v1.01.1, date 24.09.2021

DeclareModule DataSet
  
  Interface iDataSet
    Free()
    SetW(Key.s, Value.w)
    SetL(Key.s, Value.l)
    SetI(Key.s, Value.i)
    SetQ(Key.s, Value.q)
    SetF(Key.s, Value.f)
    SetD(Key.s, Value.d)
    SetStr(Key.s, Value.s)
    Get(Key.s)
    GetF.f(Key.s)
    GetD.d(Key.s)
    GetStr.s(Key.s, Decimals=2)
    GetType(Key.s)
  EndInterface
  
  Declare New()
    
EndDeclareModule


Module Dataset
  
  Structure udtAny
    Type.w
    StructureUnion
      wVal.w
      lVal.l
      iVal.i
      qVal.q
      fltVal.f
      dblVal.d
    EndStructureUnion
    sVal.s
  EndStructure
  
  Structure udtDataSet
    *vTable
    Map Value.udtAny()
  EndStructure
  
  ; ----
  
  Procedure New()
    Protected *r1.udtDataSet
    *r1 = AllocateStructure(udtDataSet)
    If *r1
      *r1\vTable = ?vTable
    Else
      Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
    EndIf
    ProcedureReturn *r1
  EndProcedure
  
  Procedure Free(*DataSet)
    If *DataSet
      FreeStructure(*DataSet)
    EndIf
  EndProcedure
  
  ; ----
  
  Procedure SetW(*DataSet.udtDataSet, Key.s, Value.w)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Word
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\wVal = Value
  EndProcedure
  
  Procedure SetL(*DataSet.udtDataSet, Key.s, Value.l)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Long
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\lVal = Value
  EndProcedure
  
  Procedure SetI(*DataSet.udtDataSet, Key.s, Value.i)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Integer
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\wVal = Value
  EndProcedure
  
  Procedure SetQ(*DataSet.udtDataSet, Key.s, Value.q)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Quad
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\qVal = Value
  EndProcedure
  
  Procedure SetF(*DataSet.udtDataSet, Key.s, Value.f)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Float
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\fltVal = Value
  EndProcedure
  
  Procedure SetD(*DataSet.udtDataSet, Key.s, Value.d)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_Double
    *DataSet\Value()\sVal = #Null$
    *DataSet\Value()\dblVal = Value
  EndProcedure
  
  Procedure SetStr(*DataSet.udtDataSet, Key.s, Value.s)
    If Not FindMapElement(*DataSet\Value(), Key)
      If Not AddMapElement(*DataSet\Value(), key)
        Debug "Error " + #PB_Compiler_Module + "/" + #PB_Compiler_Procedure + ": Out of Memory!"
        ProcedureReturn #False
      EndIf
    EndIf
    *DataSet\Value()\Type = #PB_String
    *DataSet\Value()\qVal = 0
    *DataSet\Value()\sVal = Value
  EndProcedure
  
  ; ----
  
  Procedure.q Get(*DataSet.udtDataSet, Key.s)
    Protected r1.q
    If FindMapElement(*DataSet\Value(), Key)
      Select *DataSet\Value()\Type
        Case #PB_Word
          r1 = *DataSet\Value()\wVal
        Case #PB_Long
          r1 = *DataSet\Value()\lVal
        Case #PB_Integer
          r1 = *DataSet\Value()\iVal
        Case #PB_Quad
          r1 = *DataSet\Value()\qVal
        Case #PB_Float
          r1 = *DataSet\Value()\fltVal
        Case #PB_Double
          r1 = *DataSet\Value()\dblVal
        Case #PB_String
          r1 = Val(*DataSet\Value()\sVal)
      EndSelect
      ProcedureReturn r1
    Else
      ProcedureReturn 0
    EndIf
  EndProcedure
  
  Procedure.f GetF(*DataSet.udtDataSet, Key.s)
    Protected r1.f
    If FindMapElement(*DataSet\Value(), Key)
      Select *DataSet\Value()\Type
        Case #PB_Word
          r1 = *DataSet\Value()\wVal
        Case #PB_Long
          r1 = *DataSet\Value()\lVal
        Case #PB_Integer
          r1 = *DataSet\Value()\iVal
        Case #PB_Quad
          r1 = *DataSet\Value()\qVal
        Case #PB_Float
          r1 = *DataSet\Value()\fltVal
        Case #PB_Double
          r1 = *DataSet\Value()\dblVal
        Case #PB_String
          r1 = ValF(*DataSet\Value()\sVal)
      EndSelect
      ProcedureReturn r1
    Else
      ProcedureReturn 0
    EndIf
  EndProcedure
  
  Procedure.d GetD(*DataSet.udtDataSet, Key.s)
    Protected r1.d
    If FindMapElement(*DataSet\Value(), Key)
      Select *DataSet\Value()\Type
        Case #PB_Word
          r1 = *DataSet\Value()\wVal
        Case #PB_Long
          r1 = *DataSet\Value()\lVal
        Case #PB_Integer
          r1 = *DataSet\Value()\iVal
        Case #PB_Quad
          r1 = *DataSet\Value()\qVal
        Case #PB_Float
          r1 = *DataSet\Value()\fltVal
        Case #PB_Double
          r1 = *DataSet\Value()\dblVal
        Case #PB_String
          r1 = ValD(*DataSet\Value()\sVal)
      EndSelect
      ProcedureReturn r1
    Else
      ProcedureReturn 0
    EndIf
  EndProcedure
  
  Procedure.s GetStr(*DataSet.udtDataSet, Key.s, Decimals=2)
    Protected r1.s
    If FindMapElement(*DataSet\Value(), Key)
      Select *DataSet\Value()\Type
        Case #PB_Word
          r1 = Str(*DataSet\Value()\wVal)
        Case #PB_Long
          r1 = Str(*DataSet\Value()\lVal)
        Case #PB_Integer
          r1 = Str(*DataSet\Value()\iVal)
        Case #PB_Quad
          r1 = Str(*DataSet\Value()\qVal)
        Case #PB_Float
          r1 = StrF(*DataSet\Value()\fltVal, Decimals)
        Case #PB_Double
          r1 = StrD(*DataSet\Value()\dblVal, Decimals)
        Case #PB_String
          r1 = *DataSet\Value()\sVal
      EndSelect
      ProcedureReturn r1
    Else
      ProcedureReturn ""
    EndIf
  EndProcedure
  
  Procedure GetType(*DataSet.udtDataSet, Key.s)
    If FindMapElement(*DataSet\Value(), Key)
      ProcedureReturn *DataSet\Value()\Type
    Else
      ProcedureReturn 0
    EndIf
  EndProcedure
  
  ; ----
  
  DataSection
    vTable:
    data.i @Free()
    data.i @SetW()
    data.i @SetL()
    data.i @SetI()
    data.i @SetQ()
    data.i @SetF()
    data.i @SetD()
    data.i @SetStr()
    data.i @Get()
    data.i @GetF()
    data.i @GetD()
    data.i @GetStr()
    data.i @GetType()
  EndDataSection
  
EndModule

; ****

CompilerIf #PB_Compiler_IsMainFile
  
  Global.DataSet::iDataSet *Set1, *Set2
  
  *set1 = DataSet::New()
  *set1\SetStr("FirstName", "Michael")
  *set1\SetStr("LastName", "Mustermann")
  *set1\SetStr("Age", "xxx")
  
  Debug "Type " + *Set1\GetType("Age")
  ; Overwrite Age
  *set1\SetI("Age", 55)
  Debug "Type " + *Set1\GetType("Age")
  
  Debug *set1\GetStr("FirstName")
  Debug *set1\GetStr("LastName")
  Debug *set1\GetStr("Age")
  
  ; DateSet key exits
  Debug *set1\GetType("Number")
  
  *set1\SetD("Number", 12.345678)
  Debug *Set1\GetStr("Number", 4)
  
  
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

But what’s the point of posting such code ? :?
It’s even worse here ! :shock:

I already failed with your previous code…
I don’t understand; I really don’t see the point. :|
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: A virtual object manager code

Post by SPH »

I heard that the project would see the light of day in 2027 minimum and that it would never be complete.

Is that true??

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

SPH wrote: Sat Feb 15, 2025 12:52 am I heard that the project would see the light of day in 2027 minimum and that it would never be complete.

Is that true??
SPH, stop trolling, please. It doesn’t help move things forward. What you’re saying makes no sense.
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: A virtual object manager code

Post by SPH »

So when is it coming out?

I am impatient 8)

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: A virtual object manager code

Post by idle »

SPH wrote: Sat Feb 15, 2025 12:52 am I heard that the project would see the light of day in 2027 minimum and that it would never be complete.

Is that true??
SPH I don't think that's a fair comment to make. Constructive criticism is good but don't troll.
I looked at the project and thought that's actually a good result from using an LLM to assist with code
Teach don't taunt, we're always learning!
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: A virtual object manager code

Post by Fred »

SPH wrote: Sat Feb 15, 2025 7:06 am So when is it coming out?

I am impatient 8)
Please stop posting on his topic if you're not interested
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

@ShadowStrom

Maybe let's go back to the basics. Let's don't speak about ojects.
For me it seems we have a different undertanding of objects or what it is exactly.

Let's talk about the Problem what you want to solve - nothing more!.
Just describe the problem not a a way of solutions!
I guess this will bing us to the point. If the problem is clear, we start again to speak about possible solutions!
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

I now understand why the term "Object" is problematic for some of you, if I’ve understood correctly, because it’s often associated with object-oriented programming (OOP) .

Implementing OOP in PureBasic isn’t a straightforward task, and some people have struggled with it!

This can lead to confusion, but whether I call it an object or an entity , it’s essentially the same thing: these are elements I can interact with, store values in, and retrieve values from. However, for now, I’m not using OOP methods. That said, it’s also part of what I want to achieve eventually: each object could have its own methods, such as create, search, destroy, etc.

It’s interesting! I therefore need to find the right approach to design my virtual object manager.

But it must not become too difficult to use. It needs to remain very simple—that’s the goal. Even a beginner should be able to handle it. Therefore, it’s crucial to find the right approach :)
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

Yes, I can confirm all your statements above.

And further more. Finding a good and effective univeral Datastructures is one of the hardest tings.
It's mostly a long way with a lot of changes.

I experimented a lot and now I can describe a way hwo to come to a result.

1. Describing exactly the Problem
2. Prgoraming a test code.
3. Retrun to 1. and adapt the problems descrition.
4. Split the problem down to a set of single universal problems

What's missing now at your code and the code of Editors factory too.
What's the initial problem and what's the concept to solve this problem.
It looks like a little like: "I have a solution! Where is the correct problem for?"

For Managing 'Objects' which have the same base or interface a good way is to
split the Datadefinition in a Base what all types of 'Objects' share

Code: Select all

Structure TObjBase
  x.i
  y.i
  w.i
  h.o
EndStructure

Structure TObjWhatEver Extends TObjBase
  Color.i
  Speed.i
  SomethingMore.i
EndStructure
For an universal Object Manger, you should describe that base and develop only solutions for the base data.
Post Reply