2 registered members (AndrewAMD, flink),
748
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Single- 2 Multi-Player Konvertierung / Pointer Problem (eng/ger)
#230242
10/03/08 23:02
10/03/08 23:02
|
Joined: Aug 2003
Posts: 127 Berlin, Germany
CHaP
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 127
Berlin, Germany
|
ENGLISH BELOW --------------------------------------------------- HEY !! Ich bin gerade dabei, mein derzeitigen Single-Player Code in ein Multi-Player Code zu konvertieren. Zur Hilfe hab ich mir dazu ein neues Projekt angelegt, indem ich die Mechanik erst einmal testen bzw. versuchen will zu verstehen, wie der Multiplayer mit der Engine funktioniert. Momentan hab ich das System so verstanden, dass auf jedem Rechner eine Instance mit dem selben Quellcode läuft. Soweit so gut. Mit den AUM's 76/77 bin ich auch schon gut voran gekommen und die Entitys laufen wie sie sollen. Nur die Kamera will nicht so richtig. Hier der Code aus dem Hilfs-Projekt:
////////////////////////////////////////////////////////////////////////
// Multiplayer Test Project
////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
////////////////////////////////////////////////////////////////////////
FONT* font_arial = "Arial#20b";
////////////////////////////////////////////////////////////////////////
STRING* str_Message1 = "#30";
////////////////////////////////////////////////////////////////////////
VECTOR* vec_ServerMove = {x=0;y=0;z=0;}
////////////////////////////////////////////////////////////////////////
ENTITY* ent_Camera = 0;
////////////////////////////////////////////////////////////////////////
TEXT* t_DEBUG =
{
pos_x = 10;
pos_y = 10;
font = font_arial;
string = str_Message1;
flags = VISIBLE;
}
////////////////////////////////////////////////////////////////////////
function fROOT_Camera()
{
if(ent_Camera != 0)
{
while(1)
{
camera.x = (ent_Camera.x - 400);
camera.y = ent_Camera.y;
camera.z = (ent_Camera.z + 100);
wait(1);
}
}
}
////////////////////////////////////////////////////////////////////////
function fROOT_Player()
{
while(1)
{
vec_ServerMove.y -= my.skill10;
vec_ServerMove.x += my.skill11;
vec_ServerMove.z += my.skill12;
c_move(my,vec_ServerMove,nullvector,IGNORE_ME | IGNORE_MODELS);
vec_set(vec_ServerMove,nullvector);
ent_sendnow(my);
fROOT_Camera();
wait(1);
}
}
////////////////////////////////////////////////////////////////////////
function fROOT_CreatePlayer()
{
switch(connection)
{
case 2: // Client
{
my = ent_create("player_0.mdl",vector(0,0,150),fROOT_Player);
wait(1);
ent_Camera = my;
while(1)
{
my.skill10 = key_force.x * time_step * 5;
my.skill11 = key_force.y * time_step * 5;
my.skill12 = 0;
send_skill(my.skill10,SEND_VEC);
wait(1);
}
break;
}
default: // Server-Client/Error
{
my = ent_create("player_0.mdl",vector(0,0,150),fROOT_Player);
wait(1);
ent_Camera = my;
while(1)
{
my.skill10 = key_force.x * time_step * 5;
my.skill11 = key_force.y * time_step * 5;
my.skill12 = 0;
wait(1);
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 60;
level_load ("level_0.wmb");
switch(connection)
{
case 2: // Client
{
str_cpy((t_DEBUG.pstring)[0],"Client");
break;
}
default: // Server-Client/Error
{
str_cpy((t_DEBUG.pstring)[0],"Server-Client/Error");
break;
}
}
fROOT_CreatePlayer();
}
////////////////////////////////////////////////////////////////////////
// E O F
////////////////////////////////////////////////////////////////////////
Ich vermute mal, es liegt an dem Pointer (ent_Camera). Ohne die Abfrage, ob der Pointer ungleich NULL ist, stürtzt das Programm, im Client-Modus, ab. Der Server-Modus hingegen funktioniert. Jetzt zu meiner Logik: Wenn man also annimmt, das jedes laufende Programm, also jeder laufende Client, den selben Code, wie der Server, besitzt, müssten doch auch jedesmal die Pointer neu erzeugt werden. Somit hat jeder Client, einen eigenen ent_Camera Pointer, den er auch kennen und benutzen sollte. Tjo, auf dem Client klappts aber nicht. Woran liegts? --------------------------------------------------------------- I try to convert my single-player code to an multi-player code. I've already read the AUM 76 n 77, so it works fine with the entity movement but, the point is now, I don't get it with the handling of the pointers in a multi-player game. In fact, the function fROOT_Camera doesn't work, if I start the client-mode. I think the matter in this case is the pointer ent_Camera. What's wrong?
Last edited by CHaP; 10/04/08 16:51.
|
|
|
Re: Single- 2 Multi-Player Konvertierung / Pointer Problem (eng/ger)
[Re: CHaP]
#230471
10/05/08 18:09
10/05/08 18:09
|
Joined: Aug 2003
Posts: 7,439 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,439
Red Dwarf
|
like always..?
what exactly is your problem with those events?
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: Single- 2 Multi-Player Konvertierung / Pointer Problem (eng/ger)
[Re: Michael_Schwarz]
#230493
10/06/08 00:42
10/06/08 00:42
|
Joined: Aug 2003
Posts: 127 Berlin, Germany
CHaP
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 127
Berlin, Germany
|
Like always?! Really? K, I think then I forgot something. Maybe, I've to register the Entity (cube_0.mdl) on the Server? Because, if I click on the Cube in the Client-Window, nothing happens.
////////////////////////////////////////////////////////////////////////
// Multiplayer Test Project
////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
////////////////////////////////////////////////////////////////////////
FONT* font_arial = "Arial#20b";
////////////////////////////////////////////////////////////////////////
STRING* str_Message1 = "#30";
////////////////////////////////////////////////////////////////////////
BMAP* BMAP_MouseMap = "mouse_0.tga";
////////////////////////////////////////////////////////////////////////
VECTOR* vec_ServerMove = {x=0;y=0;z=0;}
////////////////////////////////////////////////////////////////////////
ENTITY* ent_Camera = 0;
////////////////////////////////////////////////////////////////////////
TEXT* t_DEBUG =
{
pos_x = 10;
pos_y = 10;
font = font_arial;
string = str_Message1;
flags = VISIBLE;
}
////////////////////////////////////////////////////////////////////////
function fEVENT_Cube()
{
switch(event_type)
{
case EVENT_CLICK:
{
printf("YES !!!!");
break;
}
}
}
////////////////////////////////////////////////////////////////////////
function fROOT_Cube()
{
my.event = fEVENT_Cube;
my.emask |= (ENABLE_CLICK);
}
////////////////////////////////////////////////////////////////////////
function fROOT_Camera()
{
if(ent_Camera != 0)
{
while(1)
{
camera.x = (ent_Camera.x - 400);
camera.y = ent_Camera.y;
camera.z = (ent_Camera.z + 100);
wait(1);
}
}
}
////////////////////////////////////////////////////////////////////////
function fROOT_Player()
{
while(1)
{
vec_ServerMove.y -= my.skill10;
vec_ServerMove.x += my.skill11;
vec_ServerMove.z += my.skill12;
c_move(my,vec_ServerMove,nullvector,IGNORE_ME);
vec_set(vec_ServerMove,nullvector);
ent_sendnow(my);
wait(1);
}
}
////////////////////////////////////////////////////////////////////////
function fROOT_CreatePlayer()
{
switch(connection)
{
case 2: // Client
{
my = ent_create("player_0.mdl",vector(0,0,150),fROOT_Player);
wait(1);
ent_Camera = my;
while(1)
{
my.skill10 = key_force.x * time_step * 5;
my.skill11 = key_force.y * time_step * 5;
my.skill12 = 0;
send_skill(my.skill10,SEND_VEC);
fROOT_Camera();
wait(1);
}
break;
}
default: // Server-Client/Error
{
my = ent_create("player_0.mdl",vector(0,0,150),fROOT_Player);
wait(1);
ent_Camera = my;
ent_create("cube_0.mdl",vector(100,100,50),fROOT_Cube);
wait(1);
while(1)
{
my.skill10 = key_force.x * time_step * 5;
my.skill11 = key_force.y * time_step * 5;
my.skill12 = 0;
fROOT_Camera();
wait(1);
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 60;
fps_lock = ON;
mouse_map = BMAP_MouseMap;
mouse_mode += 2;
mouse_range = 2000;
level_load ("level_0.wmb");
switch(connection)
{
case 2: // Client
{
str_cpy((t_DEBUG.pstring)[0],"Client");
break;
}
default: // Server-Client/Error
{
str_cpy((t_DEBUG.pstring)[0],"Server-Client/Error");
break;
}
}
fROOT_CreatePlayer();
while(1)
{
vec_set(mouse_pos,mouse_cursor);
wait(1);
}
}
////////////////////////////////////////////////////////////////////////
// E O F
////////////////////////////////////////////////////////////////////////
These tomorrow, I will read the Loocoweed Tutorials and I hope, after this becomes some clearly.
|
|
|
Re: Single- 2 Multi-Player Konvertierung / Pointer Problem (eng/ger)
[Re: CHaP]
#230525
10/06/08 13:55
10/06/08 13:55
|
Joined: Aug 2003
Posts: 7,439 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,439
Red Dwarf
|
i guess you have to create the cube locally (ent_createlocal) aswell to register events on the client side.
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: Single- 2 Multi-Player Konvertierung (eng/ger)
[Re: Michael_Schwarz]
#230535
10/06/08 15:04
10/06/08 15:04
|
Joined: Aug 2003
Posts: 127 Berlin, Germany
CHaP
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 127
Berlin, Germany
|
K, it works (only the client), but, that's not my target. =) I want create some items, like in an Shooter or RPG, and all players can collect them in your own inventory. As well back into the 3d world for the other players. And, for the best way, I need the 'event_click'-event for this action. The Locoweed Tutorial use events for the weapon-projectiles and ammos, but I do not understand how it works. He set the emask of this Entitys on ENABLE_IMPACT and in the event function of this, there are no event_type lines. Why? I'am confused. Locoweed Tutorial (ammo example):
function ammo_event()
{
if ((you.weapon == WEAPON_COMPRESSION_RIFLE) && (my.power_up_type == POWER_UP_AMMUNITION_CARTRIDGE))
{
if (you.ammunition_remaining < AMMO_MAX)
{
you.ammunition_remaining += int(random(15)) + 1;
if (you.ammunition_remaining > AMMO_MAX)
{
you.ammunition_remaining = AMMO_MAX;
}
ent_playsound (you, snd_power_up, 60);
send_skill(you.ammunition_remaining, 0);
ammo_cartridge_count -= 1; // 1 less cartridge in level
ent_remove(my); // remove ammo
}
}
else
{
.
.
.
}
function ammo_function()
{
my.ENABLE_IMPACT = ON; // event for hit by another moving entity
my.EVENT = ammo_event; // event function
.
.
.
}
|
|
|
|