Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: Matrefeytontias on June 25, 2013, 10:04:35 am

Title: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 10:04:35 am
http://luis.net/projects/processing/wormhole/

It would be oh so awesome *.*

Although it's written for Processing, it's still Java → close to C++, so it should be feasible.
Title: Re: We MUST port that to Ndless
Post by: Lionel Debroux on June 25, 2013, 12:20:50 pm
Hmm... do you have a video of that effect ?
None of my computers' browsers has an active Java plugin (and most browsers don't have it installed at all in the first place). Given the loooong string of critical vulnerabilities in Java / the Java browser plugin, nobody should have it enabled by default, in fact :)

EDIT: I see what you mean, 4'40" into
. That's a capture of Future Crew's Unreal demo, which features the effect, according to the page you linked. I know the music of Unreal well enough, but I had never watched the gfx part :)
Title: Re: We MUST port that to Ndless
Post by: Streetwalrus on June 25, 2013, 12:23:15 pm
Same here and I don't know how to grab the page resources in Chrome. :/
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 01:33:56 pm
Lionel Debroux and Streetwalker you can also watch the video of the effect on Youtube :


Moreover, there's a link to the source in the description.

Anyone willing to team up to port it to Nspire ? :P (not a joke)
Title: Re: We MUST port that to Ndless
Post by: linuxgeek96 on June 25, 2013, 03:12:07 pm
I'm game when I get my Nspire back from school (left there, still waiting for summer school to begin to get it back)
Title: Re: We MUST port that to Ndless
Post by: Lionel Debroux on June 25, 2013, 03:36:32 pm
The code doesn't build in the latest version of Processing, it needs porting...

Before conversion to C++, it could use some optimization, even if all of those apply to the setup phase:
* getting rid of the spokeCalc array: it could just be a temporary variable inside the loop which defines it;
* although the compiler should be smart enough to notice, 2*PI*i/SPOKES needn't be recomputed each time, the temp float should be incremented by the 2*PI/SPOKES constant instead;
* ditto for the computation of divCalcX and divCalcY.
Moving the computation of sin & cos to compile time would speed up the setup phase, at the expense of binary size.
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 04:33:40 pm
I found a C++ version that uses SDL in addition of some other libraries, that should make the port easier : https://sourceforge.net/projects/insolitdust/files/windows/wormhole-0.1-Win.zip (source + binaries)
Title: Re: We MUST port that to Ndless
Post by: TIfanx1999 on June 25, 2013, 05:04:37 pm
I guess it's pretty cool, but is it just a graphics demo?
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 05:30:36 pm
Indeed it is. It only uses a 16*16 texture.
Title: Re: We MUST port that to Ndless
Post by: willrandship on June 25, 2013, 05:33:37 pm
and code, lots of code.
Title: Re: We MUST port that to Ndless
Post by: Jim Bauwens on June 25, 2013, 05:37:43 pm
I've ported most of the code the Lua and it seems to be working almost properly in the student software. (It probably will be very very slow on calc ;P). However, the code (of the original) it very unoptimized and the person porting it to the Nspire C should really rewrite some of it :) I'm already changing a lot in my Lua port ^^

Btw, it uses 15x15 textures.
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 05:46:28 pm
Yeah, from what I've seen (and understood) it's mostly intended to be a tutorial than a fast code.

I'll try to port the C++ version, only to see if I can get how they achieve that.
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 25, 2013, 05:46:39 pm
Looks nice, but it would be cool if those animations were kept as small as possible, so that maybe they can be re-used inside games, such as for a Final Fantasy magic spell animation.
Title: Re: We MUST port that to Ndless
Post by: Jim Bauwens on June 25, 2013, 06:11:56 pm
Look here how cute :P

