2022-08-28 05:09:52 +02:00
|
|
|
# Copyright (C) 2022 RozK
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-12-20 14:40:17 +01:00
|
|
|
from ctypes import c_ubyte, c_uint, POINTER
|
2022-08-28 05:09:52 +02:00
|
|
|
|
|
|
|
from engine import (
|
2022-12-17 05:03:08 +01:00
|
|
|
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, create_batch, draw_batch, destroy_batch)
|
2022-08-28 05:09:52 +02:00
|
|
|
|
|
|
|
class Batch:
|
2022-12-20 14:40:17 +01:00
|
|
|
__slots__ = '_batch', '_paramsp', 'size', 'max_size', 'flags', 'meshes', 'params'
|
2022-08-28 05:09:52 +02:00
|
|
|
|
2022-12-20 13:48:19 +01:00
|
|
|
def __init__(self, vertices, max_size, params_format, params_type):
|
2022-08-28 05:09:52 +02:00
|
|
|
assert max_size <= BATCH_MAX_SIZE
|
2022-12-18 03:44:31 +01:00
|
|
|
self._batch = create_batch(vertices, max_size, params_format)
|
2022-12-20 13:48:19 +01:00
|
|
|
self._paramsp = POINTER(params_type)
|
2022-12-20 14:40:17 +01:00
|
|
|
self.size = 0
|
2022-08-28 05:09:52 +02:00
|
|
|
self.max_size = max_size
|
2022-12-20 14:40:17 +01:00
|
|
|
self.flags = (c_ubyte * max_size)()
|
|
|
|
self.meshes = (c_uint * max_size)()
|
2022-12-20 13:48:19 +01:00
|
|
|
self.params = (params_type * max_size)()
|
2022-08-28 05:09:52 +02:00
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
destroy_batch(self._batch)
|
|
|
|
|
2022-12-17 05:03:08 +01:00
|
|
|
def append(self, flags, mesh, params):
|
2022-12-20 14:40:17 +01:00
|
|
|
index = self.size
|
2022-08-28 05:09:52 +02:00
|
|
|
assert index < self.max_size
|
2022-12-20 14:40:17 +01:00
|
|
|
self.flags[index] = flags | INSTANCE_FLAG_SPAWNED
|
|
|
|
self.meshes[index] = mesh
|
2022-12-20 13:48:19 +01:00
|
|
|
self.params[index] = params
|
2022-12-20 14:40:17 +01:00
|
|
|
self.size += 1
|
2022-12-20 13:48:19 +01:00
|
|
|
return index
|
2022-08-28 05:09:52 +02:00
|
|
|
|
|
|
|
def draw(self):
|
2022-12-20 14:40:17 +01:00
|
|
|
draw_batch(self._batch, self.size, self.flags, self.meshes, self._paramsp(self.params))
|