Substantially improve multi character conversation:

- NPCs signal when they want to end the convo, preventing infinite convo loops
- New character parameter that controls how likely they are to be silent. Good for tuning personality
main
parent e49852ba67
commit 75e6e84972

@ -7,13 +7,14 @@
{enum: Raphael, dialog: "Yeah man, what's up with you?", to: Devil}
{enum: Devil, dialog: "Nunya!", to: Raphael}
{enum: Raphael, dialog: "What does 'Nunya' mean? A wild critter you are...", to: Devil}
{enum: Daniel, dialog: "YOU ASKED FOR IT! TAKE THIS!", action: ACT_fire_shotgun, to: Devil}
{enum: Daniel, dialog: "YOU ASKED FOR IT! TAKE THIS!", action: ACT_fire_shotgun, to: Devil, action_argument: "The Devil"}
{enum: Devil, dialog: "Cute! You think your little toys can harm me!", to: Daniel}
{enum: Daniel, dialog: "What the hell??", to: Devil}
{enum: Raphael, dialog: "I don't think we can harm him like that", to: Daniel}
{enum: Daniel, dialog: "You're right, I guess we just gotta 'tolerate this feller's presence.", to: Raphael}
{enum: Devil, dialog: "I'll take my leave. Until next time!", to: Daniel}
{enum: Raphael, dialog: "What a psycho...", to: Daniel}
{enum: Raphael, dialog: "What a psycho...", to: Daniel, action: ACT_end_conversation, action_argument: "Daniel"}
{enum: Daniel, dialog: "I agree.", to: Raphael, action: ACT_end_conversation, action_argument: "Raphael"}
{can_hear: [Daniel, Raphael, Passerby]}
{enum: Passerby, dialog: "Yo?", to: Daniel}
@ -22,7 +23,7 @@
{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: Raphael, dialog: "Easy man, easy. I ain't much for helpin' folk but you're outta control.", 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}
@ -30,7 +31,14 @@
{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: Raphael, dialog: "Y-y-y-yes sir.", to: Daniel, action: ACT_end_conversation, action_argument: "Daniel"}
{enum: Daniel, dialog: "Now leave me be", to: Raphael, action: ACT_end_conversation, action_argument: "Raphael"}
{can_hear: [Daniel, Raphael]}
{enum: Raphael, dialog: "Say Daniel, why do you get so worked up all the time?", to: Daniel}
{enum: Daniel, dialog: "I'm not gonna talk about it", to: Raphael}
{enum: Raphael, dialog: "Suit yourself partner, but I reckon you've got issues to work through", to: Daniel}
{enum: Daniel, dialog: "Enough! I'm angry sometimes and that's that.", to: Raphael, action: ACT_end_conversation, action_argument: "Raphael"}
{can_hear: [Devil, Angel]}
{enum: Devil, dialog: "You will fall!", to: Angel}

