Author Topic: [Axe] Plane deformations are fun  (Read 26073 times)

0 Members and 1 Guest are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Axe] Plane deformations are fun
« Reply #15 on: January 28, 2014, 11:59:37 am »
If you're using an 8x8 texture, that's only 64 possible coordinates needed, so you could just have one byte store both the x and y coordinate in the LUT.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #16 on: January 28, 2014, 01:29:42 pm »
That'd only be slower. I store 2 coordinates because it's faster to access than a packed word that I'd have to decompress.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Axe] Plane deformations are fun
« Reply #17 on: January 28, 2014, 02:22:24 pm »
You don't need to unpack anything. Just store a number from 1-64 which corresponds with the index of each pixel in the texture as if it was a 1-D array.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: [Axe] Plane deformations are fun
« Reply #18 on: January 28, 2014, 03:25:46 pm »
I'm sure you can make it at least twice faster with ASM, because if I had to make the drawing code in C it would be (direct translation from Axe) :
Code: [Select]
for(y = 0; y < 64; y++)
  for(x = 0; x < 96; x++)
    plotSScreen[y * 96 + x] = texture[ (ylut[y * 96 + x] & 7) * 8 + xlut[y * 96 + x] ];

Lemme get on my PC and I'll attach the source.

I hope this code is slightely faster, but I haven't been able to test it, so I'm not sure if it even works.

Code: [Select]
;°xlut -> A
;°ylut -> B

Render:
  ld hl, plotsScreen
  push hl

RenderLoop:
  ld c, 8
  xor a
ByteLoop:
  ld hl, (A)
  ld b, (hl)
  ld hl, (B)
  ld e, (hl)
  ld d, 0
  ld hl, texture
  add hl, de
  ld d, (hl)
  inc b
TexelLoop:
  sra d
  djnz TexelLoop
  set 0, a
  jr c, TexelEnd
  res 0, a
TexelEnd:
  ld hl, (A)
  inc hl
  ld (A), hl
  ld hl, (B)
  inc hl
  ld (B), hl
  sla a
  dec c
  jr nz, ByteLoop
  rr a
  pop hl
  ld (hl), a
  inc hl
  push hl
  ld de, Plotsscreen+768
  or a
  sbc hl, de
  jr z, RenderLoop
  pop hl
  ret
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #19 on: January 28, 2014, 03:38:54 pm »
You don't need to unpack anything. Just store a number from 1-64 which corresponds with the index of each pixel in the texture as if it was a 1-D array.
Oh that's actually a good idea. I'll try and see how faster it is.

I'm sure you can make it at least twice faster with ASM, because if I had to make the drawing code in C it would be (direct translation from Axe) :
Code: [Select]
for(y = 0; y < 64; y++)
  for(x = 0; x < 96; x++)
    plotSScreen[y * 96 + x] = texture[ (ylut[y * 96 + x] & 7) * 8 + xlut[y * 96 + x] ];

Lemme get on my PC and I'll attach the source.

I hope this code is slightely faster, but I haven't been able to test it, so I'm not sure if it even works.

Code: [Select]
;°xlut -> A
;°ylut -> B

Render:
  ld hl, plotsScreen
  push hl

RenderLoop:
  ld c, 8
  xor a
ByteLoop:
  ld hl, (A)
  ld b, (hl)
  ld hl, (B)
  ld e, (hl)
  ld d, 0
  ld hl, texture
  add hl, de
  ld d, (hl)
  inc b
TexelLoop:
  sra d
  djnz TexelLoop
  set 0, a
  jr c, TexelEnd
  res 0, a
TexelEnd:
  ld hl, (A)
  inc hl
  ld (A), hl
  ld hl, (B)
  inc hl
  ld (B), hl
  sla a
  dec c
  jr nz, ByteLoop
  rr a
  pop hl
  ld (hl), a
  inc hl
  push hl
  ld de, Plotsscreen+768
  or a
  sbc hl, de
  jr z, RenderLoop
  pop hl
  ret
As I seldom have access to my PC, that will require some time before testing.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: [Axe] Plane deformations are fun
« Reply #20 on: January 28, 2014, 03:51:40 pm »
I just saw in the C source code that you seem to be storing the texture as an image with one byte for every pixel(64 bytes)?
My asm code expects a pointer to a sprite with 1 bit per pixel (8 bytes).
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #21 on: January 28, 2014, 03:58:20 pm »
Yeah, I use 8 BPP for the texture to avoid bit unpacking. It's definitely not Axe's thing.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: [Axe] Plane deformations are fun
« Reply #22 on: January 28, 2014, 04:07:11 pm »
Indeed. And neither is per-pixel drawing. But for assembly, bit unpacking runs at almost the same speed as reading unpacked bits. And with assembly, the usage of variables can be avoided as well, which should also give a speed boost when doing really repetitive stuff.

