diff --git a/base.mk b/base.mk index b715af4..411afb4 100644 --- a/base.mk +++ b/base.mk @@ -108,6 +108,12 @@ endef %.mod.o: %.mod $(BUILD_BINARY_O) +%.bsp.h: %.bsp + $(BUILD_BINARY_H) + +%.bsp.o: %.bsp + $(BUILD_BINARY_O) + %.o: %.s $(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@ diff --git a/example/example.mk b/example/example.mk index d06eb5a..d86eb77 100644 --- a/example/example.mk +++ b/example/example.mk @@ -990,7 +990,6 @@ BOIDS_OBJ = \ example/boids.elf: LDSCRIPT = $(LIB)/main.lds example/boids.elf: $(START_OBJ) $(BOIDS_OBJ) - MOD_OBJ = \ example/mod.o \ holly/core.o \ @@ -1005,3 +1004,22 @@ MOD_OBJ = \ example/mod.elf: LDSCRIPT = $(LIB)/main.lds example/mod.elf: $(START_OBJ) $(MOD_OBJ) + +Q3BSP_OBJ = \ + example/q3bsp.o \ + holly/core.o \ + holly/region_array.o \ + holly/background.o \ + holly/ta_fifo_polygon_converter.o \ + holly/video_output.o \ + sh7091/serial.o \ + sh7091/c_serial.o \ + printf/printf.o \ + printf/unparse.o \ + printf/parse.o \ + pk/maps/20kdm2.bsp.o \ + interrupt.o \ + $(LIBGCC) + +example/q3bsp.elf: LDSCRIPT = $(LIB)/main.lds +example/q3bsp.elf: $(START_OBJ) $(Q3BSP_OBJ) diff --git a/example/q3bsp.cpp b/example/q3bsp.cpp new file mode 100644 index 0000000..c7a723e --- /dev/null +++ b/example/q3bsp.cpp @@ -0,0 +1,509 @@ +#include "holly/background.hpp" +#include "holly/core.hpp" +#include "holly/core_bits.hpp" +#include "holly/holly.hpp" +#include "holly/isp_tsp.hpp" +#include "holly/region_array.hpp" +#include "holly/ta_bits.hpp" +#include "holly/ta_fifo_polygon_converter.hpp" +#include "holly/ta_global_parameter.hpp" +#include "holly/ta_parameter.hpp" +#include "holly/ta_vertex_parameter.hpp" +#include "holly/texture_memory_alloc3.hpp" +#include "holly/video_output.hpp" + +#include "systembus.hpp" +#include "systembus_bits.hpp" + +#include "memorymap.hpp" + +#include "sh7091/serial.hpp" +#include "printf/printf.h" + +#include "q3bsp/q3bsp.h" +#include "pk/maps/20kdm2.bsp.h" + +#include "math/vec2.hpp" +#include "math/vec3.hpp" +#include "math/vec4.hpp" +#include "math/mat4x4.hpp" +#include "math/geometry.hpp" + +#include "interrupt.hpp" + +using vec2 = vec<2, float>; +using vec3 = vec<3, float>; +using vec4 = vec<4, float>; +using mat4x4 = mat<4, 4, float>; + +#define _fsrra(n) (1.0f / (__builtin_sqrtf(n))) + +void print_direntries(struct q3bsp_header * header) +{ + // direntries + static const char * lump_name[] = { + "entities", + "textures", + "planes", + "nodes", + "leafs", + "leaffaces", + "leafbrushes", + "models", + "brushes", + "brushsides", + "vertexes", + "meshverts", + "effects", + "faces", + "lightmaps", + "lightvols", + "visdata", + }; + for (int i = 0; i < 17; i++) { + printf("%s offset=%d length=%d\n", + lump_name[i], + header->direntries[i].offset, + header->direntries[i].length); + } +} + +void print_header(void * buf) +{ + q3bsp_header_t * header = reinterpret_cast(buf); + + serial::string("magic: "); + serial::string((uint8_t *)header->magic, 4); + serial::character('\n'); + printf("version: %x\n", header->version); + + print_direntries(header); +} + +void print_textures(void * buf, int length) +{ + q3bsp_texture_t * texture = reinterpret_cast(buf); + + int count = length / (sizeof (struct q3bsp_texture)); + + for (int i = 0; i < count; i++) { + printf("texture [%d]\n", i); + printf(" name=%s\n", texture[i].name); + printf(" flags=%x\n", texture[i].flags); + printf(" contents=%x\n", texture[i].contents); + } +} + +void print_models(void * buf, int length) +{ + q3bsp_model_t * model = reinterpret_cast(buf); + + int count = length / (sizeof (struct q3bsp_model)); + + for (int i = 0; i < count; i++) { + printf("model [%d]\n", i); + printf(" mins={%f, %f, %f}\n", model->mins[0], model->mins[2], model->mins[2]); + printf(" maxs={%f, %f, %f}\n", model->maxs[0], model->maxs[2], model->maxs[2]); + printf(" face=%d\n", model->face); + printf(" n_faces=%d\n", model->n_faces); + printf(" brush=%d\n", model->brush); + printf(" n_brushes=%d\n", model->n_brushes); + } +} + +void print_faces(void * buf, int length) +{ + q3bsp_face_t * face = reinterpret_cast(buf); + + int count = length / (sizeof (struct q3bsp_face)); + + printf("faces count: %d\n", count); + for (int i = 0; i < count; i++) { + printf("face [%d]\n", i); + printf(" type=%d n_vertexes=%d n_meshverts=%d\n", face[i].type, face[i].n_vertexes, face[i].n_meshverts); + } +} + +void debug_print_q3bsp(uint8_t * buf, q3bsp_header_t * header) +{ + // header + print_header(buf); + + { + q3bsp_direntry * e = &header->direntries[LUMP_TEXTURES]; + print_textures(&buf[e->offset], e->length); + } + + { + q3bsp_direntry * e = &header->direntries[LUMP_MODELS]; + print_models(&buf[e->offset], e->length); + } + + { + q3bsp_direntry * e = &header->direntries[LUMP_FACES]; + print_faces(&buf[e->offset], e->length); + } +} + +struct position_normal { + vec3 position; + vec3 normal; +}; + +static position_normal vertex_cache[16384]; + +static inline vec3 normal_transform(mat4x4& trans, vec3 normal) +{ + vec4 n = trans * (vec4){normal.x, normal.y, normal.z, 0.f}; // no translation component + return {n.x, n.y, n.z}; +} + +static inline vec3 screen_transform(vec3 v) +{ + float dim = 480 / 2.0; + + return { + v.x / (1.f * v.z) * dim + 640 / 2.0f, + v.y / (1.f * v.z) * dim + 480 / 2.0f, + 1 / v.z, + }; +} + +void global_polygon_type_1(ta_parameter_writer& writer) +{ + const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume + | para_control::list_type::opaque + | obj_control::col_type::intensity_mode_1 + | obj_control::gouraud + | obj_control::shadow + ; + const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater + | isp_tsp_instruction_word::culling_mode::no_culling + ; + + const uint32_t tsp_instruction_word = tsp_instruction_word::fog_control::no_fog + | tsp_instruction_word::src_alpha_instr::one + | tsp_instruction_word::dst_alpha_instr::zero + ; + + const uint32_t texture_control_word = 0; + + const float a = 1.0f; + const float r = 1.0f; + const float g = 1.0f; + const float b = 1.0f; + + writer.append() = + ta_global_parameter::polygon_type_1(parameter_control_word, + isp_tsp_instruction_word, + tsp_instruction_word, + texture_control_word, + a, + r, + g, + b + ); +} + +void transform_vertices(uint8_t * buf, int length, mat4x4& trans) +{ + q3bsp_vertex_t * vert = reinterpret_cast(buf); + + int count = length / (sizeof (struct q3bsp_vertex)); + + for (int i = 0; i < count; i++) { + vec3 v = {vert[i].position[0], vert[i].position[1], vert[i].position[2]}; + vec3 n = {vert[i].normal[0], vert[i].normal[1], vert[i].normal[2]}; + + //printf("%f %f %f\n", v.x, v.y, v.z); + + vertex_cache[i].position = screen_transform(trans * v); + vertex_cache[i].normal = normal_transform(trans, n); + } +} + +static inline void render_tri(ta_parameter_writer& writer, + vec3 ap, + vec3 bp, + vec3 cp, + float ai, + float bi, + float ci) +{ + writer.append() = + ta_vertex_parameter::polygon_type_2(polygon_vertex_parameter_control_word(false), + ap.x, ap.y, ap.z, + ai); + + writer.append() = + ta_vertex_parameter::polygon_type_2(polygon_vertex_parameter_control_word(false), + bp.x, bp.y, bp.z, + bi); + + writer.append() = + ta_vertex_parameter::polygon_type_2(polygon_vertex_parameter_control_word(true), + cp.x, cp.y, cp.z, + ci); +} + +static inline float inverse_length(vec3 v) +{ + float f = dot(v, v); + return _fsrra(f); +} + +float light_intensity(vec3 light_vec, vec3 n) +{ + float n_dot_l = dot(n, light_vec); + + float intensity = 0.4f; + if (n_dot_l > 0) { + intensity += 0.5f * n_dot_l * (inverse_length(n) * inverse_length(light_vec)); + if (intensity > 1.0f) + intensity = 1.0f; + } + return intensity; +} + +void transfer_faces(uint8_t * buf, q3bsp_header_t * header, ta_parameter_writer& writer) +{ + q3bsp_direntry * me = &header->direntries[LUMP_MESHVERTS]; + q3bsp_direntry * fe = &header->direntries[LUMP_FACES]; + + q3bsp_meshvert_t * meshvert = reinterpret_cast(&buf[me->offset]); + q3bsp_face_t * face = reinterpret_cast(&buf[fe->offset]); + + int face_count = fe->length / (sizeof (struct q3bsp_face)); + + const vec3 light_vec = {20, 20, 200}; + + for (int i = 0; i < face_count; i++) { + int meshvert_ix = face[i].meshvert; + q3bsp_meshvert_t * mv = &meshvert[meshvert_ix]; + + int triangles = face[i].n_meshverts / 3; + for (int j = 0; j < triangles; j++) { + + int aix = mv[j * 3 + 0].offset + face[i].vertex; + int bix = mv[j * 3 + 1].offset + face[i].vertex; + int cix = mv[j * 3 + 2].offset + face[i].vertex; + + vec3 ap = vertex_cache[aix].position; + vec3 bp = vertex_cache[bix].position; + vec3 cp = vertex_cache[cix].position; + + if (ap.z < 0 || bp.z < 0 || cp.z < 0) { + continue; + } + + vec3 n = vertex_cache[aix].normal; + float i = light_intensity(light_vec, n); + + /* + printf("{%f %f %f} {%f %f %f} {%f %f %f}\n", + ap.x, ap.y, ap.z, + bp.x, bp.y, bp.z, + cp.x, cp.y, cp.z); + */ + + render_tri(writer, + ap, + bp, + cp, + i, + i, + i); + } + } +} + +/* + name=textures/common/caulk + name=textures/e7/e7walldesign01b + name=textures/e7/e7steptop2 + name=noshader + name=textures/e7/e7dimfloor + name=textures/e7/e7brickfloor01 + name=textures/e7/e7bmtrim + name=textures/e7/e7sbrickfloor + name=textures/e7/e7brnmetal + name=textures/common/clip + name=textures/e7/e7beam02_red + name=textures/e7/e7swindow + name=textures/e7/e7bigwall + name=textures/e7/e7panelwood + name=textures/e7/e7beam01 + name=textures/gothic_floor/xstepborder5 + name=textures/liquids/lavahell + name=textures/e7/e7steptop + name=textures/gothic_trim/metalblackwave01 + name=textures/stone/pjrock1 + name=textures/skies/tim_hell + name=textures/common/hint + name=models/mapobjects/timlamp/timlamp + name=textures/sfx/flame1side + name=textures/sfx/flame2 + name=models/mapobjects/gratelamp/gratetorch2 + name=models/mapobjects/gratelamp/gratetorch2b +*/ + +void transfer_scene(ta_parameter_writer& writer, const mat4x4& screen_trans) +{ + uint8_t * buf = reinterpret_cast(&_binary_pk_maps_20kdm2_bsp_start); + q3bsp_header_t * header = reinterpret_cast(buf); + + debug_print_q3bsp(buf, header); + while(1); + + mat4x4 trans = screen_trans; + + q3bsp_direntry * ve = &header->direntries[LUMP_VERTEXES]; + transform_vertices(&buf[ve->offset], ve->length, trans); + + global_polygon_type_1(writer); + + transfer_faces(buf, header, writer); + + writer.append() = + ta_global_parameter::end_of_list(para_control::para_type::end_of_list); +} + +uint8_t __attribute__((aligned(32))) ta_parameter_buf[1024 * 1024]; + +constexpr inline mat4x4 rotate_x(float t) +{ + mat4x4 r = { + 1, 0, 0, 0, + 0, cos(t), -sin(t), 0, + 0, sin(t), cos(t), 0, + 0, 0, 0, 1, + }; + return r; +} + +constexpr inline mat4x4 rotate_y(float t) +{ + mat4x4 r = { + cos(t), 0, sin(t), 0, + 0, 1, 0, 0, + -sin(t), 0, cos(t), 0, + 0, 0, 0, 1, + }; + return r; +} + +constexpr inline mat4x4 rotate_z(float t) +{ + mat4x4 r = { + cos(t), -sin(t), 0, 0, + sin(t), cos(t), 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + }; + return r; +} + +int main() +{ + serial::init(0); + + interrupt_init(); + + constexpr uint32_t ta_alloc = 0 + | ta_alloc_ctrl::pt_opb::no_list + | ta_alloc_ctrl::tm_opb::no_list + | ta_alloc_ctrl::t_opb::no_list + | ta_alloc_ctrl::om_opb::no_list + | ta_alloc_ctrl::o_opb::_16x4byte; + + constexpr int ta_cont_count = 1; + constexpr struct opb_size opb_size[ta_cont_count] = { + { + .opaque = 16 * 4, + .opaque_modifier = 0, + .translucent = 0, + .translucent_modifier = 0, + .punch_through = 0 + } + }; + + holly.SOFTRESET = softreset::pipeline_soft_reset + | softreset::ta_soft_reset; + holly.SOFTRESET = 0; + + core_init(); + + system.IML6NRM = istnrm::end_of_render_tsp; + + const int framebuffer_width = 640; + const int framebuffer_height = 480; + const int tile_width = framebuffer_width / 32; + const int tile_height = framebuffer_height / 32; + + for (int i = 0; i < 2; i++) { + region_array_multipass(tile_width, + tile_height, + opb_size, + ta_cont_count, + texture_memory_alloc.region_array[i].start, + texture_memory_alloc.object_list[i].start); + + background_parameter2(texture_memory_alloc.background[i].start, + 0xff202040); + } + + ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf); + + video_output::set_mode_vga(); + + int ta = 0; + int core = 0; + + mat4x4 screen_trans = { + 1, 0, 0, -1000, + 0, 1, 0, -1000, + 0, 0, 1, 1000, + 0, 0, 0, 1, + }; + + mat4x4 ztrans = { + 1, 0, 0, -1, + 0, 1, 0, -1, + 0, 0, 1, 1, + 0, 0, 0, 1, + }; + + while (1) { + //screen_trans = ztrans * screen_trans; + screen_trans = rotate_z(0.01) * screen_trans; + + ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[ta].start, + texture_memory_alloc.isp_tsp_parameters[ta].end, + texture_memory_alloc.object_list[ta].start, + texture_memory_alloc.object_list[ta].end, + opb_size[0].total(), + ta_alloc, + tile_width, + tile_height); + + writer.offset = 0; + transfer_scene(writer, screen_trans); + ta_polygon_converter_writeback(writer.buf, writer.offset); + ta_polygon_converter_transfer(writer.buf, writer.offset); + ta_wait_opaque_list(); + + render_done = 0; + core_start_render2(texture_memory_alloc.region_array[core].start, + texture_memory_alloc.isp_tsp_parameters[core].start, + texture_memory_alloc.background[core].start, + texture_memory_alloc.framebuffer[core].start, + framebuffer_width); + while (render_done == 0) { + asm volatile ("nop"); + }; + + while (spg_status::vsync(holly.SPG_STATUS)); + while (!spg_status::vsync(holly.SPG_STATUS)); + holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[ta].start; + } +} diff --git a/interrupt.cpp b/interrupt.cpp new file mode 100644 index 0000000..7314fea --- /dev/null +++ b/interrupt.cpp @@ -0,0 +1,145 @@ +#include "sh7091/sh7091.hpp" +#include "sh7091/sh7091_bits.hpp" +#include "sh7091/serial.hpp" +#include "sh7091/vbr.hpp" + +#include "systembus.hpp" +#include "systembus_bits.hpp" + +void vbr100() +{ + serial::string("vbr100\n"); + serial::string("expevt "); + serial::integer(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(sh7091.CCN.TRA); + + uint32_t spc; + uint32_t ssr; + asm volatile ("stc spc,%0" : "=r" (spc)); + asm volatile ("stc ssr,%0" : "=r" (ssr)); + serial::string("spc "); + serial::integer(spc); + serial::string("ssr "); + serial::integer(ssr); + + while (1); +} + +void vbr400() +{ + serial::string("vbr400\n"); + serial::string("expevt "); + serial::integer(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(sh7091.CCN.TRA); + + uint32_t spc; + uint32_t ssr; + asm volatile ("stc spc,%0" : "=r" (spc)); + asm volatile ("stc ssr,%0" : "=r" (ssr)); + serial::string("spc "); + serial::integer(spc); + serial::string("ssr "); + serial::integer(ssr); + + while (1); +} + +int render_done = 0; + +void vbr600() +{ + if (sh7091.CCN.EXPEVT == 0 && sh7091.CCN.INTEVT == 0x320) { + uint32_t istnrm = system.ISTNRM; + uint32_t isterr = system.ISTERR; + + if (isterr) { + serial::string("isterr: "); + serial::integer(system.ISTERR); + } + + if (istnrm & istnrm::end_of_render_tsp) { + system.ISTNRM = istnrm::end_of_render_tsp + | istnrm::end_of_render_isp + | istnrm::end_of_render_video; + render_done = 1; + return; + } + } + + serial::string("vbr600\n"); + serial::string("expevt "); + serial::integer(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(sh7091.CCN.TRA); + + serial::string("istnrm: "); + serial::integer(system.ISTNRM); + serial::string("isterr: "); + serial::integer(system.ISTERR); + + uint32_t spc; + uint32_t ssr; + asm volatile ("stc spc,%0" : "=r" (spc)); + asm volatile ("stc ssr,%0" : "=r" (ssr)); + serial::string("spc "); + serial::integer(spc); + serial::string("ssr "); + serial::integer(ssr); + + while (1); +} + +void interrupt_init() +{ + system.IML2NRM = 0; + system.IML2ERR = 0; + system.IML2EXT = 0; + + system.IML4NRM = 0; + system.IML4ERR = 0; + system.IML4EXT = 0; + + system.IML6NRM = 0; + system.IML6ERR = 0; + system.IML6EXT = 0; + + system.ISTERR = 0xffffffff; + system.ISTNRM = 0xffffffff; + + sh7091.CCN.INTEVT = 0; + sh7091.CCN.EXPEVT = 0; + + uint32_t vbr = reinterpret_cast(&__vbr_link_start) - 0x100; + serial::string("vbr "); + serial::integer(vbr); + serial::string("vbr100 "); + serial::integer(reinterpret_cast(&vbr100)); + + asm volatile ("ldc %0,vbr" + : + : "r" (vbr)); + + uint32_t sr; + asm volatile ("stc sr,%0" + : "=r" (sr)); + serial::string("sr "); + serial::integer(sr); + + sr &= ~sh::sr::bl; // BL + sr &= ~sh::sr::imask(15); // imask + + serial::string("sr "); + serial::integer(sr); + + asm volatile ("ldc %0,sr" + : + : "r" (sr)); +} diff --git a/interrupt.hpp b/interrupt.hpp new file mode 100644 index 0000000..171bbd5 --- /dev/null +++ b/interrupt.hpp @@ -0,0 +1,5 @@ +#pragma once + +extern int render_done; + +void interrupt_init(); diff --git a/pk/levelshots/20kdm2.tga b/pk/levelshots/20kdm2.tga new file mode 100644 index 0000000..9a933dc Binary files /dev/null and b/pk/levelshots/20kdm2.tga differ diff --git a/pk/map-20kdm2.pk3 b/pk/map-20kdm2.pk3 new file mode 100644 index 0000000..d86083e Binary files /dev/null and b/pk/map-20kdm2.pk3 differ diff --git a/pk/maps/20kdm2.aas b/pk/maps/20kdm2.aas new file mode 100644 index 0000000..67d3e90 Binary files /dev/null and b/pk/maps/20kdm2.aas differ diff --git a/pk/maps/20kdm2.bsp b/pk/maps/20kdm2.bsp new file mode 100644 index 0000000..babf50b Binary files /dev/null and b/pk/maps/20kdm2.bsp differ diff --git a/pk/maps/20kdm2.bsp.h b/pk/maps/20kdm2.bsp.h new file mode 100644 index 0000000..0e830f4 --- /dev/null +++ b/pk/maps/20kdm2.bsp.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_pk_maps_20kdm2_bsp_start __asm("_binary_pk_maps_20kdm2_bsp_start"); +extern uint32_t _binary_pk_maps_20kdm2_bsp_end __asm("_binary_pk_maps_20kdm2_bsp_end"); +extern uint32_t _binary_pk_maps_20kdm2_bsp_size __asm("_binary_pk_maps_20kdm2_bsp_size"); + +#ifdef __cplusplus +} +#endif diff --git a/pk/models/mapobjects/gratelamp/gratetorch2.jpg b/pk/models/mapobjects/gratelamp/gratetorch2.jpg new file mode 100644 index 0000000..89be454 Binary files /dev/null and b/pk/models/mapobjects/gratelamp/gratetorch2.jpg differ diff --git a/pk/models/mapobjects/gratelamp/gratetorch2b.tga b/pk/models/mapobjects/gratelamp/gratetorch2b.tga new file mode 100644 index 0000000..b8de91f Binary files /dev/null and b/pk/models/mapobjects/gratelamp/gratetorch2b.tga differ diff --git a/pk/models/mapobjects/timlamp/timlamp.tga b/pk/models/mapobjects/timlamp/timlamp.tga new file mode 100644 index 0000000..bcb03ff Binary files /dev/null and b/pk/models/mapobjects/timlamp/timlamp.tga differ diff --git a/pk/scripts/20kdm2.arena b/pk/scripts/20kdm2.arena new file mode 100644 index 0000000..beec390 --- /dev/null +++ b/pk/scripts/20kdm2.arena @@ -0,0 +1,7 @@ +{ +map "20kdm2" +bots "Wrack" +longname "Return to Castle: Quake" +fraglimit 20 +type "ffa tourney" +} \ No newline at end of file diff --git a/pk/scripts/common.shader b/pk/scripts/common.shader new file mode 100644 index 0000000..19a4b1a --- /dev/null +++ b/pk/scripts/common.shader @@ -0,0 +1,11 @@ +textures/common/clip +{ + qer_trans 0.40 + surfaceparm nolightmap + surfaceparm nomarks + surfaceparm nodraw + surfaceparm nonsolid + //surfaceparm nolightmap //proto_addition 11/08/99 + surfaceparm playerclip + surfaceparm noimpact +} diff --git a/pk/scripts/e7.shader b/pk/scripts/e7.shader new file mode 100644 index 0000000..aa99142 --- /dev/null +++ b/pk/scripts/e7.shader @@ -0,0 +1,274 @@ +// e7 shaders by Yves Allaire aka evil lair// +// http://www.planetquake.com/hfx // +// hfx@planetquake.com // + +//evil jump pad + +textures/e7/e7brickfloor01jump +{ + qer_editorimage textures/e7/e7brickfloor01jump.tga + q3map_lightimage textures/e7/e7brickfloor01jump_glow.tga + surfaceparm nomarks + q3map_surfacelight 400 + { + map textures/e7/e7brickfloor01jump.tga + rgbGen identity + } + { + map $lightmap + blendfunc filter + rgbGen identity + tcGen lightmap + } + { + map textures/e7/e7brickfloor01jump_glow.tga + blendfunc add + rgbGen wave sin 0.5 0.8 0 1.5 + } +} + +textures/e7/e7mlight +{ + qer_editorimage textures/e7/e7mlight.tga + q3map_lightimage textures/e7/e7mlight.blend.tga + surfaceparm nomarks + q3map_surfacelight 1500 + { + map $lightmap + rgbGen identity + tcGen lightmap + } + { + map textures/e7/e7mlight.tga + blendfunc filter + rgbGen identity + } + { + map textures/e7/e7mlight.blend.tga + blendfunc add + rgbGen identity + } +} + +//small light + +textures/e7/e7slight +{ + qer_editorimage textures/e7/e7slight.tga + q3map_lightimage textures/e7/e7slight.blend.tga + surfaceparm nomarks + q3map_surfacelight 2500 + { + map $lightmap + rgbGen identity + tcGen lightmap + } + { + map textures/e7/e7slight.tga + blendfunc filter + rgbGen identity + } + { + map textures/e7/e7slight.blend.tga + blendfunc add + rgbGen identity + } +} + +textures/e7/e7trimlight +{ + qer_editorimage textures/e7/e7trimlight.tga + q3map_lightimage textures/e7/e7trimlight.blend.tga + surfaceparm nomarks + q3map_surfacelight 700 + { + map $lightmap + rgbGen identity + tcGen lightmap + } + { + map textures/e7/e7trimlight.tga + blendfunc filter + rgbGen identity + } + { + map textures/e7/e7trimlight.blend.tga + blendfunc add + rgbGen identity + } +} + +//evilgrate + +textures/e7/e7wgrate +{ + qer_editorimage textures/e7/e7wgrate.tga + surfaceparm alphashadow + surfaceparm nomarks + surfaceparm metalsteps + surfaceparm trans + cull disable + nopicmip + { + map textures/e7/e7wgrate.tga + rgbGen identity + depthWrite + alphaFunc GE128 + } + { + map $lightmap + blendfunc filter + rgbGen identity + tcGen lightmap + depthFunc equal + } +} + +// evil lava - sorta looks bad ingame - imho + +textures/e7/e7sfx_lava +{ + qer_editorimage textures/e7/e7sfx_lava.tga + surfaceparm lava + surfaceparm noimpact + surfaceparm nolightmap + surfaceparm trans + cull disable + deformVertexes wave 100 sin 3 2 0.1 0.1 + tessSize 128 + q3map_surfacelight 1500 + q3map_globaltexture + { + map textures/e7/e7sfx_lava.tga + rgbGen identity + tcMod turb 0 0.2 0 0.08 + } +} + +//evil sky of impending doom :P + +textures/e7/e7evilsky_1 +{ + qer_editorimage textures/e7/e7evilsky_1.tga + surfaceparm noimpact + surfaceparm nolightmap + surfaceparm nomarks + q3map_surfacelight 200 + q3map_sun 0.9 0.9 1 60 65 68 + skyParms - 512 - + { + map textures/e7/e7evilsky_1.tga + rgbGen identity + tcMod scroll 0.05 0.1 + tcMod scale 2 2 + } + { + map textures/e7/e7evilsky_2.tga + blendfunc add + rgbGen identity + tcMod scroll 0.08 -0.06 + tcMod scale 3 2 + } +} + +textures/e7/e7rain +{ + qer_editorimage textures/e7/e7rain.tga + surfaceparm nolightmap + surfaceparm nomarks + surfaceparm nonsolid + surfaceparm trans + cull disable + deformVertexes move 3 1 0 sin 0 5 0 0.2 + deformVertexes move 0.6 3.3 0 sin 0 5 0 0.4 + deformVertexes wave 30 sin 0 10 0 0.2 + qer_trans 0.5 + { + map textures/e7/e7rain.tga + blendfunc add + rgbGen identity + tcMod scroll 0.5 -8 + tcMod turb 0.1 0.25 0 -0.1 + } + { + map textures/e7/e7rain.tga + blendfunc add + rgbGen identity + tcMod scroll 0.01 -6.3 + } +} + +//dark redish sky + +textures/e7/e7sky_01 +{ + qer_editorimage textures/e7/e7sky_01.tga + surfaceparm noimpact + surfaceparm nolightmap + q3map_sun .9 .9 1 65 65 68 + q3map_surfacelight 150 + skyparms - 512 - + { + map textures/e7/e7sky_01.tga + rgbGen identity + tcMod scroll 0.05 0.03 + tcMod scale 2 2 + } + { + map textures/e7/e7sky_02.tga + blendfunc add + rgbGen identity + tcMod scroll 0.01 0.02 + tcMod scale 3 2 + } +} + +//jump pad 2 + +textures/e7/e7sbrickfloor_jump +{ + qer_editorimage textures/e7/e7sbrickfloor_jump.tga + q3map_lightimage textures/e7/e7sbrickfloor_jump_glow.tga + surfaceparm nomarks + q3map_surfacelight 400 + { + map textures/e7/e7sbrickfloor_jump.tga + rgbGen identity + } + { + map $lightmap + blendfunc filter + rgbGen identity + tcGen lightmap + } + { + map textures/e7/e7sbrickfloor_jump_glow.tga + blendfunc add + rgbGen wave sin 0.5 0.8 0 1.5 + } +} + +//small grate + +textures/e7/e7smgrate +{ + qer_editorimage textures/e7/e7smgrate.tga + surfaceparm alphashadow + surfaceparm metalsteps + //surfaceparm trans + cull disable + nopicmip + { + map textures/e7/e7smgrate.tga + rgbGen identity + depthWrite + alphaFunc GE128 + } + { + map $lightmap + blendfunc filter + rgbGen identity + tcGen lightmap + depthFunc equal + } +} \ No newline at end of file diff --git a/pk/scripts/liquid.shader b/pk/scripts/liquid.shader new file mode 100644 index 0000000..4b47985 --- /dev/null +++ b/pk/scripts/liquid.shader @@ -0,0 +1,26 @@ + +textures/liquids/lavahell +{ + // Added to g3map_global texture on May 11, 1999 + q3map_globaltexture + surfaceparm trans + //surfaceparm nonsolid + surfaceparm noimpact + surfaceparm lava + surfaceparm nolightmap + q3map_surfacelight 600 + cull disable + + tesssize 128 + cull disable + deformVertexes wave 100 sin 3 2 .1 0.1 + + { + map textures/liquids/lavahell.tga + tcMod turb 0 .2 0 .1 + } + + + +// END +} diff --git a/pk/scripts/models.shader b/pk/scripts/models.shader new file mode 100644 index 0000000..f0efe05 --- /dev/null +++ b/pk/scripts/models.shader @@ -0,0 +1,45 @@ +models/mapobjects/timlamp/timlamp +{ + cull disable + surfaceparm alphashadow + { + map models/mapobjects/timlamp/timlamp.tga + alphaFunc GE128 + depthWrite + rgbGen vertex + } +} + +models/mapobjects/gratelamp/gratetorch2b +{ + cull disable + { + map models/mapobjects/gratelamp/gratetorch2b.tga + alphaFunc GE128 + depthWrite + rgbGen vertex + } + +} + +models/mapobjects/wallhead/lion_m +{ + { + map models/mapobjects/wallhead/lion_m.tga + blendFunc GL_ONE GL_ZERO + rgbGen vertex + } + { + map textures/sfx/firewalla.tga + blendFunc GL_ONE GL_ONE + tcmod scroll 0.1 1 + //rgbGen wave triangle .5 1 0 .4 + } + { + map models/mapobjects/wallhead/lion_m.tga + blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA + rgbGen vertex + } + +} + diff --git a/pk/scripts/sfx.shader b/pk/scripts/sfx.shader new file mode 100644 index 0000000..a0dc3dc --- /dev/null +++ b/pk/scripts/sfx.shader @@ -0,0 +1,71 @@ +textures/sfx/flame1side +{ + + // ************************************************* + // * Yellow Flame Side * + // * April 30 1999 * + // * Please Comment Changes * + // ************************************************* + + surfaceparm trans + surfaceparm nomarks + surfaceparm nonsolid + + surfaceparm nolightmap + cull none + + { + animMap 10 textures/sfx/flame1.tga textures/sfx/flame2.tga textures/sfx/flame3.tga textures/sfx/flame4.tga textures/sfx/flame5.tga textures/sfx/flame6.tga textures/sfx/flame7.tga textures/sfx/flame8.tga + blendFunc GL_ONE GL_ONE + rgbGen wave inverseSawtooth 0 1 0 10 + + } + { + animMap 10 textures/sfx/flame2.tga textures/sfx/flame3.tga textures/sfx/flame4.tga textures/sfx/flame5.tga textures/sfx/flame6.tga textures/sfx/flame7.tga textures/sfx/flame8.tga textures/sfx/flame1.tga + blendFunc GL_ONE GL_ONE + rgbGen wave sawtooth 0 1 0 10 + } + + + { + map textures/sfx/flameball.tga + blendFunc GL_ONE GL_ONE + rgbGen wave sin .6 .2 0 .6 + } + +} + +textures/sfx/flame2 +{ + + // ************************************************* + // * Yellow Flame Surface Light 5500 * + // * April 30 1999 * + // * Please Comment Changes * + // ************************************************* + + surfaceparm nomarks + surfaceparm nolightmap + cull none + q3map_surfacelight 5500 + qer_editorimage textures/sfx/flame1.tga + + { + animMap 10 textures/sfx/flame1.tga textures/sfx/flame2.tga textures/sfx/flame3.tga textures/sfx/flame4.tga textures/sfx/flame5.tga textures/sfx/flame6.tga textures/sfx/flame7.tga textures/sfx/flame8.tga + blendFunc GL_ONE GL_ONE + rgbGen wave inverseSawtooth 0 1 0 10 + + } + { + animMap 10 textures/sfx/flame2.tga textures/sfx/flame3.tga textures/sfx/flame4.tga textures/sfx/flame5.tga textures/sfx/flame6.tga textures/sfx/flame7.tga textures/sfx/flame8.tga textures/sfx/flame1.tga + blendFunc GL_ONE GL_ONE + rgbGen wave sawtooth 0 1 0 10 + } + + { + map textures/sfx/flameball.tga + blendFunc GL_ONE GL_ONE + rgbGen wave sin .6 .2 0 .6 + } + +} diff --git a/pk/scripts/sky.shader b/pk/scripts/sky.shader new file mode 100644 index 0000000..26bd7fb --- /dev/null +++ b/pk/scripts/sky.shader @@ -0,0 +1,31 @@ +textures/skies/tim_hell +{ + qer_editorimage textures/skies/stars_red.tga + surfaceparm noimpact + surfaceparm nomarks + surfaceparm nolightmap + surfaceparm sky + + q3map_sun 1 .77 .77 80 315 70 + //q3map_sun .5 .37 .19 80 315 70 + + //q3map_sun 1 .37 .19 85 30 70 + q3map_surfacelight 130 + skyparms - 384 - + + //cloudparms 512 full + //lightning + + { + map textures/skies/killsky_1.tga + tcMod scroll 0.05 .1 + tcMod scale 2 2 + depthWrite + } + { + map textures/skies/killsky_2.tga + blendfunc GL_ONE GL_ONE + tcMod scroll 0.05 0.06 + tcMod scale 3 2 + } +} diff --git a/pk/textures/e7/e7beam01.jpg b/pk/textures/e7/e7beam01.jpg new file mode 100644 index 0000000..ca6fc94 Binary files /dev/null and b/pk/textures/e7/e7beam01.jpg differ diff --git a/pk/textures/e7/e7beam02_red.jpg b/pk/textures/e7/e7beam02_red.jpg new file mode 100644 index 0000000..464c548 Binary files /dev/null and b/pk/textures/e7/e7beam02_red.jpg differ diff --git a/pk/textures/e7/e7bigwall.jpg b/pk/textures/e7/e7bigwall.jpg new file mode 100644 index 0000000..7791a44 Binary files /dev/null and b/pk/textures/e7/e7bigwall.jpg differ diff --git a/pk/textures/e7/e7bmtrim.jpg b/pk/textures/e7/e7bmtrim.jpg new file mode 100644 index 0000000..23cda26 Binary files /dev/null and b/pk/textures/e7/e7bmtrim.jpg differ diff --git a/pk/textures/e7/e7bmtrim2.jpg b/pk/textures/e7/e7bmtrim2.jpg new file mode 100644 index 0000000..7600b79 Binary files /dev/null and b/pk/textures/e7/e7bmtrim2.jpg differ diff --git a/pk/textures/e7/e7brickfloor01.jpg b/pk/textures/e7/e7brickfloor01.jpg new file mode 100644 index 0000000..4891c37 Binary files /dev/null and b/pk/textures/e7/e7brickfloor01.jpg differ diff --git a/pk/textures/e7/e7brnmetal.jpg b/pk/textures/e7/e7brnmetal.jpg new file mode 100644 index 0000000..dfbd957 Binary files /dev/null and b/pk/textures/e7/e7brnmetal.jpg differ diff --git a/pk/textures/e7/e7dimfloor.jpg b/pk/textures/e7/e7dimfloor.jpg new file mode 100644 index 0000000..0795ca9 Binary files /dev/null and b/pk/textures/e7/e7dimfloor.jpg differ diff --git a/pk/textures/e7/e7panelwood.jpg b/pk/textures/e7/e7panelwood.jpg new file mode 100644 index 0000000..d3c8bd0 Binary files /dev/null and b/pk/textures/e7/e7panelwood.jpg differ diff --git a/pk/textures/e7/e7sbrickfloor.jpg b/pk/textures/e7/e7sbrickfloor.jpg new file mode 100644 index 0000000..a6e8980 Binary files /dev/null and b/pk/textures/e7/e7sbrickfloor.jpg differ diff --git a/pk/textures/e7/e7steptop.jpg b/pk/textures/e7/e7steptop.jpg new file mode 100644 index 0000000..6b327bc Binary files /dev/null and b/pk/textures/e7/e7steptop.jpg differ diff --git a/pk/textures/e7/e7steptop2.jpg b/pk/textures/e7/e7steptop2.jpg new file mode 100644 index 0000000..9ac8c32 Binary files /dev/null and b/pk/textures/e7/e7steptop2.jpg differ diff --git a/pk/textures/e7/e7swindow.jpg b/pk/textures/e7/e7swindow.jpg new file mode 100644 index 0000000..f15177c Binary files /dev/null and b/pk/textures/e7/e7swindow.jpg differ diff --git a/pk/textures/e7/e7walldesign01b.jpg b/pk/textures/e7/e7walldesign01b.jpg new file mode 100644 index 0000000..609e162 Binary files /dev/null and b/pk/textures/e7/e7walldesign01b.jpg differ diff --git a/pk/textures/gothic_floor/xstepborder5.jpg b/pk/textures/gothic_floor/xstepborder5.jpg new file mode 100644 index 0000000..2c03192 Binary files /dev/null and b/pk/textures/gothic_floor/xstepborder5.jpg differ diff --git a/pk/textures/gothic_trim/metalblackwave01.jpg b/pk/textures/gothic_trim/metalblackwave01.jpg new file mode 100644 index 0000000..8e85d78 Binary files /dev/null and b/pk/textures/gothic_trim/metalblackwave01.jpg differ diff --git a/pk/textures/liquids/lavahell.jpg b/pk/textures/liquids/lavahell.jpg new file mode 100644 index 0000000..d381258 Binary files /dev/null and b/pk/textures/liquids/lavahell.jpg differ diff --git a/pk/textures/sfx/flame1.jpg b/pk/textures/sfx/flame1.jpg new file mode 100644 index 0000000..892bab7 Binary files /dev/null and b/pk/textures/sfx/flame1.jpg differ diff --git a/pk/textures/sfx/flame2.jpg b/pk/textures/sfx/flame2.jpg new file mode 100644 index 0000000..7c0b19a Binary files /dev/null and b/pk/textures/sfx/flame2.jpg differ diff --git a/pk/textures/sfx/flame3.jpg b/pk/textures/sfx/flame3.jpg new file mode 100644 index 0000000..ef818ec Binary files /dev/null and b/pk/textures/sfx/flame3.jpg differ diff --git a/pk/textures/sfx/flame4.jpg b/pk/textures/sfx/flame4.jpg new file mode 100644 index 0000000..3ab3a8e Binary files /dev/null and b/pk/textures/sfx/flame4.jpg differ diff --git a/pk/textures/sfx/flame5.jpg b/pk/textures/sfx/flame5.jpg new file mode 100644 index 0000000..dfb5994 Binary files /dev/null and b/pk/textures/sfx/flame5.jpg differ diff --git a/pk/textures/sfx/flame6.jpg b/pk/textures/sfx/flame6.jpg new file mode 100644 index 0000000..e7661a9 Binary files /dev/null and b/pk/textures/sfx/flame6.jpg differ diff --git a/pk/textures/sfx/flame7.jpg b/pk/textures/sfx/flame7.jpg new file mode 100644 index 0000000..eaa1a53 Binary files /dev/null and b/pk/textures/sfx/flame7.jpg differ diff --git a/pk/textures/sfx/flame8.jpg b/pk/textures/sfx/flame8.jpg new file mode 100644 index 0000000..26b8c15 Binary files /dev/null and b/pk/textures/sfx/flame8.jpg differ diff --git a/pk/textures/sfx/flameball.jpg b/pk/textures/sfx/flameball.jpg new file mode 100644 index 0000000..e1805af Binary files /dev/null and b/pk/textures/sfx/flameball.jpg differ diff --git a/pk/textures/skies/killsky_1.jpg b/pk/textures/skies/killsky_1.jpg new file mode 100644 index 0000000..601ce23 Binary files /dev/null and b/pk/textures/skies/killsky_1.jpg differ diff --git a/pk/textures/skies/killsky_2.jpg b/pk/textures/skies/killsky_2.jpg new file mode 100644 index 0000000..5cf1d90 Binary files /dev/null and b/pk/textures/skies/killsky_2.jpg differ diff --git a/pk/textures/stone/pjrock1.jpg b/pk/textures/stone/pjrock1.jpg new file mode 100644 index 0000000..29cbfa1 Binary files /dev/null and b/pk/textures/stone/pjrock1.jpg differ diff --git a/printf/printf.c b/printf/printf.c index 9341162..529377f 100644 --- a/printf/printf.c +++ b/printf/printf.c @@ -14,6 +14,7 @@ enum format_type { FORMAT_BASE16, FORMAT_STRING, FORMAT_CHAR, + FORMAT_FLOAT, FORMAT_PERCENT, }; @@ -63,6 +64,9 @@ static const char * parse_escape(const char * format, struct format * ft) case 'c': ft->type = FORMAT_CHAR; return format + 1; + case 'f': + ft->type = FORMAT_FLOAT; + return format + 1; case '%': ft->type = FORMAT_PERCENT; return format + 1; @@ -167,6 +171,21 @@ void _printf(const char * format, ...) print_char((char)c); } break; + case FORMAT_FLOAT: + { + double num = va_arg(args, double); + char s[20]; + int32_t whole = num; + int offset = unparse_base10(s, whole, ft.pad_length, ft.fill_char); + print_string(s, offset); + print_char('.'); + int32_t fraction = (int32_t)((num - (float)whole) * 1000.0); + if (fraction < 0) + fraction = -fraction; + offset = unparse_base10(s, fraction, 0, 0); + print_string(s, offset); + } + break; case FORMAT_PERCENT: print_char('%'); break; diff --git a/q3bsp/q3bsp.h b/q3bsp/q3bsp.h new file mode 100644 index 0000000..f7c1d87 --- /dev/null +++ b/q3bsp/q3bsp.h @@ -0,0 +1,139 @@ +#include + +typedef struct q3bsp_direntry { + int offset; + int length; +} q3bsp_direntry_t; + +typedef struct q3bsp_header { + char magic[4]; + int version; + struct q3bsp_direntry direntries[17]; +} q3bsp_header_t; + +enum q3bsp_lumps { + LUMP_ENTITES = 0, + LUMP_TEXTURES = 1, + LUMP_PLANES = 2, + LUMP_NODES = 3, + LUMP_LEAFS = 4, + LUMP_LEAFFACES = 5, + LUMP_LEAFBRUSHES = 6, + LUMP_MODELS = 7, + LUMP_BRUSHES = 8, + LUMP_BRUSHSIDES = 9, + LUMP_VERTEXES = 10, + LUMP_MESHVERTS = 11, + LUMP_EFFECTS = 12, + LUMP_FACES = 13, + LUMP_LIGHTMAPS = 14, + LUMP_LIGHTVOLS = 15, + LUMP_VISDATA = 16, +} q3bsp_lumps; + +/* +typedef struct q3bsp_entity { + char s[]; +} q3bsp_entity_t; +*/ + +typedef struct q3bsp_texture { + char name[64]; + int flags; + int contents; +} q3bsp_texture_t; + +typedef struct q3bsp_plane { + float normal[3]; + float dist; +} q3bsp_plane_t; + +typedef struct q3bsp_node { + int plane; + int children[2]; + int mins[3]; + int maxs[3]; +} q3bsp_node_t; + +typedef struct q3bsp_leaf { + int cluster; + int area; + int mins[3]; + int maxs[3]; + int leafface; + int n_leaffaces; + int leafbrush; + int n_leafbrushes; +} q3bsp_leaf_t; + +typedef struct q3bsp_leafface { + int face; +} q3bsp_leafface_t; + +typedef struct q3bsp_leafbrush { + int brush; +} q3bsp_leafbrush_t; + +typedef struct q3bsp_model { + float mins[3]; + float maxs[3]; + int face; + int n_faces; + int brush; + int n_brushes; +} q3bsp_model_t; + +typedef struct q3bsp_brush { + int brushside; + int n_brushsides; + int texture; +} q3bsp_brush_t; + +typedef struct q3bsp_brushside { + int plane; + int texture; +} q3bsp_brushside_t; + +typedef struct q3bsp_vertex { + float position[3]; + float texcoord[2][2]; + float normal[3]; + uint8_t color[4]; +} q3bsp_vertex_t; + +typedef struct q3bsp_meshvert { + int offset; +} q3bsp_meshvert_t; + +typedef struct q3bsp_effect { + char name[64]; + int brush; + int unknown; +} q3bsp_effect_t; + +typedef struct q3bsp_face { + int texture; + int effect; + int type; + int vertex; + int n_vertexes; + int meshvert; + int n_meshverts; + int lm_index; + int lm_start[2]; + int lm_size[2]; + float lm_origin[3]; + float lm_vecs[2][3]; + float normal[3]; + int size[2]; +} q3bsp_face_t; + +typedef struct q3bsp_lightmap { + uint8_t map[128][128][3]; +} q3bsp_lightmap_t; + +typedef struct q3bsp_visdata { + int n_vecs; + int sz_vecs; + uint8_t vecs[]; +} q3bsp_visdata_t; diff --git a/textures.txt b/textures.txt new file mode 100644 index 0000000..de84c63 --- /dev/null +++ b/textures.txt @@ -0,0 +1,27 @@ +textures/common/caulk +textures/e7/e7walldesign01b +textures/e7/e7steptop2 +noshader +textures/e7/e7dimfloor +textures/e7/e7brickfloor01 +textures/e7/e7bmtrim +textures/e7/e7sbrickfloor +textures/e7/e7brnmetal +textures/common/clip +textures/e7/e7beam02_red +textures/e7/e7swindow +textures/e7/e7bigwall +textures/e7/e7panelwood +textures/e7/e7beam01 +textures/gothic_floor/xstepborder5 +textures/liquids/lavahell +textures/e7/e7steptop +textures/gothic_trim/metalblackwave01 +textures/stone/pjrock1 +textures/skies/tim_hell +textures/common/hint +models/mapobjects/timlamp/timlamp +textures/sfx/flame1side +textures/sfx/flame2 +models/mapobjects/gratelamp/gratetorch2 +models/mapobjects/gratelamp/gratetorch2b