jarcane / minicosm

A FP-oriented game engine inspired by universe.rkt, written in Clojurescript
24 stars 2 forks source link

Feature/asset loader #1

Closed jarcane closed 4 years ago

jarcane commented 4 years ago

Adds a new key function and API for loading assets from URLs with proper loading confirmation before to start the game.

At present, this doesn't work, for two reasons:

Posting this as WIP 'cause I could use some eyes on.

jarcane commented 4 years ago

Further investigation by adding a watcher confirms that actually the swap! call is completed:

loaded https://images.pexels.com/photos/957010/milky-way-starry-sky-night-sky-star-957010.jpeg 
"-- Atom Changed --" 
"key" :watcher 
"atom" #object[cljs.core.Atom {:val {:loaded 1, :error 0, :total 1}}] 
"old-state" {:loaded 0, :error 0, :total 1}
"new-state" {:loaded 1, :error 0, :total 1} 

However, for some reason when we deref the value, it still shows the old-state. Something is happening out of order here somehow, and I've no idea why.

jarcane commented 4 years ago

Continuing investigation: the atom is not the problem. Swaps are happening just fine.

The problem is that instead of returning assets as it should, the return value of asset-loader continues to be the return value of requestAnimationFrame, even when the recursive call should terminate and return the value from the if statement instead. This then causes a crash, because then the demo tries to use that number as an asset map and obviously fails.