phoboslab / Impact

HTML5 Game Engine
MIT License
1.99k stars 204 forks source link

modernized Impact #49

Open cdreier opened 5 years ago

cdreier commented 5 years ago

Hi,

a few month ago, i forked Impact and tried to move it to the shiny new world of javascript.

and to simplify everything, i wrote a small cli, to bootstrap new impact projects and running weltmeister out of the box

want to take a look at it? i also made a demo gif for a short overview ;)

https://github.com/cdreier/Impact

perhaps a chance to merge it?

Joncom commented 5 years ago

I've tried doing something like that before as well. Replacing ig.Class was not as easy as I first imagined it would be. It's kind of a strange pattern. For example, properties defined in ig.Class's get evaluated before the game starts running, which automatically triggers image preloading, etc. Modern JS classes tend to instantiate properties in the constructor, which generally means after the game is already running. So preloading basically doesn't happen (it's all loaded as the game runs). Did you manage to get around this issue?

Edit: Another issue is that the ig.Class pattern allows for .injecting code into classes on the fly, which gets used in various places (such as the debug module), and I didn't think of any easy way to replicate such behavior in the modern/traditional class pattern. So I imagine certain functions, and existing plugins would break in your environment. Did you encounter this issue too?

cdreier commented 5 years ago

i think i found a solution for all these problemes... .inject was hard, but i got it working with js proxies and most of the debug panels are working as expected.

the initial game loading works with a bad timing hack... perhaps i find a better solution one day ;)

the cli is written in go and available for all plattforms from the releases page https://github.com/cdreier/Impact/releases

and the link to the demo gif

Joncom commented 5 years ago

Are you sure image preloading actually still works? Looks like you're loading your images after the game is already running, in entity constructors:

https://github.com/cdreier/Impact/blob/ab981ec766ff54e25eb320d4c714298a0f2da9b3/game/PlayerEntity.js#L6-L9

There's no reason that image would have been loaded before this line executes, right?

Furthermore, are you sure image caching isn't broken now?

https://github.com/cdreier/Impact/blob/ab981ec766ff54e25eb320d4c714298a0f2da9b3/lib/image.js#L22-L24

Normally staticInstantiate was used to hook into ig.Image instancing, returning a cached image (instead of a new instance) if found. Using JavaScript classes, there is no longer any hook into this function. Additionally, staticInstantiate is used in other classes too, also broken?

cdreier commented 5 years ago

so... i removed all the custom dependency loading too, so all the javascript is loaded in one bundle and everything is executed before the game is starting.

but for some reason the loader is not working :( I thought the delayed loader.load() was waiting for all entities to be created, but something is not working... i will investigate!

For the image cache i pushed a small fix, this is working now as intended.

Joncom commented 5 years ago

most of the debug panels are working as expected

Which panels are not working as expected?

.inject was hard, but i got it working with js proxies

Where can I see an example of some code being injected successfully? I did a search in the repo for the string "inject", but it doesn't look like any inject calls are happening anywhere.