From cdde33843eb11020826818fc50ccfc8bb939355a Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 20 Dec 2023 22:34:47 +0300 Subject: [PATCH 01/35] Refactor localskin command a bit, get rid of args.c since it is unused --- src/CMakeLists.txt | 1 - src/Makefile | 1 - src/args.c | 1309 -------------------------------------------- src/args.h | 206 ------- src/d_netcmd.c | 57 +- 5 files changed, 23 insertions(+), 1551 deletions(-) delete mode 100644 src/args.c delete mode 100644 src/args.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e992f0a3..1f47bbdb6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,6 @@ # Core sources set(SRB2_CORE_SOURCES am_map.c - args.c b_bot.c command.c comptime.c diff --git a/src/Makefile b/src/Makefile index 717f881a0..06567753a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -538,7 +538,6 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/i_time.o \ $(OBJDIR)/lzf.o \ $(OBJDIR)/b_bot.o \ - $(OBJDIR)/args.o \ $(i_net_o) \ $(i_system_o) \ $(i_sound_o) \ diff --git a/src/args.c b/src/args.c deleted file mode 100644 index 88eec9092..000000000 --- a/src/args.c +++ /dev/null @@ -1,1309 +0,0 @@ -#include "doomtype.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "args.h" -#include "command.h" -#include "m_misc.h" - - -/* ------------------ */ -/* Utility functions. */ -/* ------------------ */ - - -// Prints a message to the console marking it as an error. -static void err(const char* msg) { - CONS_Alert(CONS_ERROR, "%s\n", msg); -} - -// Duplicates a string, automatically allocating memory for the copy. -// Returns NULL if memory cannot be allocated for the copy. -static char* str_dup(const char* string) { - size_t len = strlen(string) + 1; - char *copy = malloc(len); - return copy ? memcpy(copy, string, len) : NULL; -} - - -// Hashes a string using the FNV-1a algorithm. -static uint32_t str_hash(const char* string) { - uint32_t hash = 2166136261u; - size_t length = strlen(string); - for (size_t i = 0; i < length; i++) { - hash ^= (uint8_t)string[i]; - hash *= 16777619; - } - return hash; -} - - -// Attempts to parse a string as an integer value, exiting on failure. -static int try_str_to_int(const char* string) { - char *endptr; - errno = 0; - long result = strtol(string, &endptr, 0); - if (errno == ERANGE || result > INT_MAX || result < INT_MIN) { - err(va("'%s' is out of range", string)); - } - if (*endptr != '\0') { - err(va("cannot parse '%s' as an integer", string)); - } - return (int) result; -} - - -// Attempts to parse a string as a double value, exiting on failure. -static double try_str_to_double(const char* string) { - char *endptr; - errno = 0; - double result = strtod(string, &endptr); - if (errno == ERANGE) { - err(va("'%s' is out of range", string)); - } - if (*endptr != '\0') { - err(va("cannot parse '%s' as a floating-point value", string)); - } - return result; -} - - -/* --------------------------------- */ -/* Vec: a dynamic array of pointers. */ -/* --------------------------------- */ - - -typedef struct { - int count; - int capacity; - void** entries; -} Vec; - - -static Vec* vec_new() { - Vec* vec = malloc(sizeof(Vec)); - if (!vec) { - return NULL; - } - vec->count = 0; - vec->capacity = 0; - vec->entries = NULL; - return vec; -} - - -static void vec_free(Vec* vec) { - if (vec) { - free(vec->entries); - free(vec); - } -} - - -static boolean vec_add(Vec* vec, void* entry) { - if (vec->count + 1 > vec->capacity) { - int new_capacity = vec->capacity < 8 ? 8 : vec->capacity * 2; - void** new_array = realloc(vec->entries, sizeof(void*) * new_capacity); - if (!new_array) { - return false; - } - vec->entries = new_array; - vec->capacity = new_capacity; - } - vec->entries[vec->count] = entry; - vec->count++; - return true; -} - - -/* ------------------------------------------------------------------- */ -/* Map: a linear-probing hash map with string-keys and pointer-values. */ -/* ------------------------------------------------------------------- */ - - -// The map automatically grows to keep count/capacity < MAP_MAX_LOAD. -// This data structure performs optimally when it's less than half-full. -#define MAP_MAX_LOAD 0.5 - - -typedef struct { - char* key; - void* value; - uint32_t key_hash; -} MapEntry; - - -typedef struct { - int count; - int capacity; - int max_load_threshold; - MapEntry* entries; -} Map; - - -static Map* map_new() { - Map* map = malloc(sizeof(Map)); - if (!map) { - return NULL; - } - map->count = 0; - map->capacity = 0; - map->max_load_threshold = 0; - map->entries = NULL; - return map; -} - - -static void map_free(Map* map) { - if (map) { - for (int i = 0; i < map->capacity; i++) { - MapEntry* entry = &map->entries[i]; - if (entry->key != NULL) { - free(entry->key); - } - } - free(map->entries); - free(map); - } -} - - -static MapEntry* map_find(Map* map, const char* key, uint32_t key_hash) { - // Capacity is always a power of 2 so we can use bitwise-AND as a fast - // modulo operator, i.e. this is equivalent to: index = key_hash % capacity. - size_t index = key_hash & (map->capacity - 1); - - for (;;) { - MapEntry* entry = &map->entries[index]; - if (entry->key == NULL) { - return entry; - } else if (key_hash == entry->key_hash && strcmp(key, entry->key) == 0) { - return entry; - } - index = (index + 1) & (map->capacity - 1); - } -} - - -static boolean map_grow(Map* map) { - MapEntry* old_entries = map->entries; - int old_capacity = map->capacity; - int new_capacity = old_capacity < 8 ? 8 : old_capacity * 2; - - MapEntry* new_entries = malloc(sizeof(MapEntry) * new_capacity); - if (!new_entries) { - return false; - } - - for (int i = 0; i < new_capacity; i++) { - new_entries[i].key = NULL; - } - - map->count = 0; - map->capacity = new_capacity; - map->max_load_threshold = new_capacity * MAP_MAX_LOAD; - map->entries = new_entries; - - for (int i = 0; i < old_capacity; i++) { - MapEntry* src = &old_entries[i]; - if (src->key == NULL) continue; - - MapEntry* dst = map_find(map, src->key, src->key_hash); - dst->key = src->key; - dst->value = src->value; - dst->key_hash = src->key_hash; - map->count++; - } - - free(old_entries); - return true; -} - - -// Returns true if the key was found. -static boolean map_get(Map* map, const char* key, void** value) { - if (map->count == 0) return false; - - uint32_t key_hash = str_hash(key); - MapEntry* entry = map_find(map, key, key_hash); - if (entry->key == NULL) return false; - - *value = entry->value; - return true; -} - - -// Adds a new entry to the map or updates the value of an existing entry. -// (Note that the map stores its own internal copy of the key string.) -static boolean map_set(Map* map, const char* key, void* value) { - if (map->count == map->max_load_threshold) { - if (!map_grow(map)) { - return false; - } - } - - uint32_t key_hash = str_hash(key); - MapEntry* entry = map_find(map, key, key_hash); - if (entry->key == NULL) { - char* key_copy = str_dup(key); - if (!key_copy) { - return false; - } - map->count++; - entry->key = key_copy; - entry->value = value; - entry->key_hash = key_hash; - } else { - entry->value = value; - } - - return true; -} - - -// Convenience wrapper for map_set(). This splits the key string into space- -// separated words and adds a separate entry to the map for each word. -static boolean map_set_splitkey(Map* map, const char* key_string, void* value) { - char *copy_of_key_string = str_dup(key_string); - if (!copy_of_key_string) { - return false; - } - - char* word_start = copy_of_key_string; - char* string_end = word_start + strlen(copy_of_key_string); - - while (word_start < string_end) { - if (*word_start == ' ') { - word_start++; - continue; - } - - char* word_end = word_start; - while (true) { - if (*word_end == ' ' || *word_end == '\0') { - break; - } - word_end++; - } - *word_end = '\0'; - - if (!map_set(map, word_start, value)) { - free(copy_of_key_string); - return false; - } - - word_start = word_end + 1; - } - - free(copy_of_key_string); - return true; -} - - -/* -------- */ -/* Options. */ -/* -------- */ - - -typedef enum { - OPT_FLAG, - OPT_STR, - OPT_INT, - OPT_DBL, -} OptionType; - - -typedef union { - char* str_val; - int int_val; - double dbl_val; -} OptionValue; - - -typedef struct { - OptionType type; - int count; - int capacity; - OptionValue* values; - OptionValue fallback; -} Option; - - -static void option_free(Option* opt) { - if (opt) { - free(opt->values); - free(opt); - } -} - - -static boolean option_append_value(Option* opt, OptionValue value) { - if (opt->count + 1 > opt->capacity) { - int new_capacity = opt->capacity < 4 ? 4 : opt->capacity * 2; - OptionValue* new_array = realloc(opt->values, sizeof(OptionValue) * new_capacity); - if (!new_array) { - return false; - } - opt->capacity = new_capacity; - opt->values = new_array; - } - opt->values[opt->count] = value; - opt->count++; - return true; -} - - -static boolean option_try_set(Option* opt, char* arg) { - if (opt->type == OPT_STR) { - return option_append_value(opt, (OptionValue){.str_val = arg}); - } - else if (opt->type == OPT_INT) { - int value = try_str_to_int(arg); - return option_append_value(opt, (OptionValue){.int_val = value}); - } - else if (opt->type == OPT_DBL) { - double value = try_str_to_double(arg); - return option_append_value(opt, (OptionValue){.dbl_val = value}); - } - assert(false); - return false; -} - - -static Option* option_new() { - Option *option = malloc(sizeof(Option)); - if (!option) { - return NULL; - } - option->count = 0; - option->capacity = 0; - option->values = NULL; - return option; -} - - -static Option* option_new_flag() { - Option *opt = option_new(); - if (!opt) { - return NULL; - } - opt->type = OPT_FLAG; - return opt; -} - - -static Option* option_new_str(char* fallback) { - Option *opt = option_new(); - if (!opt) { - return NULL; - } - opt->type = OPT_STR; - opt->fallback = (OptionValue){.str_val = fallback}; - return opt; -} - - -static Option* option_new_int(int fallback) { - Option *opt = option_new(); - if (!opt) { - return NULL; - } - opt->type = OPT_INT; - opt->fallback = (OptionValue){.int_val = fallback}; - return opt; -} - - -static Option* option_new_double(double fallback) { - Option *opt = option_new(); - if (!opt) { - return NULL; - } - opt->type = OPT_DBL; - opt->fallback = (OptionValue){.dbl_val = fallback}; - return opt; -} - - -static char* option_get_str(Option* opt) { - if (opt->count > 0) { - return opt->values[opt->count - 1].str_val; - } - return opt->fallback.str_val; -} - - -static int option_get_int(Option* opt) { - if (opt->count > 0) { - return opt->values[opt->count - 1].int_val; - } - return opt->fallback.int_val; -} - - -static double option_get_double(Option* opt) { - if (opt->count > 0) { - return opt->values[opt->count - 1].dbl_val; - } - return opt->fallback.dbl_val; -} - - -// Returns the option's values as a freshly-allocated array of string pointers. -static char** option_get_str_list(Option* opt) { - if (opt->count == 0) { - return NULL; - } - char** list = malloc(sizeof(char*) * opt->count); - if (!list) { - return NULL; - } - for (int i = 0; i < opt->count; i++) { - list[i] = opt->values[i].str_val; - } - return list; -} - - -// Returns the option's values as a freshly-allocated array of integers. -static int* option_get_int_list(Option* opt) { - if (opt->count == 0) { - return NULL; - } - int* list = malloc(sizeof(int) * opt->count ); - if (!list) { - return NULL; - } - for (int i = 0; i < opt->count ; i++) { - list[i] = opt->values[i].int_val; - } - return list; -} - - -// Returns the option's values as a freshly-allocated array of doubles. -static double* option_get_double_list(Option* opt) { - if (opt->count == 0) { - return NULL; - } - double* list = malloc(sizeof(double) * opt->count ); - if (!list) { - return NULL; - } - for (int i = 0; i < opt->count ; i++) { - list[i] = opt->values[i].dbl_val; - } - return list; -} - - -// Returns a freshly-allocated state-string for debugging. -static char* option_to_str(Option* opt) { - if (opt->type == OPT_FLAG) { - return va("%i", opt->count); - } - - char *fallback = NULL; - if (opt->type == OPT_STR) { - fallback = str_dup(opt->fallback.str_val); - } else if (opt->type == OPT_INT) { - fallback = va("%i", opt->fallback.int_val); - } else if (opt->type == OPT_DBL) { - fallback = va("%f", opt->fallback.dbl_val); - } - - char *values = str_dup(""); - for (int i = 0; i < opt->count; i++) { - char *value = NULL; - if (opt->type == OPT_STR) { - value = str_dup(opt->values[i].str_val); - } else if (opt->type == OPT_INT) { - value = va("%i", opt->values[i].int_val); - } else if (opt->type == OPT_DBL) { - value = va("%f", opt->values[i].dbl_val); - } - char *old_values = values; - if (i == 0) { - values = str_dup(value); - } else { - values = va("%s, %s", old_values, value); - } - free(old_values); - free(value); - } - - char *output = va("(%s) [%s]", fallback, values); - free(fallback); - free(values); - return output; -} - - -/* ----------------------------------------------------- */ -/* ArgStream: a wrapper for an array of string pointers. */ -/* ----------------------------------------------------- */ - - -typedef struct ArgStream { - int count; - int index; - char** args; -} ArgStream; - - -static ArgStream* argstream_new(int count, char** args) { - ArgStream* stream = malloc(sizeof(ArgStream)); - if (!stream) { - return NULL; - } - stream->count = count; - stream->index = 0; - stream->args = args; - return stream; -} - - -static void argstream_free(ArgStream* stream) { - free(stream); -} - - -static char* argstream_next(ArgStream* stream) { - return stream->args[stream->index++]; -} - - -static boolean argstream_has_next(ArgStream* stream) { - return stream->index < stream->count; -} - - -/* ----------------- */ -/* ArgParser: setup. */ -/* ----------------- */ - - -struct ArgParser { - char* helptext; - char* version; - Vec* option_vec; - Map* option_map; - Vec* command_vec; - Map* command_map; - Vec* positional_args; - ap_callback_t callback; - char* cmd_name; - struct ArgParser* cmd_parser; - boolean enable_help_command; - boolean had_memory_error; - struct ArgParser* parent; - boolean first_positional_arg_ends_options; -}; - - -ArgParser* ap_new() { - ArgParser *parser = malloc(sizeof(ArgParser)); - if (!parser) { - return NULL; - } - - parser->helptext = NULL; - parser->version = NULL; - parser->callback = NULL; - parser->cmd_name = NULL; - parser->cmd_parser = NULL; - parser->enable_help_command = false; - parser->had_memory_error = false; - parser->parent = NULL; - parser->first_positional_arg_ends_options = false; - - parser->option_vec = NULL; - parser->option_map = NULL; - parser->command_vec = NULL; - parser->command_map = NULL; - parser->positional_args = NULL; - - parser->option_vec = vec_new(); - if (!parser->option_vec) { - ap_free(parser); - return NULL; - } - - parser->option_map = map_new(); - if (!parser->option_map) { - ap_free(parser); - return NULL; - } - - parser->command_vec = vec_new(); - if (!parser->command_vec) { - ap_free(parser); - return NULL; - } - - parser->command_map = map_new(); - if (!parser->command_map) { - ap_free(parser); - return NULL; - } - - parser->positional_args = vec_new(); - if (!parser->positional_args) { - ap_free(parser); - return NULL; - } - - return parser; -} - - -void ap_free(ArgParser* parser) { - if (!parser) { - return; - } - - free(parser->helptext); - free(parser->version); - - if (parser->option_map) { - map_free(parser->option_map); - } - - if (parser->option_vec) { - for (int i = 0; i < parser->option_vec->count; i++) { - option_free(parser->option_vec->entries[i]); - } - vec_free(parser->option_vec); - } - - if (parser->command_map) { - map_free(parser->command_map); - } - - if (parser->command_vec) { - for (int i = 0; i < parser->command_vec->count; i++) { - ap_free(parser->command_vec->entries[i]); - } - vec_free(parser->command_vec); - } - - if (parser->positional_args) { - vec_free(parser->positional_args); - } - - free(parser); -} - - -static void ap_set_memory_error_flag(ArgParser* parser) { - parser->had_memory_error = true; - - ArgParser* parent = parser->parent; - while (parent) { - parent->had_memory_error = true; - parent = parent->parent; - } -} - - -void ap_set_helptext(ArgParser* parser, const char* helptext) { - free(parser->helptext); - parser->helptext = NULL; - - if (helptext) { - parser->helptext = str_dup(helptext); - if (!parser->helptext) { - ap_set_memory_error_flag(parser); - } - } -} - - -char* ap_get_helptext(ArgParser* parser) { - return parser->helptext; -} - - -void ap_set_version(ArgParser* parser, const char* version) { - free(parser->version); - parser->version = NULL; - - if (version) { - parser->version = str_dup(version); - if (!parser->version) { - ap_set_memory_error_flag(parser); - } - } -} - - -char* ap_get_version(ArgParser* parser) { - return parser->version; -} - - -void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable) { - parser->first_positional_arg_ends_options = enable; -} - - -/* -------------------------------------- */ -/* ArgParser: register flags and options. */ -/* -------------------------------------- */ - - -static void ap_register_option(ArgParser* parser, const char* name, Option* opt) { - if (!opt) { - ap_set_memory_error_flag(parser); - return; - } - - if (vec_add(parser->option_vec, opt)) { - if (map_set_splitkey(parser->option_map, name, opt)) { - return; - } else { - ap_set_memory_error_flag(parser); - parser->option_vec->count--; - option_free(opt); - return; - } - } else { - ap_set_memory_error_flag(parser); - option_free(opt); - return; - } -} - - -// Register a new flag. -void ap_flag(ArgParser *parser, const char* name) { - Option* opt = option_new_flag(); - ap_register_option(parser, name, opt); -} - - -// Register a new string-valued option. -void ap_str_opt(ArgParser* parser, const char* name, const char* fallback) { - Option* opt = option_new_str((char*)fallback); - ap_register_option(parser, name, opt); -} - - -// Register a new integer-valued option. -void ap_int_opt(ArgParser* parser, const char* name, int fallback) { - Option* opt = option_new_int(fallback); - ap_register_option(parser, name, opt); -} - - -// Register a new double-valued option. -void ap_dbl_opt(ArgParser* parser, const char* name, double fallback) { - Option* opt = option_new_double(fallback); - ap_register_option(parser, name, opt); -} - - -/* ---------------------------------- */ -/* ArgParser: flag and option values. */ -/* ---------------------------------- */ - - -// Retrieve an Option instance by name. -static Option* ap_get_opt(ArgParser* parser, const char* name) { - void* opt; - if (!map_get(parser->option_map, name, &opt)) { - err(va("'%s' is not a registered flag or option name", name)); - } - return (Option*)opt; -} - - -// Returns the number of times the specified flag or option was found. -int ap_count(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return opt->count; -} - - -// Returns true if the specified flag or option was found. -boolean ap_found(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return opt->count > 0; -} - - -// Returns the value of the specified string option. -char* ap_str_value(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return (char*)option_get_str(opt); -} - - -// Returns the string value at the specified index. -char* ap_str_value_at_index(ArgParser* parser, const char* name, int index) { - Option* opt = ap_get_opt(parser, name); - return opt->values[index].str_val; -} - - -// Returns the value of the specified integer option. -int ap_int_value(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return option_get_int(opt); -} - - -// Returns the integer value at the specified index. -int ap_int_value_at_index(ArgParser* parser, const char* name, int index) { - Option* opt = ap_get_opt(parser, name); - return opt->values[index].int_val; -} - - -// Returns the value of the specified floating-point option. -double ap_dbl_value(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return option_get_double(opt); -} - - -// Returns the floating-point value at the specified index. -double ap_dbl_value_at_index(ArgParser* parser, const char* name, int index) { - Option* opt = ap_get_opt(parser, name); - return opt->values[index].dbl_val; -} - - -// Returns an option's values as a freshly-allocated array of string pointers. -// The array's memory is not affected by calls to ap_free(). -// Returns NULL if memory cannot be allocated for the array. -char** ap_str_values(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return (char**)option_get_str_list(opt); -} - - -// Returns an option's values as a freshly-allocated array of integers. The -// array's memory is not affected by calls to ap_free(). -// Returns NULL if memory cannot be allocated for the array. -int* ap_int_values(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return option_get_int_list(opt); -} - - -// Returns an option's values as a freshly-allocated array of doubles. The -// array's memory is not affected by calls to ap_free(). -// Returns NULL if memory cannot be allocated for the array. -double* ap_dbl_values(ArgParser* parser, const char* name) { - Option* opt = ap_get_opt(parser, name); - return option_get_double_list(opt); -} - - -/* -------------------------------- */ -/* ArgParser: positional arguments. */ -/* -------------------------------- */ - - -// Returns true if the parser has found one or more positional arguments. -boolean ap_has_args(ArgParser* parser) { - return parser->positional_args->count > 0; -} - - -// Returns the number of positional arguments. -int ap_count_args(ArgParser* parser) { - return parser->positional_args->count; -} - - -// Returns the positional argument at the specified index. -char* ap_arg(ArgParser* parser, int index) { - return (char*)parser->positional_args->entries[index]; -} - - -// Returns the positional arguments as a freshly-allocated array of string -// pointers. The memory occupied by the returned array is not affected by -// calls to ap_free(). -// Returns NULL if memory cannot be allocated for the array. -char** ap_args(ArgParser* parser) { - int count = ap_count_args(parser); - char** args = malloc(sizeof(char*) * count); - if (!args) { - return NULL; - } - memcpy(args, parser->positional_args->entries, sizeof(char*) * count); - return args; -} - - -// Attempts to parse and return the positional arguments as a freshly -// allocated array of integers. Exits with an error message on failure. The -// memory occupied by the returned array is not affected by calls to -// ap_free(). -// Returns NULL if memory cannot be allocated for the array. -int* ap_args_as_ints(ArgParser* parser) { - int count = ap_count_args(parser); - int* args = malloc(sizeof(int) * count); - if (!args) { - return NULL; - } - for (int i = 0; i < count; i++) { - *(args + i) = try_str_to_int(parser->positional_args->entries[i]); - } - return args; -} - - -// Attempts to parse and return the positional arguments as a freshly -// allocated array of doubles. Exits with an error message on failure. The -// memory occupied by the returned array is not affected by calls to -// ap_free(). -// Returns NULL if memory cannot be allocated for the array. -double* ap_args_as_doubles(ArgParser* parser) { - int count = ap_count_args(parser); - double *args = malloc(sizeof(double) * count); - if (!args) { - return NULL; - } - for (int i = 0; i < count; i++) { - *(args + i) = try_str_to_double(parser->positional_args->entries[i]); - } - return args; -} - - -/* -------------------- */ -/* ArgParser: commands. */ -/* -------------------- */ - - -// Register a new command. -ArgParser* ap_cmd(ArgParser* parser, const char* name) { - ArgParser* cmd_parser = ap_new(); - if (!cmd_parser) { - return NULL; - } - - if (vec_add(parser->command_vec, cmd_parser)) { - if (map_set_splitkey(parser->command_map, name, cmd_parser)) { - parser->enable_help_command = true; - return cmd_parser; - } else { - parser->command_vec--; - ap_free(cmd_parser); - return NULL; - } - } else { - ap_free(cmd_parser); - return NULL; - } -} - - -// Register a callback function for a command. -void ap_callback(ArgParser* parser, ap_callback_t function) { - parser->callback = function; -} - - -// Returns true if the parser has found a command. -boolean ap_has_cmd(ArgParser* parser) { - return parser->cmd_name != NULL; -} - - -// Returns the command name, if the parser has found a command. -char* ap_cmd_name(ArgParser* parser) { - return parser->cmd_name; -} - - -// Returns the command's parser instance, if the parser has found a command. -ArgParser* ap_cmd_parser(ArgParser* parser) { - return parser->cmd_parser; -} - - -// Toggles support for the automatic 'help' command. -void ap_enable_help_command(ArgParser* parser, boolean enable) { - parser->enable_help_command = enable; -} - - -/* --------------------------- */ -/* ArgParser: parse arguments. */ -/* --------------------------- */ - - -// Parse an option of the form --name=value or -n=value. -static void ap_handle_equals_opt(ArgParser* parser, const char* prefix, const char* arg) { - char* name = str_dup(arg); - if (!name) { - ap_set_memory_error_flag(parser); - return; - } - - *strchr(name, '=') = '\0'; - char *value = strchr(arg, '=') + 1; - - Option* option; - boolean found = map_get(parser->option_map, name, (void**)&option); - - if (!found || option->type == OPT_FLAG) { - err(va("%s%s is not a recognised option name", prefix, name)); - } - - if (strlen(value) == 0) { - err(va("missing argument for %s%s", prefix, name)); - } - - if (!option_try_set(option, value)) { - ap_set_memory_error_flag(parser); - } - - free(name); -} - -// Parse a long-form option, i.e. an option beginning with a double dash. -static void ap_handle_long_opt(ArgParser* parser, const char* arg, ArgStream* stream) { - Option* option; - if (map_get(parser->option_map, arg, (void**)&option)) { - if (option->type == OPT_FLAG) { - option->count++; - } else if (argstream_has_next(stream)) { - if (!option_try_set(option, argstream_next(stream))) { - ap_set_memory_error_flag(parser); - } - } else { - err(va("missing argument for --%s", arg)); - } - } else if (strcmp(arg, "help") == 0 && parser->helptext != NULL) { - CONS_Printf("%s\n", parser->helptext); - } else if (strcmp(arg, "version") == 0 && parser->version != NULL) { - CONS_Printf("%s\n", parser->version); - } else { - err(va("--%s is not a recognised flag or option name", arg)); - } -} - - -// Parse a short-form option, i.e. an option beginning with a single dash. -static void ap_handle_short_opt(ArgParser* parser, const char* arg, ArgStream* stream) { - for (size_t i = 0; i < strlen(arg); i++) { - char keystr[] = {arg[i], 0}; - Option* option; - boolean found = map_get(parser->option_map, keystr, (void**)&option); - if (!found) { - if (arg[i] == 'h' && parser->helptext != NULL) { - CONS_Printf("%s\n", parser->helptext); - } else if (arg[i] == 'v' && parser->version != NULL) { - CONS_Printf("%s\n", parser->version); - } else if (strlen(arg) > 1) { - err(va("'%c' in -%s is not a recognised flag or option name", arg[i], arg)); - } else { - err(va("-%s is not a recognised flag or option name", arg)); - } - } else if (option->type == OPT_FLAG) { - option->count++; - } else if (argstream_has_next(stream)) { - if (!option_try_set(option, argstream_next(stream))) { - ap_set_memory_error_flag(parser); - } - } else if (strlen(arg) > 1) { - err(va("missing argument for '%c' in -%s", arg[i], arg)); - } else { - err(va("missing argument for -%s", arg)); - } - } -} - - -// Parse a stream of string arguments. -static void ap_parse_stream(ArgParser* parser, ArgStream* stream) { - if (parser->had_memory_error) { - return; - } - - ArgParser* cmd_parser; - boolean is_first_arg = true; - - while (argstream_has_next(stream)) { - char* arg = argstream_next(stream); - - // If we encounter a '--' argument, turn off option-parsing. - if (strcmp(arg, "--") == 0) { - while (argstream_has_next(stream)) { - if (!vec_add(parser->positional_args, argstream_next(stream))) { - ap_set_memory_error_flag(parser); - } - } - } - - // Is the argument a long-form option or flag? - else if (strncmp(arg, "--", 2) == 0) { - if (strstr(arg, "=") != NULL) { - ap_handle_equals_opt(parser, "--", arg + 2); - } else { - ap_handle_long_opt(parser, arg + 2, stream); - } - } - - // Is the argument a short-form option or flag? - else if (arg[0] == '-') { - if (strlen(arg) == 1 || isdigit(arg[1])) { - if (!vec_add(parser->positional_args, arg)) { - ap_set_memory_error_flag(parser); - } - } else if (strstr(arg, "=") != NULL) { - ap_handle_equals_opt(parser, "-", arg + 1); - } else { - ap_handle_short_opt(parser, arg + 1, stream); - } - } - - // Is the argument a registered command? - else if (is_first_arg && map_get(parser->command_map, arg, (void**)&cmd_parser)) { - parser->cmd_name = arg; - parser->cmd_parser = cmd_parser; - ap_parse_stream(cmd_parser, stream); - if (cmd_parser->callback && !parser->had_memory_error) { - cmd_parser->callback(arg, cmd_parser); - } - } - - // Is the argument the automatic 'help' command? - else if (is_first_arg && parser->enable_help_command && strcmp(arg, "help") == 0) { - if (argstream_has_next(stream)) { - char* name = argstream_next(stream); - if (map_get(parser->command_map, name, (void**)&cmd_parser)) { - if (cmd_parser->helptext) { - CONS_Printf("%s\n", cmd_parser->helptext); - } - } else { - err(va("'%s' is not a recognised command", name)); - } - } else { - err(va("the help command requires an argument")); - } - } - - // Otherwise add the argument to our list of positionals. - else { - if (!vec_add(parser->positional_args, arg)) { - ap_set_memory_error_flag(parser); - } - if (parser->first_positional_arg_ends_options) { - while (argstream_has_next(stream)) { - if (!vec_add(parser->positional_args, argstream_next(stream))) { - ap_set_memory_error_flag(parser); - } - } - } - } - - is_first_arg = false; - } -} - - -// Parse an array of string arguments. -static boolean ap_parse_array(ArgParser* parser, int count, char* args[]) { - if (parser->had_memory_error) { - return false; - } - - ArgStream *stream = argstream_new(count, args); - if (!stream) { - return false; - } - - ap_parse_stream(parser, stream); - argstream_free(stream); - - return !parser->had_memory_error; -} - - -// This function parses the application's command line arguments. It assumes that [argc] and [argv] -// are the arguments passed to main(), i.e. that the first element in [argv] is the program's name -// and should be ignored when parsing the actual *arguments*. In some situations [argv] can be -// empty, i.e. [argc == 0], which can lead to security vulnerabilities if not explicitly handled. -boolean ap_parse(ArgParser* parser, int argc, char* argv[]) { - if (argc > 1) { - return ap_parse_array(parser, argc - 1, argv + 1); - } - return !parser->had_memory_error; -} - - -/* --------------------- */ -/* ArgParser: utilities. */ -/* --------------------- */ - - -boolean ap_had_memory_error(ArgParser* parser) { - return parser->had_memory_error; -} - - -void ap_print(ArgParser* parser) { - CONS_Printf("%s\n", "Flags/Options:"); - if (parser->option_map->count > 0) { - for (int i = 0; i < parser->option_map->capacity; i++) { - MapEntry* entry = &parser->option_map->entries[i]; - if (entry->key != NULL) { - Option* opt = entry->value; - char* opt_str = option_to_str(opt); - CONS_Printf("%s\n", entry->key, opt_str); - free(opt_str); - } - } - } else { - CONS_Printf("%s\n", " [none]"); - } - - CONS_Printf("%s\n", "\nArguments:"); - if (parser->positional_args->count > 0) { - for (int i = 0; i < parser->positional_args->count; i++) { - CONS_Printf("%s\n", ap_arg(parser, i)); - } - } else { - CONS_Printf("%s\n", " [none]"); - } - - CONS_Printf("%s\n", "\nCommand:"); - if (ap_has_cmd(parser)) { - CONS_Printf("%s\n", ap_cmd_name(parser)); - } else { - CONS_Printf("%s\n", " [none]"); - } -} - - -/* --------------------- */ -/* Deprecated functions. */ -/* --------------------- */ - - -void ap_cmd_help(ArgParser* parser, boolean enable) { - ap_enable_help_command(parser, enable); -} - - -void ap_helptext(ArgParser* parser, const char* helptext) { - ap_set_helptext(parser, helptext); -} - - -void ap_version(ArgParser* parser, const char* version) { - ap_set_version(parser, version); -} diff --git a/src/args.h b/src/args.h deleted file mode 100644 index e2db1e501..000000000 --- a/src/args.h +++ /dev/null @@ -1,206 +0,0 @@ -// ----------------------------------------------------------------------------- -// Args: a C99 library for parsing command line arguments. -// Version: 2.8.0 -// Notes: This has been edited to work properly within SRB2. -// Licensed under the 0BSD license. -// ----------------------------------------------------------------------------- - -#ifndef args_h -#define args_h - -#include "doomtype.h" - -// ----------------------------------------------------------------------------- -// Types. -// ----------------------------------------------------------------------------- - -// An ArgParser instance stores registered flags, options and commands. -typedef struct ArgParser ArgParser; - -// A command callback function should accept two arguments: the command's name -// and the command's ArgParser instance. -typedef void (*ap_callback_t)(char* cmd_name, ArgParser* cmd_parser); - -// ----------------------------------------------------------------------------- -// Initialization, parsing, teardown. -// ----------------------------------------------------------------------------- - -// Initializes a new ArgParser instance. Returns NULL if sufficient memory -// cannot be allocated for the new parser. -ArgParser* ap_new(); - -// Specifies a helptext string for the parser. If [helptext] is not NULL, this -// activates an automatic --help/-h flag. (Either --help or -h can be overridden -// by explicitly registered flags.) The parser stores and manages its own copy -// of the [helptext] string so [helptext] can be freed immediately after this -// call if it was dynamically constructed. -void ap_set_helptext(ArgParser* parser, const char* helptext); - -// Returns a pointer to the parser's helptext string. -char* ap_get_helptext(ArgParser* parser); - -// Specifies a version string for the parser. If [version] is not NULL, this -// activates an automatic --version/-v flag. (Either --version or -v can be -// overridden by explicitly registered flags.) The parser stores and manages its -// own copy of the [version] string so [version] can be freed immediately after -// this call if it was dynamically constructed. -void ap_set_version(ArgParser* parser, const char* version); - -// Returns a pointer to the parser's version string. -char* ap_get_version(ArgParser* parser); - -// If toggled to true, the first positional argument ends option parsing; all -// subsequent arguments will be treated as positionals. Defaults to false. -void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable); - -// Parses the application's command line arguments. The parameters are assumed -// to be [argc] and [argv] as supplied to main(), i.e. the first element of the -// array is assumed to be the binary name and is therefore ignored. Returns true -// if the arguments were successfully parsed. Returns false if parsing failed -// due to a memory allocation error. (This memory allocation error may have -// occured during set-up rather than during parsing.) -boolean ap_parse(ArgParser* parser, int argc, char** argv); - -// Frees the memory associated with the parser and any subparsers. -void ap_free(ArgParser* parser); - -// ----------------------------------------------------------------------------- -// Register flags and options. -// ----------------------------------------------------------------------------- - -// Registers a new flag. -void ap_flag(ArgParser* parser, const char* name); - -// Registers a new string-valued option. -void ap_str_opt(ArgParser* parser, const char* name, const char* fallback); - -// Registers a new integer-valued option. -void ap_int_opt(ArgParser* parser, const char* name, int fallback); - -// Registers a new double-valued option. -void ap_dbl_opt(ArgParser* parser, const char* name, double fallback); - -// ----------------------------------------------------------------------------- -// Inspect flags and options. -// ----------------------------------------------------------------------------- - -// Returns the number of times the specified flag or option was found. -int ap_count(ArgParser* parser, const char* name); - -// Returns true if the specified flag or option was found. -boolean ap_found(ArgParser* parser, const char* name); - -// Returns the value of a string option. -char* ap_str_value(ArgParser* parser, const char* name); - -// Returns the string value at the specified index. -char* ap_str_value_at_index(ArgParser* parser, const char* name, int index); - -// Returns the value of an integer option. -int ap_int_value(ArgParser* parser, const char* name); - -// Returns the integer value at the specified index. -int ap_int_value_at_index(ArgParser* parser, const char* name, int index); - -// Returns the value of a floating-point option. -double ap_dbl_value(ArgParser* parser, const char* name); - -// Returns the floating-point value at the specified index. -double ap_dbl_value_at_index(ArgParser* parser, const char* name, int index); - -// Returns an option's values as a freshly-allocated array of string -// pointers. The array's memory is not affected by calls to ap_free(). -// Returns NULL if memory allocation fails. -char** ap_str_values(ArgParser* parser, const char* name); - -// Returns an option's values as a freshly-allocated array of integers. -// The array's memory is not affected by calls to ap_free(). -// Returns NULL if memory allocation fails. -int* ap_int_values(ArgParser* parser, const char* name); - -// Returns an option's values as a freshly-allocated array of doubles. -// The array's memory is not affected by calls to ap_free(). -// Returns NULL if memory allocation fails. -double* ap_dbl_values(ArgParser* parser, const char* name); - -// ----------------------------------------------------------------------------- -// Positional arguments. -// ----------------------------------------------------------------------------- - -// Returns true if the parser has found one or more positional arguments. -boolean ap_has_args(ArgParser* parser); - -// Returns the number of positional arguments. -int ap_count_args(ArgParser* parser); - -// Returns the positional argument at the specified index. -char* ap_arg(ArgParser* parser, int index); - -// Returns the positional arguments as a freshly-allocated array of string -// pointers. The memory occupied by the returned array is not affected by -// calls to ap_free(). Returns NULL if memory allocation fails. -char** ap_args(ArgParser* parser); - -// Attempts to parse and return the positional arguments as a freshly allocated -// array of integers. Exits with an error message on failure. The memory -// occupied by the returned array is not affected by calls to ap_free(). -// Returns NULL if memory allocation fails. -int* ap_args_as_ints(ArgParser* parser); - -// Attempts to parse and return the positional arguments as a freshly allocated -// array of doubles. Exits with an error message on failure. The memory -// occupied by the returned array is not affected by calls to ap_free(). -// Returns NULL if memory allocation fails. -double* ap_args_as_doubles(ArgParser* parser); - -// ----------------------------------------------------------------------------- -// Commands. -// ----------------------------------------------------------------------------- - -// Registers a new command. Returns the ArgParser instance for the command. -// Returns NULL if sufficient memory cannot be allocated for the new parser. -ArgParser* ap_cmd(ArgParser* parser, const char* name); - -// Registers a callback function on a command parser. The function will be -// called if the command is found. -void ap_callback(ArgParser* parser, ap_callback_t function); - -// Returns true if the parser has found a command. -boolean ap_has_cmd(ArgParser* parser); - -// Returns the command name, if the parser has found a command. -char* ap_cmd_name(ArgParser* parser); - -// Returns the command's parser instance, if the parser has found a command. -ArgParser* ap_cmd_parser(ArgParser* parser); - -// This booleanean switch toggles support for an automatic 'help' command that -// prints subcommand helptext. The value defaults to false but gets toggled -// automatically to true whenever a command is registered. You can use this -// function to disable the feature if required. -void ap_enable_help_command(ArgParser* parser, boolean enable); - -// ----------------------------------------------------------------------------- -// Debugging utilities. -// ----------------------------------------------------------------------------- - -// Dump a parser instance for debugging. -void ap_print(ArgParser* parser); - -// True if an attempt to allocate memory failed. -boolean ap_had_memory_error(ArgParser* parser); - -// ----------------------------------------------------------------------------- -// Deprecated. -// ----------------------------------------------------------------------------- - -// Replaced by ap_enable_help_command(). -void ap_cmd_help(ArgParser* parser, boolean enable); - -// Replaced by ap_set_helptext(). -void ap_helptext(ArgParser* parser, const char* helptext); - -// Replaced by ap_set_version(). -void ap_version(ArgParser* parser, const char* version); - -#endif diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9753bf11a..43d7377a7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4605,14 +4605,6 @@ static void Command_Addfile(void) SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); } -// i hate myself -static boolean DumbStartsWith(const char *pre, const char *str) -{ - size_t lenpre = strlen(pre), - lenstr = strlen(str); - return lenstr < lenpre ? false : memcmp(pre, str, lenpre) == 0; -} - /** Adds something at runtime. */ static void @@ -4649,16 +4641,13 @@ Command_Addskins (void) */ } -// args n stuff -#include "args.h" - -static void Command_GLocalSkin (void) +static void Command_GLocalSkin (void) { size_t first_option; size_t option_display; size_t option_all; size_t option_player; - + option_player = COM_CheckPartialParm("-p"); option_display = COM_CheckPartialParm("-d"); option_all = COM_CheckPartialParm("-a"); @@ -4686,31 +4675,27 @@ static void Command_GLocalSkin (void) fuck = ConcatCommandArgv(1, first_option); - char* player_name = player_names[consoleplayer]; - char* display_num = "0"; + const char* player_name = player_names[consoleplayer]; + const char* display_num = "0"; size_t dnum = 0; if (option_display) // -display { // handle default: 0 - if (COM_Argv(option_display + 1)[0] == "" || COM_Argv(option_display + 1)[0] != "-") + if (COM_Argc() >= option_display) display_num = COM_Argv(option_display + 1); - if (isdigit(display_num[0]) || display_num == "0") - { - dnum = atoi(display_num); - if (dnum > 3 || dnum < 0) // nuh uh - dnum = 0; - SetLocalPlayerSkin(displayplayers[dnum], fuck, NULL); + dnum = atoi(display_num); + if (dnum > 3) // nuh uh + dnum = 0; - CONS_Printf("Successfully applied localskin to displayed player.\n"); - return; - } - - CONS_Printf("Could not apply localskin.\n"); - + SetLocalPlayerSkin(displayplayers[dnum], fuck, NULL); + + CONS_Printf("Successfully applied localskin to displayed player.\n"); + + Z_Free(fuck); return; - } + } else if (option_all) // -all { int i; @@ -4723,34 +4708,38 @@ static void Command_GLocalSkin (void) } CONS_Printf("Successfully applied localskin to all players.\n"); + Z_Free(fuck); return; - } + } else // -player or no other arguments { - if (option_player) + if (option_player) { int i; player_name = COM_Argv(option_player + 1); - for (i = 0; i < MAXPLAYERS; ++i) + for (i = 0; i < MAXPLAYERS; ++i) { if (fasticmp(player_names[i], player_name)) SetLocalPlayerSkin(i, fuck, NULL); } CONS_Printf("Successfully applied localskin to specified player.\n"); + Z_Free(fuck); return; - } - else + } + else { SetLocalPlayerSkin(consoleplayer, fuck, &cv_localskin); CONS_Printf("Successfully applied localskin.\n"); + Z_Free(fuck); return; } CONS_Printf("Could not apply localskin.\n"); + Z_Free(fuck); return; } } -- 2.54.0 From 23c7aaeff2e528e13cb8fcac3af6f683f1671dbb Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Thu, 21 Dec 2023 10:55:40 +0800 Subject: [PATCH 02/35] Some hardware renderer cleanup GRAH WARNINGS --- src/hardware/hw_main.c | 346 +++++++---------------------------------- 1 file changed, 53 insertions(+), 293 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f0fab7fe5..b760c2a6f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -273,20 +273,24 @@ static fixed_t dup_viewx, dup_viewy, dup_viewz; static angle_t gr_aimingangle; static float gr_viewludsin, gr_viewludcos; -// -// PORTALS -// +// ========================================================================== +// Visual portals (attr. Hannu Hanhi) +// ========================================================================== -#define MAX_GRPORTALS 13 -// Note: portal sorting has not been ported to this -//#define PORTALSORTING // Breaks recursive portals :[ - - -// for porting gonna add stuff from r_portal here with adjustments - -typedef struct portal_s +enum { - struct portal_s *next; + GRPORTAL_OFF, + GRPORTAL_SEARCH, + GRPORTAL_STENCIL, + GRPORTAL_DEPTH, + GRPORTAL_INSIDE, +}; + +static int gr_portal = GRPORTAL_OFF; +static boolean gl_drawing_stencil = false; +typedef struct gl_portal_s +{ + struct gl_portal_s *next; // Viewport. fixed_t viewx; @@ -300,36 +304,38 @@ typedef struct portal_s INT32 drawcount; /**< For OpenGL. */ seg_t *seg; -} portal_t; +} gl_portal_t; -typedef struct portallist_s +typedef struct gl_portallist_s { - portal_t *base; - portal_t *cap; -} portallist_t; + gl_portal_t *base; + gl_portal_t *cap; +} gl_portallist_t; // new thing -portallist_t *currentportallist; +gl_portallist_t *currentportallist; INT32 portalviewside; // Linked list for portals. -portal_t *portal_base_gl, *portal_cap_gl; +gl_portal_t *portal_base_gl, *portal_cap_gl; +/* For now, these aren't used. // maybe at some point these could be organized better -void HWR_Portal_InitList (void) +static void HWR_Portal_InitList (void) { portalrender = 0; portal_base_gl = portal_cap_gl = NULL; } -void HWR_Portal_Remove (portal_t* portal) +static void HWR_Portal_Remove(gl_portal_t* portal) { portal_base_gl = portal->next; Z_Free(portal); } +*/ -void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) +static void HWR_Portal_Add2Lines(const INT32 line1, const INT32 line2, seg_t *seg) { line_t *start, *dest; @@ -340,17 +346,9 @@ void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) vertex_t dest_c, start_c; - portal_t *portal; + gl_portal_t *portal; - // check for duplicate - /*if (currentportallist->base && currentportallist->cap->startline == line1 && currentportallist->cap->clipline == line2) - { - if (printportals) - CONS_Printf("Duplicate portal skipped\n"); - return; - }*/ - - portal = Z_Malloc(sizeof(portal_t), PU_STATIC, NULL); + portal = Z_Malloc(sizeof(gl_portal_t), PU_STATIC, NULL); // Linked list. if (!currentportallist->base) @@ -404,7 +402,7 @@ void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) portal->clipline = line2; } -void HWR_PortalFrame(portal_t* portal) +static void HWR_PortalFrame(gl_portal_t* portal) { viewx = portal->viewx; viewy = portal->viewy; @@ -429,42 +427,6 @@ void HWR_PortalFrame(portal_t* portal) } } -enum -{ - GRPORTAL_OFF, - GRPORTAL_SEARCH, - GRPORTAL_STENCIL, - GRPORTAL_DEPTH, - GRPORTAL_INSIDE, -}; - -void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, player_t *player); - -#ifdef PORTALSORTING -static portal_t gr_portals[MAX_GRPORTALS]; -static size_t gr_numportals = 0; - -static void HWR_AddPortal(portal_t *portal); -static void HWR_SortPortals(player_t *player, float fpov, INT32 viewnumber, postimg_t *ptype); -#endif - -static int gr_portal = GRPORTAL_OFF; -static boolean gl_drawing_stencil = false; - -// Culling -typedef struct -{ - seg_t *seg; - sector_t *frontsector; - sector_t *backsector; -} gr_portalcullinfo_t; - -static gr_portalcullinfo_t gr_portalsegs[MAX_GRPORTALS]; -static size_t gr_numportalsegs = 0; - -static sector_t *gr_portalcullsectors[MAX_GRPORTALS]; -static size_t gr_numportalcullsectors = 0; - // ========================================================================== // Lighting // ========================================================================== @@ -566,7 +528,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col } } -void HWR_ClearLightTableCache() +void HWR_ClearLightTableCache(void) { if (rendermode == render_opengl) HWD.pfnClearLightTableCache(); @@ -1427,12 +1389,12 @@ int skyWallVertexArrayAllocSize = 65536;// what a mouthful boolean gr_collect_skywalls = false; -void HWR_SkyWallList_Clear() +static void HWR_SkyWallList_Clear(void) { skyWallVertexArraySize = 0; } -void HWR_SkyWallList_Add(FOutVector *wallVerts) +static void HWR_SkyWallList_Add(FOutVector *wallVerts) { if (!skyWallVertexArray) { @@ -1451,7 +1413,7 @@ void HWR_SkyWallList_Add(FOutVector *wallVerts) skyWallVertexArraySize++; } -void HWR_DrawSkyWallList() +static void HWR_DrawSkyWallList(void) { int i; FSurfaceInfo surf; @@ -1491,68 +1453,6 @@ void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf) // PF_Occlude is set in HWR_ProjectWall to draw into the depth buffer } -// HWR_DrawPortalClipWall -// Draws an invisible wall that extends to nowhere, -// so that portals can be clipped correctly. -static void HWR_DrawPortalClipWall(line_t *line) -{ - FOutVector wallVerts[4]; - FSurfaceInfo Surf; - v2d_t vs, ve; - fixed_t length = 1000*FRACUNIT; - fixed_t temp = 0; - - angle_t angle = R_PointToAngle2(line->v1->x, line->v1->y, line->v2->x, line->v2->y); - angle_t lineangle = 0; - - // no texture - HWD.pfnSetTexture(NULL); - wallVerts[3].t = wallVerts[2].t = 0; - wallVerts[0].t = wallVerts[1].t = 0; - wallVerts[0].s = wallVerts[3].s = 0; - wallVerts[2].s = wallVerts[1].s = 0; - - //wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; whatever this is i guess it cant be here - wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(INT32_MIN); - wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(INT32_MAX); - - // first - vs.x = FIXED_TO_FLOAT(line->v1->x); - vs.y = FIXED_TO_FLOAT(line->v1->y); - - angle -= ANGLE_180; - lineangle = (angle >> ANGLETOFINESHIFT); - temp = FixedMul(length, FINECOSINE(lineangle)); - ve.x = vs.x + FIXED_TO_FLOAT(temp); - temp = FixedMul(length, FINESINE(lineangle)); - ve.y = vs.y + FIXED_TO_FLOAT(temp); - - wallVerts[0].x = wallVerts[3].x = ve.x; - wallVerts[0].z = wallVerts[3].z = ve.y; - wallVerts[2].x = wallVerts[1].x = vs.x; - wallVerts[2].z = wallVerts[1].z = vs.y; - - HWR_ProjectWall(wallVerts, &Surf, PF_NoTexture, 255, NULL); - - // second - vs.x = FIXED_TO_FLOAT(line->v2->x); - vs.y = FIXED_TO_FLOAT(line->v2->y); - - angle += ANGLE_180; - lineangle = (angle >> ANGLETOFINESHIFT); - temp = FixedMul(length, FINECOSINE(lineangle)); - ve.x = vs.x + FIXED_TO_FLOAT(temp); - temp = FixedMul(length, FINESINE(lineangle)); - ve.y = vs.y + FIXED_TO_FLOAT(temp); - - wallVerts[0].x = wallVerts[3].x = ve.x; - wallVerts[0].z = wallVerts[3].z = ve.y; - wallVerts[2].x = wallVerts[1].x = vs.x; - wallVerts[2].z = wallVerts[1].z = vs.y; - - HWR_ProjectWall(wallVerts, &Surf, PF_NoTexture, 255, NULL); -} - // // HWR_ProcessSeg // A portion or all of a wall segment will be drawn, from startfrac to endfrac, @@ -2879,15 +2779,7 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) viewc1 = backc1; viewc2 = backc2; } -/* - // dont clip viewsector when rendering portal contents - if (portalclipline) - { - if (printportals) - CONS_Printf("Clipping skipped on portal viewsector\n"); - return false; - } -*/ + // check if camera is outside the bounds of the floor and the ceiling (noclipping) // either above the ceiling or below the floor if ((viewz > viewc1 && viewz > viewc2) || (viewz < viewf1 && viewz < viewf2)) @@ -3002,20 +2894,7 @@ void HWR_AddLine(seg_t *line) { vertex_t closest_point; boolean pass = false; - /* - if (P_PointOnLineSide(line->v1->x, line->v1->y, portalclipline) != portalviewside) - { - P_ClosestPointOnLine(line->v1->x, line->v1->y, portalclipline, &closest_point); - if (closest_point.x != line->v1->x || closest_point.y != line->v1->y) - pass = true; - } - if (!pass && P_PointOnLineSide(line->v2->x, line->v2->y, portalclipline) != portalviewside) - { - P_ClosestPointOnLine(line->v2->x, line->v2->y, portalclipline, &closest_point); - if (closest_point.x != line->v2->x || closest_point.y != line->v2->y) - pass = true; - } - */ + // similar idea than in PortalCheckBBox, but checking the line vertices instead // TODO could make the check more efficient and not check anything if pass==true from earlier or something P_ClosestPointOnLine(line->v1->x, line->v1->y, portalclipline, &closest_point); @@ -3029,19 +2908,7 @@ void HWR_AddLine(seg_t *line) { if (P_PointOnLineSide(line->v2->x, line->v2->y, portalclipline) != portalviewside) pass = true; - }/* - P_ClosestPointOnLine(v1x, v1y, portalclipline, &closest_point); - if (closest_point.x != v1x || closest_point.y != v1y) - { - if (P_PointOnLineSide(v1x, v1y, portalclipline) != portalviewside) - pass = true; } - P_ClosestPointOnLine(v2x, v2y, portalclipline, &closest_point); - if (closest_point.x != v2x || closest_point.y != v2y) - { - if (P_PointOnLineSide(v2x, v2y, portalclipline) != portalviewside) - pass = true; - }*/ if (!pass) return; } @@ -3064,83 +2931,6 @@ void HWR_AddLine(seg_t *line) gr_backsector = line->backsector; - // Portal line -/* - if (cv_grportals.value && line->linedef->special == 40 && line->side == 0) - { - if (portalrender < cv_maxportals.value) - { - // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); - if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); - if (line2 >= 0) // found it! - { - // oh no :DD - if (gr_portal == GRPORTAL_PROCESS) - { - gr_portal = GRPORTAL_FOUND; - return; - } - - // Portal processing - if ((gr_portal == GRPORTAL_MASKING) || (gr_portal == GRPORTAL_INSIDE)) - { - // masking the view 1 - if (gr_portal == GRPORTAL_MASKING) - { - size_t numportal = gr_numportalsegs; - if (numportal < MAX_GRPORTALS) - { - gr_portalsegs[numportal].seg = line; - gr_portalsegs[numportal].frontsector = gr_frontsector; - gr_portalsegs[numportal].backsector = gr_backsector; - gr_numportalsegs++; - } - } - - // Add the portal - HWR_Portal_Add2Lines(line->linedef-lines, line2); - - // masking the view 2 - if (gr_portal == GRPORTAL_MASKING) - { - // portal_cap_gl = last added portal - portal_t *lastportal = portal_cap_gl; - lastportal->drawcount = drawcount++; - - // extend clipping - HWR_DrawPortalClipWall(line->linedef); - - // add cull sector - if (gr_numportalcullsectors < MAX_GRPORTALS) - { - sector_t *cullsec = NULL; - if (lastportal->clipline != -1) - { - line_t *grclipline = &lines[lastportal->clipline]; - cullsec = grclipline->frontsector; - } - gr_portalcullsectors[gr_numportalcullsectors] = cullsec; - gr_numportalcullsectors++; - } - } - } - - gld_clipper_SafeAddClipRange(angle2, angle1); - - if (gr_portal != GRPORTAL_OUTSIDE) - return; - } - } - // Recursed TOO FAR (viewing a portal within a portal) - // So uhhh, render it as a normal wall instead or something ??? - } -#ifndef PORTALSORTING - else if (gr_portal == GRPORTAL_MASKING) - return; -#endif -*/ if (line->linedef->special == 40) { if (line->side == 0) @@ -3947,7 +3737,7 @@ skip_stuff_for_portals: // use returned value as multiplier for the added values from p_thrust thing // P_InterceptVector needs divlines which need dx and dy, dx=x2-x1 dy=y2-y1 -boolean HWR_PortalCheckBBox(fixed_t *bspcoord) +static boolean HWR_PortalCheckBBox(fixed_t *bspcoord) { vertex_t closest_point; if (!portalclipline) @@ -4020,10 +3810,6 @@ void HWR_RenderBSPNode(INT32 bspnum) return; } - // in portal checking phase we can stop after one is found - //if (gr_portal == GRPORTAL_FOUND) - // return; - // Decide which side the view point is on. side = R_PointOnSide(viewx, viewy, bsp); @@ -4031,10 +3817,6 @@ void HWR_RenderBSPNode(INT32 bspnum) if (HWR_PortalCheckBBox(bsp->bbox[side])) HWR_RenderBSPNode(bsp->children[side]); - // in portal checking phase we can stop after one is found - //if (gr_portal == GRPORTAL_FOUND) - // return; - // Possibly divide back space. if (HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1])) HWR_RenderBSPNode(bsp->children[side^1]); @@ -5518,7 +5300,6 @@ void HWR_ProjectSprite(mobj_t *thing) angle_t ang; const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; - vector3_t pos; fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; @@ -6142,7 +5923,7 @@ void HWR_ClearClipper(void) } // Adds an entry to the clipper for portal rendering -void HWR_PortalClipping(portal_t *portal) +static void HWR_PortalClipping(gl_portal_t *portal) { angle_t angle1, angle2; @@ -6158,11 +5939,11 @@ void HWR_PortalClipping(portal_t *portal) // // Render portals recursively depth first. With portals disabled only current scene is rendered. // -void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) +static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { - portallist_t portallist; - portal_t *portal; - portal_t *portal_temp; + gl_portallist_t portallist; + gl_portal_t *portal; + gl_portal_t *gl_portal_temp; portallist.base = portallist.cap = NULL; const boolean skybox = (skyboxmo[0] && cv_skybox.value); @@ -6205,8 +5986,8 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * } // go to portal frame HWR_PortalFrame(portal); - // call RecursivePortalRendering - RecursivePortalRendering(portal, fpov, player, stencil_level + 1, true); + // call HWR_RenderViewpoint + HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); // return to current frame if (rootportal) HWR_PortalFrame(rootportal); @@ -6282,14 +6063,14 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. // This fixes specific effects not working, such as horizon lines. - int oldportal_state = gr_portal; + int oldgl_portal_state = gr_portal; if (gr_portal != GRPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans gr_portal = GRPORTAL_INSIDE; // TURN IT OFF // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); // woo we back - gr_portal = oldportal_state; + gr_portal = oldgl_portal_state; PS_STOP_TIMING(ps_bsptime); @@ -6330,12 +6111,12 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_RenderDrawNodes(); } // free memory from portal list allocated by calls to Add2Lines - portal_temp = portallist.base; - while (portal_temp) + gl_portal_temp = portallist.base; + while (gl_portal_temp) { - portal_t *nextportal = portal_temp->next; - Z_Free(portal_temp); - portal_temp = nextportal; + gl_portal_t *nextportal = gl_portal_temp->next; + Z_Free(gl_portal_temp); + gl_portal_temp = nextportal; } // TODO: batching at some point @@ -6348,7 +6129,6 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * // ========================================================================== void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) { - angle_t a1; const float fpov = FIXED_TO_FLOAT(cv_fov.value+player->fovadd); postimg_t *postprocessor = &postimgtype[0]; INT32 i; @@ -6466,7 +6246,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) validcount++; portalclipline = NULL; - RecursivePortalRendering(NULL, fpov, player, 0, !skybox); + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); HWR_SetTransform(fpov, player);// not sure if needed // Unset transform and shader @@ -6485,26 +6265,6 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } -void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, player_t *player) -{ - portalrender = portal->pass; // Recursiveness depth. - - // Apply the viewpoint stored for the portal. - HWR_PortalFrame(portal); - HWR_ClearClipper(); - HWR_ClearSprites(); - HWR_SetTransform(fpov, player); - validcount++; - - // Render the BSP from the new viewpoint. - portalcullsector = gr_portalcullsectors[portalnum]; - HWR_RenderBSPNode((INT32)numnodes - 1); - - HWR_SortVisSprites(); - HWR_DrawSprites(); - HWR_RenderDrawNodes(); -} - // ========================================================================== // Render the player view. // ========================================================================== -- 2.54.0 From c7c645de00a838c35798790f08c15193f77c91e6 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Thu, 21 Dec 2023 14:52:12 +0800 Subject: [PATCH 03/35] Portal code cleanup --- src/hardware/hw_main.c | 149 +++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b760c2a6f..439d08b9c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5936,9 +5936,79 @@ static void HWR_PortalClipping(gl_portal_t *portal) gld_clipper_SafeAddClipRange(angle2, angle1); } -// -// Render portals recursively depth first. With portals disabled only current scene is rendered. -// +enum +{ + HWR_STENCIL_NORMAL, + HWR_STENCIL_BEGIN, + HWR_STENCIL_REVERSE, + HWR_STENCIL_DEPTH, + HWR_STENCIL_SKY +}; + +// Changes the current stencil state. +static void HWR_SetStencilState(int state, int level) +{ + if (!cv_nostencil.value && level > -1) + HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, level); + HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, state); +} + +// Renders a portal segment. +static void HWR_RenderPortalSeg(gl_portal_t* portal, int state) +{ + gl_drawing_stencil = true; // do not draw outside of the stencil buffer, idiot. + // set our portal state and prepare to render the seg + gr_portal = state; + gr_curline = portal->seg; + gr_frontsector = portal->seg->frontsector; + gr_backsector = portal->seg->backsector; + HWR_ProcessSeg(); + gl_drawing_stencil = false; + // need to work around the r_opengl PF_Invisible bug with this call + // similarly as in the linkdraw hack in HWR_DrawSprites + HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); +} + +// Renders the current viewpoint, though takes portal arguments for recursive portals. +static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); + +// Renders a single portal from the current viewpoint. +static void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level) +{ + // draw portal seg to stencil buffer with increment + HWR_SetTransform(fpov, player); + HWR_ClearClipper(); + + HWR_SetStencilState(HWR_STENCIL_BEGIN, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_STENCIL); + + // go to portal frame lmao + HWR_PortalFrame(portal); + // call HWR_RenderViewpoint + HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); + // return to current frame + if (rootportal) + HWR_PortalFrame(rootportal); + else // current frame is not a portal frame but the main view! + { + R_SetupFrame(player, false); + portalclipline = NULL; + } + + // remove portal seg from stencil buffer + HWR_SetTransform(fpov, player); + HWR_ClearClipper(); + + HWR_SetStencilState(HWR_STENCIL_REVERSE, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_STENCIL); + + // draw portal seg to depth buffer + HWR_ClearClipper(); + HWR_SetStencilState(HWR_STENCIL_DEPTH, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_DEPTH); +} + +// Renders the current viewpoint, though takes portal arguments for recursive portals. static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; @@ -5967,75 +6037,14 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe { if (cv_portalline.value && cv_portalline.value != portal->startline) continue; - if (!cv_nostencil.value) - { - // draw portal seg to stencil buffer with increment - HWR_SetTransform(fpov, player); - HWR_ClearClipper(); - gl_drawing_stencil = true; - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_STENCIL_SEGS); - gr_portal = GRPORTAL_STENCIL; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); - } - // go to portal frame - HWR_PortalFrame(portal); - // call HWR_RenderViewpoint - HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); - // return to current frame - if (rootportal) - HWR_PortalFrame(rootportal); - else// current frame is not a portal frame but the main view! - { - R_SetupFrame(player, false); - portalclipline = NULL; - } - if (!cv_nostencil.value) - { - // remove portal seg from stencil buffer - HWR_SetTransform(fpov, player); - HWR_ClearClipper(); - gl_drawing_stencil = true; - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_STENCIL_REVERSE_SEGS); - gr_portal = GRPORTAL_STENCIL; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); - } - // draw portal seg to depth buffer - HWR_ClearClipper(); - gl_drawing_stencil = true; - if (!cv_nostencil.value) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_DEPTH_SEGS); - gr_portal = GRPORTAL_DEPTH; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); + HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); } gr_portal = GRPORTAL_INSIDE;// when portal walls are encountered in following bsp traversal, nothing should be drawn } else gr_portal = GRPORTAL_OFF;// there may be portals and they need to be drawn as regural walls // draw normal things in current frame in current incremented stencil buffer area - if (!cv_nostencil.value) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); if (!cv_portalonly.value || rootportal) { HWR_ClearClipper(); @@ -6083,15 +6092,13 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe } if (skyWallVertexArraySize)// if there are skywalls to draw using the alternate method { - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_SKY_STENCIL_SEGS); + HWR_SetStencilState(HWR_STENCIL_SKY, -1); HWR_DrawSkyWallList(); HWR_SkyWallList_Clear(); - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, 1); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); drewsky = false; HWR_DrawSkyBackground(fpov); - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, 0); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); HWD.pfnClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer HWR_SetTransform(fpov, player);// restore transform } -- 2.54.0 From 8dcdbecf0c9937dc5e28935b25c84fbd599f07b6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:01:27 +0100 Subject: [PATCH 04/35] fix may be unitialized warning --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 439d08b9c..d56bc94ac 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2314,7 +2314,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { ffloor_t * rover; fixed_t highcut = 0, lowcut = 0; - fixed_t lowcutslope, highcutslope; + fixed_t lowcutslope = 0, highcutslope = 0; // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1; -- 2.54.0 From d07e7ade4a6bf67e943378a57a2580c3e6e70c68 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:18:20 +0100 Subject: [PATCH 05/35] this does absolutely nothing leftover from porting musictest --- src/s_sound.c | 13 ------------- src/s_sound.h | 1 - 2 files changed, 14 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index ffe18d492..4be55a8a0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1323,19 +1323,6 @@ static UINT32 queue_fadeinms; musicdef_t *musicdefstart = NULL; // First music definition struct cursongcredit cursongcredit; // Currently displayed song credit info -musicdef_t soundtestsfx = { - "_STSFX", // prevents exactly one valid track name from being used on the sound test - "Sound Effects", - "", - "SEGA, Sonic Team Jr, other sources", - 1, // show on soundtest page 1 - 0, // with no conditions - 0, - 0, - false, - NULL -}; - // // search for music definition in wad // diff --git a/src/s_sound.h b/src/s_sound.h index 5cfe937ea..72d4bd38d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -172,7 +172,6 @@ typedef struct musicdef_s struct musicdef_s *next; } musicdef_t; -extern musicdef_t soundtestsfx; extern musicdef_t *musicdefstart; extern musicdef_t **soundtestdefs; extern INT32 numsoundtestdefs; -- 2.54.0 From 0dca9f9537fb7d1ab049f5dc564ead88cda7d33e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:22:19 +0100 Subject: [PATCH 06/35] use the bool brap --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d56bc94ac..f749be289 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4113,7 +4113,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts // do interpolation if (R_UsingFrameInterpolation() && !paused) { - if (spr->precip) + if (precip) { R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, rendertimefrac, &interp); } @@ -4124,7 +4124,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts } else { - if (spr->precip) + if (precip) { R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, FRACUNIT, &interp); } -- 2.54.0 From f7f3b6497b62701b1433592c2be5469d244b898d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 10:08:57 +0100 Subject: [PATCH 07/35] fix palshader compiler warning + other stuff asdfgfagregar set a gl special state instead of using the boolean in r_opengl also move hwr_ code out of setshaders --- src/hardware/hw_defs.h | 2 +- src/hardware/hw_drv.h | 2 ++ src/hardware/hw_main.c | 14 +++++++++++--- src/hardware/hw_main.h | 1 + src/hardware/r_opengl/r_opengl.c | 30 +++++++++++++++--------------- src/hardware/r_opengl/r_opengl.h | 1 - src/sdl/hwsym_sdl.c | 1 + src/sdl/i_video.c | 1 + src/v_video.c | 4 ++-- 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 4c682b2eb..0275f7c2c 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -232,7 +232,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { HWD_SET_SHADERS, - HWD_SET_PALETTE_SHADER_ENABLED, + HWD_PAL_SHADER, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 42183a015..b231e76c4 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -84,6 +84,7 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void); EXPORT void HWRAPI(StartBatching) (void); EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); +EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut); EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable); EXPORT void HWRAPI(ClearLightTableCache) (void); @@ -138,6 +139,7 @@ struct hwdriver_s StartBatching pfnStartBatching; RenderBatches pfnRenderBatches; + InitPalette pfnInitPalette; AddLightTable pfnAddLightTable; ClearLightTableCache pfnClearLightTableCache; }; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f749be289..bc5888b2e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -183,9 +183,9 @@ static void CV_grshaders_OnChange(void) if (rendermode == render_opengl) { if (HWR_ShouldUsePaletteRendering()) - { - InitPalette(0, false); - } + HWR_InitPalette(0, false); + + HWD.pfnSetSpecialState(HWD_PAL_SHADER, HWR_ShouldUsePaletteRendering()); V_SetPalette(0); } @@ -197,6 +197,9 @@ static void CV_useCustomShaders_ONChange(void) { if (HWR_UseShader()) HWD.pfnInitCustomShaders(); + + if (HWR_ShouldUsePaletteRendering()) + HWR_InitPalette(0, false); } } @@ -207,6 +210,11 @@ static void CV_Gammaxxx_ONChange(void) V_SetPalette(0); } +void HWR_InitPalette(int flashnum, boolean skiplut) +{ + HWD.pfnInitPalette(flashnum, skiplut); +} + // ========================================================================== // Globals diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 1b259e5e7..3dc18ccf8 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -114,6 +114,7 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum); void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); void HWR_MakeScreenFinalTexture(void); void HWR_DrawScreenFinalTexture(int width, int height); +void HWR_InitPalette(int flashnum, boolean skiplut); // hw_main.c: Planes void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index cf10c059f..d489306f9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -638,6 +638,7 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; boolean gl_palette_initialized = false; +static boolean gl_palshader = false; static INT32 gl_enable_screen_textures = 1; @@ -1286,11 +1287,6 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void) #ifdef GL_SHADERS KillShaders(); return LoadShaders(); - - if (HWR_ShouldUsePaletteRendering()) - { - InitPalette(0, false); - } #endif } @@ -1340,7 +1336,7 @@ GLuint palette_tex_num; // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -void InitPalette(int flashnum, boolean skiplut) +EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut) { int i, r, g, b; @@ -1805,7 +1801,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too - if ((!gl_palette_initialized) && (HWR_ShouldUsePaletteRendering())) + if ((!gl_palette_initialized) && (gl_palshader)) InitPalette(0, false); // just gonna put this here for now } @@ -2428,7 +2424,7 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { diff = poly1->surf.LightTableId - poly2->surf.LightTableId; if (diff != 0) return diff; @@ -2571,7 +2567,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i if (gl_allowshaders) { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); @@ -2688,7 +2684,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeState = true; changePolyFlags = true; } - if ((gl_allowshaders) && (HWR_ShouldUsePaletteRendering())) + if (gl_allowshaders && gl_palshader) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2702,7 +2698,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeSurfaceInfo = true; } } - else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering())) + else if ((gl_allowshaders) && (!gl_palshader)) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2833,7 +2829,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); @@ -2944,7 +2940,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; } - if (HWR_ShouldUsePaletteRendering() && gl_allowshaders) + if (gl_palshader && gl_allowshaders) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); @@ -3292,6 +3288,10 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; } break; + + case HWD_PAL_SHADER: + gl_palshader = Value; + break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -4479,7 +4479,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { Shader_SetUniforms(NULL, NULL, NULL, NULL); // prepare shader, if it is enabled @@ -4495,7 +4495,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 8bce7d15b..a65c085a5 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -135,6 +135,5 @@ typedef enum // in order for custom playpals n shit to work properly extern boolean gl_palette_initialized; -void InitPalette(int flashnum, boolean skiplut); #endif diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index a64a11135..96b7b0679 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -118,6 +118,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(StartBatching); GETFUNC(RenderBatches); + GETFUNC(InitPalette); GETFUNC(AddLightTable); GETFUNC(ClearLightTableCache); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5aa4b684c..33ca71e94 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2151,6 +2151,7 @@ void I_StartupGraphics(void) HWD.pfnStartBatching = hwSym("StartBatching",NULL); HWD.pfnRenderBatches = hwSym("RenderBatches",NULL); + HWD.pfnInitPalette = hwSym("InitPalette",NULL); HWD.pfnAddLightTable = hwSym("AddLightTable",NULL); HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL); diff --git a/src/v_video.c b/src/v_video.c index 1fc9be187..6058d8ede 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -207,7 +207,7 @@ void V_SetPalette(INT32 palettenum) { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(palettenum, true); + HWR_InitPalette(palettenum, true); } else HWR_SetPalette(&pLocalPalette[palettenum*256]); @@ -229,7 +229,7 @@ void V_SetPaletteLump(const char *pal) { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(0, false); + HWR_InitPalette(0, false); } HWR_SetPalette(pLocalPalette); -- 2.54.0 From 2a6f551f7aaa2639263d77773393d6f7b2e08f50 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 10:31:45 +0100 Subject: [PATCH 08/35] fix compact fps counter screwing up ping counter offsets in tab rankings AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --- src/hu_stuff.c | 42 +++++++----------------------------------- src/screen.c | 5 +++-- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index e63fceffb..53f3666a0 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2583,50 +2583,22 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) gfxnum = Ping_gfx_num(lag); if (measureid == 1) - { - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+12 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); - }else{ - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - } - } - + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); if (cv_pingicon.value) - { - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+2, y+13, flags, pinggfx[gfxnum]); - }else{ - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); - } - } - + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); if (servermaxping && lag > servermaxping && hu_tick < 4) - { - // flash ping red if too high - colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - } + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high if (cv_pingmeasurement.value) - { lag = (INT32)(lag * (1000.00f / TICRATE)); - } - - if (cv_ticrate.value == 2){ - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+22, flags, lag, colormap); - }else{ - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); - } - if (measureid == 0){ - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); - }else{ + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + + + if (measureid == 0) V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - } - } - } // diff --git a/src/screen.c b/src/screen.c index ee0c76e82..bc787e4b2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -476,7 +476,8 @@ void SCR_DisplayLocalPing(void) if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { - INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, fpsflags); + INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2) ? 172 : 181); + + HU_drawPing(308, dispy, ping, fpsflags); } } -- 2.54.0 From bccc79fe4bd38cf6323fe22eaf88cace4954fb5d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 12:06:31 +0100 Subject: [PATCH 09/35] Kart v1.0/srb2 ping display option well i adjusted it a little and made it compatible with the frame ping stuff just hope the bar stuff is right but seemed so also changed it so the numbers are right alignent so they dont go out of screen aaaa --- src/d_netcmd.c | 6 ++++ src/d_netcmd.h | 1 + src/hu_stuff.c | 90 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 43d7377a7..b15b15526 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -484,6 +484,11 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; +consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; + + consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -795,6 +800,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); CV_RegisterVar(&cv_pingicon); + CV_RegisterVar(&cv_pingstyle); #ifdef SEENAMES CV_RegisterVar(&cv_allowseenames); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 0f44840d8..8fbdf1d5f 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -156,6 +156,7 @@ extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; extern consvar_t cv_pingmeasurement; extern consvar_t cv_pingicon; +extern consvar_t cv_pingstyle; //extern consvar_t cv_smallpos; extern consvar_t cv_showminimapnames; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 53f3666a0..08c2d7c33 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2579,26 +2579,92 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) UINT8 *colormap = NULL; INT32 measureid = cv_pingmeasurement.value ? 1 : 0; INT32 gfxnum; // gfx to draw + + //SRB2/Kart v1.0 style + UINT8 numbars = 0; // how many ping bars do we draw? + UINT8 barcolor = 31; // color we use for the bars (green, yellow, red or black) + SINT8 i = 0; + SINT8 yoffset = 6; + INT32 dx; gfxnum = Ping_gfx_num(lag); - - if (measureid == 1) - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - if (cv_pingicon.value) - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + if (!cv_pingstyle.value) + { + if (measureid == 1) + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + + if (cv_pingicon.value) + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); - if (servermaxping && lag > servermaxping && hu_tick < 4) - colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high + if (servermaxping && lag > servermaxping && hu_tick < 4) + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high - if (cv_pingmeasurement.value) - lag = (INT32)(lag * (1000.00f / TICRATE)); + if (cv_pingmeasurement.value) + lag = (INT32)(lag * (1000.00f / TICRATE)); - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + if (measureid == 0) + V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + } + else if (cv_pingstyle.value) // old style ping + { + if (cv_pingicon.value) + { + if (lag < 4) + { + numbars = 3; + barcolor = 184; + } + else if (lag < 7) + { + numbars = 2; // Apparently ternaries w/ multiple statements don't look good in C so I decided against it. + barcolor = 103; + } + else if (lag < 10) + { + numbars = 1; + barcolor = 155; // need a better red + } + else // brazil + { + numbars = 0; + barcolor = 31; + } + } - if (measureid == 0) - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + if (cv_pingmeasurement.value) + lag = (INT32)(lag * (1000.00f / TICRATE)); + + if (vid.width >= 640) // how sad, we're using a shit resolution. + { + if (measureid == 1) + { + //dx = x+1 - (V_SmallStringWidth(va("%dms", lag), V_ALLOWLOWERCASE|flags)/2); + //V_DrawSmallString(dx, y+4, V_ALLOWLOWERCASE|flags, va("%dms", lag)); + V_DrawRightAlignedSmallString(x+12, y+13, V_ALLOWLOWERCASE|flags, va("%dms", lag)); + } + else if (measureid == 0) + { + //dx = x+1 - (V_SmallStringWidth(va("d%d", lag), flags)/2); + //V_DrawSmallString(dx, y+4, flags, va("d%d", lag)); + V_DrawRightAlignedSmallString(x+12, y+13, flags, va("d%d", lag)); + } + } + + if (cv_pingicon.value) + { + for (i=0; (i<3); i++) // Draw the ping bar + { + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-4, 2, 8-yoffset, 31|flags); + if (i < numbars) + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-3, 1, 8-yoffset-1, barcolor|flags); + + yoffset -= 2; + } + } + } } // -- 2.54.0 From ea3fc8f526415d0bb624af6dcad23635225318f9 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:41:13 +0100 Subject: [PATCH 10/35] Kart v1.0/srb2 styled fps counter option this was so much pain for whatever reason lmao --- src/d_netcmd.c | 1 - src/m_menu.c | 2 +- src/screen.c | 76 +++++++++++++++++++++++++++++++++----------------- src/v_video.c | 2 +- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b15b15526..5cb77bf61 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -488,7 +488,6 @@ consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; - consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/m_menu.c b/src/m_menu.c index 1e0c28352..3e366df68 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1392,7 +1392,7 @@ static const char* OP_VideoTooltips[] = "How far away weather is drawn.", "Toggle being able to see the sky.", "Player field of view.", - "Show current game framerate.", + "Show current game framerate and select the style.", "Sync game framerate to refresh rate of monitor.", "Set manual framerate cap.", "Size of drift spark pulse.", diff --git a/src/screen.c b/src/screen.c index bc787e4b2..06be64abf 100644 --- a/src/screen.c +++ b/src/screen.c @@ -429,41 +429,65 @@ void SCR_DisplayTicRate(void) INT32 x = 318; double fps = round(averageFPS); INT32 fpsflags = SCR_FPSflags(); + const char *fps_string; + + INT32 ticcntcolor2 = 0; if (gamestate == GS_NULL) return; - // draw "FPS" - if (cv_ticrate.value == 1) - V_DrawFixedPatch(306< (benchmark - 5)) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); - else if (fps < 20) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - - if (cap != 0) + // new kart counter + if ((cv_ticrate.value == 1) || (cv_ticrate.value == 2)) { - UINT32 digits = 1; - UINT32 c2 = cap; + // draw "FPS" + if (cv_ticrate.value == 1) + V_DrawFixedPatch(306< (benchmark - 5)) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); + else if (fps < 20) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - while (c2 > 0) + if (cap != 0) { - c2 = c2 / 10; - digits++; + UINT32 digits = 1; + UINT32 c2 = cap; + + while (c2 > 0) + { + c2 = c2 / 10; + digits++; + } + + // draw total frame: + V_DrawPingNum(x, 190, fpsflags, cap, ticcntcolor); + + x -= digits * 4; + + // draw "/" + V_DrawFixedPatch(x< (benchmark - 5)) + ticcntcolor2 = V_GREENMAP; + else if (fps < 20) + ticcntcolor2 = V_REDMAP; - // draw our actual framerate - V_DrawPingNum(x, 190, fpsflags, fps, ticcntcolor); + if (cap != 0) + fps_string = va("%d/%d\x82", (INT32)fps, cap); + else + fps_string = va("%d\x82", (INT32)fps); + + if (cv_ticrate.value == 3) + V_DrawRightAlignedString(319, 181, V_YELLOWMAP|fpsflags, "FPS"); + + V_DrawRightAlignedString(319, 190, ticcntcolor2|fpsflags, fps_string); + } } // SCR_DisplayLocalPing @@ -476,8 +500,8 @@ void SCR_DisplayLocalPing(void) if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { - INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2) ? 172 : 181); - + INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2 || cv_ticrate.value == 4) ? 172 : ((cv_ticrate.value == 3) ? 163 : 181)); // absolute buttpain + HU_drawPing(308, dispy, ping, fpsflags); } } diff --git a/src/v_video.c b/src/v_video.c index 6058d8ede..d6c8831bf 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -42,7 +42,7 @@ UINT8 *screens[5]; static CV_PossibleValue_t gamma_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; static void CV_usegamma_OnChange(void); -static CV_PossibleValue_t fps_cons_t[] = {{0, "No"}, {1, "Normal"}, {2, "Compact"}, {0, NULL}}; +static CV_PossibleValue_t fps_cons_t[] = {{0, "No"}, {1, "Normal"}, {2, "Compact"}, {3, "Old"}, {4, "Old Compact"}, {0, NULL}}; consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; -- 2.54.0 From 0a38a2fd899d0cb87931679d376bf6af4437a3ab Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:41:52 +0100 Subject: [PATCH 11/35] forgor to add ping display stuff to menu someone pls make a better tooltip i bed ingles --- src/m_menu.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 3e366df68..3187d9219 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1762,23 +1762,24 @@ static menuitem_t OP_HUDOptionsMenu[] = static menuitem_t OP_ChatOptionsMenu[] = { // will ANYONE who doesn't know how to use the console want to touch this one? - {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 10}, // nonetheless... + {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 5}, // nonetheless... {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Chat Box Width", &cv_chatwidth, 25}, + NULL, "Chat Box Width", &cv_chatwidth, 20}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Chat Box Height", &cv_chatheight, 35}, + NULL, "Chat Box Height", &cv_chatheight, 30}, - {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 50}, - {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 60}, - {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70}, - {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, + {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 45}, + {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 55}, + {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 65}, + {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 75}, - {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. - {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 110}, - {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 120}, - - {IT_STRING | IT_CVAR, NULL, "Show IP addresses in playerlist", &cv_shownodeip, 140}, + {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 95}, // shows ping above the framerate if we want to. + {IT_STRING | IT_CVAR, NULL, "Ping display style", &cv_pingstyle, 105}, + {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 115}, + {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 125}, + + {IT_STRING | IT_CVAR, NULL, "Show IP address in playerlist", &cv_shownodeip, 135}, }; static const char* OP_ChatOptionsTooltips[] = @@ -1791,6 +1792,7 @@ static const char* OP_ChatOptionsTooltips[] = "Spam protection for in-game chat.", "Maxiumum amount of chat messages to look back at.", "Show player ping.", + "Choose the looks of the ping display.", // this is ass idk english lmao "Measurement used for ping.", "Visibility of ping icon.", "Should Player IP addresses be printed when using\nthe nodes or listplayers command?", -- 2.54.0 From b87b55ec453ea9cdddfef3b6b3caa4350b377097 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:42:05 +0100 Subject: [PATCH 12/35] fix compiler warning --- src/v_video.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/v_video.c b/src/v_video.c index d6c8831bf..894037cab 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -20,6 +20,8 @@ #include "r_draw.h" #include "console.h" +#include "r_fps.h" //vhs effect stuff + #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h" -- 2.54.0 From 1b8b92925ae78ced1f5cd01d971886a93d497891 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 22 Dec 2023 15:51:05 +0300 Subject: [PATCH 13/35] Add files for flatpak package (by riomccloud) --- org.srb2.SRB2Kart-Saturn.desktop | 20 +++++++ org.srb2.SRB2Kart-Saturn.metainfo.xml | 80 +++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 org.srb2.SRB2Kart-Saturn.desktop create mode 100644 org.srb2.SRB2Kart-Saturn.metainfo.xml diff --git a/org.srb2.SRB2Kart-Saturn.desktop b/org.srb2.SRB2Kart-Saturn.desktop new file mode 100644 index 000000000..e0282b90f --- /dev/null +++ b/org.srb2.SRB2Kart-Saturn.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Sonic Robo Blast 2 Kart Saturn +Comment=A kart racing mod based on the 3D Sonic the Hedgehog fangame Sonic Robo Blast 2 +TryExec=srb2kart.sh +Exec=srb2kart.sh +Icon=org.srb2.SRB2Kart-Saturn +Terminal=false +Categories=Game;SportsGame; +Keywords=kart;sonic;racer;multiplayer;doom; +Actions=OpenGL;Software; + +[Desktop Action OpenGL] +Name=OpenGL renderer +Exec=srb2kart.sh -opengl + +[Desktop Action Software] +Name=Software renderer +Exec=srb2kart.sh -software diff --git a/org.srb2.SRB2Kart-Saturn.metainfo.xml b/org.srb2.SRB2Kart-Saturn.metainfo.xml new file mode 100644 index 000000000..54c1de8b2 --- /dev/null +++ b/org.srb2.SRB2Kart-Saturn.metainfo.xml @@ -0,0 +1,80 @@ + + + + org.srb2.SRB2Kart-Saturn + FSFAP + GPL-2.0+ + Sonic Robo Blast 2 Kart Saturn + Modded SRB2Kart adding many custom features + +

