Jump to content




Anyone Interested In A Javascript (Web/html5) Version Of A Cc Emulator?


39 replies to this topic

#1 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 17 August 2013 - 10:19 AM

So... Me and gravs (mostly gravs) wanted to make a CC emu, but we wanted it to be multi-platform. Currently gravs has made a CC emu in C++,
Spoiler
but we were thinking of something more. So we were thinking of either practically re-writing CC in Javascript, so you can add like a "Test out this program online" button to program submissions so you can test out people's programs instantly, (it would most likely be riddled with bugs) or to just continue writing in C++ or some other native code language (Second option is Python). But writing in Javascript will poses a problem that Gravs just doesn't like, which is that you won't be able to edit code in sublime text, then run it straight off in the emu, and instead you would need to copy and paste the code, or use an in-browser editor (ace editor). So yeah, we want your opinion on whether you would use this or not, or would you rather just have a native (lightweight) cc emu.

tl;dr: We were planning to make a CC emu. Javascript/Online (Requires copying/pasting of code or online editing), or a lightweight native app?

Well since there is no poll option for the general section for some reason, post your opinions/suggestions below!

#2 reububble

  • Members
  • 72 posts
  • LocationBehind you

Posted 17 August 2013 - 10:37 AM

I like this idea! There's been a few times that I've not been bothered to open up CC simply to find out if my code runs.
It could be on this site if everybody is nice enough, then imagine how well the ask a pro and tutorial sections would work!

#3 DaGamer12345

  • Members
  • 32 posts

Posted 17 August 2013 - 12:07 PM

Do you know what this means? We will finally have an Android/iOS CC emulator for the out-and-about (or just mobile) coders. People have been waiting for something like that.

#4 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 17 August 2013 - 12:24 PM

I would like it in JavaScript, cause you could also use it on iOS/Android/Windows Phone devices.

#5 nutcase84

  • Members
  • 711 posts
  • LocationIn My Lonely Little Computer Corner

Posted 17 August 2013 - 12:59 PM

This is what I've been looking for all this time. +1!

#6 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 17 August 2013 - 01:05 PM

Mobile device support would more a lot of extra work, but entirely possible (maybe just a single computer for a phone, everything else would be too big - tablet support would be really useful).

So far it looks like Javascript is the way to go. Is anyone else interested in a more lightweight native desktop application though? I for one would use it (as I currently use my own, which is no where near the stage of releasing - it's currently very OS specific and requires all its dependencies to be manually installed and in very specific places, plus I'd need to get permission from dan to redistribute the computercraft.jar file with it). CCDesk is quite an engineering feat, but quitting it causes a kernel panic (yes, it shuts down and shows this screen) on my retina display mac, so I can't use it (I've not bothered to report this because I seem to be the only one with the problem, and didn't think it would be worth Lochie's time just for one potential user. My mac seems to hate all things Java, apart from Minecraft).

#7 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 17 August 2013 - 05:37 PM

I didnt really read through the replies on this post, but as you know you need to design a website anyway. You could possibly make it like that, that you can bind programs to an account. It really helps but can be iffy. First of all because we would need to refresh the page if we uploaded something, because I dont think you can save it in a database and get it in the runtime withoit refreshing.

However, I want to note that this comes from a unexperienced javascript coder, I have no idea if you can fetch files from a database with JS.

#8 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 17 August 2013 - 09:30 PM

View PostEngineer, on 17 August 2013 - 05:37 PM, said:

I didnt really read through the replies on this post, but as you know you need to design a website anyway. You could possibly make it like that, that you can bind programs to an account. It really helps but can be iffy. First of all because we would need to refresh the page if we uploaded something, because I dont think you can save it in a database and get it in the runtime withoit refreshing.

However, I want to note that this comes from a unexperienced javascript coder, I have no idea if you can fetch files from a database with JS.

Writing the fs API would be annoying. There are a couple of options: store the files in the database, and just upload the changed files to a database every 30 seconds or so asynchronously, which would be a lot of annoying work to protect against spammers; store the files in HTML5 localStorage, which has a max size of 5MB, so you could only open 2 - 3 computers; store the files in memory, and have them not persist across sessions, or have the user download a single data file, which they could then supply to the website upon reload or something; upload the files to the database at the end of the session, or have a manual save function that saves the session to a database.