@ -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.\n"
"You speak using short, concise, punchy language. Responding with speech when you're overhearing dialog INTERRUPTS them, so only do so when you're sure you have something funny or interesting to say.\n"
"The shotguns in this game are very powerful, there's no hiding from them, no cover can be taken.\n"
;
@ -34,6 +33,11 @@ ActionInfo actions[] = {
.description = "There has been an error, please report to the developer. No NPCs should be able to do this",
ARGUMENT("Expects the argument to be who you're approaching"),
},
{
.name = "end_conversation",
.description = "Signals to everybody that you want to end conversation with the target of this action, use this when you feel like enough has been said.",
ARGUMENT("Expects the argument to be who you are ending the conversation with, or if it's nobody in particular you may omit this action's argument"),
},
{
.name = "join",
.description = "Joins somebody else's party, so you follow them everywhere",
@ -73,6 +77,7 @@ typedef struct
char *name;
char *enum_name;
char *prompt;
float silence_factor; // 1.0 - maximum likelihood to respond with silence and not interact, 0.0 - minimum likelihood. So at 0 they will interrupt conversations often.
} CharacterGen;
CharacterGen characters[] = {
#define CHARACTER_PROMPT_PREFIX(name) "You, " name ", specifically are acting as a "
@ -89,12 +94,14 @@ CharacterGen characters[] = {
{
.name = "Daniel",
.enum_name = "Daniel",
.prompt = CHARACTER_PROMPT_PREFIX("Daniel") "weathered farmer, who lives a tough, solitary life. You don't see much of a reason to keep living but soldier on anyways. You have a tragic backstory, and mostly just work on the farm. You aim your shotgun and aren't afraid to fire at people you don't like. You HATE people who are confused, or who ask questions, immediately aiming your shotgun at them.",
.prompt = CHARACTER_PROMPT_PREFIX("Daniel") "weathered farmer, who lives a tough, solitary life. You don't see much of a reason to keep living but soldier on anyways. You have a tragic backstory, and mostly just work on the farm. You aim your shotgun and aren't afraid to fire at people you don't like. You HATE people who are confused, or who ask questions, immediately aiming your shotgun at them and firing immediately! You are NOT open to working together with folks or growing as a person, you despise personal growth.",
.silence_factor = 1.0f,
},
{
.name = "Raphael",
.enum_name = "Raphael",
.prompt = CHARACTER_PROMPT_PREFIX("Raphael") "physicist from the 1980s who got their doctorate in subatomic particle physics. They don't know why they're in a western town, but they're terrified.",
.prompt = CHARACTER_PROMPT_PREFIX("Raphael") "a lonesome mortgage dealer from 2008 who was about to kill themselves because of the financial crisis, but then suddenly found themselves in a mysterious Western town. They don't know why they're in this town, but they're terrified.",
.silence_factor = 0.5f,
},
{
.name = "The Devil",
@ -110,5 +117,6 @@ CharacterGen characters[] = {
.name = "Angel",
.enum_name = "Angel",
.prompt = CHARACTER_PROMPT_PREFIX("Angel") "mysterious, radiant, mystical creature the player first talks to. You guide the entire game: deciding on an objective for the player to fulfill until you believe they've learned their lesson, whatever that means to them.",
.silence_factor = 0.0,
},
};

@ -38,6 +38,7 @@
#include "utility.h"
#ifdef WINDOWS
@ -316,6 +317,7 @@ typedef struct Quad
#include "character_info.h"
#include "characters.gen.h"
#define RND_IMPLEMENTATION
#include "makeprompt.h"
typedef BUFF(Entity*, 16) Overlapping;
@ -1643,9 +1645,23 @@ void push_memory(GameState *gs, Entity *e, Memory new_memory)
for(Memory *cur = e->memories_first; cur; cur = cur->next) count += 1;
while(count >= REMEMBERED_MEMORIES)
{
Memory *freed = e->memories_first;
MD_DblRemove(e->memories_first, e->memories_last, freed);
MD_StackPush(memories_free_list, freed);
Memory *to_remove = e->memories_first;
assert(to_remove->context.drama_memory);
while(true)
{
if(!to_remove->context.drama_memory)
{
break;
}
if(to_remove->next == 0)
{
Log("Error: the drama memories for the character %s are bigger than the maximum number of remembered memories %d, so they can't be permanently remembered\n", characters[e->npc_kind].name, REMEMBERED_MEMORIES);
assert(false);
}
to_remove = to_remove->next;
}
MD_DblRemove(e->memories_first, e->memories_last, to_remove);
MD_StackPush(memories_free_list, to_remove);
count -= 1;
}
if(gs->stopped_time)
@ -2125,6 +2141,7 @@ Vec2 point_plane(Vec3 p)
void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *level)
{
memset(gs, 0, sizeof(GameState));
rnd_gamerand_seed(&gs->random, RANDOM_SEED);
Room *in_room = get_cur_room(level);
@ -2153,7 +2170,7 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
it->target_rotation = it->rotation;
}
// @Place(parse and enact the drama document)
// @Place(parse and enact the drama document parse drama)
if(1)
{
MD_String8List drama_errors = {0};
@ -2175,6 +2192,8 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
BUFF(NpcKind, 128) not_on_map = {0};
if(drama_errors.node_count == 0)
{
// used
MD_Node *can_hear = MD_NilNode();
for(MD_Node *cur = parse.node->first_child->first_child; !MD_NodeIsNil(cur) && drama_errors.node_count == 0; cur = cur->next)
{
@ -2199,7 +2218,7 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
Action current_action = {0};
MemoryContext current_context = {0};
current_context.dont_show_to_player = true;
current_context.drama_memory = true;
if(drama_errors.node_count == 0)
{
MD_String8 enum_str = expect_childnode(scratch.arena, cur, MD_S8Lit("enum"), &drama_errors)->first_child->string;
@ -2243,6 +2262,7 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
}
}
if(drama_errors.node_count == 0)
{
for(MD_Node *cur_kind_node = can_hear; !MD_NodeIsNil(cur_kind_node); cur_kind_node = cur_kind_node->next)
@ -2265,10 +2285,14 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
{
// it's good for NPC health that they have examples of not saying anything in response to others speaking,
// so that they do the same when it's unlikely for them to talk.
if(g_randf(gs) < characters[it->npc_kind].silence_factor)
{
Action no_speak = {0};
MemoryContext no_speak_context = {.i_said_this = true, .author_npc_kind = it->npc_kind};
remember_action(gs, it, no_speak, no_speak_context);
}
}
it->undismissed_action = false; // prevent the animating in sound effects of words said in drama document
@ -2294,6 +2318,24 @@ void initialize_gamestate_from_threedee_level(GameState *gs, ThreeDeeLevel *leve
//Log("Propagated to %d name '%s'...\n", want, characters[want].name);
}
}
// if ended conversation, make the target of the end of conversation action output silence
if(drama_errors.node_count == 0)
{
// I use FmtWithLint and the actions[] array here so it's a compile error if we ever remove this action or rename it, instead of just directly putting the string
if(current_action.kind == ACT_end_conversation)
{
ENTITIES_ITER(gs->entities)
{
if(it->is_npc && it->npc_kind == current_action.argument.targeting)
{
Action no_speak = {0};
MemoryContext no_speak_context = {.i_said_this = true, .author_npc_kind = it->npc_kind};
remember_action(gs, it, no_speak, no_speak_context);
}
}
}
}
}
}
}
@ -3224,6 +3266,7 @@ MD_String8 make_devtools_help(MD_Arena *arena)
P("7 - toggles the visibility of devtools debug drawing and debug text\n");
P("F - toggles flycam\n");
P("Q - if you're hovering over somebody, pressing this will print to the console a detailed overview of their state\n");
P("T - toggles freezing the mouse\n");
P("9 - instantly wins the game\n");
P("P - toggles spall profiling on/off, don't leave on for very long as it consumes a lot of storage if you do that. The resulting spall trace is saved to the file '%s'\n", PROFILING_SAVE_FILENAME);
@ -6948,8 +6991,9 @@ ISANERROR("Don't know how to do this stuff on this platform.")
{
static float visible = 0.0f;
float target = 0.0f;
if(gs.player->killed && !cur_unread_entity)
if(gs.player->killed && (!cur_unread_entity || gs.finished_reading_dying_dialog))
{
gs.finished_reading_dying_dialog = true;
target = 1.0f;
}
visible = Lerp(visible, unwarped_dt*4.0f, target);
@ -7044,15 +7088,21 @@ ISANERROR("Don't know how to do this stuff on this platform.")
if(keypressed[SAPP_KEYCODE_Q] && !receiving_text_input)
{
Log("-- Printing debug memories for %s --\n", characters[to_view->npc_kind].name);
Log("\n\n==========------- Printing debugging information for %s -------==========\n", characters[to_view->npc_kind].name);
Log("\nMemories-----------------------------\n");
int mem_idx = 0;
for(Memory *cur = to_view->memories_first; cur; cur = cur->next)
{
MD_String8 to_text = cur->context.talking_to_kind != NPC_nobody ? MD_S8Fmt(frame_arena, " to %s ", characters[cur->context.talking_to_kind].name) : MD_S8Lit("");
MD_String8 text = MD_S8Fmt(frame_arena, "%s%s%.*s: %.*s", to_view->npc_kind == cur->context.author_npc_kind ? "(Me) " : "", characters[cur->context.author_npc_kind].name, MD_S8VArg(to_text), cur->speech.text_length, cur->speech);
MD_String8 speech = TextChunkString8(cur->speech);
if(speech.size == 0) speech = MD_S8Lit("<said nothing>");
MD_String8 text = MD_S8Fmt(frame_arena, "%s%s%.*s: %.*s", to_view->npc_kind == cur->context.author_npc_kind ? "(Me) " : "", characters[cur->context.author_npc_kind].name, MD_S8VArg(to_text), MD_S8VArg(speech));
printf("Memory %d: %.*s\n", mem_idx, MD_S8VArg(text));
mem_idx++;
}
Log("\nPrompt-----------------------------\n");
MD_String8 prompt = generate_chatgpt_prompt(frame_arena, &gs, to_view, get_can_talk_to(to_view));
printf("%.*s\n", MD_S8VArg(prompt));
}
}
}

