Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 748 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Fast external file reading #217667
07/24/08 10:46
07/24/08 10:46
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline OP
User
delinkx  Offline OP
User

Joined: Jul 2008
Posts: 553
Singapore
Hi,

I am reading a txt file which has coordinates for moving some entities in a cube room.

i notice it takes long time to read the file. and the movements look very bad. like there is a long gap between the movements.

Below is the function to read the data of the file, Is there any way i can improve the reading of the file. cause the movements are really bad.


---------------


function load_file()
{
var anim_percent = 0;
file_handle = file_open_read("debugLog32.txt");



if(file_handle == 0)
printf("Error Reading File");
else
{
while(eof_count!=1)
{
//wait(1);
eof_count = file_str_read(file_handle,sfile);


if(str_cmp(sfile,"CREATE"))
{
agent_count++;

//id
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);

i = integer(str_num);

Agent[i].ID = i;



//x
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
Agent[i].xpos = str_num;


//y
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
Agent[i].ypos = str_num;



//z
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
Agent[i].zpos = str_num;


//timestamp
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
Agent[i].timestamp = str_num;



//CREATE ENTITY
Agent[i].entAgent = ent_create(strModel, vector(Agent[i].xpos,Agent[i].ypos,-55), NULL);
set(Agent[i].entAgent, SHADOW);

}


if(str_cmp(sfile,"RUN"))
{

//id
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
i = integer(str_num);
tempAgent.ID = i;

//x
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
tempAgent.xpos = str_num;

//y
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
tempAgent.ypos = str_num;

//z
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
tempAgent.zpos = str_num;

//timestamp
eof_count = file_str_read(file_handle,sfile);
str_num = str_to_num(sfile);
tempAgent.timestamp = str_num;


// CALCULATE speed, pan angle, distance and MAKE MOVEMENT

//x-distance
xdist = tempAgent.xpos - Agent[i].xpos;

//y-distance
ydist = tempAgent.ypos - Agent[i].ypos;

//timecount
timecount = tempAgent.timestamp - Agent[i].timestamp;

//keeping track of time
timelock = total_ticks;

while((total_ticks - timelock)/16 <= timecount )
{


Agent[i].entAgent.pan += ydist*time_step;
c_move (Agent[i].entAgent, vector(5*xdist*time_step, 0, 0), nullvector, GLIDE | IGNORE_YOU | IGNORE_MODELS);

if ((xdist == 0) && (ydist == 0))
{
//no animation
anim_percent += 5*time_step;
ent_animate(Agent[i].entAgent, "stand", anim_percent, ANM_CYCLE);
}
else
{
anim_percent += 1.3 * xdist * time_step * 5;
ent_animate(Agent[i].entAgent, "walk", anim_percent, ANM_CYCLE);
}

wait(1);
}



//UPDATING THE ARRAY
Agent[i].ID = tempAgent.ID;



Agent[i].xpos = tempAgent.xpos;




Agent[i].ypos = tempAgent.ypos;



Agent[i].zpos = tempAgent.zpos;



Agent[i].timestamp = tempAgent.timestamp;


//wait(1);

}



}
}



}


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: Fast external file reading [Re: delinkx] #217674
07/24/08 10:56
07/24/08 10:56
Joined: Feb 2008
Posts: 97
Steev Offline
Junior Member
Steev  Offline
Junior Member

Joined: Feb 2008
Posts: 97
Ugh, that is a lot of code...

I would read the file first. After loading I would steer the entitys with an array. This migth be faster than reading and moveing at runtime. You must know, the harddisk is one of the slowest hardwarecomponents in a pc.

best regards steev

Last edited by Steev; 07/24/08 10:58.

---
programming is a livestyle
Re: Fast external file reading [Re: Steev] #217675
07/24/08 11:07
07/24/08 11:07
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline OP
User
delinkx  Offline OP
User

Joined: Jul 2008
Posts: 553
Singapore
Originally Posted By: Steev
Ugh, that is a lot of code...

