Skip to content

Commit 416b804

Browse files
committed
fixing segment loading and including length in metainf
1 parent e3db708 commit 416b804

3 files changed

Lines changed: 59 additions & 73 deletions

File tree

src/SDD.Table.js

Lines changed: 51 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@ var ME = EVEoj.SDD.Table,
66
E = EVEoj,
77
SDD = EVEoj.data,
88

9-
// default object properties
10-
_D = {
11-
'src': null, // the EVEoj.data source that created this table
12-
'name': null, // the name of this table
13-
'keyname': null, // the primary key name
14-
'columns': [], // the list of columns
15-
'colmap': {}, // a reverse lookup map for column indexes
16-
'subkeys': [], // any subkeys (this implies a nested entry structure)
17-
'indexes': [], // indexes available for secondary entry lookups
18-
'segments': [] // the data for this table, in segments
19-
},
20-
219
_P = {}, // private methods
2210
P = {} // public methods
2311
;
2412

13+
// default object properties
14+
ME.D = {
15+
'src': null, // the EVEoj.SDD.Source that owns this table
16+
'name': null, // the name of this table
17+
'keyname': null, // the primary key name
18+
'columns': [], // the list of columns
19+
'colmap': {}, // a reverse lookup map for column indexes
20+
'subkeys': [], // any subkeys (this implies a nested entry structure)
21+
'data': {}, // the data for this table (shallow references into raw data from source)
22+
'segments': [], // the segment information for this table
23+
'length': 0, // the total number of entries in this table
24+
'loaded': 0 // the total number of currently loaded entries
25+
};
2526
ME.Create = function (name, src, meta) {
2627
var obj,
2728
i,
2829
keyarr
2930
;
3031

3132
obj = E.create(P);
32-
E.extend(true, obj, _D);
33+
E.extend(true, obj, ME.D);
3334

3435
// sort out relevant metadata details
3536
obj.src = src;
@@ -38,12 +39,12 @@ ME.Create = function (name, src, meta) {
3839
// determine the source(s) of this table's data
3940
if (meta.hasOwnProperty('j')) {
4041
// only one segment and it is stored with other stuff
41-
obj.segments.push({ 'min': 0, 'max': -1, 'tag': meta['j'], 'data': false, 'p': null });
42+
obj.segments.push({ 'min': 0, 'max': -1, 'tag': meta['j'], 'loaded': false, 'p': null });
4243
}
4344
else if (meta.hasOwnProperty('s')) {
4445
// at least one segment that is stored independently
4546
for (i = 0; i < meta['s'].length; i++) {
46-
obj.segments.push({ 'min': meta['s'][i][1], 'max': meta['s'][i][2], 'tag': name + '_' + meta['s'][i][0], 'data': false, 'p': null });
47+
obj.segments.push({ 'min': meta['s'][i][1], 'max': meta['s'][i][2], 'tag': name + '_' + meta['s'][i][0], 'loaded': false, 'p': null });
4748
}
4849
}
4950

@@ -59,9 +60,10 @@ ME.Create = function (name, src, meta) {
5960
obj.keyname = keyarr.shift();
6061
obj.subkeys.push(keyarr);
6162
}
62-
63-
if (meta.hasOwnProperty('i')) {
64-
obj.indexes = obj.meta['i'];
63+
64+
// grab the length
65+
if (meta.hasOwnProperty('l')) {
66+
obj.length = meta['l'];
6567
}
6668

6769
return obj;
@@ -77,16 +79,19 @@ P.GetEntry = function (key) {
7779
// is for segment comparison, string is for object property lookup
7880
nkey = parseInt(key);
7981
if (isNaN(nkey)) return null;
80-
skey = nkey.toString(10);
82+
skey = nkey.toString(10);
83+
if (this.data.hasOwnProperty(skey)) return this.data[skey];
84+
85+
// if we don't have this key, determine if we ought to by now
8186
for (i = 0; i < this.segments.length; i++) {
8287
if (nkey >= this.segments[i].min && (nkey <= this.segments[i].max || this.segments[i].max == -1)) {
8388
// the key should be in this segment
84-
if (this.segments[i].data) {
89+
if (this.segments[i].loaded) return null; // {
8590
// the segment is loaded, so either we have this key or it doesn't exist
86-
if (this.segments[i].data.hasOwnProperty(skey)) return this.segments[i].data[skey];
87-
else return null;
88-
}
89-
else return false; // the segment isn't not loaded yet
91+
// if (this.segments[i].data.hasOwnProperty(skey)) return this.segments[i].data[skey];
92+
// else return null;
93+
// }
94+
else return false; // the segment isn't loaded yet
9095
}
9196
}
9297

@@ -111,9 +116,17 @@ _P.SegLoadDone = function(tag, data, done, p, ctx) {
111116
done.has++;
112117
for (i = 0; i < this.segments.length; i++) {
113118
if (this.segments[i].tag != tag) continue;
114-
this.segments[i].data = data;
119+
if (data['tables'].hasOwnProperty(this.name) && data['tables'][this.name].hasOwnProperty('d')) {
120+
E.extend(this.data, data['tables'][this.name]['d']);
121+
if (data['tables'][this.name].hasOwnProperty('L')) {
122+
this.loaded += data['tables'][this.name]['L'];
123+
}
124+
else if (done.needs == 1) {
125+
this.loaded = this.length;
126+
}
127+
}
115128
break;
116-
}
129+
}
117130
if (done.has >= done.needs) p.resolveWith(ctx, [this]);
118131
else p.notifyWith(ctx, [this, done.has, done.needs]);
119132
};
@@ -140,7 +153,7 @@ P.Load = function(opts) {
140153
// load all segments
141154
all_needs = [];
142155
for (i = 0; i < this.segments.length; i++) {
143-
if (!this.segments[i].data) {
156+
if (!this.segments[i].loaded) {
144157
// this segment not yet loaded
145158
all_needs.push(i);
146159
}
@@ -181,9 +194,9 @@ P.Load = function(opts) {
181194
}
182195

183196
if (segment === -1) return p.rejectWith(o.ctx, [this, 'badkey', 'invalid key; no segment contains it']).promise();
184-
if (segment.data) return p.resolveWith(o.ctx, [this]).promise();
197+
if (segment.loaded) return p.resolveWith(o.ctx, [this]).promise();
185198

186-
if (segment.p == null) segment.p = this.src.LoadFile(segment.tag);
199+
if (segment.p == null) segment.p = this.src.LoadTag(segment.tag);
187200
done = {'needs': 1, 'has': 0};
188201
segment.p
189202
.done(function (tag, data) { _P.SegLoadDone.apply(self, [tag, data, done, p, o.ctx]) })
@@ -192,46 +205,14 @@ P.Load = function(opts) {
192205
return p.promise();
193206
}
194207
};
195-
196-
})();
197-
198-
/*
199-
EVEoj.data.EntryIter = EVEoj.data.EntryIter || {};
200-
(function ($) {
201-
var ME = EVEoj.data.EntryIter,
202-
E = EVEoj,
203-
D = EVEoj.data,
204-
_D = {
205-
'curidx': 0,
206-
'curseg': 0,
207-
'tbl': null
208-
},
209-
_P = {}
210-
;
211-
212-
ME.Create = function (tbl) {
213-
var obj
214-
;
215208

216-
obj = Object.create(_P),
217-
$.extend(true, obj, _D);
218-
obj.tbl = tbl;
209+
P.ColIter = function (colname) {
210+
var colnum;
211+
if (this.colmap.hasOwnProperty(colname)) {
212+
colnum = this.colmap[colname];
213+
return function (e) { return e[colnum] };
214+
}
215+
else return function (e) { return undefined };
216+
};
219217

220-
return obj;
221-
};
222-
223-
_P.HasNext = function () {
224-
if (this.curidx < this.keyset.length) return true;
225-
};
226-
227-
_P.Next = function () {
228-
var sys;
229-
230-
sys = S.Create();
231-
if (!sys.LoadID(this.src, this.tbl, this.keyset[this.curidx])) sys = null;
232-
this.curidx++;
233-
return sys;
234-
};
235-
236-
})(jQuery);
237-
*/
218+
})();

src/core.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ var ME = EVEoj,
55
F = function () {} // if needed for Object.create polyfill
66
;
77

8-
ME.MPLY = 9.4605284e+15; // meters per lightyear
9-
ME.MPAU = 1; // meters per AU
8+
ME.V_MAJOR = 0;
9+
ME.V_MINOR = 1;
10+
ME.V_PATCH = 0;
11+
ME.VERSION = ME.V_MAJOR + '.' + ME.V_MINOR + '.' + ME.V_PATCH;
12+
13+
ME.M_per_LY = 9.4605284e+15; // meters per lightyear
14+
ME.M_per_AU = 149597870700; // meters per AU
1015

1116
// implementations from external stuff (mostly jQuery) that might theoretically change later
1217
ME.create = (typeof Object.create == 'function')

src/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ EVEoj.map = EVEoj.map || {};
135135
;
136136

137137
dist = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2));
138-
return dist/E.MPLY;
138+
return dist/E.M_per_LY;
139139
};
140140

141141
_P.Route = function (fromSystemID, toSystemID, avoidList, avoidLow, avoidHi) {

0 commit comments

Comments
 (0)