Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kaacore
Submodule kaacore updated 96 files
+74 −54 .ci/az-pipelines/build.yml
+17 −109 .clang-format
+1 −0 .gitignore
+30 −15 demos/basic_scene.cpp
+16 −8 demos/controllers.cpp
+2 −1 demos/drawing_order.cpp
+51 −25 demos/fonts.cpp
+8 −6 demos/input.cpp
+29 −17 demos/physics.cpp
+22 −12 demos/polygon_tester.cpp
+19 −12 demos/spatial_indexing.cpp
+4 −3 demos/spatial_indexing_2.cpp
+18 −11 demos/sprites.cpp
+44 −43 demos/stencil.cpp
+30 −15 demos/transitions.cpp
+21 −13 demos/window.cpp
+7 −5 include/kaacore/audio.h
+19 −10 include/kaacore/draw_unit.h
+2 −1 include/kaacore/embedded_data.h
+6 −3 include/kaacore/engine.h
+6 −3 include/kaacore/exceptions.h
+66 −16 include/kaacore/fonts.h
+43 −24 include/kaacore/geometry.h
+6 −5 include/kaacore/input.h
+38 −20 include/kaacore/log.h
+20 −11 include/kaacore/materials.h
+1 −1 include/kaacore/memory.h
+43 −24 include/kaacore/node_transitions.h
+10 −8 include/kaacore/nodes.h
+24 −14 include/kaacore/physics.h
+7 −6 include/kaacore/render_passes.h
+4 −2 include/kaacore/render_targets.h
+24 −12 include/kaacore/renderer.h
+7 −4 include/kaacore/resources.h
+4 −2 include/kaacore/scenes.h
+13 −7 include/kaacore/shaders.h
+17 −9 include/kaacore/shapes.h
+4 −2 include/kaacore/spatial_index.h
+3 −2 include/kaacore/sprites.h
+14 −9 include/kaacore/stencil.h
+18 −9 include/kaacore/textures.h
+2 −1 include/kaacore/threading.h
+5 −3 include/kaacore/timers.h
+38 −26 include/kaacore/transitions.h
+105 −0 include/kaacore/unicode_buffer.h
+13 −9 include/kaacore/uniforms.h
+8 −3 include/kaacore/utils.h
+10 −5 include/kaacore/vertex_layout.h
+3 −3 include/kaacore/viewports.h
+2 −0 src/CMakeLists.txt
+42 −22 src/audio.cpp
+18 −10 src/camera.cpp
+3 −2 src/clock.cpp
+4 −2 src/draw_queue.cpp
+66 −33 src/draw_unit.cpp
+6 −3 src/embedded_data.cpp
+63 −38 src/engine.cpp
+174 −83 src/fonts.cpp
+4 −2 src/geometry.cpp
+54 −31 src/input.cpp
+23 −11 src/log.cpp
+47 −25 src/materials.cpp
+8 −4 src/node_ptr.cpp
+68 −38 src/nodes.cpp
+187 −99 src/physics.cpp
+1 −1 src/platform.cpp
+20 −11 src/render_passes.cpp
+14 −9 src/render_targets.cpp
+124 −72 src/renderer.cpp
+32 −16 src/scenes.cpp
+33 −17 src/shaders.cpp
+62 −34 src/shapes.cpp
+32 −17 src/spatial_index.cpp
+33 −16 src/sprites.cpp
+15 −8 src/statistics.cpp
+18 −13 src/stencil.cpp
+13 −9 src/textures.cpp
+11 −6 src/timers.cpp
+92 −54 src/transitions.cpp
+224 −0 src/unicode_buffer.cpp
+14 −7 src/uniforms.cpp
+2 −2 src/utils.cpp
+22 −12 src/viewports.cpp
+33 −21 src/window.cpp
+1 −0 tests/CMakeLists.txt
+30 −15 tests/test_basics.cpp
+12 −6 tests/test_draw_queue.cpp
+77 −38 tests/test_draw_unit.cpp
+4 −2 tests/test_geometry.cpp
+2 −1 tests/test_hitboxes.cpp
+26 −17 tests/test_materials.cpp
+2 −1 tests/test_shapes.cpp
+12 −6 tests/test_statistics.cpp
+24 −17 tests/test_textures.cpp
+10 −5 tests/test_transitions.cpp
+29 −0 tests/test_unicode_buffer.cpp
39 changes: 32 additions & 7 deletions src/kaa/fonts.pxi
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
from cpython.unicode cimport (
PyUnicode_FromKindAndData, PyUnicode_KIND, PyUnicode_DATA,
PyUnicode_GET_LENGTH,
)

