some static analysis cleanup

This commit is contained in:
jp9000 2013-10-17 17:21:42 -07:00
parent 6e6535d568
commit 18834c6a45
42 changed files with 240 additions and 157 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@ Debug/
x64/ x64/
ipch/ ipch/
.depend
tags tags
*.swp *.swp
*.dat *.dat

View file

@ -170,7 +170,7 @@ EXPORT enum gs_index_type indexbuffer_gettype(indexbuffer_t indexbuffer);
EXPORT void shader_destroy(shader_t shader); EXPORT void shader_destroy(shader_t shader);
EXPORT int shader_numparams(shader_t shader); EXPORT int shader_numparams(shader_t shader);
EXPORT sparam_t shader_getparambyidx(shader_t shader, int param); EXPORT sparam_t shader_getparambyidx(shader_t shader, uint32_t param);
EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name); EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name);
EXPORT void shader_getparaminfo(shader_t shader, sparam_t param, EXPORT void shader_getparaminfo(shader_t shader, sparam_t param,
struct shader_param_info *info); struct shader_param_info *info);

View file

@ -215,7 +215,7 @@ int shader_numparams(shader_t shader)
return (int)shader->params.size(); return (int)shader->params.size();
} }
sparam_t shader_getparambyidx(shader_t shader, int param) sparam_t shader_getparambyidx(shader_t shader, uint32_t param)
{ {
return &shader->params[param]; return &shader->params[param];
} }

View file

@ -232,7 +232,7 @@ ID3D11RasterizerState *gs_device::AddRasterState()
ID3D11RasterizerState *state; ID3D11RasterizerState *state;
memset(&rd, 0, sizeof(rd)); memset(&rd, 0, sizeof(rd));
/* use CCW to convert to for a right-handed coordinate system */ /* use CCW to convert to a right-handed coordinate system */
rd.FrontCounterClockwise = true; rd.FrontCounterClockwise = true;
rd.FillMode = D3D11_FILL_SOLID; rd.FillMode = D3D11_FILL_SOLID;
rd.CullMode = ConvertGSCullMode(rasterState.cullMode); rd.CullMode = ConvertGSCullMode(rasterState.cullMode);

View file

@ -164,7 +164,7 @@ EXPORT enum gs_index_type indexbuffer_gettype(indexbuffer_t indexbuffer);
EXPORT void shader_destroy(shader_t shader); EXPORT void shader_destroy(shader_t shader);
EXPORT int shader_numparams(shader_t shader); EXPORT int shader_numparams(shader_t shader);
EXPORT sparam_t shader_getparambyidx(shader_t shader, int param); EXPORT sparam_t shader_getparambyidx(shader_t shader, uint32_t param);
EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name); EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name);
EXPORT void shader_getparaminfo(shader_t shader, sparam_t param, EXPORT void shader_getparaminfo(shader_t shader, sparam_t param,
struct shader_param_info *info); struct shader_param_info *info);

View file

