Jump to content

  • Log In with Google      Sign In   
  • Create Account

BeerNutts

Member Since 27 Jun 2001
Offline Last Active Today, 01:22 PM

Posts I've Made

In Topic: Reading multiple datagrams from UDP socket

30 August 2016 - 12:00 PM

It depends on the throughput expected.
...
The question is whether the OP is at that scale or not -- we have no way of knowing.

hplus, you know more about networking than me, no doubt, but, reading his initial question, I feel pretty safe in assuming he isn't in need of that kind of throughput and it's is more of a beginner networking question.

 

Either way, we now have both bases covered.


In Topic: Reading multiple datagrams from UDP socket

30 August 2016 - 08:05 AM

Hello!

 

The call recvfrom reads messages from udp socket one by one, so to read 10 messages you should call recvfrom 10 times. Are there any methods or, may be, some low-level commands to read all the messages at once into a buffer? 

 

I think you're asking the wrong question.  My guess is you worry about multiple clients sending UDP messages to a server, and you won't be able to read them all out in a timely manner for some reason.

 

I think what you really want to do is read UDP messages as they arrive (considering you won't really have 10 UDP packets arriving at the "same time"), so you should use select() (or some other method of notification) to signal you have data to be read from the UDP socket.  At that point, it's just a matter of calling recvfrom() as you get notified of a packet arriving, and determining which client sent the data.


In Topic: State machine for beginner - how to shoot state AND jump state

26 August 2016 - 07:20 PM

For typical player operations, state machine's are really the right tool.  Being an early game you're making, you should really be doing something simple.  For example, assume you're characters have apdate() method called once a frame, for your player character, you'd do something like this:

void Player::Update()
{
  if (Input.KeyPressed(LEFT_KEY)) {
    Velocity.X = -5; // move left
  }
  else if (Input.KeyPressed(RIGHT_KEY)) {
    Velocity.X = 5; // move right
  }
 
  if (IsOnGround) {
    if (Input.KeyPressed(JUMP_KEY)) {
    Velocity.Y = -30; // set player velocity negative to jump, we'll slow down each frame
    IsOnGround = false;
  }
  else {
    // we're in the air, decrease Y velocity each frame to simulate gravity
    Velocity.Y += 2;
  }
 
  if (Weapon.RefireTimer < GetCurrentTime() && Input.KeyPressed(FIRE_KEY)) {
    // shoot a bullet and set refire timer to however long the current weapon's refire time is
    Weapon.RefireTimer = GetCurrentTime() + Weapon.RefirePeriod;
    AddBullet(Weapon.GetBullet());
  }
  // store old location, and move player in each axis
  // If we're colliding with something, set the velocity to 0 in that direction and reset player's position in that axis
  Vector2d OldPosition = Position;
  Position.X += Velocity.X;
  if (CheckCollision(Position)) {
    Position.X = OldPosition.X;
   Velocity.X = 0;
  }
  Position.Y += Velocity.Y;
  if (CheckCollision(Position)) {
    // if we hit the ground, set onGround
    IsOnGround = CheckHitGround(Position);
    Position.Y = OldPosition.Y;
    Velocity.Y = 0;
  }

In Topic: trek game

26 August 2016 - 12:47 PM

If phil makes a star trek game that causes paramount to come after them I'll eat my shoe.

 

Regardless, I hope you have fun programming that game phil.


In Topic: What's a room?

22 August 2016 - 09:49 AM

If I were doing this (and I'm only a hobbyist, making small games), I'd create a full world (in physics-library terms) with all the rooms in it, and all the enemy's given their coordinates within the world, and the player has a coordinate within the world, starting in some "room."  A room in my world would just be the current camera view, given some specific dimensions in my world (maybe I have it setup as 20 meters x 18 meters, which would map to a full screen in a window).

 

The camera component needs to know about the rooms dimensions and the player's location, so when a player walks through an opening and hits the portal at the edge of a room, the camera would shift to the next room.

 

You can work it so enemies are asleep unless the camera enters the room they are in, or, if you want Monsters alive always, you can have them doing their thing in the other rooms, I don't think it would hurt anything.

 

IMO, this is the easiest solution.  There is no real "room" concept, except to the camera.  Either way, whatever you decide, good luck!


PARTNERS