Also as far as editing files, we would probably include an ace editor in browser so you can easily modify and copy/paste into it, and allow you to save files to any of the computers.

#9 Sorroko

  • Members
  • 87 posts

Posted 17 August 2013 - 10:41 PM

I've thought about this before and it seems quite appealing however... The biggest issue is that javascript is asynchronous however the lua vm is synchronous, this poses a problem, how do you make the vm wait for user input (coroutine.yield)?

Well you can't, the only way to get input currently is via a prompt() (which is blocking), this is extremely inconvenient. I believe repl.it has a hacky solution which might make it possible (HTML5 web workers I think). lua.vm.js also looks quite promising.

I'll be interested to see how you get on. ;)

#10 ElvishJerricco

  • Members
  • 803 posts

Posted 17 August 2013 - 11:22 PM

View PostSorroko, on 17 August 2013 - 10:41 PM, said:

I've thought about this before and it seems quite appealing however... The biggest issue is that javascript is asynchronous however the lua vm is synchronous, this poses a problem, how do you make the vm wait for user input (coroutine.yield)?

Well you can't, the only way to get input currently is via a prompt() (which is blocking), this is extremely inconvenient. I believe repl.it has a hacky solution which might make it possible (HTML5 web workers I think). lua.vm.js also looks quite promising.

I'll be interested to see how you get on. ;)

It's easier than you'd think if you use WebWorkers. WebWorkers basically let you run a JavaScript file in another thread that has zero access to UI stuff. Put the VM in a web worker and send messages between the main thread and the worker whenever the display updates or events happen, and you've got an emulator. The bigger problem is getting the Lua VM working in JavaScript. I know it's been done with emscripten and asm.js but most browsers don't support accelerating asm.js so it might be slow.



Personally, I'd be more interested in seeing an emulator written for a regular terminal. So I can open up the terminal on my mac, or cmd on my pc, and run a command. Whatever my working directory is acts as the root directory for the computer that begins to emulate using my terminal window as its screen.

#11 Sorroko

  • Members
  • 87 posts

Posted 17 August 2013 - 11:29 PM

View PostElvishJerricco, on 17 August 2013 - 11:22 PM, said:

-snip-

running the lua vm in a webworker (i.e. lua.vm.js) it will still however not pause for input from the main thread, currently in cc calling os.pullEvent calls coroutine.yield which pauses execution until java returns an event. Javascript is not capable of pausing execution because it is asynchronous. There might be something I'm missing here but from my experiments it hasn't gone well :D.

#12 ElvishJerricco

  • Members
  • 803 posts

Posted 18 August 2013 - 12:37 AM

View PostSorroko, on 17 August 2013 - 11:29 PM, said:

running the lua vm in a webworker (i.e. lua.vm.js) it will still however not pause for input from the main thread, currently in cc calling os.pullEvent calls coroutine.yield which pauses execution until java returns an event. Javascript is not capable of pausing execution because it is asynchronous. There might be something I'm missing here but from my experiments it hasn't gone well :D.

WebWorkers don't run continuously. JavaScript is mostly event based actually. You never write any while (running) types of loops in javascript. Same goes for WebWorkers. You don't run loops. You create the worker, and in your worker's code, you define a function to be called when the main thread sends a message to the worker. Then, you can send a message back to the main thread. Of course to receive that message, you just set the onmessage value in the worker object to some function. It's asynchronous, yes. But still event based.

#13 Sorroko

  • Members
  • 87 posts

Posted 18 August 2013 - 01:02 AM

The lua vm in javascript ported via emscripten is blocking... and while executing lua code it will freeze your browser (assuming you dont use workers). And javascript is asynchronous, check on wiki if you dont believe me ;)/> event systems are used because it is asynchronous.

#14 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 18 August 2013 - 01:51 AM

I don't know anything about JavaScript and other web development, but wouldn't it be possible for the fs API to store the data on the local computer via cookies?

#15 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 18 August 2013 - 01:52 AM

View PostKingOfNoobs, on 18 August 2013 - 01:51 AM, said:

I don't know anything about JavaScript and other web development, but wouldn't it be possible for the fs API to store the data on the local computer via cookies?

A cookie has a max size of 4KB, which is basically useless for storing files :P

#16 ElvishJerricco

  • Members
  • 803 posts

