dMZX Forums: Linked lists for object lists? - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Linked lists for object lists?

#1 User is offline   LogiCow 

  • Ceci n'est pas un Logicow
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,600
  • Joined: 18-July 02

Posted 23 April 2010 - 03:06 AM

I'm thinking maybe some sort of linked list for object lists could work pretty well

say I have my base object to represent an abstract monster, with it's corresponding variables
m_N_x
m_N_y
m_N_character
m_N_color
m_N_abstract_previous
m_N_abstract_next
m_N_type

and my concrete object variables for a landmine monster
m_N_life
m_N_concrete_previous
m_N_concrete_next

finally, I need to keep track of two more variable: the first and the last elements of the abstract list, and the first and the last elements of the concrete landmine list.
m_first
m_last
landmine_first
landmine_last

Objects would share a common number between their abstract list and their concrete list

to add a landmine:
set "my_new_landmine" to "('m_last'+1)"

set "m_&my_new_landmine&_x" to 42
set "m_&my_new_landmine&_y" to 42
set "m_&my_new_landmine&_character" to 42
set "m_&my_new_landmine&_color" to 42
set "m_&my_new_landmine&_life" to 100

set "m_&my_new_landmine&_abstract_next" -1
set "m_&my_new_landmine&_concrete_next" -1
set "m_&my_new_landmine&_abstract_previous" to "m_last"
set "m_&my_new_landmine&_concrete_previous" to "landmine_last"

set "m_&m_last&_abstract_next" to "my_new_landmine"
set "m_&landmine_last&_concrete_next" to "my_new_landmine"

set "m_last" to "my_new_landmine"
set "landmine_last" to "my_new_landmine"


to display all the objects on the screen (including, but not specific to, landmines):

: "main_loop"

copy overlay block at "#blank_x" "#blank_y" for 80 by 25 to "#screen_buffer_x" "#screen_buffer_y"
set "iterator" "m_first"
: "loop"
if "iterator" = -1 "end"
goto "#display_character"
set "iterator" "m_&iterator&_abstract_next"
goto "loop"

: "end"
copy overlay block at "#screen_buffer_x" "#screen_buffer_y" for 80 by 25 to "screen_x" "screen_y"
wait 1
goto "main_loop"

: "#display_character"
if "m_&iterator&_x" < "buffer_left_edge" "#return"
if "m_&iterator&_x" >= "buffer_right_edge" "#return"
if "m_&iterator&_y" < "buffer_top_edge" "#return"
if "m_&iterator&_y" >= "buffer_bottom_edge" "#return"
set "vco('m_&iterator&_x'),('m_&iterator&_y')" to "m_&iterator&_color"
set "vch('m_&iterator&_x'),('m_&iterator&_y')" to "m_&iterator&_character"
goto "#return"


to remove dead landmines:

set "iterator" "landmine_first"
: "loop"
if "iterator" = -1 then "end"
set "iterator_next" "m_&iterator&_concrete_next"
goto "#verify"
set "iterator" "iterator_next"
goto "loop"

: "end"
end

: "#verify"
if "m_&iterator&_life" > 0 then "#return"
set "m_('m_&iterator&_concrete_previous')_next" "m_&iterator&_concrete_next"
set "m_('m_&iterator&_abstract_previous')_next" "m_&iterator&_abstract_next"
set "m_&iterator&_x" to 0
set "m_&iterator&_y" to 0
set "m_&iterator&_character" to 0
set "m_&iterator&_color" to 0
set "m_&iterator&_life" to 0
set "m_&iterator&_abstract_next" 0
set "m_&iterator&_concrete_next" 0
set "m_&iterator&_abstract_previous" to 0
set "m_&iterator&_concrete_previous" to 0
goto "#return"


If I'm not mistaken that would allow me to get:
Basic object inheritance (say, multiple specific enemy types all within a single enemy list),
A simple way to loop through any objects in a list,
A relatively simple way to add or remove objects in a list

Hmmm.

edit: whoops, did some basic mistake here.. lemme fix it. There.

This post has been edited by LogiCow: 23 April 2010 - 03:15 AM

0

#2 User is offline   mzxgiant 

  • DigitalMZX Server Ninja & Code Monkey
  • Group: DigiStaff
  • Posts: -79,797
  • Joined: 02-January 01

Posted 23 April 2010 - 04:00 AM

[09:37] <lolilover> logicow, that WAS a 'leaving forever' post right?
[09:37] <lolilover> you're not just going to come back in 6 months and pretend it never happened?
[09:37] * AFK has quit (Ping timeout: 180 seconds)
[09:38] <lolilover> just confirming
[09:39] <logicow> lolilover no
[09:39] <logicow> there's enough going on for me to visit once in a while
[09:39] <lolilover> what kind of halfassed leaving forever is that :(

http://zzt.belsambar...play&m=&id=3801
Visit my consulting company website, EMSA Consulting.


Posted Image The days keep on passing by... And we still chase the same star we once saw.
0

#3 User is offline   LogiCow 

  • Ceci n'est pas un Logicow
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,600
  • Joined: 18-July 02

Posted 23 April 2010 - 05:08 AM

I showed up for a DoZ and did Duck Rescue since then
0

#4 User is offline   Lancer-X 

  • どうせVIP@wwww>>安価orz
  • Group: Elite
  • Posts: 7,493
  • Joined: 20-March 02

Posted 23 April 2010 - 02:40 PM

array with swapping > linked list in mzx
Or can you show otherwise?

of course, it wouldn't let you do this but if I actually wanted to be able to iterate through arbitrary subclasses of objects quickly I'd probably just store their IDs in a string or something each cycle in the main loop. I wouldn't need to do this for all subclasses anyway

be faster too
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#5 User is offline   Maxim 

  • Dismember
  • Group: Elite
  • Posts: 901
  • Joined: 09-October 00

Posted 23 April 2010 - 02:59 PM

View PostLancer-X, on 23 April 2010 - 10:40 AM, said:

array with swapping > linked list in mzx


I can attest to that. The former there is all that I use. A linked list won't help with organization or speed at all.

It is an interesting thought, though.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users