1 registered members (TipmyPip),
18,546
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Anet demo Frozen
#351282
12/23/10 10:28
12/23/10 10:28
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
hi, i want to try anet so i downloaded the demo but when i close the alert that it will close after 3 mins the screen freezes and i cant do anything and the alert is in the screen as if it is a panel. main script
#include <acknex.h>
#include <anet.h>
#include <default.c>
#include <windows.h>
#include <ackphysx.h>
#include <main.h>
#include <kotu_network.c>
function PhysikIntialise()
{
physX_open();// für Physik !
pX_setgravity(vector(0,0,-9));
}
function main()
{
PhysikIntialise();
var i;
fps_max = 60;
mouse_mode = 0;
video_mode = 8;
video_screen = 0;
for(i=0;i<4;i++) {players[i] = 0;}
level_load("");
while(!key_any)
{
wait(1);
}
if(key_s)
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_server();
wait(4);
start_client(_str("127.0.0.1"));
}
else
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_client(_str("127.0.0.1"));
}
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
camera.pan -= mouse_intens*mouse_force.x;
camera.tilt += mouse_intens*mouse_force.y;
if(camera.tilt > 90 )
{
camera.tilt = 90;
}
if(camera.tilt < -90)
{
camera.tilt = -90;
}
wait (1);
}
}
main.h
ENTITY* players[4];
var team1 = 0;
var team2 = 0;
var run = 1;
var PlayerinderLuft = 1;
var anziehung = 0;
var gravitiy = 1;
var movement_speed_fb = 12;
var movement_speed_rl = 6;
var mouse_intens = 4.5;
STRING* playername_input = "#50";
TEXT* inkey_playername_text =
{
pos_x = 245;
pos_y = 180;
layer = 1;
strings = 2;
string = "Playername:",playername_input;
}
function start_server();
function start_client(STRING* ip);
function client_disconnected(var sender, STRING* msg, var length);
function connected_with_server(var sender, STRING* msg, var length);
function disconnected_from_server(var sender, STRING* msg, var length);
function synchronizing_complete(var sender, STRING* msg, var length);
function create_player();
function Bewegen();
function disconnected_from_server(var sender, STRING* msg);
function enet_initialisieren();
kotu_network.c
#include <acknex.h>
#include <anet.h>
#include <main.h>
#include <default.c>
#include <windows.h>
#include <ackphysx.h>
//netzwerk
function enet_initialisieren()
{
enet_init();
enet_svset_event(EVENT_DISCONNECTED,"client_disconnected");
enet_clset_event(EVENT_CONNECTED,"connected_with_server");
enet_clset_event(EVENT_DISCONNECTED,"disconnected_from_server");
enet_clset_event(EVENT_SYNCHRONIZED,"synchronizing_complete");
//enet_clset_event(EVENT_LEVEL,"change_level_event");
//enet_svset_event(16,"kick_client");
//enet_svset_event(17,"receive_chatmsg");
//enet_clset_event(17,"receive_chatmsg");
}
function start_server()
{
level_load("media/levels/shooter.wmb");
wait(3);
enet_init_server(80,4,"");
wait(-1);
enet_set_level("media/levels/shooter.wmb");
}
function start_client(STRING* ip)
{
enet_init_client(ip,80,"");
}
function client_disconnected(var sender, STRING* msg, var length)
{
if(players[sender] != NULL)
{
ptr_remove(ptr_for_handle(players[sender].skill[40]));
enet_ent_remove(enet_ent_globpointer(players[sender]));
players[sender] = 0;
}
}
function connected_with_server(var sender, STRING* msg, var length)
{
enet_set_playername(playername_input); //sets the playername
if(enet_get_connection() == CLIENT_MODE) //if started as client
{
level_load(msg); //loads the level which is loaded on the server
wait(3); //wait until the level is loaded
enet_ent_synchronize(); //sends a synchronizing request
}
else //started as server or server/client
{
create_player(); //creates the correct character
}
}
function disconnected_from_server(var sender, STRING* msg, var length)
{
if(length == 0)
error("Lost connection to server!"); //shows a warning on the screen
else
error(msg); //show the sent string
sys_exit(NULL);
}
function synchronizing_complete(var sender, STRING* msg, var length)
{
create_player(); //creates the correct character
}
function follow(ENTITY* ent)
{
my.pan = camera.pan;
vec_set(camera.x,ent.x);
}
function Bewegen()
{
VECTOR player_dist;
VECTOR save_pos;
VECTOR temp;
var save_pan = 0;
TEXT* name_text;
STRING* save_str = "#50";
VECTOR vFeet;
vec_for_min(vFeet,me);
my.flags |= SHADOW;
while(enet_ent_globpointer(my) == ANET_ERROR) {wait(1);}
players[enet_ent_creator(enet_ent_globpointer(my))] = my;
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{
wait(1);
while(enet_get_clientid() != ANET_ERROR)
{
if(key_shift)
{
run = 1.5;
}
else
{
if(key_ctrl)
{
run = 0.5;
}
else
{
run = 1;
}
}
VECTOR* mov = vector(0,0,0);
if(key_w)mov.x=movement_speed_fb * run*time_step;
if(key_s)mov.x=movement_speed_fb/2 *-1*run*time_step;
if(key_a)mov.y=movement_speed_rl * run*time_step;
if(key_d)mov.y=movement_speed_rl *-1*run*time_step;
// ANGLE* nothing = camera.pan;
// nothing.tilt=0;
if(c_trace(my.x,vector(my.x,my.y,my.z-40),IGNORE_ME | IGNORE_PASSABLE)){
anziehung=0;
PlayerinderLuft=0;
// c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
// my.z = hit.z - vFeet.z + 15;
}
else
{
anziehung=anziehung+gravitiy;
PlayerinderLuft=1;
}
vec_rotate(mov,camera.pan);
if(key_space && PlayerinderLuft==0)
{
mov.z=5*time_step;
anziehung=-30;
PlayerinderLuft=1;
mov.z=-1*anziehung*time_step;
}
else
{
mov.z=-1*anziehung*time_step; // must be set, because vec_rotate sets mov.z when the camera looks up/down.
}
pXent_movechar(me, mov, camera.pan, 0);
follow(me);
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z)
{
enet_send_pos(enet_ent_globpointer(my),BROADCAST,NULL);vec_set(save_pos,my.x);
}
if(save_pan != my.pan)
{
enet_send_angle(enet_ent_globpointer(my),BROADCAST,ONLYSEND_PAN);save_pan = my.pan;
}
}
}
else
{
name_text = txt_create(2,2);
name_text.flags |= VISIBLE;
my.skill[40] = handle(name_text); //saves the handle local
while(my != NULL && enet_get_connection() != NO_CONNECTION && enet_ent_globpointer(my) != ANET_ERROR)
{
vec_set(temp,my.x);
vec_to_screen(temp,camera);
name_text.pos_x = temp.x-20;
if(vec_dist(my.x,camera.x)>1) //no div through 0
{
name_text.pos_y = temp.y-250/(vec_dist(my.x,camera.x)*0.01);
}
else
{
name_text.pos_y = temp.y-300;
}
enet_get_playername(enet_ent_creator(enet_ent_globpointer(my)),save_str);
str_cpy((name_text->pstring)[0],save_str);
wait(1);
}
}
}
function create_player()
{
if(team1 <= team2)
{
ENTITY* phys=enet_ent_create("media/models/earth.mdl",vector(-3,2439,100),"Bewegen"); // die variable wird nur für die folgenden physikeinstellungen gebraucht
team1 += 1;
pXent_settype(phys, PH_CHAR, PH_SPHERE);
pXent_setfriction (phys,0);
pXent_setmass( phys, 2 );
}
else if(team1 >team2)
{
team2 += 1;
ENTITY* phys=enet_ent_create("media/models/earth.mdl",vector(-3,2439,100),"Bewegen"); // die variable wird nur für die folgenden physikeinstellungen gebraucht
pXent_settype(phys, PH_CHAR, PH_SPHERE);
pXent_setfriction (phys,0);
pXent_setmass( phys, 2 );
}
}
//netzwerk
any idea? or is it just on my pc?
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351293
12/23/10 12:59
12/23/10 12:59
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Two things i noticed but have nothing to do with your problem: 1) Don't use port 80 for your server. Port 80 reserved for HTTP! Use a port greater than 1023 (I always use 2300). 2) Don't do everything in one step if you write a program. Do it step by step! For example: In the first step you start to write the initialisation of ANet and then you TEST IT! In the next step you extend your script with the part that tries to start a server. If this works add the client initialisation. After that you try to connect them. And so on... If you do too much steps in one it will be very hard for you to detect occuring problems. I looked over your code, but I couldn't see anything that shouldn't work. If the ANet Demo message is displayed, ANet was loaded correctly and will work on your system. There are three methodes you can use to solve your problem: 1) You could use the debugger to find out where the script freezes. 2) You try to comment everything out that is not related to your problem (step by step). If the problem suddenly doesn't occure anymore then the last thing you commented out causes your bug. 3) OR and that's what I would advice you to do, start to write this script again and do it step by step. This way you will have a much easier life! If you add a next step and a problem occures, you always know that you did something wrong in the last step and it should be easy for you to find out what causes the problem. Otherwise, a big project will be impossible to realise. I hope I could help you 
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351294
12/23/10 13:24
12/23/10 13:24
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
thx, thopught i understand it so i havent done it step by step so now i changen the main.c and it freezes after i clicked ok when it says that it will close after 3 mins because i use the demo. main.c
#include <acknex.h>
#include <anet.h>
#include <default.c>
#include <windows.h>
#include <ackphysx.h>
#include <main.h>
#include <kotu_network.c>
function PhysikIntialise()
{
physX_open();// für Physik !
pX_setgravity(vector(0,0,-9));
}
function main()
{
PhysikIntialise();
var i;
fps_max = 60;
mouse_mode = 0;
video_mode = 8;
video_screen = 0;
//for(i=0;i<4;i++) {players[i] = 0;}
level_load("media/levels/shooter.wmb");
while(!key_any)
{
wait(1);
}
/*if(key_s)
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_server();
wait(4);
start_client(_str("127.0.0.1"));
}
else
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_client(_str("127.0.0.1"));
}
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
camera.pan -= mouse_intens*mouse_force.x;
camera.tilt += mouse_intens*mouse_force.y;
if(camera.tilt > 90 )
{
camera.tilt = 90;
}
if(camera.tilt < -90)
{
camera.tilt = -90;
}
wait (1);
}*/
sys_exit("123");
}
so it don't load the level, so i think there is no problem with anet, but with the alert of the demo or my pc.
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351392
12/24/10 07:50
12/24/10 07:50
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
i got it i forgot a wait(1) in a while loop so it freezes. now there is just the problem that it says that it is unable to send the angle and position he always says bad global entity pointer. after 1-2 seconds the pointer is -1.
Last edited by Ceryni; 12/24/10 08:29.
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351409
12/24/10 12:45
12/24/10 12:45
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Is this on the server or on the client? Maybe you overwrite the my pointer somehow?
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351413
12/24/10 14:05
12/24/10 14:05
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
ok i got the problem the time between the server init and client init was too short when i make it higher it is perfekt nice plugin. Do you know how long it will take to get the anet plugin after sending the username? main.c
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <ackphysx.h>
#include "main.h"
#include "kotu_network.c"
function PhysikIntialise()
{
physX_open();// für Physik !
pX_setgravity(vector(0,0,-9));
}
function main()
{
PhysikIntialise();
var i;
fps_max = 60;
mouse_mode = 0;
video_mode = 8;
video_screen = 2;
for(i=0;i<4;i++) {players[i] = 0;}
level_load(NULL);
while(!key_any || key_f11)
{
wait(1);
}
if(key_s)
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_server();
wait(4);
start_client(_str("localhost"));
}
else if(key_c)
{
inkey_playername_text.flags |= VISIBLE;
inkey(playername_input);
inkey_playername_text.flags &= ~VISIBLE;
enet_initialisieren();
start_client(_str("localhost"));
}
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
camera.pan -= mouse_intens*mouse_force.x;
camera.tilt += mouse_intens*mouse_force.y;
if(camera.tilt > 90 )
{
camera.tilt = 90;
}
if(camera.tilt < -90)
{
camera.tilt = -90;
}
wait (1);
}
}
main.h
ENTITY* players[4];
var team1 = 2;
var team2 = 0;
var run = 1;
var PlayerinderLuft = 1;
var anziehung = 0;
var gravitiy = 1;
var movement_speed_fb = 12;
var movement_speed_rl = 6;
var mouse_intens = 4.5;
STRING* playername_input = "#50";
TEXT* inkey_playername_text =
{
pos_x = 245;
pos_y = 180;
layer = 1;
strings = 2;
string = "Playername:",playername_input;
}
function start_server();
function start_client(STRING* ip);
function client_disconnected(var sender, STRING* msg, var length);
function connected_with_server(var sender, STRING* msg, var length);
function disconnected_from_server(var sender, STRING* msg, var length);
function synchronizing_complete(var sender, STRING* msg, var length);
function create_player();
function Bewegen();
function disconnected_from_server(var sender, STRING* msg);
function enet_initialisieren();
kotu_network.c
#include <acknex.h>
#include "anet.h"
#include <main.h>
#include <default.c>
#include <windows.h>
#include <ackphysx.h>
//netzwerk
function enet_initialisieren()
{
enet_init();
enet_svset_event(EVENT_DISCONNECTED,"client_disconnected");
enet_clset_event(EVENT_CONNECTED,"connected_with_server");
enet_clset_event(EVENT_DISCONNECTED,"disconnected_from_server");
enet_clset_event(EVENT_SYNCHRONIZED,"synchronizing_complete");
//enet_clset_event(EVENT_LEVEL,"change_level_event");
//enet_svset_event(16,"kick_client");
//enet_svset_event(17,"receive_chatmsg");
//enet_clset_event(17,"receive_chatmsg");
}
function start_server()
{
level_load("media/levels/shooter.wmb");
wait(3);
enet_init_server(80,4,"");
wait(-1);
enet_set_level("media/levels/shooter.wmb");
}
function start_client(STRING* ip)
{
enet_init_client(ip,80,"");
}
function client_disconnected(var sender, STRING* msg, var length)
{
if(players[sender] != NULL)
{
ptr_remove(ptr_for_handle(players[sender].skill[40]));
enet_ent_remove(enet_ent_globpointer(players[sender]));
players[sender] = 0;
}
}
function connected_with_server(var sender, STRING* msg, var length)
{
enet_set_playername(playername_input);
if(enet_get_connection() == CLIENT_MODE)
{
level_load(msg);
wait(3);
enet_ent_synchronize();
}
else
{
create_player();
}
}
function disconnected_from_server(var sender, STRING* msg, var length)
{
if(length == 0)
error("Lost connection to server!");
else
error(msg);
sys_exit(NULL);
}
function synchronizing_complete(var sender, STRING* msg, var length)
{
create_player();
}
function follow(ENTITY* ent)
{
my.pan = camera.pan;
vec_set(camera.x,ent.x);
}
function Bewegen()
{
VECTOR player_dist;
VECTOR save_pos;
VECTOR temp;
var save_pan = 0;
TEXT* name_text;
STRING* save_str = "#50";
follow(me);
VECTOR vFeet;
vec_for_min(vFeet,me);
my.flags |= SHADOW;
while(enet_ent_globpointer(my) == ANET_ERROR) {wait(1);}
players[enet_ent_creator(enet_ent_globpointer(my))] = my;
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{
wait(1);
while(enet_get_clientid() != ANET_ERROR )
{
var glopp = enet_ent_globpointer(my);
//printf("my var %.3f",(double) glopp);
if(key_shift)
{
run = 1.5;
}
else
{
if(key_ctrl)
{
run = 0.5;
}
else
{
run = 1;
}
}
VECTOR* mov = vector(0,0,0);
if(key_w)
{
mov.x=movement_speed_fb * run*time_step;
}
if(key_s)
{
mov.x=movement_speed_fb/2 *-1*run*time_step;
}
if(key_a)
{
mov.y=movement_speed_rl * run*time_step;
}
if(key_d)
{
mov.y=movement_speed_rl *-1*run*time_step;
}
// ANGLE* nothing = camera.pan;
// nothing.tilt=0;
if(c_trace(my.x,vector(my.x,my.y,my.z-40),IGNORE_ME | IGNORE_PASSABLE)){
anziehung=0;
PlayerinderLuft=0;
// c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
// my.z = hit.z - vFeet.z + 15;
}
else
{
anziehung=anziehung+gravitiy;
PlayerinderLuft=1;
}
vec_rotate(mov,camera.pan);
if(key_space && PlayerinderLuft==0)
{
mov.z=5*time_step;
anziehung=-30;
PlayerinderLuft=1;
mov.z=-1*anziehung*time_step;
}
else
{
mov.z=-1*anziehung*time_step;
}
pXent_movechar(me, mov, camera.pan, 0);
follow(me);
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z)
{
enet_set_unreliable(1);
enet_send_pos(enet_ent_globpointer(my),BROADCAST,0);vec_set(save_pos,my.x);
enet_set_unreliable(0);
}
if(save_pan != my.pan)
{
enet_set_unreliable(1);
enet_send_angle(enet_ent_globpointer(my),BROADCAST,ONLYSEND_PAN);save_pan = my.pan;
enet_set_unreliable(0);
}
wait(1);
}
}
else
{
name_text = txt_create(2,2);
name_text.flags |= VISIBLE;
my.skill[40] = handle(name_text);
while(my != NULL && enet_get_connection() != NO_CONNECTION && enet_ent_globpointer(my) != ANET_ERROR)
{
vec_set(temp,my.x);
vec_to_screen(temp,camera);
name_text.pos_x = temp.x-20;
if(vec_dist(my.x,camera.x)>1)
{
name_text.pos_y = temp.y-250/(vec_dist(my.x,camera.x)*0.01);
}
else
{
name_text.pos_y = temp.y-300;
}
enet_get_playername(enet_ent_creator(enet_ent_globpointer(my)),save_str);
str_cpy((name_text->pstring)[0],save_str);
wait(1);
}
}
}
function create_player()
{
if(team1 <= team2)
{
ENTITY* phys = enet_ent_create("media/models/earth.mdl",vector(-15,-3081,435),"Bewegen"); // die variable wird nur für die folgenden physikeinstellungen gebraucht
team1 += 1;
pXent_settype(phys, PH_CHAR, PH_SPHERE);
pXent_setfriction (phys,0);
pXent_setmass( phys, 2 );
}
else if(team1 >team2)
{
team2 += 1;
ENTITY* phys = enet_ent_create("media/models/earth.mdl",vector(-3,2439,100),"Bewegen"); // die variable wird nur für die folgenden physikeinstellungen gebraucht
pXent_settype(phys, PH_CHAR, PH_SPHERE);
pXent_setfriction (phys,0);
pXent_setmass( phys, 2 );
}
}
//netzwerk
i dont think taht i overwrite it but if i want to start a new process with a client and not a server/client the client cant see the server so maybe the entity is deleted when i move the client in the direction where the server can see him i see the client's entity but the client dont see the server. So i started a 3rd client he can see the client but not the client/server it seems that the client/server dont create any entity.
Last edited by Ceryni; 12/25/10 13:51.
|
|
|
Re: Anet demo Frozen
[Re: Ceryni]
#351522
12/26/10 12:16
12/26/10 12:16
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
ok i got the problem the time between the server init and client init was too short when i make it higher it is perfekt nice plugin. Do you know how long it will take to get the anet plugin after sending the username? The problem was caused by the waits in start_server(). If you have a wait in a subroutine, then the routine where the subroutine was called will continue. A wait() doesn't block the routine from where the subroutine was called like a Sleep() in C/C++ would do! I took a quick look at your code but actually I see no problem. Have you looked into the 3d chat example? It deals with exactly the same things you are asking for. Just compare your script with the 3d chat example (and read through the tutorial). Then I guess it should be easy for you to find the problem  Some hints how you could test out what the problem is: 1) Are the functions of the player entities called everywhere? (You could place an error("Function called!"); into the first line of the function) 2) Use the debugger to single step through your code (this is a bit tricky though, because if you are to slow then the connection to the server will be lost (because the client won't replay to pings from the server if you stop the client with the debugger). But you could again use the error() function to see if parts of your code are executed or not.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|