wip demo mode
This commit is contained in:
+2
-2
@@ -30,7 +30,7 @@ static void print_help(int status_code) {
|
||||
" -s, --screen output screen number (default: primary)\n"
|
||||
" -f, --frag fragment shaders directory (default: TODO)\n"
|
||||
" -fc, --frag-config fragment shaders config file (default: TODO)\n"
|
||||
" -t, --tempo base tempo (default: 120)\n"
|
||||
" -t, --tempo base tempo (default: 60)\n"
|
||||
" --demo demonstration mode\n");
|
||||
exit(status_code);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ Parameters args_parse(int argc, char **argv) {
|
||||
params.frag_path = 0;
|
||||
params.frag_config_path = 0;
|
||||
params.hot_reload = false;
|
||||
params.base_tempo = 120.0f;
|
||||
params.base_tempo = 60.0f;
|
||||
params.demo = false;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
||||
+14
-12
@@ -8,6 +8,7 @@
|
||||
#include "file.h"
|
||||
#include "forge.h"
|
||||
#include "logs.h"
|
||||
#include "rand.h"
|
||||
#include "shaders.h"
|
||||
#include "timer.h"
|
||||
#include "types.h"
|
||||
@@ -44,19 +45,20 @@ static unsigned int compute_fps(Window *window, Timer *timer) {
|
||||
static void init_context(ShaderProgram program, Context *context,
|
||||
Parameters params) {
|
||||
int size;
|
||||
int i;
|
||||
|
||||
context->tempo = params.base_tempo;
|
||||
context->demo = params.demo;
|
||||
|
||||
// TODO temporary state
|
||||
size = program.frag_count * program.sub_type_count * sizeof(unsigned int);
|
||||
context->sub_state = malloc(size);
|
||||
memset(context->sub_state, 0, size);
|
||||
context->sub_state[program.sub_type_count * 0 + 0] = 1;
|
||||
context->sub_state[program.sub_type_count * 1 + 0] = 1;
|
||||
context->sub_state[program.sub_type_count * 2 + 1] = 1;
|
||||
context->sub_state[program.sub_type_count * 3 + 1] = 3;
|
||||
context->sub_state[program.sub_type_count * 5 + 1] = 6;
|
||||
// TODO fix here ??
|
||||
size = program.frag_count * program.sub_type_count;
|
||||
context->sub_state = malloc(size * sizeof(unsigned int));
|
||||
memset(context->sub_state, 0, sizeof(&context->sub_state));
|
||||
|
||||
if (params.demo) {
|
||||
for (i = 0; i < size; i++) {
|
||||
context->sub_state[i] = rand_uint(program.sub_variant_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void hot_reload(ShaderProgram program, File *common_shader_code,
|
||||
@@ -162,10 +164,10 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_get_context(window, &context);
|
||||
|
||||
init_context(program, &context, params);
|
||||
|
||||
program = shaders_init(fragment_shaders, shader_config, context);
|
||||
|
||||
init_context(program, &context, params);
|
||||
|
||||
if (program.error) {
|
||||
window_close(window, true);
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "args.h"
|
||||
#include "config.h"
|
||||
#include "forge.h"
|
||||
#include "main.h"
|
||||
#include "rand.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Parameters params;
|
||||
@@ -14,6 +16,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
puts(PACKAGE " " VERSION);
|
||||
|
||||
set_seed((unsigned long)time(NULL));
|
||||
|
||||
forge_run(params);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#include "rand.h"
|
||||
|
||||
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
|
||||
static unsigned long long const multiplier = 6364136223846793005u;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
|
||||
static unsigned long rand(void) {
|
||||
unsigned long long x = mcg_state;
|
||||
unsigned count = (unsigned)(x >> 61);
|
||||
|
||||
mcg_state = x * multiplier;
|
||||
x ^= x >> 22;
|
||||
return (unsigned long)(x >> (22 + count));
|
||||
}
|
||||
|
||||
void set_seed(unsigned long long seed) {
|
||||
mcg_state = 2 * seed + 1;
|
||||
(void)rand();
|
||||
}
|
||||
|
||||
unsigned char rand_uchar(const unsigned int max) {
|
||||
return max == 0 ? 0 : (unsigned char)(rand() % max);
|
||||
}
|
||||
|
||||
unsigned short rand_ushort(const unsigned int max) {
|
||||
return max == 0 ? 0 : (unsigned short)(rand() % max);
|
||||
}
|
||||
|
||||
unsigned int rand_uint(const unsigned int max) {
|
||||
return max == 0 ? 0 : (unsigned int)(rand() % max);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef RAND_H
|
||||
#define RAND_H
|
||||
|
||||
void set_seed(unsigned long long seed);
|
||||
unsigned char rand_uchar(unsigned int max);
|
||||
unsigned short rand_ushort(unsigned int max);
|
||||
unsigned int rand_uint(unsigned int max);
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -345,5 +345,5 @@ void shaders_apply(ShaderProgram program, Context context) {
|
||||
}
|
||||
}
|
||||
|
||||
use_program(program, program.frag_monitor_index, true, context);
|
||||
use_program(program, program.frag_output_index, true, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user