1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "raylib.h"
#include "raymath.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "server.h"
#include "queue.h"
#include "shared.h"
#include "net_compat.h"
ClientConnection connections[MAX_PLAYERS];
PacketQueue incomingQueue;
PacketQueue outgoingQueue;
Mesh terrainMesh;
Matrix terrainTransform;
ServerPlayer players[MAX_PLAYERS];
ServerNPC npcs[MAX_NPCS];
int playerCount = 0;
int npcCount = 0;
int main() {
/* set_nonblocking(fd); */
QueueInit(&incomingQueue);
QueueInit(&outgoingQueue);
InitWindow(1, 1, "server"); // tiny hidden window
SetWindowState(FLAG_WINDOW_HIDDEN);
Model terrain = LoadModel("assets/terrain.glb");
if (terrain.meshCount == 0) {
TraceLog(LOG_ERROR, "Terrain failed to load!");
}
// Bake scale into vertices so rendering and collision match
float scaleXZ = 10.0f;
float scaleY = 10.0f;
for (int i = 0; i < terrain.meshes[0].vertexCount; i++) {
terrain.meshes[0].vertices[i * 3 + 0] *= scaleXZ;
terrain.meshes[0].vertices[i * 3 + 1] *= scaleY;
terrain.meshes[0].vertices[i * 3 + 2] *= scaleXZ;
}
UpdateMeshBuffer(terrain.meshes[0], 0, terrain.meshes[0].vertices,
terrain.meshes[0].vertexCount * 3 * sizeof(float), 0);
terrain.transform = MatrixIdentity();
terrainMesh = terrain.meshes[0];
terrainTransform = terrain.transform;
CloseWindow();
NetworkInit();
// start threads
pthread_t recvThread, sendThread, gameThread;
pthread_create(&recvThread, NULL, RecvThread, NULL);
pthread_create(&sendThread, NULL, SendThread, NULL);
pthread_create(&gameThread, NULL, GameThread, NULL);
// wait forever
pthread_join(gameThread, NULL);
NetworkShutdown();
return 0;
}
|