-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
315 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
type Facing uint8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
type Cube struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular_test | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
func (e *Engine) appendObjsInsideRange(objs []*Object, pos Vec3, radius float64) []*Object { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
import ( | ||
|
@@ -125,7 +141,7 @@ func (e *Engine) ForeachObject(cb func(o *Object)) { | |
} | ||
|
||
func (e *Engine) ForeachBlock(cb func(b Block)) { | ||
e.ForeachObject(func(o *Object){ | ||
e.ForeachObject(func(o *Object) { | ||
for _, b := range o.blocks { | ||
cb(b) | ||
} | ||
|
@@ -151,15 +167,19 @@ func (e *Engine) queueEvent(event *eventWave) { | |
func (e *Engine) Tick(dt float64) { | ||
var wg sync.WaitGroup | ||
// tick objects | ||
e.tickLocked(&wg, dt) | ||
e.tickObjectLocked(&wg, dt) | ||
wg.Wait() | ||
|
||
// tick events | ||
e.tickEventLocked(&wg, dt) | ||
wg.Wait() | ||
|
||
// save object status | ||
e.saveStatusLocked(&wg) | ||
// sync object status | ||
e.syncStatusLocked(&wg) | ||
wg.Wait() | ||
} | ||
|
||
func (e *Engine) tickLocked(wg *sync.WaitGroup, dt float64) { | ||
func (e *Engine) tickObjectLocked(wg *sync.WaitGroup, dt float64) { | ||
e.RLock() | ||
defer e.RUnlock() | ||
|
||
|
@@ -170,6 +190,12 @@ func (e *Engine) tickLocked(wg *sync.WaitGroup, dt float64) { | |
o.tick(dt) | ||
}(o) | ||
} | ||
} | ||
|
||
func (e *Engine) tickEventLocked(wg *sync.WaitGroup, dt float64) { | ||
e.RLock() | ||
defer e.RUnlock() | ||
|
||
for _, event := range e.events { | ||
if event.Heavy() { | ||
wg.Add(1) | ||
|
@@ -183,7 +209,7 @@ func (e *Engine) tickLocked(wg *sync.WaitGroup, dt float64) { | |
} | ||
} | ||
|
||
func (e *Engine) saveStatusLocked(wg *sync.WaitGroup) { | ||
func (e *Engine) syncStatusLocked(wg *sync.WaitGroup) { | ||
e.Lock() | ||
defer e.Unlock() | ||
|
||
|
@@ -194,6 +220,7 @@ func (e *Engine) saveStatusLocked(wg *sync.WaitGroup) { | |
o.saveStatus() | ||
}(o) | ||
} | ||
// remove not alive events | ||
for i := 0; i < len(e.events); { | ||
event := e.events[i] | ||
if event.AliveTime() == 0 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
import ( | ||
|
@@ -132,7 +148,6 @@ func (e *Engine) newGravityWave(sender *Object, center Vec3, f *GravityField, ti | |
g := gravityStatusPool.Get().(*gravityStatus) | ||
g.f = *f | ||
g.pos = center | ||
g.gone = false | ||
g.c.Store(1) | ||
maxRadius := -1.0 | ||
if e.cfg.MinAccel > 0 { | ||
|
@@ -143,6 +158,7 @@ func (e *Engine) newGravityWave(sender *Object, center Vec3, f *GravityField, ti | |
for i := (uint16)(2); i != 0 && tick&(i-1) == 0; i <<= 2 { | ||
life++ | ||
} | ||
g.life = life | ||
if life < len(maxRs) { | ||
if maxr := maxRs[life]; maxr < maxRadius { | ||
maxRadius = maxr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular_test | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
import ( | ||
|
@@ -21,7 +37,7 @@ func NewGravityField(mass float64, radius float64) *GravityField { | |
return &GravityField{ | ||
mass: mass, | ||
radius: radius, | ||
rSq: radius * radius, | ||
rSq: radius * radius, | ||
rCube: 1 / (radius * radius * radius), | ||
} | ||
} | ||
|
@@ -65,7 +81,7 @@ type gravityStatus struct { | |
f GravityField | ||
pos Vec3 | ||
|
||
gone bool | ||
life int | ||
c atomic.Int32 | ||
} | ||
|
||
|
@@ -83,7 +99,7 @@ func (s *gravityStatus) clone() (g *gravityStatus) { | |
g = gravityStatusPool.Get().(*gravityStatus) | ||
g.f = s.f | ||
g.pos = s.pos | ||
g.gone = false | ||
g.life = s.life | ||
g.c.Store(1) | ||
return | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
// MaterialProps saves the Material properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// molecular is a 3D physics engine written in Go | ||
// Copyright (C) 2023 Kevin Z <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package molecular | ||
|
||
import ( | ||
|
Oops, something went wrong.