example/q3bsp: initial

This commit is contained in:
Zack Buhman 2025-04-20 17:12:14 -05:00
parent 8fea03bb66
commit 534ffb60af
52 changed files with 1349 additions and 1 deletions

View File

@ -108,6 +108,12 @@ endef
%.mod.o: %.mod %.mod.o: %.mod
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
%.bsp.h: %.bsp
$(BUILD_BINARY_H)
%.bsp.o: %.bsp
$(BUILD_BINARY_O)
%.o: %.s %.o: %.s
$(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@ $(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@

View File

@ -990,7 +990,6 @@ BOIDS_OBJ = \
example/boids.elf: LDSCRIPT = $(LIB)/main.lds example/boids.elf: LDSCRIPT = $(LIB)/main.lds
example/boids.elf: $(START_OBJ) $(BOIDS_OBJ) example/boids.elf: $(START_OBJ) $(BOIDS_OBJ)
MOD_OBJ = \ MOD_OBJ = \
example/mod.o \ example/mod.o \
holly/core.o \ holly/core.o \
@ -1005,3 +1004,22 @@ MOD_OBJ = \
example/mod.elf: LDSCRIPT = $(LIB)/main.lds example/mod.elf: LDSCRIPT = $(LIB)/main.lds
example/mod.elf: $(START_OBJ) $(MOD_OBJ) 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)

509
example/q3bsp.cpp Normal file
View File

@ -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<q3bsp_header_t *>(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<q3bsp_texture_t *>(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<q3bsp_model_t *>(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<q3bsp_face_t *>(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>() =
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<q3bsp_vertex_t *>(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>() =
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>() =
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>() =
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<q3bsp_meshvert_t *>(&buf[me->offset]);
q3bsp_face_t * face = reinterpret_cast<q3bsp_face_t *>(&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<uint8_t *>(&_binary_pk_maps_20kdm2_bsp_start);
q3bsp_header_t * header = reinterpret_cast<q3bsp_header_t *>(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>() =
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;
}
}

145
interrupt.cpp Normal file
View File

@ -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<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(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<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(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<uint32_t>(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<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(sh7091.CCN.TRA);
serial::string("istnrm: ");
serial::integer<uint32_t>(system.ISTNRM);
serial::string("isterr: ");
serial::integer<uint32_t>(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<uint32_t>(&__vbr_link_start) - 0x100;
serial::string("vbr ");
serial::integer<uint32_t>(vbr);
serial::string("vbr100 ");
serial::integer<uint32_t>(reinterpret_cast<uint32_t>(&vbr100));
asm volatile ("ldc %0,vbr"
:
: "r" (vbr));
uint32_t sr;
asm volatile ("stc sr,%0"
: "=r" (sr));
serial::string("sr ");
serial::integer<uint32_t>(sr);
sr &= ~sh::sr::bl; // BL
sr &= ~sh::sr::imask(15); // imask
serial::string("sr ");
serial::integer<uint32_t>(sr);
asm volatile ("ldc %0,sr"
:
: "r" (sr));
}

5
interrupt.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
extern int render_done;
void interrupt_init();

BIN
pk/levelshots/20kdm2.tga Normal file

Binary file not shown.

BIN
pk/map-20kdm2.pk3 Normal file

Binary file not shown.

BIN
pk/maps/20kdm2.aas Normal file

Binary file not shown.

BIN
pk/maps/20kdm2.bsp Normal file

Binary file not shown.

15
pk/maps/20kdm2.bsp.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

7
pk/scripts/20kdm2.arena Normal file
View File

@ -0,0 +1,7 @@
{
map "20kdm2"
bots "Wrack"
longname "Return to Castle: Quake"
fraglimit 20
type "ffa tourney"
}

11
pk/scripts/common.shader Normal file
View File

@ -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
}

274
pk/scripts/e7.shader Normal file
View File

@ -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
}
}

26
pk/scripts/liquid.shader Normal file
View File

@ -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
}

45
pk/scripts/models.shader Normal file
View File

@ -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
}
}

71
pk/scripts/sfx.shader Normal file
View File

@ -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
}
}

31
pk/scripts/sky.shader Normal file
View File

@ -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
}
}

BIN
pk/textures/e7/e7beam01.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

BIN
pk/textures/e7/e7bmtrim.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
pk/textures/sfx/flame1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
pk/textures/sfx/flame2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
pk/textures/sfx/flame3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
pk/textures/sfx/flame4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
pk/textures/sfx/flame5.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
pk/textures/sfx/flame6.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
pk/textures/sfx/flame7.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
pk/textures/sfx/flame8.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -14,6 +14,7 @@ enum format_type {
FORMAT_BASE16, FORMAT_BASE16,
FORMAT_STRING, FORMAT_STRING,
FORMAT_CHAR, FORMAT_CHAR,
FORMAT_FLOAT,
FORMAT_PERCENT, FORMAT_PERCENT,
}; };
@ -63,6 +64,9 @@ static const char * parse_escape(const char * format, struct format * ft)
case 'c': case 'c':
ft->type = FORMAT_CHAR; ft->type = FORMAT_CHAR;
return format + 1; return format + 1;
case 'f':
ft->type = FORMAT_FLOAT;
return format + 1;
case '%': case '%':
ft->type = FORMAT_PERCENT; ft->type = FORMAT_PERCENT;
return format + 1; return format + 1;
@ -167,6 +171,21 @@ void _printf(const char * format, ...)
print_char((char)c); print_char((char)c);
} }
break; 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: case FORMAT_PERCENT:
print_char('%'); print_char('%');
break; break;

139
q3bsp/q3bsp.h Normal file
View File

@ -0,0 +1,139 @@
#include <stdint.h>
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;

27
textures.txt Normal file
View File

@ -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