Light Style© by Fisana

Jump to content


Photo

AI API changes


  • Please log in to reply
48 replies to this topic

#41 quantumstate

quantumstate

    Primus Pilus

  • WFG Programming Team
  • 1,150 posts

Posted 19 April 2012 - 11:03 AM

I suggest, in entity.js, replacing the "ressourceSupplyAmount" and "RessourceCarrying" function by those, who check whether those parameters are defined:

resourceSupplyAmount: function() {
		if(this._entity.resourceSupplyAmount == undefined)
			return undefined;
		return this._entity.resourceSupplyAmount;
	},

	resourceCarrying: function() {
		if(this._entity.resourceCarrying == undefined)
			return undefined;
		return this._entity.resourceCarrying; 
	},


You have used a weak equality check so null, 0, ""and false will be changed to undefined, is that intentional and why would you want that to happen? If it wasn't intentional then you have basically inserted a null operation (though from a quick search we do seem to have some of these checks in the entity.js file already).
  • 0
Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!

#42 wraitii

wraitii

    Primus Pilus

  • WFG Programming Team
  • 1,496 posts

Posted 19 April 2012 - 11:16 AM

Mh, no, actually, should either be === "undefined" or === undefined, not sure which one works.
I did that because if it is undefined, it will send a warning. It's not a huge problem ,I think it still works properly, but it can be a bit baffling.

Edited by wraitii, 19 April 2012 - 11:17 AM.

  • 0
Lancelot de Ferrière le Vayer [ aka Wraitii ]
Wildfire Games Programmer, AI developer, auxiliary map designer, dealing with anything water.
Contact me: wraitii@wildfiregames.com

Also the world's only three-dimensional poodle.

#43 quantumstate

quantumstate

    Primus Pilus

  • WFG Programming Team
  • 1,150 posts

Posted 20 April 2012 - 09:18 AM

Mh, no, actually, should either be === "undefined" or === undefined, not sure which one works.
I did that because if it is undefined, it will send a warning. It's not a huge problem ,I think it still works properly, but it can be a bit baffling.


Interesting, I didn't think that would happen but it does as you say. I will make the changes you suggest. It is === undefined.

Edit: I also think I have introduced a save/load bug with the new api, I will try and get this fixed soon.
  • 0
Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!

#44 quantumstate

quantumstate

    Primus Pilus

  • WFG Programming Team
  • 1,150 posts

Posted 20 April 2012 - 09:32 PM

Fixed a problem with save/load so now it works.
  • 0
Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!

#45 feneur

feneur

    Cartographer of imaginary worlds

  • 0 A.D. Project Leader
  • 7,620 posts

Posted 20 April 2012 - 09:56 PM

Fixed a problem with save/load so now it works.

(y)
  • 0

Erik Johansson [ aka feneur ]

Wildfire Games
Contact me: feneur@wildfiregames.com



Support Wildfire Games!


#46 wraitii

wraitii

    Primus Pilus

  • WFG Programming Team
  • 1,496 posts

Posted 27 April 2012 - 12:30 PM

Hi Quantumstate... A few more questions about the API.

First, I'd recommend adding the "NOT" filter. It can be useful to check something like "Not a worker".
Filters["not"] = 
	function(filter1){
		return {"func": function(ent){
			return !filter1.func(ent);
	}, 
	"dynamicProperties": filter1.dynamicProperties};
};

Secondly: you give every entity collection a "this._ai" property... It works as a reference and not as a copy, right? Javascript is messing with my brain about those things.

Third: I sometimes get a "length NAN" error with entity collections if I don't ask for the length immediately after the entityCollection's creation. I guess that's an initialization error somewhere.

Finally, and this is perhaps more of a general question, it seems that after some times, using a lot of entity collections, I get a "out of memory" error in GUI/sessio.js, in an (eval) or something... It doesn't always happen, and judging from the profiler, the AI script doesn't seem to overload. And there is no following crash. Any idea what this error is?

