ping-pong example now supports udp
added socket sets (query for non-blocking sockets) removed rpack.h removed old-packing helpers Signed-off-by: Jak Barnes <contact@jakbarnes.co.uk>
This commit is contained in:
parent
ee85f59643
commit
1f11913d8c
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Chat client
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,9 +12,8 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
|
|
@ -24,30 +23,21 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Chat server
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,9 +12,8 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
|
|
@ -22,35 +21,23 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define MYPORT "4950"
|
|
||||||
#define MAXBUFLEN 100
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -22,6 +22,9 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
|
|
@ -31,56 +34,46 @@ int main()
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_INFO);
|
SetTraceLogLevel(LOG_DEBUG);
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
InitNetwork();
|
InitNetwork();
|
||||||
|
|
||||||
// Create the server
|
// Create the server
|
||||||
SocketConfig server_cfg = {
|
SocketConfig server_cfg = {.host = "127.0.0.1", .port = "8080", .server = true, .datagram = true, .nonblocking = true};
|
||||||
.host = "127.0.0.1",
|
SocketResult* server_res = AllocSocketResult();
|
||||||
.port = "8080",
|
if (!SocketOpen(&server_cfg, server_res))
|
||||||
.server = true,
|
|
||||||
.nonblocking = true
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketResult server_res;
|
|
||||||
memset(&server_res, 0, sizeof(SocketResult));
|
|
||||||
{
|
{
|
||||||
bool ok = SocketOpen(&server_cfg, &server_res);
|
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d\n",
|
||||||
if (!ok)
|
server_res->status, server_res->socket->status);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the client
|
// Create the client
|
||||||
SocketConfig client_cfg = {
|
SocketConfig client_cfg = {.host = "127.0.0.1", .port = "8080", .datagram = true, .nonblocking = true};
|
||||||
.host = "127.0.0.1",
|
SocketResult* client_res = AllocSocketResult();
|
||||||
.port = "8080"
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketResult client_res;
|
|
||||||
memset(&client_res, 0, sizeof(SocketResult));
|
|
||||||
{
|
{
|
||||||
bool ok = SocketOpen(&client_cfg, &client_res);
|
if (!SocketOpen(&client_cfg, client_res))
|
||||||
if (!ok)
|
|
||||||
{
|
{
|
||||||
printf("failed to open: status %d, errno %d\n", client_res.status,
|
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d\n",
|
||||||
client_res.socket.error);
|
client_res->status, client_res->socket->status);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketResult connection;
|
|
||||||
memset(&connection, 0, sizeof(SocketResult));
|
|
||||||
float elapsed = 0.0f, delay = 1.0f; // ms
|
|
||||||
bool ping = false, pong = false;
|
|
||||||
char recvBuffer[512];
|
char recvBuffer[512];
|
||||||
|
memset(recvBuffer, '\0', sizeof(recvBuffer));
|
||||||
|
Socket* connection = NULL;
|
||||||
|
SocketConfig connection_cfg = { .nonblocking = true,.datagram = true };
|
||||||
|
float elapsed = 0.0f;
|
||||||
|
float delay = 1.0f;
|
||||||
|
bool ping = false;
|
||||||
|
bool pong = false;
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
memset(&recvBuffer, 0, 8);
|
const char* pingmsg = "Ping!";
|
||||||
char pingmsg[6] = "Ping!";
|
const char* pongmsg = "Pong!";
|
||||||
char pongmsg[6] = "Pong!";
|
const int msglen = strlen(pingmsg) + 1;
|
||||||
|
SocketSet* socket_set = CreateSocketSet(3);
|
||||||
|
AddSocket(socket_set, server_res->socket);
|
||||||
|
AddSocket(socket_set, client_res->socket);
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
|
|
@ -91,20 +84,51 @@ int main()
|
||||||
// Clear
|
// Clear
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
int active = CheckSockets(socket_set, 0);
|
||||||
|
if (active != 0)
|
||||||
|
{
|
||||||
|
TraceLog(LOG_DEBUG,
|
||||||
|
"There are currently %d socket(s) with data to be processed.", active);
|
||||||
|
}
|
||||||
|
|
||||||
// A valid connection will != -1
|
// A valid connection will != -1
|
||||||
if (!connected)
|
if (!connected)
|
||||||
{
|
{
|
||||||
if (SocketAccept(server_res.socket.handle, &connection))
|
if (server_cfg.datagram)
|
||||||
{
|
{
|
||||||
ping = true;
|
ping = true;
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((connection = SocketAccept(server_res->socket, &connection_cfg)) != NULL)
|
||||||
|
{
|
||||||
|
AddSocket(socket_set, connection);
|
||||||
|
ping = true;
|
||||||
|
connected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connected
|
// Connected
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
int bytesRecv = SocketReceive(&connection.socket, recvBuffer, sizeof(pingmsg));
|
int bytesRecv = 0;
|
||||||
|
|
||||||
|
if (server_cfg.datagram)
|
||||||
|
{
|
||||||
|
if (IsSocketReady(server_res->socket))
|
||||||
|
{
|
||||||
|
bytesRecv = SocketReceive(server_res->socket, recvBuffer, msglen, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsSocketReady(connection))
|
||||||
|
{
|
||||||
|
bytesRecv = SocketReceive(connection, recvBuffer, msglen, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (bytesRecv > 0)
|
if (bytesRecv > 0)
|
||||||
{
|
{
|
||||||
if (strcmp(recvBuffer, pingmsg) == 0)
|
if (strcmp(recvBuffer, pingmsg) == 0)
|
||||||
|
|
@ -125,12 +149,12 @@ int main()
|
||||||
if (ping)
|
if (ping)
|
||||||
{
|
{
|
||||||
ping = false;
|
ping = false;
|
||||||
SocketSend(&client_res.socket, pingmsg, sizeof(pingmsg));
|
SocketSend(client_res->socket, pingmsg, msglen);
|
||||||
}
|
}
|
||||||
else if (pong)
|
else if (pong)
|
||||||
{
|
{
|
||||||
pong = false;
|
pong = false;
|
||||||
SocketSend(&client_res.socket, pongmsg, sizeof(pongmsg));
|
SocketSend(client_res->socket, pongmsg, msglen);
|
||||||
}
|
}
|
||||||
elapsed = 0.0f;
|
elapsed = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,7 @@ int main()
|
||||||
// Networking
|
// Networking
|
||||||
InitNetwork();
|
InitNetwork();
|
||||||
|
|
||||||
AddressInformation addr;
|
ResolveHost("www.google.com", "80");
|
||||||
ResolveHost("www.google.com", "80", &addr);
|
|
||||||
ResolveIP("8.8.8.8", NULL, NAME_INFO_DEFAULT);
|
ResolveIP("8.8.8.8", NULL, NAME_INFO_DEFAULT);
|
||||||
ResolveIP("2001:4860:4860::8888", "80", NAME_INFO_NUMERICSERV);
|
ResolveIP("2001:4860:4860::8888", "80", NAME_INFO_NUMERICSERV);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Resolve host
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,63 +12,32 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_DEBUG);
|
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
unsigned char buf[1024];
|
|
||||||
unsigned char magic;
|
|
||||||
int monkeycount;
|
|
||||||
long altitude;
|
|
||||||
double absurdityfactor;
|
|
||||||
char* s = "Great unmitigated Zot! You've found the Runestaff!";
|
|
||||||
char s2[96];
|
|
||||||
unsigned int packetsize, ps2;
|
|
||||||
|
|
||||||
packetsize = PackData(buf, "CHhlsd", 'B', 0, 37, -5, s, -3490.5);
|
|
||||||
packi16(buf + 1, packetsize); // store packet size in packet for kicks
|
|
||||||
|
|
||||||
printf("packet is %u bytes\n", packetsize);
|
|
||||||
UnpackData(buf, "CHhl96sd", &magic, &ps2, &monkeycount, &altitude, s2, &absurdityfactor);
|
|
||||||
printf("'%c' %hhu %u %ld \"%s\" %f\n", magic, ps2, monkeycount, altitude, s2, absurdityfactor);
|
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Resolve host
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,9 +12,8 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
|
|
@ -22,72 +21,23 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define PORT "3490" // the port client will be connecting to
|
|
||||||
#define MAXDATASIZE 100 // max number of bytes we can get at once
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_DEBUG);
|
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
int numbytes;
|
|
||||||
char buf[MAXDATASIZE];
|
|
||||||
|
|
||||||
// Create the client
|
|
||||||
SocketConfig client_cfg = {
|
|
||||||
.host = "127.0.0.1",
|
|
||||||
.port = "8080"
|
|
||||||
};
|
|
||||||
SocketResult client_res;
|
|
||||||
memset(&client_res, 0, sizeof(SocketResult));
|
|
||||||
{
|
|
||||||
bool ok = SocketOpen(&client_cfg, &client_res);
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
printf("Failed to open: status %d, errno %d\n", client_res.status,
|
|
||||||
client_res.socket.error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// Receive bytes from the server
|
|
||||||
numbytes = SocketReceive(client_res.socket.handle, buf, MAXDATASIZE - 1);
|
|
||||||
if (numbytes == -1)
|
|
||||||
{
|
|
||||||
printf("Client: error recv '%s'\n", buf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf[numbytes] = '\0';
|
|
||||||
printf("Client: received '%s'\n", buf);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
SocketClose(client_res.socket.handle);
|
|
||||||
CloseNetwork();
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Resolve host
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,89 +12,32 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_DEBUG);
|
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
|
|
||||||
// Create the server
|
|
||||||
SocketConfig server_cfg = {
|
|
||||||
.host = "127.0.0.1",
|
|
||||||
.port = "8080",
|
|
||||||
.server = true,
|
|
||||||
.nonblocking = true
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketResult server_res;
|
|
||||||
memset(&server_res, 0, sizeof(SocketResult));
|
|
||||||
{
|
|
||||||
bool ok = SocketOpen(&server_cfg, &server_res);
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SocketResult connection;
|
|
||||||
memset(&connection, 0, sizeof(SocketResult));
|
|
||||||
|
|
||||||
char recvBuffer[512];
|
|
||||||
memset(&recvBuffer, 0, 8);
|
|
||||||
|
|
||||||
bool connected = false;
|
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// Wait for a valid connection
|
|
||||||
if (!connected)
|
|
||||||
{
|
|
||||||
if (SocketAccept(server_res.socket.handle, &connection))
|
|
||||||
{
|
|
||||||
connected = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connected)
|
|
||||||
{
|
|
||||||
SocketSend(&connection, "Hello, world!", 13);
|
|
||||||
}
|
|
||||||
|
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Resolve host
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,63 +12,32 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_DEBUG);
|
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
unsigned char buf[1024];
|
|
||||||
unsigned char magic;
|
|
||||||
int monkeycount;
|
|
||||||
long altitude;
|
|
||||||
double absurdityfactor;
|
|
||||||
char* s = "Great unmitigated Zot! You've found the Runestaff!";
|
|
||||||
char s2[96];
|
|
||||||
unsigned int packetsize, ps2;
|
|
||||||
|
|
||||||
packetsize = PackData(buf, "CHhlsd", 'B', 0, 37, -5, s, -3490.5);
|
|
||||||
packi16(buf + 1, packetsize); // store packet size in packet for kicks
|
|
||||||
|
|
||||||
printf("packet is %u bytes\n", packetsize);
|
|
||||||
UnpackData(buf, "CHhl96sd", &magic, &ps2, &monkeycount, &altitude, s2, &absurdityfactor);
|
|
||||||
printf("'%c' %hhu %u %ld \"%s\" %f\n", magic, ps2, monkeycount, altitude, s2, absurdityfactor);
|
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [network] example - Resolve host
|
* raylib [core] example - Basic window
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
* Welcome to raylib!
|
||||||
*
|
*
|
||||||
|
|
@ -12,63 +12,32 @@
|
||||||
*
|
*
|
||||||
* Enjoy using raylib. :)
|
* Enjoy using raylib. :)
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.0 (www.raylib.com)
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*for details)
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Setup
|
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
InitWindow(
|
InitWindow(
|
||||||
screenWidth, screenHeight, "raylib [network] example - ping pong");
|
screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_DEBUG);
|
|
||||||
|
|
||||||
// Networking
|
|
||||||
InitNetwork();
|
|
||||||
|
|
||||||
unsigned char buf[1024];
|
|
||||||
unsigned char magic;
|
|
||||||
int monkeycount;
|
|
||||||
long altitude;
|
|
||||||
double absurdityfactor;
|
|
||||||
char* s = "Great unmitigated Zot! You've found the Runestaff!";
|
|
||||||
char s2[96];
|
|
||||||
unsigned int packetsize, ps2;
|
|
||||||
|
|
||||||
packetsize = PackData(buf, "CHhlsd", 'B', 0, 37, -5, s, -3490.5);
|
|
||||||
packi16(buf + 1, packetsize); // store packet size in packet for kicks
|
|
||||||
|
|
||||||
printf("packet is %u bytes\n", packetsize);
|
|
||||||
UnpackData(buf, "CHhl96sd", &magic, &ps2, &monkeycount, &altitude, s2, &absurdityfactor);
|
|
||||||
printf("'%c' %hhu %u %ld \"%s\" %f\n", magic, ps2, monkeycount, altitude, s2, absurdityfactor);
|
|
||||||
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Draw
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Clear
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
// End draw
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +185,6 @@
|
||||||
<ClInclude Include="..\..\..\src\raylib.h" />
|
<ClInclude Include="..\..\..\src\raylib.h" />
|
||||||
<ClInclude Include="..\..\..\src\raymath.h" />
|
<ClInclude Include="..\..\..\src\raymath.h" />
|
||||||
<ClInclude Include="..\..\..\src\rlgl.h" />
|
<ClInclude Include="..\..\..\src\rlgl.h" />
|
||||||
<ClInclude Include="..\..\..\src\rpack.h" />
|
|
||||||
<ClInclude Include="..\..\..\src\sysnet.h" />
|
<ClInclude Include="..\..\..\src\sysnet.h" />
|
||||||
<ClInclude Include="..\..\..\src\utils.h" />
|
<ClInclude Include="..\..\..\src\utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
390
src/raylib.h
390
src/raylib.h
|
|
@ -74,9 +74,11 @@
|
||||||
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||||
#define RLAPI __declspec(dllexport) // We are building raylib as a Win32 shared library (.dll)
|
# define RLAPI \
|
||||||
|
__declspec(dllexport) // We are building raylib as a Win32 shared library (.dll)
|
||||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||||
#define RLAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
# define RLAPI \
|
||||||
|
__declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||||
#else
|
#else
|
||||||
# define RLAPI // We are building or using raylib as a static library (or Linux shared library)
|
# define RLAPI // We are building or using raylib as a static library (or Linux shared library)
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -94,25 +96,28 @@
|
||||||
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||||
|
|
||||||
// Shader and material limits
|
// Shader and material limits
|
||||||
#define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct
|
#define MAX_SHADER_LOCATIONS \
|
||||||
#define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct
|
32 // Maximum number of predefined locations stored in shader struct
|
||||||
|
#define MAX_MATERIAL_MAPS \
|
||||||
|
12 // Maximum number of texture maps stored in shader struct
|
||||||
|
|
||||||
// Network limits
|
// Network defines
|
||||||
#define MAX_SOCKET_SET_SIZE 32
|
#define SOCKET_MAX_SET_SIZE 32
|
||||||
#define MAX_SOCKET_QUEUE_SIZE 16
|
#define SOCKET_MAX_QUEUE_SIZE 16
|
||||||
#define MAX_SOCK_OPTS 4
|
#define SOCKET_MAX_SOCK_OPTS 4
|
||||||
|
#define SOCKET_MAX_UDPCHANNELS (32)
|
||||||
|
#define SOCKET_MAX_UDPADDRESSES (4)
|
||||||
|
|
||||||
// getnameinfo() defines
|
// getnameinfo() defines
|
||||||
#define NAME_INFO_DEFAULT 0x00 /* No flags set */
|
#define NAME_INFO_DEFAULT 0x00 /* No flags set */
|
||||||
#define NAME_INFO_NOFQDN 0x01 /* Only return nodename portion for local hosts */
|
#define NAME_INFO_NOFQDN 0x01 /* Only return nodename portion for local hosts */
|
||||||
#define NAME_INFO_NUMERICHOST 0x02 /* Return numeric form of the host's address */
|
#define NAME_INFO_NUMERICHOST \
|
||||||
|
0x02 /* Return numeric form of the host's address */
|
||||||
#define NAME_INFO_NAMEREQD 0x04 /* Error if the host's name not in DNS */
|
#define NAME_INFO_NAMEREQD 0x04 /* Error if the host's name not in DNS */
|
||||||
#define NAME_INFO_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */
|
#define NAME_INFO_NUMERICSERV \
|
||||||
|
0x08 /* Return numeric form of the service (port #) */
|
||||||
#define NAME_INFO_DGRAM 0x10 /* Service is a datagram service */
|
#define NAME_INFO_DGRAM 0x10 /* Service is a datagram service */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
|
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
|
||||||
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
|
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
@ -123,33 +128,59 @@
|
||||||
|
|
||||||
// Some Basic Colors
|
// Some Basic Colors
|
||||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||||
#define LIGHTGRAY CLITERAL{ 200, 200, 200, 255 } // Light Gray
|
#define LIGHTGRAY \
|
||||||
#define GRAY CLITERAL{ 130, 130, 130, 255 } // Gray
|
CLITERAL { 200, 200, 200, 255 } // Light Gray
|
||||||
#define DARKGRAY CLITERAL{ 80, 80, 80, 255 } // Dark Gray
|
#define GRAY \
|
||||||
#define YELLOW CLITERAL{ 253, 249, 0, 255 } // Yellow
|
CLITERAL { 130, 130, 130, 255 } // Gray
|
||||||
#define GOLD CLITERAL{ 255, 203, 0, 255 } // Gold
|
#define DARKGRAY \
|
||||||
#define ORANGE CLITERAL{ 255, 161, 0, 255 } // Orange
|
CLITERAL { 80, 80, 80, 255 } // Dark Gray
|
||||||
#define PINK CLITERAL{ 255, 109, 194, 255 } // Pink
|
#define YELLOW \
|
||||||
#define RED CLITERAL{ 230, 41, 55, 255 } // Red
|
CLITERAL { 253, 249, 0, 255 } // Yellow
|
||||||
#define MAROON CLITERAL{ 190, 33, 55, 255 } // Maroon
|
#define GOLD \
|
||||||
#define GREEN CLITERAL{ 0, 228, 48, 255 } // Green
|
CLITERAL { 255, 203, 0, 255 } // Gold
|
||||||
#define LIME CLITERAL{ 0, 158, 47, 255 } // Lime
|
#define ORANGE \
|
||||||
#define DARKGREEN CLITERAL{ 0, 117, 44, 255 } // Dark Green
|
CLITERAL { 255, 161, 0, 255 } // Orange
|
||||||
#define SKYBLUE CLITERAL{ 102, 191, 255, 255 } // Sky Blue
|
#define PINK \
|
||||||
#define BLUE CLITERAL{ 0, 121, 241, 255 } // Blue
|
CLITERAL { 255, 109, 194, 255 } // Pink
|
||||||
#define DARKBLUE CLITERAL{ 0, 82, 172, 255 } // Dark Blue
|
#define RED \
|
||||||
#define PURPLE CLITERAL{ 200, 122, 255, 255 } // Purple
|
CLITERAL { 230, 41, 55, 255 } // Red
|
||||||
#define VIOLET CLITERAL{ 135, 60, 190, 255 } // Violet
|
#define MAROON \
|
||||||
#define DARKPURPLE CLITERAL{ 112, 31, 126, 255 } // Dark Purple
|
CLITERAL { 190, 33, 55, 255 } // Maroon
|
||||||
#define BEIGE CLITERAL{ 211, 176, 131, 255 } // Beige
|
#define GREEN \
|
||||||
#define BROWN CLITERAL{ 127, 106, 79, 255 } // Brown
|
CLITERAL { 0, 228, 48, 255 } // Green
|
||||||
#define DARKBROWN CLITERAL{ 76, 63, 47, 255 } // Dark Brown
|
#define LIME \
|
||||||
|
CLITERAL { 0, 158, 47, 255 } // Lime
|
||||||
|
#define DARKGREEN \
|
||||||
|
CLITERAL { 0, 117, 44, 255 } // Dark Green
|
||||||
|
#define SKYBLUE \
|
||||||
|
CLITERAL { 102, 191, 255, 255 } // Sky Blue
|
||||||
|
#define BLUE \
|
||||||
|
CLITERAL { 0, 121, 241, 255 } // Blue
|
||||||
|
#define DARKBLUE \
|
||||||
|
CLITERAL { 0, 82, 172, 255 } // Dark Blue
|
||||||
|
#define PURPLE \
|
||||||
|
CLITERAL { 200, 122, 255, 255 } // Purple
|
||||||
|
#define VIOLET \
|
||||||
|
CLITERAL { 135, 60, 190, 255 } // Violet
|
||||||
|
#define DARKPURPLE \
|
||||||
|
CLITERAL { 112, 31, 126, 255 } // Dark Purple
|
||||||
|
#define BEIGE \
|
||||||
|
CLITERAL { 211, 176, 131, 255 } // Beige
|
||||||
|
#define BROWN \
|
||||||
|
CLITERAL { 127, 106, 79, 255 } // Brown
|
||||||
|
#define DARKBROWN \
|
||||||
|
CLITERAL { 76, 63, 47, 255 } // Dark Brown
|
||||||
|
|
||||||
#define WHITE CLITERAL{ 255, 255, 255, 255 } // White
|
#define WHITE \
|
||||||
#define BLACK CLITERAL{ 0, 0, 0, 255 } // Black
|
CLITERAL { 255, 255, 255, 255 } // White
|
||||||
#define BLANK CLITERAL{ 0, 0, 0, 0 } // Blank (Transparent)
|
#define BLACK \
|
||||||
#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta
|
CLITERAL { 0, 0, 0, 255 } // Black
|
||||||
#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo)
|
#define BLANK \
|
||||||
|
CLITERAL { 0, 0, 0, 0 } // Blank (Transparent)
|
||||||
|
#define MAGENTA \
|
||||||
|
CLITERAL { 255, 0, 255, 255 } // Magenta
|
||||||
|
#define RAYWHITE \
|
||||||
|
CLITERAL { 245, 245, 245, 255 } // My own White (raylib logo)
|
||||||
|
|
||||||
// Temporal hack to avoid breaking old codebases using
|
// Temporal hack to avoid breaking old codebases using
|
||||||
// deprecated raylib implementation of these functions
|
// deprecated raylib implementation of these functions
|
||||||
|
|
@ -164,27 +195,34 @@
|
||||||
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
#elif !defined(__cplusplus) && !defined(bool)
|
#elif !defined(__cplusplus) && !defined(bool)
|
||||||
typedef enum { false, true } bool;
|
typedef enum
|
||||||
|
{
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
} bool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Network typedefs
|
// Network typedefs
|
||||||
typedef unsigned int SocketHandle;
|
typedef unsigned int SocketChannel;
|
||||||
|
|
||||||
// Vector2 type
|
// Vector2 type
|
||||||
typedef struct Vector2 {
|
typedef struct Vector2
|
||||||
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
} Vector2;
|
} Vector2;
|
||||||
|
|
||||||
// Vector3 type
|
// Vector3 type
|
||||||
typedef struct Vector3 {
|
typedef struct Vector3
|
||||||
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
} Vector3;
|
} Vector3;
|
||||||
|
|
||||||
// Vector4 type
|
// Vector4 type
|
||||||
typedef struct Vector4 {
|
typedef struct Vector4
|
||||||
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
|
|
@ -195,7 +233,8 @@ typedef struct Vector4 {
|
||||||
typedef Vector4 Quaternion;
|
typedef Vector4 Quaternion;
|
||||||
|
|
||||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||||
typedef struct Matrix {
|
typedef struct Matrix
|
||||||
|
{
|
||||||
float m0, m4, m8, m12;
|
float m0, m4, m8, m12;
|
||||||
float m1, m5, m9, m13;
|
float m1, m5, m9, m13;
|
||||||
float m2, m6, m10, m14;
|
float m2, m6, m10, m14;
|
||||||
|
|
@ -203,7 +242,8 @@ typedef struct Matrix {
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
// Color type, RGBA (32bit)
|
// Color type, RGBA (32bit)
|
||||||
typedef struct Color {
|
typedef struct Color
|
||||||
|
{
|
||||||
unsigned char r;
|
unsigned char r;
|
||||||
unsigned char g;
|
unsigned char g;
|
||||||
unsigned char b;
|
unsigned char b;
|
||||||
|
|
@ -211,7 +251,8 @@ typedef struct Color {
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
// Rectangle type
|
// Rectangle type
|
||||||
typedef struct Rectangle {
|
typedef struct Rectangle
|
||||||
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float width;
|
float width;
|
||||||
|
|
@ -220,7 +261,8 @@ typedef struct Rectangle {
|
||||||
|
|
||||||
// Image type, bpp always RGBA (32bit)
|
// Image type, bpp always RGBA (32bit)
|
||||||
// NOTE: Data stored in CPU memory (RAM)
|
// NOTE: Data stored in CPU memory (RAM)
|
||||||
typedef struct Image {
|
typedef struct Image
|
||||||
|
{
|
||||||
void *data; // Image raw data
|
void *data; // Image raw data
|
||||||
int width; // Image base width
|
int width; // Image base width
|
||||||
int height; // Image base height
|
int height; // Image base height
|
||||||
|
|
@ -230,7 +272,8 @@ typedef struct Image {
|
||||||
|
|
||||||
// Texture2D type
|
// Texture2D type
|
||||||
// NOTE: Data stored in GPU memory
|
// NOTE: Data stored in GPU memory
|
||||||
typedef struct Texture2D {
|
typedef struct Texture2D
|
||||||
|
{
|
||||||
unsigned int id; // OpenGL texture id
|
unsigned int id; // OpenGL texture id
|
||||||
int width; // Texture base width
|
int width; // Texture base width
|
||||||
int height; // Texture base height
|
int height; // Texture base height
|
||||||
|
|
@ -245,7 +288,8 @@ typedef Texture2D Texture;
|
||||||
typedef Texture2D TextureCubemap;
|
typedef Texture2D TextureCubemap;
|
||||||
|
|
||||||
// RenderTexture2D type, for texture rendering
|
// RenderTexture2D type, for texture rendering
|
||||||
typedef struct RenderTexture2D {
|
typedef struct RenderTexture2D
|
||||||
|
{
|
||||||
unsigned int id; // OpenGL Framebuffer Object (FBO) id
|
unsigned int id; // OpenGL Framebuffer Object (FBO) id
|
||||||
Texture2D texture; // Color buffer attachment texture
|
Texture2D texture; // Color buffer attachment texture
|
||||||
Texture2D depth; // Depth buffer attachment texture
|
Texture2D depth; // Depth buffer attachment texture
|
||||||
|
|
@ -256,7 +300,8 @@ typedef struct RenderTexture2D {
|
||||||
typedef RenderTexture2D RenderTexture;
|
typedef RenderTexture2D RenderTexture;
|
||||||
|
|
||||||
// N-Patch layout info
|
// N-Patch layout info
|
||||||
typedef struct NPatchInfo {
|
typedef struct NPatchInfo
|
||||||
|
{
|
||||||
Rectangle sourceRec; // Region in the texture
|
Rectangle sourceRec; // Region in the texture
|
||||||
int left; // left border offset
|
int left; // left border offset
|
||||||
int top; // top border offset
|
int top; // top border offset
|
||||||
|
|
@ -266,7 +311,8 @@ typedef struct NPatchInfo {
|
||||||
} NPatchInfo;
|
} NPatchInfo;
|
||||||
|
|
||||||
// Font character info
|
// Font character info
|
||||||
typedef struct CharInfo {
|
typedef struct CharInfo
|
||||||
|
{
|
||||||
int value; // Character value (Unicode)
|
int value; // Character value (Unicode)
|
||||||
Rectangle rec; // Character rectangle in sprite font
|
Rectangle rec; // Character rectangle in sprite font
|
||||||
int offsetX; // Character offset X when drawing
|
int offsetX; // Character offset X when drawing
|
||||||
|
|
@ -276,7 +322,8 @@ typedef struct CharInfo {
|
||||||
} CharInfo;
|
} CharInfo;
|
||||||
|
|
||||||
// Font type, includes texture and charSet array data
|
// Font type, includes texture and charSet array data
|
||||||
typedef struct Font {
|
typedef struct Font
|
||||||
|
{
|
||||||
Texture2D texture; // Font texture
|
Texture2D texture; // Font texture
|
||||||
int baseSize; // Base size (default chars height)
|
int baseSize; // Base size (default chars height)
|
||||||
int charsCount; // Number of characters
|
int charsCount; // Number of characters
|
||||||
|
|
@ -286,7 +333,8 @@ typedef struct Font {
|
||||||
#define SpriteFont Font // SpriteFont type fallback, defaults to Font
|
#define SpriteFont Font // SpriteFont type fallback, defaults to Font
|
||||||
|
|
||||||
// Camera type, defines a camera position/orientation in 3d space
|
// Camera type, defines a camera position/orientation in 3d space
|
||||||
typedef struct Camera3D {
|
typedef struct Camera3D
|
||||||
|
{
|
||||||
Vector3 position; // Camera position
|
Vector3 position; // Camera position
|
||||||
Vector3 target; // Camera target it looks-at
|
Vector3 target; // Camera target it looks-at
|
||||||
Vector3 up; // Camera up vector (rotation over its axis)
|
Vector3 up; // Camera up vector (rotation over its axis)
|
||||||
|
|
@ -297,7 +345,8 @@ typedef struct Camera3D {
|
||||||
#define Camera Camera3D // Camera type fallback, defaults to Camera3D
|
#define Camera Camera3D // Camera type fallback, defaults to Camera3D
|
||||||
|
|
||||||
// Camera2D type, defines a 2d camera
|
// Camera2D type, defines a 2d camera
|
||||||
typedef struct Camera2D {
|
typedef struct Camera2D
|
||||||
|
{
|
||||||
Vector2 offset; // Camera offset (displacement from target)
|
Vector2 offset; // Camera offset (displacement from target)
|
||||||
Vector2 target; // Camera target (rotation and zoom origin)
|
Vector2 target; // Camera target (rotation and zoom origin)
|
||||||
float rotation; // Camera rotation in degrees
|
float rotation; // Camera rotation in degrees
|
||||||
|
|
@ -305,14 +354,16 @@ typedef struct Camera2D {
|
||||||
} Camera2D;
|
} Camera2D;
|
||||||
|
|
||||||
// Bounding box type
|
// Bounding box type
|
||||||
typedef struct BoundingBox {
|
typedef struct BoundingBox
|
||||||
|
{
|
||||||
Vector3 min; // Minimum vertex box-corner
|
Vector3 min; // Minimum vertex box-corner
|
||||||
Vector3 max; // Maximum vertex box-corner
|
Vector3 max; // Maximum vertex box-corner
|
||||||
} BoundingBox;
|
} BoundingBox;
|
||||||
|
|
||||||
// Vertex data definning a mesh
|
// Vertex data definning a mesh
|
||||||
// NOTE: Data stored in CPU memory (and GPU)
|
// NOTE: Data stored in CPU memory (and GPU)
|
||||||
typedef struct Mesh {
|
typedef struct Mesh
|
||||||
|
{
|
||||||
int vertexCount; // Number of vertices stored in arrays
|
int vertexCount; // Number of vertices stored in arrays
|
||||||
int triangleCount; // Number of triangles stored (indexed or not)
|
int triangleCount; // Number of triangles stored (indexed or not)
|
||||||
|
|
||||||
|
|
@ -337,40 +388,46 @@ typedef struct Mesh {
|
||||||
} Mesh;
|
} Mesh;
|
||||||
|
|
||||||
// Shader type (generic)
|
// Shader type (generic)
|
||||||
typedef struct Shader {
|
typedef struct Shader
|
||||||
|
{
|
||||||
unsigned int id; // Shader program id
|
unsigned int id; // Shader program id
|
||||||
int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
|
int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
|
||||||
} Shader;
|
} Shader;
|
||||||
|
|
||||||
// Material texture map
|
// Material texture map
|
||||||
typedef struct MaterialMap {
|
typedef struct MaterialMap
|
||||||
|
{
|
||||||
Texture2D texture; // Material map texture
|
Texture2D texture; // Material map texture
|
||||||
Color color; // Material map color
|
Color color; // Material map color
|
||||||
float value; // Material map value
|
float value; // Material map value
|
||||||
} MaterialMap;
|
} MaterialMap;
|
||||||
|
|
||||||
// Material type (generic)
|
// Material type (generic)
|
||||||
typedef struct Material {
|
typedef struct Material
|
||||||
|
{
|
||||||
Shader shader; // Material shader
|
Shader shader; // Material shader
|
||||||
MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
|
MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
|
||||||
float * params; // Material generic parameters (if required)
|
float * params; // Material generic parameters (if required)
|
||||||
} Material;
|
} Material;
|
||||||
|
|
||||||
// Model type
|
// Model type
|
||||||
typedef struct Model {
|
typedef struct Model
|
||||||
|
{
|
||||||
Mesh mesh; // Vertex data buffers (RAM and VRAM)
|
Mesh mesh; // Vertex data buffers (RAM and VRAM)
|
||||||
Matrix transform; // Local transform matrix
|
Matrix transform; // Local transform matrix
|
||||||
Material material; // Shader and textures data
|
Material material; // Shader and textures data
|
||||||
} Model;
|
} Model;
|
||||||
|
|
||||||
// Ray type (useful for raycast)
|
// Ray type (useful for raycast)
|
||||||
typedef struct Ray {
|
typedef struct Ray
|
||||||
|
{
|
||||||
Vector3 position; // Ray position (origin)
|
Vector3 position; // Ray position (origin)
|
||||||
Vector3 direction; // Ray direction
|
Vector3 direction; // Ray direction
|
||||||
} Ray;
|
} Ray;
|
||||||
|
|
||||||
// Raycast hit information
|
// Raycast hit information
|
||||||
typedef struct RayHitInfo {
|
typedef struct RayHitInfo
|
||||||
|
{
|
||||||
bool hit; // Did the ray hit something?
|
bool hit; // Did the ray hit something?
|
||||||
float distance; // Distance to nearest hit
|
float distance; // Distance to nearest hit
|
||||||
Vector3 position; // Position of nearest hit
|
Vector3 position; // Position of nearest hit
|
||||||
|
|
@ -378,7 +435,8 @@ typedef struct RayHitInfo {
|
||||||
} RayHitInfo;
|
} RayHitInfo;
|
||||||
|
|
||||||
// Wave type, defines audio wave data
|
// Wave type, defines audio wave data
|
||||||
typedef struct Wave {
|
typedef struct Wave
|
||||||
|
{
|
||||||
unsigned int sampleCount; // Number of samples
|
unsigned int sampleCount; // Number of samples
|
||||||
unsigned int sampleRate; // Frequency (samples per second)
|
unsigned int sampleRate; // Frequency (samples per second)
|
||||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
|
|
@ -387,7 +445,8 @@ typedef struct Wave {
|
||||||
} Wave;
|
} Wave;
|
||||||
|
|
||||||
// Sound source type
|
// Sound source type
|
||||||
typedef struct Sound {
|
typedef struct Sound
|
||||||
|
{
|
||||||
void *audioBuffer; // Pointer to internal data used by the audio system
|
void *audioBuffer; // Pointer to internal data used by the audio system
|
||||||
|
|
||||||
unsigned int source; // Audio source id
|
unsigned int source; // Audio source id
|
||||||
|
|
@ -401,7 +460,8 @@ typedef struct MusicData *Music;
|
||||||
|
|
||||||
// Audio stream type
|
// Audio stream type
|
||||||
// NOTE: Useful to create custom audio streams not bound to a specific file
|
// NOTE: Useful to create custom audio streams not bound to a specific file
|
||||||
typedef struct AudioStream {
|
typedef struct AudioStream
|
||||||
|
{
|
||||||
unsigned int sampleRate; // Frequency (samples per second)
|
unsigned int sampleRate; // Frequency (samples per second)
|
||||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
||||||
|
|
@ -414,7 +474,8 @@ typedef struct AudioStream {
|
||||||
} AudioStream;
|
} AudioStream;
|
||||||
|
|
||||||
// Head-Mounted-Display device parameters
|
// Head-Mounted-Display device parameters
|
||||||
typedef struct VrDeviceInfo {
|
typedef struct VrDeviceInfo
|
||||||
|
{
|
||||||
int hResolution; // HMD horizontal resolution in pixels
|
int hResolution; // HMD horizontal resolution in pixels
|
||||||
int vResolution; // HMD vertical resolution in pixels
|
int vResolution; // HMD vertical resolution in pixels
|
||||||
float hScreenSize; // HMD horizontal size in meters
|
float hScreenSize; // HMD horizontal size in meters
|
||||||
|
|
@ -428,7 +489,8 @@ typedef struct VrDeviceInfo {
|
||||||
} VrDeviceInfo;
|
} VrDeviceInfo;
|
||||||
|
|
||||||
// VR Stereo rendering configuration for simulator
|
// VR Stereo rendering configuration for simulator
|
||||||
typedef struct VrStereoConfig {
|
typedef struct VrStereoConfig
|
||||||
|
{
|
||||||
RenderTexture2D stereoFbo; // VR stereo rendering framebuffer
|
RenderTexture2D stereoFbo; // VR stereo rendering framebuffer
|
||||||
Shader distortionShader; // VR stereo rendering distortion shader
|
Shader distortionShader; // VR stereo rendering distortion shader
|
||||||
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
||||||
|
|
@ -437,36 +499,16 @@ typedef struct VrStereoConfig {
|
||||||
int eyeViewportLeft[4]; // VR stereo rendering left eye viewport [x, y, w, h]
|
int eyeViewportLeft[4]; // VR stereo rendering left eye viewport [x, y, w, h]
|
||||||
} VrStereoConfig;
|
} VrStereoConfig;
|
||||||
|
|
||||||
|
// IPAddress definition (in network byte order)
|
||||||
typedef struct IPAddress
|
typedef struct IPAddress
|
||||||
{
|
{
|
||||||
unsigned char* host; /* 32-bit IPv4 host address */
|
unsigned long host; /* 32-bit IPv4 host address */
|
||||||
unsigned int port; /* 16-bit protocol port */
|
unsigned short port; /* 16-bit protocol port */
|
||||||
} IPAddress;
|
} IPAddress;
|
||||||
|
|
||||||
// Used by the getaddrinfo function to hold host address information.
|
|
||||||
typedef struct AddressInformation
|
|
||||||
{
|
|
||||||
int flags; // AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
|
|
||||||
int family; // PF_xxx
|
|
||||||
int socktype; // SOCK_xxx
|
|
||||||
int protocol; // 0 or IPPROTO_xxx for IPv4 and IPv6
|
|
||||||
unsigned int addrlen; // Length of ai_addr
|
|
||||||
char * canonname; // Canonical name for nodename
|
|
||||||
struct SocketAddress *sockaddr; // Binary address
|
|
||||||
struct AddressInformation *next; // Next structure in linked list
|
|
||||||
} AddressInformation;
|
|
||||||
|
|
||||||
// The sockaddr structure varies depending on the protocol selected.
|
|
||||||
// Except for the sin*_family parameter, sockaddr contents are expressed
|
|
||||||
// in network byte order.
|
|
||||||
typedef struct SocketAddress
|
|
||||||
{
|
|
||||||
unsigned short family; // Address family.
|
|
||||||
char data[14]; // Up to 14 bytes of direct address.
|
|
||||||
} SocketAddress;
|
|
||||||
|
|
||||||
// An option ID, value, sizeof(value) tuple for setsockopt(2).
|
// An option ID, value, sizeof(value) tuple for setsockopt(2).
|
||||||
typedef struct SocketOpt {
|
typedef struct SocketOpt
|
||||||
|
{
|
||||||
int id;
|
int id;
|
||||||
void *value;
|
void *value;
|
||||||
int valueLen;
|
int valueLen;
|
||||||
|
|
@ -478,44 +520,60 @@ typedef enum
|
||||||
SOCKET_UDP = 2 // SOCK_DGRAM
|
SOCKET_UDP = 2 // SOCK_DGRAM
|
||||||
} SocketType;
|
} SocketType;
|
||||||
|
|
||||||
|
typedef struct UDPChannel
|
||||||
|
{
|
||||||
|
int numbound; // The total number of addresses this channel is bound to
|
||||||
|
IPAddress address[SOCKET_MAX_UDPADDRESSES]; // The list of remote addresses this channel is bound to
|
||||||
|
} UDPChannel;
|
||||||
|
|
||||||
typedef struct Socket
|
typedef struct Socket
|
||||||
{
|
{
|
||||||
int ready; // Is the socket ready? i.e. has information
|
int ready; // Is the socket ready? i.e. has information
|
||||||
int error; // The last error code to have occured using this socket
|
int status; // The last status code to have occured using this socket
|
||||||
bool isServer; // Is this socket a server socket (i.e. TCP/UDP Listen Server)
|
bool isServer; // Is this socket a server socket (i.e. TCP/UDP Listen Server)
|
||||||
IPAddress address; // The host/target ip for this socket
|
SocketChannel channel; // The socket handle id
|
||||||
SocketType type; // Is this socket a TCP or UDP socket?
|
SocketType type; // Is this socket a TCP or UDP socket?
|
||||||
SocketHandle handle; // The socket handle id
|
IPAddress address; // The host/target ip for this socket (in network byte order)
|
||||||
|
struct UDPChannel bindings[SOCKET_MAX_UDPCHANNELS]; // The amount of channels (if UDP) this socket is bound to
|
||||||
} Socket;
|
} Socket;
|
||||||
|
|
||||||
|
typedef struct SocketSet
|
||||||
|
{
|
||||||
|
int numsockets;
|
||||||
|
int maxsockets;
|
||||||
|
struct Socket **sockets;
|
||||||
|
} SocketSet;
|
||||||
|
|
||||||
|
typedef struct SocketDataPacket
|
||||||
|
{
|
||||||
|
int channel; /* The src/dst channel of the packet */
|
||||||
|
unsigned char *data; /* The packet data */
|
||||||
|
int len; /* The length of the packet data */
|
||||||
|
int maxlen; /* The size of the data buffer */
|
||||||
|
int status; /* packet status after sending */
|
||||||
|
IPAddress address; /* The source/dest address of an incoming/outgoing packet */
|
||||||
|
} SocketDataPacket;
|
||||||
|
|
||||||
// Configuration for a socket. Not all of these fields need to
|
// Configuration for a socket. Not all of these fields need to
|
||||||
// be set, and ones omitted from a C99-style "designated initializer"
|
// be set, and ones omitted from a C99-style "designated initializer"
|
||||||
// struct literal will be zeroed out and replaced with defaults.
|
// struct literal will be zeroed out and replaced with defaults.
|
||||||
typedef struct SocketConfig
|
typedef struct SocketConfig
|
||||||
{
|
{
|
||||||
// Hostname and port, for TCP or UDP sockets. */
|
// Hostname and port, for TCP or UDP sockets. */
|
||||||
char *host;
|
char * host; // The host address in xxx.xxx.xxx.xxx form
|
||||||
char *port;
|
char * port; // The target port/server in the form "http" or "25565"
|
||||||
|
|
||||||
// IPv4 or IPv6 address; if neither is specified, let OS decide.
|
|
||||||
// These fields should be used in place of 'host' above.
|
|
||||||
char *IPv4;
|
|
||||||
char *IPv6;
|
|
||||||
bool server; // Listen for incoming clients?
|
bool server; // Listen for incoming clients?
|
||||||
bool datagram; // TCP or UDP?
|
bool datagram; // TCP or UDP?
|
||||||
bool nonblocking; // non-blocking operation?
|
bool nonblocking; // non-blocking operation?
|
||||||
int backlog_size; // set a custom backlog size
|
int backlog_size; // set a custom backlog size
|
||||||
|
SocketOpt sockopts[SOCKET_MAX_SOCK_OPTS];
|
||||||
SocketOpt sockopts[MAX_SOCK_OPTS];
|
|
||||||
|
|
||||||
} SocketConfig;
|
} SocketConfig;
|
||||||
|
|
||||||
// Result from calling open with a given config.
|
// Result from calling open with a given config.
|
||||||
typedef struct SocketResult
|
typedef struct SocketResult
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
Socket socket;
|
Socket *socket;
|
||||||
AddressInformation addrinfo;
|
|
||||||
} SocketResult;
|
} SocketResult;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -524,7 +582,8 @@ typedef struct SocketResult
|
||||||
|
|
||||||
// System config flags
|
// System config flags
|
||||||
// NOTE: Used for bit masks
|
// NOTE: Used for bit masks
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
FLAG_SHOW_LOGO = 1, // Set to show raylib logo at startup
|
FLAG_SHOW_LOGO = 1, // Set to show raylib logo at startup
|
||||||
FLAG_FULLSCREEN_MODE = 2, // Set to run program in fullscreen
|
FLAG_FULLSCREEN_MODE = 2, // Set to run program in fullscreen
|
||||||
FLAG_WINDOW_RESIZABLE = 4, // Set to allow resizable window
|
FLAG_WINDOW_RESIZABLE = 4, // Set to allow resizable window
|
||||||
|
|
@ -536,7 +595,8 @@ typedef enum {
|
||||||
} ConfigFlag;
|
} ConfigFlag;
|
||||||
|
|
||||||
// Trace log type
|
// Trace log type
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
LOG_ALL, // Display all logs
|
LOG_ALL, // Display all logs
|
||||||
LOG_TRACE,
|
LOG_TRACE,
|
||||||
LOG_DEBUG,
|
LOG_DEBUG,
|
||||||
|
|
@ -548,7 +608,8 @@ typedef enum {
|
||||||
} TraceLogType;
|
} TraceLogType;
|
||||||
|
|
||||||
// Keyboard keys
|
// Keyboard keys
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
// Alphanumeric keys
|
// Alphanumeric keys
|
||||||
KEY_APOSTROPHE = 39,
|
KEY_APOSTROPHE = 39,
|
||||||
KEY_COMMA = 44,
|
KEY_COMMA = 44,
|
||||||
|
|
@ -662,7 +723,8 @@ typedef enum {
|
||||||
} KeyboardKey;
|
} KeyboardKey;
|
||||||
|
|
||||||
// Android buttons
|
// Android buttons
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
KEY_BACK = 4,
|
KEY_BACK = 4,
|
||||||
KEY_MENU = 82,
|
KEY_MENU = 82,
|
||||||
KEY_VOLUME_UP = 24,
|
KEY_VOLUME_UP = 24,
|
||||||
|
|
@ -670,14 +732,16 @@ typedef enum {
|
||||||
} AndroidButton;
|
} AndroidButton;
|
||||||
|
|
||||||
// Mouse buttons
|
// Mouse buttons
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MOUSE_LEFT_BUTTON = 0,
|
MOUSE_LEFT_BUTTON = 0,
|
||||||
MOUSE_RIGHT_BUTTON = 1,
|
MOUSE_RIGHT_BUTTON = 1,
|
||||||
MOUSE_MIDDLE_BUTTON = 2
|
MOUSE_MIDDLE_BUTTON = 2
|
||||||
} MouseButton;
|
} MouseButton;
|
||||||
|
|
||||||
// Gamepad number
|
// Gamepad number
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_PLAYER1 = 0,
|
GAMEPAD_PLAYER1 = 0,
|
||||||
GAMEPAD_PLAYER2 = 1,
|
GAMEPAD_PLAYER2 = 1,
|
||||||
GAMEPAD_PLAYER3 = 2,
|
GAMEPAD_PLAYER3 = 2,
|
||||||
|
|
@ -687,7 +751,8 @@ typedef enum {
|
||||||
// PS3 USB Controller Buttons
|
// PS3 USB Controller Buttons
|
||||||
// TODO: Provide a generic way to list gamepad controls schemes,
|
// TODO: Provide a generic way to list gamepad controls schemes,
|
||||||
// defining specific controls schemes is not a good option
|
// defining specific controls schemes is not a good option
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_PS3_BUTTON_TRIANGLE = 0,
|
GAMEPAD_PS3_BUTTON_TRIANGLE = 0,
|
||||||
GAMEPAD_PS3_BUTTON_CIRCLE = 1,
|
GAMEPAD_PS3_BUTTON_CIRCLE = 1,
|
||||||
GAMEPAD_PS3_BUTTON_CROSS = 2,
|
GAMEPAD_PS3_BUTTON_CROSS = 2,
|
||||||
|
|
@ -706,7 +771,8 @@ typedef enum {
|
||||||
} GamepadPS3Button;
|
} GamepadPS3Button;
|
||||||
|
|
||||||
// PS3 USB Controller Axis
|
// PS3 USB Controller Axis
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_PS3_AXIS_LEFT_X = 0,
|
GAMEPAD_PS3_AXIS_LEFT_X = 0,
|
||||||
GAMEPAD_PS3_AXIS_LEFT_Y = 1,
|
GAMEPAD_PS3_AXIS_LEFT_Y = 1,
|
||||||
GAMEPAD_PS3_AXIS_RIGHT_X = 2,
|
GAMEPAD_PS3_AXIS_RIGHT_X = 2,
|
||||||
|
|
@ -716,7 +782,8 @@ typedef enum {
|
||||||
} GamepadPS3Axis;
|
} GamepadPS3Axis;
|
||||||
|
|
||||||
// Xbox360 USB Controller Buttons
|
// Xbox360 USB Controller Buttons
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_XBOX_BUTTON_A = 0,
|
GAMEPAD_XBOX_BUTTON_A = 0,
|
||||||
GAMEPAD_XBOX_BUTTON_B = 1,
|
GAMEPAD_XBOX_BUTTON_B = 1,
|
||||||
GAMEPAD_XBOX_BUTTON_X = 2,
|
GAMEPAD_XBOX_BUTTON_X = 2,
|
||||||
|
|
@ -734,7 +801,8 @@ typedef enum {
|
||||||
|
|
||||||
// Xbox360 USB Controller Axis,
|
// Xbox360 USB Controller Axis,
|
||||||
// NOTE: For Raspberry Pi, axis must be reconfigured
|
// NOTE: For Raspberry Pi, axis must be reconfigured
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_XBOX_AXIS_LEFT_X = 0, // [-1..1] (left->right)
|
GAMEPAD_XBOX_AXIS_LEFT_X = 0, // [-1..1] (left->right)
|
||||||
GAMEPAD_XBOX_AXIS_LEFT_Y = 1, // [1..-1] (up->down)
|
GAMEPAD_XBOX_AXIS_LEFT_Y = 1, // [1..-1] (up->down)
|
||||||
GAMEPAD_XBOX_AXIS_RIGHT_X = 2, // [-1..1] (left->right)
|
GAMEPAD_XBOX_AXIS_RIGHT_X = 2, // [-1..1] (left->right)
|
||||||
|
|
@ -744,7 +812,8 @@ typedef enum {
|
||||||
} GamepadXbox360Axis;
|
} GamepadXbox360Axis;
|
||||||
|
|
||||||
// Android Gamepad Controller (SNES CLASSIC)
|
// Android Gamepad Controller (SNES CLASSIC)
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GAMEPAD_ANDROID_DPAD_UP = 19,
|
GAMEPAD_ANDROID_DPAD_UP = 19,
|
||||||
GAMEPAD_ANDROID_DPAD_DOWN = 20,
|
GAMEPAD_ANDROID_DPAD_DOWN = 20,
|
||||||
GAMEPAD_ANDROID_DPAD_LEFT = 21,
|
GAMEPAD_ANDROID_DPAD_LEFT = 21,
|
||||||
|
|
@ -763,7 +832,8 @@ typedef enum {
|
||||||
} GamepadAndroid;
|
} GamepadAndroid;
|
||||||
|
|
||||||
// Shader location point type
|
// Shader location point type
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
LOC_VERTEX_POSITION = 0,
|
LOC_VERTEX_POSITION = 0,
|
||||||
LOC_VERTEX_TEXCOORD01,
|
LOC_VERTEX_TEXCOORD01,
|
||||||
LOC_VERTEX_TEXCOORD02,
|
LOC_VERTEX_TEXCOORD02,
|
||||||
|
|
@ -795,7 +865,8 @@ typedef enum {
|
||||||
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
||||||
|
|
||||||
// Shader uniform data types
|
// Shader uniform data types
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
UNIFORM_FLOAT = 0,
|
UNIFORM_FLOAT = 0,
|
||||||
UNIFORM_VEC2,
|
UNIFORM_VEC2,
|
||||||
UNIFORM_VEC3,
|
UNIFORM_VEC3,
|
||||||
|
|
@ -808,7 +879,8 @@ typedef enum {
|
||||||
} ShaderUniformDataType;
|
} ShaderUniformDataType;
|
||||||
|
|
||||||
// Material map type
|
// Material map type
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MAP_ALBEDO = 0, // MAP_DIFFUSE
|
MAP_ALBEDO = 0, // MAP_DIFFUSE
|
||||||
MAP_METALNESS = 1, // MAP_SPECULAR
|
MAP_METALNESS = 1, // MAP_SPECULAR
|
||||||
MAP_NORMAL = 2,
|
MAP_NORMAL = 2,
|
||||||
|
|
@ -827,7 +899,8 @@ typedef enum {
|
||||||
|
|
||||||
// Pixel formats
|
// Pixel formats
|
||||||
// NOTE: Support depends on OpenGL version and platform
|
// NOTE: Support depends on OpenGL version and platform
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
||||||
UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels)
|
UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels)
|
||||||
UNCOMPRESSED_R5G6B5, // 16 bpp
|
UNCOMPRESSED_R5G6B5, // 16 bpp
|
||||||
|
|
@ -854,7 +927,8 @@ typedef enum {
|
||||||
// Texture parameters: filter mode
|
// Texture parameters: filter mode
|
||||||
// NOTE 1: Filtering considers mipmaps if available in the texture
|
// NOTE 1: Filtering considers mipmaps if available in the texture
|
||||||
// NOTE 2: Filter is accordingly set for minification and magnification
|
// NOTE 2: Filter is accordingly set for minification and magnification
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
FILTER_POINT = 0, // No filter, just pixel aproximation
|
FILTER_POINT = 0, // No filter, just pixel aproximation
|
||||||
FILTER_BILINEAR, // Linear filtering
|
FILTER_BILINEAR, // Linear filtering
|
||||||
FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
|
FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
|
||||||
|
|
@ -864,7 +938,8 @@ typedef enum {
|
||||||
} TextureFilterMode;
|
} TextureFilterMode;
|
||||||
|
|
||||||
// Cubemap layout type
|
// Cubemap layout type
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
CUBEMAP_AUTO_DETECT = 0, // Automatically detect layout type
|
CUBEMAP_AUTO_DETECT = 0, // Automatically detect layout type
|
||||||
CUBEMAP_LINE_VERTICAL, // Layout is defined by a vertical line with faces
|
CUBEMAP_LINE_VERTICAL, // Layout is defined by a vertical line with faces
|
||||||
CUBEMAP_LINE_HORIZONTAL, // Layout is defined by an horizontal line with faces
|
CUBEMAP_LINE_HORIZONTAL, // Layout is defined by an horizontal line with faces
|
||||||
|
|
@ -874,7 +949,8 @@ typedef enum {
|
||||||
} CubemapLayoutType;
|
} CubemapLayoutType;
|
||||||
|
|
||||||
// Texture parameters: wrap mode
|
// Texture parameters: wrap mode
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
WRAP_REPEAT = 0, // Repeats texture in tiled mode
|
WRAP_REPEAT = 0, // Repeats texture in tiled mode
|
||||||
WRAP_CLAMP, // Clamps texture to edge pixel in tiled mode
|
WRAP_CLAMP, // Clamps texture to edge pixel in tiled mode
|
||||||
WRAP_MIRROR_REPEAT, // Mirrors and repeats the texture in tiled mode
|
WRAP_MIRROR_REPEAT, // Mirrors and repeats the texture in tiled mode
|
||||||
|
|
@ -882,14 +958,16 @@ typedef enum {
|
||||||
} TextureWrapMode;
|
} TextureWrapMode;
|
||||||
|
|
||||||
// Font type, defines generation method
|
// Font type, defines generation method
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
FONT_DEFAULT = 0, // Default font generation, anti-aliased
|
FONT_DEFAULT = 0, // Default font generation, anti-aliased
|
||||||
FONT_BITMAP, // Bitmap font generation, no anti-aliasing
|
FONT_BITMAP, // Bitmap font generation, no anti-aliasing
|
||||||
FONT_SDF // SDF font generation, requires external shader
|
FONT_SDF // SDF font generation, requires external shader
|
||||||
} FontType;
|
} FontType;
|
||||||
|
|
||||||
// Color blending modes (pre-defined)
|
// Color blending modes (pre-defined)
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
||||||
BLEND_ADDITIVE, // Blend textures adding colors
|
BLEND_ADDITIVE, // Blend textures adding colors
|
||||||
BLEND_MULTIPLIED // Blend textures multiplying colors
|
BLEND_MULTIPLIED // Blend textures multiplying colors
|
||||||
|
|
@ -897,7 +975,8 @@ typedef enum {
|
||||||
|
|
||||||
// Gestures type
|
// Gestures type
|
||||||
// NOTE: It could be used as flags to enable only some gestures
|
// NOTE: It could be used as flags to enable only some gestures
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
GESTURE_NONE = 0,
|
GESTURE_NONE = 0,
|
||||||
GESTURE_TAP = 1,
|
GESTURE_TAP = 1,
|
||||||
GESTURE_DOUBLETAP = 2,
|
GESTURE_DOUBLETAP = 2,
|
||||||
|
|
@ -912,7 +991,8 @@ typedef enum {
|
||||||
} GestureType;
|
} GestureType;
|
||||||
|
|
||||||
// Camera system modes
|
// Camera system modes
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
CAMERA_CUSTOM = 0,
|
CAMERA_CUSTOM = 0,
|
||||||
CAMERA_FREE,
|
CAMERA_FREE,
|
||||||
CAMERA_ORBITAL,
|
CAMERA_ORBITAL,
|
||||||
|
|
@ -921,13 +1001,15 @@ typedef enum {
|
||||||
} CameraMode;
|
} CameraMode;
|
||||||
|
|
||||||
// Camera projection modes
|
// Camera projection modes
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
CAMERA_PERSPECTIVE = 0,
|
CAMERA_PERSPECTIVE = 0,
|
||||||
CAMERA_ORTHOGRAPHIC
|
CAMERA_ORTHOGRAPHIC
|
||||||
} CameraType;
|
} CameraType;
|
||||||
|
|
||||||
// Head Mounted Display devices
|
// Head Mounted Display devices
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
HMD_DEFAULT_DEVICE = 0,
|
HMD_DEFAULT_DEVICE = 0,
|
||||||
HMD_OCULUS_RIFT_DK2,
|
HMD_OCULUS_RIFT_DK2,
|
||||||
HMD_OCULUS_RIFT_CV1,
|
HMD_OCULUS_RIFT_CV1,
|
||||||
|
|
@ -937,7 +1019,8 @@ typedef enum {
|
||||||
} VrDeviceType;
|
} VrDeviceType;
|
||||||
|
|
||||||
// Type of n-patch
|
// Type of n-patch
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
NPT_9PATCH = 0, // Npatch defined by 3x3 tiles
|
NPT_9PATCH = 0, // Npatch defined by 3x3 tiles
|
||||||
NPT_3PATCH_VERTICAL, // Npatch defined by 1x3 tiles
|
NPT_3PATCH_VERTICAL, // Npatch defined by 1x3 tiles
|
||||||
NPT_3PATCH_HORIZONTAL // Npatch defined by 3x1 tiles
|
NPT_3PATCH_HORIZONTAL // Npatch defined by 3x1 tiles
|
||||||
|
|
@ -947,7 +1030,8 @@ typedef enum {
|
||||||
typedef void (*TraceLogCallback)(int logType, const char *text, va_list args);
|
typedef void (*TraceLogCallback)(int logType, const char *text, va_list args);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" { // Prevents name mangling of functions
|
extern "C"
|
||||||
|
{ // Prevents name mangling of functions
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
@ -1262,8 +1346,7 @@ RLAPI void DrawFPS(int posX, int posY);
|
||||||
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
|
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
|
||||||
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
|
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
|
||||||
RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits
|
RLAPI void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint); // Draw text using font inside rectangle limits
|
||||||
RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint,
|
RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectText, Color selectBack); // Draw text using font inside rectangle limits with support for text selection
|
||||||
int selectStart, int selectLength, Color selectText, Color selectBack); // Draw text using font inside rectangle limits with support for text selection
|
|
||||||
|
|
||||||
// Text misc. functions
|
// Text misc. functions
|
||||||
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
||||||
|
|
@ -1487,33 +1570,26 @@ RLAPI void CloseNetwork(void);
|
||||||
RLAPI char *ResolveIP(const char *host, const char *port, int flags);
|
RLAPI char *ResolveIP(const char *host, const char *port, int flags);
|
||||||
|
|
||||||
// Protocol-independent translation from an ANSI host name to an address.
|
// Protocol-independent translation from an ANSI host name to an address.
|
||||||
RLAPI char* ResolveHost(const char *address, const char *port, AddressInformation *outaddr);
|
RLAPI char *ResolveHost(const char *address, const char *port);
|
||||||
|
|
||||||
// Socket API
|
// Socket API
|
||||||
RLAPI bool SocketOpen(SocketConfig *cfg, SocketResult *res);
|
RLAPI bool SocketOpen(SocketConfig *cfg, SocketResult *res);
|
||||||
RLAPI void SocketClose(SocketHandle socket);
|
RLAPI void SocketClose(SocketChannel socket);
|
||||||
RLAPI bool SocketAccept(SocketHandle listener, SocketResult* res);
|
RLAPI Socket *SocketAccept(Socket *server, SocketConfig *cfg);
|
||||||
RLAPI int SocketSend(Socket *socket, const void *datap, int len);
|
RLAPI int SocketSend(Socket *socket, const void *datap, int len);
|
||||||
RLAPI int SocketReceive(Socket* socket, void *data, int maxlen);
|
RLAPI int SocketReceive(Socket *socket, void *data, int maxlen, int timeout);
|
||||||
RLAPI void SocketSetHints(SocketConfig *cfg, AddressInformation *hints);
|
|
||||||
|
|
||||||
// Utility print methods
|
// Socket set methods for async i/o
|
||||||
RLAPI char *SocketAddressToString(SocketAddress *sockaddr, char buffer[], int* port);
|
RLAPI bool IsSocketReady(Socket* sock);
|
||||||
RLAPI void PrintSocket(SocketAddress *addr, const int family, const int socktype, const int protocol);
|
RLAPI SocketSet* CreateSocketSet(int max);
|
||||||
|
RLAPI void CleanupSocketSet(SocketSet* sockset);
|
||||||
|
RLAPI int AddSocket(SocketSet* set, Socket* sock);
|
||||||
|
RLAPI int RemoveSocket(SocketSet* set, Socket* sock);
|
||||||
|
RLAPI int CheckSockets(SocketSet* set, unsigned int timeout);
|
||||||
|
|
||||||
// Network conversion methods
|
// Creation and allocation
|
||||||
RLAPI unsigned int PackData(unsigned char *buf, char *format, ...);
|
RLAPI SocketResult *AllocSocketResult();
|
||||||
RLAPI void UnpackData(unsigned char *buf, char *format, ...);
|
RLAPI Socket *AllocSocket();
|
||||||
RLAPI unsigned short HostToNetworkShort(unsigned short value); // 2 bytes - 0 to 65,535
|
|
||||||
RLAPI unsigned long HostToNetworkLong(unsigned long value); // 4 bytes - 0 to 4,294,967,295
|
|
||||||
RLAPI unsigned int HostToNetworkFloat(float value); // 4 bytes - 1.2E-38 to 3.4E+38
|
|
||||||
RLAPI unsigned long long HostToNetworkDouble(double value); // 8 bytes - 2.3E-308 to 1.7E+308
|
|
||||||
RLAPI unsigned long long HostToNetworkLongLong(unsigned long long value); // 8 bytes - 0 to 1.8446744073709551615 × 10^19
|
|
||||||
RLAPI unsigned short NetworkToHostShort(unsigned short value); // 2 byte - 0 to 65,535
|
|
||||||
RLAPI unsigned long NetworkToHostLong(unsigned long value); // 4 byte - 0 to 4,294,967,295
|
|
||||||
RLAPI float NetworkToHostFloat(unsigned int value); // 4 byte - 1.2E-38 to 3.4E+38
|
|
||||||
RLAPI double NetworkToHostDouble(unsigned long long value); // 8 byte - 2.3E-308 to 1.7E+308
|
|
||||||
RLAPI unsigned long long NetworkToHostLongLong(unsigned long long value); // 8 byte - 0 to 1.8446744073709551615 × 10^19
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1188
src/rnet.c
1188
src/rnet.c
File diff suppressed because it is too large
Load Diff
15
src/sysnet.h
15
src/sysnet.h
|
|
@ -186,6 +186,19 @@ typedef long int int64;
|
||||||
# define RESULT_FAILURE 1
|
# define RESULT_FAILURE 1
|
||||||
#endif // RESULT_FAILURE
|
#endif // RESULT_FAILURE
|
||||||
|
|
||||||
|
#ifndef INADDR_ANY
|
||||||
|
# define INADDR_ANY 0x00000000
|
||||||
|
#endif // INADDR_ANY
|
||||||
|
#ifndef INADDR_NONE
|
||||||
|
# define INADDR_NONE 0xFFFFFFFF
|
||||||
|
#endif // INADDR_NONE
|
||||||
|
#ifndef INADDR_LOOPBACK
|
||||||
|
# define INADDR_LOOPBACK 0x7f000001
|
||||||
|
#endif // INADDR_LOOPBACK
|
||||||
|
#ifndef INADDR_BROADCAST
|
||||||
|
# define INADDR_BROADCAST 0xFFFFFFFF
|
||||||
|
#endif // INADDR_BROADCAST
|
||||||
|
|
||||||
#ifndef htonll
|
#ifndef htonll
|
||||||
# ifdef _BIG_ENDIAN
|
# ifdef _BIG_ENDIAN
|
||||||
# define htonll(x) (x)
|
# define htonll(x) (x)
|
||||||
|
|
@ -206,9 +219,9 @@ typedef long int int64;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# pragma comment(lib, "ws2_32.lib")
|
# pragma comment(lib, "ws2_32.lib")
|
||||||
# define __USE_W32_SOCKETS
|
# define __USE_W32_SOCKETS
|
||||||
|
# include <winsock2.h>
|
||||||
# include <Ws2tcpip.h>
|
# include <Ws2tcpip.h>
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
# include <winsock2.h>
|
|
||||||
# define IPTOS_LOWDELAY 0x10
|
# define IPTOS_LOWDELAY 0x10
|
||||||
#else /* UNIX */
|
#else /* UNIX */
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user