In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Changes

Jump to navigation Jump to search
Line 630: Line 630:  
First thing we need to use layers is to include LayerManager.h, this is done in our program by including libwiisprite.h, which if you remember includes everything else in the library. Now  look further down the source at line 42;
 
First thing we need to use layers is to include LayerManager.h, this is done in our program by including libwiisprite.h, which if you remember includes everything else in the library. Now  look further down the source at line 42;
   −
<source = "cpp">LayerManager manager(3);</source>
+
<source lang = "cpp">LayerManager manager(3);</source>
    
This is the first call in the program to LayerManager, this creates an instance of LayerManager called manager and calls its constructer and passes 3 to it. This means that we now have a limit of 3 layers for this layer manager. What the constructer does is create an array of (in this case) 3 elements of type Layer. So it will look something like this (note its only and abstraction to make it easier to understand what it looks like in memory):
 
This is the first call in the program to LayerManager, this creates an instance of LayerManager called manager and calls its constructer and passes 3 to it. This means that we now have a limit of 3 layers for this layer manager. What the constructer does is create an array of (in this case) 3 elements of type Layer. So it will look something like this (note its only and abstraction to make it easier to understand what it looks like in memory):
    
     elements
 
     elements
   0        1       2
+
      0   1     2
[null][null][null]
+
  [null][null][null]
    
This is not a dynamic array, it is fixed on run time to the value you pass to the constructor so make sure you change the number to whatever is relevant to your program. The documentation defines it as;
 
This is not a dynamic array, it is fixed on run time to the value you pass to the constructor so make sure you change the number to whatever is relevant to your program. The documentation defines it as;
Line 666: Line 666:     
     elements
 
     elements
  0         1       2
+
      0     1     2
[sprite][null][null]
+
  [sprite][null][null]
    
The next line:
 
The next line:
Line 677: Line 677:     
     elements
 
     elements
  0               1           2
+
      0       1       2
[sprite][sprite2][null]
+
  [sprite][sprite2][null]
    
Now 2 of our elements ( 0 and 1 ) have objects in them, simple enough so far, now I introduce to you the Insert() function found in the LayerManager class:
 
Now 2 of our elements ( 0 and 1 ) have objects in them, simple enough so far, now I introduce to you the Insert() function found in the LayerManager class:
Line 698: Line 698:  
Just like with the Append function, it requires the address of an object to add to the list, but as well as this it requires the element, where you want to insert. In the above it adds at the element 0, which is the first. Inserting here will increment the element number of each element that is greater than that of the inserted layer, if your list is full and you add something at the start, the last layer will be deleted. Here’s a visual representation of Inserting a layer to a full list:
 
Just like with the Append function, it requires the address of an object to add to the list, but as well as this it requires the element, where you want to insert. In the above it adds at the element 0, which is the first. Inserting here will increment the element number of each element that is greater than that of the inserted layer, if your list is full and you add something at the start, the last layer will be deleted. Here’s a visual representation of Inserting a layer to a full list:
   −
    elements
+
            elements
  0               1           2                           List is full
+
      0       1       2               List is full
[object1][object2][object3]
+
  [object1][object2][object3]
    
Calling: manager.Insert(object4, 0);
 
Calling: manager.Insert(object4, 0);
   −
        elements
+
            elements
  0               1           2                           
+
        0       1       2                           
[object4][object1][object2]  -> object3 is lost in memory. NOT GOOD!!
+
  [object4][object1][object2]  -> object3 is lost in memory. NOT GOOD!!
    
To avoid losing objects in memory add a check to make sure that there is an empty, or null, element in the node, if there isn’t and you still wish to add an object delete one of the elements and Insert the object where required.  
 
To avoid losing objects in memory add a check to make sure that there is an empty, or null, element in the node, if there isn’t and you still wish to add an object delete one of the elements and Insert the object where required.  
Line 715: Line 715:  
our manager will look like this:
 
our manager will look like this:
   −
    elements
+
          elements
  0           1           2
+
      0     1       2
[quad][sprite][sprite2]
+
  [quad][sprite][sprite2]
    
Pretty slick isn’t it? Simple as that! Now you’re saying why on earth did I do all of that? Well simply put, this will now dictate what is drawn when. You may recall at the end of the previous lesson I gave you a very quick bit of information about this line:
 
Pretty slick isn’t it? Simple as that! Now you’re saying why on earth did I do all of that? Well simply put, this will now dictate what is drawn when. You may recall at the end of the previous lesson I gave you a very quick bit of information about this line:
Line 745: Line 745:  
Say we have out manager set up like this:
 
Say we have out manager set up like this:
   −
    elements
+
            elements
  0               1           2                           
+
      0       1       2                           
[object1][object2][object3]
+
  [object1][object2][object3]
    
Then we call Remove() like this:  manager.Remove(&object1);  
 
Then we call Remove() like this:  manager.Remove(&object1);  
 
Now our list will look like this:
 
Now our list will look like this:
   −
    elements
+
          elements
  0           1           2                           
+
      0     1       2                           
[null][object2][object3]
+
  [null][object2][object3]
    
You may insert an object at element 0 as the function checks if the element is null or not. Simple enough to understand, the function requires the address of the object to remove.
 
You may insert an object at element 0 as the function checks if the element is null or not. Simple enough to understand, the function requires the address of the object to remove.
Line 782: Line 782:       −
    elements
+
              elements
         0               1             2                           
+
         0       1       2                           
[object1][object2][object3]
+
    [object1][object2][object3]
000000    000001  000002  - example memory addresses
+
      000000    000001  000002  - example memory addresses
     
33

edits

Navigation menu