handmade/test/test_UDPpacketBufferV.cpp
Bubblegumdrop dcbd011582 Uncommitted changes.
Quite a bit going on in here.

- Messing with shaders
- Move ShaderProgram to std::unique_ptr

These are part of efforts to clean up the ShaderProgram class to have a
better interface.

- Working on shell-ing out commands.

This is pointless but getting me in the state of thinking about the
system as a whole - e.g. "stop" at the "prompt" should "stop the
server," so the prompt thread will need to communicate with the main
thread. We already have event signalling in place for this.

- Triangle strip cube

Performance testing reasons. Not being used for now.

- Remove TCP stuff from UDPbase. It only does UDP now.
2022-01-13 12:15:07 -05:00

133 lines
2.5 KiB
C++

#include "debug.h"
#include "glCheckErrors.h"
#include "lib_GL_common.h"
#include "lib_SDL_common.h"
#include "quad.h"
#include "shader.h"
#include "signal_common.h"
#include "unused.h"
#include "UDPbase.h"
#include "UDPpacketVBuffer.h"
#include "FileIO.h"
#include <iostream>
#include <fstream>
#include <memory>
#include <vector>
#include <getopt.h> /* getopt */
#include <stdlib.h> /* exit */
#include <string.h> /* memset */
#include <unistd.h> /* getopt */
#include <glm/vec3.hpp>
#include <glm/gtc/type_ptr.hpp>
#define Perf_Diff(a, b) ((double) 1000 * ((double)(((double) (b) - (double) (a)) / (double) SDL_GetPerformanceFrequency ())))
#define MIN_FRAME_MS 7 /* 144 Hz */
static void my_GetOpt (int, char **);
static void my_Usage (const char *);
static const char* host = "localhost";
static Uint16 port = 6666;
static int channel = -1;
static std::string path = "./test/test_UDPpacketVBuffer.cpp";
static std::unique_ptr<UDPbase> client;
int
main (int argc, char **argv)
{
UDPsocket udpsock;
common_Signal_Init ();
my_GetOpt (argc, argv);
common_SDL_Init ();
client = std::make_unique<UDPbase> (host, port);
if (NULL == (udpsock = client->UDP_Open (0)))
{
SDL_Log ("Unable to open client port");
return -1;
}
if (-1 == (channel = client->UDP_Bind (udpsock, -1)))
{
SDL_Log ("Unable to bind client port");
return -1;
}
std::string buf;
if (path == "-")
{
try {
std::string line;
while (getline (std::cin, line))
{
buf += line + "\n";
}
}
catch (std::ifstream::failure& e) {
// std::cout << e << std::endl;
}
}
else
{
FileIO f (path, "r");
buf = f.ReadToString ();
}
UDPpacket* packet = SDLNet_AllocPacket (buf.length ());
IPaddress* addr = SDLNet_UDP_GetPeerAddress (udpsock, channel);
packet->len = DEFAULT_MAX_PACKET_SIZE;
packet->address = *addr;
packet->channel = channel;
UDPpacketVBuffer packetV (packet, &buf[0], buf.length ());
packetV.Send (udpsock);
client->CloseAllSockets ();
common_SDL_Quit ();
return 0;
}
static void
my_Usage (const char *argv0)
{
fprintf (stderr, "Usage: %s [-h] [-s host] [-p port]\n", argv0);
}
static void
my_GetOpt (int argc, char **argv)
{
int opt;
host = "localhost";
port = 6666;
while ((opt = getopt (argc, argv, "f:hp:s:")) != -1)
{
switch (opt)
{
case 'p':
port = strtol (optarg, NULL, 0);
break;
case 's':
host = optarg;
break;
case 'f':
path = std::string (optarg);
break;
case 'h':
default:
my_Usage (argv[0]);
exit (EXIT_FAILURE);
break;
}
}
}