Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VectorShapes are in-extensibly hard-coded everywhere #509

Open
elfprince13 opened this issue Nov 21, 2013 · 8 comments
Open

VectorShapes are in-extensibly hard-coded everywhere #509

elfprince13 opened this issue Nov 21, 2013 · 8 comments

Comments

@elfprince13
Copy link

I started working on an extension to allow raster shapes for agents (i.e. turtles), and have run into a couple problems:

a) Even though there is a generic shape class, everything seems hard coded to use the VectorShape subclass
b) similarly, the shape-parsing code seems extensible, except that calls to VectorShape's parser also seem hard-coded
c) there's no access to the rasterization stage of the graphics layer without a Context (this seems like something Graphics2DWrapper should expose, even if GraphicsInterface doesn't).
d) none of the previous would be problematic (even if a BitmapShape that subclasses VectorShape is a little odd), except that there is also no way to pass shape references directly, because they're all stored and referenced by name, and Context also doesn't appear any to offer any handle to a ShapeManager where they could be injected

@elfprince13
Copy link
Author

I could fix some of these issues in a private build, but that sort of defeats the purpose of releasing an extension.

@SethTisue
Copy link
Collaborator

I agree, this isn't currently possible from an extension. In general, NetLogo's 2D and 3D rendering pipelines aren't customizable at all. We'd need a whole new API for that. It seems unlikely to happen, unless funding were involved, since most of our development effort is going into Tortoise these days.

One workaround is for an extension to give up on customizing the main view, and instead just open a separate window and do all of your own rendering in it. (@cbradyatinquire is currently doing some alternative visualization work this way.)

In your case in particular, consider writing an extension primitive that renders a raster shape directly to the drawing layer, a la http://evolve.lse.ac.uk/NetLogo/extensions/Simulations-NetLogo%20Extensions.php . In order to use this as a substitute for turtle shapes, you'd need to do clear-drawing before each tick ends and then re-draw each turtle. Sounds slow, but I think this trick could actually perform reasonably well — certainly well enough for a simple game or HubNet activity (without view mirroring) — assuming your code keeps the BufferedImages it's rendering cached and ready to transfer to the drawing layer with a single call.

@elfprince13
Copy link
Author

Do I really need to clear-drawing, or can I just do something like

   ask turtles [
        set hidden true
   ]

ask turtles [
    draw-sprite "some identifier (or even an object)"
]

?

@SethTisue
Copy link
Collaborator

The purpose of clear-drawing would be to erase the sprites in their previously drawn positions.

@elfprince13
Copy link
Author

right, that makes sense, I was forgetting that the screen area is not fully redrawn at each tick.

@SethTisue
Copy link
Collaborator

The drawing layer is an offscreen bitmap that holds the marks made by such primitives as pen-down, stamp, and import-drawing. The contents of the drawing layer persists from tick to tick, until cleared by clear-drawing or clear-all.

The view as a whole is fully redrawn at each tick — including transferring the current contents of the drawing layer to the screen, but also including rendering the patches, turtles, and links.

(Can't tell from your wording if you were actually in need of this clarification, but, offering it just in case.)

@SethTisue
Copy link
Collaborator

@elfprince13 has added a bitmap-shapes extension to https://github.com/NetLogo/NetLogo/wiki/Extensions (called “BMPSprites")

@elfprince13
Copy link
Author

Fair warning: the extension works fairly well, but isn't the most elegant solution in the world, largely due to the issues discussed here. Hopefully though if anyone else tries the same thing, they'll be able to make use of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants