mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 13:23:06 +02:00
Added spaceserver messaging.
This commit is contained in:
parent
c91dd5c4c2
commit
e64f46d556
6 changed files with 42 additions and 9 deletions
Binary file not shown.
14
main.cpp
14
main.cpp
|
@ -198,6 +198,9 @@ void Timer(int extra)
|
|||
|
||||
glutTimerFunc(1000,Timer,0);
|
||||
gettimeofday(&timer_start, NULL);
|
||||
|
||||
// Send a message to the spaceserver telling it we are ALIVE
|
||||
notify_spaceserver(UDP_socket, location[0], location[1], location[2]);
|
||||
}
|
||||
|
||||
void display_stats(void)
|
||||
|
@ -301,11 +304,6 @@ void terminate () {
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
const float SCALE_SENSORS = 0.3f;
|
||||
const float SCALE_X = 2.f;
|
||||
const float SCALE_Y = 1.f;
|
||||
|
||||
|
||||
void reset_sensors()
|
||||
{
|
||||
//
|
||||
|
@ -512,6 +510,7 @@ void display(void)
|
|||
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
// Render 2D overlay: I/O level bar graphs and text
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
@ -649,7 +648,10 @@ void read_network()
|
|||
timeval check;
|
||||
gettimeofday(&check, NULL);
|
||||
ping_msecs = (float)diffclock(ping_start, check);
|
||||
|
||||
} else if (incoming_packet[0] == 'S') {
|
||||
// Message from Spaceserver
|
||||
std::cout << "Spaceserver: ";
|
||||
outstring(incoming_packet, bytes_recvd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
30
network.cpp
30
network.cpp
|
@ -11,9 +11,13 @@
|
|||
#include "network.h"
|
||||
|
||||
|
||||
const int UDP_PORT = 30000;
|
||||
const int UDP_PORT = 30001;
|
||||
const char DESTINATION_IP[] = "127.0.0.1";
|
||||
|
||||
// Location of the spaceserver to talk to
|
||||
const char SPACESERVER_IP[] = "127.0.0.1";
|
||||
const int SPACESERVER_PORT = 40000;
|
||||
|
||||
// Implementation of optional delay behavior using a ring buffer
|
||||
const int MAX_DELAY_PACKETS = 300;
|
||||
char delay_buffer[MAX_PACKET_SIZE*MAX_DELAY_PACKETS];
|
||||
|
@ -22,7 +26,7 @@ int delay_size_received[MAX_DELAY_PACKETS];
|
|||
int next_to_receive = 0;
|
||||
int next_to_send = 0;
|
||||
|
||||
sockaddr_in address, dest_address, from;
|
||||
sockaddr_in address, dest_address, spaceserver_address, from;
|
||||
socklen_t fromLength = sizeof( from );
|
||||
|
||||
int network_init()
|
||||
|
@ -67,7 +71,11 @@ int network_init()
|
|||
dest_address.sin_family = AF_INET;
|
||||
dest_address.sin_addr.s_addr = inet_addr(DESTINATION_IP);
|
||||
dest_address.sin_port = htons( (unsigned short) UDP_PORT );
|
||||
|
||||
|
||||
spaceserver_address.sin_family = AF_INET;
|
||||
spaceserver_address.sin_addr.s_addr = inet_addr(SPACESERVER_IP);
|
||||
spaceserver_address.sin_port = htons( (unsigned short) SPACESERVER_PORT );
|
||||
|
||||
from.sin_family = AF_INET;
|
||||
//from.sin_addr.s_addr = htonl(ip_address);
|
||||
from.sin_port = htons( (unsigned short) UDP_PORT );
|
||||
|
@ -86,6 +94,22 @@ timeval network_send_ping(int handle) {
|
|||
return check;
|
||||
}
|
||||
|
||||
int notify_spaceserver(int handle, float x, float y, float z) {
|
||||
char data[100];
|
||||
sprintf(data, "%f,%f,%f", x, y, z);
|
||||
std::cout << "sending: " << data << "\n";
|
||||
int packet_size = strlen(data);
|
||||
int sent_bytes = sendto( handle, (const char*)data, packet_size,
|
||||
0, (sockaddr*)&spaceserver_address, sizeof(sockaddr_in) );
|
||||
|
||||
if ( sent_bytes != packet_size )
|
||||
{
|
||||
printf( "failed to send to spaceserver: return value = %d\n", sent_bytes );
|
||||
return false;
|
||||
}
|
||||
return sent_bytes;
|
||||
}
|
||||
|
||||
int network_send(int handle, char * packet_data, int packet_size)
|
||||
{
|
||||
int sent_bytes = sendto( handle, (const char*)packet_data, packet_size,
|
||||
|
|
|
@ -22,5 +22,6 @@ int network_init();
|
|||
int network_send(int handle, char * packet_data, int packet_size);
|
||||
int network_receive(int handle, char * packet_data, int delay /*msecs*/);
|
||||
timeval network_send_ping(int handle);
|
||||
int notify_spaceserver(int handle, float x, float y, float z);
|
||||
|
||||
#endif
|
||||
|
|
5
util.cpp
5
util.cpp
|
@ -39,6 +39,11 @@ void render_world_box()
|
|||
glEnd();
|
||||
}
|
||||
|
||||
void outstring(char * string, int length) {
|
||||
char out[length];
|
||||
memcpy(out, string, length);
|
||||
std::cout << out << "\n";
|
||||
}
|
||||
|
||||
double diffclock(timeval clock1,timeval clock2)
|
||||
{
|
||||
|
|
1
util.h
1
util.h
|
@ -10,6 +10,7 @@
|
|||
#define interface_util_h
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
void outstring(char * string, int length);
|
||||
float randFloat();
|
||||
void render_world_box();
|
||||
void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char *string,
|
||||
|
|
Loading…
Reference in a new issue