File: section.cpp

package info (click to toggle)
rafkill 1.2.2-3.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 13,268 kB
  • sloc: cpp: 13,508; makefile: 64; sh: 14
file content (159 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "section.h"
#include "spaceobj.h"
// #include <stdlib.h>
#include <iostream>
#include <vector>

using namespace std;

Section::Section():
section_y( 0 ),
section_x( 0 ){
// internal_list( 0 ) {

	/*
	for ( int q = 0; q < MAX_SECTION_LIST; q++ )
		container_list[q] = new vector< SpaceObject * >();
	*/

	current_list = lists.begin();

}


void Section::add( SpaceObject * who, int x, int y ) {

	y += MIN_SECTION_Y;
	y /= MAX_SECTION_OBJ_Y;
	x += MIN_SECTION_X;
	x /= MAX_SECTION_OBJ_X;

	if ( y >= 0 && y < MAX_SECTION_LIST_Y && x >= 0 && x < MAX_SECTION_LIST_X ) {

		//for ( int q = 0; q < container_list[y]->size(); q++ )
		//	if ( (*container_list[y])[q] == who ) return;

		// container_list[y]->push_back( who );
		container_list[y][x].push_back( who );

		lists[y*10+x] = &container_list[y][x];
	}

}


void Section::dispose( SpaceObject * who ) {

	for ( int y = 0; y < MAX_SECTION_LIST_Y; y++ )
		for ( int x = 0; x < MAX_SECTION_LIST_X; x++ ){
			vector< SpaceObject * > & vec = container_list[y][x];
			for ( vector< SpaceObject * >::iterator it = vec.begin(); it != vec.end(); ){
				if ( *it == who )
					it = vec.erase( it );
				else ++it;
			}
		}
	/*
	for ( int q = 0; q < MAX_SECTION_LIST_Y; q++ ) {

		for ( vector< SpaceObject * >::iterator it = container_list[q]->begin();
		it != container_list[q]->end(); ) {
			if ( *it == who )
				it = container_list[q]->erase( it );
			else ++it;
		}

	}
	*/

}


void Section::print() {

	/*
	printf("Info for %p\n", this );
	for ( int q = 0; q < MAX_SECTION_LIST; q++ ){

		printf("Container %d\n", q );
		Iterator * i = container_list[q]->iterator();

		while ( !i->isEmpty() ){
			printf("[%p]", i->getObj() );
			i->Next();
		}

	delete i;
	printf("\n");

	}
	printf("End info for %p\n", this );
	*/

}


void Section::reset() {
	// internal_list = 0;
	section_y = 0;
	section_x = 0;
	current_list = lists.begin();
}


int Section::spacerY() {
	return MAX_SECTION_OBJ_Y;
}

int Section::spacerX() {
	return MAX_SECTION_OBJ_X;
}

void Section::clear() {

	/*
	for ( int q = 0; q < MAX_SECTION_LIST; q++ )
		container_list[q]->clear();
	internal_list = 0;
	*/
	cout<<"CLEARARARA"<<endl;

}


vector< SpaceObject * > * Section::getNext() {

	/*
	if ( section_x < MAX_SECTION_LIST_X && section_y < MAX_SECTION_LIST_Y ){
		vector< SpaceObject * > * ret = &container_list[section_y][section_x];
		section_x++;
		if ( section_x >= MAX_SECTION_LIST_X ){
			section_x = 0;
			section_y++;
		}

		return ret;
	}
	*/
	if ( current_list == lists.end() ) return NULL;
	vector< SpaceObject * > * ret = (*current_list).second;
	current_list++;
	return ret;
	return NULL;
	/*
	if ( internal_list < MAX_SECTION_LIST ) {
		internal_list++;
		return container_list[ internal_list-1 ];
	}
	return NULL;
	*/
}


Section::~Section() {
	// clear();
	/*
	for ( int q = 0; q < MAX_SECTION_LIST; q++ )
		delete container_list[q];
		*/
}