Compare commits

..

No commits in common. '9d498b0aad6e4f848bb7627585c98d04a66506ad' and '30b275518613cba423e3b7c90de50ca77305c9d5' have entirely different histories.

@ -15,25 +15,3 @@ You must clone with git lfs is, and download git lfs files in this repository. I
Open `art.blend`, go to the scripting tab and hit the play button run the script and export all the 3d assets. Then, make sure that when you build, you also build and run the codegen so that said assets and other files are copied and imported. For debug builds on windows, that's `call build_desktop_debug.bat codegen`, the codegen argument to the build script causing it to run codegen
To enable codegen error messages, change @echo off to @echo on in run_codegen.bat
# Debugging in the web
To get this working, you're going to need to follow flooh's answer linked [here](https://groups.google.com/g/emscripten-discuss/c/DEmpyGoq6kE/m/Bx44ZmfmAAAJ), and copy pasted for redundancy here:
```
It should definitely work on Vanilla Chrome, but setting everything up can be a bit finicky:
- install the Debugging extension: https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb
- in the Dev Tools settings, search for 'WebAssembly Debugging' and check that box
- compile your code with '-O0 -g' (no optimization, and debug info enabled'
- IMPORTANT: in the Chrome debugger, there's a 'Filesystem' tab on the left side which is very easy to miss. Here you need to navigate to your project directory and allow Chrome to access that area of your filesystem.
(I think/hope these are all steps)
When you load your application you should see something like this on the Dev Tools console:
[C/C++ DevTools Support (DWARF)] Loading debug symbols for http://localhost:8080/cube-sapp.wasm...
[C/C++ DevTools Support (DWARF)] Loaded debug symbols for http://localhost:8080/cube-sapp.wasm, found 91 source file(s)
...and if everything works it should look roughly like this in the debugger:
```

@ -16,21 +16,17 @@
{enum: Raphael, dialog: "What a psycho...", to: Daniel}
{can_hear: [Daniel, Raphael, Passerby]}
{enum: Passerby, dialog: "Yo?", to: Daniel}
{enum: Daniel, dialog: "Are you askin' a question", to: Passerby}
{enum: Passerby, dialog: "I guess so? What do you think of farmers?", to: Daniel}
{enum: Daniel, dialog: "I don't tolerate questions. Get out of my sight before I make you!", to: Passerby, action: ACT_aim_shotgun, action_argument: "Passerby"}
{enum: Raphael, dialog: "What's going on here?", to: Daniel}
{enum: Daniel, dialog: "THIS DAMNED FOOL DOESN'T UNDERSTAND RESPECT", to: Raphael}
{enum: Raphael, dialog: "Easy man, easy.", to: Daniel}
{enum: Daniel, dialog: "I WON'T TOLERATE IT", to: Raphael}
{enum: Passerby, dialog: "Hey man woah, just put down the gun", to: Daniel}
{enum: Daniel, dialog: "YOU BETTER MAKE ME!", to: Passerby}
{enum: Passerby, dialog: "Why do you have the gun anyways?", to: Daniel}
{enum: Daniel, dialog: "ANOTHER QUESTION??? YOU HAD THIS COMING TO YOU!", to: Passerby, action: ACT_fire_shotgun}
{enum: Raphael, dialog: "Oh God! What have you done??", to: Daniel}
{enum: Daniel, dialog: "Exactly what I'll do to you if you don't keep your mouth shut", to: Raphael, action: ACT_put_shotgun_away}
{enum: Raphael, dialog: "Y-y-y-yes sir.", to: Daniel}
{enum: Passerby, dialog: "Yo", to: Raphael}
{enum: Raphael, dialog: "What's up", to: Passerby}
{enum: Passerby, dialog: "What do you think of farmers", to: Raphael}
{enum: Raphael, dialog: "What?", to: Passerby}
{enum: Daniel, dialog: "Let me 'say somthin here. Farmers are the backbone of this town, so you'd best give them some respect", to: Passerby}
{enum: Raphael, dialog: "I mean, scientists really are what's most important", to: Daniel}
{enum: Daniel, dialog: "First of all, what the hell is a scientist? Second of all, whoever they are, if they can't eat they're worthless!", to: Raphael}
{enum: Raphael, dialog: "FIne fine whatever, no need to get heated...", to: Daniel}
{enum: Daniel, dialog: "Anyways, sorry about that. What's your name?", to: Passerby}
{enum: Passerby, dialog: "Nevermind I'll just take my leave, later.", to: Daniel}
/*
{can_hear: [WellDweller, Farmer, ManInBlack]},

@ -1,21 +1,16 @@
#pragma once
#include <stdio.h>
#include <stdbool.h>
#ifdef WEB
//#include <assert.h>
#include <signal.h>
#include <assert.h>
#endif
static void assert_impl(bool cond, const char *expression)
static inline void assert_impl(bool cond, const char *expression)
{
if(!cond)
{
fprintf(stderr, "Assertion failed: %s\n", expression);
#ifdef WEB
raise(SIGTRAP);
//assert(false);
assert(false);
#elif defined(DESKTOP)
__debugbreak();
#else
@ -28,5 +23,3 @@ static void assert_impl(bool cond, const char *expression)
#endif
#define assert(cond) assert_impl(cond, #cond)
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }

@ -1,7 +1,7 @@
call run_codegen.bat || goto :error
copy marketing_page\favicon.ico %OUTPUT_FOLDER%\favicon.ico
@REM copy main.c %OUTPUT_FOLDER%\main.c || goto :error
copy main.c %OUTPUT_FOLDER%\main.c || goto :error
@echo on
emcc ^

@ -4,7 +4,7 @@ rmdir /S /q build_web
mkdir build_web
@REM set FLAGS=-fsanitize=undefined -fsanitize=address
set FLAGS=-O0 -g -DDEVTOOLS
set FLAGS=-O0 --source-map-base http://localhost:8000/ -g3 -gdwarf -DDEVTOOLS
set OUTPUT_FOLDER=build_web

@ -5,8 +5,7 @@
// @TODO allow AI to prefix out of character statemetns with [ooc], this is a well khnown thing on role playing forums so gpt would pick up on it.
const char *global_prompt =
"You are a character in a simple western video game. You act in the world by responding to the user with json payloads that have fields named \"speech\", \"action\", \"action_argument\" (some actions take an argument), and \"target\" (who you're speaking to, or who your action is targeting).\n"
"You speak only when you have something to say, or are responding to somebody, and use short, concise, punchy language. If you're just overhearing what other people are saying, you only say something when absolutely compelled to do so.\n"
"But if somebody talks directly to you, you usually say someting."
"You speak only when you have something to say, or are responding to somebody, and use short, concise, punchy language. If you're just overhearing what other people are saying, you only say something when absolutely compelled to do so"
;
const char *top_of_header = ""

@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdbool.h>
#define DESKTOP
#include "utility.h"
#include "better_assert.h"
#include "buff.h"
@ -23,6 +23,8 @@
#pragma warning(pop)
#define Log(...) { printf("Codegen: "); printf(__VA_ARGS__); }
void dump(MD_Node* from) {
printf("/ %.*s\n", MD_S8VArg(from->string));
int d = 0;

108
main.c

@ -28,8 +28,6 @@
#define SOKOL_GLES2
#endif
#include "utility.h"
#ifdef WINDOWS
@ -134,14 +132,7 @@ void *web_arena_push(WebArena *arena, size_t amount)
}
void *to_return = arena->data + arena->pos;
arena->pos += amount;
bool arena_ok = arena->pos < arena->cap;
if(!arena_ok)
{
Log("Arena size: %lu\n", arena->cap);
Log("Arena pos: %lu\n", arena->pos);
}
assert(arena_ok);
assert(arena->pos < arena->cap);
return to_return;
}
@ -2737,13 +2728,13 @@ void create_screenspace_gfx_state()
.label = "outline-pass",
});
desc.sample_count = 1;
desc.sample_count = 0;
desc.label = "threedee-pass-render-target";
state.threedee_pass_image = sg_make_image(&desc);
desc.label = "threedee-pass-depth-render-target";
desc.pixel_format = SG_PIXELFORMAT_DEPTH;
desc.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL;
state.threedee_pass_depth_image = sg_make_image(&desc);
state.threedee_pass = sg_make_pass(&(sg_pass_desc){
@ -3300,19 +3291,21 @@ void init(void)
assert(desc);
shd = sg_make_shader(desc);
state.threedee_pip = sg_make_pipeline(&(sg_pipeline_desc){
state.threedee_pip = sg_make_pipeline(&(sg_pipeline_desc)
{
.shader = shd,
.layout = {.attrs = {
[ATTR_threedee_vs_pos_in].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_threedee_vs_uv_in].format = SG_VERTEXFORMAT_FLOAT2,
}},
.depth = {
.pixel_format = SG_PIXELFORMAT_DEPTH,
.compare = SG_COMPAREFUNC_LESS_EQUAL,
.write_enabled = true,
.write_enabled = true
},
.layout = {
.attrs =
{
[ATTR_threedee_vs_pos_in].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_threedee_vs_uv_in].format = SG_VERTEXFORMAT_FLOAT2,
}
},
.colors[0].blend = (sg_blend_state){
// allow transparency
.colors[0].blend = (sg_blend_state) { // allow transparency
.enabled = true,
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
@ -3332,7 +3325,6 @@ void init(void)
{
.shader = shd,
.depth = {
.pixel_format = SG_PIXELFORMAT_DEPTH,
.compare = SG_COMPAREFUNC_LESS_EQUAL,
.write_enabled = true
},
@ -5596,14 +5588,13 @@ void frame(void)
// draw the 3d render
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.threedee_pass_image), WHITE, .layer = LAYER_WORLD, .custom_pipeline = state.twodee_colorcorrect_pip });
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.outline_pass_image), WHITE, .custom_pipeline = state.twodee_outline_pip, .layer = LAYER_UI});
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.outline_pass_image), WHITE, .layer = LAYER_UI_FG, .custom_pipeline = state.twodee_outline_pip, .layer = LAYER_UI});
// 2d drawing TODO move this to when the drawing is flushed.
sg_begin_default_pass(&state.clear_depth_buffer_pass_action, sapp_width(), sapp_height());
sg_apply_pipeline(state.twodee_pip);
// @Place(text input drawing)
#ifdef DESKTOP
draw_quad((DrawParams){quad_at(V2(0,screen_size().y), screen_size()), IMG(image_white_square), blendalpha(BLACK, text_input_fade*0.3f), .layer = LAYER_UI_FG});
Vec2 edge_of_text = MulV2F(screen_size(), 0.5f);
if(text_input_buffer_length > 0)
@ -5613,7 +5604,6 @@ void frame(void)
}
Vec2 cursor_center = V2(edge_of_text.x,screen_size().y/2.0f);
draw_quad((DrawParams){quad_centered(cursor_center, V2(3.0f, 80.0f)), IMG(image_white_square), blendalpha(WHITE, text_input_fade * (sinf((float)elapsed_time*8.0f)/2.0f + 0.5f)), .layer = LAYER_UI_FG});
#endif
// Draw Tilemap draw tilemap tilemap drawing
#if 0
@ -6417,7 +6407,6 @@ ISANERROR("Don't know how to do this stuff on this platform.")
it->generation = gen;
}
}
ENTITIES_ITER(gs.entities)
{
if (it->perceptions_dirty && !npc_does_dialog(it))
@ -6456,6 +6445,7 @@ ISANERROR("Don't know how to do this stuff on this platform.")
#endif
#ifdef DESKTOP
// desktop http request, no more mocking
MD_ArenaTemp scratch = MD_GetScratch(0, 0);
MD_String8 ai_response = {0};
@ -6485,12 +6475,20 @@ ISANERROR("Don't know how to do this stuff on this platform.")
char *target = characters[it->memories_last->context.author_npc_kind].name;
target = characters[NPC_Player].name;
ai_response = FmtWithLint(frame_arena, "{\"target\": \"%s\", \"action\": \"%s\", \"action_argument\": \"The Player\", \"speech\": \"%s\"}", target, action, next_dialog);
#ifdef DESKTOP
it->times_talked_to += 1;
#endif
}
else
{
ai_response = MD_S8Lit("{\"target\": \"nobody\", \"action\": \"none\", \"speech\": \"\"}");
}
}
else
{
MD_String8 post_request_body = FmtWithLint(scratch.arena, "|%.*s", MD_S8VArg(prompt_str));
it->gen_request_id = make_generation_request(post_request_body);
}
// something to mock
if (ai_response.size > 0)
@ -6503,6 +6501,8 @@ ISANERROR("Don't know how to do this stuff on this platform.")
error_message = parse_chatgpt_response(scratch.arena, it, ai_response, &a);
}
if (mocking_the_ai_response)
{
assert(succeeded);
assert(error_message.size == 0);
@ -6510,17 +6510,27 @@ ISANERROR("Don't know how to do this stuff on this platform.")
assert(valid_str.size == 0);
perform_action(&gs, it, a);
}
else
{
if(succeeded)
{
if (error_message.size == 0)
{
perform_action(&gs, it, a);
}
else
{
MD_String8 post_request_body = FmtWithLint(scratch.arena, "|%.*s", MD_S8VArg(prompt_str));
it->gen_request_id = make_generation_request(post_request_body);
Log("There was an error with the AI: %.*s", MD_S8VArg(error_message));
append_to_errors(it, error_message);
}
}
}
}
MD_ReleaseScratch(scratch);
#undef SAY
#endif // desktop endif
#endif }
}
}
else
@ -6596,25 +6606,25 @@ ISANERROR("Don't know how to do this stuff on this platform.")
float speed = 0.0f;
{
if(gs.player->killed) gs.player->state = CHARACTER_KILLED;
switch(gs.player->state)
if(gs.player->killed) gs.player->state = CHARACTER_KILLED;
if(gs.player->state == CHARACTER_WALKING)
{
case CHARACTER_WALKING:
player_armature.go_to_animation = MD_S8Lit("Running");
break;
case CHARACTER_IDLE:
}
else if(gs.player->state == CHARACTER_IDLE)
{
player_armature.go_to_animation = MD_S8Lit("Idle");
break;
case CHARACTER_KILLED:
}
else if(gs.player->state == CHARACTER_KILLED)
{
player_armature.go_to_animation = MD_S8Lit("Die Backwards");
player_armature.next_animation_isnt_looping = true;
break;
}
else assert(false);
switch (gs.player->state)
if (gs.player->state == CHARACTER_WALKING)
{
case CHARACTER_WALKING:
speed = PLAYER_SPEED;
if (LenV2(movement) == 0.0)
{
@ -6623,13 +6633,17 @@ ISANERROR("Don't know how to do this stuff on this platform.")
else
{
}
break;
case CHARACTER_IDLE:
if (LenV2(movement) > 0.01)
gs.player->state = CHARACTER_WALKING;
break;
case CHARACTER_KILLED:
break;
}
else if (gs.player->state == CHARACTER_IDLE)
{
if (LenV2(movement) > 0.01) gs.player->state = CHARACTER_WALKING;
}
else if (gs.player->state == CHARACTER_KILLED)
{
}
else
{
assert(false); // unknown character state? not defined how to process
}
} // not time stopped
@ -7345,7 +7359,7 @@ sapp_desc sokol_main(int argc, char* argv[])
.frame_cb = frame,
.cleanup_cb = cleanup,
.event_cb = event,
.sample_count = 1, // bumping this back to 4 is troublesome for web, because there's a mismatch in sample counts. Perhaps we must upgrade to gles3, in doing so, we should upgrade to the newest sokol gfx.
.sample_count = 4,
.width = 800,
.height = 600,
//.gl_force_gles2 = true, not sure why this was here in example, look into

@ -2,7 +2,7 @@
#include "buff.h"
#include "HandmadeMath.h" // vector types in entity struct definition
#include "utility.h"
#include "better_assert.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h> // atoi
@ -13,6 +13,9 @@
#define DO_CHATGPT_PARSING
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }
// Never expected such a stupid stuff from such a great director. If there is 0 stari can give that or -200 to this movie. Its worst to see and unnecessary loss of money
#define PushWithLint(arena, list, ...) { MD_S8ListPushFmt(arena, list, __VA_ARGS__); if(false) printf( __VA_ARGS__); }
@ -424,25 +427,26 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
// dump a human understandable sentence description of what happened in this memory
if(it->action_taken != ACT_none)
{
switch(it->action_taken)
if(it->action_taken == ACT_join)
{
case ACT_none:
break;
case ACT_join:
AddFmt("%s joined %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
break;
case ACT_leave:
}
else if(it->action_taken == ACT_leave)
{
// Needs better handling of when you leave, because the person you were following died. Maybe entities don't die anymore?
AddFmt("%s left their party\n", characters[it->context.author_npc_kind].name);
break;
case ACT_aim_shotgun:
}
else if(it->action_taken == ACT_aim_shotgun)
{
AddFmt("%s aimed their shotgun at %s\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
break;
case ACT_fire_shotgun:
}
else if(it->action_taken == ACT_fire_shotgun)
{
AddFmt("%s fired their shotgun at %s, brutally murdering them.\n", characters[it->context.author_npc_kind].name, characters[it->action_argument.targeting].name);
break;
case ACT_put_shotgun_away:
AddFmt("%s holstered their shotgun, no longer threatening anybody\n", characters[it->context.author_npc_kind].name);
break;
}
else
{
assert(false);
}
}
if(it->speech.text_length > 0)

@ -508,7 +508,6 @@ func main() {
logResponses = os.Getenv("LOG_RESPONSES") != ""
doCors = os.Getenv("CORS") != ""
if doCors { log.Println("Doing cors"); }
c = openai.NewClient(api_key)
http.HandleFunc("/completion", completion)

@ -1,12 +0,0 @@
#include <stdlib.h>
void assert_less(int x, int y) {
if (x >= y) {
abort();
}
}
int main() {
assert_less(10, 20);
assert_less(30, 20);
}

@ -5,50 +5,6 @@
@ctype vec3 Vec3
@ctype vec2 Vec2
@block inverse_functions
// Webgl 1 doesn't have inverse() but we need it, pulled from https://github.com/glslify/glsl-inverse/blob/master/index.glsl
mat4 my_inverse(mat4 m) {
float
a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3],
a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3],
a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3],
a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3],
b00 = a00 * a11 - a01 * a10,
b01 = a00 * a12 - a02 * a10,
b02 = a00 * a13 - a03 * a10,
b03 = a01 * a12 - a02 * a11,
b04 = a01 * a13 - a03 * a11,
b05 = a02 * a13 - a03 * a12,
b06 = a20 * a31 - a21 * a30,
b07 = a20 * a32 - a22 * a30,
b08 = a20 * a33 - a23 * a30,
b09 = a21 * a32 - a22 * a31,
b10 = a21 * a33 - a23 * a31,
b11 = a22 * a33 - a23 * a32,
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
return mat4(
a11 * b11 - a12 * b10 + a13 * b09,
a02 * b10 - a01 * b11 - a03 * b09,
a31 * b05 - a32 * b04 + a33 * b03,
a22 * b04 - a21 * b05 - a23 * b03,
a12 * b08 - a10 * b11 - a13 * b07,
a00 * b11 - a02 * b08 + a03 * b07,
a32 * b02 - a30 * b05 - a33 * b01,
a20 * b05 - a22 * b02 + a23 * b01,
a10 * b10 - a11 * b08 + a13 * b06,
a01 * b08 - a00 * b10 - a03 * b06,
a30 * b04 - a31 * b02 + a33 * b00,
a21 * b02 - a20 * b04 - a23 * b00,
a11 * b07 - a10 * b09 - a12 * b06,
a00 * b09 - a01 * b07 + a02 * b06,
a31 * b01 - a30 * b03 - a32 * b00,
a20 * b03 - a21 * b01 + a22 * b00) / det;
}
@end
// for this block, define a variable called `model_space_pos` to be used as an input
@block vs_compute_light_output
@ -56,7 +12,7 @@
vec4 frag_pos = view * world_space_frag_pos;
//@Speed I think we can just take the third row here and be fine.
light_dir = normalize(my_inverse(directional_light_space_matrix) * vec4(0.0, 0.0, -1.0, 0.0)).xyz;
light_dir = normalize(inverse(directional_light_space_matrix) * vec4(0.0, 0.0, -1.0, 0.0)).xyz;
light_space_fragment_position = directional_light_space_matrix * vec4(world_space_frag_pos.xyz, 1.0);
@ -91,8 +47,6 @@ float decode_normalized_float32(vec4 v)
return sign * (v.z*255.0 + v.y);
}
@include_block inverse_functions
void main() {
vec4 total_position = vec4(0.0f);
@ -150,8 +104,6 @@ uniform vs_params {
vec3 wobble_world_source;
};
@include_block inverse_functions
void main() {
//vec3 transformed_pos = vec3(pos_in.x, pos_in.y + sin(pos_in.x * 5.0 + pos_in.y * 9.0 + time*1.9)*0.045, pos_in.z);

@ -23,8 +23,8 @@
#define BUBBLE_LINES_PER_PAGE 2
#define AI_MAX_BUBBLE_PAGES_IN_OUTPUT 2
#define ARENA_SIZE (1024*1024*20)
#define BIG_ARENA_SIZE (ARENA_SIZE * 4)
#define ARENA_SIZE (1024*1024*10)
#define BIG_ARENA_SIZE (ARENA_SIZE * 8)
#ifdef DEVTOOLS
// server url cannot have trailing slash
@ -49,7 +49,7 @@
#define MAXIMUM_THREEDEE_THINGS 1024
#define ANIMATION_BLEND_TIME 0.15f
#define REMEMBERED_MEMORIES 64
#define REMEMBERED_MEMORIES 32
#define REMEMBERED_ERRORS 6
#define MAX_AFTERIMAGES 6

@ -216,7 +216,7 @@ body {
};
window.onerror = function(event) {
console.log("onerror: " + event.message);
//for(;;) {}
for(;;) {}
};
</script>
<script type="text/javascript">
@ -367,8 +367,6 @@ function load_all() {
console.log("Reading full game");
let decoded = decode(read_data);
Module.ccall('read_from_save_data', 'void', ['array', 'number'], [new Uint8Array(decoded), decoded.byteLength]);
} else {
console.log("Couldn't find full game");
}
}
}

Loading…
Cancel
Save