Giter VIP home page Giter VIP logo

Comments (3)

DjCrqss avatar DjCrqss commented on April 27, 2024

I tried lifting it out like so (partial code snippet)

    export default function Renderer() {
    // Redux store
    const background = useSelector((state) => state.world.background);
    const images = useSelector((state) => state.images.loadedImages);
    const unloadedImages = useSelector((state) => state.images.unloadedImages);
    const editorMode = useSelector((state) => state.client.editorMode);
    const {mapScale, windowHeight, windowWidth, panX, panY} = useSelector((state) => state.client);
    const dispatch = useDispatch();

    // get user setttings fil;
    const userSettings = require('../assets/world/settings.json');

    // state variables
    const EDITOR_GRID = {
        // editor grid size
        // TODO: move to worldSlice
        x: userSettings.gridColumns || 56,
        y: userSettings.gridRows || 36,
        tilesize: userSettings.tileSize || 6,
        // editor bounds
        left: -1,
        right: -1,
        top: -1,
        bottom: -1,
    }
    return (
        <ReactP5Wrapper sketch={sketch} background={background}
            editorMode={editorMode} mapScale={mapScale} windowHeight={windowHeight} windowWidth={windowWidth} panX={panX} panY={panY}
            EDITOR_GRID={EDITOR_GRID} images={images} unloadedImages={unloadedImages} dispatch={dispatch}
            />
    );
}


// The P5.js sketch
const sketch = (p5) => {
    // state variables
    let EDITOR_GRID = {
        // editor grid size
        // TODO: move to worldSlice
        x: 56,
        y: 36,
        tilesize:  6,
        // editor bounds
        left: -1,
        right: -1,
        top: -1,
        bottom: -1,
    }
    let mapScale = 0;
    let windowHeight = 0;
    let windowWidth = 0;
    let panX = p5.panX;
    let panY = p5.panY;
    let background = [];
    let images = [];
    let unloadedImages = [];
    let editorMode = p5.editorMode;
    let dispatch = ()=>{};
    
    let unloadedImagesCooldown = -1;


    p5.updateWithProps   = (newProps) => {
        EDITOR_GRID = newProps.EDITOR_GRID;
        mapScale = newProps.mapScale;
        windowHeight = newProps.windowHeight;
        windowWidth = newProps.windowWidth;
        panX = newProps.panX;
        panY = newProps.panY;
        background = newProps.background;
        images = newProps.images;
        unloadedImages = newProps.unloadedImages;
        editorMode = newProps.editorMode;
        dispatch = newProps.dispatch;
    }

   ....

   rest of functions for drawing and updating

   ...
}

however either still seems to reupdate or freezes (possibly due to recursive calls)

from react.

DjCrqss avatar DjCrqss commented on April 27, 2024

Nevermind, did do it!! Found an issue that storing p5js image objects into arrays in global contexts (redux or react createContext) will cause the app to freeze upon resizing the window. Had to make the p5.load'd images now stored in the same file as the sketch and it seems fine

from react.

jamesrweb avatar jamesrweb commented on April 27, 2024

Closed as the issue is not a library problem and is now resolved.

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.