Recent

Author Topic: Flock of Birds (boids) With Class and operation overloading takes too much mem  (Read 931 times)

Dzandaa

  • Full Member
  • ***
  • Posts: 208
  • From C# to Lazarus
Hi

This is a demonstration showing a Flock of Birds based on Boids artificial life program created by Craig Reynolds.

Using OpenGL, work on Linux and Windows.

https://en.wikipedia.org/wiki/Boids

Have fun.

B->

« Last Edit: December 05, 2023, 04:04:39 pm by Dzandaa »
Dzandaa

Dzandaa

  • Full Member
  • ***
  • Posts: 208
  • From C# to Lazarus
Re: Flock of Birds (boids) With records instead of class
« Reply #1 on: December 04, 2023, 04:56:35 pm »
Hi again,

I realize that I Didn't manage well operator overloading with a Class (memory eating!!!)

This version is just using records.

B->

« Last Edit: December 05, 2023, 04:05:38 pm by Dzandaa »
Dzandaa

cdbc

  • Hero Member
  • *****
  • Posts: 974
    • http://www.cdbc.dk
Re: Flock of Birds
« Reply #2 on: December 04, 2023, 05:08:23 pm »
Hi
Memory eating... You think  :D
The first version just "bricked" my lappy  >:D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Dzandaa

  • Full Member
  • ***
  • Posts: 208
  • From C# to Lazarus
Re: Flock of Birds
« Reply #3 on: December 04, 2023, 05:30:05 pm »
Hi,
@cbdc

I'm very sorry for that!!!

I didn't find any example with operator overloading in a class.

Just overloading of Records.

The problem come with vector2u.

If anybody have an example with overloading operators in classes, I'm interested (Form based application)

Example:

Code: Pascal  [Select][+][-]
  1. operator + (const V1: Vector2; Val: Single): Vector2;
  2. begin
  3. //      result.X := V1.X + Val; // <-- Solution one crashes because result is not initialized.
  4. //      result.Y := V1.Y + Val;
  5.  exit(Vector2.Create(V1.X + Val, V1.Y + Val)); // Solution 2 works but didn't free the memory
  6. end;
  7.  

B->
Dzandaa

MarkMLl

  • Hero Member
  • *****
  • Posts: 6579
Re: Flock of Birds
« Reply #4 on: December 05, 2023, 02:08:05 pm »
"Bricked"? Rendered indistinguishable from a boat anchor? Surely not... :-)

@Dzandaa You should have put "boids" in the subject line: I'm sure I'm not the only person around here who'd understand the allusion. I remember when this was first discussed in the late 80s, and always find myself thinking of it when I see something like the Rutan Ares.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018