--- /dev/null
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+EGIT_REPO_URI="https://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/xolatile/xolatilization"
+inherit git-r3-tor
+
+DESCRIPTION="The most hateful set of programs and libraries ever written..."
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="amd64 x86"
+
+DEPEND=""
+
+TARGET_LIST=(
+ xop
+ xscii
+ xighlight
+ xhallenge
+ xuxuxu
+ xarbon
+)
+
+src_compile() {
+ CFLAGS="-I. -std=gnu99 -Ofast"
+ CFLAGS="${CFLAGS} -Wno-unused-result -Wno-discarded-qualifiers"
+ CLIBS="-lpng"
+
+ ln -s $(realpath .) xolatile
+
+ for i in ${TARGET_LIST[@]}; do
+ gcc ${CFLAGS} -o $i $i.c ${CLIBS}
+ done
+}
+
+src_install() {
+ for i in ${TARGET_LIST[@]}; do
+ dobin $i
+ done
+}
--- /dev/null
+#!/bin/bash
+
+
+FILES=(
+ xop.c
+ xscii.c
+ xighlight.c
+ xhallenge.c
+ xuxuxu.c
+ xarbon.c
+)
+
+CFLAGS="-I. -std=gnu99 -Ofast"
+CFLAGS="${CFLAGS} -Wno-unused-result -Wno-discarded-qualifiers"
+CLIBS="-lpng"
+
+for i in ${FILES[@]}; do
+ gcc ${CFLAGS} -o $(basename -s .c $i) $i ${CLIBS}
+done
\ No newline at end of file
cp -f xpengl.h /usr/local/include/xolatile/xpengl.h
cp -f xross.h /usr/local/include/xolatile/xross.h
cp -f xui.h /usr/local/include/xolatile/xui.h
+cp -f xenu.h /usr/local/include/xolatile/xenu.h
cp -f xungeon.h /usr/local/include/xolatile/xungeon.h
cp -rf xanguage /usr/local/include/xolatile/
#include "xhape.h"
#include "xision.h"
-static v0 print_shape (shape_node * sh) {
+static procedure print_shape (shape_node * sh) {
print ("shape data:\n");
print ("v = %i // %i\n", sh->vertex_count, sh->vertex_limit);
print ("i = %i // %i\n", sh->index_count, sh->index_limit);
}
-static v0 render_shape (vision_structure * vision, shape_node * sh) {
- //~u4 vc = sh->vertex_count;
- //~u4 ic = sh->index_count;
+static procedure render_shape (vision_structure * vision, shape_node * sh) {
+ //~natural vc = sh->vertex_count;
+ //~natural ic = sh->index_count;
- //~f4 va [100] = { 0 };
- //~u4 ia [100] = { 0 };
+ //~real va [100] = { 0 };
+ //~natural ia [100] = { 0 };
- //~for (u4 i = 0; i < vc; i += 5) {
+ //~for (natural i = 0; i < vc; i += 5) {
//~va [i+0] = sh->vertex_array [i/5]->x;
//~va [i+1] = sh->vertex_array [i/5]->y;
//~va [i+2] = sh->vertex_array [i/5]->z;
//~va [i+4] = sh->unwrap_array [i/5]->y;
//~}
- //~for (u4 i = 0; i < ic; i += 5) {
+ //~for (natural i = 0; i < ic; i += 5) {
//~ia [i] = sh->index_array [i];
//~}
vision_render_base (vision, sh->vertex_count, sh->vertex_array, sh->index_count, sh->index_array, 0, 0xff7733ff);
}
-s4 main (v0) {
+integer main (none) {
//~vector_3 as = { +2,0,0 };
//~vector_3 bs = { -2,0,0 };
//~vector_3 cs = { 0,+2,0 };
vision_structure * vision = vision_initialize (60, 60, false, 6000, 3000, 256);
particle_structure * particle = particle_initialize (1024);
- u4 i0 = vision_sprite_import (vision, "xui/goblin/end_turn_button.png");
- u4 i1 = vision_sprite_import (vision, "xui/goblin/separator_center.png");
- u4 i2 = vision_sprite_import (vision, "xui/goblin/separator_left.png");
- u4 i3 = vision_sprite_import (vision, "xui/goblin/separator_middle.png");
- u4 i4 = vision_sprite_import (vision, "xui/goblin/separator_right.png");
+ natural i0 = vision_sprite_import (vision, "xui/goblin/end_turn_button.png");
+ natural i1 = vision_sprite_import (vision, "xui/goblin/separator_center.png");
+ natural i2 = vision_sprite_import (vision, "xui/goblin/separator_left.png");
+ natural i3 = vision_sprite_import (vision, "xui/goblin/separator_middle.png");
+ natural i4 = vision_sprite_import (vision, "xui/goblin/separator_right.png");
vision_configure (vision, 800, 600, "Xube");
render_shape (vision, e);
render_shape (vision, f);
- //~f4 t0 [] = {1,0,0,0,0,1,0,1,0};
- //~f4 t1 [] = {1,0,0,0,0,1,0,1,0};
- //~f4 t2 [] = {1,0,0,0,0,1,0,1,0};
- //~f4 t3 [] = {1,0,0,0,0,1,0,1,0};
- //~f4 t4 [] = {1,0,0,0,0,1,0,1,0};
- //~f4 t5 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t0 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t1 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t2 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t3 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t4 [] = {1,0,0,0,0,1,0,1,0};
+ //~real t5 [] = {1,0,0,0,0,1,0,1,0};
//~vision_render_triangle (vision, t0, 0xff7733ff);
//~vision_render_triangle (vision, t1, 0xff7733ff);
//~vision_render_triangle (vision, t4, 0xff7733ff);
//~vision_render_triangle (vision, t5, 0xff7733ff);
- //~for (u4 i = 0; i < particle->count; ++i) {
+ //~for (natural i = 0; i < particle->count; ++i) {
//~Vector3 vector = {particle->position [i]->x, particle->position [i]->y, particle->position [i]->z};
//~DrawBillboard (camera, texture, vector, 1, RED);
//~}
- //~f4 va [] = {
+ //~real va [] = {
//~-1, -1, 0, 0, 1, 1, 1, 1, 1,
//~-1, +1, 0, 0, 0, 1, 1, 1, 1,
//~+1, +1, 0, 1, 0, 1, 1, 1, 1,
//~+1, -1, 0, 1, 1, 1, 1, 1, 1
//~};
- //~u4 ia [] = { 2, 1, 0, 3, 2, 1 };
+ //~natural ia [] = { 2, 1, 0, 3, 2, 1 };
//~vision_render_base (vision, sizeof(va)/4, va, sizeof(ia)/4, ia, 1, 0xff7733ff);
#ifdef use_debug_printing
-static c1 * operand_name [operand_count] = {
+static character * operand_name [operand_count] = {
"rel", "reg", "mem", "imm"
};
-static c1 * operation_name [operation_count] = {
+static character * operation_name [operation_count] = {
"asmmem", "asmrel", "asmnum", "asmstr",
"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp",
"inc", "dec", "not", "neg", "mul", "imul", "div", "idiv",
#endif
-static u4 main_entry_pos4 = 0;
-static u4 text_sector_size = 0;
-static u1 * text_sector_byte = null;
-static u4 data_sector_size = 0; // This is unused, and it should be used...
-static u1 * data_sector_byte = null; // This is unused, and it should be used...
+static natural main_entry_pointeger = 0;
+static natural text_sector_size = 0;
+static natural_8 * text_sector_byte = null;
+static natural data_sector_size = 0; // This is unused, and it should be used...
+static natural_8 * data_sector_byte = null; // This is unused, and it should be used...
-static u4 empty_count = 1;
-static u4 empty_holes = 1;
-static u4 * empty_array = null;
-static u4 * empty_imbue = null;
-static u4 * empty_store = null;
+static natural empty_count = 1;
+static natural empty_holes = 1;
+static natural * empty_array = null;
+static natural * empty_imbue = null;
+static natural * empty_store = null;
-static u1 elf_main_header_byte [elf_main_header_size] = { // These should be done properly...
+static natural_8 elf_main_header_byte [elf_main_header_size] = { // These should be done properly...
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static u1 elf_text_sector_byte [elf_text_sector_size] = {
+static natural_8 elf_text_sector_byte [elf_text_sector_size] = {
0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static u1 elf_data_sector_byte [elf_data_sector_size] = {
+static natural_8 elf_data_sector_byte [elf_data_sector_size] = {
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static b4 register_register (u4 to, u4 from) { return ((to == operand_register) && (from == operand_register)); }
-static b4 register_memory (u4 to, u4 from) { return ((to == operand_register) && (from == operand_memory)); }
-static b4 register_immediate (u4 to, u4 from) { return ((to == operand_register) && (from == operand_immediate)); }
-static b4 memory_register (u4 to, u4 from) { return ((to == operand_memory) && (from == operand_register)); }
-static b4 memory_immediate (u4 to, u4 from) { return ((to == operand_memory) && (from == operand_immediate)); }
-static b4 register_relative (u4 to, u4 from) { return ((to == operand_register) && (from == operand_relative)); }
+static boolean register_register (natural to, natural from) { return ((to == operand_register) && (from == operand_register)); }
+static boolean register_memory (natural to, natural from) { return ((to == operand_register) && (from == operand_memory)); }
+static boolean register_immediate (natural to, natural from) { return ((to == operand_register) && (from == operand_immediate)); }
+static boolean memory_register (natural to, natural from) { return ((to == operand_memory) && (from == operand_register)); }
+static boolean memory_immediate (natural to, natural from) { return ((to == operand_memory) && (from == operand_immediate)); }
+static boolean register_relative (natural to, natural from) { return ((to == operand_register) && (from == operand_relative)); }
-static u4 absolute (v0) { return (0x4010b0 - text_sector_size - 4); }
-static u4 relative (v0) { return (0x1000 - text_sector_size - 4); }
+static natural absolute (none) { return (0x4010b0 - text_sector_size - 4); }
+static natural relative (none) { return (0x1000 - text_sector_size - 4); }
-static v0 replace (u1 * destination, u1 * source, u8 size) {
+static procedure replace (natural_8 * destination, natural_8 * source, caliber size) {
for (--size; size >= 0; --size) {
destination [size] = source [size];
}
}
-static v0 inset (b4 when, u1 data) {
+static procedure inset (boolean when, natural_8 data) {
text_sector_byte [text_sector_size] = data;
- text_sector_size += (u4) when;
+ text_sector_size += (natural) when;
}
-static v0 inset_immediate (b4 when, u4 data) {
+static procedure inset_immediate (boolean when, natural data) {
inset (when, (data >> 0) & 0xff);
inset (when, (data >> 8) & 0xff);
inset (when, (data >> 16) & 0xff);
inset (when, (data >> 24) & 0xff);
}
-static v0 inset_memory (b4 when, u4 data, u4 base) {
+static procedure inset_memory (boolean when, natural data, natural base) {
empty_array [empty_holes] = text_sector_size;
empty_imbue [empty_holes] = data;
inset_immediate (when, base);
}
-static v0 inset_relative (b4 when, u4 data, u4 base) {
+static procedure inset_relative (boolean when, natural data, natural base) {
empty_array [empty_holes] = 0;
empty_imbue [empty_holes] = data;
inset_immediate (when, base);
}
-static u4 mc0 (u4 code, u4 base) {
+static natural mc0 (natural code, natural base) {
return (0xc0 + 0x01 * (code % 8) + 0x08 * (base % 8));
}
-static u4 m05 (u4 code) {
+static natural m05 (natural code) {
return (0x05 + 0x08 * code);
}
-static u4 store_relative (u4 * array) {
- u4 relative = array [1];
+static natural store_relative (natural * array) {
+ natural relative = array [1];
#ifdef use_debug_printing
print ("/3asmrel/- %i", relative);
#endif
return 1;
}
-static u4 store_memory (u4 * array) {
- u4 memory = array [1];
+static natural store_memory (natural * array) {
+ natural memory = array [1];
#ifdef use_debug_printing
print ("/3asmmem/- %i", memory);
#endif
return 1;
}
-static u4 store_number (u4 * array) {
- u4 amount = array [1];
+static natural store_number (natural * array) {
+ natural amount = array [1];
#ifdef use_debug_printing
print ("/3asmnum/- %i", amount);
#endif
- for (u4 index = 0; index < amount; ++index) {
+ for (natural index = 0; index < amount; ++index) {
inset_immediate (true, array [2 + index]);
}
return amount + 1;
}
-static u4 store_string (u4 * array) {
- u4 amount = array [1];
+static natural store_string (natural * array) {
+ natural amount = array [1];
#ifdef use_debug_printing
print ("/3asmstr/- %i", amount);
#endif
- for (u4 index = 0; index < amount; ++index) {
+ for (natural index = 0; index < amount; ++index) {
inset (true, array [2 + index]);
}
return amount + 1;
}
-static u4 build_f8 (u4 * array) {
- u4 operation = array [0];
- u4 to = array [1];
- u4 destination = array [2];
- u4 from = array [3];
- u4 source = array [4];
+static natural build_real_64 (natural * array) {
+ natural operation = array [0];
+ natural to = array [1];
+ natural destination = array [2];
+ natural from = array [3];
+ natural source = array [4];
#ifdef use_debug_printing
print ("/3%s/- /6%s/- %i /6%s/- %i", operation_name [operation], operand_name [to], destination, operand_name [from], source);
#endif
return 4;
}
-static u4 build_single (u4 * array) {
- u4 operation = array [0];
- u4 to = array [1];
- u4 destination = array [2];
+static natural build_single (natural * array) {
+ natural operation = array [0];
+ natural to = array [1];
+ natural destination = array [2];
#ifdef use_debug_printing
print ("/3%s/- /6%s/- %i", operation_name [operation], operand_name [to], destination);
#endif
return 2;
}
-static u4 build_shift (u4 * array) {
- u4 operation = array [0];
- u4 to = array [1];
- u4 destination = array [2];
- u4 offset = array [3];
+static natural build_shift (natural * array) {
+ natural operation = array [0];
+ natural to = array [1];
+ natural destination = array [2];
+ natural offset = array [3];
#ifdef use_debug_printing
print ("/3%s/- /6%s/- %i /cimm/- %i", operation_name [operation], operand_name [to], destination, offset);
#endif
- inset (true, 0xc1);
+ inset (true, 0xcharacter);
inset (to == operand_register, 0x05 + 0x08 * (operation - operation_rotate_left));
inset (to == operand_memory, 0xc0 + 0x08 * (operation - operation_rotate_left));
return 3;
}
-static u4 build_static_1 (u4 * array) {
- u4 operation = array [0];
+static natural build_static_1 (natural * array) {
+ natural operation = array [0];
#ifdef use_debug_printing
print ("/3%s/-", operation_name [operation]);
#endif
return 0;
}
-static u4 build_jump_if (u4 * array) {
- u4 operation = array [0];
- u4 location = array [1];
+static natural build_jump_if (natural * array) {
+ natural operation = array [0];
+ natural location = array [1];
#ifdef use_debug_printing
print ("/3%s/- %i", operation_name [operation], location);
#endif
return 2;
}
-static u4 build_jump (u4 * array) {
- u4 to = array [1];
- u4 destination = array [2];
+static natural build_jump (natural * array) {
+ natural to = array [1];
+ natural destination = array [2];
#ifdef use_debug_printing
print ("/3jmp/- /6%s/- %i", operand_name [to], destination);
#endif
return 2;
}
-static u4 build_move (u4 * array) {
- u4 to = array [1];
- u4 destination = array [2];
- u4 from = array [3];
- u4 source = array [4];
+static natural build_move (natural * array) {
+ natural to = array [1];
+ natural destination = array [2];
+ natural from = array [3];
+ natural source = array [4];
#ifdef use_debug_printing
print ("/3mov/- /6%s/- %i /6%s/- %i", operand_name [to], destination, operand_name [from], source);
#endif
return 4;
}
-static u4 build_call (u4 * array) {
- u4 from = array [1];
- u4 source = array [2];
+static natural build_call (natural * array) {
+ natural from = array [1];
+ natural source = array [2];
#ifdef use_debug_printing
print ("/3call/- /6%s/- %i", operand_name [from], source);
#endif
return 2;
}
-static u4 (* build_instruction [operation_count]) (u4 * array) = {
+static natural (* build_instruction [operation_count]) (natural * array) = {
store_memory, // operation_memory : LABEL
store_relative, // operation_relative : "IMPLEMENTED"
store_number,
build_static_1, build_static_1, build_static_1, build_call, build_jump, build_move
};
-static v0 assemble (u4 count, u4 * array, u4 external_memory, u4 internal_memory) {
+static procedure assemble (natural count, natural * array, natural external_memory, natural internal_memory) {
text_sector_byte = arena_add (external_memory * sizeof (* text_sector_byte));
data_sector_byte = arena_add (external_memory * sizeof (* text_sector_byte));
empty_imbue = arena_add (internal_memory * sizeof (* empty_imbue));
empty_store = arena_add (internal_memory * sizeof (* empty_store));
- for (u4 index = 0; index < count; ++index) {
- u4 size = text_sector_size;
+ for (natural index = 0; index < count; ++index) {
+ natural size = text_sector_size;
- u1 byte = 0;
+ natural_8 byte = 0;
#ifdef use_debug_nopping
inset (array [index] > operation_string, 0x90);
#endif
#ifdef use_debug_printing
print (" /0--/- ");
for (byte = size; byte < text_sector_size; ++byte) {
- print ("/5%s/- ", format_to_string ((u1) text_sector_byte [byte], false, 16, 2, '0'));
+ print ("/5%s/- ", format_to_string ((natural_8) text_sector_byte [byte], false, 16, 2, '0'));
}
print ("\n");
#endif
}
- main_entry_pos4 = empty_store [0];
+ main_entry_pointeger = empty_store [0];
- for (u4 index = 1; index < empty_holes; ++index) {
- u4 set = 0;
- u4 get = empty_array [index];
+ for (natural index = 1; index < empty_holes; ++index) {
+ natural set = 0;
+ natural get = empty_array [index];
- replace ((u1 *) & set, & text_sector_byte [get], sizeof (set));
+ replace ((natural_8 *) & set, & text_sector_byte [get], sizeof (set));
set += empty_store [empty_imbue [index]];
- replace (& text_sector_byte [get], (u1 *) & set, sizeof (get));
+ replace (& text_sector_byte [get], (natural_8 *) & set, sizeof (get));
}
}
-static v0 elf_main_header (u4 entry_point, b4 has_program, b4 for_linux, b4 for_x86_64) {
- u4 enter = entry_pos4 + 0x4000b0;
+static procedure elf_main_header (natural entry_point, boolean has_program, boolean for_linux, boolean for_x86_64) {
+ natural enter = entry_pointeger + 0x4000b0;
elf_main_header_byte [16] = (has_program) ? 0x02 : 0x03;
elf_main_header_byte [ 7] = (for_linux) ? 0x03 : 0x00;
memory_copy (& elf_main_header_byte [24], & enter, sizeof (enter));
}
-static v0 elf_text_sector (u4 text_size, u4 data_size) {
- u4 text = elf_header_size + text_size - data_size;
+static procedure elf_text_sector (natural text_size, natural data_size) {
+ natural text = elf_header_size + text_size - data_size;
memory_copy (& elf_text_sector_byte [32], & text, sizeof (text));
memory_copy (& elf_text_sector_byte [40], & text, sizeof (text));
}
-static v0 elf_data_sector (u4 text_size, u4 data_size) {
- u4 data = data_size;
- u4 core = elf_header_size + text_size - data_size;
- u4 move = 0x401000 + core;
+static procedure elf_data_sector (natural text_size, natural data_size) {
+ natural data = data_size;
+ natural core = elf_header_size + text_size - data_size;
+ natural move = 0x401000 + core;
memory_copy (& elf_data_sector_byte [ 8], & core, sizeof (core));
memory_copy (& elf_data_sector_byte [16], & move, sizeof (move));
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
+/// Xanguage, core programming and scripting language definitions created using Xyntax, with few more output definitions that I care about, for
+/// example Valgrind. There's not much to document about this library, it's used in my projects Xarbon and Xighlight. You can add support for
+/// your language of choice by adding one enumeration value, creating header file similar to existing ones, including it here and editing
+/// functions below to match 'language_count'. If you don't like how I highlight one or more of these languages, feel free to add more fields in
+/// 'language_structure' or edit existing ones inside 'xanguage' folder. This header file may look unfamiliar, especially to my other projects,
+/// but that's the cost of highlighting multiple languages in very low amount of code.
+
+/// Enumeration of supported languages, in no particular order.
+
typedef enum {
language_common, language_ada, language_c, language_cpp,
language_d, language_eaxhla, language_flat, language_fortran,
language_pascal, language_python, language_go, language_lua,
- language_bash, language_haskell, language_valgrind,
+ language_bash, language_haskell, language_valgrind, language_holy_c,
language_count
} language_enumeration;
+/// Structure of single language definition, highlighting-wise, this will be initialized below, check out how it is used.
+///
+/// language_structure * language = null;
+
typedef struct {
- u4 comment_colour;
- u4 processor_colour;
- u4 character_colour;
- u4 string_colour;
- u4 keyword_colour;
- u4 type_colour;
- u4 bracket_colour;
- u4 operator_colour;
- u4 number_colour;
- u4 lowercase_colour;
- u4 uppercase_colour;
- u4 underscore_colour;
- u4 register_colour;
- u4 extension_colour;
- u4 fatal_colour;
- u4 comment_effect;
- u4 processor_effect;
- u4 character_effect;
- u4 string_effect;
- u4 keyword_effect;
- u4 type_effect;
- u4 bracket_effect;
- u4 operator_effect;
- u4 number_effect;
- u4 lowercase_effect;
- u4 uppercase_effect;
- u4 underscore_effect;
- u4 register_effect;
- u4 extension_effect;
- u4 fatal_effect;
+ natural comment_colour; /// Colours for basic language syntax information.
+ natural processor_colour;
+ natural character_colour;
+ natural string_colour;
+ natural keyword_colour;
+ natural type_colour;
+ natural bracket_colour;
+ natural operator_colour;
+ natural number_colour;
+ natural lowercase_colour;
+ natural uppercase_colour;
+ natural underscore_colour;
+ natural register_colour;
+ natural extension_colour;
+ natural fatal_colour;
+ natural comment_effect; /// Effects for basic language syntax information.
+ natural processor_effect;
+ natural character_effect;
+ natural string_effect;
+ natural keyword_effect;
+ natural type_effect;
+ natural bracket_effect;
+ natural operator_effect;
+ natural number_effect;
+ natural lowercase_effect;
+ natural uppercase_effect;
+ natural underscore_effect;
+ natural register_effect;
+ natural extension_effect;
+ natural fatal_effect;
} language_structure;
+/// Warning: Local macros! You don't need to use this at all, it's covered by other functions, don't worry about it.
+///
+/// You shouldn't care about these local macros, they made few lines of code shorter, we're including files in this order, in this place.
+
#define language_lowercase "abcdefghijklmnopqrstuvwxyz"
#define language_uppercase "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define language_letters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#include <xolatile/xanguage/pascal.h>
#include <xolatile/xanguage/python.h>
#include <xolatile/xanguage/go.h>
+#include <xolatile/xanguage/holy_c.h>
#include <xolatile/xanguage/lua.h>
#include <xolatile/xanguage/bash.h>
#include <xolatile/xanguage/haskell.h>
#include <xolatile/xanguage/valgrind.h>
-static v0 (* language_highlighter [language_count]) (language_structure * language, syntax_structure * syntax) = {
+#undef language_lowercase
+#undef language_uppercase
+#undef language_letters
+#undef language_digits
+
+/// Array of function pointers enumerated above, these functions are defined in separate header files in 'xanguage' folder.
+
+static procedure (* language_highlighter [language_count]) (language_structure * language, syntax_structure * syntax) = {
language_highlight_common, language_highlight_ada, language_highlight_c, language_highlight_cpp,
language_highlight_d, language_highlight_eaxhla, language_highlight_flat, language_highlight_fortran,
language_highlight_pascal, language_highlight_python, language_highlight_go, language_highlight_lua,
- language_highlight_bash, language_highlight_haskell, language_highlight_valgrind
+ language_highlight_bash, language_highlight_haskell, language_highlight_valgrind, language_highlight_holy_c
};
-static c1 * language_short_option [language_count] = {
- "-X", "-A", "-C", "-S", "-D", "-E", "-T", "-F", "-P", "-Y", "-G", "-L", "-B", "-H", "-V"
+/// Array of short command line argument enumerated above, makes main function less bloated.
+
+static character * language_short_option [language_count] = {
+ "-X", "-A", "-C", "-S", "-D", "-E", "-T", "-F", "-P", "-Y", "-G", "-L", "-B", "-H", "-V", "-O"
};
-static c1 * language_long_option [language_count] = {
+/// Array of long command line argument enumerated above, makes main function less bloated.
+
+static character * language_long_option [language_count] = {
"--common", "--ada", "--c", "--cpp", "--d", "--eaxhla", "--flat", "--fortran",
- "--pascal", "--python", "--go", "--lua", "--bash", "--haskell", "--valgrind"
+ "--pascal", "--python", "--go", "--lua", "--bash", "--haskell", "--valgrind", "--holyc"
};
-static c1 * language_identifier [language_count] = {
+/// Array of pretty language name enumerated above, makes things pretty.
+
+static character * language_identifier [language_count] = {
"Common", "Ada", "C", "C++", "D", "EAXHLA", "Flat", "Fortran",
- "Pascal", "Python", "Go", "Lua", "Bash", "Haskell", "Valgrind"
+ "Pascal", "Python", "Go", "Lua", "Bash", "Haskell", "Valgrind", "Holy C"
};
-static language_structure * language_initialize (b4 true_colour) {
+/// After you've defined global or local language variable, you want to initialize it, edit this function if you dislike my themes.
+///
+/// language = language_initialize (false); /// You're probably using this library to render an image.
+/// language = language_initialize (true); /// You're probably using this library to print to terminal.
+
+static language_structure * language_initialize (boolean true_colour) {
language_structure * language = allocate (sizeof (* language));
if (true_colour == true) {
return (language);
}
+/// When you're done doing your thing, just call this function nicely to avoid leaking memory.
+///
+/// language = language_deinitialize (language);
+
static language_structure * language_deinitialize (language_structure * language) {
return (deallocate (language));
}
-static v0 language_conditionally_select (language_structure * language, syntax_structure * syntax, language_enumeration select) {
+/// This is just a helper function that I used a lot, it made sense to define it in this file, so here it is... This function will call specific
+/// function from 'xanguage' folder, based on what file type you pass to it, enumerated in Xtandard. It takes natural number as selection value
+/// due to avoiding type-related errors that dumb compilers might warn about, because some C compilers treat enumeration values as signed, while
+/// others treat them as unsigned, unless you manually define some value there negative, which is braindead.
+///
+/// language_conditionally_select (language, syntax, selection_index);
+
+static procedure language_conditionally_select (language_structure * language, syntax_structure * syntax, natural select) {
if (syntax->count == 0) {
if ((select == file_type_c_source) || (select == file_type_c_header)) {
language_highlight_c (language, syntax);
}
}
}
-
-#undef language_lowercase
-#undef language_uppercase
-#undef language_letters
-#undef language_digits
-static v0 language_highlight_ada (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/&|()\" \t\r\n";
+static procedure language_highlight_ada (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/&|()\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"abort", "else", "new", "return", "abs", "elsif", "not", "reverse",
"abstract", "end", "null", "accept", "entry", "select", "access", "of",
"separate", "aliased", "exit", "or", "some", "all", "others", "subtype",
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
-static v0 language_highlight_bash (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|@#$()[]{}'\" \t\r\n";
+static procedure language_highlight_bash (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|@#$()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"exit", "set", "elif", "done", "in", "then", "function", "fi",
"if", "else", "do", "while", "for"
};
syntax_define (syntax, false, false, "'", "'", '\0', language->string_colour, language->string_effect);
syntax_define (syntax, false, false, "\"", "\"", '\0', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
-static v0 language_highlight_cpp (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
+static procedure language_highlight_cpp (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"alignas", "alignof", "and", "asm", "auto", "break", "case",
"catch", "class", "compl", "concept", "const", "consteval", "constexpr",
"constinit", "continue", "decltype", "default", "delete", "do", "else",
"volatile", "while", "xor", "final", "override", "import", "module"
};
- c1 * types [] = {
- "v0", "b4", "off_t", "va_list", "float", "double", "float_t", "double_t",
+ character * types [] = {
+ "v0", "boolean", "off_t", "va_list", "float", "double", "float_t", "double_t",
"char", "short", "int", "long", "uchar", "ushort", "uint", "ulong",
"int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t",
"signed", "unsigned", "size_t", "ssize_t"
};
- c1 * commons [] = {
+ character * commons [] = {
"std", "FILE", "DIR", "EOF", "va_arg", "va_start", "va_end", "va_copy"
};
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_c (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
+static procedure language_highlight_c (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "return", "sizeof", "inline",
"restrict", "true", "false"
};
- c1 * types [] = {
- "v0", "b4", "off_t", "va_list", "float", "double", "float_t", "double_t",
+ character * types [] = {
+ "void", "bool", "off_t", "va_list", "float", "double", "float_t", "double_t",
"char", "short", "int", "long", "uchar", "ushort", "uint", "ulong",
"int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t",
- "signed", "unsigned", "size_t", "ssize_t"
+ "integer_8", "integer_16", "integer", "integer_64", "natural_8", "natural_16", "natural", "natural_64",
+ "real", "real_64", "v0", "character", "boolean", "pstring", "signed", "unsigned",
+ "size_t", "ssize_t"
};
- c1 * commons [] = {
+ character * commons [] = {
"null", "NULL", "FILE", "DIR", "va_arg", "va_start", "va_end", "va_copy",
"alignas", "alignof", "offsetof", "typeof", "EOF", "ABS", "MIN", "MAX",
"ARRAYSIZE", "SWAP", "UNUSED", "UNREACHABLE", "STRINGIFY", "CONCAT", "assert", "nullptr",
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_common (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+*-/%!&~^?|()[]{}'\"@#$` \t\r\n";
+static procedure language_highlight_common (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+*-/%!&~^?|()[]{}'\"@#$` \t\r\n";
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
-static v0 language_highlight_d (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|@()[]{}'\"` \t\r\n";
+static procedure language_highlight_d (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|@()[]{}'\"` \t\r\n";
- c1 * keywords [] = {
- "abstract", "alias", "align", "asm", "assert", "auto", "body", "b4",
+ character * keywords [] = {
+ "abstract", "alias", "align", "asm", "assert", "auto", "body", "boolean",
"break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat",
"char", "class", "const", "continue", "creal", "dchar", "debug", "default",
"delegate", "delete", "deprecated", "do", "double", "else", "enum", "export",
"v0", "wchar", "while", "foreach_reverse"
};
- c1 * types [] = {
+ character * types [] = {
"byte", "ubyte", "short", "ushort", "int", "uint", "long", "ulong",
"cent", "ucent", "char", "wchar", "dchar", "float", "double", "real",
- "ifloat", "idouble", "ireal", "cfloat", "cdouble", "creal", "v0", "b4",
+ "ifloat", "idouble", "ireal", "cfloat", "cdouble", "creal", "v0", "boolean",
"string"
};
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
syntax_define (syntax, false, false, "`", "`", '\0', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
-static v0 language_highlight_eaxhla (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,+-*/[]<>=; \t\r\n";
+static procedure language_highlight_eaxhla (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,+-*/[]<>=; \t\r\n";
- c1 * declarations [] = {
+ character * declarations [] = {
"program", "procedure", "machine", "library", "fast", "unix", "begin", "end",
"if", "then", "else", "repeat", "break", "continue", "until", "exit",
"fastcall", "shell", "alias", "macro", "scope", "unscope", "use", "include"
};
- c1 * types [] = {
- "s8", "c16", "s32", "s64", "u8", "u16", "u32", "u64",
- "f32", "f64", "f80", "v0", "c128", "u128", "s256", "u256",
+ character * types [] = {
+ "integer_64", "character6", "s32", "s64", "natural_64", "natural_86", "u32", "u64",
+ "f32", "f64", "real_640", "v0", "character28", "natural_828", "integer_1656", "natural_1656",
"s512", "u512"
};
- c1 * instructions [] = {
+ character * instructions [] = {
"jnpe", "jpo", "jnpo", "jpe", "jnb", "jae", "jnbe", "ja",
"jna", "jbe", "jnae", "jb", "jnl", "jge", "jnle", "jg",
"jng", "jle", "jnge", "jl", "cmovng", "cmovle", "cmovnge", "cmovl",
"bswap", "bsf", "bsr", "loop", "loope", "loopne"
};
- c1 * registers [] = {
+ character * registers [] = {
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
"r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
};
- s4 word;
+ integer word;
syntax_define (syntax, false, false, "#", "\n", '\0', language->comment_colour, language->comment_effect);
syntax_define (syntax, false, false, "---", "\n", '\0', language->comment_colour, language->comment_effect);
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (declarations); ++word) {
+ for (natural_64 word = 0; word < array_length (declarations); ++word) {
syntax_define (syntax, false, true, declarations [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (instructions); ++word) {
+ for (natural_64 word = 0; word < array_length (instructions); ++word) {
syntax_define (syntax, false, true, instructions [word], " \t\n", '\0', language->extension_colour, language->extension_effect);
}
- for (u8 word = 0; word < array_length (registers); ++word) {
+ for (natural_64 word = 0; word < array_length (registers); ++word) {
syntax_define (syntax, false, true, registers [word], separators, '\0', language->register_colour, language->register_effect);
}
-static v0 language_highlight_flat (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,+-=:;(){}[]%$<> \t\r\n";
+static procedure language_highlight_flat (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,+-=:;(){}[]%$<> \t\r\n";
- c1 * declarations [] = {
+ character * declarations [] = {
"format", "executable", "readable", "writable", "segment", "sector", "entry", "macro",
"db", "dw", "dd", "dq", "rb", "rw", "rd", "rq"
};
- c1 * instructions [] = {
+ character * instructions [] = {
"mov", "movabs", "movapd", "movaps", "movebe", "movsd", "movsx", "movzx",
"movsxd", "movd", "movq", "movs", "movsb", "movsw", "movsd", "movsq",
"cmovmp", "cmovrcxz", "cmovc", "cmovnc", "cmove", "cmovne", "cmovz", "cmovnz",
"rep", "repe", "repz", "repne", "repnz", "loop", "loope", "loopne"
};
- c1 * registers [] = {
+ character * registers [] = {
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
"ah", "ch", "dh", "bh"
};
- s4 word;
+ integer word;
syntax_define (syntax, false, false, ";", "\n", '\0', language->comment_colour, language->comment_effect);
syntax_define (syntax, false, false, "'", "'", '\\', language->string_colour, language->string_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (declarations); ++word) {
+ for (natural_64 word = 0; word < array_length (declarations); ++word) {
syntax_define (syntax, false, true, declarations [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (instructions); ++word) {
+ for (natural_64 word = 0; word < array_length (instructions); ++word) {
syntax_define (syntax, false, true, instructions [word], " \t", '\0', language->extension_colour, language->extension_effect);
}
- for (u8 word = 0; word < array_length (registers); ++word) {
+ for (natural_64 word = 0; word < array_length (registers); ++word) {
syntax_define (syntax, false, true, registers [word], separators, '\0', language->register_colour, language->register_effect);
}
-static v0 language_highlight_fortran (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ",:<=>+-*/&()[]\"\' \t\r\n";
+static procedure language_highlight_fortran (language_structure * language, syntax_structure * syntax) {
+ character * separators = ",:<=>+-*/&()[]\"\' \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"allocatable", "allocate", "associate", "backspace", "block", "call", "case", "common",
"contains", "cycle", "data", "deallocate", "d0", "do", "else", "elseif",
"end", "enddo", "endfile", "endif", "entry", "equivalence", "exit", "external",
"then", "to", "type", "use", "where", "write"
};
- c1 * types [] = {
- "character", "integer", "logical", "real", "complex"
+ character * types [] = {
+ "character", "integer", "boolean", "real", "complex"
};
- c1 * commons [] = {
+ character * commons [] = {
".and.", ".or.", ".not.", ".true.", ".false.", "in", "out", "len",
"dimension", "modulo", "advance"
};
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->processor_colour, language->processor_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
-static v0 language_highlight_go (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\"` \t\r\n";
+static procedure language_highlight_go (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\"` \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"break", "default", "func", "interface", "select", "case", "defer", "go",
"struct", "else", "goto", "package", "switch", "const", "var", "for",
"fallthrough", "if", "range", "type", "continue", "import", "return"
};
- c1 * types [] = {
+ character * types [] = {
"map", "uint", "int", "uintptr", "uint8", "uint16", "uint32", "uint64",
"int8", "int16", "int32", "int64", "float32", "float64", "complex64", "complex128",
- "byte", "rune", "string", "chan", "b4"
+ "byte", "rune", "string", "chan", "boolean"
};
- c1 * commons [] = {
+ character * commons [] = {
"true", "false", "nil", "err"
};
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
syntax_define (syntax, false, false, "`", "`", '\0', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_haskell (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!@#$&~^?|()[]{}'\" \t\r\n";
+static procedure language_highlight_haskell (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!@#$&~^?|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"case", "class", "data", "deriving", "do", "else", "if", "import",
"in", "infix", "infixl", "infixr", "instance", "let", "of", "module",
"newtype", "then", "type", "where"
};
- c1 * types [] = {
+ character * types [] = {
"Int", "Integer", "String", "Char", "Float", "Boolean"
};
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
-static v0 language_highlight_holy_c (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^|()[]{}'\" \t\r\n";
+static procedure language_highlight_holy_c (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"static", "extern", "import", "auto", "public", "sizeof", "asm", "no_warn",
"do", "while", "for", "switch", "case", "default", "start", "end",
"if", "else", "goto", "return", "break", "try", "catch", "throw",
"enum", "union", "class"
};
- c1 * types [] = {
+ character * types [] = {
"U8", "U16", "U32", "U64", "I8", "I16", "I32", "I64",
"U0", "I0", "F64", "Bool"
};
- c1 * commons [] = {
+ character * commons [] = {
"_extern", "_intern", "_import", "lastclass", "offset", "defined", "lock", "interrupt",
- "reg", "noreg", "argpop", "noargpop", "haserrcode", "NULL"
+ "reg", "noreg", "argpop", "noargpop", "haserrcode", "NULL", "TRUE", "FALSE"
};
syntax_define (syntax, false, false, "/*", "*/", '\0', language->comment_colour, language->comment_effect);
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_lua (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%~^#|()[]{}'\" \t\r\n";
+static procedure language_highlight_lua (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%~^#|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"and", "break", "do", "else", "elseif", "end", "false", "for",
"function", "if", "in", "local", "nil", "not", "or", "until",
"repeat", "return", "then", "true", "while"
};
- c1 * types [] = {
- "b4ean", "number", "string", "userdata", "function", "thread", "table"
+ character * types [] = {
+ "booleanean", "number", "string", "userdata", "function", "thread", "table"
};
- c1 * commons [] = {
+ character * commons [] = {
"require", "print", "seek", "dofile", "loadfile", "assert", "rawset", "rawget",
"setfenv", "pairs", "ipairs", "tonumber", "tostring", "foreach", "setn", "getn",
"insert", "concat", "sort", "remove", "abs", "ceil", "floor", "log10",
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (types); ++word) {
+ for (natural_64 word = 0; word < array_length (types); ++word) {
syntax_define (syntax, false, true, types [word], separators, '\0', language->type_colour, language->type_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_pascal (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/&@#$%^()[] \t\r\n";
+static procedure language_highlight_pascal (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/&@#$%^()[] \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"absolute", "and", "array", "asm", "begin", "case", "const", "constructor",
"destructor", "div", "do", "downto", "else", "end", "file", "for",
"function", "goto", "if", "in", "inherited", "inline", "interface", "xor",
syntax_define (syntax, false, false, "{", "}", '\0', language->comment_colour, language->comment_effect);
syntax_define (syntax, false, false, "'", "'", '#', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
-static v0 language_highlight_python (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
+static procedure language_highlight_python (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"and", "as", "assert", "break", "class", "continue", "def", "del",
"elif", "else", "except", "False", "finally", "for", "from", "global",
"if", "import", "in", "is", "labmda", "None", "nonlocal", "not",
"yield", "async", "await"
};
- c1 * commons [] = {
- "abs", "all", "any", "apply", "ascii", "basestring", "bin", "b4",
+ character * commons [] = {
+ "abs", "all", "any", "apply", "ascii", "basestring", "bin", "boolean",
"breakpoint", "buffer", "bytearray", "bytes", "callable", "chr", "classmethod", "cmp",
"coerce", "compile", "complex", "copyright", "credits", "delattr", "dict", "dir",
"divmod", "enumerate", "eval", "execfile", "exit", "file", "filter", "float",
syntax_define (syntax, false, false, "'", "'", '\\', language->character_colour, language->character_effect);
syntax_define (syntax, false, false, "\"", "\"", '\\', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separators, '\0', language->keyword_colour, language->keyword_effect);
}
- for (u8 word = 0; word < array_length (commons); ++word) {
+ for (natural_64 word = 0; word < array_length (commons); ++word) {
syntax_define (syntax, false, true, commons [word], separators, '\0', language->extension_colour, language->extension_effect);
}
-static v0 language_highlight_valgrind (language_structure * language, syntax_structure * syntax) {
- c1 * separators = ".,:;<=>+-*/%!&~^?|@#$()[]{}'\" \t\r\n";
+static procedure language_highlight_valgrind (language_structure * language, syntax_structure * syntax) {
+ character * separators = ".,:;<=>+-*/%!&~^?|@#$()[]{}'\" \t\r\n";
- c1 * titles [] = {
+ character * titles [] = {
"HEAP", "LEAK", "ERROR", "SUMMARY"
};
syntax_define (syntax, false, false, "(", ")", '\0', language->lowercase_colour, language->lowercase_effect);
syntax_define (syntax, false, false, "0x", ":", '\0', language->string_colour, language->string_effect);
- for (u8 word = 0; word < array_length (titles); ++word) {
+ for (natural_64 word = 0; word < array_length (titles); ++word) {
syntax_define (syntax, false, true, titles [word], separators, '\0', language->fatal_colour, language->fatal_effect);
}
-#define use_fatal_failure
+//~#define use_fatal_failure
#define use_png_library
-#define use_raptor_renderer
+//~#define use_raptor_renderer
+#define use_opengl_renderer
//~#define use_common_renderer
-//~#define use_opengl_renderer
//~#define use_vulkan_renderer
#include <xolatile/xtandard.h>
#include <xolatile/xormat.h>
#include <xolatile/xross.h>
#include <xolatile/xui.h>
+#include <xolatile/xenu.h>
-s4 main (v0) {
- cross_structure * cross = cross_initialize (30, 3);
- ui_structure * ui = ui_initialize (cross);
+integer main (none) {
+ //~cross_structure * cross = cross_initialize (30, 3);
+ cross_structure * cross = cross_initialize (30, 3, false, 1024 * 512, 512);
+ ui_structure * ui = ui_initialize (cross, 1);
- cross_configure (cross, 640, 480, "Xaptor - File Manager");
+ menu_structure * main_menu = menu_create_root (menu_layout_vertical, menu_type_window, 48);
- while (cross->active == true) {
- u4 offset = 48;
+ menu_append (main_menu, menu_create_button (menu_layout_horizontal, menu_create_string ("New Game", 0, 1.0f, 0xff7777ff), menu_create_sprite (345, 1.0f, 0xff0000ff), 12));
+ menu_append (main_menu, menu_create_button (menu_layout_horizontal, menu_create_string ("Load Game Please", 1, 1.5f, 0x77ff77ff), null, 12));
+ menu_append (main_menu, menu_create_root (menu_layout_horizontal, menu_type_frame, 12));
+ menu_append (main_menu, menu_create_button (menu_layout_horizontal, menu_create_string ("Some more stuff", 1, 2.0f, 0xffffffff), null, 12));
- cross_synchronize (cross, 0x00000000);
+ menu_append (main_menu->array [2], menu_create_button (0, menu_create_string ("A", 1, 1.0f, ~ 0u), null, 12));
+ menu_append (main_menu->array [2], menu_create_button (0, menu_create_string ("B", 1, 1.0f, ~ 0u), null, 12));
+ menu_append (main_menu->array [2], menu_create_root (menu_layout_vertical, menu_type_frame, 12));
+
+ menu_structure * c = main_menu->array [2];
- ui_render_window (cross, ui, 0, 0, cross->window_width, cross->window_height);
+ menu_append (c->array [2], menu_create_button (0, menu_create_string ("Dd", 1, 1.0f, ~ 0u), null, 10));
+ menu_append (c->array [2], menu_create_root (menu_layout_vertical, menu_type_status, 24));
+ menu_append (c->array [2], menu_create_button (0, menu_create_string ("EEEeee", 1, 1.0f, ~ 0u), null, 10));
+ menu_append (c->array [2], menu_create_button (0, menu_create_string ("FFff", 1, 1.0f, ~ 0u), null, 10));
- ui_render_status (cross, ui, offset, offset, cross->window_width - 2 * offset, cross->window_height - 2 * offset);
+ menu_structure * d = c->array [2];
- cross_render_string (cross, "Xaptors are coming!", 0, 2 * offset, 2 * offset, 1.5f, 0x4488ccff);
+ menu_append (d->array [1], menu_create_button (0, menu_create_string ("1", 1, 1.0f, ~ 0u), null, 12));
+ menu_append (d->array [1], menu_create_button (0, menu_create_string ("23", 1, 1.0f, ~ 0u), null, 12));
- cross_render_string (cross, format ("%i", cross->framerate), 0, 2 * offset, 3 * offset, 1.0f, 0x4488ccff);
- cross_render_string (cross, format ("%i", cross->global_tick), 0, 2 * offset, 4 * offset, 1.0f, 0x4488ccff);
- cross_render_string (cross, format ("%i", cross->gameplay_tick), 0, 2 * offset, 5 * offset, 1.0f, 0x4488ccff);
- cross_render_string (cross, format ("%i", cross->animation_tick), 0, 2 * offset, 6 * offset, 1.0f, 0x4488ccff);
- cross_render_string (cross, format ("%i", cross->cursor_x), 0, 2 * offset, 7 * offset, 1.0f, 0x4488ccff);
- cross_render_string (cross, format ("%i", cross->cursor_y), 0, 2 * offset, 8 * offset, 1.0f, 0x4488ccff);
+ ui_configure (cross, ui, null);
+
+ cross_configure (cross, 800, 600, "Xaptor - File Manager");
+
+ menu_configure (cross, main_menu);
+
+ while (cross->active == true) {
+ menu_center (cross, main_menu);
+
+ menu_render (cross, ui, main_menu);
if (cross->signal [signal_q] == true) break;
+
+ cross_synchronize (cross, 0x00000000);
}
+ menu_remove (main_menu);
+
cross = cross_deinitialize (cross);
ui = ui_deinitialize (ui);
Atom atom_close_button;
Atom atom_transparency;
- b4 signal [signal_count];
- b4 cursor [cursor_count];
- s4 cursor_x;
- s4 cursor_y;
-
- u4 gameplay_framerate;
- u4 animation_framerate;
- u4 window_width;
- u4 window_height;
- b4 active;
- u4 framerate;
- u8 frame_time;
- u8 frame_begin;
- u8 frame_end;
- u4 * framebuffer;
- u4 global_tick;
- u4 gameplay_tick;
- u4 animation_tick;
- u4 tab_width;
- u4 sprite_count;
- u4 font_count;
- u4 * * sprite_data;
- u4 * sprite_width;
- u4 * sprite_height;
- u4 * * font_index;
- u4 * * font_width;
- u4 * * font_height;
- c1 * font_begin;
- c1 * font_end;
+ boolean signal [signal_count];
+ boolean cursor [cursor_count];
+ integer cursor_x;
+ integer cursor_y;
+
+ natural gameplay_framerate;
+ natural animation_framerate;
+ natural window_width;
+ natural window_height;
+ boolean active;
+ natural framerate;
+ natural_64 frame_time;
+ natural_64 frame_begin;
+ natural_64 frame_end;
+ natural * framebuffer;
+ natural global_tick;
+ natural gameplay_tick;
+ natural animation_tick;
+ natural tab_width;
+ natural sprite_count;
+ natural font_count;
+ natural * * sprite_data;
+ natural * sprite_width;
+ natural * sprite_height;
+ natural * * font_index;
+ natural * * font_width;
+ natural * * font_height;
+ character * font_begin;
+ character * font_end;
} raptor_structure;
-static raptor_structure * raptor_initialize (u4 gameplay_framerate, u4 animation_framerate) {
+static raptor_structure * raptor_initialize (natural gameplay_framerate, natural animation_framerate) {
raptor_structure * raptor = allocate (sizeof (* raptor));
raptor->gameplay_framerate = gameplay_framerate;
}
static raptor_structure * raptor_deinitialize (raptor_structure * raptor) {
- for (u4 index = 0; index < raptor->sprite_count; ++index) {
+ for (natural index = 0; index < raptor->sprite_count; ++index) {
raptor->sprite_data [index] = deallocate (raptor->sprite_data [index]);
}
- for (u4 index = 0; index < raptor->font_count; ++index) {
+ for (natural index = 0; index < raptor->font_count; ++index) {
raptor->font_index [index] = deallocate (raptor->font_index [index]);
raptor->font_width [index] = deallocate (raptor->font_width [index]);
raptor->font_height [index] = deallocate (raptor->font_height [index]);
return (deallocate (raptor));
}
-static u4 raptor_sprite_raw_import (raptor_structure * raptor, u4 * data, u4 width, u4 height) {
+static natural raptor_sprite_raw_import (raptor_structure * raptor, natural * data, natural width, natural height) {
++raptor->sprite_count;
raptor->sprite_data = reallocate (raptor->sprite_data, raptor->sprite_count * sizeof (* raptor->sprite_data));
return (raptor->sprite_count - 1);
}
-static u4 raptor_font_raw_import (raptor_structure * raptor, u4 * data, u4 image_width, c1 begin, c1 end, u4 separator_colour) {
- u4 pointer = 0;
- u4 width = 0;
- u4 height = 0;
- u4 * buffer = null;
+static natural raptor_font_raw_import (raptor_structure * raptor, natural * data, natural image_width, natural image_height, character begin,
+ character end, natural empty) {
+ natural current = ++raptor->font_count - 1;
- u4 current = raptor->font_count;
+ natural pointer = 0;
+ natural width = 0;
+ natural height = 0;
+ natural point_count = 0;
+ natural * point_array = null;
- ++raptor->font_count;
+ fatal_failure (raptor->active == true, "raptor_font_raw_import: Raptor renderer is already initialized.");
+ fatal_failure (data == null, "raptor_font_raw_import: Data is null pointer.");
+ fatal_failure (image_width == 0, "raptor_font_raw_import: Font image width is zero.");
+ fatal_failure (image_height == 0, "raptor_font_raw_import: Font image height is zero.");
+ fatal_failure (begin >= end, "raptor_font_raw_import: Font character range is inverted.");
raptor->font_index = reallocate (raptor->font_index, raptor->font_count * sizeof (* raptor->font_index));
raptor->font_width = reallocate (raptor->font_width, raptor->font_count * sizeof (* raptor->font_width));
raptor->font_begin [current] = begin;
raptor->font_end [current] = end;
- raptor->font_index [current] = allocate ((u8) (end - begin + 1) * sizeof (* * raptor->font_index));
- raptor->font_width [current] = allocate ((u8) (end - begin + 1) * sizeof (* * raptor->font_width));
- raptor->font_height [current] = allocate ((u8) (end - begin + 1) * sizeof (* * raptor->font_height));
+ raptor->font_index [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * raptor->font_index));
+ raptor->font_width [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * raptor->font_width));
+ raptor->font_height [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * raptor->font_height));
- for (c1 index = begin; index <= end; ++index) {
- for ( ; data [pointer] == separator_colour; ++pointer);
- for (width = 0; data [pointer + width] != separator_colour; ++width);
- for (height = 0; data [pointer + height * image_width] != separator_colour; ++height);
+ point_array = allocate ((caliber) (end - begin + 1) * sizeof (* point_array));
- buffer = allocate (width * height * sizeof (* buffer));
+ if (empty == 0x00000000u) {
+ empty = data [0];
+ }
- for (u4 y = 0; y < height; ++y) {
- for (u4 x = 0; x < width; ++x) {
- buffer [y * width + x] = data [pointer + (y * image_width) + x];
+ for (natural y = 0; y < image_height - 1; ++y) {
+ for (natural x = 0; x < image_width - 1; ++x) {
+ if ((data [(y + 0) * image_width + (x + 0)] == empty)
+ && (data [(y + 1) * image_width + (x + 0)] == empty)
+ && (data [(y + 0) * image_width + (x + 1)] == empty)
+ && (data [(y + 1) * image_width + (x + 1)] == 0x00000000u)) {
+ ++point_count;
+ point_array [point_count - 1] = (y + 1) * image_width + (x + 1);
}
}
+ }
- raptor->font_index [current] [index - begin] = raptor_sprite_raw_import (raptor, buffer, width, height);
- raptor->font_width [current] [index - begin] = width;
- raptor->font_height [current] [index - begin] = height;
+ if (point_count != end - begin + 1) {
+ print ("/w Mismatch between font character points:\n");
+ print ("/c --- Hardcoded expected number of character points: %i\n", end - begin + 1);
+ print ("/c --- Algorithm found number of character points: %i\n", point_count);
+ }
- pointer += width;
+ for (natural index = 0; index < end - begin + 1; ++index) {
+ for (width = 0; data [point_array [index] + width] != empty; ++width);
+ for (height = 0; data [point_array [index] + height * image_width] != empty; ++height);
- for (; data [pointer] == separator_colour; ++pointer);
+ fatal_failure (width == 0, "raptor_font_raw_import: Font width is zero.");
+ fatal_failure (height == 0, "raptor_font_raw_import: Font height is zero.");
- if (pointer % image_width == 2) {
- pointer += height * image_width;
+ natural * buffer = allocate (width * height * sizeof (* buffer));
+
+ for (natural y = 0; y < height; ++y) {
+ for (natural x = 0; x < width; ++x) {
+ buffer [y * width + x] = data [point_array [index] + y * image_width + x];
+ }
}
+
+ raptor->font_index [current] [index] = raptor_sprite_raw_import (raptor, buffer, width, height);
+ raptor->font_width [current] [index] = width;
+ raptor->font_height [current] [index] = height;
}
+ point_array = deallocate (point_array);
+
return (current);
}
-static u4 raptor_sprite_import (raptor_structure * raptor, c1 * path) {
- u4 width = 0;
- u4 height = 0;
- u4 * data = null;
+static natural raptor_sprite_import (raptor_structure * raptor, character * path) {
+ natural width = 0;
+ natural height = 0;
+ natural * data = null;
data = format_image_import (path, & width, & height);
return (raptor_sprite_raw_import (raptor, data, width, height));
}
-static u4 raptor_font_import (raptor_structure * raptor, c1 * path, c1 begin, c1 end, u4 colour) {
- u4 width = 0;
- u4 height = 0;
- u4 result = 0;
- u4 * data = null;
+static natural raptor_font_import (raptor_structure * raptor, character * path, character begin, character end, natural colour) {
+ natural width = 0;
+ natural height = 0;
+ natural result = 0;
+ natural * data = null;
data = format_image_import (path, & width, & height);
- result = raptor_font_raw_import (raptor, data, width, begin, end, colour);
+ result = raptor_font_raw_import (raptor, data, width, height, begin, end, colour);
data = deallocate (data);
return (result);
}
-static u4 raptor_sprite_width (raptor_structure * raptor, u4 sprite) {
+static natural raptor_sprite_width (raptor_structure * raptor, natural sprite) {
return (raptor->sprite_width [sprite]);
}
-static u4 raptor_sprite_height (raptor_structure * raptor, u4 sprite) {
+static natural raptor_sprite_height (raptor_structure * raptor, natural sprite) {
return (raptor->sprite_height [sprite]);
}
-static u4 raptor_character_width (raptor_structure * raptor, c1 character, u4 font, f4 scale) {
- if ((character < raptor->font_begin [font]) || (character > raptor->font_end [font])) {
+static natural raptor_character_width (raptor_structure * raptor, character data, natural font, real scale) {
+ if ((data < raptor->font_begin [font]) || (data > raptor->font_end [font])) {
return (0);
} else {
- u4 index = raptor->font_index [font] [character - raptor->font_begin [font]];
+ natural index = raptor->font_index [font] [data - raptor->font_begin [font]];
- return ((u4) (scale * (float) raptor->sprite_width [index]));
+ return ((natural) (scale * (real) raptor->sprite_width [index]));
}
}
-static u4 raptor_character_height (raptor_structure * raptor, c1 character, u4 font, f4 scale) {
- if ((character < raptor->font_begin [font]) || (character > raptor->font_end [font])) {
+static natural raptor_character_height (raptor_structure * raptor, character data, natural font, real scale) {
+ if ((data < raptor->font_begin [font]) || (data > raptor->font_end [font])) {
return (0);
} else {
- u4 index = raptor->font_index [font] [character - raptor->font_begin [font]];
+ natural index = raptor->font_index [font] [data - raptor->font_begin [font]];
- return ((u4) (scale * (float) raptor->sprite_height [index]));
+ return ((natural) (scale * (real) raptor->sprite_height [index]));
}
}
-static u4 raptor_string_width (raptor_structure * raptor, c1 * string, u4 font, f4 scale) {
- u4 width = 0;
- u4 match = 0;
+static natural raptor_string_width (raptor_structure * raptor, character * string, natural font, real scale) {
+ natural width = 0;
+ natural match = 0;
if (string == null) {
return (0);
}
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\t') {
width += raptor->tab_width * raptor_character_width (raptor, ' ', font, scale);
} else if (string [index] == '\n') {
return (maximum (width, match));
}
-static u4 raptor_string_height (raptor_structure * raptor, c1 * string, u4 font, f4 scale) {
- u4 height = raptor_character_height (raptor, ' ', font, scale);
+static natural raptor_string_height (raptor_structure * raptor, character * string, natural font, real scale) {
+ natural height = raptor_character_height (raptor, ' ', font, scale);
if ((string == null) || (string [0] == '\0')) {
return (0);
}
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\n') {
height += raptor_character_height (raptor, ' ', font, scale);
}
return (height);
}
-static u4 raptor_center_x (raptor_structure * raptor, u4 size) {
+static natural raptor_center_x (raptor_structure * raptor, natural size) {
return ((raptor->window_width - size) / 2);
}
-static u4 raptor_center_y (raptor_structure * raptor, u4 size) {
+static natural raptor_center_y (raptor_structure * raptor, natural size) {
return ((raptor->window_height - size) / 2);
}
-static b4 raptor_cursor_inside (raptor_structure * raptor, s4 x, s4 y, u4 width, u4 height) {
+static boolean raptor_cursor_inside (raptor_structure * raptor, integer x, integer y, natural width, natural height) {
return ((raptor->cursor_x > x)
&& (raptor->cursor_y > y)
- && (raptor->cursor_x < x + (int) width)
- && (raptor->cursor_y < y + (int) height));
+ && (raptor->cursor_x < x + (integer) width)
+ && (raptor->cursor_y < y + (integer) height));
}
-static b4 raptor_cursor_left_click (raptor_structure * raptor, s4 x, s4 y, u4 width, u4 height) {
+static boolean raptor_cursor_left_click (raptor_structure * raptor, integer x, integer y, natural width, natural height) {
if (raptor->cursor [cursor_left] == true) {
return (raptor_cursor_inside (raptor, x, y, width, height) == true);
}
return (false);
}
-static b4 raptor_cursor_right_click (raptor_structure * raptor, s4 x, s4 y, u4 width, u4 height) {
+static boolean raptor_cursor_right_click (raptor_structure * raptor, integer x, integer y, natural width, natural height) {
if (raptor->cursor [cursor_right] == true) {
return (raptor_cursor_inside (raptor, x, y, width, height));
}
return (false);
}
-static v0 raptor_configure (raptor_structure * raptor, u4 window_width, u4 window_height, c1 * window_title) {
- u8 font_bitmap [2 * 95] = {
+static procedure raptor_configure (raptor_structure * raptor, natural window_width, natural window_height, character * window_title) {
+ natural_64 font_bitmap [2 * 95] = {
0x0000000000000000, 0x0000000000000000, 0x0000101010101010, 0x1000101000000000, 0x0024242400000000, 0x0000000000000000,
0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927c10100000, 0x0000649468081010, 0x202c524c00000000,
0x000018242418304a, 0x4444443a00000000, 0x0010101000000000, 0x0000000000000000, 0x0000081020202020, 0x2020100800000000,
XSetWindowAttributes window_attributes;
- u4 * dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
+ natural * dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
- for (u4 index = 0; index < 256; ++index) {
+ for (natural index = 0; index < 256; ++index) {
dumb_buffer [index] = 0xffffffff;
}
raptor->font_width [raptor->font_count - 1] = allocate (95 * sizeof (* * raptor->font_width));
raptor->font_height [raptor->font_count - 1] = allocate (95 * sizeof (* * raptor->font_height));
- for (u4 index = 0; index < 95; ++index) {
- u4 * buffer = allocate (8 * 16 * sizeof (* buffer));
+ for (natural index = 0; index < 95; ++index) {
+ natural * buffer = allocate (8 * 16 * sizeof (* buffer));
- for (u4 value = 0; value < 2; ++value) {
- for (u4 bit = 64; bit > 0; --bit) {
- u4 destination = ((value << 3) - ((bit - 1) >> 3) + 7) * 8 - ((bit - 1) & 7) + 7;
- u4 source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
+ for (natural value = 0; value < 2; ++value) {
+ for (natural bit = 64; bit > 0; --bit) {
+ natural destination = ((value << 3) - ((bit - 1) >> 3) + 7) * 8 - ((bit - 1) & 7) + 7;
+ natural source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
buffer [destination] = (source) ? 0xffffffff : 0x00000000;
}
raptor->display = XOpenDisplay (null);
- s4 screen = DefaultScreen (raptor->display);
+ integer screen = DefaultScreen (raptor->display);
XMatchVisualInfo (raptor->display, screen, 32, TrueColor, & raptor->visual);
raptor->frame_begin = nano_time ();
}
-static v0 raptor_render_base (raptor_structure * raptor, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height, f4 scale_x,
- f4 scale_y, s4 flip_x, s4 flip_y, u4 upper_left, u4 upper_right, u4 lower_left, u4 lower_right) {
- (v0) scale_x;
- (v0) scale_y;
- (v0) flip_x;
- (v0) flip_y;
+static procedure raptor_render_base (raptor_structure * raptor, natural sprite, integer x, integer y, natural u, natural v, natural width,
+ natural height, real scale_x, real scale_y, integer flip_x, integer flip_y, natural upper_left,
+ natural upper_right, natural lower_left, natural lower_right) {
+ (none) scale_x;
+ (none) scale_y;
+ (none) flip_x;
+ (none) flip_y;
/// FIX TO INTERPOLATE ALL 4 COLOURS
- //~(v0) upper_left;
- (v0) upper_right;
- (v0) lower_left;
- (v0) lower_right;
+ //~(none) upper_left;
+ (none) upper_right;
+ (none) lower_left;
+ (none) lower_right;
- u4 interpolate_pixels (u4 pixel, u4 modifier) {
- u4 r = (((pixel & 0xff000000) >> 24) * ((modifier & 0x000000ff) >> 0)) / 0xff;
- u4 g = (((pixel & 0x00ff0000) >> 16) * ((modifier & 0x0000ff00) >> 8)) / 0xff;
- u4 b = (((pixel & 0x0000ff00) >> 8) * ((modifier & 0x00ff0000) >> 16)) / 0xff;
- u4 a = (((pixel & 0x000000ff) >> 0) * ((modifier & 0xff000000) >> 24)) / 0xff;
+ natural interpolate_pixels (natural pixel, natural modifier) {
+ natural r = (((pixel & 0xff000000) >> 24) * ((modifier & 0x000000ff) >> 0)) / 0xff;
+ natural g = (((pixel & 0x00ff0000) >> 16) * ((modifier & 0x0000ff00) >> 8)) / 0xff;
+ natural b = (((pixel & 0x0000ff00) >> 8) * ((modifier & 0x00ff0000) >> 16)) / 0xff;
+ natural a = (((pixel & 0x000000ff) >> 0) * ((modifier & 0xff000000) >> 24)) / 0xff;
return ((r << 24) | (g << 16) | (b << 8) | a);
}
- if ((x + (int) width < 0) || (y + (int) height < 0) || (x > (int) raptor->window_width) || (y > (int) raptor->window_height)) return;
+ if ((x + (integer) width < 0) || (y + (integer) height < 0) || (x > (integer) raptor->window_width) || (y > (integer) raptor->window_height)) return;
- for (u4 vertical = 0; vertical < height; ++vertical) {
+ for (natural vertical = 0; vertical < height; ++vertical) {
if (vertical + y >= raptor->window_height) break;
if (vertical + v >= raptor->sprite_height [sprite]) break;
- for (u4 horizontal = 0; horizontal < width; ++horizontal) {
+ for (natural horizontal = 0; horizontal < width; ++horizontal) {
if (horizontal + x >= raptor->window_width) break;
if (horizontal + u >= raptor->sprite_width [sprite]) break;
- u4 pixel = raptor->sprite_data [sprite] [(vertical + v) * raptor->sprite_width [sprite] + horizontal + u];
- u4 at = (y + vertical) * raptor->window_width + (x + horizontal);
+ natural pixel = raptor->sprite_data [sprite] [(vertical + v) * raptor->sprite_width [sprite] + horizontal + u];
+ natural at = (y + vertical) * raptor->window_width + (x + horizontal);
raptor->framebuffer [at] = (((pixel & 0xff000000) >> 24) > 0x77)
? interpolate_pixels (pixel, upper_left)
}
}
-static v0 raptor_render_rectangle (raptor_structure * raptor, s4 x, s4 y, u4 width, u4 height, u4 colour) {
- raptor_render_base (raptor, raptor->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour, colour,
+static procedure raptor_render_rectangle (raptor_structure * raptor, integer x, integer y, natural width, natural height, natural colour) {
+ raptor_render_base (raptor, raptor->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour, colour,
colour, colour);
}
-static v0 raptor_render_sprite (raptor_structure * raptor, u4 sprite, s4 x, s4 y) {
- u4 width = raptor->sprite_width [sprite];
- u4 height = raptor->sprite_height [sprite];
+static procedure raptor_render_sprite (raptor_structure * raptor, natural sprite, integer x, integer y) {
+ natural width = raptor->sprite_width [sprite];
+ natural height = raptor->sprite_height [sprite];
raptor_render_base (raptor, sprite, x, y, 0, 0, width, height, 1.0f, 1.0f, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 raptor_render_sprite_scale (raptor_structure * raptor, u4 sprite, s4 x, s4 y, f4 scale_x, f4 scale_y) {
- u4 width = raptor->sprite_width [sprite];
- u4 height = raptor->sprite_height [sprite];
+static procedure raptor_render_sprite_scale (raptor_structure * raptor, natural sprite, integer x, integer y, real scale_x, real scale_y) {
+ natural width = raptor->sprite_width [sprite];
+ natural height = raptor->sprite_height [sprite];
raptor_render_base (raptor, sprite, x, y, 0, 0, width, height, scale_x, scale_y, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu,
0xffffffffu);
}
-static v0 raptor_render_sprite_crop (raptor_structure * raptor, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
+static procedure raptor_render_sprite_crop (raptor_structure * raptor, natural sprite, integer x, integer y, natural u, natural v, natural width, natural height) {
raptor_render_base (raptor, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 raptor_render_sprite_colour (raptor_structure * raptor, u4 sprite, u4 colour, s4 x, s4 y) {
- u4 width = raptor->sprite_width [sprite];
- u4 height = raptor->sprite_height [sprite];
+static procedure raptor_render_sprite_colour (raptor_structure * raptor, natural sprite, natural colour, integer x, integer y) {
+ natural width = raptor->sprite_width [sprite];
+ natural height = raptor->sprite_height [sprite];
raptor_render_base (raptor, sprite, x, y, 0, 0, width, height, 1.0f, 1.0f, 0, 0, colour, colour, colour, colour);
}
-static v0 raptor_render_sprite_crop_colour (raptor_structure * raptor, u4 sprite, u4 colour, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
- raptor_render_base (raptor, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, colour, colour, colour, colour);
-}
-
-static v0 raptor_render_sprite_flip (raptor_structure * raptor, u4 sprite, s4 x, s4 y, s4 flip_x, s4 flip_y) {
- u4 width = raptor->sprite_width [sprite];
- u4 height = raptor->sprite_height [sprite];
+static procedure raptor_render_sprite_flip (raptor_structure * raptor, natural sprite, integer x, integer y, integer flip_x, integer flip_y) {
+ natural width = raptor->sprite_width [sprite];
+ natural height = raptor->sprite_height [sprite];
raptor_render_base (raptor, sprite, x, y, 0, 0, width, height, 1.0f, 1.0f, flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu,
0xffffffffu);
}
-static v0 raptor_render_sprite_animate (raptor_structure * raptor, u4 sprite, s4 x, s4 y, u4 frames, u4 state, u4 states) {
- u4 width = raptor->sprite_width [sprite] / states;
- u4 height = raptor->sprite_height [sprite] / frames;
+static procedure raptor_render_sprite_animation (raptor_structure * raptor, natural sprite, integer x, integer y, natural frames, natural state, natural states) {
+ natural width = raptor->sprite_width [sprite] / states;
+ natural height = raptor->sprite_height [sprite] / frames;
- u4 u = width * (state % states);
- u4 v = height * (raptor->animation_tick % frames);
+ natural u = width * (state % states);
+ natural v = height * (raptor->animation_tick % frames);
raptor_render_sprite_crop (raptor, sprite, x, y, u, v, width, height);
}
-static v0 raptor_render_character (raptor_structure * raptor, c1 character, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
- if ((character < raptor->font_begin [font]) || (character > raptor->font_end [font])) return;
+static procedure raptor_render_sprite_crop_colour (raptor_structure * raptor, natural sprite, natural colour, integer x, integer y, natural u,
+ natural v, natural width, natural height) {
+ raptor_render_base (raptor, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, colour, colour, colour, colour);
+}
+
+static procedure raptor_render_character (raptor_structure * raptor, character data, natural font, integer x, integer y, real scale, natural colour) {
+ if ((data < raptor->font_begin [font]) || (data > raptor->font_end [font])) return;
- u4 index = raptor->font_index [font] [character - raptor->font_begin [font]];
+ natural index = raptor->font_index [font] [data - raptor->font_begin [font]];
- u4 width = raptor->sprite_width [index];
- u4 height = raptor->sprite_height [index];
+ natural width = raptor->sprite_width [index];
+ natural height = raptor->sprite_height [index];
raptor_render_base (raptor, index, x, y, 0, 0, width, height, scale, scale, 0, 0, colour, colour, colour, colour);
}
-static v0 raptor_render_string (raptor_structure * raptor, c1 * string, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
- s4 offset = x;
+static procedure raptor_render_string (raptor_structure * raptor, character * string, natural font, integer x, integer y, real scale, natural colour) {
+ integer offset = x;
if (string == null) return;
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\t') {
x += raptor->tab_width * raptor_character_width (raptor, ' ', font, scale);
continue;
}
}
-static v0 raptor_render_framerate (raptor_structure * raptor, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
+static procedure raptor_render_framerate (raptor_structure * raptor, natural font, integer x, integer y, real scale, natural colour) {
raptor_render_string (raptor, number_to_string (raptor->framerate), font, x, y, scale, colour);
}
-static v0 raptor_synchronize (raptor_structure * raptor, u4 clear_colour) {
- u4 signal_code [signal_count] = {
+static procedure raptor_synchronize (raptor_structure * raptor, natural clear_colour) {
+ natural signal_code [signal_count] = {
0,
38, 56, 54, 40, 26, 41, 42, 43, 31, 44, 45, 46, 58, 57, 32, 33,
24, 27, 39, 28, 30, 55, 25, 53, 29, 52, 19, 10, 11, 12, 13, 14,
85, 79, 80, 81
};
- u4 new_window_width = raptor->window_width;
- u4 new_window_height = raptor->window_height;
+ natural new_window_width = raptor->window_width;
+ natural new_window_height = raptor->window_height;
XEvent event = { 0 };
//~Window root_window = { 0 };
- //~s4 root_x = 0;
- //~s4 root_y = 0;
- //~u4 mask = 0;
+ //~integer root_x = 0;
+ //~integer root_y = 0;
+ //~natural mask = 0;
- for (u4 index = 0; index < cursor_count; ++index) {
+ for (natural index = 0; index < cursor_count; ++index) {
raptor->cursor [index] = false;
}
- for (u4 index = 0; index < signal_count; ++index) {
+ for (natural index = 0; index < signal_count; ++index) {
raptor->signal [index] = false;
}
raptor->cursor_y = event.xbutton.y;
} break;
case (KeyPress): {
- for (u4 index = 0; index < signal_count; ++index) {
+ for (natural index = 0; index < signal_count; ++index) {
if (event.xkey.keycode == signal_code [index]) {
raptor->signal [index] = true;
}
} break;
}
- for (u4 pixel = 0; pixel < raptor->window_width * raptor->window_height; ++pixel) {
- u4 r = (raptor->framebuffer [pixel] & 0x00ff0000) >> 16;
- u4 b = (raptor->framebuffer [pixel] & 0x000000ff) << 16;
+ for (natural pixel = 0; pixel < raptor->window_width * raptor->window_height; ++pixel) {
+ natural r = (raptor->framebuffer [pixel] & 0x00ff0000) >> 16;
+ natural b = (raptor->framebuffer [pixel] & 0x000000ff) << 16;
raptor->framebuffer [pixel] = (raptor->framebuffer [pixel] & 0xff00ff00) | b | r;
}
- raptor->image = XCreateImage (raptor->display, raptor->visual.visual, raptor->visual.depth, ZPixmap, 0, (c1 *) raptor->framebuffer,
+ raptor->image = XCreateImage (raptor->display, raptor->visual.visual, raptor->visual.depth, ZPixmap, 0, (character *) raptor->framebuffer,
raptor->window_width, raptor->window_height, 32, 0);
XPutImage (raptor->display, raptor->pixmap, raptor->context, raptor->image, 0, 0, 0, 0, raptor->window_width, raptor->window_height);
clear_colour = colour_channel_reverse (clear_colour);
- for (u4 pixel = 0; pixel < raptor->window_width * raptor->window_height; ++pixel) {
+ for (natural pixel = 0; pixel < raptor->window_width * raptor->window_height; ++pixel) {
raptor->framebuffer [pixel] = clear_colour;
}
}
if (raptor->global_tick % raptor->gameplay_framerate == 0) {
- raptor->framerate = (u4) (1000000000ul / raptor->frame_time);
+ raptor->framerate = (natural) (1000000000ul / raptor->frame_time);
}
++raptor->global_tick;
////////////// MOVE ME PLEASE
-static v0 raptor_render_rectangle_vertical_gradient (raptor_structure * raptor, s4 x, s4 y, u4 width, u4 height, u4 colour_up,
- u4 colour_down) {
- raptor_render_base (raptor, raptor->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16.0f, (float) height / 16.0f, 0, 0,
+static procedure raptor_render_rectangle_vertical_gradient (raptor_structure * raptor, integer x, integer y, natural width, natural height, natural colour_up,
+ natural colour_down) {
+ raptor_render_base (raptor, raptor->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16.0f, (real) height / 16.0f, 0, 0,
colour_up, colour_up, colour_down, colour_down);
}
#include <xolatile/xanguage.h>
#include <xolatile/xormat/png.h>
-static u4 background = 0xff181818;
-static u4 foreground = 0xffcccccc;
-static u4 font_width = 8;
-static u4 font_height = 16;
-static u4 tab_width = 8;
-static u4 render_border = 10;
-
-static u4 * render_image = null;
-static u4 render_width = 0;
-static u4 render_height = 0;
-static u4 line_number = 0;
-static u4 line_digits = 0;
-
-static v0 conditionally_exit (language_structure * language, syntax_structure * syntax, b4 terminate) {
+static natural background = 0xff181818;
+static natural foreground = 0xffcccccc;
+static natural font_width = 8;
+static natural font_height = 16;
+static natural tab_width = 8;
+static natural render_border = 10;
+
+static natural * render_image = null;
+static natural render_width = 0;
+static natural render_height = 0;
+static natural line_number = 0;
+static natural line_digits = 0;
+
+static procedure conditionally_exit (language_structure * language, syntax_structure * syntax, boolean terminate) {
syntax = syntax_deinitialize (syntax);
language = language_deinitialize (language);
}
}
-static v0 print_common (v0) {
+static procedure print_common (none) {
print ("/B/4xarbon/-: /4Source code PNG renderer/-\n\n");
print ("\tAuthor: /4Ognjen 'xolatile' Milan Robovic/-\n");
print ("\tLicense: /4GNU//GPLv3/-\n\n");
}
-static v0 print_help (v0) {
+static procedure print_help (none) {
print_common ();
print ("Example usage:\n\n");
print ("Supported languages:\n\n");
for (language_enumeration index = 0; index < language_count; ++index) {
- c1 align [32] = "";
+ character align [32] = "";
print ("\t/B/4%s/- /4%s/- /0---/- %s syntax highlighting\n",
language_short_option [index],
}
}
-static v0 print_version (v0) {
+static procedure print_version (none) {
print_common ();
print ("\tVersion: /40 (Zero)/-\n");
}
-static u4 fetch_width (c1 * data) {
- u4 image_width = 0;
- u4 count = 0;
+static natural fetch_width (character * data) {
+ natural image_width = 0;
+ natural count = 0;
do {
if (* data == '\t') {
return (image_width - 1);
}
-static u4 fetch_height (c1 * data) {
- u4 image_height = 0;
- u4 count = 0;
+static natural fetch_height (character * data) {
+ natural image_height = 0;
+ natural count = 0;
do {
if (* data == '\n') {
return (image_height + 1);
}
-static v0 render_character (c1 character, u4 * x, u4 * y, u4 colour) {
- u8 glyphmap [192] = {
+static procedure render_character (character data, natural * x, natural * y, natural colour) {
+ natural_64 glyphmap [192] = {
0x0000000000000000, 0x0000000000000000, 0x0000101010101010, 0x1000101000000000, 0x0024242400000000, 0x0000000000000000,
0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927c10100000, 0x0000649468081010, 0x202c524c00000000,
0x000018242418304a, 0x4444443a00000000, 0x0010101000000000, 0x0000000000000000, 0x0000081020202020, 0x2020100800000000,
0x0000300808080408, 0x0808083000000000, 0x000000000062928c, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000
};
- for (u8 index = 0; index < 2; ++index) {
- for (u8 bit = 64; bit > 0; --bit) {
- u8 destination = (* y + (index << 3) - ((bit - 1) >> 3) + 7) * render_width + (* x - ((bit - 1) & 7) + 7);
- u8 source = (glyphmap [2 * (u8) (character - ' ') + index] >> (bit - 1)) & 1;
+ for (natural_64 index = 0; index < 2; ++index) {
+ for (natural_64 bit = 64; bit > 0; --bit) {
+ natural_64 destination = (* y + (index << 3) - ((bit - 1) >> 3) + 7) * render_width + (* x - ((bit - 1) & 7) + 7);
+ natural_64 source = (glyphmap [2 * (natural_64) (data - ' ') + index] >> (bit - 1)) & 1;
render_image [destination] = (source) ? colour : background;
}
* x += font_width;
}
-static v0 render_string (c1 * string, u4 length, u4 * x, u4 * y, u4 colour) {
- for (u4 offset = 0; offset < length; ++offset) {
+static procedure render_string (character * string, natural length, natural * x, natural * y, natural colour) {
+ for (natural offset = 0; offset < length; ++offset) {
if (string [offset] == '\t') {
* x += font_width * tab_width;
} else if (string [offset] == '\n') {
* y += font_height;
* x = render_border;
- render_string (format_to_string ((int) ++line_number, false, 10, (int) line_digits, ' '),
+ render_string (format_to_string ((integer) ++line_number, false, 10, (integer) line_digits, ' '),
line_digits, x, y, foreground);
* x += font_width;
}
}
-s4 main (s4 argc, c1 * * argv) {
- u4 select = language_count;
- u4 offset = 0;
- u4 length = 0;
- u4 x = render_border;
- u4 y = render_border;
- c1 * buffer = null;
- c1 * dump = null;
+integer main (integer argc, character * * argv) {
+ natural select = language_count;
+ natural offset = 0;
+ natural length = 0;
+ natural x = render_border;
+ natural y = render_border;
+ character * buffer = null;
+ character * dump = null;
syntax_structure * syntax = syntax_initialize (666);
language_structure * language = language_initialize (true);
- for (s4 argument = 1; argument < argc; ++argument) {
+ for (integer argument = 1; argument < argc; ++argument) {
if (argument_compare (argv [argument], "-h", "--help") == true) {
print_help ();
conditionally_exit (language, syntax, true);
continue;
}
- for (u4 index = 0; index < language_count; ++index) {
+ for (natural index = 0; index < language_count; ++index) {
if (argument_compare (argv [argument], language_short_option [index], language_long_option [index]) == true) {
(* (language_highlighter [index])) (language, syntax);
select = index;
if (file_exists (argv [argument]) == true) {
if (select == language_count) {
- select = (u4) file_type (argv [argument]);
+ select = (natural) file_type (argv [argument]);
}
if (buffer == null) {
buffer = file_import (argv [argument]);
render_image [offset] = background;
}
- render_string (format_to_string ((int) ++line_number, false, 10, (int) line_digits, ' '), line_digits, & x, & y, foreground);
+ render_string (format_to_string ((integer) ++line_number, false, 10, (integer) line_digits, ' '), line_digits, & x, & y, foreground);
x += font_width;
for (offset = 0; buffer [offset] != '\0'; offset += length) {
select = syntax_select (syntax, & buffer [offset], & length);
- render_string (& buffer [offset], length, & x, & y, (select >= syntax->count) ? background : (u4) syntax->colour [select]);
+ render_string (& buffer [offset], length, & x, & y, (select >= syntax->count) ? background : (natural) syntax->colour [select]);
}
png_image_export (dump, render_image, render_width, render_height);
/// for more details, if you dare, it is a lot of text that nobody wants to read...
typedef struct {
- u4 count;
- u4 limit;
- u4 * sprite;
- f4 * life;
- u4 * colour_in;
- u4 * colour_out;
+ natural count;
+ natural limit;
+ natural * sprite;
+ real * life;
+ natural * colour_in;
+ natural * colour_out;
vector_3 * * position;
vector_3 * * target;
vector_3 * * speed;
} particle_structure;
-static particle_structure * particle_initialize (u4 limit) {
+static particle_structure * particle_initialize (natural limit) {
particle_structure * particle = allocate (sizeof (* particle));
particle->limit = limit;
particle->target = allocate (limit * sizeof (* particle->target));
particle->speed = allocate (limit * sizeof (* particle->speed));
- for (u4 index = 0; index < limit; ++index) {
+ for (natural index = 0; index < limit; ++index) {
particle->life [index] = 0.0f;
particle->position [index] = allocate (sizeof (* * particle->position));
}
static particle_structure * particle_deinitialize (particle_structure * particle) {
- for (u4 index = 0; index < particle->count; ++index) {
+ for (natural index = 0; index < particle->count; ++index) {
particle->position [index] = deallocate (particle->position [index]);
particle->target [index] = deallocate (particle->target [index]);
particle->speed [index] = deallocate (particle->speed [index]);
return (deallocate (particle));
}
-static v0 particle_append (particle_structure * particle, u4 sprite, f4 life, u4 colour_in, u4 colour_out, vector_3 * position,
+static procedure particle_append (particle_structure * particle, natural sprite, real life, natural colour_in, natural colour_out, vector_3 * position,
vector_3 * target, vector_3 * speed) {
if (particle->count + 1 >= particle->limit) return;
++particle->count;
- u4 current = particle->count - 1;
+ natural current = particle->count - 1;
particle->sprite [current] = sprite;
particle->life [current] = life;
vector_3_copy (particle->speed [current], speed);
}
-static v0 particle_switch (particle_structure * particle, u4 this, u4 with) {
- uint_exchange (& particle->sprite [this], & particle->sprite [with]);
- float_exchange (& particle->life [this], & particle->life [with]);
- uint_exchange (& particle->colour_in [this], & particle->colour_in [with]);
- uint_exchange (& particle->colour_out [this], & particle->colour_out [with]);
+static procedure particle_switch (particle_structure * particle, natural this, natural with) {
+ exchange_natural (& particle->sprite [this], & particle->sprite [with]);
+ exchange_real (& particle->life [this], & particle->life [with]);
+ exchange_natural (& particle->colour_in [this], & particle->colour_in [with]);
+ exchange_natural (& particle->colour_out [this], & particle->colour_out [with]);
vector_3_exchange ( particle->position [this], particle->position [with]);
vector_3_exchange ( particle->target [this], particle->target [with]);
vector_3_exchange ( particle->speed [this], particle->speed [with]);
}
-static v0 particle_remove (particle_structure * particle, u4 index) {
+static procedure particle_remove (particle_structure * particle, natural index) {
if (index >= particle->count) return;
particle_switch (particle, index, particle->count - 1);
--particle->count;
}
-static v0 particle_effect_splash (particle_structure * particle, u4 sprite, f4 life, u4 colour_in, u4 colour_out,
- vector_3 * position, u4 ray_count, f4 ray_force, f4 ray_error) {
- for (u4 ray = 0; ray < ray_count; ++ray) {
+static procedure particle_effect_splash (particle_structure * particle, natural sprite, real life, natural colour_in, natural colour_out,
+ vector_3 * position, natural ray_count, real ray_force, real ray_error) {
+ for (natural ray = 0; ray < ray_count; ++ray) {
vector_3 target = {
- //~position->x + frandomize (- ray_force, + ray_force),
- //~position->y + frandomize (- ray_force, + ray_force),
- //~position->z + frandomize (- ray_force, + ray_force) + frandomize (- ray_error, + ray_error)
- //~frandomize (- ray_force, + ray_force),
- //~frandomize (- ray_force, + ray_force),
- //~frandomize (- ray_force, + ray_force)
+ //~position->x + random_real (- ray_force, + ray_force),
+ //~position->y + random_real (- ray_force, + ray_force),
+ //~position->z + random_real (- ray_force, + ray_force) + random_real (- ray_error, + ray_error)
+ //~random_real (- ray_force, + ray_force),
+ //~random_real (- ray_force, + ray_force),
+ //~random_real (- ray_force, + ray_force)
0.0f, 0.0f, 0.0f
};
vector_3 speed = {
- frandomize (- ray_force, + ray_force),
- frandomize (- ray_force, + ray_force),
- frandomize (- ray_force, + ray_force)
+ random_real (- ray_force, + ray_force),
+ random_real (- ray_force, + ray_force),
+ random_real (- ray_force, + ray_force)
};
- life += frandomize (- 1.0f, + 1.0f);
+ life += random_real (- 1.0f, + 1.0f);
particle_append (particle, sprite, life, colour_in, colour_out, position, & target, & speed);
}
}
-static v0 particle_effect_evaporate (particle_structure * particle, u4 sprite, f4 life, u4 colour_in, u4 colour_out,
- vector_3 * position, u4 ray_count, f4 ray_force, f4 ray_error) {
- for (u4 ray = 0; ray < ray_count; ++ray) {
+static procedure particle_effect_evaporate (particle_structure * particle, natural sprite, real life, natural colour_in, natural colour_out,
+ vector_3 * position, natural ray_count, real ray_force, real ray_error) {
+ for (natural ray = 0; ray < ray_count; ++ray) {
vector_3 target = {
- frandomize (0.0f, + ray_force / 6.0f),
- frandomize (0.0f, + ray_force / 1.0f),
- frandomize (0.0f, + ray_force / 6.0f),
+ random_real (0.0f, + ray_force / 6.0f),
+ random_real (0.0f, + ray_force / 1.0f),
+ random_real (0.0f, + ray_force / 6.0f),
};
vector_3 speed = {
- frandomize (- ray_force, + ray_force),
- frandomize (- ray_force, + ray_force),
- frandomize (- ray_force, + ray_force)
+ random_real (- ray_force, + ray_force),
+ random_real (- ray_force, + ray_force),
+ random_real (- ray_force, + ray_force)
};
- life += frandomize (- 1.0f, + 1.0f);
+ life += random_real (- 1.0f, + 1.0f);
particle_append (particle, sprite, life, colour_in, colour_out, position, & target, & speed);
}
}
-static v0 particle_synchronize (particle_structure * particle, u4 framerate) {
- for (u4 index = 0; index < particle->count; ++index) {
- particle->life [index] -= 1.0f / (float) framerate;
+static procedure particle_synchronize (particle_structure * particle, natural framerate) {
+ for (natural index = 0; index < particle->count; ++index) {
+ particle->life [index] -= 1.0f / (real) framerate;
if (particle->life [index] < 0.0f) {
particle_remove (particle, index);
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
-typedef f4 matrix_2 [2] [2];
-typedef f4 matrix_3 [3] [3];
-typedef f4 matrix_4 [4] [4];
+/// Description
+///
+/// Xatrix, my tiny braindead unoptimized matrix library. Unlike vectors that use x, y, z and w structure fields, matrices are double array of
+/// 32-bit floating point numbers, and they're accessed with integers, which should've been the same case with vectors, but mathematicians are
+/// dumb sometimes (blame it on the one being older than the other one?). Again, nothing much to talk about here, learn linear algebra, include
+/// this header file in your project, use it however you want, compilers might optimize this better than my vector library. This library isn't
+/// intended for neural networks, as it's not generic, it can be used in simple CPU-based ray tracers and physics simulations.
+
+/// Nice 2D, 3D and 4D matrix structures.
+
+typedef real matrix_2 [2] [2]; /// Tiny 2x2 matrix.
+typedef real matrix_3 [3] [3]; /// Tiny 3x3 matrix.
+typedef real matrix_4 [4] [4]; /// Tiny 4x4 matrix.
+
+/// Assign values to 2D, 3D or 4D matrix and return address of that matrix.
static matrix_2 * matrix_2_assign (matrix_2 * destination,
- f4 m00, f4 m01,
- f4 m10, f4 m11) {
- destination [0] [0] = m00;
- destination [0] [1] = m01;
- destination [1] [0] = m10;
- destination [1] [1] = m11;
+ real m00, real m01,
+ real m10, real m11) {
+ destination [0] [0] = m00; destination [0] [1] = m01;
+ destination [1] [0] = m10; destination [1] [1] = m11;
return (destination);
}
static matrix_3 * matrix_3_assign (matrix_3 * destination,
- f4 m00, f4 m01, f4 m02,
- f4 m10, f4 m11, f4 m12,
- f4 m20, f4 m21, f4 m22) {
- destination [0] [0] = m00;
- destination [0] [1] = m01;
- destination [0] [2] = m02;
- destination [1] [0] = m10;
- destination [1] [1] = m11;
- destination [1] [2] = m12;
- destination [2] [0] = m20;
- destination [2] [1] = m21;
- destination [2] [2] = m22;
+ real m00, real m01, real m02,
+ real m10, real m11, real m12,
+ real m20, real m21, real m22) {
+ destination [0] [0] = m00; destination [0] [1] = m01; destination [0] [2] = m02;
+ destination [1] [0] = m10; destination [1] [1] = m11; destination [1] [2] = m12;
+ destination [2] [0] = m20; destination [2] [1] = m21; destination [2] [2] = m22;
return (destination);
}
static matrix_4 * matrix_4_assign (matrix_4 * destination,
- f4 m00, f4 m01, f4 m02, f4 m03,
- f4 m10, f4 m11, f4 m12, f4 m13,
- f4 m20, f4 m21, f4 m22, f4 m23,
- f4 m30, f4 m31, f4 m32, f4 m33) {
- destination [0] [0] = m00;
- destination [0] [1] = m01;
- destination [0] [2] = m02;
- destination [0] [3] = m03;
- destination [1] [0] = m10;
- destination [1] [1] = m11;
- destination [1] [2] = m12;
- destination [1] [3] = m13;
- destination [2] [0] = m20;
- destination [2] [1] = m21;
- destination [2] [2] = m22;
- destination [2] [3] = m23;
- destination [3] [0] = m30;
- destination [3] [1] = m31;
- destination [3] [2] = m32;
- destination [3] [3] = m33;
+ real m00, real m01, real m02, real m03,
+ real m10, real m11, real m12, real m13,
+ real m20, real m21, real m22, real m23,
+ real m30, real m31, real m32, real m33) {
+ destination [0] [0] = m00; destination [0] [1] = m01; destination [0] [2] = m02; destination [0] [3] = m03;
+ destination [1] [0] = m10; destination [1] [1] = m11; destination [1] [2] = m12; destination [1] [3] = m13;
+ destination [2] [0] = m20; destination [2] [1] = m21; destination [2] [2] = m22; destination [2] [3] = m23;
+ destination [3] [0] = m30; destination [3] [1] = m31; destination [3] [2] = m32; destination [3] [3] = m33;
return (destination);
}
+/// Nullify values of 2D, 3D or 4D matrix and return address of that matrix.
+
static matrix_2 * matrix_2_nullify (matrix_2 * destination) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] = 0.0f;
}
}
}
static matrix_3 * matrix_3_nullify (matrix_3 * destination) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] = 0.0f;
}
}
}
static matrix_4 * matrix_4_nullify (matrix_4 * destination) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] = 0.0f;
}
}
return (destination);
}
+/// Identify values of 2D, 3D or 4D matrix and return address of that matrix.
+
static matrix_2 * matrix_2_identity (matrix_2 * destination) {
destination = matrix_2_nullify (destination);
- for (u4 index = 0; index < 2; ++index) {
+ for (natural index = 0; index < 2; ++index) {
destination [index] [index] = 1.0f;
}
static matrix_3 * matrix_3_identity (matrix_3 * destination) {
destination = matrix_3_nullify (destination);
- for (u4 index = 0; index < 3; ++index) {
+ for (natural index = 0; index < 3; ++index) {
destination [index] [index] = 1.0f;
}
static matrix_4 * matrix_4_identity (matrix_4 * destination) {
destination = matrix_4_nullify (destination);
- for (u4 index = 0; index < 4; ++index) {
+ for (natural index = 0; index < 4; ++index) {
destination [index] [index] = 1.0f;
}
return (destination);
}
-static f4 matrix_2_determinant (matrix_2 * matrix) {
- f4 a = matrix [0] [0] * matrix [1] [1];
- f4 b = matrix [0] [1] * matrix [1] [0];
+/// Return determinant of 2D, 3D or 4D matrix.
+
+static real matrix_2_determinant (matrix_2 * matrix) {
+ real a = matrix [0] [0] * matrix [1] [1];
+ real b = matrix [0] [1] * matrix [1] [0];
return (a - b);
}
-static f4 matrix_3_determinant (matrix_3 * matrix) {
+static real matrix_3_determinant (matrix_3 * matrix) {
matrix_2 matrix_a = { { matrix [1] [1], matrix [1] [2] },
- { matrix [2] [1], matrix [2] [2] } };
+ { matrix [2] [1], matrix [2] [2] } };
matrix_2 matrix_b = { { matrix [1] [0], matrix [1] [2] },
- { matrix [2] [0], matrix [2] [2] } };
+ { matrix [2] [0], matrix [2] [2] } };
matrix_2 matrix_c = { { matrix [1] [0], matrix [1] [1] },
- { matrix [2] [0], matrix [2] [1] } };
+ { matrix [2] [0], matrix [2] [1] } };
- f4 a = matrix [0] [0] * matrix_2_determinant (& matrix_a);
- f4 b = matrix [0] [1] * matrix_2_determinant (& matrix_b);
- f4 c = matrix [0] [2] * matrix_2_determinant (& matrix_c);
+ real a = matrix [0] [0] * matrix_2_determinant (& matrix_a);
+ real b = matrix [0] [1] * matrix_2_determinant (& matrix_b);
+ real c = matrix [0] [2] * matrix_2_determinant (& matrix_c);
return (a - b + c);
}
-static f4 matrix_4_determinant (matrix_4 * matrix) {
+static real matrix_4_determinant (matrix_4 * matrix) {
matrix_3 matrix_a = { { matrix [1] [1], matrix [1] [2], matrix [1] [3] },
- { matrix [2] [1], matrix [2] [2], matrix [2] [3] },
- { matrix [3] [1], matrix [3] [2], matrix [3] [3] } };
+ { matrix [2] [1], matrix [2] [2], matrix [2] [3] },
+ { matrix [3] [1], matrix [3] [2], matrix [3] [3] } };
matrix_3 matrix_b = { { matrix [1] [0], matrix [1] [2], matrix [1] [3] },
- { matrix [2] [0], matrix [2] [2], matrix [2] [3] },
- { matrix [3] [0], matrix [3] [2], matrix [3] [3] } };
+ { matrix [2] [0], matrix [2] [2], matrix [2] [3] },
+ { matrix [3] [0], matrix [3] [2], matrix [3] [3] } };
matrix_3 matrix_c = { { matrix [1] [0], matrix [1] [1], matrix [1] [3] },
- { matrix [2] [0], matrix [2] [1], matrix [2] [3] },
- { matrix [3] [0], matrix [3] [1], matrix [3] [3] } };
+ { matrix [2] [0], matrix [2] [1], matrix [2] [3] },
+ { matrix [3] [0], matrix [3] [1], matrix [3] [3] } };
matrix_3 matrix_d = { { matrix [1] [0], matrix [1] [1], matrix [1] [2] },
- { matrix [2] [0], matrix [2] [1], matrix [2] [2] },
- { matrix [3] [0], matrix [3] [1], matrix [3] [2] } };
+ { matrix [2] [0], matrix [2] [1], matrix [2] [2] },
+ { matrix [3] [0], matrix [3] [1], matrix [3] [2] } };
- f4 a = matrix [0] [0] * matrix_3_determinant (& matrix_a);
- f4 b = matrix [0] [1] * matrix_3_determinant (& matrix_b);
- f4 c = matrix [0] [2] * matrix_3_determinant (& matrix_c);
- f4 d = matrix [0] [3] * matrix_3_determinant (& matrix_d);
+ real a = matrix [0] [0] * matrix_3_determinant (& matrix_a);
+ real b = matrix [0] [1] * matrix_3_determinant (& matrix_b);
+ real c = matrix [0] [2] * matrix_3_determinant (& matrix_c);
+ real d = matrix [0] [3] * matrix_3_determinant (& matrix_d);
return (a - b + c - d);
}
+/// Copy 2D, 3D or 4D source matrix into destination matrix.
+
static matrix_2 * matrix_2_copy (matrix_2 * destination, matrix_2 * source) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] = source [row] [column];
}
}
}
static matrix_3 * matrix_3_copy (matrix_3 * destination, matrix_3 * source) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] = source [row] [column];
}
}
}
static matrix_4 * matrix_4_copy (matrix_4 * destination, matrix_4 * source) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] = source [row] [column];
}
}
return (destination);
}
-static matrix_2 * matrix_2_scale (matrix_2 * destination, f4 scale) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+/// Scale 2D, 3D or 4D matrix by scalar value and return address of that matrix.
+
+static matrix_2 * matrix_2_scale (matrix_2 * destination, real scale) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] *= scale;
}
}
return (destination);
}
-static matrix_3 * matrix_3_scale (matrix_3 * destination, f4 scale) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+static matrix_3 * matrix_3_scale (matrix_3 * destination, real scale) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] *= scale;
}
}
return (destination);
}
-static matrix_4 * matrix_4_scale (matrix_4 * destination, f4 scale) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+static matrix_4 * matrix_4_scale (matrix_4 * destination, real scale) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] *= scale;
}
}
return (destination);
}
-static matrix_2 * matrix_2_scale_to (matrix_2 * destination, matrix_2 * source, f4 scale) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+/// Scale 2D, 3D or 4D source matrix by scalar value into destination matrix and return its address.
+
+static matrix_2 * matrix_2_scale_to (matrix_2 * destination, matrix_2 * source, real scale) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] = source [row] [column] * scale;
}
}
return (destination);
}
-static matrix_3 * matrix_3_scale_to (matrix_3 * destination, matrix_3 * source, f4 scale) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+static matrix_3 * matrix_3_scale_to (matrix_3 * destination, matrix_3 * source, real scale) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] = source [row] [column] * scale;
}
}
return (destination);
}
-static matrix_4 * matrix_4_scale_to (matrix_4 * destination, matrix_4 * source, f4 scale) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+static matrix_4 * matrix_4_scale_to (matrix_4 * destination, matrix_4 * source, real scale) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] = source [row] [column] * scale;
}
}
return (destination);
}
+/// Add 2D, 3D or 4D source matrix onto destination matrix and return address of destination matrix.
+
static matrix_2 * matrix_2_add (matrix_2 * destination, matrix_2 * source) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] += source [row] [column];
}
}
}
static matrix_3 * matrix_3_add (matrix_3 * destination, matrix_3 * source) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] += source [row] [column];
}
}
}
static matrix_4 * matrix_4_add (matrix_4 * destination, matrix_4 * source) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] += source [row] [column];
}
}
return (destination);
}
+/// Add two 2D, 3D or 4D matrices into destination matrix and return address of destination matrix.
+
static matrix_2 * matrix_2_add_to (matrix_2 * destination, matrix_2 * matrix_a, matrix_2 * matrix_b) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] = matrix_a [row] [column] + matrix_b [row] [column];
}
}
}
static matrix_3 * matrix_3_add_to (matrix_3 * destination, matrix_3 * matrix_a, matrix_3 * matrix_b) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] = matrix_a [row] [column] + matrix_b [row] [column];
}
}
}
static matrix_4 * matrix_4_add_to (matrix_4 * destination, matrix_4 * matrix_a, matrix_4 * matrix_b) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] = matrix_a [row] [column] + matrix_b [row] [column];
}
}
return (destination);
}
+/// Subtract 2D, 3D or 4D source matrix from destination matrix and return address of destination matrix.
+
static matrix_2 * matrix_2_subtract (matrix_2 * destination, matrix_2 * source) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] -= source [row] [column];
}
}
}
static matrix_3 * matrix_3_subtract (matrix_3 * destination, matrix_3 * source) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] -= source [row] [column];
}
}
}
static matrix_4 * matrix_4_subtract (matrix_4 * destination, matrix_4 * source) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] -= source [row] [column];
}
}
return (destination);
}
+/// Subtract two 2D, 3D or 4D matrices, save values into destination matrix and return address of destination matrix.
+
static matrix_2 * matrix_2_subtract_to (matrix_2 * destination, matrix_2 * matrix_a, matrix_2 * matrix_b) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
destination [row] [column] = matrix_a [row] [column] - matrix_b [row] [column];
}
}
}
static matrix_3 * matrix_3_subtract_to (matrix_3 * destination, matrix_3 * matrix_a, matrix_3 * matrix_b) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
destination [row] [column] = matrix_a [row] [column] - matrix_b [row] [column];
}
}
}
static matrix_4 * matrix_4_subtract_to (matrix_4 * destination, matrix_4 * matrix_a, matrix_4 * matrix_b) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
destination [row] [column] = matrix_a [row] [column] - matrix_b [row] [column];
}
}
return (destination);
}
+/// Multiply two 2D, 3D or 4D matrices, save values into destination matrix and return address of destination matrix.
+
static matrix_2 * matrix_2_multiply (matrix_2 * result, matrix_2 * matrix_a, matrix_2 * matrix_b) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
result [row] [column] = 0.0f;
- for (u4 index = 0; index < 2; ++index) {
+ for (natural index = 0; index < 2; ++index) {
result [row] [column] += matrix_a [row] [index] * matrix_b [index] [column];
}
}
}
static matrix_3 * matrix_3_multiply (matrix_3 * result, matrix_3 * matrix_a, matrix_3 * matrix_b) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
result [row] [column] = 0.0f;
- for (u4 index = 0; index < 3; ++index) {
+ for (natural index = 0; index < 3; ++index) {
result [row] [column] += matrix_a [row] [index] * matrix_b [index] [column];
}
}
}
static matrix_4 * matrix_4_multiply (matrix_4 * result, matrix_4 * matrix_a, matrix_4 * matrix_b) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
result [row] [column] = 0.0f;
- for (u4 index = 0; index < 4; ++index) {
+ for (natural index = 0; index < 4; ++index) {
result [row] [column] += matrix_a [row] [index] * matrix_b [index] [column];
}
}
return (result);
}
-static f4 matrix_2_trace (matrix_2 * matrix) {
+/// Return trace of 2D, 3D or 4D matrix.
+
+static real matrix_2_trace (matrix_2 * matrix) {
return (matrix [0] [0] + matrix [1] [1]);
}
-static f4 matrix_3_trace (matrix_3 * matrix) {
+static real matrix_3_trace (matrix_3 * matrix) {
return (matrix [0] [0] + matrix [1] [1] + matrix [2] [2]);
}
-static f4 matrix_4_trace (matrix_4 * matrix) {
+static real matrix_4_trace (matrix_4 * matrix) {
return (matrix [0] [0] + matrix [1] [1] + matrix [2] [2] + matrix [3] [3]);
}
-static b4 matrix_2_compare (matrix_2 * matrix_a, matrix_2 * matrix_b) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = 0; column < 2; ++column) {
+/// Compare if two 2D, 3D or 4D matrices are identical and return boolean value of it.
+
+static boolean matrix_2_compare (matrix_2 * matrix_a, matrix_2 * matrix_b) {
+ for (natural row = 0; row < 2; ++row) {
+ for (natural column = 0; column < 2; ++column) {
if (matrix_a [row] [column] != matrix_b [row] [column]) {
return (false);
}
return (true);
}
-static b4 matrix_3_compare (matrix_3 * matrix_a, matrix_3 * matrix_b) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
+static boolean matrix_3_compare (matrix_3 * matrix_a, matrix_3 * matrix_b) {
+ for (natural row = 0; row < 3; ++row) {
+ for (natural column = 0; column < 3; ++column) {
if (matrix_a [row] [column] != matrix_b [row] [column]) {
return (false);
}
return (true);
}
-static b4 matrix_4_compare (matrix_4 * matrix_a, matrix_4 * matrix_b) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
+static boolean matrix_4_compare (matrix_4 * matrix_a, matrix_4 * matrix_b) {
+ for (natural row = 0; row < 4; ++row) {
+ for (natural column = 0; column < 4; ++column) {
if (matrix_a [row] [column] != matrix_b [row] [column]) {
return (false);
}
return (true);
}
-
-static v0 matrix_2_transpose (matrix_2 * matrix_a, matrix_2 * matrix_b) {
- for (u4 row = 0; row < 2; ++row) {
- for (u4 column = row + 1; column < 2; ++column) {
- f4 temporary = matrix_a [row] [column];
-
- matrix_a [row] [column] = matrix_b [column] [row];
- matrix_b [column] [row] = temporary;
- }
- }
-}
-
-static v0 matrix_3_transpose (matrix_3 * matrix_a, matrix_3 * matrix_b) {
- for (u4 row = 0; row < 3; ++row) {
- for (u4 column = 0; column < 3; ++column) {
- f4 temporary = matrix_a [row] [column];
-
- matrix_a [row] [column] = matrix_b [column] [row];
- matrix_b [column] [row] = temporary;
- }
- }
-}
-
-static v0 matrix_4_transpose (matrix_4 * matrix_a, matrix_4 * matrix_b) {
- for (u4 row = 0; row < 4; ++row) {
- for (u4 column = 0; column < 4; ++column) {
- f4 temporary = matrix_a [row] [column];
-
- matrix_a [row] [column] = matrix_b [column] [row];
- matrix_b [column] [row] = temporary;
- }
- }
-}
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
+/// Xcript, autistic whitespace insignificant INI/CFG-like script parser. What else to say? Usage is more complex, this library is good for
+/// defining data in configuration files that corresponds with hardcoded variables or structure fields. More elaborate examples are in my other
+/// programs such as Xhads and Xhallenge for now, this will be used in few more projects that I planned.
+///
+/// Since this is single header library, just include it in your C source file, no need to use any stb-like macros for it as it was intended to
+/// be used in projects with only one source file. After that, you want to initialize some structures and open some files, it'll be more clear as
+/// you continue reading "documentation" below. I still think it's better to check out two projects mentioned above tho.
+
+/// Enumeration of scripts syntax elements.
+
typedef enum {
script_unknown, script_comment, script_string, script_number, script_marker, script_header, script_assign, script_end,
script_from, script_to, script_next
-} script_word_type;
+} script_word_enumeration;
+
+/// Script data structure, you want to define one per file you open, usage will be explained belo, they work one string per time.
+///
+/// script_data_structure * script = null;
typedef struct {
- c1 * path;
- c1 * source;
- u4 prefix;
- u4 length;
- u4 suffix;
- u4 offset;
- u4 line;
- u4 last_length;
- c1 * last_string;
- b4 force;
- b4 range;
-} script_structure;
+ character * path; /// File path for the script used in warnings and failures.
+ character * source; /// Raw character data imported from that file.
+ natural prefix; /// Amount of ignored characters before last string.
+ natural length; /// Amount of detected characters in last string.
+ natural suffix; /// Amount of ignored characters after last string.
+ natural offset; /// Offset inside script file data.
+ natural line; /// Currently active line in script file.
+ natural last_length; /// Length of last selected string.
+ character * last_string; /// Address of first character of last selected string.
+ boolean force; /// Reserved for future use...
+ boolean range; /// Boolean value for ranged expressions.
+} script_data_structure;
+
+/// Script structure containing global data, you want to have one per parsing unit, often one per entire project.
+///
+/// script_structure * information = null;
typedef struct {
- u4 counter;
- c1 * * identifier;
- u4 * index;
-} script_information;
+ natural counter; /// Identifier count.
+ character * * identifier; /// Array of identifier strings.
+ natural * index; /// Array of identifier indices.
+} script_structure;
-static v0 script_warning (script_structure * script, b4 condition, c1 * message) {
+/// Print a warning message if condition was true, otherwise continue parsing the script, minor errors should be warnings.
+///
+/// script_warning (script, name_defined == true, "Marker 'name' already defined.");
+
+static procedure script_warning (script_data_structure * script, boolean condition, character * message) {
if (condition == true) {
- print ("[/3Warning/-] %s: %i: %s\n", script->path, script->line, message);
+ print ("/w %s: %i: %s\n", script->path, script->line, message);
}
}
-static v0 script_failure (script_structure * script, b4 condition, c1 * message) {
- if (condition == true) {
- print ("[/1Failure/-] %s: %i: %s\n", script->path, script->line, message);
+/// Print a failure message and exit program if condition was true, otherwise continue parsing the script, major errors should be failures.
+///
+/// script_failure (script, name_defined == true, "Marker 'name' already defined.");
- print ("/1%s/-", & script->source [script->offset]);
+static procedure script_failure (script_data_structure * script, boolean condition, character * message) {
+ if (condition == true) {
+ print ("/f %s: %i: %s\n", script->path, script->line, message);
exit (log_failure);
}
}
-static script_structure * script_open (c1 * path) {
- script_structure * script = allocate (sizeof (* script));
+/// Initialize script data structure, by allocating memory for it, importing raw data from file path, and set other important fields.
+///
+/// script = script_open ("script.cfg");
+
+static script_data_structure * script_open (character * path) {
+ script_data_structure * script = allocate (sizeof (* script));
script->path = string_duplicate (path);
script->source = file_import (path);
- script->prefix = 0;
- script->length = 0;
- script->suffix = 0;
- script->offset = 0;
script->line = 1;
- script->last_length = 0;
script->last_string = & script->source [0];
return (script);
}
-static script_structure * script_close (script_structure * script) {
+/// Deinitialize script data structure, by deallocating memory used in it.
+///
+/// script = script_close (script);
+
+static script_data_structure * script_close (script_data_structure * script) {
script->path = deallocate (script->path);
script->source = deallocate (script->source);
return (deallocate (script));
}
-static b4 script_compare (script_structure * script, c1 * string) {
+/// Compare certain null terminated string with last selected string from script.
+
+static boolean script_compare (script_data_structure * script, character * string) {
return (string_compare_limit (string, script->last_string, script->last_length));
}
-static b4 script_check (script_information * information, u4 index, c1 * identifier) {
+/// Compare certain null terminated string with identifier from script structure selected by index.
+
+static boolean script_check (script_structure * information, natural index, character * identifier) {
return (string_compare (identifier, information->identifier [index]));
}
-static c1 * script_export_string (script_structure * script) {
+/// Return duplicate of last selected string from script. This will allocate memory that you have to free later.
+
+static character * script_export_string (script_data_structure * script) {
return (string_duplicate_limit (script->last_string, script->last_length));
}
-static u4 script_export_number (script_structure * script) {
+/// Return duplicate of last selected number from script.
+
+static natural script_export_number (script_data_structure * script) {
return (string_limit_to_number (script->last_string, script->last_length));
}
-static u4 script_export_marker (script_information * information, script_structure * script) {
- for (u4 counter = 0; counter < information->counter; ++counter) {
+/// Return identifier index of last selected string from script, if it's not identified, this function will exit program (fatal failure). I want
+/// strict error checking in my programs, only in parts where I encountered tiny mistakes that were more difficult to debug (took more than 30
+/// seconds). This code is under GNU/GPLv3 license, you can modify it as long as you're in the frame of the license.
+
+static natural script_export_marker (script_structure * information, script_data_structure * script) {
+ for (natural counter = 0; counter < information->counter; ++counter) {
if (script_compare (script, information->identifier [counter]) == true) {
return (information->index [counter]);
}
return (~ 0u);
}
-static script_word_type script_parser (script_structure * script) {
- script_word_type word = script_unknown;
+/// Big big badass bug, function that does all the parsing, I don't even want to explain how it works, it's obvious from reading. Good luck.
+
+static script_word_enumeration script_parser (script_data_structure * script) {
+ script_word_enumeration word = script_unknown;
script->prefix = 0;
script->length = 0;
return (word);
}
-static c1 * script_expect_header (script_information * information, script_structure * script, u4 index, b4 accept) {
+/// Okay, if you're not scared by the abomination written above, lets continue. This function checks for header in script file. That's the small
+/// part of file containing "[foo_bar]" text. If variable 'accept' is true, it'll add that identifier into script structure, otherwise it'll just
+/// return that string, which can be ignored or processed further.
+
+static character * script_expect_header (script_structure * information, script_data_structure * script, natural index, boolean accept) {
if (accept == true) {
++information->counter;
return (script_export_string (script));
}
-static c1 * script_expect_string (script_structure * script) {
- script_word_type word = script_unknown;
+/// This function checks for string, if you want your configuration data to be string, this will check for it.
+
+static character * script_expect_string (script_data_structure * script) {
+ script_word_enumeration word = script_unknown;
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
script_failure (script, (word = script_parser (script)) != script_string, "Expected string literal.");
return (script_export_string (script));
}
-static u4 script_expect_number (script_structure * script) {
- script_word_type word = script_unknown;
+/// This function checks for number, if you want your configuration data to be number, this will check for it again. No floating point numbers!
+
+static natural script_expect_number (script_data_structure * script) {
+ script_word_enumeration word = script_unknown;
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
script_failure (script, (word = script_parser (script)) != script_number, "Expected number literal.");
return (script_export_number (script));
}
-static u4 script_expect_marker (script_information * information, script_structure * script) {
- script_word_type word = script_unknown;
+/// This function checks for marker, this should be previously defined identifier, also known as header string.
+
+static natural script_expect_marker (script_structure * information, script_data_structure * script) {
+ script_word_enumeration word = script_unknown;
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
script_failure (script, (word = script_parser (script)) != script_marker, "Expected marker literal.");
return (script_export_marker (information, script));
}
-static u4 script_expect_number_or_marker (script_information * information, script_structure * script) {
- script_word_type word = script_unknown;
+/// This function checks for number or marker, but not string, sometimes you want to use hardcoded enumerations in configuration files.
+
+static natural script_expect_number_or_marker (script_structure * information, script_data_structure * script) {
+ script_word_enumeration word = script_unknown;
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
return (~ 0u);
}
-static u4 * script_expect_ordered_array (script_information * information, script_structure * script, u4 * count) {
- script_word_type word = script_unknown;
+/// Warning: I don't know how to really explain this...
+
+static natural * script_expect_ordered_array (script_structure * information, script_data_structure * script, natural * count) {
+ script_word_enumeration word = script_unknown;
- u4 found = 0;
- u4 * array = null;
+ natural found = 0;
+ natural * array = null;
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
script_failure (script, (word = script_parser (script)) != script_from, "Expected '(', begin range operator.");
return (array);
}
-static u4 * script_expect_unordered_array (script_information * information, script_structure * script, u4 count) {
- script_word_type word = script_unknown;
+/// Warning: I don't know how to really explain this...
+
+static natural * script_expect_unordered_array (script_structure * information, script_data_structure * script, natural count) {
+ script_word_enumeration word = script_unknown;
- u4 * array = allocate (count * sizeof (* array));
+ natural * array = allocate (count * sizeof (* array));
script_failure (script, (word = script_parser (script)) != script_assign, "Expected '=', assignment operator.");
script_failure (script, (word = script_parser (script)) != script_from, "Expected '(', begin range operator.");
for (word = script_parser (script); word != script_to; word = script_parser (script)) {
- u4 index = script_export_marker (information, script);
+ natural index = script_export_marker (information, script);
script_failure (script, word != script_marker, "Expected ranged marker.");
return (array);
}
-static script_information * script_initialize (c1 * general_script_file_path) {
- script_information * script = allocate (sizeof (* script));
+/// Initialize script structure by importing basic headers from general script file. This is where things get complex. Everyscript parser needs
+/// to have main, general script, that's not an empty file! Consider this an entry point of all scripts, since this script parser assumes
+/// there'll be thousands of tiny configuration files (scripts!), but you can also use only one script if you wanted.
+///
+/// script = script_initialize ("general.cfg");
- script_word_type word = script_unknown;
+static script_structure * script_initialize (character * general_script_file_path) {
+ script_structure * script = allocate (sizeof (* script));
- script_structure * general = script_open (general_script_file_path);
+ script_word_enumeration word = script_unknown;
+
+ script_data_structure * general = script_open (general_script_file_path);
for (word = script_parser (general); word != script_end; word = script_parser (general)) {
if (word == script_header) {
return (script);
}
-static script_information * script_deinitialize (script_information * script) {
- for (u4 index = 0; index < script->counter; ++index) {
+/// Deinitialize script structure by deallocating all identifier data. You can clean up stuff at program exit point, or after reading the script.
+///
+/// script = script_deinitialize (script);
+
+static script_structure * script_deinitialize (script_structure * script) {
+ for (natural index = 0; index < script->counter; ++index) {
script->identifier [index] = deallocate (script->identifier [index]);
}
return (deallocate (script));
}
-static u4 script_indexer (script_information * information, c1 * identifier) {
- for (u4 counter = 0; counter < information->counter; ++counter) {
+/// This function is similar to 'script_export_marker', but it compares identifier string, then returns index if it was found.
+
+static natural script_indexer (script_structure * information, character * identifier) {
+ for (natural counter = 0; counter < information->counter; ++counter) {
if (string_compare (identifier, information->identifier [counter]) == true) {
return (information->index [counter]);
}
/// for more details, if you dare, it is a lot of text that nobody wants to read...
typedef struct {
- b4 division;
- f4 scale;
+ boolean division;
+ real scale;
vector_3 * * vertex;
vector_3 * origin;
vector_3 * offset;
} octree_node;
typedef struct {
- u4 count;
- u4 limit;
+ natural count;
+ natural limit;
octree_node * * array;
} octree_structure;
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
+/// Xector (Vector), my small vector library, not to be confused with my older project Xector (Sector) which was for procedurally generating 3D
+/// models (based on boolean operations on 3D sectors). This library isn't optimized for performance or memory usage, instead it's for my own
+/// preferred programming style. It's hard to explain linear algebra to people who don't already know it (for me at least), so I won't do that,
+/// function names should provide you enough information. There'll be simple comments for the sake of consistency with my other libraries.
+///
+/// If you want to use "good" linear algebra library, prefer CGLM over this, and GLM if you're into C++ rather than objectively better language
+/// called C. Again, reading comments in this file is useless. Include it, set the vectors, do the work.
+
+/// 2D vector structure.
+
typedef struct {
- f4 x, y;
+ real x, y; /// Two 32-bit floating point numbers.
} vector_2;
+/// 3D vector structure.
+
typedef struct {
- f4 x, y, z;
+ real x, y, z; /// Three 32-bit floating point numbers.
} vector_3;
+/// 4D vector structure.
+
typedef struct {
- f4 x, y, z, w;
+ real x, y, z, w; /// Why the hell did they choose to start from 'x', and end with 'z', it's so retarded.
} vector_4;
-static vector_2 * vector_2_assign (vector_2 * destination, f4 x, f4 y) {
+/// Assign values to 2D, 3D or 4D vector and return address of that vector.
+
+static vector_2 * vector_2_assign (vector_2 * destination, real x, real y) {
destination->x = x;
destination->y = y;
return (destination);
}
-static vector_3 * vector_3_assign (vector_3 * destination, f4 x, f4 y, f4 z) {
+static vector_3 * vector_3_assign (vector_3 * destination, real x, real y, real z) {
destination->x = x;
destination->y = y;
destination->z = z;
return (destination);
}
-static vector_4 * vector_4_assign (vector_4 * destination, f4 x, f4 y, f4 z, f4 w) {
+static vector_4 * vector_4_assign (vector_4 * destination, real x, real y, real z, real w) {
destination->x = x;
destination->y = y;
destination->z = z;
return (destination);
}
+/// Nullify values of 2D, 3D or 4D vector and return address of that vector.
+
static vector_2 * vector_2_nullify (vector_2 * destination) {
destination->x = destination->y = 0.0f;
return (destination);
}
-static f4 vector_2_length (vector_2 * vector) {
- f4 x = vector->x;
- f4 y = vector->y;
+/// Return length of 2D, 3D or 4D vector.
+
+static real vector_2_length (vector_2 * vector) {
+ real x = vector->x;
+ real y = vector->y;
return (square_root (x * x + y * y));
}
-static f4 vector_3_length (vector_3 * vector) {
- f4 x = vector->x;
- f4 y = vector->y;
- f4 z = vector->z;
+static real vector_3_length (vector_3 * vector) {
+ real x = vector->x;
+ real y = vector->y;
+ real z = vector->z;
return (square_root (x * x + y * y + z * z));
}
-static f4 vector_4_length (vector_4 * vector) {
- f4 x = vector->x;
- f4 y = vector->y;
- f4 z = vector->z;
- f4 w = vector->w;
+static real vector_4_length (vector_4 * vector) {
+ real x = vector->x;
+ real y = vector->y;
+ real z = vector->z;
+ real w = vector->w;
return (square_root (x * x + y * y + z * z + w * w));
}
+/// Normalize 2D, 3D or 4D vector and return address of that vector.
+
static vector_2 * vector_2_normalize (vector_2 * destination) {
- f4 length = vector_2_length (destination);
+ real length = vector_2_length (destination);
destination->x /= length;
destination->y /= length;
}
static vector_3 * vector_3_normalize (vector_3 * destination) {
- f4 length = vector_3_length (destination);
+ real length = vector_3_length (destination);
destination->x /= length;
destination->y /= length;
}
static vector_4 * vector_4_normalize (vector_4 * destination) {
- f4 length = vector_4_length (destination);
+ real length = vector_4_length (destination);
destination->x /= length;
destination->y /= length;
return (destination);
}
+/// Normalize 2D, 3D or 4D source vector into destination vector and return its address.
+
static vector_2 * vector_2_normalize_to (vector_2 * destination, vector_2 * source) {
- f4 length = vector_2_length (source);
+ real length = vector_2_length (source);
destination->x = source->x / length;
destination->y = source->y / length;
}
static vector_3 * vector_3_normalize_to (vector_3 * destination, vector_3 * source) {
- f4 length = vector_3_length (source);
+ real length = vector_3_length (source);
destination->x = source->x / length;
destination->y = source->y / length;
}
static vector_4 * vector_4_normalize_to (vector_4 * destination, vector_4 * source) {
- f4 length = vector_4_length (source);
+ real length = vector_4_length (source);
destination->x = source->x / length;
destination->y = source->y / length;
return (destination);
}
+/// Copy 2D, 3D or 4D source vector into destination vector.
+
static vector_2 * vector_2_copy (vector_2 * destination, vector_2 * source) {
destination->x = source->x;
destination->y = source->y;
return (destination);
}
-static v0 vector_2_exchange (vector_2 * vector_a, vector_2 * vector_b) {
- float_exchange (& vector_a->x, & vector_b->x);
- float_exchange (& vector_a->y, & vector_b->y);
+/// Exchange values of two 2D, 3D or 4D vectors.
+
+static procedure vector_2_exchange (vector_2 * vector_a, vector_2 * vector_b) {
+ exchange_real (& vector_a->x, & vector_b->x);
+ exchange_real (& vector_a->y, & vector_b->y);
}
-static v0 vector_3_exchange (vector_3 * vector_a, vector_3 * vector_b) {
- float_exchange (& vector_a->x, & vector_b->x);
- float_exchange (& vector_a->y, & vector_b->y);
- float_exchange (& vector_a->z, & vector_b->z);
+static procedure vector_3_exchange (vector_3 * vector_a, vector_3 * vector_b) {
+ exchange_real (& vector_a->x, & vector_b->x);
+ exchange_real (& vector_a->y, & vector_b->y);
+ exchange_real (& vector_a->z, & vector_b->z);
}
-static v0 vector_4_exchange (vector_4 * vector_a, vector_4 * vector_b) {
- float_exchange (& vector_a->x, & vector_b->x);
- float_exchange (& vector_a->y, & vector_b->y);
- float_exchange (& vector_a->z, & vector_b->z);
- float_exchange (& vector_a->w, & vector_b->w);
+static procedure vector_4_exchange (vector_4 * vector_a, vector_4 * vector_b) {
+ exchange_real (& vector_a->x, & vector_b->x);
+ exchange_real (& vector_a->y, & vector_b->y);
+ exchange_real (& vector_a->z, & vector_b->z);
+ exchange_real (& vector_a->w, & vector_b->w);
}
-static vector_2 * vector_2_scale (vector_2 * destination, f4 scale) {
+/// Scale 2D, 3D or 4D vector by scalar value and return address of that vector.
+
+static vector_2 * vector_2_scale (vector_2 * destination, real scale) {
destination->x *= scale;
destination->y *= scale;
return (destination);
}
-static vector_3 * vector_3_scale (vector_3 * destination, f4 scale) {
+static vector_3 * vector_3_scale (vector_3 * destination, real scale) {
destination->x *= scale;
destination->y *= scale;
destination->z *= scale;
return (destination);
}
-static vector_4 * vector_4_scale (vector_4 * destination, f4 scale) {
+static vector_4 * vector_4_scale (vector_4 * destination, real scale) {
destination->x *= scale;
destination->y *= scale;
destination->z *= scale;
return (destination);
}
-static vector_2 * vector_2_scale_to (vector_2 * destination, vector_2 * source, f4 scale) {
+/// Scale 2D, 3D or 4D source vector by scalar value into destination vector and return its address.
+
+static vector_2 * vector_2_scale_to (vector_2 * destination, vector_2 * source, real scale) {
destination->x = source->x * scale;
destination->y = source->y * scale;
return (destination);
}
-static vector_3 * vector_3_scale_to (vector_3 * destination, vector_3 * source, f4 scale) {
+static vector_3 * vector_3_scale_to (vector_3 * destination, vector_3 * source, real scale) {
destination->x = source->x * scale;
destination->y = source->y * scale;
destination->z = source->z * scale;
return (destination);
}
-static vector_4 * vector_4_scale_to (vector_4 * destination, vector_4 * source, f4 scale) {
+static vector_4 * vector_4_scale_to (vector_4 * destination, vector_4 * source, real scale) {
destination->x = source->x * scale;
destination->y = source->y * scale;
destination->z = source->z * scale;
return (destination);
}
+/// Add 2D, 3D or 4D source vector onto destination vector and return address of destination vector.
+
static vector_2 * vector_2_add (vector_2 * destination, vector_2 * source) {
destination->x += source->x;
destination->y += source->y;
return (destination);
}
+/// Add two 2D, 3D or 4D vectors into destination vector and return address of destination vector.
+
static vector_2 * vector_2_add_to (vector_2 * destination, vector_2 * vector_a, vector_2 * vector_b) {
destination->x = vector_a->x + vector_b->x;
destination->y = vector_a->y + vector_b->y;
return (destination);
}
+/// Subtract 2D, 3D or 4D source vector from destination vector and return address of destination vector.
+
static vector_2 * vector_2_subtract (vector_2 * destination, vector_2 * source) {
destination->x -= source->x;
destination->y -= source->y;
return (destination);
}
+/// Subtract two 2D, 3D or 4D vectors, save values into destination vector and return address of destination vector.
+
static vector_2 * vector_2_subtract_to (vector_2 * destination, vector_2 * vector_a, vector_2 * vector_b) {
destination->x = vector_a->x - vector_b->x;
destination->y = vector_a->y - vector_b->y;
return (destination);
}
-static b4 vector_2_compare (vector_2 * vector_a, vector_2 * vector_b) {
+/// Compare if two 2D, 3D or 4D vectors are identical and return boolean value of it.
+
+static boolean vector_2_compare (vector_2 * vector_a, vector_2 * vector_b) {
if ((vector_a->x == vector_b->x) && (vector_a->y == vector_b->y)) {
return (true);
} else {
}
}
-static b4 vector_3_compare (vector_3 * vector_a, vector_3 * vector_b) {
+static boolean vector_3_compare (vector_3 * vector_a, vector_3 * vector_b) {
if ((vector_a->x == vector_b->x) && (vector_a->y == vector_b->y) && (vector_a->z == vector_b->z)) {
return (true);
} else {
}
}
-static b4 vector_4_compare (vector_4 * vector_a, vector_4 * vector_b) {
+static boolean vector_4_compare (vector_4 * vector_a, vector_4 * vector_b) {
if ((vector_a->x == vector_b->x) && (vector_a->y == vector_b->y) && (vector_a->z == vector_b->z) && (vector_a->w == vector_b->w)) {
return (true);
} else {
}
}
-static f4 vector_2_dot_product (vector_2 * vector_a, vector_2 * vector_b) {
+/// Return dot product of two 2D, 3D or 4D vectors.
+
+static real vector_2_dot_product (vector_2 * vector_a, vector_2 * vector_b) {
return (vector_a->x * vector_b->x + vector_a->y * vector_b->y);
}
-static f4 vector_3_dot_product (vector_3 * vector_a, vector_3 * vector_b) {
+static real vector_3_dot_product (vector_3 * vector_a, vector_3 * vector_b) {
return (vector_a->x * vector_b->x + vector_a->y * vector_b->y + vector_a->z * vector_b->z);
}
-static f4 vector_4_dot_product (vector_4 * vector_a, vector_4 * vector_b) {
+static real vector_4_dot_product (vector_4 * vector_a, vector_4 * vector_b) {
return (vector_a->x * vector_b->x + vector_a->y * vector_b->y + vector_a->z * vector_b->z + vector_a->w * vector_b->w);
}
-static f4 vector_2_cross_product (vector_2 * vector_a, vector_2 * vector_b) {
+/// Return cross product of two 2D vectors.
+
+static real vector_2_cross_product (vector_2 * vector_a, vector_2 * vector_b) {
return (vector_a->x * vector_b->y - vector_a->y * vector_b->x);
}
+/// Return cross product of two 3D vectors.
+
static vector_3 * vector_3_cross_product (vector_3 * destination, vector_3 * source) {
destination->x = destination->y * source->z - destination->z * source->y;
destination->y = destination->z * source->x - destination->x * source->z;
--- /dev/null
+/// __ _____ _ __ _ _
+/// \ \/ / _ \ '_ \| | | |
+/// > < __/ | | | |_| |
+/// /_/\_\___|_| |_|\__,_|
+///
+/// Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic
+///
+/// xolatile@chud.cyou - xenu - Tiny menu unity header, depending on Xross and XUI headers, hard to use but efficient.
+///
+/// This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU
+/// General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish...
+///
+/// This program is distributed in the hope that it will be useful, but it is probably not, and without any warranty, without even the implied
+/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
+/// for more details, if you dare, it is a lot of text that nobody wants to read...
+
+typedef enum {
+ menu_layout_vertical, menu_layout_horizontal,
+ menu_layout_count
+} menu_layout_enumeration;
+
+typedef enum {
+ menu_type_empty,
+ menu_type_window, menu_type_menu, menu_type_status, menu_type_frame,
+ menu_type_button, menu_type_separator, menu_type_string, menu_type_sprite,
+ menu_type_check_box, menu_type_icon, menu_type_overicon, menu_type_ubericon,
+ menu_type_text_field, menu_type_signal_field, menu_type_cursor_field, menu_type_slider_field,
+ menu_type_text_box, menu_type_code_box, menu_type_help_box, menu_type_data_box,
+ menu_type_count
+} menu_type_enumeration;
+
+typedef struct {
+ character * data;
+ natural font;
+ real scale;
+ natural colour;
+} menu_string;
+
+typedef struct {
+ natural data;
+ real scale;
+ natural colour;
+} menu_sprite;
+
+typedef struct {
+ menu_layout_enumeration layout;
+ menu_type_enumeration type;
+ menu_string * string;
+ menu_string * number;
+ menu_sprite * sprite;
+ integer x;
+ integer y;
+ natural width;
+ natural height;
+ natural offset;
+ natural count;
+ generic * * array;
+ generic * root;
+} menu_structure;
+
+static procedure menu_append (menu_structure * root, menu_structure * menu) {
+ ++root->count;
+
+ root->array = reallocate (root->array, root->count * sizeof (* root->array));
+
+ menu->root = root;
+
+ root->array [root->count - 1] = menu;
+}
+
+static procedure menu_remove (menu_structure * menu) {
+ if (menu->string != null) { menu->string = deallocate (menu->string); }
+ if (menu->number != null) { menu->number = deallocate (menu->number); }
+ if (menu->sprite != null) { menu->sprite = deallocate (menu->sprite); }
+
+ for (natural index = 0; index < menu->count; ++index) {
+ menu_remove (menu->array [index]);
+ }
+
+ if (menu->array != null) {
+ menu->array = deallocate (menu->array);
+ }
+
+ menu = deallocate (menu);
+}
+
+static menu_string * menu_create_string (character * data, natural font, real scale, natural colour) {
+ menu_string * string = allocate (sizeof (* string));
+
+ string->data = data;
+ string->font = font;
+ string->scale = scale;
+ string->colour = colour;
+
+ return (string);
+}
+
+static menu_sprite * menu_create_sprite (natural data, real scale, natural colour) {
+ menu_sprite * sprite = allocate (sizeof (* sprite));
+
+ sprite->data = data;
+ sprite->scale = scale;
+ sprite->colour = colour;
+
+ return (sprite);
+}
+
+static menu_structure * menu_create_base (menu_layout_enumeration layout, menu_type_enumeration type, menu_string * string,
+ menu_string * number, menu_sprite * sprite, integer x, integer y, natural offset) {
+ menu_structure * menu = allocate (sizeof (* menu));
+
+ menu->layout = layout;
+ menu->type = type;
+ menu->string = string;
+ menu->number = number;
+ menu->sprite = sprite;
+ menu->x = x;
+ menu->y = y;
+ menu->offset = offset;
+
+ return (menu);
+}
+
+static menu_structure * menu_create_root (menu_layout_enumeration layout, menu_type_enumeration type, natural offset) {
+ return (menu_create_base (layout, type, null, null, null, 0, 0, offset));
+}
+
+static menu_structure * menu_create_button (menu_layout_enumeration layout, menu_string * text, menu_sprite * icon, natural offset) {
+ return (menu_create_base (layout, menu_type_button, text, null, icon, 0, 0, offset));
+}
+
+static natural menu_string_width (cross_structure * cross, menu_string * string) {
+ return ((string == null) ? 0 : cross_string_width (cross, string->data, string->font, string->scale));
+}
+
+static natural menu_string_height (cross_structure * cross, menu_string * string) {
+ return ((string == null) ? 0 : cross_string_height (cross, string->data, string->font, string->scale));
+}
+
+static natural menu_sprite_width (cross_structure * cross, menu_sprite * sprite) {
+ return ((sprite == null) ? 0 : cross_sprite_width (cross, sprite->data));
+}
+
+static natural menu_sprite_height (cross_structure * cross, menu_sprite * sprite) {
+ return ((sprite == null) ? 0 : cross_sprite_height (cross, sprite->data));
+}
+
+static procedure menu_configure (cross_structure * cross, menu_structure * menu) {
+ for (natural index = 0; index < menu->count; ++index) {
+ menu_structure * submenu = menu->array [index];
+
+ menu_configure (cross, submenu);
+ }
+
+ for (natural index = 0; index < menu->count; ++index) {
+ menu_structure * submenu = menu->array [index];
+
+ if (menu->layout == menu_layout_vertical) {
+ menu->width = maximum_macro (menu->width, submenu->width + 2 * menu->offset);
+ menu->height += submenu->height;
+ }
+
+ if (menu->layout == menu_layout_horizontal) {
+ menu->width += submenu->width;
+ menu->height = maximum_macro (menu->height, submenu->height + 2 * menu->offset);
+ }
+ }
+
+ if (menu->layout == menu_layout_vertical) {
+ menu->width += maximum_natural (3, menu_sprite_width (cross, menu->sprite),
+ menu_string_width (cross, menu->string),
+ menu_string_width (cross, menu->number));
+
+ menu->height += menu_sprite_height (cross, menu->sprite)
+ + menu_string_height (cross, menu->string)
+ + menu_string_height (cross, menu->number);
+ }
+
+ if (menu->layout == menu_layout_horizontal) {
+ menu->width += menu_sprite_width (cross, menu->sprite)
+ + menu_string_width (cross, menu->string)
+ + menu_string_width (cross, menu->number);
+
+ menu->height += maximum_natural (3, menu_sprite_height (cross, menu->sprite),
+ menu_string_height (cross, menu->string),
+ menu_string_height (cross, menu->number));
+ }
+
+ menu->width += 2 * menu->offset;
+ menu->height += 2 * menu->offset;
+
+ if ((menu->count != 0) && (menu->root != null)) {
+ menu->width -= 2 * menu->offset * (menu->layout == menu_layout_vertical);
+ menu->height -= 2 * menu->offset * (menu->layout == menu_layout_horizontal);
+ }
+}
+
+static procedure menu_center (cross_structure * cross, menu_structure * menu) {
+ menu->x = cross_center_x (cross, menu->width);
+ menu->y = cross_center_y (cross, menu->height);
+}
+
+static procedure menu_subrender (cross_structure * cross, ui_structure * ui, menu_structure * menu) {
+ switch (menu->type) {
+ case (menu_type_empty): break;
+
+ case (menu_type_window): ui_render_window (cross, ui, menu->x, menu->y, menu->width, menu->height); break;
+ case (menu_type_menu): ui_render_menu (cross, ui, menu->x, menu->y, menu->width, menu->height); break;
+ case (menu_type_status): ui_render_status (cross, ui, menu->x, menu->y, menu->width, menu->height); break;
+ case (menu_type_frame): ui_render_frame (cross, ui, menu->x, menu->y, menu->width, menu->height); break;
+
+ case (menu_type_button): {
+ boolean sprite_is_used = (menu->sprite != null) && (menu->sprite->data != ~ 0u);
+ ui_render_button (cross, ui, menu->x, menu->y, menu->width, menu->height);
+ if (sprite_is_used == true) {
+ cross_render_sprite_colour (cross, menu->sprite->data, menu->x + menu->offset, menu->y + menu->offset, menu->sprite->colour);
+ }
+ if ((menu->string != null) && (menu->string->data != null)) {
+ integer x = menu->x + menu->offset + (sprite_is_used == true) * menu_sprite_width (cross, menu->sprite) * (menu->layout == menu_layout_horizontal);
+ integer y = menu->y + menu->offset + (sprite_is_used == true) * menu_sprite_height (cross, menu->sprite) * (menu->layout == menu_layout_vertical);
+ cross_render_string (cross, menu->string->data, menu->string->font, x, y, menu->string->scale, menu->string->colour);
+ }
+ } break;
+
+ default: break;
+ }
+}
+
+static procedure menu_render (cross_structure * cross, ui_structure * ui, menu_structure * menu) {
+ menu_subrender (cross, ui, menu);
+
+ for (natural index = 0; index < menu->count; ++index) {
+ menu_structure * submenu = menu->array [index];
+
+ menu_structure * root = submenu->root;
+
+ submenu->x = root->x + root->offset;
+ submenu->y = root->y + root->offset;
+
+ for (natural subindex = 0; subindex < index; ++subindex) {
+ menu_structure * base = root->array [subindex];
+
+ submenu->x += (root->layout == menu_layout_horizontal) * base->width;
+ submenu->y += (root->layout == menu_layout_vertical) * base->height;
+ }
+
+ menu_render (cross, ui, submenu);
+ }
+}
#define terminal_cursor_length (sizeof ("\033[---;---H") - 1)
typedef struct {
- c1 * screen;
- u4 screen_width;
- u4 screen_height;
+ character * screen;
+ natural screen_width;
+ natural screen_height;
- c1 format [terminal_format_length + 1];
- c1 cursor [terminal_cursor_length + 1];
+ character format [terminal_format_length + 1];
+ character cursor [terminal_cursor_length + 1];
- b4 active;
- b4 signal [signal_count];
+ boolean active;
+ boolean signal [signal_count];
- u4 character;
+ natural literal;
struct termios * old_terminal;
struct termios * new_terminal;
} terminal_structure;
-static c1 * terminal_screen_offset (terminal_structure * terminal, u4 x, u4 y) {
+static character * terminal_screen_offset (terminal_structure * terminal, natural x, natural y) {
return (& terminal->screen [terminal_revert_length + terminal_format_length * (y * terminal->screen_width + x) + 2 * y]);
}
-static u4 terminal_screen_length (terminal_structure * terminal) {
- u4 constant = terminal_revert_length + terminal_cursor_length + 1;
- u4 variable = terminal_format_length * terminal->screen_height * terminal->screen_width;
- u4 new_line = 2 * (terminal->screen_height - 1);
+static natural terminal_screen_length (terminal_structure * terminal) {
+ natural constant = terminal_revert_length + terminal_cursor_length + 1;
+ natural variable = terminal_format_length * terminal->screen_height * terminal->screen_width;
+ natural new_line = 2 * (terminal->screen_height - 1);
return (constant + variable + new_line);
}
-static v0 terminal_screen_dimensions (terminal_structure * terminal) {
+static procedure terminal_screen_dimensions (terminal_structure * terminal) {
struct winsize screen_dimension = { 0 };
- u4 old_width = terminal->screen_width;
- u4 old_height = terminal->screen_height;
+ natural old_width = terminal->screen_width;
+ natural old_height = terminal->screen_height;
- s4 status = ioctl (STDOUT_FILENO, TIOCGWINSZ, & screen_dimension);
+ integer status = ioctl (STDOUT_FILENO, TIOCGWINSZ, & screen_dimension);
fatal_failure (status == -1, "ioctl: Failed to get dimensions.");
string_copy (& terminal->screen [0], "\033[H");
- for (u4 index = 0; index < terminal->screen_height - 1; ++index) {
+ for (natural index = 0; index < terminal->screen_height - 1; ++index) {
string_copy (& terminal->screen [terminal_revert_length + index * terminal_format_length * terminal->screen_width], "\r\n");
}
}
-static c1 * terminal_format_character (terminal_structure * terminal, c1 character, s4 colour, s4 effect) {
- if (character_is_visible (character) == false) {
- character = ' ';
+static character * terminal_format_character (terminal_structure * terminal, character data, integer colour, integer effect) {
+ if (character_is_visible (data) == false) {
+ data = ' ';
}
colour %= colour_count;
effect %= effect_count;
- terminal->format [2] = (char) effect + '0';
- terminal->format [5] = (char) colour + '0';
- terminal->format [7] = character;
+ terminal->format [2] = (character) effect + '0';
+ terminal->format [5] = (character) colour + '0';
+ terminal->format [7] = data;
return (terminal->format);
}
-static terminal_structure * terminal_initialize (v0) {
+static terminal_structure * terminal_initialize (none) {
terminal_structure * terminal = allocate (sizeof (* terminal));
- s4 status = -1;
+ integer status = -1;
string_copy_limit (terminal->format, "\033[-;3-m-\033[0m", terminal_format_length + 1);
string_copy_limit (terminal->cursor, "\033[---;---H", terminal_cursor_length + 1);
memory_copy (terminal->new_terminal, terminal->old_terminal, sizeof (* terminal->old_terminal));
- terminal->new_terminal->c_cc [VMIN] = (u1) 0;
- terminal->new_terminal->c_cc [VTIME] = (u1) 1;
+ terminal->new_terminal->c_cc [VMIN] = (natural_8) 0;
+ terminal->new_terminal->c_cc [VTIME] = (natural_8) 1;
- terminal->new_terminal->c_iflag &= (u4) ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
- terminal->new_terminal->c_oflag &= (u4) ~(OPOST);
- terminal->new_terminal->c_cflag |= (u4) (CS8);
- terminal->new_terminal->c_lflag &= (u4) ~(ECHO | ICANON | IEXTEN | ISIG);
+ terminal->new_terminal->c_iflag &= (natural) ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ terminal->new_terminal->c_oflag &= (natural) ~(OPOST);
+ terminal->new_terminal->c_cflag |= (natural) (CS8);
+ terminal->new_terminal->c_lflag &= (natural) ~(ECHO | ICANON | IEXTEN | ISIG);
status = tcsetattr (STDIN_FILENO, TCSAFLUSH, terminal->new_terminal);
}
static terminal_structure * terminal_deinitialize (terminal_structure * terminal) {
- s4 status = tcsetattr (STDIN_FILENO, TCSAFLUSH, terminal->old_terminal);
+ integer status = tcsetattr (STDIN_FILENO, TCSAFLUSH, terminal->old_terminal);
fatal_failure (status == -1, "tcsetattr: Failed to set default attributes.");
return (deallocate (terminal));
}
-static v0 terminal_synchronize (terminal_structure * terminal) {
- u4 character = 0;
+static procedure terminal_synchronize (terminal_structure * terminal) {
+ natural signal = 0;
output (terminal->screen, terminal_screen_length (terminal));
terminal_screen_dimensions (terminal);
- for (u4 index = 0; index < signal_count; ++index) {
+ for (natural index = 0; index < signal_count; ++index) {
terminal->signal [index] = false;
}
- input (& character, sizeof (character));
+ input (& signal, sizeof (signal));
- terminal->character = (u4) character;
+ terminal->literal = (natural) signal;
- if (character == 0x0000001b) {
+ if (signal == 0x0000001b) {
terminal->signal [signal_escape] = true;
- } else if (character == 0x00415b1b) {
+ } else if (signal == 0x00415b1b) {
terminal->signal [signal_arrow_up] = true;
- } else if (character == 0x00425b1b) {
+ } else if (signal == 0x00425b1b) {
terminal->signal [signal_arrow_down] = true;
- } else if (character == 0x00435b1b) {
+ } else if (signal == 0x00435b1b) {
terminal->signal [signal_arrow_right] = true;
- } else if (character == 0x00445b1b) {
+ } else if (signal == 0x00445b1b) {
terminal->signal [signal_arrow_left] = true;
- } else if (character == 0x00000020) {
+ } else if (signal == 0x00000020) {
terminal->signal [signal_space] = true;
- } else if (character == 0x0000007f) {
+ } else if (signal == 0x0000007f) {
terminal->signal [signal_backspace] = true;
- } else if (character == 0x0000000d) {
+ } else if (signal == 0x0000000d) {
terminal->signal [signal_return] = true;
- } else if (character_is_digit ((char) character) == true) {
- terminal->signal [signal_0 + character - '0'] = true;
- } else if (character_is_lowercase ((char) character) == true) {
- terminal->signal [signal_a + character - 'a'] = true;
- } else if (character_is_uppercase ((char) character) == true) {
- terminal->signal [signal_a + character - 'A'] = true;
- terminal->signal [signal_left_shift] = true;
- terminal->signal [signal_right_shift] = true;
+ } else if (character_is_digit ((character) signal) == true) {
+ terminal->signal [signal_0 + signal - '0'] = true;
+ } else if (character_is_lowercase ((character) signal) == true) {
+ terminal->signal [signal_a + signal - 'a'] = true;
+ } else if (character_is_uppercase ((character) signal) == true) {
+ terminal->signal [signal_a + signal - 'A'] = true;
+ terminal->signal [signal_left_shift] = true;
+ terminal->signal [signal_right_shift] = true;
}
}
-static v0 terminal_render_cursor (terminal_structure * terminal, u4 x, u4 y) { /* BROKE IT INTENTIONALLY */
+static procedure terminal_render_cursor (terminal_structure * terminal, natural x, natural y) { /* BROKE IT INTENTIONALLY */
string_copy_limit (terminal->cursor + 2, string_align_left (number_to_string (y % 1000 + 1), 3, '0'), 3);
string_copy_limit (terminal->cursor + 6, string_align_left (number_to_string (x % 1000 + 1), 3, '0'), 3);
string_copy_limit (& terminal->screen [terminal_screen_length (terminal) - terminal_cursor_length - 1], terminal->cursor, terminal_cursor_length);
}
-static v0 terminal_render_character (terminal_structure * terminal, c1 character, u4 colour, u4 effect, u4 x, u4 y) {
+static procedure terminal_render_character (terminal_structure * terminal, character data, natural colour, natural effect, natural x, natural y) {
if ((x >= terminal->screen_width) || (y >= terminal->screen_height)) {
return;
}
- string_copy_limit (terminal_screen_offset (terminal, x, y), terminal_format_character (terminal, character, colour, effect), terminal_format_length);
+ string_copy_limit (terminal_screen_offset (terminal, x, y), terminal_format_character (terminal, data, colour, effect), terminal_format_length);
}
-static v0 terminal_render_toggle (terminal_structure * terminal, b4 toggle, u4 x, u4 y) {
- c1 marker = (toggle == true) ? '+' : '-';
- c1 colour = (toggle == true) ? colour_green : colour_red;
+static procedure terminal_render_toggle (terminal_structure * terminal, boolean toggle, natural x, natural y) {
+ character marker = (toggle == true) ? '+' : '-';
+ character colour = (toggle == true) ? colour_green : colour_red;
terminal_render_character (terminal, '[', colour_grey, effect_bold, x + 0, y);
terminal_render_character (terminal, marker, colour, effect_bold, x + 1, y);
terminal_render_character (terminal, ']', colour_grey, effect_bold, x + 2, y);
}
-static v0 terminal_render_fill_bar (terminal_structure * terminal, u4 value, u4 limit, c1 character, u4 colour, u4 effect, u4 x, u4 y) {
+static procedure terminal_render_fill_bar (terminal_structure * terminal, natural value, natural limit, character data, natural colour, natural effect, natural x, natural y) {
terminal_render_character (terminal, '[', colour_grey, effect_bold, x, y);
terminal_render_character (terminal, ']', colour_grey, effect_bold, x + limit + 1, y);
- for (u4 index = 0; index < limit; ++index) {
- terminal_render_character (terminal, (index < value) ? character : ' ', colour, effect, x + index + 1, y);
+ for (natural index = 0; index < limit; ++index) {
+ terminal_render_character (terminal, (index < value) ? data : ' ', colour, effect, x + index + 1, y);
}
}
-static v0 terminal_render_string (terminal_structure * terminal, c1 * string, u4 colour, u4 effect, u4 x, u4 y) {
- for (u4 index = 0; string [index] != '\0'; ++index) {
+static procedure terminal_render_string (terminal_structure * terminal, character * string, natural colour, natural effect, natural x, natural y) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
terminal_render_character (terminal, string [index], colour, effect, x + index, y);
}
}
-static v0 terminal_render_number (terminal_structure * terminal, s4 number, u4 colour, u4 effect, u4 x, u4 y) {
+static procedure terminal_render_number (terminal_structure * terminal, integer number, natural colour, natural effect, natural x, natural y) {
terminal_render_string (terminal, number_to_string (number), colour, effect, x, y);
}
-static v0 terminal_render_string_crop (terminal_structure * terminal, c1 * string, u4 colour, u4 effect, u4 x, u4 y, u4 crop) {
- for (u4 index = 0; (string [index] != '\0') && (index < crop); ++index) {
+static procedure terminal_render_string_crop (terminal_structure * terminal, character * string, natural colour, natural effect, natural x, natural y, natural crop) {
+ for (natural index = 0; (string [index] != '\0') && (index < crop); ++index) {
terminal_render_character (terminal, string [index], colour, effect, x + index, y);
}
}
-static v0 terminal_render_number_crop (terminal_structure * terminal, s4 number, u4 colour, u4 effect, u4 x, u4 y, u4 crop) {
+static procedure terminal_render_number_crop (terminal_structure * terminal, integer number, natural colour, natural effect, natural x, natural y, natural crop) {
terminal_render_string_crop (terminal, number_to_string (number), colour, effect, x, y, crop);
}
-static v0 terminal_render_vertical_line (terminal_structure * terminal, c1 character, u4 colour, u4 effect, u4 x, u4 y, u4 height) {
- for (u4 offset = 0; offset != height; ++offset) {
- terminal_render_character (terminal, character, colour, effect, x, y + offset);
+static procedure terminal_render_vertical_line (terminal_structure * terminal, character data, natural colour, natural effect, natural x, natural y, natural height) {
+ for (natural offset = 0; offset != height; ++offset) {
+ terminal_render_character (terminal, data, colour, effect, x, y + offset);
}
}
-static v0 terminal_render_horizontal_line (terminal_structure * terminal, c1 character, u4 colour, u4 effect, u4 x, u4 y, u4 width) {
- for (u4 offset = 0; offset != width; ++offset) {
- terminal_render_character (terminal, character, colour, effect, x + offset, y);
+static procedure terminal_render_horizontal_line (terminal_structure * terminal, character data, natural colour, natural effect, natural x, natural y, natural width) {
+ for (natural offset = 0; offset != width; ++offset) {
+ terminal_render_character (terminal, data, colour, effect, x + offset, y);
}
}
-static v0 terminal_render_rectangle_line (terminal_structure * terminal, c1 character, u4 colour, u4 effect, u4 x, u4 y, u4 width, u4 height) {
- terminal_render_vertical_line (terminal, character, colour, effect, x + 0, y + 0, height + 0);
- terminal_render_vertical_line (terminal, character, colour, effect, x + width - 1, y + 0, height + 0);
- terminal_render_horizontal_line (terminal, character, colour, effect, x + 1, y + 0, width - 1);
- terminal_render_horizontal_line (terminal, character, colour, effect, x + 1, y + height - 1, width - 1);
+static procedure terminal_render_rectangle_line (terminal_structure * terminal, character data, natural colour, natural effect, natural x, natural y, natural width, natural height) {
+ terminal_render_vertical_line (terminal, data, colour, effect, x + 0, y + 0, height + 0);
+ terminal_render_vertical_line (terminal, data, colour, effect, x + width - 1, y + 0, height + 0);
+ terminal_render_horizontal_line (terminal, data, colour, effect, x + 1, y + 0, width - 1);
+ terminal_render_horizontal_line (terminal, data, colour, effect, x + 1, y + height - 1, width - 1);
}
-static v0 terminal_render_rectangle_fill (terminal_structure * terminal, c1 character, u4 colour, u4 effect, u4 x, u4 y, u4 width, u4 height) {
- for (u4 offset_y = 0; offset_y != height; ++offset_y) {
- for (u4 offset_x = 0; offset_x != width; ++offset_x) {
- terminal_render_character (terminal, character, colour, effect, x + offset_x, y + offset_y);
+static procedure terminal_render_rectangle_fill (terminal_structure * terminal, character data, natural colour, natural effect, natural x, natural y, natural width, natural height) {
+ for (natural offset_y = 0; offset_y != height; ++offset_y) {
+ for (natural offset_x = 0; offset_x != width; ++offset_x) {
+ terminal_render_character (terminal, data, colour, effect, x + offset_x, y + offset_y);
}
}
}
-static v0 terminal_render_background (terminal_structure * terminal, c1 character, u4 colour, u4 effect) {
- for (u4 y = 0; y != terminal->screen_height; ++y) {
- for (u4 x = 0; x != terminal->screen_width; ++x) {
- terminal_render_character (terminal, character, colour, effect, x, y);
+static procedure terminal_render_background (terminal_structure * terminal, character data, natural colour, natural effect) {
+ for (natural y = 0; y != terminal->screen_height; ++y) {
+ for (natural x = 0; x != terminal->screen_width; ++x) {
+ terminal_render_character (terminal, data, colour, effect, x, y);
}
}
}
-static v0 terminal_render_format (terminal_structure * terminal, c1 * format, u4 x, u4 y, ...) {
+static procedure terminal_render_format (terminal_structure * terminal, character * format, natural x, natural y, ...) {
va_list list;
- u4 offset_x = 0;
- u4 offset_y = 0;
+ natural offset_x = 0;
+ natural offset_y = 0;
colour_enumeration colour = colour_white;
effect_enumeration effect = effect_normal;
++offset_x;
} break;
case ('i'): {
- c1 * number = number_to_string (va_arg (list, int));
- terminal_render_string (terminal, number, colour, effect, x + offset_x, y + offset_y);
- offset_x += string_length (number);
+ character * data = number_to_string (va_arg (list, int));
+ terminal_render_string (terminal, data, colour, effect, x + offset_x, y + offset_y);
+ offset_x += string_length (data);
} break;
case ('t'): {
- b4 toggle = (b4) va_arg (list, int);
- terminal_render_toggle (terminal, toggle, x + offset_x, y + offset_y);
+ boolean data = (boolean) va_arg (list, int);
+ terminal_render_toggle (terminal, data, x + offset_x, y + offset_y);
offset_x += 3;
} break;
case ('b'): {
- b4 b4ean = (b4) va_arg (list, int);
- terminal_render_string (terminal, (b4ean == true) ? "true" : "false", colour, effect, x + offset_x, y + offset_y);
- offset_x += (b4ean == true) ? 4 : 5;
+ boolean data = (boolean) va_arg (list, int);
+ terminal_render_string (terminal, (data == true) ? "true" : "false", colour, effect, x + offset_x, y + offset_y);
+ offset_x += (data == true) ? 4 : 5;
} break;
case ('c'): {
- c1 character = (char) va_arg (list, int);
- terminal_render_character (terminal, character, colour, effect, x + offset_x, y + offset_y);
+ character data = (character) va_arg (list, int);
+ terminal_render_character (terminal, data, colour, effect, x + offset_x, y + offset_y);
++offset_x;
} break;
case ('s'): {
- c1 * string = va_arg (list, c1 *);
- terminal_render_string (terminal, string, colour, effect, x + offset_x, y + offset_y);
- offset_x += string_length (string);
+ character * data = va_arg (list, character *);
+ terminal_render_string (terminal, data, colour, effect, x + offset_x, y + offset_y);
+ offset_x += string_length (data);
} break;
default: {
terminal_render_character (terminal, '?', colour, effect, x + offset_x, y + offset_y);
} break;
case ('A'): effect = effect_normal; break;
case ('B'): effect = effect_bold; break;
- case ('C'): effect = effect_italic; break;
- case ('D'): effect = effect_undefined_code; break;
+ case ('C'): effect = effect_darken; break;
+ case ('D'): effect = effect_italic; break;
case ('E'): effect = effect_underline; break;
case ('F'): effect = effect_blink; break;
case ('G'): effect = effect_reverse; break;
} special_enumeration;
typedef struct {
- u4 count;
- u4 limit;
- u4 * completed;
- u4 * * requirement;
- u4 * type;
- c1 * * class;
- c1 * * description;
+ natural count;
+ natural limit;
+ natural * completed;
+ natural * * requirement;
+ natural * type;
+ character * * class;
+ character * * description;
} challenge_structure;
-static c1 * special_name [special_count] = {
+static character * special_name [special_count] = {
"strength", "perception", "edurance", "charisma", "intelligence", "agility", "luck"
};
-static b4 challenge_is_repeatable (challenge_structure * challenges, u4 index) {
+static boolean challenge_is_repeatable (challenge_structure * challenges, natural index) {
return ((challenges->type [index] == special_strength + 1) ||
(challenges->type [index] == special_edurance + 1) ||
(challenges->type [index] == special_agility + 1));
}
-static b4 challenge_is_available (challenge_structure * challenges, u4 index) {
+static boolean challenge_is_available (challenge_structure * challenges, natural index) {
return ((challenges->completed [index] == 0) || (challenge_is_repeatable (challenges, index) == true));
}
-static b4 challenge_is_completable (u4 * special, challenge_structure * challenges, u4 index) {
+static boolean challenge_is_completable (natural * special, challenge_structure * challenges, natural index) {
if (challenge_is_available (challenges, index) == false) {
return (false);
}
- for (u4 check = 0; check < special_count; ++check) {
+ for (natural check = 0; check < special_count; ++check) {
if (challenges->requirement [index] [check] > special [check]) {
return (false);
}
return (true);
}
-static v0 render_challenge_list (terminal_structure * terminal, u4 * special, challenge_structure * challenges, u4 x, u4 y) {
- u4 count = 0;
- u4 * array = allocate (challenges->count * sizeof (* array));
+static procedure render_challenge_list (terminal_structure * terminal, natural * special, challenge_structure * challenges, natural x, natural y) {
+ natural count = 0;
+ natural * array = allocate (challenges->count * sizeof (* array));
- for (u4 index = 0; index < challenges->count; ++index) {
+ for (natural index = 0; index < challenges->count; ++index) {
if (challenge_is_completable (special, challenges, index) == true) {
++count;
array [count - 1] = index;
terminal_render_format (terminal, "Count of unlocked challenges: /2/B%i", x, y + 0, count);
terminal_render_format (terminal, "Count of locked challenges: /1/B%i", x, y + 1, challenges->count - count);
- for (u4 index = 0; index < count; ++index) {
+ for (natural index = 0; index < count; ++index) {
terminal_render_character (terminal, '[', colour_grey, effect_bold, x, y + index + 2);
- for (u4 value = 0; value < special_count; ++value) {
+ for (natural value = 0; value < special_count; ++value) {
terminal_render_number (terminal, challenges->requirement [array [index]] [value], value + 1, effect_bold, x + 3 * value + 2, y + index + 2);
}
array = deallocate (array);
}
-static v0 render_special_attributes (terminal_structure * terminal, u4 * special, u4 offset, u4 selection) {
- for (u4 index = 0; index < special_count; ++index) {
- u4 effect = (selection == index) ? effect_bold : effect_normal;
- u4 length = attribute_maximum + 3;
+static procedure render_special_attributes (terminal_structure * terminal, natural * special, natural offset, natural selection) {
+ for (natural index = 0; index < special_count; ++index) {
+ natural effect = (selection == index) ? effect_bold : effect_normal;
+ natural length = attribute_maximum + 3;
- c1 name [32] = "";
+ character name [32] = "";
string_copy_limit (name, special_name [index], sizeof (name));
}
}
-static v0 prompt_special_attributes (u4 * special) {
+static procedure prompt_special_attributes (natural * special) {
terminal_structure * terminal = terminal_initialize ();
- u4 selection = 0;
- b4 show_help = false;
+ natural selection = 0;
+ boolean show_help = false;
- c1 * main_messages [] = {
+ character * main_messages [] = {
"Press H or Tab to toggle help.",
"Press Q or Escape to use default settings.",
"Press S or Enter to save changes.",
"Choose your SPECIAL attributes:"
};
- c1 * help_messages [] = {
+ character * help_messages [] = {
"Show help - H or Tab",
"Use default settings - Q or Escape",
"Save and quit - S or Enter",
"Decrease attribute - N, Left arrow key or KP4"
};
- for (u4 index = 0; index < special_count; ++index) {
+ for (natural index = 0; index < special_count; ++index) {
special [index] = 5;
}
while (terminal->active == true) {
terminal_render_background (terminal, ' ', colour_white, effect_normal);
- for (u4 index = 0; index < array_length (main_messages); ++index) {
+ for (natural index = 0; index < array_length (main_messages); ++index) {
terminal_render_string (terminal, main_messages [index], colour_white, effect_normal, 0, index);
}
render_special_attributes (terminal, special, array_length (main_messages) + 1, selection);
if (show_help == true) {
- for (u4 index = 0; index < array_length (help_messages); ++index) {
- u4 offset = array_length (main_messages) + special_count + 2;
+ for (natural index = 0; index < array_length (help_messages); ++index) {
+ natural offset = array_length (main_messages) + special_count + 2;
terminal_render_string (terminal, help_messages [index], colour_white, effect_normal, 0, index + offset);
}
if ((terminal->signal [signal_tabulator] == true) || (terminal->signal [signal_h] == true)) {
show_help = ! show_help;
} else if ((terminal->signal [signal_escape] == true) || (terminal->signal [signal_q] == true)) {
- for (u4 index = 0; index < special_count; ++index) {
+ for (natural index = 0; index < special_count; ++index) {
special [index] = 5;
} break;
} else if ((terminal->signal [signal_return] == true) || (terminal->signal [signal_s] == true)) {
terminal = terminal_deinitialize (terminal);
}
-static v0 import_user_configuration (u4 * special, u4 challenge_count, u4 * * daily_challenges, b4 * * completition) {
- b4 special_defined [special_count] = { false };
+static procedure import_user_configuration (natural * special, natural challenge_count, natural * * daily_challenges, boolean * * completition) {
+ boolean special_defined [special_count] = { false };
- b4 daily_challenges_defined = false;
- b4 completition_defined = false;
+ boolean daily_challenges_defined = false;
+ boolean completition_defined = false;
- script_information * information = allocate (sizeof (* information));
- script_structure * structure = script_open (configuration_format ("xhallenge.cfg"));
+ script_structure * information = allocate (sizeof (* information));
+ script_data_structure * structure = script_open (configuration_format ("xhallenge.cfg"));
- for (script_word_type word = script_parser (structure); word != script_end; word = script_parser (structure)) {
+ for (script_word_enumeration word = script_parser (structure); word != script_end; word = script_parser (structure)) {
if (word == script_marker) {
if (script_compare (structure, "challenges") == true) {
- u4 check = 0;
+ natural check = 0;
script_failure (structure, daily_challenges_defined == true, "Challenge array was already defined.");
(* daily_challenges) = script_expect_ordered_array (information, structure, & check);
daily_challenges_defined = true;
script_failure (structure, check != challenges_per_day, "Ordered array 'daily_challenges' is incomplete.");
- for (u4 index = 0; index < challenges_per_day; ++index) {
+ for (natural index = 0; index < challenges_per_day; ++index) {
script_failure (structure, (* daily_challenges) [index] >= challenge_count, "Invalid index.");
}
} else if (script_compare (structure, "completition") == true) {
- u4 check = 0;
+ natural check = 0;
script_failure (structure, completition_defined == true, "Completition array was already defined.");
(* completition) = script_expect_ordered_array (information, structure, & check);
completition_defined = true;
script_failure (structure, check != challenges_per_day, "Ordered array 'completition' is incomplete.");
- } else for (u4 index = 0; index < special_count; ++index) {
+ } else for (natural index = 0; index < special_count; ++index) {
if (script_compare (structure, special_name [index]) == true) {
script_failure (structure, special_defined [index] == true, "Attribute was already defined.");
special [index] = script_expect_number (structure);
information = deallocate (information);
}
-static v0 export_user_configuration (u4 * special, u4 * daily_challenges, b4 * completition) {
- c1 buffer [4096] = "";
+static procedure export_user_configuration (natural * special, natural * daily_challenges, boolean * completition) {
+ character buffer [4096] = "";
- for (u4 index = 0; index < special_count; ++index) {
+ for (natural index = 0; index < special_count; ++index) {
string_concatenate (buffer, format ("%s = %i\n", special_name [index], special [index]));
}
string_concatenate (buffer, "challenges = (");
- for (u4 index = 0; index < challenges_per_day; ++index) {
+ for (natural index = 0; index < challenges_per_day; ++index) {
string_concatenate (buffer, number_to_string (daily_challenges [index]));
if (index < challenges_per_day - 1) {
string_concatenate (buffer, ")\n");
string_concatenate (buffer, "completition = (");
- for (u4 index = 0; index < challenges_per_day; ++index) {
+ for (natural index = 0; index < challenges_per_day; ++index) {
string_concatenate (buffer, number_to_string (completition [index]));
if (index < challenges_per_day - 1) {
configuration_export ("xhallenge.cfg", buffer);
}
-static challenge_structure * challenges_initialize (u4 limit) {
+static challenge_structure * challenges_initialize (natural limit) {
challenge_structure * challenges = allocate (sizeof (* challenges));
challenges->limit = limit;
}
static challenge_structure * challenges_deinitialize (challenge_structure * challenges) {
- for (u4 index = 0; index < challenges->count; ++index) {
+ for (natural index = 0; index < challenges->count; ++index) {
challenges->requirement [index] = deallocate (challenges->requirement [index]);
challenges->description [index] = deallocate (challenges->description [index]);
challenges->class [index] = deallocate (challenges->class [index]);
return (deallocate (challenges));
}
-static v0 import_challenges (challenge_structure * challenges) {
- b4 completed_defined = false;
- b4 requirement_defined = false;
- b4 type_defined = false;
- b4 class_defined = false;
- b4 description_defined = false;
+static procedure import_challenges (challenge_structure * challenges) {
+ boolean completed_defined = false;
+ boolean requirement_defined = false;
+ boolean type_defined = false;
+ boolean class_defined = false;
+ boolean description_defined = false;
- script_information * information = allocate (sizeof (* information));
- script_structure * structure = script_open (configuration_format ("xhallenge_list.cfg"));
+ script_structure * information = allocate (sizeof (* information));
+ script_data_structure * structure = script_open (configuration_format ("xhallenge_list.cfg"));
- for (script_word_type word = script_parser (structure); word != script_end; word = script_parser (structure)) {
+ for (script_word_enumeration word = script_parser (structure); word != script_end; word = script_parser (structure)) {
if (word == script_header) {
if (challenges->count > 0) {
script_warning (structure,
class_defined = false;
description_defined = false;
} else if (word == script_marker) {
- u4 current = challenges->count - 1;
+ natural current = challenges->count - 1;
if (script_compare (structure, "completed") == true) {
script_failure (structure, completed_defined == true, "Marker 'completed' already defined.");
challenges->completed [current] = script_expect_number (structure);
completed_defined = true;
} else if (script_compare (structure, "requirement") == true) {
- u4 check = 0;
+ natural check = 0;
script_failure (structure, requirement_defined == true, "Marker 'requirement' already defined.");
challenges->requirement [current] = script_expect_ordered_array (information, structure, & check);
requirement_defined = true;
information = deallocate (information);
}
-static v0 export_challenges (challenge_structure * challenges) {
- s4 file = file_open (configuration_format ("xhallenge_list.cfg"), file_flag_edit | file_flag_truncate);
+static procedure export_challenges (challenge_structure * challenges) {
+ integer file = file_open (configuration_format ("xhallenge_list.cfg"), file_flag_edit | file_flag_truncate);
- for (u4 index = 0; index < challenges->count; ++index) {
+ for (natural index = 0; index < challenges->count; ++index) {
file_echo (file, "[] ");
file_echo (file, format ("completed = %i ", challenges->completed [index]));
file_echo (file, "requirement = (");
- for (u4 subindex = 0; subindex < special_count; ++subindex) {
+ for (natural subindex = 0; subindex < special_count; ++subindex) {
file_echo (file, number_to_string (challenges->requirement [index] [subindex]));
if (subindex < special_count - 1) {
file = file_close (file);
}
-static u4 generate_challenge (u4 * special, challenge_structure * challenges) {
- u4 index = urandomize (0, challenges->count - 1);
- b4 valid = false;
+static natural generate_challenge (natural * special, challenge_structure * challenges) {
+ natural index = random_natural (0, challenges->count - 1);
+ boolean valid = false;
while (valid == false) {
valid = true;
- index = urandomize (0, challenges->count - 1);
+ index = random_natural (0, challenges->count - 1);
if ((challenges->completed [index] > 0) && (challenges->type [index] != 1) && (challenges->type [index] != 3)) continue;
- for (u4 check = 0; check < special_count; ++check) {
+ for (natural check = 0; check < special_count; ++check) {
if (challenges->requirement [index] [check] > special [check]) {
valid = false;
break;
return (index);
}
-static v0 generate_challenges (u4 * special, challenge_structure * challenges, u4 * * daily_challenges, b4 * * completition) {
+static procedure generate_challenges (natural * special, challenge_structure * challenges, natural * * daily_challenges, boolean * * completition) {
(* daily_challenges) = allocate (challenges_per_day * sizeof (* * daily_challenges));
(* completition) = allocate (challenges_per_day * sizeof (* * completition));
- for (u4 index = 0; index < challenges_per_day; ++index) {
+ for (natural index = 0; index < challenges_per_day; ++index) {
(* daily_challenges) [index] = generate_challenge (special, challenges);
}
}
-static v0 render_challenges (u4 * special, challenge_structure * challenges, u4 * daily_challenges, b4 * completition) {
+static procedure render_challenges (natural * special, challenge_structure * challenges, natural * daily_challenges, boolean * completition) {
terminal_structure * terminal = terminal_initialize ();
- u4 selection = 0;
- b4 show_help = false;
- b4 show_list = false;
+ natural selection = 0;
+ boolean show_help = false;
+ boolean show_list = false;
- c1 * main_messages [] = {
+ character * main_messages [] = {
"Press H or Tab to toggle help.",
"Press Q or Escape to quit the program without saving changes.",
"Press S or Enter to save changes and quit the program.",
"Your daily challenges:"
};
- c1 * help_messages [] = {
+ character * help_messages [] = {
"Show help - H or Tab",
"Quit - Q or Escape",
"Save and quit - S or Enter",
while (terminal->active == true) {
terminal_render_background (terminal, ' ', colour_white, effect_normal);
- for (u4 index = 0; index < array_length (main_messages); ++index) {
+ for (natural index = 0; index < array_length (main_messages); ++index) {
terminal_render_string (terminal, main_messages [index], colour_white, effect_normal, 0, index);
}
- for (u4 index = 0; index < challenges_per_day; ++index) {
- u4 type = challenges->type [daily_challenges [index]];
- c1 * class = challenges->class [daily_challenges [index]];
- c1 * description = challenges->description [daily_challenges [index]];
+ for (natural index = 0; index < challenges_per_day; ++index) {
+ natural type = challenges->type [daily_challenges [index]];
+ character * class = challenges->class [daily_challenges [index]];
+ character * description = challenges->description [daily_challenges [index]];
- u4 effect = (selection == index) ? effect_bold : effect_normal;
+ natural effect = (selection == index) ? effect_bold : effect_normal;
- u4 offset = array_length (main_messages) + 2;
+ natural offset = array_length (main_messages) + 2;
- u4 alignment = string_length (class) + 4;
+ natural alignment = string_length (class) + 4;
terminal_render_toggle (terminal, completition [index], 0, index + offset);
}
if (show_help == true) {
- u4 offset = array_length (main_messages) + challenges_per_day + 3;
+ natural offset = array_length (main_messages) + challenges_per_day + 3;
- for (u4 index = 0; index < array_length (help_messages); ++index) {
+ for (natural index = 0; index < array_length (help_messages); ++index) {
terminal_render_string (terminal, help_messages [index], colour_white, effect_normal, 0, index + offset);
}
daily_challenges [selection] = generate_challenge (special, challenges);
completition [selection] = false;
} else if (/*(terminal->signal [signal_backspace] == true) || */(terminal->signal [signal_r] == true)) {
- for (u4 index = 0; index < challenges_per_day; ++index) {
+ for (natural index = 0; index < challenges_per_day; ++index) {
daily_challenges [index] = generate_challenge (special, challenges);
completition [index] = false;
}
terminal = terminal_deinitialize (terminal);
}
-s4 main (s4 argc, c1 * * argv) {
- u4 special [special_count] = { 0 };
+integer main (integer argc, character * * argv) {
+ natural special [special_count] = { 0 };
- u4 * daily_challenges = null;
- b4 * completition = null;
+ natural * daily_challenges = null;
+ boolean * completition = null;
challenge_structure * challenges = challenges_initialize (1024);
- randomize_seed_by_time ();
+ random_integer_seed_by_time ();
if (argc == 2) {
if (string_compare (argv [1], "-r") == true) {
/// for more details, if you dare, it is a lot of text that nobody wants to read...
typedef struct {
- u4 vertex_count;
- u4 index_count;
- u4 vertex_limit;
- u4 index_limit;
- f4 * vertex_array;
- u4 * index_array;
+ natural vertex_count;
+ natural index_count;
+ natural vertex_limit;
+ natural index_limit;
+ real * vertex_array;
+ natural * index_array;
} shape_node;
-static shape_node * shape_allocate (u4 vertex_limit, u4 index_limit) {
+static shape_node * shape_allocate (natural vertex_limit, natural index_limit) {
shape_node * shape = allocate (sizeof (* shape));
shape->vertex_limit = vertex_limit;
return (deallocate (shape));
}
-static v0 shape_add_vertex_unwrap_colour (shape_node * shape, f4 x, f4 y, f4 z, f4 u, f4 v, u4 colour) {
+static procedure shape_add_vertex_unwrap_colour (shape_node * shape, real x, real y, real z, real u, real v, natural colour) {
fatal_failure (shape->vertex_count + 9 > shape->vertex_limit, "shape_add_vertex");
if (shape->vertex_count + 9 > shape->vertex_limit) return;
shape->vertex_count += 9;
}
-static v0 shape_add_index (shape_node * shape, u4 a, u4 b, u4 c) {
+static procedure shape_add_index (shape_node * shape, natural a, natural b, natural c) {
fatal_failure (shape->index_count + 3 > shape->index_limit, "shape_add_index");
if (shape->index_count + 3 > shape->index_limit) return;
shape->index_count += 3;
}
-//~static shape_node * shape_tetrahedron_unwrap (f4 x, f4 y, f4 z, f4 scale) {
-//~static shape_node * shape_tetrahedron_unwrap_colour (f4 x, f4 y, f4 z, f4 scale, u4 colour) {
-static shape_node * shape_tetrahedron_colour (f4 x, f4 y, f4 z, f4 scale, u4 colour) {
+//~static shape_node * shape_tetrahedron_unwrap (real x, real y, real z, real scale) {
+//~static shape_node * shape_tetrahedron_unwrap_colour (real x, real y, real z, real scale, natural colour) {
+static shape_node * shape_tetrahedron_colour (real x, real y, real z, real scale, natural colour) {
shape_node * shape = shape_allocate (4 * 9, 4 * 3);
- f4 vertices [12] = {
+ real vertices [12] = {
x + scale, y + scale, z + scale,
x - scale, y - scale, z + scale,
x - scale, y + scale, z - scale,
x + scale, y - scale, z - scale
};
- for (u4 vertex = 0; vertex < 4; ++vertex) {
- f4 x = vertices [3 * vertex + 0];
- f4 y = vertices [3 * vertex + 1];
- f4 z = vertices [3 * vertex + 2];
- f4 u = (binary_sign (vertex >> 0) + 1.0f) / 2.0f;
- f4 v = (binary_sign (vertex >> 1) + 1.0f) / 2.0f;
+ for (natural vertex = 0; vertex < 4; ++vertex) {
+ real x = vertices [3 * vertex + 0];
+ real y = vertices [3 * vertex + 1];
+ real z = vertices [3 * vertex + 2];
+ real u = (binary_sign (vertex >> 0) + 1.0f) / 2.0f;
+ real v = (binary_sign (vertex >> 1) + 1.0f) / 2.0f;
shape_add_vertex_unwrap_colour (shape, x, y, z, u, v, colour);
}
return (shape);
}
-//~static shape_node * shape_square (vector_3 * origin, f4 scale, u4 colour) {
+//~static shape_node * shape_square (vector_3 * origin, real scale, natural colour) {
//~shape_node * shape = shape_allocate (4, 2 * 3);
//~shape_set_origin (shape, origin);
- //~f4 central = square_root (2.0f) * scale / 2.0f;
+ //~real central = square_root (2.0f) * scale / 2.0f;
//~vector_4 normal_colour = {
//~normal_r (colour),
//~normal_a (colour)
//~};
- //~for (u4 vertex = 0; vertex < 4; ++vertex) {
- //~vector_3 pos4 = {
+ //~for (natural vertex = 0; vertex < 4; ++vertex) {
+ //~vector_3 pointeger = {
//~origin->x + binary_sign (vertex >> 0) * central,
//~origin->y + binary_sign (vertex >> 1) * central,
//~origin->z
//~return (shape);
//~}
-//~static shape_node * shape_cube (vector_3 * origin, f4 scale, u4 colour) {
+//~static shape_node * shape_cube (vector_3 * origin, real scale, natural colour) {
//~shape_node * shape = shape_allocate (8, 12 * 3);
//~shape_set_origin (shape, origin);
- //~f4 central = square_root (3.0f) * scale / 2.0f;
+ //~real central = square_root (3.0f) * scale / 2.0f;
//~vector_4 normal_colour = {
//~normal_r (colour),
//~normal_a (colour)
//~};
- //~for (u4 vertex = 0; vertex < 8; ++vertex) {
- //~vector_3 pos4 = {
+ //~for (natural vertex = 0; vertex < 8; ++vertex) {
+ //~vector_3 pointeger = {
//~origin->x + binary_sign (vertex >> 0) * central,
//~origin->y + binary_sign (vertex >> 1) * central,
//~origin->z + binary_sign (vertex >> 2) * central
register_8, register_9, register_10, register_11, register_12, register_13, register_14, register_15
};
-static s4 empty_count = 0;
-static s4 empty_holes = 1;
-static s4 * empty_array = null;
-static s4 * empty_imbue = null;
-static s4 * empty_store = null;
+static integer empty_count = 0;
+static integer empty_holes = 1;
+static integer * empty_array = null;
+static integer * empty_imbue = null;
+static integer * empty_store = null;
-static s4 text_sector_size = 0;
-static s4 data_sector_size = 0;
+static integer text_sector_size = 0;
+static integer data_sector_size = 0;
-static unsigned c1 * text_sector_byte = null;
-static unsigned c1 * data_sector_byte = null;
+static unsigned character * text_sector_byte = null;
+static unsigned character * data_sector_byte = null;
-static unsigned c1 elf_main_header_byte [elf_main_header_size] = {
+static unsigned character elf_main_header_byte [elf_main_header_size] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static unsigned c1 elf_text_sector_byte [elf_text_sector_size] = {
+static unsigned character elf_text_sector_byte [elf_text_sector_size] = {
0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static unsigned c1 elf_data_sector_byte [elf_data_sector_size] = {
+static unsigned character elf_data_sector_byte [elf_data_sector_size] = {
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static s4 front (s4 data) { return ((data >= register_4) && (data <= register_7)); }
-static s4 lower (s4 data) { return ((data >= register_0) && (data <= register_7)); }
-static s4 upper (s4 data) { return ((data >= register_8) && (data <= register_15)); }
+static integer front (integer data) { return ((data >= register_4) && (data <= register_7)); }
+static integer lower (integer data) { return ((data >= register_0) && (data <= register_7)); }
+static integer upper (integer data) { return ((data >= register_8) && (data <= register_15)); }
-static s4 far (s4 label) { return (label && 1); }
-static s4 near (s4 label) { return (label && 0); }
+static integer far (integer label) { return (label && 1); }
+static integer near (integer label) { return (label && 0); }
-static v0 inset (s4 when, s4 data) {
+static procedure inset (integer when, integer data) {
text_sector_byte [text_sector_size] = (unsigned char) data;
text_sector_size += (unsigned int) when;
}
-static v0 inset_immediate (s4 when, s4 size, s4 data) {
+static procedure inset_immediate (integer when, integer size, integer data) {
inset ((when), (data >> 0) & 0xff);
inset ((when) && (size >= size_16), (data >> 8) & 0xff);
inset ((when) && (size >= size_32), (data >> 16) & 0xff);
inset ((when) && (size >= size_32), (data >> 24) & 0xff);
}
-static v0 inset_memory (s4 when, s4 size, s4 data, s4 base) {
+static procedure inset_memory (integer when, integer size, integer data, integer base) {
empty_array [empty_holes] = text_sector_size;
empty_imbue [empty_holes] = data;
- empty_holes += (int) when;
+ empty_holes += (integer) when;
inset_immediate (when, size, base);
}
-static s4 store_relative (s4 * array) {
- s4 relative = array [1];
+static integer store_relative (integer * array) {
+ integer relative = array [1];
empty_array [empty_holes] = text_sector_size;
empty_imbue [empty_holes] = relative;
return (1);
}
-static s4 store_memory (s4 * array) {
- s4 operation = array [0],
+static integer store_memory (integer * array) {
+ integer operation = array [0],
memory = array [1];
empty_store [memory] = text_sector_size;
return (1);
}
-static s4 store_immediate (s4 * array) {
- s4 index = 0,
+static integer store_immediate (integer * array) {
+ integer index = 0,
operation = array [0],
size = array [1],
amount = array [2];
return (amount + 2);
}
-static v0 short_prefix (s4 size) {
+static procedure short_prefix (integer size) {
inset (size == size_16, 0x66);
}
-static v0 long_prefix (s4 size, s4 to, s4 destination, s4 from, s4 source) {
- s4 to_upper = (to == for_register) && (upper (destination)),
+static procedure long_prefix (integer size, integer to, integer destination, integer from, integer source) {
+ integer to_upper = (to == for_register) && (upper (destination)),
from_upper = (from == for_register) && (upper (source)),
extension = (size == size_64);
inset (extension || to_upper || from_upper, 0x40 + 0x01 * to_upper + 0x04 * from_upper + 0x08 * extension);
}
-static v0 modify_registers (s4 to, s4 destination, s4 from, s4 source) {
- s4 to_register_from_register = ((to == for_register) && (from == for_register));
+static procedure modify_registers (integer to, integer destination, integer from, integer source) {
+ integer to_register_from_register = ((to == for_register) && (from == for_register));
inset (to_register_from_register, 0xc0 + 0x01 * (destination & 0x07) + 0x08 * (source & 0x07));
}
-static v0 modify_memory (s4 operation, s4 to, s4 from) {
- s4 to_register_from_memory = ((to == for_register) && (from == for_memory)),
+static procedure modify_memory (integer operation, integer to, integer from) {
+ integer to_register_from_memory = ((to == for_register) && (from == for_memory)),
to_memory_from_register = ((to == for_memory) && (from == for_register)),
to_memory_from_immediate = ((to == for_memory) && (from == for_immediate));
inset (to_register_from_memory || to_memory_from_register, 0x05 + 0x08 * operation * to_memory_from_immediate);
}
-static s4 build_f8 (s4 * array) {
- s4 operation = array [0],
+static integer build_real_64 (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3],
from = array [4],
source = array [5];
- s4 to_register_from_register = ((to == for_register) && (from == for_register)),
+ integer to_register_from_register = ((to == for_register) && (from == for_register)),
to_register_from_memory = ((to == for_register) && (from == for_memory)),
to_register_from_immediate = ((to == for_register) && (from == for_immediate)),
to_register_from_relative = ((to == for_register) && (from == for_relative)),
return (5);
}
-static s4 build_single (s4 * array) {
- s4 operation = array [0],
+static integer build_single (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3];
- s4 irregularity = ((operation == increment) || (operation == decrement));
+ integer irregularity = ((operation == increment) || (operation == decrement));
short_prefix (size);
return (3);
}
-static s4 build_static_1 (s4 * array) {
- s4 operation = array [0];
+static integer build_static_1 (integer * array) {
+ integer operation = array [0];
- unsigned c1 data [] = {
+ unsigned character data [] = {
0x90, 0xc3, 0xcb, 0xc9, 0x9d, 0x9c
};
return (0);
}
-static s4 build_static_2 (s4 * array) {
- s4 operation = array [0];
+static integer build_static_2 (integer * array) {
+ integer operation = array [0];
- unsigned s2 data [] = {
+ unsigned integer_16 data [] = {
0x050f, 0xa20f, 0xd0d9, 0xe0d9, 0xe1d9, 0xe4d9, 0xe5d9, 0xe8d9,
0xe9d9, 0xead9, 0xebd9, 0xecd9, 0xedd9, 0xeed9, 0xf0d9, 0xf1d9,
- 0xf2d9, 0xf3d9, 0xf4d9, 0xf5d9, 0xf6d9, 0xf7d9, 0xf8d9, 0xf9d9,
+ 0xf2d9, 0xf3d9, 0xreald9, 0xf5d9, 0xf6d9, 0xf7d9, 0xreal_64d9, 0xf9d9,
0xfad9, 0xfbd9, 0xfcd9, 0xfdd9, 0xfed9, 0xffd9
};
return (0);
}
-static s4 build_jump_if (s4 * array) {
- s4 operation = array [0],
+static integer build_jump_if (integer * array) {
+ integer operation = array [0],
size = array [1],
location = array [3];
return (3);
}
-static s4 build_move_if (s4 * array) {
- s4 operation = array [0],
+static integer build_move_if (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3],
return (5);
}
-static s4 build_set_if (s4 * array) {
- s4 operation = array [0],
+static integer build_set_if (integer * array) {
+ integer operation = array [0],
to = array [2],
destination = array [3];
return (3);
}
-static s4 build_jump (s4 * array) {
- s4 operation = array [0],
+static integer build_jump (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3];
return (3);
}
-static s4 build_move (s4 * array) {
- s4 operation = array [0],
+static integer build_move (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3],
return (5 + (size == size_64));
}
-static s4 build_call (s4 * array) {
- s4 operation = array [0],
+static integer build_call (integer * array) {
+ integer operation = array [0],
from = array [1],
source = array [2];
return (2);
}
-static s4 build_enter (s4 * array) {
- s4 operation = array [0],
+static integer build_enter (integer * array) {
+ integer operation = array [0],
dynamic_storage = array [1],
nesting_level = array [2];
return (2);
}
-static s4 build_f4 (s4 * array) {
- s4 operation = array [0],
+static integer build_real (integer * array) {
+ integer operation = array [0],
size = array [1],
from = array [2],
source = array [3];
return (3);
}
-static s4 build_shift (s4 * array) {
- s4 operation = array [0],
+static integer build_shift (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3],
return (5);
}
-static s4 build_in_out (s4 * array) {
- s4 move = array [0],
+static integer build_in_out (integer * array) {
+ integer move = array [0],
size = array [1],
type = array [2],
port = array [3];
return (3);
}
-static s4 build_pop (s4 * array) {
- s4 operation = array [0],
+static integer build_pop (integer * array) {
+ integer operation = array [0],
size = array [1],
to = array [2],
destination = array [3];
return (3);
}
-static s4 build_push (s4 * array) {
- s4 operation = array [0],
+static integer build_push (integer * array) {
+ integer operation = array [0],
size = array [1],
from = array [2],
source = array [3];
return (3);
}
-static s4 build_swap (s4 * array) {
- s4 operation = array [0],
+static integer build_swap (integer * array) {
+ integer operation = array [0],
size = array [1],
destination = array [3];
return (3);
}
-static s4 build_bit_scan (s4 * array) {
- s4 operation = array [0],
+static integer build_bit_scan (integer * array) {
+ integer operation = array [0],
size = array [1],
destination = array [3],
from = array [4],
return (5);
}
-static s4 build_loop (s4 * array) {
- s4 operation = array [0],
+static integer build_loop (integer * array) {
+ integer operation = array [0],
location = array [3];
inset (operation == loop_not_equal, 0xe0);
return (3);
}
-static v0 elf_main_header (v0) {
- s4 enter = empty_store [0] + 0x4000b0;
+static procedure elf_main_header (none) {
+ integer enter = empty_store [0] + 0x4000b0;
elf_main_header_byte [16] = 0x02;
elf_main_header_byte [ 7] = 0x03;
memory_copy (& elf_main_header_byte [24], & enter, sizeof (enter));
}
-static v0 elf_text_sector (unsigned s8 text_size, unsigned s8 data_size) {
- unsigned s8 text = elf_header_size + text_size - data_size;
+static procedure elf_text_sector (unsigned integer_64 text_size, unsigned integer_64 data_size) {
+ unsigned integer_64 text = elf_header_size + text_size - data_size;
- memory_copy (& elf_text_sector_byte [32], & text, (int) sizeof (text));
- memory_copy (& elf_text_sector_byte [40], & text, (int) sizeof (text));
+ memory_copy (& elf_text_sector_byte [32], & text, (integer) sizeof (text));
+ memory_copy (& elf_text_sector_byte [40], & text, (integer) sizeof (text));
}
-static v0 elf_data_sector (unsigned s8 text_size, unsigned s8 data_size) {
- unsigned s8 data = data_size;
- unsigned s8 core = elf_header_size + text_size - data_size;
- unsigned s8 move = 0x401000 + core;
+static procedure elf_data_sector (unsigned integer_64 text_size, unsigned integer_64 data_size) {
+ unsigned integer_64 data = data_size;
+ unsigned integer_64 core = elf_header_size + text_size - data_size;
+ unsigned integer_64 move = 0x401000 + core;
- memory_copy (& elf_data_sector_byte [ 8], & core, (int) sizeof (core));
- memory_copy (& elf_data_sector_byte [16], & move, (int) sizeof (move));
- memory_copy (& elf_data_sector_byte [24], & move, (int) sizeof (move));
- memory_copy (& elf_data_sector_byte [32], & data, (int) sizeof (data));
- memory_copy (& elf_data_sector_byte [40], & data, (int) sizeof (data));
+ memory_copy (& elf_data_sector_byte [ 8], & core, (integer) sizeof (core));
+ memory_copy (& elf_data_sector_byte [16], & move, (integer) sizeof (move));
+ memory_copy (& elf_data_sector_byte [24], & move, (integer) sizeof (move));
+ memory_copy (& elf_data_sector_byte [32], & data, (integer) sizeof (data));
+ memory_copy (& elf_data_sector_byte [40], & data, (integer) sizeof (data));
}
-static s4 (* build_instruction []) (s4 * array) = {
+static integer (* build_instruction []) (integer * array) = {
store_memory, store_relative, store_immediate,
build_double, build_double, build_double, build_double, build_double, build_double, build_double, build_double,
build_single, build_single, build_single, build_single, build_single, build_single, build_single, build_single,
build_swap, build_bit_scan, build_bit_scan, build_loop, build_loop, build_loop
};
-static s4 assemble (s4 count, s4 * array) {
- for (u4 index = 0; index < count; ++index) {
+static integer assemble (integer count, integer * array) {
+ for (natural index = 0; index < count; ++index) {
index += build_instruction [array [index]] (& array [index]);
}
- for (u4 index = 1; index < empty_holes; ++index) {
- s4 set = 0;
- s4 get = empty_array [index];
+ for (natural index = 1; index < empty_holes; ++index) {
+ integer set = 0;
+ integer get = empty_array [index];
- memory_copy ((c1 *) & set, (c1 *) & text_sector_byte [get], (int) sizeof (set));
+ memory_copy ((character *) & set, (character *) & text_sector_byte [get], (integer) sizeof (set));
set += empty_store [empty_imbue [index]];
- memory_copy ((c1 *) & text_sector_byte [get], (c1 *) & set, (int) sizeof (set));
+ memory_copy ((character *) & text_sector_byte [get], (character *) & set, (integer) sizeof (set));
}
return (log_success);
#include <xolatile/xyntax.h>
#include <xolatile/xanguage.h>
-static v0 conditionally_exit (language_structure * language, syntax_structure * syntax, b4 terminate) {
+static procedure conditionally_exit (language_structure * language, syntax_structure * syntax, boolean terminate) {
syntax = syntax_deinitialize (syntax);
language = language_deinitialize (language);
}
}
-static v0 print_common (v0) {
+static procedure print_common (none) {
print ("/B/4xighlight/-: /4Terminal syntax highlighter/-\n\n");
print ("\tAuthor: /4Ognjen 'xolatile' Milan Robovic/-\n");
print ("\tLicense: /4GNU//GPLv3/-\n\n");
}
-static v0 print_help (v0) {
+static procedure print_help (none) {
print_common ();
print ("Example usage:\n\n");
print ("Supported languages:\n\n");
for (language_enumeration index = 0; index < language_count; ++index) {
- c1 align [32] = "";
+ character align [32] = "";
print ("\t/B/4%s/- /4%s/- /0---/- %s syntax highlighting\n",
language_short_option [index],
}
}
-static v0 print_version (v0) {
+static procedure print_version (none) {
print_common ();
print ("\tVersion: /40 (Zero)/-\n");
}
-s4 main (s4 argc, c1 * * argv) {
- u4 select = language_count;
- u4 length = 0;
- c1 * buffer = null;
+integer main (integer argc, character * * argv) {
+ natural select = language_count;
+ natural length = 0;
+ character * buffer = null;
syntax_structure * syntax = syntax_initialize (360);
language_structure * language = language_initialize (false);
- for (s4 argument = 1; argument < argc; ++argument) {
+ for (integer argument = 1; argument < argc; ++argument) {
if (argument_compare (argv [argument], "-h", "--help") == true) {
print_help ();
conditionally_exit (language, syntax, true);
conditionally_exit (language, syntax, true);
}
- for (u4 index = 0; index < language_count; ++index) {
+ for (natural index = 0; index < language_count; ++index) {
if (argument_compare (argv [argument], language_short_option [index], language_long_option [index]) == true) {
(* (language_highlighter [index])) (language, syntax);
select = index;
if (file_exists (argv [argument]) == true) {
if (select == language_count) {
- select = (u4) file_type (argv [argument]);
+ select = (natural) file_type (argv [argument]);
}
if (buffer == null) {
buffer = file_import (argv [argument]);
language_conditionally_select (language, syntax, select);
- for (u4 offset = 0; buffer [offset] != '\0'; offset += length) {
+ for (natural offset = 0; buffer [offset] != '\0'; offset += length) {
select = syntax_select (syntax, & buffer [offset], & length);
if (select >= syntax->count) {
PFNGLBUFFERDATAPROC glBufferData;
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
- b4 signal [signal_count];
- b4 cursor [cursor_count];
- s4 cursor_x;
- s4 cursor_y;
-
- b4 using_precomputed_spritesheet;
- u8 spritesheet_size;
- u8 vertex_limit;
- u8 index_limit;
- u4 gameplay_framerate;
- u4 animation_framerate;
- u4 tab_width;
- u4 default_font;
- b4 active;
- u4 window_width;
- u4 window_height;
- f4 pixel_width;
- f4 pixel_height;
- u4 framerate;
- u8 frame_time;
- u8 frame_begin;
- u8 frame_end;
- u4 global_tick;
- u4 gameplay_tick;
- u4 animation_tick;
- b4 freeze_cursor;
- b4 freeze_signal;
- u4 vertex_object;
- u4 vertex_buffer;
- u4 index_buffer;
- u4 vertex_shader;
- u4 fragment_shader;
- u4 shader_program;
- u4 spritesheet;
- u4 vertex_count;
- u4 index_count;
- f4 * vertex_array;
- u4 * index_array;
- u4 sprite_count;
- u4 font_count;
- u4 * spritesheet_data;
- u4 * * sprite_data;
- u4 * sprite_width;
- u4 * sprite_height;
- f4 * sprite_u;
- f4 * sprite_v;
- u4 * * font_index;
- u4 * * font_width;
- u4 * * font_height;
- c1 * font_begin;
- c1 * font_end;
- f4 projection_matrix [16];
- f4 movement_matrix [16];
- f4 rotation_matrix [16];
- f4 aspect_ratio;
- f4 field_of_view;
- f4 far_plane;
- f4 near_plane;
- f4 camera_x;
- f4 camera_y;
- f4 sensitivity;
+ boolean signal [signal_count];
+ boolean cursor [cursor_count];
+ integer cursor_x;
+ integer cursor_y;
+
+ boolean using_precomputed_spritesheet;
+ caliber spritesheet_size;
+ caliber vertex_limit;
+ caliber index_limit;
+ natural gameplay_framerate;
+ natural animation_framerate;
+ natural tab_width;
+ natural default_font;
+ boolean active;
+ natural window_width;
+ natural window_height;
+ real pixel_width;
+ real pixel_height;
+ natural framerate;
+ natural_64 frame_time;
+ natural_64 frame_begin;
+ natural_64 frame_end;
+ natural global_tick;
+ natural gameplay_tick;
+ natural animation_tick;
+ boolean freeze_cursor;
+ boolean freeze_signal;
+ natural vertex_object;
+ natural vertex_buffer;
+ natural index_buffer;
+ natural vertex_shader;
+ natural fragment_shader;
+ natural shader_program;
+ natural spritesheet;
+ natural vertex_count;
+ natural index_count;
+ real * vertex_array;
+ natural * index_array;
+ natural sprite_count;
+ natural font_count;
+ natural * spritesheet_data;
+ natural * * sprite_data;
+ natural * sprite_width;
+ natural * sprite_height;
+ real * sprite_u;
+ real * sprite_v;
+ natural * * font_index;
+ natural * * font_width;
+ natural * * font_height;
+ character * font_begin;
+ character * font_end;
+ real projection_matrix [16];
+ real movement_matrix [16];
+ real rotation_matrix [16];
+ real aspect_ratio;
+ real field_of_view;
+ real far_plane;
+ real near_plane;
+ real camera_x;
+ real camera_y;
+ real sensitivity;
} vision_structure;
-static u4 vision_sprite_raw_import (vision_structure * vision, u4 * data, u4 width, u4 height) {
+static natural vision_sprite_raw_import (vision_structure * vision, natural * data, natural width, natural height) {
fatal_failure (vision->active == true, "vision_sprite_raw_import: OpenGL renderer is already initialized.");
fatal_failure (data == null, "vision_sprite_raw_import: Data is null pointer.");
fatal_failure (width == 0, "vision_sprite_raw_import: Font image width is zero.");
return (vision->sprite_count - 1);
}
-static u4 vision_font_raw_import (vision_structure * vision, u4 * data, u4 image_width, c1 begin, c1 end, u4 empty) {
- u4 pointer = 0;
- u4 width = 0;
- u4 height = 0;
+static natural vision_font_raw_import (vision_structure * vision, natural * data, natural image_width, character begin, character end, natural empty) {
+ natural pointer = 0;
+ natural width = 0;
+ natural height = 0;
fatal_failure (vision->active == true, "vision_font_raw_import: OpenGL renderer is already initialized.");
fatal_failure (data == null, "vision_font_raw_import: Data is null pointer.");
vision->font_begin [vision->font_count - 1] = begin;
vision->font_end [vision->font_count - 1] = end;
- vision->font_index [vision->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * vision->font_index));
- vision->font_width [vision->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * vision->font_width));
- vision->font_height [vision->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * vision->font_height));
+ vision->font_index [vision->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * vision->font_index));
+ vision->font_width [vision->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * vision->font_width));
+ vision->font_height [vision->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * vision->font_height));
- for (c1 index = begin; index <= end; ++index) {
+ for (character index = begin; index <= end; ++index) {
for ( ; data [pointer] == empty; ++pointer);
for (width = 0; data [pointer + width] != empty; ++width);
for (height = 0; data [pointer + height * image_width] != empty; ++height);
- u4 * buffer = allocate (width * height * sizeof (* buffer));
+ natural * buffer = allocate (width * height * sizeof (* buffer));
- for (u4 y = 0; y < height; ++y) {
- for (u4 x = 0; x < width; ++x) {
+ for (natural y = 0; y < height; ++y) {
+ for (natural x = 0; x < width; ++x) {
buffer [y * width + x] = data [pointer + (y * image_width) + x];
}
}
return (vision->font_count - 1);
}
-static u4 vision_sprite_import (vision_structure * vision, c1 * path) {
- u4 width = 0;
- u4 height = 0;
- u4 * data = null;
+static natural vision_sprite_import (vision_structure * vision, character * path) {
+ natural width = 0;
+ natural height = 0;
+ natural * data = null;
data = format_image_import (path, & width, & height);
return (vision_sprite_raw_import (vision, data, width, height));
}
-static u4 vision_font_import (vision_structure * vision, c1 * path, c1 begin, c1 end, u4 colour) {
- u4 width = 0;
- u4 height = 0;
- u4 result = 0;
- u4 * data = null;
+static natural vision_font_import (vision_structure * vision, character * path, character begin, character end, natural colour) {
+ natural width = 0;
+ natural height = 0;
+ natural result = 0;
+ natural * data = null;
data = format_image_import (path, & width, & height);
return (result);
}
-static u4 vision_sprite_width (vision_structure * vision, u4 sprite) {
+static natural vision_sprite_width (vision_structure * vision, natural sprite) {
return (vision->sprite_width [sprite]);
}
-static u4 vision_sprite_height (vision_structure * vision, u4 sprite) {
+static natural vision_sprite_height (vision_structure * vision, natural sprite) {
return (vision->sprite_height [sprite]);
}
-static u4 vision_center_x (vision_structure * vision, u4 size) {
+static natural vision_center_x (vision_structure * vision, natural size) {
return ((vision->window_width - size) / 2);
}
-static u4 vision_center_y (vision_structure * vision, u4 size) {
+static natural vision_center_y (vision_structure * vision, natural size) {
return ((vision->window_height - size) / 2);
}
-static b4 vision_cursor_inside (vision_structure * vision, s4 x, s4 y, u4 width, u4 height) {
+static boolean vision_cursor_inside (vision_structure * vision, integer x, integer y, natural width, natural height) {
return ((vision->cursor_x > x) &&
(vision->cursor_y > y) &&
- (vision->cursor_x < x + (int) width) &&
- (vision->cursor_y < y + (int) height));
+ (vision->cursor_x < x + (integer) width) &&
+ (vision->cursor_y < y + (integer) height));
}
-static b4 vision_cursor_left_click (vision_structure * vision, s4 x, s4 y, u4 width, u4 height) {
+static boolean vision_cursor_left_click (vision_structure * vision, integer x, integer y, natural width, natural height) {
if (vision->cursor [cursor_left] == true) {
vision->freeze_cursor = true;
return (false);
}
-static b4 vision_cursor_right_click (vision_structure * vision, s4 x, s4 y, u4 width, u4 height) {
+static boolean vision_cursor_right_click (vision_structure * vision, integer x, integer y, natural width, natural height) {
if (vision->cursor [cursor_right]) {
vision->freeze_cursor = true;
return (false);
}
-static v0 vision_import_spritesheet (vision_structure * vision, c1 * data_file) {
- s4 file = file_open (data_file, file_flag_read);
+static procedure vision_import_spritesheet (vision_structure * vision, character * data_file) {
+ integer file = file_open (data_file, file_flag_read);
fatal_failure (vision->active == true, "vision_import_spritesheet: OpenGL renderer is already initialized.");
file_read (file, vision->font_begin, vision->font_count * sizeof (* vision->font_begin));
file_read (file, vision->font_end, vision->font_count * sizeof (* vision->font_end));
- for (u4 index = 0; index < vision->font_count; ++index) {
- u4 range = (u4) (vision->font_end [index] - vision->font_begin [index]) + 1;
+ for (natural index = 0; index < vision->font_count; ++index) {
+ natural range = (natural) (vision->font_end [index] - vision->font_begin [index]) + 1;
vision->font_index [index] = allocate (range * sizeof (* * vision->font_index));
vision->font_width [index] = allocate (range * sizeof (* * vision->font_width));
vision->font_height [index] = allocate (range * sizeof (* * vision->font_height));
- for (u4 subindex = 0; subindex < range; ++subindex) {
+ for (natural subindex = 0; subindex < range; ++subindex) {
file_read (file, & vision->font_index [index] [subindex], sizeof (* * vision->font_index));
file_read (file, & vision->font_width [index] [subindex], sizeof (* * vision->font_width));
file_read (file, & vision->font_height [index] [subindex], sizeof (* * vision->font_height));
vision->font_count = 0;
}
-static v0 vision_export_spritesheet (vision_structure * vision, c1 * data_file) {
- s4 file = file_open (data_file, file_flag_write | file_flag_create | file_flag_truncate);
+static procedure vision_export_spritesheet (vision_structure * vision, character * data_file) {
+ integer file = file_open (data_file, file_flag_write | file_flag_create | file_flag_truncate);
fatal_failure (vision->spritesheet_data == null, "vision_export_spritesheet: OpenGL renderer can't access spritesheet data.");
file_write (file, vision->font_begin, vision->font_count * sizeof (* vision->font_begin));
file_write (file, vision->font_end, vision->font_count * sizeof (* vision->font_end));
- for (u4 index = 0; index < vision->font_count; ++index) {
- for (u4 subindex = 0; subindex < (u4) (vision->font_end [index] - vision->font_begin [index]) + 1; ++subindex) {
+ for (natural index = 0; index < vision->font_count; ++index) {
+ for (natural subindex = 0; subindex < (natural) (vision->font_end [index] - vision->font_begin [index]) + 1; ++subindex) {
file_write (file, & vision->font_index [index] [subindex], sizeof (* * vision->font_index));
file_write (file, & vision->font_width [index] [subindex], sizeof (* * vision->font_width));
file_write (file, & vision->font_height [index] [subindex], sizeof (* * vision->font_height));
print ("/c Exported internal binary data of OpenGL spritesheet.");
}
-static vision_structure * vision_initialize (u4 gameplay_framerate, u4 animation_framerate, b4 use_precomputed_spritesheet,
- u4 vertex_limit, u4 index_limit, u4 spritesheet_side) {
+static vision_structure * vision_initialize (natural gameplay_framerate, natural animation_framerate, boolean use_precomputed_spritesheet,
+ natural vertex_limit, natural index_limit, natural spritesheet_side) {
vision_structure * vision = allocate (sizeof (* vision));
vision->using_precomputed_spritesheet = use_precomputed_spritesheet;
vision_import_spritesheet (vision, "binary/spritesheet.bin");
}
- print ("[/2Success/-] Initialized OpenGL renderer.\n");
+ print ("/s Initialized OpenGL renderer.\n");
return (vision);
}
static vision_structure * vision_deinitialize (vision_structure * vision) {
vision->active = false;
- for (u4 index = 0; index < vision->font_count; ++index) {
+ for (natural index = 0; index < vision->font_count; ++index) {
vision->font_index [index] = deallocate (vision->font_index [index]);
vision->font_width [index] = deallocate (vision->font_width [index]);
vision->font_height [index] = deallocate (vision->font_height [index]);
glfwTerminate ();
- print ("[/2Success/-] Deinitialized OpenGL renderer.\n");
+ print ("/s Deinitialized OpenGL renderer.\n");
return (deallocate (vision));
}
-static v0 vision_configure (vision_structure * vision, u4 window_width, u4 window_height, c1 * window_title) {
- u8 font_bitmap [190] = {
+static procedure vision_configure (vision_structure * vision, natural window_width, natural window_height, character * window_title) {
+ natural_64 font_bitmap [190] = {
0x0000000000000000, 0x0000000000000000, 0x0000101010101010, 0x1000101000000000, 0x0024242400000000, 0x0000000000000000,
0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927c10100000, 0x0000649468081010, 0x202c524c00000000,
0x000018242418304a, 0x4444443a00000000, 0x0010101000000000, 0x0000000000000000, 0x0000081020202020, 0x2020100800000000,
0x0000300808080408, 0x0808083000000000, 0x000000000062928c, 0x0000000000000000
};
- c1 * vertex_shader =
+ character * vertex_shader =
"#version 330 core\n"
"in vec3 vertex_xyz;\n"
"in vec2 vertex_uv;\n"
"uniform mat4 projection_matrix;\n"
"uniform mat4 movement_matrix;\n"
"uniform mat4 rotation_matrix;\n"
- "v0 main () {\n"
+ "procedure main () {\n"
" gl_Position = movement_matrix * rotation_matrix * projection_matrix * vec4 (vertex_xyz, 1.0);\n"
" fragment_uv = vertex_uv;\n"
" fragment_rgba = vertex_rgba;\n"
"}\n";
- c1 * fragment_shader =
+ character * fragment_shader =
"#version 330 core\n"
"uniform sampler2D texture_p;\n"
"in vec2 fragment_uv;\n"
"in vec4 fragment_rgba;\n"
"out vec4 data;\n"
- "v0 main () {\n"
+ "procedure main () {\n"
" data = texture (texture_p, fragment_uv) * fragment_rgba;\n"
"}\n";
- u4 * dumb_buffer = null;
- u4 * order = null;
+ natural * dumb_buffer = null;
+ natural * order = null;
- u4 xyz_attribute = 0;
- u4 uv_attribute = 0;
- u4 rgba_attribute = 0;
+ natural xyz_attribute = 0;
+ natural uv_attribute = 0;
+ natural rgba_attribute = 0;
- u4 u = 0;
- u4 v = 0;
+ natural u = 0;
+ natural v = 0;
if (vision->using_precomputed_spritesheet == true) {
- for (u4 index = 0; index < 95; ++index) {
+ for (natural index = 0; index < 95; ++index) {
vision->font_index [vision->font_count] [index] = ++vision->sprite_count - 1;
}
dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
- for (u4 index = 0; index < 256; ++index) {
+ for (natural index = 0; index < 256; ++index) {
dumb_buffer [index] = 0xffffffff;
}
++vision->font_count;
- u4 current = vision->font_count - 1;
+ natural current = vision->font_count - 1;
vision->font_index = reallocate (vision->font_index, vision->font_count * sizeof (* vision->font_index));
vision->font_width = reallocate (vision->font_width, vision->font_count * sizeof (* vision->font_width));
vision->font_width [vision->font_count - 1] = allocate (95 * sizeof (* * vision->font_width));
vision->font_height [vision->font_count - 1] = allocate (95 * sizeof (* * vision->font_height));
- for (u4 index = 0; index < 95; ++index) {
- u4 * buffer = allocate (vision_font_width * vision_font_height * sizeof (* buffer));
+ for (natural index = 0; index < 95; ++index) {
+ natural * buffer = allocate (vision_font_width * vision_font_height * sizeof (* buffer));
- for (u4 value = 0; value < 2; ++value) {
- for (u4 bit = 64; bit > 0; --bit) {
- u4 destination = ((value << 3) - ((bit - 1) >> 3) + 7) * vision_font_width - ((bit - 1) & 7) + 7;
- u4 source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
+ for (natural value = 0; value < 2; ++value) {
+ for (natural bit = 64; bit > 0; --bit) {
+ natural destination = ((value << 3) - ((bit - 1) >> 3) + 7) * vision_font_width - ((bit - 1) & 7) + 7;
+ natural source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
buffer [destination] = (source) ? 0xffffffff : 0x00000000;
}
order = allocate (vision->sprite_count * sizeof (* order));
- for (u4 index = 0; index < vision->sprite_count; ++index) {
+ for (natural index = 0; index < vision->sprite_count; ++index) {
order [index] = index;
}
- for (u4 index = 0; index < vision->sprite_count; ++index) {
- for (u4 subindex = 0; subindex < vision->sprite_count; ++subindex) {
+ for (natural index = 0; index < vision->sprite_count; ++index) {
+ for (natural subindex = 0; subindex < vision->sprite_count; ++subindex) {
if (vision->sprite_height [order [index]] < vision->sprite_height [order [subindex]]) {
- u4 temporary = order [index];
+ natural temporary = order [index];
order [index] = order [subindex];
order [subindex] = temporary;
}
}
- for (u4 index = 0; index < vision->sprite_count; ++index) {
+ for (natural index = 0; index < vision->sprite_count; ++index) {
if (u + vision->sprite_width [order [index]] >= vision->spritesheet_size) {
u *= 0;
v += vision->sprite_height [order [index]];
}
- vision->sprite_u [order [index]] = (float) u / (float) vision->spritesheet_size;
- vision->sprite_v [order [index]] = (float) v / (float) vision->spritesheet_size;
+ vision->sprite_u [order [index]] = (real) u / (real) vision->spritesheet_size;
+ vision->sprite_v [order [index]] = (real) v / (real) vision->spritesheet_size;
- for (u4 y = 0; y < vision->sprite_height [order [index]]; ++y) {
- for (u4 x = 0; x < vision->sprite_width [order [index]]; ++x) {
- u4 destination = (v + y) * vision->spritesheet_size + (u + x);
- u4 source = y * vision->sprite_width [order [index]] + x;
+ for (natural y = 0; y < vision->sprite_height [order [index]]; ++y) {
+ for (natural x = 0; x < vision->sprite_width [order [index]]; ++x) {
+ natural destination = (v + y) * vision->spritesheet_size + (u + x);
+ natural source = y * vision->sprite_width [order [index]] + x;
vision->spritesheet_data [destination] = vision->sprite_data [order [index]] [source];
}
vision->window_width = window_width;
vision->window_height = window_height;
- vision->aspect_ratio = (float) window_height / (float) window_width;
+ vision->aspect_ratio = (real) window_height / (real) window_width;
- vision->pixel_width = 2.0f / (float) window_width;
- vision->pixel_height = 2.0f / (float) window_height;
+ vision->pixel_width = 2.0f / (real) window_width;
+ vision->pixel_height = 2.0f / (real) window_height;
glfwInit ();
- glfwWindowHs4 (GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHs4 (GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHs4 (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHs4 (GLFW_OPENGL_FORWARD_COMPAT, 1);
+ glfwWindowHinteger (GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHinteger (GLFW_CONTEXT_VERSION_MINOR, 3);
+ glfwWindowHinteger (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHinteger (GLFW_OPENGL_FORWARD_COMPAT, 1);
- vision->window = glfwCreateWindow ((int) window_width, (int) window_height, window_title, null, null);
+ vision->window = glfwCreateWindow ((integer) window_width, (integer) window_height, window_title, null, null);
fatal_failure (vision->window == null, "Failed to create GLFW window.\n");
vision->glBufferData = (PFNGLBUFFERDATAPROC) glfwGetProcAddress ("glBufferData");
vision->glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) glfwGetProcAddress ("glUniformMatrix4fv");
- glViewport (0, 0, (int) window_width, (int) window_height);
+ glViewport (0, 0, (integer) window_width, (integer) window_height);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc (GL_LESS);
vision->glLinkProgram (vision->shader_program);
vision->glUseProgram (vision->shader_program);
- xyz_attribute = (u4) vision->glGetAttribLocation (vision->shader_program, "vertex_xyz");
+ xyz_attribute = (natural) vision->glGetAttribLocation (vision->shader_program, "vertex_xyz");
vision->glEnableVertexAttribArray (xyz_attribute);
- vision->glVertexAttribPointer (xyz_attribute, 3, GL_FLOAT, GL_FALSE, 9 * sizeof (float), (v0 *) 0);
+ vision->glVertexAttribPointer (xyz_attribute, 3, GL_FLOAT, GL_FALSE, 9 * sizeof (real), (procedure *) 0);
- uv_attribute = (u4) vision->glGetAttribLocation (vision->shader_program, "vertex_uv");
+ uv_attribute = (natural) vision->glGetAttribLocation (vision->shader_program, "vertex_uv");
vision->glEnableVertexAttribArray (uv_attribute);
- vision->glVertexAttribPointer (uv_attribute, 2, GL_FLOAT, GL_FALSE, 9 * sizeof (float), (v0 *) (3 * sizeof (float)));
+ vision->glVertexAttribPointer (uv_attribute, 2, GL_FLOAT, GL_FALSE, 9 * sizeof (real), (procedure *) (3 * sizeof (real)));
- rgba_attribute = (u4) vision->glGetAttribLocation (vision->shader_program, "vertex_rgba");
+ rgba_attribute = (natural) vision->glGetAttribLocation (vision->shader_program, "vertex_rgba");
vision->glEnableVertexAttribArray (rgba_attribute);
- vision->glVertexAttribPointer (rgba_attribute, 4, GL_FLOAT, GL_FALSE, 9 * sizeof (float), (v0 *) (5 * sizeof (float)));
+ vision->glVertexAttribPointer (rgba_attribute, 4, GL_FLOAT, GL_FALSE, 9 * sizeof (real), (procedure *) (5 * sizeof (real)));
vision->vertex_array = allocate (vision->vertex_limit * sizeof (vision->vertex_array));
vision->index_array = allocate (vision->index_limit * sizeof (vision->index_array));
- for (u4 index = 0; index < 16; ++index) {
+ for (natural index = 0; index < 16; ++index) {
vision->projection_matrix [index] = 0.0f;
vision->movement_matrix [index] = 0.0f;
vision->rotation_matrix [index] = 0.0f;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- print ("[/2Success/-] Configured OpenGL renderer.\n");
+ print ("/s Configured OpenGL renderer.\n");
}
-static v0 vision_synchronize (vision_structure * vision, u4 colour) {
- s4 signal_code [signal_count] = {
+static procedure vision_synchronize (vision_structure * vision, natural colour) {
+ integer signal_code [signal_count] = {
0,
GLFW_KEY_A, GLFW_KEY_B, GLFW_KEY_C, GLFW_KEY_D,
GLFW_KEY_E, GLFW_KEY_F, GLFW_KEY_G, GLFW_KEY_H,
GLFW_KEY_KP_6, GLFW_KEY_KP_7, GLFW_KEY_KP_8, GLFW_KEY_KP_9
};
- s4 new_window_width = 0;
- s4 new_window_height = 0;
+ integer new_window_width = 0;
+ integer new_window_height = 0;
glClearColor (normal_r (colour), normal_g (colour), normal_b (colour), normal_a (colour));
glfwGetWindowSize (vision->window, & new_window_width, & new_window_height);
- if ((vision->window_width != (u4) new_window_width) || (vision->window_height != (u4) new_window_height)) {
+ if ((vision->window_width != (natural) new_window_width) || (vision->window_height != (natural) new_window_height)) {
if ((new_window_width <= 0) || (new_window_height <= 0)) return;
glViewport (0, 0, new_window_width, new_window_height);
- vision->window_width = (u4) new_window_width;
- vision->window_height = (u4) new_window_height;
+ vision->window_width = (natural) new_window_width;
+ vision->window_height = (natural) new_window_height;
- vision->pixel_width = 2.0f / (float) new_window_width;
- vision->pixel_height = 2.0f / (float) new_window_height;
+ vision->pixel_width = 2.0f / (real) new_window_width;
+ vision->pixel_height = 2.0f / (real) new_window_height;
}
- vision->cursor [cursor_left] = (b4) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
- vision->cursor [cursor_middle] = (b4) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
- vision->cursor [cursor_right] = (b4) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
+ vision->cursor [cursor_left] = (boolean) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
+ vision->cursor [cursor_middle] = (boolean) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
+ vision->cursor [cursor_right] = (boolean) (glfwGetMouseButton (vision->window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
glfwSetCursorPos (vision->window, (double) vision->window_width / 2.0, (double) vision->window_height / 2.0);
if (vision->freeze_cursor == false) {
- f8 x = 0.0;
- f8 y = 0.0;
+ real_64 x = 0.0;
+ real_64 y = 0.0;
glfwGetCursorPos (vision->window, & x, & y);
- vision->cursor_x = (int) x;
- vision->cursor_y = (int) y;
+ vision->cursor_x = (integer) x;
+ vision->cursor_y = (integer) y;
- //~f4 offset_x = vision->camera_x - x;
+ //~real offset_x = vision->camera_x - x;
- //~for (u4 index = 0; index < 16; ++index) {
+ //~for (natural index = 0; index < 16; ++index) {
//~vision->rotation_matrix [index] = 0.0f;
//~}
}
if (vision->freeze_signal == false) {
- for (u4 index = 0; index < signal_count; ++index) {
- vision->signal [index] = (b4) (glfwGetKey (vision->window, signal_code [index]) == GLFW_PRESS);
+ for (natural index = 0; index < signal_count; ++index) {
+ vision->signal [index] = (boolean) (glfwGetKey (vision->window, signal_code [index]) == GLFW_PRESS);
}
}
vision->glBindBuffer (GL_ARRAY_BUFFER, vision->vertex_buffer);
- glDrawElements (GL_TRIANGLES, (int) vision->index_count * 4, GL_UNSIGNED_INT, null);
+ glDrawElements (GL_TRIANGLES, (integer) vision->index_count * 4, GL_UNSIGNED_INT, null);
glfwSwapBuffers (vision->window);
}
if (vision->global_tick % vision->gameplay_framerate == 0) {
- vision->framerate = (u4) (1000000000ul / vision->frame_time);
+ vision->framerate = (natural) (1000000000ul / vision->frame_time);
}
++vision->global_tick;
vision->frame_begin = nano_time ();
}
-static v0 vision_render_base (vision_structure * vision, u4 vertex_count, f4 * vertex_array, u4 index_count,
- u4 * index_array, u4 sprite, u4 colour) {
+static procedure vision_render_base (vision_structure * vision, natural vertex_count, real * vertex_array, natural index_count,
+ natural * index_array, natural sprite, natural colour) {
if (sprite >= vision->sprite_count) return;
if (vision->vertex_count + vertex_count >= vision->vertex_limit) return;
if (vision->index_count + index_count >= vision->index_limit) return;
- f4 unwrap_x = (float) vision->sprite_u [sprite] / (float) vision->spritesheet_size;
- f4 unwrap_y = (float) vision->sprite_v [sprite] / (float) vision->spritesheet_size;
+ real unwrap_x = (real) vision->sprite_u [sprite] / (real) vision->spritesheet_size;
+ real unwrap_y = (real) vision->sprite_v [sprite] / (real) vision->spritesheet_size;
- f4 unwrap_width = (float) vision->sprite_width [sprite] / (float) vision->spritesheet_size;
- f4 unwrap_height = (float) vision->sprite_height [sprite] / (float) vision->spritesheet_size;
+ real unwrap_width = (real) vision->sprite_width [sprite] / (real) vision->spritesheet_size;
+ real unwrap_height = (real) vision->sprite_height [sprite] / (real) vision->spritesheet_size;
- //~for (u4 vertex = 0; vertex < vertex_count; ++vertex) {
- //~u4 destination = 9 * vertex + vision->vertex_count;
- //~u4 source = 5 * vertex;
+ //~for (natural vertex = 0; vertex < vertex_count; ++vertex) {
+ //~natural destination = 9 * vertex + vision->vertex_count;
+ //~natural source = 5 * vertex;
//~vision->vertex_array [destination + 0] = vertex_array [source + 0];
//~vision->vertex_array [destination + 1] = vertex_array [source + 1];
//~vision->vertex_array [destination + 8] = normal_a (colour);
//~}
- for (u4 vertex = 0; vertex < vertex_count; ++vertex) {
+ for (natural vertex = 0; vertex < vertex_count; ++vertex) {
vision->vertex_array [vision->vertex_count + vertex] = vertex_array [vertex];
}
//~vision->vertex_array [destination + 3] = vertex_array [source + 3] * unwrap_width + unwrap_x;
//~vision->vertex_array [destination + 4] = vertex_array [source + 4] * unwrap_height + unwrap_y;
- for (u4 index = 0; index < index_count; ++index) {
+ for (natural index = 0; index < index_count; ++index) {
vision->index_array [vision->index_count + index] = index_array [index];
}
vision->index_count += index_count;
}
-//~static v0 vision_render_triangle (vision_structure * vision, f4 * vertex_array, u4 colour) {
+//~static procedure vision_render_triangle (vision_structure * vision, real * vertex_array, natural colour) {
//~if (vision->vertex_count + 3 * 36 >= vision->vertex_limit) return;
//~if (vision->index_count + 3 >= vision->index_limit) return;
- //~for (u4 vertex = 0; vertex < 3; ++vertex) {
- //~u4 destination = 9 * vertex + vision->vertex_count;
- //~u4 source = 5 * vertex;
+ //~for (natural vertex = 0; vertex < 3; ++vertex) {
+ //~natural destination = 9 * vertex + vision->vertex_count;
+ //~natural source = 5 * vertex;
//~vision->vertex_array [destination + 0] = vertex_array [source + 0];
//~vision->vertex_array [destination + 1] = vertex_array [source + 1];
//~vision->vertex_array [destination + 8] = normal_a (colour);
//~}
- //~for (u4 index = 0; index < 3; ++index) {
+ //~for (natural index = 0; index < 3; ++index) {
//~vision->index_array [vision->index_count + index] = vision->vertex_array [vision->vertex_count / 9 + index];
//~}
//~vision->index_count += 3;
//~}
-static v0 vision_change_field_of_view (vision_structure * vision, f4 change) {
+static procedure vision_change_field_of_view (vision_structure * vision, real change) {
vision->field_of_view += change;
vision->projection_matrix [ 0] = vision->aspect_ratio / tangent (vision->field_of_view / 2.0f);
vision->projection_matrix);
}
-static v0 vision_change_translation (vision_structure * vision, f4 x, f4 y, f4 z) {
+static procedure vision_change_translation (vision_structure * vision, real x, real y, real z) {
vision->movement_matrix [ 3] += x;
vision->movement_matrix [ 7] += y;
vision->movement_matrix [11] += z;
vision->movement_matrix);
}
-static v0 vision_change_rotation (vision_structure * vision, f4 vertical, f4 horizontal) {
- for (u4 index = 0; index < 16; ++index) {
+static procedure vision_change_rotation (vision_structure * vision, real vertical, real horizontal) {
+ for (natural index = 0; index < 16; ++index) {
vision->rotation_matrix [index] = 0.0f;
}
#include <xolatile/xormat/png.h>
#include <xolatile/xpengl.h>
-s4 main (v0) {
+integer main (none) {
opengl_structure * opengl = opengl_initialize (60, 60, false, 1024, 1024);
- s4 x = 0;
- s4 y = 0;
+ integer x = 0;
+ integer y = 0;
//~opengl_sprite_import (opengl, "");
xcb_gcontext_t context;
xcb_pixmap_t pixmap;
- b4 signal [signal_count];
- b4 cursor [cursor_count];
-
- b4 active;
- u4 window_width;
- u4 window_height;
- u4 framerate;
- u8 frame_time;
- u8 frame_begin;
- u8 frame_end;
- u4 * framebuffer;
- u4 global_tick;
- u4 gameplay_tick;
- u4 animation_tick;
- s4 cursor_x;
- s4 cursor_y;
- b4 freeze_cursor;
- b4 freeze_signal;
- u4 sprite_count;
- u4 font_count;
- u4 dummy; /// TODO USE ME PLEASE
- u4 * * sprite_data;
- u4 * sprite_width;
- u4 * sprite_height;
- u4 * * font_index;
- u4 * * font_width;
- u4 * * font_height;
- c1 * font_begin;
- c1 * font_end;
+ boolean signal [signal_count];
+ boolean cursor [cursor_count];
+
+ boolean active;
+ natural window_width;
+ natural window_height;
+ natural framerate;
+ natural_64 frame_time;
+ natural_64 frame_begin;
+ natural_64 frame_end;
+ natural * framebuffer;
+ natural global_tick;
+ natural gameplay_tick;
+ natural animation_tick;
+ integer cursor_x;
+ integer cursor_y;
+ boolean freeze_cursor;
+ boolean freeze_signal;
+ natural sprite_count;
+ natural font_count;
+ natural dummy; /// TODO USE ME PLEASE
+ natural * * sprite_data;
+ natural * sprite_width;
+ natural * sprite_height;
+ natural * * font_index;
+ natural * * font_width;
+ natural * * font_height;
+ character * font_begin;
+ character * font_end;
} common_structure;
-static u4 common_center_x (common_structure * common, u4 size) {
+static natural common_center_x (common_structure * common, natural size) {
return ((common->window_width - size) / 2);
}
-static u4 common_center_y (common_structure * common, u4 size) {
+static natural common_center_y (common_structure * common, natural size) {
return ((common->window_height - size) / 2);
}
-static b4 common_cursor_inside (common_structure * common, s4 x, s4 y, u4 width, u4 height) {
+static boolean common_cursor_inside (common_structure * common, integer x, integer y, natural width, natural height) {
return ((common->cursor_x > x)
&& (common->cursor_y > y)
- && (common->cursor_x < x + (int) width)
- && (common->cursor_y < y + (int) height));
+ && (common->cursor_x < x + (integer) width)
+ && (common->cursor_y < y + (integer) height));
}
-static b4 common_cursor_left_click (common_structure * common, s4 x, s4 y, u4 width, u4 height) {
+static boolean common_cursor_left_click (common_structure * common, integer x, integer y, natural width, natural height) {
if (common->cursor [cursor_left] == true) {
common->freeze_cursor = true;
return (false);
}
-static b4 common_cursor_right_click (common_structure * common, s4 x, s4 y, u4 width, u4 height) {
+static boolean common_cursor_right_click (common_structure * common, integer x, integer y, natural width, natural height) {
if (common->cursor [cursor_right]) {
common->freeze_cursor = true;
return (false);
}
-static u4 common_sprite_raw_import (common_structure * common, u4 * data, u4 width, u4 height) {
+static natural common_sprite_raw_import (common_structure * common, natural * data, natural width, natural height) {
++common->sprite_count;
common->sprite_data = reallocate (common->sprite_data, common->sprite_count * sizeof (* common->sprite_data));
return (common->sprite_count - 1);
}
-static u4 common_font_raw_import (common_structure * common, u4 * data, u4 image_width, c1 begin, c1 end, u4 empty) {
- u4 pointer = 0;
- u4 width = 0;
- u4 height = 0;
- u4 * buffer = null;
+static natural common_font_raw_import (common_structure * common, natural * data, natural image_width, character begin, character end, natural empty) {
+ natural pointer = 0;
+ natural width = 0;
+ natural height = 0;
+ natural * buffer = null;
++common->font_count;
common->font_begin [common->font_count - 1] = begin;
common->font_end [common->font_count - 1] = end;
- common->font_index [common->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * common->font_index));
- common->font_width [common->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * common->font_width));
- common->font_height [common->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * common->font_height));
+ common->font_index [common->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * common->font_index));
+ common->font_width [common->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * common->font_width));
+ common->font_height [common->font_count - 1] = allocate ((caliber) (end - begin + 1) * sizeof (* * common->font_height));
- for (c1 index = begin; index <= end; ++index) {
+ for (character index = begin; index <= end; ++index) {
for ( ; data [pointer] == empty; ++pointer);
for (width = 0; data [pointer + width] != empty; ++width);
for (height = 0; data [pointer + height * image_width] != empty; ++height);
buffer = allocate (width * height * sizeof (* buffer));
- for (u4 y = 0; y < height; ++y) {
- for (u4 x = 0; x < width; ++x) {
+ for (natural y = 0; y < height; ++y) {
+ for (natural x = 0; x < width; ++x) {
buffer [y * width + x] = data [pointer + (y * image_width) + x];
}
}
return (common->font_count - 1);
}
-static u4 common_sprite_import (common_structure * common, c1 * path) {
- u4 width = 0;
- u4 height = 0;
- u4 * data = null;
+static natural common_sprite_import (common_structure * common, character * path) {
+ natural width = 0;
+ natural height = 0;
+ natural * data = null;
- c1 buffer [256] = "";
+ character buffer [256] = "";
#ifdef use_png_library
if ((data == null) && (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true)) {
return (common_sprite_raw_import (common, data, width, height));
}
-static u4 common_font_import (common_structure * common, c1 * path, c1 begin, c1 end, u4 colour) {
- u4 width = 0;
- u4 height = 0;
- u4 result = 0;
- u4 * data = null;
+static natural common_font_import (common_structure * common, character * path, character begin, character end, natural colour) {
+ natural width = 0;
+ natural height = 0;
+ natural result = 0;
+ natural * data = null;
- c1 buffer [256] = "";
+ character buffer [256] = "";
#ifdef use_png_library
if ((data == null) && (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true)) {
return (result);
}
-static u4 common_sprite_width (common_structure * common, u4 sprite) {
+static natural common_sprite_width (common_structure * common, natural sprite) {
return (common->sprite_width [sprite]);
}
-static u4 common_sprite_height (common_structure * common, u4 sprite) {
+static natural common_sprite_height (common_structure * common, natural sprite) {
return (common->sprite_height [sprite]);
}
-static common_structure * common_initialize (v0) {
+static common_structure * common_initialize (none) {
common_structure * common = allocate (sizeof (* common));
return (common);
}
static common_structure * common_deinitialize (common_structure * common) {
- for (u4 index = 0; index < common->sprite_count; ++index) {
+ for (natural index = 0; index < common->sprite_count; ++index) {
common->sprite_data [index] = deallocate (common->sprite_data [index]);
}
- for (u4 index = 0; index < common->font_count; ++index) {
+ for (natural index = 0; index < common->font_count; ++index) {
common->font_index [index] = deallocate (common->font_index [index]);
common->font_width [index] = deallocate (common->font_width [index]);
common->font_height [index] = deallocate (common->font_height [index]);
return (deallocate (common));
}
-static v0 common_configure (common_structure * common, u4 width, u4 height, c1 * title, u4 window_flags) {
- u8 font_bitmap [190] = {
+static procedure common_configure (common_structure * common, natural width, natural height, character * title, natural window_flags) {
+ natural_64 font_bitmap [190] = {
0x0000000000000000, 0x0000000000000000, 0x0000101010101010, 0x1000101000000000, 0x0024242400000000, 0x0000000000000000,
- 0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927c10100000, 0x0000649468081010, 0x202c524c00000000,
+ 0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927character0100000, 0x0000649468081010, 0x202c524c00000000,
0x000018242418304a, 0x4444443a00000000, 0x0010101000000000, 0x0000000000000000, 0x0000081020202020, 0x2020100800000000,
0x0000201008080808, 0x0808102000000000, 0x000000000024187e, 0x1824000000000000, 0x000000000010107c, 0x1010000000000000,
0x0000000000000000, 0x0000101020000000, 0x000000000000007e, 0x0000000000000000, 0x0000000000000000, 0x0000101000000000,
0x0000404020201010, 0x0808040400000000, 0x0000380808080808, 0x0808083800000000, 0x0000102844000000, 0x0000000000000000,
0x0000000000000000, 0x0000007e00000000, 0x1008000000000000, 0x0000000000000000, 0x00000000003c023e, 0x4242423e00000000,
0x00004040407c4242, 0x4242427c00000000, 0x00000000003c4240, 0x4040423c00000000, 0x00000202023e4242, 0x4242423e00000000,
- 0x00000000003c4242, 0x7e40403c00000000, 0x00000e10107c1010, 0x1010101000000000, 0x00000000003e4242, 0x4242423e02023c00,
+ 0x00000000003c4242, 0x7e40403c00000000, 0x00000e10107character010, 0x1010101000000000, 0x00000000003e4242, 0x4242423e02023c00,
0x00004040407c4242, 0x4242424200000000, 0x0000101000301010, 0x1010103800000000, 0x00000404000c0404, 0x0404040444443800,
0x0000404040424448, 0x7048444200000000, 0x0000301010101010, 0x1010103800000000, 0x0000000000fc9292, 0x9292929200000000,
0x00000000007c4242, 0x4242424200000000, 0x00000000003c4242, 0x4242423c00000000, 0x00000000007c4242, 0x4242427c40404000,
0x00000000003e4242, 0x4242423e02020200, 0x00000000005e6040, 0x4040404000000000, 0x00000000003e4040, 0x3c02027c00000000,
- 0x00001010107c1010, 0x1010100e00000000, 0x0000000000424242, 0x4242423e00000000, 0x0000000000424242, 0x2424181800000000,
+ 0x00001010107character010, 0x1010100e00000000, 0x0000000000424242, 0x4242423e00000000, 0x0000000000424242, 0x2424181800000000,
0x0000000000828292, 0x9292927c00000000, 0x0000000000424224, 0x1824424200000000, 0x0000000000424242, 0x4242423e02023c00,
- 0x00000000007e0408, 0x1020407e00000000, 0x00000c1010102010, 0x1010100c00000000, 0x0000101010101010, 0x1010101000000000,
+ 0x00000000007e0408, 0x1020407e00000000, 0x00000character010102010, 0x1010100c00000000, 0x0000101010101010, 0x1010101000000000,
0x0000300808080408, 0x0808083000000000, 0x000000000062928c, 0x0000000000000000
};
- u4 event_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
+ natural event_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
- u4 mask_window_flags [2] = { 0 };
+ natural mask_window_flags [2] = { 0 };
- (v0) window_flags;
+ (none) window_flags;
- u4 * dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
+ natural * dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
- for (u4 index = 0; index < 256; ++index) {
+ for (natural index = 0; index < 256; ++index) {
dumb_buffer [index] = 0xffffffff;
}
common->font_width [common->font_count - 1] = allocate (95 * sizeof (* * common->font_width));
common->font_height [common->font_count - 1] = allocate (95 * sizeof (* * common->font_height));
- for (u4 index = 0; index < 95; ++index) {
- u4 * buffer = allocate (common_font_width * common_font_height * sizeof (* buffer));
+ for (natural index = 0; index < 95; ++index) {
+ natural * buffer = allocate (common_font_width * common_font_height * sizeof (* buffer));
- for (u4 value = 0; value < 2; ++value) {
- for (u4 bit = 64; bit > 0; --bit) {
- u4 destination = ((value << 3) - ((bit - 1) >> 3) + 7) * common_font_width - ((bit - 1) & 7) + 7;
- u4 source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
+ for (natural value = 0; value < 2; ++value) {
+ for (natural bit = 64; bit > 0; --bit) {
+ natural destination = ((value << 3) - ((bit - 1) >> 3) + 7) * common_font_width - ((bit - 1) & 7) + 7;
+ natural source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
buffer [destination] = (source) ? 0xffffffff : 0x00000000;
}
XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_BUTTON_PRESS;
- xcb_create_window (common->connection, common->screen->root_depth, common->window, common->screen->root, 0, 0, (u2) width,
- (u2) height, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, common->screen->root_visual, event_mask, mask_window_flags);
+ xcb_create_window (common->connection, common->screen->root_depth, common->window, common->screen->root, 0, 0, (natural_16) width,
+ (natural_16) height, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, common->screen->root_visual, event_mask, mask_window_flags);
xcb_map_window (common->connection, common->window);
//~xcb_composite_redirect_window (common->connection, common->window, XCB_COMPOSITE_REDIRECT_MANUAL);
xcb_change_property (common->connection, XCB_PROP_MODE_REPLACE, common->window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
- (u4) string_length (title), title);
+ (natural) string_length (title), title);
- xcb_create_pixmap (common->connection, common->screen->root_depth, common->pixmap, common->window, (u2) width, (u2 ) height);
+ xcb_create_pixmap (common->connection, common->screen->root_depth, common->pixmap, common->window, (natural_16) width, (natural_16 ) height);
xcb_create_gc (common->connection, common->context, common->pixmap, 0, null);
common->frame_begin = nano_time ();
}
-static v0 common_synchronize (common_structure * common, u4 colour) {
- u4 signal_code [signal_count] = {
+static procedure common_synchronize (common_structure * common, natural colour) {
+ natural signal_code [signal_count] = {
0,
38, 56, 54, 40, 26, 41, 42, 43, 31, 44, 45, 46, 58, 57, 32, 33,
24, 27, 39, 28, 30, 55, 25, 53, 29, 52, 19, 10, 11, 12, 13, 14,
xcb_generic_event_t * generic_event = xcb_wait_for_event (common->connection);
//~xcb_generic_event_t * generic_event = null;
- (v0) colour;
+ (none) colour;
//~for (; ; ) {
//~generic_event = xcb_poll_for_event (common->connection);
} break;
case (XCB_KEY_PRESS): {
xcb_key_press_event_t * key_press = (xcb_key_press_event_t *) generic_event;
- for (u4 index = 0; index < signal_count; ++index) {
+ for (natural index = 0; index < signal_count; ++index) {
if (key_press->detail == signal_code [index]) {
common->signal [index] = true;
}
} break;
case (XCB_KEY_RELEASE): {
xcb_key_release_event_t * key_release = (xcb_key_release_event_t *) generic_event;
- for (u4 index = 0; index < signal_count; ++index) {
+ for (natural index = 0; index < signal_count; ++index) {
if (key_release->detail == signal_code [index]) {
common->signal [index] = false;
}
generic_event = deallocate (generic_event);
//~}
- for (u4 pixel = 0; pixel < common->window_width * common->window_height; ++pixel) {
- u4 r = (common->framebuffer [pixel] & 0x00ff0000) >> 16;
- u4 b = (common->framebuffer [pixel] & 0x000000ff) << 16;
+ for (natural pixel = 0; pixel < common->window_width * common->window_height; ++pixel) {
+ natural r = (common->framebuffer [pixel] & 0x00ff0000) >> 16;
+ natural b = (common->framebuffer [pixel] & 0x000000ff) << 16;
common->framebuffer [pixel] = (common->framebuffer [pixel] & 0xff00ff00) | b | r;
}
- common->image = xcb_image_create_native (common->connection, (u2) common->window_width, (u2) common->window_height,
+ common->image = xcb_image_create_native (common->connection, (natural_16) common->window_width, (natural_16) common->window_height,
XCB_IMAGE_FORMAT_Z_PIXMAP, common->screen->root_depth, common->framebuffer,
- (u4) (common->window_width * common->window_height * sizeof (* common->framebuffer)),
- (u1 *) common->framebuffer);
+ (natural) (common->window_width * common->window_height * sizeof (* common->framebuffer)),
+ (natural_8 *) common->framebuffer);
xcb_image_put (common->connection, common->pixmap, common->context, common->image, 0, 0, 0);
xcb_image_destroy (common->image);
- xcb_copy_area (common->connection, common->pixmap, common->window, common->context, 0, 0, 0, 0, (u2) common->window_width,
- (u2) common->window_height);
+ xcb_copy_area (common->connection, common->pixmap, common->window, common->context, 0, 0, 0, 0, (natural_16) common->window_width,
+ (natural_16) common->window_height);
common->framebuffer = allocate (common->window_width * common->window_height * sizeof (* common->framebuffer));
}
if (common->global_tick % common_gameplay_framerate == 0) {
- common->framerate = (u4) (1000000000ul / common->frame_time);
+ common->framerate = (natural) (1000000000ul / common->frame_time);
}
++common->global_tick;
common->frame_begin = nano_time ();
}
-static v0 common_render_base (common_structure * common, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height, f4 scale_x, f4 scale_y, s4 flip_x,
- s4 flip_y, u4 upper_left, u4 upper_right, u4 lower_left, u4 lower_right) {
- (v0) scale_x;
- (v0) scale_y;
- (v0) flip_x;
- (v0) flip_y;
+static procedure common_render_base (common_structure * common, natural sprite, integer x, integer y, natural u, natural v, natural width, natural height, real scale_x, real scale_y, integer flip_x,
+ integer flip_y, natural upper_left, natural upper_right, natural lower_left, natural lower_right) {
+ (none) scale_x;
+ (none) scale_y;
+ (none) flip_x;
+ (none) flip_y;
/// FIX TO INTERPOLATE ALL 4 COLOURS
- //~(v0) upper_left;
- (v0) upper_right;
- (v0) lower_left;
- (v0) lower_right;
+ //~(none) upper_left;
+ (none) upper_right;
+ (none) lower_left;
+ (none) lower_right;
/// COLOUR INTERPOLATION WITH RBGA-ABGR CONVERSION
- u4 interpolate_pixels (u4 pixel, u4 modifier) {
- u4 r = (((pixel & 0xff000000) >> 24) * ((modifier & 0x000000ff) >> 0)) / 0xff;
- u4 g = (((pixel & 0x00ff0000) >> 16) * ((modifier & 0x0000ff00) >> 8)) / 0xff;
- u4 b = (((pixel & 0x0000ff00) >> 8) * ((modifier & 0x00ff0000) >> 16)) / 0xff;
- u4 a = (((pixel & 0x000000ff) >> 0) * ((modifier & 0xff000000) >> 24)) / 0xff;
+ natural interpolate_pixels (natural pixel, natural modifier) {
+ natural r = (((pixel & 0xff000000) >> 24) * ((modifier & 0x000000ff) >> 0)) / 0xff;
+ natural g = (((pixel & 0x00ff0000) >> 16) * ((modifier & 0x0000ff00) >> 8)) / 0xff;
+ natural b = (((pixel & 0x0000ff00) >> 8) * ((modifier & 0x00ff0000) >> 16)) / 0xff;
+ natural a = (((pixel & 0x000000ff) >> 0) * ((modifier & 0xff000000) >> 24)) / 0xff;
return ((r << 24) | (g << 16) | (b << 8) | a);
}
- if ((x + (int) width < 0) || (y + (int) height < 0) || (x > (int) common->window_width) || (y > (int) common->window_height)) return;
+ if ((x + (integer) width < 0) || (y + (integer) height < 0) || (x > (integer) common->window_width) || (y > (integer) common->window_height)) return;
- for (u4 vertical = 0; vertical < height; ++vertical) {
+ for (natural vertical = 0; vertical < height; ++vertical) {
if (vertical + y >= common->window_height) break;
if (vertical + v >= common->sprite_height [sprite]) break;
- for (u4 horizontal = 0; horizontal < width; ++horizontal) {
+ for (natural horizontal = 0; horizontal < width; ++horizontal) {
if (horizontal + x >= common->window_width) break;
if (horizontal + u >= common->sprite_width [sprite]) break;
- u4 pixel = common->sprite_data [sprite] [(vertical + v) * common->sprite_width [sprite] + horizontal + u];
- u4 at = (y + vertical) * common->window_width + (x + horizontal);
+ natural pixel = common->sprite_data [sprite] [(vertical + v) * common->sprite_width [sprite] + horizontal + u];
+ natural at = (y + vertical) * common->window_width + (x + horizontal);
common->framebuffer [at] = (((pixel & 0xff000000) >> 24) > 0x77) ? interpolate_pixels (pixel, upper_left) : common->framebuffer [at];
}
}
}
-static v0 common_render_rectangle (common_structure * common, s4 x, s4 y, u4 width, u4 height, u4 colour) {
- common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour, colour,
+static procedure common_render_rectangle (common_structure * common, integer x, integer y, natural width, natural height, natural colour) {
+ common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour, colour,
colour, colour);
}
-static v0 common_render_rectangle_gradient_v (common_structure * common, s4 x, s4 y, u4 width, u4 height, u4 colour_up, u4 colour_down) {
- common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour_up, colour_up,
+static procedure common_render_rectangle_gradient_v (common_structure * common, integer x, integer y, natural width, natural height, natural colour_up, natural colour_down) {
+ common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour_up, colour_up,
colour_down, colour_down);
}
-static v0 common_render_rectangle_gradient_h (common_structure * common, s4 x, s4 y, u4 width, u4 height, u4 colour_left, u4 colour_right) {
- common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour_left,
+static procedure common_render_rectangle_gradient_h (common_structure * common, integer x, integer y, natural width, natural height, natural colour_left, natural colour_right) {
+ common_render_base (common, common->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour_left,
colour_right, colour_left, colour_right);
}
-static v0 common_render_sprite (common_structure * common, u4 sprite, s4 x, s4 y) {
+static procedure common_render_sprite (common_structure * common, natural sprite, integer x, integer y) {
common_render_base (common, sprite, x, y, 0, 0, common->sprite_width [sprite], common->sprite_height [sprite], 1, 1, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu,
0xffffffffu);
}
-static v0 common_render_sprite_crop (common_structure * common, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
+static procedure common_render_sprite_crop (common_structure * common, natural sprite, integer x, integer y, natural u, natural v, natural width, natural height) {
common_render_base (common, sprite, x, y, u, v, width, height, 1, 1, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 common_render_sprite_colour (common_structure * common, u4 sprite, u4 colour, s4 x, s4 y) {
+static procedure common_render_sprite_colour (common_structure * common, natural sprite, natural colour, integer x, integer y) {
common_render_base (common, sprite, x, y, 0, 0, common->sprite_width [sprite], common->sprite_height [sprite], 1, 1, 0, 0, colour, colour, colour, colour);
}
-static v0 common_render_sprite_crop_colour (common_structure * common, u4 sprite, u4 colour, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
+static procedure common_render_sprite_crop_colour (common_structure * common, natural sprite, natural colour, integer x, integer y, natural u, natural v, natural width, natural height) {
common_render_base (common, sprite, x, y, u, v, width, height, 1, 1, 0, 0, colour, colour, colour, colour);
}
-static v0 common_render_sprite_flip (common_structure * common, u4 sprite, s4 x, s4 y, s4 flip_x, s4 flip_y) {
+static procedure common_render_sprite_flip (common_structure * common, natural sprite, integer x, integer y, integer flip_x, integer flip_y) {
common_render_base (common, sprite, x, y, 0, 0, common->sprite_width [sprite], common->sprite_height [sprite], 1, 1, flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 common_render_sprite_animate (common_structure * common, u4 sprite, s4 x, s4 y, u4 frames, u4 state, u4 states) {
- u4 width = common->sprite_width [sprite] / states;
- u4 height = common->sprite_height [sprite] / frames;
- u4 u = width * (state % states);
- u4 v = height * (common->animation_tick % frames);
+static procedure common_render_sprite_animation (common_structure * common, natural sprite, integer x, integer y, natural frames, natural state, natural states) {
+ natural width = common->sprite_width [sprite] / states;
+ natural height = common->sprite_height [sprite] / frames;
+ natural u = width * (state % states);
+ natural v = height * (common->animation_tick % frames);
common_render_sprite_crop (common, sprite, x, y, u, v, width, height);
}
-static v0 common_render_sprite_preview (common_structure * common, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height, f4 zoom) {
+static procedure common_render_sprite_preview (common_structure * common, natural sprite, integer x, integer y, natural u, natural v, natural width, natural height, real zoom) {
common_render_base (common, sprite, x, y, u, v, width, height, zoom, zoom, false, false, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 common_render_sprite_control (common_structure * common, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height, s4 flip_x, s4 flip_y) {
+static procedure common_render_sprite_control (common_structure * common, natural sprite, integer x, integer y, natural u, natural v, natural width, natural height, integer flip_x, integer flip_y) {
common_render_base (common, sprite, x, y, u, v, width, height, 1, 1, flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static u4 common_render_string_width (common_structure * common, c1 * string, u4 font, f4 scale) {
- u4 length = 0;
+static natural common_render_string_width (common_structure * common, character * string, natural font, real scale) {
+ natural length = 0;
if (string == null) {
return (0);
}
- for (u4 index = 0; string [index] != '\0'; ++index) {
- u4 character = common->font_index [font] [string [index] - common->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ natural character = common->font_index [font] [string [index] - common->font_begin [font]];
- length += (u4) ((float) common->sprite_width [character] * scale);
+ length += (natural) ((real) common->sprite_width [character] * scale);
}
return (length);
}
-static v0 common_render_string (common_structure * common, c1 * string, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
- s4 offset = x;
+static procedure common_render_string (common_structure * common, character * string, natural font, integer x, integer y, real scale, natural colour) {
+ integer offset = x;
if (string == null) return;
font = common->font_count - 1;
}
- for (u4 index = 0; string [index] != '\0'; ++index) {
- u4 character = 0;
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ natural character = 0;
if (string [index] == '\t') {
- x += (int) (scale * (float) common_font_tabulator * (float) common->sprite_width [common->font_index [font] [' ' - common->font_begin [font]]]);
+ x += (integer) (scale * (real) common_font_tabulator * (real) common->sprite_width [common->font_index [font] [' ' - common->font_begin [font]]]);
continue;
} else if (string [index] == '\n') {
x = offset;
- y += (int) (scale * (float) common->sprite_height [common->font_index [font] [' ' - common->font_begin [font]]]);
+ y += (integer) (scale * (real) common->sprite_height [common->font_index [font] [' ' - common->font_begin [font]]]);
continue;
} else if ((string [index] >= common->font_begin [font]) && (string [index] <= common->font_end [font])) {
character = common->font_index [font] [string [index] - common->font_begin [font]];
common_render_base (common, character, x, y, 0, 0, common->sprite_width [character], common->sprite_height [character],
scale, scale, 0, 0, colour, colour, colour, colour);
- x += (int) (scale * (float) common->sprite_width [character]);
+ x += (integer) (scale * (real) common->sprite_width [character]);
}
}
#include <xolatile/xtandard.h>
-static v0 echo_byte (u1 byte) {
+static procedure echo_byte (natural_8 byte) {
output ("0123456789ABCDEF" + byte / 16, 1);
output ("0123456789ABCDEF" + byte % 16, 1);
output (" ", 1);
}
-s4 main (s4 argc, c1 * * argv) {
- s4 file = 0;
- u8 size = 0;
- u1 * buffer = null;
+integer main (integer argc, character * * argv) {
+ integer file = 0;
+ caliber size = 0;
+ natural_8 * buffer = null;
if (argc != 2) {
print ("> xop input_file\n");
file = file_close (file);
- for (u8 offset = 0; offset < size; ++offset) {
+ for (caliber offset = 0; offset < size; ++offset) {
if (buffer [offset] == 0x90) {
echo ("\n");
}
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
+/// Xormat, simple and hacky for file formats that I dislike, but everyone else uses them, so I have to use them too. I hate technology. This
+/// more normal library comparing to my other ones, include this header file and use simplistic functions however you want. Don't care too much
+/// about abstractions I introduced here, but keep in mind that you have to link your program correctly, this isn't stb-like library, even tho
+/// it's header only. You should define a macro of which format(s) you want to use before including this file in your project.
+
#ifdef use_png_library
#include <xolatile/xormat/png.h>
#endif
#include <xolatile/xormat/tga.h>
#endif
-static v0 * format_image_import (c1 * path, u4 * width, u4 * height) {
- u4 * data = null;
-
-//~#ifdef use_png_library
- //~if (data == null) {
- //~c1 buffer [256] = "";
-
- //~if (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true) {
- //~data = png_image_import (buffer, width, height);
- //~}
- //~}
-//~#endif
-
-//~#ifdef use_jxl_library
- //~if (data == null) {
- //~c1 buffer [256] = "";
-
- //~if (file_exists (string_concatenate (string_copy (buffer, path), ".jxl")) == true) {
- //~data = jxl_image_import (buffer, width, height);
- //~}
- //~}
-//~#endif
-
-//~#ifdef use_jpg_library
- //~if (data == null) {
- //~c1 buffer [256] = "";
-
- //~if (file_exists (string_concatenate (string_copy (buffer, path), ".jpg")) == true) {
- //~data = jpg_image_import (buffer, width, height);
- //~}
- //~}
-//~#endif
-
-//~#ifdef use_tga_library
- //~if (data == null) {
- //~c1 buffer [256] = "";
-
- //~if (file_exists (string_concatenate (string_copy (buffer, path), ".tga")) == true) {
- //~data = tga_image_import (buffer, width, height);
- //~}
- //~}
-//~#endif
+/// Return image raw 32-bit colour data, in RGBA channel format by providing file path to image (with or without extension, if there's no
+/// extension it's load first file found in order declared below) and two pointers to store width and height values. All images will be
+/// implicitly converted into 32-bit RGBA colour, 8 bits per channel.
+///
+/// natural_32 * image = format_image_import ("image.png", & width, & height); /// You can omit '.png' part in file path too.
+
+static natural_32 * format_image_import (character * path, natural * width, natural * height) {
+ natural_32 * data = null;
+
+#ifdef use_png_library
+ if (data == null) {
+ character buffer [256] = "";
+
+ if (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true) {
+ data = png_image_import (buffer, width, height);
+ }
+ }
+#endif
+
+#ifdef use_jxl_library
+ if (data == null) {
+ character buffer [256] = "";
+
+ if (file_exists (string_concatenate (string_copy (buffer, path), ".jxl")) == true) {
+ data = jxl_image_import (buffer, width, height);
+ }
+ }
+#endif
+
+#ifdef use_jpg_library
+ if (data == null) {
+ character buffer [256] = "";
+
+ if (file_exists (string_concatenate (string_copy (buffer, path), ".jpg")) == true) {
+ data = jpg_image_import (buffer, width, height);
+ }
+ }
+#endif
+
+#ifdef use_tga_library
+ if (data == null) {
+ character buffer [256] = "";
+
+ if (file_exists (string_concatenate (string_copy (buffer, path), ".tga")) == true) {
+ data = tga_image_import (buffer, width, height);
+ }
+ }
+#endif
if (data == null) {
switch (file_type (path)) {
#define use_jxl_library
#endif
-static v0 * jxl_image_import (c1 * path, u4 * width, u4 * height) {
+static generic * jxl_image_import (character * path, natural * width, natural * height) {
JxlDecoder * decoder = null;
JxlBasicInfo information = { 0 };
JxlPixelFormat format = { 4, JXL_TYPE_UINT8, JXL_NATIVE_ENDIAN, 0 };
fatal_failure (width == null, "jxl_image_import: Width is null pointer.");
fatal_failure (height == null, "jxl_image_import: Height is null pointer.");
- u8 size = file_size (path);
- u1 * data = file_record (path);
- u4 * pixel_array = null;
- u8 output_size = 0;
+ natural_64 size = file_size (path);
+ natural_8 * data = file_record (path);
+ natural_32 * pixel_array = null;
+ natural_64 output_size = 0;
decoder = JxlDecoderCreate (null);
#define use_png_library
#endif
-static v0 * png_image_import (c1 * path, u4 * width, u4 * height) {
- FILE * file;
- u4 * data;
- u4 index;
+static generic * png_image_import (character * path, natural * width, natural * height) {
+ FILE * file = null;
+ natural * data = null;
png_byte colour_type = 0;
png_byte bit_depth = 0;
row_pointers = allocate ((* height) * sizeof (* row_pointers));
- for (index = 0; index < (* height); ++index) {
+ for (natural index = 0; index < (* height); ++index) {
row_pointers [index] = allocate (png_get_rowbytes (structure, information));
}
data = allocate ((* width) * (* height) * sizeof (* data));
- for (index = 0; index < (* height); ++index) {
+ for (natural index = 0; index < (* height); ++index) {
memory_copy (& data [index * (* width)], row_pointers [index], (* width) * sizeof (* data));
row_pointers [index] = deallocate (row_pointers [index]);
return (data);
}
-static v0 png_image_export (c1 * path, u4 * data, u4 width, u4 height) {
+static procedure png_image_export (character * path, natural * data, natural width, natural height) {
png_image image = { 0 };
fatal_failure (path == null, "png_image_export: File path is null pointer.");
--- /dev/null
+/// __ _____ _ _ _ __ ___ ___
+/// \ \/ / _ \| | | | '__/ __/ _ \
+/// > < (_) | |_| | | | (_| __/
+/// /_/\_\___/ \__,_|_| \___\___|
+///
+/// Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic
+///
+/// xolatile@chud.cyou - xource - Not quite STANDARD GNU/Linux tiny text editor, but it does the work...
+///
+/// This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU
+/// General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish...
+///
+/// This program is distributed in the hope that it will be useful, but it is probably not, and without any warranty, without even the implied
+/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
+/// for more details, if you dare, it is a lot of text that nobody wants to read...
+
+#include <xolatile/xtandard.h>
+
+integer main (integer argc, character * * argv) {
+ return (log_success);
+}
#define opengl_font_width (8)
#define opengl_font_height (16)
-//~typedef enum {
- //~opengl_window_fullscreen = 0x1,
- //~opengl_window_transparent = 0x2,
- //~opengl_window_resizable = 0x4,
- //~opengl_window_decorated = 0x8
-//~} opengl_window_flag;
-
typedef struct {
GLFWwindow * window;
PFNGLDELETEPROGRAMPROC glDeleteProgram;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLBUFFERDATAPROC glBufferData;
-
- b4 signal [signal_count];
- b4 cursor [cursor_count];
- s4 cursor_x;
- s4 cursor_y;
-
- b4 using_precomputed_spritesheet;
- u8 spritesheet_size;
- u8 vertex_limit;
- u8 index_limit;
- u4 gameplay_framerate;
- u4 animation_framerate;
- u4 tab_width;
- u4 default_font;
- b4 active;
- u4 window_width;
- u4 window_height;
- f4 pixel_width;
- f4 pixel_height;
- u4 framerate;
- u8 frame_time;
- u8 frame_begin;
- u8 frame_end;
- u4 global_tick;
- u4 gameplay_tick;
- u4 animation_tick;
- b4 freeze_cursor;
- b4 freeze_signal;
- u4 vertex_object;
- u4 vertex_buffer;
- u4 index_buffer;
- u4 vertex_shader;
- u4 fragment_shader;
- u4 shader_program;
- u4 spritesheet;
- u4 vertex_count;
- u4 index_count;
- f4 * vertex_array;
- u4 * index_array;
- u4 sprite_count;
- u4 font_count;
- u4 * spritesheet_data;
- u4 * * sprite_data;
- u4 * sprite_width;
- u4 * sprite_height;
- f4 * sprite_u;
- f4 * sprite_v;
- u4 * * font_index;
- u4 * * font_width;
- u4 * * font_height;
- c1 * font_begin;
- c1 * font_end;
+ PFNGLGETSHADERIVPROC glGetShaderiv;
+ PFNGLGETPROGRAMIVPROC glGetProgramiv;
+
+ boolean signal [signal_count];
+ boolean cursor [cursor_count];
+
+ integer cursor_x;
+ integer cursor_y;
+ boolean active;
+ boolean very_verbose_spam;
+ natural window_width;
+ natural window_height;
+ natural_64 frame_time;
+ natural_64 frame_begin;
+ natural_64 frame_end;
+ natural framerate;
+ natural global_tick;
+ natural gameplay_tick;
+ natural animation_tick;
+ natural gameplay_framerate;
+ natural animation_framerate;
+ natural sprite_count;
+ natural font_count;
+ natural * * sprite_data;
+ natural * sprite_width;
+ natural * sprite_height;
+ natural * * font_index;
+ natural * * font_width;
+ natural * * font_height;
+ character * font_begin;
+ character * font_end;
+ natural tab_width;
+ natural default_font;
+
+ boolean using_precomputed_spritesheet;
+ real pixel_width;
+ real pixel_height;
+ natural vertex_object;
+ natural vertex_buffer;
+ natural index_buffer;
+ natural vertex_shader;
+ natural fragment_shader;
+ natural shader_program;
+ natural spritesheet;
+ caliber vertex_limit;
+ caliber index_limit;
+ natural vertex_count;
+ natural index_count;
+ real * vertex_array;
+ natural * index_array;
+ natural * spritesheet_data;
+ real * sprite_u;
+ real * sprite_v;
+ caliber spritesheet_size;
+ boolean freeze_cursor;
+ boolean freeze_signal;
} opengl_structure;
-static u4 opengl_sprite_raw_import (opengl_structure * opengl, u4 * data, u4 width, u4 height) {
+static opengl_structure * opengl_initialize (natural gameplay_framerate, natural animation_framerate, boolean use_precomputed_spritesheet,
+ natural maximum_quads_on_screen, natural spritesheet_side) {
+ opengl_structure * opengl = allocate (sizeof (* opengl));
+
+ opengl->using_precomputed_spritesheet = use_precomputed_spritesheet;
+
+ opengl->spritesheet_size = spritesheet_side;
+ opengl->gameplay_framerate = gameplay_framerate;
+ opengl->animation_framerate = animation_framerate;
+ opengl->vertex_limit = maximum_quads_on_screen * 32;
+ opengl->index_limit = maximum_quads_on_screen * 6;
+ opengl->tab_width = 4;
+ opengl->default_font = ~0u;
+
+ print ("/s Initialized OpenGL renderer.\n");
+
+ return (opengl);
+}
+
+static opengl_structure * opengl_deinitialize (opengl_structure * opengl) {
+ opengl->active = false;
+
+ for (natural index = 0; index < opengl->font_count; ++index) {
+ opengl->font_index [index] = deallocate (opengl->font_index [index]);
+ opengl->font_width [index] = deallocate (opengl->font_width [index]);
+ opengl->font_height [index] = deallocate (opengl->font_height [index]);
+ }
+
+ opengl->font_index = deallocate (opengl->font_index);
+ opengl->font_width = deallocate (opengl->font_width);
+ opengl->font_height = deallocate (opengl->font_height);
+ opengl->font_begin = deallocate (opengl->font_begin);
+ opengl->font_end = deallocate (opengl->font_end);
+
+ opengl->sprite_width = deallocate (opengl->sprite_width);
+ opengl->sprite_height = deallocate (opengl->sprite_height);
+ opengl->sprite_u = deallocate (opengl->sprite_u);
+ opengl->sprite_v = deallocate (opengl->sprite_v);
+
+ if (opengl->using_precomputed_spritesheet == false) {
+ opengl->spritesheet_data = deallocate (opengl->spritesheet_data);
+ }
+
+ opengl->vertex_array = deallocate (opengl->vertex_array);
+ opengl->index_array = deallocate (opengl->index_array);
+
+ glDeleteTextures (1, & opengl->spritesheet);
+
+ opengl->glDeleteProgram (opengl->shader_program);
+ opengl->glDeleteShader (opengl->fragment_shader);
+ opengl->glDeleteShader (opengl->vertex_shader);
+
+ opengl->glDeleteBuffers (1, & opengl->index_buffer);
+ opengl->glDeleteBuffers (1, & opengl->vertex_buffer);
+ opengl->glDeleteVertexArrays (1, & opengl->vertex_object);
+
+ glfwDestroyWindow (opengl->window);
+
+ glfwTerminate ();
+
+ print ("/s Deinitialized OpenGL renderer.\n");
+
+ return (deallocate (opengl));
+}
+
+static natural opengl_sprite_raw_import (opengl_structure * opengl, natural * data, natural width, natural height) {
+ natural current = ++opengl->sprite_count - 1;
+
fatal_failure (opengl->active == true, "opengl_sprite_raw_import: OpenGL renderer is already initialized.");
fatal_failure (data == null, "opengl_sprite_raw_import: Data is null pointer.");
fatal_failure (width == 0, "opengl_sprite_raw_import: Font image width is zero.");
fatal_failure (height == 0, "opengl_sprite_raw_import: Font image height is zero.");
- ++opengl->sprite_count;
-
opengl->sprite_data = reallocate (opengl->sprite_data, opengl->sprite_count * sizeof (* opengl->sprite_data));
opengl->sprite_width = reallocate (opengl->sprite_width, opengl->sprite_count * sizeof (* opengl->sprite_width));
opengl->sprite_height = reallocate (opengl->sprite_height, opengl->sprite_count * sizeof (* opengl->sprite_height));
opengl->sprite_u = reallocate (opengl->sprite_u, opengl->sprite_count * sizeof (* opengl->sprite_u));
opengl->sprite_v = reallocate (opengl->sprite_v, opengl->sprite_count * sizeof (* opengl->sprite_v));
- opengl->sprite_data [opengl->sprite_count - 1] = data;
- opengl->sprite_width [opengl->sprite_count - 1] = width;
- opengl->sprite_height [opengl->sprite_count - 1] = height;
- opengl->sprite_u [opengl->sprite_count - 1] = 0;
- opengl->sprite_v [opengl->sprite_count - 1] = 0;
+ opengl->sprite_data [current] = data;
+ opengl->sprite_width [current] = width;
+ opengl->sprite_height [current] = height;
+ opengl->sprite_u [current] = 0;
+ opengl->sprite_v [current] = 0;
- return (opengl->sprite_count - 1);
+ return (current);
}
-static u4 opengl_font_raw_import (opengl_structure * opengl, u4 * data, u4 image_width, c1 begin, c1 end, u4 empty) {
- u4 pointer = 0;
- u4 width = 0;
- u4 height = 0;
+static natural opengl_font_raw_import (opengl_structure * opengl, natural * data, natural image_width, natural image_height, character begin,
+ character end, natural separator_colour) {
+ natural current = ++opengl->font_count - 1;
+
+ natural pointer = 0;
+ natural width = 0;
+ natural height = 0;
+ natural point_count = 0;
+ natural * point_array = null;
fatal_failure (opengl->active == true, "opengl_font_raw_import: OpenGL renderer is already initialized.");
fatal_failure (data == null, "opengl_font_raw_import: Data is null pointer.");
fatal_failure (image_width == 0, "opengl_font_raw_import: Font image width is zero.");
+ fatal_failure (image_height == 0, "opengl_font_raw_import: Font image height is zero.");
fatal_failure (begin >= end, "opengl_font_raw_import: Font character range is inverted.");
- ++opengl->font_count;
-
opengl->font_index = reallocate (opengl->font_index, opengl->font_count * sizeof (* opengl->font_index));
opengl->font_width = reallocate (opengl->font_width, opengl->font_count * sizeof (* opengl->font_width));
opengl->font_height = reallocate (opengl->font_height, opengl->font_count * sizeof (* opengl->font_height));
opengl->font_begin = reallocate (opengl->font_begin, opengl->font_count * sizeof (* opengl->font_begin));
opengl->font_end = reallocate (opengl->font_end, opengl->font_count * sizeof (* opengl->font_end));
- opengl->font_begin [opengl->font_count - 1] = begin;
- opengl->font_end [opengl->font_count - 1] = end;
+ opengl->font_begin [current] = begin;
+ opengl->font_end [current] = end;
- opengl->font_index [opengl->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * opengl->font_index));
- opengl->font_width [opengl->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * opengl->font_width));
- opengl->font_height [opengl->font_count - 1] = allocate ((u8) (end - begin + 1) * sizeof (* * opengl->font_height));
+ opengl->font_index [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * opengl->font_index));
+ opengl->font_width [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * opengl->font_width));
+ opengl->font_height [current] = allocate ((caliber) (end - begin + 1) * sizeof (* * opengl->font_height));
- for (c1 index = begin; index <= end; ++index) {
- for ( ; data [pointer] == empty; ++pointer);
- for (width = 0; data [pointer + width] != empty; ++width);
- for (height = 0; data [pointer + height * image_width] != empty; ++height);
+ point_array = allocate ((caliber) (end - begin + 1) * sizeof (* point_array));
- u4 * buffer = allocate (width * height * sizeof (* buffer));
+ if (separator_colour == 0x00000000u) {
+ separator_colour = data [0];
+ }
- for (u4 y = 0; y < height; ++y) {
- for (u4 x = 0; x < width; ++x) {
- buffer [y * width + x] = data [pointer + (y * image_width) + x];
+ for (natural y = 0; y < image_height - 1; ++y) {
+ for (natural x = 0; x < image_width - 1; ++x) {
+ if ((data [(y + 0) * image_width + (x + 0)] == separator_colour)
+ && (data [(y + 1) * image_width + (x + 0)] == separator_colour)
+ && (data [(y + 0) * image_width + (x + 1)] == separator_colour)
+ && (data [(y + 1) * image_width + (x + 1)] == 0x00000000u)) {
+ ++point_count;
+ point_array [point_count - 1] = (y + 1) * image_width + (x + 1);
}
}
+ }
+
+ if (point_count != end - begin + 1) {
+ print ("/w Mismatch between font character points:\n");
+ print ("/c --- Hardcoded expected number of character points: %i\n", end - begin + 1);
+ print ("/c --- Algorithm found number of character points: %i\n", point_count);
+ }
- opengl->font_index [opengl->font_count - 1] [index - begin] = opengl_sprite_raw_import (opengl, buffer, width, height);
- opengl->font_width [opengl->font_count - 1] [index - begin] = width;
- opengl->font_height [opengl->font_count - 1] [index - begin] = height;
+ for (natural index = 0; index < end - begin + 1; ++index) {
+ for (width = 0; data [point_array [index] + width] != separator_colour; ++width);
+ for (height = 0; data [point_array [index] + height * image_width] != separator_colour; ++height);
- pointer += width;
+ fatal_failure (width == 0, "opengl_font_raw_import: Font width is zero.");
+ fatal_failure (height == 0, "opengl_font_raw_import: Font height is zero.");
- for (; data [pointer] == empty; ++pointer);
+ natural * buffer = allocate (width * height * sizeof (* buffer));
- if (pointer % image_width == 2) {
- pointer += height * image_width;
+ for (natural y = 0; y < height; ++y) {
+ for (natural x = 0; x < width; ++x) {
+ buffer [y * width + x] = data [point_array [index] + y * image_width + x];
+ }
}
+
+ opengl->font_index [current] [index] = opengl_sprite_raw_import (opengl, buffer, width, height);
+ opengl->font_width [current] [index] = width;
+ opengl->font_height [current] [index] = height;
}
- return (opengl->font_count - 1);
+ point_array = deallocate (point_array);
+
+ return (current);
}
-static u4 opengl_sprite_import (opengl_structure * opengl, c1 * path) {
- u4 width = 0;
- u4 height = 0;
- u4 * data = null;
+static natural opengl_sprite_import (opengl_structure * opengl, character * path) {
+ natural width = 0;
+ natural height = 0;
+ natural * data = null;
- c1 buffer [256] = "";
+ fatal_failure (opengl->active == true, "opengl_sprite_import: OpenGL renderer is already initialized.");
if (opengl->using_precomputed_spritesheet == true) {
return (++opengl->sprite_count - 1);
}
-#ifdef use_png_library
- if (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true) {
- data = png_image_import (buffer, & width, & height);
- } else {
- print ("/w File '/3%s/-' doesn't exist.\n", buffer);
- }
-#endif
+ data = format_image_import (path, & width, & height);
-#ifdef use_jxl_library
- if ((data == null) && (file_exists (string_concatenate (string_copy (buffer, path), ".jxl")) == true)) {
- data = jxl_image_import (buffer, & width, & height);
- }
-#endif
+ conditional_print ((data == null) || (width == 0) || (height == 0), "/f Failed to import sprite '%s'.", path);
- fatal_failure (data == null, "opengl_sprite_import: Unsupported image format.");
+ conditional_print (opengl->very_verbose_spam == true, "/c Importing sprite '/0/B%s/-' of size %i x %i.\n", path, width, height);
return (opengl_sprite_raw_import (opengl, data, width, height));
}
-static u4 opengl_font_import (opengl_structure * opengl, c1 * path, c1 begin, c1 end, u4 colour) {
- u4 width = 0;
- u4 height = 0;
- u4 result = 0;
- u4 * data = null;
+static natural opengl_font_import (opengl_structure * opengl, character * path, character begin, character end, natural colour) {
+ natural width = 0;
+ natural height = 0;
+ natural result = 0;
+ natural * data = null;
- c1 buffer [256] = "";
+ character buffer [256] = "";
+
+ fatal_failure (opengl->active == true, "opengl_font_import: OpenGL renderer is already initialized.");
if (opengl->using_precomputed_spritesheet == true) {
- for (c1 index = begin; index <= end; ++index) {
+ for (character index = begin; index <= end; ++index) {
opengl->font_index [opengl->font_count] [index - begin] = ++opengl->sprite_count - 1;
}
return (++opengl->font_count - 1);
}
-#ifdef use_png_library
- if (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true) {
- data = png_image_import (buffer, & width, & height);
- } else {
- print ("/w File '/3%s/-' doesn't exist.\n", buffer);
- }
-#endif
-
-#ifdef use_jxl_library
- if ((data == null) && (file_exists (string_concatenate (string_copy (buffer, path), ".jxl")) == true)) {
- data = jxl_image_import (buffer, & width, & height);
- }
-#endif
+ data = format_image_import (path, & width, & height);
- fatal_failure (data == null, "opengl_font_import: Unsupported image format.");
+ conditional_print (opengl->very_verbose_spam == true, "/c Importing font '/0/B%s/-' of size %i x %i, in range from (%i) to (%i).\n",
+ path, width, height, begin, end);
- result = opengl_font_raw_import (opengl, data, width, begin, end, colour);
+ result = opengl_font_raw_import (opengl, data, width, height, begin, end, colour);
data = deallocate (data);
return (result);
}
-static u4 opengl_sprite_width (opengl_structure * opengl, u4 sprite) {
- return (opengl->sprite_width [sprite]);
+static natural opengl_sprite_width (opengl_structure * opengl, natural sprite) {
+ return ((sprite >= opengl->sprite_count) ? 0 : opengl->sprite_width [sprite]);
}
-static u4 opengl_sprite_height (opengl_structure * opengl, u4 sprite) {
- return (opengl->sprite_height [sprite]);
+static natural opengl_sprite_height (opengl_structure * opengl, natural sprite) {
+ return ((sprite >= opengl->sprite_count) ? 0 : opengl->sprite_height [sprite]);
}
-static u4 opengl_center_x (opengl_structure * opengl, u4 size) {
- return ((opengl->window_width - size) / 2);
-}
+static natural opengl_character_width (opengl_structure * opengl, character data, natural font, real scale) {
+ if (font == ~ 0u) {
+ font = opengl->font_count - 1;
+ }
-static u4 opengl_center_y (opengl_structure * opengl, u4 size) {
- return ((opengl->window_height - size) / 2);
+ if ((data < opengl->font_begin [font]) || (data > opengl->font_end [font])) {
+ return (0);
+ } else {
+ natural index = opengl->font_index [font] [data - opengl->font_begin [font]];
+
+ return ((natural) (scale * (real) opengl->sprite_width [index]));
+ }
}
-static b4 opengl_cursor_inside (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height) {
- return ((opengl->cursor_x > x) &&
- (opengl->cursor_y > y) &&
- (opengl->cursor_x < x + (int) width) &&
- (opengl->cursor_y < y + (int) height));
+static natural opengl_character_height (opengl_structure * opengl, character data, natural font, real scale) {
+ if (font == ~ 0u) {
+ font = opengl->font_count - 1;
+ }
+
+ if ((data < opengl->font_begin [font]) || (data > opengl->font_end [font])) {
+ return (0);
+ } else {
+ natural index = opengl->font_index [font] [data - opengl->font_begin [font]];
+
+ return ((natural) (scale * (real) opengl->sprite_height [index]));
+ }
}
-static b4 opengl_cursor_left_click (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height) {
- if (opengl->cursor [cursor_left] == true) {
- opengl->freeze_cursor = true;
+static natural opengl_string_width (opengl_structure * opengl, character * string, natural font, real scale) {
+ natural width = 0;
+ natural match = 0;
- return (opengl_cursor_inside (opengl, x, y, width, height) == true);
+ if (string == null) {
+ return (0);
}
- return (false);
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ if (string [index] == '\t') {
+ width += opengl->tab_width * opengl_character_width (opengl, ' ', font, scale);
+ } else if (string [index] == '\n') {
+ match = maximum_macro (width, match);
+ width = 0;
+ } else {
+ width += opengl_character_width (opengl, string [index], font, scale);
+ }
+ }
+
+ return (maximum_macro (width, match));
}
-static b4 opengl_cursor_right_click (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height) {
- if (opengl->cursor [cursor_right]) {
- opengl->freeze_cursor = true;
+static natural opengl_string_height (opengl_structure * opengl, character * string, natural font, real scale) {
+ natural height = opengl_character_height (opengl, ' ', font, scale);
+
+ if ((string == null) || (string [0] == '\0')) {
+ return (0);
+ }
- return (opengl_cursor_inside (opengl, x, y, width, height));
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ if (string [index] == '\n') {
+ height += opengl_character_height (opengl, ' ', font, scale);
+ }
}
- return (false);
+ return (height);
}
-static v0 opengl_import_spritesheet (opengl_structure * opengl, c1 * data_file) {
- s4 file = file_open (data_file, file_flag_read);
+static natural opengl_center_x (opengl_structure * opengl, natural size) {
+ return ((opengl->window_width - size) / 2);
+}
+
+static natural opengl_center_y (opengl_structure * opengl, natural size) {
+ return ((opengl->window_height - size) / 2);
+}
+
+static boolean opengl_cursor_inside (opengl_structure * opengl, integer x, integer y, natural width, natural height) {
+ return ((opengl->cursor_x > x) &&
+ (opengl->cursor_y > y) &&
+ (opengl->cursor_x < x + (integer) width) &&
+ (opengl->cursor_y < y + (integer) height));
+}
+
+static procedure opengl_import_spritesheet (opengl_structure * opengl, character * data_file) {
+ integer file = file_open (data_file, file_flag_read);
fatal_failure (opengl->active == true, "opengl_import_spritesheet: OpenGL renderer is already initialized.");
file_read (file, opengl->font_begin, opengl->font_count * sizeof (* opengl->font_begin));
file_read (file, opengl->font_end, opengl->font_count * sizeof (* opengl->font_end));
- for (u4 index = 0; index < opengl->font_count; ++index) {
- u4 range = (u4) (opengl->font_end [index] - opengl->font_begin [index]) + 1;
+ for (natural index = 0; index < opengl->font_count; ++index) {
+ natural range = (natural) (opengl->font_end [index] - opengl->font_begin [index]) + 1;
opengl->font_index [index] = allocate (range * sizeof (* * opengl->font_index));
opengl->font_width [index] = allocate (range * sizeof (* * opengl->font_width));
opengl->font_height [index] = allocate (range * sizeof (* * opengl->font_height));
- for (u4 subindex = 0; subindex < range; ++subindex) {
+ for (natural subindex = 0; subindex < range; ++subindex) {
file_read (file, & opengl->font_index [index] [subindex], sizeof (* * opengl->font_index));
file_read (file, & opengl->font_width [index] [subindex], sizeof (* * opengl->font_width));
file_read (file, & opengl->font_height [index] [subindex], sizeof (* * opengl->font_height));
opengl->sprite_count = 0;
opengl->font_count = 0;
+
+ print ("/c Imported internal binary data of OpenGL spritesheet.\n");
}
-static v0 opengl_export_spritesheet (opengl_structure * opengl, c1 * data_file) {
- s4 file = file_open (data_file, file_flag_write | file_flag_create | file_flag_truncate);
+static procedure opengl_export_spritesheet (opengl_structure * opengl, character * data_file) {
+ integer file = file_open (data_file, file_flag_write | file_flag_create | file_flag_truncate);
fatal_failure (opengl->spritesheet_data == null, "opengl_export_spritesheet: OpenGL renderer can't access spritesheet data.");
file_write (file, opengl->font_begin, opengl->font_count * sizeof (* opengl->font_begin));
file_write (file, opengl->font_end, opengl->font_count * sizeof (* opengl->font_end));
- for (u4 index = 0; index < opengl->font_count; ++index) {
- for (u4 subindex = 0; subindex < (u4) (opengl->font_end [index] - opengl->font_begin [index]) + 1; ++subindex) {
+ for (natural index = 0; index < opengl->font_count; ++index) {
+ for (natural subindex = 0; subindex < (natural) (opengl->font_end [index] - opengl->font_begin [index]) + 1; ++subindex) {
file_write (file, & opengl->font_index [index] [subindex], sizeof (* * opengl->font_index));
file_write (file, & opengl->font_width [index] [subindex], sizeof (* * opengl->font_width));
file_write (file, & opengl->font_height [index] [subindex], sizeof (* * opengl->font_height));
file = file_close (file);
- print ("/c Exported internal binary data of OpenGL spritesheet.");
-}
-
-static opengl_structure * opengl_initialize (u4 gameplay_framerate, u4 animation_framerate, b4 use_precomputed_spritesheet,
- u4 maximum_quads_on_screen, u4 spritesheet_side) {
- opengl_structure * opengl = allocate (sizeof (* opengl));
-
- opengl->using_precomputed_spritesheet = use_precomputed_spritesheet;
-
- opengl->spritesheet_size = spritesheet_side;
- opengl->gameplay_framerate = gameplay_framerate;
- opengl->animation_framerate = animation_framerate;
- opengl->vertex_limit = maximum_quads_on_screen * 32;
- opengl->index_limit = maximum_quads_on_screen * 6;
- opengl->tab_width = 4;
- opengl->default_font = ~0u;
-
- if (use_precomputed_spritesheet == true) {
- print ("[/0Comment/-] Importing spritesheet image and information...\n");
-
- opengl_import_spritesheet (opengl, "binary/spritesheet.bin");
- }
-
- print ("[/2Success/-] Initialized OpenGL renderer.\n");
-
- return (opengl);
-}
-
-static opengl_structure * opengl_deinitialize (opengl_structure * opengl) {
- opengl->active = false;
-
- for (u4 index = 0; index < opengl->font_count; ++index) {
- opengl->font_index [index] = deallocate (opengl->font_index [index]);
- opengl->font_width [index] = deallocate (opengl->font_width [index]);
- opengl->font_height [index] = deallocate (opengl->font_height [index]);
- }
-
- opengl->font_index = deallocate (opengl->font_index);
- opengl->font_width = deallocate (opengl->font_width);
- opengl->font_height = deallocate (opengl->font_height);
- opengl->font_begin = deallocate (opengl->font_begin);
- opengl->font_end = deallocate (opengl->font_end);
-
- opengl->sprite_width = deallocate (opengl->sprite_width);
- opengl->sprite_height = deallocate (opengl->sprite_height);
- opengl->sprite_u = deallocate (opengl->sprite_u);
- opengl->sprite_v = deallocate (opengl->sprite_v);
-
- if (opengl->using_precomputed_spritesheet == false) {
- opengl->spritesheet_data = deallocate (opengl->spritesheet_data);
- }
-
- opengl->vertex_array = deallocate (opengl->vertex_array);
- opengl->index_array = deallocate (opengl->index_array);
-
- glDeleteTextures (1, & opengl->spritesheet);
-
- opengl->glDeleteProgram (opengl->shader_program);
- opengl->glDeleteShader (opengl->fragment_shader);
- opengl->glDeleteShader (opengl->vertex_shader);
-
- opengl->glDeleteBuffers (1, & opengl->index_buffer);
- opengl->glDeleteBuffers (1, & opengl->vertex_buffer);
- opengl->glDeleteVertexArrays (1, & opengl->vertex_object);
-
- glfwDestroyWindow (opengl->window);
-
- glfwTerminate ();
-
- print ("[/2Success/-] Deinitialized OpenGL renderer.\n");
-
- return (deallocate (opengl));
+ print ("/c Exported internal binary data of OpenGL spritesheet.\n");
}
-static v0 opengl_configure (opengl_structure * opengl, u4 window_width, u4 window_height, c1 * window_title) {
- u8 font_bitmap [190] = {
+static procedure opengl_configure (opengl_structure * opengl, natural window_width, natural window_height, character * window_title) {
+ natural_64 font_bitmap [190] = {
0x0000000000000000, 0x0000000000000000, 0x0000101010101010, 0x1000101000000000, 0x0024242400000000, 0x0000000000000000,
0x00002424247e2424, 0x7e24242400000000, 0x0010107c9290907c, 0x1212927c10100000, 0x0000649468081010, 0x202c524c00000000,
0x000018242418304a, 0x4444443a00000000, 0x0010101000000000, 0x0000000000000000, 0x0000081020202020, 0x2020100800000000,
0x0000300808080408, 0x0808083000000000, 0x000000000062928c, 0x0000000000000000
};
- c1 * vertex_shader =
- "# version 330 core\n"
+ const character * vertex_shader =
+ "#version 330 core\n"
"in vec2 vertex_xy;\n"
"in vec2 vertex_uv;\n"
"in vec4 vertex_rgba;\n"
"out vec2 fragment_uv;\n"
"out vec4 fragment_rgba;\n"
- "v0 main () {\n"
- " gl_Position = vec4 (vertex_xy, 0, 1);\n"
- " fragment_uv = vertex_uv;\n"
- " fragment_rgba = vertex_rgba;\n"
+ "void main () {\n"
+ " gl_Position = vec4 (vertex_xy, 0, 1);\n"
+ " fragment_uv = vertex_uv;\n"
+ " fragment_rgba = vertex_rgba;\n"
"}\n";
- c1 * fragment_shader =
- "# version 330 core\n"
+ const character * fragment_shader =
+ "#version 330 core\n"
"uniform sampler2D texture_p;\n"
"in vec2 fragment_uv;\n"
"in vec4 fragment_rgba;\n"
"out vec4 data;\n"
- "v0 main () {\n"
- " data = texture (texture_p, fragment_uv) * fragment_rgba;\n"
+ "void main () {\n"
+ " data = texture (texture_p, fragment_uv) * fragment_rgba;\n"
"}\n";
- u4 * dumb_buffer = null;
- u4 * order = null;
+ natural * dumb_buffer = null;
+ natural * order = null;
- u4 xy_attribute = 0;
- u4 uv_attribute = 0;
- u4 rgba_attribute = 0;
- //~u4 flags = 0;
+ natural xy_attribute = 0;
+ natural uv_attribute = 0;
+ natural rgba_attribute = 0;
- u4 u = 0;
- u4 v = 0;
+ natural u = 0;
+ natural v = 0;
+
+ integer status = GL_NO_ERROR;
if (opengl->using_precomputed_spritesheet == true) {
- for (u4 index = 0; index < 95; ++index) {
+ for (natural index = 0; index < 95; ++index) {
opengl->font_index [opengl->font_count] [index] = ++opengl->sprite_count - 1;
}
++opengl->sprite_count;
++opengl->font_count;
+ print ("[/0Comment/-] Importing spritesheet image and information...\n");
+
+ opengl_import_spritesheet (opengl, "binary/spritesheet.bin");
+
goto ignore_import;
}
dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
- for (u4 index = 0; index < 256; ++index) {
+ for (natural index = 0; index < 256; ++index) {
dumb_buffer [index] = 0xffffffff;
}
- ++opengl->font_count;
-
- u4 current = opengl->font_count - 1;
+ natural current = ++opengl->font_count - 1;
opengl->font_index = reallocate (opengl->font_index, opengl->font_count * sizeof (* opengl->font_index));
opengl->font_width = reallocate (opengl->font_width, opengl->font_count * sizeof (* opengl->font_width));
opengl->font_begin = reallocate (opengl->font_begin, opengl->font_count * sizeof (* opengl->font_begin));
opengl->font_end = reallocate (opengl->font_end, opengl->font_count * sizeof (* opengl->font_end));
- opengl->font_begin [opengl->font_count - 1] = ' ';
- opengl->font_end [opengl->font_count - 1] = '~';
+ opengl->font_begin [current] = ' ';
+ opengl->font_end [current] = '~';
- opengl->font_index [opengl->font_count - 1] = allocate (95 * sizeof (* * opengl->font_index));
- opengl->font_width [opengl->font_count - 1] = allocate (95 * sizeof (* * opengl->font_width));
- opengl->font_height [opengl->font_count - 1] = allocate (95 * sizeof (* * opengl->font_height));
+ opengl->font_index [current] = allocate (95 * sizeof (* * opengl->font_index));
+ opengl->font_width [current] = allocate (95 * sizeof (* * opengl->font_width));
+ opengl->font_height [current] = allocate (95 * sizeof (* * opengl->font_height));
- for (u4 index = 0; index < 95; ++index) {
- u4 * buffer = allocate (opengl_font_width * opengl_font_height * sizeof (* buffer));
+ for (natural index = 0; index < 95; ++index) {
+ natural * buffer = allocate (opengl_font_width * opengl_font_height * sizeof (* buffer));
- for (u4 value = 0; value < 2; ++value) {
- for (u4 bit = 64; bit > 0; --bit) {
- u4 destination = ((value << 3) - ((bit - 1) >> 3) + 7) * opengl_font_width - ((bit - 1) & 7) + 7;
- u4 source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
+ for (natural value = 0; value < 2; ++value) {
+ for (natural bit = 64; bit > 0; --bit) {
+ natural destination = ((value << 3) - ((bit - 1) >> 3) + 7) * opengl_font_width - ((bit - 1) & 7) + 7;
+ natural source = (font_bitmap [2 * index + value] >> (bit - 1)) & 1;
buffer [destination] = (source) ? 0xffffffff : 0x00000000;
}
order = allocate (opengl->sprite_count * sizeof (* order));
- for (u4 index = 0; index < opengl->sprite_count; ++index) {
+ for (natural index = 0; index < opengl->sprite_count; ++index) {
order [index] = index;
}
- for (u4 index = 0; index < opengl->sprite_count; ++index) {
- for (u4 subindex = 0; subindex < opengl->sprite_count; ++subindex) {
+ for (natural index = 0; index < opengl->sprite_count; ++index) {
+ for (natural subindex = 0; subindex < opengl->sprite_count; ++subindex) {
if (opengl->sprite_height [order [index]] < opengl->sprite_height [order [subindex]]) {
- u4 temporary = order [index];
-
- order [index] = order [subindex];
- order [subindex] = temporary;
+ exchange_natural (& order [index], & order [subindex]);
}
}
}
- for (u4 index = 0; index < opengl->sprite_count; ++index) {
+ for (natural index = 0; index < opengl->sprite_count; ++index) {
if (u + opengl->sprite_width [order [index]] >= opengl->spritesheet_size) {
u *= 0;
v += opengl->sprite_height [order [index]];
}
- opengl->sprite_u [order [index]] = (float) u / (float) opengl->spritesheet_size;
- opengl->sprite_v [order [index]] = (float) v / (float) opengl->spritesheet_size;
+ opengl->sprite_u [order [index]] = (real) u / (real) opengl->spritesheet_size;
+ opengl->sprite_v [order [index]] = (real) v / (real) opengl->spritesheet_size;
- for (u4 y = 0; y < opengl->sprite_height [order [index]]; ++y) {
- for (u4 x = 0; x < opengl->sprite_width [order [index]]; ++x) {
- u4 destination = (v + y) * opengl->spritesheet_size + (u + x);
- u4 source = y * opengl->sprite_width [order [index]] + x;
+ for (natural y = 0; y < opengl->sprite_height [order [index]]; ++y) {
+ for (natural x = 0; x < opengl->sprite_width [order [index]]; ++x) {
+ natural destination = (v + y) * opengl->spritesheet_size + (u + x);
+ natural source = y * opengl->sprite_width [order [index]] + x;
opengl->spritesheet_data [destination] = opengl->sprite_data [order [index]] [source];
}
}
opengl->sprite_data = deallocate (opengl->sprite_data);
- order = deallocate (order);
+ order = deallocate (order);
ignore_import:
opengl->window_width = window_width;
opengl->window_height = window_height;
- opengl->pixel_width = 2.0f / (float) window_width;
- opengl->pixel_height = 2.0f / (float) window_height;
-
- //~if (window_flags == 0) {
- //~flags = opengl_window_decorated | opengl_window_resizable;
- //~} else {
- //~flags = window_flags;
- //~}
+ opengl->pixel_width = 2.0f / (real) window_width;
+ opengl->pixel_height = 2.0f / (real) window_height;
glfwInit ();
- glfwWindowHs4 (GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHs4 (GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHs4 (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHs4 (GLFW_OPENGL_FORWARD_COMPAT, 1);
-
- opengl->window = glfwCreateWindow ((int) window_width, (int) window_height, window_title, null, null);
+ glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
+ glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, 1);
- glfwSetWindowSizeLimits (opengl->window, 320, 240, 1920, 1080);
+ opengl->window = glfwCreateWindow ((integer) window_width, (integer) window_height, window_title, null, null);
fatal_failure (opengl->window == null, "Failed to create GLFW window.\n");
+ glfwSetWindowSizeLimits (opengl->window, 320, 240, 1920, 1080); /// REDO
+
glfwMakeContextCurrent (opengl->window);
opengl->glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) glfwGetProcAddress ("glGenVertexArrays");
opengl->glDeleteProgram = (PFNGLDELETEPROGRAMPROC) glfwGetProcAddress ("glDeleteProgram");
opengl->glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) glfwGetProcAddress ("glGetUniformLocation");
opengl->glBufferData = (PFNGLBUFFERDATAPROC) glfwGetProcAddress ("glBufferData");
+ opengl->glGetShaderiv = (PFNGLGETSHADERIVPROC) glfwGetProcAddress ("glGetShaderiv");
+ opengl->glGetProgramiv = (PFNGLGETPROGRAMIVPROC) glfwGetProcAddress ("glGetProgramiv");
- glViewport (0, 0, (int) window_width, (int) window_height);
+ glViewport (0, 0, (integer) window_width, (integer) window_height);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glEnable (GL_CULL_FACE);
- glEnable (GL_BLEND);
+ conditional_print ((status = glGetError ()) != GL_NO_ERROR, "/f Failed to set OpenGL viewport dimensions: %i\n", status);
opengl->glGenVertexArrays (1, & opengl->vertex_object);
opengl->glBindVertexArray (opengl->vertex_object);
+ conditional_print ((status = glGetError ()) != GL_NO_ERROR, "/f Failed to generate and bind OpenGL vertex array object: %i\n", status);
+
opengl->glGenBuffers (1, & opengl->vertex_buffer);
opengl->glBindBuffer (GL_ARRAY_BUFFER, opengl->vertex_buffer);
+ conditional_print ((status = glGetError ()) != GL_NO_ERROR, "/f Failed to generate and bind OpenGL vertex buffer object: %i\n", status);
+
opengl->glGenBuffers (1, & opengl->index_buffer);
opengl->glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, opengl->index_buffer);
+ conditional_print ((status = glGetError ()) != GL_NO_ERROR, "/f Failed to generate and bind OpenGL index buffer object: %i\n", status);
+
opengl->vertex_shader = opengl->glCreateShader (GL_VERTEX_SHADER);
+ conditional_print (opengl->vertex_shader == 0, "/f Failed to create OpenGL vertex shader: %i\n", glGetError ());
+
opengl->glShaderSource (opengl->vertex_shader, 1, & vertex_shader, null);
opengl->glCompileShader (opengl->vertex_shader);
+ opengl->glGetShaderiv (opengl->vertex_shader, GL_COMPILE_STATUS, & status);
+
+ conditional_print (status == GL_FALSE, "/f Failed to compile OpenGL vertex shader: %i\n", status);
+
opengl->fragment_shader = opengl->glCreateShader (GL_FRAGMENT_SHADER);
+ conditional_print (opengl->fragment_shader == 0, "/f Failed to create OpenGL fragment shader: %i\n", glGetError ());
+
opengl->glShaderSource (opengl->fragment_shader, 1, & fragment_shader, null);
opengl->glCompileShader (opengl->fragment_shader);
+ opengl->glGetShaderiv (opengl->fragment_shader, GL_COMPILE_STATUS, & status);
+
+ conditional_print (status == GL_FALSE, "/f Failed to compile OpenGL fragment shader: %i\n", status);
+
opengl->shader_program = opengl->glCreateProgram ();
+ conditional_print (opengl->shader_program == 0, "/f Failed to create OpenGL shader program: /1%i/-.\n", glGetError ());
+
opengl->glAttachShader (opengl->shader_program, opengl->vertex_shader);
opengl->glAttachShader (opengl->shader_program, opengl->fragment_shader);
opengl->glBindFragDataLocation (opengl->shader_program, 0, "data");
opengl->glLinkProgram (opengl->shader_program);
- opengl->glUseProgram (opengl->shader_program);
- xy_attribute = (u4) opengl->glGetAttribLocation (opengl->shader_program, "vertex_xy");
+ opengl->glGetProgramiv (opengl->shader_program, GL_LINK_STATUS, & status);
+
+ conditional_print (status == GL_FALSE, "/f Failed to link OpenGL shader program: %i\n", status);
+
+ opengl->glUseProgram (opengl->shader_program);
+ ///////////////////
+ status = glGetError (); if (status != GL_NO_ERROR) printf (">>> using %i\n", status);
+
+ xy_attribute = (natural) opengl->glGetAttribLocation (opengl->shader_program, "vertex_xy");
opengl->glEnableVertexAttribArray (xy_attribute);
- opengl->glVertexAttribPointer (xy_attribute, 2, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (v0 *) 0);
+ opengl->glVertexAttribPointer (xy_attribute, 2, GL_FLOAT, GL_FALSE, 8 * sizeof (real), (procedure *) 0);
- uv_attribute = (u4) opengl->glGetAttribLocation (opengl->shader_program, "vertex_uv");
+ uv_attribute = (natural) opengl->glGetAttribLocation (opengl->shader_program, "vertex_uv");
opengl->glEnableVertexAttribArray (uv_attribute);
- opengl->glVertexAttribPointer (uv_attribute, 2, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (v0 *) (2 * sizeof (float)));
+ opengl->glVertexAttribPointer (uv_attribute, 2, GL_FLOAT, GL_FALSE, 8 * sizeof (real), (procedure *) (2 * sizeof (real)));
- rgba_attribute = (u4) opengl->glGetAttribLocation (opengl->shader_program, "vertex_rgba");
+ rgba_attribute = (natural) opengl->glGetAttribLocation (opengl->shader_program, "vertex_rgba");
opengl->glEnableVertexAttribArray (rgba_attribute);
- opengl->glVertexAttribPointer (rgba_attribute, 4, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (v0 *) (4 * sizeof (float)));
+ opengl->glVertexAttribPointer (rgba_attribute, 4, GL_FLOAT, GL_FALSE, 8 * sizeof (real), (procedure *) (4 * sizeof (real)));
+
+ if (glGetError () != GL_NO_ERROR) printf (">>> texture+\n");
opengl->vertex_array = allocate (opengl->vertex_limit * sizeof (opengl->vertex_array));
opengl->index_array = allocate (opengl->index_limit * sizeof (opengl->index_array));
opengl->glUniform1i (opengl->glGetUniformLocation (opengl->shader_program, "texture_p"), 0);
+ if (glGetError () != GL_NO_ERROR) printf (">>> texture-\n");
+
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
opengl->spritesheet_data = deallocate (opengl->spritesheet_data);
}
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glEnable (GL_CULL_FACE);
+ glEnable (GL_BLEND);
+
opengl->active = true;
opengl->frame_begin = nano_time ();
glClear (GL_COLOR_BUFFER_BIT);
- print ("[/2Success/-] Configured OpenGL renderer.\n");
-}
+ if (glGetError () != GL_NO_ERROR) printf (">>> done\n");
-static v0 opengl_synchronize (opengl_structure * opengl, u4 colour) {
- s4 signal_code [signal_count] = {
- 0,
- GLFW_KEY_A, GLFW_KEY_B, GLFW_KEY_C, GLFW_KEY_D,
- GLFW_KEY_E, GLFW_KEY_F, GLFW_KEY_G, GLFW_KEY_H,
- GLFW_KEY_I, GLFW_KEY_J, GLFW_KEY_K, GLFW_KEY_L,
- GLFW_KEY_M, GLFW_KEY_N, GLFW_KEY_O, GLFW_KEY_P,
- GLFW_KEY_Q, GLFW_KEY_R, GLFW_KEY_S, GLFW_KEY_T,
- GLFW_KEY_U, GLFW_KEY_V, GLFW_KEY_W, GLFW_KEY_X,
- GLFW_KEY_Y, GLFW_KEY_Z, GLFW_KEY_0, GLFW_KEY_1,
- GLFW_KEY_2, GLFW_KEY_3, GLFW_KEY_4, GLFW_KEY_5,
- GLFW_KEY_6, GLFW_KEY_7, GLFW_KEY_8, GLFW_KEY_9,
- GLFW_KEY_ESCAPE, GLFW_KEY_TAB, GLFW_KEY_ENTER, GLFW_KEY_ENTER,
- GLFW_KEY_SLASH, GLFW_KEY_BACKSLASH, GLFW_KEY_SEMICOLON, GLFW_KEY_GRAVE_ACCENT,
- GLFW_KEY_SPACE, GLFW_KEY_BACKSPACE, GLFW_KEY_PERIOD, GLFW_KEY_COMMA,
- GLFW_KEY_APOSTROPHE, GLFW_KEY_CAPS_LOCK, GLFW_KEY_MINUS, GLFW_KEY_EQUAL,
- GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_LEFT_CONTROL, GLFW_KEY_RIGHT_CONTROL,
- GLFW_KEY_LEFT_SHIFT, GLFW_KEY_RIGHT_SHIFT, GLFW_KEY_LEFT_ALT, GLFW_KEY_RIGHT_ALT,
- GLFW_KEY_F1, GLFW_KEY_F2, GLFW_KEY_F3, GLFW_KEY_F4,
- GLFW_KEY_F5, GLFW_KEY_F6, GLFW_KEY_F7, GLFW_KEY_F8,
- GLFW_KEY_F9, GLFW_KEY_F10, GLFW_KEY_F11, GLFW_KEY_F12,
- GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT,
- GLFW_KEY_NUM_LOCK, GLFW_KEY_PAUSE, GLFW_KEY_INSERT, GLFW_KEY_HOME,
- GLFW_KEY_PAGE_UP, GLFW_KEY_DELETE, GLFW_KEY_END, GLFW_KEY_PAGE_DOWN,
- GLFW_KEY_KP_ADD, GLFW_KEY_KP_SUBTRACT, GLFW_KEY_KP_MULTIPLY, GLFW_KEY_KP_DIVIDE,
- GLFW_KEY_KP_ENTER, GLFW_KEY_KP_DECIMAL, GLFW_KEY_KP_0, GLFW_KEY_KP_1,
- GLFW_KEY_KP_2, GLFW_KEY_KP_3, GLFW_KEY_KP_4, GLFW_KEY_KP_5,
- GLFW_KEY_KP_6, GLFW_KEY_KP_7, GLFW_KEY_KP_8, GLFW_KEY_KP_9
- };
-
- f4 r = (float) ((colour >> 24) & 0xff) / 255.0f;
- f4 g = (float) ((colour >> 16) & 0xff) / 255.0f;
- f4 b = (float) ((colour >> 8) & 0xff) / 255.0f;
- f4 a = (float) ((colour >> 0) & 0xff) / 255.0f;
-
- s4 new_window_width = 0;
- s4 new_window_height = 0;
-
- glClearColor (r, g, b, a);
-
- glClear (GL_COLOR_BUFFER_BIT);
-
- glfwPollEvents ();
-
- glfwSetWindowShouldClose (opengl->window, opengl->active == false);
-
- glfwGetWindowSize (opengl->window, & new_window_width, & new_window_height);
-
- if ((opengl->window_width != (u4) new_window_width) || (opengl->window_height != (u4) new_window_height)) {
- if ((new_window_width <= 0) || (new_window_height <= 0)) return;
-
- glViewport (0, 0, new_window_width, new_window_height);
-
- opengl->window_width = (u4) new_window_width;
- opengl->window_height = (u4) new_window_height;
-
- opengl->pixel_width = 2.0f / (float) new_window_width;
- opengl->pixel_height = 2.0f / (float) new_window_height;
- }
-
- opengl->cursor [cursor_left] = (b4) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
- opengl->cursor [cursor_middle] = (b4) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
- opengl->cursor [cursor_right] = (b4) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
-
- if (opengl->freeze_cursor == false) {
- f8 x = 0.0;
- f8 y = 0.0;
-
- glfwGetCursorPos (opengl->window, & x, & y);
-
- opengl->cursor_x = (int) x;
- opengl->cursor_y = (int) y;
-
- //~if ((opengl->cursor_x < 0) || (opengl->cursor_x > (int) opengl->window_width) ||
- //~(opengl->cursor_y < 0) || (opengl->cursor_y > (int) opengl->window_height)) {
- //~opengl->cursor_x = 0;
- //~opengl->cursor_y = 0;
- //~}
- } else {
- if ((opengl->cursor [cursor_left] == false)
- && (opengl->cursor [cursor_middle] == false)
- && (opengl->cursor [cursor_right] == false)) {
- opengl->freeze_cursor = false;
- }
- }
-
- if (opengl->freeze_signal == false) {
- for (u4 index = 0; index < signal_count; ++index) {
- opengl->signal [index] = (b4) (glfwGetKey (opengl->window, signal_code [index]) == GLFW_PRESS);
- }
- }
-
- opengl->glBufferData (GL_ARRAY_BUFFER, opengl->vertex_count * 4, opengl->vertex_array, GL_DYNAMIC_DRAW);
- opengl->glBufferData (GL_ELEMENT_ARRAY_BUFFER, opengl->index_count * 4, opengl->index_array, GL_DYNAMIC_DRAW);
-
- opengl->glBindBuffer (GL_ARRAY_BUFFER, opengl->vertex_buffer);
-
- glDrawElements (GL_TRIANGLES, (int) opengl->index_count * 4, GL_UNSIGNED_INT, null);
-
- glfwSwapBuffers (opengl->window);
-
- opengl->vertex_count = 0;
- opengl->index_count = 0;
-
- opengl->frame_end = nano_time ();
-
- opengl->frame_time = opengl->frame_end - opengl->frame_begin;
-
- if (opengl->frame_time < 1000000000ul / opengl->gameplay_framerate) {
- nano_wait (1000000000ul / opengl->gameplay_framerate - opengl->frame_time);
- }
-
- if (opengl->global_tick % opengl->gameplay_framerate == 0) {
- opengl->framerate = (u4) (1000000000ul / opengl->frame_time);
- }
-
- ++opengl->global_tick;
-
- opengl->global_tick = opengl->global_tick % (opengl->gameplay_framerate * opengl->animation_framerate);
- opengl->gameplay_tick = opengl->global_tick % (opengl->gameplay_framerate);
- opengl->animation_tick = opengl->global_tick / (opengl->gameplay_framerate / opengl->animation_framerate);
-
- opengl->frame_begin = nano_time ();
+ print ("/s Configured OpenGL renderer.\n");
}
-static v0 opengl_render_base (opengl_structure * opengl, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height,
- f4 scale_x, f4 scale_y, s4 flip_x, s4 flip_y,
- u4 colour_upper_left, u4 colour_upper_right, u4 colour_lower_left, u4 colour_lower_right) {
- f4 screen_x = 0.0f;
- f4 screen_y = 0.0f;
- f4 unwrap_x = 0.0f;
- f4 unwrap_y = 0.0f;
- f4 screen_width = 0.0f;
- f4 screen_height = 0.0f;
- f4 unwrap_width = 0.0f;
- f4 unwrap_height = 0.0f;
-
- if ((x > (int) opengl->window_width) || (y > (int) opengl->window_height)) return;
-
- if ((x < (int) - ((float) width * scale_x)) || (y < (int) - ((float) height * scale_y))) return;
+static procedure opengl_render_base (opengl_structure * opengl, natural sprite, integer x, integer y, natural u, natural v, natural width,
+ natural height, real scale_x, real scale_y, integer flip_x, integer flip_y, natural colour_upper_left,
+ natural colour_upper_right, natural colour_lower_left, natural colour_lower_right) {
+ if ((x > (integer) opengl->window_width) || (x < (integer) - ((real) width * scale_x))) return;
+ if ((y > (integer) opengl->window_height) || (y < (integer) - ((real) height * scale_y))) return;
- if (sprite >= opengl->sprite_count) return;
- if (opengl->vertex_count + 32 >= opengl->vertex_limit) return;
- if (opengl->index_count + 6 >= opengl->index_limit) return;
+ fatal_failure (sprite >= opengl->sprite_count, "Not rendering, sprite out of range.");
+ fatal_failure (opengl->vertex_count + 32 >= opengl->vertex_limit, "Not rendering, not enough vertex space.");
+ fatal_failure (opengl->index_count + 6 >= opengl->index_limit, "Not rendering, not enough index space.");
- screen_x = + ((float) x * opengl->pixel_width - 1);
- screen_y = - ((float) y * opengl->pixel_height - 1);
+ real screen_x = + ((real) x * opengl->pixel_width - 1.0f);
+ real screen_y = - ((real) y * opengl->pixel_height - 1.0f);
- unwrap_x = opengl->sprite_u [sprite] + (float) u / (float) opengl->spritesheet_size;
- unwrap_y = opengl->sprite_v [sprite] + (float) v / (float) opengl->spritesheet_size;
+ real screen_width = + ((real) width * opengl->pixel_width * scale_x);
+ real screen_height = - ((real) height * opengl->pixel_height * scale_y);
- screen_width = +((float) width * opengl->pixel_width * scale_x);
- screen_height = -((float) height * opengl->pixel_height * scale_y);
+ real unwrap_x = opengl->sprite_u [sprite] + (real) u / (real) opengl->spritesheet_size;
+ real unwrap_y = opengl->sprite_v [sprite] + (real) v / (real) opengl->spritesheet_size;
- unwrap_width = (float) width / (float) opengl->spritesheet_size;
- unwrap_height = (float) height / (float) opengl->spritesheet_size;
+ real unwrap_width = (real) width / (real) opengl->spritesheet_size;
+ real unwrap_height = (real) height / (real) opengl->spritesheet_size;
opengl->vertex_array [opengl->vertex_count + 0] = screen_x;
opengl->vertex_array [opengl->vertex_count + 1] = screen_y;
- opengl->vertex_array [opengl->vertex_count + 2] = unwrap_x + unwrap_width * (float) (flip_y != 0);
- opengl->vertex_array [opengl->vertex_count + 3] = unwrap_y + unwrap_height * (float) (flip_x != 0);
+ opengl->vertex_array [opengl->vertex_count + 2] = unwrap_x + unwrap_width * (real) (flip_y != 0);
+ opengl->vertex_array [opengl->vertex_count + 3] = unwrap_y + unwrap_height * (real) (flip_x != 0);
opengl->vertex_array [opengl->vertex_count + 4] = normal_r (colour_upper_left);
opengl->vertex_array [opengl->vertex_count + 5] = normal_g (colour_upper_left);
opengl->vertex_array [opengl->vertex_count + 6] = normal_b (colour_upper_left);
opengl->vertex_array [opengl->vertex_count + 8] = screen_x + screen_width;
opengl->vertex_array [opengl->vertex_count + 9] = screen_y;
- opengl->vertex_array [opengl->vertex_count + 10] = unwrap_x + unwrap_width * (float) (flip_y == 0);
- opengl->vertex_array [opengl->vertex_count + 11] = unwrap_y + unwrap_height * (float) (flip_x != 0);
+ opengl->vertex_array [opengl->vertex_count + 10] = unwrap_x + unwrap_width * (real) (flip_y == 0);
+ opengl->vertex_array [opengl->vertex_count + 11] = unwrap_y + unwrap_height * (real) (flip_x != 0);
opengl->vertex_array [opengl->vertex_count + 12] = normal_r (colour_upper_right);
opengl->vertex_array [opengl->vertex_count + 13] = normal_g (colour_upper_right);
opengl->vertex_array [opengl->vertex_count + 14] = normal_b (colour_upper_right);
opengl->vertex_array [opengl->vertex_count + 16] = screen_x;
opengl->vertex_array [opengl->vertex_count + 17] = screen_y + screen_height;
- opengl->vertex_array [opengl->vertex_count + 18] = unwrap_x + unwrap_width * (float) (flip_y != 0);
- opengl->vertex_array [opengl->vertex_count + 19] = unwrap_y + unwrap_height * (float) (flip_x == 0);
+ opengl->vertex_array [opengl->vertex_count + 18] = unwrap_x + unwrap_width * (real) (flip_y != 0);
+ opengl->vertex_array [opengl->vertex_count + 19] = unwrap_y + unwrap_height * (real) (flip_x == 0);
opengl->vertex_array [opengl->vertex_count + 20] = normal_r (colour_lower_left);
opengl->vertex_array [opengl->vertex_count + 21] = normal_g (colour_lower_left);
opengl->vertex_array [opengl->vertex_count + 22] = normal_b (colour_lower_left);
opengl->vertex_array [opengl->vertex_count + 24] = screen_x + screen_width;
opengl->vertex_array [opengl->vertex_count + 25] = screen_y + screen_height;
- opengl->vertex_array [opengl->vertex_count + 26] = unwrap_x + unwrap_width * (float) (flip_y == 0);
- opengl->vertex_array [opengl->vertex_count + 27] = unwrap_y + unwrap_height * (float) (flip_x == 0);
+ opengl->vertex_array [opengl->vertex_count + 26] = unwrap_x + unwrap_width * (real) (flip_y == 0);
+ opengl->vertex_array [opengl->vertex_count + 27] = unwrap_y + unwrap_height * (real) (flip_x == 0);
opengl->vertex_array [opengl->vertex_count + 28] = normal_r (colour_lower_right);
opengl->vertex_array [opengl->vertex_count + 29] = normal_g (colour_lower_right);
opengl->vertex_array [opengl->vertex_count + 30] = normal_b (colour_lower_right);
opengl->vertex_array [opengl->vertex_count + 31] = normal_a (colour_lower_right);
- opengl->index_array [opengl->index_count + 0] = (opengl->vertex_count / 8) + 2;
- opengl->index_array [opengl->index_count + 1] = (opengl->vertex_count / 8) + 1;
- opengl->index_array [opengl->index_count + 2] = (opengl->vertex_count / 8) + 0;
- opengl->index_array [opengl->index_count + 3] = (opengl->vertex_count / 8) + 1;
- opengl->index_array [opengl->index_count + 4] = (opengl->vertex_count / 8) + 2;
- opengl->index_array [opengl->index_count + 5] = (opengl->vertex_count / 8) + 3;
+ opengl->index_array [opengl->index_count + 0] = opengl->vertex_count / 8 + 2;
+ opengl->index_array [opengl->index_count + 1] = opengl->vertex_count / 8 + 1;
+ opengl->index_array [opengl->index_count + 2] = opengl->vertex_count / 8 + 0;
+ opengl->index_array [opengl->index_count + 3] = opengl->vertex_count / 8 + 1;
+ opengl->index_array [opengl->index_count + 4] = opengl->vertex_count / 8 + 2;
+ opengl->index_array [opengl->index_count + 5] = opengl->vertex_count / 8 + 3;
opengl->vertex_count += 32;
opengl->index_count += 6;
}
-static v0 opengl_render_rectangle (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height, u4 colour) {
- opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16.0f, (float) height / 16.0f, 0, 0,
+static procedure opengl_render_rectangle (opengl_structure * opengl, integer x, integer y, natural width, natural height, natural colour) {
+ opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16.0f, (real) height / 16.0f, 0, 0,
colour, colour, colour, colour);
}
-static v0 opengl_render_rectangle_vertical_gradient (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height,
- u4 colour_up, u4 colour_down) {
- opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16.0f, (float) height / 16.0f, 0, 0,
+static procedure opengl_render_rectangle_vertical_gradient (opengl_structure * opengl, integer x, integer y, natural width, natural height,
+ natural colour_up, natural colour_down) {
+ opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16.0f, (real) height / 16.0f, 0, 0,
colour_up, colour_up, colour_down, colour_down);
}
-static v0 opengl_render_rectangle_horizontal_gradient (opengl_structure * opengl, s4 x, s4 y, u4 width, u4 height,
- u4 colour_left, u4 colour_right) {
- opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16.0f, (float) height / 16.0f, 0, 0,
+static procedure opengl_render_rectangle_horizontal_gradient (opengl_structure * opengl, integer x, integer y, natural width, natural height,
+ natural colour_left, natural colour_right) {
+ opengl_render_base (opengl, opengl->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16.0f, (real) height / 16.0f, 0, 0,
colour_left, colour_right, colour_left, colour_right);
}
-static v0 opengl_render_sprite (opengl_structure * opengl, u4 sprite, s4 x, s4 y) {
+static procedure opengl_render_sprite (opengl_structure * opengl, natural sprite, integer x, integer y) {
opengl_render_base (opengl, sprite, x, y, 0, 0, opengl->sprite_width [sprite], opengl->sprite_height [sprite], 1.0f, 1.0f, 0, 0,
0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 opengl_render_sprite_crop (opengl_structure * opengl, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
- opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
+static procedure opengl_render_sprite_scale (opengl_structure * opengl, natural sprite, integer x, integer y, real scale_x, real scale_y) {
+ opengl_render_base (opengl, sprite, x, y, 0, 0, opengl->sprite_width [sprite], opengl->sprite_height [sprite], scale_x, scale_y, 0, 0,
+ 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 opengl_render_sprite_flip (opengl_structure * opengl, u4 sprite, s4 x, s4 y, s4 flip_x, s4 flip_y) {
- opengl_render_base (opengl, sprite, x, y, 0, 0, opengl->sprite_width [sprite], opengl->sprite_height [sprite], 1.0f, 1.0f,
- flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
+static procedure opengl_render_sprite_crop (opengl_structure * opengl, natural sprite, integer x, integer y, natural u, natural v,
+ natural width, natural height) {
+ opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static v0 opengl_render_sprite_colour (opengl_structure * opengl, u4 sprite, s4 x, s4 y, u4 colour) {
+static procedure opengl_render_sprite_colour (opengl_structure * opengl, natural sprite, integer x, integer y, natural colour) {
opengl_render_base (opengl, sprite, x, y, 0, 0, opengl->sprite_width [sprite], opengl->sprite_height [sprite], 1.0f, 1.0f, 0, 0,
colour, colour, colour, colour);
}
-static v0 opengl_render_sprite_control (opengl_structure * opengl, u4 sprite, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height,
- s4 flip_x, s4 flip_y) {
- opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
-}
-
-static v0 opengl_render_sprite_crop_colour (opengl_structure * opengl, u4 sprite, u4 colour, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
- opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, colour, colour, colour, colour);
-}
-
-static v0 opengl_render_sprite_animate (opengl_structure * opengl, u4 sprite, s4 x, s4 y, u4 frames, u4 state, u4 states) {
- u4 width = opengl->sprite_width [sprite] / states;
- u4 height = opengl->sprite_height [sprite] / frames;
- u4 u = width * (state % states);
- u4 v = height * (opengl->animation_tick % frames);
-
- opengl_render_sprite_crop (opengl, sprite, x, y, u, v, width, height);
-}
-
-static u4 opengl_render_character_width (opengl_structure * opengl, c1 character, u4 font, f4 scale) {
- if ((character < opengl->font_begin [font]) || (character > opengl->font_end [font])) {
- return (0);
- } else {
- u4 index = opengl->font_index [font] [character - opengl->font_begin [font]];
-
- return ((u4) (scale * (float) opengl->sprite_width [index]));
- }
+static procedure opengl_render_sprite_flip (opengl_structure * opengl, natural sprite, integer x, integer y, integer flip_x, integer flip_y) {
+ opengl_render_base (opengl, sprite, x, y, 0, 0, opengl->sprite_width [sprite], opengl->sprite_height [sprite], 1.0f, 1.0f,
+ flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu);
}
-static u4 opengl_render_character_height (opengl_structure * opengl, c1 character, u4 font, f4 scale) {
- if ((character < opengl->font_begin [font]) || (character > opengl->font_end [font])) {
- return (0);
- } else {
- u4 index = opengl->font_index [font] [character - opengl->font_begin [font]];
-
- return ((u4) (scale * (float) opengl->sprite_height [index]));
- }
+static procedure opengl_render_sprite_orient (opengl_structure * opengl, natural sprite, integer x, integer y, natural u, natural v,
+ natural width, natural height, integer flip_x, integer flip_y) {
+ opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, flip_x, flip_y, 0xffffffffu, 0xffffffffu, 0xffffffffu,
+ 0xffffffffu);
}
-static u4 opengl_render_string_width (opengl_structure * opengl, c1 * string, u4 font, f4 scale) {
- u4 width = 0;
- u4 match = 0;
+static procedure opengl_render_sprite_animation (opengl_structure * opengl, natural sprite, integer x, integer y, natural frames, natural state,
+ natural states) {
+ natural width = opengl->sprite_width [sprite] / states;
+ natural height = opengl->sprite_height [sprite] / frames;
- if (string == null) {
- return (0);
- }
-
- for (u4 index = 0; string [index] != '\0'; ++index) {
- if (string [index] == '\t') {
- width += opengl->tab_width * opengl_render_character_width (opengl, ' ', font, scale);
- } else if (string [index] == '\n') {
- match = maximum (width, match);
- width = 0;
- } else {
- width += opengl_render_character_width (opengl, string [index], font, scale);
- }
- }
+ natural u = width * (state % states);
+ natural v = height * (opengl->animation_tick % frames);
- return (maximum (width, match));
+ opengl_render_sprite_crop (opengl, sprite, x, y, u, v, width, height);
}
-static u4 opengl_render_string_height (opengl_structure * opengl, c1 * string, u4 font, f4 scale) {
- u4 height = opengl_render_character_height (opengl, ' ', font, scale);
-
- if ((string == null) || (string [0] == '\0')) {
- return (0);
- }
-
- for (u4 index = 0; string [index] != '\0'; ++index) {
- if (string [index] == '\n') {
- height += opengl_render_character_height (opengl, ' ', font, scale);
- }
- }
-
- return (height);
+static procedure opengl_render_sprite_crop_colour (opengl_structure * opengl, natural sprite, natural colour, integer x, integer y, natural u,
+ natural v, natural width, natural height) {
+ opengl_render_base (opengl, sprite, x, y, u, v, width, height, 1.0f, 1.0f, 0, 0, colour, colour, colour, colour);
}
-static v0 opengl_render_character_base (opengl_structure * opengl, c1 character, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_upper_left, u4 colour_upper_right, u4 colour_lower_left, u4 colour_lower_right) {
- if ((character < opengl->font_begin [font]) || (character > opengl->font_end [font])) return;
+static procedure opengl_render_character_base (opengl_structure * opengl, character data, natural font, integer x, integer y, real scale,
+ natural colour_upper_left, natural colour_upper_right, natural colour_lower_left,
+ natural colour_lower_right) {
+ if ((font >= opengl->font_count) && (font != ~ 0u)) return;
- if (font == opengl->default_font) {
+ if (font == ~ 0u) {
font = opengl->font_count - 1;
}
- u4 index = opengl->font_index [font] [character - opengl->font_begin [font]];
- u4 width = opengl->sprite_width [index];
- u4 height = opengl->sprite_height [index];
+ if ((data < opengl->font_begin [font]) || (data > opengl->font_end [font])) return;
+
+ natural index = opengl->font_index [font] [data - opengl->font_begin [font]];
+ natural width = opengl->sprite_width [index];
+ natural height = opengl->sprite_height [index];
opengl_render_base (opengl, index, x, y, 0, 0, width, height, scale, scale, 0, 0, colour_upper_left, colour_upper_right,
colour_lower_left, colour_lower_right);
}
-static v0 opengl_render_character (opengl_structure * opengl, c1 character, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
- opengl_render_character_base (opengl, character, font, x, y, scale, colour, colour, colour, colour);
+static procedure opengl_render_character (opengl_structure * opengl, character data, natural font, integer x, integer y, real scale, natural colour) {
+ opengl_render_character_base (opengl, data, font, x, y, scale, colour, colour, colour, colour);
}
-static v0 opengl_render_character_vertical_gradient (opengl_structure * opengl, c1 character, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_up, u4 colour_down) {
- opengl_render_character_base (opengl, character, font, x, y, scale, colour_up, colour_up, colour_down, colour_down);
+static procedure opengl_render_character_vertical_gradient (opengl_structure * opengl, character data, natural font, integer x, integer y, real scale,
+ natural colour_up, natural colour_down) {
+ opengl_render_character_base (opengl, data, font, x, y, scale, colour_up, colour_up, colour_down, colour_down);
}
-static v0 opengl_render_character_horizontal_gradient (opengl_structure * opengl, c1 character, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_left, u4 colour_right) {
- opengl_render_character_base (opengl, character, font, x, y, scale, colour_left, colour_right, colour_left, colour_right);
+static procedure opengl_render_character_horizontal_gradient (opengl_structure * opengl, character data, natural font, integer x, integer y, real scale,
+ natural colour_left, natural colour_right) {
+ opengl_render_character_base (opengl, data, font, x, y, scale, colour_left, colour_right, colour_left, colour_right);
}
-static v0 opengl_render_string_base (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_upper_left, u4 colour_upper_right, u4 colour_lower_left, u4 colour_lower_right) {
- s4 offset = x;
+static procedure opengl_render_string_base (opengl_structure * opengl, character * string, natural font, integer x, integer y, real scale,
+ natural colour_upper_left, natural colour_upper_right, natural colour_lower_left, natural colour_lower_right) {
+ integer offset = x;
if (string == null) return;
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\t') {
- x += opengl->tab_width * opengl_render_character_width (opengl, ' ', font, scale);
+ x += opengl->tab_width * opengl_character_width (opengl, ' ', font, scale);
continue;
} else if (string [index] == '\n') {
x = offset;
- y += opengl_render_character_height (opengl, ' ', font, scale);
+ y += opengl_character_height (opengl, ' ', font, scale);
continue;
} else {
opengl_render_character_base (opengl, string [index], font, x, y, scale, colour_upper_left, colour_upper_right,
colour_lower_left, colour_lower_right);
- x += opengl_render_character_width (opengl, string [index], font, scale);
+ x += opengl_character_width (opengl, string [index], font, scale);
}
}
}
-static v0 opengl_render_string (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
+static procedure opengl_render_string (opengl_structure * opengl, character * string, natural font, integer x, integer y, real scale, natural colour) {
opengl_render_string_base (opengl, string, font, x, y, scale, colour, colour, colour, colour);
}
-static v0 opengl_render_string_vertical_gradient (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_up, u4 colour_down) {
+static procedure opengl_render_string_vertical_gradient (opengl_structure * opengl, character * string, natural font, integer x, integer y, real scale,
+ natural colour_up, natural colour_down) {
opengl_render_string_base (opengl, string, font, x, y, scale, colour_up, colour_up, colour_down, colour_down);
}
-static v0 opengl_render_string_horizontal_gradient (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_left, u4 colour_right) {
+static procedure opengl_render_string_horizontal_gradient (opengl_structure * opengl, character * string, natural font, integer x, integer y, real scale,
+ natural colour_left, natural colour_right) {
opengl_render_string_base (opengl, string, font, x, y, scale, colour_left, colour_right, colour_left, colour_right);
}
-static v0 opengl_render_string_full_vertical_gradient (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_up, u4 colour_down) {
- s4 offset = x;
- u4 back = 0;
- u4 up = 0;
- u4 down = 0;
+static procedure opengl_render_string_full_vertical_gradient (opengl_structure * opengl, character * string, natural font, integer x, integer y, real scale,
+ natural colour_up, natural colour_down) {
+ integer offset = x;
+ natural back = 0;
+ natural up = 0;
+ natural down = 0;
- f4 interpolator = 1.0f / (float) string_full_height (string);
+ real interpolator = 1.0f / (real) string_full_height (string);
if (string == null) return;
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\t') {
- x += opengl->tab_width * opengl_render_character_width (opengl, ' ', font, scale);
+ x += opengl->tab_width * opengl_character_width (opengl, ' ', font, scale);
continue;
} else if (string [index] == '\n') {
back += 1;
x = offset;
- y += opengl_render_character_height (opengl, ' ', font, scale);
+ y += opengl_character_height (opengl, ' ', font, scale);
continue;
} else {
- up = colour_linear_interpolation (colour_up, colour_down, (float) (back + 0) * interpolator);
- down = colour_linear_interpolation (colour_up, colour_down, (float) (back + 1) * interpolator);
+ up = colour_linear_interpolation (colour_up, colour_down, (real) (back + 0) * interpolator);
+ down = colour_linear_interpolation (colour_up, colour_down, (real) (back + 1) * interpolator);
opengl_render_character_vertical_gradient (opengl, string [index], font, x, y, scale, up, down);
- x += opengl_render_character_width (opengl, string [index], font, scale);
+ x += opengl_character_width (opengl, string [index], font, scale);
}
}
}
-static v0 opengl_render_string_full_horizontal_gradient (opengl_structure * opengl, c1 * string, u4 font, s4 x, s4 y, f4 scale,
- u4 colour_left, u4 colour_right) {
- s4 offset = x;
- u4 back = 0;
- u4 left = 0;
- u4 right = 0;
+static procedure opengl_render_string_full_horizontal_gradient (opengl_structure * opengl, character * string, natural font, integer x,
+ integer y, real scale, natural colour_left, natural colour_right) {
+ integer offset = x;
+ natural back = 0;
+ natural left = 0;
+ natural right = 0;
- f4 interpolator = 1.0f / (float) string_full_width (string, opengl->tab_width);
+ real interpolator = 1.0f / (real) string_full_width (string, opengl->tab_width);
if (string == null) return;
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
if (string [index] == '\t') {
- x += opengl->tab_width * opengl_render_character_width (opengl, ' ', font, scale);
+ x += opengl->tab_width * opengl_character_width (opengl, ' ', font, scale);
continue;
} else if (string [index] == '\n') {
back = 0;
x = offset;
- y += opengl_render_character_height (opengl, ' ', font, scale);
+ y += opengl_character_height (opengl, ' ', font, scale);
continue;
} else {
back += 1;
- left = colour_linear_interpolation (colour_left, colour_right, (float) (back + 0) * interpolator);
- right = colour_linear_interpolation (colour_left, colour_right, (float) (back + 1) * interpolator);
+ left = colour_linear_interpolation (colour_left, colour_right, (real) (back + 0) * interpolator);
+ right = colour_linear_interpolation (colour_left, colour_right, (real) (back + 1) * interpolator);
opengl_render_character_horizontal_gradient (opengl, string [index], font, x, y, scale, left, right);
- x += opengl_render_character_width (opengl, string [index], font, scale);
+ x += opengl_character_width (opengl, string [index], font, scale);
}
}
}
-static v0 opengl_render_framerate (opengl_structure * opengl, u4 font, s4 x, s4 y, f4 scale, u4 colour) {
+static procedure opengl_render_framerate (opengl_structure * opengl, natural font, integer x, integer y, real scale, natural colour) {
opengl_render_string (opengl, number_to_string (opengl->framerate), font, x, y, scale, colour);
}
+static procedure opengl_synchronize (opengl_structure * opengl, natural colour) {
+ integer signal_code [signal_count] = {
+ 0,
+ GLFW_KEY_A, GLFW_KEY_B, GLFW_KEY_C, GLFW_KEY_D,
+ GLFW_KEY_E, GLFW_KEY_F, GLFW_KEY_G, GLFW_KEY_H,
+ GLFW_KEY_I, GLFW_KEY_J, GLFW_KEY_K, GLFW_KEY_L,
+ GLFW_KEY_M, GLFW_KEY_N, GLFW_KEY_O, GLFW_KEY_P,
+ GLFW_KEY_Q, GLFW_KEY_R, GLFW_KEY_S, GLFW_KEY_T,
+ GLFW_KEY_U, GLFW_KEY_V, GLFW_KEY_W, GLFW_KEY_X,
+ GLFW_KEY_Y, GLFW_KEY_Z, GLFW_KEY_0, GLFW_KEY_1,
+ GLFW_KEY_2, GLFW_KEY_3, GLFW_KEY_4, GLFW_KEY_5,
+ GLFW_KEY_6, GLFW_KEY_7, GLFW_KEY_8, GLFW_KEY_9,
+ GLFW_KEY_ESCAPE, GLFW_KEY_TAB, GLFW_KEY_ENTER, GLFW_KEY_ENTER,
+ GLFW_KEY_SLASH, GLFW_KEY_BACKSLASH, GLFW_KEY_SEMICOLON, GLFW_KEY_GRAVE_ACCENT,
+ GLFW_KEY_SPACE, GLFW_KEY_BACKSPACE, GLFW_KEY_PERIOD, GLFW_KEY_COMMA,
+ GLFW_KEY_APOSTROPHE, GLFW_KEY_CAPS_LOCK, GLFW_KEY_MINUS, GLFW_KEY_EQUAL,
+ GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_LEFT_CONTROL, GLFW_KEY_RIGHT_CONTROL,
+ GLFW_KEY_LEFT_SHIFT, GLFW_KEY_RIGHT_SHIFT, GLFW_KEY_LEFT_ALT, GLFW_KEY_RIGHT_ALT,
+ GLFW_KEY_F1, GLFW_KEY_F2, GLFW_KEY_F3, GLFW_KEY_F4,
+ GLFW_KEY_F5, GLFW_KEY_F6, GLFW_KEY_F7, GLFW_KEY_F8,
+ GLFW_KEY_F9, GLFW_KEY_F10, GLFW_KEY_F11, GLFW_KEY_F12,
+ GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT,
+ GLFW_KEY_NUM_LOCK, GLFW_KEY_PAUSE, GLFW_KEY_INSERT, GLFW_KEY_HOME,
+ GLFW_KEY_PAGE_UP, GLFW_KEY_DELETE, GLFW_KEY_END, GLFW_KEY_PAGE_DOWN,
+ GLFW_KEY_KP_ADD, GLFW_KEY_KP_SUBTRACT, GLFW_KEY_KP_MULTIPLY, GLFW_KEY_KP_DIVIDE,
+ GLFW_KEY_KP_ENTER, GLFW_KEY_KP_DECIMAL, GLFW_KEY_KP_0, GLFW_KEY_KP_1,
+ GLFW_KEY_KP_2, GLFW_KEY_KP_3, GLFW_KEY_KP_4, GLFW_KEY_KP_5,
+ GLFW_KEY_KP_6, GLFW_KEY_KP_7, GLFW_KEY_KP_8, GLFW_KEY_KP_9
+ };
+
+ integer new_window_width = 0;
+ integer new_window_height = 0;
+
+ opengl->cursor [cursor_left] = false;
+ opengl->cursor [cursor_middle] = false;
+ opengl->cursor [cursor_right] = false;
+
+ glClearColor (normal_r (colour), normal_g (colour), normal_b (colour), normal_a (colour));
+
+ glClear (GL_COLOR_BUFFER_BIT);
+
+ glfwPollEvents ();
+
+ glfwSetWindowShouldClose (opengl->window, opengl->active == false);
+
+ glfwGetWindowSize (opengl->window, & new_window_width, & new_window_height);
+
+ if ((opengl->window_width != (natural) new_window_width) || (opengl->window_height != (natural) new_window_height)) {
+ if ((new_window_width <= 0) || (new_window_height <= 0)) return;
+
+ glViewport (0, 0, new_window_width, new_window_height);
+
+ opengl->window_width = (natural) new_window_width;
+ opengl->window_height = (natural) new_window_height;
+
+ opengl->pixel_width = 2.0f / (real) new_window_width;
+ opengl->pixel_height = 2.0f / (real) new_window_height;
+ }
+
+ opengl->cursor [cursor_left] = (boolean) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
+ opengl->cursor [cursor_middle] = (boolean) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
+ opengl->cursor [cursor_right] = (boolean) (glfwGetMouseButton (opengl->window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
+
+ if (opengl->freeze_cursor == false) {
+ real_64 x = 0.0;
+ real_64 y = 0.0;
+
+ glfwGetCursorPos (opengl->window, & x, & y);
+
+ opengl->cursor_x = (integer) x;
+ opengl->cursor_y = (integer) y;
+
+ //~if ((opengl->cursor_x < 0) || (opengl->cursor_x > (integer) opengl->window_width) ||
+ //~(opengl->cursor_y < 0) || (opengl->cursor_y > (integer) opengl->window_height)) {
+ //~opengl->cursor_x = 0;
+ //~opengl->cursor_y = 0;
+ //~}
+ } else {
+ if ((opengl->cursor [cursor_left] == false)
+ && (opengl->cursor [cursor_middle] == false)
+ && (opengl->cursor [cursor_right] == false)) {
+ opengl->freeze_cursor = false;
+ }
+ }
+
+ if (opengl->freeze_signal == false) {
+ for (natural index = 0; index < signal_count; ++index) {
+ opengl->signal [index] = (boolean) (glfwGetKey (opengl->window, signal_code [index]) == GLFW_PRESS);
+ }
+ }
+
+ opengl->glBufferData (GL_ARRAY_BUFFER, opengl->vertex_count * 4, opengl->vertex_array, GL_DYNAMIC_DRAW);
+ opengl->glBufferData (GL_ELEMENT_ARRAY_BUFFER, opengl->index_count * 4, opengl->index_array, GL_DYNAMIC_DRAW);
+
+ opengl->glBindBuffer (GL_ARRAY_BUFFER, opengl->vertex_buffer);
+
+ glDrawElements (GL_TRIANGLES, (integer) opengl->index_count * 4, GL_UNSIGNED_INT, null);
+
+ glfwSwapBuffers (opengl->window);
+
+ opengl->vertex_count = 0;
+ opengl->index_count = 0;
+
+ opengl->frame_end = nano_time ();
+
+ opengl->frame_time = opengl->frame_end - opengl->frame_begin;
+
+ if (opengl->frame_time < 1000000000ul / opengl->gameplay_framerate) {
+ nano_wait (1000000000ul / opengl->gameplay_framerate - opengl->frame_time);
+ }
+
+ if (opengl->global_tick % opengl->gameplay_framerate == 0) {
+ opengl->framerate = (natural) (1000000000ul / opengl->frame_time);
+ }
+
+ ++opengl->global_tick;
+
+ opengl->global_tick = opengl->global_tick % (opengl->gameplay_framerate * opengl->animation_framerate);
+ opengl->gameplay_tick = opengl->global_tick % (opengl->gameplay_framerate);
+ opengl->animation_tick = opengl->global_tick / (opengl->gameplay_framerate / opengl->animation_framerate);
+
+ opengl->frame_begin = nano_time ();
+}
+
#undef opengl_font_width
#undef opengl_font_height
/// for more details, if you dare, it is a lot of text that nobody wants to read...
typedef struct {
- f4 distance;
- f4 horizontal;
- f4 vertical;
+ real distance;
+ real horizontal;
+ real vertical;
} sphere_vector;
-static b4 sphere_epsilon (f4 error) {
+static boolean sphere_epsilon (real error) {
return (error < 0.000001);
}
-static f4 sphere_distance (f4 x, f4 y, f4 z) {
+static real sphere_distance (real x, real y, real z) {
return (square_root (x * x + y * y + z * z));
}
-static f4 sphere_horizontal (f4 x, f4 z) {
+static real sphere_horizontal (real x, real z) {
return ((sphere_epsilon (z)) ? (sign (x) * pi / 2.0f) : (arc_tangent (x / z)));
}
-static f4 sphere_vertical (f4 y, f4 z) {
+static real sphere_vertical (real y, real z) {
return ((sphere_epsilon (z)) ? (sign (y) * pi / 2.0f) : (arc_tangent (y / z)));
}
-static f4 sphere_x (f4 horizontal, f4 z) {
+static real sphere_x (real horizontal, real z) {
return (z * tangent (horizontal));
}
-static f4 sphere_y (f4 vertical, f4 z) {
+static real sphere_y (real vertical, real z) {
return (z * tangent (vertical));
}
-static f4 sphere_z (f4 distance, f4 horizontal, f4 vertical) {
- f4 x_over_z = tangent (horizontal);
- f4 y_over_z = tangent (vertical);
+static real sphere_z (real distance, real horizontal, real vertical) {
+ real x_over_z = tangent (horizontal);
+ real y_over_z = tangent (vertical);
return (distance * square_root (1.0f / (x_over_z * x_over_z + y_over_z * y_over_z + 1.0f)));
}
-static v0 sphere_transpose_x (f4 * distance, f4 * horizontal, f4 x) {
- f4 origin = (* distance) * (* distance);
- f4 offset = x * x;
- f4 square = origin + offset + 2 * x * (* distance) * cosine (* horizontal);
+static procedure sphere_transpose_x (real * distance, real * horizontal, real x) {
+ real origin = (* distance) * (* distance);
+ real offset = x * x;
+ real square = origin + offset + 2 * x * (* distance) * cosine (* horizontal);
* distance = square_root (square);
* horizontal = arc_sine ((square + offset - origin) / (2 * (* distance) * x));
}
-static v0 sphere_transpose_y (f4 * distance, f4 * vertical, f4 y) {
- f4 origin = (* distance) * (* distance);
- f4 offset = y * y;
+static procedure sphere_transpose_y (real * distance, real * vertical, real y) {
+ real origin = (* distance) * (* distance);
+ real offset = y * y;
* distance = square_root (origin + offset + 2 * y * (* distance) * cosine (* vertical));
}
-static v0 sphere_transpose_z (f4 * distance, f4 * horizontal, f4 * vertical, f4 z) {
- f4 origin = (* distance) * (* distance);
- f4 offset = z * z;
- f4 side_a = secant (* vertical);
- f4 side_b = tangent (* horizontal);
+static procedure sphere_transpose_z (real * distance, real * horizontal, real * vertical, real z) {
+ real origin = (* distance) * (* distance);
+ real offset = z * z;
+ real side_a = secant (* vertical);
+ real side_b = tangent (* horizontal);
* distance = square_root (origin + offset + 2 * z * (* distance) * square_root (1.0f / (side_a * side_a + sibe_b * side_b)));
}
-static v0 sphere_convert (sphere_vector * vector, f4 x, f4 y, f4 z) {
+static procedure sphere_convert (sphere_vector * vector, real x, real y, real z) {
vector->distance = sphere_distance (x, y, z);
vector->horizontal = sphere_horizontal (x, z);
vector->vertical = sphere_vertical ( y, z);
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
-static unsigned s4 sprite_colour [128] = {
+static unsigned integer sprite_colour [128] = {
0x00000000, 0xff222222, 0xff444444, 0xff666666, 0xff888888, 0xffaaaaaa, 0xffcccccc, 0xffeeeeee,
0x11000000, 0xff000022, 0xff000044, 0xff000066, 0xff000088, 0xff0000aa, 0xff0000cc, 0xff0000ee,
0x22000000, 0xff002200, 0xff004400, 0xff006600, 0xff008800, 0xff00aa00, 0xff00cc00, 0xff00ee00,
0xff000000, 0xff221122, 0xff442244, 0xff663366, 0xff884488, 0xffaa55aa, 0xffcc66cc, 0xffee77ee
};
-static v0 * sprite_import (c1 * path, s4 * width, s4 * height) {
- unsigned c1 check_width = 0;
- unsigned c1 check_height = 0;
+static generic * sprite_import (character * path, integer * width, integer * height) {
+ unsigned character check_width = 0;
+ unsigned character check_height = 0;
- s4 file, move;
+ integer file, move;
- unsigned s4 * data = null;
+ unsigned integer * data = null;
file = file_open (path, file_flag_read);
- file_read (file, & check_width, (int) sizeof (check_width));
- file_read (file, & check_height, (int) sizeof (check_height));
+ file_read (file, & check_width, (integer) sizeof (check_width));
+ file_read (file, & check_height, (integer) sizeof (check_height));
- * width = (int) check_width;
- * height = (int) check_height;
+ * width = (integer) check_width;
+ * height = (integer) check_height;
fatal_failure ((* width) == 0, "sprite_import: Invalid sprite width.");
fatal_failure ((* height) == 0, "sprite_import: Invalid sprite height.");
- data = allocate ((* width) * (* height) * (int) sizeof (* data));
+ data = allocate ((* width) * (* height) * (integer) sizeof (* data));
for (move = 0; move < (* width) * (* height); ++move) {
- s4 colour = 0;
- s4 repeat = 0;
+ integer colour = 0;
+ integer repeat = 0;
file_read (file, & colour, 1);
if ((colour & 0x80) == 0) {
data [move] = sprite_colour [colour];
} else {
- s4 offset;
+ integer offset;
file_read (file, & repeat, 1);
return (data);
}
-static v0 sprite_export (c1 * path, s4 width, s4 height, unsigned s4 * data) {
- s4 file, move;
+static procedure sprite_export (character * path, integer width, integer height, unsigned integer * data) {
+ integer file, move;
file = file_open (path, file_flag_edit | file_flag_truncate | file_flag_create);
file_write (file, & height, 1);
for (move = 0; move < width * height; ++move) {
- s4 colour = 0;
- s4 repeat = 0;
+ integer colour = 0;
+ integer repeat = 0;
for (repeat = 1; (move + repeat < width * height) && (data [move] == data [move + repeat]) && (repeat < 256); ++repeat);
file = file_close (file);
}
-static v0 sprite_swap_channels (unsigned s4 * data, s4 width, s4 height) {
- s4 move;
+static procedure sprite_swap_channels (unsigned integer * data, integer width, integer height) {
+ integer move;
for (move = 0; move < width * height; ++move) {
data [move] = (data [move] & 0xff00ff00) | ((data [move] & 0xff0000) >> 16) | ((data [move] & 0xff) << 16);
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
+/// Xrena, extremely small header only library serving as arena allocator, with one global variable.In order to use it, include this header file,
+/// there's no macro for including implementation (like stb libraries), this is for projects that have only one C source file, and one or more C
+/// header files. I'll provide minimal examples below.
+
+/// Maximum size for single memory "allocation", if you're making a parser, you can use as low as 8 or 16, but as soon as you start working with
+/// bigger structures, images or models, you need this to be higher value, for example 64 * 1024 * 1024 (loading 4k textures). If you don't
+/// understand how to use this macro, turn off your machine and read some books, or alternatively, fuck around until you find out.
+
#ifndef arena_block_limit
#define arena_block_limit (1024 * 1024)
#endif
+/// Structure and global variable definition, you shouldn't ever modify this, functions below cover that task.
+
static struct {
- u8 block_count;
- u8 block_limit;
+ caliber block_count;
+ caliber block_limit;
struct {
- u8 count;
- u8 capacity;
- c1 * buffer;
+ caliber count;
+ caliber capacity;
+ character * buffer;
} * * block_array;
-} * arena = null;
+} * arena_memory = null;
+
+/// Warning: Local function! You don't need to use this at all, it's covered by other functions, don't worry about it.
+///
+/// This function will initialize the state of variable 'arena_memory', or extend it's size once memory is filled.
-static v0 arena_initialize (v0) {
- u8 current = ++arena->block_count - 1;
+static procedure arena_begin_or_widen (none) {
+ caliber current = ++arena_memory->block_count - 1;
- arena->block_limit = arena_block_limit;
+ arena_memory->block_limit = arena_block_limit;
- arena->block_array = reallocate (arena->block_array, arena->block_count * sizeof (* arena->block_array));
+ arena_memory->block_array = reallocate (arena_memory->block_array, arena_memory->block_count * sizeof (* arena_memory->block_array));
- arena->block_array [current] = allocate (sizeof (* arena));
+ arena_memory->block_array [current] = allocate (sizeof (* arena));
- arena->block_array [current]->buffer = allocate (arena_block_limit);
- arena->block_array [current]->count = 0;
- arena->block_array [current]->capacity = arena_block_limit;
+ arena_memory->block_array [current]->buffer = allocate (arena_block_limit);
+ arena_memory->block_array [current]->count = 0;
+ arena_memory->block_array [current]->capacity = arena_block_limit;
}
-static v0 arena_deinitialize (v0) {
- for (u8 index = 0; index < arena->block_count; ++index) {
- arena->block_array [index]->buffer = deallocate (arena->block_array [index]->buffer);
- arena->block_array [index] = deallocate (arena->block_array [index]);
+/// Warning: Local function! You don't need to use this at all, it's covered by other functions, don't worry about it.
+///
+/// This function will clean all memory pools from variable 'arena_memory', freeing all memory used by the arena allocator.
+
+static procedure arena_clean (none) {
+ for (caliber index = 0; index < arena_memory->block_count; ++index) {
+ arena_memory->block_array [index]->buffer = deallocate (arena_memory->block_array [index]->buffer);
+ arena_memory->block_array [index] = deallocate (arena_memory->block_array [index]);
}
- arena->block_array = deallocate (arena->block_array);
- arena = deallocate (arena);
+ arena_memory->block_array = deallocate (arena_memory->block_array);
+ arena_memory = deallocate (arena_memory);
}
-static v0 * arena_add (u8 size) {
- u8 current = arena->block_count - 1;
+/// Now, this is finally a function that you want to use. You want to allocate object of some size, just add that size in arena, it'll return
+/// you a pointer to that memory location, the same way you'd use 'malloc', and that memory will be zero initialized (unlike 'malloc', just like
+/// 'calloc'). You don't ever have to worry about freeing memory, if your program has definite exit routine. Internally, it checks if arena
+/// allocator was initialized, if it was, it'll extend it if there's not enough memory and return that pointer, otherwise, it will initialize it
+/// and set clean up call at exit.
+///
+/// Make an array of 60 integers, they'll all be zero.
+///
+/// integer * my_integers = arena_add (60 * sizeof (my_integers));
+
+static generic * arena_add (caliber size) {
+ caliber current = arena_memory->block_count - 1;
if (arena == null) {
- clean_up (arena_deinitialize);
+ clean_up (arena_clean);
- arena = allocate (sizeof (* arena));
+ arena_memory = allocate (sizeof (* arena_memory));
- arena_initialize ();
+ arena_begin_or_widen ();
}
- fatal_failure (size > arena->block_limit, "arena_add: Block limit reached.");
+ fatal_failure (size > arena_memory->block_limit, "arena_add: Block limit reached.");
- if (arena->block_array [current]->count + size > arena->block_array [current]->capacity) {
- arena_initialize ();
+ if (arena_memory->block_array [current]->count + size > arena_memory->block_array [current]->capacity) {
+ arena_begin_or_widen ();
}
- arena->block_array [current]->count += size;
+ arena_memory->block_array [current]->count += size;
+
+ return ((generic *) & arena_memory->block_array [current]->buffer [arena_memory->block_array [current]->count - size]);
+}
+
+/// Add null terminated string to arena memory.
+///
+/// character * my_token = arena_add_string (parsed_token);
- return ((v0*) & arena->block_array [current]->buffer [arena->block_array [current]->count - size]);
+static character * arena_add_string (character * string) {
+ character * pointer = arena_add (string_length (string) * sizeof (pointer));
+
+ string_copy (pointer, string);
+
+ return (pointer);
}
-static c1 * arena_add_data (v0 * data, u8 size) {
- v0 * pointer = arena_add (size);
+/// Add raw memory of certain size to arena memory.
+///
+/// generic * my_model = arena_add_memory (raw_model_data, size_of_model_data);
+
+static generic * arena_add_memory (generic * memory, caliber size) {
+ generic * pointer = arena_add (size);
- memory_copy (pointer, data, size);
+ memory_copy (pointer, memory, size);
return (pointer);
}
-static c1 * arena_add_file (c1 * path, u4 flag, b4 null_terminate) {
- s4 file = -1;
- u8 size = 0;
- c1 * data = null;
+/// Add file data from certain path, specify file flags (similar to 'open' system call) and set if you want it to be null terminated.
+///
+/// generic * my_binary_file = arena_add_file ("foo.bin", file_flag_read, false);
+/// character * my_text_file = arena_add_file ("foo.txt", file_flag_read, true);
+
+static character * arena_add_file (character * path, integer flag, boolean null_terminate) {
+ integer file = -1;
+ caliber size = 0;
+ character * data = null;
file = file_open (path, flag);
- size = file_size (path) + (u8) null_terminate;
+ size = file_size (path) + (caliber) null_terminate;
data = arena_add (size);
- file_read (file, data, size - (u8) null_terminate);
+ file_read (file, data, size - (caliber) null_terminate);
file = file_close (file);
return (data);
}
-static u8 arena_usage (v0) {
- u8 usage = 0;
+/// Simple utility function that returns how many bytes have been added to arena allocator.
+///
+/// print ("So far I used %l bytes of memory...\n", arena_usage ());
+
+static caliber arena_usage (none) {
+ caliber usage = 0;
- for (u8 block = 0; block < arena->block_count; ++block) {
- usage += arena->block_array [block]->count;
+ for (caliber block = 0; block < arena_memory->block_count; ++block) {
+ usage += arena_memory->block_array [block]->count;
}
return (usage);
///
/// Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic
///
-/// xolatile@chud.cyou - xrocessor - Probably the most minimalistic general preprocessor aimed at Ada, Pascal and EAXHLA language syntax.
+/// xolatile@chud.cyou - xrocessor - Probably the most minimalistic general preprocessor aimed at EAXHLA language syntax.
///
/// This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU
/// General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish...
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
-#define processor_token_limit (1024)
+static natural processor_parse_comment (character * buffer);
+static natural processor_parse_include (character * buffer);
+static natural processor_parse_use (character * buffer);
+static natural processor_parse_alias (character * buffer);
+static natural processor_parse_macro (character * buffer);
+static natural processor_parse_scope (character * buffer);
+static natural processor_parse_unscope (character * buffer);
+static natural processor_parse_default (character * buffer);
-static u8 processor_parse_comment (c1 * buffer);
-static u8 processor_parse_include (c1 * buffer);
-static u8 processor_parse_use (c1 * buffer);
-static u8 processor_parse_alias (c1 * buffer);
-static u8 processor_parse_macro (c1 * buffer);
-static u8 processor_parse_scope (c1 * buffer);
-static u8 processor_parse_unscope (c1 * buffer);
-static u8 processor_parse_default (c1 * buffer);
-
-static v0 processor_parse_buffer (c1 * buffer, u8 limit);
+static procedure processor_parse_buffer (character * buffer, natural limit);
typedef enum {
processor_token_comment, processor_token_include, processor_token_use, processor_token_alias,
processor_token_count
} processor_token_enumeration;
-static c1 * processor_token_key [processor_token_count - 1] = {
+static character * processor_token_key [processor_token_count - 1] = {
"---", "include ", "use ", "alias ", "macro ", "scope ", "unscope "
};
-static u8 (* processor_parse_key [processor_token_count]) (c1 * buffer) = {
+static natural (* processor_parse_key [processor_token_count]) (character * buffer) = {
processor_parse_comment, processor_parse_include, processor_parse_use, processor_parse_alias,
processor_parse_macro, processor_parse_scope, processor_parse_unscope, processor_parse_default
};
-static u4 token_count = 0;
-
-static struct {
- c1 * data;
- u8 size;
- s4 type;
-} * token_array [processor_token_limit],
- * token_value [processor_token_limit];
-
-static u8 processor_parse_default (c1 * buffer) {
- s4 select;
+typedef struct {
+ natural count;
+ natural limit;
+ character * * token_array_data;
+ natural * token_array_size;
+ natural * token_array_type;
+} processor_structure;
- for (select = 0; select < token_count; ++select) {
+static natural processor_parse_default (character * buffer) {
+ for (natural select = 0; select < token_count; ++select) {
if (string_compare_limit (buffer, token_array [select]->data, token_array [select]->size) == true) {
if (token_array [select]->type == token_alias) {
if (character_is_separator (buffer [-1]) == false) continue;
return (1);
}
-static u8 processor_parse_comment (c1 * buffer) {
- s4 offset;
-
- for (offset = 3; buffer [offset] != '\0'; ++offset) {
+static natural processor_parse_comment (character * buffer) {
+ for (natural offset = 3; buffer [offset] != '\0'; ++offset) {
if (buffer [offset] == '\n') break;
}
return (offset + 1);
}
-static u8 processor_parse_use (c1 * buffer) {
- s4 offset;
- s4 length;
+static natural processor_parse_use (character * buffer) {
+ natural length = 0;
- for (offset = 4; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
+ for (natural offset = 4; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
++token_count;
return (offset + length + 1);
}
-static u8 processor_parse_include (c1 * buffer) {
- s4 length;
- s4 offset;
- c1 * data;
+static natural processor_parse_include (character * buffer) {
+ natural length = 0;
+ natural offset = 0;
+ character * data = null;
for (offset = 8; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
return (offset + length + 1);
}
-static u8 processor_parse_alias (c1 * buffer) {
- s4 offset;
- s4 length;
+static natural processor_parse_alias (character * buffer) {
+ natural offset = 0;
+ natural length = 0;
for (offset = 6; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
return (offset + length + 1);
}
-static u8 processor_parse_macro (c1 * buffer) {
- s4 offset;
- s4 length;
+static natural processor_parse_macro (character * buffer) {
+ natural offset = 0;
+ natural length = 0;
for (offset = 6; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
return (offset + length + 9 + 1);
}
-static u8 processor_parse_scope (c1 * buffer) {
- s4 offset;
- s4 length;
- s4 select;
+static natural processor_parse_scope (character * buffer) {
+ natural offset = 0;
+ natural length = 0;
+ natural select = 0;
for (offset = 6; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
return (offset + length + 1);
}
-static u8 processor_parse_unscope (c1 * buffer) {
- s4 offset;
- s4 length;
- s4 select;
+static natural processor_parse_unscope (character * buffer) {
+ natural offset = 0;
+ natural length = 0;
+ natural select = 0;
for (offset = 8; (buffer [offset] != '\0') && (character_is_blank (buffer [offset]) == true); ++offset);
return (offset + length + 1);
}
-static v0 processor_parse_buffer (c1 * buffer, s4 limit) {
- s4 offset;
- s4 length;
- s4 select;
+static procedure processor_parse_buffer (character * buffer, natural limit) {
+ for (natural length = 0, offset = 0; (buffer [offset] != '\0') && (offset != limit); offset += length) {
+ natural select = 0;
- for (length = offset = 0; (buffer [offset] != '\0') && (offset != limit); offset += length) {
for (select = 0; select < token_default; ++select) {
length = string_length (token_key [select]);
if (string_compare_limit (& buffer [offset], token_key [select], length) == true) {
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
-typedef enum {
- cross_window_fullscreen = 0x1,
- cross_window_transparent = 0x2,
- cross_window_resizable = 0x4,
- cross_window_decorated = 0x8
-} cross_window_flag;
-
#ifdef use_raptor_renderer
-#define cross_structure raptor_structure
-#define cross_initialize raptor_initialize
-#define cross_deinitialize raptor_deinitialize
-#define cross_sprite_raw_import raptor_sprite_raw_import
-#define cross_font_raw_import raptor_font_raw_import
-#define cross_sprite_import raptor_sprite_import
-#define cross_font_import raptor_font_import
-#define cross_sprite_width raptor_sprite_width
-#define cross_sprite_height raptor_sprite_height
-#define cross_character_width raptor_character_width
-#define cross_character_height raptor_character_height
-#define cross_string_width raptor_string_width
-#define cross_string_height raptor_string_height
-#define cross_center_x raptor_center_x
-#define cross_center_y raptor_center_y
-#define cross_cursor_inside raptor_cursor_inside
-#define cross_cursor_left_click raptor_cursor_left_click
-#define cross_cursor_right_click raptor_cursor_right_click
-#define cross_configure raptor_configure
-#define cross_render_base raptor_render_base
-#define cross_render_rectangle raptor_render_rectangle
-#define cross_render_sprite raptor_render_sprite
-#define cross_render_sprite_scale raptor_render_sprite_scale
-#define cross_render_sprite_crop raptor_render_sprite_crop
-#define cross_render_sprite_colour raptor_render_sprite_colour
-#define cross_render_sprite_crop_colour raptor_render_sprite_crop_colour
-#define cross_render_sprite_flip raptor_render_sprite_flip
-#define cross_render_sprite_animate raptor_render_sprite_animate
-#define cross_render_character raptor_render_character
-#define cross_render_string raptor_render_string
-#define cross_render_framerate raptor_render_framerate
-#define cross_synchronize raptor_synchronize
-#define cross_render_rectangle_vertical_gradient raptor_render_rectangle_vertical_gradient
-
-#include "xaptor.h"
+#define cross_initialize raptor_initialize
+#define cross_deinitialize raptor_deinitialize
+#define cross_sprite_raw_import raptor_sprite_raw_import
+#define cross_font_raw_import raptor_font_raw_import
+#define cross_sprite_import raptor_sprite_import
+#define cross_font_import raptor_font_import
+#define cross_sprite_width raptor_sprite_width
+#define cross_sprite_height raptor_sprite_height
+#define cross_character_width raptor_character_width
+#define cross_character_height raptor_character_height
+#define cross_string_width raptor_string_width
+#define cross_string_height raptor_string_height
+#define cross_center_x raptor_center_x
+#define cross_center_y raptor_center_y
+#define cross_cursor_inside raptor_cursor_inside
+#define cross_configure raptor_configure
+#define cross_render_base raptor_render_base
+#define cross_render_rectangle raptor_render_rectangle
+#define cross_render_sprite raptor_render_sprite
+#define cross_render_sprite_scale raptor_render_sprite_scale
+#define cross_render_sprite_crop raptor_render_sprite_crop
+#define cross_render_sprite_colour raptor_render_sprite_colour
+#define cross_render_sprite_flip raptor_render_sprite_flip
+#define cross_render_sprite_animation raptor_render_sprite_animation
+#define cross_render_sprite_crop_colour raptor_render_sprite_crop_colour
+#define cross_render_character raptor_render_character
+#define cross_render_string raptor_render_string
+#define cross_render_framerate raptor_render_framerate
+#define cross_synchronize raptor_synchronize
+#define cross_render_rectangle_vertical_gradient raptor_render_rectangle_vertical_gradient
+#define cross_render_rectangle_horizontal_gradient raptor_render_rectangle_horizontal_gradient
+
+#include <xolatile/xaptor.h>
+
+typedef raptor_structure cross_structure;
#endif
#ifdef use_common_renderer
-#define cross_structure common_structure
#define cross_font_width common_font_width
#define cross_font_height common_font_height
#define cross_font_tabulator common_font_tabulator
-#define cross_gameplay_framerate common_gameplay_framerate
-#define cross_animation_framerate common_animation_framerate
#define cross_center_x common_center_x
#define cross_center_y common_center_y
#define cross_cursor_inside common_cursor_inside
#define cross_render_sprite_colour common_render_sprite_colour
#define cross_render_sprite_crop_colour common_render_sprite_crop_colour
#define cross_render_sprite_flip common_render_sprite_flip
-#define cross_render_sprite_animate common_render_sprite_animate
+#define cross_render_sprite_animation common_render_sprite_animation
#define cross_render_sprite_preview common_render_sprite_preview
#define cross_render_sprite_control common_render_sprite_control
#define cross_render_string_width common_render_string_width
#define cross_render_string common_render_string
-#include "xommon.h"
+#include <xolatile/xommon.h>
+
+typedef common_structure cross_structure;
#endif
#ifdef use_opengl_renderer
-#define cross_structure opengl_structure
-#define cross_font_width opengl_font_width
-#define cross_font_height opengl_font_height
-#define cross_font_tabulator opengl_font_tabulator
-#define cross_gameplay_framerate opengl_gameplay_framerate
-#define cross_animation_framerate opengl_animation_framerate
-#define cross_center_x opengl_center_x
-#define cross_center_y opengl_center_y
-#define cross_cursor_inside opengl_cursor_inside
-#define cross_cursor_left_click opengl_cursor_left_click
-#define cross_cursor_right_click opengl_cursor_right_click
-#define cross_sprite_raw_import opengl_sprite_raw_import
-#define cross_font_raw_import opengl_font_raw_import
-#define cross_sprite_import opengl_sprite_import
-#define cross_font_import opengl_font_import
-#define cross_sprite_width opengl_sprite_width
-#define cross_sprite_height opengl_sprite_height
-#define cross_initialize opengl_initialize
-#define cross_deinitialize opengl_deinitialize
-#define cross_configure opengl_configure
-#define cross_synchronize opengl_synchronize
-#define cross_render_base opengl_render_base
-#define cross_render_rectangle opengl_render_rectangle
-#define cross_render_rectangle_gradient_v opengl_render_rectangle_gradient_v
-#define cross_render_rectangle_gradient_h opengl_render_rectangle_gradient_h
-#define cross_render_sprite opengl_render_sprite
-#define cross_render_sprite_crop opengl_render_sprite_crop
-#define cross_render_sprite_colour opengl_render_sprite_colour
-#define cross_render_sprite_crop_colour opengl_render_sprite_crop_colour
-#define cross_render_sprite_flip opengl_render_sprite_flip
-#define cross_render_sprite_animate opengl_render_sprite_animate
-#define cross_render_sprite_preview opengl_render_sprite_preview
-#define cross_render_sprite_control opengl_render_sprite_control
-#define cross_render_character opengl_render_character
-#define cross_render_string_width opengl_render_string_width
-#define cross_render_string opengl_render_string
-
-#include "xpengl.h"
+#define cross_initialize opengl_initialize
+#define cross_deinitialize opengl_deinitialize
+#define cross_sprite_raw_import opengl_sprite_raw_import
+#define cross_font_raw_import opengl_font_raw_import
+#define cross_sprite_import opengl_sprite_import
+#define cross_font_import opengl_font_import
+#define cross_sprite_width opengl_sprite_width
+#define cross_sprite_height opengl_sprite_height
+#define cross_character_width opengl_character_width
+#define cross_character_height opengl_character_height
+#define cross_string_width opengl_string_width
+#define cross_string_height opengl_string_height
+#define cross_center_x opengl_center_x
+#define cross_center_y opengl_center_y
+#define cross_cursor_inside opengl_cursor_inside
+#define cross_configure opengl_configure
+#define cross_render_base opengl_render_base
+#define cross_render_rectangle opengl_render_rectangle
+#define cross_render_sprite opengl_render_sprite
+#define cross_render_sprite_scale opengl_render_sprite_scale
+#define cross_render_sprite_crop opengl_render_sprite_crop
+#define cross_render_sprite_colour opengl_render_sprite_colour
+#define cross_render_sprite_flip opengl_render_sprite_flip
+#define cross_render_sprite_orient opengl_render_sprite_orient
+#define cross_render_sprite_animation opengl_render_sprite_animation
+#define cross_render_sprite_crop_colour opengl_render_sprite_crop_colour
+#define cross_render_character opengl_render_character
+#define cross_render_string opengl_render_string
+#define cross_render_framerate opengl_render_framerate
+#define cross_synchronize opengl_synchronize
+#define cross_render_rectangle_vertical_gradient opengl_render_rectangle_vertical_gradient
+#define cross_render_rectangle_horizontal_gradient opengl_render_rectangle_horizontal_gradient
+
+#include <xolatile/xpengl.h>
+
+typedef opengl_structure cross_structure;
#endif
#ifdef use_vulkan_renderer
-#define cross_structure vulkan_structure
#define cross_font_width vulkan_font_width
#define cross_font_height vulkan_font_height
#define cross_font_tabulator vulkan_font_tabulator
-#define cross_gameplay_framerate vulkan_gameplay_framerate
-#define cross_animation_framerate vulkan_animation_framerate
#define cross_center_x vulkan_center_x
#define cross_center_y vulkan_center_y
#define cross_cursor_inside vulkan_cursor_inside
#define cross_cursor_left_click vulkan_cursor_left_click
#define cross_cursor_right_click vulkan_cursor_right_click
-#define cross_sprite_raw_import vulkan_sprite_raw_import
-#define cross_font_raw_import vulkan_font_raw_import
+#define cross_sprite_raw_import vulkan_sprite_raw_import
+#define cross_font_raw_import vulkan_font_raw_import
#define cross_sprite_import vulkan_sprite_import
#define cross_font_import vulkan_font_import
#define cross_sprite_width vulkan_sprite_width
#define cross_render_sprite_colour vulkan_render_sprite_colour
#define cross_render_sprite_crop_colour vulkan_render_sprite_crop_colour
#define cross_render_sprite_flip vulkan_render_sprite_flip
-#define cross_render_sprite_animate vulkan_render_sprite_animate
+#define cross_render_sprite_animation vulkan_render_sprite_animation
#define cross_render_sprite_preview vulkan_render_sprite_preview
#define cross_render_sprite_control vulkan_render_sprite_control
#define cross_render_character vulkan_render_character
#define cross_render_string_width vulkan_render_string_width
#define cross_render_string vulkan_render_string
-#include "xulkan.h"
+#include <xolatile/xulkan.h>
+
+typedef vulkan_structure cross_structure;
#endif
#include <xolatile/xtandard.h>
-static v0 echo_base (s4 character, s4 base, s4 colour, s4 effect) {
+static procedure echo_base (integer index, integer base, integer colour, integer effect) {
print ("/0 | /-");
echo_colour (colour, effect);
if (base == 2) {
- echo (format_to_string (character, 0, base, 7, '0'));
+ echo (format_to_string (index, 0, base, 7, '0'));
} else if (base == 8) {
- echo (format_to_string (character, 0, base, 3, '0'));
+ echo (format_to_string (index, 0, base, 3, '0'));
} else if (base == 16) {
- echo (format_to_string (character, 0, base, 2, '0'));
+ echo (format_to_string (index, 0, base, 2, '0'));
} else {
- echo (format_to_string (character, 0, base, 3, ' '));
+ echo (format_to_string (index, 0, base, 3, ' '));
}
echo_cancel ();
}
-static v0 echo_code (s4 character) {
- c1 * code [] = {
+static procedure echo_code (integer index) {
+ character * code [] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US",
" "
};
- if (character == 127) {
+ if (index == 127) {
print ("/0 | /4DEL/-");
- } else if (character_is_visible (character) == false) {
- print ("/0 | /4%s/-", code [character]);
- if (string_length (code [character]) == 2) {
+ } else if (character_is_visible (index) == false) {
+ print ("/0 | /4%s/-", code [index]);
+ if (string_length (code [index]) == 2) {
echo (" ");
}
} else {
- print ("/0 | /4%c /-", character);
+ print ("/0 | /4%c /-", index);
}
}
-static v0 echo_name (s4 character) {
- c1 * name [] = {
+static procedure echo_name (integer index) {
+ character * name [] = {
"Null", "Start of heading", "Start of text", "End of text",
"End of transmission", "Enquiry", "Acknowledge", "Bell",
"Backspace", "Horizontal tab", "Line feed", "Vertical tab",
"Vertical bar", "Closing brace", "Tilde", "Delete"
};
- print ("/0 | /5%s/-", name [character]);
+ print ("/0 | /5%s/-", name [index]);
- output (" ", 24 - string_length (name [character]));
+ output (" ", 24 - string_length (name [index]));
}
-s4 main (v0) {
- s4 character;
+integer main (none) {
+ for (integer index = 0; index < 128; ++index) {
+ echo_base (index, 2, colour_white, effect_normal);
+ echo_base (index, 8, colour_cyan, effect_normal);
+ echo_base (index, 10, colour_cyan, effect_italic);
+ echo_base (index, 16, colour_cyan, effect_bold);
- for (character = 0; character < 128; ++character) {
- echo_base (character, 2, colour_white, effect_normal);
- echo_base (character, 8, colour_cyan, effect_normal);
- echo_base (character, 10, colour_cyan, effect_italic);
- echo_base (character, 16, colour_cyan, effect_bold);
+ echo_code (index);
+ echo_name (index);
- echo_code (character);
- echo_name (character);
-
- if (character % 2 != 0) {
+ if (index % 2 != 0) {
echo ("\n");
}
}
#define _GNU_SOURCE
#include <sys/stat.h>
+
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <dirent.h>
-#define null ((v0 *) 0)
+#define null ((generic *) 0)
#define standard_input (STDIN_FILENO)
#define standard_output (STDOUT_FILENO)
#define file_seek_set (SEEK_SET)
#define file_seek_end (SEEK_END)
+#define maximal_integer (0b01111111111111111111111111111111)
+#define minimal_integer (0b10000000000000000000000000000000)
+#define maximal_natural (0b11111111111111111111111111111111)
+#define minimal_natural (0b00000000000000000000000000000000)
+
+#define pstring_length (256)
+
#define echo(text) output ((text), sizeof ((text)) - 1)
-#define maximum(x, y) (((x) > (y)) ? (x) : (y))
-#define minimum(x, y) (((x) < (y)) ? (x) : (y))
+#define maximum_macro(x, y) (((x) > (y)) ? (x) : (y))
+#define minimum_macro(x, y) (((x) < (y)) ? (x) : (y))
#define array_length(array) (sizeof ((array)) / sizeof (* (array)))
-typedef void v0;
-typedef char c1;
+typedef void procedure;
+typedef void none;
+typedef void generic;
+typedef char character;
+typedef float real;
-typedef signed char s1;
-typedef signed short s2;
-typedef signed int s4;
-typedef signed long s8;
+typedef signed int integer;
+typedef unsigned int natural;
-typedef unsigned char u1;
-typedef unsigned short u2;
-typedef unsigned int u4;
-typedef unsigned long u8;
+typedef size_t caliber;
-typedef float f4;
-typedef double f8;
+typedef float real_32;
+typedef double real_64;
-typedef char pstring [256];
+typedef signed char integer_8;
+typedef signed short integer_16;
+typedef signed int integer_32;
+typedef signed long integer_64;
+
+typedef unsigned char natural_8;
+typedef unsigned short natural_16;
+typedef unsigned int natural_32;
+typedef unsigned long natural_64;
+
+typedef char pstring [pstring_length];
typedef enum {
false,
true
-} b4;
+} boolean;
typedef enum {
log_success, log_warning, log_failure, log_comment,
} file_type_enumeration;
typedef enum {
- effect_normal, effect_bold, effect_italic, effect_undefined_code,
+ effect_normal, effect_bold, effect_darken, effect_italic,
effect_underline, effect_blink, effect_reverse, effect_invisible_text,
effect_count
} effect_enumeration;
signal_count
} signal_enumeration;
-static c1 * cursor_name [cursor_count] = {
+static character * cursor_name [cursor_count] = {
"---",
"Left button", "Middle button", "Right button",
"Scroll up", "Scroll down"
};
-static c1 * signal_name [signal_count] = {
+static character * signal_name [signal_count] = {
"---",
"A", "B", "C", "D",
"E", "F", "G", "H",
"Key 6", "Key 7", "Key 8", "Key 9"
};
-static v0 randomize_seed_by_time (v0) {
- srand ((u4) time (null));
+static procedure random_integer_seed_by_time (none) {
+ srand ((natural) time (null));
}
-static s4 randomize (s4 from, s4 to) {
+static integer random_integer (integer from, integer to) {
return (rand () % (to - from + 1) + from);
}
-static u4 urandomize (u4 from, u4 to) {
- return ((u4) rand () % (to - from + 1) + from);
+static natural random_natural (natural from, natural to) {
+ return ((natural) rand () % (to - from + 1) + from);
}
-static f4 frandomize (f4 from, f4 to) {
- return (((float) rand () / (float) RAND_MAX) * (to - from) + from);
+static real random_real (real from, real to) {
+ return (((real) rand () / (real) RAND_MAX) * (to - from) + from);
}
-static s4 upper_bound (s4 a, s4 b) {
- return ((a > b) ? a : b);
-}
-
-static s4 lower_bound (s4 a, s4 b) {
- return ((a < b) ? a : b);
-}
-
-static v0 input (v0 * data, u8 size) {
+static procedure input (generic * data, caliber size) {
read (standard_input, data, size);
}
-static v0 output (v0 * data, u8 size) {
+static procedure output (generic * data, caliber size) {
write (standard_output, data, size);
}
-static v0 clean_up (v0 (* procedure) (v0)) {
- atexit (procedure);
+static procedure clean_up (procedure (* procedure_pointer) (none)) {
+ atexit (procedure_pointer);
}
#ifdef use_fatal_failure
-static v0 fatal_failure (b4 condition, c1 * message) {
+static procedure fatal_failure (boolean condition, character * message) {
if (condition == true) {
echo ("[\x1b[1;31m FATAL \x1b[0m] ");
- for (s4 index = 0; message [index] != '\0'; ++index) {
+ for (integer index = 0; message [index] != '\0'; ++index) {
output (& message [index], 1);
}
#define fatal_failure(...)
#endif
-static v0 execute (c1 * command) {
- s4 status = 0;
+static procedure execute (character * command) {
+ integer status = 0;
system (command);
fatal_failure (status != 0, "execute: System returned an error code.");
}
-static u4 tick_tock (v0) {
- return ((u4) clock ());
+static natural tick_tock (none) {
+ return ((natural) clock ());
}
-static u8 nano_time (v0) {
+static natural_64 nano_time (none) {
struct timespec time = { 0 };
- u8 result = 0;
+ natural_64 result = 0;
clock_gettime (CLOCK_MONOTONIC, & time);
- result = 1000000000ul * (u8) time.tv_sec + (u8) time.tv_nsec;
+ result = 1000000000ul * (natural_64) time.tv_sec + (natural_64) time.tv_nsec;
return (result);
}
-static v0 nano_wait (u8 time) {
+static procedure nano_wait (natural_64 time) {
struct timespec wait = {
time / 1000000000,
time % 1000000000
while (nanosleep (& wait, null)) continue;
}
-static f4 normal_r (u4 colour) { return ((float) ((colour >> 24) & 0xff) / 255.0f); }
-static f4 normal_g (u4 colour) { return ((float) ((colour >> 16) & 0xff) / 255.0f); }
-static f4 normal_b (u4 colour) { return ((float) ((colour >> 8) & 0xff) / 255.0f); }
-static f4 normal_a (u4 colour) { return ((float) ((colour >> 0) & 0xff) / 255.0f); }
+static natural maximum_natural (caliber count, ...) {
+ va_list list;
+
+ natural match = minimal_natural;
+
+ va_start (list, count);
+
+ for (caliber index = 0; index < count; ++index) {
+ natural current = (natural) va_arg (list, integer);
+
+ if (current > match) {
+ match = current;
+ }
+ }
+
+ va_end (list);
+
+ return (match);
+}
+
+static natural minimum_natural (caliber count, ...) {
+ va_list list;
+
+ natural match = maximal_natural;
+
+ va_start (list, count);
+
+ for (caliber index = 0; index < count; ++index) {
+ natural current = (natural) va_arg (list, integer);
+
+ if (current < match) {
+ match = current;
+ }
+ }
+
+ va_end (list);
+
+ return (match);
+}
+
+static integer maximum_integer (caliber count, ...) {
+ va_list list;
+
+ integer match = maximal_integer;
+
+ va_start (list, count);
+
+ for (caliber index = 0; index < count; ++index) {
+ integer current = va_arg (list, integer);
+
+ if (current > match) {
+ match = current;
+ }
+ }
+
+ va_end (list);
+
+ return (match);
+}
+
+static integer minimum_integer (caliber count, ...) {
+ va_list list;
+
+ integer match = minimal_integer;
-static u4 channel_r (u4 colour) { return ((colour >> 24) & 0xff); }
-static u4 channel_g (u4 colour) { return ((colour >> 16) & 0xff); }
-static u4 channel_b (u4 colour) { return ((colour >> 8) & 0xff); }
-static u4 channel_a (u4 colour) { return ((colour >> 0) & 0xff); }
+ va_start (list, count);
-static u4 colour_channel_reverse (u4 colour) {
- u4 r = channel_r (colour);
- u4 g = channel_g (colour);
- u4 b = channel_b (colour);
- u4 a = channel_a (colour);
+ for (caliber index = 0; index < count; ++index) {
+ integer current = va_arg (list, integer);
+
+ if (current < match) {
+ match = current;
+ }
+ }
+
+ va_end (list);
+
+ return (match);
+}
+
+static procedure exchange_integer (integer * a, integer * b) { integer c = * a; * a = * b; * b = c; }
+static procedure exchange_natural (natural * a, natural * b) { natural c = * a; * a = * b; * b = c; }
+static procedure exchange_real (real * a, real * b) { real c = * a; * a = * b; * b = c; }
+
+static procedure clamp_integer (integer * x, integer lower, integer upper) { if (* x < lower) * x = lower; if (* x > upper) * x = upper; }
+static procedure clamp_natural (natural * x, natural lower, natural upper) { if (* x < lower) * x = lower; if (* x > upper) * x = upper; }
+static procedure clamp_real (real * x, real lower, real upper) { if (* x < lower) * x = lower; if (* x > upper) * x = upper; }
+
+static real normal_r (natural colour) { return ((real) ((colour >> 24) & 0xff) / 255.0f); }
+static real normal_g (natural colour) { return ((real) ((colour >> 16) & 0xff) / 255.0f); }
+static real normal_b (natural colour) { return ((real) ((colour >> 8) & 0xff) / 255.0f); }
+static real normal_a (natural colour) { return ((real) ((colour >> 0) & 0xff) / 255.0f); }
+
+static natural channel_r (natural colour) { return ((colour >> 24) & 0xff); }
+static natural channel_g (natural colour) { return ((colour >> 16) & 0xff); }
+static natural channel_b (natural colour) { return ((colour >> 8) & 0xff); }
+static natural channel_a (natural colour) { return ((colour >> 0) & 0xff); }
+
+static natural colour_channel_reverse (natural colour) {
+ natural r = channel_r (colour);
+ natural g = channel_g (colour);
+ natural b = channel_b (colour);
+ natural a = channel_a (colour);
return ((a << 24) | (b << 16) | (g << 8) | (r << 0));
}
-static u4 colour_linear_interpolation (u4 colour_a, u4 colour_b, f4 scale) {
+static natural colour_linear_interpolation (natural colour_a, natural colour_b, real scale) {
if (scale <= 0.0f) {
return (colour_a);
}
return (colour_b);
}
- u4 r = (u4) ((1.0f - scale) * channel_r (colour_a) + scale * channel_r (colour_b));
- u4 g = (u4) ((1.0f - scale) * channel_g (colour_a) + scale * channel_g (colour_b));
- u4 b = (u4) ((1.0f - scale) * channel_b (colour_a) + scale * channel_b (colour_b));
- u4 a = (u4) ((1.0f - scale) * channel_a (colour_a) + scale * channel_a (colour_b));
+ natural r = (natural) ((1.0f - scale) * channel_r (colour_a) + scale * channel_r (colour_b));
+ natural g = (natural) ((1.0f - scale) * channel_g (colour_a) + scale * channel_g (colour_b));
+ natural b = (natural) ((1.0f - scale) * channel_b (colour_a) + scale * channel_b (colour_b));
+ natural a = (natural) ((1.0f - scale) * channel_a (colour_a) + scale * channel_a (colour_b));
return ((r << 24) | (g << 16) | (b << 8) | (a << 0));
}
-static v0 * allocate (u8 size) {
- c1 * data = null;
+static generic * allocate (caliber size) {
+ character * data = null;
fatal_failure (size <= 0, "allocate: Size is equal or below zero.");
return (data);
}
-static v0 * reallocate (v0 * data, u8 size) {
+static generic * reallocate (generic * data, caliber size) {
fatal_failure (size <= 0, "reallocate: Size is equal or below zero.");
data = realloc (data, size);
return (data);
}
-static v0 * deallocate (v0 * data) {
+static generic * deallocate (generic * data) {
fatal_failure (data == null, "deallocate: Data is null pointer.");
free (data);
return (null);
}
-static v0 * record (v0) {
- c1 * buffer = null;
- u8 offset = 0;
- u8 memory = 64 * 1024;
+static generic * record (none) {
+ character * buffer = null;
+ caliber offset = 0;
+ caliber memory = 64 * 1024;
buffer = reallocate (buffer, memory);
return (buffer);
}
-static b4 character_compare_array (c1 character, c1 * character_array) {
- for (u8 index = 0; character_array [index] != '\0'; ++index) {
- if (character == character_array [index]) {
+static boolean character_compare_array (character c, character * character_array) {
+ for (caliber index = 0; character_array [index] != '\0'; ++index) {
+ if (c == character_array [index]) {
return (true);
}
}
return (false);
}
-static b4 character_is_uppercase (c1 character) {
- return ((character >= 'A') && (character <= 'Z'));
+static boolean character_is_uppercase (character c) {
+ return ((c >= 'A') && (c <= 'Z'));
}
-static b4 character_is_lowercase (c1 character) {
- return ((character >= 'a') && (character <= 'z'));
+static boolean character_is_lowercase (character c) {
+ return ((c >= 'a') && (c <= 'z'));
}
-static b4 character_is_digit (c1 character) {
- return ((character >= '0') && (character <= '9'));
+static boolean character_is_digit (character c) {
+ return ((c >= '0') && (c <= '9'));
}
-static b4 character_is_letter (c1 character) {
- return (((character >= 'A') && (character <= 'Z')) || ((character >= 'a') && (character <= 'z')));
+static boolean character_is_letter (character c) {
+ return (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')));
}
-static b4 character_is_blank (c1 character) {
- return ((character == ' ') || (character == '\t') || (character == '\r') || (character == '\n'));
+static boolean character_is_blank (character c) {
+ return ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n'));
}
-static b4 character_is_symbol (c1 character) {
- return (((character >= '!') && (character <= '/')) || ((character >= ':') && (character <= '@'))
- || ((character >= '[') && (character <= '`')) || ((character >= '{') && (character <= '~')));
+static boolean character_is_symbol (character c) {
+ return (((c >= '!') && (c <= '/')) || ((c >= ':') && (c <= '@')) || ((c >= '[') && (c <= '`')) || ((c >= '{') && (c <= '~')));
}
-static b4 character_is_separator (c1 character) {
- return ((character != '_') && ((character_is_blank (character) == true) || (character_is_symbol (character) == true)));
+static boolean character_is_separator (character c) {
+ return ((c != '_') && ((character_is_blank (c) == true) || (character_is_symbol (c) == true)));
}
-static b4 character_is_identifier (c1 character) {
- return ((character == '_') || (character_is_letter (character) == true) || (character_is_digit (character) == true));
+static boolean character_is_identifier (character c) {
+ return ((c == '_') || (character_is_letter (c) == true) || (character_is_digit (c) == true));
}
-static b4 character_is_visible (c1 character) {
- return ((character >= '!') && (character <= '~'));
+static boolean character_is_visible (character c) {
+ return ((c >= '!') && (c <= '~'));
}
-static c1 * capitalize (c1 * string) {
+static boolean character_is_invisible (character c) {
+ return (character_is_visible (c) == false);
+}
+
+static character * capitalize (character * string) {
fatal_failure (string == null, "capitalize: String is null pointer.");
string [0] -= (character_is_lowercase (string [0]) == true) ? ' ' : '\0';
return (string);
}
-static c1 * uppercase (c1 * string) {
+static character * uppercase (character * string) {
fatal_failure (string == null, "uppercase: String is null pointer.");
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
string [index] += (character_is_lowercase (string [index]) == true) ? ' ' : '\0';
}
return (string);
}
-static c1 * lowercase (c1 * string) {
+static character * lowercase (character * string) {
fatal_failure (string == null, "lowercase: String is null pointer.");
- for (u4 index = 0; string [index] != '\0'; ++index) {
+ for (natural index = 0; string [index] != '\0'; ++index) {
string [index] -= (character_is_uppercase (string [index]) == true) ? ' ' : '\0';
}
return (string);
}
-static u8 string_length (c1 * string) {
- u8 length = 0;
+static caliber string_length (character * string) {
+ caliber length = 0;
fatal_failure (string == null, "string_length: String is null pointer.");
return (length);
}
-static c1 * string_nullify (c1 * string, u8 length) {
- fatal_failure (string == null, "string_nullify: String is null pointer.");
- fatal_failure (length <= 0, "string_nullify: Length is equal or below zero.");
+static character * string_nullify (character * destination, caliber length) {
+ fatal_failure (destination == null, "string_reverse_limit: Destination string is null pointer.");
+ fatal_failure (length <= 0, "string_reverse_limit: Length is equal or below zero.");
- for (u8 index = 0; index < length; ++index) {
- string [index] = '\0';
+ for (caliber index = 0; index < length; ++index) {
+ destination [index] = '\0';
}
- return (string);
+ return (destination);
}
-static c1 * string_reverse_limit (c1 * string, u8 limit) {
- fatal_failure (string == null, "string_reverse_limit: String is null pointer.");
- fatal_failure (limit <= 0, "string_reverse_limit: Limit is equal or below zero.");
+static character * string_reverse_limit (character * destination, caliber limit) {
+ fatal_failure (destination == null, "string_reverse_limit: Destination string is null pointer.");
+ fatal_failure (limit <= 0, "string_reverse_limit: Limit is equal or below zero.");
- for (u8 index = 0; index < limit / 2; ++index) {
- c1 temporary = string [index];
+ for (caliber index = 0; index < limit / 2; ++index) {
+ character temporary = destination [index];
- string [index] = string [limit - 1 - index];
- string [limit - 1 - index] = temporary;
+ destination [index] = destination [limit - 1 - index];
+ destination [limit - 1 - index] = temporary;
}
- return (string);
+ return (destination);
}
-static c1 * string_reverse (c1 * string) {
- return (string_reverse_limit (string, string_length (string)));
+static character * string_reverse (character * destination) {
+ return (string_reverse_limit (destination, string_length (destination)));
}
-static b4 string_compare_limit (c1 * string_a, c1 * string_b, u8 limit) {
+static boolean string_compare_limit (character * string_a, character * string_b, caliber limit) {
fatal_failure (string_a == null, "string_compare_limit: First source string is null pointer.");
fatal_failure (string_b == null, "string_compare_limit: Second source string is null pointer.");
fatal_failure (limit <= 0, "string_compare_limit: Limit is equal or below zero.");
- for (u8 index = 0; index < limit; ++index) {
+ for (caliber index = 0; index < limit; ++index) {
if (string_a [index] != string_b [index]) {
return (false);
}
return (true);
}
-static b4 string_compare (c1 * string_a, c1 * string_b) {
+static boolean string_compare (character * string_a, character * string_b) {
return (string_compare_limit (string_a, string_b, string_length (string_a) + 1));
}
-static c1 * string_copy_limit (c1 * destination, c1 * source, u8 limit) {
+static character * string_copy_limit (character * destination, character * source, caliber limit) {
fatal_failure (destination == null, "string_copy_limit: Destination string is null pointer.");
fatal_failure (source == null, "string_copy_limit: Source string is null pointer.");
fatal_failure (limit <= 0, "string_copy_limit: Limit is equal or below zero.");
- for (u8 index = 0; index < limit; ++index) {
+ for (caliber index = 0; index < limit; ++index) {
destination [index] = source [index];
}
return (destination);
}
-static c1 * string_copy (c1 * destination, c1 * source) {
+static character * string_copy (character * destination, character * source) {
return (string_copy_limit (destination, source, string_length (source) + 1));
}
-static c1 * string_concatenate_limit (c1 * destination, c1 * source, u8 limit) {
- u8 offset = string_length (destination);
+static character * string_concatenate_limit (character * destination, character * source, caliber limit) {
+ caliber offset = string_length (destination);
fatal_failure (destination == null, "string_concatenate_limit: Destination string is null pointer.");
fatal_failure (source == null, "string_concatenate_limit: Source string is null pointer.");
fatal_failure (limit <= 0, "string_concatenate_limit: Limit is equal or below zero.");
- for (u8 index = 0; index < limit; ++index) {
+ for (caliber index = 0; index < limit; ++index) {
destination [offset + index] = source [index];
}
return (destination);
}
-static c1 * string_concatenate (c1 * destination, c1 * source) {
+static character * string_concatenate (character * destination, character * source) {
return (string_concatenate_limit (destination, source, string_length (source) + 1));
}
-static c1 * string_duplicate (c1 * string) {
- c1 * duplicate = null;
+static character * string_duplicate (character * source) {
+ character * duplicate = allocate ((string_length (source) + 1) * sizeof (* duplicate));
- duplicate = allocate ((string_length (string) + 1) * sizeof (* duplicate));
-
- string_copy (duplicate, string);
+ string_copy (duplicate, source);
return (duplicate);
}
-static c1 * string_duplicate_limit (c1 * string, u4 limit) {
- c1 * duplicate = null;
-
- duplicate = allocate ((limit + 1) * sizeof (* duplicate));
+static character * string_duplicate_limit (character * source, caliber limit) {
+ character * duplicate = allocate ((limit + 1) * sizeof (* duplicate));
- string_copy_limit (duplicate, string, limit);
+ string_copy_limit (duplicate, source, limit);
return (duplicate);
}
-static c1 * string_align_left (c1 * string, u8 amount, c1 character) {
- u8 length = string_length (string);
-
- for (u8 offset = length; offset < amount; ++offset) {
- string [offset] = character;
+static character * string_align_left (character * destination, caliber amount, character with) {
+ for (caliber offset = string_length (destination); offset < amount; ++offset) {
+ destination [offset] = with;
}
- string [amount] = '\0';
+ destination [amount] = '\0';
- return (string);
+ return (destination);
+}
+
+static character * string_remove_extension (character * destination) {
+ caliber length = string_length (destination);
+
+ for (--length; destination [length] != '.'; --length);
+
+ destination [length] = '\0';
+
+ return (destination);
}
-static v0 memory_nullify (v0 * memory, u8 size) {
- c1 * cast = (c1 *) memory;
+static procedure memory_nullify (generic * memory, caliber size) {
+ character * cast = (character *) memory;
fatal_failure (memory == null, "memory_nullify: Memory is null pointer.");
- for (u8 offset = 0; offset < size; ++offset) {
- cast [offset] = (char) 0;
+ for (caliber offset = 0; offset < size; ++offset) {
+ cast [offset] = '\0';
}
}
-static s4 memory_compare (v0 * memory_0, v0 * memory_1, u8 size) {
- c1 * cast_0 = ( c1 *) memory_0;
- c1 * cast_1 = (c1 *) memory_1;
+static integer memory_compare (generic * memory_0, generic * memory_1, caliber size) {
+ character * cast_0 = (character *) memory_0;
+ character * cast_1 = (character *) memory_1;
fatal_failure (memory_0 == null, "memory_compare: Memory is null pointer.");
fatal_failure (memory_1 == null, "memory_compare: Source is null pointer.");
- for (u8 offset = 0; offset < size; ++offset) {
+ for (caliber offset = 0; offset < size; ++offset) {
if (cast_0 [offset] != cast_1 [offset]) {
return (false);
}
return (true);
}
-static v0 memory_copy (v0 * destination, v0 * source, u8 size) {
- c1 * cast_0 = ( c1 *) destination;
- c1 * cast_1 = (c1 *) source;
+static procedure memory_copy (generic * destination, generic * source, caliber size) {
+ character * cast_0 = (character *) destination;
+ character * cast_1 = (character *) source;
fatal_failure (destination == null, "memory_copy: Destination is null pointer.");
fatal_failure (source == null, "memory_copy: Source is null pointer.");
- for (u8 offset = 0; offset < size; ++offset) {
+ for (caliber offset = 0; offset < size; ++offset) {
cast_0 [offset] = cast_1 [offset];
}
}
-static c1 * string_remove_extension (c1 * string) {
- u8 length = string_length (string);
-
- for (--length; string [length] != '.'; --length);
-
- string [length] = '\0';
-
- return (string);
-}
-
-static v0 echo_clear (v0) {
+static procedure echo_clear (none) {
echo ("\033[2J\033[H");
}
-static v0 echo_colour (colour_enumeration colour, effect_enumeration effect) {
- c1 format [8] = "\033[ ;3 m";
+static procedure echo_colour (colour_enumeration colour, effect_enumeration effect) {
+ character format [8] = "\033[ ;3 m";
- format [2] = (char) (effect % effect_count) + '0';
- format [5] = (char) (colour % colour_count) + '0';
+ format [2] = (character) (effect % effect_count) + '0';
+ format [5] = (character) (colour % colour_count) + '0';
echo (format);
}
-static v0 echo_cancel (v0) {
+static procedure echo_cancel (none) {
echo ("\033[0m");
}
-static v0 show_cursor (b4 show) {
+static procedure show_cursor (boolean show) {
if (show == true) {
echo ("\033[?25h");
} else {
}
}
-static s4 file_open (c1 * path, s4 mode) {
+static integer file_open (character * path, integer mode) {
fatal_failure (path == null, "file_open: File path is null pointer.");
return (open (path, mode, 0777));
}
-static s4 file_close (s4 file) {
+static integer file_close (integer file) {
fatal_failure (file == -1, "file_close: Invalid file descriptor.");
close (file);
return (-1);
}
-static v0 file_read (s4 file, v0 * data, u8 size) {
+static procedure file_read (integer file, generic * data, caliber size) {
fatal_failure (file <= -1, "file_read: File descriptor is closed or invalid.");
fatal_failure (data == null, "file_read: Data is null pointer.");
fatal_failure (size == 0, "file_read: Size is zero.");
read (file, data, size);
}
-static v0 file_write (s4 file, v0 * data, u8 size) {
+static procedure file_write (integer file, generic * data, caliber size) {
fatal_failure (file <= -1, "file_write: File descriptor is closed or invalid.");
fatal_failure (data == null, "file_write: Data is null pointer.");
fatal_failure (size == 0, "file_write: Size is zero.");
write (file, data, size);
}
-static v0 file_echo (s4 file, c1 * data) {
+static procedure file_echo (integer file, character * data) {
file_write (file, data, string_length (data));
}
-static u8 file_seek (s4 file, s4 whence) {
+static caliber file_seek (integer file, integer whence) {
fatal_failure (file == -1, "file_seek: Invalid file descriptor.");
-
- return ((u8) lseek (file, 0, whence));
+/// CHECK FOR ERRORS
+ return ((caliber) lseek (file, 0, whence));
}
-static u8 file_size (c1 * path) {
+static caliber file_size (character * path) {
struct stat data = { 0 };
fatal_failure (path == null, "file_size: File path is null pointer.");
lstat (path, & data);
- return ((u8) data.st_size);
+ return ((caliber) data.st_size);
+}
+
+static boolean file_exists (character * path) {
+ fatal_failure (path == null, "file_record: File path is null pointer.");
+
+ return ((access (path, F_OK) == 0) ? true : false);
}
-static file_type_enumeration file_type (c1 * path) { /// SHIT BREAKS ON "./THIS/THAT.EXT"...
- c1 * extensions [file_type_count] = {
+static file_type_enumeration file_type (character * path) {
+ character * extensions [file_type_count] = {
".c", ".h", ".adb", ".ads", ".cpp", ".hpp", ".f90", ".mod",
".pas", ".d", ".go", ".jai", ".asm", ".eax", ".gas", ".fasm",
".hs", ".el", ".cfg", ".lua", ".sh", ".py", ".tcl", ".4th",
".obj", ".iqm", ".md5", ".ply", ".o", ".spv"
};
- fatal_failure (path == null, "file_type: File path is null pointer.");
+ natural cut_at = 0;
- for (; * path != '.'; ++path);
+ fatal_failure ((path == null) || (* path == '\0'), "file_type: File path is null pointer.");
+
+ for (cut_at = string_length (path) - 1; cut_at != 0; --cut_at) {
+ if (path [cut_at] == '.') break;
+ }
for (file_type_enumeration type = 0; type != file_type_count; ++type) {
- if (string_compare (path, extensions [type])) {
+ if (string_compare (& path [cut_at], extensions [type])) {
return (type);
}
}
- return (~ 0u);
+ return (file_type_count);
}
-static b4 file_exists (c1 * path) {
- fatal_failure (path == null, "file_record: File path is null pointer.");
-
- return ((access (path, F_OK) == 0) ? true : false);
-}
-
-static v0 file_remove (c1 * path) {
+static procedure file_remove (character * path) {
unlink (path);
}
-static v0 * file_record (c1 * path) {
- s4 file = -1;
- u8 size = 0;
- c1 * data = null;
+static generic * file_record (character * path) {
+ integer file = -1;
+ caliber size = 0;
+ character * data = null;
fatal_failure (path == null, "file_record: File path is null pointer.");
return (data);
}
-static c1 * file_import (c1 * path) {
- s4 file = -1;
- u8 size = 0;
- c1 * data = null;
+static character * file_import (character * path) {
+ integer file = -1;
+ caliber size = 0;
+ character * data = null;
fatal_failure (path == null, "file_import: File path is null pointer.");
return (data);
}
-static v0 file_export (c1 * path, c1 * data) {
- s4 file = -1;
+static procedure file_export (character * path, character * data) {
+ integer file = -1;
fatal_failure (path == null, "file_export: File path is null pointer.");
fatal_failure (data == null, "file_export: Data is null pointer.");
file = file_close (file);
}
-static v0 * folder_open (c1 * path) {
+static generic * folder_open (character * path) {
DIR * folder = null;
fatal_failure (path == null, "folder_open: Folder path is null pointer.");
folder = opendir (path);
- return ((v0 *) folder);
+ return ((generic *) folder);
}
-static c1 * folder_read (v0 * handle) {
+static character * folder_read (generic * handle) {
struct dirent * file = null;
DIR * folder = (DIR *) handle;
}
}
-static v0 * folder_close (v0 * handle) {
+static generic * folder_close (generic * handle) {
DIR * folder = (DIR *) handle;
fatal_failure (handle == null, "folder_read: Folder handle is null pointer.");
return (null);
}
-static c1 * * folder_create_path_list (c1 * folder, u4 * path_count, b4 sort) {
- v0 * handle = null;
- c1 * * path_array = 0;
+static character * * folder_create_path_list (character * folder, natural * path_count, boolean sort) {
+ procedure * handle = null;
+ character * * path_array = 0;
- (v0) sort;
+ (none) sort;
fatal_failure (folder == null, "folder_create_path_list: Folder handle is null pointer.");
fatal_failure (path_count == null, "folder_create_path_list: Path count address is null pointer.");
handle = folder_open (folder);
- for (c1 * path = folder_read (handle); path != null; path = folder_read (handle)) {
+ for (character * path = folder_read (handle); path != null; path = folder_read (handle)) {
if (path [0] != '.') {
(* path_count) += 1;
return (path_array);
}
-static c1 * * folder_remove_path_list (c1 * * path_array, u4 path_count) {
- for (u4 index = 0; index < path_count; ++index) {
+static character * * folder_remove_path_list (character * * path_array, natural path_count) {
+ for (natural index = 0; index < path_count; ++index) {
path_array [index] = deallocate (path_array [index]);
}
return (deallocate (path_array));
}
-static c1 * configuration_format (c1 * path) {
- static c1 buffer [512] = "";
+static character * configuration_format (character * path) {
+ static character buffer [512] = "";
string_copy (buffer, getenv ("HOME"));
string_concatenate (buffer, "/.config/xolatile/");
return (buffer);
}
-static b4 configuration_exists (c1 * path) {
+static boolean configuration_exists (character * path) {
return (file_exists (configuration_format (path)));
}
-static v0 configuration_remove (c1 * path) {
+static procedure configuration_remove (character * path) {
file_remove (configuration_format (path));
}
-static c1 * configuration_import (c1 * path) {
+static character * configuration_import (character * path) {
return (file_import (configuration_format (path)));
}
-static v0 configuration_export (c1 * path, c1 * data) {
+static procedure configuration_export (character * path, character * data) {
file_export (configuration_format (path), data);
}
-static b4 argument_compare (c1 * argument, c1 * short_option, c1 * long_option) {
+static boolean argument_compare (character * argument, character * short_option, character * long_option) {
return ((string_compare (argument, short_option) == true) || (string_compare (argument, long_option) == true));
}
-static u4 string_full_width (c1 * string, u4 tab_width) {
- u4 width = 0;
- u4 count = 0;
+static natural string_full_width (character * string, natural tab_width) {
+ natural width = 0;
+ natural count = 0;
do {
if (* string == '\t') {
return (width - 1);
}
-static u4 string_full_height (c1 * string) {
- u4 height = 0;
+static natural string_full_height (character * string) {
+ natural height = 0;
do {
if (* string == '\n') {
return (height + 1);
}
-static u4 string_limit_to_number (c1 * string, u4 limit) {
- u4 number = 0;
+static natural string_limit_to_number (character * string, natural limit) {
+ natural number = 0;
- for (u4 index = 0; (string [index] != '\0') && (index < limit); ++index) {
+ for (natural index = 0; (string [index] != '\0') && (index < limit); ++index) {
number *= 10;
- number += (u4) (string [index] - '0');
+ number += (natural) (string [index] - '0');
}
return (number);
}
-static u4 string_to_number (c1 * string) {
+static natural string_to_number (character * string) {
return (string_limit_to_number (string, string_length (string)));
}
-static c1 * number_to_string (s4 number) {
- static c1 string [34] = "";
+static character * number_to_string (integer number) {
+ static character string [34] = "";
- u4 index = 0;
- b4 sign = false;
+ natural index = 0;
+ boolean sign = false;
string_nullify (string, sizeof (string));
sign = false;
}
- for (index = 0; (number != 0) && (index < (u4) sizeof (string) - 1); ++index) {
- string [index] = (char) (number % 10) + '0';
+ for (index = 0; (number != 0) && (index < (natural) sizeof (string) - 1); ++index) {
+ string [index] = (character) (number % 10) + '0';
number /= 10;
}
return (string);
}
-static c1 * format_to_string (s4 number, b4 sign, u4 base, u8 amount, c1 character) {
- static c1 string [36];
+static character * format_to_string (integer number, boolean sign, natural base, caliber amount, character with) {
+ static character string [36];
- s4 i;
+ integer i;
string_nullify (string, sizeof (string));
string [0] = '0';
string [1] = '\0';
- string_align_left (string, amount, character);
+ string_align_left (string, amount, with);
return (string);
}
string_reverse (string);
- string_align_left (string, amount, character);
+ string_align_left (string, amount, with);
return (string);
}
-static c1 * format (c1 * base, ...) {
- static c1 string [1024];
+static character * format (character * base, ...) {
+ static character string [1024];
va_list list;
case ('%'): {
++base;
switch (* base) {
- case ('%'): string_concatenate (string, "%"); break;
- case ('i'): string_concatenate (string, number_to_string (va_arg (list, int))); break;
- case ('s'): string_concatenate (string, va_arg (list, c1 *)); break;
- default: string_concatenate (string, "?"); break;
+ case ('%'): string_concatenate (string, "%"); break;
+ case ('i'): string_concatenate (string, number_to_string (va_arg (list, integer))); break;
+ case ('s'): string_concatenate (string, va_arg (list, character *)); break;
+ default: string_concatenate (string, "?"); break;
}
} break;
default: {
return (string);
}
-static v0 print (c1 * format, ...) {
+static procedure print (character * format, ...) {
va_list list;
va_start (list, format);
output ("%", 1);
} break;
case ('i'): {
- c1 * string = number_to_string (va_arg (list, int));
+ character * string = number_to_string (va_arg (list, integer));
output (string, string_length (string));
} break;
case ('f'): {
- f4 number = (float) va_arg (list, double);
- c1 * upper = number_to_string ((int) number);
- c1 * lower = number_to_string ((int) (number * 1000.0f) % 1000);
+ real data = (real) va_arg (list, real_64);
+ character * upper = number_to_string ((integer) data);
+ character * lower = number_to_string ((integer) (data * 1000.0f) % 1000);
output (upper, string_length (upper));
output (".", 1);
output (lower, string_length (lower));
} break;
case ('t'): {
- s4 toggle = (va_arg (list, int));
- echo_colour ((toggle == true) ? colour_green : colour_red, effect_normal);
- output ((toggle == true) ? "+" : "-", 1);
+ integer data = (va_arg (list, integer));
+ echo_colour ((data == true) ? colour_green : colour_red, effect_normal);
+ output ((data == true) ? "+" : "-", 1);
echo_cancel ();
} break;
case ('b'): {
- s4 b4ean = (va_arg (list, int));
- output ((b4ean == true) ? "true" : "false", (b4ean == true) ? 4 : 5);
+ integer data = (va_arg (list, integer));
+ output ((data == true) ? "true" : "false", (data == true) ? 4 : 5);
} break;
case ('c'): {
- c1 character = (char) va_arg (list, int);
- output (& character, 1);
+ character data = (character) va_arg (list, integer);
+ output (& data, 1);
} break;
case ('s'): {
- c1 * string = va_arg (list, c1 *);
- output (string, string_length (string));
+ character * data = va_arg (list, character *);
+ output (data, string_length (data));
} break;
default: {
output ("?", 1);
va_end (list);
}
-static v0 uint_exchange (u4 * a, u4 * b) {
- u4 c = * a;
+static procedure conditional_print (boolean condition, character * format, ...) {
+ va_list list;
- * a = * b;
- * b = c;
-}
+ if (condition == false) return;
-static v0 float_exchange (f4 * a, f4 * b) {
- f4 c = * a;
+ va_start (list, format);
+
+ for (; * format != character_null; ++format) {
+ switch (* format) {
+ case ('%'): {
+ ++format;
+ switch (* format) {
+ case ('%'): {
+ output ("%", 1);
+ } break;
+ case ('i'): {
+ character * string = number_to_string (va_arg (list, integer));
+ output (string, string_length (string));
+ } break;
+ case ('f'): {
+ real data = (real) va_arg (list, real_64);
+ character * upper = number_to_string ((integer) data);
+ character * lower = number_to_string ((integer) (data * 1000.0f) % 1000);
+ output (upper, string_length (upper));
+ output (".", 1);
+ output (lower, string_length (lower));
+ } break;
+ case ('t'): {
+ integer data = (va_arg (list, integer));
+ echo_colour ((data == true) ? colour_green : colour_red, effect_normal);
+ output ((data == true) ? "+" : "-", 1);
+ echo_cancel ();
+ } break;
+ case ('b'): {
+ integer data = (va_arg (list, integer));
+ output ((data == true) ? "true" : "false", (data == true) ? 4 : 5);
+ } break;
+ case ('c'): {
+ character data = (character) va_arg (list, integer);
+ output (& data, 1);
+ } break;
+ case ('s'): {
+ character * data = va_arg (list, character *);
+ output (data, string_length (data));
+ } break;
+ default: {
+ output ("?", 1);
+ } break;
+ }
+ } break;
+ case ('/'): {
+ ++format;
+ switch (* format) {
+ case ('/'): echo ("/"); break;
+ case ('s'): echo ("[\x1b[1;32mSuccess\x1b[0m]"); break;
+ case ('f'): echo ("[\x1b[1;31mFailure\x1b[0m]"); break;
+ case ('w'): echo ("[\x1b[1;33mWarning\x1b[0m]"); break;
+ case ('c'): echo ("[\x1b[1;30mComment\x1b[0m]"); break;
+ case ('A'): echo ("\x1b[0m"); break;
+ case ('B'): echo ("\x1b[1m"); break;
+ case ('C'): echo ("\x1b[2m"); break;
+ case ('D'): echo ("\x1b[3m"); break;
+ case ('E'): echo ("\x1b[4m"); break;
+ case ('F'): echo ("\x1b[5m"); break;
+ case ('G'): echo ("\x1b[6m"); break;
+ case ('H'): echo ("\x1b[7m"); break;
+ case ('0'): echo ("\x1b[30m"); break;
+ case ('1'): echo ("\x1b[31m"); break;
+ case ('2'): echo ("\x1b[32m"); break;
+ case ('3'): echo ("\x1b[33m"); break;
+ case ('4'): echo ("\x1b[34m"); break;
+ case ('5'): echo ("\x1b[35m"); break;
+ case ('6'): echo ("\x1b[36m"); break;
+ case ('7'): echo ("\x1b[37m"); break;
+ case ('-'): echo ("\x1b[0m"); break;
+ default: echo ("?"); break;
+ }
+ } break;
+ default: {
+ output (format, 1);
+ } break;
+ }
+ }
- * a = * b;
- * b = c;
+ va_end (list);
}
#ifdef use_mathematics
#define pi (3.14159265f)
-static f4 sign (f4 x) { return ((x > 0.0f) ? + 1.0f : - 1.0f); }
-static f4 binary_sign (u4 x) { return ((x > 0) ? + 1.0f : - 1.0f); }
+static real sign (real x) { return ((x > 0.0f) ? + 1.0f : - 1.0f); }
+static real binary_sign (natural x) { return ((x > 0) ? + 1.0f : - 1.0f); }
-static f4 square_root (f4 x) { return (sqrtf (x)); }
-static f4 cube_root (f4 x) { return (cbrtf (x)); }
+static real square_root (real x) { return (sqrtf (x)); }
+static real cube_root (real x) { return (cbrtf (x)); }
-static f4 sine (f4 x) { return (sinf (x)); }
-static f4 cosine (f4 x) { return (cosf (x)); }
-static f4 tangent (f4 x) { return (tanf (x)); }
+static real sine (real x) { return (sinf (x)); }
+static real cosine (real x) { return (cosf (x)); }
+static real tangent (real x) { return (tanf (x)); }
-static f4 arc_sine (f4 x) { return (asinf (x)); }
-static f4 arc_cosine (f4 x) { return (acosf (x)); }
-static f4 arc_tangent (f4 x) { return (atanf (x)); }
+static real arc_sine (real x) { return (asinf (x)); }
+static real arc_cosine (real x) { return (acosf (x)); }
+static real arc_tangent (real x) { return (atanf (x)); }
-static f4 cosecant (f4 x) { return (1.0f / sinf (x)); }
-static f4 secant (f4 x) { return (1.0f / cosf (x)); }
-static f4 cotangent (f4 x) { return (1.0f / tanf (x)); }
+static real cosecant (real x) { return (1.0f / sinf (x)); }
+static real secant (real x) { return (1.0f / cosf (x)); }
+static real cotangent (real x) { return (1.0f / tanf (x)); }
#endif
ui_button_upper_left, ui_button_upper_right, ui_button_lower_left, ui_button_lower_right,
ui_button_middle,
ui_fill_bar_left, ui_fill_bar_middle, ui_fill_bar_right, ui_fill_bar_base,
- ui_tiny_fill_bar_middle, ui_tiny_fill_bar_left, ui_tiny_fill_bar_right, ui_tiny_fill_middle,
+ ui_tiny_fill_bar_left, ui_tiny_fill_bar_middle, ui_tiny_fill_bar_right, ui_tiny_fill_bar_base,
ui_check_box_off, ui_check_box_on,
- ui_end_turn_button,
+ ui_cursor,
ui_icon_frame, ui_overicon_frame, ui_ubericon_frame,
ui_scroll_bar_lower, ui_scroll_bar_middle, ui_scroll_bar_upper, ui_scroll_bar_slider,
ui_separator_left, ui_separator_middle, ui_separator_right, ui_separator_center,
ui_title_bar_left, ui_title_bar_middle, ui_title_bar_right,
ui_subcount
-} ui_subtype;
+} ui_subtype_enumeration;
typedef enum {
ui_window = ui_window_left,
ui_status = ui_status_left,
ui_menu = ui_menu_left,
ui_button = ui_button_left
-} ui_type;
+} ui_type_enumeration;
typedef struct {
- b4 freeview;
- u4 ignore;
- u4 camera_x;
- u4 camera_y;
- c1 * help_box_none;
- c1 * help_box_text;
- u4 help_box_icon;
- u4 side_panel;
- u4 font;
- u4 monofont;
- u4 sprite [ui_subcount];
- u4 width [ui_subcount];
- u4 height [ui_subcount];
- u4 separator_size;
- u4 icon_size;
- u4 overicon_size;
- u4 ubericon_size;
- u4 title_bar_size;
- u4 fill_bar_size;
- u4 scroll_bar_size;
- u4 camera_speed;
+ natural count;
+ natural limit;
+ natural active;
+ natural ignore;
+ natural help_box_icon;
+ character * help_box_none;
+ character * help_box_text;
+ character * * folder;
+ natural * * sprite;
+ natural * * width;
+ natural * * height;
+ natural * font;
+ natural * monofont;
+ natural * separator_size;
+ natural * icon_size;
+ natural * overicon_size;
+ natural * ubericon_size;
+ natural * title_bar_size;
+ natural * fill_bar_size;
+ natural * tiny_fill_bar_size;
+ natural * scroll_bar_size;
} ui_structure;
-static ui_structure * ui_initialize (cross_structure * cross) {
- c1 * subtype_file_name [ui_subcount] = {
- "window_left", "window_right", "window_upper", "window_lower",
- "window_upper_left", "window_upper_right", "window_lower_left", "window_lower_right",
- "frame_left", "frame_right", "frame_upper", "frame_lower",
- "frame_upper_left", "frame_upper_right", "frame_lower_left", "frame_lower_right",
- "status_left", "status_right", "status_upper", "status_lower",
- "status_upper_left", "status_upper_right", "status_lower_left", "status_lower_right",
- "status_middle",
- "menu_left", "menu_right", "menu_upper", "menu_lower",
- "menu_upper_left", "menu_upper_right", "menu_lower_left", "menu_lower_right",
- "menu_middle",
- "button_left", "button_right", "button_upper", "button_lower",
- "button_upper_left", "button_upper_right", "button_lower_left", "button_lower_right",
- "button_middle",
- "fill_bar_left", "fill_bar_middle", "fill_bar_right", "fill_bar_base",
- "tiny_fill_bar_left", "tiny_fill_bar_middle", "tiny_fill_bar_right", "tiny_fill_bar_base",
- "check_box_off", "check_box_on",
- "end_turn_button",
- "cursor",
- "icon_frame", "overicon_frame", "ubericon_frame",
- "scroll_bar_lower", "scroll_bar_middle", "scroll_bar_upper", "scroll_bar_slider",
- "separator_left", "separator_middle", "separator_right", "separator_center",
- "title_bar_left", "title_bar_middle", "title_bar_right"
- };
-
+static character * ui_subtype_file_name [ui_subcount] = {
+ "window_left", "window_right", "window_upper", "window_lower",
+ "window_upper_left", "window_upper_right", "window_lower_left", "window_lower_right",
+ "frame_left", "frame_right", "frame_upper", "frame_lower",
+ "frame_upper_left", "frame_upper_right", "frame_lower_left", "frame_lower_right",
+ "status_left", "status_right", "status_upper", "status_lower",
+ "status_upper_left", "status_upper_right", "status_lower_left", "status_lower_right",
+ "status_middle",
+ "menu_left", "menu_right", "menu_upper", "menu_lower",
+ "menu_upper_left", "menu_upper_right", "menu_lower_left", "menu_lower_right",
+ "menu_middle",
+ "button_left", "button_right", "button_upper", "button_lower",
+ "button_upper_left", "button_upper_right", "button_lower_left", "button_lower_right",
+ "button_middle",
+ "fill_bar_left", "fill_bar_middle", "fill_bar_right", "fill_bar_base",
+ "tiny_fill_bar_left", "tiny_fill_bar_middle", "tiny_fill_bar_right", "tiny_fill_bar_base",
+ "check_box_off", "check_box_on",
+ "cursor",
+ "icon_frame", "overicon_frame", "ubericon_frame",
+ "scroll_bar_lower", "scroll_bar_middle", "scroll_bar_upper", "scroll_bar_slider",
+ "separator_left", "separator_middle", "separator_right", "separator_center",
+ "title_bar_left", "title_bar_middle", "title_bar_right"
+};
+
+static ui_structure * ui_initialize (cross_structure * cross, natural limit) {
ui_structure * ui = allocate (sizeof (* ui));
- ui->freeview = false;
+ ui->limit = limit;
+
ui->ignore = ~ 0u;
- ui->camera_x = 0;
- ui->camera_y = 0;
ui->help_box_none = string_duplicate ("---");
ui->help_box_text = ui->help_box_none;
ui->help_box_icon = ui->ignore;
- ui->side_panel = 400;
-
- ui->font = cross_font_import (cross, configuration_format ("xui/regular"), ' ', '~', 0xffee0000u);
- ui->monofont = cross_font_import (cross, configuration_format ("xui/monospace"), ' ', '~', 0xffeeee00u);
- for (u4 index = 0; index < ui_subcount; ++index) {
- c1 * file_name = configuration_format (format ("xui/%s", subtype_file_name [index]));
-
- ui->sprite [index] = cross_sprite_import (cross, file_name);
-
- ui->width [index] = cross_sprite_width (cross, ui->sprite [index]);
- ui->height [index] = cross_sprite_height (cross, ui->sprite [index]);
+ ui->folder = allocate (limit * sizeof (* ui->folder));
+ ui->sprite = allocate (limit * sizeof (* ui->sprite));
+ ui->width = allocate (limit * sizeof (* ui->width));
+ ui->height = allocate (limit * sizeof (* ui->height));
+ ui->font = allocate (limit * sizeof (* ui->font));
+ ui->monofont = allocate (limit * sizeof (* ui->monofont));
+ ui->separator_size = allocate (limit * sizeof (* ui->separator_size));
+ ui->icon_size = allocate (limit * sizeof (* ui->icon_size));
+ ui->overicon_size = allocate (limit * sizeof (* ui->overicon_size));
+ ui->ubericon_size = allocate (limit * sizeof (* ui->ubericon_size));
+ ui->title_bar_size = allocate (limit * sizeof (* ui->title_bar_size));
+ ui->fill_bar_size = allocate (limit * sizeof (* ui->fill_bar_size));
+ ui->tiny_fill_bar_size = allocate (limit * sizeof (* ui->tiny_fill_bar_size));
+ ui->scroll_bar_size = allocate (limit * sizeof (* ui->scroll_bar_size));
+
+ for (natural index = 0; index < limit; ++index) {
+ ui->sprite [index] = allocate (ui_subcount * sizeof (* * ui->sprite));
+ ui->width [index] = allocate (ui_subcount * sizeof (* * ui->width));
+ ui->height [index] = allocate (ui_subcount * sizeof (* * ui->height));
}
- ui->separator_size = ui->height [ui_separator_middle];
- ui->icon_size = ui->height [ui_icon_frame];
- ui->overicon_size = ui->height [ui_overicon_frame];
- ui->ubericon_size = ui->height [ui_ubericon_frame];
- ui->title_bar_size = ui->height [ui_title_bar_middle];
- ui->fill_bar_size = ui->height [ui_fill_bar_middle];
- ui->scroll_bar_size = ui->width [ui_scroll_bar_middle];
-
- print ("[/2Success/-] Initialized UI structure.\n");
+ print ("/s Initialized UI structure.\n");
return (ui);
}
static ui_structure * ui_deinitialize (ui_structure * ui) {
- ui->help_box_none = deallocate (ui->help_box_none);
+ for (natural index = 0; index < ui->limit; ++index) {
+ ui->sprite [index] = deallocate (ui->sprite [index]);
+ ui->width [index] = deallocate (ui->width [index]);
+ ui->height [index] = deallocate (ui->height [index]);
- print ("[/2Success/-] Deinitialized UI information.\n");
+ if (ui->folder [index] != null) {
+ ui->folder [index] = deallocate (ui->folder [index]);
+ }
+ }
+
+ ui->folder = deallocate (ui->folder);
+ ui->sprite = deallocate (ui->sprite);
+ ui->width = deallocate (ui->width);
+ ui->height = deallocate (ui->height);
+ ui->font = deallocate (ui->font);
+ ui->monofont = deallocate (ui->monofont);
+ ui->separator_size = deallocate (ui->separator_size);
+ ui->icon_size = deallocate (ui->icon_size);
+ ui->overicon_size = deallocate (ui->overicon_size);
+ ui->ubericon_size = deallocate (ui->ubericon_size);
+ ui->title_bar_size = deallocate (ui->title_bar_size);
+ ui->fill_bar_size = deallocate (ui->fill_bar_size);
+ ui->tiny_fill_bar_size = deallocate (ui->tiny_fill_bar_size);
+ ui->scroll_bar_size = deallocate (ui->scroll_bar_size);
+ ui->help_box_none = deallocate (ui->help_box_none);
+
+ print ("/s Deinitialized UI structure.\n");
return (deallocate (ui));
}
-static s4 ui_offset_x (cross_structure * cross, ui_structure * ui) {
- return (ui->camera_x - cross->window_width / 2);
+static boolean ui_validate_dimensions (ui_structure * ui, ui_subtype_enumeration subtype) {
+ if (ui->width [ui->active] [subtype] != ui->height [ui->active] [subtype]) {
+ print ("/w Mismatching sizes for sprite '%s', in UI '%s'.\n", ui_subtype_file_name [subtype], ui->folder [ui->active]);
+ }
}
-static s4 ui_offset_y (cross_structure * cross, ui_structure * ui) {
- return (ui->camera_y - cross->window_height / 2);
+static boolean ui_validate_width_dimensions (ui_structure * ui, ui_subtype_enumeration begin, ui_subtype_enumeration end) {
+ for (ui_subtype_enumeration index = begin; index <= end; ++index) {
+ if (ui->width [ui->active] [index] != ui->width [ui->active] [begin]) {
+ print ("/w Mismatching width for sprite '%s', in UI '%s'.\n", ui_subtype_file_name [index], ui->folder [ui->active]);
+ }
+ }
}
-static u4 ui_side_panel (ui_structure * ui) {
- return (ui->side_panel); /// MAKE IT WINDOW SIZE DEPENDENT?
+static boolean ui_validate_height_dimensions (ui_structure * ui, ui_subtype_enumeration begin, ui_subtype_enumeration end) {
+ for (ui_subtype_enumeration index = begin; index <= end; ++index) {
+ if (ui->height [ui->active] [index] != ui->height [ui->active] [begin]) {
+ print ("/w Mismatching height for sprite '%s', in UI '%s'.\n", ui_subtype_file_name [index], ui->folder [ui->active]);
+ }
+ }
}
-static v0 ui_camera_upper (ui_structure * ui) { ui->freeview = true; ui->camera_y -= ui->camera_speed; }
-static v0 ui_camera_lower (ui_structure * ui) { ui->freeview = true; ui->camera_y += ui->camera_speed; }
-static v0 ui_camera_left (ui_structure * ui) { ui->freeview = true; ui->camera_x -= ui->camera_speed; }
-static v0 ui_camera_right (ui_structure * ui) { ui->freeview = true; ui->camera_x += ui->camera_speed; }
+static boolean ui_validate_grid_dimensions (ui_structure * ui, ui_subtype_enumeration begin, ui_subtype_enumeration end) {
+ for (ui_subtype_enumeration index = begin; index <= end; ++index) {
+ if ((ui->width [ui->active] [index] != ui->width [ui->active] [begin])
+ || (ui->height [ui->active] [index] != ui->height [ui->active] [begin])) {
+ print ("/w Mismatching grid for sprite '%s', in UI '%s'.\n", ui_subtype_file_name [index], ui->folder [ui->active]);
+ }
+ }
+}
-static v0 ui_render (cross_structure * cross, ui_structure * ui, ui_subtype index, s4 x, s4 y) {
- cross_render_sprite (cross, ui->sprite [index], x, y);
+static procedure ui_configure (cross_structure * cross, ui_structure * ui, character * folder) {
+ if (ui->count >= ui->limit) {
+ print ("/w You are trying to configure more UIs than you set the limit to.\n");
+ return;
+ }
+
+ natural current = ui->active = ++ui->count - 1;
+
+ if (cross->very_verbose_spam == true) {
+ print ("/c Importing UI sprites from '%s' at index %i...\n", folder, current);
+ }
+
+ if (folder != null) {
+ ui->folder [current] = string_duplicate (folder);
+ }
+
+ ui->font [current] = cross_font_import (cross, (folder == null)
+ ? configuration_format ("xui/regular")
+ : format ("%s/regular", folder), ' ', '~' + 0, 0);
+
+ ui->monofont [current] = cross_font_import (cross, (folder == null)
+ ? configuration_format ("xui/monospace")
+ : format ("%s/monospace", folder), ' ', '~' + 1, 0);
+
+ for (natural index = 0; index < ui_subcount; ++index) {
+ character * file_name = (folder == null)
+ ? configuration_format (format ("xui/%s", ui_subtype_file_name [index]))
+ : format ("%s/%s", folder, ui_subtype_file_name [index]);
+
+ ui->sprite [current] [index] = cross_sprite_import (cross, file_name);
+
+ ui->width [current] [index] = cross_sprite_width (cross, ui->sprite [current] [index]);
+ ui->height [current] [index] = cross_sprite_height (cross, ui->sprite [current] [index]);
+
+ if ((ui->width [current] [index] == 0) || (ui->height [current] [index] == 0)) {
+ print ("/f UI sprite '%s' has width or height zero.\n", file_name);
+ exit (log_failure);
+ }
+ }
+
+ ui_validate_dimensions (ui, ui_cursor);
+ ui_validate_dimensions (ui, ui_icon_frame);
+ ui_validate_dimensions (ui, ui_overicon_frame);
+ ui_validate_dimensions (ui, ui_ubericon_frame);
+
+ ui_validate_grid_dimensions (ui, ui_status_left, ui_status_lower_right);
+ ui_validate_grid_dimensions (ui, ui_menu_left, ui_menu_lower_right);
+ ui_validate_grid_dimensions (ui, ui_button_left, ui_button_lower_right);
+
+ ui_validate_width_dimensions (ui, ui_scroll_bar_lower, ui_scroll_bar_slider);
+
+ ui_validate_height_dimensions (ui, ui_fill_bar_left, ui_fill_bar_base);
+ ui_validate_height_dimensions (ui, ui_tiny_fill_bar_left, ui_tiny_fill_bar_base);
+ ui_validate_height_dimensions (ui, ui_separator_left, ui_separator_center);
+ ui_validate_height_dimensions (ui, ui_title_bar_left, ui_title_bar_right);
+
+ ui->separator_size [current] = ui->height [current] [ui_separator_middle];
+ ui->icon_size [current] = ui->height [current] [ui_icon_frame];
+ ui->overicon_size [current] = ui->height [current] [ui_overicon_frame];
+ ui->ubericon_size [current] = ui->height [current] [ui_ubericon_frame];
+ ui->title_bar_size [current] = ui->height [current] [ui_title_bar_middle];
+ ui->fill_bar_size [current] = ui->height [current] [ui_fill_bar_middle];
+ ui->tiny_fill_bar_size [current] = ui->height [current] [ui_tiny_fill_bar_middle];
+ ui->scroll_bar_size [current] = ui->width [current] [ui_scroll_bar_middle];
+
+ if (cross->very_verbose_spam == true) {
+ print ("/c Imported UI sprites from '%s' at index %i.\n", folder, ui->count);
+ }
+}
+
+static procedure ui_render (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, integer x, integer y) {
+ cross_render_sprite (cross, ui->sprite [ui->active] [index], x, y);
}
-static v0 ui_render_colour (cross_structure * cross, ui_structure * ui, ui_subtype index, u4 colour, s4 x, s4 y) {
- cross_render_sprite_colour (cross, ui->sprite [index], colour, x, y);
+static procedure ui_render_colour (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, natural colour, integer x, integer y) {
+ cross_render_sprite_colour (cross, ui->sprite [ui->active] [index], colour, x, y);
}
-static v0 ui_subrender (cross_structure * cross, ui_structure * ui, ui_subtype index, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
- cross_render_sprite_crop (cross, ui->sprite [index], x, y, u, v, width, height);
+static procedure ui_subrender (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, integer x, integer y, natural u, natural v,
+ natural width, natural height) {
+ cross_render_sprite_crop (cross, ui->sprite [ui->active] [index], x, y, u, v, width, height);
}
-static v0 ui_subrender_colour (cross_structure * cross, ui_structure * ui, ui_subtype index, u4 colour, s4 x, s4 y, u4 u, u4 v, u4 width, u4 height) {
- cross_render_sprite_crop_colour (cross, ui->sprite [index], colour, x, y, u, v, width, height);
+static procedure ui_subrender_colour (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, natural colour, integer x, integer y,
+ natural u, natural v, natural width, natural height) {
+ cross_render_sprite_crop_colour (cross, ui->sprite [ui->active] [index], colour, x, y, u, v, width, height);
}
-static v0 ui_render_horizontal (cross_structure * cross, ui_structure * ui, ui_subtype index, s4 x, s4 y, u4 width) {
- s4 entire = (width / ui->width [index]) * ui->width [index];
+static procedure ui_render_horizontal (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, integer x, integer y, natural width) {
+ integer entire = (width / ui->width [ui->active] [index]) * ui->width [ui->active] [index];
- for (u4 margin = 0; margin < width / ui->width [index]; ++margin) {
- ui_render (cross, ui, index, x + margin * ui->width [index], y);
+ for (natural margin = 0; margin < width / ui->width [ui->active] [index]; ++margin) {
+ ui_render (cross, ui, index, x + margin * ui->width [ui->active] [index], y);
}
- if (width % ui->width [index] > 0) {
- ui_subrender (cross, ui, index, x + entire, y, 0, 0, width % ui->width [index], ui->height [index]);
+ if (width % ui->width [ui->active] [index] > 0) {
+ ui_subrender (cross, ui, index, x + entire, y, 0, 0, width % ui->width [ui->active] [index], ui->height [ui->active] [index]);
}
}
-static v0 ui_render_horizontal_colour (cross_structure * cross, ui_structure * ui, ui_subtype index, u4 colour, s4 x, s4 y, u4 width) {
- s4 entire = (width / ui->width [index]) * ui->width [index];
+static procedure ui_render_horizontal_colour (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, natural colour,
+ integer x, integer y, natural width) {
+ //~natural width_divisor = width / ui->width [ui->active] [index];
+ //~natural width_remainder = width % ui->width [ui->active] [index];
+
+ //~for (natural offset = 0; offset < width_divisor; ++offset) {
+ //~ui_render_colour (cross, ui, index, colour, x + offset * ui->width [ui->active] [index], y);
+ //~}
+
+ //~if (width_remainder > 0) {
+ //~ui_subrender_colour (cross, ui, index, colour, x + width - width_remainder, y, 0, 0, width_remainder, ui->height [ui->active] [index]);
+ //~}
+ integer entire = (width / ui->width [ui->active] [index]) * ui->width [ui->active] [index];
- for (u4 margin = 0; margin < width / ui->width [index]; ++margin) {
- ui_render_colour (cross, ui, index, colour, x + margin * ui->width [index], y);
+ for (natural margin = 0; margin < width / ui->width [ui->active] [index]; ++margin) {
+ ui_render (cross, ui, index, x + margin * ui->width [ui->active] [index], y);
}
- if (width % ui->width [index] > 0) {
- ui_subrender_colour (cross, ui, index, colour, x + entire, y, 0, 0, width % ui->width [index], ui->height [index]);
+ if (width % ui->width [ui->active] [index] > 0) {
+ ui_subrender (cross, ui, index, x + entire, y, 0, 0, width % ui->width [ui->active] [index], ui->height [ui->active] [index]);
}
}
-static v0 ui_render_vertical (cross_structure * cross, ui_structure * ui, ui_subtype index, s4 x, s4 y, u4 height) {
- s4 entire = (height / ui->height [index]) * ui->height [index];
+static procedure ui_render_vertical (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, integer x, integer y, natural height) {
+ integer entire = (height / ui->height [ui->active] [index]) * ui->height [ui->active] [index];
- for (u4 margin = 0; margin < height / ui->height [index]; ++margin) {
- ui_render (cross, ui, index, x, y + margin * ui->height [index]);
+ for (natural margin = 0; margin < height / ui->height [ui->active] [index]; ++margin) {
+ ui_render (cross, ui, index, x, y + margin * ui->height [ui->active] [index]);
}
- if (height % ui->height [index] > 0) {
- ui_subrender (cross, ui, index, x, y + entire, 0, 0, ui->width [index], height % ui->height [index]);
+ if (height % ui->height [ui->active] [index] > 0) {
+ ui_subrender (cross, ui, index, x, y + entire, 0, 0, ui->width [ui->active] [index], height % ui->height [ui->active] [index]);
}
}
-static v0 ui_render_background (cross_structure * cross, ui_structure * ui, ui_subtype index, s4 x, s4 y, u4 width, u4 height) {
- u4 offset_x = (width / ui->width [index]) * ui->width [index];
- u4 offset_y = (height / ui->height [index]) * ui->height [index];
+static procedure ui_render_background (cross_structure * cross, ui_structure * ui, ui_subtype_enumeration index, integer x, integer y, natural width, natural height) {
+ natural offset_x = (width / ui->width [ui->active] [index]) * ui->width [ui->active] [index];
+ natural offset_y = (height / ui->height [ui->active] [index]) * ui->height [ui->active] [index];
- u4 cutoff_x = width % ui->width [index];
- u4 cutoff_y = height % ui->height [index];
+ natural cutoff_x = width % ui->width [ui->active] [index];
+ natural cutoff_y = height % ui->height [ui->active] [index];
- for (u4 vertical = 0; vertical < height / ui->height [index]; ++vertical) {
- for (u4 horizontal = 0; horizontal < width / ui->width [index]; ++horizontal) {
- ui_render (cross, ui, index, x + horizontal * ui->width [index], y + vertical * ui->height [index]);
+ for (natural vertical = 0; vertical < height / ui->height [ui->active] [index]; ++vertical) {
+ for (natural horizontal = 0; horizontal < width / ui->width [ui->active] [index]; ++horizontal) {
+ ui_render (cross, ui, index, x + horizontal * ui->width [ui->active] [index], y + vertical * ui->height [ui->active] [index]);
}
- if (width % ui->width [index] > 0) {
- ui_subrender (cross, ui, index, x + offset_x, y + vertical * ui->height [index], 0, 0, cutoff_x, ui->height [index]);
+ if (width % ui->width [ui->active] [index] > 0) {
+ ui_subrender (cross, ui, index, x + offset_x, y + vertical * ui->height [ui->active] [index], 0, 0, cutoff_x, ui->height [ui->active] [index]);
}
}
- for (u4 horizontal = 0; horizontal < width / ui->width [index]; ++horizontal) {
- ui_subrender (cross, ui, index, x + horizontal * ui->width [index], y + offset_y, 0, 0, ui->width [index], cutoff_y);
+ for (natural horizontal = 0; horizontal < width / ui->width [ui->active] [index]; ++horizontal) {
+ ui_subrender (cross, ui, index, x + horizontal * ui->width [ui->active] [index], y + offset_y, 0, 0, ui->width [ui->active] [index], cutoff_y);
}
- if (width % ui->width [index] > 0) {
+ if (width % ui->width [ui->active] [index] > 0) {
ui_subrender (cross, ui, index, x + offset_x, y + offset_y, 0, 0, cutoff_x, cutoff_y);
}
}
-static v0 ui_screen_overlay (cross_structure * cross) {
- cross_render_rectangle_vertical_gradient (cross, 0, 0, cross->window_width, cross->window_height / 2, 0xcc, 0x00);
- cross_render_rectangle_vertical_gradient (cross, 0, cross->window_height / 2, cross->window_width, cross->window_height / 2, 0x00, 0xcc);
+static procedure ui_screen_overlay (cross_structure * cross, natural colour) {
+ cross_render_rectangle (cross, 0, 0, cross->window_width, cross->window_height, colour);
}
-static v0 ui_render_grid (cross_structure * cross, ui_structure * ui, ui_type element, s4 x, s4 y, u4 width, u4 height, u4 margin, b4 background) {
- u4 upper_length = width - ui->width [element + 4] - ui->width [element + 5];
- u4 lower_length = width - ui->width [element + 6] - ui->width [element + 7];
- u4 left_length = height - ui->height [element + 4] - ui->height [element + 6];
- u4 right_length = height - ui->height [element + 5] - ui->height [element + 7];
+static procedure ui_render_grid (cross_structure * cross, ui_structure * ui, ui_type_enumeration element, integer x, integer y, natural width,
+ natural height, boolean background) {
+ if ((width < ui->width [ui->active] [element + 4] + ui->width [ui->active] [element + 5] + ui->width [ui->active] [element + 2]) ||
+ (height < ui->height [ui->active] [element + 4] + ui->height [ui->active] [element + 6] + ui->height [ui->active] [element + 0])) {
+ return;
+ }
- s4 upper_offset_x = ui->width [element + 4];
- s4 lower_offset_x = ui->width [element + 6];
- s4 lower_offset_y = height - ui->height [element + 3];
+ natural upper_length = width - ui->width [ui->active] [element + 4] - ui->width [ui->active] [element + 5];
+ natural lower_length = width - ui->width [ui->active] [element + 6] - ui->width [ui->active] [element + 7];
+ natural left_length = height - ui->height [ui->active] [element + 4] - ui->height [ui->active] [element + 6];
+ natural right_length = height - ui->height [ui->active] [element + 5] - ui->height [ui->active] [element + 7];
- s4 right_offset_x = width - ui->width [element + 1];
- s4 left_offset_y = ui->height [element + 4];
- s4 right_offset_y = ui->height [element + 5];
+ integer upper_offset_x = ui->width [ui->active] [element + 4];
+ integer lower_offset_x = ui->width [ui->active] [element + 6];
+ integer lower_offset_y = height - ui->height [ui->active] [element + 3];
- s4 upper_right_offset_x = width - ui->width [element + 5];
- s4 lower_right_offset_x = width - ui->width [element + 7];
- s4 lower_left_offset_y = height - ui->height [element + 6];
- s4 lower_right_offset_y = height - ui->height [element + 7];
+ integer right_offset_x = width - ui->width [ui->active] [element + 1];
+ integer left_offset_y = ui->height [ui->active] [element + 4];
+ integer right_offset_y = ui->height [ui->active] [element + 5];
- if ((background == true) && (width > 2 * margin) && (height > 2 * margin)) {
- ui_render_background (cross, ui, element + 8, x + margin, y + margin, width - 2 * margin, height - 2 * margin);
- }
+ integer upper_right_offset_x = width - ui->width [ui->active] [element + 5];
+ integer lower_right_offset_x = width - ui->width [ui->active] [element + 7];
+ integer lower_left_offset_y = height - ui->height [ui->active] [element + 6];
+ integer lower_right_offset_y = height - ui->height [ui->active] [element + 7];
ui_render_vertical (cross, ui, element + 0, x, y + left_offset_y, left_length);
ui_render_vertical (cross, ui, element + 1, x + right_offset_x, y + right_offset_y, right_length);
ui_render (cross, ui, element + 5, x + upper_right_offset_x, y);
ui_render (cross, ui, element + 6, x, y + lower_left_offset_y);
ui_render (cross, ui, element + 7, x + lower_right_offset_x, y + lower_right_offset_y);
+
+ if (background == true) {
+ ui_render_background (cross, ui, element + 8, x + upper_offset_x, y + left_offset_y, upper_length, left_length);
+ }
}
-static v0 ui_render_window (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width, u4 height) {
- ui_render_grid (cross, ui, ui_window, x, y, width, height, 0, false);
+static procedure ui_render_window (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width, natural height) {
+ ui_render_grid (cross, ui, ui_window, x, y, width, height, false);
}
-static v0 ui_render_frame (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width, u4 height) {
- ui_render_grid (cross, ui, ui_frame, x, y, width, height, 0, false);
+static procedure ui_render_frame (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width, natural height) {
+ ui_render_grid (cross, ui, ui_frame, x, y, width, height, false);
}
-static v0 ui_render_status (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width, u4 height) {
- ui_render_grid (cross, ui, ui_status, x, y, width, height, 16, true);
+static procedure ui_render_status (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width, natural height) {
+ ui_render_grid (cross, ui, ui_status, x, y, width, height, true);
}
-static v0 ui_render_menu (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width, u4 height) {
- ui_render_grid (cross, ui, ui_menu, x, y, width, height, 24, true);
+static procedure ui_render_menu (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width, natural height) {
+ ui_render_grid (cross, ui, ui_menu, x, y, width, height, true);
}
-static v0 ui_render_button (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width, u4 height) {
- ui_render_grid (cross, ui, ui_button, x, y, width, height, 16, true);
+static procedure ui_render_button (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width, natural height) {
+ ui_render_grid (cross, ui, ui_button, x, y, width, height, true);
}
-static v0 ui_render_separator (cross_structure * cross, ui_structure * ui, s4 x, s4 y, u4 width) {
- u4 margin = ui->width [ui_separator_left];
- u4 length = width - margin - ui->width [ui_separator_right];
+static procedure ui_render_separator (cross_structure * cross, ui_structure * ui, integer x, integer y, natural width) {
+ natural margin = ui->width [ui->active] [ui_separator_left];
+ natural length = width - margin - ui->width [ui->active] [ui_separator_right];
ui_render (cross, ui, ui_separator_left, x, y);
ui_render (cross, ui, ui_separator_right, x + margin + length, y);
- ui_render (cross, ui, ui_separator_center, x + (width - ui->width [ui_separator_center]) / 2, y);
+ ui_render (cross, ui, ui_separator_center, x + (width - ui->width [ui->active] [ui_separator_center]) / 2, y);
}
-static v0 ui_render_title_bar (cross_structure * cross, ui_structure * ui, c1 * title, s4 x, s4 y, u4 width) {
- u4 margin = ui->width [ui_title_bar_left];
- u4 length = width - margin - ui->width [ui_title_bar_right];
+static procedure ui_render_title_bar (cross_structure * cross, ui_structure * ui, character * title, integer x, integer y, natural width) {
+ natural margin = ui->width [ui->active] [ui_title_bar_left];
+ natural length = width - margin - ui->width [ui->active] [ui_title_bar_right];
ui_render (cross, ui, ui_title_bar_left, x, y);
ui_render (cross, ui, ui_title_bar_right, x + margin + length, y);
- cross_render_string (cross, title, ui->font, x + margin + 8, y + 8, 1, 0x112233ff);
+ cross_render_string (cross, title, ui->font [ui->active], x + margin + 8, y + 8, 1, 0x112233ff);
}
-static v0 ui_render_icon_and_text (cross_structure * cross, ui_structure * ui, c1 * title, u4 icon, s4 x, s4 y) {
+static procedure ui_render_icon_and_text (cross_structure * cross, ui_structure * ui, character * title, natural icon, integer x, integer y,
+ natural colour) {
cross_render_sprite (cross, icon, x, y);
-
- cross_render_string (cross, title, ui->font, x - 2 + ui->icon_size, y + 2, 1, 0x112233ffu);
+//////////////////////////////////////////
+ cross_render_string (cross, title, ui->font [ui->active], x - 2 + ui->icon_size [ui->active], y + 2, 1.0f, colour);
}
-static v0 ui_render_scroll_bar (cross_structure * cross, ui_structure * ui, f4 slider, s4 x, s4 y, u4 height) {
- u4 margin = ui->height [ui_scroll_bar_upper];
- u4 length = height - margin - ui->height [ui_scroll_bar_lower];
+static procedure ui_render_scroll_bar (cross_structure * cross, ui_structure * ui, real slider, integer x, integer y, natural height) {
+ natural margin = ui->height [ui->active] [ui_scroll_bar_upper];
+ natural length = height - margin - ui->height [ui->active] [ui_scroll_bar_lower];
+
+ real slider_offset = slider * (real) (length - ui->height [ui->active] [ui_scroll_bar_slider]);
ui_render (cross, ui, ui_scroll_bar_upper, x, y);
ui_render (cross, ui, ui_scroll_bar_lower, x, y + margin + length);
- ui_render (cross, ui, ui_scroll_bar_slider, x, y + margin + (u4) (slider * (float) (length - ui->height [ui_scroll_bar_slider])));
+ ui_render (cross, ui, ui_scroll_bar_slider, x, y + margin + (natural) slider_offset);
}
-static v0 ui_render_fill_bar (cross_structure * cross, ui_structure * ui, f4 fill, u4 colour, s4 x, s4 y, u4 width) {
- u4 margin = ui->width [ui_fill_bar_left];
- u4 length = width - margin - ui->width [ui_fill_bar_right];
+static procedure ui_render_fill_bar (cross_structure * cross, ui_structure * ui, real fill, natural colour, integer x, integer y, natural width) {
+ natural margin = ui->width [ui->active] [ui_fill_bar_left];
+ natural length = width - margin - ui->width [ui->active] [ui_fill_bar_right];
ui_render (cross, ui, ui_fill_bar_left, x, y);
ui_render (cross, ui, ui_fill_bar_right, x + margin + length, y);
- ui_render_horizontal_colour (cross, ui, ui_fill_bar_base, colour, x + margin, y, (u4) (fill * (float) length));
+ ui_render_horizontal_colour (cross, ui, ui_fill_bar_base, colour, x + margin, y, (natural) (fill * (real) length));
}
-static v0 ui_render_icon (cross_structure * cross, ui_structure * ui, u4 icon, s4 x, s4 y) {
- cross_render_sprite (cross, ui->sprite [ui_icon_frame], x, y);
+static procedure ui_render_icon (cross_structure * cross, ui_structure * ui, natural icon, integer x, integer y) {
+ cross_render_sprite (cross, ui->sprite [ui->active] [ui_icon_frame], x, y);
if (icon != ui->ignore) {
cross_render_sprite (cross, icon, x, y);
}
}
-static v0 ui_render_overicon (cross_structure * cross, ui_structure * ui, u4 icon, s4 x, s4 y) {
+static procedure ui_render_overicon (cross_structure * cross, ui_structure * ui, natural icon, integer x, integer y) {
if (icon != ui->ignore) {
cross_render_sprite (cross, icon, x, y);
}
- cross_render_sprite (cross, ui->sprite [ui_overicon_frame], x, y);
+ cross_render_sprite (cross, ui->sprite [ui->active] [ui_overicon_frame], x, y);
}
-static v0 ui_render_ubericon (cross_structure * cross, ui_structure * ui, u4 icon, s4 x, s4 y) {
- cross_render_sprite (cross, ui->sprite [ui_ubericon_frame], x, y);
+static procedure ui_render_ubericon (cross_structure * cross, ui_structure * ui, natural icon, integer x, integer y, natural offset) {
+ cross_render_sprite (cross, ui->sprite [ui->active] [ui_ubericon_frame], x, y);
if (icon != ui->ignore) {
- cross_render_sprite (cross, icon, x + 16, y + 16);
+ cross_render_sprite (cross, icon, x + offset, y + offset);
}
}
-static v0 ui_render_menu_full (cross_structure * cross, ui_structure * ui, c1 * title, s4 x, s4 y, u4 width, u4 height) {
- u4 margin = 24;
-
- ui_screen_overlay (cross);
+static procedure ui_render_menu_full (cross_structure * cross, ui_structure * ui, character * title, integer x, integer y, natural width,
+ natural height, natural overlay_colour, natural margin) {
+ if (overlay_colour != 0x00000000u) {
+ ui_screen_overlay (cross, overlay_colour);
+ }
ui_render_menu (cross, ui, x, y, width, height);
if (title != null) {
- ui_render_title_bar (cross, ui, format ("<%s>", title), x + margin, y + margin / 2 - ui->title_bar_size, width - 2 * margin);
+ ui_render_title_bar (cross, ui, title, x + margin, y + margin / 2 - ui->title_bar_size [ui->active], width - 2 * margin);
}
}
#include <vulkan/vulkan.h>
typedef struct {
- b4 active;
- b4 reconfigure_active;
- b4 validation_layers;
- b4 hide_cursor_full;
- b4 hide_cursor;
- u4 time;
-
- u4 cursor; /// TODO: PROPER INPUT
- s4 cursor_x;
- s4 cursor_y;
-
- b4 signal [signal_count];
-
- f4 pixel_width;
- f4 pixel_height;
- u4 frame;
- u4 width;
- u4 height;
- u4 sprite_count;
- u4 * * sprite_data;
- u4 * sprite_width;
- u4 * sprite_height;
- f4 * sprite_u;
- f4 * sprite_v;
- u4 font_count;
- u4 * * font_index;
- u4 * * font_width;
- u4 * * font_height;
- c1 * font_begin;
- c1 * font_end;
+ boolean active;
+ boolean reconfigure_active;
+ boolean validation_layers;
+ boolean hide_cursor_full;
+ boolean hide_cursor;
+ natural time;
+
+ natural cursor; /// TODO: PROPER INPUT
+ integer cursor_x;
+ integer cursor_y;
+
+ boolean signal [signal_count];
+
+ real pixel_width;
+ real pixel_height;
+ natural frame;
+ natural width;
+ natural height;
+ natural sprite_count;
+ natural * * sprite_data;
+ natural * sprite_width;
+ natural * sprite_height;
+ real * sprite_u;
+ real * sprite_v;
+ natural font_count;
+ natural * * font_index;
+ natural * * font_width;
+ natural * * font_height;
+ character * font_begin;
+ character * font_end;
xcb_connection_t * connection;
xcb_screen_t * screen;
xcb_window_t window;
- u4 global_time;
- u4 gameplay_time;
- u4 animation_time;
- u4 framerate;
- u4 gameplay_framerate;
- u4 animation_framerate;
- u8 frame_time_in_ns;
+ natural global_time;
+ natural gameplay_time;
+ natural animation_time;
+ natural framerate;
+ natural gameplay_framerate;
+ natural animation_framerate;
+ natural_64 frame_time_in_ns;
VkInstance instance;
VkSurfaceKHR surface;
VkPhysicalDevice physical_device;
VkQueue queue;
- u4 queue_index;
- VkDevice logical_device;
- u4 image_count;
+ natural queue_index;
+ VkDevice boolean_device;
+ natural image_count;
VkExtent2D extent;
VkFormat format;
VkPresentModeKHR present_mode;
VkCommandBuffer transfer_buffer;
VkBuffer vertex_buffer;
VkDeviceMemory vertex_memory;
- f4 * vertex_data;
+ real * vertex_data;
VkDeviceSize vertex_size;
- u4 vertex_count;
- u4 vertex_limit;
+ natural vertex_count;
+ natural vertex_limit;
VkBuffer index_buffer;
VkDeviceMemory index_memory;
- u4 * index_data;
+ natural * index_data;
VkDeviceSize index_size;
- u4 index_count;
- u4 index_limit;
+ natural index_count;
+ natural index_limit;
VkSampler sampler;
VkImage layout_image;
VkDeviceMemory layout_memory;
VkImageView layout_image_view;
- u4 * layout_data;
- u4 layout_size;
- u4 layout_width;
- u4 layout_height;
+ natural * layout_data;
+ natural layout_size;
+ natural layout_width;
+ natural layout_height;
} vulkan_structure;
-static c1 * vulkan_continue_execution [] = {
+static character * vulkan_continue_execution [] = {
"/s Commands successfully completed.\n",
"/w Fence or query hasn't yet completed.\n",
"/w Wait operation hasn't completed in the specified time.\n",
"/w Return array was too small for the result.\n"
};
-static c1 * vulkan_break_execution [] = {
+static character * vulkan_break_execution [] = {
"/f Host memory allocation has failed.\n",
"/f Device memory allocation has failed.\n",
"/f Initialization of an object couldn't be completed.\n",
"/f Undefined error has occured.\n"
};
-static v0 vulkan_result (VkResult result) {
+static procedure vulkan_result (VkResult result) {
if (result == 0) {
return;
} else if (result > 0) {
}
}
-static vulkan_structure * vulkan_initialize (u8 quad_memory, u8 layout_side, u4 gameplay_framerate, u4 animation_framerate) {
+static vulkan_structure * vulkan_initialize (caliber quad_memory, caliber layout_side, natural gameplay_framerate, natural animation_framerate) {
vulkan_structure * vulkan = allocate (sizeof (* vulkan));
vulkan->vertex_limit = quad_memory * 32;
print ("/c Destroying and deallocating all the bullshit used so far...\n");
vulkan_result (vkQueueWaitIdle (vulkan->queue));
- vulkan_result (vkDeviceWaitIdle (vulkan->logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan->boolean_device));
vulkan->sprite_width = deallocate (vulkan->sprite_width);
vulkan->sprite_height = deallocate (vulkan->sprite_height);
vulkan->sprite_v = deallocate (vulkan->sprite_v);
if (vulkan->font_count > 0) {
- for (u4 index = 0; index < vulkan->font_count; ++index) {
+ for (natural index = 0; index < vulkan->font_count; ++index) {
vulkan->font_index [index] = deallocate (vulkan->font_index [index]);
vulkan->font_width [index] = deallocate (vulkan->font_width [index]);
vulkan->font_height [index] = deallocate (vulkan->font_height [index]);
vulkan->font_end = deallocate (vulkan->font_end);
}
- vkFreeDescriptorSets (vulkan->logical_device, vulkan->descriptor_pool, vulkan->image_count, vulkan->descriptor_sets);
+ vkFreeDescriptorSets (vulkan->boolean_device, vulkan->descriptor_pool, vulkan->image_count, vulkan->descriptor_sets);
vulkan->descriptor_set_layouts = deallocate (vulkan->descriptor_set_layouts);
vulkan->descriptor_sets = deallocate (vulkan->descriptor_sets);
- vkDestroyDescriptorPool (vulkan->logical_device, vulkan->descriptor_pool, null);
- vkDestroySampler (vulkan->logical_device, vulkan->sampler, null);
- vkDestroyImageView (vulkan->logical_device, vulkan->layout_image_view, null);
- vkDestroyImage (vulkan->logical_device, vulkan->layout_image, null);
- vkFreeMemory (vulkan->logical_device, vulkan->layout_memory, null);
+ vkDestroyDescriptorPool (vulkan->boolean_device, vulkan->descriptor_pool, null);
+ vkDestroySampler (vulkan->boolean_device, vulkan->sampler, null);
+ vkDestroyImageView (vulkan->boolean_device, vulkan->layout_image_view, null);
+ vkDestroyImage (vulkan->boolean_device, vulkan->layout_image, null);
+ vkFreeMemory (vulkan->boolean_device, vulkan->layout_memory, null);
vulkan->layout_data = deallocate (vulkan->layout_data);
vulkan->index_data = deallocate (vulkan->index_data);
vulkan->vertex_data = deallocate (vulkan->vertex_data);
/*
- vkFreeCommandBuffers (vulkan->logical_device, vulkan->command_pool, vulkan->image_count, vulkan->command_buffers);
+ vkFreeCommandBuffers (vulkan->boolean_device, vulkan->command_pool, vulkan->image_count, vulkan->command_buffers);
*/
vulkan->command_buffers = deallocate (vulkan->command_buffers);
- vkDestroyCommandPool (vulkan->logical_device, vulkan->command_pool, null);
+ vkDestroyCommandPool (vulkan->boolean_device, vulkan->command_pool, null);
- for (u4 index = 0; index < vulkan->image_count; ++index) {
- vkDestroyFramebuffer (vulkan->logical_device, vulkan->framebuffers [index], null);
+ for (natural index = 0; index < vulkan->image_count; ++index) {
+ vkDestroyFramebuffer (vulkan->boolean_device, vulkan->framebuffers [index], null);
}
vulkan->framebuffers = deallocate (vulkan->framebuffers);
- vkDestroyPipeline (vulkan->logical_device, vulkan->pipeline, null);
- vkDestroyPipelineLayout (vulkan->logical_device, vulkan->pipeline_layout, null);
- vkDestroyShaderModule (vulkan->logical_device, vulkan->fragment_shader, null);
- vkDestroyShaderModule (vulkan->logical_device, vulkan->vertex_shader, null);
- vkDestroyDescriptorSetLayout (vulkan->logical_device, vulkan->descriptor_set_layout, null);
- vkDestroyRenderPass (vulkan->logical_device, vulkan->render_pass, null);
-
- for (u4 index = 0; index < vulkan->image_count; ++index) {
- vkDestroySemaphore (vulkan->logical_device, vulkan->semaphore_set_1 [index], null);
- vkDestroySemaphore (vulkan->logical_device, vulkan->semaphore_set_2 [index], null);
- vkDestroyFence (vulkan->logical_device, vulkan->fence_set_1 [index], null);
+ vkDestroyPipeline (vulkan->boolean_device, vulkan->pipeline, null);
+ vkDestroyPipelineLayout (vulkan->boolean_device, vulkan->pipeline_layout, null);
+ vkDestroyShaderModule (vulkan->boolean_device, vulkan->fragment_shader, null);
+ vkDestroyShaderModule (vulkan->boolean_device, vulkan->vertex_shader, null);
+ vkDestroyDescriptorSetLayout (vulkan->boolean_device, vulkan->descriptor_set_layout, null);
+ vkDestroyRenderPass (vulkan->boolean_device, vulkan->render_pass, null);
+
+ for (natural index = 0; index < vulkan->image_count; ++index) {
+ vkDestroySemaphore (vulkan->boolean_device, vulkan->semaphore_set_1 [index], null);
+ vkDestroySemaphore (vulkan->boolean_device, vulkan->semaphore_set_2 [index], null);
+ vkDestroyFence (vulkan->boolean_device, vulkan->fence_set_1 [index], null);
}
vulkan->semaphore_set_1 = deallocate (vulkan->semaphore_set_1);
vulkan->semaphore_set_2 = deallocate (vulkan->semaphore_set_2);
vulkan->fence_set_1 = deallocate (vulkan->fence_set_1);
- for (u4 index = 0; index < vulkan->image_count; ++index) {
- vkDestroyImageView (vulkan->logical_device, vulkan->image_views [index], null);
+ for (natural index = 0; index < vulkan->image_count; ++index) {
+ vkDestroyImageView (vulkan->boolean_device, vulkan->image_views [index], null);
}
vulkan->image_views = deallocate (vulkan->image_views);
- vkDestroySwapchainKHR (vulkan->logical_device, vulkan->swapchain, null);
+ vkDestroySwapchainKHR (vulkan->boolean_device, vulkan->swapchain, null);
vulkan->images = deallocate (vulkan->images);
vkDestroySurfaceKHR (vulkan->instance, vulkan->surface, null);
- vkDestroyDevice (vulkan->logical_device, null);
+ vkDestroyDevice (vulkan->boolean_device, null);
vkDestroyInstance (vulkan->instance, null);
xcb_destroy_window (vulkan->connection, vulkan->window);
return (deallocate (vulkan));
}
-static u4 vulkan_choose_memory_property (vulkan_structure * vulkan, u4 wanted) {
- u4 index = 0;
- u4 usable = 0;
+static natural vulkan_choose_memory_property (vulkan_structure * vulkan, natural wanted) {
+ natural index = 0;
+ natural usable = 0;
VkPhysicalDeviceMemoryProperties memory_properties = { 0 };
return (usable);
}
-static v0 vulkan_create_buffer (vulkan_structure * vulkan, VkBuffer * buffer, VkDeviceMemory * memory, VkDeviceSize size, VkMemoryPropertyFlags usage) {
- u4 wanted_memory_index = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
+static procedure vulkan_create_buffer (vulkan_structure * vulkan, VkBuffer * buffer, VkDeviceMemory * memory, VkDeviceSize size, VkMemoryPropertyFlags usage) {
+ natural wanted_memory_index = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
VkBufferCreateInfo buffer_information = { 0 };
VkMemoryRequirements memory_requirements = { 0 };
buffer_information.usage = usage;
buffer_information.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- vulkan_result (vkCreateBuffer (vulkan->logical_device, & buffer_information, null, buffer));
+ vulkan_result (vkCreateBuffer (vulkan->boolean_device, & buffer_information, null, buffer));
- vkGetBufferMemoryRequirements (vulkan->logical_device, * buffer, & memory_requirements);
+ vkGetBufferMemoryRequirements (vulkan->boolean_device, * buffer, & memory_requirements);
memory_allocation_information.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
memory_allocation_information.allocationSize = memory_requirements.size;
memory_allocation_information.memoryTypeIndex = vulkan_choose_memory_property (vulkan, wanted_memory_index);
- vulkan_result (vkAllocateMemory (vulkan->logical_device, & memory_allocation_information, null, memory));
+ vulkan_result (vkAllocateMemory (vulkan->boolean_device, & memory_allocation_information, null, memory));
- vulkan_result (vkBindBufferMemory (vulkan->logical_device, * buffer, * memory, 0));
+ vulkan_result (vkBindBufferMemory (vulkan->boolean_device, * buffer, * memory, 0));
}
-static v0 vulkan_begin_command_buffer (vulkan_structure * vulkan) {
+static procedure vulkan_begin_command_buffer (vulkan_structure * vulkan) {
VkCommandBufferAllocateInfo command_buffer_allocation_information = { 0 };
VkCommandBufferBeginInfo command_buffer_begin_information = { 0 };
command_buffer_begin_information.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
command_buffer_begin_information.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
- vulkan_result (vkAllocateCommandBuffers (vulkan->logical_device, & command_buffer_allocation_information, & vulkan->transfer_buffer));
+ vulkan_result (vkAllocateCommandBuffers (vulkan->boolean_device, & command_buffer_allocation_information, & vulkan->transfer_buffer));
vulkan_result (vkBeginCommandBuffer (vulkan->transfer_buffer, & command_buffer_begin_information));
}
-static v0 vulkan_end_command_buffer (vulkan_structure * vulkan) {
+static procedure vulkan_end_command_buffer (vulkan_structure * vulkan) {
VkSubmitInfo submit_information = { 0 };
vkEndCommandBuffer (vulkan->transfer_buffer);
vkQueueWaitIdle (vulkan->queue);
- vkFreeCommandBuffers (vulkan->logical_device, vulkan->command_pool, 1, & vulkan->transfer_buffer);
+ vkFreeCommandBuffers (vulkan->boolean_device, vulkan->command_pool, 1, & vulkan->transfer_buffer);
vulkan->transfer_buffer = VK_NULL_HANDLE;
}
-static v0 vulkan_create_window (vulkan_structure * vulkan, c1 * application) {
- u4 window_flags [2] = { 0 };
+static procedure vulkan_create_window (vulkan_structure * vulkan, character * application) {
+ natural window_flags [2] = { 0 };
vulkan->time = tick_tock ();
XCB_EVENT_MASK_BUTTON_PRESS;
xcb_create_window (vulkan->connection, vulkan->screen->root_depth, vulkan->window, vulkan->screen->root, 0, 0,
- (u2) vulkan->width, (u2) vulkan->height, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ (natural_16) vulkan->width, (natural_16) vulkan->height, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT,
vulkan->screen->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, window_flags);
print ("/c Created /3XCB window/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_instance (vulkan_structure * vulkan, c1 * application) {
- u4 current = 0;
- u4 general = 0;
+static procedure vulkan_create_instance (vulkan_structure * vulkan, character * application) {
+ natural current = 0;
+ natural general = 0;
VkApplicationInfo application_information = { 0 };
VkInstanceCreateInfo instance_information = { 0 };
- u4 instance_layer_count = 0;
- u4 * instance_layer_index = null;
+ natural instance_layer_count = 0;
+ natural * instance_layer_index = null;
VkLayerProperties * instance_layer_array = null;
- u4 instance_extension_count = 0;
- u4 * instance_extension_index = null;
+ natural instance_extension_count = 0;
+ natural * instance_extension_index = null;
VkExtensionProperties * instance_extension_array = null;
- u4 default_instance_layer_count = (u4) (vulkan->validation_layers == true);
- u4 default_instance_extension_count = 2;
+ natural default_instance_layer_count = (natural) (vulkan->validation_layers == true);
+ natural default_instance_extension_count = 2;
- c1 * default_instance_layer_array [VK_MAX_EXTENSION_NAME_SIZE] = {
+ character * default_instance_layer_array [VK_MAX_EXTENSION_NAME_SIZE] = {
"VK_LAYER_KHRONOS_validation"
//~"VK_LAYER_LUNARG_parameter_validation",
//~"VK_LAYER_LUNARG_core_validation",
//~"VK_LAYER_LUNARG_standard_validation"
};
- c1 * default_instance_extension_array [VK_MAX_EXTENSION_NAME_SIZE] = {
+ character * default_instance_extension_array [VK_MAX_EXTENSION_NAME_SIZE] = {
VK_KHR_SURFACE_EXTENSION_NAME,
VK_KHR_XCB_SURFACE_EXTENSION_NAME
};
for (current = 0; current < instance_layer_count; ++current) {
for (general = 0; general < default_instance_layer_count; ++general) {
- if (string_compare (instance_layer_array [current].layerName, (c1 *) default_instance_layer_array [general])) {
+ if (string_compare (instance_layer_array [current].layerName, (character *) default_instance_layer_array [general])) {
instance_layer_index [current] = true;
}
}
for (current = 0; current < instance_extension_count; ++current) {
for (general = 0; general < default_instance_extension_count; ++general) {
- if (string_compare (instance_extension_array [current].extensionName, (c1 *) default_instance_extension_array [general])) {
+ if (string_compare (instance_extension_array [current].extensionName, (character *) default_instance_extension_array [general])) {
instance_extension_index [current] = true;
}
}
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_surface (vulkan_structure * vulkan) {
+static procedure vulkan_create_surface (vulkan_structure * vulkan) {
VkXcbSurfaceCreateInfoKHR surface_information = { 0 };
vulkan->time = tick_tock ();
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_device (vulkan_structure * vulkan) {
+static procedure vulkan_create_device (vulkan_structure * vulkan) {
VkDeviceQueueCreateInfo queues = { 0 };
VkDeviceCreateInfo device_information = { 0 };
VkPhysicalDeviceMemoryProperties memory_properties = { 0 };
- u4 queue_count = 0;
- u4 physical_device_count = 0;
+ natural queue_count = 0;
+ natural physical_device_count = 0;
VkPhysicalDevice * physical_device_array = null;
VkBool32 * support = null;
- f4 queue_priorities [1] = { 1 };
+ real queue_priorities [1] = { 1 };
- u4 default_device_extension_count = 1;
+ natural default_device_extension_count = 1;
- c1 * default_device_extension_array [VK_MAX_EXTENSION_NAME_SIZE] = {
+ character * default_device_extension_array [VK_MAX_EXTENSION_NAME_SIZE] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME
};
print ("Enumerated available physical devices.\n");
- for (u4 index = 0; index < physical_device_count; ++index) {
- u4 general = 0;
- u4 current = 0;
+ for (natural index = 0; index < physical_device_count; ++index) {
+ natural general = 0;
+ natural current = 0;
- u4 device_extension_count = 0;
- u4 * device_extension_index = null;
+ natural device_extension_count = 0;
+ natural * device_extension_index = null;
VkExtensionProperties * device_extension_array = null;
VkPhysicalDeviceProperties physical_device_properties = { 0 };
for (current = 0; current < device_extension_count; ++current) {
for (general = 0; general < default_device_extension_count; ++general) {
- if (string_compare (device_extension_array [current].extensionName, (c1 *) default_device_extension_array [general])) {
+ if (string_compare (device_extension_array [current].extensionName, (character *) default_device_extension_array [general])) {
device_extension_index [current] = true;
}
}
device_information.ppEnabledExtensionNames = default_device_extension_array;
device_information.pEnabledFeatures = null;
- vulkan_result (vkCreateDevice (vulkan->physical_device, & device_information, null, & vulkan->logical_device));
+ vulkan_result (vkCreateDevice (vulkan->physical_device, & device_information, null, & vulkan->boolean_device));
- print ("/c Created Vulkan logical device.\n");
+ print ("/c Created Vulkan boolean device.\n");
- vkGetDeviceQueue (vulkan->logical_device, vulkan->queue_index, 0, & vulkan->queue);
+ vkGetDeviceQueue (vulkan->boolean_device, vulkan->queue_index, 0, & vulkan->queue);
vkGetPhysicalDeviceQueueFamilyProperties (vulkan->physical_device, & queue_count, null);
support = allocate (queue_count * sizeof (VkBool32));
- for (u4 index = 0; index < queue_count; ++index) {
+ for (natural index = 0; index < queue_count; ++index) {
vulkan_result (vkGetPhysicalDeviceSurfaceSupportKHR (vulkan->physical_device, index, vulkan->surface, & support [index]));
}
- for (u4 index = 0; (index != queue_count) && (! (vulkan->queue_index = support [index] ? (index++) : 0)); );
+ for (natural index = 0; (index != queue_count) && (! (vulkan->queue_index = support [index] ? (index++) : 0)); );
support = deallocate (support);
print ("Found /2Vulkan physical device/- memory properties.\n");
- for (u4 index = 0; index < memory_properties.memoryTypeCount; ++index) {
+ for (natural index = 0; index < memory_properties.memoryTypeCount; ++index) {
print ("> %i\n", memory_properties.memoryTypes [index].propertyFlags);
}
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_choose_extent (vulkan_structure * vulkan) {
+static procedure vulkan_choose_extent (vulkan_structure * vulkan) {
VkSurfaceCapabilitiesKHR capabilities = { 0 };
vulkan->time = tick_tock ();
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_choose_format (vulkan_structure * vulkan) {
- u4 format_count = 0;
+static procedure vulkan_choose_format (vulkan_structure * vulkan) {
+ natural format_count = 0;
VkSurfaceFormatKHR * format_array = null;
vulkan->time = tick_tock ();
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_choose_present_mode (vulkan_structure * vulkan) {
- u4 present_mode_count = 0;
+static procedure vulkan_choose_present_mode (vulkan_structure * vulkan) {
+ natural present_mode_count = 0;
VkPresentModeKHR * present_mode_array = null;
vulkan->time = tick_tock ();
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_swapchain (vulkan_structure * vulkan) {
+static procedure vulkan_create_swapchain (vulkan_structure * vulkan) {
VkSwapchainCreateInfoKHR swapchain_information = { 0 };
vulkan->time = tick_tock ();
swapchain_information.clipped = VK_TRUE;
swapchain_information.oldSwapchain = VK_NULL_HANDLE;
- vulkan_result (vkCreateSwapchainKHR (vulkan->logical_device, & swapchain_information, null, & vulkan->swapchain));
+ vulkan_result (vkCreateSwapchainKHR (vulkan->boolean_device, & swapchain_information, null, & vulkan->swapchain));
print ("/c Created /2Vulkan swapchain/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_images (vulkan_structure * vulkan) {
- u4 temporary = vulkan->image_count;
+static procedure vulkan_create_images (vulkan_structure * vulkan) {
+ natural temporary = vulkan->image_count;
vulkan->time = tick_tock ();
- vulkan_result (vkGetSwapchainImagesKHR (vulkan->logical_device, vulkan->swapchain, & temporary, null));
+ vulkan_result (vkGetSwapchainImagesKHR (vulkan->boolean_device, vulkan->swapchain, & temporary, null));
vulkan->images = allocate (vulkan->image_count * sizeof (VkImage));
- vulkan_result (vkGetSwapchainImagesKHR (vulkan->logical_device, vulkan->swapchain, & temporary, vulkan->images));
+ vulkan_result (vkGetSwapchainImagesKHR (vulkan->boolean_device, vulkan->swapchain, & temporary, vulkan->images));
print ("/c Created /2Vulkan swapchain images/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_image_views (vulkan_structure * vulkan) {
+static procedure vulkan_create_image_views (vulkan_structure * vulkan) {
VkComponentMapping component_mapping = { 0 };
VkImageSubresourceRange image_subresource_range = { 0 };
VkImageViewCreateInfo image_view_information = { 0 };
image_view_information.components = component_mapping;
image_view_information.subresourceRange = image_subresource_range;
- for (u4 index = 0; index < vulkan->image_count; ++index) {
+ for (natural index = 0; index < vulkan->image_count; ++index) {
image_view_information.image = vulkan->images [index];
- vulkan_result (vkCreateImageView (vulkan->logical_device, & image_view_information, null, & vulkan->image_views [index]));
+ vulkan_result (vkCreateImageView (vulkan->boolean_device, & image_view_information, null, & vulkan->image_views [index]));
}
print ("/c Created /2Vulkan swapchain image views/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_semaphores (vulkan_structure * vulkan) {
+static procedure vulkan_create_semaphores (vulkan_structure * vulkan) {
VkSemaphoreCreateInfo semaphore_information = { 0 };
vulkan->time = tick_tock ();
semaphore_information.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
- for (u4 index = 0; index < vulkan->image_count; ++index) {
- vulkan_result (vkCreateSemaphore (vulkan->logical_device, & semaphore_information, null, & vulkan->semaphore_set_1 [index]));
- vulkan_result (vkCreateSemaphore (vulkan->logical_device, & semaphore_information, null, & vulkan->semaphore_set_2 [index]));
+ for (natural index = 0; index < vulkan->image_count; ++index) {
+ vulkan_result (vkCreateSemaphore (vulkan->boolean_device, & semaphore_information, null, & vulkan->semaphore_set_1 [index]));
+ vulkan_result (vkCreateSemaphore (vulkan->boolean_device, & semaphore_information, null, & vulkan->semaphore_set_2 [index]));
}
print ("/c Created /2Vulkan synchronization semaphores/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_fences (vulkan_structure * vulkan) {
- u4 index = 0;
+static procedure vulkan_create_fences (vulkan_structure * vulkan) {
+ natural index = 0;
VkFenceCreateInfo fence_information = { 0 };
fence_information.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for (index = 0; index < vulkan->image_count; ++index) {
- vulkan_result (vkCreateFence (vulkan->logical_device, & fence_information, null, & vulkan->fence_set_1 [index]));
+ vulkan_result (vkCreateFence (vulkan->boolean_device, & fence_information, null, & vulkan->fence_set_1 [index]));
}
print ("/c Created /2Vulkan synchronization fences/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_render_pass (vulkan_structure * vulkan) {
+static procedure vulkan_create_render_pass (vulkan_structure * vulkan) {
VkAttachmentDescription attachment_description = { 0 };
VkAttachmentReference attachment_reference = { 0 };
VkSubpassDescription subpass_description = { 0 };
attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
subpass_description.flags = 0;
- subpass_description.pipelineBindPos4 = VK_PIPELINE_BIND_POINT_GRAPHICS;
+ subpass_description.pipelineBindPointeger = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass_description.inputAttachmentCount = 0;
subpass_description.pInputAttachments = null;
subpass_description.colorAttachmentCount = 1;
render_pass_information.dependencyCount = 2;
render_pass_information.pDependencies = subpass_dependencies;
- vulkan_result (vkCreateRenderPass (vulkan->logical_device, & render_pass_information, null, & vulkan->render_pass));
+ vulkan_result (vkCreateRenderPass (vulkan->boolean_device, & render_pass_information, null, & vulkan->render_pass));
print ("/c Created /2Vulkan render pass/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_descriptor_set_layout (vulkan_structure * vulkan) {
+static procedure vulkan_create_descriptor_set_layout (vulkan_structure * vulkan) {
VkDescriptorSetLayoutBinding descriptor_set_layout_bindings [2] = { { 0 } };
VkDescriptorSetLayoutCreateInfo descriptor_set_layout_information = { 0 };
descriptor_set_layout_information.bindingCount = 2;
descriptor_set_layout_information.pBindings = descriptor_set_layout_bindings;
- vulkan_result (vkCreateDescriptorSetLayout (vulkan->logical_device, & descriptor_set_layout_information, null,
+ vulkan_result (vkCreateDescriptorSetLayout (vulkan->boolean_device, & descriptor_set_layout_information, null,
& vulkan->descriptor_set_layout));
print ("/c Created /2 Vulkan descriptor layout/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_vertex_shader (vulkan_structure * vulkan) {
- u4 vertex_shader_code [] = {
+static procedure vulkan_create_vertex_shader (vulkan_structure * vulkan) {
+ natural vertex_shader_code [] = {
0x07230203, 0x00010000, 0x000d000b, 0x00000028, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
0x000b000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000d, 0x00000012, 0x00000021,
vertex_shader_information.codeSize = sizeof (vertex_shader_code);
vertex_shader_information.pCode = vertex_shader_code;
- vulkan_result (vkCreateShaderModule (vulkan->logical_device, & vertex_shader_information, null, & vulkan->vertex_shader));
+ vulkan_result (vkCreateShaderModule (vulkan->boolean_device, & vertex_shader_information, null, & vulkan->vertex_shader));
print ("/c Created /2Vulkan vertex shader module/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_fragment_shader (vulkan_structure * vulkan) {
- u4 fragment_shader_code [] = {
+static procedure vulkan_create_fragment_shader (vulkan_structure * vulkan) {
+ natural fragment_shader_code [] = {
0x07230203, 0x00010000, 0x000d000b, 0x00000018, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
0x0008000f, 0x00000004, 0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x00000011, 0x00000015,
fragment_shader_information.codeSize = sizeof (fragment_shader_code);
fragment_shader_information.pCode = fragment_shader_code;
- vulkan_result (vkCreateShaderModule (vulkan->logical_device, & fragment_shader_information, null, & vulkan->fragment_shader));
+ vulkan_result (vkCreateShaderModule (vulkan->boolean_device, & fragment_shader_information, null, & vulkan->fragment_shader));
print ("/c Created /2Vulkan fragment shader module/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_pipeline_layout (vulkan_structure * vulkan) {
+static procedure vulkan_create_pipeline_layout (vulkan_structure * vulkan) {
VkPipelineLayoutCreateInfo pipeline_layout_information = { 0 };
vulkan->time = tick_tock ();
pipeline_layout_information.setLayoutCount = 1;
pipeline_layout_information.pSetLayouts = & vulkan->descriptor_set_layout;
- vulkan_result (vkCreatePipelineLayout (vulkan->logical_device, & pipeline_layout_information, VK_NULL_HANDLE, & vulkan->pipeline_layout));
+ vulkan_result (vkCreatePipelineLayout (vulkan->boolean_device, & pipeline_layout_information, VK_NULL_HANDLE, & vulkan->pipeline_layout));
print ("/c Created /2Vulkan graphics pipeline layout/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_pipeline (vulkan_structure * vulkan) {
+static procedure vulkan_create_pipeline (vulkan_structure * vulkan) {
VkPipelineShaderStageCreateInfo pipeline_shader_stage_information [2] = { { 0 } };
VkPipelineInputAssemblyStateCreateInfo pipeline_input_assembly_state_information = { 0 };
VkVertexInputBindingDescription vertex_input_binding_description [1] = { { 0 } };
pipeline_information.basePipelineHandle = VK_NULL_HANDLE;
pipeline_information.basePipelineIndex = -1;
- vulkan_result (vkCreateGraphicsPipelines (vulkan->logical_device, VK_NULL_HANDLE, 1, & pipeline_information, null, & vulkan->pipeline));
+ vulkan_result (vkCreateGraphicsPipelines (vulkan->boolean_device, VK_NULL_HANDLE, 1, & pipeline_information, null, & vulkan->pipeline));
print ("/c Created /2Vulkan graphics pipeline/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_framebuffers (vulkan_structure * vulkan) {
+static procedure vulkan_create_framebuffers (vulkan_structure * vulkan) {
VkFramebufferCreateInfo framebuffer_information = { 0 };
vulkan->time = tick_tock ();
framebuffer_information.height = vulkan->extent.height;
framebuffer_information.layers = 1;
- for (u4 index = 0; index < vulkan->image_count; ++index) {
+ for (natural index = 0; index < vulkan->image_count; ++index) {
framebuffer_information.pAttachments = & vulkan->image_views [index];
- vulkan_result (vkCreateFramebuffer (vulkan->logical_device, & framebuffer_information, null, & vulkan->framebuffers [index]));
+ vulkan_result (vkCreateFramebuffer (vulkan->boolean_device, & framebuffer_information, null, & vulkan->framebuffers [index]));
}
print ("/c Created /2Vulkan framebuffers/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_command_pool (vulkan_structure * vulkan) {
+static procedure vulkan_create_command_pool (vulkan_structure * vulkan) {
VkCommandPoolCreateInfo command_pool_information = { 0 };
vulkan->time = tick_tock ();
command_pool_information.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
command_pool_information.queueFamilyIndex = vulkan->queue_index;
- vulkan_result (vkCreateCommandPool (vulkan->logical_device, & command_pool_information, null, & vulkan->command_pool));
+ vulkan_result (vkCreateCommandPool (vulkan->boolean_device, & command_pool_information, null, & vulkan->command_pool));
print ("/c Created /2Vulkan command pool/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_command_buffers (vulkan_structure * vulkan) {
+static procedure vulkan_create_command_buffers (vulkan_structure * vulkan) {
VkCommandBufferAllocateInfo command_buffer_information = { 0 };
vulkan->time = tick_tock ();
command_buffer_information.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
command_buffer_information.commandBufferCount = vulkan->image_count;
- vulkan_result (vkAllocateCommandBuffers (vulkan->logical_device, & command_buffer_information, vulkan->command_buffers));
+ vulkan_result (vkAllocateCommandBuffers (vulkan->boolean_device, & command_buffer_information, vulkan->command_buffers));
print ("/c Allocated /2Vulkan command buffers/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_vertex_buffer (vulkan_structure * vulkan) {
+static procedure vulkan_create_vertex_buffer (vulkan_structure * vulkan) {
VkBuffer transfer_buffer = VK_NULL_HANDLE;
VkDeviceMemory transfer_memory = VK_NULL_HANDLE;
- v0 * transfer_v0 = null;
+ procedure * transfer_procedure = null;
VkBufferCopy copy_information = { 0 };
/*
vulkan_create_buffer (vulkan, & transfer_buffer, & transfer_memory, vulkan->vertex_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
- vulkan_result (vkMapMemory (vulkan->logical_device, transfer_memory, 0, vulkan->vertex_size, 0, & transfer_v0));
+ vulkan_result (vkMapMemory (vulkan->boolean_device, transfer_memory, 0, vulkan->vertex_size, 0, & transfer_v0));
memory_copy (transfer_v0, vulkan->vertex_data, vulkan->vertex_size);
vulkan_end_command_buffer (vulkan);
- vkDestroyBuffer (vulkan->logical_device, transfer_buffer, null);
- vkFreeMemory (vulkan->logical_device, transfer_memory, null);
+ vkDestroyBuffer (vulkan->boolean_device, transfer_buffer, null);
+ vkFreeMemory (vulkan->boolean_device, transfer_memory, null);
/*print ("/c Created /2Vulkan vertex buffer/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);*/
}
-static v0 vulkan_create_index_buffer (vulkan_structure * vulkan) {
+static procedure vulkan_create_index_buffer (vulkan_structure * vulkan) {
VkBuffer transfer_buffer = VK_NULL_HANDLE;
VkDeviceMemory transfer_memory = VK_NULL_HANDLE;
- v0 * transfer_v0 = null;
+ procedure * transfer_procedure = null;
VkBufferCopy copy_information = { 0 };
/*
vulkan_create_buffer (vulkan, & transfer_buffer, & transfer_memory, vulkan->index_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
- vulkan_result (vkMapMemory (vulkan->logical_device, transfer_memory, 0, vulkan->index_size, 0, & transfer_v0));
+ vulkan_result (vkMapMemory (vulkan->boolean_device, transfer_memory, 0, vulkan->index_size, 0, & transfer_v0));
memory_copy (transfer_v0, vulkan->index_data, vulkan->index_size);
vulkan_end_command_buffer (vulkan);
- vkDestroyBuffer (vulkan->logical_device, transfer_buffer, null);
- vkFreeMemory (vulkan->logical_device, transfer_memory, null);
+ vkDestroyBuffer (vulkan->boolean_device, transfer_buffer, null);
+ vkFreeMemory (vulkan->boolean_device, transfer_memory, null);
/*
print ("/c Created /2Vulkan index buffer/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);*/
}
-static v0 vulkan_create_image_buffer (vulkan_structure * vulkan) {
+static procedure vulkan_create_image_buffer (vulkan_structure * vulkan) {
VkBuffer transfer_buffer = VK_NULL_HANDLE;
VkDeviceMemory transfer_memory = VK_NULL_HANDLE;
- v0 * transfer_v0 = null;
+ procedure * transfer_procedure = null;
VkExtent3D image_extent = { 0 };
VkImageCreateInfo image_information = { 0 };
vulkan_create_buffer (vulkan, & transfer_buffer, & transfer_memory, vulkan->layout_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
- vulkan_result (vkMapMemory (vulkan->logical_device, transfer_memory, 0, vulkan->layout_size, 0, & transfer_v0));
+ vulkan_result (vkMapMemory (vulkan->boolean_device, transfer_memory, 0, vulkan->layout_size, 0, & transfer_v0));
memory_copy (transfer_v0, vulkan->layout_data, vulkan->layout_size);
image_subresource_range.baseArrayLayer = 0;
image_subresource_range.layerCount = 1;
- vulkan_result (vkCreateImage (vulkan->logical_device, & image_information, null, & vulkan->layout_image));
+ vulkan_result (vkCreateImage (vulkan->boolean_device, & image_information, null, & vulkan->layout_image));
- vkGetImageMemoryRequirements (vulkan->logical_device, vulkan->layout_image, & memory_requirements);
+ vkGetImageMemoryRequirements (vulkan->boolean_device, vulkan->layout_image, & memory_requirements);
memory_allocation_information.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
memory_allocation_information.allocationSize = memory_requirements.size;
memory_allocation_information.memoryTypeIndex = vulkan_choose_memory_property (vulkan, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
- vulkan_result (vkAllocateMemory (vulkan->logical_device, & memory_allocation_information, null, & vulkan->layout_memory));
+ vulkan_result (vkAllocateMemory (vulkan->boolean_device, & memory_allocation_information, null, & vulkan->layout_memory));
- vulkan_result (vkBindImageMemory (vulkan->logical_device, vulkan->layout_image, vulkan->layout_memory, 0));
+ vulkan_result (vkBindImageMemory (vulkan->boolean_device, vulkan->layout_image, vulkan->layout_memory, 0));
vulkan_begin_command_buffer (vulkan);
image_view_information.subresourceRange = image_subresource_range;
image_view_information.image = vulkan->layout_image;
- vulkan_result (vkCreateImageView (vulkan->logical_device, & image_view_information, null, & vulkan->layout_image_view));
+ vulkan_result (vkCreateImageView (vulkan->boolean_device, & image_view_information, null, & vulkan->layout_image_view));
- vkDestroyBuffer (vulkan->logical_device, transfer_buffer, null);
- vkFreeMemory (vulkan->logical_device, transfer_memory, null);
+ vkDestroyBuffer (vulkan->boolean_device, transfer_buffer, null);
+ vkFreeMemory (vulkan->boolean_device, transfer_memory, null);
print ("/c Created /2Vulkan image layout buffer/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_sampler (vulkan_structure * vulkan) {
+static procedure vulkan_create_sampler (vulkan_structure * vulkan) {
VkSamplerCreateInfo sampler_information = { 0 };
vulkan->time = tick_tock ();
sampler_information.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
sampler_information.unnormalizedCoordinates = VK_FALSE;
- vulkan_result (vkCreateSampler (vulkan->logical_device, & sampler_information, null, & vulkan->sampler));
+ vulkan_result (vkCreateSampler (vulkan->boolean_device, & sampler_information, null, & vulkan->sampler));
print ("/c Created /2Vulkan sampler/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_descriptor_pool (vulkan_structure * vulkan) {
+static procedure vulkan_create_descriptor_pool (vulkan_structure * vulkan) {
VkDescriptorPoolSize descriptor_pool_sizes [2] = { { 0 } };
VkDescriptorPoolCreateInfo descriptor_pool_information = { 0 };
descriptor_pool_information.poolSizeCount = 2;
descriptor_pool_information.pPoolSizes = descriptor_pool_sizes;
- vulkan_result (vkCreateDescriptorPool (vulkan->logical_device, & descriptor_pool_information, null, & vulkan->descriptor_pool));
+ vulkan_result (vkCreateDescriptorPool (vulkan->boolean_device, & descriptor_pool_information, null, & vulkan->descriptor_pool));
print ("/c Created /2Vulkan descriptor pool/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_create_descriptor_sets (vulkan_structure * vulkan) {
+static procedure vulkan_create_descriptor_sets (vulkan_structure * vulkan) {
VkDescriptorSetAllocateInfo descriptor_set_allocation_information = { 0 };
vulkan->time = tick_tock ();
vulkan->descriptor_set_layouts = allocate (vulkan->image_count * sizeof (VkDescriptorSetLayout));
- for (u4 index = 0; index < vulkan->image_count; ++index) {
+ for (natural index = 0; index < vulkan->image_count; ++index) {
vulkan->descriptor_set_layouts [index] = vulkan->descriptor_set_layout;
}
vulkan->descriptor_sets = allocate (vulkan->image_count * sizeof (VkDescriptorSet));
- vulkan_result (vkAllocateDescriptorSets (vulkan->logical_device, & descriptor_set_allocation_information, vulkan->descriptor_sets));
+ vulkan_result (vkAllocateDescriptorSets (vulkan->boolean_device, & descriptor_set_allocation_information, vulkan->descriptor_sets));
print ("/c Allocated /2Vulkan descriptor sets/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_record_descriptor_sets (vulkan_structure * vulkan) {
+static procedure vulkan_record_descriptor_sets (vulkan_structure * vulkan) {
VkDescriptorBufferInfo descriptor_buffer_information = { 0 };
VkDescriptorImageInfo descriptor_image_information = { 0 };
VkWriteDescriptorSet write_descriptor_set = { 0 };
write_descriptor_set.pImageInfo = & descriptor_image_information;
write_descriptor_set.pBufferInfo = null;
- for (u4 index = 0; index < vulkan->image_count; ++index) {
+ for (natural index = 0; index < vulkan->image_count; ++index) {
write_descriptor_set.dstSet = vulkan->descriptor_sets [index];
- vkUpdateDescriptorSets (vulkan->logical_device, 1, & write_descriptor_set, 0, null);
+ vkUpdateDescriptorSets (vulkan->boolean_device, 1, & write_descriptor_set, 0, null);
}
print ("/c Recorded /2Vulkan descriptor sets/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);
}
-static v0 vulkan_record_command_buffers (vulkan_structure * vulkan, s4 clear_colour, s4 frame) {
- u4 index = 0;
+static procedure vulkan_record_command_buffers (vulkan_structure * vulkan, integer clear_colour, integer frame) {
+ natural index = 0;
VkCommandBufferBeginInfo command_buffer_begin_information = { 0 };
//~VkImageSubresourceRange image_subresource_range = { 0 };
VkDeviceSize vertex_offset = 0;
VkClearColorValue clear_colour_value = { {
- (float) ((clear_colour & 0xff000000) >> 24) / 255,
- (float) ((clear_colour & 0x00ff0000) >> 16) / 255,
- (float) ((clear_colour & 0x0000ff00) >> 8) / 255,
- (float) ((clear_colour & 0x000000ff) >> 0) / 255
+ (real) ((clear_colour & 0xff000000) >> 24) / 255,
+ (real) ((clear_colour & 0x00ff0000) >> 16) / 255,
+ (real) ((clear_colour & 0x0000ff00) >> 8) / 255,
+ (real) ((clear_colour & 0x000000ff) >> 0) / 255
} };
- (v0) frame;
+ (none) frame;
/*
vulkan->time = tick_tock ();
*/
vulkan_result (vkEndCommandBuffer (vulkan_command_buffers [frame]));
*/
vulkan_result (vkQueueWaitIdle (vulkan->queue));
- vulkan_result (vkDeviceWaitIdle (vulkan->logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan->boolean_device));
/*print ("/c Recorded /2Vulkan command buffers/-.\n");
print ("/c Time approximation: /6%i/-\n", tick_tock () - vulkan->time);*/
}
-static u4 vulkan_import_sprite (vulkan_structure * vulkan, u4 * data, u4 width, u4 height) {
+static natural vulkan_import_sprite (vulkan_structure * vulkan, natural * data, natural width, natural height) {
fatal_failure (vulkan->active == true, "vulkan_import_sprite: Failed to import sprite, engine was already configured.");
fatal_failure (data == null, "vulkan_import_sprite: Failed to import sprite, data is null pointer.");
fatal_failure (width <= 0, "vulkan_import_sprite: Failed to import sprite, width is equal or below zero.");
return (vulkan->sprite_count - 1);
}
-static u4 vulkan_import_font (vulkan_structure * vulkan, u4 * data, u4 image_width, u4 image_height, c1 begin, c1 end, u4 empty) {
- u4 pointer = 0;
- c1 index = 0;
- u4 width = 0;
- u4 height = 0;
- u4 x = 0;
- u4 y = 0;
+static natural vulkan_import_font (vulkan_structure * vulkan, natural * data, natural image_width, natural image_height, character begin, character end, natural empty) {
+ natural pointer = 0;
+ character index = 0;
+ natural width = 0;
+ natural height = 0;
+ natural x = 0;
+ natural y = 0;
- u4 * buffer = null;
+ natural * buffer = null;
++vulkan->font_count;
return (vulkan->font_count - 1);
}
-static v0 vulkan_bundle_layout (vulkan_structure * vulkan) {
- u4 * order = null;
+static procedure vulkan_bundle_layout (vulkan_structure * vulkan) {
+ natural * order = null;
- vulkan->layout_size = vulkan->layout_width * vulkan->layout_height * (u4) sizeof (* vulkan->layout_data);
+ vulkan->layout_size = vulkan->layout_width * vulkan->layout_height * (natural) sizeof (* vulkan->layout_data);
vulkan->layout_data = allocate (vulkan->layout_size);
order = allocate (vulkan->sprite_count * sizeof (* order));
- for (u4 index = 0; index < vulkan->sprite_count; ++index) {
+ for (natural index = 0; index < vulkan->sprite_count; ++index) {
order [index] = index;
}
- for (u4 index = 0; index < vulkan->sprite_count; ++index) {
- for (u4 subindex = 0; subindex < vulkan->sprite_count; ++subindex) {
+ for (natural index = 0; index < vulkan->sprite_count; ++index) {
+ for (natural subindex = 0; subindex < vulkan->sprite_count; ++subindex) {
if (vulkan->sprite_height [order [index]] < vulkan->sprite_height [order [subindex]]) {
- s4 temporary = order [index];
+ integer temporary = order [index];
order [index] = order [subindex];
order [subindex] = temporary;
}
}
- for (u4 index = 0; index < vulkan->sprite_count; ++index) {
- u4 x = 0;
- u4 y = 0;
- u4 u = 0;
- u4 v = 0;
+ for (natural index = 0; index < vulkan->sprite_count; ++index) {
+ natural x = 0;
+ natural y = 0;
+ natural u = 0;
+ natural v = 0;
if (u + vulkan->sprite_width [order [index]] >= vulkan->layout_width) {
v += vulkan->sprite_height [order [index]];
}
- vulkan->sprite_u [order [index]] = (float) u / (float) vulkan->layout_width;
- vulkan->sprite_v [order [index]] = (float) v / (float) vulkan->layout_height;
+ vulkan->sprite_u [order [index]] = (real) u / (real) vulkan->layout_width;
+ vulkan->sprite_v [order [index]] = (real) v / (real) vulkan->layout_height;
- for (u4 y = 0; y < vulkan->sprite_height [order [index]]; ++y) {
- for (u4 x = 0; x < vulkan->sprite_width [order [index]]; ++x) {
- u4 destination = (v + y) * vulkan->layout_width + (u + x);
- u4 source = y * vulkan->sprite_width [order [index]] + x;
+ for (natural y = 0; y < vulkan->sprite_height [order [index]]; ++y) {
+ for (natural x = 0; x < vulkan->sprite_width [order [index]]; ++x) {
+ natural destination = (v + y) * vulkan->layout_width + (u + x);
+ natural source = y * vulkan->sprite_width [order [index]] + x;
vulkan->layout_data [destination] = vulkan->sprite_data [order [index]] [source];
}
order = deallocate (order);
}
-static v0 vulkan_configure (vulkan_structure * vulkan, s4 width, s4 height, c1 * application) {
- s4 index = 0;
+static procedure vulkan_configure (vulkan_structure * vulkan, integer width, integer height, character * application) {
+ integer index = 0;
- u4 * dumb_buffer = null;
+ natural * dumb_buffer = null;
if (vulkan->active == true) {
return;
vulkan->width = width;
vulkan->height = height;
- vulkan->pixel_width = (float) 2 / (float) width;
- vulkan->pixel_height = (float) 2 / (float) height;
+ vulkan->pixel_width = (real) 2 / (real) width;
+ vulkan->pixel_height = (real) 2 / (real) height;
dumb_buffer = allocate (256 * sizeof (* dumb_buffer));
vulkan->active = true;
}
/*
-static v0 vulkan_reconfigure (v0) {
- s4 index;
+static procedure vulkan_reconfigure (none) {
+ integer index;
vulkan_result (vkQueueWaitIdle (vulkan_queue));
- vulkan_result (vkDeviceWaitIdle (vulkan_logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan_boolean_device));
for (index = 0; index < vulkan_image_count; ++index) {
- vkDestroyFramebuffer (vulkan_logical_device, vulkan_framebuffers [index], null);
+ vkDestroyFramebuffer (vulkan_boolean_device, vulkan_framebuffers [index], null);
}
vulkan_framebuffers = deallocate (vulkan_framebuffers);
for (index = 0; index < vulkan_image_count; ++index) {
- vkDestroyImageView (vulkan_logical_device, vulkan_image_views [index], null);
+ vkDestroyImageView (vulkan_boolean_device, vulkan_image_views [index], null);
}
vulkan_image_views = deallocate (vulkan_image_views);
- vkDestroySwapchainKHR (vulkan_logical_device, vulkan_swapchain, null);
+ vkDestroySwapchainKHR (vulkan_boolean_device, vulkan_swapchain, null);
vulkan_images = deallocate (vulkan_images);
vulkan_create_framebuffers ();
vulkan_result (vkQueueWaitIdle (vulkan_queue));
- vulkan_result (vkDeviceWaitIdle (vulkan_logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan_boolean_device));
vulkan_reconfigure_active = false;
}
*/
-static v0 vulkan_render_core (vulkan_structure * vulkan, s4 sprite, s4 x, s4 y, s4 u, s4 v, s4 width, s4 height,
- f4 scale_x, f4 scale_y, s4 flip_x, s4 flip_y,
- s4 colour_0, u4 colour_1, u4 colour_2, u4 colour_3) {
- f4 screen_x = x * vulkan->pixel_width;
- f4 screen_y = y * vulkan->pixel_height;
+static procedure vulkan_render_core (vulkan_structure * vulkan, integer sprite, integer x, integer y, integer u, integer v, integer width, integer height,
+ real scale_x, real scale_y, integer flip_x, integer flip_y,
+ integer colour_0, natural colour_1, natural colour_2, natural colour_3) {
+ real screen_x = x * vulkan->pixel_width;
+ real screen_y = y * vulkan->pixel_height;
- f4 unwrap_x = vulkan->sprite_u [sprite] + (float) u / vulkan->layout_width;
- f4 unwrap_y = vulkan->sprite_v [sprite] + (float) v / vulkan->layout_height;
+ real unwrap_x = vulkan->sprite_u [sprite] + (real) u / vulkan->layout_width;
+ real unwrap_y = vulkan->sprite_v [sprite] + (real) v / vulkan->layout_height;
- f4 screen_width = (float) width * vulkan->pixel_width * scale_x;
- f4 screen_height = (float) height * vulkan->pixel_height * scale_y;
+ real screen_width = (real) width * vulkan->pixel_width * scale_x;
+ real screen_height = (real) height * vulkan->pixel_height * scale_y;
- f4 unwrap_width = (float) width / vulkan->layout_width;
- f4 unwrap_height = (float) height / vulkan->layout_height;
+ real unwrap_width = (real) width / vulkan->layout_width;
+ real unwrap_height = (real) height / vulkan->layout_height;
fatal_failure (vulkan->vertex_count + 32 >= vulkan->vertex_limit, "Reached vertex limit.");
fatal_failure (vulkan->index_count + 6 >= vulkan->index_limit, "Reached index limit.");
vulkan->vertex_data [vulkan->vertex_count + 1] = screen_y;
vulkan->vertex_data [vulkan->vertex_count + 2] = unwrap_x + unwrap_width * (flip_y != 0);
vulkan->vertex_data [vulkan->vertex_count + 3] = unwrap_y + unwrap_height * (flip_x != 0);
- vulkan->vertex_data [vulkan->vertex_count + 4] = (float) ((colour_0 >> 24) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 5] = (float) ((colour_0 >> 16) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 6] = (float) ((colour_0 >> 8) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 7] = (float) ((colour_0 >> 0) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 4] = (real) ((colour_0 >> 24) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 5] = (real) ((colour_0 >> 16) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 6] = (real) ((colour_0 >> 8) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 7] = (real) ((colour_0 >> 0) & 0xff) / 255;
vulkan->vertex_data [vulkan->vertex_count + 8] = screen_x + screen_width;
vulkan->vertex_data [vulkan->vertex_count + 9] = screen_y;
vulkan->vertex_data [vulkan->vertex_count + 10] = unwrap_x + unwrap_width * (flip_y == 0);
vulkan->vertex_data [vulkan->vertex_count + 11] = unwrap_y + unwrap_height * (flip_x != 0);
- vulkan->vertex_data [vulkan->vertex_count + 12] = (float) ((colour_1 >> 24) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 13] = (float) ((colour_1 >> 16) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 14] = (float) ((colour_1 >> 8) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 15] = (float) ((colour_1 >> 0) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 12] = (real) ((colour_1 >> 24) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 13] = (real) ((colour_1 >> 16) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 14] = (real) ((colour_1 >> 8) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 15] = (real) ((colour_1 >> 0) & 0xff) / 255;
vulkan->vertex_data [vulkan->vertex_count + 16] = screen_x;
vulkan->vertex_data [vulkan->vertex_count + 17] = screen_y + screen_height;
vulkan->vertex_data [vulkan->vertex_count + 18] = unwrap_x + unwrap_width * (flip_y != 0);
vulkan->vertex_data [vulkan->vertex_count + 19] = unwrap_y + unwrap_height * (flip_x == 0);
- vulkan->vertex_data [vulkan->vertex_count + 20] = (float) ((colour_2 >> 24) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 21] = (float) ((colour_2 >> 16) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 22] = (float) ((colour_2 >> 8) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 23] = (float) ((colour_2 >> 0) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 20] = (real) ((colour_2 >> 24) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 21] = (real) ((colour_2 >> 16) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 22] = (real) ((colour_2 >> 8) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 23] = (real) ((colour_2 >> 0) & 0xff) / 255;
vulkan->vertex_data [vulkan->vertex_count + 24] = screen_x + screen_width;
vulkan->vertex_data [vulkan->vertex_count + 25] = screen_y + screen_height;
vulkan->vertex_data [vulkan->vertex_count + 26] = unwrap_x + unwrap_width * (flip_y == 0);
vulkan->vertex_data [vulkan->vertex_count + 27] = unwrap_y + unwrap_height * (flip_x == 0);
- vulkan->vertex_data [vulkan->vertex_count + 28] = (float) ((colour_3 >> 24) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 29] = (float) ((colour_3 >> 16) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 30] = (float) ((colour_3 >> 8) & 0xff) / 255;
- vulkan->vertex_data [vulkan->vertex_count + 31] = (float) ((colour_3 >> 0) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 28] = (real) ((colour_3 >> 24) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 29] = (real) ((colour_3 >> 16) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 30] = (real) ((colour_3 >> 8) & 0xff) / 255;
+ vulkan->vertex_data [vulkan->vertex_count + 31] = (real) ((colour_3 >> 0) & 0xff) / 255;
vulkan->index_data [vulkan->index_count + 0] = (vulkan->vertex_count >> 3) + 0;
vulkan->index_data [vulkan->index_count + 1] = (vulkan->vertex_count >> 3) + 1;
vulkan->index_count += 6;
}
-static v0 vulkan_render_sprite (vulkan_structure * vulkan, s4 sprite, s4 x, s4 y, u4 colour) {
+static procedure vulkan_render_sprite (vulkan_structure * vulkan, integer sprite, integer x, integer y, natural colour) {
vulkan_render_core (vulkan, sprite, x, y, 0, 0, vulkan->sprite_width [sprite], vulkan->sprite_height [sprite], 1.0, 1.0, 0, 0, colour, colour, colour,colour);
}
-static v0 vulkan_render_sprite_scale (vulkan_structure * vulkan, s4 sprite, s4 x, s4 y, f4 scale, u4 colour) {
+static procedure vulkan_render_sprite_scale (vulkan_structure * vulkan, integer sprite, integer x, integer y, real scale, natural colour) {
vulkan_render_core (vulkan, sprite, x, y, 0, 0, vulkan->sprite_width [sprite], vulkan->sprite_height [sprite], scale, scale, 0, 0, colour, colour, colour,colour);
}
-static v0 vulkan_render_sprite_crop (vulkan_structure * vulkan, s4 sprite, s4 x, s4 y, s4 u, s4 v, s4 width, s4 height, u4 colour) {
+static procedure vulkan_render_sprite_crop (vulkan_structure * vulkan, integer sprite, integer x, integer y, integer u, integer v, integer width, integer height, natural colour) {
vulkan_render_core (vulkan, sprite, x, y, u, v, width, height, 1.0, 1.0, 0, 0, colour, colour, colour, colour);
}
-static v0 vulkan_render_rectangle (vulkan_structure * vulkan, s4 x, s4 y, s4 width, s4 height, u4 colour) {
- vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour, colour, colour, colour);
+static procedure vulkan_render_rectangle (vulkan_structure * vulkan, integer x, integer y, integer width, integer height, natural colour) {
+ vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour, colour, colour, colour);
}
-static v0 vulkan_render_rectangle_gradient_v (vulkan_structure * vulkan, s4 x, s4 y, s4 width, s4 height, u4 colour_up, u4 colour_down) {
- vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour_up, colour_up, colour_down, colour_down);
+static procedure vulkan_render_rectangle_gradient_v (vulkan_structure * vulkan, integer x, integer y, integer width, integer height, natural colour_up, natural colour_down) {
+ vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour_up, colour_up, colour_down, colour_down);
}
-static v0 vulkan_render_rectangle_gradient_h (vulkan_structure * vulkan, s4 x, s4 y, s4 width, s4 height, u4 colour_left, u4 colour_right) {
- vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (float) width / 16, (float) height / 16, 0, 0, colour_left, colour_right, colour_left, colour_right);
+static procedure vulkan_render_rectangle_gradient_h (vulkan_structure * vulkan, integer x, integer y, integer width, integer height, natural colour_left, natural colour_right) {
+ vulkan_render_core (vulkan, vulkan->sprite_count - 1, x, y, 0, 0, 16, 16, (real) width / 16, (real) height / 16, 0, 0, colour_left, colour_right, colour_left, colour_right);
}
-static s4 vulkan_string_width (vulkan_structure * vulkan, c1 * string, s4 font, f4 scale) {
- s4 length = 0;
+static integer vulkan_string_width (vulkan_structure * vulkan, character * string, integer font, real scale) {
+ integer length = 0;
- for (u4 index = 0; string [index] != '\0'; ++index) {
- s4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ integer character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
/*
if (string [index] == '\t') {
length += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]];
return (length);
}
-static v0 vulkan_render_string (vulkan_structure * vulkan, c1 * string, s4 font, s4 x, s4 y, u4 colour) {
- s4 offset = x;
+static procedure vulkan_render_string (vulkan_structure * vulkan, character * string, integer font, integer x, integer y, natural colour) {
+ integer offset = x;
- for (u4 index = 0; string [index] != '\0'; ++index) {
- s4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ integer character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
if (string [index] == '\t') {
x += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]];
}
}
-static v0 vulkan_render_string_scale (vulkan_structure * vulkan, c1 * string, s4 font, s4 x, s4 y, f4 scale, u4 colour) {
- s4 offset = x;
+static procedure vulkan_render_string_scale (vulkan_structure * vulkan, character * string, integer font, integer x, integer y, real scale, natural colour) {
+ integer offset = x;
- for (u4 index = 0; string [index] != '\0'; ++index) {
- s4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ integer character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
if (string [index] == '\t') {
x += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]];
}
}
-static v0 vulkan_render_string_offset (vulkan_structure * vulkan, c1 * string, u4 length, u4 font, u4 offset, s4 * x, s4 * y, u4 colour) {
- for (u4 index = 0; (string [index] != '\0') && (index < length); ++index) {
- u4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+static procedure vulkan_render_string_offset (vulkan_structure * vulkan, character * string, natural length, natural font, natural offset, integer * x, integer * y, natural colour) {
+ for (natural index = 0; (string [index] != '\0') && (index < length); ++index) {
+ natural character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
if (string [index] == '\t') {
* x += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]];
}
}
-static v0 vulkan_render_string_gradient_v (vulkan_structure * vulkan, c1 * string, s4 font, s4 x, s4 y, f4 scale, u4 colour_up, u4 colour_down) {
- s4 offset = x;
+static procedure vulkan_render_string_gradient_v (vulkan_structure * vulkan, character * string, integer font, integer x, integer y, real scale, natural colour_up, natural colour_down) {
+ integer offset = x;
- for (u4 index = 0; string [index] != '\0'; ++index) {
- u4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ natural character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
if (string [index] == '\t') {
x += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]] * scale;
}
}
-static v0 vulkan_render_string_gradient_h (vulkan_structure * vulkan, c1 * string, s4 font, s4 x, s4 y, f4 scale, u4 colour_left, u4 colour_right) {
- s4 offset = x;
+static procedure vulkan_render_string_gradient_h (vulkan_structure * vulkan, character * string, integer font, integer x, integer y, real scale, natural colour_left, natural colour_right) {
+ integer offset = x;
- for (u4 index = 0; string [index] != '\0'; ++index) {
- u4 character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
+ for (natural index = 0; string [index] != '\0'; ++index) {
+ natural character = vulkan->font_index [font] [string [index] - vulkan->font_begin [font]];
if (string [index] == '\t') {
x += 8 * vulkan->sprite_width [vulkan->font_index [font] [' ' - vulkan->font_begin [font]]] * scale;
}
}
-static v0 vulkan_handle_events (vulkan_structure * vulkan) {
- static s4 signal_code [signal_count] = {
+static procedure vulkan_handle_events (vulkan_structure * vulkan) {
+ static integer signal_code [signal_count] = {
0,
38, 56, 54, 40, 26, 41, 42, 43, 31, 44, 45, 46, 58, 57, 32, 33,
24, 27, 39, 28, 30, 55, 25, 53, 29, 52, 19, 10, 11, 12, 13, 14,
85, 79, 80, 81
};
- s4 index, key_code;
+ integer index, key_code;
xcb_generic_event_t * generic_event;
}
} break;*/
case (XCB_BUTTON_PRESS): {
- vulkan->cursor = (int) ((xcb_button_press_event_t *) generic_event)->detail;
- vulkan->cursor_x = (int) ((xcb_button_press_event_t *) generic_event)->event_x;
- vulkan->cursor_y = (int) ((xcb_button_press_event_t *) generic_event)->event_y;
+ vulkan->cursor = (integer) ((xcb_button_press_event_t *) generic_event)->detail;
+ vulkan->cursor_x = (integer) ((xcb_button_press_event_t *) generic_event)->event_x;
+ vulkan->cursor_y = (integer) ((xcb_button_press_event_t *) generic_event)->event_y;
} break;
case (XCB_BUTTON_RELEASE): {
vulkan->cursor = cursor_none;
- vulkan->cursor_x = (int) ((xcb_button_release_event_t *) generic_event)->event_x;
- vulkan->cursor_y = (int) ((xcb_button_release_event_t *) generic_event)->event_y;
+ vulkan->cursor_x = (integer) ((xcb_button_release_event_t *) generic_event)->event_x;
+ vulkan->cursor_y = (integer) ((xcb_button_release_event_t *) generic_event)->event_y;
} break;
case (XCB_KEY_PRESS): {
- key_code = (int) ((xcb_key_press_event_t *) generic_event)->detail;
+ key_code = (integer) ((xcb_key_press_event_t *) generic_event)->detail;
for (index = 0; index < signal_count; ++index) {
if (key_code == signal_code [index]) {
vulkan->signal [index] = true;
}
} break;
case (XCB_KEY_RELEASE): {
- key_code = (int) ((xcb_key_release_event_t *) generic_event)->detail;
+ key_code = (integer) ((xcb_key_release_event_t *) generic_event)->detail;
for (index = 0; index < signal_count; ++index) {
if (key_code == signal_code [index]) {
vulkan->signal [index] = false;
}
} break;
/*case (XCB_MOTION_NOTIFY): {
- vulkan->cursor_x = (int) ((xcb_motion_notify_event_t *) generic_event)->event_x;
- vulkan->cursor_y = (int) ((xcb_motion_notify_event_t *) generic_event)->event_y;
+ vulkan->cursor_x = (integer) ((xcb_motion_notify_event_t *) generic_event)->event_x;
+ vulkan->cursor_y = (integer) ((xcb_motion_notify_event_t *) generic_event)->event_y;
} break;*/
default: {
} break;
generic_event = deallocate (generic_event);
}
-static v0 vulkan_synchronize (vulkan_structure * vulkan, u4 clear_colour) {
- u4 index = 0;
- u4 frame = 0;
+static procedure vulkan_synchronize (vulkan_structure * vulkan, natural clear_colour) {
+ natural index = 0;
+ natural frame = 0;
VkResult result = VK_SUCCESS;
- v0 * ubo_v0 = null;
+ generic * ubo_procedure = null;
VkPipelineStageFlags wait_stages [1] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT} ;
vulkan_record_command_buffers (vulkan, clear_colour, frame);
- vulkan_result (vkWaitForFences (vulkan->logical_device, 1, & vulkan->fence_set_1 [vulkan->frame], VK_TRUE, ~0));
+ vulkan_result (vkWaitForFences (vulkan->boolean_device, 1, & vulkan->fence_set_1 [vulkan->frame], VK_TRUE, ~0));
- vulkan_result (vkAcquireNextImageKHR (vulkan->logical_device, vulkan->swapchain, ~0, vulkan->semaphore_set_1 [vulkan->frame],
+ vulkan_result (vkAcquireNextImageKHR (vulkan->boolean_device, vulkan->swapchain, ~0, vulkan->semaphore_set_1 [vulkan->frame],
VK_NULL_HANDLE, & frame));
/*
- result = vkAcquireNextImageKHR (vulkan->logical_device, vulkan->swapchain, ~0, vulkan->semaphore_set_1 [vulkan->frame],
+ result = vkAcquireNextImageKHR (vulkan->boolean_device, vulkan->swapchain, ~0, vulkan->semaphore_set_1 [vulkan->frame],
VK_NULL_HANDLE, & frame);
print ("vkAcquireNextImageKHR : /5%i/-\n", result);
return;
}
*/
- vulkan_result (vkResetFences (vulkan->logical_device, 1, & vulkan->fence_set_1 [vulkan->frame]));
+ vulkan_result (vkResetFences (vulkan->boolean_device, 1, & vulkan->fence_set_1 [vulkan->frame]));
submit_information.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submit_information.waitSemaphoreCount = 1;
vulkan->frame = (vulkan->frame + 1) % vulkan->image_count;
vulkan_result (vkQueueWaitIdle (vulkan->queue));
- vulkan_result (vkDeviceWaitIdle (vulkan->logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan->boolean_device));
- vkDestroyBuffer (vulkan->logical_device, vulkan->index_buffer, null);
- vkFreeMemory (vulkan->logical_device, vulkan->index_memory, null);
- vkDestroyBuffer (vulkan->logical_device, vulkan->vertex_buffer, null);
- vkFreeMemory (vulkan->logical_device, vulkan->vertex_memory, null);
+ vkDestroyBuffer (vulkan->boolean_device, vulkan->index_buffer, null);
+ vkFreeMemory (vulkan->boolean_device, vulkan->index_memory, null);
+ vkDestroyBuffer (vulkan->boolean_device, vulkan->vertex_buffer, null);
+ vkFreeMemory (vulkan->boolean_device, vulkan->vertex_memory, null);
vulkan->vertex_count = 0;
vulkan->index_count = 0;
vulkan_result (vkQueueWaitIdle (vulkan->queue));
- vulkan_result (vkDeviceWaitIdle (vulkan->logical_device));
+ vulkan_result (vkDeviceWaitIdle (vulkan->boolean_device));
clock_gettime (CLOCK_REALTIME, & frame_end);
if (vulkan->gameplay_time % (vulkan->gameplay_framerate / 10) == 0) {
vulkan->frame_time_in_ns = (frame_end.tv_sec - frame_begin.tv_sec) * 1000000000 + frame_end.tv_nsec - frame_begin.tv_nsec;
- vulkan->framerate = (int) (1000000000 / vulkan->frame_time_in_ns);
+ vulkan->framerate = (integer) (1000000000 / vulkan->frame_time_in_ns);
}
if (vulkan->framerate > vulkan->gameplay_framerate) {
// for more details, if you dare, it is a lot of text that nobody wants to read...
//~typedef struct {
- //~c1 * name;
+ //~character * name;
//~} * _definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 temperature; // ;
- u4 humidity; // ;
+ character * name; // Name string copy.
+ natural temperature; // ;
+ natural humidity; // ;
} * dungeon_biome_definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 biome; // Index in biome array.
- b4 clip; // Can entities move through?
+ character * name; // Name string copy.
+ natural biome; // Index in biome array.
+ boolean clip; // Can entities move through?
} * dungeon_landmark_definition;
typedef struct {
- c1 * name; // Name string copy.
+ character * name; // Name string copy.
} * dungeon_expertise_definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 base; // Default amount of points per entity.
- u4 limit; // After this point, points won't increase.
+ character * name; // Name string copy.
+ natural base; // Default amount of points per entity.
+ natural limit; // After this point, points won't increase.
} * dungeon_attribute_definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 base; // Default amount of points per entity.
- u4 limit; // After this point, points won't increase.
+ character * name; // Name string copy.
+ natural base; // Default amount of points per entity.
+ natural limit; // After this point, points won't increase.
} * dungeon_skill_definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 base; // Default amount of points per entity.
- u4 limit; // After this point, points won't increase.
- u4 value; // Constant trade value per index 0.
- u4 trade; // Trade rate for acquiring the resource.
+ character * name; // Name string copy.
+ natural base; // Default amount of points per entity.
+ natural limit; // After this point, points won't increase.
+ natural value; // Constant trade value per index 0.
+ natural trade; // Trade rate for acquiring the resource.
} * dungeon_resource_definition;
typedef struct {
- c1 * name; // Name string copy.
+ character * name; // Name string copy.
} * dungeon_item_slot_definition;
typedef struct {
- c1 * name; // Name string copy.
- u4 slot; // Index in item slot array.
- u4 effect; // Index in effect array.
+ character * name; // Name string copy.
+ natural slot; // Index in item slot array.
+ natural effect; // Index in effect array.
} * dungeon_item_definition;
typedef struct {
- u4 biome_count;
- u4 landmark_count;
- u4 expertise_count;
- u4 attribute_count;
- u4 skill_count;
- u4 resource_count;
- u4 item_slot_count;
- u4 item_count;
+ natural biome_count;
+ natural landmark_count;
+ natural expertise_count;
+ natural attribute_count;
+ natural skill_count;
+ natural resource_count;
+ natural item_slot_count;
+ natural item_count;
dungeon_biome_definition * biome_array;
dungeon_landmark_definition * landmark_array;
dungeon_expertise_definition * expertise_array;
dungeon_item_definition * item_array;
} * dungeon_structure;
-static u4 dungeon_biome_define (dungeon_structure dungeon, c1 * name, u4 temperature, u4 humidity) {
+static natural dungeon_biome_define (dungeon_structure dungeon, character * name, natural temperature, natural humidity) {
dungeon_biome_definition biome = arena_add (sizeof (* biome));
fatal_failure (dungeon == null, "biome_define: Dungeon is not configured.");
return (dungeon->biome_count - 1);
}
-static c1 * dungeon_biome_name (dungeon_structure dungeon, u4 index) { return (dungeon->biome_array [index]->name); }
-static u4 dungeon_biome_temperature (dungeon_structure dungeon, u4 index) { return (dungeon->biome_array [index]->temperature); }
-static u4 dungeon_biome_humidity (dungeon_structure dungeon, u4 index) { return (dungeon->biome_array [index]->humidity); }
+static character * dungeon_biome_name (dungeon_structure dungeon, natural index) { return (dungeon->biome_array [index]->name); }
+static natural dungeon_biome_temperature (dungeon_structure dungeon, natural index) { return (dungeon->biome_array [index]->temperature); }
+static natural dungeon_biome_humidity (dungeon_structure dungeon, natural index) { return (dungeon->biome_array [index]->humidity); }
-static u4 dungeon_landmark_define (dungeon_structure dungeon, c1 * name, u4 biome, b4 clip) {
+static natural dungeon_landmark_define (dungeon_structure dungeon, character * name, natural biome, boolean clip) {
dungeon_landmark_definition landmark = arena_add (sizeof (* landmark));
fatal_failure (dungeon == null, "landmark_define: Dungeon is not configured.");
return (dungeon->landmark_count - 1);
}
-static c1 * dungeon_landmark_name (dungeon_structure dungeon, u4 index) { return (dungeon->landmark_array [index]->name); }
-static u4 dungeon_landmark_biome (dungeon_structure dungeon, u4 index) { return (dungeon->landmark_array [index]->biome); }
-static b4 dungeon_landmark_clip (dungeon_structure dungeon, u4 index) { return (dungeon->landmark_array [index]->clip); }
+static character * dungeon_landmark_name (dungeon_structure dungeon, natural index) { return (dungeon->landmark_array [index]->name); }
+static natural dungeon_landmark_biome (dungeon_structure dungeon, natural index) { return (dungeon->landmark_array [index]->biome); }
+static boolean dungeon_landmark_clip (dungeon_structure dungeon, natural index) { return (dungeon->landmark_array [index]->clip); }
-static u4 dungeon_expertise_define (dungeon_structure dungeon, c1 * name) {
+static natural dungeon_expertise_define (dungeon_structure dungeon, character * name) {
dungeon_expertise_definition expertise = arena_add (sizeof (* expertise));
fatal_failure (dungeon == null, "expertise_define: Dungeon is not configured.");
return (dungeon->expertise_count - 1);
}
-static c1 * dungeon_expertise_name (dungeon_structure dungeon, u4 index) { return (dungeon->expertise_array [index]->name); }
+static character * dungeon_expertise_name (dungeon_structure dungeon, natural index) { return (dungeon->expertise_array [index]->name); }
-static u4 dungeon_attribute_define (dungeon_structure dungeon, c1 * name, u4 base, u4 limit) {
+static natural dungeon_attribute_define (dungeon_structure dungeon, character * name, natural base, natural limit) {
dungeon_attribute_definition attribute = arena_add (sizeof (* attribute));
fatal_failure (dungeon == null, "attribute_define: Dungeon is not configured.");
return (dungeon->attribute_count - 1);
}
-static c1 * dungeon_attribute_name (dungeon_structure dungeon, u4 index) { return (dungeon->attribute_array [index]->name); }
-static u4 dungeon_attribute_base (dungeon_structure dungeon, u4 index) { return (dungeon->attribute_array [index]->base); }
-static u4 dungeon_attribute_limit (dungeon_structure dungeon, u4 index) { return (dungeon->attribute_array [index]->limit); }
+static character * dungeon_attribute_name (dungeon_structure dungeon, natural index) { return (dungeon->attribute_array [index]->name); }
+static natural dungeon_attribute_base (dungeon_structure dungeon, natural index) { return (dungeon->attribute_array [index]->base); }
+static natural dungeon_attribute_limit (dungeon_structure dungeon, natural index) { return (dungeon->attribute_array [index]->limit); }
-static u4 dungeon_skill_define (dungeon_structure dungeon, c1 * name, u4 base, u4 limit) {
+static natural dungeon_skill_define (dungeon_structure dungeon, character * name, natural base, natural limit) {
dungeon_skill_definition skill = arena_add (sizeof (* skill));
fatal_failure (dungeon == null, "skill_define: Dungeon is not configured.");
return (dungeon->skill_count - 1);
}
-static c1 * dungeon_skill_name (dungeon_structure dungeon, u4 index) { return (dungeon->skill_array [index]->name); }
-static u4 dungeon_skill_base (dungeon_structure dungeon, u4 index) { return (dungeon->skill_array [index]->base); }
-static u4 dungeon_skill_limit (dungeon_structure dungeon, u4 index) { return (dungeon->skill_array [index]->limit); }
+static character * dungeon_skill_name (dungeon_structure dungeon, natural index) { return (dungeon->skill_array [index]->name); }
+static natural dungeon_skill_base (dungeon_structure dungeon, natural index) { return (dungeon->skill_array [index]->base); }
+static natural dungeon_skill_limit (dungeon_structure dungeon, natural index) { return (dungeon->skill_array [index]->limit); }
-static u4 dungeon_resource_define (dungeon_structure dungeon, c1 * name, u4 base, u4 limit, u4 value, u4 trade) {
+static natural dungeon_resource_define (dungeon_structure dungeon, character * name, natural base, natural limit, natural value, natural trade) {
dungeon_resource_definition resource = arena_add (sizeof (* resource));
fatal_failure (dungeon == null, "resource_define: Dungeon is not configured.");
return (dungeon->resource_count - 1);
}
-static c1 * dungeon_resource_name (dungeon_structure dungeon, u4 index) { return (dungeon->resource_array [index]->name); }
-static u4 dungeon_resource_base (dungeon_structure dungeon, u4 index) { return (dungeon->resource_array [index]->base); }
-static u4 dungeon_resource_limit (dungeon_structure dungeon, u4 index) { return (dungeon->resource_array [index]->limit); }
-static u4 dungeon_resource_value (dungeon_structure dungeon, u4 index) { return (dungeon->resource_array [index]->value); }
-static u4 dungeon_resource_trade (dungeon_structure dungeon, u4 index) { return (dungeon->resource_array [index]->trade); }
+static character * dungeon_resource_name (dungeon_structure dungeon, natural index) { return (dungeon->resource_array [index]->name); }
+static natural dungeon_resource_base (dungeon_structure dungeon, natural index) { return (dungeon->resource_array [index]->base); }
+static natural dungeon_resource_limit (dungeon_structure dungeon, natural index) { return (dungeon->resource_array [index]->limit); }
+static natural dungeon_resource_value (dungeon_structure dungeon, natural index) { return (dungeon->resource_array [index]->value); }
+static natural dungeon_resource_trade (dungeon_structure dungeon, natural index) { return (dungeon->resource_array [index]->trade); }
-static u4 dungeon_item_slot_define (dungeon_structure dungeon, c1 * name) {
+static natural dungeon_item_slot_define (dungeon_structure dungeon, character * name) {
dungeon_item_slot_definition item_slot = arena_add (sizeof (* item_slot));
fatal_failure (dungeon == null, "item_slot_define: Dungeon is not configured.");
return (dungeon->item_slot_count - 1);
}
-static c1 * dungeon_item_slot_name (dungeon_structure dungeon, u4 index) { return (dungeon->item_slot_array [index]->name); }
+static character * dungeon_item_slot_name (dungeon_structure dungeon, natural index) { return (dungeon->item_slot_array [index]->name); }
-static u4 dungeon_item_define (dungeon_structure dungeon, c1 * name, u4 slot, u4 effect) {
+static natural dungeon_item_define (dungeon_structure dungeon, character * name, natural slot, natural effect) {
dungeon_item_definition item = arena_add (sizeof (* item));
fatal_failure (dungeon == null, "item_define: Dungeon is not configured.");
return (dungeon->item_count - 1);
}
-static c1 * dungeon_item_name (dungeon_structure dungeon, u4 index) { return (dungeon->item_array [index]->name); }
-static u4 dungeon_item_slot (dungeon_structure dungeon, u4 index) { return (dungeon->item_array [index]->slot); }
-static u4 dungeon_item_effect (dungeon_structure dungeon, u4 index) { return (dungeon->item_array [index]->effect); }
+static character * dungeon_item_name (dungeon_structure dungeon, natural index) { return (dungeon->item_array [index]->name); }
+static natural dungeon_item_slot (dungeon_structure dungeon, natural index) { return (dungeon->item_array [index]->slot); }
+static natural dungeon_item_effect (dungeon_structure dungeon, natural index) { return (dungeon->item_array [index]->effect); }
-static dungeon_structure dungeon_configure (u4 biome_limit, u4 landmark_limit, u4 expertise_limit, u4 attribute_limit, u4 skill_limit,
- u4 resource_limit, u4 item_slot_limit, u4 item_limit) {
+static dungeon_structure dungeon_configure (natural biome_limit, natural landmark_limit, natural expertise_limit, natural attribute_limit, natural skill_limit,
+ natural resource_limit, natural item_slot_limit, natural item_limit) {
dungeon_structure dungeon = arena_add (sizeof (* dungeon));
dungeon->biome_array = arena_add (biome_limit * sizeof (* dungeon->biome_array));
#define font_height ( 8)
#define font_count (96)
-static u4 * render = null;
-static u4 colour = foreground;
+static natural * render = null;
+static natural colour = foreground;
-static u4 width = 0;
-static u4 height = 0;
-static u4 x = 0;
-static u4 y = 0;
+static natural width = 0;
+static natural height = 0;
+static natural x = 0;
+static natural y = 0;
-static v0 render_character (c1 character) {
- u8 font_code [font_count] = {
+static procedure render_character (character character) {
+ natural_64 font_code [font_count] = {
0x0000000000000000, 0x00180018183c3c18, 0x0000000000363636, 0x006c6cfe6cfe6c6c,
0x00187ed07c16fc30, 0x0060660c18306606, 0x00dc66b61c36361c, 0x0000000000181818,
0x0030180c0c0c1830, 0x000c18303030180c, 0x0000187e3c7e1800, 0x000018187e181800,
0x0018181818181818, 0x000c18187018180c, 0x000000000062d68c, 0x0000000000000000
};
- for (u4 offset = 0; offset < font_width * font_height; ++offset) {
- u4 u = offset / font_width + y;
- u4 v = offset % font_width + x;
+ for (natural offset = 0; offset < font_width * font_height; ++offset) {
+ natural u = offset / font_width + y;
+ natural v = offset % font_width + x;
- render [u * width + v] = ((font_code [(u4) (character - ' ')] >> offset) % 2) ? colour : background;
+ render [u * width + v] = ((font_code [(natural) (character - ' ')] >> offset) % 2) ? colour : background;
}
x += font_width + 1;
}
-static v0 render_string (c1 * string, u4 length) {
- for (u4 offset = 0; offset < length; ++offset) {
+static procedure render_string (character * string, natural length) {
+ for (natural offset = 0; offset < length; ++offset) {
if (string [offset] == '\t') {
x += font_width * font_indent;
} else if (string [offset] == '\n') {
}
}
-s4 main (v0) {
- u4 index = 0;
- u4 length = 0;
- c1 * buffer = null;
+integer main (none) {
+ natural index = 0;
+ natural length = 0;
+ character * buffer = null;
- c1 separator [] = ".,:;<=>+-*/%!&~^()[]{}'\" \t\r\n";
+ character separator [] = ".,:;<=>+-*/%!&~^()[]{}'\" \t\r\n";
- c1 * keywords [] = {
+ character * keywords [] = {
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "v0", "return", "sizeof",
syntax_define (syntax, true, false, ".,:;<=>+-*/%!&~^?|", "", '\0', 0xffccaa33, 0);
syntax_define (syntax, true, false, "(){}[]", "", '\0', 0xffcc3333, 0);
- for (u8 word = 0; word < array_length (keywords); ++word) {
+ for (natural_64 word = 0; word < array_length (keywords); ++word) {
syntax_define (syntax, false, true, keywords [word], separator, '\0', 0xff33aacc, 0);
}
render = allocate (4 * width * height);
- for (u4 offset = 0; offset < width * height; ++offset) {
+ for (natural offset = 0; offset < width * height; ++offset) {
render [offset] = background;
}
- for (u4 offset = 0; buffer [offset] != '\0'; offset += length) {
+ for (natural offset = 0; buffer [offset] != '\0'; offset += length) {
index = syntax_select (syntax, & buffer [offset], & length);
colour = syntax->colour [index];
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...
+/// Description
+///
/// Xyntax, the most minimal text parser that can deal with syntax highlighting that I could've come up with, and the most generic name for it
/// also, it's rather slow, but if you're creating heavy duty program, you'd use heavy duty library for it. This library has only one header, so
/// it's easy to incorporate it into existing projects. If you want to see how it is used, check out simple examples below, if you want more
/// robust example, check out my other programs, Xarbon and Xighlight.
///
/// For start, you want to include this header file, there's no macro for including implementation (like stb libraries), this is for projects
-/// that have only one C source file, and one or more C header files. After that simple make global or local variable 'syntax_structure * x'
-/// defined below, initialize it, define the rules, then in main loop select rule, do your thing with it, then deinitialize the structure. It's
+/// that have only one C source file, and one or more C header files. Then make global or local variable 'syntax_structure * whatever_syntax'
+/// defined below, initialize it, define the rules, then in main loop select rule, do whatever you wanted, then deinitialize the structure. It's
/// simple, I'll provide minimal examples below.
/// Structure for single syntax definition (array of rules), if you want to parse multiple languages simultaneously, use an array.
///
-/// syntax_structure * c_syntax = null;
+/// syntax_structure * syntax = null;
typedef struct {
natural count; /// Count of syntax rules used, maximum is set with limit below, if limit is 0, it'll allocate it dynamically.
/// Initialize syntax structure before calling other functions that take it as an argument, set 'limit' to 0 if you want dynamic array of rules.
///
-/// c_syntax = syntax_initialize (0);
+/// syntax = syntax_initialize (0);
static syntax_structure * syntax_initialize (natural limit) {
syntax_structure * syntax = allocate (sizeof (* syntax));
/// Deinitialize syntax structure after using it, in order to avoid memory leaks.
///
-/// c_syntax = syntax_deinitialize (c_syntax);
+/// syntax = syntax_deinitialize (syntax);
static syntax_structure * syntax_deinitialize (syntax_structure * syntax) {
for (natural index = 0; index < syntax->count; ++index) {
///
/// Take a look into few simple examples of defining some simplified rules of C programming language.
/// Two examples below show how to define multiline comments and strings, since these have priority, both enrange and derange are false.
+///
/// syntax_define (syntax, false, false, "/*", "*/", '\\', 1, 0);
/// syntax_define (syntax, false, false, "\"", "\"", '\\', 2, 0);
+///
/// Now we're defining syntax rule for one keyword, static, notice that end string contaings separator characters because derange is true.
+///
/// syntax_define (syntax, false, true, "static", "()[]{}.,:;<=>+*-/%!&~^?| \t\r\n", '\0', 3, 0);
+///
/// You can define brackets and operator characters separately, or if you want to, you can define some of them separately again.
+///
/// syntax_define (syntax, true, false, "()[]{}", "", '\0', 4, 0);
/// syntax_define (syntax, true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', 5, 0);
+///
/// And lastly, we can define number selection like this below, by setting both enrange and derange as false.
+///
/// syntax_define (syntax, true, true, "0123456789", "()[]{}.,:;<=>+*-/%!&~^?| \t\r\n", '\0', 6, 0);
+///
+/// I hope this is pretty clear, if you want to select a number, you start by matching any of digits provided above, and you end matching that
+/// number by any character from 'end' string, if you want to support floating point numbers, you'd exclude '.' character, or alternatively add
+/// letters f, u, l and whatever else your language supports (like in C/C++). However, this approach is too weak for detecting syntax errors,
+/// you shouldn't use this library for robust linter or parser.
static natural syntax_define (syntax_structure * syntax, boolean enrange, boolean derange, character * begin, character * end, character escape,
natural colour, natural effect) {
///
/// Now, imagine that 'buffer' is file you've loaded into memory, you have declared natural numbers 'offset', 'length' and 'select', and you've
/// properly initialized syntax structure 'syntax', defined its rules for wanted language(s), simple main loop would look like this:
+///
/// for (offset = 0; buffer [offset] != '\0'; offset += length) {
/// /// Notice that we're not incrementing 'offset', we're increasing it by 'length'.
/// select = syntax_select (syntax, & buffer [offset], & length);
/// /// Syntax definition is incomplete, unknown sequence has been detected, either print nothing, or print default.
/// } else {
/// /// Print string of 'length', at '& buffer [offset]', using 'syntax->colour [select]' and 'syntax->effect [select]'.
+/// /// Strings here aren't null terminated, you want to print sized string.
/// }
/// }
natural subset = 0;
natural select = 0;
- natural_64 begin_length = 0;
- natural_64 end_length = 0;
-
for (; select != syntax->count; ++select) {
- begin_length = string_length (syntax->begin [select]);
+ caliber begin_length = string_length (syntax->begin [select]);
- if (! syntax->enrange [select]) {
- if (! syntax->derange [select]) {
- if (string_compare_limit (string, syntax->begin [select], begin_length)) {
+ if (syntax->enrange [select] == false) {
+ if (syntax->derange [select] == false) {
+ if (string_compare_limit (string, syntax->begin [select], begin_length) == true) {
break;
}
} else {
- if ((string_compare_limit (string, syntax->begin [select], begin_length))
- && (character_compare_array (string [offset + begin_length], syntax->end [select]))) {
+ if ((string_compare_limit (string, syntax->begin [select], begin_length) == true)
+ && (character_compare_array (string [offset + begin_length], syntax->end [select]) == true)) {
break;
}
}
return (syntax->count);
}
- end_length = string_length (syntax->end [select]);
+ caliber end_length = string_length (syntax->end [select]);
for (offset = 1; string [offset - 1] != character_null; ++offset) {
if (string [offset] == syntax->escape [select]) {
continue;
}
- if (syntax->derange [select]) {
+ if (syntax->derange [select] == true) {
subset = 0;
if (end_length == 0) {
break;