mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Build script + rename tag release->nmage_release+protect against invalid physx use
This commit is contained in:
28
build.sh
Executable file
28
build.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo -e "1) Build Debug mode\n2) Build Release mode"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mode=$1
|
||||
if [[ $mode -eq 1 ]]; then
|
||||
|
||||
./switch-physx-mode.sh 1
|
||||
go build .
|
||||
echo "Debug build finished"
|
||||
|
||||
elif [[ $mode -eq 2 ]]; then
|
||||
|
||||
./switch-physx-mode.sh 2
|
||||
go build -tags "nmage_release,physx_release" .
|
||||
echo "Release build finished"
|
||||
|
||||
else
|
||||
|
||||
echo "Unknown build option. Please select 1 for a Debug build or 2 for a Release build"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build !release
|
||||
//go:build !nmage_release
|
||||
|
||||
package consts
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//go:build release
|
||||
//go:build nmage_release
|
||||
|
||||
package consts
|
||||
|
||||
|
||||
@ -172,6 +172,7 @@ func createWindow(title string, x, y, width, height int32, flags WindowFlags, re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
win.SDLWin.GLSwap()
|
||||
return win, err
|
||||
}
|
||||
|
||||
|
||||
4
go.mod
4
go.mod
@ -9,8 +9,8 @@ require github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
|
||||
require (
|
||||
github.com/bloeys/assimp-go v0.4.4
|
||||
github.com/bloeys/gglm v0.43.0
|
||||
github.com/bloeys/physx-go v0.2.0
|
||||
github.com/inkyblackness/imgui-go/v4 v4.6.0
|
||||
github.com/bloeys/physx-go v0.1.2
|
||||
)
|
||||
|
||||
// replace github.com/bloeys/physx-go => ../physx-go
|
||||
// replace github.com/bloeys/physx-go => ../physx-go
|
||||
|
||||
8
go.sum
8
go.sum
@ -2,12 +2,8 @@ github.com/bloeys/assimp-go v0.4.4 h1:Yn5e/RpE0Oes0YMBy8O7KkwAO4R/RpgrZPJCt08dVI
|
||||
github.com/bloeys/assimp-go v0.4.4/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0=
|
||||
github.com/bloeys/gglm v0.43.0 h1:ZpOghR3PHfpkigTDh+FqxLsF0gN8CD6s/bWoei6LyxI=
|
||||
github.com/bloeys/gglm v0.43.0/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
|
||||
github.com/bloeys/physx-go v0.1.0 h1:/Zon+zt05hPfCo3gFTbFeZ1PJAGc/pFDyLIiO+V9n4M=
|
||||
github.com/bloeys/physx-go v0.1.0/go.mod h1:NeG0fl0thLNfZNXkPPZF1dpZpB57BT8MUOdtdCxQSBw=
|
||||
github.com/bloeys/physx-go v0.1.1 h1:gFUfn3PAuqENStxtFfc2W6bVJXEhiQNYOBm+KlffHv8=
|
||||
github.com/bloeys/physx-go v0.1.1/go.mod h1:NeG0fl0thLNfZNXkPPZF1dpZpB57BT8MUOdtdCxQSBw=
|
||||
github.com/bloeys/physx-go v0.1.2 h1:an/8R/QHMiysd2IcviAIVmgwzXRl7fSqiTSNPzi0qzk=
|
||||
github.com/bloeys/physx-go v0.1.2/go.mod h1:NeG0fl0thLNfZNXkPPZF1dpZpB57BT8MUOdtdCxQSBw=
|
||||
github.com/bloeys/physx-go v0.2.0 h1:zsjskoPFlH7m8hKnlCsJ4hVKe8ys2s1fLEhcNDfofS4=
|
||||
github.com/bloeys/physx-go v0.2.0/go.mod h1:YNt5tX4T8d/4RdldvpWc77DeHM4jqlIunUQUi/rqSKA=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
|
||||
|
||||
10
main.go
10
main.go
@ -224,7 +224,7 @@ func (g *OurGame) Init() {
|
||||
TypicalObjectLength: 1,
|
||||
TypicalObjectSpeed: 9.81,
|
||||
|
||||
EnableVisualDebugger: true,
|
||||
EnableVisualDebugger: pgo.PvdSupported,
|
||||
VisualDebuggerHost: "127.0.0.1",
|
||||
VisualDebuggerPort: 5425,
|
||||
VisualDebuggerTimeoutMillis: 10_000,
|
||||
@ -233,12 +233,8 @@ func (g *OurGame) Init() {
|
||||
VisualDebuggerTransmitSceneQueries: true,
|
||||
|
||||
SceneGravity: gglm.NewVec3(0, -9.81, 0),
|
||||
// @TODO: This has to be zero because PhysX is deciding to throw 'Exception 0x406d1388' when creating threads.
|
||||
// This exception is used to provide debuggers with thread names :)
|
||||
// I don't know why it thinks we are running a debugger, but this doesn't happen in physx-go.
|
||||
// To fix it either we run in a debugger, which will handle the exception for us, or we set this
|
||||
// to zero and run everything on the main thread
|
||||
SceneCPUDispatcherThreads: 0,
|
||||
|
||||
SceneCPUDispatcherThreads: 2,
|
||||
SceneContactHandler: g.PhysxContactHandler,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
"github.com/bloeys/nmage/logging"
|
||||
"github.com/bloeys/physx-go/pgo"
|
||||
)
|
||||
|
||||
@ -40,6 +41,12 @@ type PhysXCreationOptions struct {
|
||||
|
||||
func NewPhysx(options PhysXCreationOptions) (px *PhysX, err error) {
|
||||
|
||||
if options.EnableVisualDebugger && !pgo.PvdSupported {
|
||||
return nil, errors.New("can not enable PhysX visual debugger (PVD) because physx-go is in release mode. Please build without the 'physx_release' tag")
|
||||
}
|
||||
|
||||
logging.InfoLog.Printf("Initializing PhysX. Worker threads: %d. PVD supported: %v\n", options.SceneCPUDispatcherThreads, pgo.PvdSupported)
|
||||
|
||||
// Setup foundation, pvd, and physics
|
||||
px = &PhysX{}
|
||||
px.Foundation = pgo.CreateFoundation()
|
||||
@ -66,7 +73,6 @@ func NewPhysx(options PhysXCreationOptions) (px *PhysX, err error) {
|
||||
sd.SetOnContactCallback(options.SceneContactHandler)
|
||||
|
||||
px.Scene = px.Physics.CreateScene(sd)
|
||||
|
||||
if options.EnableVisualDebugger {
|
||||
|
||||
scenePvdClient := px.Scene.GetScenePvdClient()
|
||||
|
||||
38
switch-physx-mode.sh
Executable file
38
switch-physx-mode.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo -e "1) Checked mode\n2) Release mode"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mode=$1
|
||||
physxBinDir="../physx/physx/bin/win.x86_64.vc142.mt"
|
||||
physxCBinDir="../physx-c/x64"
|
||||
if [[ $mode -eq 1 ]]; then
|
||||
|
||||
physxCheckedBinDir="$physxBinDir/checked"
|
||||
cp "$physxCheckedBinDir/PhysX_64.dll" "$physxCheckedBinDir/PhysXCommon_64.dll" "$physxCheckedBinDir/PhysXFoundation_64.dll" .
|
||||
|
||||
physxCCheckedBinDir="$physxCBinDir/Checked"
|
||||
cp "$physxCCheckedBinDir/physx-c.dll" .
|
||||
|
||||
echo "Switched PhysX to Checked mode"
|
||||
|
||||
elif [[ $mode -eq 2 ]]; then
|
||||
|
||||
physxReleaseBinDir="$physxBinDir/release"
|
||||
cp "$physxReleaseBinDir/PhysX_64.dll" "$physxReleaseBinDir/PhysXCommon_64.dll" "$physxReleaseBinDir/PhysXFoundation_64.dll" .
|
||||
|
||||
physxCReleaseBinDir="$physxCBinDir/Release"
|
||||
cp "$physxCReleaseBinDir/physx-c.dll" .
|
||||
|
||||
echo "Switched PhysX to Release mode"
|
||||
|
||||
else
|
||||
|
||||
echo "Unknown mode. Please select 1 or 2"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
Reference in New Issue
Block a user