(http://i.imgur.com/QUmuMaT.jpg)

Now I just need to see if I can speed it up so it works decent on calc (since it's Lua) ^^
Title: Re: We MUST port that to Ndless
Post by: willrandship on June 25, 2013, 06:21:13 pm
still not ported to ndless
/me runs.
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 25, 2013, 06:23:14 pm
You already ported it? O.O

But why is there the border at the top of the screen? ??? Is it in Lua instead of C++? How fast does it run btw?

Also if someone made a vid of calc demos, the following song would fit really well :P
Title: Re: We MUST port that to Ndless
Post by: Jim Bauwens on June 25, 2013, 06:36:20 pm
You already ported it? O.O

But why is there the border at the top of the screen? ??? Is it in Lua instead of C++? How fast does it run btw?

Also if someone made a vid of calc demos, the following song would fit really well :P


As I mentioned, I ported it to Lua ^^
I havent tested it on a handheld, but I presume very slow.
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 25, 2013, 06:40:55 pm
Would you be able to describe precisely how it works ?
Title: Re: We MUST port that to Ndless
Post by: Lionel Debroux on June 26, 2013, 03:47:30 am
Most of the work is in the setup phase (setup() in the Processing version, InitTables() in the C++ version). And the C++ version could use the optimizations I described above, if not more (for instance, if we have enough room on the stack, then we can even put the arrays of floats used in InitTables() on the stack, no need for new + delete later).
Title: Re: We MUST port that to Ndless
Post by: ElementCoder on June 26, 2013, 03:54:30 am
I've ported most of the code the Lua and it seems to be working almost properly in the student software. (It probably will be very very slow on calc ;P). However, the code (of the original) it very unoptimized and the person porting it to the Nspire C should really rewrite some of it :) I'm already changing a lot in my Lua port ^^

Btw, it uses 15x15 textures.
I was kind of waiting for this comment to show up :P

Cool effect though. It might be useful for a space themed game or something.
Title: Re: We MUST port that to Ndless
Post by: Keoni29 on June 26, 2013, 03:55:28 am
How about a port of tempest2000 with this in the background changing hue?
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 26, 2013, 05:39:17 am
A SHMUP or Arkanoid game with that as background would be awesome :D or even ... Bit Trip :D
Title: Re: We MUST port that to Ndless
Post by: Jim Bauwens on June 26, 2013, 09:21:42 am
Would you be able to describe precisely how it works ?

I suppose, but if you stare long enough at the code you will see that it isn't so complex.

Alright, for those who are interested here is my Lua code
Code: [Select]
local reg  = {}
local wormImg
local width, height

local wormTexture = {
0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,
0x7fab,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x7fab,
0x7fab,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53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,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab,0x7fab
}


function on.construction()
  width = 338/2
  height = 212/2
  wormImg = {}
 
  local tsize = 15
  local width, height = width, height
  local wormImg = wormImg

  local SPOKES = 1200
  local spokeCalc = {}
  local spokeCosCalc = {}
  local spokeSinCalc = {}

  local x,y,z
  local divCalcX,divCalcY = 0,0
  local sin, cos, log, floor = math.sin, math.cos, math.log, math.floor

  local XCENTER = floor(width/2)
  local YCENTER = floor(height/2 - height/4)
  local DIVS = SPOKES/2

  for i=1, SPOKES do
    local n = 2*math.pi*i/SPOKES
    spokeCalc[i] = n
    spokeCosCalc[i] = cos(n)
    spokeSinCalc[i] = sin(n)
  end
 
  local incW = width/DIVS
  local incH = height/DIVS
 
  for j=1, SPOKES, 2 do
    z = log(j/DIVS)*25-25
    divCalcX = divCalcX + incW
    divCalcY = divCalcY + incH
    for i=1, SPOKES do
      x = floor(divCalcX*spokeCosCalc[i]) + XCENTER
      y = floor(divCalcY*spokeSinCalc[i]  - z ) + YCENTER

      if x>=0 and x<=width and y>=0 and y<=height then
        if not wormImg[y] then wormImg[y] = {} end
        wormImg[y][x] = 1 + floor(i/8)%tsize + tsize*(floor(j/12)%tsize)
      end
    end
  end
 
  timer.start(0.05)
end

local function shiftup()
    local wormTexture = wormTexture
    local reg=reg
   
    for k=1, 15 do
      reg[k]=wormTexture[k]
    end
    for k=16, 15*15  do
      wormTexture[k-15]=wormTexture[k] -- +1 for C to Lua
    end
    for k=1,15 do
      wormTexture[k+210]=reg[k]
    end
end

local function shiftright()
    local wormTexture = wormTexture
    local last
   
    for k=0, 14 do
      last=wormTexture[15*k+15]
      for i=15, 2, -1 do
        wormTexture[15*k+i]=wormTexture[15*k+(i-1)]
      end
      wormTexture[15*k + 1]=last
    end
end

--count=0
function on.paint(gc)
  local wormTexture = wormTexture
  local wormImg = wormImg
  local height, width= height-1, width-1
  local pos=0
  for y=0, height do
    local yy=wormImg[y]
    for x=0, width do
        pos=pos+1
        gc:setColorRGB(wormTexture[yy[x]])
        gc:fillRect(x*2, y*2, 2, 2)
        --gc:fillRect(x, y, 1, 1)
    end
  end
  --count=count+1
  --gc:setColorRGB(0xFF00FF)
  --gc:drawString(""..count, 100, 100, "top")
end

function on.timer()
  shiftup()
  shiftright()
 
  platform.window:invalidate()
end

I halved the resolution and amount of spokes so that it actually can run on your handheld. Of course speed will not be awesome, but it does run. Keep in mind that launching takes some time (as it then generates the swirl 'lookup' image).

Also, I changed and removed parts that aren't necessary for it to run. For example I completely removed wormTexture2 as that's only need for smooth transition to another texture and wormEffect because there is no reason in storing it.

Now, if TI only would give us some proper way to have a graphics buffer, this could run at a very decent speed :P
Title: Re: We MUST port that to Ndless
Post by: Keoni29 on June 26, 2013, 09:27:47 am
Don't expect anything from ti :P Even with the CSE they managed to disappoint.
Title: We MUST port that to Ndless - DONE !
Post by: Matrefeytontias on June 26, 2013, 11:01:45 am
Aaaaaaand ... success ! :D

Look at it running, it's so cute ;D (thanks nSDL)

Binaries and source attached (I changed some things but didn't bother too much with optimization).

It takes 5 seconds to start, and after that runs smoothly with a small artefact at the bottom of the screen :P (hit [esc] to quit). If someone can see where it's coming from in the source code ...
Title: Re: We MUST port that to Ndless
Post by: Hayleia on June 26, 2013, 12:11:42 pm
Great job !
Now you know what would be epic ? That you update your SpeedX3D project to use that method for the tunnel (I don't know if you can "move the hole" in the effect you just ported).
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 26, 2013, 12:18:11 pm
In fact, the tunnel and the wormhole already use the same technique → precompute a LUT for the whole screen and shift a texture afterwards. And moving the hole would require computing the whole screen each iteration, which would be awfully slow (computing it only once takes the 5 seconds I've talked about).
Title: Re: We MUST port that to Ndless
Post by: Lionel Debroux on June 26, 2013, 12:18:29 pm
AFAICS, the artefact is also in the original C++ / SDL version, albeit at a different place.
nSDL, being linked statically, makes the program fairly large. Adding a couple precomputed sin/cos tables + a precomputed log table to the binary wouldn't increase size that much...
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 26, 2013, 05:20:04 pm
That looks really cool! O.O What would be nice is some sort of space shooter where you have to shoot whatever is coming out of the hole before it reaches the sides but I bet that would be kinda hard to code even if the tunnel hole didn't move.
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 26, 2013, 05:59:27 pm
Mhm, that should be doable. But I already have projects ;D
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 26, 2013, 06:08:12 pm
Here is an animated screenshot, by the way. Look at this! O.O

(By the way, for those who want to make good looking Youtube videos of their Nspire programs, but can't capture with anything at a decent frame rate, just lower Nspire_emu speed to 5% then capture at like 5-10 FPS. Then in VirtualDub or another video editing tool, speed up the resulting video so that it matches the speed of the emulator when it runs at 100% speed, then save in 30 frames per second. Warning: This takes a long while and the video or animated GIF will take a lot of space. (in GIF case, about 12-15 MB per minute)
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 26, 2013, 06:38:55 pm
Thanks for the screenshot :) for my part, I just use Nspire_emu -> CamStudio -> Virtual Dub.
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 26, 2013, 06:41:57 pm
Yeah that's what I used. Since Camstudio for me captures at 7 FPS or so for anything larger than  192x128 I just slowed down the emu then speeded up the vid afterward. I really don't recommend posting (let alone uploading directly) long screenshots made like that on the forums, though. It will eat people's bandwidth. Mine is fine because it lasts about half a second, else I would just reduce framerate to 3 FPS.

I think a compilation of Omnimaga calc demos would be a nice video to add on my Youtube channel or OmnimagaTV, just to show what can be done with those calcs. :D
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 26, 2013, 07:19:29 pm
All-calcs then :) and only demos that got presented on Omnimaga, because there are too many yolo-worthy ASM demos for the z80 and 68k line out there ;D

But in fact, not only demos, but also animations, why not ? For example we could take Yeong's old Axe rotating room, Grammer oval rotation, leafy's explosion, some scenes from The Cutting Edge of Axe and more for z80, and Lionel Debroux's fire, dissolve and parallax scrolling effects, my plasma, the above wormhole and Spenceboy98's tunnel for Nspire :)
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 26, 2013, 08:51:59 pm
Yeah I meant the Omni ones, not just by staff but by members too. I could possibly include some Z80 stuff too, however, such as your demos, Xeda's or my CSE Triforce.
Title: Re: We MUST port that to Ndless
Post by: TIfanx1999 on June 27, 2013, 04:37:11 pm
Well done Matrefeytontias. Looks like this came out quite nicely. :)
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 27, 2013, 05:20:54 pm
Thanks :) it wasn't really hard to port though :P
Title: Re: We MUST port that to Ndless
Post by: tr1p1ea on June 27, 2013, 05:42:20 pm
There are also some cool water demos that have been shown on omnimaga.
Title: Re: We MUST port that to Ndless
Post by: Matrefeytontias on June 27, 2013, 06:37:23 pm
Do you have any link ? I don't know them ...
Title: Re: We MUST port that to Ndless
Post by: DJ Omnimaga on June 30, 2013, 09:06:05 pm
You might be able to find some via Google by searching for cellular automata, water physics or maybe just water, although for some reasons, in the past 3 weeks, Google seems to miss several results and returns more and more unrelated ones.
All-calcs then :) and only demos that got presented on Omnimaga, because there are too many yolo-worthy ASM demos for the z80 and 68k line out there ;D

But in fact, not only demos, but also animations, why not ? For example we could take Yeong's old Axe rotating room, Grammer oval rotation, leafy's explosion, some scenes from The Cutting Edge of Axe and more for z80, and Lionel Debroux's fire, dissolve and parallax scrolling effects, my plasma, the above wormhole and Spenceboy98's tunnel for Nspire :)
I considered including Mode 7 and the flaming cube from your demo program, but not the 3D stars animation due to the text. I know some Youtubers will just constantly comment saying that my video is called The Cutting Edge of Axe in its entirety, even if it's the case. As for the other stuff you mentionned I would probably need to find them first, though.

And yeah not just demos might be included. For example, I might include Tinycraft and the raycaster you made (using different textures).