Compare commits

...

2 Commits

Author SHA1 Message Date
Peter Nelson 6dfc0cc5dd
Something 2023-08-05 18:54:11 +01:00
Peter Nelson 86dfa2637d Change: Force spaces for indentation, and auto-reformat.
Some of the formatting is no longer optimal but it is at least consistent.
2023-08-05 16:43:57 +01:00
26 changed files with 3286 additions and 3141 deletions

View File

@ -14,8 +14,8 @@ SRCS += worker.c
OBJS := $(SRCS:.c=.o)
CFLAGS += `pkg-config libglfw ftgl openal --cflags` -g
LDFLAGS += `pkg-config libglfw ftgl openal --libs` -g
CFLAGS += `pkg-config freetype2 glfw3 ftgl openal opengl --cflags` -g
LDFLAGS += -lm -lpthread -lSOIL `pkg-config freetype2 glfw3 ftgl openal opengl --libs`
lfsdash: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $@

36
audio.c
View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
//#include <GL/glut.h>
// #include <GL/glut.h>
#include <AL/al.h>
#include <AL/alc.h>
#include <string.h>
@ -14,16 +14,16 @@
ALCdevice *dev;
ALCcontext *ctx;
//There is only one listener, and these arrays define the initial set up of the listener for its position, direction, and velocity. The listener is not moving at the start, but can move around any other sound source.
ALfloat listenerPos[]={0.0,0.0,4.0};
ALfloat listenerVel[]={0.0,0.0,0.0};
ALfloat listenerOri[]={0.0,0.0,1.0, 0.0,1.0,0.0};
// There is only one listener, and these arrays define the initial set up of the listener for its position, direction, and velocity. The listener is not moving at the start, but can move around any other sound source.
ALfloat listenerPos[] = {0.0, 0.0, 4.0};
ALfloat listenerVel[] = {0.0, 0.0, 0.0};
ALfloat listenerOri[] = {0.0, 0.0, 1.0, 0.0, 1.0, 0.0};
//Each sound source has similar properties that the listener has. The source0Pos and source0Vel arrays show the position and velocity of the sound source.
ALfloat source0Pos[]={ -2.0, 0.0, 0.0};
ALfloat source0Vel[]={ 0.0, 0.0, 0.0};
// Each sound source has similar properties that the listener has. The source0Pos and source0Vel arrays show the position and velocity of the sound source.
ALfloat source0Pos[] = {-2.0, 0.0, 0.0};
ALfloat source0Vel[] = {0.0, 0.0, 0.0};
//Sounds need to be stored in an array, similar to textures. Several buffers are needed to contain the sounds and other necessary information. The size, freq, format, and data variables are used when loading the sound files.
// Sounds need to be stored in an array, similar to textures. Several buffers are needed to contain the sounds and other necessary information. The size, freq, format, and data variables are used when loading the sound files.
ALuint buffer[NUM_BUFFERS];
ALuint source[NUM_SOURCES];
ALuint environment[NUM_ENVIRONMENTS];
@ -58,7 +58,8 @@ void *file_allocate_and_read_bytes(FILE *file, size_t bytes)
return buffer;
}
static inline ALenum GetFormatFromInfo(short channels, short bitsPerSample) {
static inline ALenum GetFormatFromInfo(short channels, short bitsPerSample)
{
if (channels == 1)
return AL_FORMAT_MONO16;
return AL_FORMAT_STEREO16;
@ -66,7 +67,7 @@ static inline ALenum GetFormatFromInfo(short channels, short bitsPerSample) {
void audio_load(const char *filename, ALuint buffer)
{
FILE* file = fopen(filename, "rb");
FILE *file = fopen(filename, "rb");
char xbuffer[5];
memset(xbuffer, 0, sizeof xbuffer);
if (fread(xbuffer, sizeof(char), 4, file) != 4 || strcmp(xbuffer, "RIFF") != 0)
@ -96,7 +97,7 @@ void audio_load(const char *filename, ALuint buffer)
printf("Invalid WAV file: %s\n", xbuffer);
int dataChunkSize = file_read_int32_le(xbuffer, file);
unsigned char* bufferData = file_allocate_and_read_bytes(file, (size_t) dataChunkSize);
unsigned char *bufferData = file_allocate_and_read_bytes(file, (size_t)dataChunkSize);
float duration = (float)(dataChunkSize) / byteRate;
alBufferData(buffer, GetFormatFromInfo(channels, bitsPerSample), bufferData, dataChunkSize, sampleRate);
@ -121,16 +122,17 @@ void audio_init(void)
return;
}
alListenerfv(AL_POSITION,listenerPos);
alListenerfv(AL_VELOCITY,listenerVel);
alListenerfv(AL_ORIENTATION,listenerOri);
alListenerfv(AL_POSITION, listenerPos);
alListenerfv(AL_VELOCITY, listenerVel);
alListenerfv(AL_ORIENTATION, listenerOri);
alGetError(); // clear any error messages
// Generate buffers, or else no sound will happen!
alGenBuffers(NUM_BUFFERS, buffer);
if (alGetError() != AL_NO_ERROR) {
if (alGetError() != AL_NO_ERROR)
{
printf("- Error creating buffers !!\n");
exit(1);
}
@ -157,7 +159,7 @@ void audio_init(void)
alSourcef(source[ii], AL_GAIN, 1.0f);
alSourcefv(source[ii], AL_POSITION, source0Pos);
alSourcefv(source[ii], AL_VELOCITY, source0Vel);
//alSourcei(source[0], AL_BUFFER, buffer[0]);
// alSourcei(source[0], AL_BUFFER, buffer[0]);
alSourcei(source[ii], AL_LOOPING, AL_FALSE);
}
}

View File

@ -1,7 +1,8 @@
#ifndef AUDIO_H
#define AUDIO_H
enum {
enum
{
FX_ON,
FX_OFF,
FX_BING,

21
cars.c
View File

@ -10,10 +10,10 @@ struct car s_cars[MAX_CARS];
#include <string.h>
#include <stdio.h>
char* strsep(char** stringp, const char* delim)
char *strsep(char **stringp, const char *delim)
{
char* start = *stringp;
char* p;
char *start = *stringp;
char *p;
p = (start != NULL) ? strpbrk(start, delim) : NULL;
@ -36,15 +36,18 @@ void init_cars(void)
memset(s_cars, 0, sizeof s_cars);
FILE *f = fopen("cars.txt", "r");
if (!f) return;
if (!f)
return;
struct car *car = s_cars;
while (!feof(f))
{
char buf[1024];
if (fgets(buf, sizeof buf, f) <= 0) break;
if (*buf == '#') continue;
if (fgets(buf, sizeof buf, f) <= 0)
break;
if (*buf == '#')
continue;
char *bufp = buf, *p;
p = strsep(&bufp, ",");
@ -70,7 +73,8 @@ void init_cars(void)
car++;
if (car - s_cars == MAX_CARS) break;
if (car - s_cars == MAX_CARS)
break;
}
fclose(f);
@ -83,7 +87,8 @@ int get_car(const char tag[4], struct car *car)
{
if (!strcmp(s_cars[i].tag, tag))
{
if (car != NULL) memcpy(car, &s_cars[i], sizeof *car);
if (car != NULL)
memcpy(car, &s_cars[i], sizeof *car);
return i;
}
}

View File

@ -57,7 +57,8 @@ void config_set_string(const char *key, const char *value)
itemp = &(*itemp)->next;
}
if (value == NULL) return;
if (value == NULL)
return;
*itemp = malloc(sizeof *item);
item = *itemp;
@ -70,24 +71,29 @@ void config_set_string(const char *key, const char *value)
static void config_rehash(void)
{
FILE *f = fopen(s_config.filename, "r");
if (f == NULL) return;
if (f == NULL)
return;
config_free();
while (!feof(f))
{
char buf[256];
if (fgets(buf, sizeof buf, f) <= 0) break;
if (fgets(buf, sizeof buf, f) <= 0)
break;
/* Ignore comments */
if (*buf == '#') continue;
if (*buf == '#')
continue;
char *n = strchr(buf, '=');
if (n == NULL) continue;
if (n == NULL)
continue;
*n++ = '\0';
char *eol = strchr(n, '\n');
if (eol != NULL) *eol = '\0';
if (eol != NULL)
*eol = '\0';
config_set_string(buf, n);
}
@ -98,7 +104,8 @@ static void config_rehash(void)
static void config_write(void)
{
FILE *f = fopen(s_config.filename, "w");
if (f == NULL) return;
if (f == NULL)
return;
struct configitem *curr;
for (curr = s_config.head; curr != NULL; curr = curr->next)
@ -158,10 +165,12 @@ int config_get_int(const char *setting, int *value)
char *c, *endptr;
int v;
if (!config_get_string(setting, &c)) return 0;
if (!config_get_string(setting, &c))
return 0;
v = strtol(c, &endptr, 10);
if (*endptr != '\0') return 0;
if (*endptr != '\0')
return 0;
*value = v;
return 1;
@ -172,10 +181,12 @@ int config_get_float(const char *setting, float *value)
char *c, *endptr;
float v;
if (!config_get_string(setting, &c)) return 0;
if (!config_get_string(setting, &c))
return 0;
v = strtof(c, &endptr);
if (*endptr != '\0') return 0;
if (*endptr != '\0')
return 0;
*value = v;
return 1;

85
gauge.c
View File

@ -1,4 +1,4 @@
#include <GL/glfw.h>
#include <GLFW/glfw3.h>
#include <FTGL/ftgl.h>
#include <math.h>
#include <stdio.h>
@ -12,21 +12,20 @@ void init_gauges(void)
void DrawArc(float inner, float outer, float start_angle, float arc_angle, int num_segments)
{
num_segments = 72;
float theta = arc_angle / (float)(num_segments - 1);//theta is now calculated from the arc angle instead, the - 1 bit comes from the fact that the arc is open
float theta = arc_angle / (float)(num_segments - 1); // theta is now calculated from the arc angle instead, the - 1 bit comes from the fact that the arc is open
float tangetial_factor = tanf(theta);
float radial_factor = cosf(theta);
float xi = inner * sinf(start_angle); //we now start at the start angle
float xi = inner * sinf(start_angle); // we now start at the start angle
float yi = inner * cosf(start_angle);
float xo = outer * sinf(start_angle); //we now start at the start angle
float xo = outer * sinf(start_angle); // we now start at the start angle
float yo = outer * cosf(start_angle);
glBegin(GL_TRIANGLE_STRIP);//since the arc is not a closed curve, this is a strip now
glBegin(GL_TRIANGLE_STRIP); // since the arc is not a closed curve, this is a strip now
int ii;
for(ii = 0; ii < num_segments; ii++)
for (ii = 0; ii < num_segments; ii++)
{
glVertex3f(xi, yi, 0);
glVertex3f(xo, yo, 0);
@ -81,8 +80,6 @@ void drawDial(const struct gauge *gauge, float value, int style)
float angle = gauge->anglemax - gauge->anglemin;
float cura = (value - gauge->rangemin) / range * angle + gauge->anglemin;
switch (style)
{
case GT_NONE:
@ -110,29 +107,28 @@ void drawDial(const struct gauge *gauge, float value, int style)
glColor4f(gauge->dial.r, gauge->dial.g, gauge->dial.b, gauge->dial.a);
glRotatef(cura * -180.0 / M_PI, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLE_STRIP);
//glVertex3f(-0.01, -0.04, 0.0);
//glVertex3f(0.01, -0.04, 0.0);
//glVertex3f(-0.02, 0, 0.0);
//glVertex3f(0.02, 0.0, 0.0);
//glVertex3f(-0.005, 1.0, 0.0);
//glVertex3f(0.005, 1.0, 0.0);
// glVertex3f(-0.01, -0.04, 0.0);
// glVertex3f(0.01, -0.04, 0.0);
// glVertex3f(-0.02, 0, 0.0);
// glVertex3f(0.02, 0.0, 0.0);
// glVertex3f(-0.005, 1.0, 0.0);
// glVertex3f(0.005, 1.0, 0.0);
glVertex3f(-0.02, 0.2, 0.0);
glVertex3f(0.02, 0.2, 0.0);
glVertex3f(-0.005, 1.0, 0.0);
glVertex3f(0.005, 1.0, 0.0);
//glVertex3f(0.0, 1.0, 0.0);
// glVertex3f(0.0, 1.0, 0.0);
glEnd();
break;
}
}
void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *font, int gaugetype)
{
float range = gauge->rangemax - gauge->rangemin;
float angle = gauge->anglemax - gauge->anglemin;
float major;// = angle / (range / gauge->majorstep + 0.0);
float minor;// = angle / (range / gauge->minorstep + 0.0);
float major; // = angle / (range / gauge->majorstep + 0.0);
float minor; // = angle / (range / gauge->minorstep + 0.0);
float cura;
float x1, y1, x2, y2;
int ii;
@ -140,30 +136,37 @@ void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *fon
float majorstep = gauge->majorstep;
float minorstep = gauge->minorstep;
while (1) {
while (1)
{
major = angle / (range / majorstep + 0.0);
minor = angle / (range / minorstep + 0.0);
if (fabsf(major) < 12 * M_PI / 180.0) {
if (fabsf(major) < 12 * M_PI / 180.0)
{
majorstep *= 2;
minorstep = majorstep / 2;
} else {
}
else
{
break;
}
}
if (value < gauge->rangemin) value = gauge->rangemin;
if (value > gauge->rangemax * 2) value = gauge->rangemax * 2;
if (value < gauge->rangemin)
value = gauge->rangemin;
if (value > gauge->rangemax * 2)
value = gauge->rangemax * 2;
glPushMatrix();
glScalef(gauge->radius, gauge->radius, 1.0);
if (red > 0) {
if (red > 0)
{
glLineWidth(1.0);
glColor4f(0.8, 0.0, 0.0, 1.0);
cura = (red - gauge->rangemin) / range * angle + gauge->anglemin;
/*
/*
float x1 = sin(cura) * gauge->majorstart;
float y1 = cos(cura) * gauge->majorstart;
float x2 = sin(cura) * gauge->majorend;
@ -173,16 +176,17 @@ void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *fon
glVertex3f(x2, y2, 0);
glEnd();*/
// printf("%f -> %f\n", cura, gauge->anglemax);
// printf("%f -> %f\n", cura, gauge->anglemax);
DrawArc(gauge->majorstart, gauge->majorend, gauge->anglemax, gauge->anglemax - cura, 10);
}
glLineWidth(gauge->minorwidth);
glColor4f(gauge->minor.r, gauge->minor.g, gauge->minor.b, gauge->minor.a);
// for (cura = gauge->anglemin; cura < gauge->anglemax; cura += minor)
// for (cura = gauge->anglemin; cura < gauge->anglemax; cura += minor)
for (ii = 0; ii <= range / minorstep; ii++)
{
if (red > 0 && ii * minorstep >= red) {
if (red > 0 && ii * minorstep >= red)
{
glColor4f(1.0, 1.0, 1.0, 1.0);
}
float cura = gauge->anglemin + ii * minor;
@ -198,10 +202,11 @@ void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *fon
glLineWidth(gauge->majorwidth);
glColor4f(gauge->major.r, gauge->major.g, gauge->major.b, gauge->major.a);
// for (cura = gauge->anglemin; cura < gauge->anglemax; cura += major)
// for (cura = gauge->anglemin; cura < gauge->anglemax; cura += major)
for (ii = 0; ii <= range / majorstep; ii++)
{
if (red > 0 && ii * majorstep > red) {
if (red > 0 && ii * majorstep > red)
{
glColor4f(1.0, 1.0, 1.0, 1.0);
}
float cura = gauge->anglemin + ii * major;
@ -215,12 +220,19 @@ void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *fon
glEnd();
char text[10];
if (gauge->majorstep > 100) {
if (gauge->majorstep > 100)
{
snprintf(text, sizeof text, "%d", (int)(ii * majorstep / 1000 + gauge->rangemin));
} else {
if (range == 1) {
snprintf(text, sizeof text, ii == 0 ? "E" : ii == 1 ? "½" : "F");
} else {
}
else
{
if (range == 1)
{
snprintf(text, sizeof text, ii == 0 ? "E" : ii == 1 ? "½"
: "F");
}
else
{
snprintf(text, sizeof text, "%d", (int)(ii * majorstep + gauge->rangemin));
}
}
@ -234,4 +246,3 @@ void draw_gauge(const struct gauge *gauge, float value, float red, FTGLfont *fon
glPopMatrix();
}

View File

@ -58,7 +58,8 @@ struct gauge
struct colour dial;
};
enum {
enum
{
GT_NONE,
GT_NEEDLE,
GT_LINE,

View File

@ -40,21 +40,28 @@ static inline int clock_gettime(int X, struct timespec *ts)
static int initialized = 0;
static BOOL usePerformanceCounter = 0;
if (!initialized) {
if (!initialized)
{
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if (usePerformanceCounter) {
if (usePerformanceCounter)
{
QueryPerformanceCounter(&offset);
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
} else {
}
else
{
offset = getFILETIMEoffset();
frequencyToMicroseconds = 10.;
}
}
if (usePerformanceCounter) {
if (usePerformanceCounter)
{
QueryPerformanceCounter(&t);
} else {
}
else
{
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;

69
insim.c
View File

@ -1,4 +1,4 @@
//#define USE_IPV6
// #define USE_IPV6
#include <stdlib.h>
#ifdef WIN32
@ -7,9 +7,9 @@
#include <windows.h>
#define MSG_NOSIGNAL 0
#else
//#include <sys/types.h>
// #include <sys/types.h>
#include <sys/socket.h>
//#include <netinet/in.h>
// #include <netinet/in.h>
#endif
#include <errno.h>
#include <stdio.h>
@ -25,7 +25,8 @@
struct conninfo s_conninfo[256];
struct carinfo s_carinfo[256];
struct insim_buffer {
struct insim_buffer
{
int state;
uint8_t buffer[65536];
int pos;
@ -48,12 +49,14 @@ void insim_queue(const void *buffer, size_t size)
int insim_dequeue(int fd)
{
if (s_send_packet == NULL) queue_consume(s_send_queue, (void *)&s_send_packet);
if (s_send_packet == NULL)
queue_consume(s_send_queue, (void *)&s_send_packet);
if (s_send_packet != NULL)
{
ssize_t s = send(fd, (char *)s_send_packet + s_send_pos, s_send_packet[0] - s_send_pos, MSG_NOSIGNAL);
if (s >= 0) s_send_pos += s;
if (s >= 0)
s_send_pos += s;
if (s_send_pos >= s_send_packet[0])
{
free(s_send_packet);
@ -105,8 +108,10 @@ void insim_handle_tiny(int fd, const void *buffer)
static void ltc_duty(const char *uname, int state)
{
int i;
for (i = 0; i < 256; i++) {
if (!strcmp(uname, s_conninfo[i].uname)) {
for (i = 0; i < 256; i++)
{
if (!strcmp(uname, s_conninfo[i].uname))
{
s_conninfo[i].state = state;
printf("Player %s state %d\n", uname, state);
return;
@ -135,16 +140,25 @@ void insim_handle_mso(int fd, const void *buffer)
char *name = NULL;
int i;
for (i = 0; i < 10; i++) {
for (i = 0; i < 10; i++)
{
char *a = strsep(&bufp, " ");
if (a == NULL) return;
if (i == 0 && strcmp(a, "***")) return;
if (i == 1 && (!strcmp(a, "Officer") || !strcmp(a, "Cadet"))) state |= 1;
if (i == 2 && state == 1) name = a;
if (i == 3 && strcmp(a, "has")) return;
if (i == 4 && strcmp(a, "gone")) return;
if (i == 5 && !strcmp(a, "onduty")) ltc_duty(name, 1);
if (i == 5 && !strcmp(a, "offduty")) ltc_duty(name, 0);
if (a == NULL)
return;
if (i == 0 && strcmp(a, "***"))
return;
if (i == 1 && (!strcmp(a, "Officer") || !strcmp(a, "Cadet")))
state |= 1;
if (i == 2 && state == 1)
name = a;
if (i == 3 && strcmp(a, "has"))
return;
if (i == 4 && strcmp(a, "gone"))
return;
if (i == 5 && !strcmp(a, "onduty"))
ltc_duty(name, 1);
if (i == 5 && !strcmp(a, "offduty"))
ltc_duty(name, 0);
}
}
@ -172,7 +186,8 @@ void insim_handle_cpr(int fd, const void *buffer)
{
const struct IS_CPR *p = buffer;
struct conninfo *c = s_conninfo + p->UCID;
if (c->active == 0) fprintf(stderr, "Rename of inactive connection\n");
if (c->active == 0)
fprintf(stderr, "Rename of inactive connection\n");
strncpy(c->pname, p->PName, sizeof c->pname);
}
@ -182,7 +197,7 @@ void insim_handle_npl(int fd, const void *buffer)
struct carinfo *car = s_carinfo + p->PLID;
memset(car, 0, sizeof *car);
car->active = 1;
//strncpy(car->cname, p->CName, sizeof car->cname);
// strncpy(car->cname, p->CName, sizeof car->cname);
car->ucid = p->UCID;
car->mass = p->H_Mass;
car->intake = p->H_TRes;
@ -230,7 +245,7 @@ void insim_handle_mci(int fd, const void *buffer)
typedef void (*insim_handler)(int fd, const void *buffer);
static const insim_handler s_handlers[] =
{
{
NULL, // ISP_NONE // 0 : not used
NULL, // ISP_ISI // 1 - instruction : insim initialise
NULL, // ISP_VER // 2 - info : version info
@ -316,20 +331,20 @@ int insim_recv(int fd, int can_write, int can_read, void *arg)
ssize_t res = recv(fd, (char *)buffer->buffer + buffer->pos, sizeof buffer->buffer - buffer->pos, 0);
if (res == -1)
{
#ifdef WIN32
#ifdef WIN32
if (WSAGetLastError() == WSAECONNRESET)
#else
#else
if (errno == ECONNRESET)
#endif
#endif
{
printf("connreset\n");
return 0;
}
#ifdef WIN32
#ifdef WIN32
else if (WSAGetLastError() != WSAEWOULDBLOCK)
#else
#else
else if (errno != EWOULDBLOCK && errno != EAGAIN)
#endif
#endif
{
printf("hmm: %s\n", strerror(errno));
return 0;
@ -410,7 +425,7 @@ static void insim_connect(int fd, void *arg)
p.Type = ISP_ISI;
p.ReqI = 0;
p.Zero = 0;
p.UDPPort = g_outgauge_port; //g_insim_port + 1;
p.UDPPort = g_outgauge_port; // g_insim_port + 1;
p.Flags = ISF_LOCAL;
p.Sp0 = 0;
p.Prefix = 0;

36
insim.h
View File

@ -14,13 +14,11 @@
// NOTE : This text file was written with a TAB size equal to 4 spaces.
// INSIM VERSION NUMBER (updated for version 0.6B)
// ====================
static const int INSIM_VERSION = 5;
// CHANGES
// =======
@ -51,7 +49,6 @@ static const int INSIM_VERSION = 5;
// FIX : OutGaugePack ID was always zero regardless of ID in cfg.txt
// FIX : InSim camera with vertical pitch would cause LFS to crash
// TYPES : (all multi-byte types are PC style - lowest byte first)
// =====
@ -70,7 +67,6 @@ static const int INSIM_VERSION = 5;
// 100-190 : 100 to 1000 laps... laps = (rl - 100) * 10 + 100
// 191-238 : 1 to 48 hours... hours = rl - 190
// InSim PACKETS
// =============
@ -81,7 +77,6 @@ static const int INSIM_VERSION = 5;
// ReqI : non zero if the packet is a packet request or a reply to a request
// Data : the first data byte
// INITIALISING InSim
// ==================
@ -167,7 +162,6 @@ struct IS_ISI // InSim Init - packet to initialise the InSim system
// Messages typed with this prefix will be sent to your InSim program
// on the host (in IS_MSO) and not displayed on anyone's screen.
// ENUMERATIONS FOR PACKET TYPES
// =============================
@ -270,7 +264,6 @@ enum // the fourth byte of an IS_SMALL packet is one of these
SMALL_NLI, // 7 - instruction : set node lap interval
};
// GENERAL PURPOSE PACKETS - IS_TINY (4 bytes) and IS_SMALL (8 bytes)
// =======================
@ -300,7 +293,6 @@ struct IS_SMALL // General purpose 8 byte packet
uint32_t UVal; // value (e.g. for SMALL_SSP this would be the OutSim packet rate)
};
// VERSION REQUEST
// ===============
@ -327,7 +319,6 @@ struct IS_VER // VERsion
// ReqI : non-zero (returned in the reply)
// SubT : TINY_VER (request an IS_VER)
// CLOSING InSim
// =============
@ -341,7 +332,6 @@ struct IS_VER // VERsion
// You can shut down InSim completely and stop it listening at all by typing /insim=0
// into LFS (or send a MsgTypePack to do the same thing).
// MAINTAINING THE CONNECTION - IMPORTANT
// ==========================
@ -369,7 +359,6 @@ struct IS_VER // VERsion
// ReqI : non-zero (as received in the request packet)
// SubT : TINY_REPLY (reply to ping)
// STATE REPORTING AND REQUESTS
// ============================
@ -453,7 +442,6 @@ struct IS_SFP // State Flags Pack
// Other states must be set by using keypresses or messages (see below)
// SCREEN MODE
// ===========
@ -478,7 +466,6 @@ struct IS_MOD // MODe : send to LFS to change screen mode
// If Width and Height are both zero, LFS will switch to windowed mode.
// TEXT MESSAGES AND KEY PRESSES
// ==============================
@ -592,7 +579,7 @@ struct IS_MTC // Msg To Connection - hosts only - send to a connection / a playe
uint8_t Sp2;
uint8_t Sp3;
// char Text[TEXT_SIZE]; // up to 128 characters of text - last byte must be zero
// char Text[TEXT_SIZE]; // up to 128 characters of text - last byte must be zero
};
// Message Sounds (for Sound byte)
@ -625,7 +612,6 @@ struct IS_SCH // Single CHaracter
uint8_t Spare3;
};
// MULTIPLAYER NOTIFICATION
// ========================
@ -658,7 +644,6 @@ struct IS_ISM // InSim Multi
// NOTE : If LFS is not in multiplayer mode, the host name in the ISM will be empty.
// VOTE NOTIFY AND CANCEL
// ======================
@ -704,7 +689,6 @@ struct IS_VTN // VoTe Notify
// ReqI : 0
// SubT : TINY_VTC (VoTe Cancel)
// ALLOWED CARS
// ============
@ -752,7 +736,6 @@ struct IS_PLC // PLayer Cars
// BMW SAUBER F1.06 - 0x40000
// FORMULA BMW FB02 - 0x80000
// RACE TRACKING
// =============
@ -1313,7 +1296,6 @@ static const int NOT_CHANGED = 255;
// bit 6 female
// bit 7 rear right
// TRACKING PACKET REQUESTS
// ========================
@ -1327,7 +1309,6 @@ static const int NOT_CHANGED = 255;
// SubT : TINY_NLP - request a single IS_NLP
// SubT : TINY_MCI - request a set of IS_MCI
// AUTOCROSS
// =========
@ -1372,7 +1353,6 @@ struct IS_AXO // AutoX Object
uint8_t PLID; // player's unique id
};
// CAR TRACKING - car position info sent at constant intervals
// ============
@ -1452,7 +1432,6 @@ struct IS_MCI // Multi Car Info - if more than 8 in race then more than one of t
// SubT : SMALL_NLI (Node Lap Interval)
// UVal : interval (0 means stop, otherwise time interval : 40, 50, 60... 8000 ms)
// CONTACT - reports contacts between two cars if the closing speed is above 0.25 m/s
// =======
@ -1529,7 +1508,6 @@ struct IS_OBH // OBject Hit - car hit an autocross object or an unknown object
//'BBBBHHBBBBhhhhBBBB'
// OBHFlags byte
#define OBH_LAYOUT 1 // an added object
@ -1553,7 +1531,6 @@ struct IS_HLV // Hot Lap Validity - illegal ground / hit wall / speeding in pit
struct CarContOBJ C;
};
// AUTOCROSS OBJECTS - reporting / adding / removing
// =================
@ -1632,7 +1609,6 @@ enum
// the corresponding IS_AXM that will be output when the packet is processed. Then
// you can send the second packet and again wait for the IS_AXM and so on.
// CAR POSITION PACKETS (Initialising OutSim from InSim - See "OutSim" below)
// ====================
@ -1652,7 +1628,6 @@ enum
// NOTE : OutSim packets are not InSim packets and don't have a 4-byte header.
// DASHBOARD PACKETS (Initialising OutGauge from InSim - See "OutGauge" below)
// =================
@ -1672,7 +1647,6 @@ enum
// NOTE : OutGauge packets are not InSim packets and don't have a 4-byte header.
// CAMERA CONTROL
// ==============
@ -1773,7 +1747,6 @@ struct IS_CPP // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
// and later send back exactly the same packet to LFS and it will try to replicate
// that camera position.
// TIME CONTROL
// ============
@ -1806,7 +1779,6 @@ struct IS_CPP // Cam Pos Pack - Full camera packet (in car OR SHIFT+U mode)
// SubT : SMALL_STP (STeP)
// UVal : number (number of hundredths of a second to update)
// REPLAY CONTROL
// ==============
@ -1868,7 +1840,6 @@ enum
// NOTE : RIPOPT_FULL_PHYS makes MPR searching much slower so should not normally be used.
// This flag was added to allow high accuracy MCI packets to be output when fast forwarding.
// SCREENSHOTS
// ===========
@ -1902,7 +1873,6 @@ enum
SSH_NO_SAVE, // 3 - could not save the screenshot
};
// BUTTONS
// =======
@ -1977,7 +1947,7 @@ struct IS_BTN // BuTtoN - button header - followed by 0 to 240 characters
uint8_t W; // width : 0 - 200
uint8_t H; // height : 0 - 200
// char Text[TEXT_SIZE]; // 0 to 240 characters of text
// char Text[TEXT_SIZE]; // 0 to 240 characters of text
};
// ClickID byte : this value is returned in IS_BTC and IS_BTT packets.
@ -2077,7 +2047,6 @@ struct IS_BTT // BuTton Type - sent back when user types into a text entry butto
char Text[96]; // typed text, zero to TypeIn specified in IS_BTN
};
// OutSim - MOTION SIMULATOR SUPPORT
// ======
@ -2116,7 +2085,6 @@ struct OutSimPack
// not support any motion systems in particular and cannot accept responsibility
// for injuries or deaths connected with the use of such machinery.
// OutGauge - EXTERNAL DASHBOARD SUPPORT
// ========

375
lfsdash.c
View File

@ -1,9 +1,11 @@
#include <GL/glfw.h>
#include <GLFW/glfw3.h>
#include <FTGL/ftgl.h>
#include <SOIL/SOIL.h>
#include <pthread.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include "outgauge.h"
#include "cars.h"
#include "config.h"
@ -16,7 +18,8 @@
static GLuint s_symbols[1];
struct sympos {
struct sympos
{
float a, b, c, d;
int flag;
struct colour off;
@ -39,47 +42,50 @@ struct sympos {
*/
static int dl_to_sympos[] = {
18, 0, 12, 17, 11, 15, 16, 2, 10, 9, 14, 13
};
18, 0, 12, 17, 11, 15, 16, 2, 10, 9, 14, 13};
static struct sympos s_sympos[] = {
{ 0.0, 0.0, 0.125, 0.125, (1 << DL_FULLBEAM), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 0.15, 1.0, 1.0 } },
{ 0.125, 0.0, 0.25, 0.125, 0, { 0.1, 0.1, 0.1, 1.0 }, { 0.5, 0.5, 1.0, 1.0 } },
{ 0.25, 0.0, 0.375, 0.125, (1 << DL_SIGNAL_ANY), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 1.0, 0.15, 1.0 } },
{ 0.375, 0.0, 0.5, 0.125, 0, { 0.1, 0.1, 0.1, 1.0 }, { 0.5, 0.5, 1.0, 1.0 } },
{0.0, 0.0, 0.125, 0.125, (1 << DL_FULLBEAM), {0.1, 0.1, 0.1, 1.0}, {0.15, 0.15, 1.0, 1.0}},
{0.125, 0.0, 0.25, 0.125, 0, {0.1, 0.1, 0.1, 1.0}, {0.5, 0.5, 1.0, 1.0}},
{0.25, 0.0, 0.375, 0.125, (1 << DL_SIGNAL_ANY), {0.1, 0.1, 0.1, 1.0}, {0.15, 1.0, 0.15, 1.0}},
{0.375, 0.0, 0.5, 0.125, 0, {0.1, 0.1, 0.1, 1.0}, {0.5, 0.5, 1.0, 1.0}},
{ 0.0, 0.125, 0.125, 0.25, 0, { 1.0, 1.0, 1.0, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{ 0.125, 0.125, 0.25, 0.25, 0, { 1.0, 1.0, 1.0, 1.0 }, { 0.15, 0.15, 1.0, 1.0 } },
{ 0.25, 0.125, 0.375, 0.25, 0, { 1.0, 1.0, 1.0, 1.0 }, { 0.15, 0.15, 1.0, 1.0 } },
{ 0.375, 0.125, 0.5, 0.25, 0, { 1.0, 1.0, 1.0, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{ 0.5, 0.125, 0.625, 0.25, 0, { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 0.15, 0.15, 1.0 } },
{0.0, 0.125, 0.125, 0.25, 0, {1.0, 1.0, 1.0, 1.0}, {1.0, 0.15, 0.15, 1.0}},
{0.125, 0.125, 0.25, 0.25, 0, {1.0, 1.0, 1.0, 1.0}, {0.15, 0.15, 1.0, 1.0}},
{0.25, 0.125, 0.375, 0.25, 0, {1.0, 1.0, 1.0, 1.0}, {0.15, 0.15, 1.0, 1.0}},
{0.375, 0.125, 0.5, 0.25, 0, {1.0, 1.0, 1.0, 1.0}, {1.0, 0.15, 0.15, 1.0}},
{0.5, 0.125, 0.625, 0.25, 0, {0.1, 0.1, 0.1, 1.0}, {0.15, 0.15, 0.15, 1.0}},
{ 0.0, 0.25, 0.125, 0.375, (1 << DL_BATTERY), { 0.1, 0.1, 0.1, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{ 0.125, 0.25, 0.25, 0.375, (1 << DL_OILWARN), { 0.1, 0.1, 0.1, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{ 0.25, 0.25, 0.375, 0.375, (1 << DL_TC), { 0.1, 0.1, 0.1, 1.0 }, { 1.0, 0.5, 0.0, 1.0 } },
{ 0.375, 0.25, 0.5, 0.375, (1 << DL_HANDBRAKE), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 0.15, 1.0, 1.0 } },
{ 0.5, 0.25, 0.625, 0.375, 0, { 0.1, 0.1, 0.1, 1.0 }, { 0.25, 0.25, 1.0, 1.0 } },
{ 0.625, 0.25, 0.75, 0.375, (1 << DL_ABS), { 0.1, 0.1, 0.1, 1.0 }, { 1.0, 0.5, 0.0, 1.0 } },
{0.0, 0.25, 0.125, 0.375, (1 << DL_BATTERY), {0.1, 0.1, 0.1, 1.0}, {1.0, 0.15, 0.15, 1.0}},
{0.125, 0.25, 0.25, 0.375, (1 << DL_OILWARN), {0.1, 0.1, 0.1, 1.0}, {1.0, 0.15, 0.15, 1.0}},
{0.25, 0.25, 0.375, 0.375, (1 << DL_TC), {0.1, 0.1, 0.1, 1.0}, {1.0, 0.5, 0.0, 1.0}},
{0.375, 0.25, 0.5, 0.375, (1 << DL_HANDBRAKE), {0.1, 0.1, 0.1, 1.0}, {0.15, 0.15, 1.0, 1.0}},
{0.5, 0.25, 0.625, 0.375, 0, {0.1, 0.1, 0.1, 1.0}, {0.25, 0.25, 1.0, 1.0}},
{0.625, 0.25, 0.75, 0.375, (1 << DL_ABS), {0.1, 0.1, 0.1, 1.0}, {1.0, 0.5, 0.0, 1.0}},
{ 0.0, 0.375, 0.125, 0.5, (1 << DL_SIGNAL_L), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 1.0, 0.15, 1.0 } },
{ 0.125, 0.375, 0.25, 0.5, (1 << DL_SIGNAL_R), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 1.0, 0.15, 1.0 } },
{ 0.25, 0.375, 0.375, 0.5, (1 << DL_PITSPEED), { 0.1, 0.1, 0.1, 1.0 }, { 0.15, 1.0, 0.15, 1.0 } },
{ 0.375, 0.375, 0.5, 0.5, (1 << DL_SHIFT), { 0.1, 0.1, 0.1, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{0.0, 0.375, 0.125, 0.5, (1 << DL_SIGNAL_L), {0.1, 0.1, 0.1, 1.0}, {0.15, 1.0, 0.15, 1.0}},
{0.125, 0.375, 0.25, 0.5, (1 << DL_SIGNAL_R), {0.1, 0.1, 0.1, 1.0}, {0.15, 1.0, 0.15, 1.0}},
{0.25, 0.375, 0.375, 0.5, (1 << DL_PITSPEED), {0.1, 0.1, 0.1, 1.0}, {0.15, 1.0, 0.15, 1.0}},
{0.375, 0.375, 0.5, 0.5, (1 << DL_SHIFT), {0.1, 0.1, 0.1, 1.0}, {1.0, 0.15, 0.15, 1.0}},
{ 0.5, 0.0, 0.625, 0.125, 0, { 1.0, 0.5, 0.0, 1.0 }, { 1.0, 0.15, 0.15, 1.0 } },
{0.5, 0.0, 0.625, 0.125, 0, {1.0, 0.5, 0.0, 1.0}, {1.0, 0.15, 0.15, 1.0}},
};
void drawSymbol(int symbol, int on, int map)
{
if (map) symbol = dl_to_sympos[symbol];
if (map)
symbol = dl_to_sympos[symbol];
struct sympos *s = &s_sympos[symbol];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, s_symbols[0]);
if (on) {
if (on)
{
glColor4f(s->on.r, s->on.g, s->on.b, s->on.a);
} else {
}
else
{
glColor4f(s->off.r, s->off.g, s->off.b, s->off.a);
}
glBegin(GL_QUADS);
@ -123,17 +129,28 @@ int main(int argc, char **argv)
float warn_fuel2;
config_init("lfsdash.txt");
if (!config_get_int("port", &g_outgauge_port)) g_outgauge_port = 4000;
if (!config_get_int("fullscreen", &fullscreen)) fullscreen = 0;
if (!config_get_int("width", &width)) width = 1024;
if (!config_get_int("height", &height)) height = 600;
if (!config_get_int("volume", &volume)) volume = 100;
if (!config_get_int("rpmleft", &rpmleft)) rpmleft = 0;
if (!config_get_int("fade", &dofade)) dofade = 1;
if (!config_get_string("insim_host", &insim_host)) insim_host = strdup("localhost");
if (!config_get_int("insim_port", &g_insim_port)) g_insim_port = 29999;
if (!config_get_float("warn_fuel1", &warn_fuel1)) warn_fuel1 = 0.05f;
if (!config_get_float("warn_fuel2", &warn_fuel2)) warn_fuel2 = 0.01f;
if (!config_get_int("port", &g_outgauge_port))
g_outgauge_port = 4000;
if (!config_get_int("fullscreen", &fullscreen))
fullscreen = 0;
if (!config_get_int("width", &width))
width = 1024;
if (!config_get_int("height", &height))
height = 600;
if (!config_get_int("volume", &volume))
volume = 100;
if (!config_get_int("rpmleft", &rpmleft))
rpmleft = 0;
if (!config_get_int("fade", &dofade))
dofade = 1;
if (!config_get_string("insim_host", &insim_host))
insim_host = strdup("localhost");
if (!config_get_int("insim_port", &g_insim_port))
g_insim_port = 29999;
if (!config_get_float("warn_fuel1", &warn_fuel1))
warn_fuel1 = 0.05f;
if (!config_get_float("warn_fuel2", &warn_fuel2))
warn_fuel2 = 0.01f;
network_worker_init();
@ -143,14 +160,16 @@ int main(int argc, char **argv)
init_cars();
glfwInit();
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 1);
if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW))
glfwWindowHint(GLFW_SAMPLES, 1);
GLFWwindow *window = glfwCreateWindow(width, height, "GL LFS Dashboard", fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL);
if (window == NULL)
{
printf("Could not create window\n");
glfwTerminate();
return 0;
}
glfwSetWindowTitle("GL LFS Dashboard");
glfwSetWindowTitle(window, "GL LFS Dashboard");
audio_init();
@ -343,7 +362,7 @@ int main(int argc, char **argv)
oil.dial.b = 1.0;
oil.dial.a = 0.8;
/*
/*
struct gauge clock;
clock.radius = 60.0;
clock.anglemin = 0 * M_PI / 180.0;
@ -370,38 +389,44 @@ int main(int argc, char **argv)
clock.dial.g = 1.0;
clock.dial.b = 1.0;
clock.dial.a = 0.8;
*/
*/
char text[40];
//float last_fuel = 1.0;
//float consumption = 0.0;
// float last_fuel = 1.0;
// float consumption = 0.0;
double next = glfwGetTime();
double last_time = next;
struct car car;
int running = 1;
//int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
//void *(*start_routine)(void*), void *arg);
// int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
// void *(*start_routine)(void*), void *arg);
pthread_t thread;
pthread_create(&thread, NULL, &socket_run, NULL);
FTGLfont *font = ftglCreateTextureFont("arialbd.ttf");//"Arial.ttf");//"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf");
//DS_DIGII
if (!font) return 0;
FTGLfont *font = ftglCreateOutlineFont("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"); //"Arial.ttf");//"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf");
// DS_DIGII
if (!font) {
fprintf(stderr, "Unable to open font\n");
return 0;
}
ftglSetFontFaceSize(font, TEXT_SIZE, TEXT_SIZE);
ftglSetFontFaceSize(font, TEXT_SIZE, 0);
glGenTextures(1, s_symbols);
glBindTexture(GL_TEXTURE_2D, s_symbols[0]);
glfwLoadTexture2D("symbols512.tga", GLFW_BUILD_MIPMAPS_BIT);
SOIL_load_OGL_texture("symbols512.png", 0, 1, SOIL_FLAG_MIPMAPS);
// glfwLoadTexture2D("symbols512.tga", GLFW_BUILD_MIPMAPS_BIT);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, )
// Use trilinear interpolation for minification
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Use bilinear interpolation for magnification
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Enable texturing
//glEnable(GL_TEXTURE_2D);
// glEnable(GL_TEXTURE_2D);
int s1 = FX_OFF;
int s2 = FX_OFF;
@ -429,7 +454,8 @@ int main(int argc, char **argv)
float speedtimer = 0;
float zoom = 65536.0;
while (running) {
while (running)
{
double curtime = glfwGetTime();
if (curtime >= next)
@ -438,19 +464,23 @@ int main(int argc, char **argv)
float interval = curtime - last_time;
flash += interval;
if (flash >= 1) flash = 0;
if (flash >= 1)
flash = 0;
if (bing == 2)
{
binger += interval;
if (binger >= 1) {
if (binger >= 1)
{
binger = 0;
if (!g_fade) audio_play(3, FX_BING);
if (!g_fade)
audio_play(3, FX_BING);
}
}
last_time = curtime;
if (speedtimer > 0) {
if (speedtimer > 0)
{
speedtimer -= interval;
if (speedtimer <= 0)
{
@ -459,11 +489,12 @@ int main(int argc, char **argv)
}
}
if (g_pressed == 3) {
if (g_pressed == 3)
{
if (g_outgauge.time - g_shift_time > 1000 &&
g_outgauge.time - g_ctrl_time > 1000)
{
//if (g_released == 3)
// if (g_released == 3)
//{
g_pressed = 0;
g_released = 0;
@ -474,18 +505,24 @@ int main(int argc, char **argv)
}
}
if (ack == 0) {
if (mode == 1) {
if (g_pressed == 1 && volume > 0) {
if (ack == 0)
{
if (mode == 1)
{
if (g_pressed == 1 && volume > 0)
{
volume -= 10;
if (volume < 0) volume = 0;
if (volume < 0)
volume = 0;
audio_volume(volume * 0.01);
audio_play(4, FX_BOP);
ack = 1;
}
if (g_pressed == 2 && volume < 100) {
if (g_pressed == 2 && volume < 100)
{
volume += 10;
if (volume > 100) volume = 100;
if (volume > 100)
volume = 100;
audio_volume(volume * 0.01);
audio_play(4, FX_BIP);
ack = 1;
@ -527,7 +564,7 @@ int main(int argc, char **argv)
}*/
}
glfwGetWindowSize(&width, &height);
glfwGetFramebufferSize(window, &width, &height);
height = height > 0 ? height : 1;
glViewport(0, 0, width, height);
glClearColor(0.0, 0.0, 0.0, 0.0);
@ -540,7 +577,7 @@ int main(int argc, char **argv)
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
//socket_run();
// socket_run();
/* Car change */
if (*g_outgauge.car != '\0' && strcmp(g_outgauge.car, car.tag))
@ -555,7 +592,8 @@ int main(int argc, char **argv)
float speedunit = (g_outgauge.flags & OG_KM) ? 3.6 : 2.23693629;
float distunit = (g_outgauge.flags & OG_KM) ? 0.001 : 0.0006215;
if (g_outgauge.speed > maxspeed) {
if (g_outgauge.speed > maxspeed)
{
maxspeed = g_outgauge.speed;
speedtimer = 15.0f;
}
@ -572,30 +610,39 @@ int main(int argc, char **argv)
{
float gal = litres * 0.219969157;
hurr = g_outgauge.speed * speedunit / gal;
//printf("mpg %f\n", hurr);
// printf("mpg %f\n", hurr);
speed.rangemax = car.maxspeed;
speed2.rangemax = speed.rangemax * 1.609f;
}
if (hurr < 0) hurr = 0;
if (hurr > 100) hurr = 100;
if (hurr < 0)
hurr = 0;
if (hurr > 100)
hurr = 100;
if (speed.rangemax < 150) {
if (speed.rangemax < 150)
{
speed.majorstep = 10;
speed.minorstep = 2;
} else {
}
else
{
speed.majorstep = 20;
speed.minorstep = 10;
}
if (speed2.rangemax < 150) {
if (speed2.rangemax < 150)
{
speed2.majorstep = 10;
speed2.minorstep = 2;
} else {
}
else
{
speed2.majorstep = 20;
speed2.minorstep = 10;
}
float gsize = width * 0.20;
if (gsize > height * 0.4) gsize = height * 0.4;
if (gsize > height * 0.4)
gsize = height * 0.4;
speed.radius = gsize * 0.9;
speed2.radius = speed.radius * 0.6;
rpm.radius = speed.radius;
@ -612,16 +659,20 @@ int main(int argc, char **argv)
float lsize = sgsize * 0.16;
glPushMatrix();
if (rpmleft) {
if (rpmleft)
{
glTranslatef(width * 0.5 + gsize * 1.5, height - gsize, 0);
} else {
}
else
{
glTranslatef(width * 0.5 - gsize * 1.5, height - gsize, 0);
}
glColor4f(1.0, 1.0, 1.0, 1.0);
snprintf(text, sizeof text, "%d", (int)(g_outgauge.speed * speedunit));
drawText(text, font, 20, -speed.radius * 0.8, msize, msize, TA_RIGHT, TA_BOTTOM);
drawText((g_outgauge.flags & OG_KM) ? "km/h" : "mph", font, 26, -speed.radius * 0.8, msize * 0.3, msize * 0.4, TA_LEFT, TA_BOTTOM);
if (g_outgauge.dashlights & (1 << DL_PITSPEED)) {
if (g_outgauge.dashlights & (1 << DL_PITSPEED))
{
drawSymbol2(DL_PITSPEED, g_outgauge.showlights & (1 << DL_PITSPEED), 1, 0, gsize * -0.4, symsize * 1.3, symsize * 1.3);
}
if (maxspeed > 0.001f)
@ -641,31 +692,39 @@ int main(int argc, char **argv)
glPopMatrix();
glPushMatrix();
if (rpmleft) {
if (rpmleft)
{
glTranslatef(width * 0.5 - gsize * 1.5, height - gsize, 0);
} else {
}
else
{
glTranslatef(width * 0.5 + gsize * 1.5, height - gsize, 0);
}
glColor4f(1.0, 1.0, 1.0, 1.0);
snprintf(text, sizeof text, "%d", (int)(g_outgauge.rpm));
drawText(text, font, 40, -rpm.radius * 0.8, msize, msize, TA_RIGHT, TA_BOTTOM);
drawText("rpm", font, 46, -rpm.radius * 0.8, msize * 0.3, msize * 0.4, TA_LEFT, TA_BOTTOM);
if (g_outgauge.dashlights & (1 << DL_SHIFT)) {
if (g_outgauge.dashlights & (1 << DL_SHIFT))
{
drawSymbol2(DL_SHIFT, g_outgauge.showlights & (1 << DL_SHIFT), 1, 0, gsize * -0.4, symsize * 1.3, symsize * 1.3);
}
draw_gauge(&rpm, g_outgauge.rpm, car.maxrpm, font, GT_NEEDLE);
glPopMatrix();
if (g_owncar == g_outgauge.playerid) {
if (g_owncar == g_outgauge.playerid)
{
glPushMatrix();
glTranslatef(width * 0.5 - gsize * 1.5, fuel.radius * 0.75, 0);
drawSymbol2(4, 0, 0, fuel.radius * -0.65, 0, lsize, lsize);
if (g_outgauge.fuel <= warn_fuel2) {
if (flash < 0.5) {
if (g_outgauge.fuel <= warn_fuel2)
{
if (flash < 0.5)
{
drawSymbol2(19, 1, 0, -fuel.radius * 0.6, -fuel.radius * 0.3, lsize, lsize);
}
}
else if (g_outgauge.fuel <= warn_fuel1) {
else if (g_outgauge.fuel <= warn_fuel1)
{
drawSymbol2(19, 0, 0, -fuel.radius * 0.6, -fuel.radius * 0.3, lsize * 0.6, lsize * 0.6);
}
draw_gauge(&fuel, g_outgauge.fuel, -1, font, GT_BAR);
@ -677,7 +736,7 @@ int main(int argc, char **argv)
glColor4f(1.0, 1.0, 1.0, 1.0);
drawText("Trip Computer", font, 0, tcsize * 4.8, tcsize, tcsize, TA_CENTRE, TA_BOTTOM);
//snprintf(text, sizeof text, "dist %0.1f time %0.1f fuel %0.1f", s_cars[carnum].dist * distunit, s_cars[carnum].time, s_cars[carnum].cons);
// snprintf(text, sizeof text, "dist %0.1f time %0.1f fuel %0.1f", s_cars[carnum].dist * distunit, s_cars[carnum].time, s_cars[carnum].cons);
snprintf(text, sizeof text, "Rem: %0.1f%%", g_outgauge.fuel * 100);
drawText(text, font, -fuel.radius * 0.3, tcsize * 3.6, tcsize, tcsize, TA_LEFT, TA_BOTTOM);
snprintf(text, sizeof text, "Eco: %0.1f %s", hurr, (g_outgauge.flags & OG_KM) ? "l/100km" : "mpg");
@ -695,10 +754,13 @@ int main(int argc, char **argv)
if (g_outgauge.flags & OG_TURBO)
{
if (g_outgauge.flags & OG_BAR) {
if (g_outgauge.flags & OG_BAR)
{
boost.majorstep = 0.4;
boost.minorstep = 0.1;
} else {
}
else
{
boost.majorstep = 2.0;
boost.minorstep = 1.0;
}
@ -709,20 +771,20 @@ int main(int argc, char **argv)
draw_gauge(&boost, g_outgauge.turbo * mult, -1, font, GT_BAR);
}
//drawSymbol2(7, 0, 0, oil.radius * 0.65, 0, lsize, lsize);
//draw_gauge(&oil, g_outgauge.oiltemp, -1, font, GT_BAR);
// drawSymbol2(7, 0, 0, oil.radius * 0.65, 0, lsize, lsize);
// draw_gauge(&oil, g_outgauge.oiltemp, -1, font, GT_BAR);
glPopMatrix();
//glPushMatrix();
//glTranslatef(width * 0.5 + gsize * 1.5, boost.radius * 0.75, 0);
// glPushMatrix();
// glTranslatef(width * 0.5 + gsize * 1.5, boost.radius * 0.75, 0);
time_t rawtime;
time(&rawtime);
struct tm *timeinfo = localtime(&rawtime);
//draw_gauge(&clock, (timeinfo->tm_hour % 12) + timeinfo->tm_min / 60.0, -1, font, GT_NEEDLE);
//glPopMatrix();
// draw_gauge(&clock, (timeinfo->tm_hour % 12) + timeinfo->tm_min / 60.0, -1, font, GT_NEEDLE);
// glPopMatrix();
//printf("%f %f\n", g_outgauge.oilpressure, g_outgauge.oiltemp);
// printf("%f %f\n", g_outgauge.oilpressure, g_outgauge.oiltemp);
float symspace = symsize * -1.2;
@ -747,33 +809,46 @@ int main(int argc, char **argv)
if (g_outgauge.dashlights & (1 << DL_SIGNAL_ANY))
{
drawSymbol2(DL_SIGNAL_ANY, g_outgauge.showlights & (1 << DL_SIGNAL_ANY), 1, 0, 0, symsize, symsize);
} else {
if (g_outgauge.dashlights & (1 << DL_SIGNAL_L)) {
}
else
{
if (g_outgauge.dashlights & (1 << DL_SIGNAL_L))
{
drawSymbol2(DL_SIGNAL_L, g_outgauge.showlights & (1 << DL_SIGNAL_L), 1, -symsize * 0.75, 0, symsize, symsize);
}
if (g_outgauge.dashlights & (1 << DL_SIGNAL_R)) {
if (g_outgauge.dashlights & (1 << DL_SIGNAL_R))
{
drawSymbol2(DL_SIGNAL_R, g_outgauge.showlights & (1 << DL_SIGNAL_R), 1, symsize * 0.75, 0, symsize, symsize);
}
}
if (g_outgauge.dashlights & (1 << DL_FULLBEAM)) {
if (g_outgauge.dashlights & (1 << DL_FULLBEAM))
{
drawSymbol2(DL_FULLBEAM, g_outgauge.showlights & (1 << DL_FULLBEAM), 1, 0, symspace, symsize, symsize);
}
if (g_outgauge.dashlights & (1 << DL_HANDBRAKE)) {
if (g_outgauge.dashlights & (1 << DL_HANDBRAKE))
{
drawSymbol2(DL_HANDBRAKE, g_outgauge.showlights & (1 << DL_HANDBRAKE), 1, 0, symspace * 2, symsize, symsize);
}
if (g_outgauge.dashlights & (1 << DL_ABS)) {
if (g_outgauge.dashlights & (1 << DL_ABS))
{
drawSymbol2(DL_ABS, g_outgauge.showlights & (1 << DL_ABS), 1, 0, symspace * 3, symsize, symsize);
}
if (g_outgauge.dashlights & (1 << DL_TC)) {
if (g_outgauge.dashlights & (1 << DL_TC))
{
drawSymbol2(DL_TC, g_outgauge.showlights & (1 << DL_TC), 1, 0, symspace * 4, symsize, symsize);
}
if (g_outgauge.dashlights & (1 << DL_OILWARN)) {
if (g_outgauge.dashlights & (1 << DL_BATTERY)) {
if (g_outgauge.dashlights & (1 << DL_OILWARN))
{
if (g_outgauge.dashlights & (1 << DL_BATTERY))
{
drawSymbol2(DL_BATTERY, g_outgauge.showlights & (1 << DL_BATTERY), 1, -symsize * 0.75, symspace * 5, symsize, symsize);
}
drawSymbol2(DL_OILWARN, g_outgauge.showlights & (1 << DL_OILWARN), 1, symsize * 0.75, symspace * 5, symsize, symsize);
} else {
if (g_outgauge.dashlights & (1 << DL_BATTERY)) {
}
else
{
if (g_outgauge.dashlights & (1 << DL_BATTERY))
{
drawSymbol2(DL_BATTERY, g_outgauge.showlights & (1 << DL_BATTERY), 1, 0, symspace * 5, symsize, symsize);
}
}
@ -808,11 +883,16 @@ int main(int argc, char **argv)
glPushMatrix();
glColor4f(0.15, 0.15, 1.0, 1.0);
glTranslatef(width * 0.5, 0, 0.0f);
if (g_outgauge.gear == 0) {
if (g_outgauge.gear == 0)
{
snprintf(text, sizeof text, "R");
} else if (g_outgauge.gear == 1) {
}
else if (g_outgauge.gear == 1)
{
snprintf(text, sizeof text, "N");
} else {
}
else
{
snprintf(text, sizeof text, "%d", g_outgauge.gear - 1);
}
drawText(text, font, 0, sgsize * 0.7, sgsize * 0.7, sgsize * 0.7, TA_CENTRE, TA_BOTTOM);
@ -820,15 +900,15 @@ int main(int argc, char **argv)
drawText(text, font, 0, sgsize * 0.4, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_BOTTOM);
snprintf(text, sizeof text, "%s", s_conninfo[s_carinfo[g_outgauge.playerid].ucid].uname);
drawText(text, font, 0, sgsize * 0.2, sgsize * 0.15, sgsize * 0.15, TA_CENTRE, TA_BOTTOM);
//snprintf(text, sizeof text, "dist %0.1f time %0.1f fuel %0.1f", s_cars[carnum].dist * distunit, s_cars[carnum].time, s_cars[carnum].cons);
//snprintf(text, sizeof text, "p %d r %d; %d %d, %u", g_pressed, g_released, volume, mode, mode_timer);
//drawText(text, font, 0, sgsize * 1.2, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_CENTRE);
//snprintf(text, sizeof text, "s %u c %u; %u", g_shift_time, g_ctrl_time, g_outgauge.time);
//drawText(text, font, 0, sgsize * 1.5, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_CENTRE);
// snprintf(text, sizeof text, "dist %0.1f time %0.1f fuel %0.1f", s_cars[carnum].dist * distunit, s_cars[carnum].time, s_cars[carnum].cons);
// snprintf(text, sizeof text, "p %d r %d; %d %d, %u", g_pressed, g_released, volume, mode, mode_timer);
// drawText(text, font, 0, sgsize * 1.2, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_CENTRE);
// snprintf(text, sizeof text, "s %u c %u; %u", g_shift_time, g_ctrl_time, g_outgauge.time);
// drawText(text, font, 0, sgsize * 1.5, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_CENTRE);
snprintf(text, sizeof text, "%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min);
drawText(text, font, 0, sgsize * 1.3, sgsize * 0.2, sgsize * 0.2, TA_CENTRE, TA_BOTTOM);
glPopMatrix();
/*
/*
int ox = s_carinfo[g_outgauge.playerid].x;
int oy = s_carinfo[g_outgauge.playerid].y;
int oz = s_carinfo[g_outgauge.playerid].z;
@ -850,7 +930,7 @@ int main(int argc, char **argv)
//float ddy = (ci->y - oy) / 65536.0;
//ci->dist = sqrtf(ddx * ddx + ddy * ddy);
// if (ci->dist >= width / 2 && ci->dist >= height / 2) continue;
// if (ci->dist >= width / 2 && ci->dist >= height / 2) continue;
const struct conninfo *pi = s_conninfo + ci->ucid;
int idx = (ci->x - ox) >> 16;
@ -901,21 +981,29 @@ int main(int argc, char **argv)
int os3 = (g_outgauge.showlights & (1 << DL_SIGNAL_ANY)) ? FX_ON : FX_OFF;
int os6 = (g_outgauge.showlights & (1 << DL_PITSPEED)) ? FX_ON : FX_OFF;
if (s1 != os1) {
if (s1 != os1)
{
s1 = os1;
if (!g_fade) audio_play(0, s1);
if (!g_fade)
audio_play(0, s1);
}
if (s2 != os2) {
if (s2 != os2)
{
s2 = os2;
if (!g_fade) audio_play(1, s2);
if (!g_fade)
audio_play(1, s2);
}
if (s3 != os3) {
if (s3 != os3)
{
s3 = os3;
if (!g_fade) audio_play(2, s3);
if (!g_fade)
audio_play(2, s3);
}
if (s6 != os6) {
if (s6 != os6)
{
s6 = os6;
if (!g_fade) audio_play(5, s6);
if (!g_fade)
audio_play(5, s6);
}
if (g_outgauge.fuel > warn_fuel1 || g_outgauge.rpm == 0)
@ -929,18 +1017,23 @@ int main(int argc, char **argv)
else if (bing != 1 && g_outgauge.fuel <= warn_fuel1)
{
bing = 1;
if (!g_fade) audio_play(3, FX_BING);
if (!g_fade)
audio_play(3, FX_BING);
}
if (g_fade && fade < 0.8) {
if (g_fade && fade < 0.8)
{
fade = fade + 0.01;
} else if (!g_fade && fade > 0.0) {
}
else if (!g_fade && fade > 0.0)
{
fade = fade - 0.01;
}
//glPopMatrix();
// glPopMatrix();
if (dofade && fade > 0) {
if (dofade && fade > 0)
{
glColor4f(0.0, 0.0, 0.0, fade);
glBegin(GL_QUADS);
glVertex3f(0.0, 0.0, 0.0);
@ -950,22 +1043,23 @@ int main(int argc, char **argv)
glEnd();
}
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
// printf("%f\n", g_outgauge.speed * 2.23693629);
// printf("%f\n", g_outgauge.speed * 2.23693629);
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED) && !glfwGetMouseButton(1);
/*
running = !glfwGetKey(window, GLFW_KEY_ESCAPE) && !glfwWindowShouldClose(window) && !glfwGetMouseButton(window, 1);
/*
int wheel = glfwGetMouseWheel();
if (wheel >= 1) {
zoom = 65536.0 * wheel;
} else {
zoom = 65536 / (-wheel + 2);
}
*/
//printf("%u %u %u\n", g_outgauge.flags, g_outgauge.dashlights, g_outgauge.showlights);
*/
// printf("%u %u %u\n", g_outgauge.flags, g_outgauge.dashlights, g_outgauge.showlights);
usleep(100);
usleep(1000);
}
s_running = 0;
@ -991,4 +1085,3 @@ int main(int argc, char **argv)
return 0;
}

60
list.h
View File

@ -4,27 +4,27 @@
#include <stdlib.h>
#define LIST(X, T, compare_func) \
struct X ## _list_t \
{ \
struct X##_list_t \
{ \
size_t used; \
size_t size; \
T *items; \
}; \
\
static inline void X ## _list_init(struct X ## _list_t *list) \
{ \
}; \
\
static inline void X##_list_init(struct X##_list_t *list) \
{ \
list->used = 0; \
list->size = 0; \
list->items = NULL; \
} \
\
static inline void X ## _list_free(struct X ## _list_t *list) \
{ \
} \
\
static inline void X##_list_free(struct X##_list_t *list) \
{ \
free(list->items); \
} \
\
static inline void X ## _list_add(struct X ## _list_t *list, T item) \
{ \
} \
\
static inline void X##_list_add(struct X##_list_t *list, T item) \
{ \
if (list->used >= list->size) \
{ \
list->size += 64U; \
@ -38,35 +38,37 @@ static inline void X ## _list_add(struct X ## _list_t *list, T item) \
list->items = new_items; \
} \
list->items[list->used++] = item; \
} \
\
static inline void X ## _list_del_item(struct X ## _list_t *list, T item) \
{ \
} \
\
static inline void X##_list_del_item(struct X##_list_t *list, T item) \
{ \
size_t i; \
for (i = 0; i < list->used; i++) \
{ \
if (compare_func(&list->items[i], &item)) { \
if (compare_func(&list->items[i], &item)) \
{ \
list->items[i] = list->items[--list->used]; \
return; \
} \
} \
} \
\
static inline void X ## _list_del_index(struct X ## _list_t *list, size_t index) \
{ \
} \
\
static inline void X##_list_del_index(struct X##_list_t *list, size_t index) \
{ \
list->items[index] = list->items[--list->used]; \
} \
\
static inline int X ## _list_contains(struct X ## _list_t *list, T item) \
{ \
} \
\
static inline int X##_list_contains(struct X##_list_t *list, T item) \
{ \
size_t i; \
for (i = 0; i < list->used; i++) \
{ \
if (compare_func(&list->items[i], &item)) { \
if (compare_func(&list->items[i], &item)) \
{ \
return 1; \
} \
} \
return 0; \
}
}
#endif /* LIST_H */

View File

@ -14,7 +14,7 @@
#include <netinet/in.h>
#endif
#include <errno.h>
//#include "network.h"
// #include "network.h"
#include "network_worker.h"
#include "socket.h"
#include "worker.h"
@ -35,9 +35,9 @@ int resolve(const char *hostname, int port, struct sockaddr_in *addr)
struct addrinfo hints;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
#ifndef WIN32
#ifndef WIN32
hints.ai_flags = AI_ADDRCONFIG;
#endif
#endif
hints.ai_socktype = SOCK_STREAM;
char port_name[6];
@ -86,11 +86,11 @@ static void network_worker(void *arg)
int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
{
#ifdef WIN32
#ifdef WIN32
fprintf(stderr, "socket: %d\n", WSAGetLastError());
#else
#else
fprintf(stderr, "socket: %s\n", strerror(errno));
#endif
#endif
}
else
{
@ -98,19 +98,19 @@ static void network_worker(void *arg)
socket_set_nodelay(fd);
if (connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0)
{
#ifdef WIN32
#ifdef WIN32
if (WSAGetLastError() != WSAEINPROGRESS && WSAGetLastError() != WSAEWOULDBLOCK)
{
fprintf(stderr, "connect: %d\n", WSAGetLastError());
fd = -1;
}
#else
#else
if (errno != EINPROGRESS && errno != EWOULDBLOCK)
{
fprintf(stderr, "connect: %s\n", strerror(errno));
fd = -1;
}
#endif
#endif
}
}
job->callback(fd, job->data);
@ -188,7 +188,8 @@ int network_listen(int port, int tcp)
}
socket_set_nonblock(fd);
if (tcp) socket_set_nodelay(fd);
if (tcp)
socket_set_nodelay(fd);
return fd;
}

View File

@ -1,8 +1,8 @@
//#define USE_IPV6
// #define USE_IPV6
#ifdef WIN32
#include <winsock2.h>
//#include <ws2tcpip.h>
// #include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
@ -37,16 +37,19 @@ int outgauge_recv(int fd, int can_write, int can_read, void *arg)
ssize_t len = recv(fd, (char *)&o, sizeof o, 0);
/* Ignore out of order packet */
//if (o.time < s_prev_time)
// if (o.time < s_prev_time)
if (o.rpm < 0) o.rpm = 0;
if (o.rpm < 0)
o.rpm = 0;
memcpy(&g_outgauge, &o, len);
g_fade &= ~1;
g_released |= g_pressed & (~(o.flags & 3));
if (!(g_pressed & 1) && (o.flags & 1)) g_shift_time = o.time;
if (!(g_pressed & 2) && (o.flags & 2)) g_ctrl_time = o.time;
if (!(g_pressed & 1) && (o.flags & 1))
g_shift_time = o.time;
if (!(g_pressed & 2) && (o.flags & 2))
g_ctrl_time = o.time;
g_pressed |= (o.flags & 3);
if (g_owncar != o.playerid)
@ -100,6 +103,7 @@ int outgauge_recv(int fd, int can_write, int can_read, void *arg)
void outgauge_init(int port)
{
int fd = network_listen(port, 0);
if (fd < 0) return;
if (fd < 0)
return;
register_socket(fd, SM_READ, &outgauge_recv, NULL);
}

View File

@ -37,7 +37,6 @@ extern int g_released;
extern uint32_t g_shift_time;
extern uint32_t g_ctrl_time;
void outgauge_init(int port);
#endif /* OUTGAUGE_H */

View File

@ -42,7 +42,7 @@ void queue_delete(struct queue_t *queue)
struct queue_object_t *qo = queue->head;
queue->head = qo->next;
//free(qo->data);
// free(qo->data);
free(qo);
n++;
}
@ -55,7 +55,8 @@ void queue_delete(struct queue_t *queue)
int queue_produce(struct queue_t *queue, void *data)
{
if (queue == NULL) return 0;
if (queue == NULL)
return 0;
struct queue_object_t *qo = malloc(sizeof *qo);
qo->next = NULL;
@ -73,7 +74,7 @@ int queue_produce(struct queue_t *queue, void *data)
struct queue_object_t *qo = queue->head;
queue->head = qo->next;
//free(qo->data);
// free(qo->data);
free(qo);
n++;
}

View File

@ -1,5 +1,5 @@
#ifndef WIN32
//#define USE_POLL
// #define USE_POLL
#endif
#include <stdio.h>
@ -54,7 +54,8 @@ static struct socket_t *socket_get_by_fd(int fd)
for (i = 0; i < s_sockets.used; i++)
{
struct socket_t *s = s_sockets.items[i];
if (s->fd == fd) return s;
if (s->fd == fd)
return s;
}
return NULL;
@ -76,14 +77,16 @@ void register_socket(int fd, int mode, socket_func socket_func, void *arg)
if (s_epoll_fd == -1)
{
s_epoll_fd = epoll_create(32);
if (s_epoll_fd == -1) fprintf(stderr, "register_socket(): epoll_create: %s\n", strerror(errno));
if (s_epoll_fd == -1)
fprintf(stderr, "register_socket(): epoll_create: %s\n", strerror(errno));
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.ptr = s;
int r = epoll_ctl(s_epoll_fd, EPOLL_CTL_ADD, fd, &ev);
if (r == -1) fprintf(stderr, "register_socket(): epoll_ctl: %s\n", strerror(errno));
if (r == -1)
fprintf(stderr, "register_socket(): epoll_ctl: %s\n", strerror(errno));
#endif /* USE_POLL */
pthread_mutex_unlock(&s_sockets_mutex);
@ -94,9 +97,11 @@ void socket_flag_write(int fd)
#ifdef USE_POLL
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLOUT;
ev.data.ptr = socket_get_by_fd(fd);;
ev.data.ptr = socket_get_by_fd(fd);
;
int r = epoll_ctl(s_epoll_fd, EPOLL_CTL_MOD, fd, &ev);
if (r == -1) fprintf(stderr, "socket_flag_write(): epoll_ctl: %s\n", strerror(errno));
if (r == -1)
fprintf(stderr, "socket_flag_write(): epoll_ctl: %s\n", strerror(errno));
#endif /* USE_POLL */
}
@ -107,7 +112,8 @@ void socket_clear_write(int fd)
ev.events = EPOLLIN;
ev.data.ptr = socket_get_by_fd(fd);
int r = epoll_ctl(s_epoll_fd, EPOLL_CTL_MOD, fd, &ev);
if (r == -1) fprintf(stderr, "socket_clear_write(): epoll_ctl: %s\n", strerror(errno));
if (r == -1)
fprintf(stderr, "socket_clear_write(): epoll_ctl: %s\n", strerror(errno));
#endif /* USE_POLL */
}
@ -123,10 +129,10 @@ void deregister_socket(int fd)
void socket_init(void)
{
#ifdef WIN32
#ifdef WIN32
WSADATA WSA_Data;
WSAStartup (0x101, & WSA_Data);
#endif
WSAStartup(0x101, &WSA_Data);
#endif
pthread_mutex_init(&s_sockets_mutex, NULL);
}
@ -182,7 +188,8 @@ void *socket_run(void *arg)
{
struct epoll_event events[EPOLL_EVENTS];
int n = epoll_wait(s_epoll_fd, events, EPOLL_EVENTS, 10000);
if (n == -1) fprintf(stderr, "socket_run(): epoll_wait: %s\n", strerror(errno));
if (n == -1)
fprintf(stderr, "socket_run(): epoll_wait: %s\n", strerror(errno));
int i;
for (i = 0; i < n; i++)
@ -221,8 +228,10 @@ void *socket_run(void *arg)
int fd = s_sockets.items[i]->fd;
if (fd >= 0)
{
if (s_sockets.items[i]->mode & SM_READ ) FD_SET(fd, &read_fd);
if (s_sockets.items[i]->mode & SM_WRITE) FD_SET(fd, &write_fd);
if (s_sockets.items[i]->mode & SM_READ)
FD_SET(fd, &read_fd);
if (s_sockets.items[i]->mode & SM_WRITE)
FD_SET(fd, &write_fd);
}
}
@ -235,7 +244,8 @@ void *socket_run(void *arg)
fprintf(stderr, "select: %s\n", strerror(errno));
return NULL;
}
if (n == 0) continue;
if (n == 0)
continue;
for (i = 0; i < s_sockets.used; i++)
{

View File

@ -3,12 +3,13 @@
extern int s_running;
enum {
enum
{
SM_READ = 1,
SM_WRITE = 2,
};
typedef int(*socket_func)(int fd, int can_write, int can_read, void *arg);
typedef int (*socket_func)(int fd, int can_write, int can_read, void *arg);
void register_socket(int fd, int mode, socket_func socket_func, void *arg);
void deregister_socket(int fd);

BIN
symbtols512.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

26
text.c
View File

@ -1,4 +1,4 @@
#include <GL/glfw.h>
#include <GLFW/glfw3.h>
#include <FTGL/ftgl.h>
#include "text.h"
@ -12,15 +12,27 @@ void drawText(const char *text, FTGLfont *font, float x, float y, float xs, floa
float ox = 0, oy = 0;
switch (xa)
{
case TA_LEFT: ox = 0; break;
case TA_RIGHT: ox = -1; break;
case TA_CENTRE: ox = -0.5; break;
case TA_LEFT:
ox = 0;
break;
case TA_RIGHT:
ox = -1;
break;
case TA_CENTRE:
ox = -0.5;
break;
}
switch (ya)
{
case TA_TOP: oy = -1; break;
case TA_BOTTOM: oy = 0; break;
case TA_CENTRE: oy = -0.5; break;
case TA_TOP:
oy = -1;
break;
case TA_BOTTOM:
oy = 0;
break;
case TA_CENTRE:
oy = -0.5;
break;
}
glPushMatrix();

3
text.h
View File

@ -3,7 +3,8 @@
#define TEXT_SIZE 64
enum {
enum
{
TA_LEFT,
TA_RIGHT,
TA_TOP,

View File

@ -1,7 +1,7 @@
#ifndef TIMER_H
#define TIMER_H
typedef void(*timer_func_t)(void *arg);
typedef void (*timer_func_t)(void *arg);
struct timer_t;

View File

@ -1,16 +1,16 @@
#ifdef WIN32
//#include <windows.h>
// #include <windows.h>
#endif
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
//#include <sys/syscall.h>
// #include <sys/syscall.h>
#include <errno.h>
#include "queue.h"
#include "worker.h"
//#include "mcc.h"
// #include "mcc.h"
#include "gettime.h"
void *worker_thread(void *arg)
@ -19,7 +19,7 @@ void *worker_thread(void *arg)
bool timeout = false;
int jobs = 0;
//pid_t tid = (pid_t)syscall(SYS_gettid);
// pid_t tid = (pid_t)syscall(SYS_gettid);
unsigned tid = 0;
#ifndef WIN32
@ -38,7 +38,8 @@ void *worker_thread(void *arg)
if (s == -1)
{
worker->thread_timeout = true;
if (errno == ETIMEDOUT) {
if (errno == ETIMEDOUT)
{
timeout = true;
break;
}
@ -50,7 +51,8 @@ void *worker_thread(void *arg)
if (queue_consume(worker->queue, &data))
{
/* Null item added to the queue indicate we should exit. */
if (data == NULL) break;
if (data == NULL)
break;
worker->callback(data);
jobs++;
@ -129,5 +131,3 @@ void worker_queue(struct worker *worker, void *data)
fprintf(stderr, "Queue worker %s unable to queue\n", worker->name);
}
}

View File

@ -4,7 +4,7 @@
#include <pthread.h>
#include <semaphore.h>
typedef void(*worker_callback)(void *arg);
typedef void (*worker_callback)(void *arg);
struct worker
{
@ -22,6 +22,6 @@ struct worker
void worker_init(struct worker *worker, const char *name, unsigned timeout, int nice, worker_callback callback);
void worker_deinit(struct worker *worker);
void worker_queue(struct worker* worker, void *data);
void worker_queue(struct worker *worker, void *data);
#endif /* WORKER_H */