Hi,
So I understand why the "proc_mode = PROC_GLOBAL;" and if(!me) break; lines are included, so I would assume that it would be good to include this error checking feature in any while loop of an entity? It seems to be a good method.
But the program still crashes as soon as the model collides with a block or entity, I'll post the entire code, it is not much more lines than I have already included, but maybe after you see the other few lines can see what I missed..
There are only 2 files to the program: 1)level_1.c and play_2.c, the level is just a great square hollowed out block
with two models in it one assigned the players_code() action and 1 assigned the entity_example()
Note that a lot of the code from level_1.c has been commented out because it was taken from one og George's articles. Tomorrow I will clean it up a little better.
level_1.c
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////
#include "play_2.c"
function main()
{
level_load("level_1.WMB");
wait(2);
//printf("Press [0] to move the camera!");
fps_max = 70;
video_mode = 8; // run in 800 x 600 pixels
video_depth = 32; // 32 bit mode
video_screen = 2; // start in full screen mode
time_smooth = 0.9; // use a time_step value that is the average of the last 10 frames to smooth the replayed movement
//level_load (test_wmb);
// the quit_game function deletes the previously saved data files as well - examine recreplay.c to see its code
//on_esc = sys_exit(NULL); // now we can safely shut down the engine
}
action players_code() // simple (flying!) player and 1st person camera code
{
// these 3 lines have to be added to every entity that needs to be recorded
//max_ents += 1; // get a unique entity number
//my.skill99 = max_ents; // and store it inside skill99 (don't use skill99 for anything else)
//record_me(my.skill99); // put this line here
// these 3 lines have to be added to every entity that needs to be recorded
//mouse_mode=2;
player = my; // I'm the player
set (my, INVISIBLE); // no need to see player's model in 1st person mode
//set (my, PASSABLE);
while (1)
{
//if (mode != REPLAYING) // this is your regular entity code
//{
// move the player using the "W", "S", "A" and "D" keys; "10" = movement speed, "6" = strafing speed
c_move (my, vector(10 * (key_w - key_s) * time_step, 6 * (key_a - key_d) * time_step, 0), nullvector, GLIDE);
vec_set (camera.x, player.x);
player.pan -= 5 * mouse_force.x * time_step; // rotate the camera around by moving the mouse
player.tilt += 3 * mouse_force.y * time_step;
camera.pan = player.pan; // the camera and the player have the same angles
camera.tilt = player.tilt;
camera.roll = player.roll;
//}
// we need this "else" section because the recreplay.c code moves the player entity and not the camera
// this is the playback code; the camera copies player's values, which were stored in player's recorded data file
//else
//{
// camera.x = my.x;
// camera.y = my.y;
// camera.z = my.z;
// camera.pan = my.pan;
// camera.tilt = my.tilt;
// camera.roll = my.roll;
//}
wait (1);
}
}
action entity_example()
{
play((my.skill99=max_ents++));
}
play_2.c:
var max_ents = 0; // this variable stores the maximum number of entities
var recorded_position[70000][50]; // stores x y z pan tilt roll frame for 10,000 frames and up to 50 different entities
var pause_replay[50];
BMAP* cursor_tga = "cursor.tga";
function mouse_startup()
{
mouse_mode = 0;
mouse_map = cursor_tga;
while (1)
{
vec_set(mouse_pos, mouse_cursor);
wait(1);
}
}
var gt=0;
function my_event()
{
switch (event_type)
{
case EVENT_BLOCK:
beep();
gt=5;
break;
case EVENT_ENTITY:
beep();
break;
}
}
function play(entity_number)
{
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY ) ;
my.event = my_event();
STRING* rec_str = str_create("_______"); // stores the name of the recorded data file
STRING* temp_str = str_create("___"); // just a temporary string
var filehandle;
str_cpy(rec_str, str_for_num(temp_str, entity_number)); // create the name of the data file depending on entity's number
str_cat(rec_str, ".txt"); // and then add it the ".txt" extension
filehandle = file_open_read(rec_str); // now we can try to open the file
if (filehandle)
{
proc_mode = PROC_GLOBAL;
var temp = 0;
VECTOR tempStore;
VECTOR tempStorePan;
VECTOR tempVector;
var spaceFind;
var totalSpaces=0;
var count=0;
while(file_find(filehandle, " ")>=0) count++;
file_seek (filehandle, 0, 0); // reset read position back
while(temp < count)
{
if(!me) break; //abort reading if entity gone.
tempStore.x=file_var_read(filehandle);
tempStore.y=file_var_read(filehandle);
tempStore.z=file_var_read(filehandle);
tempStorePan.x=file_var_read(filehandle);
tempStorePan.y=file_var_read(filehandle);
tempStorePan.z=file_var_read(filehandle);
my.frame = file_var_read(filehandle); // and put them inside the array
// rotate towards target
vec_set(tempVector, tempStore.x);
vec_sub(tempVector, my.x);
vec_to_angle(my.pan, tempVector);
//move to it with collision
c_move(my, vector(5 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);
temp +=1;
wait(1);
}
file_close(filehandle); // close the file
beep();
}
}