@ -8,6 +8,7 @@
#include <stdlib.h> // atoi
#include "character_info.h"
#include "characters.gen.h"
#include "rnd.h"
#include "tuning.h"
@ -120,7 +121,7 @@ typedef struct
NpcKind author_npc_kind;
NpcKind talking_to_kind;
bool heard_physically; // if not physically, the source was directly
bool dont_show_to_player; // jester and past memories are hidden to the player when made into dialog
bool drama_memory; // drama memories arent forgotten, and once they end it's understood that a lot of time has passed.
} MemoryContext;
// memories are subjective to an individual NPC
@ -273,6 +274,7 @@ typedef struct GameState {
uint64_t tick;
bool won;
bool finished_reading_dying_dialog;
bool no_angel_screen;
// processing may still occur after time has stopped on the gamestate,
@ -282,10 +284,16 @@ typedef struct GameState {
Entity *player;
Entity *world_entity;
Entity entities[MAX_ENTITIES];
rnd_gamerand_t random;
} GameState;
#define ENTITIES_ITER(ents) for (Entity *it = ents; it < ents + ARRLEN(ents); it++) if (it->exists && !it->destroy && it->generation > 0)
float g_randf(GameState *gs)
{
return rnd_gamerand_nextf(&gs->random);
}
Entity *gete_specified(GameState *gs, EntityRef ref)
{
if (ref.generation == 0) return 0;
@ -417,6 +425,8 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
}
MD_String8List current_list = {0};
bool in_drama_memories = true;
assert(e->memories_first->context.drama_memory);
for(Memory *it = e->memories_first; it; it = it->next)
{
// going through memories, I'm going to accumulate human understandable sentences for what happened in current_list.
@ -425,7 +435,13 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
// write a new human understandable sentence or two to current_list
if (!it->context.i_said_this) {
if(in_drama_memories && !it->context.drama_memory)
{
in_drama_memories = false;
AddFmt("Some time passed...\n");
}
// dump a human understandable sentence description of what happened in this memory
bool no_longer_wants_to_converse = false; // add the no longer wants to converse text after any speech, it makes more sense reading it
if(it->action_taken != ACT_none)
{
switch(it->action_taken)
@ -451,7 +467,9 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
case ACT_approach:
AddFmt("%.*s approached %.*s\n", HUMAN(it->context.author_npc_kind), HUMAN(it->action_argument.targeting));
break;
#undef HUMAN
case ACT_end_conversation:
no_longer_wants_to_converse = true;
break;
}
}
if(it->speech.text_length > 0)
@ -473,6 +491,19 @@ MD_String8 generate_chatgpt_prompt(MD_Arena *arena, GameState *gs, Entity *e, Ca
AddFmt("%.*s%s said \"%.*s\" to %.*s (you are %s)\n", MD_S8VArg(speaking_to_you_helper), characters[it->context.author_npc_kind].name, TextChunkVArg(it->speech), MD_S8VArg(target_string), characters[e->npc_kind].name);
}
if(no_longer_wants_to_converse)
{
if (it->action_argument.targeting == NPC_nobody)
{
AddFmt("%.*s no longer wants to converse with everybody\n", HUMAN(it->context.author_npc_kind));
}
else
{
AddFmt("%.*s no longer wants to converse with %.*s\n", HUMAN(it->context.author_npc_kind), HUMAN(it->action_argument.targeting));
}
}
#undef HUMAN
}
// if I said this, or it's the last memory, flush the current list as a user node
@ -613,7 +644,7 @@ MD_String8 parse_chatgpt_response(MD_Arena *arena, Entity *e, MD_String8 action_
if(actions[out->kind].takes_argument)
{
// @TODO refactor into, action argument kinds and they parse into different action argument types
bool arg_is_character = out->kind == ACT_join || out->kind == ACT_aim_shotgun;
bool arg_is_character = out->kind == ACT_join || out->kind == ACT_aim_shotgun || out->kind == ACT_end_conversation;
if(arg_is_character)
{

584
thirdparty/rnd.h vendored

@ -0,0 +1,584 @@
/*
------------------------------------------------------------------------------
Licensing information can be found at the end of the file.
------------------------------------------------------------------------------
rnd.h - v1.0 - Pseudo-random number generators for C/C++.
Do this:
#define RND_IMPLEMENTATION
before you include this file in *one* C/C++ file to create the implementation.
*/
#ifndef rnd_h
#define rnd_h
#ifndef RND_U32
#define RND_U32 unsigned int
#endif
#ifndef RND_U64
#define RND_U64 unsigned long long
#endif
typedef struct rnd_pcg_t { RND_U64 state[ 2 ]; } rnd_pcg_t;
void rnd_pcg_seed( rnd_pcg_t* pcg, RND_U32 seed );
RND_U32 rnd_pcg_next( rnd_pcg_t* pcg );
float rnd_pcg_nextf( rnd_pcg_t* pcg );
int rnd_pcg_range( rnd_pcg_t* pcg, int min, int max );
typedef struct rnd_well_t { RND_U32 state[ 17 ]; } rnd_well_t;
void rnd_well_seed( rnd_well_t* well, RND_U32 seed );
RND_U32 rnd_well_next( rnd_well_t* well );
float rnd_well_nextf( rnd_well_t* well );
int rnd_well_range( rnd_well_t* well, int min, int max );
typedef struct rnd_gamerand_t { RND_U32 state[ 2 ]; } rnd_gamerand_t;
void rnd_gamerand_seed( rnd_gamerand_t* gamerand, RND_U32 seed );
RND_U32 rnd_gamerand_next( rnd_gamerand_t* gamerand );
float rnd_gamerand_nextf( rnd_gamerand_t* gamerand );
int rnd_gamerand_range( rnd_gamerand_t* gamerand, int min, int max );
typedef struct rnd_xorshift_t { RND_U64 state[ 2 ]; } rnd_xorshift_t;
void rnd_xorshift_seed( rnd_xorshift_t* xorshift, RND_U64 seed );
RND_U64 rnd_xorshift_next( rnd_xorshift_t* xorshift );
float rnd_xorshift_nextf( rnd_xorshift_t* xorshift );
int rnd_xorshift_range( rnd_xorshift_t* xorshift, int min, int max );
#endif /* rnd_h */
/**
rnd.h
=====
Pseudo-random number generators for C/C++.
Example
-------
A basic example showing how to use the PCG set of random functions.
#define RND_IMPLEMENTATION
#include "rnd.h"
#include <stdio.h> // for printf
#include <time.h> // for time
int main( int argc, char** argv ) {
rnd_pcg_t pcg;
rnd_pcg_seed( &pcg, 0u ); // initialize generator
// print a handful of random integers
// these will be the same on every run, as we
// seeded the rng with a fixed value
for( int i = 0; i < 5; ++i ) {
RND_U32 n = rnd_pcg_next( &pcg );
printf( "%08x, ", n );
}
printf( "\n" );
// reseed with a value which is different on each run
time_t seconds;
time( &seconds );
rnd_pcg_seed( &pcg, (RND_U32) seconds );
// print another handful of random integers
// these will be different on every run
for( int i = 0; i < 5; ++i ) {
RND_U32 n = rnd_pcg_next( &pcg );
printf( "%08x, ", n );
}
printf( "\n" );
// print a handful of random floats
for( int i = 0; i < 5; ++i ) {
float f = rnd_pcg_nextf( &pcg );
printf( "%f, ", f );
}
printf( "\n" );
// print random integers in the range 1 to 6
for( int i = 0; i < 15; ++i ) {
int r = rnd_pcg_range( &pcg, 1, 6 );
printf( "%d, ", r );
}
printf( "\n" );
return 0;
}
API Documentation
-----------------
rnd.h is a single-header library, and does not need any .lib files or other binaries, or any build scripts. To use it,
you just include rnd.h to get the API declarations. To get the definitions, you must include rnd.h from *one* single C
or C++ file, and #define the symbol `RND_IMPLEMENTATION` before you do.
The library is meant for general-purpose use, such as games and similar apps. It is not meant to be used for
cryptography and similar use cases.
### Customization
rnd.h allows for specifying the exact type of 32 and 64 bit unsigned integers to be used in its API. By default, these
default to `unsigned int` and `unsigned long long`, but can be redefined by #defining RND_U32 and RND_U64 respectively
before including rnd.h. This is useful if you, for example, use the types from `<stdint.h>` in the rest of your program,
and you want rnd.h to use compatible types. In this case, you would include rnd.h using the following code:
#define RND_U32 uint32_t
#define RND_U64 uint64_t
#include "rnd.h"
Note that when customizing the data type, you need to use the same definition in every place where you include rnd.h,
as it affect the declarations as well as the definitions.
### The generators
The library includes four different generators: PCG, WELL, GameRand and XorShift. They all have different
characteristics, and you might want to use them for different things. GameRand is very fast, but does not give a great
distribution or period length. XorShift is the only one returning a 64-bit value. WELL is an improvement of the often
used Mersenne Twister, and has quite a large internal state. PCG is small, fast and has a small state. If you don't
have any specific reason, you may default to using PCG.
All generators expose their internal state, so it is possible to save this state and later restore it, to resume the
random sequence from the same point.
#### PCG - Permuted Congruential Generator
PCG is a family of simple fast space-efficient statistically good algorithms for random number generation. Unlike many
general-purpose RNGs, they are also hard to predict.
More information can be found here:
http://www.pcg-random.org/
#### WELL - Well Equidistributed Long-period Linear
Random number generation, using the WELL algorithm by F. Panneton, P. L'Ecuyer and M. Matsumoto.
More information in the original paper:
http://www.iro.umontreal.ca/~panneton/WELLRNG.html
This code is originally based on WELL512 C/C++ code written by Chris Lomont (published in Game Programming Gems 7)
and placed in the public domain.
http://lomont.org/Math/Papers/2008/Lomont_PRNG_2008.pdf
#### GameRand
Based on the random number generator by Ian C. Bullard:
http://www.redditmirror.cc/cache/websites/mjolnirstudios.com_7yjlc/mjolnirstudios.com/IanBullard/files/79ffbca75a75720f066d491e9ea935a0-10.html
GameRand is a random number generator based off an "Image of the Day" posted by Stephan Schaem. More information here:
http://www.flipcode.com/archives/07-15-2002.shtml
#### XorShift
A random number generator of the type LFSR (linear feedback shift registers). This specific implementation uses the
XorShift+ variation, and returns 64-bit random numbers.
More information can be found here:
https://en.wikipedia.org/wiki/Xorshift
rnd_pcg_seed
------------
void rnd_pcg_seed( rnd_pcg_t* pcg, RND_U32 seed )
Initialize a PCG generator with the specified seed. The generator is not valid until it's been seeded.
rnd_pcg_next
------------
RND_U32 rnd_pcg_next( rnd_pcg_t* pcg )
Returns a random number N in the range: 0 <= N <= 0xffffffff, from the specified PCG generator.
rnd_pcg_nextf
-------------
float rnd_pcg_nextf( rnd_pcg_t* pcg )
Returns a random float X in the range: 0.0f <= X < 1.0f, from the specified PCG generator.
rnd_pcg_range
-------------
int rnd_pcg_range( rnd_pcg_t* pcg, int min, int max )
Returns a random integer N in the range: min <= N <= max, from the specified PCG generator.
rnd_well_seed
-------------
void rnd_well_seed( rnd_well_t* well, RND_U32 seed )
Initialize a WELL generator with the specified seed. The generator is not valid until it's been seeded.
rnd_well_next
-------------
RND_U32 rnd_well_next( rnd_well_t* well )
Returns a random number N in the range: 0 <= N <= 0xffffffff, from the specified WELL generator.
rnd_well_nextf
--------------
float rnd_well_nextf( rnd_well_t* well )
Returns a random float X in the range: 0.0f <= X < 1.0f, from the specified WELL generator.
rnd_well_range
--------------
int rnd_well_range( rnd_well_t* well, int min, int max )
Returns a random integer N in the range: min <= N <= max, from the specified WELL generator.
rnd_gamerand_seed
-----------------
void rnd_gamerand_seed( rnd_gamerand_t* gamerand, RND_U32 seed )
Initialize a GameRand generator with the specified seed. The generator is not valid until it's been seeded.
rnd_gamerand_next
-----------------
RND_U32 rnd_gamerand_next( rnd_gamerand_t* gamerand )
Returns a random number N in the range: 0 <= N <= 0xffffffff, from the specified GameRand generator.
rnd_gamerand_nextf
------------------
float rnd_gamerand_nextf( rnd_gamerand_t* gamerand )
Returns a random float X in the range: 0.0f <= X < 1.0f, from the specified GameRand generator.
rnd_gamerand_range
------------------
int rnd_gamerand_range( rnd_gamerand_t* gamerand, int min, int max )
Returns a random integer N in the range: min <= N <= max, from the specified GameRand generator.
rnd_xorshift_seed
-----------------
void rnd_xorshift_seed( rnd_xorshift_t* xorshift, RND_U64 seed )
Initialize a XorShift generator with the specified seed. The generator is not valid until it's been seeded.
rnd_xorshift_next
-----------------
RND_U64 rnd_xorshift_next( rnd_xorshift_t* xorshift )
Returns a random number N in the range: 0 <= N <= 0xffffffffffffffff, from the specified XorShift generator.
rnd_xorshift_nextf
------------------
float rnd_xorshift_nextf( rnd_xorshift_t* xorshift )
Returns a random float X in the range: 0.0f <= X < 1.0f, from the specified XorShift generator.
rnd_xorshift_range
------------------
int rnd_xorshift_range( rnd_xorshift_t* xorshift, int min, int max )
Returns a random integer N in the range: min <= N <= max, from the specified XorShift generator.
*/
/*
----------------------
IMPLEMENTATION
----------------------
*/
#ifdef RND_IMPLEMENTATION
#undef RND_IMPLEMENTATION
// Convert a randomized RND_U32 value to a float value x in the range 0.0f <= x < 1.0f. Contributed by Jonatan Hedborg
static float rnd_internal_float_normalized_from_u32( RND_U32 value )
{
RND_U32 exponent = 127;
RND_U32 mantissa = value >> 9;
RND_U32 result = ( exponent << 23 ) | mantissa;
float fresult = *(float*)( &result );
return fresult - 1.0f;
}
static RND_U32 rnd_internal_murmur3_avalanche32( RND_U32 h )
{
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
static RND_U64 rnd_internal_murmur3_avalanche64( RND_U64 h )
{
h ^= h >> 33;
h *= 0xff51afd7ed558ccd;
h ^= h >> 33;
h *= 0xc4ceb9fe1a85ec53;
h ^= h >> 33;
return h;
}
void rnd_pcg_seed( rnd_pcg_t* pcg, RND_U32 seed )
{
RND_U64 value = ( ( (RND_U64) seed ) << 1ULL ) | 1ULL;
value = rnd_internal_murmur3_avalanche64( value );
pcg->state[ 0 ] = 0U;
pcg->state[ 1 ] = ( value << 1ULL ) | 1ULL;
rnd_pcg_next( pcg );
pcg->state[ 0 ] += rnd_internal_murmur3_avalanche64( value );
rnd_pcg_next( pcg );
}
RND_U32 rnd_pcg_next( rnd_pcg_t* pcg )
{
RND_U64 oldstate = pcg->state[ 0 ];
pcg->state[ 0 ] = oldstate * 0x5851f42d4c957f2dULL + pcg->state[ 1 ];
RND_U32 xorshifted = (RND_U32)( ( ( oldstate >> 18ULL) ^ oldstate ) >> 27ULL );
RND_U32 rot = (RND_U32)( oldstate >> 59ULL );
return ( xorshifted >> rot ) | ( xorshifted << ( ( -(int) rot ) & 31 ) );
}
float rnd_pcg_nextf( rnd_pcg_t* pcg )
{
return rnd_internal_float_normalized_from_u32( rnd_pcg_next( pcg ) );
}
int rnd_pcg_range( rnd_pcg_t* pcg, int min, int max )
{
int const range = ( max - min ) + 1;
if( range <= 0 ) return min;
int const value = (int) ( rnd_pcg_nextf( pcg ) * range );
return min + value;
}
void rnd_well_seed( rnd_well_t* well, RND_U32 seed )
{
RND_U32 value = rnd_internal_murmur3_avalanche32( ( seed << 1U ) | 1U );
well->state[ 16 ] = 0;
well->state[ 0 ] = value ^ 0xf68a9fc1U;
for( int i = 1; i < 16; ++i )
well->state[ i ] = ( 0x6c078965U * ( well->state[ i - 1 ] ^ ( well->state[ i - 1 ] >> 30 ) ) + i );
}
RND_U32 rnd_well_next( rnd_well_t* well )
{
RND_U32 a = well->state[ well->state[ 16 ] ];
RND_U32 c = well->state[ ( well->state[ 16 ] + 13 ) & 15 ];
RND_U32 b = a ^ c ^ ( a << 16 ) ^ ( c << 15 );
c = well->state[ ( well->state[ 16 ] + 9 ) & 15 ];
c ^= ( c >> 11 );
a = well->state[ well->state[ 16 ] ] = b ^ c;
RND_U32 d = a ^ ( ( a << 5 ) & 0xda442d24U );
well->state[ 16 ] = (well->state[ 16 ] + 15 ) & 15;
a = well->state[ well->state[ 16 ] ];
well->state[ well->state[ 16 ] ] = a ^ b ^ d ^ ( a << 2 ) ^ ( b << 18 ) ^ ( c << 28 );
return well->state[ well->state[ 16 ] ];
}
float rnd_well_nextf( rnd_well_t* well )
{
return rnd_internal_float_normalized_from_u32( rnd_well_next( well ) );
}
int rnd_well_range( rnd_well_t* well, int min, int max )
{
int const range = ( max - min ) + 1;
if( range <= 0 ) return min;
int const value = (int) ( rnd_well_nextf( well ) * range );
return min + value;
}
void rnd_gamerand_seed( rnd_gamerand_t* gamerand, RND_U32 seed )
{
RND_U32 value = rnd_internal_murmur3_avalanche32( ( seed << 1U ) | 1U );
gamerand->state[ 0 ] = value;
gamerand->state[ 1 ] = value ^ 0x49616e42U;
}
RND_U32 rnd_gamerand_next( rnd_gamerand_t* gamerand )
{
gamerand->state[ 0 ] = ( gamerand->state[ 0 ] << 16 ) + ( gamerand->state[ 0 ] >> 16 );
gamerand->state[ 0 ] += gamerand->state[ 1 ];
gamerand->state[ 1 ] += gamerand->state[ 0 ];
return gamerand->state[ 0 ];
}
float rnd_gamerand_nextf( rnd_gamerand_t* gamerand )
{
return rnd_internal_float_normalized_from_u32( rnd_gamerand_next( gamerand ) );
}
int rnd_gamerand_range( rnd_gamerand_t* gamerand, int min, int max )
{
int const range = ( max - min ) + 1;
if( range <= 0 ) return min;
int const value = (int) ( rnd_gamerand_nextf( gamerand ) * range );
return min + value;
}
void rnd_xorshift_seed( rnd_xorshift_t* xorshift, RND_U64 seed )
{
RND_U64 value = rnd_internal_murmur3_avalanche64( ( seed << 1ULL ) | 1ULL );
xorshift->state[ 0 ] = value;
value = rnd_internal_murmur3_avalanche64( value );
xorshift->state[ 1 ] = value;
}
RND_U64 rnd_xorshift_next( rnd_xorshift_t* xorshift )
{
RND_U64 x = xorshift->state[ 0 ];
RND_U64 const y = xorshift->state[ 1 ];
xorshift->state[ 0 ] = y;
x ^= x << 23;
x ^= x >> 17;
x ^= y ^ ( y >> 26 );
xorshift->state[ 1 ] = x;
return x + y;
}
float rnd_xorshift_nextf( rnd_xorshift_t* xorshift )
{
return rnd_internal_float_normalized_from_u32( (RND_U32)( rnd_xorshift_next( xorshift ) >> 32 ) );
}
int rnd_xorshift_range( rnd_xorshift_t* xorshift, int min, int max )
{
int const range = ( max - min ) + 1;
if( range <= 0 ) return min;
int const value = (int) ( rnd_xorshift_nextf( xorshift ) * range );
return min + value;
}
#endif /* RND_IMPLEMENTATION */
/*
contributors:
Jonatan Hedborg (unsigned int to normalized float conversion)
revision history:
1.0 first publicly released version
*/
/*
------------------------------------------------------------------------------
This software is available under 2 licenses - you may choose the one you like.
Based on public domain implementation - original licenses can be found next to
the relevant implementation sections of this file.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2016 Mattias Gustavsson
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/

@ -1,7 +1,7 @@
Urgent:
- Fix everything about the shotgun, put shotgun away. Make them understand they're holding their shotgun more. REALLY look into characters not being able to shoot eachother
- On startup if devtools print the estimated cost per generation request of the worst offending character
- Silent threshold for each character from 0 to 1 that controls random chance after every eavesdropped dialog that the character says nothing in response
- Tag memories from drama as permanent so they're never forgotten and always seed character behavior
- simple room transition system for angel/real map interop, angel room
- angel character that gives you randomized goals such as (kill so and so) or (befriend blank) or (get john to go to other room), and decides itself with gpt when you're done with the game, when you've 'learned your lesson'.
- can't interact with characters while they're thinking
@ -19,6 +19,7 @@ Long distance:
- Let ChatGPT file bug reports with something like !BugReport(This shouldn't be happening, developer. I killed them and they're still alive)
- System where I can upload any AI interaction into gpt playground and inspect the conversation
- Incrementally higher resolution system for all textures, configured in a #define. Also flips the images at build time
- Maybe check the hashes of the exported meshes if they all have the same name in the file, to attempt to detect identical geometry data. Same deal with textures in blender, or maybe in the game too actually.
- Stop time when you talk to people
- Much higher move accel, almost instantaneously goes to
- Imgui Button doesn't move enough when highlighted

@ -1,6 +1,7 @@
#ifndef TUNING_H // #pragma once isn't supported by sokol-shdc yet
#define TUNING_H
#define RANDOM_SEED 42
#define LEVEL_TILES 150 // width and height of level tiles array
#define LAYERS 3
#define TILE_SIZE 0.5f // in pixels

Loading…
Cancel
Save