├── .gitignore ├── LICENSE ├── README.md └── code ├── build.clbs ├── build_debug.bat ├── build_dev.bat ├── deps ├── common │ ├── chipmunk │ │ ├── LICENSE.txt │ │ ├── VERSION.txt │ │ ├── include │ │ │ └── chipmunk │ │ │ │ ├── chipmunk.h │ │ │ │ ├── chipmunk_ffi.h │ │ │ │ ├── chipmunk_private.h │ │ │ │ ├── chipmunk_types.h │ │ │ │ ├── chipmunk_unsafe.h │ │ │ │ ├── cpArbiter.h │ │ │ │ ├── cpBB.h │ │ │ │ ├── cpBody.h │ │ │ │ ├── cpConstraint.h │ │ │ │ ├── cpDampedRotarySpring.h │ │ │ │ ├── cpDampedSpring.h │ │ │ │ ├── cpGearJoint.h │ │ │ │ ├── cpGrooveJoint.h │ │ │ │ ├── cpHastySpace.h │ │ │ │ ├── cpMarch.h │ │ │ │ ├── cpPinJoint.h │ │ │ │ ├── cpPivotJoint.h │ │ │ │ ├── cpPolyShape.h │ │ │ │ ├── cpPolyline.h │ │ │ │ ├── cpRatchetJoint.h │ │ │ │ ├── cpRobust.h │ │ │ │ ├── cpRotaryLimitJoint.h │ │ │ │ ├── cpShape.h │ │ │ │ ├── cpSimpleMotor.h │ │ │ │ ├── cpSlideJoint.h │ │ │ │ ├── cpSpace.h │ │ │ │ ├── cpSpatialIndex.h │ │ │ │ ├── cpTransform.h │ │ │ │ └── cpVect.h │ │ └── src │ │ │ ├── chipmunk.c │ │ │ ├── cpArbiter.c │ │ │ ├── cpArray.c │ │ │ ├── cpBBTree.c │ │ │ ├── cpBody.c │ │ │ ├── cpCollision.c │ │ │ ├── cpConstraint.c │ │ │ ├── cpDampedRotarySpring.c │ │ │ ├── cpDampedSpring.c │ │ │ ├── cpGearJoint.c │ │ │ ├── cpGrooveJoint.c │ │ │ ├── cpHashSet.c │ │ │ ├── cpHastySpace.c │ │ │ ├── cpMarch.c │ │ │ ├── cpPinJoint.c │ │ │ ├── cpPivotJoint.c │ │ │ ├── cpPolyShape.c │ │ │ ├── cpPolyline.c │ │ │ ├── cpRatchetJoint.c │ │ │ ├── cpRobust.c │ │ │ ├── cpRotaryLimitJoint.c │ │ │ ├── cpShape.c │ │ │ ├── cpSimpleMotor.c │ │ │ ├── cpSlideJoint.c │ │ │ ├── cpSpace.c │ │ │ ├── cpSpaceComponent.c │ │ │ ├── cpSpaceDebug.c │ │ │ ├── cpSpaceHash.c │ │ │ ├── cpSpaceQuery.c │ │ │ ├── cpSpaceStep.c │ │ │ ├── cpSpatialIndex.c │ │ │ ├── cpSweep1D.c │ │ │ └── prime.h │ ├── jsmn │ │ ├── LICENSE │ │ ├── jsmn.c │ │ └── jsmn.h │ ├── lodepng │ │ ├── lodepng.c │ │ └── lodepng.h │ ├── miniz │ │ └── miniz.c │ ├── ogg │ │ ├── AUTHORS │ │ ├── COPYING │ │ ├── VERSION │ │ ├── include │ │ │ └── ogg │ │ │ │ ├── config_types.h.in │ │ │ │ ├── ogg.h │ │ │ │ └── os_types.h │ │ └── src │ │ │ ├── bitwise.c │ │ │ └── framing.c │ ├── qc │ │ ├── ast.c │ │ ├── ast.h │ │ ├── backend_c.c │ │ ├── backend_c.h │ │ ├── config.h │ │ ├── core.c │ │ ├── core.h │ │ ├── lib_unity.c │ │ ├── parse.c │ │ ├── parse.h │ │ ├── tokenize.c │ │ └── tokenize.h │ ├── stb │ │ └── stb_truetype.h │ ├── unity.c │ └── vorbis │ │ ├── AUTHORS │ │ ├── COPYING │ │ ├── VERSION │ │ ├── include │ │ └── vorbis │ │ │ ├── codec.h │ │ │ ├── vorbisenc.h │ │ │ └── vorbisfile.h │ │ └── lib │ │ ├── analysis.c │ │ ├── backends.h │ │ ├── barkmel.c │ │ ├── bitrate.c │ │ ├── bitrate.h │ │ ├── block.c │ │ ├── books │ │ ├── coupled │ │ │ ├── res_books_51.h │ │ │ └── res_books_stereo.h │ │ ├── floor │ │ │ └── floor_books.h │ │ └── uncoupled │ │ │ └── res_books_uncoupled.h │ │ ├── codebook.c │ │ ├── codebook.h │ │ ├── codec_internal.h │ │ ├── envelope.c │ │ ├── envelope.h │ │ ├── floor0.c │ │ ├── floor1.c │ │ ├── highlevel.h │ │ ├── info.c │ │ ├── lookup.c │ │ ├── lookup.h │ │ ├── lookup_data.h │ │ ├── lpc.c │ │ ├── lpc.h │ │ ├── lsp.c │ │ ├── lsp.h │ │ ├── mapping0.c │ │ ├── masking.h │ │ ├── mdct.c │ │ ├── mdct.h │ │ ├── misc.h │ │ ├── modes │ │ ├── floor_all.h │ │ ├── psych_11.h │ │ ├── psych_16.h │ │ ├── psych_44.h │ │ ├── psych_8.h │ │ ├── residue_16.h │ │ ├── residue_44.h │ │ ├── residue_44p51.h │ │ ├── residue_44u.h │ │ ├── residue_8.h │ │ ├── setup_11.h │ │ ├── setup_16.h │ │ ├── setup_22.h │ │ ├── setup_32.h │ │ ├── setup_44.h │ │ ├── setup_44p51.h │ │ ├── setup_44u.h │ │ ├── setup_8.h │ │ └── setup_X.h │ │ ├── os.h │ │ ├── psy.c │ │ ├── psy.h │ │ ├── registry.c │ │ ├── registry.h │ │ ├── res0.c │ │ ├── scales.h │ │ ├── sharedbook.c │ │ ├── smallft.c │ │ ├── smallft.h │ │ ├── synthesis.c │ │ ├── tone.c │ │ ├── vorbisenc.c │ │ ├── vorbisfile.c │ │ ├── window.c │ │ └── window.h └── win │ └── portaudio-19 │ ├── LICENSE.txt │ ├── include │ ├── pa_asio.h │ ├── pa_jack.h │ ├── pa_linux_alsa.h │ ├── pa_mac_core.h │ ├── pa_win_ds.h │ ├── pa_win_wasapi.h │ ├── pa_win_waveformat.h │ ├── pa_win_wdmks.h │ ├── pa_win_wmme.h │ └── portaudio.h │ └── src │ ├── common │ ├── pa_allocation.c │ ├── pa_allocation.h │ ├── pa_converters.c │ ├── pa_converters.h │ ├── pa_cpuload.c │ ├── pa_cpuload.h │ ├── pa_debugprint.c │ ├── pa_debugprint.h │ ├── pa_dither.c │ ├── pa_dither.h │ ├── pa_endianness.h │ ├── pa_front.c │ ├── pa_hostapi.h │ ├── pa_memorybarrier.h │ ├── pa_process.c │ ├── pa_process.h │ ├── pa_ringbuffer.c │ ├── pa_ringbuffer.h │ ├── pa_stream.c │ ├── pa_stream.h │ ├── pa_trace.c │ ├── pa_trace.h │ ├── pa_types.h │ └── pa_util.h │ ├── hostapi │ ├── alsa │ │ └── pa_linux_alsa.c │ ├── asihpi │ │ └── pa_linux_asihpi.c │ ├── asio │ │ ├── iasiothiscallresolver.cpp │ │ ├── iasiothiscallresolver.h │ │ └── pa_asio.cpp │ ├── coreaudio │ │ ├── pa_mac_core.c │ │ ├── pa_mac_core_blocking.c │ │ ├── pa_mac_core_blocking.h │ │ ├── pa_mac_core_internal.h │ │ ├── pa_mac_core_old.c │ │ ├── pa_mac_core_utilities.c │ │ └── pa_mac_core_utilities.h │ ├── dsound │ │ ├── pa_win_ds.c │ │ ├── pa_win_ds_dynlink.c │ │ └── pa_win_ds_dynlink.h │ ├── jack │ │ └── pa_jack.c │ ├── oss │ │ ├── pa_unix_oss.c │ │ └── recplay.c │ ├── skeleton │ │ └── pa_hostapi_skeleton.c │ ├── wasapi │ │ ├── mingw-include │ │ │ ├── AudioSessionTypes.h │ │ │ ├── FunctionDiscoveryKeys_devpkey.h │ │ │ ├── audioclient.h │ │ │ ├── devicetopology.h │ │ │ ├── endpointvolume.h │ │ │ ├── functiondiscoverykeys.h │ │ │ ├── ks.h │ │ │ ├── ksguid.h │ │ │ ├── ksmedia.h │ │ │ ├── ksproxy.h │ │ │ ├── ksuuids.h │ │ │ ├── mmdeviceapi.h │ │ │ ├── propidl.h │ │ │ ├── propkey.h │ │ │ ├── propkeydef.h │ │ │ ├── propsys.h │ │ │ ├── rpcsal.h │ │ │ ├── sal.h │ │ │ ├── sdkddkver.h │ │ │ ├── shtypes.h │ │ │ └── structuredquery.h │ │ └── pa_win_wasapi.c │ ├── wdmks │ │ └── pa_win_wdmks.c │ └── wmme │ │ └── pa_win_wmme.c │ └── os │ ├── unix │ ├── pa_unix_hostapis.c │ ├── pa_unix_util.c │ └── pa_unix_util.h │ └── win │ ├── pa_win_coinitialize.c │ ├── pa_win_coinitialize.h │ ├── pa_win_hostapis.c │ ├── pa_win_util.c │ ├── pa_win_waveformat.c │ ├── pa_win_wdmks_utils.c │ └── pa_win_wdmks_utils.h ├── source ├── animation │ ├── armature.c │ ├── armature.h │ ├── clip.c │ ├── clip.h │ ├── clipinst.c │ ├── clipinst.h │ ├── joint.c │ └── joint.h ├── audio │ ├── audiosystem.c │ ├── audiosystem.h │ ├── sound.c │ └── sound.h ├── build.h ├── clover │ ├── clover.c │ ├── dirtbug.c │ ├── playerch.c │ ├── playerch.h │ ├── slidedoor.c │ ├── slidedoor.h │ └── unity.c ├── core │ ├── archive.c │ ├── archive.h │ ├── array.c │ ├── array.h │ ├── assert.h │ ├── basic.c │ ├── basic.h │ ├── color.h │ ├── cson.c │ ├── cson.h │ ├── debug.c │ ├── debug.h │ ├── device.c │ ├── device.h │ ├── dll.h │ ├── gl.c │ ├── gl.h │ ├── grid.c │ ├── grid.h │ ├── hash.h │ ├── hashtable.c │ ├── hashtable.h │ ├── linux.c │ ├── math.c │ ├── math.h │ ├── memory.c │ ├── memory.h │ ├── random.h │ ├── socket.c │ ├── socket.h │ ├── sparsetable.c │ ├── sparsetable.h │ ├── udp.c │ ├── udp.h │ └── windows.c ├── editor │ ├── editor.c │ ├── editor.h │ ├── editor_util.c │ └── editor_util.h ├── game │ ├── aitest.c │ ├── aitest.h │ ├── game.c │ ├── game.h │ ├── net.c │ ├── net.h │ ├── nodegroupdef.c │ ├── nodegroupdef.h │ ├── nodetype.c │ ├── nodetype.h │ ├── world.c │ ├── world.h │ ├── worldgen.c │ └── worldgen.h ├── global │ ├── cfg.h │ ├── env.c │ ├── env.h │ ├── module.c │ ├── module.h │ ├── rtti.c │ ├── rtti.h │ └── symbol.h ├── main.c ├── physics │ ├── chipmunk_util.h │ ├── physgrid.c │ ├── physgrid.h │ ├── physmat.c │ ├── physmat.h │ ├── physworld.c │ ├── physworld.h │ ├── query.c │ ├── query.h │ ├── rigidbody.c │ ├── rigidbody.h │ ├── rigidbodydef.c │ ├── rigidbodydef.h │ └── shapes.h ├── resources │ ├── resblob.c │ ├── resblob.h │ ├── resource.c │ ├── resource.h │ └── resources.def ├── rts │ ├── grid.c │ ├── grid.h │ ├── minion.c │ ├── minion.h │ ├── net.c │ ├── net.h │ ├── rts.c │ ├── rts.h │ └── unity.c ├── ui │ ├── gen_layout.c │ ├── gui.c │ ├── gui.h │ ├── uicontext.c │ └── uicontext.h ├── unity.c └── visual │ ├── atlas.h │ ├── compdef.c │ ├── compdef.h │ ├── compentity.c │ ├── compentity.h │ ├── ddraw.c │ ├── ddraw.h │ ├── font.c │ ├── font.h │ ├── mesh.c │ ├── mesh.h │ ├── model.c │ ├── model.h │ ├── modelentity.c │ ├── modelentity.h │ ├── renderer.c │ ├── renderer.h │ ├── shadersource.c │ ├── shadersource.h │ ├── texture.c │ ├── texture.h │ ├── vao.c │ └── vao.h └── tools └── codegen ├── main.c ├── sparse ├── .gitignore ├── FAQ ├── LICENSE ├── Makefile ├── README ├── allocate.c ├── allocate.h ├── ast-inspect.h ├── ast-model.h ├── ast-view.h ├── bitmap.h ├── cgcc.1 ├── char.c ├── char.h ├── compat-bsd.c ├── compat-cygwin.c ├── compat-linux.c ├── compat-mingw.c ├── compat-solaris.c ├── compat.h ├── compat │ ├── mmap-blob.c │ └── strtold.c ├── compile-i386.c ├── compile.h ├── cse.c ├── dissect.c ├── dissect.h ├── evaluate.c ├── expand.c ├── expression.c ├── expression.h ├── flow.c ├── flow.h ├── gdbhelpers ├── ident-list.h ├── inline.c ├── lib.c ├── lib.h ├── linearize.c ├── linearize.h ├── liveness.c ├── memops.c ├── parse.c ├── parse.dtd ├── parse.h ├── pre-process.c ├── ptrlist.c ├── ptrlist.h ├── scope.c ├── scope.h ├── show-parse.c ├── simplify.c ├── sort.c ├── sparse.1 ├── sparse.pc.in ├── storage.c ├── storage.h ├── symbol.c ├── symbol.h ├── target.c ├── target.h ├── token.h ├── tokenize.c ├── unssa.c └── version.h └── unity.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | builds/ 31 | code/codegen 32 | code/obj 33 | 34 | # Temps 35 | *~ 36 | *.swp 37 | *.fuse* 38 | *.cache 39 | .* 40 | 41 | # Resources 42 | resources 43 | 44 | # Generated 45 | gen_rtti.c 46 | 47 | # Other 48 | copy_gui_to_alive.bat 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Tuukka Pensala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # revolc 2 | Rewrite of the clover engine. The name has a symbolic meaning, as now everything is done the opposite compared to the original engine, i.e. the right way, not the wrong way. 3 | 4 | This will be written in C99 instead of C++. I've tried to write my reasoning for this choice in a non-ranting manner on my website: http://crafn.kapsi.fi/new_engine.html 5 | 6 | Here are some older posts, in which I complain about mistakes I made with the old engine: 7 | 8 | http://crafn.kapsi.fi/clover_engine_mistakes.html 9 | http://crafn.kapsi.fi/pain_in_game_development.html 10 | -------------------------------------------------------------------------------- /code/build_debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | clbs debug -j8 -v 3 | pause>nul -------------------------------------------------------------------------------- /code/build_dev.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | clbs dev -j8 3 | pause>nul -------------------------------------------------------------------------------- /code/deps/common/chipmunk/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2013 Scott Lembcke and Howling Moon Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpGearJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpGearJoint cpGearJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a damped rotary springs. 26 | cpBool cpConstraintIsGearJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a gear joint. 29 | cpGearJoint* cpGearJointAlloc(void); 30 | /// Initialize a gear joint. 31 | cpGearJoint* cpGearJointInit(cpGearJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio); 32 | /// Allocate and initialize a gear joint. 33 | cpConstraint* cpGearJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio); 34 | 35 | /// Get the phase offset of the gears. 36 | cpFloat cpGearJointGetPhase(const cpConstraint *constraint); 37 | /// Set the phase offset of the gears. 38 | void cpGearJointSetPhase(cpConstraint *constraint, cpFloat phase); 39 | 40 | /// Get the angular distance of each ratchet. 41 | cpFloat cpGearJointGetRatio(const cpConstraint *constraint); 42 | /// Set the ratio of a gear joint. 43 | void cpGearJointSetRatio(cpConstraint *constraint, cpFloat ratio); 44 | 45 | /// @} 46 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpGrooveJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpGrooveJoint cpGrooveJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a slide joint. 26 | cpBool cpConstraintIsGrooveJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a groove joint. 29 | cpGrooveJoint* cpGrooveJointAlloc(void); 30 | /// Initialize a groove joint. 31 | cpGrooveJoint* cpGrooveJointInit(cpGrooveJoint *joint, cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchorB); 32 | /// Allocate and initialize a groove joint. 33 | cpConstraint* cpGrooveJointNew(cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchorB); 34 | 35 | /// Get the first endpoint of the groove relative to the first body. 36 | cpVect cpGrooveJointGetGrooveA(const cpConstraint *constraint); 37 | /// Set the first endpoint of the groove relative to the first body. 38 | void cpGrooveJointSetGrooveA(cpConstraint *constraint, cpVect grooveA); 39 | 40 | /// Get the first endpoint of the groove relative to the first body. 41 | cpVect cpGrooveJointGetGrooveB(const cpConstraint *constraint); 42 | /// Set the first endpoint of the groove relative to the first body. 43 | void cpGrooveJointSetGrooveB(cpConstraint *constraint, cpVect grooveB); 44 | 45 | /// Get the location of the second anchor relative to the second body. 46 | cpVect cpGrooveJointGetAnchorB(const cpConstraint *constraint); 47 | /// Set the location of the second anchor relative to the second body. 48 | void cpGrooveJointSetAnchorB(cpConstraint *constraint, cpVect anchorB); 49 | 50 | /// @} 51 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpHastySpace.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Howling Moon Software. All rights reserved. 2 | // See http://chipmunk2d.net/legal.php for more information. 3 | 4 | /// cpHastySpace is exclusive to Chipmunk Pro 5 | /// Currently it enables ARM NEON optimizations in the solver, but in the future will include other optimizations such as 6 | /// a multi-threaded solver and multi-threaded collision broadphases. 7 | 8 | struct cpHastySpace; 9 | typedef struct cpHastySpace cpHastySpace; 10 | 11 | /// Create a new hasty space. 12 | /// On ARM platforms that support NEON, this will enable the vectorized solver. 13 | /// cpHastySpace also supports multiple threads, but runs single threaded by default for determinism. 14 | cpSpace *cpHastySpaceNew(void); 15 | void cpHastySpaceFree(cpSpace *space); 16 | 17 | /// Set the number of threads to use for the solver. 18 | /// Currently Chipmunk is limited to 2 threads as using more generally provides very minimal performance gains. 19 | /// Passing 0 as the thread count on iOS or OS X will cause Chipmunk to automatically detect the number of threads it should use. 20 | /// On other platforms passing 0 for the thread count will set 1 thread. 21 | void cpHastySpaceSetThreads(cpSpace *space, unsigned long threads); 22 | 23 | /// Returns the number of threads the solver is using to run. 24 | unsigned long cpHastySpaceGetThreads(cpSpace *space); 25 | 26 | /// When stepping a hasty space, you must use this function. 27 | void cpHastySpaceStep(cpSpace *space, cpFloat dt); 28 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpMarch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Howling Moon Software. All rights reserved. 2 | // See http://chipmunk2d.net/legal.php for more information. 3 | 4 | /// Function type used as a callback from the marching squares algorithm to sample an image function. 5 | /// It passes you the point to sample and your context pointer, and you return the density. 6 | typedef cpFloat (*cpMarchSampleFunc)(cpVect point, void *data); 7 | 8 | /// Function type used as a callback from the marching squares algorithm to output a line segment. 9 | /// It passes you the two endpoints and your context pointer. 10 | typedef void (*cpMarchSegmentFunc)(cpVect v0, cpVect v1, void *data); 11 | 12 | /// Trace an anti-aliased contour of an image along a particular threshold. 13 | /// The given number of samples will be taken and spread across the bounding box area using the sampling function and context. 14 | /// The segment function will be called for each segment detected that lies along the density contour for @c threshold. 15 | void cpMarchSoft( 16 | cpBB bb, unsigned long x_samples, unsigned long y_samples, cpFloat threshold, 17 | cpMarchSegmentFunc segment, void *segment_data, 18 | cpMarchSampleFunc sample, void *sample_data 19 | ); 20 | 21 | /// Trace an aliased curve of an image along a particular threshold. 22 | /// The given number of samples will be taken and spread across the bounding box area using the sampling function and context. 23 | /// The segment function will be called for each segment detected that lies along the density contour for @c threshold. 24 | void cpMarchHard( 25 | cpBB bb, unsigned long x_samples, unsigned long y_samples, cpFloat threshold, 26 | cpMarchSegmentFunc segment, void *segment_data, 27 | cpMarchSampleFunc sample, void *sample_data 28 | ); 29 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpPinJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpPinJoint cpPinJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a pin joint. 26 | cpBool cpConstraintIsPinJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a pin joint. 29 | cpPinJoint* cpPinJointAlloc(void); 30 | /// Initialize a pin joint. 31 | cpPinJoint* cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB); 32 | /// Allocate and initialize a pin joint. 33 | cpConstraint* cpPinJointNew(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB); 34 | 35 | /// Get the location of the first anchor relative to the first body. 36 | cpVect cpPinJointGetAnchorA(const cpConstraint *constraint); 37 | /// Set the location of the first anchor relative to the first body. 38 | void cpPinJointSetAnchorA(cpConstraint *constraint, cpVect anchorA); 39 | 40 | /// Get the location of the second anchor relative to the second body. 41 | cpVect cpPinJointGetAnchorB(const cpConstraint *constraint); 42 | /// Set the location of the second anchor relative to the second body. 43 | void cpPinJointSetAnchorB(cpConstraint *constraint, cpVect anchorB); 44 | 45 | /// Get the distance the joint will maintain between the two anchors. 46 | cpFloat cpPinJointGetDist(const cpConstraint *constraint); 47 | /// Set the distance the joint will maintain between the two anchors. 48 | void cpPinJointSetDist(cpConstraint *constraint, cpFloat dist); 49 | 50 | ///@} 51 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpPivotJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpPivotJoint cpPivotJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a slide joint. 26 | cpBool cpConstraintIsPivotJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a pivot joint 29 | cpPivotJoint* cpPivotJointAlloc(void); 30 | /// Initialize a pivot joint. 31 | cpPivotJoint* cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB); 32 | /// Allocate and initialize a pivot joint. 33 | cpConstraint* cpPivotJointNew(cpBody *a, cpBody *b, cpVect pivot); 34 | /// Allocate and initialize a pivot joint with specific anchors. 35 | cpConstraint* cpPivotJointNew2(cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB); 36 | 37 | /// Get the location of the first anchor relative to the first body. 38 | cpVect cpPivotJointGetAnchorA(const cpConstraint *constraint); 39 | /// Set the location of the first anchor relative to the first body. 40 | void cpPivotJointSetAnchorA(cpConstraint *constraint, cpVect anchorA); 41 | 42 | /// Get the location of the second anchor relative to the second body. 43 | cpVect cpPivotJointGetAnchorB(const cpConstraint *constraint); 44 | /// Set the location of the second anchor relative to the second body. 45 | void cpPivotJointSetAnchorB(cpConstraint *constraint, cpVect anchorB); 46 | 47 | /// @} 48 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpRatchetJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpRatchetJoint cpRatchetJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a damped rotary springs. 26 | cpBool cpConstraintIsRatchetJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a ratchet joint. 29 | cpRatchetJoint* cpRatchetJointAlloc(void); 30 | /// Initialize a ratched joint. 31 | cpRatchetJoint* cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet); 32 | /// Allocate and initialize a ratchet joint. 33 | cpConstraint* cpRatchetJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet); 34 | 35 | /// Get the angle of the current ratchet tooth. 36 | cpFloat cpRatchetJointGetAngle(const cpConstraint *constraint); 37 | /// Set the angle of the current ratchet tooth. 38 | void cpRatchetJointSetAngle(cpConstraint *constraint, cpFloat angle); 39 | 40 | /// Get the phase offset of the ratchet. 41 | cpFloat cpRatchetJointGetPhase(const cpConstraint *constraint); 42 | /// Get the phase offset of the ratchet. 43 | void cpRatchetJointSetPhase(cpConstraint *constraint, cpFloat phase); 44 | 45 | /// Get the angular distance of each ratchet. 46 | cpFloat cpRatchetJointGetRatchet(const cpConstraint *constraint); 47 | /// Set the angular distance of each ratchet. 48 | void cpRatchetJointSetRatchet(cpConstraint *constraint, cpFloat ratchet); 49 | 50 | /// @} 51 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpRobust.h: -------------------------------------------------------------------------------- 1 | #include "chipmunk/cpVect.h" 2 | 3 | // This is a private header for functions (currently just one) that need strict floating point results. 4 | // It was easier to put this in it's own file than to fiddle with 4 different compiler specific pragmas or attributes. 5 | // "Fast math" should be disabled here. 6 | 7 | // Check that the signed area of the triangle a, b, c is positive. 8 | // Compiler optimizations for associativity break certain edge cases (ex: when a or b equals c) that lead to excessive EPA iteration. 9 | cpBool cpCheckSignedArea(const cpVect a, const cpVect b, const cpVect c); 10 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpRotaryLimitJoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpRotaryLimitJoint cpRotaryLimitJoint 23 | /// @{ 24 | 25 | /// Check if a constraint is a damped rotary springs. 26 | cpBool cpConstraintIsRotaryLimitJoint(const cpConstraint *constraint); 27 | 28 | /// Allocate a damped rotary limit joint. 29 | cpRotaryLimitJoint* cpRotaryLimitJointAlloc(void); 30 | /// Initialize a damped rotary limit joint. 31 | cpRotaryLimitJoint* cpRotaryLimitJointInit(cpRotaryLimitJoint *joint, cpBody *a, cpBody *b, cpFloat min, cpFloat max); 32 | /// Allocate and initialize a damped rotary limit joint. 33 | cpConstraint* cpRotaryLimitJointNew(cpBody *a, cpBody *b, cpFloat min, cpFloat max); 34 | 35 | /// Get the minimum distance the joint will maintain between the two anchors. 36 | cpFloat cpRotaryLimitJointGetMin(const cpConstraint *constraint); 37 | /// Set the minimum distance the joint will maintain between the two anchors. 38 | void cpRotaryLimitJointSetMin(cpConstraint *constraint, cpFloat min); 39 | 40 | /// Get the maximum distance the joint will maintain between the two anchors. 41 | cpFloat cpRotaryLimitJointGetMax(const cpConstraint *constraint); 42 | /// Set the maximum distance the joint will maintain between the two anchors. 43 | void cpRotaryLimitJointSetMax(cpConstraint *constraint, cpFloat max); 44 | 45 | /// @} 46 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/include/chipmunk/cpSimpleMotor.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | /// @defgroup cpSimpleMotor cpSimpleMotor 23 | /// @{ 24 | 25 | /// Opaque struct type for damped rotary springs. 26 | typedef struct cpSimpleMotor cpSimpleMotor; 27 | 28 | /// Check if a constraint is a damped rotary springs. 29 | cpBool cpConstraintIsSimpleMotor(const cpConstraint *constraint); 30 | 31 | /// Allocate a simple motor. 32 | cpSimpleMotor* cpSimpleMotorAlloc(void); 33 | /// initialize a simple motor. 34 | cpSimpleMotor* cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate); 35 | /// Allocate and initialize a simple motor. 36 | cpConstraint* cpSimpleMotorNew(cpBody *a, cpBody *b, cpFloat rate); 37 | 38 | /// Get the rate of the motor. 39 | cpFloat cpSimpleMotorGetRate(const cpConstraint *constraint); 40 | /// Set the rate of the motor. 41 | void cpSimpleMotorSetRate(cpConstraint *constraint, cpFloat rate); 42 | 43 | /// @} 44 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/src/cpRobust.c: -------------------------------------------------------------------------------- 1 | #include "chipmunk/cpRobust.h" 2 | 3 | 4 | cpBool 5 | cpCheckSignedArea(const cpVect a, const cpVect b, const cpVect c) 6 | { 7 | const cpVect v0 = cpvsub(b, a); 8 | const cpVect v1 = cpvadd(cpvsub(c, a), cpvsub(c, b)); 9 | return (v0.x*v1.y) > (v1.x*v0.y); 10 | } 11 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/src/cpSpatialIndex.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #include "chipmunk/chipmunk_private.h" 23 | 24 | void 25 | cpSpatialIndexFree(cpSpatialIndex *index) 26 | { 27 | if(index){ 28 | cpSpatialIndexDestroy(index); 29 | cpfree(index); 30 | } 31 | } 32 | 33 | cpSpatialIndex * 34 | cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *klass, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex) 35 | { 36 | index->klass = klass; 37 | index->bbfunc = bbfunc; 38 | index->staticIndex = staticIndex; 39 | 40 | if(staticIndex){ 41 | cpAssertHard(!staticIndex->dynamicIndex, "This static index is already associated with a dynamic index."); 42 | staticIndex->dynamicIndex = index; 43 | } 44 | 45 | return index; 46 | } 47 | 48 | typedef struct dynamicToStaticContext { 49 | cpSpatialIndexBBFunc bbfunc; 50 | cpSpatialIndex *staticIndex; 51 | cpSpatialIndexQueryFunc queryFunc; 52 | void *data; 53 | } dynamicToStaticContext; 54 | 55 | static void 56 | dynamicToStaticIter(void *obj, dynamicToStaticContext *context) 57 | { 58 | cpSpatialIndexQuery(context->staticIndex, obj, context->bbfunc(obj), context->queryFunc, context->data); 59 | } 60 | 61 | void 62 | cpSpatialIndexCollideStatic(cpSpatialIndex *dynamicIndex, cpSpatialIndex *staticIndex, cpSpatialIndexQueryFunc func, void *data) 63 | { 64 | if(staticIndex && cpSpatialIndexCount(staticIndex) > 0){ 65 | dynamicToStaticContext context = {dynamicIndex->bbfunc, staticIndex, func, data}; 66 | cpSpatialIndexEach(dynamicIndex, (cpSpatialIndexIteratorFunc)dynamicToStaticIter, &context); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /code/deps/common/chipmunk/src/prime.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #ifndef CHIPMUNK_PRIME_H 23 | #define CHIPMUNK_PRIME_H 24 | 25 | // Used for resizing hash tables. 26 | // Values approximately double. 27 | // http://planetmath.org/encyclopedia/GoodHashTablePrimes.html 28 | static int primes[] = { 29 | 5, 30 | 13, 31 | 23, 32 | 47, 33 | 97, 34 | 193, 35 | 389, 36 | 769, 37 | 1543, 38 | 3079, 39 | 6151, 40 | 12289, 41 | 24593, 42 | 49157, 43 | 98317, 44 | 196613, 45 | 393241, 46 | 786433, 47 | 1572869, 48 | 3145739, 49 | 6291469, 50 | 12582917, 51 | 25165843, 52 | 50331653, 53 | 100663319, 54 | 201326611, 55 | 402653189, 56 | 805306457, 57 | 1610612741, 58 | 0, 59 | }; 60 | 61 | static inline int 62 | next_prime(int n) 63 | { 64 | int i = 0; 65 | while(n > primes[i]){ 66 | i++; 67 | cpAssertHard(primes[i], "Tried to resize a hash table to a size greater than 1610612741 O_o"); // realistically this should never happen 68 | } 69 | 70 | return primes[i]; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /code/deps/common/jsmn/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Serge A. Zaitsev 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /code/deps/common/jsmn/jsmn.h: -------------------------------------------------------------------------------- 1 | #ifndef __JSMN_H_ 2 | #define __JSMN_H_ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** 11 | * JSON type identifier. Basic types are: 12 | * o Object 13 | * o Array 14 | * o String 15 | * o Other primitive: number, boolean (true/false) or null 16 | */ 17 | typedef enum { 18 | JSMN_PRIMITIVE = 0, 19 | JSMN_OBJECT = 1, 20 | JSMN_ARRAY = 2, 21 | JSMN_STRING = 3 22 | } jsmntype_t; 23 | 24 | typedef enum { 25 | /* Not enough tokens were provided */ 26 | JSMN_ERROR_NOMEM = -1, 27 | /* Invalid character inside JSON string */ 28 | JSMN_ERROR_INVAL = -2, 29 | /* The string is not a full JSON packet, more bytes expected */ 30 | JSMN_ERROR_PART = -3 31 | } jsmnerr_t; 32 | 33 | /** 34 | * JSON token description. 35 | * @param type type (object, array, string etc.) 36 | * @param start start position in JSON data string 37 | * @param end end position in JSON data string 38 | */ 39 | typedef struct { 40 | jsmntype_t type; 41 | int start; 42 | int end; 43 | int size; // Number of fields 44 | int deep_size; // Recursive number of fields 45 | #ifdef JSMN_PARENT_LINKS 46 | int parent; 47 | #endif 48 | } jsmntok_t; 49 | 50 | /** 51 | * JSON parser. Contains an array of token blocks available. Also stores 52 | * the string being parsed now and current position in that string 53 | */ 54 | typedef struct { 55 | unsigned int pos; /* offset in the JSON string */ 56 | unsigned int toknext; /* next token to allocate */ 57 | int toksuper; /* superior token node, e.g parent object or array */ 58 | } jsmn_parser; 59 | 60 | /** 61 | * Create JSON parser over an array of tokens 62 | */ 63 | void jsmn_init(jsmn_parser *parser); 64 | 65 | /** 66 | * Run JSON parser. It parses a JSON data string into and array of tokens, each describing 67 | * a single JSON object. 68 | */ 69 | jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 70 | jsmntok_t *tokens, unsigned int num_tokens); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* __JSMN_H_ */ 77 | -------------------------------------------------------------------------------- /code/deps/common/ogg/AUTHORS: -------------------------------------------------------------------------------- 1 | Monty 2 | Greg Maxwell 3 | Ralph Giles 4 | Cristian Adam 5 | Tim Terriberry 6 | 7 | and the rest of the Xiph.Org Foundation. 8 | -------------------------------------------------------------------------------- /code/deps/common/ogg/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002, Xiph.org Foundation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of the Xiph.org Foundation nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /code/deps/common/ogg/VERSION: -------------------------------------------------------------------------------- 1 | 1.3.2 2 | -------------------------------------------------------------------------------- /code/deps/common/ogg/include/ogg/config_types.h.in: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_TYPES_H__ 2 | #define __CONFIG_TYPES_H__ 3 | 4 | /* these are filled in by configure */ 5 | #define INCLUDE_INTTYPES_H @INCLUDE_INTTYPES_H@ 6 | #define INCLUDE_STDINT_H @INCLUDE_STDINT_H@ 7 | #define INCLUDE_SYS_TYPES_H @INCLUDE_SYS_TYPES_H@ 8 | 9 | #if INCLUDE_INTTYPES_H 10 | # include 11 | #endif 12 | #if INCLUDE_STDINT_H 13 | # include 14 | #endif 15 | #if INCLUDE_SYS_TYPES_H 16 | # include 17 | #endif 18 | 19 | typedef @SIZE16@ ogg_int16_t; 20 | typedef @USIZE16@ ogg_uint16_t; 21 | typedef @SIZE32@ ogg_int32_t; 22 | typedef @USIZE32@ ogg_uint32_t; 23 | typedef @SIZE64@ ogg_int64_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /code/deps/common/qc/ast.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crafn/revolc/2c9cf78941bebf8d3f5d4664cd5ac06462bfe3eb/code/deps/common/qc/ast.c -------------------------------------------------------------------------------- /code/deps/common/qc/backend_c.h: -------------------------------------------------------------------------------- 1 | #ifndef QC_BACKEND_C_H 2 | #define QC_BACKEND_C_H 3 | 4 | #include "config.h" 5 | #include "core.h" 6 | #include "parse.h" 7 | 8 | QC_API QC_AST_Var_Decl *qc_is_device_field_member_decl(QC_AST_Type_Decl *field_decl); 9 | 10 | /* Utils for other c-like backends */ 11 | QC_API void qc_lift_var_decls(QC_AST_Scope *root); 12 | QC_API void qc_parallel_loops_to_ordinary(QC_AST_Scope *root); 13 | QC_API void qc_lift_types_and_funcs_to_global_scope(QC_AST_Scope *root); 14 | QC_API void qc_add_builtin_c_decls_to_global_scope(QC_AST_Scope *root, QC_Bool cpu_device_impl); 15 | QC_API void qc_apply_c_operator_overloading(QC_AST_Scope *root, QC_Bool convert_mat_expr); 16 | /* Type name for builtin type */ 17 | QC_API void qc_append_builtin_type_c_str(QC_Array(char) *buf, QC_Builtin_Type bt); 18 | /* Function name for expression */ 19 | QC_API void qc_append_expr_c_func_name(QC_Array(char) *buf, QC_AST_Node *expr); 20 | QC_API void qc_append_c_stdlib_includes(QC_Array(char) *buf); 21 | 22 | QC_API QC_Bool qc_ast_to_c_str(QC_Array(char) *buf, int indent, QC_AST_Node *node); 23 | 24 | /* @todo Flag determining C99 or C89 */ 25 | QC_API QC_Array(char) qc_gen_c_code(QC_AST_Scope *root); 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /code/deps/common/qc/config.h: -------------------------------------------------------------------------------- 1 | #ifndef QC_CONFIG_H 2 | #define QC_CONFIG_H 3 | 4 | /* Default library settings */ 5 | 6 | #ifndef QC_MALLOC 7 | # define QC_MALLOC malloc 8 | #endif 9 | 10 | #ifndef QC_FREE 11 | # define QC_FREE free 12 | #endif 13 | 14 | #ifndef QC_API 15 | # define QC_API 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /code/deps/common/qc/core.c: -------------------------------------------------------------------------------- 1 | #include "core.h" 2 | 3 | QC_DEFINE_ARRAY(char) 4 | QC_DEFINE_ARRAY(int) 5 | 6 | void *qc_nonull_impl(void *ptr) 7 | { 8 | if (!ptr) 9 | abort(); 10 | return ptr; 11 | } 12 | 13 | QC_Bool qc_buf_str_equals(QC_Buf_Str a, QC_Buf_Str b) 14 | { 15 | if (a.len != b.len) 16 | return QC_false; 17 | return !strncmp(a.buf, b.buf, a.len); 18 | } 19 | 20 | QC_Buf_Str qc_c_str_to_buf_str(const char* str) 21 | { 22 | QC_Buf_Str b = {0}; 23 | b.buf = str; 24 | b.len = strlen(str); 25 | return b; 26 | } 27 | 28 | void qc_safe_vsprintf(QC_Array(char) *buf, const char *fmt, va_list args) 29 | { 30 | char tmp[1024*100]; /* :( */ 31 | int len; 32 | int i; 33 | 34 | /* @todo Find open source non-gpl snprintf */ 35 | len = vsprintf(tmp, fmt, args); 36 | if (len < 0) 37 | return; 38 | if (len > (int)sizeof(tmp)/2) /* Crappy failsafe */ 39 | abort(); 40 | 41 | if (buf->size > 0 && buf->data[buf->size - 1] == '\0') 42 | qc_pop_array(char)(buf); 43 | 44 | for (i = 0; i < len; ++i) 45 | qc_push_array(char)(buf, tmp[i]); 46 | qc_push_array(char)(buf, '\0'); 47 | } 48 | 49 | void qc_append_str(QC_Array(char) *buf, const char *fmt, ...) 50 | { 51 | va_list args; 52 | va_start(args, fmt); 53 | qc_safe_vsprintf(buf, fmt, args); 54 | va_end(args); 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /code/deps/common/qc/lib_unity.c: -------------------------------------------------------------------------------- 1 | /* 2 | Include this file wherever you want the implementation of the library to be. 3 | Define wanted output backends (QC_BACKEND_* macros) before including. 4 | */ 5 | 6 | #include "ast.c" 7 | 8 | #if defined(QC_BACKEND_C) || defined(QC_BACKEND_CUDA) 9 | # include "backend_c.c" 10 | #endif 11 | 12 | #if defined(QC_BACKEND_CUDA) 13 | # include "backend_cuda.c" 14 | #endif 15 | 16 | #include "core.c" 17 | #include "parse.c" 18 | #include "tokenize.c" 19 | -------------------------------------------------------------------------------- /code/deps/common/qc/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef QC_PARSE_H 2 | #define QC_PARSE_H 3 | 4 | #include "config.h" 5 | #include "ast.h" 6 | #include "tokenize.h" 7 | 8 | /* @todo To *precedence and *associativity */ 9 | QC_API int qc_biop_prec(QC_Token_Type type); 10 | QC_API int qc_biop_assoc(QC_Token_Type type); 11 | 12 | /* dont_reference_tokens: Allowing AST to reference tokens will give e.g. line number for each node */ 13 | /* allow_undeclared: Don't mind if types/identifiers stay unresolved. Can result in wrong AST though */ 14 | /* @todo dont_reference_tokens -> self_contained (no token refs, no source refs) */ 15 | /* @todo Don't print error messages, return them */ 16 | QC_API QC_AST_Scope *qc_parse_tokens( QC_Token *toks, 17 | QC_Bool dont_reference_tokens, 18 | QC_Bool allow_undeclared); 19 | 20 | 21 | /* Convenience functions */ 22 | 23 | /* `string` can be like "foo.bar.x = 123" or a whole program. 24 | Note that parsing pieces of a program doesn't necessarily result in 25 | a full or even correct AST because C is context sensitive. */ 26 | /* Return value is the scope which contains the expr and builtin type decls */ 27 | /* expr is the expression corresponding to the string */ 28 | QC_API QC_AST_Scope *qc_parse_string(QC_AST_Node **expr, const char *string); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/AUTHORS: -------------------------------------------------------------------------------- 1 | Monty 2 | 3 | and the rest of the Xiph.org Foundation. 4 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2008 Xiph.org Foundation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | - Neither the name of the Xiph.org Foundation nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/VERSION: -------------------------------------------------------------------------------- 1 | 1.3.4 2 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/barkmel.c: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: bark scale utility 14 | last mod: $Id: barkmel.c 16037 2009-05-26 21:10:58Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #include 19 | #include "scales.h" 20 | int main(){ 21 | int i; 22 | double rate; 23 | for(i=64;i<32000;i*=2){ 24 | rate=48000.f; 25 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 26 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 27 | 28 | rate=44100.f; 29 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 30 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 31 | 32 | rate=32000.f; 33 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 34 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 35 | 36 | rate=22050.f; 37 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 38 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 39 | 40 | rate=16000.f; 41 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 42 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 43 | 44 | rate=11025.f; 45 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n", 46 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 47 | 48 | rate=8000.f; 49 | fprintf(stderr,"rate=%gHz, block=%d, f(1)=%.2gHz bark(1)=%.2g (of %.2g)\n\n", 50 | rate,i,rate/2 / (i/2),toBARK(rate/2 /(i/2)),toBARK(rate/2)); 51 | 52 | 53 | } 54 | { 55 | float i; 56 | int j; 57 | for(i=0.,j=0;i<28;i+=1,j++){ 58 | fprintf(stderr,"(%d) bark=%f %gHz (%d of 128)\n", 59 | j,i,fromBARK(i),(int)(fromBARK(i)/22050.*128.)); 60 | } 61 | } 62 | return(0); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/bitrate.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: bitrate tracking and management 14 | last mod: $Id: bitrate.h 13293 2007-07-24 00:09:47Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_BITRATE_H_ 19 | #define _V_BITRATE_H_ 20 | 21 | #include "vorbis/codec.h" 22 | #include "codec_internal.h" 23 | #include "os.h" 24 | 25 | /* encode side bitrate tracking */ 26 | typedef struct bitrate_manager_state { 27 | int managed; 28 | 29 | long avg_reservoir; 30 | long minmax_reservoir; 31 | long avg_bitsper; 32 | long min_bitsper; 33 | long max_bitsper; 34 | 35 | long short_per_long; 36 | double avgfloat; 37 | 38 | vorbis_block *vb; 39 | int choice; 40 | } bitrate_manager_state; 41 | 42 | typedef struct bitrate_manager_info{ 43 | long avg_rate; 44 | long min_rate; 45 | long max_rate; 46 | long reservoir_bits; 47 | double reservoir_bias; 48 | 49 | double slew_damp; 50 | 51 | } bitrate_manager_info; 52 | 53 | extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs); 54 | extern void vorbis_bitrate_clear(bitrate_manager_state *bs); 55 | extern int vorbis_bitrate_managed(vorbis_block *vb); 56 | extern int vorbis_bitrate_addblock(vorbis_block *vb); 57 | extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/envelope.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: PCM data envelope analysis and manipulation 14 | last mod: $Id: envelope.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_ENVELOPE_ 19 | #define _V_ENVELOPE_ 20 | 21 | #include "mdct.h" 22 | 23 | #define VE_PRE 16 24 | #define VE_WIN 4 25 | #define VE_POST 2 26 | #define VE_AMP (VE_PRE+VE_POST-1) 27 | 28 | #define VE_BANDS 7 29 | #define VE_NEARDC 15 30 | 31 | #define VE_MINSTRETCH 2 /* a bit less than short block */ 32 | #define VE_MAXSTRETCH 12 /* one-third full block */ 33 | 34 | typedef struct { 35 | float ampbuf[VE_AMP]; 36 | int ampptr; 37 | 38 | float nearDC[VE_NEARDC]; 39 | float nearDC_acc; 40 | float nearDC_partialacc; 41 | int nearptr; 42 | 43 | } envelope_filter_state; 44 | 45 | typedef struct { 46 | int begin; 47 | int end; 48 | float *window; 49 | float total; 50 | } envelope_band; 51 | 52 | typedef struct { 53 | int ch; 54 | int winlength; 55 | int searchstep; 56 | float minenergy; 57 | 58 | mdct_lookup mdct; 59 | float *mdct_win; 60 | 61 | envelope_band band[VE_BANDS]; 62 | envelope_filter_state *filter; 63 | int stretch; 64 | 65 | int *mark; 66 | 67 | long storage; 68 | long current; 69 | long curmark; 70 | long cursor; 71 | } envelope_lookup; 72 | 73 | extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi); 74 | extern void _ve_envelope_clear(envelope_lookup *e); 75 | extern long _ve_envelope_search(vorbis_dsp_state *v); 76 | extern void _ve_envelope_shift(envelope_lookup *e,long shift); 77 | extern int _ve_envelope_mark(vorbis_dsp_state *v); 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/highlevel.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: highlevel encoder setup struct separated out for vorbisenc clarity 14 | last mod: $Id: highlevel.h 17195 2010-05-05 21:49:51Z giles $ 15 | 16 | ********************************************************************/ 17 | 18 | typedef struct highlevel_byblocktype { 19 | double tone_mask_setting; 20 | double tone_peaklimit_setting; 21 | double noise_bias_setting; 22 | double noise_compand_setting; 23 | } highlevel_byblocktype; 24 | 25 | typedef struct highlevel_encode_setup { 26 | int set_in_stone; 27 | const void *setup; 28 | double base_setting; 29 | 30 | double impulse_noisetune; 31 | 32 | /* bitrate management below all settable */ 33 | float req; 34 | int managed; 35 | long bitrate_min; 36 | long bitrate_av; 37 | double bitrate_av_damp; 38 | long bitrate_max; 39 | long bitrate_reservoir; 40 | double bitrate_reservoir_bias; 41 | 42 | int impulse_block_p; 43 | int noise_normalize_p; 44 | int coupling_p; 45 | 46 | double stereo_point_setting; 47 | double lowpass_kHz; 48 | int lowpass_altered; 49 | 50 | double ath_floating_dB; 51 | double ath_absolute_dB; 52 | 53 | double amplitude_track_dBpersec; 54 | double trigger_setting; 55 | 56 | highlevel_byblocktype block[4]; /* padding, impulse, transition, long */ 57 | 58 | } highlevel_encode_setup; 59 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/lookup.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: lookup based functions 14 | last mod: $Id: lookup.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_LOOKUP_H_ 19 | 20 | #ifdef FLOAT_LOOKUP 21 | extern float vorbis_coslook(float a); 22 | extern float vorbis_invsqlook(float a); 23 | extern float vorbis_invsq2explook(int a); 24 | extern float vorbis_fromdBlook(float a); 25 | #endif 26 | #ifdef INT_LOOKUP 27 | extern long vorbis_invsqlook_i(long a,long e); 28 | extern long vorbis_coslook_i(long a); 29 | extern float vorbis_fromdBlook_i(long a); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/lpc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: LPC low level routines 14 | last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_LPC_H_ 19 | #define _V_LPC_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | /* simple linear scale LPC code */ 24 | extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m); 25 | 26 | extern void vorbis_lpc_predict(float *coeff,float *prime,int m, 27 | float *data,long n); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/lsp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: LSP (also called LSF) conversion routines 14 | last mod: $Id: lsp.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | 19 | #ifndef _V_LSP_H_ 20 | #define _V_LSP_H_ 21 | 22 | extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m); 23 | 24 | extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln, 25 | float *lsp,int m, 26 | float amp,float ampoffset); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/mdct.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: modified discrete cosine transform prototypes 14 | last mod: $Id: mdct.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _OGG_mdct_H_ 19 | #define _OGG_mdct_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | 24 | 25 | 26 | 27 | /*#define MDCT_INTEGERIZED <- be warned there could be some hurt left here*/ 28 | #ifdef MDCT_INTEGERIZED 29 | 30 | #define DATA_TYPE int 31 | #define REG_TYPE register int 32 | #define TRIGBITS 14 33 | #define cPI3_8 6270 34 | #define cPI2_8 11585 35 | #define cPI1_8 15137 36 | 37 | #define FLOAT_CONV(x) ((int)((x)*(1<>TRIGBITS) 39 | #define HALVE(x) ((x)>>1) 40 | 41 | #else 42 | 43 | #define DATA_TYPE float 44 | #define REG_TYPE float 45 | #define cPI3_8 .38268343236508977175F 46 | #define cPI2_8 .70710678118654752441F 47 | #define cPI1_8 .92387953251128675613F 48 | 49 | #define FLOAT_CONV(x) (x) 50 | #define MULT_NORM(x) (x) 51 | #define HALVE(x) ((x)*.5f) 52 | 53 | #endif 54 | 55 | 56 | typedef struct { 57 | int n; 58 | int log2n; 59 | 60 | DATA_TYPE *trig; 61 | int *bitrev; 62 | 63 | DATA_TYPE scale; 64 | } mdct_lookup; 65 | 66 | extern void mdct_init(mdct_lookup *lookup,int n); 67 | extern void mdct_clear(mdct_lookup *l); 68 | extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out); 69 | extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/misc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: miscellaneous prototypes 14 | last mod: $Id: misc.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_RANDOM_H_ 19 | #define _V_RANDOM_H_ 20 | #include "vorbis/codec.h" 21 | 22 | extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes); 23 | extern void _vorbis_block_ripcord(vorbis_block *vb); 24 | 25 | #ifdef ANALYSIS 26 | extern int analysis_noisy; 27 | extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB, 28 | ogg_int64_t off); 29 | extern void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB, 30 | ogg_int64_t off); 31 | #endif 32 | 33 | #ifdef DEBUG_MALLOC 34 | 35 | #define _VDBG_GRAPHFILE "malloc.m" 36 | #undef _VDBG_GRAPHFILE 37 | extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line); 38 | extern void _VDBG_free(void *ptr,char *file,long line); 39 | 40 | #ifndef MISC_C 41 | #undef _ogg_malloc 42 | #undef _ogg_calloc 43 | #undef _ogg_realloc 44 | #undef _ogg_free 45 | 46 | #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__) 47 | #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__) 48 | #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__) 49 | #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__) 50 | #endif 51 | #endif 52 | 53 | #endif 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/modes/psych_11.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: 11kHz settings 14 | last mod: $Id: psych_11.h 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | static const double _psy_lowpass_11[3]={4.5,5.5,30.,}; 19 | 20 | static const att3 _psy_tone_masteratt_11[3]={ 21 | {{ 30, 25, 12}, 0, 0}, /* 0 */ 22 | {{ 30, 25, 12}, 0, 0}, /* 0 */ 23 | {{ 20, 0, -14}, 0, 0}, /* 0 */ 24 | }; 25 | 26 | static const vp_adjblock _vp_tonemask_adj_11[3]={ 27 | /* adjust for mode zero */ 28 | /* 63 125 250 500 1 2 4 8 16 */ 29 | {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */ 30 | {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */ 31 | {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */ 32 | }; 33 | 34 | 35 | static const noise3 _psy_noisebias_11[3]={ 36 | /* 63 125 250 500 1k 2k 4k 8k 16k*/ 37 | {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99}, 38 | {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99}, 39 | {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}}, 40 | 41 | {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99}, 42 | {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99}, 43 | {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}}, 44 | 45 | {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99}, 46 | {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99}, 47 | {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}}, 48 | }; 49 | 50 | static const double _noise_thresh_11[3]={ .3,.5,.5 }; 51 | 52 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/modes/setup_44p51.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: toplevel settings for 44.1/48kHz 5.1 surround modes 14 | last mod: $Id: setup_44p51.h 19013 2013-11-12 04:04:50Z giles $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "modes/residue_44p51.h" 19 | 20 | static const double rate_mapping_44p51[12]={ 21 | 14000.,20000.,28000.,38000.,46000.,54000., 22 | 75000.,96000.,120000.,140000.,180000.,240001. 23 | }; 24 | 25 | static const ve_setup_data_template ve_setup_44_51={ 26 | 11, 27 | rate_mapping_44p51, 28 | quality_mapping_44, 29 | 6, 30 | 40000, 31 | 70000, 32 | 33 | blocksize_short_44, 34 | blocksize_long_44, 35 | 36 | _psy_tone_masteratt_44, 37 | _psy_tone_0dB, 38 | _psy_tone_suppress, 39 | 40 | _vp_tonemask_adj_otherblock, 41 | _vp_tonemask_adj_longblock, 42 | _vp_tonemask_adj_otherblock, 43 | 44 | _psy_noiseguards_44, 45 | _psy_noisebias_impulse, 46 | _psy_noisebias_padding, 47 | _psy_noisebias_trans, 48 | _psy_noisebias_long, 49 | _psy_noise_suppress, 50 | 51 | _psy_compand_44, 52 | _psy_compand_short_mapping, 53 | _psy_compand_long_mapping, 54 | 55 | {_noise_start_short_44,_noise_start_long_44}, 56 | {_noise_part_short_44,_noise_part_long_44}, 57 | _noise_thresh_44, 58 | 59 | _psy_ath_floater, 60 | _psy_ath_abs, 61 | 62 | _psy_lowpass_44, 63 | 64 | _psy_global_44, 65 | _global_mapping_44, 66 | _psy_stereo_modes_44, 67 | 68 | _floor_books, 69 | _floor, 70 | 3, 71 | _floor_mapping_44, 72 | 73 | _mapres_template_44_51 74 | }; 75 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/modes/setup_44u.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: toplevel settings for 44.1/48kHz uncoupled modes 14 | last mod: $Id: setup_44u.h 16962 2010-03-11 07:30:34Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "modes/residue_44u.h" 19 | 20 | static const double rate_mapping_44_un[12]={ 21 | 32000.,48000.,60000.,70000.,80000.,86000., 22 | 96000.,110000.,120000.,140000.,160000.,240001. 23 | }; 24 | 25 | static const ve_setup_data_template ve_setup_44_uncoupled={ 26 | 11, 27 | rate_mapping_44_un, 28 | quality_mapping_44, 29 | -1, 30 | 40000, 31 | 50000, 32 | 33 | blocksize_short_44, 34 | blocksize_long_44, 35 | 36 | _psy_tone_masteratt_44, 37 | _psy_tone_0dB, 38 | _psy_tone_suppress, 39 | 40 | _vp_tonemask_adj_otherblock, 41 | _vp_tonemask_adj_longblock, 42 | _vp_tonemask_adj_otherblock, 43 | 44 | _psy_noiseguards_44, 45 | _psy_noisebias_impulse, 46 | _psy_noisebias_padding, 47 | _psy_noisebias_trans, 48 | _psy_noisebias_long, 49 | _psy_noise_suppress, 50 | 51 | _psy_compand_44, 52 | _psy_compand_short_mapping, 53 | _psy_compand_long_mapping, 54 | 55 | {_noise_start_short_44,_noise_start_long_44}, 56 | {_noise_part_short_44,_noise_part_long_44}, 57 | _noise_thresh_44, 58 | 59 | _psy_ath_floater, 60 | _psy_ath_abs, 61 | 62 | _psy_lowpass_44, 63 | 64 | _psy_global_44, 65 | _global_mapping_44, 66 | _psy_stereo_modes_44, 67 | 68 | _floor_books, 69 | _floor, 70 | 2, 71 | _floor_mapping_44, 72 | 73 | _mapres_template_44_uncoupled 74 | }; 75 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/registry.c: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: registry for time, floor, res backends and channel mappings 14 | last mod: $Id: registry.c 16227 2009-07-08 06:58:46Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #include "vorbis/codec.h" 19 | #include "codec_internal.h" 20 | #include "registry.h" 21 | #include "misc.h" 22 | /* seems like major overkill now; the backend numbers will grow into 23 | the infrastructure soon enough */ 24 | 25 | extern const vorbis_func_floor floor0_exportbundle; 26 | extern const vorbis_func_floor floor1_exportbundle; 27 | extern const vorbis_func_residue residue0_exportbundle; 28 | extern const vorbis_func_residue residue1_exportbundle; 29 | extern const vorbis_func_residue residue2_exportbundle; 30 | extern const vorbis_func_mapping mapping0_exportbundle; 31 | 32 | const vorbis_func_floor *const _floor_P[]={ 33 | &floor0_exportbundle, 34 | &floor1_exportbundle, 35 | }; 36 | 37 | const vorbis_func_residue *const _residue_P[]={ 38 | &residue0_exportbundle, 39 | &residue1_exportbundle, 40 | &residue2_exportbundle, 41 | }; 42 | 43 | const vorbis_func_mapping *const _mapping_P[]={ 44 | &mapping0_exportbundle, 45 | }; 46 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/registry.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: registry for time, floor, res backends and channel mappings 14 | last mod: $Id: registry.h 15531 2008-11-24 23:50:06Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_REG_H_ 19 | #define _V_REG_H_ 20 | 21 | #define VI_TRANSFORMB 1 22 | #define VI_WINDOWB 1 23 | #define VI_TIMEB 1 24 | #define VI_FLOORB 2 25 | #define VI_RESB 3 26 | #define VI_MAPB 1 27 | 28 | extern const vorbis_func_floor *const _floor_P[]; 29 | extern const vorbis_func_residue *const _residue_P[]; 30 | extern const vorbis_func_mapping *const _mapping_P[]; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/smallft.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: fft transform 14 | last mod: $Id: smallft.h 13293 2007-07-24 00:09:47Z xiphmont $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_SMFT_H_ 19 | #define _V_SMFT_H_ 20 | 21 | #include "vorbis/codec.h" 22 | 23 | typedef struct { 24 | int n; 25 | float *trigcache; 26 | int *splitcache; 27 | } drft_lookup; 28 | 29 | extern void drft_forward(drft_lookup *l,float *data); 30 | extern void drft_backward(drft_lookup *l,float *data); 31 | extern void drft_init(drft_lookup *l,int n); 32 | extern void drft_clear(drft_lookup *l); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/tone.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void usage(){ 7 | fprintf(stderr,"tone ,[] [,[]...]\n"); 8 | exit(1); 9 | } 10 | 11 | int main (int argc,char *argv[]){ 12 | int i,j; 13 | double *f; 14 | double *amp; 15 | 16 | if(argc<2)usage(); 17 | 18 | f=alloca(sizeof(*f)*(argc-1)); 19 | amp=alloca(sizeof(*amp)*(argc-1)); 20 | 21 | i=0; 22 | while(argv[i+1]){ 23 | char *pos=strchr(argv[i+1],','); 24 | 25 | f[i]=atof(argv[i+1]); 26 | if(pos) 27 | amp[i]=atof(pos+1)*32767.f; 28 | else 29 | amp[i]=32767.f; 30 | 31 | fprintf(stderr,"%g Hz, %g amp\n",f[i],amp[i]); 32 | 33 | i++; 34 | } 35 | 36 | for(i=0;i<44100*10;i++){ 37 | float val=0; 38 | int ival; 39 | for(j=0;j32767.f)ival=32767.f; 44 | if(ival<-32768.f)ival=-32768.f; 45 | 46 | fprintf(stdout,"%c%c%c%c", 47 | (char)(ival&0xff), 48 | (char)((ival>>8)&0xff), 49 | (char)(ival&0xff), 50 | (char)((ival>>8)&0xff)); 51 | } 52 | return(0); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /code/deps/common/vorbis/lib/window.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: window functions 14 | last mod: $Id: window.h 19028 2013-12-02 23:23:39Z tterribe $ 15 | 16 | ********************************************************************/ 17 | 18 | #ifndef _V_WINDOW_ 19 | #define _V_WINDOW_ 20 | 21 | extern const float *_vorbis_window_get(int n); 22 | extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes, 23 | int lW,int W,int nW); 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /code/deps/win/portaudio-19/src/common/pa_debugprint.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crafn/revolc/2c9cf78941bebf8d3f5d4664cd5ac06462bfe3eb/code/deps/win/portaudio-19/src/common/pa_debugprint.c -------------------------------------------------------------------------------- /code/deps/win/portaudio-19/src/hostapi/wasapi/mingw-include/ksguid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. 5 | */ 6 | #define INITGUID 7 | #include 8 | 9 | #ifndef DECLSPEC_SELECTANY 10 | #define DECLSPEC_SELECTANY __declspec(selectany) 11 | #endif 12 | 13 | #ifdef DEFINE_GUIDEX 14 | #undef DEFINE_GUIDEX 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID DECLSPEC_SELECTANY name = { STATICGUIDOF(name) } 19 | #else 20 | #define DEFINE_GUIDEX(name) const CDECL GUID DECLSPEC_SELECTANY name = { STATICGUIDOF(name) } 21 | #endif 22 | #ifndef STATICGUIDOF 23 | #define STATICGUIDOF(guid) STATIC_##guid 24 | #endif 25 | 26 | #ifndef DEFINE_WAVEFORMATEX_GUID 27 | #define DEFINE_WAVEFORMATEX_GUID(x) (USHORT)(x),0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71 28 | #endif 29 | -------------------------------------------------------------------------------- /code/deps/win/portaudio-19/src/hostapi/wasapi/mingw-include/propkeydef.h: -------------------------------------------------------------------------------- 1 | #ifndef PID_FIRST_USABLE 2 | #define PID_FIRST_USABLE 2 3 | #endif 4 | 5 | #ifndef REFPROPERTYKEY 6 | #ifdef __cplusplus 7 | #define REFPROPERTYKEY const PROPERTYKEY & 8 | #else // !__cplusplus 9 | #define REFPROPERTYKEY const PROPERTYKEY * __MIDL_CONST 10 | #endif // __cplusplus 11 | #endif //REFPROPERTYKEY 12 | 13 | #ifdef DEFINE_PROPERTYKEY 14 | #undef DEFINE_PROPERTYKEY 15 | #endif 16 | 17 | #ifdef INITGUID 18 | #define DEFINE_PROPERTYKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }, pid } 19 | #else 20 | #define DEFINE_PROPERTYKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) EXTERN_C const PROPERTYKEY name 21 | #endif // INITGUID 22 | 23 | #ifndef IsEqualPropertyKey 24 | #define IsEqualPropertyKey(a, b) (((a).pid == (b).pid) && IsEqualIID((a).fmtid, (b).fmtid) ) 25 | #endif // IsEqualPropertyKey 26 | 27 | -------------------------------------------------------------------------------- /code/deps/win/portaudio-19/src/os/win/pa_win_wdmks_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef PA_WIN_WDMKS_UTILS_H 2 | #define PA_WIN_WDMKS_UTILS_H 3 | 4 | /* 5 | * PortAudio Portable Real-Time Audio Library 6 | * Windows WDM KS utilities 7 | * 8 | * Copyright (c) 1999 - 2007 Ross Bencina, Andrew Baldwin 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining 11 | * a copy of this software and associated documentation files 12 | * (the "Software"), to deal in the Software without restriction, 13 | * including without limitation the rights to use, copy, modify, merge, 14 | * publish, distribute, sublicense, and/or sell copies of the Software, 15 | * and to permit persons to whom the Software is furnished to do so, 16 | * subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be 19 | * included in all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 25 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 26 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | /* 31 | * The text above constitutes the entire PortAudio license; however, 32 | * the PortAudio community also makes the following non-binding requests: 33 | * 34 | * Any person wishing to distribute modifications to the Software is 35 | * requested to send the modifications to the original developer so that 36 | * they can be incorporated into the canonical version. It is also 37 | * requested that these non-binding requests be included along with the 38 | * license above. 39 | */ 40 | 41 | /** @file 42 | @brief Utilities for working with the Windows WDM KS API 43 | */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | Query for the maximum number of channels supported by any pin of the 51 | specified device. Returns 0 if the query fails for any reason. 52 | 53 | @param wcharDevicePath A system level PnP interface path, supplied as a WCHAR unicode string. 54 | Declard as void* to avoid introducing a dependency on wchar_t here. 55 | 56 | @param isInput A flag specifying whether to query for input (non-zero) or output (zero) channels. 57 | */ 58 | int PaWin_WDMKS_QueryFilterMaximumChannelCount( void *wcharDevicePath, int isInput ); 59 | 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif /* __cplusplus */ 64 | 65 | #endif /* PA_WIN_WDMKS_UTILS_H */ -------------------------------------------------------------------------------- /code/source/animation/armature.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_ANIMATION_ARMATURE_H 2 | #define REVOLC_ANIMATION_ARMATURE_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "global/cfg.h" 7 | #include "joint.h" 8 | #include "resources/resource.h" 9 | 10 | typedef struct Armature { 11 | Resource res; 12 | char joint_names[MAX_ARMATURE_JOINT_COUNT][RES_NAME_SIZE]; 13 | Joint joints[MAX_ARMATURE_JOINT_COUNT]; 14 | U32 joint_count; 15 | } PACKED Armature; 16 | 17 | struct WArchive; 18 | struct RArchive; 19 | 20 | REVOLC_API WARN_UNUSED 21 | Armature *blobify_armature(struct WArchive *ar, Cson c, bool *err); 22 | REVOLC_API void deblobify_armature(WCson *c, struct RArchive *ar); 23 | 24 | REVOLC_API 25 | JointId joint_id_by_name(const Armature *a, const char *name); 26 | 27 | #endif // REVOLC_ANIMATION_ARMATURE_H 28 | -------------------------------------------------------------------------------- /code/source/animation/clip.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_ANIMATION_CLIP_H 2 | #define REVOLC_ANIMATION_CLIP_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "core/basic.h" 7 | #include "joint.h" 8 | #include "resources/resource.h" 9 | 10 | typedef enum { 11 | Clip_Key_Type_none, 12 | Clip_Key_Type_scale, 13 | Clip_Key_Type_rot, 14 | Clip_Key_Type_pos, 15 | } Clip_Key_Type; 16 | 17 | typedef struct Clip_Key { 18 | char joint_name[RES_NAME_SIZE]; 19 | U8 joint_ix; // Index in clip, not in armature 20 | F64 time; 21 | 22 | Clip_Key_Type type; 23 | T3f value; 24 | } Clip_Key; 25 | 26 | typedef struct Clip { 27 | Resource res; 28 | 29 | F32 duration; // At the beginning of the last frame 30 | 31 | char armature_name[RES_NAME_SIZE]; 32 | REL_PTR(Clip_Key) keys; 33 | U32 key_count; 34 | 35 | // Clip joint index to armature joint id 36 | JointId joint_ix_to_id[MAX_ARMATURE_JOINT_COUNT]; 37 | 38 | U32 joint_count; // Can be less than armature->joint_count 39 | U32 frame_count; // Last frame is only interpolation target 40 | REL_PTR(T3f) local_samples; // joint_count*frame_count elements 41 | } PACKED Clip; 42 | 43 | struct Armature; 44 | REVOLC_API struct Armature *clip_armature(const Clip *c); 45 | REVOLC_API U32 clip_sample_count(const Clip *c); 46 | REVOLC_API T3f * clip_local_samples(const Clip *c); 47 | REVOLC_API Clip_Key * clip_keys(const Clip *c); 48 | 49 | REVOLC_API void init_clip(Clip *clip); 50 | 51 | struct WArchive; 52 | struct RArchive; 53 | 54 | REVOLC_API WARN_UNUSED Clip *blobify_clip(struct WArchive *ar, Cson c, bool *err); 55 | REVOLC_API void deblobify_clip(WCson *c, struct RArchive *ar); 56 | 57 | REVOLC_API JointPoseArray calc_clip_pose(const Clip *c, F64 t); 58 | 59 | // 60 | // These all are kind of editor functions, but there's all kinds of caching 61 | // (sorting keys, recalculating samples from keys) to be caren of so it's 62 | // maybe better that they're near Clip 63 | // 64 | 65 | // Add or update key 66 | REVOLC_API void update_rt_clip_key(Clip *c, Clip_Key key); 67 | REVOLC_API void delete_rt_clip_key(Clip *c, U32 del_i); 68 | // Copy first keys of every channel to end 69 | REVOLC_API void make_rt_clip_looping(Clip *c); 70 | // Moves keys __OF_SELECTED_JOINTS__ (<- ugly) at `from` -> `to` 71 | REVOLC_API void move_rt_clip_keys(Clip *c, F64 from, F64 to); 72 | 73 | REVOLC_API void recache_ptrs_to_clips(); 74 | 75 | #endif // REVOLC_ANIMATION_CLIP_H 76 | -------------------------------------------------------------------------------- /code/source/animation/clipinst.c: -------------------------------------------------------------------------------- 1 | #include "clipinst.h" 2 | #include "global/env.h" 3 | #include "resources/resblob.h" 4 | #include "game/world.h" 5 | 6 | void init_clipinst(ClipInst *data) 7 | { 8 | *data = (ClipInst) {}; 9 | for (U32 i = 0; i < MAX_ARMATURE_JOINT_COUNT; ++i) 10 | data->pose.tf[i] = identity_t3f(); 11 | } 12 | 13 | U32 resurrect_clipinst(ClipInst *dead) 14 | { 15 | return NULL_HANDLE; 16 | } 17 | 18 | void upd_clipinst(ClipInst *inst) 19 | { 20 | F64 dt = g_env.world->dt; 21 | // This hurts! 22 | const Clip *c = 23 | (Clip*)res_by_name(g_env.resblob, ResType_Clip, inst->clip_name); 24 | 25 | inst->t += dt; 26 | while (inst->t > c->duration) 27 | inst->t -= c->duration; 28 | 29 | inst->pose = calc_clip_pose(c, inst->t); 30 | } 31 | -------------------------------------------------------------------------------- /code/source/animation/clipinst.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_ANIMATION_CLIPINST_H 2 | #define REVOLC_ANIMATION_CLIPINST_H 3 | 4 | #include "build.h" 5 | #include "clip.h" 6 | #include "joint.h" 7 | 8 | // Animation clip being played 9 | typedef struct ClipInst { 10 | // @todo Use ResId instead 11 | char clip_name[RES_NAME_SIZE]; 12 | 13 | JointPoseArray pose; // Interpolated straight from Clip 14 | F32 t; 15 | } ClipInst; 16 | 17 | REVOLC_API 18 | void init_clipinst(ClipInst *data); 19 | 20 | // In-place resurrection 21 | REVOLC_API 22 | U32 resurrect_clipinst(ClipInst *dead); 23 | 24 | REVOLC_API 25 | void upd_clipinst(ClipInst *inst); 26 | 27 | #endif // REVOLC_ANIMATION_CLIPINST_H 28 | -------------------------------------------------------------------------------- /code/source/animation/joint.c: -------------------------------------------------------------------------------- 1 | #include "joint.h" 2 | 3 | JointPoseArray identity_pose() 4 | { 5 | JointPoseArray pose; 6 | for (U32 i = 0; i < MAX_ARMATURE_JOINT_COUNT; ++i) 7 | pose.tf[i] = identity_t3f(); 8 | return pose; 9 | } 10 | 11 | JointPoseArray lerp_pose( JointPoseArray p1, 12 | JointPoseArray p2, 13 | F64 t) 14 | { 15 | JointPoseArray p; 16 | for (U32 i = 0; i < MAX_ARMATURE_JOINT_COUNT; ++i) 17 | p.tf[i] = lerp_t3f(p1.tf[i], p2.tf[i], t); 18 | return p; 19 | } 20 | -------------------------------------------------------------------------------- /code/source/animation/joint.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_ANIMATION_JOINT_H 2 | #define REVOLC_ANIMATION_JOINT_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | #include "core/math.h" 7 | #include "resources/resource.h" 8 | 9 | typedef U8 JointId; 10 | #define NULL_JOINT_ID ((U8)-1) 11 | 12 | // Wrapper for an array of joint poses to allow assigning 13 | typedef struct JointPoseArray { 14 | T3f tf[MAX_ARMATURE_JOINT_COUNT]; 15 | } JointPoseArray; 16 | 17 | REVOLC_API JointPoseArray identity_pose(); 18 | 19 | REVOLC_API JointPoseArray lerp_pose( JointPoseArray p1, 20 | JointPoseArray p2, 21 | F64 t); 22 | 23 | typedef struct Joint { 24 | JointId id; 25 | JointId super_id; 26 | T3f bind_pose; // Offsets relative to super joint in bind pose 27 | bool selected; // Editor 28 | } Joint; 29 | 30 | #endif // REVOLC_ANIMATION_JOINT_H 31 | -------------------------------------------------------------------------------- /code/source/audio/audiosystem.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_AUDIO_AUDIOSYSTEM_H 2 | #define REVOLC_AUDIO_AUDIOSYSTEM_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | 7 | typedef U64 SoundHandle; 8 | #define NULL_SOUND_HANDLE 0 9 | 10 | typedef enum { 11 | AC_free, // No audio is assigned for this channel 12 | AC_play, // Audio callback is pushing samples to be played 13 | } AudioChannel_State; 14 | 15 | typedef struct AudioChannel { 16 | AudioChannel_State state; 17 | F32 *samples; // Interleaved samples 18 | U32 ch_count; 19 | U32 frame_count; // sample_count/ch_count 20 | U32 last_id; 21 | const char *last_sound_name; 22 | 23 | // Modified by non-critical code 24 | F32 in_pan; 25 | F32 in_vol; 26 | 27 | // These belong to the audio callback 28 | F32 out_pan; 29 | F32 out_vol; 30 | U32 cur_frame; 31 | } AudioChannel; 32 | 33 | typedef struct AudioSystem { 34 | AudioChannel channels[MAX_AUDIO_CHANNELS]; 35 | U32 next_sound_id; 36 | 37 | void *pa_out_stream; 38 | } AudioSystem; 39 | 40 | /// @note Sets g_env.audiosystem 41 | REVOLC_API void create_audiosystem(); 42 | REVOLC_API void destroy_audiosystem(); 43 | 44 | REVOLC_API SoundHandle play_sound(const char *name, F32 vol, F32 pan); 45 | REVOLC_API SoundHandle sound_handle_by_name(const char *name); 46 | REVOLC_API bool is_sound_playing(SoundHandle h); 47 | REVOLC_API void set_sound_vol(SoundHandle h, F32 vol); 48 | 49 | #endif // REVOLC_AUDIO_AUDIOSYSTEM_H 50 | -------------------------------------------------------------------------------- /code/source/audio/sound.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_SOUND_H 2 | #define REVOLC_SOUND_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "resources/resource.h" 7 | 8 | typedef struct Sound { 9 | Resource res; 10 | char rel_file[MAX_PATH_SIZE]; 11 | 12 | U32 ch_count; 13 | U32 frame_count; // sample_count/ch_count 14 | F32 samples[]; // Interleaved samples 15 | } PACKED Sound; 16 | 17 | REVOLC_API WARN_UNUSED 18 | Sound *blobify_sound(struct WArchive *ar, Cson c, bool *err); 19 | REVOLC_API void deblobify_sound(WCson *c, struct RArchive *ar); 20 | 21 | #endif // REVOLC_SOUND_H 22 | -------------------------------------------------------------------------------- /code/source/build.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_BUILD_H 2 | #define REVOLC_BUILD_H 3 | 4 | #define PLATFORM_LINUX 1 5 | #define PLATFORM_WINDOWS 2 6 | 7 | #if defined(__linux__) 8 | # define PLATFORM PLATFORM_LINUX 9 | # define PLATFORM_BITNESS 64 10 | #else 11 | # define PLATFORM PLATFORM_WINDOWS 12 | # if defined(__WIN64) 13 | # define PLATFORM_BITNESS 64 14 | # else 15 | # define PLATFORM_BITNESS 32 16 | # endif 17 | #endif 18 | 19 | #define DLL_EXPORT __attribute__((visibility ("default"))) 20 | #define DLL_IMPORT __attribute__((visibility ("default"))) 21 | 22 | #ifdef MOD_DLL_BUILD 23 | # define REVOLC_API DLL_IMPORT 24 | # define MOD_API DLL_EXPORT 25 | #else 26 | # define REVOLC_API DLL_EXPORT 27 | #endif 28 | 29 | #if PLATFORM == PLATFORM_WINDOWS 30 | # ifndef WIN32_LEAN_AND_MEAN 31 | # define WIN32_LEAN_AND_MEAN 32 | # endif 33 | #endif 34 | 35 | // BUILD macro defined in compile command 36 | #define BUILD_DEBUG 1 37 | #define BUILD_DEV 2 38 | #define BUILD_RELEASE 3 39 | 40 | #define GUI_API REVOLC_API 41 | #define GUI_BOOL bool 42 | 43 | #define QC_API REVOLC_API 44 | 45 | // @todo Don't include here 46 | #include "core/basic.h" 47 | 48 | #endif // REVOLC_BUILD_H 49 | -------------------------------------------------------------------------------- /code/source/clover/clover.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crafn/revolc/2c9cf78941bebf8d3f5d4664cd5ac06462bfe3eb/code/source/clover/clover.c -------------------------------------------------------------------------------- /code/source/clover/playerch.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOVER_PLAYERCH_H 2 | #define CLOVER_PLAYERCH_H 3 | 4 | // Character 5 | typedef struct PlayerCh { 6 | T3d tf; 7 | JointPoseArray pose; 8 | 9 | F64 idle_run_lerp; 10 | F64 clip_time; 11 | F64 fake_dif; 12 | 13 | F64 on_ground_timer; 14 | //V2d target_position_on_ground; 15 | //V2d last_velocity_on_ground; 16 | 17 | V2d last_ground_velocity; 18 | //V2d smoothed_ground_velocity; 19 | V2d last_ground_contact_point; 20 | F64 time_from_jump; 21 | F64 dig_timer; 22 | F64 build_timer; 23 | S8 walk_dir; 24 | S8 facing_dir; 25 | 26 | U8 active_slot; // 0-9 27 | S32 dirt_amount; 28 | 29 | U8 peer_id; // To distinguish which peer controls which character 30 | 31 | // Cached 32 | ResId run_clip_id; 33 | ResId idle_clip_id; 34 | ResId dig_clip_id; 35 | } PACKED PlayerCh; 36 | 37 | MOD_API void init_playerch(PlayerCh *p); 38 | MOD_API U32 resurrect_playerch(PlayerCh *p); 39 | MOD_API void upd_playerch(PlayerCh *p, RigidBody *body); 40 | MOD_API void free_playerch(Handle h, PlayerCh *p); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /code/source/clover/slidedoor.c: -------------------------------------------------------------------------------- 1 | #include "slidedoor.h" 2 | 3 | void init_slidedoor(SlideDoor *d) 4 | { 5 | *d = (SlideDoor) { 6 | .delta_open = (V2d) {0, 5}, 7 | .open_force = 100, 8 | .close_force = 100, 9 | }; 10 | } 11 | 12 | void upd_slidedoor(SlideDoor *door, RigidBody *body) 13 | { 14 | V2d anchor_open = add_v2d(door->delta_open, door->pos); 15 | apply_groove_joint(body, anchor_open, door->pos); 16 | 17 | V2d dir = normalized_v2d(door->delta_open); 18 | 19 | V2d dif = sub_v2d(door->pos, v3d_to_v2d(body->tf.pos)); 20 | door->fraction = length_v2d(dif)/length_v2d(door->delta_open); 21 | door->half_open_state = door->fraction > 0.5; 22 | 23 | if (door->fraction > -0.5 && door->fraction < 1.5) { // Failsafe 24 | if (door->open) 25 | apply_force(body, scaled_v2d(door->open_force, dir)); 26 | else 27 | apply_force(body, scaled_v2d(-door->close_force, dir)); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /code/source/clover/slidedoor.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOVER_SLIDEDOOR_H 2 | #define CLOVER_SLIDEDOOR_H 3 | 4 | #include "build.h" 5 | 6 | typedef struct SlideDoor { 7 | bool open; // Wanted state 8 | V2d pos; // Closed position 9 | V2d delta_open; 10 | 11 | F64 open_force; 12 | F64 close_force; 13 | 14 | F64 fraction; // 0 when closed, 1 when open 15 | bool half_open_state; // Changes midway 16 | } PACKED SlideDoor; 17 | 18 | MOD_API void init_slidedoor(SlideDoor *d); 19 | MOD_API void upd_slidedoor(SlideDoor *door, RigidBody *body); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /code/source/clover/unity.c: -------------------------------------------------------------------------------- 1 | #define MOD_DLL_BUILD 2 | 3 | #include "clover.c" 4 | #include "dirtbug.c" 5 | #include "playerch.c" 6 | #include "slidedoor.c" 7 | 8 | #ifndef CODEGEN 9 | # include "gen_rtti.c" 10 | #endif 11 | -------------------------------------------------------------------------------- /code/source/core/array.c: -------------------------------------------------------------------------------- 1 | #include "array.h" 2 | #include "debug.h" 3 | #include "basic.h" 4 | 5 | DEFINE_ARRAY(U32) 6 | DEFINE_ARRAY(U64) 7 | 8 | void * enlarge_array(void *array, U32 *old_c, U32 elem_size) 9 | { 10 | if (!array) { 11 | const U32 new_c = 4; 12 | const U32 new_size = new_c*elem_size; 13 | 14 | array = malloc(new_size); 15 | memset(array, 0, new_size); 16 | 17 | *old_c = new_c; 18 | return array; 19 | } else { 20 | U32 old_size = *old_c*elem_size; 21 | U32 new_c = *old_c*1.5; 22 | U32 new_size = new_c*elem_size; 23 | ensure(new_c > *old_c); 24 | 25 | array = realloc(array, new_size); 26 | memset(array + old_size, 0, new_size - old_size); 27 | 28 | *old_c = new_c; 29 | return array; 30 | } 31 | } 32 | 33 | void * push_dyn_array( 34 | void *array, U32 *capacity, U32 *count, U32 elem_size, void *elem) 35 | { 36 | if (*capacity == *count) 37 | array = enlarge_array(array, capacity, elem_size); 38 | memcpy(array + (*count)*elem_size, elem, elem_size); 39 | ++(*count); 40 | return array; 41 | } 42 | -------------------------------------------------------------------------------- /code/source/core/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PLATFORM_ASSERT_H 2 | #define REVOLC_PLATFORM_ASSERT_H 3 | 4 | #include 5 | 6 | #endif // REVOLC_PLATFORM_ASSERT_H 7 | -------------------------------------------------------------------------------- /code/source/core/color.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_COLOR_H 2 | #define REVOLC_CORE_COLOR_H 3 | 4 | #include "build.h" 5 | 6 | typedef struct Color { 7 | F32 r, g, b, a; 8 | } Color; 9 | 10 | static 11 | Color mul_color(Color c1, Color c2) 12 | { return (Color) {c1.r*c2.r, c1.g*c2.g, c1.b*c2.b, c1.a*c2.a}; } 13 | 14 | static 15 | Color lerp_color(Color c1, Color c2, F32 t) 16 | { return (Color) { c1.r*(1 - t) + c2.r*t, 17 | c1.g*(1 - t) + c2.g*t, 18 | c1.b*(1 - t) + c2.b*t, 19 | c1.a*(1 - t) + c2.a*t}; } 20 | 21 | static 22 | Color white_color() 23 | { return (Color) {1, 1, 1, 1}; } 24 | 25 | static 26 | Color black_color() 27 | { return (Color) {0, 0, 0, 1}; } 28 | 29 | #endif // REVOLC_CORE_COLOR_H 30 | -------------------------------------------------------------------------------- /code/source/core/debug.c: -------------------------------------------------------------------------------- 1 | #include "basic.h" 2 | #include "debug.h" 3 | #include "device.h" 4 | #include "visual/renderer.h" 5 | 6 | void debug_print(const char *fmt, ...) 7 | { 8 | va_list a; 9 | va_start(a, fmt); 10 | vprintf(fmt, a); 11 | va_end(a); 12 | 13 | printf("\n"); 14 | } 15 | 16 | void critical_print(const char *fmt, ...) 17 | { 18 | plat_set_term_color(TermColor_red); 19 | 20 | va_list a; 21 | va_start(a, fmt); 22 | vprintf(fmt, a); 23 | va_end(a); 24 | printf("\n"); 25 | 26 | plat_set_term_color(TermColor_default); 27 | } 28 | 29 | void fail(const char *format, ...) 30 | { 31 | plat_set_term_color(TermColor_red); 32 | 33 | va_list a; 34 | va_start(a, format); 35 | vprintf(format, a); 36 | va_end(a); 37 | 38 | plat_set_term_color(TermColor_default); 39 | printf("\n"); 40 | 41 | asm("int $3"); // For mingw breakpoint problems when b exit doesn't work 42 | abort(); 43 | } 44 | 45 | Debug *create_debug() 46 | { 47 | Debug *d = ZERO_ALLOC(gen_ator(), sizeof(*d), "debug"); 48 | return d; 49 | } 50 | 51 | void destroy_debug(Debug *d) 52 | { 53 | FREE(gen_ator(), d); 54 | } 55 | 56 | void upd_debug(Debug *d) 57 | { 58 | #if 0 59 | memmove(d->dt_history, d->dt_history + 1, sizeof(*d->dt_history)*(DT_HISTORY_COUNT - 1)); 60 | d->dt_history[DT_HISTORY_COUNT - 1] = g_env.device->dt; 61 | 62 | F32 max = 0; 63 | for (U32 i = 0; i < DT_HISTORY_COUNT; ++i) { 64 | if (d->dt_history[i] > max) 65 | max = d->dt_history[i]; 66 | } 67 | 68 | int height = 128; 69 | for (U32 i = 0; i < DT_HISTORY_COUNT; ++i) { 70 | V2i size = {1, d->dt_history[i]/max*height}; 71 | V2i pos = {i, height - size.y}; 72 | Color c = {1.f, 0.f, 0.f, 0.9f}; 73 | drawcmd_px_quad(pos, size, 0.0, c, c, 9999999); 74 | } 75 | #endif 76 | } 77 | 78 | -------------------------------------------------------------------------------- /code/source/core/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_DEBUG_PRINT_H 2 | #define REVOLC_CORE_DEBUG_PRINT_H 3 | 4 | #include "build.h" 5 | 6 | REVOLC_API void debug_print(const char *format, ...); 7 | REVOLC_API void critical_print(const char *format, ...); 8 | 9 | // @todo release/debug ensure 10 | // @todo ensure -> ASSERT 11 | #if BUILD == BUILD_DEBUG || BUILD == BUILD_DEV 12 | # define ensure(x) \ 13 | do { if (!(x)) fail("ensure failed (%s: %i): %s", __FILE__, __LINE__, #x); } while(0) 14 | #else 15 | # define ensure 16 | #endif 17 | 18 | REVOLC_API NORETURN 19 | void fail(const char *format, ...); 20 | 21 | typedef enum { 22 | TermColor_default, 23 | TermColor_red, 24 | } TermColor; 25 | 26 | REVOLC_API void plat_set_term_color(TermColor c); 27 | 28 | // Misc debug and dev info 29 | typedef struct Debug { 30 | # define DT_HISTORY_COUNT (60*10) 31 | F32 dt_history[DT_HISTORY_COUNT]; 32 | } Debug; 33 | 34 | REVOLC_API Debug *create_debug(); 35 | REVOLC_API void destroy_debug(Debug *d); 36 | REVOLC_API void upd_debug(Debug *d); 37 | 38 | #endif // REVOLC_CORE_DEBUG_PRINT_H 39 | -------------------------------------------------------------------------------- /code/source/core/device.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PLATFORM_DEVICE_H 2 | #define REVOLC_PLATFORM_DEVICE_H 3 | 4 | #include "build.h" 5 | #include "core/math.h" 6 | 7 | #define KEY_COUNT 256 8 | #define KEY_LMB 0 9 | #define KEY_MMB 1 10 | #define KEY_RMB 2 11 | #define KEY_TAB 9 12 | #define KEY_LSHIFT 10 13 | #define KEY_LCTRL 11 14 | #define KEY_SPACE 12 15 | #define KEY_DEL 13 16 | #define KEY_KP_0 14 17 | #define KEY_KP_1 15 18 | #define KEY_KP_2 16 19 | #define KEY_KP_3 17 20 | #define KEY_KP_4 18 21 | #define KEY_KP_5 19 22 | #define KEY_KP_6 20 23 | #define KEY_KP_7 21 24 | #define KEY_KP_8 22 25 | #define KEY_KP_9 23 26 | // @todo Change to match with ascii 27 | #define KEY_0 24 28 | #define KEY_1 25 29 | #define KEY_2 26 30 | #define KEY_3 27 31 | #define KEY_4 28 32 | #define KEY_5 29 33 | #define KEY_6 30 34 | #define KEY_7 31 35 | #define KEY_8 32 36 | #define KEY_9 33 37 | 38 | // ... 39 | 40 | #define KEY_A 97 // 'a' 41 | // ... 42 | #define KEY_F1 128 43 | #define KEY_F2 129 44 | #define KEY_F3 130 45 | #define KEY_F4 131 46 | #define KEY_F5 132 47 | #define KEY_F6 133 48 | #define KEY_F7 134 49 | #define KEY_F8 135 50 | #define KEY_F9 136 51 | #define KEY_F10 137 52 | #define KEY_F11 138 53 | #define KEY_F12 139 54 | #define KEY_ESC 140 55 | #define KEY_LEFT 144 56 | #define KEY_UP 145 57 | #define KEY_RIGHT 146 58 | #define KEY_DOWN 147 59 | 60 | #define WRITTEN_TEXT_BUF_SIZE 32 61 | 62 | struct DevicePlatformData; 63 | typedef struct Device { 64 | V2i cursor_pos; 65 | V2i win_size; 66 | bool quit_requested; 67 | F32 dt; 68 | 69 | bool key_down[KEY_COUNT]; 70 | bool key_pressed[KEY_COUNT]; 71 | bool key_released[KEY_COUNT]; 72 | 73 | char written_text_buf[WRITTEN_TEXT_BUF_SIZE]; 74 | U32 written_text_size; 75 | 76 | F64 mwheel_delta; 77 | 78 | struct DevicePlatformData* impl; 79 | } Device; 80 | 81 | /// @note Sets g_env.device 82 | REVOLC_API Device * plat_init(const char* title, V2i reso); 83 | REVOLC_API void plat_quit(Device *d); 84 | 85 | REVOLC_API void plat_update(Device *d); 86 | REVOLC_API void plat_swap_buffers(Device *d); 87 | REVOLC_API void plat_sleep(int ms); 88 | REVOLC_API void plat_flush_denormals(bool enable); 89 | REVOLC_API U32 plat_malloc_size(void *ptr); 90 | 91 | /// @return Mallocated null-terminated array of null-terminated, mallocated strings 92 | REVOLC_API char ** plat_find_paths_with_end(const char *path_to_dir, const char *end); 93 | 94 | #endif // REVOLC_PLATFORM_DEVICE_H 95 | -------------------------------------------------------------------------------- /code/source/core/dll.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PLATFORM_DLL_H 2 | #define REVOLC_PLATFORM_DLL_H 3 | 4 | #include "build.h" 5 | 6 | typedef void * DllHandle; 7 | const DllHandle g_main_program_dll = NULL; 8 | 9 | REVOLC_API DllHandle load_dll(const char *path); 10 | REVOLC_API void unload_dll(DllHandle dll); 11 | REVOLC_API void * query_dll_sym(DllHandle dll, const char* sym); 12 | REVOLC_API const char * dll_error(); 13 | REVOLC_API const char * plat_dll_ext(); 14 | 15 | #endif // REVOLC_PLATFORM_DLL_H 16 | -------------------------------------------------------------------------------- /code/source/core/gl.c: -------------------------------------------------------------------------------- 1 | #include "core/debug.h" 2 | #include "gl.h" 3 | 4 | void gl_check_shader_status(GLuint shd, const char *msg) 5 | { 6 | GLint status; 7 | glGetShaderiv(shd, GL_COMPILE_STATUS, &status); 8 | if (!status) { 9 | const GLsizei max_len = 512; 10 | GLchar log[max_len]; 11 | glGetShaderInfoLog(shd, max_len, NULL, log); 12 | fail("Shader compilation failed (%i, %s): %s", shd, msg, log); 13 | } 14 | } 15 | 16 | void gl_check_program_status(GLuint prog) 17 | { 18 | GLint link_status; 19 | glGetProgramiv(prog, GL_LINK_STATUS, &link_status); 20 | if (!link_status) { 21 | const GLsizei size = 512; 22 | GLchar log[size]; 23 | glGetProgramInfoLog(prog, size, NULL, log); 24 | fail("Program link failed: %s", log); 25 | } 26 | } 27 | 28 | void gl_check_errors(const char *tag) 29 | { 30 | GLenum error = glGetError(); 31 | if (error!= GL_NO_ERROR) 32 | debug_print("GL Error (%s): %i\n", tag, error); 33 | } 34 | 35 | void gl_destroy_shader_prog(GLuint *prog, GLuint *vs, GLuint *gs, GLuint *fs) 36 | { 37 | glDetachShader(*prog, *vs); 38 | glDeleteShader(*vs); 39 | 40 | if (*gs) { 41 | glDetachShader(*prog, *gs); 42 | glDeleteShader(*gs); 43 | } 44 | 45 | glDetachShader(*prog, *fs); 46 | glDeleteShader(*fs); 47 | 48 | glDeleteProgram(*prog); 49 | 50 | *prog = *vs = *gs = *fs = 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /code/source/core/grid.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_GRID_H 2 | #define REVOLC_CORE_GRID_H 3 | 4 | #include "build.h" 5 | #include "math.h" 6 | 7 | // Utility for grid calculations 8 | typedef struct GridDef { 9 | V2i offset; 10 | V2i reso; 11 | U32 reso_per_unit; 12 | U32 cell_count; 13 | U32 sizeof_cell; 14 | U32 sizeof_grid; 15 | } GridDef; 16 | 17 | // grid_vec is measured from world origo, not grid origo (makes using patches of grid with different offsets easy as they have the same grid vectors) 18 | REVOLC_API 19 | GridDef make_griddef(V2d center, V2d size, U32 reso_per_unit, U32 sizeof_cell); 20 | REVOLC_API void set_grid_border(GridDef def, void *grid_data, void *value); 21 | 22 | REVOLC_API U32 gvec_to_gix(GridDef def, V2i grid_vec); 23 | REVOLC_API U32 wvec_to_gix(GridDef def, V2d world_vec); 24 | REVOLC_API V2i gix_to_gvec(GridDef def, U32 ix); 25 | REVOLC_API V2d gix_to_wvec_center(GridDef def, U32 ix); 26 | REVOLC_API V2i wvec_to_gvec(GridDef def, V2d world_vec); 27 | REVOLC_API U32 gix_to_gix(GridDef dst, GridDef src, U32 src_ix); 28 | REVOLC_API bool is_wvec_in_grid(GridDef def, V2d world_vec); 29 | 30 | #endif // REVOLC_CORE_GRID_H 31 | -------------------------------------------------------------------------------- /code/source/core/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_HASH_H 2 | #define REVOLC_CORE_HASH_H 3 | 4 | #include "build.h" 5 | 6 | typedef U32 Hash; 7 | 8 | // Hash "template" 9 | #define hash(V) JOIN2(hash_, LC(V)) 10 | 11 | // Hash functions should avoid generating neighbouring hashes easily (linear probing) 12 | static Hash hash(U32)(U32 value) { return value*2; } 13 | static Hash hash(U64)(U64 value) { return (value*2) % U32_MAX; } 14 | 15 | #endif // REVOLC_CORE_HASH_H 16 | -------------------------------------------------------------------------------- /code/source/core/hashtable.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_HASHTABLE_H 2 | #define REVOLC_CORE_HASHTABLE_H 3 | 4 | #include "build.h" 5 | #include "core/hash.h" 6 | #include "core/memory.h" 7 | 8 | // Key_Value 9 | #define KV(K, V) JOIN3(ORIG_TYPE(K), _, ORIG_TYPE(V)) 10 | // key_value 11 | #define LC_KV(K, V) JOIN3(LC(ORIG_TYPE(K)), _, LC(ORIG_TYPE(V))) 12 | 13 | #define create_tbl(K, V) JOIN3(create_, LC_KV(K, V), _tbl) 14 | #define destroy_tbl(K, V) JOIN3(destroy_, LC_KV(K, V), _tbl) 15 | #define get_tbl(K, V) JOIN3(get_, LC_KV(K, V), _tbl) 16 | #define set_tbl(K, V) JOIN3(set_, LC_KV(K, V), _tbl) 17 | #define clear_tbl(K, V) JOIN3(clear_tbl, LC_KV(K, V), _tbl) 18 | #define null_tbl_entry(K, V) JOIN3(null_, LC_KV(K, V), _tbl_entry) 19 | #define HashTbl(K, V) JOIN2(KV(K, V), _Tbl) 20 | #define HashTbl_Entry(K, V) JOIN2(KV(K, V), _Tbl_Entry) 21 | 22 | #define DECLARE_HASHTABLE(K, V)\ 23 | struct HashTbl_Entry(K, V);\ 24 | \ 25 | typedef struct HashTbl(K, V) {\ 26 | Ator *ator;\ 27 | struct HashTbl_Entry(K, V) *array;\ 28 | U32 array_size;\ 29 | U32 count;\ 30 | K null_key;\ 31 | V null_value;\ 32 | } HashTbl(K, V);\ 33 | typedef struct HashTbl_Entry(K, V) {\ 34 | K key;\ 35 | V value;\ 36 | } HashTbl_Entry(K, V);\ 37 | \ 38 | REVOLC_API HashTbl(K, V) create_tbl(K, V)( K null_key, V null_value,\ 39 | Ator *ator, U32 expected_item_count);\ 40 | REVOLC_API void destroy_tbl(K, V)(HashTbl(K, V) *tbl);\ 41 | \ 42 | REVOLC_API V get_tbl(K, V)(HashTbl(K, V) *tbl, K key);\ 43 | REVOLC_API void set_tbl(K, V)(HashTbl(K, V) *tbl, K key, V value);\ 44 | REVOLC_API void clear_tbl(K, V)(HashTbl(K, V) *tbl);\ 45 | 46 | 47 | DECLARE_HASHTABLE(U64, U32) 48 | DECLARE_HASHTABLE(U32, U32) 49 | 50 | #endif // REVOLC_CORE_HASHTABLE_H 51 | -------------------------------------------------------------------------------- /code/source/core/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_MEMORY_H 2 | #define REVOLC_CORE_MEMORY_H 3 | 4 | #include "build.h" 5 | 6 | /// @todo Other compilers 7 | #define PLAT_FULL_MEMORY_BARRIER() __sync_synchronize() 8 | #define PLAT_ACQUIRE_FENCE() __atomic_thread_fence(__ATOMIC_ACQUIRE) 9 | #define PLAT_RELEASE_FENCE() __atomic_thread_fence(__ATOMIC_RELEASE) 10 | 11 | // Allocator types 12 | typedef enum AtorType { 13 | AtorType_none, 14 | AtorType_gen, // malloc/realloc/free 15 | AtorType_linear, // allocates linearly from buffer. free == nop 16 | AtorType_dev, 17 | AtorType_leakable_dev, // Use for one-off allocations if lazy. 18 | } AtorType; 19 | 20 | typedef struct Ator { 21 | AtorType type; 22 | // Only used for linear 23 | U8 *buf; 24 | U32 offset; 25 | U32 capacity; 26 | U32 last_allocd_size; 27 | void *last_allocd_ptr; 28 | 29 | const char *tag; 30 | } Ator; 31 | 32 | // General allocation functions 33 | #define ALLOC(ator, size, tag) (alloc_impl((ator), (size), NULL, (tag))) 34 | #define REALLOC(ator, ptr, size, tag) (alloc_impl((ator), (size), ptr, (tag))) 35 | #define ZERO_ALLOC(ator, size, tag) (memset(alloc_impl((ator), (size), NULL, (tag)), 0, (size))) 36 | #define FREE(ator, ptr) (free_impl((ator), (ptr))) 37 | 38 | // Specific allocators to be used with general allocation functions 39 | REVOLC_API WARN_UNUSED Ator *gen_ator(); 40 | REVOLC_API WARN_UNUSED Ator linear_ator(void *buf, U32 size, const char *tag); 41 | REVOLC_API WARN_UNUSED Ator *dev_ator(); 42 | REVOLC_API WARN_UNUSED Ator *leakable_dev_ator(); 43 | REVOLC_API WARN_UNUSED Ator *frame_ator(); // No need to free (valid for this frame) 44 | 45 | REVOLC_API WARN_UNUSED 46 | void * alloc_impl(Ator *ator, U32 size, void *realloc_ptr, const char *tag); 47 | REVOLC_API void free_impl(Ator *ator, void *ptr); 48 | 49 | 50 | #define STACK_ALLOC(size) alloca(size) 51 | #define ZERO_STACK_ALLOC(size) memset(alloca(size), 0, size) 52 | 53 | // @todo Remove 54 | REVOLC_API WARN_UNUSED 55 | void * dev_malloc(U32 size); 56 | REVOLC_API WARN_UNUSED 57 | void * dev_realloc(void *ptr, U32 size); 58 | REVOLC_API void dev_free(void *mem); 59 | 60 | REVOLC_API void * frame_alloc(U32 size); 61 | REVOLC_API void reset_frame_alloc(); 62 | 63 | #endif // REVOLC_CORE_MEMORY_H 64 | -------------------------------------------------------------------------------- /code/source/core/random.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_RANDOM_H 2 | #define REVOLC_CORE_RANDOM_H 3 | 4 | // Thanks R.. http://stackoverflow.com/questions/19083566/what-are-the-better-pseudo-random-number-generator-than-the-lcg-for-lottery-sc 5 | static 6 | U32 temper(U32 x) 7 | { 8 | x ^= x>>11; 9 | x ^= x<<7 & 0x9D2C5680; 10 | x ^= x<<15 & 0xEFC60000; 11 | x ^= x>>18; 12 | return x; 13 | } 14 | 15 | static 16 | U32 random_u32_base(U64 *seed) 17 | { 18 | *seed = 6364136223846793005ULL * *seed + 1; 19 | return temper(*seed >> 32); 20 | } 21 | 22 | // Not production quality 23 | static 24 | U32 random_u32(U32 min, U32 max, U64 *seed) 25 | { 26 | ensure(max > min); 27 | return random_u32_base(seed)%(max - min) + min; 28 | } 29 | 30 | // Not production quality 31 | static 32 | S32 random_s32(S32 min, S32 max, U64 *seed) 33 | { 34 | ensure(max > min); 35 | return random_u32_base(seed)%(max - min) + min; 36 | } 37 | 38 | // Not production quality 39 | static 40 | F64 random_f64(F64 min, F64 max, U64 *seed) 41 | { 42 | ensure(max > min); 43 | F64 f = (F64)random_u32_base(seed)/U32_MAX; 44 | return f*(max - min) + min; 45 | } 46 | 47 | // Not production quality 48 | static 49 | F32 random_f32(F32 min, F32 max, U64 *seed) 50 | { 51 | ensure(max > min); 52 | F32 f = (F32)random_u32_base(seed)/U32_MAX; 53 | return f*(max - min) + min; 54 | } 55 | 56 | #endif // REVOLC_CORE_RANDOM_H -------------------------------------------------------------------------------- /code/source/core/socket.c: -------------------------------------------------------------------------------- 1 | #include "core/socket.h" 2 | #include "core/basic.h" 3 | 4 | const char *ip_to_str(IpAddress addr) 5 | { 6 | return frame_str("%i.%i.%i.%i:%i", 7 | addr.a, addr.b, addr.c, addr.d, 8 | addr.port); 9 | } 10 | 11 | IpAddress str_to_ip(const char *str) 12 | { 13 | int a, b, c, d, port; 14 | int ret = sscanf(str, "%i.%i.%i.%i:%i", &a, &b, &c, &d, &port); 15 | if (ret < 4) 16 | fail("Ip parsing failed: %s", str); 17 | return (IpAddress) {a, b, c, d, port}; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /code/source/core/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CORE_SOCKET_H 2 | #define REVOLC_CORE_SOCKET_H 3 | 4 | #include "build.h" 5 | 6 | typedef S64 Socket; 7 | typedef struct IpAddress { 8 | U8 a, b, c, d; 9 | U16 port; 10 | } IpAddress; 11 | 12 | REVOLC_API const char *ip_to_str(IpAddress addr); 13 | REVOLC_API IpAddress str_to_ip(const char *str); 14 | 15 | static bool ip_equals(IpAddress ip1, IpAddress ip2) 16 | { return ip1.a == ip2.a && ip1.b == ip2.b && 17 | ip1.c == ip2.c && ip1.d == ip2.d && 18 | ip1.port == ip2.port; } 19 | 20 | REVOLC_API int socket_error(); 21 | REVOLC_API Socket invalid_socket(); 22 | 23 | REVOLC_API Socket open_udp_socket(U16 port); 24 | REVOLC_API void close_socket(Socket *fd); 25 | 26 | REVOLC_API U32 send_packet(Socket sock, IpAddress addr, const void *data, U32 size); 27 | REVOLC_API U32 recv_packet(Socket sock, IpAddress *addr, void *dst, U32 dst_size); 28 | 29 | #endif // REVOLC_CORE_SOCKET_H 30 | -------------------------------------------------------------------------------- /code/source/core/sparsetable.c: -------------------------------------------------------------------------------- 1 | #include "sparsetable.h" 2 | 3 | -------------------------------------------------------------------------------- /code/source/editor/editor.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_EDITOR_H 2 | #define REVOLC_EDITOR_H 3 | 4 | #include "build.h" 5 | 6 | typedef enum { 7 | EditorState_invisible, 8 | EditorState_res, 9 | EditorState_world, 10 | EditorState_gui_test, 11 | } EditorState; 12 | 13 | typedef enum { 14 | EditorState_Res_mesh, 15 | EditorState_Res_armature, 16 | EditorState_Res_body, 17 | } EditorState_Res; 18 | 19 | typedef struct CreateCmdEditor { 20 | bool select_src; 21 | bool select_dst; 22 | Id src_node; // Initialize to NULL_ID 23 | U32 src_offset; 24 | U32 src_size; 25 | Id dst_node; // Initialize to NULL_ID 26 | U32 dst_offset; 27 | U32 dst_size; 28 | } CreateCmdEditor; 29 | 30 | typedef struct ArmatureEditor { 31 | U32 comp_h; // Initialize to NULL_HANDLE 32 | char clip_name[RES_NAME_SIZE]; 33 | bool clip_is_bind_pose; 34 | bool is_playing; 35 | F64 clip_time; 36 | } ArmatureEditor; 37 | 38 | #define MAX_BODY_VERTICES (MAX_SHAPES_PER_BODY*(MAX_POLY_VERTEX_COUNT + 2)) 39 | typedef struct BodyEditor { 40 | Handle body_h; // Initialize to NULL_HANDLE 41 | bool vertex_selected[MAX_BODY_VERTICES]; 42 | } BodyEditor; 43 | 44 | typedef struct WorldNodeEditor { 45 | Array(U64) selected_groups; 46 | } WorldNodeEditor; 47 | 48 | typedef struct Editor { 49 | U32 cur_model_h; 50 | ArmatureEditor armature_editor; 51 | BodyEditor body_editor; 52 | 53 | WorldNodeEditor world_node_editor; 54 | 55 | // Undo states 56 | void *mesh_state; 57 | void *armature_state; 58 | void *clip_state; 59 | void *bodydef_state; 60 | 61 | bool is_edit_mode; // Edit or object mode 62 | 63 | EditorState state; 64 | EditorState_Res res_state; // When in EditorState_res 65 | bool edit_layout; 66 | 67 | bool show_prog_state; 68 | bool show_node_list; 69 | bool show_cmd_list; 70 | 71 | bool show_nodegroupdef_list; 72 | U32 selected_nodegroupdef; 73 | 74 | bool show_create_cmd; 75 | // @todo Rename to cmd_editor 76 | CreateCmdEditor create_cmd; 77 | 78 | F32 world_time_mul; 79 | } Editor; 80 | 81 | // Sets g_env.editor 82 | REVOLC_API void create_editor(); 83 | REVOLC_API void destroy_editor(); 84 | 85 | REVOLC_API void upd_editor(F64 *world_dt); 86 | 87 | // Individual editor views 88 | 89 | REVOLC_API void do_mesh_editor(U32 *model_h, bool *is_edit_mode, bool active); 90 | REVOLC_API void do_armature_editor( ArmatureEditor *state, 91 | bool is_edit_mode, 92 | bool active); 93 | REVOLC_API void do_body_editor(BodyEditor *editor, bool is_edit_mode, bool active); 94 | 95 | #endif // REVOLC_EDITOR_H 96 | -------------------------------------------------------------------------------- /code/source/editor/editor_util.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_EDITOR_EDITOR_UTIL_H 2 | #define REVOLC_EDITOR_EDITOR_UTIL_H 3 | 4 | #include "build.h" 5 | #include "core/color.h" 6 | #include "ui/gui.h" 7 | 8 | /// @todo Remove unused fields 9 | typedef struct EditorBoxState { 10 | // RMB 11 | bool hover; 12 | bool down; 13 | bool pressed; 14 | bool released; 15 | 16 | // LMB 17 | bool ldown; 18 | } EditorBoxState; 19 | 20 | REVOLC_API F64 editor_vertex_size(); 21 | 22 | // @todo Not sure if this is a good idea. Could probably just have 23 | // if (ctx.dev.grabbing == gui_id(label)) 24 | // instead of 25 | // if (cursor_delta_mode(label) == CursorDeltaMode_translate) 26 | typedef enum { 27 | CursorDeltaMode_none, 28 | CursorDeltaMode_scale, 29 | CursorDeltaMode_rotate, 30 | CursorDeltaMode_translate, 31 | } CursorDeltaMode; 32 | REVOLC_API CursorDeltaMode cursor_delta_mode(const char *label); 33 | REVOLC_API CursorDeltaMode cursor_transform_delta_world( T3f *out, 34 | const char *label, 35 | T3d coords); 36 | REVOLC_API CursorDeltaMode cursor_transform_delta_pixels( T3f *out, 37 | const char *label, 38 | T3d coords); 39 | 40 | // Some common functionality, like scale/grab/rotate 41 | // @todo Grab etc. functionality should be in the gui lib. Then this can be substituted with simple gui_begin/end. 42 | REVOLC_API EditorBoxState gui_begin_editorbox( GuiContext *ctx, 43 | V2i *p, V2i *s, 44 | const char *label, 45 | bool invisible); 46 | REVOLC_API void gui_end_editorbox(GuiContext *ctx); 47 | 48 | #endif // REVOLC_EDITOR_EDITOR_UTIL_H 49 | -------------------------------------------------------------------------------- /code/source/game/aitest.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_AITEST_H 2 | #define REVOLC_GAME_AITEST_H 3 | 4 | // Testing node system here 5 | 6 | #include "build.h" 7 | #include "core/math.h" 8 | #include "physics/physworld.h" 9 | #include "visual/modelentity.h" 10 | 11 | typedef struct AiTest { 12 | V3d input_pos; 13 | V2d force; 14 | bool allocated; 15 | } AiTest; 16 | 17 | REVOLC_API U32 resurrect_aitest(const AiTest *dead); 18 | REVOLC_API void free_aitest(U32 handle); 19 | REVOLC_API void * storage_aitest(); 20 | REVOLC_API void upd_aitest(AiTest *t); 21 | 22 | REVOLC_API 23 | void rotate_modelentity(ModelEntity *e, U32 count); 24 | 25 | REVOLC_API 26 | void poly_to_modelentity( ModelEntity *e, ModelEntity *e_end, 27 | RigidBody *b, RigidBody *b_end); 28 | 29 | #endif // REVOLC_GAME_AITEST_H 30 | -------------------------------------------------------------------------------- /code/source/game/game.c: -------------------------------------------------------------------------------- 1 | #include "game.h" 2 | 3 | void make_main_blob(const char *blob_path, const char *game) 4 | { 5 | const char *engine_res_root = frame_str("%srevolc/", DEFAULT_RES_ROOT); 6 | const char *game_res_root = frame_str("%s%s/", DEFAULT_RES_ROOT, game); 7 | 8 | // @todo Fix crappy api! 9 | char **game_res_paths = plat_find_paths_with_end(game_res_root, ".cres"); 10 | char **engine_res_paths = plat_find_paths_with_end(engine_res_root, ".cres"); 11 | 12 | U32 res_count = 0; 13 | char *res_paths[MAX_RES_FILES] = {0}; 14 | for (U32 i = 0; res_count < MAX_RES_FILES && engine_res_paths[i]; ++i) 15 | res_paths[res_count++] = engine_res_paths[i]; 16 | for (U32 i = 0; res_count < MAX_RES_FILES && game_res_paths[i]; ++i) 17 | res_paths[res_count++] = game_res_paths[i]; 18 | 19 | make_blob(blob_path, res_paths); 20 | for (U32 i = 0; res_paths[i]; ++i) 21 | FREE(gen_ator(), res_paths[i]); 22 | FREE(gen_ator(), engine_res_paths); 23 | FREE(gen_ator(), game_res_paths); 24 | } 25 | 26 | const char *blob_path(const char *game) 27 | { return frame_str("%s.blob", game); } 28 | 29 | -------------------------------------------------------------------------------- /code/source/game/game.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_GAME_H 2 | #define REVOLC_GAME_GAME_H 3 | 4 | #include "build.h" 5 | 6 | // Stuff above engine level, but not game-specific -- things you'd see in main.c, but need to be shared. 7 | 8 | #define SAVEFILE_PATH "save.bin" 9 | 10 | REVOLC_API void make_main_blob(const char *blob_path, const char *game); 11 | REVOLC_API const char *blob_path(const char *game); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /code/source/game/net.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_NET_H 2 | #define REVOLC_GAME_NET_H 3 | 4 | #include "build.h" 5 | #include "core/basic.h" 6 | #include "core/array.h" 7 | #include "core/udp.h" 8 | 9 | // World snapshot to which deltas are relative 10 | typedef struct WorldBaseState { 11 | U32 seq; 12 | U8 *data ALIGNED(MAX_ALIGNMENT); 13 | U32 size; 14 | U32 capacity; 15 | 16 | bool peer_has_this; 17 | } WorldBaseState; 18 | 19 | DECLARE_ARRAY(WorldBaseState) 20 | 21 | #define NULL_PEER ((U8)-1) 22 | #define AUTHORITY_PEER 0 23 | 24 | // Client/server state 25 | typedef struct NetState { 26 | UdpPeer *peer; 27 | bool authority; // Do we have authority over the game world 28 | U8 peer_id; // server = 0, clients = 1, .. 29 | 30 | F64 game_time; // Increasing monotonically in real time 31 | F64 delta_interval; 32 | 33 | bool peer_has_received_base; 34 | 35 | F64 world_upd_time; // Send/recv time 36 | F64 stats_timer; 37 | U32 world_seq; // Incremented at every delta 38 | Array(WorldBaseState) bases; 39 | U32 cur_base_ix; 40 | } NetState; 41 | 42 | REVOLC_API NetState *create_netstate( bool authority, F64 delta_interval, 43 | U32 state_history_count, U32 state_max_size, 44 | U16 local_port, IpAddress *remote_addr); 45 | REVOLC_API void destroy_netstate(NetState *net); 46 | REVOLC_API void upd_netstate(NetState *net); 47 | 48 | // Messaging 49 | 50 | typedef enum NetMsg { 51 | NetMsg_chat = 1, 52 | NetMsg_client_init, 53 | NetMsg_base, // Authority sends to peers at start 54 | NetMsg_delta, // Authority sends regularly 55 | NetMsg_world_seq_confirm, // Peers send to authority, so authority knows which base it can use 56 | NetMsg_single_node, // Peers send to authority for nodes which they have authority over (player character) 57 | // Debug 58 | NetMsg_brush_action, 59 | NetMsg_spawn_action, 60 | } NetMsg; 61 | 62 | typedef struct NetMsgHeader { 63 | NetMsg type; 64 | //F64 time; // Game time 65 | } PACKED NetMsgHeader; 66 | 67 | typedef struct ClientInit { 68 | U8 peer_id; 69 | } ClientInit; 70 | 71 | typedef struct BrushAction { // @todo Range and precision "attributes" 72 | V2d pos; 73 | F64 size; 74 | U8 material; 75 | } BrushAction; 76 | 77 | typedef struct SpawnAction { 78 | char name[RES_NAME_SIZE]; 79 | V2d pos; 80 | } SpawnAction; 81 | 82 | 83 | REVOLC_API U32 send_net_msg(NetMsg type, void *data, U32 data_size); 84 | REVOLC_API void local_brush_action(BrushAction *action); 85 | REVOLC_API void brush_action(BrushAction *action); 86 | REVOLC_API void local_spawn_action(SpawnAction *action); 87 | REVOLC_API void spawn_action(SpawnAction *action); 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /code/source/game/nodegroupdef.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_NODEGROUPDEF_H 2 | #define REVOLC_GAME_NODEGROUPDEF_H 3 | 4 | #include "build.h" 5 | #include "resources/resource.h" 6 | #include "core/cson.h" 7 | #include "core/basic.h" 8 | 9 | typedef enum { 10 | CmdType_memcpy, 11 | CmdType_call, 12 | } CmdType; 13 | 14 | typedef struct NodeGroupDef_Cmd { 15 | char str[MAX_CMD_STR_SIZE]; 16 | 17 | CmdType type; 18 | 19 | bool has_condition; 20 | U32 cond_node_i; 21 | U32 cond_offset; 22 | U32 cond_size; 23 | 24 | union { 25 | struct { // memcpy 26 | U32 src_offset; 27 | U32 src_node_i; // Index to `nodes in NodeGroupDef` 28 | U32 dst_offset; 29 | U32 dst_node_i; 30 | U32 size; 31 | }; 32 | struct { // call 33 | char func_name[MAX_FUNC_NAME_SIZE]; 34 | void *fptr; // Cached 35 | 36 | U32 p_node_i[MAX_CMD_CALL_PARAMS]; 37 | U32 p_count; 38 | }; 39 | }; 40 | } PACKED NodeGroupDef_Cmd; 41 | 42 | typedef struct NodeGroupDef_Node_Defaults { 43 | char str[MAX_CMD_STR_SIZE]; // "member = value" 44 | } PACKED NodeGroupDef_Node_Defaults; 45 | 46 | typedef struct NodeGroupDef_Node { 47 | char type_name[RES_NAME_SIZE]; 48 | char name[RES_NAME_SIZE]; 49 | 50 | NodeGroupDef_Node_Defaults defaults[MAX_NODE_DEFAULTS]; 51 | U32 defaults_count; 52 | 53 | // Would like to write these to blob, but that would require modules 54 | // to be loaded at make_blob... 55 | // Bytes of default node struct, which can be resurrected 56 | U8* default_struct; 57 | // 1 if corresponding byte is set in default_struct 58 | U8* default_struct_set_bytes; 59 | U32 default_struct_size; 60 | 61 | } PACKED NodeGroupDef_Node; 62 | 63 | typedef struct NodeGroupDef { 64 | Resource res; 65 | // @todo Allocate separately if sizes grow much 66 | NodeGroupDef_Node nodes[MAX_NODES_IN_GROUP_DEF]; 67 | U32 node_count; 68 | 69 | // Cmds of different types are in the same array, as the order of 70 | // performing cmds matter. Consider e.g. "a = b", "copy(b, a)" 71 | NodeGroupDef_Cmd cmds[MAX_CMDS_IN_GROUP_DEF]; 72 | U32 cmd_count; 73 | } PACKED NodeGroupDef; 74 | 75 | REVOLC_API void init_nodegroupdef(NodeGroupDef *def); 76 | REVOLC_API void deinit_nodegroupdef(NodeGroupDef *def); 77 | 78 | REVOLC_API WARN_UNUSED 79 | NodeGroupDef *blobify_nodegroupdef(struct WArchive *ar, Cson c, bool *err); 80 | REVOLC_API void deblobify_nodegroupdef(WCson *c, struct RArchive *ar); 81 | 82 | #endif // REVOLC_GAME_NODEGROUPDEF_H 83 | -------------------------------------------------------------------------------- /code/source/game/nodetype.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_NODETYPE_H 2 | #define REVOLC_GAME_NODETYPE_H 3 | 4 | #include "build.h" 5 | #include "resources/resource.h" 6 | #include "core/cson.h" 7 | 8 | struct World; 9 | struct Module; 10 | struct WArchive; 11 | struct RArchive; 12 | typedef void (*InitNodeImpl)(void *data); 13 | typedef Handle (*ResurrectNodeImpl)(void *dead); 14 | typedef void (*OverwriteNodeImpl)(void *node, const void *dead); 15 | typedef void (*FreeNodeImpl)(Handle h, void *data); 16 | typedef void * (*StorageNodeImpl)(); 17 | typedef void (*UpdNodeImpl)(void *node); 18 | typedef void (*PackNodeImpl)(WArchive *ar, const void *begin, const void *end); 19 | typedef void (*UnpackNodeImpl)(RArchive *ar, void *begin, void *end); 20 | 21 | typedef enum PackSync { 22 | PackSync_presence, // Only creation, destroying, and cmds 23 | PackSync_full, // Full state 24 | } PackSync; 25 | 26 | typedef struct NodeType { 27 | Resource res; 28 | 29 | char init_func_name[MAX_FUNC_NAME_SIZE]; 30 | char resurrect_func_name[MAX_FUNC_NAME_SIZE]; 31 | char overwrite_func_name[MAX_FUNC_NAME_SIZE]; 32 | char free_func_name[MAX_FUNC_NAME_SIZE]; 33 | char upd_func_name[MAX_FUNC_NAME_SIZE]; 34 | char storage_func_name[MAX_FUNC_NAME_SIZE]; 35 | char pack_func_name[MAX_FUNC_NAME_SIZE]; 36 | char unpack_func_name[MAX_FUNC_NAME_SIZE]; 37 | 38 | // If true, handles & impls are managed by the node system. 39 | // Also, free and storage funcs are NULL, and resurrect 40 | // works in-place, returning NULL_HANDLE. 41 | bool auto_impl_mgmt; 42 | U32 max_count; 43 | 44 | PackSync packsync; 45 | 46 | // Cached 47 | const struct Module *module; 48 | InitNodeImpl init; // Provides default values as dead data 49 | ResurrectNodeImpl resurrect; // Creates living node from dead data 50 | OverwriteNodeImpl overwrite; // Overwrites data of living node by dead data. Used in net game updates. 51 | UpdNodeImpl upd; // Updates living node 52 | FreeNodeImpl free; // Frees living node 53 | StorageNodeImpl storage; // Pointer to storage of nodes 54 | PackNodeImpl pack; // Picks necessary info from dead node for reconstructing node 55 | UnpackNodeImpl unpack; // Puts back necessary info to dead node, which can then be resurrected 56 | U32 size; 57 | 58 | // Set by node system! 59 | U32 auto_storage_handle; // Handle to AutoNodeImplStorage 60 | } NodeType; 61 | 62 | REVOLC_API void init_nodetype(NodeType *node); 63 | 64 | REVOLC_API WARN_UNUSED 65 | NodeType *blobify_nodetype(struct WArchive *ar, Cson c, bool *err); 66 | REVOLC_API void deblobify_nodetype(WCson *c, struct RArchive *ar); 67 | 68 | #endif // REVOLC_GAME_NODETYPE_H 69 | -------------------------------------------------------------------------------- /code/source/game/worldgen.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GAME_WORLDGEN_H 2 | #define REVOLC_GAME_WORLDGEN_H 3 | 4 | #include "build.h" 5 | #include "world.h" 6 | 7 | // This is just a test world generation 8 | 9 | REVOLC_API 10 | void generate_test_world(World *w); 11 | 12 | REVOLC_API 13 | F64 ground_surf_y(F64 x); 14 | 15 | REVOLC_API 16 | void spawn_visual_prop(World *world, V3d pos, F64 rot, V3d scale, const char *name); 17 | 18 | REVOLC_API 19 | void spawn_phys_prop(World *world, V2d pos, const char *name, bool is_static); 20 | 21 | 22 | #endif // REVOLC_GAME_WORLDGEN_H 23 | -------------------------------------------------------------------------------- /code/source/global/env.c: -------------------------------------------------------------------------------- 1 | #include "core/debug.h" 2 | #include "env.h" 3 | #include "symbol.h" 4 | #include "memory.h" 5 | 6 | Env g_env; 7 | 8 | void init_env(U32 argc, const char **argv) 9 | { 10 | g_env.argc = argc; 11 | g_env.argv = argv; 12 | 13 | { // Frame allocator 14 | ensure(g_env.frame_ator.buf == NULL); 15 | g_env.frame_ator = 16 | linear_ator( ZERO_ALLOC(gen_ator(), FRAME_MEM_SIZE, "frame"), 17 | FRAME_MEM_SIZE, 18 | "frame_ator"); 19 | } 20 | 21 | g_env.used_rtti_symbols = 22 | ZERO_ALLOC(gen_ator(), sizeof(*g_env.used_rtti_symbols), "rtti_symbols"); 23 | 24 | g_env.debug = create_debug(); 25 | } 26 | 27 | void deinit_env() 28 | { 29 | FREE(gen_ator(), g_env.used_rtti_symbols); 30 | FREE(gen_ator(), g_env.frame_ator.buf); 31 | 32 | destroy_debug(g_env.debug); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /code/source/global/env.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GLOBAL_ENV_H 2 | #define REVOLC_GLOBAL_ENV_H 3 | 4 | #include "build.h" 5 | #include "core/memory.h" 6 | 7 | struct AudioSystem; 8 | struct Debug; 9 | struct Editor; 10 | struct Device; 11 | struct PhysWorld; 12 | struct ResBlob; 13 | struct Renderer; 14 | struct NetState; 15 | struct UiContext; 16 | struct World; 17 | 18 | struct SymbolTable; 19 | 20 | typedef struct Env { 21 | struct AudioSystem *audiosystem; 22 | struct Debug *debug; 23 | struct Editor *editor; 24 | struct Device *device; 25 | struct PhysWorld *physworld; 26 | struct Renderer *renderer; 27 | struct ResBlob *resblob; 28 | struct NetState *netstate; 29 | struct UiContext *uicontext; 30 | struct World *world; 31 | 32 | U32 argc; 33 | const char **argv; 34 | const char *game; 35 | 36 | F64 time_from_start; 37 | F64 dt; 38 | 39 | void *game_data; // Pointer to be used by the game module 40 | 41 | Ator frame_ator; 42 | 43 | U32 prod_heap_alloc_count; // Not thread-safe 44 | bool os_allocs_forbidden; 45 | 46 | // All symbols which have been queried using rtti 47 | // This is used to relocate pointers to dll on reload, see `rtti_relocate` 48 | struct SymbolTable *used_rtti_symbols; 49 | } Env; 50 | 51 | extern REVOLC_API Env g_env; 52 | 53 | REVOLC_API void init_env(U32 argc, const char **argv); 54 | REVOLC_API void deinit_env(); 55 | 56 | 57 | #endif // REVOLC_GLOBAL_ENV_H 58 | -------------------------------------------------------------------------------- /code/source/global/module.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GLOBAL_MODULE_H 2 | #define REVOLC_GLOBAL_MODULE_H 3 | 4 | #include "build.h" 5 | #include "core/dll.h" 6 | #include "core/cson.h" 7 | #include "global/cfg.h" 8 | #include "resources/resource.h" 9 | 10 | struct World; 11 | typedef void (*InitModuleImpl)(); 12 | typedef void (*DeinitModuleImpl)(); 13 | typedef void (*WorldGenModuleImpl)(struct World*); 14 | typedef void (*UpdModuleImpl)(); 15 | 16 | typedef struct Module { 17 | Resource res; 18 | char extless_file[MAX_PATH_SIZE]; 19 | char rel_extless_file[MAX_PATH_SIZE]; 20 | char tmp_file[MAX_PATH_SIZE]; 21 | bool is_main_prog_module; // If true, dll == g_main_program_dll 22 | DllHandle dll; 23 | 24 | char worldgen_func_name[MAX_FUNC_NAME_SIZE]; 25 | char init_func_name[MAX_FUNC_NAME_SIZE]; 26 | char deinit_func_name[MAX_FUNC_NAME_SIZE]; 27 | char upd_func_name[MAX_FUNC_NAME_SIZE]; 28 | InitModuleImpl init; // Called during resource load 29 | DeinitModuleImpl deinit; 30 | WorldGenModuleImpl worldgen; 31 | UpdModuleImpl upd; 32 | } PACKED Module; 33 | 34 | // Call module init/deinit for all modules. 35 | // Must be separated from res init because module init is after 36 | // subsystem init, which is after resource init. 37 | REVOLC_API void init_for_modules(); 38 | REVOLC_API void deinit_for_modules(); 39 | REVOLC_API void worldgen_for_modules(World *w); 40 | REVOLC_API void upd_for_modules(); 41 | 42 | // Module _resource_ init/deinit 43 | REVOLC_API void init_module(Module *mod); 44 | REVOLC_API void deinit_module(Module *mod); 45 | 46 | REVOLC_API WARN_UNUSED 47 | Module *blobify_module(struct WArchive *ar, Cson c, bool *err); 48 | REVOLC_API void deblobify_module(WCson *c, struct RArchive *ar); 49 | 50 | #endif // REVOLC_GLOBAL_MODULE_H 51 | -------------------------------------------------------------------------------- /code/source/global/rtti.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GLOBAL_RTTI_H 2 | #define REVOLC_GLOBAL_RTTI_H 3 | 4 | #include "build.h" 5 | 6 | typedef struct MemberRtti { 7 | const char *name; 8 | const char *base_type_name; 9 | U32 ptr_depth; 10 | U32 array_depth; 11 | 12 | U32 offset; 13 | U32 size; 14 | } MemberRtti; 15 | 16 | typedef struct StructRtti { 17 | const char *name; 18 | U32 size; 19 | 20 | MemberRtti *members; 21 | U32 member_count; 22 | } StructRtti; 23 | 24 | // Lookup is done from all loaded Modules 25 | // These are currently quite slow, but that can be easily fixed 26 | 27 | // @todo Rename functions rtti_* -> *_rtti 28 | REVOLC_API 29 | StructRtti *rtti_struct(const char *struct_name); 30 | 31 | REVOLC_API 32 | void *rtti_func_ptr(const char *func_name); 33 | 34 | REVOLC_API 35 | U32 rtti_member_index(const char *struct_name, const char *member_name); 36 | 37 | // e.g. rtti_sym_name(rtti_func_ptr("foo")) == "foo" 38 | REVOLC_API 39 | const char *rtti_sym_name(void *ptr); 40 | 41 | 42 | // Give a valid pointer corresponding to a pointer invalidated by dll reload 43 | // This is prohibited: rtti_relocate(rtti_relocate(ptr)), as symbols can 44 | // theoretically switch addresses with each other on the process of dll reload 45 | REVOLC_API WARN_UNUSED 46 | void * rtti_relocate_sym(void *possibly_invalidated_ptr); 47 | 48 | // Example: 49 | // sym = rtti_func_ptr("foo"); 50 | // while (1) { 51 | // reload_some_dlls(); 52 | // rtti_requery_syms(); 53 | // sym = rtti_relocate_sym(sym); 54 | // } 55 | // Be very careful where to call, as every previously invalidated symbol 56 | // should've been resolved as in the example code above 57 | // So this is prohibited: 58 | // reload_some_dlls(); 59 | // rtti_requery_syms(); 60 | // // sym = rtti_relocate_sym(sym); 61 | // reload_some_dlls(); 62 | // rtti_requery_syms(); 63 | // sym = rtti_relocate_sym(sym); // Probably fails 64 | REVOLC_API 65 | void rtti_requery_syms(); 66 | 67 | #endif // REVOLC_GLOBAL_RTTI_H 68 | -------------------------------------------------------------------------------- /code/source/global/symbol.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_GLOBAL_SYMBOL_H 2 | #define REVOLC_GLOBAL_SYMBOL_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | 7 | typedef struct Symbol { 8 | char module_name[RES_NAME_SIZE]; 9 | char name[SYM_NAME_SIZE]; 10 | void *addr; 11 | void *old_addr; // Address before last dll reload 12 | } Symbol; 13 | 14 | typedef struct SymbolTable { 15 | Symbol symbols[MAX_SYM_COUNT]; 16 | U32 symbol_count; 17 | } SymbolTable; 18 | 19 | #endif // REVOLC_GLOBAL_SYMBOL_H 20 | -------------------------------------------------------------------------------- /code/source/physics/chipmunk_util.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_CHIPMUNK_UTIL_H 2 | #define REVOLC_CHIPMUNK_UTIL_H 3 | 4 | #include "build.h" 5 | #include "core/math.h" 6 | 7 | #include 8 | 9 | static 10 | V2d from_cpv(cpVect v) 11 | { return (V2d) {v.x, v.y}; } 12 | 13 | static 14 | cpVect to_cpv(V2d v) 15 | { return (cpVect) {v.x, v.y}; } 16 | 17 | #endif // REVOLC_CHIPMUNK_UTIL_H 18 | -------------------------------------------------------------------------------- /code/source/physics/physgrid.c: -------------------------------------------------------------------------------- 1 | #include "core/archive.h" 2 | #include "physgrid.h" 3 | 4 | void pack_physgrid(WArchive *ar, const PhysGrid *begin, const PhysGrid *end) 5 | { 6 | for (const PhysGrid *grid = begin; grid != end; ++grid) { 7 | pack_buf(ar, WITH_DEREF_SIZEOF(&grid->def)); 8 | 9 | const U32 mat_grid_size = grid->def.cell_count; 10 | U8 *mat_grid = ALLOC(frame_ator(), mat_grid_size, "mat_grid"); 11 | for (U32 i = 0; i < grid->def.cell_count; ++i) { 12 | mat_grid[i] = grid->cells[i].material; 13 | ensure(mat_grid[i] < 2); 14 | } 15 | pack_buf(ar, mat_grid, mat_grid_size); 16 | } 17 | } 18 | 19 | void unpack_physgrid(RArchive *ar, PhysGrid *begin, PhysGrid *end) 20 | { 21 | for (PhysGrid *grid = begin; grid != end; ++grid) { 22 | unpack_buf(ar, WITH_DEREF_SIZEOF(&grid->def)); 23 | 24 | const U32 mat_grid_size = grid->def.cell_count; 25 | U8 *mat_grid = ALLOC(frame_ator(), mat_grid_size, "mat_grid"); 26 | unpack_buf(ar, mat_grid, mat_grid_size); 27 | for (U32 i = 0; i < grid->def.cell_count; ++i) { 28 | ensure(mat_grid[i] < 2); 29 | grid->cells[i] = (GridCell) { 30 | .material = mat_grid[i], 31 | }; 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /code/source/physics/physgrid.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_PHYSGRID_H 2 | #define REVOLC_PHYSICS_PHYSGRID_H 3 | 4 | #include "build.h" 5 | 6 | // @todo Replace these with core/grid functions 7 | #define GRID_INDEX_W(x, y) \ 8 | ((U32)((floor((x + 0.0)*GRID_RESO_PER_UNIT) + GRID_WIDTH_IN_CELLS/2)) + \ 9 | (U32)((floor((y + 0.0)*GRID_RESO_PER_UNIT) + GRID_WIDTH_IN_CELLS/2)*GRID_WIDTH_IN_CELLS)) 10 | 11 | #define GRID_VEC_W(x, y) \ 12 | (V2i) { \ 13 | (U32)(floor((x + 0.0)*GRID_RESO_PER_UNIT) + GRID_WIDTH_IN_CELLS/2), \ 14 | (U32)(floor((y + 0.0)*GRID_RESO_PER_UNIT) + GRID_WIDTH_IN_CELLS/2) \ 15 | } 16 | 17 | #define GRID_INDEX(x, y) ((x) + (y)*GRID_WIDTH_IN_CELLS) 18 | 19 | #define GRIDCELL_MATERIAL_AIR 0 20 | #define GRIDCELL_MATERIAL_GROUND 1 21 | 22 | //#define USE_FLUIDS 23 | #define SIMPLE_FLUID_SWAP_DYNAMICS 24 | 25 | typedef struct GridCell { 26 | // @todo Rethink division between static/dynamic when fluids are ready 27 | U8 body_portion; 28 | bool is_static_edge; 29 | 30 | U8 material; // Ground or what 31 | 32 | U8 draw_something; // For debugging 33 | #ifdef USE_FLUID_PROTO 34 | // @todo Pack to bitfields when design is stabilized 35 | U8 water; 36 | bool already_swapped; // To prevent double swap in sim, could be temp 37 | U16 pressure; 38 | #ifndef SIMPLE_FLUID_SWAP_DYNAMICS 39 | U16 fluid_area_id; // Used in sim, could be temp 40 | U16 potential; // Used in flow analysis, could be temp 41 | U32 edge_begin_index; // Could be temp 42 | U8 fluid_path_count; // Could be temp 43 | #endif 44 | #endif 45 | } GridCell; 46 | 47 | typedef struct PhysGrid { 48 | GridDef def; 49 | GridCell cells[GRID_CELL_COUNT]; 50 | bool modified; // Set to true after making changes to grid 51 | } PhysGrid; 52 | 53 | struct WArchive; 54 | struct RArchive; 55 | REVOLC_API void pack_physgrid(struct WArchive *ar, const PhysGrid *begin, const PhysGrid *end); 56 | REVOLC_API void unpack_physgrid(struct RArchive *ar, PhysGrid *begin, PhysGrid *end); 57 | 58 | #endif // REVOLC_PHYSICS_PHYSGRID_H 59 | -------------------------------------------------------------------------------- /code/source/physics/physmat.c: -------------------------------------------------------------------------------- 1 | #include "physmat.h" 2 | #include "resources/resblob.h" 3 | 4 | PhysMat *blobify_physmat(struct WArchive *ar, Cson c, bool *err) 5 | { 6 | Cson c_density = cson_key(c, "density"); 7 | Cson c_friction = cson_key(c, "friction"); 8 | Cson c_restitution = cson_key(c, "restitution"); 9 | 10 | if (cson_is_null(c_density)) 11 | RES_ATTRIB_MISSING("density"); 12 | if (cson_is_null(c_friction)) 13 | RES_ATTRIB_MISSING("friction"); 14 | if (cson_is_null(c_restitution)) 15 | RES_ATTRIB_MISSING("restitution"); 16 | 17 | PhysMat mat = { 18 | .density = blobify_floating(c_density, err), 19 | .friction = blobify_floating(c_friction, err), 20 | .restitution = blobify_floating(c_restitution, err), 21 | }; 22 | 23 | if (err && *err) 24 | goto error; 25 | 26 | PhysMat *ptr = warchive_ptr(ar); 27 | pack_buf(ar, &mat, sizeof(mat)); 28 | return ptr; 29 | 30 | error: 31 | SET_ERROR_FLAG(err); 32 | return NULL; 33 | } 34 | 35 | void deblobify_physmat(WCson *c, struct RArchive *ar) 36 | { 37 | PhysMat *mat = rarchive_ptr(ar, sizeof(*mat)); 38 | unpack_advance(ar, sizeof(*mat)); 39 | 40 | wcson_begin_compound(c, "PhysMat"); 41 | 42 | wcson_designated(c, "name"); 43 | deblobify_string(c, mat->res.name); 44 | 45 | wcson_designated(c, "density"); 46 | deblobify_floating(c, mat->density); 47 | 48 | wcson_designated(c, "friction"); 49 | deblobify_floating(c, mat->friction); 50 | 51 | wcson_designated(c, "restitution"); 52 | deblobify_floating(c, mat->restitution); 53 | 54 | wcson_end_compound(c); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /code/source/physics/physmat.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_PHYSMAT_HPP 2 | #define REVOLC_PHYSICS_PHYSMAT_HPP 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "resources/resource.h" 7 | 8 | typedef struct PhysMat { 9 | Resource res; 10 | F64 density; 11 | F64 friction; 12 | F64 restitution; 13 | } PACKED PhysMat; 14 | 15 | REVOLC_API WARN_UNUSED 16 | PhysMat *blobify_physmat(struct WArchive *ar, Cson c, bool *err); 17 | REVOLC_API void deblobify_physmat(WCson *c, struct RArchive *ar); 18 | 19 | #endif // REVOLC_PHYSICS_PHYSMAT_HPP 20 | -------------------------------------------------------------------------------- /code/source/physics/physworld.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_PHYS_WORLD_H 2 | #define REVOLC_PHYSICS_PHYS_WORLD_H 3 | 4 | #include "build.h" 5 | #include "core/grid.h" 6 | #include "physgrid.h" 7 | #include "rigidbody.h" 8 | #include "rigidbodydef.h" 9 | 10 | #include 11 | 12 | typedef enum JointType { 13 | JointType_none, 14 | JointType_slide, 15 | JointType_groove, 16 | JointType_spring, 17 | } JointType; 18 | 19 | typedef struct JointInfo { 20 | JointType type; 21 | cpBody *body_a; 22 | cpBody *body_b; 23 | V2d anchor_a_1; 24 | V2d anchor_a_2; 25 | V2d anchor_b; 26 | F64 min; 27 | F64 max; 28 | F64 length, stiffness, damping; 29 | 30 | cpConstraint *cp_joint; 31 | } JointInfo; 32 | 33 | DECLARE_ARRAY(JointInfo) 34 | 35 | typedef struct PhysWorld { 36 | bool debug_draw; 37 | F64 dt_accum; 38 | F64 simulation_dt; 39 | U32 max_simulation_steps; 40 | F64 smooth_offset; // -1: interpolation, 1: extrapolation 41 | bool simulation_occurred; // Updated every frame 42 | 43 | RigidBody bodies[MAX_RIGIDBODY_COUNT]; 44 | U32 next_body, body_count; 45 | 46 | PhysGrid grid; 47 | 48 | cpSpace *cp_space; 49 | cpBody *cp_ground_body; 50 | RigidBody ground_body; // So that every cpShape has a RigidBody 51 | 52 | Array(JointInfo) used_joints; // Joints used this frame 53 | Array(JointInfo) existing_joints; 54 | } PhysWorld; 55 | 56 | /// @note Sets g_env.physworld 57 | REVOLC_API void create_physworld(); 58 | REVOLC_API void destroy_physworld(); 59 | 60 | // @todo overwrite_rigidbody 61 | REVOLC_API U32 resurrect_rigidbody(const RigidBody *dead); 62 | REVOLC_API void free_rigidbody(Handle h); 63 | REVOLC_API void * storage_rigidbody(); 64 | REVOLC_API RigidBody * get_rigidbody(U32 h); 65 | REVOLC_API Handle rigidbody_handle(RigidBody *b); 66 | 67 | REVOLC_API U32 resurrect_physgrid(const PhysGrid *dead); 68 | REVOLC_API void *storage_physgrid(); 69 | 70 | REVOLC_API void upd_physworld(F64 dt); 71 | REVOLC_API void post_upd_physworld(); 72 | REVOLC_API void upd_phys_rendering(); 73 | 74 | typedef struct QueryInfo { 75 | RigidBody *body; 76 | F64 distance; 77 | } QueryInfo; 78 | 79 | REVOLC_API QueryInfo *query_bodies(U32 *count, V2d pos, F64 max_dist); 80 | 81 | // 0 = empty, 1 = partial, 2 = full 82 | REVOLC_API U32 grid_material_fullness_in_circle(V2d center, F64 rad, U8 material); 83 | // Returns number of changed cells 84 | REVOLC_API U32 set_grid_material_in_circle(V2d center, F64 rad, U8 material); 85 | REVOLC_API GridCell grid_cell(V2i vec); 86 | 87 | // Editor 88 | REVOLC_API void recache_ptrs_to_rigidbodydef(RigidBodyDef *def); 89 | REVOLC_API void recache_ptrs_to_rigidbodydefs(); 90 | 91 | #endif // REVOLC_PHYSICS_PHYS_WORLD_H 92 | -------------------------------------------------------------------------------- /code/source/physics/query.c: -------------------------------------------------------------------------------- 1 | #include "chipmunk_util.h" 2 | #include "global/env.h" 3 | #include "physworld.h" 4 | #include "query.h" 5 | 6 | struct SegmentCbWrapData 7 | { 8 | PhysSegmentCb cb; 9 | void *data; 10 | }; 11 | 12 | internal 13 | void phys_segment_cb_wrap( cpShape *shape, 14 | cpVect point, cpVect normal, 15 | cpFloat fraction, void *void_wrapped_data) 16 | { 17 | cpBody *cp_body = cpShapeGetBody(shape); 18 | RigidBodyCpData *body_cp_data = cpBodyGetUserData(cp_body); 19 | RigidBody *body = body_cp_data->body; 20 | ensure(body); 21 | ensure(body->cp_body == cp_body); 22 | 23 | struct SegmentCbWrapData *wrapped_data = void_wrapped_data; 24 | wrapped_data->cb( body, from_cpv(point), from_cpv(normal), 25 | fraction, wrapped_data->data); 26 | } 27 | 28 | void phys_segment_query(V2d a, V2d b, F64 rad, 29 | PhysSegmentCb cb, void *data) 30 | { 31 | struct SegmentCbWrapData wrapped_data = { 32 | .cb = cb, 33 | .data = data, 34 | }; 35 | cpSpaceSegmentQuery(g_env.physworld->cp_space, 36 | to_cpv(a), to_cpv(b), rad, 37 | CP_SHAPE_FILTER_ALL, 38 | phys_segment_cb_wrap, 39 | &wrapped_data); 40 | } 41 | -------------------------------------------------------------------------------- /code/source/physics/query.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_QUERY_H 2 | #define REVOLC_PHYSICS_QUERY_H 3 | 4 | #include "build.h" 5 | 6 | struct RigidBody; 7 | 8 | // @todo Wrap 9 | typedef void (*PhysSegmentCb)(RigidBody *body, V2d point, V2d normal, F64 fraction, void *data); 10 | 11 | REVOLC_API void phys_segment_query( V2d a, V2d b, F64 rad, 12 | PhysSegmentCb cb, void *data); 13 | 14 | #endif // REVOLC_PHYSICS_QUERY_H 15 | -------------------------------------------------------------------------------- /code/source/physics/rigidbodydef.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_RIGIDBODYDEF_H 2 | #define REVOLC_PHYSICS_RIGIDBODYDEF_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | #include "resources/resource.h" 7 | #include "shapes.h" 8 | 9 | typedef struct RigidBodyDef { 10 | Resource res; 11 | 12 | char mat_name[RES_NAME_SIZE]; 13 | bool disable_rot; 14 | bool is_static; 15 | 16 | Circle circles[MAX_SHAPES_PER_BODY]; 17 | U32 circle_count; 18 | Poly polys[MAX_SHAPES_PER_BODY]; 19 | U32 poly_count; 20 | } PACKED RigidBodyDef; 21 | 22 | REVOLC_API WARN_UNUSED 23 | RigidBodyDef *blobify_rigidbodydef(struct WArchive *ar, Cson c, bool *err); 24 | REVOLC_API void deblobify_rigidbodydef(WCson *c, struct RArchive *ar); 25 | 26 | #endif // REVOLC_PHYSICS_RIGIDBODYDEF_H 27 | -------------------------------------------------------------------------------- /code/source/physics/shapes.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_PHYSICS_SHAPES_H 2 | #define REVOLC_PHYSICS_SHAPES_H 3 | 4 | #include "build.h" 5 | #include "core/math.h" 6 | 7 | typedef struct Circle { 8 | V2d pos; 9 | F64 rad; 10 | } Circle; 11 | 12 | /// @todo Concave support. 13 | typedef struct Poly { 14 | V2d v[MAX_POLY_VERTEX_COUNT]; 15 | U32 v_count; 16 | } Poly; 17 | 18 | #endif // REVOLC_PHYSICS_SHAPES_H 19 | -------------------------------------------------------------------------------- /code/source/resources/resource.c: -------------------------------------------------------------------------------- 1 | #include "resource.h" 2 | 3 | ResType str_to_restype(const char *str) 4 | { 5 | #define RESOURCE(x, init, deinit, blobify, deblobify, recache) \ 6 | if (!strcmp(#x, str)) \ 7 | return ResType_ ## x; 8 | # include "resources.def" 9 | #undef RESOURCE 10 | return ResType_None; 11 | } 12 | 13 | const char * restype_to_str(ResType type) 14 | { 15 | #define RESOURCE(x, init, deinit, blobify, deblobify, recache) \ 16 | if (ResType_ ## x == type) \ 17 | return #x; 18 | # include "resources.def" 19 | #undef RESOURCE 20 | return "None"; 21 | } 22 | -------------------------------------------------------------------------------- /code/source/resources/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_RESOURCES_RESOURCE_H 2 | #define REVOLC_RESOURCES_RESOURCE_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | 7 | // @todo Don't use this for members. Use RelPtr in core/ptr.h 8 | typedef U64 BlobOffset; 9 | 10 | #define RES_ATTRIB_MISSING(name) \ 11 | do { critical_print("Attrib '%s' missing", name); goto error; } while(0) 12 | 13 | typedef enum { 14 | ResType_None, 15 | #define RESOURCE(x, init, deinit, blobify, deblobify, recache) ResType_ ## x, 16 | # include "resources.def" 17 | #undef RESOURCE 18 | ResType_last 19 | } ResType; 20 | 21 | ResType str_to_restype(const char *str); 22 | const char * restype_to_str(ResType type); 23 | 24 | // @todo Should be hash of resource name and type for extremely fast lookup & 25 | // small memory footprint 26 | typedef struct ResId { 27 | char name[RES_NAME_SIZE]; 28 | ResType type; 29 | } ResId; 30 | 31 | 32 | struct ResBlob; 33 | struct BlobBuf; 34 | struct RuntimeResource; 35 | 36 | typedef struct Resource { 37 | ResType type; 38 | char name[RES_NAME_SIZE]; 39 | struct ResBlob *blob; 40 | U32 size; // Size of actual resource struct + appended rel_ptr data 41 | 42 | // Dev info 43 | U32 res_file_index; 44 | struct Resource *substitute; // If set, this resource is substituted by another (modified) resource 45 | struct RuntimeResource *runtime_owner; // If set, this is a missing/created/modified resource 46 | } PACKED Resource; 47 | 48 | // RuntimeResource are created on demand to separately allocated 49 | // chunks, using the conventional blob creation facility. 50 | // 51 | // Can't use just a single Resource represent runtime ones, as then 52 | // pointers can't be resolved when reloading updated blob. 53 | // 54 | // RuntimeResources are used for missing and edited resources 55 | typedef void (*RtResFree)(Resource *res); 56 | typedef struct RuntimeResource { 57 | Resource *res; 58 | struct RuntimeResource *next; 59 | 60 | bool needs_saving; 61 | // Allocated RelPtrs in the resource 62 | # define MAX_RESOURCE_REL_PTR_COUNT 4 63 | RelPtr *allocated_ptrs[MAX_RESOURCE_REL_PTR_COUNT]; 64 | U32 allocated_sizes[MAX_RESOURCE_REL_PTR_COUNT]; 65 | } RuntimeResource; 66 | 67 | #endif // REVOLC_RESOURCES_RESOURCE_H 68 | -------------------------------------------------------------------------------- /code/source/resources/resources.def: -------------------------------------------------------------------------------- 1 | #ifdef HEADERS 2 | 3 | #include "animation/armature.h" 4 | #include "animation/clip.h" 5 | #include "audio/sound.h" 6 | #include "game/nodegroupdef.h" 7 | #include "game/nodetype.h" 8 | #include "global/module.h" 9 | #include "physics/physmat.h" 10 | #include "physics/rigidbodydef.h" 11 | #include "visual/compdef.h" 12 | #include "visual/font.h" 13 | #include "visual/mesh.h" 14 | #include "visual/model.h" 15 | #include "visual/shadersource.h" 16 | #include "visual/texture.h" 17 | 18 | #else 19 | 20 | // @todo Init functions should be called resurrect_* 21 | RESOURCE(Module, init_module, deinit_module, blobify_module, deblobify_module, NULL) 22 | RESOURCE(Texture, NULL, NULL, blobify_texture, deblobify_texture, NULL) 23 | RESOURCE(Mesh, NULL, NULL, blobify_mesh, deblobify_mesh, recache_ptrs_to_meshes) 24 | RESOURCE(Model, NULL, NULL, blobify_model, deblobify_model, NULL) 25 | RESOURCE(CompDef, NULL, NULL, blobify_compdef, deblobify_compdef, NULL) 26 | RESOURCE(ShaderSource, init_shadersource, deinit_shadersource, blobify_shadersource, deblobify_shadersource, NULL) 27 | RESOURCE(RigidBodyDef, NULL, NULL, blobify_rigidbodydef, deblobify_rigidbodydef, recache_ptrs_to_rigidbodydefs) 28 | RESOURCE(PhysMat, NULL, NULL, blobify_physmat, deblobify_physmat, NULL) 29 | RESOURCE(NodeType, init_nodetype, NULL, blobify_nodetype, deblobify_nodetype, NULL) 30 | RESOURCE(NodeGroupDef, init_nodegroupdef, deinit_nodegroupdef, blobify_nodegroupdef, deblobify_nodegroupdef, NULL) 31 | RESOURCE(Sound, NULL, NULL, blobify_sound, deblobify_sound, NULL) 32 | RESOURCE(Armature, NULL, NULL, blobify_armature, deblobify_armature, recache_ptrs_to_armatures) 33 | RESOURCE(Clip, init_clip, NULL, blobify_clip, deblobify_clip, recache_ptrs_to_clips) 34 | RESOURCE(Font, NULL, NULL, blobify_font, deblobify_font, NULL) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /code/source/rts/grid.c: -------------------------------------------------------------------------------- 1 | #include "grid.h" 2 | #include "visual/renderer.h" 3 | 4 | 5 | void upd_rtsgrid(RtsGrid *grid) 6 | { 7 | Texel *rgrid = g_env.renderer->grid_ddraw_data; 8 | for (U32 i = 0; i < GRID_CELL_COUNT; ++i) { 9 | if (grid->cells[i].assigned) { 10 | rgrid[i].r = 255; 11 | rgrid[i].g = 255; 12 | rgrid[i].b = 255; 13 | rgrid[i].a = 255; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /code/source/rts/grid.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_RTS_GRID_H 2 | #define REVOLC_RTS_GRID_H 3 | 4 | #include "build.h" 5 | #include "global/cfg.h" 6 | 7 | typedef struct RtsGridCell { 8 | bool assigned; 9 | } RtsGridCell; 10 | 11 | typedef struct RtsGrid { 12 | RtsGridCell cells[GRID_CELL_COUNT]; 13 | } RtsGrid; 14 | 15 | MOD_API void upd_rtsgrid(RtsGrid *grid_begin, RtsGrid *grid_end); 16 | 17 | #endif // REVOLC_RTS_GRID_H 18 | -------------------------------------------------------------------------------- /code/source/rts/minion.c: -------------------------------------------------------------------------------- 1 | #include "animation/clip.h" 2 | #include "animation/joint.h" 3 | #include "audio/audiosystem.h" 4 | #include "core/archive.h" 5 | #include "core/debug_print.h" 6 | #include "core/ensure.h" 7 | #include "core/grid.h" 8 | #include "core/memory.h" 9 | #include "core/random.h" 10 | #include "core/scalar.h" 11 | #include "global/env.h" 12 | #include "game/world.h" 13 | #include "minion.h" 14 | #include "physics/physworld.h" 15 | #include "physics/query.h" 16 | #include "platform/device.h" 17 | #include "resources/resblob.h" 18 | #include "visual/renderer.h" // screen_to_world_point, camera 19 | 20 | 21 | void upd_minion(Minion *minion) 22 | { 23 | if (!rts_env()->authority) 24 | return; 25 | 26 | F64 dt = g_env.world->dt; 27 | minion->pos.x += 0.5*dt*(ABS(sin(minion->pos.x)) + 0.1); 28 | } 29 | 30 | void pack_minion(WArchive *ar, const Minion *begin, const Minion *end) 31 | { // @todo Generate this function 32 | for (const Minion *minion = begin; minion != end; ++minion) { 33 | pack_f64(ar, &minion->pos.x); 34 | pack_f64(ar, &minion->pos.y); 35 | pack_f32(ar, &minion->health); 36 | } 37 | } 38 | 39 | void unpack_minion(RArchive *ar, Minion *begin, Minion *end) 40 | { // @todo Generate this function 41 | for (Minion *minion = begin; minion != end; ++minion) { 42 | unpack_f64(ar, &minion->pos.x); 43 | unpack_f64(ar, &minion->pos.y); 44 | unpack_f32(ar, &minion->health); 45 | } 46 | } 47 | 48 | void upd_selection(Selection *sel) 49 | { 50 | if (!sel->selected) 51 | continue; 52 | T3d tf = {{1, 1, 1}, identity_qd(), sel->pos}; 53 | drawcmd_model( tf, 54 | (Model*)res_by_name(g_env.resblob, ResType_Model, "unitquad"), 55 | (Color){1, 1, 1, 0.2}, 0, 0.0); 56 | } 57 | 58 | Handle resurrect_selection(const Selection *dead) 59 | { return insert_stbl(Selection)(&rts_env()->selection_nodes, *dead); } 60 | 61 | void free_selection(Handle h) 62 | { remove_stbl(Selection)(&rts_env()->selection_nodes, h); } 63 | 64 | void *storage_selection() 65 | { return rts_env()->selection_nodes.array; } 66 | -------------------------------------------------------------------------------- /code/source/rts/minion.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_RTS_MINION_H 2 | #define REVOLC_RTS_MINION_H 3 | 4 | #include "core/vector.h" 5 | #include "build.h" 6 | 7 | struct WArchive; 8 | struct RArchive; 9 | typedef struct Minion { 10 | V3d pos; 11 | F32 health; 12 | } Minion; 13 | 14 | MOD_API void upd_minion(Minion *minion); 15 | MOD_API void pack_minion(struct WArchive *ar, const Minion *begin, const Minion *end); 16 | MOD_API void unpack_minion(struct RArchive *ar, Minion *begin, Minion *end); 17 | 18 | typedef struct Selection { 19 | bool selected; 20 | V3d pos; 21 | } Selection; 22 | // @todo Generate 23 | #define ORIG_TYPE_Selection Selection 24 | 25 | MOD_API Handle resurrect_selection(const Selection *dead); 26 | MOD_API void free_selection(Handle h); 27 | MOD_API void *storage_selection(); 28 | 29 | #endif // REVOLC_RTS_MINION_H 30 | -------------------------------------------------------------------------------- /code/source/rts/net.h: -------------------------------------------------------------------------------- 1 | #ifndef RTS_NET_H 2 | #define RTS_NET_H 3 | 4 | #include "build.h" 5 | 6 | typedef enum RtsMsg { 7 | RtsMsg_chat = 1, 8 | RtsMsg_base, 9 | RtsMsg_delta, 10 | // Debug 11 | RtsMsg_brush_action, 12 | RtsMsg_spawn_action, 13 | } RtsMsg; 14 | 15 | typedef struct RtsMsgHeader { 16 | RtsMsg type; 17 | //F64 time; // Game time 18 | } PACKED RtsMsgHeader; 19 | 20 | typedef struct BrushAction { // @todo Range and precision "attributes" 21 | V2d pos; 22 | F64 size; 23 | U8 material; 24 | } BrushAction; 25 | 26 | typedef struct SpawnAction { 27 | char name[RES_NAME_SIZE]; 28 | V2d pos; 29 | } SpawnAction; 30 | 31 | 32 | MOD_API void send_rts_msg(RtsMsg type, void *data, U32 data_size); 33 | MOD_API void local_brush_action(BrushAction *action); 34 | MOD_API void brush_action(BrushAction *action); 35 | MOD_API void local_spawn_action(SpawnAction *action); 36 | MOD_API void spawn_action(SpawnAction *action); 37 | 38 | MOD_API void upd_rts_net(); 39 | 40 | // Internal 41 | MOD_API void make_and_save_base(); 42 | MOD_API void resurrect_and_save_base(RArchive *ar); 43 | MOD_API void make_world_delta(WArchive *ar); 44 | MOD_API void resurrect_world_delta(RArchive *ar); 45 | 46 | #endif // RTS_NET_H 47 | -------------------------------------------------------------------------------- /code/source/rts/rts.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_RTS_RTS_H 2 | #define REVOLC_RTS_RTS_H 3 | 4 | #include "build.h" 5 | #include "core/sparsetable.h" 6 | #include "rts/minion.h" 7 | 8 | #define RTS_AUTHORITY_PORT 19995 9 | #define RTS_CLIENT_PORT 19996 10 | #define RTS_BASE_SIZE (1024*1024*5) 11 | #define RTS_MAX_BASE_HISTORY_COUNT 10 12 | #define RTS_DELTA_INTERVAL 0.1 13 | 14 | DECLARE_SPARSETABLE(Selection); 15 | 16 | // @todo Replace net code with almost identical code in game/net.h 17 | 18 | typedef struct WorldBaseState { 19 | U32 seq; 20 | U8 data[RTS_BASE_SIZE] ALIGNED(MAX_ALIGNMENT); 21 | U32 size; 22 | } WorldBaseState; 23 | 24 | typedef struct RtsEnv { 25 | UdpPeer *peer; 26 | bool authority; // Do we have authority over the game world 27 | F64 game_time; // Same at client and server 28 | 29 | SparseTbl(Selection) selection_nodes; 30 | 31 | // @todo Move to RtsNet struct 32 | F64 world_upd_time; // Send/recv time 33 | F64 stats_timer; 34 | U32 world_seq; // Incremented at every delta 35 | WorldBaseState bases[RTS_MAX_BASE_HISTORY_COUNT]; 36 | U32 cur_base_ix; 37 | } RtsEnv; 38 | 39 | MOD_API RtsEnv *rts_env(); 40 | MOD_API void upd_rts(); 41 | 42 | #endif // REVOLC_RTS_RTS_H 43 | -------------------------------------------------------------------------------- /code/source/rts/unity.c: -------------------------------------------------------------------------------- 1 | #define MOD_DLL_BUILD 2 | 3 | #include "rts.c" 4 | #include "minion.c" 5 | #include "net.c" 6 | #include "grid.c" 7 | 8 | #ifndef CODEGEN 9 | # include "gen_rtti.c" 10 | #endif 11 | -------------------------------------------------------------------------------- /code/source/ui/uicontext.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_UI_UICONTEXT_H 2 | #define REVOLC_UI_UICONTEXT_H 3 | 4 | #include "build.h" 5 | #include "gui.h" 6 | 7 | typedef struct ButtonState { 8 | bool pressed, down, released; 9 | } ButtonState; 10 | 11 | struct Font; 12 | 13 | Color panel_color(); 14 | Color inactive_color(); 15 | Color darken_color(Color c); 16 | Color highlight_color(Color c); 17 | Color outline_color(Color c); 18 | const struct Font *gui_font(); 19 | 20 | typedef struct UiContext_Dev { 21 | // @todo Remove stuff duplicated respect to gui.h 22 | V2i cursor_pos; 23 | V2i prev_cursor_pos; 24 | V2i cursor_delta; 25 | ButtonState lmb; 26 | ButtonState mmb; 27 | ButtonState rmb; 28 | bool shift_down; 29 | bool snap_to_closest; 30 | bool g_pressed; 31 | bool r_pressed; 32 | bool s_pressed; 33 | bool toggle_select_all; 34 | bool toggle_play; 35 | bool delete; 36 | 37 | GuiId grabbing; // Set by editor elements 38 | GuiId rotating; // Set by editor elements 39 | GuiId scaling; // Set by editor elements 40 | } UiContext_Dev; 41 | 42 | // @todo Rename to something like UiState -- gui is already *Context 43 | typedef struct UiContext { 44 | UiContext_Dev dev; 45 | 46 | GuiContext *gui; 47 | } UiContext; 48 | 49 | // Sets g_env.uicontext 50 | REVOLC_API void create_uicontext(); 51 | REVOLC_API void destroy_uicontext(); 52 | 53 | // Update cursor position etc. 54 | REVOLC_API void begin_ui_frame(); 55 | REVOLC_API void end_ui_frame(); 56 | 57 | REVOLC_API bool world_has_input(); 58 | 59 | #endif // REVOLC_UI_UICONTEXT_H 60 | -------------------------------------------------------------------------------- /code/source/unity.c: -------------------------------------------------------------------------------- 1 | #include "animation/armature.c" 2 | #include "animation/clip.c" 3 | #include "animation/clipinst.c" 4 | #include "animation/joint.c" 5 | #include "audio/audiosystem.c" 6 | #include "audio/sound.c" 7 | #include "core/archive.c" 8 | #include "core/array.c" 9 | #include "core/basic.c" 10 | #include "core/debug.c" 11 | #include "core/device.c" 12 | #include "core/gl.c" 13 | #include "core/grid.c" 14 | #include "core/hashtable.c" 15 | #include "core/cson.c" 16 | #include "core/memory.c" 17 | #include "core/math.c" 18 | #include "core/socket.c" 19 | #include "core/sparsetable.c" 20 | #include "core/udp.c" 21 | #include "editor/editor.c" 22 | #include "editor/editor_util.c" 23 | #include "game/aitest.c" 24 | #include "game/net.c" 25 | #include "game/nodegroupdef.c" 26 | #include "game/nodetype.c" 27 | #include "game/game.c" 28 | #include "game/world.c" 29 | #include "game/worldgen.c" 30 | #include "global/env.c" 31 | #include "global/module.c" 32 | #include "global/rtti.c" 33 | #include "main.c" 34 | #include "physics/physgrid.c" 35 | #include "physics/physmat.c" 36 | #include "physics/physworld.c" 37 | #include "physics/query.c" 38 | #include "physics/rigidbody.c" 39 | #include "physics/rigidbodydef.c" 40 | #include "resources/resblob.c" 41 | #include "resources/resource.c" 42 | #include "ui/uicontext.c" 43 | #include "ui/gui.c" 44 | #include "visual/compdef.c" 45 | #include "visual/compentity.c" 46 | #include "visual/ddraw.c" 47 | #include "visual/font.c" 48 | #include "visual/mesh.c" 49 | #include "visual/model.c" 50 | #include "visual/modelentity.c" 51 | #include "visual/renderer.c" 52 | #include "visual/shadersource.c" 53 | #include "visual/texture.c" 54 | #include "visual/vao.c" 55 | 56 | #ifndef CODEGEN 57 | # if PLATFORM == PLATFORM_LINUX 58 | # include "core/linux.c" 59 | # elif PLATFORM == PLATFORM_WINDOWS 60 | # include "core/windows.c" 61 | # else 62 | # error "Unknown platform" 63 | # endif 64 | # include "global/gen_rtti.c" 65 | #endif 66 | -------------------------------------------------------------------------------- /code/source/visual/atlas.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_ATLAS_H 2 | #define REVOLC_VISUAL_ATLAS_H 3 | 4 | #include "build.h" 5 | #include "core/math.h" 6 | 7 | typedef struct AtlasUv { 8 | V3f uv; 9 | V2f scale; 10 | } AtlasUv; 11 | 12 | #endif // REVOLC_VISUAL_ATLAS_H 13 | -------------------------------------------------------------------------------- /code/source/visual/compdef.c: -------------------------------------------------------------------------------- 1 | #include "compdef.h" 2 | 3 | CompDef *blobify_compdef(struct WArchive *ar, Cson c, bool *err) 4 | { 5 | Cson c_armature = cson_key(c, "armature"); 6 | Cson c_subs = cson_key(c, "subs"); 7 | 8 | if (cson_is_null(c_armature)) 9 | RES_ATTRIB_MISSING("armature"); 10 | if (cson_is_null(c_subs)) 11 | RES_ATTRIB_MISSING("subs"); 12 | 13 | CompDef def = {}; 14 | fmt_str(def.armature_name, sizeof(def.armature_name), "%s", 15 | blobify_string(c_armature, err)); 16 | if (cson_member_count(c_subs) > MAX_SUBENTITY_COUNT) { 17 | critical_print("Too many subs: %i > %i", 18 | cson_member_count(c_subs), MAX_SUBENTITY_COUNT); 19 | goto error; 20 | } 21 | for (U32 sub_i = 0; sub_i < cson_member_count(c_subs); ++sub_i) { 22 | Cson c_sub = cson_member(c_subs, sub_i); 23 | 24 | Cson c_entity = cson_key(c_sub, "entity"); 25 | Cson c_joint = cson_key(c_sub, "joint"); 26 | Cson c_offset = cson_key(c_sub, "offset"); 27 | 28 | if (cson_is_null(c_entity)) 29 | RES_ATTRIB_MISSING("entity"); 30 | if (cson_is_null(c_joint)) 31 | RES_ATTRIB_MISSING("joint"); 32 | if (cson_is_null(c_offset)) 33 | RES_ATTRIB_MISSING("offset"); 34 | 35 | CompDef_Sub *sub = &def.subs[sub_i]; 36 | fmt_str(sub->entity_name, sizeof(sub->entity_name), "%s", 37 | blobify_string(c_entity, err)); 38 | fmt_str(sub->joint_name, sizeof(sub->joint_name), "%s", 39 | blobify_string(c_joint, err)); 40 | sub->offset = t3d_to_t3f(blobify_t3(c_offset, err)); 41 | ++def.sub_count; 42 | } 43 | 44 | if (err && *err) 45 | goto error; 46 | 47 | CompDef *ptr = warchive_ptr(ar); 48 | pack_buf(ar, &def, sizeof(def)); 49 | return ptr; 50 | 51 | error: 52 | SET_ERROR_FLAG(err); 53 | return NULL; 54 | } 55 | 56 | void deblobify_compdef(WCson *c, struct RArchive *ar) 57 | { 58 | CompDef *def = rarchive_ptr(ar, sizeof(*def)); 59 | unpack_advance(ar, sizeof(*def)); 60 | 61 | wcson_begin_compound(c, "CompDef"); 62 | 63 | wcson_designated(c, "name"); 64 | deblobify_string(c, def->res.name); 65 | 66 | wcson_designated(c, "armature"); 67 | deblobify_string(c, def->armature_name); 68 | 69 | wcson_designated(c, "subs"); 70 | wcson_begin_initializer(c); 71 | for (U32 i = 0; i < def->sub_count; ++i) { 72 | CompDef_Sub sub = def->subs[i]; 73 | 74 | wcson_begin_initializer(c); 75 | 76 | wcson_designated(c, "entity"); 77 | deblobify_string(c, sub.entity_name); 78 | 79 | wcson_designated(c, "joint"); 80 | deblobify_string(c, sub.joint_name); 81 | 82 | wcson_designated(c, "offset"); 83 | deblobify_t3(c, t3f_to_t3d(sub.offset)); 84 | 85 | wcson_end_initializer(c); 86 | } 87 | wcson_end_initializer(c); 88 | 89 | wcson_end_compound(c); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /code/source/visual/compdef.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_COMPDEF_H 2 | #define REVOLC_VISUAL_COMPDEF_H 3 | 4 | #include "build.h" 5 | #include "resources/resource.h" 6 | 7 | typedef struct CompDef_Sub { 8 | char entity_name[RES_NAME_SIZE]; 9 | char joint_name[RES_NAME_SIZE]; 10 | /// @todo Shouldn't we cache joint id for fast CompEntity creation? 11 | T3f offset; 12 | } CompDef_Sub; 13 | 14 | // Definition for CompEntity 15 | // CompEntity and CompDef are analoguous with ModelEntity and Model 16 | typedef struct CompDef { 17 | Resource res; 18 | char armature_name[RES_NAME_SIZE]; 19 | 20 | CompDef_Sub subs[MAX_SUBENTITY_COUNT]; 21 | U32 sub_count; 22 | } PACKED CompDef; 23 | 24 | REVOLC_API WARN_UNUSED 25 | CompDef *blobify_compdef(struct WArchive *ar, Cson c, bool *err); 26 | REVOLC_API void deblobify_compdef(WCson *c, struct RArchive *ar); 27 | 28 | #endif // REVOLC_VISUAL_COMPDEF_H 29 | -------------------------------------------------------------------------------- /code/source/visual/compentity.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_COMPOUNDENTITY_H 2 | #define REVOLC_VISUAL_COMPOUNDENTITY_H 3 | 4 | #include "animation/armature.h" 5 | #include "animation/joint.h" 6 | #include "compdef.h" 7 | #include "build.h" 8 | #include "core/math.h" 9 | 10 | typedef enum { 11 | VEntityType_model, 12 | VEntityType_comp, 13 | } VEntityType; 14 | 15 | typedef struct SubEntity { 16 | T3f offset; // Relative to joint 17 | U32 handle; // Owned handle to the entity 18 | VEntityType type; 19 | JointId joint_id; 20 | } SubEntity; 21 | 22 | // Compound entity 23 | // Contains other entities positioned by armature 24 | typedef struct CompEntity { 25 | char def_name[RES_NAME_SIZE]; 26 | T3d tf; 27 | bool allocated; 28 | 29 | JointPoseArray pose; // Relative to bind offsets 30 | 31 | // Local 32 | T3d smoothing_delta; 33 | F32 smoothing_phase; // 1 at start of smoothing, 0 when done 34 | 35 | // Cached 36 | Armature *armature; 37 | SubEntity subs[MAX_SUBENTITY_COUNT]; 38 | U8 sub_count; 39 | } CompEntity; 40 | 41 | REVOLC_API void init_compentity(CompEntity *data); 42 | struct WArchive; 43 | struct RArchive; 44 | REVOLC_API void pack_compentity( struct WArchive *ar, 45 | const CompEntity *begin, 46 | const CompEntity *end); 47 | REVOLC_API void unpack_compentity( struct RArchive *ar, 48 | CompEntity *begin, 49 | CompEntity *end); 50 | 51 | REVOLC_API SubEntity create_subentity(const Armature *a, CompDef_Sub sub); 52 | REVOLC_API void destroy_subentity(SubEntity e); 53 | 54 | REVOLC_API void calc_global_pose(T3d *global_pose, const CompEntity *e); 55 | 56 | #endif // REVOLC_VISUAL_COMPOUNDENTITY_H 57 | -------------------------------------------------------------------------------- /code/source/visual/ddraw.c: -------------------------------------------------------------------------------- 1 | #include "ddraw.h" 2 | #include "global/env.h" 3 | #include "renderer.h" 4 | 5 | void ddraw_poly(Color c, V3d *poly, U32 count, S32 layer) 6 | { 7 | Renderer *r = g_env.renderer; 8 | 9 | if (r->ddraw_v_count + count > MAX_DEBUG_DRAW_VERTICES) 10 | critical_print("ddraw_poly: Too many vertices"); 11 | if (r->ddraw_i_count + count > MAX_DEBUG_DRAW_INDICES) 12 | critical_print("ddraw_poly: Too many indices"); 13 | 14 | Texture *white = 15 | (Texture*)res_by_name( 16 | g_env.resblob, 17 | ResType_Texture, 18 | "white"); 19 | V3f atlas_uv = white->atlas_uv.uv; 20 | atlas_uv.x += 0.5*white->reso.x/TEXTURE_ATLAS_WIDTH; 21 | atlas_uv.y += 0.5*white->reso.y/TEXTURE_ATLAS_WIDTH; 22 | 23 | U32 start_index = r->ddraw_v_count; 24 | for (U32 i = 0; i < count; ++i) { 25 | TriMeshVertex v = default_vertex(); 26 | v.pos = v3d_to_v3f(poly[i]); 27 | v.uv = atlas_uv; 28 | v.outline_uv = (V2f) {0.5, 0.5}; 29 | v.color = c; 30 | v.outline_color = c; 31 | r->ddraw_v[r->ddraw_v_count++] = v; 32 | } 33 | 34 | U32 start_i_index = r->ddraw_i_count; 35 | for (U32 i = 0; i < count - 2; ++i) { 36 | r->ddraw_i[r->ddraw_i_count++] = 0; 37 | r->ddraw_i[r->ddraw_i_count++] = i + 1; 38 | r->ddraw_i[r->ddraw_i_count++] = i + 2; 39 | } 40 | 41 | drawcmd( identity_t3d(), 42 | &r->ddraw_v[start_index], count, 43 | &r->ddraw_i[start_i_index], (count - 2)*3, 44 | ((Texture*)res_by_name(g_env.resblob, ResType_Texture, "white"))->atlas_uv, 45 | c, 46 | c, 47 | layer, 48 | 0.0, 49 | true); 50 | } 51 | 52 | void ddraw_circle(Color c, V3d p, F64 rad, S32 layer) 53 | { 54 | const U32 v_count = 15; 55 | V3d v[v_count]; 56 | for (U32 i = 0; i < v_count; ++i) { 57 | F64 a = i*3.141*2.0/v_count; 58 | v[i].x = p.x + cos(a)*rad; 59 | v[i].y = p.y + sin(a)*rad; 60 | v[i].z = 0.0; 61 | } 62 | ddraw_poly(c, v, v_count, layer); 63 | } 64 | 65 | void ddraw_line(Color c, V3d a, V3d b, F64 w, S32 layer) 66 | { 67 | F64 scale = screen_to_world_size((V2i) {1, 0}).x*w; 68 | F64 rot = atan2(a.y - b.y, a.x - b.x); 69 | F64 c1 = cos(rot - PI/2)*scale; 70 | F64 s1 = sin(rot - PI/2)*scale; 71 | F64 c2 = cos(rot + PI/2)*scale; 72 | F64 s2 = sin(rot + PI/2)*scale; 73 | V3d quad[4] = { 74 | {a.x + c1, a.y + s1, a.z}, 75 | {b.x + c1, b.y + s1, b.z}, 76 | {b.x + c2, b.y + s2, b.z}, 77 | {a.x + c2, a.y + s2, a.z}, 78 | }; 79 | ddraw_poly(c, quad, 4, layer); 80 | } 81 | 82 | void ddraw_dot(Color c, V3d p, F64 w, S32 layer) 83 | { 84 | F64 rad = 0.5*screen_to_world_size((V2i) {1, 0}).x*w; 85 | V3d quad[4] = { 86 | {p.x - rad, p.y - rad}, 87 | {p.x + rad, p.y - rad}, 88 | {p.x + rad, p.y + rad}, 89 | {p.x - rad, p.y + rad}, 90 | }; 91 | ddraw_poly(c, quad, 4, layer); 92 | } 93 | -------------------------------------------------------------------------------- /code/source/visual/ddraw.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_DDRAW_H 2 | #define REVOLC_VISUAL_DDRAW_H 3 | 4 | #include "build.h" 5 | 6 | REVOLC_API void ddraw_poly(Color c, V3d *poly, U32 count, S32 layer); 7 | REVOLC_API void ddraw_circle(Color c, V3d p, F64 rad, S32 layer); 8 | 9 | // Sizes in pixels 10 | REVOLC_API void ddraw_line(Color c, V3d a, V3d b, F64 w, S32 layer); 11 | REVOLC_API void ddraw_dot(Color c, V3d p, F64 w, S32 layer); 12 | 13 | #endif // REVOLC_VISUAL_DDRAW_H 14 | -------------------------------------------------------------------------------- /code/source/visual/font.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_FONT_H 2 | #define REVOLC_VISUAL_FONT_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "resources/resource.h" 7 | 8 | #include 9 | 10 | #define FONT_CHAR_BEGIN 32 11 | #define FONT_CHAR_COUNT 96 // ASCII 32..126 12 | #define FONT_CHAR_END (FONT_CHAR_BEGIN + FONT_CHAR_COUNT) 13 | 14 | typedef struct Font { 15 | Resource res; 16 | 17 | char rel_file[MAX_PATH_SIZE]; 18 | 19 | // Renderer sets 20 | AtlasUv atlas_uv; 21 | 22 | stbtt_packedchar chars[FONT_CHAR_COUNT]; 23 | // @todo Should probably have rgba bitmap, or ttf data. 24 | // Monochrome bitmap is no good for anyone. 25 | REL_PTR(U8) bitmap_offset; 26 | V2i bitmap_reso; 27 | F32 px_height; 28 | } PACKED Font; 29 | 30 | REVOLC_API WARN_UNUSED 31 | Font *blobify_font(struct WArchive *ar, Cson c, bool *err); 32 | REVOLC_API void deblobify_font(WCson *c, struct RArchive *ar); 33 | 34 | Texel * malloc_rgba_font_bitmap(const Font *font); 35 | 36 | // Mesh is in OpenGL-like coordinates (but px sized) 37 | // Origin is at upper left corner of the text 38 | REVOLC_API WARN_UNUSED 39 | U32 text_mesh( V2i *size, 40 | TriMeshVertex *verts, // len(text)*4 41 | MeshIndexType *inds, // len(text)*6 42 | const Font *font, 43 | const char *text); 44 | 45 | V2i calc_text_mesh_size(const Font *font, const char *text); 46 | 47 | #endif // REVOLC_VISUAL_FONT_H 48 | -------------------------------------------------------------------------------- /code/source/visual/mesh.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_MESH_H 2 | #define REVOLC_VISUAL_MESH_H 3 | 4 | #include "build.h" 5 | #include "core/color.h" 6 | #include "core/basic.h" 7 | #include "core/math.h" 8 | #include "core/cson.h" 9 | #include "resources/resource.h" 10 | #include "core/gl.h" 11 | 12 | typedef enum { MeshType_tri } MeshType_enum; 13 | typedef U32 MeshType; 14 | typedef U32 MeshIndexType; 15 | #define MESH_INDEX_GL_TYPE GL_UNSIGNED_INT 16 | 17 | typedef struct VertexAttrib { 18 | const GLchar *name; 19 | GLint size; 20 | GLenum type; 21 | bool floating; // False for integer attribs 22 | GLboolean normalized; 23 | U64 offset; 24 | } VertexAttrib; 25 | 26 | REVOLC_API void vertex_attributes(MeshType type, const VertexAttrib **attribs, U32 *count); 27 | REVOLC_API bool is_indexed_mesh(MeshType type); 28 | REVOLC_API U32 vertex_size(MeshType type); 29 | 30 | typedef struct TriMeshVertex { 31 | V3f pos; 32 | V3f uv; 33 | V2f outline_uv; 34 | // @todo Colors could be U8[4], or at least U16[4] 35 | Color color; 36 | Color outline_color; 37 | F32 color_exp; // Controls gradient over area of triangle. 1.0 == linear (in linear color space) 38 | F32 outline_exp; // Controls gradient over the area of outline width. 1.0 == linear 39 | F32 outline_width; // In pixels 40 | F32 emission; 41 | bool selected; // Editor 42 | bool pad[47]; 43 | } PACKED TriMeshVertex; // 128 bytes 44 | 45 | REVOLC_API TriMeshVertex default_vertex(); 46 | 47 | typedef struct Mesh { 48 | Resource res; 49 | MeshType mesh_type; 50 | U32 v_count; 51 | U32 i_count; 52 | REL_PTR(TriMeshVertex) vertices; 53 | REL_PTR(MeshIndexType) indices; 54 | } PACKED Mesh; 55 | 56 | REVOLC_API TriMeshVertex * mesh_vertices(const Mesh *m); 57 | REVOLC_API MeshIndexType * mesh_indices(const Mesh *m); 58 | 59 | REVOLC_API WARN_UNUSED Mesh *blobify_mesh(struct WArchive *ar, Cson c, bool *err); 60 | REVOLC_API void deblobify_mesh(WCson *c, struct RArchive *ar); 61 | 62 | // Only for runtime resources 63 | REVOLC_API void add_rt_mesh_vertex(Mesh *mesh, TriMeshVertex vertex); 64 | REVOLC_API void add_rt_mesh_index(Mesh *mesh, MeshIndexType index); 65 | REVOLC_API void remove_rt_mesh_vertex(Mesh *mesh, MeshIndexType index); // Removes also faces 66 | 67 | #endif // REVOLC_VISUAL_MESH_H 68 | -------------------------------------------------------------------------------- /code/source/visual/model.c: -------------------------------------------------------------------------------- 1 | #include "resources/resblob.h" 2 | 3 | Texture* model_texture(const Model *model, U32 index) 4 | { 5 | if (model->textures[index][0] == 0) 6 | return NULL; 7 | return (Texture*)res_by_name( 8 | model->res.blob, ResType_Texture, model->textures[index]); 9 | } 10 | 11 | Mesh* model_mesh(const Model *model) 12 | { return (Mesh*)res_by_name( 13 | model->res.blob, ResType_Mesh, model->mesh); } 14 | 15 | Model *blobify_model(struct WArchive *ar, Cson c, bool *err) 16 | { 17 | Cson c_mesh = cson_key(c, "mesh"); 18 | Cson c_texs = cson_key(c, "textures"); 19 | Cson c_color = cson_key(c, "color"); 20 | Cson c_emission = cson_key(c, "emission"); 21 | 22 | if (cson_is_null(c_mesh)) 23 | RES_ATTRIB_MISSING("mesh"); 24 | if (cson_is_null(c_texs)) 25 | RES_ATTRIB_MISSING("textures"); 26 | if (cson_is_null(c_color)) 27 | RES_ATTRIB_MISSING("color"); 28 | 29 | Model m = {}; 30 | fmt_str(m.mesh, sizeof(m.mesh), "%s", blobify_string(c_mesh, err)); 31 | 32 | for (U32 i = 0; i < cson_member_count(c_texs); ++i) { 33 | Cson c_tex = cson_member(c_texs, i); 34 | fmt_str(m.textures[i], sizeof(m.textures[i]), "%s", blobify_string(c_tex, err)); 35 | } 36 | 37 | m.color = blobify_color(c_color, err); 38 | if (!cson_is_null(c_emission)) 39 | m.emission = blobify_floating(c_emission, err); 40 | 41 | if (err && *err) 42 | goto error; 43 | 44 | Model *ptr = warchive_ptr(ar); 45 | pack_buf(ar, &m, sizeof(m)); 46 | return ptr; 47 | 48 | error: 49 | SET_ERROR_FLAG(err); 50 | return NULL; 51 | } 52 | 53 | void deblobify_model(WCson *c, struct RArchive *ar) 54 | { 55 | Model *m = rarchive_ptr(ar, sizeof(*m)); 56 | unpack_advance(ar, sizeof(*m)); 57 | 58 | wcson_begin_compound(c, "Model"); 59 | 60 | wcson_designated(c, "name"); 61 | deblobify_string(c, m->res.name); 62 | 63 | wcson_designated(c, "mesh"); 64 | deblobify_string(c, m->mesh); 65 | 66 | wcson_designated(c, "color"); 67 | deblobify_color(c, m->color); 68 | 69 | wcson_designated(c, "emission"); 70 | deblobify_floating(c, m->emission); 71 | 72 | wcson_designated(c, "textures"); 73 | wcson_begin_initializer(c); 74 | for (U32 i = 0; i < MODEL_TEX_COUNT; ++i) { 75 | deblobify_string(c, m->textures[i]); 76 | } 77 | wcson_end_initializer(c); 78 | 79 | wcson_end_compound(c); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /code/source/visual/model.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_MODEL_H 2 | #define REVOLC_VISUAL_MODEL_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "resources/resource.h" 7 | #include "texture.h" 8 | #include "mesh.h" 9 | 10 | #define MODEL_TEX_COUNT 1 11 | typedef struct Model { 12 | Resource res; 13 | char textures[MODEL_TEX_COUNT][RES_NAME_SIZE]; 14 | char mesh[RES_NAME_SIZE]; 15 | Color color; 16 | F64 emission; 17 | } PACKED Model; 18 | 19 | REVOLC_API Texture* model_texture(const Model *model, U32 index); 20 | REVOLC_API Mesh* model_mesh(const Model *model); 21 | 22 | REVOLC_API WARN_UNUSED Model *blobify_model(struct WArchive *ar, Cson c, bool *err); 23 | REVOLC_API void deblobify_model(WCson *c, struct RArchive *ar); 24 | 25 | #endif // REVOLC_VISUAL_MODEL_H 26 | -------------------------------------------------------------------------------- /code/source/visual/modelentity.c: -------------------------------------------------------------------------------- 1 | #include "core/archive.h" 2 | #include "modelentity.h" 3 | 4 | void upd_smoothing_phase(F32 *phase, F64 dt) 5 | { 6 | if (*phase < 0.001f) { 7 | *phase = 0.0f; 8 | return; 9 | } 10 | 11 | *phase = exp_drive(*phase, 0, dt*15); 12 | } 13 | 14 | T3d smoothed_tf(T3d tf, F32 phase, T3d delta) 15 | { 16 | if (phase == 0.0f) 17 | return tf; 18 | 19 | T3d ret = lerp_t3d(tf, mul_t3d(tf, delta), phase); 20 | ret.rot = normalized_qd(ret.rot); 21 | return ret; 22 | } 23 | 24 | void init_modelentity(ModelEntity *data) 25 | { 26 | *data = (ModelEntity) { 27 | .tf = identity_t3d(), 28 | .color = (Color) {1, 1, 1, 1}, 29 | .layer = WORLD_VISUAL_LAYER, 30 | }; 31 | } 32 | 33 | void pack_modelentity(WArchive *ar, const ModelEntity *begin, const ModelEntity *end) 34 | { 35 | for (const ModelEntity *it = begin; it != end; ++it) { 36 | ensure(!it->has_own_mesh && "@todo"); 37 | pack_strbuf(ar, it->model_name, sizeof(it->model_name)); 38 | lossy_pack_t3d(ar, &it->tf); 39 | pack_s32(ar, &it->layer); 40 | } 41 | } 42 | 43 | void unpack_modelentity(RArchive *ar, ModelEntity *begin, ModelEntity *end) 44 | { 45 | for (ModelEntity *it = begin; it != end; ++it) { 46 | init_modelentity(it); 47 | 48 | unpack_strbuf(ar, it->model_name, sizeof(it->model_name)); 49 | lossy_unpack_t3d(ar, &it->tf); 50 | unpack_s32(ar, &it->layer); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /code/source/visual/modelentity.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_ENTITY_MODEL_H 2 | #define REVOLC_VISUAL_ENTITY_MODEL_H 3 | 4 | #include "atlas.h" 5 | #include "build.h" 6 | #include "core/cson.h" 7 | #include "core/math.h" 8 | #include "model.h" 9 | #include "mesh.h" 10 | 11 | typedef struct ModelEntity { 12 | char model_name[RES_NAME_SIZE]; // @todo Replace with ResId 13 | T3d tf; 14 | S32 layer; // Overrides z-sorting. 0 for world stuff 15 | bool allocated; 16 | bool has_own_mesh; // If true, vertices and indices are free'd along this 17 | 18 | // Local 19 | T3d smoothing_delta; 20 | F32 smoothing_phase; // 1 at start of smoothing, 0 when done 21 | 22 | // Cached 23 | Color color; 24 | F32 emission; 25 | U8 pattern; 26 | V3f atlas_uv; // @todo Use AtlasUv 27 | V2f scale_to_atlas_uv; 28 | U32 mesh_v_count; 29 | U32 mesh_i_count; 30 | TriMeshVertex* vertices; 31 | MeshIndexType* indices; 32 | } ModelEntity; 33 | 34 | 35 | // Visual smoothing for discontinuities caused by net sync 36 | REVOLC_API void upd_smoothing_phase(F32 *phase, F64 dt); 37 | REVOLC_API T3d smoothed_tf(T3d tf, F32 phase, T3d delta); 38 | 39 | // Rest of node-API or ModelEntity is in renderer 40 | 41 | REVOLC_API void init_modelentity(ModelEntity *data); 42 | 43 | struct WArchive; 44 | struct RArchive; 45 | REVOLC_API void pack_modelentity( struct WArchive *ar, 46 | const ModelEntity *begin, 47 | const ModelEntity *end); 48 | REVOLC_API void unpack_modelentity( struct RArchive *ar, 49 | ModelEntity *begin, 50 | ModelEntity *end); 51 | 52 | #endif // REVOLC_VISUAL_ENTITY_MODEL_H 53 | -------------------------------------------------------------------------------- /code/source/visual/shadersource.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_SHADERSOURCE_H 2 | #define REVOLC_VISUAL_SHADERSOURCE_H 3 | 4 | #include "build.h" 5 | #include "core/cson.h" 6 | #include "resources/resource.h" 7 | #include "mesh.h" // MeshType 8 | 9 | typedef struct ShaderSource { 10 | Resource res; 11 | 12 | char rel_vs_file[MAX_PATH_SIZE]; 13 | char rel_gs_file[MAX_PATH_SIZE]; 14 | char rel_fs_file[MAX_PATH_SIZE]; 15 | 16 | // NULL-terminated strings 17 | REL_PTR(char) vs_src_offset; 18 | REL_PTR(char) gs_src_offset; 19 | REL_PTR(char) fs_src_offset; 20 | MeshType mesh_type; 21 | char feedback_varyings[MAX_SHADER_VARYING_COUNT][RES_NAME_SIZE]; 22 | 23 | // On init 24 | /// @todo Store these somewhere else, as single shader source can 25 | /// produce multiple programs (macros) 26 | U32 vs_gl_id; 27 | U32 gs_gl_id; 28 | U32 fs_gl_id; 29 | U32 prog_gl_id; 30 | } PACKED ShaderSource; 31 | 32 | REVOLC_API void init_shadersource(ShaderSource *shd); 33 | REVOLC_API void deinit_shadersource(ShaderSource *shd); 34 | 35 | REVOLC_API WARN_UNUSED 36 | ShaderSource *blobify_shadersource(struct WArchive *ar, Cson c, bool *err); 37 | REVOLC_API void deblobify_shadersource(WCson *c, struct RArchive *ar); 38 | 39 | #endif // REVOLC_VISUAL_SHADERSOURCE_H 40 | -------------------------------------------------------------------------------- /code/source/visual/texture.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_TEXTURE_H 2 | #define REVOLC_VISUAL_TEXTURE_H 3 | 4 | #include "atlas.h" 5 | #include "build.h" 6 | #include "core/cson.h" 7 | #include "core/math.h" 8 | #include "global/cfg.h" 9 | #include "resources/resource.h" 10 | 11 | typedef struct Texel { 12 | U8 r, g, b, a; 13 | } Texel; 14 | 15 | typedef struct Texture { 16 | Resource res; 17 | V2i reso; 18 | char rel_file[MAX_PATH_SIZE]; 19 | 20 | // Renderer sets 21 | AtlasUv atlas_uv; 22 | 23 | REL_PTR(Texel) texel_offsets[MAX_TEXTURE_LOD_COUNT]; 24 | U32 lod_count; 25 | U32 texel_data_size; 26 | } PACKED Texture; 27 | 28 | Texel * texture_texels(const Texture *tex, U32 lod); 29 | V2i lod_reso(V2i base, U32 lod); 30 | 31 | REVOLC_API WARN_UNUSED 32 | Texture *blobify_texture(struct WArchive *ar, Cson c, bool *err); 33 | REVOLC_API void deblobify_texture(WCson *c, struct RArchive *ar); 34 | 35 | #endif // REVOLC_VISUAL_TEXTURE_H 36 | -------------------------------------------------------------------------------- /code/source/visual/vao.h: -------------------------------------------------------------------------------- 1 | #ifndef REVOLC_VISUAL_VAO_H 2 | #define REVOLC_VISUAL_VAO_H 3 | 4 | #include "build.h" 5 | #include "mesh.h" 6 | 7 | typedef struct Vao { 8 | U32 vao_id; 9 | U32 vbo_id; 10 | U32 ibo_id; 11 | 12 | MeshType mesh_type; 13 | U32 v_count; 14 | U32 v_capacity; 15 | U32 v_size; 16 | U32 i_count; 17 | U32 i_capacity; 18 | } Vao; 19 | 20 | REVOLC_API Vao create_vao(MeshType m, U32 max_v_count, U32 max_i_count); 21 | REVOLC_API void destroy_vao(Vao *vao); 22 | 23 | REVOLC_API void bind_vao(const Vao *vao); 24 | REVOLC_API void unbind_vao(); 25 | REVOLC_API void add_mesh_to_vao(Vao *vao, const Mesh *mesh); 26 | REVOLC_API void add_vertices_to_vao(Vao *vao, void *vertices, U32 count); 27 | REVOLC_API void add_indices_to_vao(Vao *vao, MeshIndexType *indices, U32 count); 28 | REVOLC_API void reset_vao_mesh(Vao *vao); 29 | REVOLC_API void draw_vao(const Vao *vao); 30 | REVOLC_API void draw_vao_range(const Vao *vao, U32 begin_i, U32 end_i); 31 | 32 | #endif // REVOLC_VISUAL_VAO_H 33 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/.gitignore: -------------------------------------------------------------------------------- 1 | # generic 2 | *.o 3 | *.o.d 4 | *.a 5 | *.so 6 | .*.swp 7 | 8 | # generated 9 | pre-process.h 10 | sparse.pc 11 | version.h 12 | 13 | # programs 14 | test-inspect 15 | test-lexing 16 | test-parsing 17 | obfuscate 18 | sparse 19 | compile 20 | graph 21 | test-dissect 22 | test-linearize 23 | example 24 | test-unssa 25 | ctags 26 | c2xml 27 | sparse-llvm 28 | 29 | # tags 30 | tags 31 | TAGS 32 | 33 | # stgit generated dirs 34 | patches-* 35 | 36 | # quilt's files 37 | patches 38 | series 39 | 40 | # local makefile 41 | local.mk 42 | 43 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/LICENSE: -------------------------------------------------------------------------------- 1 | The 'sparse' C parser front-end library is copyrighted by Transmeta Corp 2 | and other authors and licensed under the "MIT License" as 3 | obtained from www.opensource.org (and included here-in for easy 4 | reference). 5 | 6 | [ This copy of the license is the flat-text version of original, 7 | available in its full glory at 8 | 9 | http://opensource.org/licenses/MIT 10 | 11 | please refer to there for the authoritative and slightly more 12 | pretty-printed version ] 13 | 14 | ------ 15 | 16 | The MIT License (MIT) 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy 19 | of this software and associated documentation files (the "Software"), to deal 20 | in the Software without restriction, including without limitation the rights 21 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | copies of the Software, and to permit persons to whom the Software is 23 | furnished to do so, subject to the following conditions: 24 | 25 | The above copyright notice and this permission notice shall be included in 26 | all copies or substantial portions of the Software. 27 | 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 34 | THE SOFTWARE. 35 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/allocate.h: -------------------------------------------------------------------------------- 1 | #ifndef ALLOCATE_H 2 | #define ALLOCATE_H 3 | 4 | struct allocation_blob { 5 | struct allocation_blob *next; 6 | unsigned int left, offset; 7 | unsigned char data[]; 8 | }; 9 | 10 | struct allocator_struct { 11 | const char *name; 12 | struct allocation_blob *blobs; 13 | unsigned int alignment; 14 | unsigned int chunking; 15 | void *freelist; 16 | /* statistics */ 17 | unsigned int allocations, total_bytes, useful_bytes; 18 | }; 19 | 20 | extern void protect_allocations(struct allocator_struct *desc); 21 | extern void drop_all_allocations(struct allocator_struct *desc); 22 | extern void *allocate(struct allocator_struct *desc, unsigned int size); 23 | extern void free_one_entry(struct allocator_struct *desc, void *entry); 24 | extern void show_allocations(struct allocator_struct *); 25 | 26 | #define __DECLARE_ALLOCATOR(type, x) \ 27 | extern type *__alloc_##x(int); \ 28 | extern void __free_##x(type *); \ 29 | extern void show_##x##_alloc(void); \ 30 | extern void clear_##x##_alloc(void); \ 31 | extern void protect_##x##_alloc(void); 32 | #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x) 33 | 34 | #define __DO_ALLOCATOR(type, objsize, objalign, objname, x) \ 35 | static struct allocator_struct x##_allocator = { \ 36 | .name = objname, \ 37 | .alignment = objalign, \ 38 | .chunking = CHUNK }; \ 39 | type *__alloc_##x(int extra) \ 40 | { \ 41 | return allocate(&x##_allocator, objsize+extra); \ 42 | } \ 43 | void __free_##x(type *entry) \ 44 | { \ 45 | free_one_entry(&x##_allocator, entry); \ 46 | } \ 47 | void show_##x##_alloc(void) \ 48 | { \ 49 | show_allocations(&x##_allocator); \ 50 | } \ 51 | void clear_##x##_alloc(void) \ 52 | { \ 53 | drop_all_allocations(&x##_allocator); \ 54 | } \ 55 | void protect_##x##_alloc(void) \ 56 | { \ 57 | protect_allocations(&x##_allocator); \ 58 | } 59 | 60 | #define __ALLOCATOR(t, n, x) \ 61 | __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x) 62 | 63 | #define ALLOCATOR(x, n) __ALLOCATOR(struct x, n, x) 64 | 65 | DECLARE_ALLOCATOR(ident); 66 | DECLARE_ALLOCATOR(token); 67 | DECLARE_ALLOCATOR(context); 68 | DECLARE_ALLOCATOR(symbol); 69 | DECLARE_ALLOCATOR(expression); 70 | DECLARE_ALLOCATOR(statement); 71 | DECLARE_ALLOCATOR(string); 72 | DECLARE_ALLOCATOR(scope); 73 | __DECLARE_ALLOCATOR(void, bytes); 74 | DECLARE_ALLOCATOR(basic_block); 75 | DECLARE_ALLOCATOR(entrypoint); 76 | DECLARE_ALLOCATOR(instruction); 77 | DECLARE_ALLOCATOR(multijmp); 78 | DECLARE_ALLOCATOR(phi); 79 | DECLARE_ALLOCATOR(pseudo); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/ast-inspect.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _AST_INSPECT_H_ 3 | #define _AST_INSPECT_H_ 4 | 5 | #include "ast-model.h" 6 | 7 | void inspect_symbol(AstNode *node); 8 | void inspect_symbol_list(AstNode *node); 9 | 10 | void inspect_statement(AstNode *node); 11 | void inspect_statement_list(AstNode *node); 12 | 13 | void inspect_expression(AstNode *node); 14 | void inspect_expression_list(AstNode *node); 15 | 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/ast-model.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * ast-model.h 4 | * 5 | * Copyright (C) 2010 Christopher Li. 6 | * 7 | */ 8 | 9 | #ifndef _ast_model_h_ 10 | #define _ast_model_h_ 11 | 12 | #include 13 | #include 14 | #include "lib.h" 15 | 16 | #define AST_TYPE_NODE (ast_get_type ()) 17 | #define AST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AST_TYPE_NODE, AstNode)) 18 | #define AST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AST_TYPE_NODE, AstNodeClass)) 19 | #define AST_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AST_TYPE_NODE)) 20 | #define AST_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AST_TYPE_NODE)) 21 | #define AST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AST_TYPE_NODE, AstNodeClass)) 22 | 23 | enum 24 | { 25 | AST_COL_RECORD = 0, 26 | AST_COL_NAME, 27 | AST_N_COLUMNS, 28 | } ; 29 | 30 | 31 | typedef struct AstNode AstNode; 32 | typedef struct AstNodeClass AstNodeClass; 33 | 34 | 35 | 36 | /* AstNode: this structure contains everything we need for our 37 | * model implementation. You can add extra fields to 38 | * this structure, e.g. hashtables to quickly lookup 39 | * rows or whatever else you might need, but it is 40 | * crucial that 'parent' is the first member of the 41 | * structure. */ 42 | 43 | struct AstNode 44 | { 45 | GObject base; /* this MUST be the first member */ 46 | 47 | AstNode *parent; 48 | int index; 49 | const gchar *text; 50 | void (*inspect)(struct AstNode* node); 51 | void *ptr; 52 | GArray *childnodes; 53 | gint stamp; 54 | }; 55 | 56 | 57 | 58 | /* AstNodeClass: more boilerplate GObject stuff */ 59 | 60 | struct AstNodeClass 61 | { 62 | GObjectClass base_class; 63 | }; 64 | 65 | 66 | GType ast_get_type(void); 67 | AstNode* ast_new(AstNode *parent, int index, const char *prefix, void *ptr, void (*expand)(AstNode*)); 68 | 69 | 70 | static inline 71 | AstNode* ast_append_child(AstNode *parent, const char *text, 72 | void *ptr, void (*inspect)(AstNode*)) 73 | { 74 | if (ptr) { 75 | AstNode *child = ast_new(parent, parent->childnodes->len, 76 | text, ptr, inspect); 77 | g_array_append_val(parent->childnodes, child); 78 | return child; 79 | } 80 | return NULL; 81 | } 82 | 83 | static inline 84 | void ast_append_attribute(AstNode *parent, const char *text) 85 | { 86 | AstNode *child = ast_new(parent, parent->childnodes->len, text, NULL, NULL); 87 | g_array_append_val(parent->childnodes, child); 88 | } 89 | 90 | #endif /* _ast_h_*/ 91 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/ast-view.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "lib.h" 4 | 5 | extern void treeview_main(struct symbol_list *syms); 6 | 7 | 8 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/bitmap.h: -------------------------------------------------------------------------------- 1 | #ifndef BITMAP_H 2 | #define BITMAP_H 3 | 4 | #define BITS_IN_LONG (sizeof(unsigned long)*8) 5 | #define LONGS(x) ((x + BITS_IN_LONG - 1) & -BITS_IN_LONG) 6 | 7 | /* Every bitmap gets its own type */ 8 | #define DECLARE_BITMAP(name, x) unsigned long name[LONGS(x)] 9 | 10 | static inline int test_bit(unsigned int nr, unsigned long *bitmap) 11 | { 12 | unsigned long offset = nr / BITS_IN_LONG; 13 | unsigned long bit = nr & (BITS_IN_LONG-1); 14 | return (bitmap[offset] >> bit) & 1; 15 | } 16 | 17 | static inline void set_bit(unsigned int nr, unsigned long *bitmap) 18 | { 19 | unsigned long offset = nr / BITS_IN_LONG; 20 | unsigned long bit = nr & (BITS_IN_LONG-1); 21 | bitmap[offset] |= 1UL << bit; 22 | } 23 | 24 | static inline void clear_bit(unsigned int nr, unsigned long *bitmap) 25 | { 26 | unsigned long offset = nr / BITS_IN_LONG; 27 | unsigned long bit = nr & (BITS_IN_LONG-1); 28 | bitmap[offset] &= ~(1UL << bit); 29 | } 30 | 31 | static inline int test_and_set_bit(unsigned int nr, unsigned long *bitmap) 32 | { 33 | unsigned long offset = nr / BITS_IN_LONG; 34 | unsigned long bit = nr & (BITS_IN_LONG-1); 35 | unsigned long old = bitmap[offset]; 36 | unsigned long mask = 1UL << bit; 37 | bitmap[offset] = old | mask; 38 | return (old & mask) != 0; 39 | } 40 | 41 | static inline int test_and_clear_bit(unsigned int nr, unsigned long *bitmap) 42 | { 43 | unsigned long offset = nr / BITS_IN_LONG; 44 | unsigned long bit = nr & (BITS_IN_LONG-1); 45 | unsigned long old = bitmap[offset]; 46 | unsigned long mask = 1UL << bit; 47 | bitmap[offset] = old & ~mask; 48 | return (old & mask) != 0; 49 | } 50 | 51 | #endif /* BITMAP_H */ 52 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/cgcc.1: -------------------------------------------------------------------------------- 1 | .\" cgcc manpage by Josh Triplett 2 | .TH cgcc "1" 3 | . 4 | .SH NAME 5 | cgcc \- Compiler wrapper to run Sparse after compiling 6 | . 7 | .SH SYNOPSIS 8 | .B cgcc 9 | [\fISPARSE OPTIONS\fR]... [\fICOMPILER OPTIONS\fR]... [\fIINPUT FILES\fR]... 10 | .br 11 | .B make CC=cgcc 12 | . 13 | .SH DESCRIPTION 14 | \fBcgcc\fR provides a wrapper around a C compiler (\fBcc\fR by 15 | default) which also invokes the Sparse static analysis tool. 16 | .P 17 | \fBcgcc\fR accepts all Sparse command-line options, such as warning 18 | options, and passes all other options through to the compiler. 19 | .P 20 | By providing the same interface as the C compiler, \fBcgcc\fR allows 21 | projects to run Sparse as part of their build without modifying their 22 | build system, by using \fBcgcc\fR as the compiler. For many projects, 23 | setting \fBCC=cgcc\fR on the \fBmake\fR command-line will work. 24 | . 25 | .SH ENVIRONMENT 26 | .TP 27 | .B REAL_CC 28 | If set, \fBcgcc\fR will use this as the compiler to invoke, rather 29 | than the default \fBcc\fR. 30 | . 31 | .TP 32 | .B CHECK 33 | If set, \fBcgcc\fR will use this as the Sparse program to invoke, 34 | rather than the default \fBsparse\fR. 35 | . 36 | .SH SEE ALSO 37 | .BR sparse (1) 38 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/char.h: -------------------------------------------------------------------------------- 1 | extern void get_char_constant(struct token *, unsigned long long *); 2 | extern struct token *get_string_constant(struct token *, struct expression *); 3 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat-bsd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD Compatibility functions 3 | * 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "lib.h" 28 | #include "allocate.h" 29 | #include "token.h" 30 | 31 | #include "compat/mmap-blob.c" 32 | 33 | long double string_to_ld(const char *nptr, char **endptr) 34 | { 35 | return strtod(nptr, endptr); 36 | } 37 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat-cygwin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Cygwin Compatibility functions 3 | * 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "lib.h" 32 | #include "allocate.h" 33 | #include "token.h" 34 | 35 | void *blob_alloc(unsigned long size) 36 | { 37 | void *ptr; 38 | size = (size + 4095) & ~4095; 39 | ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 40 | if (ptr == MAP_FAILED) 41 | ptr = NULL; 42 | else 43 | memset(ptr, 0, size); 44 | return ptr; 45 | } 46 | 47 | void blob_free(void *addr, unsigned long size) 48 | { 49 | size = (size + 4095) & ~4095; 50 | munmap(addr, size); 51 | } 52 | 53 | long double string_to_ld(const char *nptr, char **endptr) 54 | { 55 | return strtod(nptr, endptr); 56 | } 57 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat-linux.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | 3 | #include "lib.h" 4 | #include "allocate.h" 5 | 6 | #include "compat/mmap-blob.c" 7 | #include "compat/strtold.c" 8 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat-mingw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MinGW Compatibility functions 3 | * 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | 25 | //#include 26 | //#include 27 | //#include 28 | #include 29 | #include 30 | 31 | #include "lib.h" 32 | #include "allocate.h" 33 | #include "token.h" 34 | 35 | void *blob_alloc(unsigned long size) 36 | { 37 | void *ptr; 38 | ptr = malloc(size); 39 | if (ptr != NULL) 40 | memset(ptr, 0, size); 41 | return ptr; 42 | } 43 | 44 | void blob_free(void *addr, unsigned long size) 45 | { 46 | free(addr); 47 | } 48 | 49 | long double string_to_ld(const char *nptr, char **endptr) 50 | { 51 | return strtod(nptr, endptr); 52 | } 53 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat-solaris.c: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | #include "allocate.h" 3 | 4 | #include "compat/mmap-blob.c" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | long double string_to_ld(const char *str, char **endptr) 11 | { 12 | long double res; 13 | decimal_record dr; 14 | enum decimal_string_form form; 15 | decimal_mode dm; 16 | fp_exception_field_type excp; 17 | char *echar; 18 | 19 | string_to_decimal ((char **)&str, INT_MAX, 0, 20 | &dr, &form, &echar); 21 | if (endptr) *endptr = (char *)str; 22 | 23 | if (form == invalid_form) { 24 | errno = EINVAL; 25 | return 0.0; 26 | } 27 | 28 | dm.rd = fp_nearest; 29 | decimal_to_quadruple (&res, &dm, &dr, &excp); 30 | if (excp & ((1 << fp_overflow) | (1 << fp_underflow))) 31 | errno = ERANGE; 32 | return res; 33 | } 34 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPAT_H 2 | #define COMPAT_H 3 | 4 | /* 5 | * Various systems get these things wrong. So 6 | * we create a small compat library for them. 7 | * 8 | * - zeroed anonymous mmap 9 | * Missing in MinGW 10 | * - "string to long double" (C99 strtold()) 11 | * Missing in Solaris and MinGW 12 | */ 13 | struct stream; 14 | struct stat; 15 | 16 | /* 17 | * Our "blob" allocator works on chunks that are multiples 18 | * of this size (the underlying allocator may be a mmap that 19 | * cannot handle smaller chunks, for example, so trying to 20 | * allocate blobs that aren't aligned is not going to work). 21 | */ 22 | #define CHUNK 32768 23 | 24 | void *blob_alloc(unsigned long size); 25 | void blob_free(void *addr, unsigned long size); 26 | long double string_to_ld(const char *nptr, char **endptr); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat/mmap-blob.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * Allow old BSD naming too, it would be a pity to have to make a 6 | * separate file just for this. 7 | */ 8 | #ifndef MAP_ANONYMOUS 9 | #define MAP_ANONYMOUS MAP_ANON 10 | #endif 11 | 12 | /* 13 | * Our blob allocator enforces the strict CHUNK size 14 | * requirement, as a portability check. 15 | */ 16 | void *blob_alloc(unsigned long size) 17 | { 18 | void *ptr; 19 | 20 | if (size & ~CHUNK) 21 | die("internal error: bad allocation size (%lu bytes)", size); 22 | ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 23 | if (ptr == MAP_FAILED) 24 | ptr = NULL; 25 | return ptr; 26 | } 27 | 28 | void blob_free(void *addr, unsigned long size) 29 | { 30 | if (!size || (size & ~CHUNK) || ((unsigned long) addr & 512)) 31 | die("internal error: bad blob free (%lu bytes at %p)", size, addr); 32 | #ifndef DEBUG 33 | munmap(addr, size); 34 | #else 35 | mprotect(addr, size, PROT_NONE); 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compat/strtold.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long double string_to_ld(const char *nptr, char **endptr) 4 | { 5 | return strtold(nptr, endptr); 6 | } 7 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/compile.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPILE_H 2 | #define COMPILE_H 3 | 4 | struct symbol; 5 | 6 | extern void emit_one_symbol(struct symbol *); 7 | extern void emit_unit_begin(const char *); 8 | extern void emit_unit_end(void); 9 | 10 | #endif /* COMPILE_H */ 11 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/dissect.h: -------------------------------------------------------------------------------- 1 | #ifndef DISSECT_H 2 | #define DISSECT_H 3 | 4 | #include 5 | #include "parse.h" 6 | #include "expression.h" 7 | 8 | #define U_SHIFT 8 9 | 10 | #define U_R_AOF 0x01 11 | #define U_W_AOF 0x02 12 | 13 | #define U_R_VAL 0x04 14 | #define U_W_VAL 0x08 15 | 16 | #define U_R_PTR (U_R_VAL << U_SHIFT) 17 | #define U_W_PTR (U_W_VAL << U_SHIFT) 18 | 19 | struct reporter 20 | { 21 | void (*r_symdef)(struct symbol *); 22 | 23 | void (*r_symbol)(unsigned, struct position *, struct symbol *); 24 | void (*r_member)(unsigned, struct position *, struct symbol *, struct symbol *); 25 | }; 26 | 27 | extern void dissect(struct symbol_list *, struct reporter *); 28 | 29 | #define MK_IDENT(s) ({ \ 30 | static struct { \ 31 | struct ident ident; \ 32 | char __[sizeof(s)]; \ 33 | } ident = {{ \ 34 | .len = sizeof(s)-1, \ 35 | .name = s, \ 36 | }}; \ 37 | &ident.ident; \ 38 | }) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/flow.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOW_H 2 | #define FLOW_H 3 | 4 | #include "lib.h" 5 | 6 | extern unsigned long bb_generation; 7 | 8 | #define REPEAT_CSE 1 9 | #define REPEAT_SYMBOL_CLEANUP 2 10 | 11 | struct entrypoint; 12 | struct instruction; 13 | 14 | extern int simplify_flow(struct entrypoint *ep); 15 | 16 | extern void simplify_symbol_usage(struct entrypoint *ep); 17 | extern void simplify_memops(struct entrypoint *ep); 18 | extern void pack_basic_blocks(struct entrypoint *ep); 19 | 20 | extern void convert_instruction_target(struct instruction *insn, pseudo_t src); 21 | extern void cleanup_and_cse(struct entrypoint *ep); 22 | extern int simplify_instruction(struct instruction *); 23 | 24 | extern void kill_bb(struct basic_block *); 25 | extern void kill_use(pseudo_t *); 26 | extern void kill_instruction(struct instruction *); 27 | extern void kill_unreachable_bbs(struct entrypoint *ep); 28 | 29 | void check_access(struct instruction *insn); 30 | void convert_load_instruction(struct instruction *, pseudo_t); 31 | void rewrite_load_instruction(struct instruction *, struct pseudo_list *); 32 | int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom, int local); 33 | 34 | extern void clear_liveness(struct entrypoint *ep); 35 | extern void track_pseudo_liveness(struct entrypoint *ep); 36 | extern void track_pseudo_death(struct entrypoint *ep); 37 | extern void track_phi_uses(struct instruction *insn); 38 | 39 | extern void vrfy_flow(struct entrypoint *ep); 40 | extern int pseudo_in_list(struct pseudo_list *list, pseudo_t pseudo); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/parse.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 52 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/scope.h: -------------------------------------------------------------------------------- 1 | #ifndef SCOPE_H 2 | #define SCOPE_H 3 | /* 4 | * Symbol scoping is pretty simple. 5 | * 6 | * Copyright (C) 2003 Transmeta Corp. 7 | * 2003 Linus Torvalds 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | struct symbol; 29 | 30 | struct scope { 31 | struct token *token; /* Scope start information */ 32 | struct symbol_list *symbols; /* List of symbols in this scope */ 33 | struct scope *next; 34 | }; 35 | 36 | extern struct scope 37 | *block_scope, 38 | *function_scope, 39 | *file_scope, 40 | *global_scope; 41 | 42 | static inline int toplevel(struct scope *scope) 43 | { 44 | return scope == file_scope || scope == global_scope; 45 | } 46 | 47 | extern void start_file_scope(void); 48 | extern void end_file_scope(void); 49 | extern void new_file_scope(void); 50 | 51 | extern void start_symbol_scope(void); 52 | extern void end_symbol_scope(void); 53 | 54 | extern void start_function_scope(void); 55 | extern void end_function_scope(void); 56 | 57 | extern void bind_scope(struct symbol *, struct scope *); 58 | 59 | extern int is_outer_scope(struct scope *); 60 | #endif 61 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/sparse.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | libdir=@libdir@ 3 | includedir=@includedir@ 4 | 5 | Name: Sparse 6 | Description: Semantic parser for C 7 | Version: @version@ 8 | Libs: -L${libdir} -lsparse 9 | Cflags: -I${includedir} 10 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef STORAGE_H 2 | #define STORAGE_H 3 | 4 | #include "allocate.h" 5 | #include "lib.h" 6 | 7 | /* 8 | * The "storage" that underlies an incoming/outgoing pseudo. It's 9 | * basically the backing store for a pseudo, and may be a real hardware 10 | * register, a stack slot or a static symbol. Or nothing at all, 11 | * since some pseudos can just be recalculated on the fly. 12 | */ 13 | enum storage_type { 14 | REG_UDEF, 15 | REG_REG, 16 | REG_STACK, 17 | REG_FRAME, 18 | REG_SYM, 19 | REG_ARG, 20 | REG_BAD, 21 | }; 22 | 23 | enum inout_enum { 24 | STOR_IN, 25 | STOR_OUT 26 | }; 27 | 28 | struct storage; 29 | DECLARE_PTR_LIST(storage_ptr_list, struct storage *); 30 | 31 | struct storage { 32 | enum storage_type type; 33 | int name; 34 | struct storage_ptr_list *users; 35 | union { 36 | int regno; 37 | int offset; 38 | struct symbol *sym; 39 | }; 40 | }; 41 | 42 | DECLARE_PTR_LIST(storage_list, struct storage); 43 | 44 | struct storage_hash { 45 | struct basic_block *bb; 46 | pseudo_t pseudo; 47 | enum inout_enum inout; 48 | struct storage *storage; 49 | unsigned long flags; 50 | }; 51 | 52 | DECLARE_PTR_LIST(storage_hash_list, struct storage_hash); 53 | 54 | extern struct storage_hash_list *gather_storage(struct basic_block *, enum inout_enum); 55 | extern void free_storage(void); 56 | extern const char *show_storage(struct storage *); 57 | extern void set_up_storage(struct entrypoint *); 58 | struct storage *lookup_storage(struct basic_block *, pseudo_t, enum inout_enum); 59 | void add_storage(struct storage *, struct basic_block *, pseudo_t, enum inout_enum); 60 | 61 | DECLARE_ALLOCATOR(storage); 62 | DECLARE_ALLOCATOR(storage_hash); 63 | 64 | static inline struct storage *alloc_storage(void) 65 | { 66 | return __alloc_storage(0); 67 | } 68 | 69 | static inline struct storage_hash *alloc_storage_hash(struct storage *s) 70 | { 71 | struct storage_hash *entry = __alloc_storage_hash(0); 72 | struct storage **usep = &entry->storage; 73 | 74 | *usep = s; 75 | add_ptr_list(&s->users, usep); 76 | return entry; 77 | } 78 | 79 | #endif /* STORAGE_H */ 80 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/target.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "symbol.h" 4 | #include "target.h" 5 | 6 | struct symbol *size_t_ctype = &uint_ctype; 7 | struct symbol *ssize_t_ctype = &int_ctype; 8 | 9 | /* 10 | * For "__attribute__((aligned))" 11 | */ 12 | int max_alignment = 16; 13 | 14 | /* 15 | * Integer data types 16 | */ 17 | int bits_in_bool = 1; 18 | int bits_in_char = 8; 19 | int bits_in_short = 16; 20 | int bits_in_int = 32; 21 | int bits_in_long = 32; 22 | int bits_in_longlong = 64; 23 | int bits_in_longlonglong = 128; 24 | 25 | int max_int_alignment = 4; 26 | 27 | /* 28 | * Floating point data types 29 | */ 30 | int bits_in_float = 32; 31 | int bits_in_double = 64; 32 | int bits_in_longdouble = 80; 33 | 34 | int max_fp_alignment = 8; 35 | 36 | /* 37 | * Pointer data type 38 | */ 39 | int bits_in_pointer = 32; 40 | int pointer_alignment = 4; 41 | 42 | /* 43 | * Enum data types 44 | */ 45 | int bits_in_enum = 32; 46 | int enum_alignment = 4; 47 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/target.h: -------------------------------------------------------------------------------- 1 | #ifndef TARGET_H 2 | #define TARGET_H 3 | 4 | extern struct symbol *size_t_ctype; 5 | extern struct symbol *ssize_t_ctype; 6 | 7 | /* 8 | * For "__attribute__((aligned))" 9 | */ 10 | extern int max_alignment; 11 | 12 | /* 13 | * Integer data types 14 | */ 15 | extern int bits_in_bool; 16 | extern int bits_in_char; 17 | extern int bits_in_short; 18 | extern int bits_in_int; 19 | extern int bits_in_long; 20 | extern int bits_in_longlong; 21 | extern int bits_in_longlonglong; 22 | 23 | extern int max_int_alignment; 24 | 25 | /* 26 | * Floating point data types 27 | */ 28 | extern int bits_in_float; 29 | extern int bits_in_double; 30 | extern int bits_in_longdouble; 31 | 32 | extern int max_fp_alignment; 33 | 34 | /* 35 | * Pointer data type 36 | */ 37 | extern int bits_in_pointer; 38 | extern int pointer_alignment; 39 | 40 | /* 41 | * Enum data types 42 | */ 43 | extern int bits_in_enum; 44 | extern int enum_alignment; 45 | 46 | /* 47 | * Helper functions for converting bits to bytes and vice versa. 48 | */ 49 | 50 | static inline int bits_to_bytes(int bits) 51 | { 52 | return bits >= 0 ? bits / bits_in_char : -1; 53 | } 54 | 55 | static inline int bytes_to_bits(int bytes) 56 | { 57 | return bytes * bits_in_char; 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /code/tools/codegen/sparse/version.h: -------------------------------------------------------------------------------- 1 | #define SPARSE_VERSION "0.5.0" 2 | -------------------------------------------------------------------------------- /code/tools/codegen/unity.c: -------------------------------------------------------------------------------- 1 | #include "main.c" 2 | 3 | #include 4 | //#include // Piles of compile errors on MinGW, and doesn't seem necessary 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #if defined(__linux__) 30 | # include 31 | #elif defined(__MINGW32__) 32 | # include 33 | #endif 34 | --------------------------------------------------------------------------------