| 356 | } |
| 357 | |
| 358 | static s32 compile_light(Buffer &output, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts) |
| 359 | { |
| 360 | CE_UNUSED(compiler); |
| 361 | |
| 362 | TempAllocator4096 ta; |
| 363 | DynamicString type(ta); |
| 364 | RETURN_IF_ERROR(sjson::parse_string(type, flat_json_object::get(obj, "data.type"))); |
| 365 | |
| 366 | LightType::Enum lt = light_name_to_enum(type.c_str()); |
| 367 | RETURN_IF_FALSE(UNIT_COMPILER, lt != LightType::COUNT |
| 368 | , opts |
| 369 | , "Unknown light type: '%s'" |
| 370 | , type.c_str() |
| 371 | ); |
| 372 | |
| 373 | LightDesc ld; |
| 374 | ld.type = lt; |
| 375 | ld.range = RETURN_IF_ERROR(sjson::parse_float (flat_json_object::get(obj, "data.range"))); |
| 376 | ld.intensity = RETURN_IF_ERROR(sjson::parse_float (flat_json_object::get(obj, "data.intensity"))); |
| 377 | ld.spot_angle = RETURN_IF_ERROR(sjson::parse_float (flat_json_object::get(obj, "data.spot_angle"))); |
| 378 | ld.color = RETURN_IF_ERROR(sjson::parse_vector3(flat_json_object::get(obj, "data.color"))); |
| 379 | ld.shadow_bias = 0.0004f; |
| 380 | if (flat_json_object::has(obj, "data.shadow_bias")) { |
| 381 | ld.shadow_bias = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.shadow_bias"))); |
| 382 | } |
| 383 | ld.flags = 0u; |
| 384 | if (flat_json_object::has(obj, "data.cast_shadows")) { |
| 385 | bool cast_shadows = RETURN_IF_ERROR(sjson::parse_bool(flat_json_object::get(obj, "data.cast_shadows"))); |
| 386 | ld.flags |= cast_shadows ? RenderableFlags::SHADOW_CASTER : 0u; |
| 387 | } else { |
| 388 | ld.flags |= RenderableFlags::SHADOW_CASTER; |
| 389 | } |
| 390 | |
| 391 | FileBuffer fb(output); |
| 392 | BinaryWriter bw(fb); |
| 393 | bw.write(ld.type); |
| 394 | bw.write(ld.range); |
| 395 | bw.write(ld.intensity); |
| 396 | bw.write(ld.spot_angle); |
| 397 | bw.write(ld.color); |
| 398 | bw.write(ld.shadow_bias); |
| 399 | bw.write(ld.flags); |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static s32 compile_script(Buffer &output, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts) |
| 404 | { |
nothing calls this directly
no test coverage detected