Jump to content


Photo

39dll colour blending


  • Please log in to reply
21 replies to this topic

#1 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 09:18 AM

Hello. I have been having issue with my multiplayer game using 39dll.

I can send x, y, username and image angles perfectly fine, but sending image colour blending is the problem... I send the colour variable through writeint(), but when the game is running, the other player's sprite is just black and not the actual colour sent...

I am wondering what I am doing wrong, and how to go about this issue. I know that the message actually sends since the other player's sprite changes colour, but it seems as if the message data is only 0 resulting in the colour black.

Here is the code for the client sending the message:
clearbuffer();
writebyte(2);
writebyte(global.myid);
writeshort(x);
writeshort(y);
writeshort(sprite_index);
writeshort(image_speed);
writeshort(image_index);
writeshort(direction);
writeint(colour);
sendmessage(global.clienttcp);

alarm[11] = 1;

And here is the code for receiving and sending via the server:

var messagesize, messageid;

while(1)
{
 messagesize = receivemessage(obj_server.serverudp);

 if (messagesize <=0) messagesize = receivemessage(tcp);

 if (messagesize <=0) break;

 messageid = readbyte();

 switch(messageid)
 {   
  case 2:
  
  var player, value;
  value = readbyte();
  
  (string(global.players[value]),c_black);
  player = global.players[value];
  player.x = readshort();
  player.y = readshort();
  player.sprite_index = readshort();
  player.image_speed = readshort();
  player.image_index = readshort();
  player.direction = readshort();
  player.colour = readint();
  clearbuffer();
  writebyte(5);
  writebyte(value);
  writeshort(player.x);
  writeshort(player.y);
  writeshort(player.sprite_index);
  writeshort(player.image_speed);
  writeshort(player.image_index);
  writeshort(player.direction);
  writeint(player.colour);
  with(obj_client)
  {
   sendmessage(tcp);
  }
  break;
    
  case 3:
 
  var playerid, username;
  playerid = readbyte();
  username = readstring();
  clearbuffer();
  writebyte(6);
  writebyte(playerid);
  writestring(username,true);
  with(obj_client)
  {
   sendmessage(tcp);
  }
  script_addline(username + " has left.",c_black);
  with(global.players[playerid])
  {
   instance_destroy();
  }
  global.players[playerid] = -1;
  break;
    
  case 4:
  
  chatmessage = readstring();
  script_addline(chatmessage,c_black);
  clearbuffer();
  writebyte(8)
  writestring(chatmessage,true);
  with(obj_client)
  {
   sendmessage(tcp);
  }
  break;
 }
}

If you could help, that would be greatly appreciated, thankyou.

Edited by BlackEnergy, 03 July 2012 - 08:51 AM.

  • 0

#2 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 28 June 2012 - 09:33 AM

I think GM colors fit in a int but try using a double instead of int and see if it works.

Edited by filulilus, 28 June 2012 - 09:33 AM.

  • 0

#3 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 09:39 AM

Unfortunately it still results as black.
  • 0

#4 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 28 June 2012 - 10:40 AM

Yeah... if I remember correctly int should do.
As far as I can see there is nothing wrong with your code, so how do the variable "colour" effect the player object? I mean in the draw event etc...?

Edited by filulilus, 28 June 2012 - 10:40 AM.

  • 0

#5 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 11:49 AM

Well, the player object receives the colour variable in the draw event as:
colour = readint();
And draws its own sprite as:
draw_sprite_ext(sprite_index,image_index,x,y,1,1,direction,colour,1);

Edited by BlackEnergy, 28 June 2012 - 11:49 AM.

  • 0

#6 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 28 June 2012 - 12:06 PM

Well, the player object receives the colour variable in the draw event as:

>receives the colour variable in the draw event
>readint() in draw event

Wait, can you show what it exactly looks like, and the message receiving code of the client?

Edited by PrimuS, 28 June 2012 - 12:06 PM.

  • 0

#7 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 02:01 PM

Here is the code for receiving the colour variable through the client:

var messagesize, messageid;

while(1)
{
 messagesize = receivemessage(global.clienttcp);
    
 if (messagesize <= 0) break;

 messageid = readbyte();
    
 ping = 0;
    
 switch(messageid)
 {
  case 1:
  
  global.myid = readbyte();
  if end_game = true
  {
   clearbuffer();
   writebyte(4);
   writestring(global.username+" cannot join.",true);
   sendmessage(global.clienttcp);
            
   scr_online_gameend();
   exit;
  }
  else
  {
   obj_player1.alarm[11] = 1;
   obj_player1.alarm[10] = 1;
  }
  break;
    
  case 2:

  show_message("Cannot join, this server is full.");
  if end_game = true
  {
   scr_online_gameend();
   exit;
  }
  break;
        
  case 3:
  
  var userid, name, user;
  userid = readbyte();
  user = instance_create(obj_player1.xstart,obj_player1.ystart,obj_otherPlayer);
  user.pid = userid;
  name = readstring();
  user.username = name;
  players[userid] = user;
  script_addline(name + " has joined the game.",c_yellow);
  break;
        
  case 4:
 
  var name, userid;
  userid = readbyte();
  name = readstring();
  user = players[userid];
  user.username = name;
  script_addline(name + " has joined the game.",c_yellow);
  break;
        
  case 5:
 
  value = readbyte();
  player = players[value];
  player.x = readshort();
  player.y = readshort();
  player.sprite_index = readshort();
  player.image_speed = readshort();
  player.image_index = readshort();
  player.direction = readshort();
  player.colour = readint();
  break;
        
  case 6:
 
  var playerid, username;
  playerid = readbyte();
  username = readstring();
  script_addline(username + " has left the game.",c_yellow);
  with(players[playerid])
  {
   instance_destroy();
  }
  players[playerid] = -1;
  break;
        
  case 7:
  
  show_message("Connection lost. The server has shut down.");
  game_end();
  break;
        
  case 8:
 
  script_addline(readstring(),c_white);
  break;
        
  case 9:
  
  script_addline("Server: " + readstring(),c_white);
  break;
 }
}
    