@ -67,6 +67,7 @@ static bool gl_add_param(struct gs_shader *shader, struct shader_var *var,
param.array_count = var->array_count; param.array_count = var->array_count;
param.name = bstrdup(var->name); param.name = bstrdup(var->name);
param.shader = shader;
param.type = get_shader_param_type(var->type); param.type = get_shader_param_type(var->type);
if (param.type == SHADER_PARAM_TEXTURE) { if (param.type == SHADER_PARAM_TEXTURE) {
@ -310,7 +311,7 @@ int shader_numparams(shader_t shader)
return (int)shader->params.num; return (int)shader->params.num;
} }
sparam_t shader_getparambyidx(shader_t shader, int param) sparam_t shader_getparambyidx(shader_t shader, uint32_t param)
{ {
assert(param < shader->params.num); assert(param < shader->params.num);
return shader->params.array+param; return shader->params.array+param;
@ -329,9 +330,22 @@ sparam_t shader_getparambyname(shader_t shader, const char *name)
return NULL; return NULL;
} }
static inline bool matching_shader(shader_t shader, sparam_t sparam)
{
if (shader != sparam->shader) {
blog(LOG_ERROR, "Shader and shader parameter do not match");
return false;
}
return true;
}
void shader_getparaminfo(shader_t shader, sparam_t param, void shader_getparaminfo(shader_t shader, sparam_t param,
struct shader_param_info *info) struct shader_param_info *info)
{ {
if (!matching_shader(shader, param))
return;
info->type = param->type; info->type = param->type;
info->name = param->name; info->name = param->name;
} }
@ -348,20 +362,26 @@ sparam_t shader_getworldmatrix(shader_t shader)
void shader_setbool(shader_t shader, sparam_t param, bool val) void shader_setbool(shader_t shader, sparam_t param, bool val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform1i(shader->program, param->param, (GLint)val); glProgramUniform1i(shader->program, param->param, (GLint)val);
gl_success("glProgramUniform1i"); gl_success("glProgramUniform1i");
}
} }
void shader_setfloat(shader_t shader, sparam_t param, float val) void shader_setfloat(shader_t shader, sparam_t param, float val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform1f(shader->program, param->param, val); glProgramUniform1f(shader->program, param->param, val);
gl_success("glProgramUniform1f"); gl_success("glProgramUniform1f");
}
} }
void shader_setint(shader_t shader, sparam_t param, int val) void shader_setint(shader_t shader, sparam_t param, int val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform1i(shader->program, param->param, val); glProgramUniform1i(shader->program, param->param, val);
gl_success("glProgramUniform1i"); gl_success("glProgramUniform1i");
}
} }
void shader_setmatrix3(shader_t shader, sparam_t param, void shader_setmatrix3(shader_t shader, sparam_t param,
@ -370,48 +390,62 @@ void shader_setmatrix3(shader_t shader, sparam_t param,
struct matrix4 mat; struct matrix4 mat;
matrix4_from_matrix3(&mat, val); matrix4_from_matrix3(&mat, val);
glProgramUniformMatrix4fv(shader->program, param->param, 1, false, if (matching_shader(shader, param)) {
mat.x.ptr); glProgramUniformMatrix4fv(shader->program, param->param, 1,
false, mat.x.ptr);
gl_success("glProgramUniformMatrix4fv"); gl_success("glProgramUniformMatrix4fv");
}
} }
void shader_setmatrix4(shader_t shader, sparam_t param, void shader_setmatrix4(shader_t shader, sparam_t param,
const struct matrix4 *val) const struct matrix4 *val)
{ {
glProgramUniformMatrix4fv(shader->program, param->param, 1, false, if (matching_shader(shader, param)) {
val->x.ptr); glProgramUniformMatrix4fv(shader->program, param->param, 1,
false, val->x.ptr);
gl_success("glProgramUniformMatrix4fv"); gl_success("glProgramUniformMatrix4fv");
}
} }
void shader_setvec2(shader_t shader, sparam_t param, void shader_setvec2(shader_t shader, sparam_t param,
const struct vec2 *val) const struct vec2 *val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform2fv(shader->program, param->param, 1, val->ptr); glProgramUniform2fv(shader->program, param->param, 1, val->ptr);
gl_success("glProgramUniform2fv"); gl_success("glProgramUniform2fv");
}
} }
void shader_setvec3(shader_t shader, sparam_t param, void shader_setvec3(shader_t shader, sparam_t param,
const struct vec3 *val) const struct vec3 *val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform3fv(shader->program, param->param, 1, val->ptr); glProgramUniform3fv(shader->program, param->param, 1, val->ptr);
gl_success("glProgramUniform3fv"); gl_success("glProgramUniform3fv");
}
} }
void shader_setvec4(shader_t shader, sparam_t param, void shader_setvec4(shader_t shader, sparam_t param,
const struct vec4 *val) const struct vec4 *val)
{ {
if (matching_shader(shader, param)) {
glProgramUniform4fv(shader->program, param->param, 1, val->ptr); glProgramUniform4fv(shader->program, param->param, 1, val->ptr);
gl_success("glProgramUniform4fv"); gl_success("glProgramUniform4fv");
}
} }
void shader_settexture(shader_t shader, sparam_t param, texture_t val) void shader_settexture(shader_t shader, sparam_t param, texture_t val)
{ {
if (matching_shader(shader, param))
param->texture = val; param->texture = val;
} }
static void shader_setval_data(shader_t shader, sparam_t param, static void shader_setval_data(shader_t shader, sparam_t param,
const void *val, int count) const void *val, int count)
{ {
if (!matching_shader(shader, param))
return;
if (param->type == SHADER_PARAM_BOOL || if (param->type == SHADER_PARAM_BOOL ||
param->type == SHADER_PARAM_INT) { param->type == SHADER_PARAM_INT) {
glProgramUniform1iv(shader->program, param->param, count, val); glProgramUniform1iv(shader->program, param->param, count, val);
@ -460,6 +494,9 @@ void shader_setval(shader_t shader, sparam_t param, const void *val,
if (!count) if (!count)
count = 1; count = 1;
if (!matching_shader(shader, param))
return;
switch (param->type) { switch (param->type) {
case SHADER_PARAM_FLOAT: expected_size = sizeof(float); break; case SHADER_PARAM_FLOAT: expected_size = sizeof(float); break;
case SHADER_PARAM_BOOL: case SHADER_PARAM_BOOL:

View file

@ -145,7 +145,9 @@ static void gl_write_storage_var(struct gl_shader_parser *glsp,
if (st) { if (st) {
gl_unwrap_storage_struct(glsp, st, var->name, input, prefix); gl_unwrap_storage_struct(glsp, st, var->name, input, prefix);
} else { } else {
struct gl_parser_attrib attrib = {{0}}; struct gl_parser_attrib attrib;
gl_parser_attrib_init(&attrib);
dstr_cat(&glsp->gl_string, input ? "in " : "out "); dstr_cat(&glsp->gl_string, input ? "in " : "out ");
if (prefix) if (prefix)
@ -286,14 +288,14 @@ static inline bool gl_write_texture_call(struct gl_shader_parser *glsp,
struct shader_var *var, const char *call) struct shader_var *var, const char *call)
{ {
struct cf_parser *cfp = &glsp->parser.cfp; struct cf_parser *cfp = &glsp->parser.cfp;
size_t sampler_id = -1; size_t sampler_id = (size_t)-1;
if (!next_token(cfp)) return false; if (!next_token(cfp)) return false;
if (!token_is(cfp, "(")) return false; if (!token_is(cfp, "(")) return false;
if (!next_token(cfp)) return false; if (!next_token(cfp)) return false;
sampler_id = sp_getsampler(glsp, cfp->cur_token); sampler_id = sp_getsampler(glsp, cfp->cur_token);
if (sampler_id == -1) return false; if (sampler_id == (size_t)-1) return false;
if (!next_token(cfp)) return false; if (!next_token(cfp)) return false;
if (!token_is(cfp, ",")) return false; if (!token_is(cfp, ",")) return false;

View file

@ -32,6 +32,11 @@ struct gl_parser_attrib {
bool input; bool input;
}; };
static inline void gl_parser_attrib_init(struct gl_parser_attrib *attr)
{
memset(attr, 0, sizeof(struct gl_parser_attrib));
}
static inline void gl_parser_attrib_free(struct gl_parser_attrib *attr) static inline void gl_parser_attrib_free(struct gl_parser_attrib *attr)
{ {
dstr_free(&attr->name); dstr_free(&attr->name);

View file

@ -265,7 +265,7 @@ static bool load_sampler_on_textures(device_t device, samplerstate_t ss,
struct shader_param *param = shader->params.array+i; struct shader_param *param = shader->params.array+i;
if (param->type == SHADER_PARAM_TEXTURE && if (param->type == SHADER_PARAM_TEXTURE &&
param->sampler_id == sampler_unit && param->sampler_id == (uint32_t)sampler_unit &&
param->texture) { param->texture) {
if (!gl_active_texture(GL_TEXTURE0 + param->texture_id)) if (!gl_active_texture(GL_TEXTURE0 + param->texture_id))
return false; return false;

View file

@ -279,6 +279,7 @@ struct shader_param {
enum shader_param_type type; enum shader_param_type type;
char *name; char *name;
shader_t shader;
GLint param; GLint param;
GLint texture_id; GLint texture_id;
size_t sampler_id; size_t sampler_id;

View file

@ -55,6 +55,7 @@ zstencil_t device_create_zstencil(device_t device, uint32_t width,
memset(zs, 0, sizeof(struct gs_zstencil_buffer)); memset(zs, 0, sizeof(struct gs_zstencil_buffer));
zs->format = convert_zstencil_format(format); zs->format = convert_zstencil_format(format);
zs->attachment = get_attachment(format); zs->attachment = get_attachment(format);
zs->device = device;
if (!gl_init_zsbuffer(zs, width, height)) { if (!gl_init_zsbuffer(zs, width, height)) {
blog(LOG_ERROR, "device_create_zstencil (GL) failed"); blog(LOG_ERROR, "device_create_zstencil (GL) failed");

View file

@ -676,7 +676,7 @@ static bool ep_parse_param_array(struct effect_parser *ep,
ep->cfp.cur_token->str.len)) ep->cfp.cur_token->str.len))
return false; return false;
param->array_count = strtol(ep->cfp.cur_token->str.array, NULL, 10); param->array_count =(int)strtol(ep->cfp.cur_token->str.array, NULL, 10);
if (next_token_should_be(&ep->cfp, "]", ";", NULL) == PARSE_EOF) if (next_token_should_be(&ep->cfp, "]", ";", NULL) == PARSE_EOF)
return false; return false;
@ -1100,10 +1100,10 @@ static inline void ep_write_func_func_deps(struct effect_parser *ep,
size_t i; size_t i;
for (i = 0; i < func->func_deps.num; i++) { for (i = 0; i < func->func_deps.num; i++) {
const char *name = func->func_deps.array[i]; const char *name = func->func_deps.array[i];
struct ep_func *func = ep_getfunc(ep, name); struct ep_func *func_dep = ep_getfunc(ep, name);
if (!func->written) { if (!func_dep->written) {
ep_write_func(ep, shader, func, used_params); ep_write_func(ep, shader, func_dep, used_params);
dstr_cat(shader, "\n\n"); dstr_cat(shader, "\n\n");
} }
} }
@ -1274,6 +1274,7 @@ static void ep_compile_param(struct effect_parser *ep, size_t idx)
param->name = bstrdup(param_in->name); param->name = bstrdup(param_in->name);
param->section = EFFECT_PARAM; param->section = EFFECT_PARAM;
param->effect = ep->effect;
da_move(param->default_val, param_in->default_val); da_move(param->default_val, param_in->default_val);
if (strcmp(param_in->type, "bool") == 0) if (strcmp(param_in->type, "bool") == 0)
@ -1337,7 +1338,7 @@ static inline bool ep_compile_pass_shader(struct effect_parser *ep,
struct dstr shader_str; struct dstr shader_str;
struct dstr location; struct dstr location;
struct darray used_params; /* struct dstr */ struct darray used_params; /* struct dstr */
struct darray *pass_params; /* struct pass_shaderparam */ struct darray *pass_params = NULL; /* struct pass_shaderparam */
shader_t shader = NULL; shader_t shader = NULL;
bool success = true; bool success = true;

View file

@ -43,12 +43,12 @@ technique_t effect_gettechnique(effect_t effect, const char *name)
return NULL; return NULL;
} }
int technique_begin(technique_t tech) size_t technique_begin(technique_t tech)
{ {
tech->effect->cur_technique = tech; tech->effect->cur_technique = tech;
tech->effect->graphics->cur_effect = tech->effect; tech->effect->graphics->cur_effect = tech->effect;
return (int)tech->passes.num; return tech->passes.num;
} }
void technique_end(technique_t tech) void technique_end(technique_t tech)
@ -156,7 +156,7 @@ bool technique_beginpassbyname(technique_t tech,
for (i = 0; i < tech->passes.num; i++) { for (i = 0; i < tech->passes.num; i++) {
struct effect_pass *pass = tech->passes.array+i; struct effect_pass *pass = tech->passes.array+i;
if (strcmp(pass->name, name) == 0) { if (strcmp(pass->name, name) == 0) {
technique_beginpass(tech, (int)i); technique_beginpass(tech, i);
return true; return true;
} }
} }
@ -190,9 +190,9 @@ void technique_endpass(technique_t tech)
tech->effect->cur_pass = NULL; tech->effect->cur_pass = NULL;
} }
int effect_numparams(effect_t effect) size_t effect_numparams(effect_t effect)
{ {
return (int)effect->params.num; return effect->params.num;
} }
eparam_t effect_getparambyidx(effect_t effect, size_t param) eparam_t effect_getparambyidx(effect_t effect, size_t param)
@ -220,9 +220,22 @@ eparam_t effect_getparambyname(effect_t effect, const char *name)
return NULL; return NULL;
} }
static inline bool matching_effect(effect_t effect, eparam_t param)
{
if (effect != param->effect) {
blog(LOG_ERROR, "Effect and effect parameter do not match");
return false;
}
return true;
}
void effect_getparaminfo(effect_t effect, eparam_t param, void effect_getparaminfo(effect_t effect, eparam_t param,
struct effect_param_info *info) struct effect_param_info *info)
{ {
if (!matching_effect(effect, param))
return;
info->name = param->name; info->name = param->name;
info->type = param->type; info->type = param->type;
} }
@ -241,6 +254,10 @@ static inline void effect_setval_inline(effect_t effect, eparam_t param,
const void *data, size_t size) const void *data, size_t size)
{ {
bool size_changed = param->cur_val.num != size; bool size_changed = param->cur_val.num != size;
if (!matching_effect(effect, param))
return;
if (size_changed) if (size_changed)
da_resize(param->cur_val, size); da_resize(param->cur_val, size);

View file

@ -56,6 +56,8 @@ struct effect_param {
DARRAY(uint8_t) cur_val; DARRAY(uint8_t) cur_val;
DARRAY(uint8_t) default_val; DARRAY(uint8_t) default_val;
effect_t effect;
/*char *full_name; /*char *full_name;
float scroller_min, scroller_max, scroller_inc, scroller_mul;*/ float scroller_min, scroller_max, scroller_inc, scroller_mul;*/
}; };

View file

@ -176,7 +176,7 @@ struct gs_exports {
void (*shader_destroy)(shader_t shader); void (*shader_destroy)(shader_t shader);
int (*shader_numparams)(shader_t shader); int (*shader_numparams)(shader_t shader);
sparam_t (*shader_getparambyidx)(shader_t shader, int param); sparam_t (*shader_getparambyidx)(shader_t shader, uint32_t param);
sparam_t (*shader_getparambyname)(shader_t shader, const char *name); sparam_t (*shader_getparambyname)(shader_t shader, const char *name);
void (*shader_getparaminfo)(shader_t shader, sparam_t param, void (*shader_getparaminfo)(shader_t shader, sparam_t param,
struct shader_param_info *info); struct shader_param_info *info);

View file

@ -472,8 +472,7 @@ void gs_normal3f(float x, float y, float z)
static inline bool validvertsize(graphics_t graphics, size_t num, static inline bool validvertsize(graphics_t graphics, size_t num,
const char *name) const char *name)
{ {
if (graphics->using_immediate && if (graphics->using_immediate && num == IMMEDIATE_COUNT) {
graphics->colors.num == IMMEDIATE_COUNT) {
blog(LOG_WARNING, "%s: tried to use over %u " blog(LOG_WARNING, "%s: tried to use over %u "
"for immediate rendering", "for immediate rendering",
name, IMMEDIATE_COUNT); name, IMMEDIATE_COUNT);
@ -690,7 +689,7 @@ void gs_resetviewport(void)
{ {
uint32_t cx, cy; uint32_t cx, cy;
gs_getsize(&cx, &cy); gs_getsize(&cx, &cy);
gs_setviewport(0, 0, cx, cy); gs_setviewport(0, 0, (int)cx, (int)cy);
} }
void gs_set2dmode(void) void gs_set2dmode(void)
@ -1222,7 +1221,7 @@ int shader_numparams(shader_t shader)
return graphics->exports.shader_numparams(shader); return graphics->exports.shader_numparams(shader);
} }
sparam_t shader_getparambyidx(shader_t shader, int param) sparam_t shader_getparambyidx(shader_t shader, uint32_t param)
{ {
graphics_t graphics = thread_graphics; graphics_t graphics = thread_graphics;
return graphics->exports.shader_getparambyidx(shader, param); return graphics->exports.shader_getparambyidx(shader, param);

View file

@ -293,7 +293,7 @@ enum shader_type {
EXPORT void shader_destroy(shader_t shader); EXPORT void shader_destroy(shader_t shader);
EXPORT int shader_numparams(shader_t shader); EXPORT int shader_numparams(shader_t shader);
EXPORT sparam_t shader_getparambyidx(shader_t shader, int param); EXPORT sparam_t shader_getparambyidx(shader_t shader, uint32_t param);
EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name); EXPORT sparam_t shader_getparambyname(shader_t shader, const char *name);
EXPORT void shader_getparaminfo(shader_t shader, sparam_t param, EXPORT void shader_getparaminfo(shader_t shader, sparam_t param,
struct shader_param_info *info); struct shader_param_info *info);
@ -345,14 +345,14 @@ EXPORT void effect_destroy(effect_t effect);
EXPORT technique_t effect_gettechnique(effect_t effect, const char *name); EXPORT technique_t effect_gettechnique(effect_t effect, const char *name);
EXPORT int technique_begin(technique_t technique); EXPORT size_t technique_begin(technique_t technique);
EXPORT void technique_end(technique_t technique); EXPORT void technique_end(technique_t technique);
EXPORT bool technique_beginpass(technique_t technique, size_t pass); EXPORT bool technique_beginpass(technique_t technique, size_t pass);
EXPORT bool technique_beginpassbyname(technique_t technique, EXPORT bool technique_beginpassbyname(technique_t technique,
const char *name); const char *name);
EXPORT void technique_endpass(technique_t technique); EXPORT void technique_endpass(technique_t technique);
EXPORT int effect_numparams(effect_t effect); EXPORT size_t effect_numparams(effect_t effect);
EXPORT eparam_t effect_getparambyidx(effect_t effect, size_t param); EXPORT eparam_t effect_getparambyidx(effect_t effect, size_t param);
EXPORT eparam_t effect_getparambyname(effect_t effect, const char *name); EXPORT eparam_t effect_getparambyname(effect_t effect, const char *name);
EXPORT void effect_getparaminfo(effect_t effect, eparam_t param, EXPORT void effect_getparaminfo(effect_t effect, eparam_t param,
@ -389,7 +389,7 @@ EXPORT void effect_setdefault(effect_t effect, eparam_t param);
EXPORT texrender_t texrender_create(enum gs_color_format format, EXPORT texrender_t texrender_create(enum gs_color_format format,
enum gs_zstencil_format zsformat); enum gs_zstencil_format zsformat);
EXPORT void texrender_destroy(texrender_t texrender); EXPORT void texrender_destroy(texrender_t texrender);
EXPORT bool texrender_begin(texrender_t texrender, int cx, int cy); EXPORT bool texrender_begin(texrender_t texrender, uint32_t cx, uint32_t cy);
EXPORT void texrender_end(texrender_t texrender); EXPORT void texrender_end(texrender_t texrender);
EXPORT void texrender_reset(texrender_t texrender); EXPORT void texrender_reset(texrender_t texrender);
EXPORT texture_t texrender_gettexture(texrender_t texrender); EXPORT texture_t texrender_gettexture(texrender_t texrender);
@ -681,7 +681,8 @@ static inline uint32_t gs_get_format_bpp(enum gs_color_format format)
case GS_DXT1: return 4; case GS_DXT1: return 4;
case GS_DXT3: return 8; case GS_DXT3: return 8;
case GS_DXT5: return 8; case GS_DXT5: return 8;
default: return 0; default:
case GS_UNKNOWN: return 0;
} }
} }

View file

@ -18,6 +18,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "vec2.h" #include "vec2.h"
#include "vec3.h" #include "vec3.h"
#include "math-defs.h"
#include "math-extra.h" #include "math-extra.h"
void polar_to_cart(struct vec3 *dst, const struct vec3 *v) void polar_to_cart(struct vec3 *dst, const struct vec3 *v)
@ -70,7 +71,7 @@ float calc_torquef(float val1, float val2, float torque, float min_adjust,
float dist; float dist;
bool over; bool over;
if (val1 == val2) if (close_float(val1, val2, EPSILON))
return val1; return val1;
dist = (val2-val1)*torque; dist = (val2-val1)*torque;

View file

@ -58,7 +58,7 @@ struct f4x4 {
float ptr[4][4]; float ptr[4][4];
}; };
void quat_from_matrix(struct quat *dst, const struct matrix3 *m) void quat_from_matrix3(struct quat *dst, const struct matrix3 *m)
{ {
float tr = (m->x.x + m->y.y + m->z.z); float tr = (m->x.x + m->y.y + m->z.z);
float inv_half; float inv_half;

View file

@ -110,7 +110,7 @@ void shader_sampler_convert(struct shader_sampler *ss,
else if (astrcmpi(state, "AddressW") == 0) else if (astrcmpi(state, "AddressW") == 0)
info->address_w = get_address_mode(value); info->address_w = get_address_mode(value);
else if (astrcmpi(state, "MaxAnisotropy") == 0) else if (astrcmpi(state, "MaxAnisotropy") == 0)
info->max_anisotropy = strtol(value, NULL, 10); info->max_anisotropy = (int)strtol(value, NULL, 10);
/*else if (astrcmpi(state, "BorderColor") == 0) /*else if (astrcmpi(state, "BorderColor") == 0)
// TODO */ // TODO */
} }
@ -319,7 +319,7 @@ static inline int sp_check_for_keyword(struct shader_parser *sp,
} }
static inline int sp_parse_func_param(struct shader_parser *sp, static inline int sp_parse_func_param(struct shader_parser *sp,
struct shader_func *func, struct shader_var *var) struct shader_var *var)
{ {
int errcode; int errcode;
bool is_uniform = false; bool is_uniform = false;
@ -380,7 +380,7 @@ static bool sp_parse_func_params(struct shader_parser *sp,
if (!token_is(&sp->cfp, "(") && !token_is(&sp->cfp, ",")) if (!token_is(&sp->cfp, "(") && !token_is(&sp->cfp, ","))
cf_adderror_syntax_error(&sp->cfp); cf_adderror_syntax_error(&sp->cfp);
errcode = sp_parse_func_param(sp, func, &var); errcode = sp_parse_func_param(sp, &var);
if (errcode != PARSE_SUCCESS) { if (errcode != PARSE_SUCCESS) {
shader_var_free(&var); shader_var_free(&var);
@ -453,7 +453,7 @@ static bool sp_parse_param_array(struct shader_parser *sp,
sp->cfp.cur_token->str.len)) sp->cfp.cur_token->str.len))
return false; return false;
param->array_count = strtol(sp->cfp.cur_token->str.array, NULL, 10); param->array_count =(int)strtol(sp->cfp.cur_token->str.array, NULL, 10);
if (next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF) if (next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
return false; return false;

View file

@ -27,7 +27,7 @@ struct gs_texture_render {
texture_t target, prev_target; texture_t target, prev_target;
zstencil_t zs, prev_zs; zstencil_t zs, prev_zs;
int cx, cy; uint32_t cx, cy;
enum gs_color_format format; enum gs_color_format format;
enum gs_zstencil_format zsformat; enum gs_zstencil_format zsformat;
@ -57,7 +57,8 @@ void texrender_destroy(texrender_t texrender)
} }
} }
static bool texrender_resetbuffer(texrender_t texrender, int cx, int cy) static bool texrender_resetbuffer(texrender_t texrender, uint32_t cx,
uint32_t cy)
{ {
texture_destroy(texrender->target); texture_destroy(texrender->target);
zstencil_destroy(texrender->zs); zstencil_destroy(texrender->zs);
@ -85,14 +86,14 @@ static bool texrender_resetbuffer(texrender_t texrender, int cx, int cy)
return true; return true;
} }
bool texrender_begin(texrender_t texrender, int cx, int cy) bool texrender_begin(texrender_t texrender, uint32_t cx, uint32_t cy)
{ {
if (texrender->rendered) if (texrender->rendered)
return false; return false;
if (cx == -1) if (cx == 0)
cx = gs_getwidth(); cx = gs_getwidth();
if (cy == -1) if (cy == 0)
cy = gs_getheight(); cy = gs_getheight();
assert(cx && cy); assert(cx && cy);

View file

@ -128,9 +128,9 @@ static inline void vec3_cross(struct vec3 *dst, const struct vec3 *v1,
static inline void vec3_neg(struct vec3 *dst, const struct vec3 *v) static inline void vec3_neg(struct vec3 *dst, const struct vec3 *v)
{ {
dst->x = -dst->x; dst->x = -v->x;
dst->y = -dst->y; dst->y = -v->y;
dst->z = -dst->z; dst->z = -v->z;
} }
static inline float vec3_len(const struct vec3 *v) static inline float vec3_len(const struct vec3 *v)

View file

@ -111,10 +111,10 @@ static inline float vec4_dot(const struct vec4 *v1, const struct vec4 *v2)
static inline void vec4_neg(struct vec4 *dst, const struct vec4 *v) static inline void vec4_neg(struct vec4 *dst, const struct vec4 *v)
{ {
dst->x = -dst->x; dst->x = -v->x;
dst->y = -dst->y; dst->y = -v->y;
dst->z = -dst->z; dst->z = -v->z;
dst->w = -dst->w; dst->w = -v->w;
} }
static inline float vec4_len(const struct vec4 *v) static inline float vec4_len(const struct vec4 *v)

View file

@ -41,7 +41,7 @@ void *load_module_subfunc(void *module, const char *module_name,
return func_addr; return func_addr;
} }
static void module_load_exports(struct obs_data *obs, struct obs_module *mod, static void module_load_exports(struct obs_module *mod,
struct darray *output_array, const char *type, struct darray *output_array, const char *type,
const size_t data_size, void *callback_ptr) const size_t data_size, void *callback_ptr)
{ {
@ -94,13 +94,13 @@ int obs_load_module(const char *path)
} }
mod.name = bstrdup(path); mod.name = bstrdup(path);
module_load_exports(obs, &mod, &obs->input_types.da, "inputs", module_load_exports(&mod, &obs->input_types.da, "inputs",
sizeof(struct source_info), get_source_info); sizeof(struct source_info), get_source_info);
module_load_exports(obs, &mod, &obs->filter_types.da, "filters", module_load_exports(&mod, &obs->filter_types.da, "filters",
sizeof(struct source_info), get_source_info); sizeof(struct source_info), get_source_info);
module_load_exports(obs, &mod, &obs->transition_types.da, "transitions", module_load_exports(&mod, &obs->transition_types.da, "transitions",
sizeof(struct source_info), get_source_info); sizeof(struct source_info), get_source_info);
module_load_exports(obs, &mod, &obs->output_types.da, "outputs", module_load_exports(&mod, &obs->output_types.da, "outputs",
sizeof(struct output_info), get_output_info); sizeof(struct output_info), get_output_info);
da_push_back(obs->modules, &mod); da_push_back(obs->modules, &mod);

View file

@ -64,9 +64,9 @@ static void scene_video_render(void *data)
} }
} }
static int scene_getsize(void *data) static uint32_t scene_getsize(void *data)
{ {
return -1; return 0;
} }
static bool scene_enum_children(void *data, size_t idx, obs_source_t *child) static bool scene_enum_children(void *data, size_t idx, obs_source_t *child)
@ -147,7 +147,7 @@ obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source)
return item; return item;
} }
void obs_sceneitem_remove(obs_sceneitem_t item) void obs_sceneitem_destroy(obs_sceneitem_t item)
{ {
if (item) { if (item) {
da_erase_item(item->parent->items, item); da_erase_item(item->parent->items, item);

View file

@ -98,6 +98,7 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *name,
case SOURCE_INPUT: list = &obs->input_types.da; break; case SOURCE_INPUT: list = &obs->input_types.da; break;
case SOURCE_FILTER: list = &obs->filter_types.da; break; case SOURCE_FILTER: list = &obs->filter_types.da; break;
case SOURCE_TRANSITION: list = &obs->transition_types.da; break; case SOURCE_TRANSITION: list = &obs->transition_types.da; break;
case SOURCE_SCENE:
default: default:
return NULL; return NULL;
} }
@ -180,14 +181,14 @@ void obs_source_video_render(obs_source_t source)
} }
} }
int obs_source_getwidth(obs_source_t source) uint32_t obs_source_getwidth(obs_source_t source)
{ {
if (source->callbacks.getwidth) if (source->callbacks.getwidth)
return source->callbacks.getwidth(source->data); return source->callbacks.getwidth(source->data);
return 0; return 0;
} }
int obs_source_getheight(obs_source_t source) uint32_t obs_source_getheight(obs_source_t source)
{ {
if (source->callbacks.getheight) if (source->callbacks.getheight)
return source->callbacks.getheight(source->data); return source->callbacks.getheight(source->data);
@ -225,7 +226,7 @@ obs_source_t obs_filter_gettarget(obs_source_t filter)
void obs_source_filter_add(obs_source_t source, obs_source_t filter) void obs_source_filter_add(obs_source_t source, obs_source_t filter)
{ {
if (da_find(source->filters, &filter, 0) != -1) { if (da_find(source->filters, &filter, 0) != DARRAY_INVALID) {
blog(LOG_WARNING, "Tried to add a filter that was already " blog(LOG_WARNING, "Tried to add a filter that was already "
"present on the source"); "present on the source");
return; return;
@ -243,7 +244,7 @@ void obs_source_filter_add(obs_source_t source, obs_source_t filter)
void obs_source_filter_remove(obs_source_t source, obs_source_t filter) void obs_source_filter_remove(obs_source_t source, obs_source_t filter)
{ {
size_t idx = da_find(source->filters, &filter, 0); size_t idx = da_find(source->filters, &filter, 0);
if (idx == -1) if (idx == DARRAY_INVALID)
return; return;
if (idx > 0) { if (idx > 0) {
@ -260,7 +261,7 @@ void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
{ {
size_t idx = da_find(source->filters, &filter, 0); size_t idx = da_find(source->filters, &filter, 0);
size_t i; size_t i;
if (idx == -1) if (idx == DARRAY_INVALID)
return; return;
if (movement == ORDER_MOVE_UP) { if (movement == ORDER_MOVE_UP) {

View file

@ -76,12 +76,12 @@
* + SOURCE_ASYNC: video is sent asynchronously via RAM * + SOURCE_ASYNC: video is sent asynchronously via RAM
* *
* --------------------------------------------------------- * ---------------------------------------------------------
* int [name]_getwidth(void *data); * uint32_t [name]_getwidth(void *data);
* Returns the width of a source, or -1 for maximum width. If you render * Returns the width of a source, or -1 for maximum width. If you render
* video, this is required. * video, this is required.
* *
* --------------------------------------------------------- * ---------------------------------------------------------
* int [name]_getheight(void *data); * uint32_t [name]_getheight(void *data);
* Returns the height of a source, or -1 for maximum height. If you * Returns the height of a source, or -1 for maximum height. If you
* render video, this is required. * render video, this is required.
* *
@ -170,8 +170,8 @@ struct source_info {
void (*video_tick)(void *data, float seconds); void (*video_tick)(void *data, float seconds);
void (*video_render)(void *data); void (*video_render)(void *data);
int (*getwidth)(void *data); uint32_t (*getwidth)(void *data);
int (*getheight)(void *data); uint32_t (*getheight)(void *data);
size_t (*getparam)(void *data, const char *param, void *data_out, size_t (*getparam)(void *data, const char *param, void *data_out,
size_t buf_size); size_t buf_size);

View file

@ -42,17 +42,21 @@ static inline void render_displays(void)
struct vec4 clear_color; struct vec4 clear_color;
vec4_set(&clear_color, 0.3f, 0.0f, 0.0f, 1.0f); vec4_set(&clear_color, 0.3f, 0.0f, 0.0f, 1.0f);
gs_ortho(0.0f, (float)obs->output_width,
0.0f, (float)obs->output_height,
-100.0f, 100.0f);
for (i = 0; i < obs->displays.num; i++) { for (i = 0; i < obs->displays.num; i++) {
uint32_t cx, cy;
obs_display_t display = obs->displays.array[i]; obs_display_t display = obs->displays.array[i];
gs_load_swapchain(display->swap); gs_load_swapchain(display->swap);
cx = gs_getwidth();
cy = gs_getheight();
gs_beginscene(); gs_beginscene();
gs_setviewport(0, 0, gs_getwidth(), gs_getheight()); gs_setviewport(0, 0, (int)cx, (int)cy);
gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
gs_setviewport(0, 0, obs->output_width, obs->output_height);
if (display->source) if (display->source)
obs_source_video_render(display->source); obs_source_video_render(display->source);
@ -71,7 +75,10 @@ static inline void render_displays(void)
gs_enable_blending(false); gs_enable_blending(false);
gs_setcullmode(GS_NEITHER); gs_setcullmode(GS_NEITHER);
gs_setviewport(0, 0, gs_getwidth(), gs_getheight()); gs_ortho(0.0f, (float)obs->output_width,
0.0f, (float)obs->output_height,
-100.0f, 100.0f);
gs_setviewport(0, 0, obs->output_width, obs->output_height);
if (obs->primary_source) if (obs->primary_source)
obs_source_video_render(obs->primary_source); obs_source_video_render(obs->primary_source);
@ -113,7 +120,6 @@ static bool swap_frame(uint64_t timestamp)
void *obs_video_thread(void *param) void *obs_video_thread(void *param)
{ {
struct obs_data *obs = param;
uint64_t last_time = 0; uint64_t last_time = 0;
while (video_output_wait(obs->video)) { while (video_output_wait(obs->video)) {

View file

@ -182,7 +182,7 @@ EXPORT void obs_source_destroy(obs_source_t source);
* SOURCE_ASYNC if the video is asynchronous. * SOURCE_ASYNC if the video is asynchronous.
* SOURCE_AUDIO if it presents/modifies audio (always async) * SOURCE_AUDIO if it presents/modifies audio (always async)
*/ */
EXPORT uint32_t obs_source_get_obs_output_flags(obs_source_t source); EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
/** Specifies whether the source can be configured */ /** Specifies whether the source can be configured */
EXPORT bool obs_source_hasconfig(obs_source_t source); EXPORT bool obs_source_hasconfig(obs_source_t source);
@ -194,10 +194,10 @@ EXPORT void obs_source_config(obs_source_t source, void *parent);
EXPORT void obs_source_video_render(obs_source_t source); EXPORT void obs_source_video_render(obs_source_t source);
/** Gets the width of a source (if it has video) */ /** Gets the width of a source (if it has video) */
EXPORT int obs_source_getwidth(obs_source_t source); EXPORT uint32_t obs_source_getwidth(obs_source_t source);
/** Gets the height of a source (if it has video) */ /** Gets the height of a source (if it has video) */
EXPORT int obs_source_getheight(obs_source_t source); EXPORT uint32_t obs_source_getheight(obs_source_t source);
/** /**
* Gets a custom parameter from the source. * Gets a custom parameter from the source.

View file

@ -33,13 +33,18 @@
*/ */
#define ALIGNMENT 16 #define ALIGNMENT 16
#if defined(_WIN32) && !defined(_WIN64)
#define ALIGNED_MALLOC 1
#elif !defined(__LP64__)
#define ALIGNMENT_HACK 1 #define ALIGNMENT_HACK 1
#endif
static void *a_malloc(size_t size) static void *a_malloc(size_t size)
{ {
#ifdef _WIN32 #ifdef ALIGNED_MALLOC
return _aligned_malloc(size, ALIGNMENT); return _aligned_malloc(size, ALIGNMENT);
#else #elif ALIGNMENT_HACK
void *ptr = NULL; void *ptr = NULL;
long diff; long diff;
@ -49,14 +54,16 @@ static void *a_malloc(size_t size)
((char *)ptr)[-1] = (char)diff; ((char *)ptr)[-1] = (char)diff;
return ptr; return ptr;
#else
return malloc(size);
#endif #endif
} }
static void *a_realloc(void *ptr, size_t size) static void *a_realloc(void *ptr, size_t size)
{ {
#ifdef _WIN32 #ifdef ALIGNED_MALLOC
return _aligned_realloc(ptr, size, ALIGNMENT); return _aligned_realloc(ptr, size, ALIGNMENT);
#else #elif ALIGNMENT_HACK
long diff; long diff;
if (!ptr) if (!ptr)
@ -66,16 +73,20 @@ static void *a_realloc(void *ptr, size_t size)
if (ptr) if (ptr)
ptr = (char *)ptr + diff; ptr = (char *)ptr + diff;
return ptr; return ptr;
#else
return realloc(ptr, size);
#endif #endif
} }
static void a_free(void *ptr) static void a_free(void *ptr)
{ {
#ifdef _WIN32 #ifdef ALIGNED_MALLOC
_aligned_free(ptr); _aligned_free(ptr);
#else #elif ALIGNMENT_HACK
if (ptr) if (ptr)
free((char *)ptr - ((char*)ptr)[-1]); free((char *)ptr - ((char*)ptr)[-1]);
#else
free(ptr);
#endif #endif
} }

View file

@ -131,7 +131,7 @@ static bool cf_is_token_break(struct base_token *start_token,
break; break;
} }
default: case BASETOKEN_NONE:
return true; return true;
} }
@ -196,7 +196,8 @@ static bool cf_lexer_process_comment(struct cf_lexer *lex,
} }
} }
out_token->unmerged_str.len += offset - out_token->unmerged_str.array; out_token->unmerged_str.len +=
(size_t)(offset - out_token->unmerged_str.array);
out_token->type = CFTOKEN_SPACETAB; out_token->type = CFTOKEN_SPACETAB;
lex->base_lexer.offset = offset; lex->base_lexer.offset = offset;
@ -277,7 +278,8 @@ static void cf_lexer_getstrtoken(struct cf_lexer *lex,
} }
*lex->write_offset = 0; *lex->write_offset = 0;
out_token->unmerged_str.len += offset - out_token->unmerged_str.array; out_token->unmerged_str.len +=
(size_t)(offset - out_token->unmerged_str.array);
out_token->type = CFTOKEN_STRING; out_token->type = CFTOKEN_STRING;
lex->base_lexer.offset = offset; lex->base_lexer.offset = offset;
} }
@ -316,7 +318,8 @@ static inline enum cf_token_type cf_get_token_type(const struct cf_token *token,
else else
return CFTOKEN_SPACETAB; return CFTOKEN_SPACETAB;
default: case BASETOKEN_NONE:
case BASETOKEN_OTHER:
break; break;
} }
@ -370,8 +373,8 @@ static bool cf_lexer_nexttoken(struct cf_lexer *lex, struct cf_token *out_token)
} }
if (wrote_data) { if (wrote_data) {
out_token->unmerged_str.len = lex->base_lexer.offset - out_token->unmerged_str.len = (size_t)(lex->base_lexer.offset -
out_token->unmerged_str.array; out_token->unmerged_str.array);
out_token->type = cf_get_token_type(out_token, &start_token); out_token->type = cf_get_token_type(out_token, &start_token);
} }
@ -738,6 +741,8 @@ exit:
return success; return success;
} }
#define INVALID_INDEX ((size_t)-1)
static inline size_t cf_preprocess_get_def_idx(struct cf_preprocessor *pp, static inline size_t cf_preprocess_get_def_idx(struct cf_preprocessor *pp,
const struct strref *def_name) const struct strref *def_name)
{ {
@ -751,14 +756,14 @@ static inline size_t cf_preprocess_get_def_idx(struct cf_preprocessor *pp,
return i; return i;
} }
return -1; return INVALID_INDEX;
} }
static inline struct cf_def *cf_preprocess_get_def(struct cf_preprocessor *pp, static inline struct cf_def *cf_preprocess_get_def(struct cf_preprocessor *pp,
const struct strref *def_name) const struct strref *def_name)
{ {
size_t idx = cf_preprocess_get_def_idx(pp, def_name); size_t idx = cf_preprocess_get_def_idx(pp, def_name);
if (idx == -1) if (idx == INVALID_INDEX)
return NULL; return NULL;
return pp->defines.array+idx; return pp->defines.array+idx;
@ -844,7 +849,7 @@ static inline void cf_preprocess_remove_def_strref(struct cf_preprocessor *pp,
const struct strref *ref) const struct strref *ref)
{ {
size_t def_idx = cf_preprocess_get_def_idx(pp, ref); size_t def_idx = cf_preprocess_get_def_idx(pp, ref);
if (def_idx != -1) { if (def_idx != INVALID_INDEX) {
struct cf_def *array = pp->defines.array; struct cf_def *array = pp->defines.array;
cf_def_free(array+def_idx); cf_def_free(array+def_idx);
da_erase(pp->defines, def_idx); da_erase(pp->defines, def_idx);

View file

@ -163,7 +163,7 @@ static inline bool go_to_token_type(struct cf_parser *p,
enum cf_token_type type) enum cf_token_type type)
{ {
while (p->cur_token->type != CFTOKEN_NONE && while (p->cur_token->type != CFTOKEN_NONE &&
p->cur_token->type != CFTOKEN_NEWLINE) p->cur_token->type != type)
p->cur_token++; p->cur_token++;
return p->cur_token->type != CFTOKEN_NONE; return p->cur_token->type != CFTOKEN_NONE;

View file

@ -172,7 +172,8 @@ static void config_parse_section(struct config_section *section,
} }
} }
static int config_parse(struct darray *sections, const char *file) static int config_parse(struct darray *sections, const char *file,
bool always_open)
{ {
char *file_data; char *file_data;
struct lexer lex; struct lexer lex;
@ -181,6 +182,8 @@ static int config_parse(struct darray *sections, const char *file)
FILE *f; FILE *f;
f = os_fopen(file, "rb"); f = os_fopen(file, "rb");
if (always_open && !f)
f = os_fopen(file, "w+");
if (!f) if (!f)
return CONFIG_FILENOTFOUND; return CONFIG_FILENOTFOUND;
@ -238,7 +241,7 @@ int config_open(config_t *config, const char *file, bool always_open)
*config = bmalloc(sizeof(struct config_data)); *config = bmalloc(sizeof(struct config_data));
memset(*config, 0, sizeof(struct config_data)); memset(*config, 0, sizeof(struct config_data));
errorcode = config_parse(&(*config)->sections, file); errorcode = config_parse(&(*config)->sections, file, always_open);
if (errorcode != CONFIG_SUCCESS) { if (errorcode != CONFIG_SUCCESS) {
config_close(*config); config_close(*config);
@ -253,7 +256,7 @@ int config_open_defaults(config_t config, const char *file)
if (!config) if (!config)
return CONFIG_ERROR; return CONFIG_ERROR;
return config_parse(&config->defaults, file); return config_parse(&config->defaults, file, false);
} }
int config_save(config_t config) int config_save(config_t config)

View file

@ -43,6 +43,8 @@ extern "C" {
* See DARRAY macro at the bottom of thhe file for slightly safer usage. * See DARRAY macro at the bottom of thhe file for slightly safer usage.
*/ */
#define DARRAY_INVALID ((size_t)-1)
struct darray { struct darray {
void *array; void *array;
size_t num; size_t num;
@ -186,7 +188,7 @@ static inline size_t darray_find(const size_t element_size,
return i; return i;
} }
return -1; return DARRAY_INVALID;
} }
static inline size_t darray_push_back(const size_t element_size, static inline size_t darray_push_back(const size_t element_size,
@ -322,7 +324,7 @@ static inline void darray_erase_item(const size_t element_size,
struct darray *dst, const void *item) struct darray *dst, const void *item)
{ {
size_t idx = darray_find(element_size, dst, item, 0); size_t idx = darray_find(element_size, dst, item, 0);
if (idx != (size_t)-1) if (idx != DARRAY_INVALID)
darray_erase(element_size, dst, idx); darray_erase(element_size, dst, idx);
} }

View file

@ -46,8 +46,8 @@ int astrcmpi(const char *str1, const char *str2)
str2 = astrblank; str2 = astrblank;
do { do {
char ch1 = toupper(*str1); char ch1 = (char)toupper(*str1);
char ch2 = toupper(*str2); char ch2 = (char)toupper(*str2);
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;
@ -66,8 +66,8 @@ int wstrcmpi(const wchar_t *str1, const wchar_t *str2)
str2 = wstrblank; str2 = wstrblank;
do { do {
wchar_t ch1 = towupper(*str1); wchar_t ch1 = (wchar_t)towupper(*str1);
wchar_t ch2 = towupper(*str2); wchar_t ch2 = (wchar_t)towupper(*str2);
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;
@ -132,8 +132,8 @@ int astrcmpi_n(const char *str1, const char *str2, size_t n)
str2 = astrblank; str2 = astrblank;
do { do {
char ch1 = toupper(*str1); char ch1 = (char)toupper(*str1);
char ch2 = toupper(*str2); char ch2 = (char)toupper(*str2);
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;
@ -154,8 +154,8 @@ int wstrcmpi_n(const wchar_t *str1, const wchar_t *str2, size_t n)
str2 = wstrblank; str2 = wstrblank;
do { do {
wchar_t ch1 = towupper(*str1); wchar_t ch1 = (wchar_t)towupper(*str1);
wchar_t ch2 = towupper(*str2); wchar_t ch2 = (wchar_t)towupper(*str2);
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;
@ -476,7 +476,7 @@ void dstr_replace(struct dstr *str, const char *find,
temp = str->array; temp = str->array;
if (replace_len < find_len) { if (replace_len < find_len) {
int count = 0; unsigned long count = 0;
while ((temp = strstr(temp, find)) != NULL) { while ((temp = strstr(temp, find)) != NULL) {
char *end = temp+find_len; char *end = temp+find_len;
@ -498,7 +498,7 @@ void dstr_replace(struct dstr *str, const char *find,
str->len += (replace_len-find_len) * count; str->len += (replace_len-find_len) * count;
} else if (replace_len > find_len) { } else if (replace_len > find_len) {
int count = 0; unsigned long count = 0;
while ((temp = strstr(temp, find)) != NULL) { while ((temp = strstr(temp, find)) != NULL) {
temp += find_len; temp += find_len;
@ -595,17 +595,3 @@ void dstr_from_wcs(struct dstr *dst, const wchar_t *wstr)
dstr_free(dst); dstr_free(dst);
} }
} }
wchar_t *dstr_to_utf8(const struct dstr *str)
{
wchar_t *out = NULL;
size_t len = utf8_to_wchar(str->array, str->len, NULL, 0, 0);
if (len) {
out = bmalloc((len+1) * sizeof(wchar_t));
utf8_to_wchar(str->array, str->len, out, len+1, 0);
out[len] = 0;
}
return out;
}

View file

@ -67,8 +67,8 @@ int strref_cmpi(const struct strref *str1, const char *str2)
do { do {
char ch1, ch2; char ch1, ch2;
ch1 = (i < str1->len) ? toupper(str1->array[i]) : 0; ch1 = (i < str1->len) ? (char)toupper(str1->array[i]) : 0;
ch2 = toupper(*str2); ch2 = (char)toupper(*str2);
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;
@ -117,8 +117,8 @@ int strref_cmpi_strref(const struct strref *str1, const struct strref *str2)
do { do {
char ch1, ch2; char ch1, ch2;
ch1 = (i < str1->len) ? toupper(str1->array[i]) : 0; ch1 = (i < str1->len) ? (char)toupper(str1->array[i]) : 0;
ch2 = (i < str2->len) ? toupper(str2->array[i]) : 0; ch2 = (i < str2->len) ? (char)toupper(str2->array[i]) : 0;
if (ch1 < ch2) if (ch1 < ch2)
return -1; return -1;

View file

@ -21,8 +21,6 @@
distribution. distribution.
******************************************************************************/ ******************************************************************************/
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#include "base.h" #include "base.h"
#include "platform.h" #include "platform.h"
@ -165,5 +163,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
} }
#endif #endif
#endif

View file

@ -84,11 +84,11 @@ off_t os_fgetsize(FILE *file)
size_t os_fread_mbs(FILE *file, char **pstr) size_t os_fread_mbs(FILE *file, char **pstr)
{ {
off_t size = 0; size_t size = 0;
size_t len = 0; size_t len = 0;
fseeko(file, 0, SEEK_END); fseeko(file, 0, SEEK_END);
size = ftello(file); size = (size_t)ftello(file);
if (size > 0) { if (size > 0) {
char *mbstr = bmalloc(size+1); char *mbstr = bmalloc(size+1);
@ -107,11 +107,11 @@ size_t os_fread_mbs(FILE *file, char **pstr)
size_t os_fread_utf8(FILE *file, char **pstr) size_t os_fread_utf8(FILE *file, char **pstr)
{ {
off_t size = 0; size_t size = 0;
size_t len = 0; size_t len = 0;
fseeko(file, 0, SEEK_END); fseeko(file, 0, SEEK_END);
size = ftello(file); size = (size_t)ftello(file);
if (size > 0) { if (size > 0) {
char bom[3]; char bom[3];
@ -244,7 +244,7 @@ size_t os_wcs_to_mbs(const wchar_t *str, size_t len, char **pstr)
size_t os_wcs_to_utf8(const wchar_t *str, size_t len, char **pstr) size_t os_wcs_to_utf8(const wchar_t *str, size_t len, char **pstr)
{ {
size_t in_len = wcslen(str); size_t in_len = (len != 0) ? len : wcslen(str);
size_t out_len = wchar_to_utf8(str, in_len, NULL, 0, 0); size_t out_len = wchar_to_utf8(str, in_len, NULL, 0, 0);
char *dst = NULL; char *dst = NULL;

View file

@ -48,6 +48,9 @@ EXPORT size_t os_fread_utf8(FILE *file, char **pstr);
EXPORT char *os_quick_read_utf8_file(const char *path); EXPORT char *os_quick_read_utf8_file(const char *path);
EXPORT bool os_quick_write_utf8_file(const char *path, const char *str, EXPORT bool os_quick_write_utf8_file(const char *path, const char *str,
size_t len, bool marker); size_t len, bool marker);
EXPORT char *os_quick_read_mbs_file(const char *path);
EXPORT bool os_quick_write_mbs_file(const char *path, const char *str,
size_t len);
EXPORT size_t os_mbs_to_wcs(const char *str, size_t len, wchar_t **pstr); EXPORT size_t os_mbs_to_wcs(const char *str, size_t len, wchar_t **pstr);
EXPORT size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t **pstr); EXPORT size_t os_utf8_to_wcs(const char *str, size_t len, wchar_t **pstr);

View file

@ -117,7 +117,7 @@ static void lookup_createsubnode(const char *lookup_val,
new->leaf = leaf; new->leaf = leaf;
dstr_copy(&new->str, lookup_val); dstr_copy(&new->str, lookup_val);
darray_push_back(sizeof(struct text_node*), &new->subnodes, &new); darray_push_back(sizeof(struct text_node*), &node->subnodes, &new);
} }
static void lookup_splitnode(const char *lookup_val, size_t len, static void lookup_splitnode(const char *lookup_val, size_t len,
@ -197,7 +197,8 @@ static void lookup_getstringtoken(struct lexer *lex, struct strref *token)
++temp; ++temp;
} }
token->len += temp - lex->offset - 1; /* include starting " char */ /* include starting " char */
token->len += (size_t)(temp - lex->offset - 1);
lex->offset = temp; lex->offset = temp;
} }

View file

@ -74,12 +74,12 @@ void random_video_render(struct random_tex *rt, obs_source_t filter_target)
technique_end(tech); technique_end(tech);
} }
int random_getwidth(struct random_tex *rt) uint32_t random_getwidth(struct random_tex *rt)
{ {
return texture_getwidth(rt->texture); return texture_getwidth(rt->texture);
} }
int random_getheight(struct random_tex *rt) uint32_t random_getheight(struct random_tex *rt)
{ {
return texture_getheight(rt->texture); return texture_getheight(rt->texture);
} }

View file

@ -17,8 +17,8 @@ EXPORT uint32_t random_get_output_flags(struct random_tex *rt);
EXPORT void random_video_render(struct random_tex *rt, obs_source_t filter_target); EXPORT void random_video_render(struct random_tex *rt, obs_source_t filter_target);
EXPORT int random_getwidth(struct random_tex *rt); EXPORT uint32_t random_getwidth(struct random_tex *rt);
EXPORT int random_getheight(struct random_tex *rt); EXPORT uint32_t random_getheight(struct random_tex *rt);
#ifdef __cplusplus #ifdef __cplusplus
} }