[RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
parent
84c3a02b9a
commit
80b3b82332
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/.build
|
||||
/.rbuild
|
||||
*.swp
|
||||
|
5
.gitmodules
vendored
5
.gitmodules
vendored
@ -1,3 +1,6 @@
|
||||
[submodule "thirdparty/miniaudio"]
|
||||
path = thirdparty/miniaudio/repo
|
||||
url = https://github.com/dr-soft/miniaudio
|
||||
url = https://github.com/mackron/miniaudio
|
||||
[submodule "thirdparty/tinycthread"]
|
||||
path = thirdparty/tinycthread
|
||||
url = https://github.com/tinycthread/tinycthread
|
||||
|
@ -2,35 +2,37 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(leftone C)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
enable_testing()
|
||||
endif()
|
||||
include(CTest)
|
||||
|
||||
set(LEFTONE_C_FLAGS
|
||||
-Werror -Wall -Wextra -Wno-missing-field-initializers
|
||||
$<$<CONFIG:Release>:-Wno-unused-parameter>
|
||||
$<$<PLATFORM_ID:Windows>:-mconsole>
|
||||
)
|
||||
set(LEFTONE_TOOL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tool")
|
||||
|
||||
set(CMAKE_C_FLAGS
|
||||
"${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers")
|
||||
set(CMAKE_C_FLAGS_RELEASE
|
||||
"${CMAKE_C_FLAGS_RELEASE} -Wno-unused-parameter")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mconsole")
|
||||
endif()
|
||||
|
||||
find_package(Freetype REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(msgpack REQUIRED)
|
||||
|
||||
set(SDL2_TARGET SDL2::SDL2)
|
||||
if (NOT TARGET SDL2::SDL2)
|
||||
set(SDL2_TARGET ${SDL2_LIBRARIES})
|
||||
endif()
|
||||
|
||||
include_directories(SYSTEM
|
||||
${FREETYPE_INCLUDE_DIRS}
|
||||
${GLEW_INCLUDE_DIRS}
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
include_directories(.)
|
||||
include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
include(cmake/anysrc.cmake)
|
||||
include(cmake/benum.cmake)
|
||||
include(cmake/crial.cmake)
|
||||
include(cmake/sos.cmake)
|
||||
|
||||
add_subdirectory(app)
|
||||
|
361
LICENSE
Normal file
361
LICENSE
Normal file
@ -0,0 +1,361 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
Attribution-NonCommercial-ShareAlike 3.0 Unported
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
|
||||
DAMAGES RESULTING FROM ITS USE.
|
||||
|
||||
License
|
||||
|
||||
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
|
||||
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
|
||||
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
|
||||
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
|
||||
|
||||
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
|
||||
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
|
||||
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
|
||||
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
|
||||
CONDITIONS.
|
||||
|
||||
1. Definitions
|
||||
|
||||
a. "Adaptation" means a work based upon the Work, or upon the Work and
|
||||
other pre-existing works, such as a translation, adaptation,
|
||||
derivative work, arrangement of music or other alterations of a
|
||||
literary or artistic work, or phonogram or performance and includes
|
||||
cinematographic adaptations or any other form in which the Work may be
|
||||
recast, transformed, or adapted including in any form recognizably
|
||||
derived from the original, except that a work that constitutes a
|
||||
Collection will not be considered an Adaptation for the purpose of
|
||||
this License. For the avoidance of doubt, where the Work is a musical
|
||||
work, performance or phonogram, the synchronization of the Work in
|
||||
timed-relation with a moving image ("synching") will be considered an
|
||||
Adaptation for the purpose of this License.
|
||||
b. "Collection" means a collection of literary or artistic works, such as
|
||||
encyclopedias and anthologies, or performances, phonograms or
|
||||
broadcasts, or other works or subject matter other than works listed
|
||||
in Section 1(g) below, which, by reason of the selection and
|
||||
arrangement of their contents, constitute intellectual creations, in
|
||||
which the Work is included in its entirety in unmodified form along
|
||||
with one or more other contributions, each constituting separate and
|
||||
independent works in themselves, which together are assembled into a
|
||||
collective whole. A work that constitutes a Collection will not be
|
||||
considered an Adaptation (as defined above) for the purposes of this
|
||||
License.
|
||||
c. "Distribute" means to make available to the public the original and
|
||||
copies of the Work or Adaptation, as appropriate, through sale or
|
||||
other transfer of ownership.
|
||||
d. "License Elements" means the following high-level license attributes
|
||||
as selected by Licensor and indicated in the title of this License:
|
||||
Attribution, Noncommercial, ShareAlike.
|
||||
e. "Licensor" means the individual, individuals, entity or entities that
|
||||
offer(s) the Work under the terms of this License.
|
||||
f. "Original Author" means, in the case of a literary or artistic work,
|
||||
the individual, individuals, entity or entities who created the Work
|
||||
or if no individual or entity can be identified, the publisher; and in
|
||||
addition (i) in the case of a performance the actors, singers,
|
||||
musicians, dancers, and other persons who act, sing, deliver, declaim,
|
||||
play in, interpret or otherwise perform literary or artistic works or
|
||||
expressions of folklore; (ii) in the case of a phonogram the producer
|
||||
being the person or legal entity who first fixes the sounds of a
|
||||
performance or other sounds; and, (iii) in the case of broadcasts, the
|
||||
organization that transmits the broadcast.
|
||||
g. "Work" means the literary and/or artistic work offered under the terms
|
||||
of this License including without limitation any production in the
|
||||
literary, scientific and artistic domain, whatever may be the mode or
|
||||
form of its expression including digital form, such as a book,
|
||||
pamphlet and other writing; a lecture, address, sermon or other work
|
||||
of the same nature; a dramatic or dramatico-musical work; a
|
||||
choreographic work or entertainment in dumb show; a musical
|
||||
composition with or without words; a cinematographic work to which are
|
||||
assimilated works expressed by a process analogous to cinematography;
|
||||
a work of drawing, painting, architecture, sculpture, engraving or
|
||||
lithography; a photographic work to which are assimilated works
|
||||
expressed by a process analogous to photography; a work of applied
|
||||
art; an illustration, map, plan, sketch or three-dimensional work
|
||||
relative to geography, topography, architecture or science; a
|
||||
performance; a broadcast; a phonogram; a compilation of data to the
|
||||
extent it is protected as a copyrightable work; or a work performed by
|
||||
a variety or circus performer to the extent it is not otherwise
|
||||
considered a literary or artistic work.
|
||||
h. "You" means an individual or entity exercising rights under this
|
||||
License who has not previously violated the terms of this License with
|
||||
respect to the Work, or who has received express permission from the
|
||||
Licensor to exercise rights under this License despite a previous
|
||||
violation.
|
||||
i. "Publicly Perform" means to perform public recitations of the Work and
|
||||
to communicate to the public those public recitations, by any means or
|
||||
process, including by wire or wireless means or public digital
|
||||
performances; to make available to the public Works in such a way that
|
||||
members of the public may access these Works from a place and at a
|
||||
place individually chosen by them; to perform the Work to the public
|
||||
by any means or process and the communication to the public of the
|
||||
performances of the Work, including by public digital performance; to
|
||||
broadcast and rebroadcast the Work by any means including signs,
|
||||
sounds or images.
|
||||
j. "Reproduce" means to make copies of the Work by any means including
|
||||
without limitation by sound or visual recordings and the right of
|
||||
fixation and reproducing fixations of the Work, including storage of a
|
||||
protected performance or phonogram in digital form or other electronic
|
||||
medium.
|
||||
|
||||
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
|
||||
limit, or restrict any uses free from copyright or rights arising from
|
||||
limitations or exceptions that are provided for in connection with the
|
||||
copyright protection under copyright law or other applicable laws.
|
||||
|
||||
3. License Grant. Subject to the terms and conditions of this License,
|
||||
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
||||
perpetual (for the duration of the applicable copyright) license to
|
||||
exercise the rights in the Work as stated below:
|
||||
|
||||
a. to Reproduce the Work, to incorporate the Work into one or more
|
||||
Collections, and to Reproduce the Work as incorporated in the
|
||||
Collections;
|
||||
b. to create and Reproduce Adaptations provided that any such Adaptation,
|
||||
including any translation in any medium, takes reasonable steps to
|
||||
clearly label, demarcate or otherwise identify that changes were made
|
||||
to the original Work. For example, a translation could be marked "The
|
||||
original work was translated from English to Spanish," or a
|
||||
modification could indicate "The original work has been modified.";
|
||||
c. to Distribute and Publicly Perform the Work including as incorporated
|
||||
in Collections; and,
|
||||
d. to Distribute and Publicly Perform Adaptations.
|
||||
|
||||
The above rights may be exercised in all media and formats whether now
|
||||
known or hereafter devised. The above rights include the right to make
|
||||
such modifications as are technically necessary to exercise the rights in
|
||||
other media and formats. Subject to Section 8(f), all rights not expressly
|
||||
granted by Licensor are hereby reserved, including but not limited to the
|
||||
rights described in Section 4(e).
|
||||
|
||||
4. Restrictions. The license granted in Section 3 above is expressly made
|
||||
subject to and limited by the following restrictions:
|
||||
|
||||
a. You may Distribute or Publicly Perform the Work only under the terms
|
||||
of this License. You must include a copy of, or the Uniform Resource
|
||||
Identifier (URI) for, this License with every copy of the Work You
|
||||
Distribute or Publicly Perform. You may not offer or impose any terms
|
||||
on the Work that restrict the terms of this License or the ability of
|
||||
the recipient of the Work to exercise the rights granted to that
|
||||
recipient under the terms of the License. You may not sublicense the
|
||||
Work. You must keep intact all notices that refer to this License and
|
||||
to the disclaimer of warranties with every copy of the Work You
|
||||
Distribute or Publicly Perform. When You Distribute or Publicly
|
||||
Perform the Work, You may not impose any effective technological
|
||||
measures on the Work that restrict the ability of a recipient of the
|
||||
Work from You to exercise the rights granted to that recipient under
|
||||
the terms of the License. This Section 4(a) applies to the Work as
|
||||
incorporated in a Collection, but this does not require the Collection
|
||||
apart from the Work itself to be made subject to the terms of this
|
||||
License. If You create a Collection, upon notice from any Licensor You
|
||||
must, to the extent practicable, remove from the Collection any credit
|
||||
as required by Section 4(d), as requested. If You create an
|
||||
Adaptation, upon notice from any Licensor You must, to the extent
|
||||
practicable, remove from the Adaptation any credit as required by
|
||||
Section 4(d), as requested.
|
||||
b. You may Distribute or Publicly Perform an Adaptation only under: (i)
|
||||
the terms of this License; (ii) a later version of this License with
|
||||
the same License Elements as this License; (iii) a Creative Commons
|
||||
jurisdiction license (either this or a later license version) that
|
||||
contains the same License Elements as this License (e.g.,
|
||||
Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License").
|
||||
You must include a copy of, or the URI, for Applicable License with
|
||||
every copy of each Adaptation You Distribute or Publicly Perform. You
|
||||
may not offer or impose any terms on the Adaptation that restrict the
|
||||
terms of the Applicable License or the ability of the recipient of the
|
||||
Adaptation to exercise the rights granted to that recipient under the
|
||||
terms of the Applicable License. You must keep intact all notices that
|
||||
refer to the Applicable License and to the disclaimer of warranties
|
||||
with every copy of the Work as included in the Adaptation You
|
||||
Distribute or Publicly Perform. When You Distribute or Publicly
|
||||
Perform the Adaptation, You may not impose any effective technological
|
||||
measures on the Adaptation that restrict the ability of a recipient of
|
||||
the Adaptation from You to exercise the rights granted to that
|
||||
recipient under the terms of the Applicable License. This Section 4(b)
|
||||
applies to the Adaptation as incorporated in a Collection, but this
|
||||
does not require the Collection apart from the Adaptation itself to be
|
||||
made subject to the terms of the Applicable License.
|
||||
c. You may not exercise any of the rights granted to You in Section 3
|
||||
above in any manner that is primarily intended for or directed toward
|
||||
commercial advantage or private monetary compensation. The exchange of
|
||||
the Work for other copyrighted works by means of digital file-sharing
|
||||
or otherwise shall not be considered to be intended for or directed
|
||||
toward commercial advantage or private monetary compensation, provided
|
||||
there is no payment of any monetary compensation in con-nection with
|
||||
the exchange of copyrighted works.
|
||||
d. If You Distribute, or Publicly Perform the Work or any Adaptations or
|
||||
Collections, You must, unless a request has been made pursuant to
|
||||
Section 4(a), keep intact all copyright notices for the Work and
|
||||
provide, reasonable to the medium or means You are utilizing: (i) the
|
||||
name of the Original Author (or pseudonym, if applicable) if supplied,
|
||||
and/or if the Original Author and/or Licensor designate another party
|
||||
or parties (e.g., a sponsor institute, publishing entity, journal) for
|
||||
attribution ("Attribution Parties") in Licensor's copyright notice,
|
||||
terms of service or by other reasonable means, the name of such party
|
||||
or parties; (ii) the title of the Work if supplied; (iii) to the
|
||||
extent reasonably practicable, the URI, if any, that Licensor
|
||||
specifies to be associated with the Work, unless such URI does not
|
||||
refer to the copyright notice or licensing information for the Work;
|
||||
and, (iv) consistent with Section 3(b), in the case of an Adaptation,
|
||||
a credit identifying the use of the Work in the Adaptation (e.g.,
|
||||
"French translation of the Work by Original Author," or "Screenplay
|
||||
based on original Work by Original Author"). The credit required by
|
||||
this Section 4(d) may be implemented in any reasonable manner;
|
||||
provided, however, that in the case of a Adaptation or Collection, at
|
||||
a minimum such credit will appear, if a credit for all contributing
|
||||
authors of the Adaptation or Collection appears, then as part of these
|
||||
credits and in a manner at least as prominent as the credits for the
|
||||
other contributing authors. For the avoidance of doubt, You may only
|
||||
use the credit required by this Section for the purpose of attribution
|
||||
in the manner set out above and, by exercising Your rights under this
|
||||
License, You may not implicitly or explicitly assert or imply any
|
||||
connection with, sponsorship or endorsement by the Original Author,
|
||||
Licensor and/or Attribution Parties, as appropriate, of You or Your
|
||||
use of the Work, without the separate, express prior written
|
||||
permission of the Original Author, Licensor and/or Attribution
|
||||
Parties.
|
||||
e. For the avoidance of doubt:
|
||||
|
||||
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
|
||||
which the right to collect royalties through any statutory or
|
||||
compulsory licensing scheme cannot be waived, the Licensor
|
||||
reserves the exclusive right to collect such royalties for any
|
||||
exercise by You of the rights granted under this License;
|
||||
ii. Waivable Compulsory License Schemes. In those jurisdictions in
|
||||
which the right to collect royalties through any statutory or
|
||||
compulsory licensing scheme can be waived, the Licensor reserves
|
||||
the exclusive right to collect such royalties for any exercise by
|
||||
You of the rights granted under this License if Your exercise of
|
||||
such rights is for a purpose or use which is otherwise than
|
||||
noncommercial as permitted under Section 4(c) and otherwise waives
|
||||
the right to collect royalties through any statutory or compulsory
|
||||
licensing scheme; and,
|
||||
iii. Voluntary License Schemes. The Licensor reserves the right to
|
||||
collect royalties, whether individually or, in the event that the
|
||||
Licensor is a member of a collecting society that administers
|
||||
voluntary licensing schemes, via that society, from any exercise
|
||||
by You of the rights granted under this License that is for a
|
||||
purpose or use which is otherwise than noncommercial as permitted
|
||||
under Section 4(c).
|
||||
f. Except as otherwise agreed in writing by the Licensor or as may be
|
||||
otherwise permitted by applicable law, if You Reproduce, Distribute or
|
||||
Publicly Perform the Work either by itself or as part of any
|
||||
Adaptations or Collections, You must not distort, mutilate, modify or
|
||||
take other derogatory action in relation to the Work which would be
|
||||
prejudicial to the Original Author's honor or reputation. Licensor
|
||||
agrees that in those jurisdictions (e.g. Japan), in which any exercise
|
||||
of the right granted in Section 3(b) of this License (the right to
|
||||
make Adaptations) would be deemed to be a distortion, mutilation,
|
||||
modification or other derogatory action prejudicial to the Original
|
||||
Author's honor and reputation, the Licensor will waive or not assert,
|
||||
as appropriate, this Section, to the fullest extent permitted by the
|
||||
applicable national law, to enable You to reasonably exercise Your
|
||||
right under Section 3(b) of this License (right to make Adaptations)
|
||||
but not otherwise.
|
||||
|
||||
5. Representations, Warranties and Disclaimer
|
||||
|
||||
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE
|
||||
FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS
|
||||
AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE
|
||||
WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT
|
||||
LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||
ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT
|
||||
DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
|
||||
WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
|
||||
|
||||
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
|
||||
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
|
||||
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
|
||||
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
|
||||
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
7. Termination
|
||||
|
||||
a. This License and the rights granted hereunder will terminate
|
||||
automatically upon any breach by You of the terms of this License.
|
||||
Individuals or entities who have received Adaptations or Collections
|
||||
from You under this License, however, will not have their licenses
|
||||
terminated provided such individuals or entities remain in full
|
||||
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
|
||||
survive any termination of this License.
|
||||
b. Subject to the above terms and conditions, the license granted here is
|
||||
perpetual (for the duration of the applicable copyright in the Work).
|
||||
Notwithstanding the above, Licensor reserves the right to release the
|
||||
Work under different license terms or to stop distributing the Work at
|
||||
any time; provided, however that any such election will not serve to
|
||||
withdraw this License (or any other license that has been, or is
|
||||
required to be, granted under the terms of this License), and this
|
||||
License will continue in full force and effect unless terminated as
|
||||
stated above.
|
||||
|
||||
8. Miscellaneous
|
||||
|
||||
a. Each time You Distribute or Publicly Perform the Work or a Collection,
|
||||
the Licensor offers to the recipient a license to the Work on the same
|
||||
terms and conditions as the license granted to You under this License.
|
||||
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
|
||||
offers to the recipient a license to the original Work on the same
|
||||
terms and conditions as the license granted to You under this License.
|
||||
c. If any provision of this License is invalid or unenforceable under
|
||||
applicable law, it shall not affect the validity or enforceability of
|
||||
the remainder of the terms of this License, and without further action
|
||||
by the parties to this agreement, such provision shall be reformed to
|
||||
the minimum extent necessary to make such provision valid and
|
||||
enforceable.
|
||||
d. No term or provision of this License shall be deemed waived and no
|
||||
breach consented to unless such waiver or consent shall be in writing
|
||||
and signed by the party to be charged with such waiver or consent.
|
||||
e. This License constitutes the entire agreement between the parties with
|
||||
respect to the Work licensed here. There are no understandings,
|
||||
agreements or representations with respect to the Work not specified
|
||||
here. Licensor shall not be bound by any additional provisions that
|
||||
may appear in any communication from You. This License may not be
|
||||
modified without the mutual written agreement of the Licensor and You.
|
||||
f. The rights granted under, and the subject matter referenced, in this
|
||||
License were drafted utilizing the terminology of the Berne Convention
|
||||
for the Protection of Literary and Artistic Works (as amended on
|
||||
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
|
||||
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
|
||||
and the Universal Copyright Convention (as revised on July 24, 1971).
|
||||
These rights and subject matter take effect in the relevant
|
||||
jurisdiction in which the License terms are sought to be enforced
|
||||
according to the corresponding provisions of the implementation of
|
||||
those treaty provisions in the applicable national law. If the
|
||||
standard suite of rights granted under applicable copyright law
|
||||
includes additional rights not granted under this License, such
|
||||
additional rights are deemed to be included in the License; this
|
||||
License is not intended to restrict the license of any rights under
|
||||
applicable law.
|
||||
|
||||
|
||||
Creative Commons Notice
|
||||
|
||||
Creative Commons is not a party to this License, and makes no warranty
|
||||
whatsoever in connection with the Work. Creative Commons will not be
|
||||
liable to You or any party on any legal theory for any damages
|
||||
whatsoever, including without limitation any general, special,
|
||||
incidental or consequential damages arising in connection to this
|
||||
license. Notwithstanding the foregoing two (2) sentences, if Creative
|
||||
Commons has expressly identified itself as the Licensor hereunder, it
|
||||
shall have all rights and obligations of Licensor.
|
||||
|
||||
Except for the limited purpose of indicating to the public that the
|
||||
Work is licensed under the CCPL, Creative Commons does not authorize
|
||||
the use by either party of the trademark "Creative Commons" or any
|
||||
related trademark or logo of Creative Commons without the prior
|
||||
written consent of Creative Commons. Any permitted use will be in
|
||||
compliance with Creative Commons' then-current trademark usage
|
||||
guidelines, as may be published on its website or otherwise made
|
||||
available upon request from time to time. For the avoidance of doubt,
|
||||
this trademark restriction does not form part of this License.
|
||||
|
||||
Creative Commons may be contacted at https://creativecommons.org/.
|
||||
|
39
README.md
Normal file
39
README.md
Normal file
@ -0,0 +1,39 @@
|
||||
# LEFTONE
|
||||
|
||||
LEFTONE is 2d action game got a prize on [2020 U22 Programming Contest](https://u22procon.com)
|
||||
|
||||
I'm noob at composing so don't expect the BGM quality. :(
|
||||
|
||||
## AUTHOR
|
||||
|
||||
falsycat
|
||||
[portfolio](https://falsy.cat/) | [twitter](https://twitter.com/falsycat)
|
||||
|
||||
## LICENSE
|
||||
|
||||
***CC-BY-NC-SA-3.0***
|
||||
|
||||
### Libraries
|
||||
|
||||
- [freetype2](https://www.freetype.org/index.html) - FreeType License
|
||||
- [glew](http://glew.sourceforge.net) - Modified BSD License
|
||||
- [miniaudio](https://github.com/mackron/miniaudio) - public domain
|
||||
- [msgpack-c](https://github.com/msgpack/msgpack-c) - Boost Software License
|
||||
- [SDL2](https://www.libsdl.org/index.php) - zlib License
|
||||
- [tinycthread](https://github.com/tinycthread/tinycthread) - zlib License
|
||||
|
||||
### Resources
|
||||
|
||||
- [Otologic](https://otologic.jp) - CC-BY-4.0
|
||||
- [99sounds](https://99sounds.org) - [license](https://99sounds.org/license/)
|
||||
- They replied me it's no problem to put their works on GitHub.
|
||||
- [minimized Noto Font](https://github.com/hirofumii/Noto-Sans-CJK-JP.min) - SIL OPEN FONT LICENSE
|
||||
|
||||
### Why CC?
|
||||
|
||||
Because some of my shaders are inspired by the followings on ShaderToy, whose default license is CC-BY-NC-SA-3.0.
|
||||
***YOU HAD BETTER NOT OPEN THESE LINKS BY POOR MACHINES.***
|
||||
|
||||
- [fractal cage - gaz](https://www.shadertoy.com/view/3l2yDd)
|
||||
- [Ray Marching: Part 2 - jlfwong](https://www.shadertoy.com/view/lt33z7)
|
||||
- [Raymarching - Primitives - iq](https://www.shadertoy.com/view/Xds3zN)
|
@ -1 +1,3 @@
|
||||
add_compile_options(${LEFTONE_C_FLAGS})
|
||||
|
||||
add_subdirectory(sdl)
|
||||
|
@ -5,7 +5,7 @@ add_executable(app-sdl
|
||||
)
|
||||
target_link_libraries(app-sdl
|
||||
GLEW::GLEW
|
||||
SDL2::SDL2
|
||||
${SDL2_TARGET}
|
||||
|
||||
conv
|
||||
parsarg
|
||||
|
@ -75,9 +75,6 @@ void app_args_parse(app_args_t* args, int argc, char** argv) {
|
||||
|
||||
bool_("skip-title", args->scene.skip_title);
|
||||
|
||||
bool_("test-poolset-packing", args->scene.test.loworld_poolset_packing);
|
||||
bool_("test-player-packing", args->scene.test.loplayer_packing);
|
||||
|
||||
/* ---- app parameters ---- */
|
||||
int_("max-fps", args->max_fps, 1, INT32_MAX);
|
||||
|
||||
|
@ -10,15 +10,13 @@
|
||||
#define APP_EVENT_GET_BUTTON_BIT_FROM_KEY(k) ( \
|
||||
(k) == SDLK_a? LOCOMMON_INPUT_BUTTON_LEFT: \
|
||||
(k) == SDLK_d? LOCOMMON_INPUT_BUTTON_RIGHT: \
|
||||
(k) == SDLK_w? LOCOMMON_INPUT_BUTTON_UP: \
|
||||
(k) == SDLK_s? LOCOMMON_INPUT_BUTTON_DOWN: \
|
||||
(k) == SDLK_SPACE? LOCOMMON_INPUT_BUTTON_JUMP: \
|
||||
(k) == SDLK_LSHIFT? LOCOMMON_INPUT_BUTTON_DASH: \
|
||||
(k) == SDLK_LSHIFT? LOCOMMON_INPUT_BUTTON_DODGE: \
|
||||
(k) == SDLK_ESCAPE? LOCOMMON_INPUT_BUTTON_MENU: \
|
||||
0)
|
||||
|
||||
#define APP_EVENT_GET_BUTTON_BIT_FROM_MOUSE(m) ( \
|
||||
(m) == SDL_BUTTON_LEFT? LOCOMMON_INPUT_BUTTON_ATTACK: \
|
||||
(m) == SDL_BUTTON_LEFT? LOCOMMON_INPUT_BUTTON_SHOOT: \
|
||||
(m) == SDL_BUTTON_RIGHT? LOCOMMON_INPUT_BUTTON_GUARD: \
|
||||
0)
|
||||
|
||||
|
@ -3,7 +3,9 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <SDL2/SDL.h>
|
||||
@ -128,7 +130,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
app_get_dpi_(&libs, &args);
|
||||
|
||||
loscene_context_t* ctx = loscene_context_new(&args.scene);
|
||||
loscene_context_t ctx;
|
||||
loscene_context_initialize(&ctx, &args.scene);
|
||||
|
||||
locommon_input_t input = {
|
||||
.resolution = vec2(args.scene.width, args.scene.height),
|
||||
@ -147,10 +150,10 @@ int main(int argc, char** argv) {
|
||||
if (!app_event_handle(&input, &e)) goto EXIT;
|
||||
}
|
||||
|
||||
if (!loscene_context_update(ctx, &input, base_time)) goto EXIT;
|
||||
if (!loscene_context_update(&ctx, &input, base_time)) goto EXIT;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
loscene_context_draw(ctx);
|
||||
loscene_context_draw(&ctx);
|
||||
SDL_GL_SwapWindow(libs.win);
|
||||
|
||||
# ifndef NDEBUG
|
||||
@ -166,7 +169,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
EXIT:
|
||||
loscene_context_delete(ctx);
|
||||
loscene_context_deinitialize(&ctx);
|
||||
app_deinitialize_libraries_(&libs);
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
function(target_any_sources target)
|
||||
set(bin2c ${LEFTONE_TOOL_DIR}/bin2c.sh)
|
||||
|
||||
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
foreach (path ${ARGN})
|
||||
get_filename_component(dirname ${path} DIRECTORY)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/anysrc/${dirname})
|
||||
@ -12,9 +10,10 @@ function(target_any_sources target)
|
||||
set(out ${CMAKE_CURRENT_BINARY_DIR}/anysrc/${path})
|
||||
add_custom_command(
|
||||
OUTPUT ${out}.c ${out}.h
|
||||
COMMAND cat ${in} | ${bin2c} ${name} ${out}
|
||||
COMMAND cat ${in} | bash ${bin2c} ${name} ${out}
|
||||
DEPENDS ${path} ${bin2c}
|
||||
COMMENT "converting ${path} to C header")
|
||||
COMMENT "converting ${path} to C header"
|
||||
VERBATIM)
|
||||
target_sources(${target} PRIVATE ${out}.c ${out}.h)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
29
cmake/benum.cmake
Normal file
29
cmake/benum.cmake
Normal file
@ -0,0 +1,29 @@
|
||||
add_custom_target(benum-generated)
|
||||
|
||||
function(target_benum_sources target)
|
||||
set(benum ${LEFTONE_TOOL_DIR}/benum.sh)
|
||||
|
||||
set(output_files "")
|
||||
foreach (path ${ARGN})
|
||||
get_filename_component(dirname ${path} DIRECTORY)
|
||||
get_filename_component(basename ${path} NAME_WE)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/benum/${dirname})
|
||||
|
||||
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${path})
|
||||
set(out ${CMAKE_CURRENT_BINARY_DIR}/benum/${dirname}/${basename})
|
||||
add_custom_command(
|
||||
OUTPUT ${out}.c ${out}.h
|
||||
COMMAND bash ${benum} ${out} ${in} < ${in}
|
||||
DEPENDS ${path} ${benum}
|
||||
COMMENT "generating benum utilities for ${path}"
|
||||
VERBATIM)
|
||||
target_sources(${target} PRIVATE ${out}.c)
|
||||
|
||||
list(APPEND output_files ${out}.c ${out}.h)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(${target}-benum-generated DEPENDS ${output_files})
|
||||
add_dependencies(${target} ${target}-benum-generated)
|
||||
add_dependencies(benum-generated ${target}-benum-generated)
|
||||
|
||||
endfunction()
|
19
cmake/crial.cmake
Normal file
19
cmake/crial.cmake
Normal file
@ -0,0 +1,19 @@
|
||||
function(target_crial_sources target)
|
||||
set(crial ${LEFTONE_TOOL_DIR}/crial.sh)
|
||||
|
||||
foreach (path ${ARGN})
|
||||
get_filename_component(dirname ${path} DIRECTORY)
|
||||
get_filename_component(basename ${path} NAME_WE)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/crial/${dirname})
|
||||
|
||||
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${path})
|
||||
set(out ${CMAKE_CURRENT_BINARY_DIR}/crial/${dirname}/${basename}.h)
|
||||
add_custom_command(
|
||||
OUTPUT ${out}
|
||||
COMMAND bash ${crial} < ${in} > ${out}
|
||||
DEPENDS ${path} ${crial}
|
||||
COMMENT "generating serializer from ${path}"
|
||||
VERBATIM)
|
||||
target_sources(${target} PRIVATE ${out})
|
||||
endforeach()
|
||||
endfunction()
|
@ -1,20 +1,22 @@
|
||||
function(target_source_of_source target)
|
||||
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sos)
|
||||
foreach (file ${ARGN})
|
||||
get_filename_component(name ${file} NAME_WE)
|
||||
foreach (path ${ARGN})
|
||||
get_filename_component(dirname ${path} DIRECTORY)
|
||||
get_filename_component(basename ${path} NAME_WE)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sos/${dirname})
|
||||
|
||||
set(sos_target sos-${target}-${name})
|
||||
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${file})
|
||||
set(out ${CMAKE_CURRENT_BINARY_DIR}/sos/${file})
|
||||
set(sos_target ${target}-${basename}-sos-generator)
|
||||
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${path})
|
||||
set(out ${CMAKE_CURRENT_BINARY_DIR}/sos/${path})
|
||||
|
||||
add_executable(${sos_target} ${in})
|
||||
add_custom_command(
|
||||
OUTPUT ${out}
|
||||
COMMAND ${sos_target} > ${out}
|
||||
DEPENDS ${sos_target}
|
||||
COMMENT "generating ${file}")
|
||||
COMMENT "generating ${path}"
|
||||
VERBATIM)
|
||||
target_sources(${target} PRIVATE ${out})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
@ -1,13 +1,15 @@
|
||||
include_directories(.)
|
||||
add_compile_options(${LEFTONE_C_FLAGS})
|
||||
|
||||
add_subdirectory(lobullet)
|
||||
add_subdirectory(locharacter)
|
||||
add_subdirectory(lochara)
|
||||
add_subdirectory(locommon)
|
||||
add_subdirectory(loeffect)
|
||||
add_subdirectory(loentity)
|
||||
add_subdirectory(loground)
|
||||
add_subdirectory(loparticle)
|
||||
add_subdirectory(loplayer)
|
||||
add_subdirectory(loresource)
|
||||
add_subdirectory(loscene)
|
||||
add_subdirectory(loshader)
|
||||
add_subdirectory(loui)
|
||||
add_subdirectory(loworld)
|
||||
|
@ -1,10 +1,14 @@
|
||||
add_library(lobullet
|
||||
base.c
|
||||
bomb.c
|
||||
linear.c
|
||||
misc.c
|
||||
pool.c
|
||||
)
|
||||
target_benum_sources(lobullet
|
||||
type.h
|
||||
)
|
||||
target_crial_sources(lobullet
|
||||
base.crial
|
||||
)
|
||||
target_link_libraries(lobullet
|
||||
msgpackc
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "util/mpkutil/get.h"
|
||||
#include "util/mpkutil/pack.h"
|
||||
|
||||
#include "core/locommon/msgpack.h"
|
||||
#include "core/locommon/position.h"
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loentity/bullet.h"
|
||||
@ -20,10 +21,20 @@
|
||||
#include "core/loentity/store.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/bullet.h"
|
||||
#include "core/loshader/set.h"
|
||||
|
||||
#include "./bomb.h"
|
||||
#include "./linear.h"
|
||||
#include "./misc.h"
|
||||
#include "./type.h"
|
||||
|
||||
/* generated serializer */
|
||||
#include "core/lobullet/crial/base.h"
|
||||
|
||||
static bool
|
||||
(*const update_function_vtable_[LOBULLET_TYPE_COUNT])(lobullet_base_t* base) = {
|
||||
[LOBULLET_TYPE_LINEAR_CIRCLE] = lobullet_linear_circle_update,
|
||||
[LOBULLET_TYPE_LINEAR_TRIANGLE] = lobullet_linear_triangle_update,
|
||||
[LOBULLET_TYPE_LINEAR_SQUARE] = lobullet_linear_square_update,
|
||||
};
|
||||
|
||||
static void lobullet_base_delete_(loentity_t* entity) {
|
||||
assert(entity != NULL);
|
||||
@ -32,18 +43,6 @@ static void lobullet_base_delete_(loentity_t* entity) {
|
||||
if (!base->used) return;
|
||||
|
||||
base->used = false;
|
||||
|
||||
# define each_(NAME, name) do { \
|
||||
if (base->type == LOBULLET_TYPE_##NAME) { \
|
||||
lobullet_##name##_tear_down(base); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
LOBULLET_TYPE_EACH_(each_);
|
||||
assert(false);
|
||||
|
||||
# undef each_
|
||||
}
|
||||
|
||||
static void lobullet_base_die_(loentity_t* entity) {
|
||||
@ -55,18 +54,22 @@ static bool lobullet_base_update_(loentity_t* entity) {
|
||||
assert(entity != NULL);
|
||||
|
||||
lobullet_base_t* base = (typeof(base)) entity;
|
||||
|
||||
base->cache = (typeof(base->cache)) {0};
|
||||
base->super.owner = base->param.owner;
|
||||
base->super.velocity = vec2(0, 0);
|
||||
|
||||
# define each_(NAME, name) do { \
|
||||
if (base->type == LOBULLET_TYPE_##NAME) { \
|
||||
return lobullet_##name##_update(base); \
|
||||
} \
|
||||
} while (0)
|
||||
const locommon_position_t oldpos = base->super.super.pos;
|
||||
|
||||
LOBULLET_TYPE_EACH_(each_);
|
||||
return false;
|
||||
|
||||
# undef each_
|
||||
assert(update_function_vtable_[base->param.type] != NULL);
|
||||
if (!update_function_vtable_[base->param.type](base)) {
|
||||
return false;
|
||||
}
|
||||
if (base->cache.velocity_calc) {
|
||||
locommon_position_sub(
|
||||
&base->super.velocity, &base->super.super.pos, &oldpos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void lobullet_base_draw_(
|
||||
@ -80,7 +83,8 @@ static void lobullet_base_draw_(
|
||||
locommon_position_sub(&p, &base->super.super.pos, basepos);
|
||||
vec2_addeq(&base->cache.instance.pos, &p);
|
||||
|
||||
loshader_bullet_drawer_add_instance(base->drawer, &base->cache.instance);
|
||||
loshader_bullet_drawer_add_instance(
|
||||
&base->shaders->drawer.bullet, &base->cache.instance);
|
||||
}
|
||||
|
||||
static void lobullet_base_pack_(
|
||||
@ -90,29 +94,8 @@ static void lobullet_base_pack_(
|
||||
|
||||
const lobullet_base_t* base = (typeof(base)) entity;
|
||||
|
||||
msgpack_pack_map(packer, 4);
|
||||
|
||||
mpkutil_pack_str(packer, "subclass");
|
||||
mpkutil_pack_str(packer, "bullet");
|
||||
|
||||
mpkutil_pack_str(packer, "type");
|
||||
mpkutil_pack_str(packer, lobullet_type_stringify(base->type));
|
||||
|
||||
mpkutil_pack_str(packer, "id");
|
||||
msgpack_pack_uint64(packer, base->super.super.id);
|
||||
|
||||
mpkutil_pack_str(packer, "data");
|
||||
# define each_(NAME, name) do { \
|
||||
if (base->type == LOBULLET_TYPE_##NAME) { \
|
||||
lobullet_##name##_pack_data(base, packer); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
LOBULLET_TYPE_EACH_(each_);
|
||||
assert(false);
|
||||
|
||||
# undef each_
|
||||
msgpack_pack_map(packer, CRIAL_PROPERTY_COUNT_);
|
||||
CRIAL_SERIALIZER_;
|
||||
}
|
||||
|
||||
static bool lobullet_base_affect_(
|
||||
@ -122,57 +105,31 @@ static bool lobullet_base_affect_(
|
||||
lobullet_base_t* base = (typeof(base)) bullet;
|
||||
|
||||
vec2_t v = vec2(0, 0);
|
||||
switch (base->cache.knockback.algorithm) {
|
||||
case LOBULLET_BASE_KNOCKBACK_ALGORITHM_VELOCITY:
|
||||
v = base->super.velocity;
|
||||
break;
|
||||
case LOBULLET_BASE_KNOCKBACK_ALGORITHM_POSITION:
|
||||
locommon_position_sub(&v, &chara->super.pos, &base->super.super.pos);
|
||||
break;
|
||||
}
|
||||
const float plen = vec2_pow_length(&v);
|
||||
if (plen != 0) {
|
||||
vec2_diveq(&v, sqrtf(plen));
|
||||
vec2_muleq(&v, base->cache.knockback.acceleration);
|
||||
loentity_character_knockback(chara, &v);
|
||||
}
|
||||
locommon_position_sub(&v, &chara->super.pos, &base->super.super.pos);
|
||||
vec2_muleq(&v, base->cache.knockback);
|
||||
loentity_character_knockback(chara, &v);
|
||||
|
||||
if (base->cache.toxic) {
|
||||
loentity_character_apply_effect(chara, &base->cache.effect);
|
||||
loentity_character_apply_effect(chara, &base->param.effect);
|
||||
}
|
||||
return base->cache.toxic;
|
||||
}
|
||||
|
||||
void lobullet_base_initialize(
|
||||
lobullet_base_t* base,
|
||||
loresource_set_t* res,
|
||||
loshader_bullet_drawer_t* drawer,
|
||||
const locommon_ticker_t* ticker,
|
||||
loentity_store_t* entities) {
|
||||
lobullet_base_t* base,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker,
|
||||
loentity_store_t* entities) {
|
||||
assert(base != NULL);
|
||||
assert(res != NULL);
|
||||
assert(drawer != NULL);
|
||||
assert(shaders != NULL);
|
||||
assert(ticker != NULL);
|
||||
assert(entities != NULL);
|
||||
|
||||
*base = (typeof(*base)) {
|
||||
.super = {
|
||||
.super = {
|
||||
.vtable = {
|
||||
.delete = lobullet_base_delete_,
|
||||
.die = lobullet_base_die_,
|
||||
.update = lobullet_base_update_,
|
||||
.draw = lobullet_base_draw_,
|
||||
.pack = lobullet_base_pack_,
|
||||
},
|
||||
.subclass = LOENTITY_SUBCLASS_BULLET,
|
||||
},
|
||||
.vtable = {
|
||||
.affect = lobullet_base_affect_,
|
||||
},
|
||||
},
|
||||
.res = res,
|
||||
.drawer = drawer,
|
||||
.shaders = shaders,
|
||||
.ticker = ticker,
|
||||
.entities = entities,
|
||||
};
|
||||
@ -180,12 +137,31 @@ void lobullet_base_initialize(
|
||||
|
||||
void lobullet_base_reinitialize(lobullet_base_t* base, loentity_id_t id) {
|
||||
assert(base != NULL);
|
||||
assert(!base->used);
|
||||
|
||||
base->super.super.id = id;
|
||||
base->super = (typeof(base->super)) {
|
||||
.super = {
|
||||
.vtable = {
|
||||
.delete = lobullet_base_delete_,
|
||||
.die = lobullet_base_die_,
|
||||
.update = lobullet_base_update_,
|
||||
.draw = lobullet_base_draw_,
|
||||
.pack = lobullet_base_pack_,
|
||||
},
|
||||
.id = id,
|
||||
.subclass = LOENTITY_SUBCLASS_BULLET,
|
||||
},
|
||||
.vtable = {
|
||||
.affect = lobullet_base_affect_,
|
||||
},
|
||||
};
|
||||
|
||||
base->param = (typeof(base->param)) {0};
|
||||
}
|
||||
|
||||
void lobullet_base_deinitialize(lobullet_base_t* base) {
|
||||
assert(base != NULL);
|
||||
assert(!base->used);
|
||||
|
||||
lobullet_base_delete_(&base->super.super);
|
||||
}
|
||||
@ -195,41 +171,13 @@ bool lobullet_base_unpack(lobullet_base_t* base, const msgpack_object* obj) {
|
||||
|
||||
lobullet_base_reinitialize(base, 0);
|
||||
|
||||
const char* v;
|
||||
size_t vlen;
|
||||
|
||||
const msgpack_object_map* root = mpkutil_get_map(obj);
|
||||
if (root == NULL) goto FAIL;
|
||||
|
||||
# define item_(v) mpkutil_get_map_item_by_str(root, v)
|
||||
|
||||
# define streq_(v1, len, v2) \
|
||||
(strncmp(v1, v2, len) == 0 && v2[len] == 0)
|
||||
if (!mpkutil_get_str(item_("subclass"), &v, &vlen) ||
|
||||
!streq_(v, vlen, "bullet")) {
|
||||
return false;
|
||||
}
|
||||
# undef streq_
|
||||
|
||||
if (!mpkutil_get_str(item_("type"), &v, &vlen) ||
|
||||
!lobullet_type_unstringify(&base->type, v, vlen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mpkutil_get_uint64(item_("id"), &base->super.super.id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const msgpack_object* data = item_("data");
|
||||
# define each_(NAME, name) do { \
|
||||
if (base->type == LOBULLET_TYPE_##NAME) { \
|
||||
if (!lobullet_##name##_unpack_data(base, data)) return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
LOBULLET_TYPE_EACH_(each_);
|
||||
|
||||
# undef each_
|
||||
|
||||
# undef item_
|
||||
CRIAL_DESERIALIZER_;
|
||||
return true;
|
||||
|
||||
FAIL:
|
||||
lobullet_base_delete_(&base->super.super);
|
||||
return false;
|
||||
}
|
||||
|
44
core/lobullet/base.crial
Normal file
44
core/lobullet/base.crial
Normal file
@ -0,0 +1,44 @@
|
||||
/* CRIAL
|
||||
SERIALIZER_BEGIN
|
||||
mpkutil_pack_str(packer, "$name");
|
||||
mpkutil_pack_str(packer, $code);
|
||||
END
|
||||
DESERIALIZER_BEGIN
|
||||
const char* v;
|
||||
size_t vlen;
|
||||
if (!mpkutil_get_str(
|
||||
mpkutil_get_map_item_by_str(root, "$name"), &v, &vlen) ||
|
||||
strncmp(v, $code, vlen) != 0 || $code[vlen] != 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
END
|
||||
PROPERTY subclass = "bullet"
|
||||
|
||||
SERIALIZER_BEGIN
|
||||
mpkutil_pack_str(packer, "$name");
|
||||
LOCOMMON_MSGPACK_PACK_ANY(packer, &base->$code);
|
||||
END
|
||||
DESERIALIZER_BEGIN
|
||||
if (!LOCOMMON_MSGPACK_UNPACK_ANY(
|
||||
mpkutil_get_map_item_by_str(root, "$name"), &base->$code)) {
|
||||
goto FAIL;
|
||||
}
|
||||
END
|
||||
PROPERTY id = super.super.id
|
||||
PROPERTY pos = super.super.pos
|
||||
PROPERTY owner = param.owner
|
||||
PROPERTY type = param.type
|
||||
PROPERTY target = param.target
|
||||
PROPERTY basepos = param.basepos
|
||||
PROPERTY size = param.size
|
||||
PROPERTY color = param.color
|
||||
PROPERTY velocity = param.velocity
|
||||
PROPERTY acceleration = param.acceleration
|
||||
PROPERTY angle = param.angle
|
||||
PROPERTY angular_velocity = param.angular_velocity
|
||||
PROPERTY quiet = param.quiet
|
||||
PROPERTY knockback = param.knockback
|
||||
PROPERTY effect = param.effect
|
||||
PROPERTY since = param.since
|
||||
PROPERTY duration = param.duration
|
||||
*/
|
@ -13,54 +13,61 @@
|
||||
#include "core/loentity/store.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/bullet.h"
|
||||
#include "core/loshader/set.h"
|
||||
|
||||
#include "./misc.h"
|
||||
#include "./type.h"
|
||||
|
||||
typedef enum {
|
||||
LOBULLET_BASE_KNOCKBACK_ALGORITHM_VELOCITY,
|
||||
LOBULLET_BASE_KNOCKBACK_ALGORITHM_POSITION,
|
||||
} lobullet_base_knockback_algorithm_t;
|
||||
typedef struct {
|
||||
lobullet_type_t type;
|
||||
loentity_id_t owner;
|
||||
loentity_id_t target;
|
||||
|
||||
locommon_position_t basepos;
|
||||
vec2_t size;
|
||||
vec4_t color;
|
||||
|
||||
vec2_t velocity;
|
||||
vec2_t acceleration;
|
||||
|
||||
float angle;
|
||||
float angular_velocity;
|
||||
|
||||
bool quiet;
|
||||
float knockback;
|
||||
|
||||
loeffect_t effect;
|
||||
|
||||
uint64_t since;
|
||||
uint64_t duration;
|
||||
} lobullet_base_param_t;
|
||||
|
||||
typedef struct {
|
||||
loentity_bullet_t super;
|
||||
bool used;
|
||||
|
||||
/* injected deps */
|
||||
loresource_set_t* res;
|
||||
loshader_bullet_drawer_t* drawer;
|
||||
const locommon_ticker_t* ticker;
|
||||
loentity_store_t* entities;
|
||||
loresource_set_t* res;
|
||||
loshader_set_t* shaders;
|
||||
const locommon_ticker_t* ticker;
|
||||
loentity_store_t* entities;
|
||||
|
||||
lobullet_base_param_t param;
|
||||
|
||||
/* params not to be packed */
|
||||
struct {
|
||||
bool toxic;
|
||||
loeffect_t effect;
|
||||
/* When toxic is true, apply this effect to characters hit. */
|
||||
|
||||
struct {
|
||||
float acceleration;
|
||||
lobullet_base_knockback_algorithm_t algorithm;
|
||||
} knockback;
|
||||
bool toxic;
|
||||
float knockback;
|
||||
bool velocity_calc;
|
||||
|
||||
loshader_bullet_drawer_instance_t instance;
|
||||
/* instance pos is added to draw pos */
|
||||
} cache;
|
||||
|
||||
/* params to be packed (includes id) */
|
||||
lobullet_type_t type;
|
||||
|
||||
# define LOBULLET_BASE_DATA_MAX_SIZE 256
|
||||
uint8_t data[LOBULLET_BASE_DATA_MAX_SIZE];
|
||||
/* pack function for the type is used */
|
||||
} lobullet_base_t;
|
||||
|
||||
void
|
||||
lobullet_base_initialize(
|
||||
lobullet_base_t* base,
|
||||
loresource_set_t* res,
|
||||
loshader_bullet_drawer_t* drawer,
|
||||
const locommon_ticker_t* ticker,
|
||||
loentity_store_t* entities
|
||||
lobullet_base_t* base,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker,
|
||||
loentity_store_t* entities
|
||||
);
|
||||
|
||||
void
|
||||
|
@ -1,205 +0,0 @@
|
||||
#include "./bomb.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/coly2d/shape.h"
|
||||
#include "util/math/algorithm.h"
|
||||
#include "util/math/constant.h"
|
||||
#include "util/math/vector.h"
|
||||
#include "util/mpkutil/pack.h"
|
||||
|
||||
#include "core/locommon/msgpack.h"
|
||||
#include "core/locommon/position.h"
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loentity/entity.h"
|
||||
#include "core/loresource/sound.h"
|
||||
#include "core/loshader/bullet.h"
|
||||
|
||||
#include "./base.h"
|
||||
#include "./misc.h"
|
||||
|
||||
#define LOBULLET_BOMB_PARAM_TO_PACK_EACH_(PROC) do { \
|
||||
PROC("owner", owner); \
|
||||
PROC("pos", pos); \
|
||||
PROC("size", size); \
|
||||
PROC("angle", angle); \
|
||||
PROC("color", color); \
|
||||
PROC("silent", silent); \
|
||||
PROC("beat", beat); \
|
||||
PROC("step", step); \
|
||||
PROC("knockback", knockback); \
|
||||
PROC("effect", effect); \
|
||||
PROC("since", since); \
|
||||
} while (0)
|
||||
#define LOBULLET_BOMB_PARAM_TO_PACK_COUNT 11
|
||||
|
||||
_Static_assert(sizeof(lobullet_bomb_param_t) <= LOBULLET_BASE_DATA_MAX_SIZE);
|
||||
|
||||
static bool lobullet_bomb_update_(lobullet_base_t* base) {
|
||||
assert(base != NULL);
|
||||
|
||||
const lobullet_bomb_param_t* p = (typeof(p)) base->data;
|
||||
|
||||
base->super.super.pos = p->pos;
|
||||
base->super.owner = p->owner;
|
||||
base->super.velocity = vec2(0, 0);
|
||||
base->super.shape.size = p->size;
|
||||
base->super.shape.angle = p->angle;
|
||||
|
||||
const uint64_t st = (p->step-1) * p->beat;
|
||||
const uint64_t ed = st + 100;
|
||||
|
||||
const uint64_t t = base->ticker->time - p->since;
|
||||
const uint64_t pt =
|
||||
(int64_t) t >= base->ticker->delta? t - base->ticker->delta: 0;
|
||||
|
||||
if (!p->silent && pt < st && t >= st) {
|
||||
loresource_sound_play(base->res->sound, "bomb");
|
||||
}
|
||||
|
||||
base->cache.toxic = st <= t && t < ed;
|
||||
base->cache.effect = p->effect;
|
||||
return t < p->step*p->beat;
|
||||
}
|
||||
|
||||
bool lobullet_bomb_param_valid(const lobullet_bomb_param_t* param) {
|
||||
return
|
||||
param != NULL &&
|
||||
locommon_position_valid(¶m->pos) &&
|
||||
vec2_valid(¶m->size) &&
|
||||
MATH_FLOAT_VALID(param->angle) &&
|
||||
vec4_valid(¶m->color) &&
|
||||
MATH_FLOAT_VALID(param->beat) &&
|
||||
param->step > 0 &&
|
||||
MATH_FLOAT_VALID(param->knockback);
|
||||
}
|
||||
void lobullet_bomb_param_pack(
|
||||
const lobullet_bomb_param_t* p, msgpack_packer* packer) {
|
||||
assert(lobullet_bomb_param_valid(p));
|
||||
assert(packer != NULL);
|
||||
|
||||
msgpack_pack_map(packer, LOBULLET_BOMB_PARAM_TO_PACK_COUNT);
|
||||
|
||||
# define pack_(name, var) do { \
|
||||
mpkutil_pack_str(packer, name); \
|
||||
LOCOMMON_MSGPACK_PACK_ANY(packer, &p->var); \
|
||||
} while (0)
|
||||
|
||||
LOBULLET_BOMB_PARAM_TO_PACK_EACH_(pack_);
|
||||
|
||||
# undef pack_
|
||||
}
|
||||
bool lobullet_bomb_param_unpack(
|
||||
lobullet_bomb_param_t* p, const msgpack_object* obj) {
|
||||
assert(p != NULL);
|
||||
|
||||
const msgpack_object_map* root = mpkutil_get_map(obj);
|
||||
|
||||
# define item_(v) mpkutil_get_map_item_by_str(root, v)
|
||||
|
||||
# define unpack_(name, var) do { \
|
||||
if (!LOCOMMON_MSGPACK_UNPACK_ANY(item_(name), &p->var)) { \
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
LOBULLET_BOMB_PARAM_TO_PACK_EACH_(unpack_);
|
||||
return lobullet_bomb_param_valid(p);
|
||||
|
||||
# undef unpack_
|
||||
|
||||
# undef item_
|
||||
}
|
||||
|
||||
void lobullet_bomb_build(
|
||||
lobullet_base_t* base,
|
||||
lobullet_type_t type,
|
||||
const lobullet_bomb_param_t* param) {
|
||||
assert(base != NULL);
|
||||
assert(lobullet_bomb_param_valid(param));
|
||||
|
||||
base->type = type;
|
||||
|
||||
lobullet_bomb_param_t* p = (typeof(p)) base->data;
|
||||
*p = *param;
|
||||
p->since = base->ticker->time;
|
||||
}
|
||||
|
||||
bool lobullet_bomb_square_update(lobullet_base_t* base) {
|
||||
assert(base != NULL);
|
||||
|
||||
if (!lobullet_bomb_update_(base)) return false;
|
||||
|
||||
const lobullet_bomb_param_t* p = (typeof(p)) base->data;
|
||||
|
||||
/* ---- calculate motion ---- */
|
||||
const float beats = (base->ticker->time - p->since) / p->beat;
|
||||
|
||||
float time = 0;
|
||||
float angle = p->angle;
|
||||
float alpha = 1;
|
||||
if (beats < p->step-1) {
|
||||
time = beats - (int64_t) beats;
|
||||
alpha = 1-time;
|
||||
time = time*time;
|
||||
time = (1-time)*.05f;
|
||||
} else {
|
||||
time = 1 - powf(1-(beats - (int64_t) beats), 2);
|
||||
angle += time * MATH_PI/4;
|
||||
time = 1-time;
|
||||
}
|
||||
|
||||
/* ---- apply motion ---- */
|
||||
base->super.shape.type = COLY2D_SHAPE_TYPE_RECT;
|
||||
base->super.shape.angle = angle;
|
||||
|
||||
base->cache.instance = (loshader_bullet_drawer_instance_t) {
|
||||
.bullet_id = LOSHADER_BULLET_ID_SQUARE,
|
||||
.size = p->size,
|
||||
.theta = angle,
|
||||
.color = p->color,
|
||||
.time = time,
|
||||
};
|
||||
base->cache.instance.color.w *= alpha;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lobullet_bomb_triangle_update(lobullet_base_t* base) {
|
||||
assert(base != NULL);
|
||||
|
||||
if (!lobullet_bomb_update_(base)) return false;
|
||||
|
||||
const lobullet_bomb_param_t* p = (typeof(p)) base->data;
|
||||
|
||||
/* ---- calculate motion ---- */
|
||||
const float beats = (base->ticker->time - p->since) / p->beat;
|
||||
|
||||
float time = 0;
|
||||
float alpha = 1;
|
||||
if (beats < p->step-1) {
|
||||
time = beats - (int64_t) beats;
|
||||
alpha = 1-time;
|
||||
time = time*time;
|
||||
time = (1-time)*.05f;
|
||||
} else {
|
||||
time = 1 - powf(1-(beats - (int64_t) beats), 2);
|
||||
time = 1-time;
|
||||
}
|
||||
|
||||
/* ---- apply motion ---- */
|
||||
base->super.shape.type = COLY2D_SHAPE_TYPE_TRIANGLE;
|
||||
|
||||
base->cache.instance = (loshader_bullet_drawer_instance_t) {
|
||||
.bullet_id = LOSHADER_BULLET_ID_TRIANGLE,
|
||||
.size = p->size,
|
||||
.theta = base->super.shape.angle,
|
||||
.color = p->color,
|
||||
.time = time,
|
||||
};
|
||||
base->cache.instance.color.w *= alpha;
|
||||
return true;
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <msgpack.h>
|
||||
|
||||
#include "util/math/vector.h"
|
||||
|
||||
#include "core/locommon/position.h"
|
||||
#include "core/loeffect/effect.h"
|
||||
#include "core/loentity/entity.h"
|
||||
|
||||
#include "./base.h"
|
||||
#include "./misc.h"
|
||||
|
||||
typedef struct {
|
||||
loentity_id_t owner;
|
||||
locommon_position_t pos;
|
||||
vec2_t size;
|
||||
float angle;
|
||||
vec4_t color;
|
||||
bool silent;
|
||||
|
||||
float beat;
|
||||
int32_t step;
|
||||
float knockback;
|
||||
|
||||
loeffect_t effect;
|
||||
|
||||
uint64_t since; /* set by build function */
|
||||
} lobullet_bomb_param_t;
|
||||
|
||||
bool
|
||||
lobullet_bomb_param_valid(
|
||||
const lobullet_bomb_param_t* param /* NULLABLE */
|
||||
);
|
||||
void
|
||||
lobullet_bomb_param_pack(
|
||||
const lobullet_bomb_param_t* param,
|
||||
msgpack_packer* packer
|
||||
);
|
||||
bool
|
||||
lobullet_bomb_param_unpack(
|
||||
lobullet_bomb_param_t* param,
|
||||
const msgpack_object* obj /* NULLABLE */
|
||||
);
|
||||
|
||||
void
|
||||
lobullet_bomb_build(
|
||||
lobullet_base_t* base,
|
||||
lobullet_type_t type,
|
||||
const lobullet_bomb_param_t* param
|
||||
);
|
||||
|
||||
bool
|
||||
lobullet_bomb_square_update(
|
||||
lobullet_base_t* base
|
||||
);
|
||||
#define lobullet_bomb_square_build(base, param) \
|
||||
lobullet_bomb_build(base, LOBULLET_TYPE_BOMB_SQUARE, param)
|
||||
#define lobullet_bomb_square_tear_down(base)
|
||||
#define lobullet_bomb_square_pack_data(base, packer) \
|
||||
lobullet_bomb_param_pack( \
|
||||
(const lobullet_bomb_param_t*) base->data, packer)
|
||||
#define lobullet_bomb_square_unpack_data(base, obj) \
|
||||
lobullet_bomb_param_unpack( \
|
||||
(lobullet_bomb_param_t*) base->data, obj)
|
||||
|
||||
bool
|
||||
lobullet_bomb_triangle_update(
|
||||
lobullet_base_t* base
|
||||
);
|
||||
#define lobullet_bomb_triangle_build(base, param) \
|
||||
lobullet_bomb_build(base, LOBULLET_TYPE_BOMB_TRIANGLE, param)
|
||||
#define lobullet_bomb_triangle_tear_down(base)
|
||||
#define lobullet_bomb_triangle_pack_data(base, packer) \
|
||||
lobullet_bomb_param_pack( \
|
||||
(const lobullet_bomb_param_t*) base->data, packer)
|
||||
#define lobullet_bomb_triangle_unpack_data(base, obj) \
|
||||
lobullet_bomb_param_unpack( \
|
||||
(lobullet_bomb_param_t*) base->data, obj)
|