Skip to content

Commit

Permalink
add license header
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Dec 11, 2023
1 parent e816330 commit 23fadfb
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 42 deletions.
16 changes: 16 additions & 0 deletions block.go
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
Expand Down
16 changes: 16 additions & 0 deletions box.go
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 {
Expand Down
16 changes: 16 additions & 0 deletions box_test.go
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 (
Expand Down
16 changes: 16 additions & 0 deletions conflict.go
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 {
Expand Down
39 changes: 33 additions & 6 deletions engine.go
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 (
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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()

Expand All @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion event.go
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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions event_test.go
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 (
Expand Down
22 changes: 19 additions & 3 deletions force.go
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 (
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -65,7 +81,7 @@ type gravityStatus struct {
f GravityField
pos Vec3

gone bool
life int
c atomic.Int32
}

Expand All @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions matter.go
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
Expand Down
16 changes: 16 additions & 0 deletions motion.go
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 (
Expand Down
Loading

0 comments on commit 23fadfb

Please sign in to comment.