edit: oh, and any ETA on AI support for technologies?

Edited by wraitii, 27 April 2012 - 12:51 PM.

  • 0
Lancelot de Ferrière le Vayer [ aka Wraitii ]
Wildfire Games Programmer, AI developer, auxiliary map designer, dealing with anything water.
Contact me: wraitii@wildfiregames.com

Also the world's only three-dimensional poodle.

#47 quantumstate

quantumstate

    Primus Pilus

  • WFG Programming Team
  • 1,150 posts

Posted 02 May 2012 - 04:25 PM

Hi Quantumstate... A few more questions about the API.

First, I'd recommend adding the "NOT" filter. It can be useful to check something like "Not a worker".


Thanks I added this.

Secondly: you give every entity collection a "this._ai" property... It works as a reference and not as a copy, right? Javascript is messing with my brain about those things.

Yes, all assignments with objects or array in javascript are by reference.

Third: I sometimes get a "length NAN" error with entity collections if I don't ask for the length immediately after the entityCollection's creation. I guess that's an initialization error somewhere.


Thanks, I have fixed this. It happened when the entity collection had a unit added or removed before the length was requested. Trying to increment or decrement 'undefined' is a bad idea.

Finally, and this is perhaps more of a general question, it seems that after some times, using a lot of entity collections, I get a "out of memory" error in GUI/sessio.js, in an (eval) or something... It doesn't always happen, and judging from the profiler, the AI script doesn't seem to overload. And there is no following crash. Any idea what this error is?


Out of memory is a nasty one to debug, currently there isn't a good way I know to debug them. One that I came across before which hit some GUI javascript was a mismatched profiler start/stop which lead to the profiler tree continuously growing.

edit: oh, and any ETA on AI support for technologies?

Not currently, I am fairly busy at the moment. I also don't know quite how ti will be implemented.
  • 0
Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!

#48 wraitii

wraitii

    Primus Pilus

  • WFG Programming Team
  • 1,496 posts

Posted 05 May 2012 - 04:55 PM

Yes, all assignments with objects or array in javascript are by reference.

Good to know, thanks!

Out of memory is a nasty one to debug, currently there isn't a good way I know to debug them. One that I came across before which hit some GUI javascript was a mismatched profiler start/stop which lead to the profiler tree continuously growing.

Allright, I'll keep watching.

No problem about the technologies, take all the time you need, better done well than rushed.

Another thing about the API: I see you use "VectorDistance" for "ByDistance" filtering... I've done checks in the past, and at least on my computer (but I'd expect on most), it was faster using SquareVectorDistance, even with the added multiplying (though by very little). Since afaik this will trigger for every position change for every entity in any entitycollection that requires it, I think it could be a, however little, welcome addition (if for some reason, one comes to do it 1000 times per turn in some extreme cases, it could make a difference).
  • 0
Lancelot de Ferrière le Vayer [ aka Wraitii ]
Wildfire Games Programmer, AI developer, auxiliary map designer, dealing with anything water.
Contact me: wraitii@wildfiregames.com

Also the world's only three-dimensional poodle.

#49 quantumstate

quantumstate

    Primus Pilus

  • WFG Programming Team
  • 1,150 posts

Posted 09 May 2012 - 09:46 PM

Another thing about the API: I see you use "VectorDistance" for "ByDistance" filtering... I've done checks in the past, and at least on my computer (but I'd expect on most), it was faster using SquareVectorDistance, even with the added multiplying (though by very little). Since afaik this will trigger for every position change for every entity in any entitycollection that requires it, I think it could be a, however little, welcome addition (if for some reason, one comes to do it 1000 times per turn in some extreme cases, it could make a difference).


Thanks. I have changed my local copy. I will not commit right now because we are in feature freeze.
  • 0
Jonathan Waller [ aka quantumstate ]

Wildfire Games Programmer
Contact me: jonathanmarkwaller at gmail dot com


Support Wildfire Games!