-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from obiwac/ep13b
Episode 13b: Performance improvements
- Loading branch information
Showing
16 changed files
with
816 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,12 @@ | |
.vscode | ||
*.ogg | ||
*.sw[nop] | ||
*.so | ||
*.c | ||
*.so | ||
*.html | ||
*.cache | ||
dist | ||
build | ||
*.egg-info | ||
*.prof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from setuptools.command.build_ext import build_ext | ||
from Cython.Build import cythonize | ||
import Cython.Compiler.Options | ||
|
||
Cython.Compiler.Options.cimport_from_pyx = True # needed? | ||
|
||
|
||
class BuildExt(build_ext): | ||
def build_extension(self, ext): | ||
self.inplace = True # Important or the LSP won't have access to the compiled files. | ||
super().build_extension(ext) | ||
|
||
|
||
def build(setup_kwargs): | ||
ext_modules = cythonize( | ||
[ | ||
"src/chunk/__init__.pyx", | ||
"src/chunk/chunk.pyx", | ||
"src/chunk/subchunk.pyx", | ||
], | ||
compiler_directives={ | ||
"language_level": 3, | ||
"profile": True, | ||
}, | ||
annotate=True, | ||
) | ||
|
||
setup_kwargs.update({"ext_modules": ext_modules, "cmdclass": {"build_ext": BuildExt}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from src.chunk.common import CHUNK_HEIGHT, CHUNK_LENGTH, CHUNK_WIDTH | ||
from src.chunk.common import SUBCHUNK_HEIGHT, SUBCHUNK_LENGTH, SUBCHUNK_WIDTH | ||
|
||
__all__ = [ | ||
"CHUNK_WIDTH", | ||
"CHUNK_HEIGHT", | ||
"CHUNK_LENGTH", | ||
"SUBCHUNK_WIDTH", | ||
"SUBCHUNK_HEIGHT", | ||
"SUBCHUNK_LENGTH", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from src.chunk.common import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_LENGTH | ||
from src.chunk.common import SUBCHUNK_WIDTH, SUBCHUNK_HEIGHT, SUBCHUNK_LENGTH | ||
|
||
from libc.stdlib cimport malloc, free | ||
from libc.string cimport memset | ||
from libc.stdint cimport uint8_t, uint32_t | ||
|
||
cdef int C_CHUNK_WIDTH = CHUNK_WIDTH | ||
cdef int C_CHUNK_HEIGHT = CHUNK_HEIGHT | ||
cdef int C_CHUNK_LENGTH = CHUNK_LENGTH | ||
|
||
cdef int C_SUBCHUNK_WIDTH = SUBCHUNK_WIDTH | ||
cdef int C_SUBCHUNK_HEIGHT = SUBCHUNK_HEIGHT | ||
cdef int C_SUBCHUNK_LENGTH = SUBCHUNK_LENGTH | ||
|
||
cdef class CSubchunk: | ||
cdef size_t data_count | ||
cdef float* data | ||
|
||
cdef size_t index_count | ||
cdef uint32_t* indices | ||
|
||
def __init__(self): | ||
self.data_count = 0 | ||
self.index_count = 0 | ||
|
||
cdef class CChunk: | ||
cdef size_t data_count | ||
cdef float* data | ||
|
||
cdef size_t index_count | ||
cdef int* indices | ||
|
||
cdef size_t size | ||
cdef uint8_t* blocks | ||
|
||
def __init__(self): | ||
self.size = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_LENGTH * sizeof(self.blocks[0]) | ||
self.blocks = <uint8_t*>malloc(self.size) | ||
memset(self.blocks, 0, self.size) | ||
|
||
def __del__(self): | ||
free(self.blocks) | ||
|
||
@property | ||
def index_count(self): | ||
return self.index_count | ||
|
||
def get_blocks(self, i): | ||
return self.blocks[i] | ||
|
||
def set_blocks(self, i, val): | ||
self.blocks[i] = val | ||
|
||
def copy_blocks(self, blocks): | ||
cdef int i | ||
cdef int length = len(blocks) | ||
|
||
for i in range(length): | ||
self.blocks[i] = blocks[i] |
Oops, something went wrong.