ping += current_time - deltatime;
deltatime = current_time;

if(ping > timeout)
{
 show_message("Your connection has timed out.");
 game_end();
}

  • 0

#8 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 28 June 2012 - 03:53 PM

Dunno, should work fine. Try show_message(string(player.colour)) after you receive it to see what exactly does it send.
You're using ints, and they are 4 bytes IIRC. Just for debugging you can try sending RGB values in bytes instead of the whole GM color value, so it would take 3b instead of 4b and may also solve your problem.

Edited by PrimuS, 28 June 2012 - 03:54 PM.

  • 0

#9 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 29 June 2012 - 12:51 AM

Just out of curiosity, do you actually use the variable colour? Not image_blend? Or color?

Point is, you might be looking in the wrong place.
  • 0

#10 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 29 June 2012 - 07:28 AM

Do you recive all the other variables correctly btw?
  • 0

#11 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 29 June 2012 - 07:35 AM

@Primus: The message receives, but results as 0, being black...

@Gamer3D: Yes, I use initialize the colour variable as colour = readint(), and then draw the sprite's colour using that variable.

@filulilus: Yep, all other messages receive correctly like x, y, sprite_index, image_index and image_angle.

Edited by BlackEnergy, 29 June 2012 - 07:37 AM.

  • 0

#12 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 29 June 2012 - 07:54 AM

Try to put the writeint/readint in between the readshort/writeshort functions and see if that makes a diffrence.

such as:
clearbuffer(); 
writebyte(2); 
writebyte(global.myid); 
writeshort(x); 
writeshort(y); 
writeshort(sprite_index);
writeint(colour); 
writeshort(image_speed); 
writeshort(image_index); 
writeshort(direction); 
sendmessage(global.clienttcp);

  • 0

#13 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 29 June 2012 - 12:59 PM

Yeah, try changing its position, like place it right after ID or XY. 39dll may cut off a piece of the message in some rare cases (ie when the internal buffer is full).
  • 0

#14 iceshield

iceshield

    GMC Member

  • GMC Member
  • 393 posts

Posted 30 June 2012 - 10:16 AM

color is too big for 39dll int use big int or string to send and convert to back to int when received
  • 0

#15 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 30 June 2012 - 02:46 PM

It actually isn't. Maximum GM color value is 16777215, while 39dll int is 4 bytes long (IIRC) and that makes its range a lot larger, even if it's signed. Even if i am mistaken, three bytes instead of a whole string still take less bandwidth.
  • 0

#16 dark_master4

dark_master4

    GMC Member

  • GMC Member
  • 1176 posts
  • Version:GM:Studio

Posted 30 June 2012 - 11:57 PM

>receives the colour variable in the draw event
>readint() in draw event

Wait, can you show what it exactly looks like, and the message receiving code of the client?

[offtopic]
Don't try to greentext here /b/ro... I know it's down, but hold on tight!
[/offtopic]
  • 0

#17 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 01 July 2012 - 08:44 AM

Unfortunately that doesn't work either... And now image_angle doesn't do anything?
  • 0

#18 dark_master4

dark_master4

    GMC Member

  • GMC Member
  • 1176 posts
  • Version:GM:Studio

Posted 01 July 2012 - 04:41 PM

It actually isn't. Maximum GM color value is 16777215, while 39dll int is 4 bytes long (IIRC) and that makes its range a lot larger, even if it's signed. Even if i am mistaken, three bytes instead of a whole string still take less bandwidth.

Based on that information, you could try to send RGB separately as 3 bytes and reassemble the color on the other side.
  • 0

#19 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 01 July 2012 - 07:34 PM

A look at main.cpp and buffer.cpp indicates that you can find out how many bytes were written by checking the value returned by each function (0 if error/none written). Please tell us these results.

EDIT: Fixed typo.

Edited by Gamer3D, 01 July 2012 - 07:35 PM.

  • 0

#20 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 02 July 2012 - 08:53 AM

yeah, try the byte conversion.

writebyte(color_get_red(colour));  
writebyte(color_get_green(colour));  
writebyte(color_get_blue(colour));
player.colour = make_color_rgb(readbyte(), readbyte(), readbyte());
It's quite anoying but it should work :thumbsup:
I know I have sent GM colors before, I could check an old project and see how I did it... I'm not at home atm but will post it if I remeber

Edited by filulilus, 02 July 2012 - 08:55 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users