It is currently Wed Oct 18, 2017 8:01 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Tue Nov 15, 2016 3:39 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19094
Location: NE Indiana, USA (NTSC)
If you want to start a quiet RIOT, you can use $4010 and $4013 as a crude timer. It's a RIOT in that you get an IRQ notifying you that time has passed, but it's quiet because you won't be able to play sampled sound in the background.


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 4:40 pm 
Offline

Joined: Thu Aug 28, 2008 1:17 am
Posts: 591
Tepples: Nice :lol:

I meant knowing what your game logic can handle per frame, and using that regulate the max number of colisions for whatever objects for this frame, and the rest get queued for the next frame. Split it up however you want, but as someone else mentioned - certain collisions should have priority (player to map interface would be one) so they can be finished in one frame. But be careful, if the original queue overflowed to the next frame, and even just one from that queue overflowed to the following frame, I would stall game logic at that point and get it done. Because while roughly 1-2 pixel difference off from collision accuracy (due to a frame delay in logic relative to speed of object) might not be detectable by the player, anything larger than that probably will be detectable.

So, some game logic always runs 60fps (or every frame, to be more accurate), and some mitigates between every other frame and every frame (or is always assigned even or odd frame logic; either works). It won't guarantee you won't run into slowdown, but you'll reduce it and at the same time giving the appearance that everything is running 60 fps smooth - or done on every frame.

I've actually never done this in my own stuff. But I've noticed some games appeared to do this, and no one ever mentions anything about it - ignorance is bliss.

_________________
__________________________
http://pcedev.wordpress.com


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 5:01 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2283
I noticed that most of his code is spent looking up "collision box data" and setting everything up to do the collision detection.


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 5:58 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10051
Location: Rio de Janeiro - Brazil
psycopathicteen wrote:
I noticed that most of his code is spent looking up "collision box data" and setting everything up to do the collision detection.

I avoid this by indexing my collision boxes (up to 256 sets of top+bottom+left+right offsets from an object's hotspot), and having a field in each object's RAM indicating what box it's currently using.

My collision routine takes the indices of 2 objects in registers X and Y, so it can quickly subtract/compare their coordinates. If the distance between them is over 256 pixels, I don't even do anything else. If it's smaller than 256, that means I can do the next calculations using 8-bit math, which is a plus. I then subtract the relevant edges (either left and right or top and bottom, depending on the axis being tested) of each object's box from the distance, and a negative result means the objects are overlapping. Objects have to overlap in both axes to register a collision.

With this method I believe I'm saving some CPU time, mostly because I don't need to mess with pointers, and because part of the math can be done in 8-bit.


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 6:30 pm 
Offline

Joined: Thu Aug 28, 2008 1:17 am
Posts: 591
psycopathicteen wrote:
I noticed that most of his code is spent looking up "collision box data" and setting everything up to do the collision detection.

Oh wow, you're right.


Punch: That looks waaaaay over kill. What are you trying to do? (Something out of the norm?)

Why are you doing position translations of all corners? ;Obj2.x1 + Obj2.Posx

What is OBJ_COLLISION, x and what is OBJ_METASPRITE, x ? Are these projectiles? Destructible player objects? Enemy projectiles? Enemy objects?

_________________
__________________________
http://pcedev.wordpress.com


Last edited by tomaitheous on Tue Nov 15, 2016 6:51 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 6:49 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
If you're dealing with object tables, it seems natural to just use register X for everything, then you have parallel arrays (one array for X low byte, one array for X high byte, etc...) that can all be indexed with just X or Y.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 7:20 pm 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 218
I spent the day trying to code something better, and since I dropped the "multiple boxes per metasprite" requirement, I did just as tokumaru said. No more indirection for what I'm doing, at least. It's buggy and not working properly but I'll see what I can do tomorrow.

Compare the old collision table with the new one:
Old: https://gitlab.com/aleff/BrixBattle/blo ... lision.txt
New: https://gitlab.com/aleff/BrixBattle/blo ... lision.txt

Way simpler huh? This is the new collision code: https://gitlab.com/aleff/BrixBattle/blo ... lision.asm . Less stupider. :lol:

tomaitheous wrote:
psycopathicteen wrote:
I noticed that most of his code is spent looking up "collision box data" and setting everything up to do the collision detection.

Oh wow, you're right.


Punch: That looks waaaaay over kill. What are you trying to do? (Something out of the norm?)

Why are you doing position translations of all corners? ;Obj2.x1 + Obj2.Posx

What is OBJ_COLLISION, x and what is OBJ_METASPRITE, x ? Are these projectiles? Destructible player objects? Enemy projectiles? Enemy objects?


It is now that I think about it. The translations are done because the center of the object is arbitrary, it's not always the left corner of the sprite. See https://gitlab.com/aleff/BrixBattle/blo ... r/anim.txt for the format.

OBJ_COLLISION is a byte for registering which object from the list is currently colliding with the object. I might think of something better later but that will do for now.
OBJ_METASPRITE is the metasprite id for the object. One metasprite is paired with one or more bounding boxes. (now just one box per metasprite)
The objects can be anything, from projectiles to enemies to players to static sprites to anything really. They all have the same attributes for now since I have lots of free RAM.

_________________
This is a block of text that can be added to posts you make. There is a 255 character limit.


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 7:36 pm 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 218
Double post: I wanted to implement this code: http://atariage.com/forums/topic/71120- ... ?p=1054049 but I can't figure out how it works. Anyone knows and wants to do an explanation of it?

_________________
This is a block of text that can be added to posts you make. There is a 255 character limit.


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 8:05 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1771
Location: DIGDUG
I suppose this would work, but this one only compares X, you would still need to check Y. I'm not convinced that it would be more efficient, but it's possible.

Code:
lda xpos1 ; x position, object 1
  sbc xpos2 ; x position, object 2 (without sec ??)
;the comment says n-1, perhaps you should clc first
  sbc #SIZE2-1 ;width of object 2(-1)
  adc #SIZE1+SIZE2-1 ;width of object 1+object2(-1)
; Carry set if overlap


I feel like there would be overhead for calculating sizes, therefore, not more efficient.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 1:35 am 
Offline
User avatar

Joined: Thu Sep 15, 2016 6:29 am
Posts: 249
Location: Denmark (PAL)
Did anyone actually do that thing where you check your frame timing to see if you need to delay certain routines until the next frame?
I've heard it mentioned several times before, and I know some commercial games do it, but to me it just sounds incredibly flaky... At least when it affects logic as critical to gameplay as collisions.

As I said in my previous post, apart from optimizing your algorithms and indexing your data, etc. the most effecient thing you could do, should always be building your game logic around what you know you can "afford", and how much stuff you're actually expecting to happen. If you're planning to often have 10 or more enemies on screen at the same time, your collision detection should be able to handle all of them, and if you need to spread collisions of certain objects between multiple frames in order to handle them all, I would personally prefer to do this unconditionally, rather than depending on whether your program is "running slow".
Checking if you need to delay some collisions to the next frame would add extra overhead to your code even when it's not relevant, and certainly allows for more bugs and erratic behavior, making testing more cumbersome.

I guess what I'm getting to is that if your program has special features that allows it to handle critical situations with a lot of action going on, it should be able to handle it well enough that it might as well do the same thing when nothing much is going on? Maybe I'm just being judgmental, but it sounds like bad design to me. :)


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 5:37 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1771
Location: DIGDUG
Quote:
Did anyone actually do that thing where you check your frame timing to see if you need to delay certain routines


