Author Topic: Drawing from 2-byte positions  (Read 4009 times)

0 Members and 1 Guest are viewing this topic.

Offline ThatTreeOverThere

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Drawing from 2-byte positions
« on: March 23, 2013, 11:16:51 pm »
So I'm ThatTreeOverThere, new only in posting to the forums  :) , and I've been playing with Axe for a little while. I've run into an issue, though...
I'm making a top-down zombie shooter, and i'm having trouble drawing sprites exactly where I want them to go. I want to be able to store the positions of each zombie in 2 bytes per value (so, 4 bytes for X and Y together), but when I go to draw them on the screen, I suspect that Pt-On( converts my beautiful 16-bit numbers into 8-bit numbers and causes sprites to draw modulo 256, which is annoying!  >:(

The specific part in source looks like:

Code: [Select]
For(I,0,S
Pt-On({I*2*2+B}[sup]r[/sup]+X,{I*2*2+B+2}[sup]r[/sup]+Y,Pic1
End

Where S is the number of sprites-1, Pic1 is the sprite image pointer, B is a pointer to a list consisting of 2byte X and Y values (and I'll optimize out that last duplicate expression later :) )

So can anyone help me?

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Drawing from 2-byte positions
« Reply #1 on: March 24, 2013, 02:17:59 am »
First of all, closed parentheses are encouraged in Axe as future versions may not support open parentheses.
Code: [Select]
For(I,0,S)
Pt-On({I*2*2+B}{^r}+X,{I*2*2+B+2}{^r}+Y,Pic1)
End

Keep in mind that the screen is only 96x64 pixels wide, so even if I is only 24, you're not going to see your sprite at all. If you post a bit more information and maybe a screenshot, it'll be easier to resolve this issue.
« Last Edit: March 24, 2013, 02:18:11 am by leafy »
In-progress: Graviter (...)

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Drawing from 2-byte positions
« Reply #2 on: March 24, 2013, 03:46:33 am »
The sprite drawing routines (and for that matter, pretty much all drawing routines) in Axe have always treated the position inputs as 8-bit numbers. Probably the main reason is that it makes the underlying assembly code simpler, smaller, and faster, while still doing enough for almost all uses of the commands. I always wondered in the back of my head if this would ever be a problem for anybody, but I think you're actually the first one to ever come forward with this issue. :P

Unfortunately, I shouldn't/can't really change it from 8-bit clipping as it is now. There is the issue of increased code complexity, size, and execution time as I mentioned before, but those alone probably wouldn't stop me from thinking about making the change. What would stop me is that, although you use 16-bit positions, I know a lot of other coders and their projects are fine with, and use, 8-bit positions for objects/entities. The issue arises if these 8-bit positions are negative, because the sign information is really lost with Axe's standard, unsigned 8-bit memory read (the value is actually converted to a 16-bit value, it's just a value from 0-255 so the high 8 bits are always 0). And having negative positions is important in some cases, like having sprites that are partly off-screen on the top or left side of the screen.

Anyways, tl;dr: sprite commands use, and must keep using, 8-bit positions. So I think your possible solutions are either to find a way to downgrade to 8-bit positions or to perform initial major clipping with your own code. The first option is definitely easier and more efficient, so I'd be interested to know a bit more about your project and entities to determine whether or not it's possible.
« Last Edit: March 24, 2013, 03:47:36 am by Runer112 »

Offline ThatTreeOverThere

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: Drawing from 2-byte positions
« Reply #3 on: March 24, 2013, 07:25:05 am »
So can you explain to me how I'm supposed to draw the sprites? Like using conditionals to say, "oh this is obviously not the correct 256*256 area that I'm supposed to draw in, let's not draw the sprite"?
I mean, all I have for code now are boxes and a camera system, it's basically all drawing from prewritten data. Runer, you can modify whatever you'd like, there's not much there yet :)
(Also if I could figure out how to post entire sources without retyping them...)
I'd like it to feel like an open world, if possible. I'd like to draw and store procedurally created buildings in a city (even though it may not be possible)
« Last Edit: March 24, 2013, 07:29:53 am by ThatTreeOverThere »

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Drawing from 2-byte positions
« Reply #4 on: March 24, 2013, 08:33:06 am »
To post source code, you can use SourceCoder or TokenIDE, which are on-computer TI-Basic/Axe editors (they're respectively web and app based).
And for your problem, you can simply check whether or not the sprite is on screen, and then draw it at the proper position if it is. ;) That's what Runer meant by "initial major clipping" I think.

Offline ThatTreeOverThere

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: Drawing from 2-byte positions
« Reply #5 on: March 24, 2013, 08:42:09 am »
So I need to check if the sprite is in a certain position... So I'll check if each coordinate is greater than 0 but less than the screen size in that direction? Lemme try this out.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Drawing from 2-byte positions
« Reply #6 on: March 24, 2013, 08:43:28 am »
Hmm, might I ask why you need 16-bit coordinates? And will they be signed or unsigned? If they are unsigned, you will not be able to use the negative coordinates Runer112 mentioned.

Offline ThatTreeOverThere

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: Drawing from 2-byte positions
« Reply #7 on: March 24, 2013, 08:51:39 am »
Xeda:
I feel like 1 byte for position is too limiting... even though I could be wrong and am just overlooking a better way to make a slightly more "open-world" game :P Also right now they're unsigned, but I can work with that. Also I'm just testing everything out, there's not really that much written just yet.

Edit: Dang, didn't work with a bunch of comparisons to see if it's in screen space. Are comparisons 16-bit? (also I think I may just go back to 8-bit)
« Last Edit: March 24, 2013, 08:56:26 am by ThatTreeOverThere »

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Drawing from 2-byte positions
« Reply #8 on: March 24, 2013, 10:38:58 am »
You wouldn't need 16-bit coordinates if you just want the screen to be the area to walk around or whatever, but that''s not what you want, right?

If I understood you correctly, you have also 2 16-bit coordinates of the camera. To get the right coordinates for your sprite on the screen, simply subtract the camera coordinates from the sprite coordinates. You might need to check whether the sprite is on the screen or not, you can achieve that by testing X+8 > 103 and Y+8 > 71, that will handle negative coordinates as well.
« Last Edit: March 24, 2013, 10:39:34 am by MGOS »

Offline ThatTreeOverThere

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +0/-0
    • View Profile
Re: Drawing from 2-byte positions
« Reply #9 on: March 24, 2013, 12:42:42 pm »
EDIT: I'm an idiot, I left the conditional commented for testing and uncommented it when I wanted to change it :P
It works now, thanks so much guys :)
(Original message)
MGOS: I tried that, or at least something similar:

Quote from: Code
:For(I,0,S
:I*2*2+B→r6
:{r6}^r^+X→r1
:{r6+2}^r^+Y→r2
:.If r1≥≥0?r1<<96?r2≥≥0?r2<<64
:Pt-On(r1,r2,Pic1
:.End
:End
« Last Edit: March 24, 2013, 12:45:17 pm by ThatTreeOverThere »