Hey Daniel, All the updates from the engine go into the Updater, so you can check that to just see changes in the model due to commands being run. You could add a breakpoint in the view-controller in the `update()` method to inspect what those updates look like, and see the `update()` method in `agentmodel.coffee` for how the updates are merged. You could create a wrapper around the updater to publish and handle those updates in whatever manner would work easiest for you.
I should add that Galapagos/Beak does re-draw the full view on purpose. There are a lot of fiddly rules about breed order determining which agents are drawn on top of other agents, and rather trying to get those re-drawing "smartly", it's much simpler to just re-draw the whole view correctly. Because the view is small and there are usually not more than a few thousand agents, this doesn't really take long and isn't usually a bottleneck for model simulation speed. I hope that helps! -Jeremy From: <netlogo-devel@googlegroups.com> on behalf of Daniel Graungaard <danielgraunga...@gmail.com> Date: Friday, August 9, 2019 at 8:21 AM To: netlogo-devel <netlogo-devel@googlegroups.com> Subject: Re: [netlogo-devel] Re: Getting Tortoise running on my own machine?! Thank you so much for all your help until now. I have been playing around with the engine for a bit now. I have been looking for something like an observer pattern somewhere, or an equal mechanism where whatever draws the view can subscribe to changes in the engine. Seems a bit cumbersome to poll the engine for changes and redraw everything. Does such a mechanism exist? //Daniel On Friday, 5 July 2019 16:31:16 UTC+2, Jeremy Baker wrote: Hey Daniel, So the Tortoise engine doesn't really know how to draw anything, it just produces model updates that something else can consume and use to visualize the model run. Here is the core loop of NetLogo Web where it generates the updates and dispatches them. Most of the work is done by widgets, as you can see, since forever buttons are the primary way to get a model to do work. https://github.com/NetLogo/Galapagos/blob/e141f9be7d2c851bcd45716aab33bd94c17b7ce5/app/assets/javascripts/beak/session-lite.coffee#L98-L120<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Galapagos_blob_e141f9be7d2c851bcd45716aab33bd94c17b7ce5_app_assets_javascripts_beak_session-2Dlite.coffee-23L98-2DL120&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=idNv4VBiONegY013hILcHgWfoaw8X5Xg6ZgTuFnxjJ8&m=1hzPHNrpe_GBpIupdEV18auFf3QZpZxR3jHurV2ScxU&s=R4SoBZMacj4BxQ5VH-sxUZVYZhQrUZ64CJCag96X_-w&e=> Most of the code for actually drawing to a canvas is in the view controller. You can check out the `update()` method that calls `repaint()` which delegates the work to some sub-components. https://github.com/NetLogo/Galapagos/blob/master/app/assets/javascripts/beak/widgets/draw/view-controller.coffee<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Galapagos_blob_master_app_assets_javascripts_beak_widgets_draw_view-2Dcontroller.coffee&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=idNv4VBiONegY013hILcHgWfoaw8X5Xg6ZgTuFnxjJ8&m=1hzPHNrpe_GBpIupdEV18auFf3QZpZxR3jHurV2ScxU&s=SN6ATIEL0NpPL9Qdw2fHaxY1nNpFaJX5gycIukWFHa4&e=> Re-implementing all of the visualization code would definitely take some work, but Galapagos should be a good reference, and if you're just trying to do something basic like get some turtles to display, that shouldn't be too bad. -Jeremy On Friday, July 5, 2019 at 8:31:39 AM UTC-5, Daniel Graungaard wrote: Hey guys Seems like I am getting some stuff to work and getting an overview of Tortoise in general. I have on more question however: How do I specify a canvas for the engine to draw on? Do you have some code from Galapagos or an other source showing this? //Daniel On Thursday, 4 July 2019 14:14:21 UTC+2, Daniel Graungaard wrote: Hello Jason and Jeremy Thanks so much for your very helpful and detailed replies! Very useful to get an overview of the architecture and pointers to both Galapagos and Tortoise. I'm currently playing a bit more around and making slow progress in my project. //Daniel On Wednesday, 3 July 2019 15:37:34 UTC+2, Jason Bertsche wrote: Your `nlogo` variable needs to contain the string form of a valid NetLogo model file (i.e. a '.nlogo' file). In order to compile code into something useful, NetLogo needs a lot more information than just your procedures (e.g. it needs to know if there are any global variables that are declared in widgets). To make this example of yours work, just get ahold of a '.nlogo' file for a blank model in either NetLogo or NetLogo Web. '.nlogo' files are text files that are delimited by instances of @#$#@#$#@ . Add the code for your NetLogo procedures before the first instance of the delimiter. Then, copy the entire contents of that file as the value for your `nlogo` variable in your JavaScript program, and it should work. On 7/3/2019 6:06 AM, Daniel Graungaard wrote: The answer provided in #3 was exactly what I was looking for. Thanks so much for that. However I keep getting "success false", with the message: "Models must have 12 sections, this had 1". I have looked through both test and code from Galapagos, and have tried different values for the nlogo string. However I keep getting the error. Do you have any idea why or can you provide the format for the nlogo string? I have attached screenshots of my code and outputs below. //Daniel On Wednesday, 3 July 2019 08:40:27 UTC+2, Daniel Graungaard wrote: Hi Jeremy Thank you so much for your very detailed answer. The use case I am working on is closest to #3. I had been looking on Galapagos and Teletortoise (which I know is discontinued) to see if I could come up with how to use tortoise. However your instructions was really helpful. I am going to try them out, and see how it goes. Thank you :) //Daniel On Tuesday, 2 July 2019 23:44:53 UTC+2, Jeremy Baker wrote: Hey Daniel! Welcome. The answer here really depends on what you're trying to use Tortoise for, but I tried to cover the possibilities below. If I missed you're use case, just let me know and I'll try to fill in more details. 0) The first thing I'd point out is that Tortoise is just the compiler and engine for NetLogo Web, it doesn't include any front-end UI or view code. For that, there is Galapagos, which gives a UI for loading models and also runs models, updating a view for them while they go: https://github.com/NetLogo/Galapagos<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Galapagos&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=9m7nuws8obuQj3KVSXKYEe9xN-izRLAG48QZbKMCzVk&s=Z1bdlUpDKPcq5Oe3U9PCl0GS-R3ahfALHIRHg45Mg3w&e=>. If you want to make changes to Tortoise and see those in a front-end, check out the instructions in the Galapagos repo for that: https://github.com/NetLogo/Galapagos/wiki/Contributing#publishing-tortoise-changes<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Galapagos_wiki_Contributing-23publishing-2Dtortoise-2Dchanges&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=9m7nuws8obuQj3KVSXKYEe9xN-izRLAG48QZbKMCzVk&s=bcCJ1ZmUZUwmUc-_BQRNRgeSSBSxWa1w0Q35L2gax-Y&e=> 1) If you're trying to make changes to the Tortoise code to do things like adding features or changing existing primitives, you're probably best served using the tests built into Tortoise in order to "use" it. You can take a look at `Tortoise.txt` to see how add simple NetLogo language tests, or `Model.scala` to add a whole model for testing if you prefer to test that way. More info on tests: https://github.com/NetLogo/Tortoise/wiki/Tortoise-Tests<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Tortoise_wiki_Tortoise-2DTests&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=9m7nuws8obuQj3KVSXKYEe9xN-izRLAG48QZbKMCzVk&s=ACgyvolNMZIoG6uMtDvFwNJRUiQFTrh-EfMvtn7-F7E&e=> 2) If you're trying to compile and run models headless-ly, then I'd recommend using NetLogo desktop, as it's probably going to be better for that purpose than Tortoise, especially with BehaviorSpace. 3) If you're trying to build your own UI around Tortoise from within Javascript (or just want to play with it), then the best reference will probably be the Galapagos project code. The short steps to using the Tortoise compiler and engine from a Javascript runtime (a web page loaded in a browser, Node.js): * Get the `tortoise-engine.js` and `tortoise-compiler.js` files added/loaded to your environment. If you run `netLogoWeb/package` from within sbt, you'll get a copy of those in the `netlogo-web/target/classes` folder to copy off. * Run `var compiler = new BrowserCompiler()` to get a compiler instance to use with NetLogo model code. * Run `var compilation = compiler.fromNlogo(nlogo, [])` where `nlogo` is a string with your NetLogo model code, as if from an `.nlogo` file. There are other methods exposed on `BrowserCompiler` as well: https://github.com/NetLogo/Tortoise/blob/master/compiler/js/src/main/scala/BrowserCompiler.scala<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_NetLogo_Tortoise_blob_master_compiler_js_src_main_scala_BrowserCompiler.scala&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=9m7nuws8obuQj3KVSXKYEe9xN-izRLAG48QZbKMCzVk&s=XrENAwyJW_WinT39cMKVhENq5MchLbdzoLmi1f2C2tU&e=> * Now `compilation` should have some data like `{ model: { success: true, result: jsCode }, widgets: widgetJSONArray }` (assuming success). * You can then use that `compilation.model.result` along with `eval()` to load the generated model Javascript for execution. * Feel free to check out the `compilation.model.result` to see what the generated Javascript for a model looks like. That will help know what you can do with it. * The procedures from the model will be placed in a `procedures` object in the global context (or the context you `eval()` in, really), so you can then do things like `procedures["SETUP"]` or `procedures["GO"]`. * You'll also have a `world` object with some interesting properties, like `world.observer.varNames()` and also a `workspace` with objects and functions needed for the engine to run. That doesn't get you a view or usable widgets or anything like that (see item #0), but will get you a model you can run or mess around with a bit. I hope that helps! -Jeremy On Tuesday, July 2, 2019 at 9:28:32 AM UTC-5, Daniel Graungaard wrote: Hi everybody! I have been trying to get Tortoise to run on my own machine for a couple of days. My plan is to try and use it for a reserach experiment on collaborative computing and CT, so I really need to be able to run it on my own machine /server. As I really want NetLogo to be part of this, Tortoise seemed very promising. I have tried multiple things, including figuring out which version of GraalVM is used, and can now compile everything without errors. However, I have no overview of the project, and no idea about how to actually run the thing. I have been looking for an explanation both in here and in the different repos without luck. Can somebody provide me with a quick intro into how to actually run Tortoise, or point me in the direction of a ressource with an explanation? I have prior experience with java and Nodejs, so I am not looking for a complete tutorial, developement guide or documentation. Just some quick pointers to get over the initial confusion. Really hopes anybody can help me. //Daniel -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlog...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/bbf2bf2a-d4c2-425b-b523-02b68b95faaa%40googlegroups.com<https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_netlogo-2Ddevel_bbf2bf2a-2Dd4c2-2D425b-2Db523-2D02b68b95faaa-2540googlegroups.com-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dfooter&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=9m7nuws8obuQj3KVSXKYEe9xN-izRLAG48QZbKMCzVk&s=Ru1HyD3jgWUg87uub7_wMpklIM-srMoi9hmWf0CxeaM&e=>. -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com<mailto:netlogo-devel+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/6e13ae31-1c90-46bf-871d-fd0547b92e04%40googlegroups.com<https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_netlogo-2Ddevel_6e13ae31-2D1c90-2D46bf-2D871d-2Dfd0547b92e04-2540googlegroups.com-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dfooter&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=idNv4VBiONegY013hILcHgWfoaw8X5Xg6ZgTuFnxjJ8&m=1hzPHNrpe_GBpIupdEV18auFf3QZpZxR3jHurV2ScxU&s=PT-a-aeo43mamHaf-_qiQi5PFq8mLiBPDjxJLsMQKpw&e=>. -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/4BC58017-8F32-4142-8136-6FF1F648928B%40northwestern.edu.