Commits

Juha Komulainen committed 5585ddd

Made code to compile with latest latest Kotlin.

Comments (0)

Files changed (6)

.idea/runConfigurations/threed.xml

+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="threed" type="JetRunConfigurationType" factoryName="Kotlin">
+    <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+    <option name="MAIN_CLASS_NAME" value="threed.namespace" />
+    <option name="VM_PARAMETERS" value="-Djava.library.path=libs/native/macosx" />
+    <option name="PROGRAM_PARAMETERS" value="" />
+    <option name="WORKING_DIRECTORY" value="" />
+    <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+    <option name="ALTERNATIVE_JRE_PATH" />
+    <option name="PASS_PARENT_ENVS" value="true" />
+    <module name="threed" />
+    <envs />
+    <RunnerSettings RunnerId="Run" />
+    <ConfigurationWrapper RunnerId="Run" />
+    <method />
+  </configuration>
+</component>

src/main/java/threed/ShaderDemo.kt

         shader.bind()
 
         shader["time"] = System.currentTimeMillis() % 1000000 / 1000.toFloat()
-        shader["unResolution"] = #(mode.getWidth().toFloat(), mode.getHeight().toFloat(), 1.toFloat())
+        shader["unResolution"] = Triple(mode.getWidth().toFloat(), mode.getHeight().toFloat(), 1.toFloat())
 
         glVertexPointer(Mesh.VERTEX_COUNT, GL_FLOAT, Mesh.SIZE_IN_BYTES, Mesh.VERTEX_OFFSET)
         shader["vertexTextureCoordinate"] = AttributePointer(Mesh.TEX_COORD_COUNT, GL_FLOAT, true, Mesh.SIZE_IN_BYTES, Mesh.TEX_COORD_OFFSET)
 
 fun main(args: Array<String>) {
     try {
-        val mode = Display.getDisplayMode().sure()
+        val mode = Display.getDisplayMode()!!
         Display.setDisplayModeAndFullscreen(mode)
         Display.create()
         Keyboard.create()

src/main/java/threed/common/Mesh.kt

                 .build()
 
         private fun createVertexBuffer(data: FloatArray): Int {
-            val buffer = BufferUtils.createFloatBuffer(data.size).sure()
-            for (val v in data)
+            val buffer = BufferUtils.createFloatBuffer(data.size)!!
+            for (v in data)
                 buffer.put(v)
             buffer.rewind()
 
             return id
         }
 
-        class Builder private (capacity: Int) {
+        class Builder internal(capacity: Int) {
 
             private var index = 0
             private val data = FloatArray(capacity * ENTRIES)

src/main/java/threed/common/ShaderLoader.kt

         glLinkProgram(program)
         glValidateProgram(program)
 
-        val log = glGetProgramInfoLog(program, 1024).sure()
+        val log = glGetProgramInfoLog(program, 1024)!!
         if (!log.isEmpty())
             throw RuntimeException("Invalid program: $log")
 
         glShaderSource(shader, source)
         glCompileShader(shader)
         
-        val log = glGetShaderInfoLog(shader, 1024).sure()
+        val log = glGetShaderInfoLog(shader, 1024)!!
         if (!log.isEmpty())
             throw RuntimeException("Invalid shader: $log")
 

src/main/java/threed/common/ShaderProgram.kt

             glUniform1f(location, value)
     }
 
-    fun set(name: String, value: #(Float, Float, Float)) {
+    fun set(name: String, value: Triple<Float, Float, Float>) {
         val location = glGetUniformLocation(id, name)
         if (location != -1)
-            glUniform3f(location, value._1, value._2, value._3)
+            glUniform3f(location, value.first, value.second, value.third)
     }
 
     fun set(name: String, p: AttributePointer) {

src/main/java/threed/utils/ResourceUtils.kt

 object ResourceUtils {
         
     fun loadStringResource(path: String, encoding: String): String {
-        val input = ResourceUtils.javaClass.getClassLoader().sure().getResourceAsStream(path)
-        if (input == null)
+        val input = javaClass.getClassLoader()!!.getResourceAsStream(path)
+        if (input != null)
+            return input.use { it.reader(encoding).readText() }
+        else
             throw FileNotFoundException("no such file: $path")
-
-        try {
-            val reader = InputStreamReader(input, encoding)
-            val buffer = CharArray(1024)
-            val sb = StringBuilder()
-
-            while (true) {
-                val n = reader.read(buffer)
-                if (n == -1)
-                    break
-                sb.append(buffer, 0, n);
-            }
-
-            return sb.toString().sure()
-            
-        } finally {
-            input.close()
-        }
     }
 }