+ A modded net-compatible version of SRB2Kart v1.6 that offers multiple code optimizations, palette rendering, player sprite rotation, base Kart HUD customization, and many more. +

+
+ org.srb2.SRB2Kart-Saturn.desktop + + + https://wiki.srb2.org/w/images/a/ac/Srb2kart_title.png + Title screen + + + https://user-images.githubusercontent.com/15758649/227740700-26e0962b-5572-486c-b633-7d4990d86f89.png + Game modes + + + https://user-images.githubusercontent.com/1964655/82821921-3d180c00-9ea5-11ea-937b-e1f53fe6c686.png + Game play as Sonic + + + https://user-images.githubusercontent.com/1964655/82821933-41442980-9ea5-11ea-9146-38998161edae.png + Game play as Tails + + + https://user-images.githubusercontent.com/1964655/82821966-502adc00-9ea5-11ea-9cbd-274d7adb479e.png + Game play as Eggman + + + https://user-images.githubusercontent.com/1964655/82821980-5620bd00-9ea5-11ea-9eec-2835ebb2a262.png + Game play as Metal Sonic + + + https://github.com/Indev450/SRB2Kart-Saturn + https://github.com/Indev450/SRB2Kart-Saturn/issues + Indev450 + + srb2kart + + + + +

The complete changelog can be found on the build's GitHub repository.