Yes. Imagine that you do something as simple as update colors, which needs to be done during v-blank. Now imagine your game does some loading of information at some boundary (you crossed a room). Ok, the game will load all the information, which pushes the frame to the end of the next v-blank. You get to the color writing function, and instead of changing colors, you write junk tiles at the top of the screen. This scenario is easy to imagine for me, so I have to handle it by waiting till the next v-blank happens before writing those colors. Which is slow-down.

Super Mario Bros swaps colors of coins every frame. When too many hammers are on screen, which only happens rarely, it skips tons of frames, so it won't screw up timing on coin colors writes. I guess they didn't catch that in play testing, or maybe they would have limited the number of hammers. But, the programmers understood the importance of timing PPU writes.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 12:54 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2283
Wait? That doesn't make any sense? Updating the palette only takes writing 3 bytes. Does SMB manually write bytes to OAM instead of using sprite DMA?


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 1:45 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5714
Location: Canada
psycopathicteen wrote:
Does SMB manually write bytes to OAM instead of using sprite DMA?

No. Manual OAM updates are almost useless on hardware due to the DRAM decay. (I don't know of any games that use it, but I'm sure some exist. Not SMB though. Micro Machines polls $2004, but it doesn't use it to update sprites.)


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 2:16 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
rainwarrior wrote:
No. Manual OAM updates are almost useless on hardware due to the DRAM decay. (I don't know of any games that use it, but I'm sure some exist. Not SMB though. Micro Machines polls $2004, but it doesn't use it to update sprites.)

RC Pro Am apparently does things... interestingly. Some other games, like Trojan (Tatakai no Banka) and Huge Insect do something even more odd (that's for $2003 though, but the point stands).

The short of it: NES OAM is a weird quirk-filled beast.


Top
 Profile  
 
PostPosted: Wed Nov 16, 2016 2:37 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10051
Location: Rio de Janeiro - Brazil
rainwarrior wrote:
Micro Machines polls $2004, but it doesn't use it to update sprites.

I believe Super Cars does it too, to time a raster effect near the top of the screen.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Tomy and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group