I would read the file first. After loading I would steer the entitys with an array. This migth be faster than reading and moveing at runtime. You must know, the harddisk is one of the slowest hardwarecomponents in a pc.

best regards steev


yes thats true. but the file is quite big. every 0.05 seconds it gives the position of the entities. i have around 200 entities. and the file looks like this:


CREATE,1,2460.11,-596.35,128.001,0.0*
CREATE,2,1034.28,-1228.65,128.001,0.0*
CREATE,3,1430.34,273.059,128.001,0.0*
CREATE,4,479.787,-2572.28,128.001,0.0*
CREATE,5,2380.9,352.096,128.001,0.0*
CREATE,6,2618.53,-754.424,128.001,0.0*
CREATE,7,-946.045,-912.498,128.001,0.0*
CREATE,8,479.787,273.059,128.001,0.0*
CREATE,9,1271.92,-833.461,128.001,0.0*
CREATE,10,162.936,-438.275,128.001,0.0*
.
.
.
. (till 200)
.
RUN,7,-930.045,-912.498,128.001,0.0
RUN,8,479.787,257.059,128.001,0.0
RUN,10,162.936,-454.275,128.001,0.0
RUN,4,479.787,-2556.28,128.001,0.0
RUN,3,1414.34,273.059,128.001,0.0
RUN,1,2444.11,-596.35,128.001,0.0
RUN,2,1034.28,-1244.65,128.001,0.0
RUN,5,2364.9,352.096,128.001,0.0
RUN,9,1281.146745456179,-837.613113872019,128.001,0.0
RUN,6,2602.53,-754.424,128.001,0.0
RUN,9,1293.098549970394,-845.5541176069796,128.001,0.05
RUN,1,2428.11,-596.3464999999851,128.001,0.05
RUN,10,162.936,-470.275,128.001,0.05
RUN,2,1034.28,-1260.65,128.001,0.05
RUN,5,2348.9,352.096,128.001,0.05
RUN,8,479.787,241.05900000000003,128.001,0.05
RUN,3,1398.34,273.059,128.001,0.05
RUN,6,2586.53,-754.424,128.001,0.05
RUN,7,-914.045,-912.498,128.001,0.05
RUN,4,479.787,-2540.28,128.001,0.05,0
.
.
.
.
.
(some more for every 0.05secs)


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: Fast external file reading [Re: delinkx] #217678
07/24/08 11:26
07/24/08 11:26
Joined: Feb 2008
Posts: 97
Steev Offline
Junior Member
Steev  Offline
Junior Member

Joined: Feb 2008
Posts: 97
But (only) 200 Entitys are in any case possible.

First you´ve to read the (whole) file and save the positions for a move into an array. While reading the file you must not move the entitys.
After reading all positions, you´ve to create a while-loop to move the entitys. If you want to do this for every 0.05 secs, you could use a wait(-0.5).

best regards
steev


---
programming is a livestyle
Re: Fast external file reading [Re: Steev] #217686
07/24/08 11:46
07/24/08 11:46
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline OP
User
delinkx  Offline OP
User

Joined: Jul 2008
Posts: 553
Singapore
Originally Posted By: Steev
But (only) 200 Entitys are in any case possible.

First you´ve to read the (whole) file and save the positions for a move into an array. While reading the file you must not move the entitys.
After reading all positions, you´ve to create a while-loop to move the entitys. If you want to do this for every 0.05 secs, you could use a wait(-0.5).

best regards
steev



u mean to say save the whole file in arrays ? but thats gonna be very huge. cause the time steps are in 0.05 and for every 0.05 i will have 200 entries. (if reading the whole file).

but if every 0.05 secs i read the file, then here again the time to read the file come into play.

see suppose i run this simulation for 200 agents. for 34.4 secs, i will have 688 timesteps of 0.05secs. that means 688 x 200 vector entries.

thats gonna be huge for array values.


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1