Compare commits
32 Commits
0efd1fca91
...
dcdeaf4cc1
@ -1,12 +1,17 @@
|
||||
*.spall # profiling
|
||||
*.bin # world files
|
||||
debug_world.bin
|
||||
flight*.zip
|
||||
flight_server
|
||||
flight.zip
|
||||
ipsettings.h
|
||||
|
||||
releases/
|
||||
.vs/
|
||||
x64/
|
||||
*.exe
|
||||
*.obj
|
||||
*.pdb
|
||||
*.exp
|
||||
*.lib
|
||||
*.ilk
|
||||
*.gen.h
|
||||
|
@ -1,23 +1,3 @@
|
||||
@echo off
|
||||
|
||||
@REM what all the compile flags mean: https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
||||
|
||||
WHERE sokol-shdc.exe
|
||||
IF %ERRORLEVEL% NEQ 0 ECHO ERROR download sokol-shdc from https://github.com/floooh/sokol-tools-bin/blob/master/bin/win32/sokol-shdc.exe and put it in this folder
|
||||
|
||||
@REM example of how to compile shaders: sokol-shdc.exe --input triangle.glsl --output triangle.gen.h --slang glsl330:hlsl5:metal_macos
|
||||
|
||||
setlocal enabledelayedexpansion enableextensions
|
||||
pushd thirdparty\Chipmunk2D\src
|
||||
set MUNKSRC=
|
||||
for %%x in (*.c) do set MUNKSRC=!MUNKSRC! thirdparty\Chipmunk2D\src\%%x
|
||||
popd
|
||||
|
||||
@REM /DENET_DEBUG=1^
|
||||
cl /MP /Zi /FS /Fd"flight.pdb" /Fe"flight"^
|
||||
/I"thirdparty" /I"thirdparty\minilzo" /I"thirdparty\enet\include" /I"thirdparty\Chipmunk2D\include\chipmunk" /I"thirdparty\Chipmunk2D\include"^
|
||||
/DSERVER_ADDRESS="\"127.0.0.1\""^
|
||||
main.c gamestate.c server.c debugdraw.c^
|
||||
thirdparty\minilzo\minilzo.c^
|
||||
thirdparty\enet\callbacks.c thirdparty\enet\compress.c thirdparty\enet\host.c thirdparty\enet\list.c thirdparty\enet\packet.c thirdparty\enet\peer.c thirdparty\enet\protocol.c thirdparty\enet\win32.c Ws2_32.lib winmm.lib^
|
||||
%MUNKSRC%
|
||||
call shadergen.bat
|
||||
set compileopts=/Fe"flight_debug" /Zi /FS /Fd"flight.pdb" /DSERVER_ADDRESS="\"127.0.0.1\"" /DDEBUG_RENDERING
|
||||
call build_msvc.bat
|
@ -1,3 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
gcc -o flight_server -Wall -O2 -Ithirdparty -Ithirdparty/enet/include -Ithirdparty/minilzo -Ithirdparty/Chipmunk2D/include -Ithirdparty/Chipmunk2D/include/chipmunk server_main.c server.c debugdraw.c gamestate.c sokol_impl.c thirdparty/minilzo/minilzo.c thirdparty/enet/*.c thirdparty/Chipmunk2D/src/*.c -lm -lpthread
|
||||
mkdir thirdparty/opus/build
|
||||
cd thirdparty/opus/build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
cd -
|
||||
|
||||
gcc -o flight_server -Wall -O2 -Ithirdparty -Ithirdparty/opus/include -Ithirdparty/enet/include -Ithirdparty/minilzo -Ithirdparty/Chipmunk2D/include -Ithirdparty/Chipmunk2D/include/chipmunk server_main.c server.c debugdraw.c gamestate.c sokol_impl.c thirdparty/minilzo/minilzo.c thirdparty/enet/*.c thirdparty/Chipmunk2D/src/*.c -lm -lpthread -ldl thirdparty/opus/build/libopus.a
|
||||
|
@ -0,0 +1,25 @@
|
||||
@echo off
|
||||
|
||||
@REM what all the compile flags mean: https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
||||
|
||||
|
||||
set OPUSLIB=%~dp0\thirdparty\opus\win32\VS2015\x64\Release\opus.lib
|
||||
|
||||
WHERE %OPUSLIB%
|
||||
IF %ERRORLEVEL% NEQ 0 ECHO ERROR Couldn't find %OPUSLIB% compile opus by opening the visual studio project in win32\VS2015 and building the release setting
|
||||
|
||||
setlocal enabledelayedexpansion enableextensions
|
||||
pushd thirdparty\Chipmunk2D\src
|
||||
set MUNKSRC=
|
||||
for %%x in (*.c) do set MUNKSRC=!MUNKSRC! thirdparty\Chipmunk2D\src\%%x
|
||||
popd
|
||||
|
||||
@REM /DENET_DEBUG=1^
|
||||
cl /MP^
|
||||
%compileopts%^
|
||||
/I"thirdparty" /I"thirdparty\minilzo" /I"thirdparty\enet\include" /I"thirdparty\Chipmunk2D\include\chipmunk" /I"thirdparty\Chipmunk2D\include" /I"thirdparty\opus\include" /I"thirdparty\opus\src"^
|
||||
main.c gamestate.c server.c debugdraw.c^
|
||||
thirdparty\minilzo\minilzo.c^
|
||||
thirdparty\enet\callbacks.c thirdparty\enet\compress.c thirdparty\enet\host.c thirdparty\enet\list.c thirdparty\enet\packet.c thirdparty\enet\peer.c thirdparty\enet\protocol.c thirdparty\enet\win32.c Ws2_32.lib winmm.lib^
|
||||
%MUNKSRC%^
|
||||
%OPUSLIB%
|
@ -0,0 +1,2 @@
|
||||
set compileopts=/Fe"flight_release" /O2
|
||||
call build_msvc.bat
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,53 @@
|
||||
@module hueshift
|
||||
|
||||
@vs vs
|
||||
in vec4 coord;
|
||||
out vec2 texUV;
|
||||
void main() {
|
||||
gl_Position = vec4(coord.xy, 0.0, 1.0);
|
||||
texUV = coord.zw;
|
||||
}
|
||||
@end
|
||||
|
||||
@fs fs
|
||||
uniform sampler2D iChannel0;
|
||||
uniform uniforms {
|
||||
int is_colorless; // if greater than zero, no color
|
||||
float target_hue;
|
||||
};
|
||||
in vec2 texUV;
|
||||
out vec4 fragColor;
|
||||
|
||||
vec3 rgb2hsv(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 hsv2rgb(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 outColor = texture(iChannel0, texUV);
|
||||
vec3 hsv = rgb2hsv(outColor.rgb);
|
||||
|
||||
if(is_colorless > 0)
|
||||
{
|
||||
hsv.y = 0.0f;
|
||||
} else if(hsv.y > 0.5) {
|
||||
hsv.x = target_hue;
|
||||
}
|
||||
fragColor = vec4(hsv2rgb(hsv), outColor.a);
|
||||
}
|
||||
@end
|
||||
|
||||
@program program vs fs
|
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,3 @@
|
||||
call build_release.bat
|
||||
call update_server.bat
|
||||
tar.exe -a -c -f releases\flight-nonumber.zip flight_release.exe loaded
|
Binary file not shown.
@ -1,10 +1,32 @@
|
||||
#include "types.h"
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "miniaudio.h"
|
||||
|
||||
#define SOKOL_IMPL
|
||||
#include "sokol_time.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
ServerThreadInfo server_info = {
|
||||
.world_save = "world.bin",
|
||||
};
|
||||
|
||||
void term(int signum)
|
||||
{
|
||||
server_info.should_quit = true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
server(0);
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(struct sigaction));
|
||||
action.sa_handler = term;
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
|
||||
stm_setup();
|
||||
ma_mutex_init(&server_info.info_mutex);
|
||||
server(&server_info);
|
||||
ma_mutex_uninit(&server_info.info_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
|
||||
WHERE sokol-shdc.exe
|
||||
IF %ERRORLEVEL% NEQ 0 ECHO ERROR download sokol-shdc from https://github.com/floooh/sokol-tools-bin/blob/master/bin/win32/sokol-shdc.exe and put it in this folder
|
||||
|
||||
@REM example of how to compile shaders: sokol-shdc.exe --input triangle.glsl --output triangle.gen.h --slang glsl330:hlsl5:metal_macos
|
||||
sokol-shdc.exe --format sokol --input hueshift.glsl --output hueshift.gen.h --slang glsl330:hlsl5:metal_macos
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
Subproject commit bce1f392353d72d77d543bb2069a044ae1045e9d
|
@ -0,0 +1,429 @@
|
||||
// SPDX-FileCopyrightText: © 2022 Phillip Trudeau-Tavara <pmttavara@protonmail.com>
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
/*
|
||||
|
||||
TODO: Core API:
|
||||
|
||||
- Completely contextless; you pass in params to begin()/end(), get a packed begin/end struct
|
||||
- Simple, handmade, user has full control and full responsibility
|
||||
|
||||
TODO: Optional Helper APIs:
|
||||
|
||||
- Buffered-writing API
|
||||
- Caller allocates and stores a buffer for multiple events
|
||||
- begin()/end() writes chunks to the buffer
|
||||
- Function invokes a callback when the buffer is full and needs flushing
|
||||
- Can a callback be avoided? The function indicates when the buffer must be flushed?
|
||||
|
||||
- Compression API: would require a mutexed lockable context (yuck...)
|
||||
- Either using a ZIP library, a name cache + TIDPID cache, or both (but ZIP is likely more than enough!!!)
|
||||
- begin()/end() writes compressed chunks to a caller-determined destination
|
||||
- The destination can be the buffered-writing API or a custom user destination
|
||||
- Ultimately need to take a lock with some granularity... can that be the caller's responsibility?
|
||||
|
||||
- fopen()/fwrite() API: requires a context (no mutex needed, since fwrite() takes a lock)
|
||||
- begin()/end() writes chunks to a FILE*
|
||||
- before writing them to disk, the chunks can optionally be sent through the compression API
|
||||
- is this opt-in or opt-out?
|
||||
- the write to disk can optionally use the buffered writing API
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SPALL_H
|
||||
#define SPALL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SPALL_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct SpallHeader {
|
||||
uint64_t magic_header; // = 0x0BADF00D
|
||||
uint64_t version; // = 1
|
||||
double timestamp_unit;
|
||||
uint64_t must_be_0;
|
||||
} SpallHeader;
|
||||
|
||||
enum {
|
||||
SpallEventType_Invalid = 0,
|
||||
SpallEventType_Custom_Data = 1, // Basic readers can skip this.
|
||||
SpallEventType_StreamOver = 2,
|
||||
|
||||
SpallEventType_Begin = 3,
|
||||
SpallEventType_End = 4,
|
||||
SpallEventType_Instant = 5,
|
||||
|
||||
SpallEventType_Overwrite_Timestamp = 6, // Retroactively change timestamp units - useful for incrementally improving RDTSC frequency.
|
||||
};
|
||||
|
||||
typedef struct SpallBeginEvent {
|
||||
uint8_t type; // = SpallEventType_Begin
|
||||
uint8_t category;
|
||||
|
||||
uint32_t pid;
|
||||
uint32_t tid;
|
||||
double when;
|
||||
|
||||
uint8_t name_length;
|
||||
uint8_t args_length;
|
||||
|
||||
// char name[1];
|
||||
// char args[1];
|
||||
} SpallBeginEvent;
|
||||
|
||||
typedef struct SpallBeginEventMax {
|
||||
SpallBeginEvent event;
|
||||
char name_bytes[255];
|
||||
char args_bytes[255];
|
||||
} SpallBeginEventMax;
|
||||
|
||||
typedef struct SpallEndEvent {
|
||||
uint8_t type; // = SpallEventType_End
|
||||
uint32_t pid;
|
||||
uint32_t tid;
|
||||
double when;
|
||||
} SpallEndEvent;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct SpallProfile {
|
||||
double timestamp_unit;
|
||||
bool (*write)(struct SpallProfile *self, const void *data, size_t length);
|
||||
bool (*flush)(struct SpallProfile *self);
|
||||
void (*close)(struct SpallProfile *self);
|
||||
union {
|
||||
FILE *file;
|
||||
void *userdata;
|
||||
};
|
||||
} SpallProfile;
|
||||
|
||||
// Important!: If you are writing Begin/End events, then do NOT write
|
||||
// events for the same PID + TID pair on different buffers!!!
|
||||
typedef struct SpallBuffer {
|
||||
void *data;
|
||||
size_t length;
|
||||
|
||||
// Internal data - don't assign this
|
||||
size_t head;
|
||||
SpallProfile *ctx;
|
||||
} SpallBuffer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Profile context
|
||||
SpallProfile SpallInit (const char *filename, double timestamp_unit);
|
||||
void SpallQuit (SpallProfile *ctx);
|
||||
|
||||
bool SpallFlush(SpallProfile *ctx);
|
||||
|
||||
// Buffer API
|
||||
extern SpallBuffer SpallSingleThreadedBuffer;
|
||||
|
||||
bool SpallBufferInit (SpallProfile *ctx, SpallBuffer *wb);
|
||||
bool SpallBufferQuit (SpallProfile *ctx, SpallBuffer *wb);
|
||||
|
||||
bool SpallBufferFlush(SpallProfile *ctx, SpallBuffer *wb);
|
||||
|
||||
// Begin events
|
||||
bool SpallTraceBeginLen (SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, double when);
|
||||
bool SpallTraceBeginLenTid (SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, uint32_t tid, double when);
|
||||
bool SpallTraceBeginLenTidPid(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, uint32_t tid, uint32_t pid, double when);
|
||||
|
||||
// End events
|
||||
bool SpallTraceEnd (SpallProfile *ctx, SpallBuffer *wb, double when);
|
||||
bool SpallTraceEndTid (SpallProfile *ctx, SpallBuffer *wb, uint32_t tid, double when);
|
||||
bool SpallTraceEndTidPid(SpallProfile *ctx, SpallBuffer *wb, uint32_t tid, uint32_t pid, double when);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SPALL_H
|
||||
|
||||
#ifdef SPALL_IMPLEMENTATION
|
||||
#ifndef SPALL_IMPLEMENTED
|
||||
#define SPALL_IMPLEMENTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(SPALL_BUFFER_PROFILING) && !defined(SPALL_BUFFER_PROFILING_GET_TIME)
|
||||
#error "You must #define SPALL_BUFFER_PROFILING_GET_TIME() to profile buffer flushes."
|
||||
#endif
|
||||
|
||||
#ifdef SPALL_BUFFER_PROFILING
|
||||
static void Spall__BufferProfile(SpallProfile *ctx, SpallBuffer *wb, double spall_time_begin, double spall_time_end, const char *name, int name_len) {
|
||||
// precon: ctx
|
||||
// precon: ctx->write
|
||||
char temp_buffer_data[2048];
|
||||
SpallBuffer temp_buffer = { temp_buffer_data, sizeof(temp_buffer_data) };
|
||||
if (!SpallTraceBeginLenTidPid(ctx, &temp_buffer, name, sizeof(name) - 1, (uint32_t)(uintptr_t)wb->data, 4222222222, spall_time_begin)) return;
|
||||
if (!SpallTraceEndTidPid(ctx, &temp_buffer, (uint32_t)(uintptr_t)wb->data, 4222222222, spall_time_end)) return;
|
||||
if (ctx->write) ctx->write(ctx, temp_buffer_data, temp_buffer.head);
|
||||
}
|
||||
#define SPALL_BUFFER_PROFILE_BEGIN() double spall_time_begin = (SPALL_BUFFER_PROFILING_GET_TIME())
|
||||
// Don't call this with anything other than a string literal
|
||||
#define SPALL_BUFFER_PROFILE_END(name) Spall__BufferProfile(ctx, wb, spall_time_begin, (SPALL_BUFFER_PROFILING_GET_TIME()), "" name "", sizeof("" name "") - 1)
|
||||
#else
|
||||
#define SPALL_BUFFER_PROFILE_BEGIN()
|
||||
#define SPALL_BUFFER_PROFILE_END(name)
|
||||
#endif
|
||||
|
||||
extern char SpallSingleThreadedBufferData[];
|
||||
char SpallSingleThreadedBufferData[1 << 16];
|
||||
SpallBuffer SpallSingleThreadedBuffer = {SpallSingleThreadedBufferData, sizeof(SpallSingleThreadedBufferData)};
|
||||
|
||||
static bool Spall__FileWrite(SpallProfile *ctx, const void *p, size_t n) {
|
||||
if (!ctx->file) return false;
|
||||
#ifdef SPALL_DEBUG
|
||||
if (feof(ctx->file)) return false;
|
||||
if (ferror(ctx->file)) return false;
|
||||
#endif
|
||||
|
||||
if (fwrite(p, n, 1, ctx->file) != 1) return false;
|
||||
return true;
|
||||
}
|
||||
static bool Spall__FileFlush(SpallProfile *ctx) {
|
||||
if (!ctx->file) return false;
|
||||
if (fflush(ctx->file)) return false;
|
||||
return true;
|
||||
}
|
||||
static void Spall__FileClose(SpallProfile *ctx) {
|
||||
if (!ctx->file) return;
|
||||
|
||||
#ifdef SPALL_JSON
|
||||
#ifdef SPALL_DEBUG
|
||||
if (!feof(ctx->file) && !ferror(ctx->file))
|
||||
#endif
|
||||
{
|
||||
fseek(ctx->file, -2, SEEK_CUR); // seek back to overwrite trailing comma
|
||||
fwrite("\n]}\n", sizeof("\n]}\n") - 1, 1, ctx->file);
|
||||
}
|
||||
#endif
|
||||
fflush(ctx->file);
|
||||
fclose(ctx->file);
|
||||
ctx->file = NULL;
|
||||
}
|
||||
|
||||
static bool Spall__BufferFlush(SpallProfile *ctx, SpallBuffer *wb) {
|
||||
// precon: wb
|
||||
// precon: wb->data
|
||||
// precon: wb->head <= wb->length
|
||||
// precon: !ctx || ctx->write
|
||||
#ifdef SPALL_DEBUG
|
||||
if (wb->ctx != ctx) return false; // Buffer must be bound to this context (or to NULL)
|
||||
#endif
|
||||
|
||||
if (wb->head && ctx) {
|
||||
SPALL_BUFFER_PROFILE_BEGIN();
|
||||
if (!ctx->write || !ctx->write(ctx, wb->data, wb->head)) return false;
|
||||
SPALL_BUFFER_PROFILE_END("Buffer Flush");
|
||||
}
|
||||
wb->head = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool Spall__BufferWrite(SpallProfile *ctx, SpallBuffer *wb, void *p, size_t n) {
|
||||
// precon: !wb || wb->head < wb->length
|
||||
// precon: !ctx || ctx->write
|
||||
if (!wb) return ctx->write && ctx->write(ctx, p, n);
|
||||
#ifdef SPALL_DEBUG
|
||||
if (wb->ctx != ctx) return false; // Buffer must be bound to this context (or to NULL)
|
||||
#endif
|
||||
if (wb->head + n > wb->length && !Spall__BufferFlush(ctx, wb)) return false;
|
||||
if (n > wb->length) {
|
||||
SPALL_BUFFER_PROFILE_BEGIN();
|
||||
if (!ctx->write || !ctx->write(ctx, p, n)) return false;
|
||||
SPALL_BUFFER_PROFILE_END("Unbuffered Write");
|
||||
return true;
|
||||
}
|
||||
memcpy((char *)wb->data + wb->head, p, n);
|
||||
wb->head += n;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallBufferFlush(SpallProfile *ctx, SpallBuffer *wb) {
|
||||
#ifdef SPALL_DEBUG
|
||||
if (!wb) return false;
|
||||
if (!wb->data) return false;
|
||||
#endif
|
||||
|
||||
if (!Spall__BufferFlush(ctx, wb)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallBufferInit(SpallProfile *ctx, SpallBuffer *wb) {
|
||||
if (!SpallBufferFlush(NULL, wb)) return false;
|
||||
wb->ctx = ctx;
|
||||
return true;
|
||||
}
|
||||
bool SpallBufferQuit(SpallProfile *ctx, SpallBuffer *wb) {
|
||||
if (!SpallBufferFlush(ctx, wb)) return false;
|
||||
wb->ctx = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallBufferAbort(SpallBuffer *wb) {
|
||||
if (!wb) return false;
|
||||
wb->ctx = NULL;
|
||||
if (!Spall__BufferFlush(NULL, wb)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static SpallProfile Spall__Init(const char *filename, double timestamp_unit) {
|
||||
SpallProfile ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
if (timestamp_unit < 0) return ctx;
|
||||
if (!filename) return ctx;
|
||||
ctx.file = fopen(filename, "wb"); // TODO: handle utf8 and long paths on windows
|
||||
ctx.write = Spall__FileWrite;
|
||||
ctx.flush = Spall__FileFlush;
|
||||
ctx.close = Spall__FileClose;
|
||||
if (!ctx.file) { SpallQuit(&ctx); return ctx; }
|
||||
ctx.timestamp_unit = timestamp_unit;
|
||||
|
||||
#ifdef SPALL_JSON
|
||||
if (!ctx.write(&ctx, "{\"traceEvents\":[\n", sizeof("{\"traceEvents\":[\n") - 1)) { SpallQuit(&ctx); return ctx; }
|
||||
#else
|
||||
SpallHeader header;
|
||||
header.magic_header = 0x0BADF00D;
|
||||
header.version = 1;
|
||||
header.timestamp_unit = timestamp_unit;
|
||||
header.must_be_0 = 0;
|
||||
if (!ctx.write(&ctx, &header, sizeof(header))) { SpallQuit(&ctx); return ctx; }
|
||||
#endif
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
SpallProfile SpallInit (const char *filename, double timestamp_unit) { return Spall__Init(filename, timestamp_unit); }
|
||||
|
||||
void SpallQuit(SpallProfile *ctx) {
|
||||
if (!ctx) return;
|
||||
if (ctx->close) ctx->close(ctx);
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
bool SpallFlush(SpallProfile *ctx) {
|
||||
#ifdef SPALL_DEBUG
|
||||
if (!ctx) return false;
|
||||
if (!ctx->file) return false;
|
||||
#endif
|
||||
|
||||
if (!ctx->flush || !ctx->flush(ctx)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallTraceBeginLenArgsTidPid(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, const char *args, signed long args_len, uint32_t tid, uint32_t pid, double when) {
|
||||
SpallBeginEventMax ev;
|
||||
|
||||
#ifdef SPALL_DEBUG
|
||||
if (!ctx) return false;
|
||||
if (!name) return false;
|
||||
if (!ctx->file) return false;
|
||||
if (name_len <= 0) return false;
|
||||
#endif
|
||||
name_len = SPALL_MIN(name_len, 255); // will be interpreted as truncated in the app (?)
|
||||
args_len = SPALL_MIN(args_len, 255); // will be interpreted as truncated in the app (?)
|
||||
char *args_bytes = ev.name_bytes + name_len;
|
||||
|
||||
ev.event.type = SpallEventType_Begin;
|
||||
ev.event.category = 0;
|
||||
ev.event.pid = pid;
|
||||
ev.event.tid = tid;
|
||||
ev.event.when = when;
|
||||
ev.event.name_length = (uint8_t)name_len;
|
||||
ev.event.args_length = (uint8_t)args_len;
|
||||
memcpy(ev.name_bytes, name, (uint8_t)name_len);
|
||||
memcpy(args_bytes, args, (uint8_t)args_len);
|
||||
|
||||
#ifdef SPALL_JSON
|
||||
char buf[1024];
|
||||
int buf_len = snprintf(buf, sizeof(buf),
|
||||
"{\"args\":\"%.*s\",\"name\":\"%.*s\",\"ph\":\"B\",\"pid\":%u,\"tid\":%u,\"ts\":%f},\n",
|
||||
(int)ev.event.args_length, args_bytes,
|
||||
(int)ev.event.name_length, ev.name_bytes,
|
||||
ev.event.pid,
|
||||
ev.event.tid,
|
||||
ev.event.when * ctx->timestamp_unit);
|
||||
if (buf_len <= 0) return false;
|
||||
if (buf_len >= sizeof(buf)) return false;
|
||||
if (!Spall__BufferWrite(ctx, wb, buf, buf_len)) return false;
|
||||
#else
|
||||
if (!Spall__BufferWrite(ctx, wb, &ev, sizeof(SpallBeginEvent) + (uint8_t)name_len + (uint8_t)args_len)) return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallTraceBeginLenTidPid(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, uint32_t tid, uint32_t pid, double when) { return SpallTraceBeginLenArgsTidPid(ctx, wb, name, name_len, "", 0, tid, 0, when); }
|
||||
bool SpallTraceBeginLenTid(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, uint32_t tid, double when) { return SpallTraceBeginLenArgsTidPid(ctx, wb, name, name_len, "", 0, tid, 0, when); }
|
||||
bool SpallTraceBeginLen (SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, double when) { return SpallTraceBeginLenArgsTidPid(ctx, wb, name, name_len, "", 0, 0, 0, when); }
|
||||
|
||||
bool SpallTraceEndTidPid(SpallProfile *ctx, SpallBuffer *wb, uint32_t tid, uint32_t pid, double when) {
|
||||
SpallEndEvent ev;
|
||||
|
||||
#ifdef SPALL_DEBUG
|
||||
if (!ctx) return false;
|
||||
if (!ctx->file) return false;
|
||||
#endif
|
||||
|
||||
ev.type = SpallEventType_End;
|
||||
ev.pid = pid;
|
||||
ev.tid = tid;
|
||||
ev.when = when;
|
||||
|
||||
#ifdef SPALL_JSON
|
||||
char buf[512];
|
||||
int buf_len = snprintf(buf, sizeof(buf),
|
||||
"{\"ph\":\"E\",\"pid\":%u,\"tid\":%u,\"ts\":%f},\n",
|
||||
ev.pid,
|
||||
ev.tid,
|
||||
ev.when * ctx->timestamp_unit);
|
||||
if (buf_len <= 0) return false;
|
||||
if (buf_len >= sizeof(buf)) return false;
|
||||
if (!Spall__BufferWrite(ctx, wb, buf, buf_len)) return false;
|
||||
#else
|
||||
if (!Spall__BufferWrite(ctx, wb, &ev, sizeof(ev))) return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpallTraceEndTid(SpallProfile *ctx, SpallBuffer *wb, uint32_t tid, double when) { return SpallTraceEndTidPid(ctx, wb, tid, 0, when); }
|
||||
bool SpallTraceEnd (SpallProfile *ctx, SpallBuffer *wb, double when) { return SpallTraceEndTidPid(ctx, wb, 0, 0, when); }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SPALL_IMPLEMENTED
|
||||
#endif // SPALL_IMPLEMENTATION
|
||||
|
||||
/*
|
||||
Zero-Clause BSD (0BSD)
|
||||
|
||||
Copyright (c) 2022, Phillip Trudeau-Tavara
|
||||
All rights reserved.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
@ -0,0 +1 @@
|
||||
ssh astris "cd flight; git pull; ./linux_server_install.sh"
|
Loading…
Reference in New Issue