Would you prefer it if I convert my code to HEX? That may make it easier to test for you.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #23 on: January 28, 2014, 04:16:52 pm »
Actually I use another code now, based on fb39ca4's proposition. In C, it would be :

Code: [Select]
// usual for loops, x, y
plotSScreen[y * 96 + x] = texture[ tlut[y * 96 + x] ];
I'll put a pointer to texture in $8000 and a pointer to tlut in $8002.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: [Axe] Plane deformations are fun
« Reply #24 on: January 28, 2014, 04:59:57 pm »
You can optimize it by using only 1 loop:
Code: [Select]
:for(A,0,6144)
:plotsScreen[A] = texture[tlut[A]]
:End
« Last Edit: January 28, 2014, 05:00:12 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #25 on: January 28, 2014, 05:16:51 pm »
But no, in Axe I must pack the bits to plotSScreen ;D

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: [Axe] Plane deformations are fun
« Reply #26 on: January 28, 2014, 06:40:29 pm »
This is my attempt at converting it to assembly:
Code: [Select]
Asm(214093E50E08AF2A02805E160021(°Texture)1946CBC7CB402802CB872A028023220280CB270D20E1CB1FE17723E5114096B7ED5220D0E1)I have dissasembled it to see if I converted it to HEX correctly, and it was, but what I don't know is if my assembly code is fully correct, so backup your data just in case.

EDIT: the more readable source code:
Code: [Select]
Render:
  ld hl, plotsScreen
  push hl

RenderLoop:
  ld c, 8
  xor a
ByteLoop:
  ld hl, ($8002)
  ld e, (hl)
  ld d, 0
  ld hl, texture
  add hl, de
  ld b, (hl)
  set 0, a
  bit 0, b
  jr z, TexelEnd
  res 0, a
TexelEnd:
  ld hl, ($8002)
  inc hl
  ld ($8002), hl
  sla a ;optimization: add a, a
  dec c
  jr nz, ByteLoop
  rr a
  pop hl
  ld (hl), a
  inc hl
  push hl
  ld de, Plotsscreen+768
  or a
  sbc hl, de
  jr nz, RenderLoop
  pop hl
  ret

#comment
HEX:
214093E5 -> 4 bytes
RenderLoop:
0E08AF -> 3 bytes
ByteLoop:
2A02805E1600 -> 6 bytes
21(°Texture) -> 3 bytes ld hl, texture
1946CBC7CB40 -> 6 bytes
2802 -> 2 bytes jr z, TexelEnd
CB87 -> 2 bytes
TexelEnd:
2A028023220280CB270D -> 10 bytes
20E1 -> 2 bytes jr nz, ByteLoop
CB1FE17723E5114096B7ED52 -> 12 bytes
20D0 -> 2 bytes jr nz, renderLoop
E1 -> 1 byte

TOTAL COMMAND:
Asm(214093E50E08AF2A02805E160021(°Texture)1946CBC7CB402802CB872A028023220280CB270D20E1CB1FE17723E5114096B7ED5220D0E1)
#endcomment
« Last Edit: January 28, 2014, 07:13:52 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Axe] Plane deformations are fun
« Reply #27 on: January 28, 2014, 08:19:49 pm »
Okay, so I optimized your a bit and completely replaced my drawing code by it. I also replaced the translation by a simple texture wrapping. Everything happened to work, and HOLY SHIT IT'S FAST *.*

I really think that speed was multiplied by 6 or 7. Be ready for an awesomeness galore. Note that these screenshots are still 6 MHz and that the program is actually faster and smoother on-calc :w00t:

Apart from that, it now requires a little bit more than 7500 bytes of RAM, instead of the previous 13800 ;D

DEFORM.8xp is the Axe source, PLDEFORM.8xp is the executable. As before, put a number f [0, 5] inclusive in Ans before using it, no out-of-bounds test made blah blah blah. I was busy working on optimizing it ;D

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: [Axe] Plane deformations are fun
« Reply #28 on: January 28, 2014, 09:42:02 pm »
Glad to hear that it helped. This would be a great effect to have for a demoscene program. Speaking of demoscene, you should have a magnifying lens effect, as was common in demos for older systems. Also, if you want the GIFs to be smoother, crank up the framerate setting in Wabbitemu.
« Last Edit: January 28, 2014, 11:21:22 pm by fb39ca4 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Axe] Plane deformations are fun
« Reply #29 on: January 28, 2014, 11:55:31 pm »
Woah that's quite a nice speed improvement O.O!