Author Topic: Light  (Read 20474 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Light
« on: October 17, 2010, 10:40:42 pm »
So I was thinking of making a new game, based around a single gameplay mechanic: light and shadows.
I was planning on making a rogue-like game (where you descend endlessly down a randomly generated dungeon, finding treasures, killing monsters, and avoiding traps and whatnot).
I decided that it would be cool to add light and shadow to the game, so that it's like you're in a DARK dungeon, emanating light (and it's scary - what could be lurking around the next corner?)

Sadly, it's extremely slow - this is an Axe assembly program going at full speed on an TI-84+SE, and moving the circle feels like pulling teeth.

Any optimization suggestions, please?
(I'm using a variant of Bresenham's line algorithm, for those interested)

Also: how fast does pxl-Test work?  And the line( command?

Code: [Select]
.LIGHT
Full
DiagnosticOff
Fix 5
Fix 9
Fix 0
ClrDraw
ClrDraw[radians]

[FFFFFFFFFFFFFFFF]->PIC1
[3844828282443800]->PIC2
45->A->B
0->C
sub(MAP)
Pt-On(A-3,B-3,PIC2)
DispGraph
::While 1
If getKey(15)
Goto END
End
getKey(1)-getKey(4)->E
getKey(3)-getKey(2)->D

If D or E
ClrDraw
A+D->A
B+E->B
sub(MAP)
For(C,0,64)
sub(LIN,A,B,96,C)
sub(LIN,A,B,0,C)
End
For(C,1,95)
sub(LIN,A,B,C,64)
sub(LIN,A,B,C,0)
End
Pt-On(A-3,B-3,PIC2)
0->C
DispGraph
:End

::End

Label MAP
For(F,0,7)
For(G,0,1)
Pt-On(G*16,F*8,PIC1)
Pt-On(G*16+72,F*8,PIC1)
End
Pt-On(F*8+16,0,PIC1)
Pt-On(F*8+16,56,PIC1)
End
Pt-Change(16,24,PIC1)
Pt-Change(72,32,PIC1)
For(F,0,1)
For(G,0,1)
Pt-On(F*24+32,G*24+16,PIC1
End
End
Return



Label LIN
If abs(R4-R2)>abs(R3-R1)->U
expr([degrees]R1,[degrees]R2,2)
expr([degrees]R3,[degrees]R4,2)
End
R1>R3->K
abs(R3-R1)->S/2->V
abs(R4-R2)->T
R2<R4*2-1->W
R2->Y
For(Z,R1,abs(R3-R1)+R1)
If K
2*R1-Z->X
Else
Z->X
End
getKey(15)*9+W->W
ReturnIf getKey(15)
If U
If pxl-Test(Y,X)
Line(Y,X,R4,R3)
Return
End
Else
If pxl-Test(X,Y)
Line(X,Y,R3,R4)
Return
End
End

V-T->V
If V>99
Y+W->Y
V+S->V
End
End
Return

Label END
Fix 4
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline tloz128

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 324
  • Rating: +58/-6
  • I feel asleep.
    • View Profile
Re: Light
« Reply #1 on: October 17, 2010, 10:46:59 pm »
Woah! Pseudo 3d awesomeness!
Oh, and for optimizations, how about drawing the screen once every two runs through the loop instead of every time?
Naaa... Na Nah Na Nana Na Nah... Hey Jude!

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Light
« Reply #2 on: October 17, 2010, 10:53:16 pm »
So is it kind of like a birds-eye-view 3D adventure type game? It looks cool, I hope you get the speed worked out :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

SirCmpwn

  • Guest
Re: Light
« Reply #3 on: October 17, 2010, 11:00:46 pm »
That is REALLY cool.  I do suggest making the shadows grayscale, however.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Light
« Reply #4 on: October 17, 2010, 11:03:29 pm »
That looks awesome!  By the way, if you think you can read the algorithms, there's this wonderful program: http://www.ticalc.org/archives/files/fileinfo/226/22637.html
I love that game on my 86. ;D

Here's the source: http://www.ticalc.org/archives/files/fileinfo/226/22638.html

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Light
« Reply #5 on: October 17, 2010, 11:04:27 pm »
That is REALLY cool.  I do suggest making the shadows grayscale, however.

i second this. but instead of drawing lines to the backbuffer, draw the lines as you are now every other frame. that way you gain speed, and the shadows now appear gray.


Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Light
« Reply #6 on: October 17, 2010, 11:07:35 pm »
Oh, those are shadows! I totally thought those were like columns coming up at you :P That makes more sense now about the light thing. Ya, gray shadows would be cool :)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Light
« Reply #7 on: October 17, 2010, 11:21:53 pm »
Any optimization suggestions, please?
(I'm using a variant of Bresenham's line algorithm, for those interested)

It looks awesome, but why are you using that algorithm? It could very well be faster to set the initial screen and adjust the start/end points of the Line( function (which already uses Bresenham's algorithm).
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

_player1537

  • Guest
Re: Light
« Reply #8 on: October 17, 2010, 11:33:29 pm »
I think the algorithm is to allow a straight line to be drawn from the player to the next pillar (or from the pillar to the edge of the screen)  Qwerty is kinda right though, there is already a line routine written in ASM, if you can get the code for that routine and edit it apropriately, you can get the same routine but 9001% faster.  Quigibo released the source a long time ago, so you might want to look for it, if you (or anyone) can't find it, I'll edit my post.

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: Light
« Reply #9 on: October 17, 2010, 11:37:26 pm »
Wow that seems slow but looks AWESOME! It brought me back awesome memories from Blinded By The Dark! I hope you can make it faster. :)

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Light
« Reply #10 on: October 17, 2010, 11:38:10 pm »
Any optimization suggestions, please?
(I'm using a variant of Bresenham's line algorithm, for those interested)

It looks awesome, but why are you using that algorithm? It could very well be faster to set the initial screen and adjust the start/end points of the Line( function (which already uses Bresenham's algorithm).

I'm using the algorithm to test when the shadows should start.  The algorithm tests all the points in the line, and when it encounters a black pixel, it switches over to the built in line( function to draw it.

--
Okay, grayscale it is!
--
Anybody know where I can find a TI-86 emulator?  I wanna try Blinded by the Dark.
« Last Edit: October 17, 2010, 11:39:58 pm by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

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: Light
« Reply #11 on: October 17, 2010, 11:43:31 pm »
There's VirtualTI on ticalc.org but you need a 86 ROM.

Btw what makes the grayscale faster than monochrome? O.O

_player1537

  • Guest
Re: Light
« Reply #12 on: October 17, 2010, 11:53:32 pm »
It makes it prettier :)

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: Light
« Reply #13 on: October 18, 2010, 12:22:53 am »
Ah ok.

_player1537

  • Guest
Re: Light
« Reply #14 on: October 18, 2010, 12:26:18 am »
Actually, it just occured to me that it'd be *really* easy to add greyscale with the way greyscale is currently set up.  Store the layer you get from here, to the backbuffer, and copy-pasta the main image that you are doing collision tests with to the front buffer and blamo!  Greyscale shadows :D