HELP! - how to do this with an array of data.

Advanced game related topics
russellbdavis
User
User
Posts: 31
Joined: Wed Dec 02, 2009 4:50 pm
Location: Oklahoma City, OK
Contact:

HELP! - how to do this with an array of data.

Post by russellbdavis »

Okay, I've hit a dilema.

I need to store a series of polyline shapes that are defined as a list of x/y coordinates. These represent the locations of coordinates for each point in an irregular 2d shape. In VB, I was drawing a series of shapes and filling them with a color. It's for a mapping display showing buildings. Each building outline is drawn and then filled.

I had created a structure such as:
structure pts
x.f
y.f
endstructure

Define bldgs.pts(0)

Then, as I read the data file, "999" is used as a flag for the end of each segment.

I would read the datafile and continue to add the points to the bldgs() array until "999" was encountered".

In VB, I would then add the entire bldgs.pts() array to a collection called allpoints() say. So allpoints(0) would contain multiple copies of bldgs() with different sets of points.

I would then use For Each to draw the polyline segments of each building from the allpoints() collection.

How can I do this with Purebasic? I need an an array of a structured array; something like;

structure pts
x.f
y.f
endstructure

Define points.pts(0) ; first create the structure to hold the points.

Define bldgs().points ; then an array to hold the collection of points.

Here is the actual VB.NET code

Code: Select all

Here is the actual VB.NET code

	Public gdiBLDGS As New Collection 'this is a collection of point arrays

        Dim Temppts(0) As PointF
        Dim x1 As Single
        Dim y1 As Single
        Dim ub As Int32
        Dim FileName$ = TowerPath + "\asde_bldgs.srq"
        ' Open file.
        FileOpen(1, FileName$, OpenMode.Input)
        ' Loop until end of file.
        ub = 0
        Do While Not EOF(1)
            ' Read line into variable.
            Input(1, x1)
            Input(1, y1)
            If x1 = 999 And y1 = 999 Then
                gdiBLDGS.Add(Temppts)
                ub = 0
                'clear the temppts array
                ReDim Temppts(0)
            Else
                ReDim Preserve Temppts(ub)
                Temppts(ub).X = x1 + 288.81145 '293.81145
                Temppts(ub).Y = Abs(y1 + -88.59055) '-91.59055)
                ub = ub + 1
            End If
        Loop
        FileClose(1)
So, any ideas of how to handle this would be appreciated.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: HELP! - how to do this with an array of data.

Post by idle »

something like this using lists would be easier

Code: Select all

Structure pts 
   x.f
   y.f 
EndStructure   

Structure building 
   List pts.pts() 
EndStructure 

Structure buildings 
   List building.building() 
EndStructure    

Global colbuildings.buildings()
InitializeStructure(@colbuildings,buildings) 

Procedure readbuildings(file.s) 
   Protected pts.pts,fn    
   
   fn = OpenFile(#PB_Any,file) 
   If fn 
      While Not Eof(fn)
         pts\x = ReadFloat(fn) 
         pts\y = ReadFloat(fn) 
         If Int(pts\x) = 999 And Int(pts\y) =999 
            AddElement(colbuildings\building()) 
         Else 
            AddElement(colbuildings\building()\pts()) 
            colbuildings\building()\pts()\x = pts\x
            colbuildings\building()\pts()\y = pts\y 
         EndIf 
      Wend
      CloseFile(fn) 
   EndIf   
EndProcedure 

Procedure plotbuilding() 
   Protected x.f,y.f,x1.f,y1.f  
   
   ForEach colbuildings\building() 
      ForEach colbuildings\building()\pts() 
         x1 = x 
         y2 = y 
         x = colbuildings\building()\pts()\x 
         y = colbuildings\building()\pts()\y  
         If Int(x1) <> 0 Or Int(y1) <> 0   
            ;plot 
         EndIf    
      Next
      x1=0
      y1=0  
   Next 
EndProcedure   


Windows 11, Manjaro, Raspberry Pi OS
Image
russellbdavis
User
User
Posts: 31
Joined: Wed Dec 02, 2009 4:50 pm
Location: Oklahoma City, OK
Contact:

Re: HELP! - how to do this with an array of data.

Post by russellbdavis »

Thank you very much. I will give this a shot.
Post Reply