Posted 18 August 2013 - 01:56 AM

View PostSorroko, on 18 August 2013 - 01:02 AM, said:

The lua vm in javascript ported via emscripten is blocking... and while executing lua code it will freeze your browser (assuming you dont use workers). And javascript is asynchronous, check on wiki if you dont believe me ;) event systems are used because it is asynchronous.

My last sentence was basically exactly what you said here =P Except the emscripten thing. And you're right. But I'm not sure the details on how emscripten calls code that would normally wait on user input. I'm sure there's a way to make it work.

#17 AfterLifeLochie

    Wiki Oracle

  • Moderators
  • 480 posts
  • LocationAfterLifeLochie's "Dungeon", Australia

Posted 18 August 2013 - 01:58 AM

View PostKingOfNoobs, on 18 August 2013 - 01:51 AM, said:

I don't know anything about JavaScript and other web development, but wouldn't it be possible for the fs API to store the data on the local computer via cookies?
You can store a seriously limited and unreliably cleared quantity of data in the local-storage.

The biggest physical problem is the fact Javascript is purely asynchronous and has no concepts of threads or workers, nor any reasonable stacks, so this project requires inventing things which even I cannot think of a practical, sane solution to - the only really sure-fire way to ensure events occurs is to act entirely reactively, which from a technical standpoint is going to be extremely chaotic and possibly lag-inducing for the user, and events are still not guaranteed to fire. I can also think of plenty of ways the Lua VM would cause the browser to panic uncontrollably. Long running Javascript can, and will, cause modern browsers to fling their arms in the air or even totally crash in the event you're still an Internet Exploder user.

#18 ElvishJerricco

  • Members
  • 803 posts

Posted 18 August 2013 - 02:09 AM

View PostAfterLifeLochie, on 18 August 2013 - 01:58 AM, said:

The biggest physical problem is the fact Javascript is purely asynchronous and has no concepts of threads or workers, nor any reasonable stacks, so this project requires inventing things which even I cannot think of a practical, sane solution to - the only really sure-fire way to ensure events occurs is to act entirely reactively, which from a technical standpoint is going to be extremely chaotic and possibly lag-inducing for the user, and events are still not guaranteed to fire. I can also think of plenty of ways the Lua VM would cause the browser to panic uncontrollably. Long running Javascript can, and will, cause modern browsers to fling their arms in the air or even totally crash in the event you're still an Internet Exploder user.

Again, I point to WebWorkers. And still, I'm sure there's a way to make a non-blocking VM. No concrete evidence on this because that would take much more research than I'm willing to put into a project I'm not building, but the emscripten VM is capable of using setTimeout and other call-back based JS functions.

#19 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 18 August 2013 - 02:11 AM

View PostGravityScore, on 17 August 2013 - 01:05 PM, said:

Mobile device support would more a lot of extra work, but entirely possible (maybe just a single computer for a phone, everything else would be too big - tablet support would be really useful).

So far it looks like Javascript is the way to go. Is anyone else interested in a more lightweight native desktop application though? I for one would use it (as I currently use my own, which is no where near the stage of releasing - it's currently very OS specific and requires all its dependencies to be manually installed and in very specific places, plus I'd need to get permission from dan to redistribute the computercraft.jar file with it). CCDesk is quite an engineering feat, but quitting it causes a kernel panic (yes, it shuts down and shows this screen) on my retina display mac, so I can't use it (I've not bothered to report this because I seem to be the only one with the problem, and didn't think it would be worth Lochie's time just for one potential user. My mac seems to hate all things Java, apart from Minecraft).

You could easily create a native Android app in C, and compile the Lua library(or port it, idk?) for ARM.

#20 ElvishJerricco

  • Members
  • 803 posts

Posted 18 August 2013 - 02:21 AM

View PostGravityScore, on 17 August 2013 - 01:05 PM, said:

CCDesk is quite an engineering feat, but quitting it causes a kernel panic (yes, it shuts down and shows this screen) on my retina display mac, so I can't use it (I've not bothered to report this because I seem to be the only one with the problem, and didn't think it would be worth Lochie's time just for one potential user. My mac seems to hate all things Java, apart from Minecraft).

I have the same problems. CCDesk is not mac compatible. Maybe it's just 10.8 and up or something but I've never been able to get it to work properly.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users