Forum Replies Created
-
AuthorPosts
-
Interesting read! I was wondering why it worked with lists (in Blitz), and noticed they were also ‘failing’ in mx2 the way stacks do. (I’d tried switching the above code to a list.)
The pb.Destroy () / boxes.Clear () option works well here for the Space-bar hit, but what would be the best way to handle removing an object mid-iteration, as UpdateBoxes () — minus boxes.Remove (pb) — still crashes, obviously for the reasons you’ve explained, since it’s not emptying the whole stack like Space does.
Thinking about it, I suppose a stack isn’t the best solution for this scenario, ie. removing arbitrary objects from the middle of a collection, since stacks are all about adding/removing at the top of the stack, but what would be better here?
(I just used a stack because I gather they’re quicker than lists!)
That stack-top popping-copying thing is pretty cool, but I guess maybe a map could be a better overall solution?
Hmm, thanks, nerobot. It’s quite complex, but seems to do the job anyway. I’ll try understand it!
Cool, I had to not-New it, too (suspected so), but it’s working now with:
Monkey123456Function Main ()Local proc:PROCESSENTRY32Wproc.dwSize = libc.sizeof (proc)Print proc.dwSizeEndThanks!
This is pretty cool, but I can’t figure out how to delete/remove RigidBodies… see KeyHit (Key.Space). I’m trying to clear my stack of PhysBoxes (containing RigidBody and Model references), but they always remain! Perhaps not implemented yet? There is code that looks intended to work in RigidBody.OnDestroy…
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Class PhysBoxField box:BoxfField model:ModelField collider:BoxColliderField body:RigidBodyMethod New (width:Float = 1, height:Float = 1, depth:Float = 1, mass:Float = 1, material:Material = Null, group:Int = 1, mask:Int = 1)If Not materialmaterial = New PbrMaterial (Color.Red)Endifbox = New Boxf (-width * 0.5, -height * 0.5, -depth * 0.5, width * 0.5, height * 0.5, depth * 0.5)model = Model.CreateBox (box, 8, 8, 8, material)collider = New BoxCollider (model)body = New RigidBody (model)collider.Box = boxbody.Mass = massbody.CollisionGroup = groupbody.CollisionMask = maskEndMethod Move (x:Float, y:Float, z:Float)model.Move (x, y, z)EndMethod Rotate (pitch:Float, roll:Float, yaw:Float, localspace:Bool = False)model.Rotate (pitch, roll, yaw, localspace)EndEndClass Game Extends WindowConst CAMERA_MOVE:Float = 0.05Const SHIFT_BOOST:Float = 4.0Field cam_boost:Float = 1.0Field scene:SceneField cam:CameraField light:LightField ground:PhysBoxField boxes:Stack <PhysBox>Method New (title:String, width:Int, height:Int, flags:WindowFlags)Super.New (title, width, height, flags)SwapInterval = 1CreateArena ()EndMethod CreateArena:Void ()SeedRnd (Millisecs ())scene = Scene.GetCurrent ()ground = New PhysBox (100, 1, 100, 0, New PbrMaterial (Color.Green * 0.25))cam = New Cameralight = New Lightscene.AmbientLight = Color.White * 0.75scene.ClearColor = Color.Sky * 0.75cam.FOV = 100cam.Move (0, 20, -20)ground.Move (0, -5, 0)cam.Near = 0.01cam.Far = 1000light.CastsShadow = Truelight.Range = 1000light.Move (0, 50, 10)cam.PointAt (ground.model)light.PointAt (ground.model)SpewBoxes (200)EndMethod SpewBoxes (num:Int)boxes = New Stack <PhysBox>For Local loop:Int = 1 To numLocal scale:Float = Rnd (0.5, 4.0)Local color:Color = New Color (Rnd (0.4, 1.0), Rnd (0.4, 1.0), Rnd (0.4, 1.0))' Just for clarity in New below...Local dimension:Float = scaleLocal mass:Float = scaleLocal pb:PhysBox = New PhysBox (dimension, dimension, dimension, mass, New PbrMaterial (color))pb.Move (Rnd (-10, 10), Rnd (100), Rnd (-10, 10))' *** Set loop to max 1 and enable this -- physics mesh still appears unturned when settled!' pb.Rotate (45, 45, 45)NextEndMethod UpdateGame ()If Keyboard.KeyHit (Key.Escape)App.Terminate ()EndifIf Keyboard.KeyHit (Key.S)light.CastsShadow = Not light.CastsShadowEndifIf Keyboard.KeyHit (Key.Space)For Local pb:PhysBox = Eachin boxes' *** HELP! ***' pb.body.Destroy () ' er, = Null? OnDestroy? Um...' How about, per http://monkeycoder.co.nz/forums/topic/cast-object-to-int-handle-and-back/#post-10084pb.model.Destroy () ' Nope, all there!Nextboxes.Clear () ' Nah, bodies remain in Bullet! Prob need to destroy entities too...Print boxes.LengthSpewBoxes (200)EndifIf Keyboard.KeyDown (Key.LeftShift)cam_boost = SHIFT_BOOSTElsecam_boost = 1.0EndifIf Keyboard.KeyDown (Key.A)cam.Move (0.0, 0.0, CAMERA_MOVE * cam_boost)EndifIf Keyboard.KeyDown (Key.Z)cam.Move (0.0, 0.0, -CAMERA_MOVE * cam_boost)EndifIf Keyboard.KeyDown (Key.Left)cam.Rotate (0.0, 1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Right)cam.Rotate (0.0, -1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Up)cam.Rotate (1.0, 0.0, 0.0, True)EndifIf Keyboard.KeyDown (Key.Down)cam.Rotate (-1.0, 0.0, 0.0, True)EndifEndMethod ShadowText:Void (canvas:Canvas, s:String, x:Float, y:Float)canvas.Color = Color.Blackcanvas.DrawText (s, x + 1, y + 1)canvas.Color = Color.Whitecanvas.DrawText (s, x, y)EndMethod RenderText (canvas:Canvas)ShadowText (canvas, "FPS: " + App.FPS, 20.0, 20.0)ShadowText (canvas, "A/Z + Cursors to move camera", 20.0, 40.0)ShadowText (canvas, "SHIFT to boost", 20.0, 60.0)ShadowText (canvas, "SPACE to spew boxes", 20.0, 80.0)ShadowText (canvas, "S to toggle shadows", 20.0, 100.0)EndMethod OnRender (canvas:Canvas) OverrideUpdateGame ()RequestRender ()scene.Update ()scene.Render (canvas, cam)RenderText (canvas)EndEndFunction Run3D (title:String, width:Int, height:Int, flags:WindowFlags = WindowFlags.Center)New AppInstanceNew Game (title, width, height, flags)App.Run ()EndFunction Main ()Run3D ("3D Scene", 960, 540, WindowFlags.Center) ' 1/4 HD!' Run3D ("3D Scene", 1920, 1080, WindowFlags.Fullscreen)EndRotation doesn’t work, either, as the RigidBody doesn’t pick up the Model’s rotation, which I suppose it to be expected, though it picks up position. Not sure how this should be handled…
Sorted this — turned out to be the order in which I was declaring the Boxf parameters at start of PhysBox.New ()!
Was:
Monkey1box = New Boxf (-width * 0.5, height * 0.5, depth * 0.5, width * 0.5, -height * 0.5, -depth * 0.5)… but should be:
Monkey1box = New Boxf (-width * 0.5, -height * 0.5, -depth * 0.5, width * 0.5, height * 0.5, depth * 0.5)This revised version gives me “Translator.Trans() Internal Error”:
Monkey1234567891011121314151617181920212223242526272829303132333435#Import "<std>"#Import "<windows.h>"#Import "<tlhelp32.h>"Using std..ExternConst MAX_PATH:IntStruct PROCESSENTRY32WField dwSize:UIntField cntUsage:UIntField th32ProcessID:UIntField th32DefaultHeapID:ULong PtrField th32ModuleID:UIntField cntThreads:UIntField th32ParentProcessID:UIntField pcPriClassBase:LongField dwFlags:UIntField szExeFile:UShort PtrEndPublicFunction Main ()Local proc:PROCESSENTRY32W = New PROCESSENTRY32Wproc.dwSize = libc.sizeof (PROCESSENTRY32W)EndThis says…
Monkey1234567891011121314Mx2cc version 1.1.09***** Making app 'I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.monkey2' (windows release x86 gcc) *****Parsing...Semanting...Translating...? [?] : Error : Translator.Trans() Internal Error***** Uncaught Monkey 2 Throwable *****Done.Turns out that’s the error the first version gave, it was just that the output was hidden.
I get various different internal errors depending on what I do in Main with that last code…
This builds OK, but obviously does nothing:
Monkey1234Function Main ()Local proc:PROCESSENTRY32WEndNew’ing produces a different error:
Monkey1234Function Main ()Local proc:PROCESSENTRY32W = New PROCESSENTRY32WEndOutput for this is:
Monkey1234567891011121314151617181920212223242526Mx2cc version 1.1.09***** Making app 'I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.monkey2' (windows release x86 gcc) *****Parsing...Semanting...Translating...Compiling...Build error: System command failed:g++ -c -std=c++11 -D_WIN32_WINNT=0x0603 -m32 -O3 -DNDEBUG -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/modules/" -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/modules/monkey/native" -I"I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/" -DBB_NEWREFLECTION -I"I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.buildv1.1.09/windows_release/build/" -o "I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.buildv1.1.09/windows_release/build/win32_04proc32_0win32_04proc32.cpp.o" "I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.buildv1.1.09/windows_release/src/win32_4proc32_win32_4proc32.cpp"I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.buildv1.1.09/windows_release/src/win32_4proc32_win32_4proc32.cpp: In function 'void bbMain()':I:/SpiderOak/DevTools/Monkey2/monkey2-develop/modules/mojo3d/tests/win32 proc32.buildv1.1.09/windows_release/src/win32_4proc32_win32_4proc32.cpp:13:52: error: cannot convert 'bbNullCtor_t' to 'DWORD {aka long unsigned int}' in initializationPROCESSENTRY32W l_proc=PROCESSENTRY32W{bbNullCtor};^***** Fatal mx2cc error *****Internal mx2cc build error… and adding the sizeof line gives the “Translator.Trans() Internal Error”:
Monkey12345Function Main ()Local proc:PROCESSENTRY32W = New PROCESSENTRY32Wproc.dwSize = libc.sizeof (PROCESSENTRY32W)EndTried without New as well, but assume that is needed… same Trans() error anyway…
Monkey12345Function Main ()Local proc:PROCESSENTRY32Wproc.dwSize = libc.sizeof (PROCESSENTRY32W)EndOK, will give that a shot later. Didn’t even realise there were W versions of Win32 structs!
Thanks, Mark — thy are both 1 at the moment, but aren’t colliding in this demo. Will be playing again tonight though, no doubt.
It is.
Got this working using Diffrenzy’s HWND hack here.
I did try Aliasing it as Void Ptr, which I thought would work, as HWND is a HANDLE, which is a void pointer according to Windows Data Types
Monkey123456789101112131415161718192021#Import "<libuser32.a>"#Import "<windows.h>"ExternStruct HWND__EndAlias HWND:HWND__ PtrFunction MessageBoxA:Int (hWnd:HWND, lpText:CString, lpCaption:CString, uType:Int)PublicFunction Main:Void ()MessageBoxA (Null, "Test", "Test", 0)EndThis no longer builds here (your code), gving a load of output I don’t really understand! Just ran into it while trying to do something else (around 6 hours trying to debug Ted2Go debugger crashes!)…
Monkey1234567891011121314151617181920212223242526272829303132333435363738Mx2cc version 1.1.09***** Making app 'I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.monkey2' (windows debug x86 gcc) *****Parsing...Semanting...Translating...Compiling...Build error: System command failed:g++ -c -std=c++11 -D_WIN32_WINNT=0x0603 -m32 -Os -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/modules/" -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/modules/monkey/native" -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/" -DBB_NEWREFLECTION -I"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/build/" -o "I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/build/untitled2_0untitled2.cpp.o" "I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/src/untitled2_untitled2.cpp"I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/src/untitled2_untitled2.cpp: In function 'void bbMain()':I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/src/untitled2_untitled2.cpp:15:15: error: invalid conversion from 'bbInt {aka int}' to 'HWND {aka HWND__*}' [-fpermissive]MessageBoxA(bbInt(0),bbCString(bbString(L"Test",4)),bbCString(bbString(L"Test",4)),bbInt(0));^~~~~~~~In file included from I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/devtools/i686-6.2.0-posix-dwarf-rt_v5-rev1/mingw32/i686-w64-mingw32/include/windows.h:72:0,from I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/include/untitled2_untitled2.h:6,from I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/tmp/untitled2.buildv1.1.09/windows_debug/src/untitled2_untitled2.cpp:2:I:/SpiderOak/DevTools/Monkey2/mx2builder/monkey2/devtools/i686-6.2.0-posix-dwarf-rt_v5-rev1/mingw32/i686-w64-mingw32/include/winuser.h:3563:25: note: initializing argument 1 of 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)'WINUSERAPI int WINAPI MessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType);^~~~~~~~~~~***** Fatal mx2cc error *****Internal mx2cc build errorI’m on latest dev, though last one fails too.
OK… that looks to be it — with SwapInterval=1, cubes runs at around 4-5% total CPU now (that would be maybe 20% on a single CPU), obviously much better, though if nothing’s going on I’d have thought it’d be near zero. Maybe that’s mostly the driver stuff, though? [EDIT: It is… ]
I did find a cool little profiler while trying to determine which thread was doing the most work:
It’s pretty cool — you highlight the process of interest, then either profile all threads, or the one(s) you’re interested in, leave it a few seconds and stop it, then you get a list of functions that are being called, and for how long (much better function list if you download the symbols first and run the game in debug mode).
Kinda hard to make much practical sense of, but running in release mode, then just highlighting the cubes process and watching the thread usage is kind of interesting (see image vsleepy.jpg). It shows WaitForSingleObject as a key busy-function (right-hand pane), and if I profile that, I get vsleepy2.jpg, which seems to suggest DrvValidateVersion as the caller, and a quick Google says that’s part of the driver.
I checked the only other high-usage thread showing in vsleepy.jpg — everything else being basically 0% — and that’s also driver-related (DrvPresentBuffers and DrvValidateVersion), so it seems all of that CPU usage is down to Nvidia.
Anyway, that has basically solved it, way better than before, been running for a while now and fans are much quieter!
Well sorted!
Regarding the 1060, it’s a pretty good card for 1080p stuff, runs most things very well. Does 4k, but you have to turn most things down for that. Just saw on PCGamer that it’s currently the most-used graphics card on Steam!
Oh, I had vsync set to use app setting already… however, just tried commenting out SwapInterval=1 in cubes, and it does do the lower CPU usage, so sounds like that’s actually working! Which doesn’t explain last night’s results/screenshots… er… ?
Treat as resolved for now!
Attachments:
Being the bearer of bad news, I apologise… but cubes shows higher CPU here (actually more than 1 CPU, somehow, average about 26%, seen 28%), while the code at the top shows almost 0!
It was typically 16-17% before, which at least makes sense for full 1 x CPU usage. Perhaps it’s now somehow using another couple of threads?
EDIT: Er, it’s using way less threads, but more CPU… see attachments!
Both are in Release mode.
Perhaps cubes is doing heavy stuff in main loop, though it doesn’t look like it (not checked code, gotta go to bed for work!).
The changes obviously do something really weird with threads…
Just re-run both current and last develops to check again, definitely per screenshots, ie. old has 16-17% (1 x CPU) and new has 26-27% (2-3 CPUs), with old having ~twice as many threads! Both in Release.
Just building, will post before hitting the hay!
-
AuthorPosts



