Compare commits

..

7 Commits
0.6.1 ... 0.6.3

Author SHA1 Message Date
Stefan Zermatten
463b7f0fc9 Merge branch 'hotfix-rounding' 2015-06-29 09:45:38 +02:00
Stefan Zermatten
266495abc8 Bumped version 2015-06-29 09:44:57 +02:00
Stefan Zermatten
453d4365d3 Prevent memoized values being used in dependency loops 2015-06-29 09:41:01 +02:00
Stefan Zermatten
e0ce6275bf Floor character attribute values 2015-06-29 09:40:37 +02:00
Stefan Zermatten
80c72a274e Merge branch 'hotfix-minmax' 2015-06-26 10:48:43 +02:00
Stefan Zermatten
91f0f7954c Bumped version 2015-06-26 10:48:33 +02:00
Stefan Zermatten
c74abcb608 Fixed min and max error 2015-06-26 10:48:04 +02:00
3 changed files with 39 additions and 9 deletions

View File

@@ -186,7 +186,7 @@ Schemas.Character = new SimpleSchema({
Characters.attachSchema(Schemas.Character);
var attributeBase = function(charId, statName){
var attributeBase = preventLoop(function(charId, statName){
check(statName, String);
//if it's a damage multiplier, we treat it specially
if (_.contains(DAMAGE_MULTIPLIERS, statName)){
@@ -226,8 +226,8 @@ var attributeBase = function(charId, statName){
var base = 0;
var add = 0;
var mul = 1;
var min = Math.NEGATIVE_INFINITY;
var max = Math.POSITIVE_INFINITY;
var min = Number.NEGATIVE_INFINITY;
var max = Number.POSITIVE_INFINITY;
Effects.find({
charId: charId,
@@ -253,8 +253,8 @@ var attributeBase = function(charId, statName){
if (result < min) result = min;
if (result > max) result = max;
return result;
};
return Math.floor(result);
});
if (Meteor.isClient) {
Template.registerHelper("characterCalculate", function(func, charId, input) {
@@ -324,9 +324,9 @@ Characters.calculate = {
value += attribute.adjustment;
return value;
}),
attributeBase: memoize(preventLoop(function(charId, attributeName){
attributeBase: memoize(function(charId, attributeName){
return attributeBase(charId, attributeName);
})),
}),
skillMod: memoize(preventLoop(function(charId, skillName){
var skill = Characters.calculate.getField(charId, skillName);
//get the final value of the ability score
@@ -369,7 +369,7 @@ Characters.calculate = {
if (result < min) result = min;
if (result > max) result = max;
return result;
return Math.floor(result);
})),
proficiency: memoize(function(charId, skillName){
//return largest value in proficiency array
@@ -390,7 +390,7 @@ Characters.calculate = {
});
var advantage = Characters.calculate.advantage(charId, skillName);
value += 5 * advantage;
return value;
return Math.floor(value);
}),
advantage: memoize(function(charId, skillName){
var advantage = Effects.find(

View File

@@ -15,6 +15,7 @@ function CacheObject(func, address, args, cache, context){
var self = this;
self.currentValue = null;
self.dep = new Tracker.Dependency();
self.numRun = 0;
//spawn a new autorun that keeps the value up-to-date
Tracker.nonreactive(function() {
@@ -26,8 +27,22 @@ function CacheObject(func, address, args, cache, context){
delete cache[address];
return;
}
//if we haven't run this before this flush, reset the counter after the flush
if(self.numRun === 0){
Tracker.afterFlush(function(){
self.numRun = 0;
});
}
self.numRun++;
//call the expensive function
//even if we don't use its value, we need to track its dependencies
var newValue = func.apply(context, args);
//prevent dependency loops, the memoized function shouldn't re-run
//more than once per flush
if (self.numRun > 1){
newValue = NaN;
if(_.isNaN(self.currentValue)) return;
}
//if the value changed, store the new value
if (self.currentValue !== newValue){
self.currentValue = newValue;

View File

@@ -193,3 +193,18 @@ ChangeLogs.insert({
"Experience dialogs should update their edit-mode inputs properly now",
],
});
ChangeLogs.insert({
version: "0.6.2",
changes: [
"Fixed a regression which broke min and max effects",
],
});
ChangeLogs.insert({
version: "0.6.3",
changes: [
"Fixed a regression that stopped skills and attributes from rounding down correctly",
"Made dependency loops return NaN immediately, rather than looping indefinitely until a page refresh. Adding an effect that adds \"strength\" to Strength, won't cause Strength to constantly increase or freeze the browser, Strength just becomes NaN",
],
});