Game Development Community

ScriptObject and memory question

by Travis Womack · in Torque Game Builder · 08/14/2005 (10:46 am) · 5 replies

I am working on an RPG (old school 2d SSI Gold box kinda stuff) and the memory usage of T2D is alarming. I have a question about ScriptObjects and my use of them.
Right now for example I have a character class for the characters and enemies in my game:
$defaultObj = new ScriptObject(defaultObj){
		class = "character";
		t2d_ref = 0;
		x_size = 50;
		y_size = 50;
		imageMap = "punk_char";
		x_position = 0; //X position in tiles
		y_position = 0; //Y position in tiles

		str = 10;
		dex = 10;
		cons = 10;
		int = 10;
		mnt = 10;
		hit_pts = 10;
		mnt_pts = 10;
		max_hit_pts = 10;
		max_mnt_pts = 10;
		orig_str = 10;
		orig_dex = 10;
		orig_int = 10;
		orig_mnt = 10;
		orig_cons = 10;
		orig_hit_pts = 10;
		orig_mnt_pts = 10;
		level = 1;
		game_class = "Monster";
		move_pts = 3;
		game_name = "Monster";
		status = "Normal";
		move_pts_left=0;
		initative = 0;
		effect_set = 0;
		spell_set = 0;
		weapon_set = 0;
		armor_set = 0;
		item_set = 0;
		
	};
This is really working great because I can write functions like this:
function character::setCons(%this, %set_var){
		%this.cons = %set_var;
}
	
function character::getCons(%this){
		return %this.cons;
}
	
function character::setInt(%this, %set_var){
		%this.int = %set_var;
}
	
function character::getInt(%this){
		return %this.int;
}
There are alot of functions for the character class (applying damage, figuring out status, applying bonuses and penalties, etc...)
and in my game there are around 2-15 character Scriptobjects at any time.
My question is about memory usage. For each character scriptobject is there a seperate memory space for their functions or since they are all of the character class does the character specific functions share the same space?

I am hitting around 140 mb of memory and that is just kinda scary due to what still needs to get implemented.
Any ideas?

#1
08/14/2005 (11:27 am)
140mb of memory is a lot! Marbleblast and ThinkTanks use much less memory. Have you tried calling: purgeResources and clearTextureHolds ?
#2
08/14/2005 (11:40 am)
Quote:I am hitting around 140 mb of memory and that is just kinda scary due to what still needs to get implemented.

Torque's script engine would have to be horribly inefficient for it to be taking up any significant portion of that. What other stuff have you loaded (images, sounds, etc)?
#3
08/14/2005 (11:48 am)
Ok I solved the 140 mb issue. I was playing around a few weeks ago with a large (54mb) wav file and forgot to get rid of the datablock.
Brought the mem usage down to 34 mb, yay!

But the main question I had was about ScriptObjects of the same class sharing the same function memory space, or does each ScriptOjbect instance have a the class's functions in a seperate memory space?
#4
08/16/2005 (12:19 pm)
Travis, no, each instance of a ScriptObject does not have it's own functions loaded into memory. In fact, instances of a ScriptObject don't use memory to even keep a reference to it's associated functions. Torque simply figures out what functions call to make when you call an object's function at runtime through a bit of intelligent namespace mapping.

So no, it's nothing to worry about. Good luck wth your game!
#5
08/16/2005 (1:28 pm)
Thanks for the response. I was worried but they way you descrive it makes sense.
For some reason I can get inheritance, polymorphism, and classes but namespaces make my head hurt :)