+
+ https://github.com/Indev450/SRB2Kart-Saturn/releases/tag/v5.1 +
+ + +

The complete changelog can be found on the build's GitHub repository.

+
+ https://github.com/Indev450/SRB2Kart-Saturn/releases/tag/v5 +
+
+ + Game + SportsGame + + + keyboard + gamepad + + + moderate + mild + intense + mild + + + doom + multiplayer + racing + +
-- 2.54.0 From 37187c7753a5f4b83769abba05fd77585e0f5524 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 22 Dec 2023 20:20:06 +0100 Subject: [PATCH 14/35] fix pal water shader --- src/hardware/r_opengl/r_opengl.c | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d489306f9..e4a55d63d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -850,33 +850,34 @@ static float shader_leveltime = 0; "}\0" #define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ + "const float freq = 0.025;\n" \ + "const float amp = 0.025;\n" \ + "const float speed = 2.0;\n" \ + "const float pi = 3.14159;\n" \ "uniform sampler2D tex;\n" \ - "uniform sampler2D lighttable_tex;\n" \ + "uniform sampler2D lighttable_tex;\n" \ "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ "uniform vec4 poly_color;\n" \ "uniform float lighting;\n" \ "uniform float leveltime;\n" \ - "const float freq = 0.025;\n" \ - "const float amp = 0.025;\n" \ - "const float speed = 2.0;\n" \ - "const float pi = 3.14159;\n" \ GLSL_DOOM_COLORMAP_floors \ "void main(void) {\n" \ - "float z = (gl_FragCoord.z / gl_FragCoord.w) / 2.0;\n" \ - "float a = -pi * (z * freq) + (leveltime * speed);\n" \ - "float sdistort = sin(a) * amp;\n" \ - "float cdistort = cos(a) * amp;\n" \ - "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" \ - "int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ - "int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \ - "vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \ - "int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \ + "float water_z = (gl_FragCoord.z / gl_FragCoord.w) / 2.0;\n" \ + "float a = -pi * (water_z * freq) + (leveltime * speed);\n" \ + "float sdistort = sin(a) * amp;\n" \ + "float cdistort = cos(a) * amp;\n" \ + "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" \ + "int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ + "int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \ + "vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \ + "int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \ "vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \ "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ "}\0" - + // // Fog block shader // @@ -1434,6 +1435,12 @@ EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut) // bind tex unit 2 to lighttable tex pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_lighttable_tex], 2); pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_color_lookup], 1); + // bind stuff to wöter shader + pglUseProgram(gl_shaderprograms[11].program); + pglUniform1iv(gl_shaderprograms[11].uniforms[gluniform_palette], 768, gl_palette); + pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_lighttable_tex], 2); + pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_color_lookup], 1); + pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); -- 2.54.0 From 590440ff8262f4fcb3fa64312de6c05bbf06b61e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 22 Dec 2023 22:54:33 +0100 Subject: [PATCH 15/35] make palshader a little more accurate --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e4a55d63d..c679a466c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -910,7 +910,7 @@ static float shader_leveltime = 0; "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" -- 2.54.0 From 3297a885eb6773fcbde248bd59eb09494cf5da67 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 23 Dec 2023 22:24:13 +0300 Subject: [PATCH 16/35] Remove args.h from src/CMakeLists.txt --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f47bbdb6..3bcc54e9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,6 @@ set(SRB2_CORE_SOURCES set(SRB2_CORE_HEADERS am_map.h - args.h b_bot.h byteptr.h command.h -- 2.54.0 From 1a6893289c89dc48347a96e3158c4698b624208e Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 23 Dec 2023 22:29:02 +0300 Subject: [PATCH 17/35] Remove p5prof.h from src/CMakeLists.txt --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3bcc54e9d..8f6a56235 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -105,7 +105,6 @@ set(SRB2_CORE_HEADERS m_swap.h md5.h mserv.h - p5prof.h s_sound.h screen.h sounds.h -- 2.54.0 From 405de4e597dcb111e4977bf1bbf0244e95995b01 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 23 Dec 2023 20:36:35 +0100 Subject: [PATCH 18/35] remove asm leftovers - profiling stuff --- src/r_plane.c | 21 --------------------- src/r_segs.c | 27 --------------------------- 2 files changed, 48 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 3578bd7b4..beb551963 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -29,13 +29,6 @@ #include "p_tick.h" #include "r_fps.h" -#ifdef TIMING -#include "p5prof.h" - INT64 mycount; - INT64 mytotal = 0; - UINT32 nombre = 100000; -#endif - // // opening // @@ -339,20 +332,6 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) ds_y = y; ds_x1 = x1; ds_x2 = x2; - - // profile drawer -#ifdef TIMING - ProfZeroTimer(); -#endif - - spanfunc(); - -#ifdef TIMING - RDMSR(0x10, &mycount); - mytotal += mycount; // 64bit add - if (!(nombre--)) - I_Error("spanfunc() CPU Spy reports: 0x%d %d\n", *((INT32 *)&mytotal+1), (INT32)mytotal); -#endif } // diff --git a/src/r_segs.c b/src/r_segs.c index 0c4e1d763..4623d3b0e 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1248,19 +1248,6 @@ static boolean R_FFloorCanClip(visffloor_t *pfloor) #define HEIGHTBITS 12 #define HEIGHTUNIT (1<>FRACBITS; - - //profile stuff --------------------------------------------------------- -#ifdef TIMING - ProfZeroTimer(); -#endif colfunc(); -#ifdef TIMING - RDMSR(0x10,&mycount); - mytotal += mycount; //64bit add - - if (nombre--==0) - I_Error("R_DrawColumn CPU Spy reports: 0x%d %d\n", *((INT32 *)&mytotal+1), - (INT32)mytotal); -#endif - //profile stuff --------------------------------------------------------- // dont draw anything more for this column, since // a midtexture blocks the view -- 2.54.0 From 142d678e8ca51132c402662d9750860858270e9d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 23 Dec 2023 20:42:11 +0100 Subject: [PATCH 19/35] oops --- src/r_plane.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_plane.c b/src/r_plane.c index beb551963..590ea32a2 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -332,6 +332,8 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) ds_y = y; ds_x1 = x1; ds_x2 = x2; + + spanfunc(); } // -- 2.54.0 From 134364eee3dc2d3d2094c5269ea79af5eccc7900 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 24 Dec 2023 20:51:16 +0300 Subject: [PATCH 20/35] Always load vanilla musicdefs --- src/d_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 257402ed2..3850243b8 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1641,10 +1641,11 @@ void D_SRB2Main(void) I_StartupSound(); I_InitMusic(); S_InitSfxChannels(cv_soundvolume.value); - S_InitMusicDefs(); - S_InitMTDefs(); } + S_InitMusicDefs(); + S_InitMTDefs(); + CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); -- 2.54.0 From a926cdf7c11d96252d583bf36323902506206848 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 24 Dec 2023 18:54:10 +0100 Subject: [PATCH 21/35] add translucency support to V_Drawfill ayeyeerasyedasaedysase i really hope the software version doesent break aaaaaaaaa --- src/hardware/hw_draw.c | 14 ++++++++++++-- src/v_video.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index cfb9fae2c..c2fad85a3 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -960,11 +960,13 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 // -----------------+ // HWR_DrawFill : draw flat coloured rectangle, with no texture // -----------------+ +// alug: now with translucency support X) void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) { FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh; + UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT); if (w < 0 || h < 0) return; // consistency w/ software @@ -1061,8 +1063,16 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) Surf.PolyColor = V_GetColor(color); - HWD.pfnDrawPolygon(&Surf, v, 4, - PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); + if ((alphalevel) && (!(alphalevel >= 10 && alphalevel < 13))) + { + if (alphalevel == 13) Surf.PolyColor.s.alpha = softwaretranstogl_lo[hudtrans]; + else if (alphalevel == 14) Surf.PolyColor.s.alpha = softwaretranstogl[hudtrans]; + else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; + else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); + } + else + HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); } #ifdef HAVE_PNG diff --git a/src/v_video.c b/src/v_video.c index 894037cab..28a02bcff 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -695,10 +695,13 @@ void V_DrawBlock(INT32 x, INT32 y, INT32 scrn, INT32 width, INT32 height, const // // Fills a box of pixels with a single color, NOTE: scaled to screen size // +// alug: now with translucency support X) void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) { UINT8 *dest; const UINT8 *deststop; + INT32 u, v; + UINT32 alphalevel = 0; if (rendermode == render_none) return; @@ -752,6 +755,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (x >= vid.width || y >= vid.height) return; // off the screen + if (x < 0) { w += x; @@ -765,18 +769,45 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (w <= 0 || h <= 0) return; // zero width/height wouldn't draw anything + if (x + w > vid.width) - w = vid.width - x; + w = vid.width-x; if (y + h > vid.height) - h = vid.height - y; + h = vid.height-y; dest = screens[0] + y*vid.width + x; deststop = screens[0] + vid.rowbytes * vid.height; + if ((alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT))) + { + if (alphalevel == 13) + alphalevel = hudminusalpha[cv_translucenthud.value]; + else if (alphalevel == 14) + alphalevel = 10 - cv_translucenthud.value; + else if (alphalevel == 15) + alphalevel = hudplusalpha[cv_translucenthud.value]; + + if (alphalevel >= 10) + return; // invis + } + c &= 255; - for (;(--h >= 0) && dest < deststop; dest += vid.width) - memset(dest, c, w * vid.bpp); + if (!alphalevel) { + for (;(--h >= 0) && dest < deststop; dest += vid.width) + memset(dest, c, w * vid.bpp); + } else { // holy fuck i hope this doesent break lmao + const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<y) ? y : x + w = clip(w,vid.width); + h = clip(h,vid.height); +#undef clip + for (v = 0; v < h; v++, dest += vid.width) { + for (u = 0; u < w; u++) { + dest[u] = fadetable[dest[u]]; + } + } + } } #ifdef HWRENDER -- 2.54.0 From 0e12ad0189179fc3da793f57f2d5dd8a8464b09b Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 24 Dec 2023 21:40:15 +0300 Subject: [PATCH 22/35] Fix HWR_DrawFill ignoring transparency levels 10-13 --- src/hardware/hw_draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index c2fad85a3..5aa2ae312 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1063,7 +1063,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) Surf.PolyColor = V_GetColor(color); - if ((alphalevel) && (!(alphalevel >= 10 && alphalevel < 13))) + if (alphalevel) { if (alphalevel == 13) Surf.PolyColor.s.alpha = softwaretranstogl_lo[hudtrans]; else if (alphalevel == 14) Surf.PolyColor.s.alpha = softwaretranstogl[hudtrans]; -- 2.54.0 From ca288b89b3b39c54a93300d850425e6717dc0c6d Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Dec 2023 13:10:48 +0100 Subject: [PATCH 23/35] why do that twice? --- src/hardware/hw_cache.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index bfd5fa26d..4255475bb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -672,14 +672,6 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) grmip->colormap += (256*32); #endif - grmip->colormap = colormaps; - -#ifdef GLENCORE - if (!noencoremap && encoremap) - grmip->colormap += (256*32); -#endif - - if (!grmip->downloaded && !grmip->grInfo.data) HWR_CacheFlat(grmip, flatlumpnum); -- 2.54.0 From 8e6023d85060a82b0311a3e862b56f53d6440272 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Dec 2023 13:11:08 +0100 Subject: [PATCH 24/35] invert encore remap is 12 not 15? is it? --- src/r_bsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index f0dcbd80e..795ef459c 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -39,7 +39,7 @@ INT32 doorclosed; boolean R_NoEncore(sector_t *sector, boolean ceiling) { - boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15); + boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 12); #if 0 // perfect implementation INT32 val = GETSECSPECIAL(sector->special, 3); if (val != 1 && val != 3 // spring panel -- 2.54.0 From 647641214a0410a3a47bdb9e8738f69b0cabeb91 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Dec 2023 13:30:09 +0100 Subject: [PATCH 25/35] try and cleanup sector special comments a little --- src/p_spec.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index bba01ed0e..dc2ea796d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3627,8 +3627,8 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers case 5: // Spikes // Don't do anything. In Soviet Russia, spikes find you. break; - case 6: // Death Pit (Camera Mod) - case 7: // Death Pit (No Camera Mod) + case 6: // Death Pit (Camera Tilt) + case 7: // Death Pit (No Camera Tilt) if (roversector || P_MobjReadyToTrigger(player->mo, sector)) P_DamageMobj(player->mo, NULL, NULL, 10000); break; @@ -3685,8 +3685,8 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers { case 1: // Trigger Linedef Exec (Pushable Objects) break; - case 2: // Linedef executor requires all players present+doesn't require touching floor - case 3: // Linedef executor requires all players present + case 2: // Linedef executor requires all players present+doesn't require touching floor // Trigger Linedef Exec (Anywhere, All Players) + case 3: // Linedef executor requires all players present // Trigger Linedef Exec (Floor Touch, All Players) /// \todo check continues for proper splitscreen support? for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && !players[i].bot && players[i].mo && (gametype != GT_COOP || players[i].lives > 0)) @@ -3743,16 +3743,16 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers } } /* FALLTHRU */ - case 4: // Linedef executor that doesn't require touching floor - case 5: // Linedef executor - case 6: // Linedef executor (7 Emeralds) - case 7: // Linedef executor (NiGHTS Mare) + case 4: // Linedef executor that doesn't require touching floor // Trigger Linedef Exec (Anywhere in Sector) + case 5: // Linedef executor // Trigger Linedef Exec (Floor Touch) + case 6: // Linedef executor (7 Emeralds) // unused + case 7: // SRB2kart: Linedef executor (Race Lap) if (!player->bot) P_LinedefExecute(sector->tag, player->mo, sector); break; - case 8: // Tells pushable things to check FOFs + case 8: // Tells pushable things to check FOFs // Check for Linedef Executor on FOFs break; - case 9: // Egg trap capsule + case 9: // Egg trap capsule // unused { thinker_t *th; mobj_t *mo2; @@ -3792,12 +3792,12 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers P_DoPlayerExit(&players[i]); break; } - case 10: // Special Stage Time/Rings + case 10: // Special Stage Time/Rings // unused case 11: // Custom Gravity break; - case 12: // Lua sector special + case 12: // SRB2kart: Invert Encore Remap break; - case 15: // Invert Encore Remap + case 15: // no idea but keep it dont want anything to break break; } DoneSection2: -- 2.54.0 From ea49c2a5575137ae789c6a5488896115be09e9a5 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 29 Dec 2023 20:58:39 +0300 Subject: [PATCH 26/35] Fix 'Add local skins...' position in pause menu for remote admins --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 3187d9219..0b3d39a50 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4126,7 +4126,7 @@ void M_StartControlPanel(void) MPauseMenu[mpause_addons].alphaKey = 8; if (IsPlayerAdmin(consoleplayer)) - MPauseMenu[mpause_addlocalskins].alphaKey = 8; + MPauseMenu[mpause_addlocalskins].alphaKey = 16; else MPauseMenu[mpause_addlocalskins].alphaKey = 24; -- 2.54.0 From 9a1883cd6623b5b65fb4978f3a6f0748774a3476 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 31 Dec 2023 03:01:03 +0100 Subject: [PATCH 27/35] duh --- src/k_kart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/k_kart.c b/src/k_kart.c index c44c0398d..e9a1dbe7a 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8718,6 +8718,7 @@ static void K_drawKartSpeedometer(void) V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d P", convSpeed)); else V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d %%", convSpeed)); + break; } } else if (cv_newspeedometer.value == 2 && snw_speedo) // why bother if we dont? -- 2.54.0 From 728cf1eca9f3bc6add879c8002f06fc01aeed478 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 31 Dec 2023 03:46:07 +0100 Subject: [PATCH 28/35] switches should have default i think ug --- src/k_kart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index e9a1dbe7a..4d10d9b64 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8719,6 +8719,8 @@ static void K_drawKartSpeedometer(void) else V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d %%", convSpeed)); break; + default: + break; } } else if (cv_newspeedometer.value == 2 && snw_speedo) // why bother if we dont? -- 2.54.0 From 7a4d5ac1c1a311393797dddd13c93cab1edbe31a Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 13:21:23 -0500 Subject: [PATCH 29/35] Add ``cv_sparkroll`` --- src/g_game.c | 2 ++ src/g_game.h | 1 + src/r_main.c | 1 + 3 files changed, 4 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index 55438cc83..b8aa208db 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -517,6 +517,8 @@ static CV_PossibleValue_t sloperolldist_cons_t[] = { {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; consvar_t cv_sloperolldist = {"sloperolldist", "Infinite", CV_SAVE, sloperolldist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_sparkroll = {"sparkroll", "Off", CV_SAVE|CV_CALL, CV_OnOff, PDistort_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_cechotoggle = {"show_cecho", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #if MAXPLAYERS > 16 diff --git a/src/g_game.h b/src/g_game.h index 2f69070af..bc6d5f3b9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -159,6 +159,7 @@ extern consvar_t cv_sloperoll; extern consvar_t cv_sliptideroll; extern consvar_t cv_slamsound; extern consvar_t cv_sloperolldist; +extern consvar_t cv_sparkroll; extern consvar_t cv_cechotoggle; diff --git a/src/r_main.c b/src/r_main.c index 63d1a7a59..45c56ede1 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1957,6 +1957,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_sloperoll); CV_RegisterVar(&cv_sliptideroll); CV_RegisterVar(&cv_sloperolldist); + CV_RegisterVar(&cv_sparkroll); CV_RegisterVar(&cv_showhud); CV_RegisterVar(&cv_translucenthud); -- 2.54.0 From 793e8bfdcbf8e223b4cbc754dcc09bcbd1f44140 Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 13:22:56 -0500 Subject: [PATCH 30/35] Add ``K_RollMobjBySlopes`` and spark and trail rolling --- src/k_kart.c | 143 ++++++++++++++++++++++++--------------------------- src/k_kart.h | 1 + 2 files changed, 67 insertions(+), 77 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index c44c0398d..42e848efb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3005,6 +3005,13 @@ static void K_SpawnDriftSparks(player_t *player) spark->momy = player->mo->momy/2; //spark->momz = player->mo->momz/2; + // rotate the sparks based on pitch and roll; it just looks neat + if (cv_sparkroll.value == 1) + { + spark->slopepitch = player->mo->slopepitch; + spark->sloperoll = player->mo->sloperoll; + } + if (player->kartstuff[k_driftcharge] >= K_GetKartDriftSparkValue(player)*4) { spark->color = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))); @@ -3226,93 +3233,57 @@ static INT32 K_FindPlayerNum(player_t *plyr) return 0; // technically defaulting to player 1 but fuck it } -static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useReserves) +void K_RollMobjBySlopes(mobj_t* mo, boolean usedistance, boolean camera_tilting) { - angle_t lookAngle = 0; - angle_t zangle = 0; - angle_t xydirection = 0; - angle_t an; - angle_t final_slope; - INT32 pNum = K_FindPlayerNum(p); + I_Assert(mo->subsector != NULL); + I_Assert(mo->subsector->sector != NULL); - I_Assert(p != NULL); - I_Assert(p->mo != NULL); - I_Assert(!P_MobjWasRemoved(p->mo)); + angle_t an; + fixed_t m_dist = R_PointToDist(mo->x, mo->y); + fixed_t rolldist = cv_sloperolldist.value * mapobjectscale; - if (useReserves) - { - I_Assert(p->mo->reservezangle != NULL); - I_Assert(p->mo->reservexydir != NULL); - } + // lifted from hw_md2 + if (mo->standingslope) + { + fixed_t tempz = mo->standingslope->normal.z; + fixed_t tempy = mo->standingslope->normal.y; + fixed_t tempx = mo->standingslope->normal.x; + fixed_t tempangle = -(R_PointToAngle2( + 0, 0, FixedSqrt(FixedMul(tempy, tempy) + FixedMul(tempz, tempz)), tempx)); - lookAngle = R_PointToAngle2(camera[pNum].x, camera[pNum].y, p->mo->x, p->mo->y); + // admittedly this is a very hacky way to do the pitch and roll easing - if (!R_PointToDist(p->mo->x, p->mo->y)) - lookAngle = p->mo->angle; + // pitch + if ((!usedistance) || (m_dist <= (rolldist))) + { + an = (INT32)((angle_t)tempangle - mo->pitch_sprite) / (camera_tilting ? 1 : 3); - if (!useReserves) - { - zangle = p->mo->standingslope->zangle; - xydirection = p->mo->standingslope->xydirection; + mo->pitch_sprite = an ? mo->pitch_sprite + an : (angle_t)tempangle; + } + else + mo->pitch_sprite = FixedAngle(0); - p->mo->reservezangle = zangle; - p->mo->reservexydir = xydirection; - } - else if (p->mo->reservezangle) - { - zangle = p->mo->reservezangle; - xydirection = p->mo->reservexydir; - } + mo->slopepitch = mo->pitch_sprite; - if ((p->mo->eflags & MFE_VERTICALFLIP) && (!dontflip)) - zangle = InvAngle(zangle); + // roll + tempangle = (R_PointToAngle2(0, 0, tempz, tempy)); - an = (lookAngle - xydirection); - final_slope = -(FixedMul(FINESINE(an>>ANGLETOFINESHIFT), zangle)); - - an = (INT32)(final_slope - p->tilt_sprite) / (camspin[pNum] ? 1 : 3); - - p->tilt_sprite = an ? p->tilt_sprite + an : final_slope; - return -p->tilt_sprite; -} + if ((!usedistance) || (m_dist <= (rolldist))) + { + an = (INT32)((angle_t)tempangle - mo->roll_sprite) / (camera_tilting ? 1 : 3); -static void K_RollPlayerBySlopes(player_t *p, boolean usedistance) -{ - I_Assert(p->mo->subsector != NULL); - I_Assert(p->mo->subsector->sector != NULL); + mo->roll_sprite = an ? mo->roll_sprite + an : (angle_t)tempangle; + } + else + mo->roll_sprite = FixedAngle(0); - INT32 pNum = K_FindPlayerNum(p); - - fixed_t p_dist = R_PointToDist2(p->mo->x, p->mo->y, camera[pNum].x, camera[pNum].y); - fixed_t mos = mapobjectscale; - fixed_t rolldist = cv_sloperolldist.value*mos; - - if (!P_IsObjectOnGround(p->mo)) - { - if (!usedistance) - p->mo->sloperoll = K_GetSlopeRollAngle(p, false, true); - else if (p_dist <= (rolldist)) - p->mo->sloperoll = K_GetSlopeRollAngle(p, false, true); - else - p->mo->sloperoll = FixedAngle(0); - - return; - } - - if (!p->mo->standingslope) - { - p->mo->sloperoll = FixedAngle(0); - p->mo->reservezangle = FixedAngle(0); - p->mo->reservexydir = FixedAngle(0); - return; - } - - if (!usedistance) - p->mo->sloperoll = K_GetSlopeRollAngle(p, false, false); - else if (p_dist <= (rolldist)) - p->mo->sloperoll = K_GetSlopeRollAngle(p, false, false); - else - p->mo->sloperoll = FixedAngle(0); + mo->sloperoll = mo->roll_sprite; + } + else if (P_IsObjectOnGround(mo)) + { + mo->sloperoll = FixedAngle(0); + mo->slopepitch = FixedAngle(0); + } } void K_SpawnBoostTrail(player_t *player) @@ -3364,6 +3335,14 @@ void K_SpawnBoostTrail(player_t *player) K_FlipFromObject(flame, player->mo); flame->momx = 8; + + // since you have to be on the ground for sneaker trails, this should be fine(?) + if (cv_sparkroll.value == 1) + { + flame->slopepitch = player->mo->slopepitch; + flame->sloperoll = player->mo->sloperoll; + } + P_XYMovement(flame); if (P_MobjWasRemoved(flame)) continue; @@ -6459,13 +6438,23 @@ void K_MoveKartPlayer(player_t *player, boolean onground) player->mo->spritexscale = player->mo->realxscale; player->mo->spriteyscale = player->mo->realyscale; } + boolean usedist = false; + INT32 pNum = K_FindPlayerNum(player); + boolean camera_tilt = camspin[pNum] ? true : false; + if (cv_sloperolldist.value > 0) usedist = true; if (cv_sloperoll.value == 1) - K_RollPlayerBySlopes(player, usedist); + { + if ((!player->mo->salty_jump)) // seeing a character rotate mid-hop looks really janky + K_RollMobjBySlopes(player->mo, usedist, camera_tilt); + } else + { player->mo->sloperoll = FixedAngle(0); + player->mo->slopepitch = FixedAngle(0); + } // Quick Turning diff --git a/src/k_kart.h b/src/k_kart.h index 40353f5df..e7c238491 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -49,6 +49,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor); void K_StealBumper(player_t *player, player_t *victim, boolean force); void K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, angle_t rotangle, boolean spawncenter, boolean ghostit, mobj_t *source); void K_SpawnMineExplosion(mobj_t *source, UINT8 color); +void K_RollMobjBySlopes(mobj_t *mo, boolean usedistance, boolean camera_tilting); void K_SpawnBoostTrail(player_t *player); void K_SpawnSparkleTrail(mobj_t *mo); void K_SpawnWipeoutTrail(mobj_t *mo, boolean translucent); -- 2.54.0 From 5ec64e50ef22e86ad76d57f7bf87f1b0b72fe666 Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 13:26:17 -0500 Subject: [PATCH 31/35] Lots of pitch and roll stuff ``pitch``, ``roll``, slope versions, interpolation, and ``P_RollPitchMobj`` --- src/lua_baselib.c | 13 ++++++ src/lua_mobjlib.c | 7 +++- src/p_mobj.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++ src/p_mobj.h | 26 ++++++++---- src/p_saveg.c | 10 ++++- src/p_user.c | 8 ++++ src/r_fps.c | 29 ++++++++++++++ src/r_fps.h | 2 + 8 files changed, 184 insertions(+), 11 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 5fd813dc5..9e42e7e9f 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -538,6 +538,18 @@ static int lib_pFlashPal(lua_State *L) return 0; } + +// not sure if this is netsafe... +static int lib_pRollPitchMobj(lua_State *L) +{ + mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + NOHUD + if (!source) + return LUA_ErrInvalid(L, "mobj_t"); + P_RollPitchMobj(source); + return 0; +} + static int lib_pGetClosestAxis(lua_State *L) { mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -3033,6 +3045,7 @@ static luaL_Reg lib[] = { {"P_GetMobjGravity",lib_pGetMobjGravity}, {"P_WeaponOrPanel",lib_pWeaponOrPanel}, {"P_FlashPal",lib_pFlashPal}, + {"P_RollPitchMobj",lib_pRollPitchMobj}, {"P_GetClosestAxis",lib_pGetClosestAxis}, {"P_SpawnParaloop",lib_pSpawnParaloop}, {"P_BossTargetPlayer",lib_pBossTargetPlayer}, diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 52eda4554..6a5536c1c 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -83,8 +83,11 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, snext, udatalib_getter_mobj, mobj_snext_noset), FIELD(mobj_t, sprev, mobj_sprev_unimplemented, mobj_sprev_unimplemented), FIELD(mobj_t, angle, udatalib_getter_angle, mobj_angle_setter), + FIELD(mobj_t, pitch, udatalib_getter_angle, udatalib_setter_angle), + FIELD(mobj_t, roll, udatalib_getter_angle, udatalib_setter_angle), FIELD(mobj_t, rollangle, udatalib_getter_angle, udatalib_setter_angle), FIELD(mobj_t, sloperoll, udatalib_getter_angle, mobj_sloperoll_noop), + FIELD(mobj_t, slopepitch, udatalib_getter_angle, mobj_sloperoll_noop), // Macro fails here { "rollsum", 0, mobj_rollsum_getter, mobj_rollsum_noset }, FIELD(mobj_t, sprite, udatalib_getter_spritenum, udatalib_setter_spritenum), @@ -624,7 +627,9 @@ int mobj_rollsum_getter(lua_State *L) { mobj_t *mo = GETMO(); - angle_t rollsum = mo->rollangle + cv_sloperoll.value ? mo->sloperoll : 0; + angle_t pitchnroll = P_MobjPitchAndRoll(mo); + + angle_t rollsum = mo->rollangle + pitchnroll; if (mo->player) { diff --git a/src/p_mobj.c b/src/p_mobj.c index c52bb05be..66f7d5c9b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6251,6 +6251,84 @@ static void P_KoopaThinker(mobj_t *koopa) } } +// +// P_RollPitchMobj +// Assigns slopepitch and sloperoll to objects, and resets said values when slope-rolling +// is turned off completely. +// +void P_RollPitchMobj(mobj_t* mobj) +{ + boolean usedist = false; + + if (cv_sloperolldist.value > 0) + usedist = true; + + if (cv_sloperoll.value == 1) + { + K_RollMobjBySlopes(mobj, usedist, false); + } + else + { + mobj->sloperoll = FixedAngle(0); + mobj->slopepitch = FixedAngle(0); + } +} + +angle_t P_MobjPitchAndRoll(mobj_t *mobj) +{ + spritedef_t *sprdef; + spriteframe_t *sprframe; + angle_t ang = 0; + angle_t camang = 0; + angle_t return_angle = 0; + + if (P_MobjWasRemoved(mobj)) + return 0; + + size_t rot = mobj->frame & FF_FRAMEMASK; + boolean papersprite = (mobj->frame & FF_PAPERSPRITE); + + if (mobj->skin && mobj->sprite == SPR_PLAY) + { + sprdef = &((skin_t *)mobj->skin)->spritedef; + + if (rot >= sprdef->numframes) + sprdef = &sprites[mobj->sprite]; + } + else + { + sprdef = &sprites[mobj->sprite]; + } + + if (rot >= sprdef->numframes) + { + sprdef = &sprites[states[S_UNKNOWN].sprite]; + rot = states[S_UNKNOWN].frame&FF_FRAMEMASK; + } + + sprframe = &sprdef->spriteframes[rot]; + + // No sprite frame? I guess it is possible + if (!sprframe) return 0; + + if (sprframe->rotate != SRF_SINGLE || papersprite) + { + ang = R_PointToAngle(mobj->x, mobj->y) - mobj->angle; + camang = R_PointToAngle(mobj->x, mobj->y); + } + + return_angle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mobj->roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), mobj->pitch); + + if (cv_sloperoll.value) + { + return_angle += FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), mobj->sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), mobj->slopepitch); + } + + return return_angle; +} + // // P_MobjThinker // @@ -6393,6 +6471,12 @@ void P_MobjThinker(mobj_t *mobj) return; } + if (mobj->state == &states[S_PLAY_SIGN]) // hack to make the player sign icon roll with the sign itself + { + mobj->slopepitch = mobj->target->slopepitch; + mobj->sloperoll = mobj->target->sloperoll; + } + P_AddOverlay(mobj); break; case MT_SHADOW: @@ -6428,6 +6512,7 @@ void P_MobjThinker(mobj_t *mobj) P_RemoveMobj(mobj); return; } + P_RollPitchMobj(mobj); break; case MT_SMOLDERING: if (leveltime % 2 == 0) @@ -7856,6 +7941,7 @@ void P_MobjThinker(mobj_t *mobj) fixed_t distbarrier = 512*mapobjectscale; fixed_t distaway; + P_RollPitchMobj(mobj); P_SpawnGhostMobj(mobj); if (mobj->threshold > 0) @@ -7923,6 +8009,7 @@ void P_MobjThinker(mobj_t *mobj) } else { + P_RollPitchMobj(mobj); P_SpawnGhostMobj(mobj); mobj->angle = R_PointToAngle2(0, 0, mobj->momx, mobj->momy); P_InstaThrust(mobj, mobj->angle, mobj->movefactor); @@ -7956,6 +8043,9 @@ void P_MobjThinker(mobj_t *mobj) mobj->momx = mobj->momy = 0; mobj->health = 1; } + + P_RollPitchMobj(mobj); + if (mobj->threshold > 0) mobj->threshold--; break; @@ -8003,6 +8093,8 @@ void P_MobjThinker(mobj_t *mobj) || (mobj->state >= &states[S_SSMINE_DEPLOY8] && mobj->state <= &states[S_SSMINE_DEPLOY13])) A_GrenadeRing(mobj); + P_RollPitchMobj(mobj); + if (mobj->threshold > 0) mobj->threshold--; break; @@ -8355,6 +8447,10 @@ void P_MobjThinker(mobj_t *mobj) } } } + + // fancy sign rotation + P_RollPitchMobj(mobj); + break; case MT_CDUFO: if (!mobj->spawnpoint || mobj->fuse) @@ -9535,6 +9631,10 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->height = info->height; mobj->flags = info->flags; mobj->sloperoll = 0; + mobj->slopepitch = 0; + + mobj->pitch_sprite = 0; + mobj->roll_sprite = 0; mobj->health = info->spawnhealth; diff --git a/src/p_mobj.h b/src/p_mobj.h index d53d7e3f0..5d26f9b44 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -283,9 +283,9 @@ typedef struct mobj_s struct mobj_s **sprev; // killough 8/11/98: change to ptr-to-ptr // More drawing info: to determine current sprite. - angle_t angle; // orientation - angle_t old_angle; // orientation interpolation - angle_t old_angle2; + angle_t angle, pitch, roll; // orientation + angle_t old_angle, old_pitch, old_roll; // orientation interpolation + angle_t old_angle2, old_pitch2, old_roll2; angle_t rollangle; spritenum_t sprite; // used to find patch_t and flip value UINT32 frame; // frame number, plus bits see p_pspr.h @@ -302,7 +302,10 @@ typedef struct mobj_s fixed_t stretchslam; // "squish" effect when you land //sloperollangle - angle_t sloperoll, reservezangle, reservexydir; + angle_t sloperoll, slopepitch; + angle_t old_sloperoll, old_slopepitch; + angle_t old_sloperoll2, old_slopepitch2; + angle_t pitch_sprite, roll_sprite; struct msecnode_s *touching_sectorlist; // a linked list of sectors where this object appears @@ -433,9 +436,9 @@ typedef struct precipmobj_s struct precipmobj_s **sprev; // killough 8/11/98: change to ptr-to-ptr // More drawing info: to determine current sprite. - angle_t angle; // orientation - angle_t old_angle; // orientation interpolation - angle_t old_angle2; + angle_t angle, pitch, roll; // orientation + angle_t old_angle, old_pitch, old_roll; // orientation interpolation + angle_t old_angle2, old_pitch2, old_roll2; angle_t rollangle; spritenum_t sprite; // used to find patch_t and flip value UINT32 frame; // frame number, plus bits see p_pspr.h @@ -452,7 +455,10 @@ typedef struct precipmobj_s fixed_t stretchslam; // "squish" effect when you land //sloperollangle - angle_t sloperoll, reservezangle, reservexydir; + angle_t sloperoll, slopepitch; + angle_t old_sloperoll, old_slopepitch; + angle_t old_sloperoll2, old_slopepitch2; + angle_t pitch_sprite, roll_sprite; struct mprecipsecnode_s *touching_sectorlist; // a linked list of sectors where this object appears @@ -494,6 +500,10 @@ void P_AddCachedAction(mobj_t *mobj, INT32 statenum); // check mobj against water content, before movement code void P_MobjCheckWater(mobj_t *mobj); +// fancy sprite rotation +void P_RollPitchMobj(mobj_t *mobj); +angle_t P_MobjPitchAndRoll(mobj_t *mobj); + // Player spawn points void P_SpawnPlayer(INT32 playernum); void P_MovePlayerToSpawn(INT32 playernum, mapthing_t *mthing); diff --git a/src/p_saveg.c b/src/p_saveg.c index d4e9b2f5e..3ac86eae6 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1976,9 +1976,15 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->thinker.function.acp1 = thinker; mobj->rollangle = 0; + + mobj->pitch = 0; + mobj->roll = 0; + mobj->sloperoll = 0; - mobj->reservexydir = 0; - mobj->reservezangle = 0; + mobj->slopepitch = 0; + + mobj->pitch_sprite = 0; + mobj->roll_sprite = 0; mobj->spritexoffset = mobj->old_spritexoffset = 0; mobj->spriteyoffset = mobj->old_spriteyoffset = 0; diff --git a/src/p_user.c b/src/p_user.c index fab59d28b..e759aba4d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1697,11 +1697,15 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) else ghost->angle = mobj->angle; + ghost->pitch = mobj->pitch; + ghost->roll = mobj->roll; + ghost->sprite = mobj->sprite; ghost->frame = mobj->frame; ghost->tics = -1; ghost->frame &= ~FF_TRANSMASK; ghost->frame |= tr_trans50<slopepitch = mobj->slopepitch; ghost->sloperoll = mobj->sloperoll; ghost->fuse = ghost->info->damage; @@ -1724,6 +1728,10 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost->old_y = mobj->old_y2; ghost->old_z = mobj->old_z2; ghost->old_angle = (mobj->player ? mobj->player->old_frameangle2 : mobj->old_angle2); + ghost->old_pitch = mobj->old_pitch2; + ghost->old_roll = mobj->old_roll2; + ghost->old_sloperoll = mobj->old_sloperoll2; + ghost->old_slopepitch = mobj->old_slopepitch2; return ghost; } diff --git a/src/r_fps.c b/src/r_fps.c index 8aca51646..2ef5a68ba 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -282,6 +282,10 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->scale = mobj->scale; out->subsector = mobj->subsector; out->angle = mobj->player ? mobj->player->frameangle : mobj->angle; + out->pitch = mobj->pitch; + out->roll = mobj->roll; + out->slopepitch = mobj->slopepitch; + out->sloperoll = mobj->sloperoll; out->spritexscale = mobj->spritexscale; out->spriteyscale = mobj->spriteyscale; out->spritexoffset = mobj->spritexoffset; @@ -313,6 +317,14 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) { out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } + + // pitch roll stuff + out->pitch = mobj->resetinterp ? mobj->pitch : R_LerpAngle(mobj->old_pitch, mobj->pitch, frac); + out->roll = mobj->resetinterp ? mobj->roll : R_LerpAngle(mobj->old_roll, mobj->roll, frac); + + // and the slope stuff + out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); + out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); } void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjstate_t *out) @@ -755,10 +767,27 @@ void R_ResetMobjInterpolationState(mobj_t *mobj) mobj->old_z2 = mobj->old_z; mobj->old_angle2 = mobj->old_angle; mobj->old_scale2 = mobj->old_scale; + + // rotation humor + mobj->old_pitch2 = mobj->old_pitch; + mobj->old_roll2 = mobj->old_roll; + mobj->old_slopepitch2 = mobj->old_slopepitch; + mobj->old_sloperoll2 = mobj->old_sloperoll; + mobj->old_x = mobj->x; mobj->old_y = mobj->y; mobj->old_z = mobj->z; mobj->old_angle = mobj->angle; + + // rotation humor, again + + // pitch and roll first + mobj->old_pitch = mobj->pitch; + mobj->old_roll = mobj->roll; + + mobj->old_slopepitch = mobj->slopepitch; + mobj->old_sloperoll = mobj->sloperoll; + mobj->old_scale = mobj->scale; mobj->old_spritexscale = mobj->spritexscale; mobj->old_spriteyscale = mobj->spriteyscale; diff --git a/src/r_fps.h b/src/r_fps.h index 520843fd2..deb0c8788 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -65,6 +65,8 @@ typedef struct { fixed_t spriteyscale; fixed_t spritexoffset; fixed_t spriteyoffset; + angle_t pitch, roll; + angle_t sloperoll, slopepitch; } interpmobjstate_t; // Level interpolators -- 2.54.0 From 1babed3d669feb60079a71713e9148001c006d44 Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 14:26:29 -0500 Subject: [PATCH 32/35] Changes to rotation rendering Handlers for ``pitch``, ``roll``, and slope equivalents have been added. --- src/hardware/hw_main.c | 17 ++++++--- src/r_things.c | 79 ++++++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f0fab7fe5..3dfc2eb3c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5515,7 +5515,7 @@ void HWR_ProjectSprite(mobj_t *thing) boolean mirrored = thing->mirrored; boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); - angle_t ang; + angle_t ang, camang; const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; vector3_t pos; @@ -5616,6 +5616,8 @@ void HWR_ProjectSprite(mobj_t *thing) #endif ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + camang = R_PointToAngle (interp.x, interp.y); + if (mirrored) ang = InvAngle(ang); @@ -5666,15 +5668,22 @@ void HWR_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lumpoff].topoffset; #ifdef ROTSPRITE - if ((thing->rollangle)||(thing->sloperoll)||(thing->player && thing->player->sliproll)) + + rollangle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp.roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp.pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp.sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp.slopepitch) + + thing->rollangle; + + if ((rollangle)||(thing->player && thing->player->sliproll)) { if (thing->player) { sliptiderollangle = cv_sliptideroll.value ? thing->player->sliproll*(thing->player->sliptidemem) : 0; - rollsum = (thing->rollangle)+(thing->sloperoll)+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + rollsum = rollangle+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); } else - rollsum = (thing->rollangle)+(thing->sloperoll); + rollsum = rollangle; rollangle = R_GetRollAngle(rollsum); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); diff --git a/src/r_things.c b/src/r_things.c index d112c05f2..43a4aaab9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1327,6 +1327,7 @@ static void R_ProjectSprite(mobj_t *thing) spritecut_e cut = SC_NONE; angle_t ang = 0; // gcc 4.6 and lower fix + angle_t camang = 0; fixed_t iscale; fixed_t scalestep; // toast '16 fixed_t offset, offset2; @@ -1346,6 +1347,7 @@ static void R_ProjectSprite(mobj_t *thing) patch_t *rotsprite = NULL; INT32 rollangle = 0; angle_t rollsum = 0; + angle_t pitchnroll = 0; angle_t sliptiderollangle = 0; #endif @@ -1446,6 +1448,8 @@ static void R_ProjectSprite(mobj_t *thing) if (sprframe->rotate != SRF_SINGLE || papersprite) { ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + camang = R_PointToAngle (interp.x, interp.y); + if (mirrored) ang = InvAngle(ang); if (papersprite) @@ -1489,31 +1493,62 @@ static void R_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lump].topoffset; #ifdef ROTSPRITE - if ((thing->rollangle)||(thing->sloperoll)||(thing->player && thing->player->sliproll)) - { - if (thing->player) - { - sliptiderollangle = cv_sliptideroll.value ? thing->player->sliproll*(thing->player->sliptidemem) : 0; - rollsum = (thing->rollangle)+(thing->sloperoll)+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); - } - else - rollsum = (thing->rollangle)+(thing->sloperoll); + pitchnroll = 0; // set this to 0, non-paper sprites will affect this value - rollangle = R_GetRollAngle(rollsum); - rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); + if (papersprite) + { + if (ang >= ANGLE_180) + { + // Makes Software act much more sane like OpenGL + rollangle = InvAngle(thing->rollangle); + } + else + { + rollangle = thing->rollangle; + } + } + else + { + // this is very messy, but it on-the-fly calculates rotations for all the + // pitch and roll variables + pitchnroll = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp.roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp.pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp.sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp.slopepitch); - if (rotsprite != NULL) - { - spr_width = rotsprite->width << FRACBITS; - spr_height = rotsprite->height << FRACBITS; - spr_offset = rotsprite->leftoffset << FRACBITS; - spr_topoffset = rotsprite->topoffset << FRACBITS; - spr_topoffset += FEETADJUST; + rollangle = thing->rollangle; + } - // flip -> rotate, not rotate -> flip - flip = 0; - } - } + if ((rollangle) || (pitchnroll) || (thing->player && thing->player->sliproll)) + { + rollsum = pitchnroll; + + if (thing->player) + { + sliptiderollangle = + cv_sliptideroll.value ? thing->player->sliproll * (thing->player->sliptidemem) : 0; + rollsum += thing->rollangle + + FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + } + else + rollsum += thing->rollangle; + + rollangle = R_GetRollAngle(rollsum); + rotsprite = Patch_GetRotatedSprite( + sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); + + if (rotsprite != NULL) + { + spr_width = rotsprite->width << FRACBITS; + spr_height = rotsprite->height << FRACBITS; + spr_offset = rotsprite->leftoffset << FRACBITS; + spr_topoffset = rotsprite->topoffset << FRACBITS; + spr_topoffset += FEETADJUST; + + // flip -> rotate, not rotate -> flip + flip = 0; + } + } #endif // calculate edges of the shape -- 2.54.0 From d79d754b15e834e577134438a04590f9947dc8c3 Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 14:28:02 -0500 Subject: [PATCH 33/35] Changes to model rendering Standard slope rotation is now handled through secondary variables, while the primary ones are used for pitch and roll. --- src/hardware/hw_defs.h | 2 ++ src/hardware/hw_md2.c | 41 ++++++++++++++++++++++++++++++-- src/hardware/r_opengl/r_opengl.c | 12 ++++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 4c682b2eb..5d63795ed 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -129,8 +129,10 @@ typedef struct FLOAT x,y,z; // position #ifdef USE_FTRANSFORM_ANGLEZ FLOAT anglex,angley,anglez; // aimingangle / viewangle + FLOAT anglex2,anglez2; // secondaries #else FLOAT anglex,angley; // aimingangle / viewangle + FLOAT anglex2; // secondaries #endif FLOAT scalex,scaley,scalez; FLOAT spritexscale,spriteyscale; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 9cd077588..9a50b8a4f 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1401,18 +1401,55 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.anglex = 0.0f; + p.anglex2 = 0.0f; #ifdef USE_FTRANSFORM_ANGLEZ // Slope rotation from Kart p.anglez = 0.0f; + p.anglez2 = 0.0f; + + // use secondary angles for the slope rotation if (spr->mobj->standingslope) { fixed_t tempz = spr->mobj->standingslope->normal.z; fixed_t tempy = spr->mobj->standingslope->normal.y; fixed_t tempx = spr->mobj->standingslope->normal.x; fixed_t tempangle = AngleFixed(R_PointToAngle2(0, 0, FixedSqrt(FixedMul(tempy, tempy) + FixedMul(tempz, tempz)), tempx)); - p.anglez = FIXED_TO_FLOAT(tempangle); + p.anglez2 = FIXED_TO_FLOAT(tempangle); tempangle = -AngleFixed(R_PointToAngle2(0, 0, tempz, tempy)); - p.anglex = FIXED_TO_FLOAT(tempangle); + p.anglex2 = FIXED_TO_FLOAT(tempangle); + } + else if ((spr->mobj->sloperoll || spr->mobj->slopepitch) && (!P_IsObjectOnGround(spr->mobj)) && (!paused)) + { + SINT8 flipfactor = flip ? -1 : 1; + + angle_t camang = R_PointToAngle(interp.x, interp.y); + angle_t mobjang; + + if (spr->mobj->flags & (MF_NOTHINK|MF_SCENERY)) + mobjang = spr->mobj->angle; + else + mobjang = interp.angle; + + angle_t fmoang; + fmoang = camang - mobjang; + + // slopepitch + p.anglex += flipfactor*FIXED_TO_FLOAT( AngleFixed(FixedMul(FINESINE((camang-fmoang) >> ANGLETOFINESHIFT), interp.slopepitch)) ); + p.anglez -= flipfactor*FIXED_TO_FLOAT( AngleFixed(FixedMul(FINECOSINE((camang-fmoang) >> ANGLETOFINESHIFT), interp.slopepitch)) ); + + // sloperoll + p.anglex += flipfactor*FIXED_TO_FLOAT( AngleFixed(FixedMul(FINECOSINE((camang-fmoang) >> ANGLETOFINESHIFT), interp.sloperoll)) ); + p.anglez += flipfactor*FIXED_TO_FLOAT( AngleFixed(FixedMul(FINESINE((camang-fmoang) >> ANGLETOFINESHIFT), interp.sloperoll)) ); + p.roll = true; + } + + // pitch and roll + if (interp.roll || interp.pitch) + { + SINT8 flipfactor = flip ? -1 : 1; + p.anglex += flipfactor*FIXED_TO_FLOAT(AngleFixed(interp.roll)); + p.anglez -= flipfactor*FIXED_TO_FLOAT(AngleFixed(interp.pitch)); + p.roll = true; } #endif diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index cf10c059f..8022f0091 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3742,21 +3742,29 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float if (hflipped) scalez = -scalez; #ifdef USE_FTRANSFORM_ANGLEZ - pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart + pglRotatef(pos->anglez2, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart #endif - pglRotatef(pos->anglex, -1.0f, 0.0f, 0.0f); + pglRotatef(pos->anglex2, -1.0f, 0.0f, 0.0f); pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); if (pos->roll) { float roll = (1.0f * pos->rollflip); pglTranslatef(pos->centerx, pos->centery, 0); + + // rotate model for pitch and roll + pglRotatef(pos->anglex, 1.0f, 0.0f, 0.0f); +#ifdef USE_FTRANSFORM_ANGLEZ + pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); +#endif + if (pos->rotaxis == 2) // Z pglRotatef(pos->rollangle, 0.0f, 0.0f, roll); else if (pos->rotaxis == 1) // Y pglRotatef(pos->rollangle, 0.0f, roll, 0.0f); else // X pglRotatef(pos->rollangle, roll, 0.0f, 0.0f); + pglTranslatef(-pos->centerx, -pos->centery, 0); } -- 2.54.0 From f2faa87e51d3b5e3d1443e165742540797fedf0a Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 14:29:32 -0500 Subject: [PATCH 34/35] Menu changes and additions. "Player Distortion" is now "Sprite Distortion" to reflect the additions and changes to the slope-rolling system. All relevant option names have also been changed. --- src/m_menu.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 1e0c28352..b8c9a04e5 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2005,7 +2005,7 @@ static menuitem_t OP_SaturnMenu[] = {IT_STRING | IT_CVAR, NULL, "Midnight Channel Flicker Effect", &cv_lessflicker, 95}, - {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 105}, + {IT_SUBMENU|IT_STRING, NULL, "Sprite Distortion...", &OP_PlayerDistortDef, 105}, {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 110}, {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 120}, // uwu @@ -2029,7 +2029,7 @@ static const char* OP_SaturnTooltips[] = "Show the big Cecho Messages.", "Show Localskin Menus.", "Disables the flicker effect on Midnight Channel.", - "Options for player distortion effects.", + "Options for sprite distortion effects.", "Move position of HUD elements.", "See the people who helped make this project possible!", }; @@ -2057,13 +2057,14 @@ enum static menuitem_t OP_PlayerDistortMenu[] = { - {IT_HEADER, NULL, "Player Distortion", NULL, 0}, + {IT_HEADER, NULL, "Sprite Distortion", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Rotate players on slopes", &cv_sloperoll, 20}, - {IT_STRING | IT_CVAR, NULL, "Slope rotation distance", &cv_sloperolldist, 35}, - {IT_STRING | IT_CVAR, NULL, "Rotate players when sliptiding", &cv_sliptideroll, 50}, - {IT_STRING | IT_CVAR, NULL, "Player stretch factor", &cv_gravstretch, 65}, - {IT_STRING | IT_CVAR, NULL, "Squish Sound Effect", &cv_slamsound, 80}, + {IT_STRING | IT_CVAR, NULL, "Rotate Objects on Slopes", &cv_sloperoll, 20}, + {IT_STRING | IT_CVAR, NULL, "Slope Rotation Distance", &cv_sloperolldist, 35}, + {IT_STRING | IT_CVAR, NULL, "Rotate Players when Sliptiding", &cv_sliptideroll, 50}, + {IT_STRING | IT_CVAR, NULL, "Rotate Sparks and Boost Trails", &cv_sparkroll, 65}, + {IT_STRING | IT_CVAR, NULL, "Player Stretch Factor", &cv_gravstretch, 80}, + {IT_STRING | IT_CVAR, NULL, "Squish Sound Effect", &cv_slamsound, 95}, {IT_STRING | IT_CVAR, NULL, "Saltyhop", &cv_saltyhop, 110}, {IT_STRING | IT_CVAR, NULL, "Saltyhop Sound Effect", &cv_saltyhopsfx, 125}, {IT_STRING | IT_CVAR, NULL, "Saltyhop Squish", &cv_saltysquish, 140}, @@ -2072,9 +2073,10 @@ static menuitem_t OP_PlayerDistortMenu[] = static const char* OP_PlayerDistortTooltips[] = { NULL, - "Player rotation on slopes.", - "Distance player rotation should be visable.", + "Object rotation on slopes.", + "Distance object rotation should be visable.", "Player rotation when sliptiding.", + "Rotation of a player's boost trails and drift sparks.", "Player squash and stretch.", "Player landing sound effect.", "Kart hopping while drifting. This is purely visual.", @@ -3136,7 +3138,9 @@ void PDistort_menu_Onchange(void) status = IT_GRAYEDOUT; } + // enable/disable rolldist and sparkroll options OP_PlayerDistortMenu[2].status = status; + OP_PlayerDistortMenu[4].status = status; } void Bird_menu_Onchange(void) -- 2.54.0 From b55fc95ce88dbc541b96208bf46cec0d2d8dd530 Mon Sep 17 00:00:00 2001 From: Chearii Date: Mon, 1 Jan 2024 17:11:25 -0500 Subject: [PATCH 35/35] Remove ``camera_tilting`` from ``K_RollMobjBySlopes``, and make the divisor a static value --- src/k_kart.c | 16 ++++++++-------- src/k_kart.h | 2 +- src/p_mobj.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 42e848efb..8791da368 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3221,7 +3221,7 @@ static void K_QuiteSaltyHop(player_t *p) } } -static INT32 K_FindPlayerNum(player_t *plyr) +/*static INT32 K_FindPlayerNum(player_t *plyr) { INT32 i; @@ -3231,9 +3231,11 @@ static INT32 K_FindPlayerNum(player_t *plyr) return i; } return 0; // technically defaulting to player 1 but fuck it -} +}*/ -void K_RollMobjBySlopes(mobj_t* mo, boolean usedistance, boolean camera_tilting) +#define SLOPEROLL_DIV 3 + +void K_RollMobjBySlopes(mobj_t* mo, boolean usedistance) { I_Assert(mo->subsector != NULL); I_Assert(mo->subsector->sector != NULL); @@ -3256,7 +3258,7 @@ void K_RollMobjBySlopes(mobj_t* mo, boolean usedistance, boolean camera_tilting) // pitch if ((!usedistance) || (m_dist <= (rolldist))) { - an = (INT32)((angle_t)tempangle - mo->pitch_sprite) / (camera_tilting ? 1 : 3); + an = (INT32)((angle_t)tempangle - mo->pitch_sprite) / SLOPEROLL_DIV; mo->pitch_sprite = an ? mo->pitch_sprite + an : (angle_t)tempangle; } @@ -3270,7 +3272,7 @@ void K_RollMobjBySlopes(mobj_t* mo, boolean usedistance, boolean camera_tilting) if ((!usedistance) || (m_dist <= (rolldist))) { - an = (INT32)((angle_t)tempangle - mo->roll_sprite) / (camera_tilting ? 1 : 3); + an = (INT32)((angle_t)tempangle - mo->roll_sprite) / SLOPEROLL_DIV; mo->roll_sprite = an ? mo->roll_sprite + an : (angle_t)tempangle; } @@ -6440,15 +6442,13 @@ void K_MoveKartPlayer(player_t *player, boolean onground) } boolean usedist = false; - INT32 pNum = K_FindPlayerNum(player); - boolean camera_tilt = camspin[pNum] ? true : false; if (cv_sloperolldist.value > 0) usedist = true; if (cv_sloperoll.value == 1) { if ((!player->mo->salty_jump)) // seeing a character rotate mid-hop looks really janky - K_RollMobjBySlopes(player->mo, usedist, camera_tilt); + K_RollMobjBySlopes(player->mo, usedist); } else { diff --git a/src/k_kart.h b/src/k_kart.h index e7c238491..803594790 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -49,7 +49,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor); void K_StealBumper(player_t *player, player_t *victim, boolean force); void K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, angle_t rotangle, boolean spawncenter, boolean ghostit, mobj_t *source); void K_SpawnMineExplosion(mobj_t *source, UINT8 color); -void K_RollMobjBySlopes(mobj_t *mo, boolean usedistance, boolean camera_tilting); +void K_RollMobjBySlopes(mobj_t *mo, boolean usedistance); void K_SpawnBoostTrail(player_t *player); void K_SpawnSparkleTrail(mobj_t *mo); void K_SpawnWipeoutTrail(mobj_t *mo, boolean translucent); diff --git a/src/p_mobj.c b/src/p_mobj.c index 66f7d5c9b..d8237ff7b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6265,7 +6265,7 @@ void P_RollPitchMobj(mobj_t* mobj) if (cv_sloperoll.value == 1) { - K_RollMobjBySlopes(mobj, usedist, false); + K_RollMobjBySlopes(mobj, usedist); } else { -- 2.54.0