Author Topic: We MUST port that to Ndless  (Read 15536 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: We MUST port that to Ndless
« Reply #15 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
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: We MUST port that to Ndless
« Reply #16 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.
« Last Edit: June 25, 2013, 06:36:34 pm by Jim Bauwens »

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: We MUST port that to Ndless
« Reply #17 on: June 25, 2013, 06:40:55 pm »
Would you be able to describe precisely how it works ?

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: We MUST port that to Ndless
« Reply #18 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).
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: We MUST port that to Ndless
« Reply #19 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.

Some people need a high five in the face... with a chair.
~EC

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: We MUST port that to Ndless
« Reply #20 on: June 26, 2013, 03:55:28 am »
How about a port of tempest2000 with this in the background changing hue?
If you like my work: why not give me an internet?








Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: We MUST port that to Ndless
« Reply #21 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

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: We MUST port that to Ndless
« Reply #22 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,
0x7f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,0x3F53,0x3F53,0x7fab,
0x7fab,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x3F53,0x7fab,
0x7fab,0x7fab,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
« Last Edit: June 26, 2013, 09:32:05 am by Jim Bauwens »

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: We MUST port that to Ndless
« Reply #23 on: June 26, 2013, 09:27:47 am »
Don't expect anything from ti :P Even with the CSE they managed to disappoint.
If you like my work: why not give me an internet?








Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
We MUST port that to Ndless - DONE !
« Reply #24 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 ...
« Last Edit: June 26, 2013, 11:18:04 am by Matrefeytontias »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: We MUST port that to Ndless
« Reply #25 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).
« Last Edit: June 26, 2013, 12:11:53 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: We MUST port that to Ndless
« Reply #26 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).

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: We MUST port that to Ndless
« Reply #27 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...
« Last Edit: June 26, 2013, 12:23:52 pm by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: We MUST port that to Ndless
« Reply #28 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.
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: We MUST port that to Ndless
« Reply #29 on: June 26, 2013, 05:59:27 pm »
Mhm, that should be doable. But I already have projects ;D