It is currently Sat Oct 21, 2017 7:58 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Dec 13, 2016 8:31 pm 
Offline

Joined: Sat Oct 22, 2016 3:36 am
Posts: 8
I'll be starting another NES game soon and am trying to come up with a different way to handle objects. In my current game, I just have arrays of variables that are accessed by using X or Y:
Code:
MAX OBJECTS = 6

X .dsb 6
Y .dsb 6
Health .dsb 6
State .dsb 6
Animation .dsb 6

I can access individual object's variables like so:
Code:
   ; Change object 0's health to 5
   LDX #$00
   LDA #$05
   STA Health, x
   
   ; Add 8 to object 2's X position
   LDY #$02
   LDA X, y
   CLC
   ADC #$08
   STA X, y

This system works fine for objects as long as they have the same number of variables. But what if I want to have an object that doesn't have any health? I could just use the same system but then I would be wasting a variable for an object that doesn't need it.

How have you guys implemented objects into your project? Does it handle cases such as mine?


Top
 Profile  
 
PostPosted: Tue Dec 13, 2016 8:41 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19115
Location: NE Indiana, USA (NTSC)
On the Atari 2600, you have only 128 bytes, so you must make each count. But on the NES, you have 2048 bytes, of which about 512 are spoken for by the structure of an NES program (VRAM transfer buffer, stack, OAM transfer buffer). If your object table has 16 variables for each of 16 actors, that's only one-eighth of RAM. Even if none of them have health at any given moment, you're wasting less than one percent. So some waste is probably acceptable.

If you do end up running out of RAM, and you have some actors that are far more complex than others, such as enemies and their bullets, reserving the highest numbered actor slots for "simple" actors might help you save memory.


Top
 Profile  
 
PostPosted: Tue Dec 13, 2016 9:17 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2963
Location: Tampere, Finland
You can, of course, reuse the health byte for some other purpose in the object that doesn't require health. You can make an alias for the Health symbol within the object code to make the code clearer (or, you can change the symbol to something more generic, like ObjData0, and alias it to Health for the objects which need it).

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Wed Dec 14, 2016 6:09 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
thefox wrote:
You can, of course, reuse the health byte for some other purpose in the object that doesn't require health. You can make an alias for the Health symbol within the object code to make the code clearer (or, you can change the symbol to something more generic, like ObjData0, and alias it to Health for the objects which need it).

I use this approach myself, but even then there's still a lot of wasted space.

I have considered other methods, such having 2 sizes of object slots, or having each object allocate only the memory it needs and use pointers instead of structures of arrays, but I don't think the memory savings are worth the increased complexity of the object system caused by these options.


Top
 Profile  
 
PostPosted: Thu Dec 15, 2016 2:27 pm 
Offline
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1306
For objects integral to the game, or other "special-case" objects that I expect to spawn and despawn frequently, I sometimes give them their own lists. For example, if I'm using particle effects, they get their own small buffer, same with projectiles. Things that are varied and change state less, like enemies or other objects on the map get placed in a general purpose "objects" list.


Top
 Profile  
 
PostPosted: Tue Dec 20, 2016 1:00 am 
Offline

Joined: Sat Oct 22, 2016 3:36 am
Posts: 8
Thanks guys. Seems like the most practical way is to just have those extra variables and maybe try to order the less complex objects first.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] 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