-
94.87%
Rate
-
37
Hits
-
2
Missed
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
-
-
-
-
-
- 1x
- 1x
- 1x
-
- 1x
-
-
-
-
-
-
-
- 23x
-
-
- 1x
-
- 1x
- 10x
-
-
- 1x
- 13x
-
-
-
- 1x
-
- 1x
- 4x
- 3x
-
-
- 3x
- 3x
- 2x
- 1x
- 1x
-
-
- 1x
- 1x
-
-
-
- 1x
-
- 1x
-
-
-
-
-
-
-
-
-
-
-
- 1x
- 1x
-
-
- 1x
- 8x
- 8x
-
-
-
-
-
-
- 1x
- 1x
-
-
-
- 1x
- 12x
- 12x
-
- 12x
- 12x
-
- 12x
-
-
-
-
-
-
- 1x
- -------------------------------------------------------------------------------
- -- Base transport medium for PUMAS
- -- Author: Valentin Niess
- -- License: GNU LGPL-3.0
- -------------------------------------------------------------------------------
- local ffi = require('ffi')
- local clib = require('pumas.clib')
- local error = require('pumas.error')
-
- local base = {}
-
-
- -------------------------------------------------------------------------------
- -- Cross utilities between C media and their Lua wrappers
- -------------------------------------------------------------------------------
- do
- local function addressof (ptr)
- return tonumber(ffi.cast('uintptr_t', ptr))
- end
-
- local media_table = setmetatable({}, {__mode = 'v'})
-
- function base.get (c_medium)
- return media_table[addressof(c_medium)]
- end
-
- function base.add (medium)
- media_table[addressof(medium._c)] = medium
- end
-
- local last_version
- local index = ffi.new('int [1]')
-
- function base.update (physics)
- if last_version == physics._version then
- return true
- end
-
- for _, medium in pairs(media_table) do
- if medium.material and (medium.material ~= 'Transparent') then
- local rc = clib.pumas_physics_material_index(physics._c[0],
- medium.material, index)
- if rc ~= clib.PUMAS_RETURN_SUCCESS then
- return false, medium
- else
- local m = ffi.cast('struct pumas_medium *', medium._c)
- m.material = index[0]
- end
- end
- end
- last_version = physics._version
-
- return true
- end
- end
-
-
- -------------------------------------------------------------------------------
- -- The base medium
- --
- -- Note: this is an incomplete metatype intended to be inherited. It provides
- -- common functionalities for media types.
- -------------------------------------------------------------------------------
- -- XXX Allow to provide an optional name?
- local BaseMedium = {}
- base.BaseMedium = BaseMedium
-
-
- function BaseMedium.__index (_, k, strtype)
- if k == '__metatype' then
- return 'Medium'
- else
- error.raise{['type'] = strtype, bad_member = k}
- end
- end
-
-
- function BaseMedium.__newindex (_, k, _, strtype)
- error.raise{['type'] = strtype, bad_member = k}
- end
-
-
- function BaseMedium.new (ctype, ctype_ptr, material)
- local c = ffi.cast(ctype_ptr, ffi.C.calloc(1, ffi.sizeof(ctype)))
- ffi.gc(c, ffi.C.free)
-
- local obj = {_c = c, material = material}
- base.add(obj)
-
- return obj
- end
-
-
- -------------------------------------------------------------------------------
- -- Return the package
- -------------------------------------------------------------------------------
- return base