from .kaacore.nodes cimport CNodeType
from .kaacore.fonts cimport CFont, CTextNode
from .kaacore.hashing cimport c_calculate_hash
from .kaacore.unicode_buffer cimport CUnicodeRepresentationSize, CUnicodeView


cdef object unicode_view_to_str(CUnicodeView view):
return PyUnicode_FromKindAndData(
<uint8_t>view.representation_size(),
view.data(),
view.length(),
)


cdef CUnicodeView str_to_unicode_view(str text):
return CUnicodeView(
<uint8_t*>PyUnicode_DATA(text),
PyUnicode_GET_LENGTH(text),
<CUnicodeRepresentationSize>(<uint8_t>PyUnicode_KIND(text)),
)


cdef class Font:
Expand All @@ -9,8 +31,11 @@ cdef class Font:
cdef void attach_c_font(self, const CFont& c_font):
self.c_font = c_font

def __init__(self, str font_filepath):
self.attach_c_font(CFont.load(font_filepath.encode()))
def __init__(self, str font_filepath, str additional_codepoints=None):
if additional_codepoints is None:
self.attach_c_font(CFont.load(font_filepath.encode()))
else:
self.attach_c_font(CFont.load(font_filepath.encode(), str_to_unicode_view(additional_codepoints)))

def __eq__(self, Font other):
return self.c_font == other.c_font
Expand Down Expand Up @@ -50,19 +75,19 @@ cdef class TextNode(NodeBase):

@property
def content(self):
return (<bytes>self.get_c_node().text.content()).decode()
return unicode_view_to_str(self.get_c_node().text.content())

@content.setter
def content(self, str content_text):
self.get_c_node().text.content(<string>content_text.encode())
self.get_c_node().text.content(str_to_unicode_view(content_text))

@property
def text(self):
return (<bytes>self.get_c_node().text.content()).decode()
return unicode_view_to_str(self.get_c_node().text.content())

@text.setter
def text(self, str text):
self.get_c_node().text.content(<string>text.encode())
def text(self, str content_text):
self.get_c_node().text.content(str_to_unicode_view(content_text))

@property
def font_size(self):
Expand Down
8 changes: 6 additions & 2 deletions src/kaa/kaacore/fonts.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ from libcpp.string cimport string
from libcpp cimport bool

from .exceptions cimport raise_py_error
from .unicode_buffer cimport CUnicodeView


cdef extern from "kaacore/fonts.h" namespace "kaacore" nogil:
cdef cppclass CFont "kaacore::Font":
@staticmethod
CFont load(const string& font_filepath) \
except +raise_py_error
@staticmethod
CFont load(const string& font_filepath, const CUnicodeView additional_codepoints) \
except +raise_py_error

bool operator==(const CFont&)

cdef cppclass CTextNode "kaacore::TextNode":
string content() \
CUnicodeView content() \
except +raise_py_error
void content(const string& content) \
void content(const CUnicodeView content) \
except +raise_py_error

double font_size() \
Expand Down
19 changes: 19 additions & 0 deletions src/kaa/kaacore/unicode_buffer.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from libc.stdint cimport uint8_t
from libcpp.string cimport string
from libcpp cimport bool

from .exceptions cimport raise_py_error


cdef extern from "kaacore/unicode_buffer.h" namespace "kaacore" nogil:
cdef enum CUnicodeRepresentationSize "kaacore::UnicodeRepresentationSize":
ucs1 "kaacore::UnicodeRepresentationSize::ucs1",
ucs2 "kaacore::UnicodeRepresentationSize::ucs2",
ucs4 "kaacore::UnicodeRepresentationSize::ucs4",

cdef cppclass CUnicodeView "kaacore::UnicodeView":
CUnicodeView()
CUnicodeView(uint8_t* data, size_t length, CUnicodeRepresentationSize representation_size)
CUnicodeRepresentationSize representation_size() const
size_t length() const
uint8_t* data() const
Loading