use va() for events

main
Dominik Madarász 2023-08-22 13:29:47 +02:00
parent 36c7a81884
commit 3e1e170e16
12 changed files with 236 additions and 228 deletions

View File

@ -31,6 +31,7 @@ int main(int argc, char** argv) {
bool must_reload = 0;
while( window_swap()) {
if (input_down(KEY_ESC)) break;
// reloading
if( must_reload ) {
must_reload = 0;
@ -42,7 +43,7 @@ int main(int argc, char** argv) {
initialized = 1;
sky = skybox(SKY_DIRS[SKY_DIR], 0);
mdl = model(OBJ_MDLS[OBJ_MDL], 0);
rotation44(mdl.pivot, 0, 1,0,0); // @fixme: -90,1,0,0 -> should we rotate SHMs as well? compensate rotation in shader?
// rotation44(mdl.pivot, 0, 1,0,0); // @fixme: -90,1,0,0 -> should we rotate SHMs as well? compensate rotation in shader?
}
// fps camera
@ -58,20 +59,14 @@ int main(int argc, char** argv) {
// render
mat44 mvp; multiply44x2(mvp, cam.proj, cam.view);
{
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//glDisable(GL_CULL_FACE);
// mesh
glDepthMask(GL_TRUE);
glUseProgram(mdl.program);
glUniform3fv(glGetUniformLocation(mdl.program, "u_coefficients_sh"), 9, &sky.cubemap.sh[0].x);
glUniform1i(glGetUniformLocation(mdl.program, "u_textured"), false);
skybox_render(&sky, cam.proj, cam.view);
shader_bind(mdl.program);
shader_vec3v("u_coefficients_sh", 9, sky.cubemap.sh);
shader_int("u_textured", false);
model_render(mdl, cam.proj, cam.view, mdl.pivot, 0);
// sky
skybox_render(&sky, cam.proj, cam.view);
}
if( ui_panel("Scene", 0)) {

View File

@ -15,10 +15,9 @@ struct world_t {
struct npc_t npc[MAX_NPCS];
} world = {0};
char *show_notification(char *msg) {
void show_notification(char *msg) {
printf("notif %s\n", msg);
ui_notify("server", msg);
return NULL;
}
void bind_netbuffers(int64_t self_id) {
@ -39,7 +38,7 @@ void bind_netbuffers(int64_t self_id) {
// register server->client rpc
if (self_id > 0) {
network_rpc("char* show_notification(char*)", show_notification);
network_rpc("void show_notification(char*)", show_notification);
}
}

View File

@ -1174,6 +1174,9 @@ ffi.cdef([[
//lcpp INF [0000] vec3: macro name but used as C declaration in:API void shader_vec3(const char *uniform, vec3 v);
//lcpp INF [0000] vec3: macro name but used as C declaration in:STATIC void shader_vec3(const char *uniform, vec3 v);
//lcpp INF [0000] vec3: macro name but used as C declaration in: void shader_vec3(const char *uniform, vec3 v);
//lcpp INF [0000] vec3: macro name but used as C declaration in:API void shader_vec3v(const char *uniform, int count, vec3 *v);
//lcpp INF [0000] vec3: macro name but used as C declaration in:STATIC void shader_vec3v(const char *uniform, int count, vec3 *v);
//lcpp INF [0000] vec3: macro name but used as C declaration in: void shader_vec3v(const char *uniform, int count, vec3 *v);
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void shader_vec4(const char *uniform, vec4 v);
//lcpp INF [0000] vec4: macro name but used as C declaration in:STATIC void shader_vec4(const char *uniform, vec4 v);
//lcpp INF [0000] vec4: macro name but used as C declaration in: void shader_vec4(const char *uniform, vec4 v);
@ -2347,6 +2350,7 @@ int texture_width;
void shader_float(const char *uniform, float f);
void shader_vec2(const char *uniform, vec2 v);
void shader_vec3(const char *uniform, vec3 v);
void shader_vec3v(const char *uniform, int count, vec3 *v);
void shader_vec4(const char *uniform, vec4 v);
void shader_mat44(const char *uniform, mat44 m);
void shader_texture(const char *sampler, texture_t texture);

View File

@ -16472,6 +16472,7 @@ API void shader_uint(const char *uniform, unsigned i );
API void shader_float(const char *uniform, float f);
API void shader_vec2(const char *uniform, vec2 v);
API void shader_vec3(const char *uniform, vec3 v);
API void shader_vec3v(const char *uniform, int count, vec3 *v);
API void shader_vec4(const char *uniform, vec4 v);
API void shader_mat44(const char *uniform, mat44 m);
API void shader_texture(const char *sampler, texture_t texture);
@ -338905,13 +338906,13 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_CONNECT:;
msg = stringf( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
msg = va( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
/* Store any relevant client information here. */
event.peer->data = STRDUP(ip); /* TEMP */
/* ensure we have free slot for client */
if (map_count(clients) >= network_get(NETWORK_CAPACITY)-1) {
msg = stringf("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
msg = va("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
enet_peer_disconnect_now(event.peer, 1);
break;
}
@ -338943,7 +338944,7 @@ char** server_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:;
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -339008,12 +339009,12 @@ char** server_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -339024,7 +339025,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -339033,7 +339034,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
server_drop_client_peer(event.peer);
@ -339041,7 +339042,7 @@ char** server_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);
@ -339068,7 +339069,7 @@ char** client_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -339118,12 +339119,12 @@ char** client_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -339134,7 +339135,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -339143,7 +339144,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
network_put(NETWORK_RANK, -1);
@ -339151,7 +339152,7 @@ char** client_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);
@ -339462,56 +339463,55 @@ const char *const fs_32_4_model = "//" FILELINE "\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
" return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
" vec3 n = /*normalize*/(v_normal);\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
" // SH lighting\n"
" vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
" vec3 SHLightResult[9];\n"
" SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
" SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
" SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
" SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
" SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
" SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
" SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
" SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
" SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
" vec3 result = vec3(0.0);\n"
" for (int i = 0; i < 9; ++i)\n"
" result += SHLightResult[i];\n"
" \n"
" if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" // base\n"
" vec4 diffuse;\n"
" if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" \n"
" }\n";
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
"}\n"
"\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
@ -340110,6 +340110,7 @@ void shader_int(const char *uniform, int i) { glUniform1i(shader_uniform(uni
void shader_float(const char *uniform, float f) { glUniform1f(shader_uniform(uniform), f); }
void shader_vec2(const char *uniform, vec2 v) { glUniform2fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }

View File

@ -19,53 +19,51 @@ in vec4 vpeye;
in vec4 vneye;
in vec4 sc;
vec4 shadowing() {
return shadowmap(vpeye, vneye, v_texcoord, sc);
return shadowmap(vpeye, vneye, v_texcoord, sc);
}
void main() {
vec3 n = /*normalize*/(v_normal);
vec3 n = /*normalize*/(v_normal);
// SH lighting
vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);
vec3 SHLightResult[9];
SHLightResult[0] = 0.282095f * u_coefficients_sh[0];
SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;
SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;
SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;
SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;
SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;
SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);
SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;
SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);
vec3 result = vec3(0.0);
for (int i = 0; i < 9; ++i)
result += SHLightResult[i];
if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);
// SH lighting
vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);
vec3 SHLightResult[9];
SHLightResult[0] = 0.282095f * u_coefficients_sh[0];
SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;
SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;
SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;
SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;
SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;
SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);
SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;
SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);
vec3 result = vec3(0.0);
for (int i = 0; i < 9; ++i)
result += SHLightResult[i];
if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);
// base
vec4 diffuse;
if(u_matcaps) {
vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space
diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));
// base
vec4 diffuse;
if(u_matcaps) {
vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space
diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));
} else if(u_textured) {
diffuse = texture(u_texture2d, v_texcoord);
} else {
diffuse = u_diffuse; // * v_color;
}
} else {
diffuse = u_diffuse; // * v_color;
}
// lighting mix
fragcolor = diffuse * lit * shadowing();
// rimlight
#ifdef RIM
{vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space
vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space
vec3 v = normalize(-p); // eye vector
float rim = 1.0 - max(dot(v, n), 0.0); // rimlight
rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)
fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue
#endif
}
// lighting mix
fragcolor = diffuse * lit * shadowing();
// rimlight
#ifdef RIM
{vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space
vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space
vec3 v = normalize(-p); // eye vector
float rim = 1.0 - max(dot(v, n), 0.0); // rimlight
rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)
fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue
#endif
}

View File

@ -442,13 +442,13 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_CONNECT:;
msg = stringf( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
msg = va( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
/* Store any relevant client information here. */
event.peer->data = STRDUP(ip); /* TEMP */
/* ensure we have free slot for client */
if (map_count(clients) >= network_get(NETWORK_CAPACITY)-1) {
msg = stringf("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
msg = va("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
enet_peer_disconnect_now(event.peer, 1);
break;
}
@ -480,7 +480,7 @@ char** server_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:;
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -545,12 +545,12 @@ char** server_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -561,7 +561,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -570,7 +570,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
server_drop_client_peer(event.peer);
@ -578,7 +578,7 @@ char** server_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);
@ -605,7 +605,7 @@ char** client_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -655,12 +655,12 @@ char** client_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -671,7 +671,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -680,7 +680,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
network_put(NETWORK_RANK, -1);
@ -688,7 +688,7 @@ char** client_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);

View File

@ -213,6 +213,7 @@ void shader_int(const char *uniform, int i) { glUniform1i(shader_uniform(uni
void shader_float(const char *uniform, float f) { glUniform1f(shader_uniform(uniform), f); }
void shader_vec2(const char *uniform, vec2 v) { glUniform2fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }

View File

@ -317,6 +317,7 @@ API void shader_uint(const char *uniform, unsigned i );
API void shader_float(const char *uniform, float f);
API void shader_vec2(const char *uniform, vec2 v);
API void shader_vec3(const char *uniform, vec3 v);
API void shader_vec3v(const char *uniform, int count, vec3 *v);
API void shader_vec4(const char *uniform, vec4 v);
API void shader_mat44(const char *uniform, mat44 m);
API void shader_texture(const char *sampler, texture_t texture);

View File

@ -265,56 +265,55 @@ const char *const fs_32_4_model = "//" FILELINE "\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
" return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
" vec3 n = /*normalize*/(v_normal);\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
" // SH lighting\n"
" vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
" vec3 SHLightResult[9];\n"
" SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
" SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
" SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
" SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
" SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
" SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
" SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
" SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
" SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
" vec3 result = vec3(0.0);\n"
" for (int i = 0; i < 9; ++i)\n"
" result += SHLightResult[i];\n"
" \n"
" if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" // base\n"
" vec4 diffuse;\n"
" if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" \n"
" }\n";
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
"}\n"
"\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"

View File

@ -9919,13 +9919,13 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_CONNECT:;
msg = stringf( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
msg = va( "%d %s", 0, va("A new client connected from ::%s:%u", ip, event.peer->address.port ));
/* Store any relevant client information here. */
event.peer->data = STRDUP(ip); /* TEMP */
/* ensure we have free slot for client */
if (map_count(clients) >= network_get(NETWORK_CAPACITY)-1) {
msg = stringf("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
msg = va("%d %s", 1, va("%s", "Server is at maximum capacity, disconnecting the peer (::%s:%u)...", ip, event.peer->address.port));
enet_peer_disconnect_now(event.peer, 1);
break;
}
@ -9957,7 +9957,7 @@ char** server_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:;
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -10022,12 +10022,12 @@ char** server_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -10038,7 +10038,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -10047,7 +10047,7 @@ char** server_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
server_drop_client_peer(event.peer);
@ -10055,7 +10055,7 @@ char** server_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);
@ -10082,7 +10082,7 @@ char** client_poll(unsigned timeout_ms) {
case ENET_EVENT_TYPE_RECEIVE:
/*
msg = stringf( "A packet of length %u containing %s was received from %s on channel %u",
msg = va( "A packet of length %u containing %s was received from %s on channel %u",
(unsigned)event.packet->dataLength,
event.packet->data,
(char *)event.peer->data,
@ -10132,12 +10132,12 @@ char** client_poll(unsigned timeout_ms) {
memcpy(&resp_msg[4], resp, strlen(resp)+1);
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
msg = va("%d %s", 0, va("req:%s res:%s", cmdline, resp));
FREE(resp_msg);
} break;
case MSG_RPC_RESP: {
event.type = NETWORK_EVENT_RPC_RESP;
msg = stringf("%d %s", 0, va("%s", ptr));
msg = va("%d %s", 0, va("%s", ptr));
} break;
default:
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
@ -10148,7 +10148,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT:
msg = stringf( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s disconnected", (char *)event.peer->data));
/* Reset the peer's client information. */
FREE(event.peer->data);
event.peer->data = NULL;
@ -10157,7 +10157,7 @@ char** client_poll(unsigned timeout_ms) {
break;
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
msg = stringf( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
msg = va( "%d %s", 0, va("%s timeout", (char *)event.peer->data));
FREE(event.peer->data);
event.peer->data = NULL;
network_put(NETWORK_RANK, -1);
@ -10165,7 +10165,7 @@ char** client_poll(unsigned timeout_ms) {
break;
}
if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg));
if(msg) array_push(events, va("%d %s", enet_event_to_netsync(event.type), msg));
}
array_push(events, NULL);
@ -10476,56 +10476,55 @@ const char *const fs_32_4_model = "//" FILELINE "\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
" return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
" vec3 n = /*normalize*/(v_normal);\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
" // SH lighting\n"
" vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
" vec3 SHLightResult[9];\n"
" SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
" SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
" SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
" SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
" SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
" SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
" SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
" SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
" SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
" vec3 result = vec3(0.0);\n"
" for (int i = 0; i < 9; ++i)\n"
" result += SHLightResult[i];\n"
" \n"
" if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" // base\n"
" vec4 diffuse;\n"
" if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" \n"
" }\n";
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
"}\n"
"\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
@ -11124,6 +11123,7 @@ void shader_int(const char *uniform, int i) { glUniform1i(shader_uniform(uni
void shader_float(const char *uniform, float f) { glUniform1f(shader_uniform(uniform), f); }
void shader_vec2(const char *uniform, vec2 v) { glUniform2fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3(const char *uniform, vec3 v) { glUniform3fv(shader_uniform(uniform), 1, &v.x); }
void shader_vec3v(const char *uniform, int count, vec3 *v) { glUniform3fv(shader_uniform(uniform), count, &v[0].x); }
void shader_vec4(const char *uniform, vec4 v) { glUniform4fv(shader_uniform(uniform), 1, &v.x); }
void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_uniform(uniform), 1, GL_FALSE/*GL_TRUE*/, m); }
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }

View File

@ -2555,6 +2555,7 @@ API void shader_uint(const char *uniform, unsigned i );
API void shader_float(const char *uniform, float f);
API void shader_vec2(const char *uniform, vec2 v);
API void shader_vec3(const char *uniform, vec3 v);
API void shader_vec3v(const char *uniform, int count, vec3 *v);
API void shader_vec4(const char *uniform, vec4 v);
API void shader_mat44(const char *uniform, mat44 m);
API void shader_texture(const char *sampler, texture_t texture);

File diff suppressed because one or more lines are too long