Compare commits
No commits in common. "master" and "feat/thread-syntax" have entirely different histories.
master
...
feat/threa
49 changed files with 72 additions and 5901 deletions
|
|
@ -11,17 +11,25 @@ static void cleanup(int sig){
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
fishbone::Client* client;
|
fishbone::SoundDriver* drv;
|
||||||
fishbone::StringArrayMap param;
|
fishbone::Sound* snd;
|
||||||
|
|
||||||
param["basedir"] = {"./data", "../data"};
|
|
||||||
|
|
||||||
client = new fishbone::Client(param);
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
signal(SIGINT, cleanup);
|
signal(SIGINT, cleanup);
|
||||||
signal(SIGTERM, cleanup);
|
signal(SIGTERM, cleanup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(!quit && client->step());
|
drv = new fishbone::SoundDriver();
|
||||||
|
|
||||||
|
snd = drv->mixer.open("shanghai.mp3");
|
||||||
|
snd->setLoop(true);
|
||||||
|
snd->position[0] = -1;
|
||||||
|
snd->position[1] = 0;
|
||||||
|
snd->position[2] = 0;
|
||||||
|
snd->is3d = true;
|
||||||
|
snd->resume();
|
||||||
|
|
||||||
|
while(!quit);
|
||||||
|
|
||||||
|
delete drv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
# Blender 5.0.1
|
|
||||||
# www.blender.org
|
|
||||||
v -0.500000 -0.500000 0.500000
|
|
||||||
v -0.500000 0.500000 0.500000
|
|
||||||
v -0.500000 -0.500000 -0.500000
|
|
||||||
v -0.500000 0.500000 -0.500000
|
|
||||||
v 0.500000 -0.500000 0.500000
|
|
||||||
v 0.500000 0.500000 0.500000
|
|
||||||
v 0.500000 -0.500000 -0.500000
|
|
||||||
v 0.500000 0.500000 -0.500000
|
|
||||||
vn -1.0000 -0.0000 -0.0000
|
|
||||||
vn -0.0000 -0.0000 -1.0000
|
|
||||||
vn 1.0000 -0.0000 -0.0000
|
|
||||||
vn -0.0000 -0.0000 1.0000
|
|
||||||
vn -0.0000 -1.0000 -0.0000
|
|
||||||
vn -0.0000 1.0000 -0.0000
|
|
||||||
vt 0.000000 0.000000
|
|
||||||
vt 0.000000 1.000000
|
|
||||||
vt 1.000000 1.000000
|
|
||||||
vt 1.000000 0.000000
|
|
||||||
s 0
|
|
||||||
usemtl Material
|
|
||||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
|
||||||
f 3/1/2 4/2/2 8/3/2 7/4/2
|
|
||||||
f 7/4/3 8/3/3 6/2/3 5/1/3
|
|
||||||
f 5/4/4 6/3/4 2/2/4 1/1/4
|
|
||||||
f 3/2/5 7/3/5 5/4/5 1/1/5
|
|
||||||
f 8/3/6 4/2/6 2/1/6 6/4/6
|
|
||||||
BIN
data/model.png
BIN
data/model.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB |
|
|
@ -15,6 +15,7 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
|
||||||
message(FATAL_ERROR "Failed to download CPM.cmake: ${status}\n${log_content}")
|
message(FATAL_ERROR "Failed to download CPM.cmake: ${status}\n${log_content}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
|
||||||
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/util.cmake")
|
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/util.cmake")
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCS src/**.cc src/**.c)
|
file(GLOB_RECURSE SRCS src/**.cc src/**.c)
|
||||||
|
|
@ -37,7 +38,6 @@ pkg_add(fishbone sdl2 REQUIRED)
|
||||||
set(FISHBONE_SOUND_USE_SDL2 ON)
|
set(FISHBONE_SOUND_USE_SDL2 ON)
|
||||||
set(FISHBONE_WINDOW_USE_SDL2 ON)
|
set(FISHBONE_WINDOW_USE_SDL2 ON)
|
||||||
set(FISHBONE_THREAD_USE_SDL2 ON)
|
set(FISHBONE_THREAD_USE_SDL2 ON)
|
||||||
set(FISHBONE_DRAW_USE_OPENGL ON)
|
|
||||||
|
|
||||||
configure_file(config.h.in fishbone/config.h)
|
configure_file(config.h.in fishbone/config.h)
|
||||||
target_include_directories(fishbone PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
target_include_directories(fishbone PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
@ -48,9 +48,6 @@ fb_add_dep(fishbone ode)
|
||||||
# Image
|
# Image
|
||||||
fb_add_dep(fishbone stb_image)
|
fb_add_dep(fishbone stb_image)
|
||||||
|
|
||||||
# Graphics
|
|
||||||
fb_add_dep(fishbone glad)
|
|
||||||
|
|
||||||
# Sound
|
# Sound
|
||||||
fb_add_dep(fishbone stb_vorbis)
|
fb_add_dep(fishbone stb_vorbis)
|
||||||
fb_add_dep(fishbone dr_libs)
|
fb_add_dep(fishbone dr_libs)
|
||||||
|
|
@ -69,6 +66,3 @@ if(FISHBONE_BUILD_TESTS)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Tools
|
|
||||||
add_subdirectory(tools)
|
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,3 @@ CPMAddPackage(
|
||||||
GITHUB_REPOSITORY "lsalzman/enet"
|
GITHUB_REPOSITORY "lsalzman/enet"
|
||||||
GIT_TAG master
|
GIT_TAG master
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(enet PUBLIC ${enet_SOURCE_DIR}/include)
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
add_library(glad ${CMAKE_CURRENT_SOURCE_DIR}/glad/src/glad.c)
|
|
||||||
target_include_directories(glad PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)
|
|
||||||
set_target_properties(glad PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
|
||||||
|
|
@ -12,12 +12,7 @@ function(fb_add_dep TARGET_NAME DEP_NAME)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(TOP_CMAKE "${CMAKE_CURRENT_SOURCE_DIR}/")
|
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deps/${DEP_NAME}.cmake")
|
||||||
while(NOT EXISTS "${TOP_CMAKE}")
|
|
||||||
set(TOP_CMAKE "${TOP_CMAKE}../")
|
|
||||||
endwhile()
|
|
||||||
|
|
||||||
include("${TOP_CMAKE}cmake/deps/${DEP_NAME}.cmake")
|
|
||||||
|
|
||||||
if(NOT TARGET deps::${DEP_NAME})
|
if(NOT TARGET deps::${DEP_NAME})
|
||||||
add_library(deps::${DEP_NAME} ALIAS ${DEP_NAME})
|
add_library(deps::${DEP_NAME} ALIAS ${DEP_NAME})
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,5 @@
|
||||||
#cmakedefine FISHBONE_SOUND_USE_SDL2
|
#cmakedefine FISHBONE_SOUND_USE_SDL2
|
||||||
#cmakedefine FISHBONE_WINDOW_USE_SDL2
|
#cmakedefine FISHBONE_WINDOW_USE_SDL2
|
||||||
#cmakedefine FISHBONE_THREAD_USE_SDL2
|
#cmakedefine FISHBONE_THREAD_USE_SDL2
|
||||||
#cmakedefine FISHBONE_DRAW_USE_OPENGL
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,311 +0,0 @@
|
||||||
#ifndef __khrplatform_h_
|
|
||||||
#define __khrplatform_h_
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
|
||||||
**
|
|
||||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
** copy of this software and/or associated documentation files (the
|
|
||||||
** "Materials"), to deal in the Materials without restriction, including
|
|
||||||
** without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
|
||||||
** permit persons to whom the Materials are furnished to do so, subject to
|
|
||||||
** the following conditions:
|
|
||||||
**
|
|
||||||
** The above copyright notice and this permission notice shall be included
|
|
||||||
** in all copies or substantial portions of the Materials.
|
|
||||||
**
|
|
||||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Khronos platform-specific types and definitions.
|
|
||||||
*
|
|
||||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
|
||||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
|
||||||
* The last semantic modification to khrplatform.h was at commit ID:
|
|
||||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
|
||||||
*
|
|
||||||
* Adopters may modify this file to suit their platform. Adopters are
|
|
||||||
* encouraged to submit platform specific modifications to the Khronos
|
|
||||||
* group so that they can be included in future versions of this file.
|
|
||||||
* Please submit changes by filing pull requests or issues on
|
|
||||||
* the EGL Registry repository linked above.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* See the Implementer's Guidelines for information about where this file
|
|
||||||
* should be located on your system and for more details of its use:
|
|
||||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
|
||||||
*
|
|
||||||
* This file should be included as
|
|
||||||
* #include <KHR/khrplatform.h>
|
|
||||||
* by Khronos client API header files that use its types and defines.
|
|
||||||
*
|
|
||||||
* The types in khrplatform.h should only be used to define API-specific types.
|
|
||||||
*
|
|
||||||
* Types defined in khrplatform.h:
|
|
||||||
* khronos_int8_t signed 8 bit
|
|
||||||
* khronos_uint8_t unsigned 8 bit
|
|
||||||
* khronos_int16_t signed 16 bit
|
|
||||||
* khronos_uint16_t unsigned 16 bit
|
|
||||||
* khronos_int32_t signed 32 bit
|
|
||||||
* khronos_uint32_t unsigned 32 bit
|
|
||||||
* khronos_int64_t signed 64 bit
|
|
||||||
* khronos_uint64_t unsigned 64 bit
|
|
||||||
* khronos_intptr_t signed same number of bits as a pointer
|
|
||||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
|
||||||
* khronos_ssize_t signed size
|
|
||||||
* khronos_usize_t unsigned size
|
|
||||||
* khronos_float_t signed 32 bit floating point
|
|
||||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
|
||||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
|
||||||
* nanoseconds
|
|
||||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
|
||||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
|
||||||
* only be used as a base type when a client API's boolean type is
|
|
||||||
* an enum. Client APIs which use an integer or other type for
|
|
||||||
* booleans cannot use this as the base type for their boolean.
|
|
||||||
*
|
|
||||||
* Tokens defined in khrplatform.h:
|
|
||||||
*
|
|
||||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
|
||||||
*
|
|
||||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
|
||||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
|
||||||
*
|
|
||||||
* Calling convention macros defined in this file:
|
|
||||||
* KHRONOS_APICALL
|
|
||||||
* KHRONOS_APIENTRY
|
|
||||||
* KHRONOS_APIATTRIBUTES
|
|
||||||
*
|
|
||||||
* These may be used in function prototypes as:
|
|
||||||
*
|
|
||||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
|
||||||
* int arg1,
|
|
||||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
|
||||||
# define KHRONOS_STATIC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APICALL
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This precedes the return type of the function in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(KHRONOS_STATIC)
|
|
||||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
|
||||||
* header compatible with static linking. */
|
|
||||||
# define KHRONOS_APICALL
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
# define KHRONOS_APICALL __declspec(dllimport)
|
|
||||||
#elif defined (__SYMBIAN32__)
|
|
||||||
# define KHRONOS_APICALL IMPORT_C
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
# define KHRONOS_APICALL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIENTRY
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the return type of the function and precedes the function
|
|
||||||
* name in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
|
||||||
/* Win32 but not WinCE */
|
|
||||||
# define KHRONOS_APIENTRY __stdcall
|
|
||||||
#else
|
|
||||||
# define KHRONOS_APIENTRY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIATTRIBUTES
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the closing parenthesis of the function prototype arguments.
|
|
||||||
*/
|
|
||||||
#if defined (__ARMCC_2__)
|
|
||||||
#define KHRONOS_APIATTRIBUTES __softfp
|
|
||||||
#else
|
|
||||||
#define KHRONOS_APIATTRIBUTES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* basic type definitions
|
|
||||||
*-----------------------------------------------------------------------*/
|
|
||||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <stdint.h>
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
/*
|
|
||||||
* To support platform where unsigned long cannot be used interchangeably with
|
|
||||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
|
||||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
|
||||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
|
||||||
* unsigned long long or similar (this results in different C++ name mangling).
|
|
||||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
|
||||||
* platforms where the size of a pointer is larger than the size of long.
|
|
||||||
*/
|
|
||||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
|
||||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
|
||||||
#define KHRONOS_USE_INTPTR_T
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__VMS ) || defined(__sgi)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <inttypes.h>
|
|
||||||
*/
|
|
||||||
#include <inttypes.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Win32
|
|
||||||
*/
|
|
||||||
typedef __int32 khronos_int32_t;
|
|
||||||
typedef unsigned __int32 khronos_uint32_t;
|
|
||||||
typedef __int64 khronos_int64_t;
|
|
||||||
typedef unsigned __int64 khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(__sun__) || defined(__digital__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sun or Digital
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#if defined(__arch64__) || defined(_LP64)
|
|
||||||
typedef long int khronos_int64_t;
|
|
||||||
typedef unsigned long int khronos_uint64_t;
|
|
||||||
#else
|
|
||||||
typedef long long int khronos_int64_t;
|
|
||||||
typedef unsigned long long int khronos_uint64_t;
|
|
||||||
#endif /* __arch64__ */
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif 0
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hypothetical platform with no float or int64 support
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 0
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 0
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic fallback
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that are (so far) the same on all platforms
|
|
||||||
*/
|
|
||||||
typedef signed char khronos_int8_t;
|
|
||||||
typedef unsigned char khronos_uint8_t;
|
|
||||||
typedef signed short int khronos_int16_t;
|
|
||||||
typedef unsigned short int khronos_uint16_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
|
||||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
|
||||||
* to be the only LLP64 architecture in current use.
|
|
||||||
*/
|
|
||||||
#ifdef KHRONOS_USE_INTPTR_T
|
|
||||||
typedef intptr_t khronos_intptr_t;
|
|
||||||
typedef uintptr_t khronos_uintptr_t;
|
|
||||||
#elif defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_intptr_t;
|
|
||||||
typedef unsigned long long int khronos_uintptr_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_intptr_t;
|
|
||||||
typedef unsigned long int khronos_uintptr_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_ssize_t;
|
|
||||||
typedef unsigned long long int khronos_usize_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_ssize_t;
|
|
||||||
typedef unsigned long int khronos_usize_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_FLOAT
|
|
||||||
/*
|
|
||||||
* Float type
|
|
||||||
*/
|
|
||||||
typedef float khronos_float_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_INT64
|
|
||||||
/* Time types
|
|
||||||
*
|
|
||||||
* These types can be used to represent a time interval in nanoseconds or
|
|
||||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
|
||||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
|
||||||
* time the system booted). The Unadjusted System Time is an unsigned
|
|
||||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
|
||||||
* may be either signed or unsigned.
|
|
||||||
*/
|
|
||||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
|
||||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dummy value used to pad enum types to 32 bits.
|
|
||||||
*/
|
|
||||||
#ifndef KHRONOS_MAX_ENUM
|
|
||||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enumerated boolean type
|
|
||||||
*
|
|
||||||
* Values other than zero should be considered to be true. Therefore
|
|
||||||
* comparisons should not be made against KHRONOS_TRUE.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
KHRONOS_FALSE = 0,
|
|
||||||
KHRONOS_TRUE = 1,
|
|
||||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
|
||||||
} khronos_boolean_enum_t;
|
|
||||||
|
|
||||||
#endif /* __khrplatform_h_ */
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,25 +0,0 @@
|
||||||
#ifndef __FISHBONE_BASE_H__
|
|
||||||
#define __FISHBONE_BASE_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Base;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include <fishbone/log.h>
|
|
||||||
#include <fishbone/file.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Base : public fishbone::Logger {
|
|
||||||
fishbone::StringArrayMap mountpoints;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Base(fishbone::StringArrayMap param);
|
|
||||||
|
|
||||||
void mount(std::string name, std::string path);
|
|
||||||
fishbone::File* open(std::string path, std::string mode);
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,30 +1,17 @@
|
||||||
#ifndef __FISHBONE_CLIENT_H__
|
#ifndef __FISHBONE_CLIENT_H__
|
||||||
#define __FISHBONE_CLIENT_H__
|
#define __FISHBONE_CLIENT_H__
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class Client;
|
class Client;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <fishbone/machdep.h>
|
||||||
#include <fishbone/sound.h>
|
#include <fishbone/sound.h>
|
||||||
#include <fishbone/window.h>
|
|
||||||
#include <fishbone/mixer.h>
|
|
||||||
#include <fishbone/draw.h>
|
|
||||||
#include <fishbone/base.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class Client : public fishbone::Base {
|
class Client {
|
||||||
public:
|
public:
|
||||||
Client(fishbone::StringArrayMap param);
|
fishbone::SoundDriver sound;
|
||||||
~Client();
|
|
||||||
|
|
||||||
bool step();
|
|
||||||
|
|
||||||
fishbone::Window* window;
|
|
||||||
fishbone::SoundDriver* sounddrv;
|
|
||||||
fishbone::Mixer* mixer;
|
|
||||||
fishbone::Renderer* renderer;
|
|
||||||
};
|
};
|
||||||
}; // namespace fishbone
|
}; // namespace fishbone
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
#ifndef __FISHBOWL_DRAW_H__
|
|
||||||
#define __FISHBOWL_DRAW_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Texture;
|
|
||||||
class Mesh;
|
|
||||||
class Renderer;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#include <fishbone/window.h>
|
|
||||||
#include <fishbone/meshldr.h>
|
|
||||||
#include <fishbone/textureldr.h>
|
|
||||||
#include <fishbone/math.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Texture {
|
|
||||||
void init(fishbone::Renderer* renderer, unsigned char* rgba, int width, int height);
|
|
||||||
|
|
||||||
struct Impl;
|
|
||||||
Impl* impl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Texture(fishbone::Renderer* renderer, unsigned char* rgba, int width, int height) {
|
|
||||||
this->init(renderer, rgba, width, height);
|
|
||||||
}
|
|
||||||
Texture(fishbone::Renderer* renderer, fishbone::TextureData* data) {
|
|
||||||
this->init(renderer, data->rgba, data->width, data->height);
|
|
||||||
}
|
|
||||||
~Texture();
|
|
||||||
|
|
||||||
void begin();
|
|
||||||
void end();
|
|
||||||
};
|
|
||||||
|
|
||||||
class Mesh {
|
|
||||||
void init(fishbone::Renderer* renderer, std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals);
|
|
||||||
|
|
||||||
struct Impl;
|
|
||||||
Impl* impl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Mesh(fishbone::Renderer* renderer, std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
|
|
||||||
this->init(renderer, vertices, texcoords, normals);
|
|
||||||
}
|
|
||||||
Mesh(fishbone::Renderer* renderer, fishbone::MeshData* data) {
|
|
||||||
this->init(renderer, data->vertices, data->texcoords, data->normals);
|
|
||||||
}
|
|
||||||
~Mesh();
|
|
||||||
|
|
||||||
void draw();
|
|
||||||
void draw(struct fishbone::Vector3 pos);
|
|
||||||
void draw(struct fishbone::Vector3 pos, struct fishbone::Vector3 rot);
|
|
||||||
|
|
||||||
fishbone::Texture* texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
struct Impl;
|
|
||||||
Impl* impl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Renderer(fishbone::Window* window);
|
|
||||||
~Renderer();
|
|
||||||
|
|
||||||
void prepare();
|
|
||||||
void quad(std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
|
|
||||||
std::vector<struct fishbone::Vector3> v;
|
|
||||||
std::vector<struct fishbone::Vector2> t;
|
|
||||||
std::vector<struct fishbone::Vector3> n;
|
|
||||||
|
|
||||||
v = fishbone::quadToTriangle<struct fishbone::Vector3>(vertices);
|
|
||||||
t = fishbone::quadToTriangle<struct fishbone::Vector2>(texcoords);
|
|
||||||
n = fishbone::quadToTriangle<struct fishbone::Vector3>(normals);
|
|
||||||
|
|
||||||
this->triangle(v, t, n);
|
|
||||||
}
|
|
||||||
void triangle(std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals);
|
|
||||||
void quad(std::vector<struct fishbone::Vector2> vertices, std::vector<struct fishbone::Vector2> texcoords) {
|
|
||||||
std::vector<struct fishbone::Vector2> v;
|
|
||||||
std::vector<struct fishbone::Vector2> t;
|
|
||||||
|
|
||||||
v = fishbone::quadToTriangle<struct fishbone::Vector2>(vertices);
|
|
||||||
t = fishbone::quadToTriangle<struct fishbone::Vector2>(texcoords);
|
|
||||||
|
|
||||||
this->triangle(v, t);
|
|
||||||
}
|
|
||||||
void triangle(std::vector<struct fishbone::Vector2> vertices, std::vector<struct fishbone::Vector2> texcoords);
|
|
||||||
};
|
|
||||||
|
|
||||||
static float maxDistance = 64;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,30 +1,26 @@
|
||||||
#ifndef __FISHBONE_FILE_H__
|
#ifndef __FISHBONE_FILE_H__
|
||||||
#define __FISHBONE_FILE_H__
|
#define __FISHBONE_FILE_H__
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class File;
|
class File;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* no includes */
|
#include <fishbone/machdep.h>
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class File {
|
class File {
|
||||||
std::ifstream ifs;
|
std::ifstream ifs;
|
||||||
std::ofstream ofs;
|
std::ofstream ofs;
|
||||||
bool opened;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
File();
|
|
||||||
File(std::string path, std::string type);
|
File(std::string path, std::string type);
|
||||||
~File();
|
~File();
|
||||||
|
|
||||||
virtual size_t read(void* buffer, size_t size);
|
size_t read(void* buffer, size_t size);
|
||||||
virtual size_t write(const void* buffer, size_t size);
|
size_t write(const void* buffer, size_t size);
|
||||||
bool good();
|
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
|
bool good;
|
||||||
};
|
};
|
||||||
}; // namespace fishbone
|
}; // namespace fishbone
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#ifndef __FISHBONE_FILESYSTEM_H__
|
|
||||||
#define __FISHBONE_FILESYSTEM_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
bool exists(std::string path);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* no includes */
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
bool exists(std::string path);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -6,15 +6,5 @@
|
||||||
#include <fishbone/mixer.h>
|
#include <fishbone/mixer.h>
|
||||||
#include <fishbone/thread.h>
|
#include <fishbone/thread.h>
|
||||||
#include <fishbone/file.h>
|
#include <fishbone/file.h>
|
||||||
#include <fishbone/window.h>
|
|
||||||
#include <fishbone/resource.h>
|
|
||||||
#include <fishbone/draw.h>
|
|
||||||
#include <fishbone/time.h>
|
|
||||||
#include <fishbone/base.h>
|
|
||||||
#include <fishbone/meshldr.h>
|
|
||||||
#include <fishbone/log.h>
|
|
||||||
#include <fishbone/math.h>
|
|
||||||
#include <fishbone/textureldr.h>
|
|
||||||
#include <fishbone/filesystem.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
#ifndef __FISHBONE_LOG_H__
|
|
||||||
#define __FISHBONE_LOG_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Logger;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* no includes */
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Logger {
|
|
||||||
enum LoggerLevel {
|
|
||||||
Log = 0,
|
|
||||||
Info,
|
|
||||||
Warn,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
|
|
||||||
void init(std::string path);
|
|
||||||
|
|
||||||
std::ofstream ofs;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Logger();
|
|
||||||
Logger(std::string path);
|
|
||||||
~Logger();
|
|
||||||
|
|
||||||
void log(std::string arg);
|
|
||||||
void log(int level, std::string arg);
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -4,14 +4,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <chrono>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <fishbone/config.h>
|
#include <fishbone/config.h>
|
||||||
|
|
||||||
|
|
@ -21,21 +18,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STB_VORBIS_HEADER_ONLY
|
#define STB_VORBIS_HEADER_ONLY
|
||||||
#include <ode/ode.h>
|
#include <xmp.h>
|
||||||
|
|
||||||
#include <stb_image.h>
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include <stb_vorbis.c>
|
|
||||||
#include <dr_mp3.h>
|
#include <dr_mp3.h>
|
||||||
#include <dr_wav.h>
|
#include <dr_wav.h>
|
||||||
#include <dr_flac.h>
|
#include <dr_flac.h>
|
||||||
#include <xmp.h>
|
#include <stb_vorbis.c>
|
||||||
|
|
||||||
#include <lz4.h>
|
|
||||||
|
|
||||||
#include <enet/enet.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
#ifndef __FISHBONE_MATH_H__
|
|
||||||
#define __FISHBONE_MATH_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
float cot(float x);
|
|
||||||
template <typename T>
|
|
||||||
std::vector<T> quadToTriangle(std::vector<T> v);
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
/* no includes */
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
float cot(float x);
|
|
||||||
template <typename T>
|
|
||||||
std::vector<T> quadToTriangle(std::vector<T> v) {
|
|
||||||
std::vector<T> r;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1-4
|
|
||||||
* |\|
|
|
||||||
* 2-3
|
|
||||||
*/
|
|
||||||
for(int i = 0; i < v.size(); i += 4) {
|
|
||||||
r.push_back(v[i + 0]);
|
|
||||||
r.push_back(v[i + 1]);
|
|
||||||
r.push_back(v[i + 2]);
|
|
||||||
|
|
||||||
r.push_back(v[i + 2]);
|
|
||||||
r.push_back(v[i + 3]);
|
|
||||||
r.push_back(v[i + 0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double pi = 3.14159265358979323846;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#ifndef __FISHBONE_MESHLDR_H__
|
|
||||||
#define __FISHBONE_MESHLDR_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class MeshData;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include <fishbone/file.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class MeshData {
|
|
||||||
public:
|
|
||||||
MeshData(fishbone::File* file);
|
|
||||||
|
|
||||||
bool good();
|
|
||||||
|
|
||||||
std::vector<struct fishbone::Vector3> vertices;
|
|
||||||
std::vector<struct fishbone::Vector2> texcoords;
|
|
||||||
std::vector<struct fishbone::Vector3> normals;
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
#ifndef __FISHBONE_MIXER_H__
|
#ifndef __FISHBONE_MIXER_H__
|
||||||
#define __FISHBONE_MIXER_H__
|
#define __FISHBONE_MIXER_H__
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class Mixer;
|
class Mixer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <fishbone/machdep.h>
|
||||||
#include <fishbone/sound.h>
|
#include <fishbone/sound.h>
|
||||||
#include <fishbone/thread.h>
|
#include <fishbone/thread.h>
|
||||||
|
|
||||||
|
|
@ -23,10 +22,10 @@ namespace fishbone {
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
|
static const int rate = 44100;
|
||||||
std::vector<fishbone::SoundLoader*> loaders;
|
std::vector<fishbone::SoundLoader*> loaders;
|
||||||
std::vector<fishbone::Sound*> sounds;
|
std::vector<fishbone::Sound*> sounds;
|
||||||
float position[3];
|
float position[3];
|
||||||
static const int rate = 44100;
|
|
||||||
};
|
};
|
||||||
}; // namespace fishbone
|
}; // namespace fishbone
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#ifndef __FISHBONE_PRE_H__
|
|
||||||
#define __FISHBONE_PRE_H__
|
|
||||||
|
|
||||||
#include <fishbone/machdep.h>
|
|
||||||
#include <fishbone/types.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
#ifndef __FISHBONE_THREAD_H__
|
|
||||||
#define __FISHBONE_THREAD_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Resource;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#include <fishbone/file.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Resource {
|
|
||||||
public:
|
|
||||||
Resource(std::string path);
|
|
||||||
~Resource();
|
|
||||||
|
|
||||||
fishbone::File* open(std::string path);
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef __FISHBONE_SOUND_H__
|
#ifndef __FISHBONE_SOUND_H__
|
||||||
#define __FISHBONE_SOUND_H__
|
#define __FISHBONE_SOUND_H__
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
#define FB_SOUND_DECL(prefix) \
|
#define FB_SOUND_DECL(prefix) \
|
||||||
class prefix##SoundLoader; \
|
class prefix##SoundLoader; \
|
||||||
class prefix##Sound
|
class prefix##Sound
|
||||||
|
|
@ -39,6 +37,7 @@ namespace fishbone {
|
||||||
#undef LOADER
|
#undef LOADER
|
||||||
}; // namespace fishbone
|
}; // namespace fishbone
|
||||||
|
|
||||||
|
#include <fishbone/machdep.h>
|
||||||
#include <fishbone/mixer.h>
|
#include <fishbone/mixer.h>
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
|
|
@ -55,16 +54,12 @@ namespace fishbone {
|
||||||
|
|
||||||
class SoundLoader {
|
class SoundLoader {
|
||||||
public:
|
public:
|
||||||
SoundLoader() {};
|
SoundLoader();
|
||||||
~SoundLoader() {};
|
~SoundLoader();
|
||||||
|
|
||||||
virtual Sound* open(Mixer* mixer, void* buffer, size_t size) {
|
virtual Sound* open(Mixer* mixer, void* buffer, size_t size);
|
||||||
return nullptr;
|
virtual int read(Sound* sound, short* buffer, size_t frames);
|
||||||
};
|
virtual void seek(Sound* sound, size_t pos);
|
||||||
virtual int read(Sound* sound, short* buffer, size_t frames) {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
virtual void seek(Sound* sound, size_t pos) {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Sound {
|
class Sound {
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
#ifndef __FISHBONE_TEXLDR_H__
|
|
||||||
#define __FISHBONE_TEXLDR_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class TextureData;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include <fishbone/file.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class TextureData {
|
|
||||||
public:
|
|
||||||
TextureData(fishbone::File* file);
|
|
||||||
~TextureData();
|
|
||||||
|
|
||||||
bool good();
|
|
||||||
|
|
||||||
unsigned char* rgba;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
#ifndef __FISHBONE_THREAD_H__
|
#ifndef __FISHBONE_THREAD_H__
|
||||||
#define __FISHBONE_THREAD_H__
|
#define __FISHBONE_THREAD_H__
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class Thread;
|
class Thread;
|
||||||
class Mutex;
|
class Mutex;
|
||||||
}; // namespace fishbone
|
}; // namespace fishbone
|
||||||
|
|
||||||
/* no includes */
|
#include <fishbone/machdep.h>
|
||||||
|
|
||||||
namespace fishbone {
|
namespace fishbone {
|
||||||
class Thread {
|
class Thread {
|
||||||
|
|
@ -16,11 +14,11 @@ namespace fishbone {
|
||||||
Impl* impl;
|
Impl* impl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Callable = void (*)(fishbone::Thread* thread, void* arg);
|
using Callable = void(*)(fishbone::Thread* thread, void* arg);
|
||||||
using CallableLambda = std::function<void(fishbone::Thread* thread)>;
|
using CallableFunc = std::function<void(fishbone::Thread* thread)>;
|
||||||
|
|
||||||
Thread(Callable call, void* arg);
|
Thread(Callable call, void* arg);
|
||||||
Thread(CallableLambda call);
|
Thread(CallableFunc call);
|
||||||
~Thread();
|
~Thread();
|
||||||
|
|
||||||
void join();
|
void join();
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
#ifndef __FISHBONE_TIME_H__
|
|
||||||
#define __FISHBONE_TIME_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
using AccurateClock = std::chrono::time_point<std::chrono::high_resolution_clock, std::chrono::high_resolution_clock::duration>;
|
|
||||||
|
|
||||||
fishbone::AccurateClock accurateTime();
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
/* no includes */
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
fishbone::AccurateClock accurateTime();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
#ifndef __FISHBOWL_TYPES_H__
|
|
||||||
#define __FISHBOWL_TYPES_H__
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
struct Vector2 {
|
|
||||||
struct fishbone::Vector2 operator+(struct fishbone::Vector2 v) const;
|
|
||||||
struct fishbone::Vector2 operator-(struct fishbone::Vector2 v) const;
|
|
||||||
|
|
||||||
float length();
|
|
||||||
struct fishbone::Vector2 normalize();
|
|
||||||
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Vector3 {
|
|
||||||
struct fishbone::Vector3 operator+(struct fishbone::Vector3 v) const;
|
|
||||||
struct fishbone::Vector3 operator-(struct fishbone::Vector3 v) const;
|
|
||||||
struct fishbone::Vector3 operator*(struct fishbone::Vector3 v) const;
|
|
||||||
|
|
||||||
float length();
|
|
||||||
struct fishbone::Vector3 normalize();
|
|
||||||
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Quaternion {
|
|
||||||
struct fishbone::Quaternion operator+(struct fishbone::Quaternion q) const;
|
|
||||||
struct fishbone::Quaternion operator-(struct fishbone::Quaternion q) const;
|
|
||||||
|
|
||||||
float w;
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
};
|
|
||||||
|
|
||||||
using StringArrayMap = std::unordered_map<std::string, std::vector<std::string>>;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#ifndef __FISHBONE_WINDOW_H__
|
|
||||||
#define __FISHBONE_WINDOW_H__
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Window;
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#include <fishbone/pre.h>
|
|
||||||
|
|
||||||
namespace fishbone {
|
|
||||||
class Window {
|
|
||||||
struct Impl;
|
|
||||||
Impl* impl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Window(std::string title, int width, int height);
|
|
||||||
~Window();
|
|
||||||
|
|
||||||
void poll();
|
|
||||||
void swapBuffer();
|
|
||||||
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
}; // namespace fishbone
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
fishbone::Base::Base(fishbone::StringArrayMap param) {
|
|
||||||
for(auto i = param.begin(); i != param.end(); i++) {
|
|
||||||
if(i->first == "basedir") {
|
|
||||||
for(int j = 0; j < i->second.size(); j++) {
|
|
||||||
this->mount("base", i->second[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Base::mount(std::string name, std::string path) {
|
|
||||||
if(this->mountpoints.find(name) == this->mountpoints.end()) this->mountpoints[name] = {};
|
|
||||||
|
|
||||||
this->mountpoints[name].push_back(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::File* fishbone::Base::open(std::string path, std::string mode) {
|
|
||||||
fishbone::File* f = nullptr;
|
|
||||||
|
|
||||||
for(int i = 0; i < path.size() - 1; i++) {
|
|
||||||
if(path.substr(i, 2) == ":/") {
|
|
||||||
std::string p = path.substr(i + 1);
|
|
||||||
std::string k = path.substr(0, i);
|
|
||||||
|
|
||||||
if(this->mountpoints.find(k) != this->mountpoints.end()) {
|
|
||||||
for(int j = 0; j < this->mountpoints[k].size(); j++) {
|
|
||||||
f = new fishbone::File(this->mountpoints[k][j] + p, mode);
|
|
||||||
|
|
||||||
if(!f->good()) {
|
|
||||||
delete f;
|
|
||||||
f = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(f != nullptr && f->good()) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(f == nullptr) f = new fishbone::File(path, mode);
|
|
||||||
|
|
||||||
if(f != nullptr && !f->good()) {
|
|
||||||
delete f;
|
|
||||||
f = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +1 @@
|
||||||
#include <fishbone/foundation.h>
|
#include <fishbone/client.h>
|
||||||
|
|
||||||
fishbone::File* f;
|
|
||||||
fishbone::Mesh* m;
|
|
||||||
|
|
||||||
fishbone::Client::Client(fishbone::StringArrayMap param)
|
|
||||||
: fishbone::Base::Base(param) {
|
|
||||||
this->window = new fishbone::Window("Fishbone", 800, 600);
|
|
||||||
this->sounddrv = new fishbone::SoundDriver();
|
|
||||||
this->mixer = &this->sounddrv->mixer;
|
|
||||||
this->renderer = new fishbone::Renderer(this->window);
|
|
||||||
|
|
||||||
fishbone::MeshData* md;
|
|
||||||
fishbone::TextureData* td;
|
|
||||||
|
|
||||||
f = this->open("base:/model.obj", "r");
|
|
||||||
md = new fishbone::MeshData(f);
|
|
||||||
delete f;
|
|
||||||
|
|
||||||
f = this->open("base:/model.png", "r");
|
|
||||||
td = new fishbone::TextureData(f);
|
|
||||||
delete f;
|
|
||||||
|
|
||||||
m = new fishbone::Mesh(this->renderer, md);
|
|
||||||
m->texture = new fishbone::Texture(this->renderer, td);
|
|
||||||
|
|
||||||
delete md;
|
|
||||||
delete td;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Client::~Client() {
|
|
||||||
delete this->renderer;
|
|
||||||
delete this->sounddrv;
|
|
||||||
delete this->window;
|
|
||||||
}
|
|
||||||
|
|
||||||
float r = 0;
|
|
||||||
|
|
||||||
bool fishbone::Client::step() {
|
|
||||||
this->renderer->prepare();
|
|
||||||
|
|
||||||
m->draw((struct fishbone::Vector3){0, 0, 0}, (struct fishbone::Vector3){r, r, r});
|
|
||||||
r += 30.0 / 60;
|
|
||||||
|
|
||||||
this->window->swapBuffer();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,308 +0,0 @@
|
||||||
#include <fishbone/config.h>
|
|
||||||
#ifdef FISHBONE_DRAW_USE_OPENGL
|
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
struct fishbone::Texture::Impl {
|
|
||||||
GLuint texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
void fishbone::Texture::init(fishbone::Renderer* renderer, unsigned char* rgba, int width, int height) {
|
|
||||||
this->impl = new struct fishbone::Texture::Impl();
|
|
||||||
|
|
||||||
glGenTextures(1, &this->impl->texture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, this->impl->texture);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Texture::~Texture() {
|
|
||||||
glDeleteTextures(1, &this->impl->texture);
|
|
||||||
|
|
||||||
delete this->impl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Texture::begin() {
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, this->impl->texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Texture::end() {
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Mesh::Impl {
|
|
||||||
GLuint v_vbo;
|
|
||||||
GLuint t_vbo;
|
|
||||||
GLuint n_vbo;
|
|
||||||
|
|
||||||
GLfloat* vertices;
|
|
||||||
GLfloat* texcoords;
|
|
||||||
GLfloat* normals;
|
|
||||||
|
|
||||||
int count;
|
|
||||||
};
|
|
||||||
|
|
||||||
void fishbone::Mesh::init(fishbone::Renderer* renderer, std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
|
|
||||||
this->texture = nullptr;
|
|
||||||
|
|
||||||
this->impl = new struct fishbone::Mesh::Impl();
|
|
||||||
this->impl->vertices = new GLfloat[vertices.size() * 3];
|
|
||||||
this->impl->texcoords = new GLfloat[texcoords.size() * 2];
|
|
||||||
this->impl->normals = new GLfloat[normals.size() * 3];
|
|
||||||
this->impl->count = vertices.size();
|
|
||||||
|
|
||||||
glGenBuffers(1, &this->impl->v_vbo);
|
|
||||||
glGenBuffers(1, &this->impl->t_vbo);
|
|
||||||
glGenBuffers(1, &this->impl->n_vbo);
|
|
||||||
|
|
||||||
for(int i = 0; i < vertices.size(); i++) {
|
|
||||||
this->impl->vertices[i * 3 + 0] = vertices[i].x;
|
|
||||||
this->impl->vertices[i * 3 + 1] = vertices[i].y;
|
|
||||||
this->impl->vertices[i * 3 + 2] = vertices[i].z;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < texcoords.size(); i++) {
|
|
||||||
this->impl->texcoords[i * 2 + 0] = texcoords[i].x;
|
|
||||||
this->impl->texcoords[i * 2 + 1] = texcoords[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < normals.size(); i++) {
|
|
||||||
this->impl->normals[i * 3 + 0] = normals[i].x;
|
|
||||||
this->impl->normals[i * 3 + 1] = normals[i].y;
|
|
||||||
this->impl->normals[i * 3 + 2] = normals[i].z;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->v_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float) * 3, this->impl->vertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->t_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, texcoords.size() * sizeof(float) * 2, this->impl->texcoords, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->n_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(float) * 3, this->impl->normals, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Mesh::~Mesh() {
|
|
||||||
glDeleteBuffers(1, &this->impl->n_vbo);
|
|
||||||
glDeleteBuffers(1, &this->impl->t_vbo);
|
|
||||||
glDeleteBuffers(1, &this->impl->v_vbo);
|
|
||||||
|
|
||||||
delete[] this->impl->normals;
|
|
||||||
delete[] this->impl->texcoords;
|
|
||||||
delete[] this->impl->vertices;
|
|
||||||
delete this->impl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Mesh::draw() {
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->v_vbo);
|
|
||||||
glVertexPointer(3, GL_FLOAT, 0, nullptr);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->t_vbo);
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, this->impl->n_vbo);
|
|
||||||
glNormalPointer(GL_FLOAT, 0, nullptr);
|
|
||||||
|
|
||||||
glColor3f(1, 1, 1);
|
|
||||||
if(this->texture != nullptr) this->texture->begin();
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, this->impl->count);
|
|
||||||
if(this->texture != nullptr) this->texture->end();
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Mesh::draw(struct fishbone::Vector3 pos) {
|
|
||||||
this->draw(pos, {0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Mesh::draw(struct fishbone::Vector3 pos, struct fishbone::Vector3 rot) {
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(pos.x, pos.y, pos.z);
|
|
||||||
glRotatef(rot.x, 1, 0, 0);
|
|
||||||
glRotatef(rot.y, 0, 1, 0);
|
|
||||||
glRotatef(rot.z, 0, 0, 1);
|
|
||||||
|
|
||||||
this->draw();
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Renderer::Impl {
|
|
||||||
fishbone::Window* window;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void cameraPerspective(float width, float height) {
|
|
||||||
float aspect;
|
|
||||||
float f;
|
|
||||||
GLdouble matrix[16];
|
|
||||||
float fovy = 60.0;
|
|
||||||
float znear = 0.01;
|
|
||||||
float zfar = fishbone::maxDistance;
|
|
||||||
|
|
||||||
aspect = width / height;
|
|
||||||
f = fishbone::cot(fovy / 180 * fishbone::pi / 2);
|
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) matrix[i] = 0;
|
|
||||||
matrix[4 * 0 + 0] = f / aspect;
|
|
||||||
matrix[4 * 1 + 1] = f;
|
|
||||||
matrix[4 * 2 + 2] = (zfar + znear) / (znear - zfar);
|
|
||||||
matrix[4 * 3 + 2] = ((GLdouble)2 * zfar * znear) / (znear - zfar);
|
|
||||||
matrix[4 * 2 + 3] = -1;
|
|
||||||
|
|
||||||
glMultMatrixd(matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void lookAt(fishbone::Vector3 camera, fishbone::Vector3 look_at) {
|
|
||||||
GLdouble matrix[16];
|
|
||||||
fishbone::Vector3 f;
|
|
||||||
fishbone::Vector3 up;
|
|
||||||
fishbone::Vector3 s;
|
|
||||||
fishbone::Vector3 u;
|
|
||||||
|
|
||||||
f = (look_at - camera).normalize();
|
|
||||||
|
|
||||||
up.x = 0;
|
|
||||||
up.y = 1;
|
|
||||||
up.z = 0;
|
|
||||||
up = up.normalize();
|
|
||||||
|
|
||||||
s = (f * up).normalize();
|
|
||||||
|
|
||||||
u = s * f;
|
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) matrix[i] = 0;
|
|
||||||
matrix[4 * 0 + 0] = s.x;
|
|
||||||
matrix[4 * 1 + 0] = s.y;
|
|
||||||
matrix[4 * 2 + 0] = s.z;
|
|
||||||
matrix[4 * 0 + 1] = u.x;
|
|
||||||
matrix[4 * 1 + 1] = u.y;
|
|
||||||
matrix[4 * 2 + 1] = u.z;
|
|
||||||
matrix[4 * 0 + 2] = -f.x;
|
|
||||||
matrix[4 * 1 + 2] = -f.y;
|
|
||||||
matrix[4 * 2 + 2] = -f.z;
|
|
||||||
matrix[4 * 3 + 3] = 1;
|
|
||||||
|
|
||||||
glMultMatrixd(matrix);
|
|
||||||
glTranslated(-camera.x, -camera.y, -camera.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Renderer::Renderer(fishbone::Window* window) {
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_NORMALIZE);
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glEnable(GL_LIGHT0);
|
|
||||||
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat[]){0, -1, 0, 1});
|
|
||||||
|
|
||||||
this->impl = new struct fishbone::Renderer::Impl();
|
|
||||||
this->impl->window = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Renderer::~Renderer() {
|
|
||||||
delete this->impl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Renderer::prepare() {
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
|
||||||
cameraPerspective(this->impl->window->width, this->impl->window->height);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
lookAt({4, 4, 4}, {0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Renderer::triangle(std::vector<struct fishbone::Vector3> vertices, std::vector<struct fishbone::Vector2> texcoords, std::vector<struct fishbone::Vector3> normals) {
|
|
||||||
GLfloat* v = new GLfloat[vertices.size() * 3];
|
|
||||||
GLfloat* t = new GLfloat[texcoords.size() * 2];
|
|
||||||
GLfloat* n = new GLfloat[normals.size() * 3];
|
|
||||||
|
|
||||||
for(int i = 0; i < vertices.size(); i++) {
|
|
||||||
v[i * 3 + 0] = vertices[i].x;
|
|
||||||
v[i * 3 + 1] = vertices[i].y;
|
|
||||||
v[i * 3 + 2] = vertices[i].z;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < texcoords.size(); i++) {
|
|
||||||
t[i * 2 + 0] = texcoords[i].x;
|
|
||||||
t[i * 2 + 1] = texcoords[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < normals.size(); i++) {
|
|
||||||
n[i * 3 + 0] = normals[i].x;
|
|
||||||
n[i * 3 + 1] = normals[i].y;
|
|
||||||
n[i * 3 + 2] = normals[i].z;
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
|
||||||
|
|
||||||
glVertexPointer(3, GL_FLOAT, 0, v);
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, t);
|
|
||||||
glNormalPointer(GL_FLOAT, 0, n);
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
|
|
||||||
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
|
|
||||||
delete[] n;
|
|
||||||
delete[] t;
|
|
||||||
delete[] v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Renderer::triangle(std::vector<struct fishbone::Vector2> vertices, std::vector<struct fishbone::Vector2> texcoords) {
|
|
||||||
GLfloat* v = new GLfloat[vertices.size() * 2];
|
|
||||||
GLfloat* t = new GLfloat[texcoords.size() * 2];
|
|
||||||
|
|
||||||
for(int i = 0; i < vertices.size(); i++) {
|
|
||||||
v[i * 2 + 0] = vertices[i].x;
|
|
||||||
v[i * 2 + 1] = vertices[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < texcoords.size(); i++) {
|
|
||||||
t[i * 2 + 0] = texcoords[i].x;
|
|
||||||
t[i * 2 + 1] = texcoords[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
|
|
||||||
glVertexPointer(2, GL_FLOAT, 0, v);
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, t);
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
|
|
||||||
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
|
|
||||||
delete[] t;
|
|
||||||
delete[] v;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
#include <fishbone/file.h>
|
#include <fishbone/file.h>
|
||||||
|
|
||||||
fishbone::File::File() {
|
|
||||||
this->size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::File::File(std::string path, std::string type) {
|
fishbone::File::File(std::string path, std::string type) {
|
||||||
this->size = 0;
|
this->good = false;
|
||||||
this->opened = false;
|
this->size = 0;
|
||||||
|
|
||||||
if(type == "r") {
|
if(type == "r") {
|
||||||
this->ifs = std::ifstream(path, std::ios::binary);
|
this->ifs = std::ifstream(path, std::ios::binary);
|
||||||
|
|
@ -24,12 +20,10 @@ fishbone::File::File(std::string path, std::string type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->opened = true;
|
this->good = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fishbone::File::~File() {
|
fishbone::File::~File() {
|
||||||
this->ifs.close();
|
|
||||||
this->ofs.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fishbone::File::read(void* buffer, size_t size) {
|
size_t fishbone::File::read(void* buffer, size_t size) {
|
||||||
|
|
@ -47,8 +41,3 @@ size_t fishbone::File::write(const void* buffer, size_t size) {
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fishbone::File::good() {
|
|
||||||
if(this->opened) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
bool fishbone::exists(std::string path) {
|
|
||||||
struct stat s;
|
|
||||||
|
|
||||||
if(stat(path.c_str(), &s) == 0) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
void fishbone::Logger::init(std::string path) {
|
|
||||||
this->ofs = std::ofstream(path, std::ios_base::app);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Logger::Logger() {
|
|
||||||
this->init("log.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Logger::Logger(std::string path) {
|
|
||||||
this->init(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Logger::~Logger() {
|
|
||||||
this->ofs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Logger::log(std::string arg) {
|
|
||||||
this->log(fishbone::Logger::Info, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Logger::log(int level, std::string arg) {
|
|
||||||
this->ofs << "" + arg << std::endl;
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
float fishbone::cot(float x) {
|
|
||||||
return 1.0 / tan(x);
|
|
||||||
}
|
|
||||||
|
|
@ -1,128 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
static std::vector<int> parseFace(std::string s) {
|
|
||||||
std::vector<int> v;
|
|
||||||
std::string n = "";
|
|
||||||
|
|
||||||
for(int i = 0; i < s.size(); i++) {
|
|
||||||
if(s[i] == '/') {
|
|
||||||
v.push_back(std::stoi(n));
|
|
||||||
n = "";
|
|
||||||
} else {
|
|
||||||
n += s[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(n.size() > 0) v.push_back(std::stoi(n));
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::MeshData::MeshData(fishbone::File* f) {
|
|
||||||
char c;
|
|
||||||
std::string l = "";
|
|
||||||
std::vector<struct fishbone::Vector3> v;
|
|
||||||
std::vector<struct fishbone::Vector2> vt;
|
|
||||||
std::vector<struct fishbone::Vector3> vn;
|
|
||||||
fishbone::Vector2 e2 = {0, 0};
|
|
||||||
fishbone::Vector3 e3 = {0, 0, 0};
|
|
||||||
float lm = 0; /* leftmost */
|
|
||||||
float rm = 0; /* rightmost */
|
|
||||||
float um = 0; /* upmost */
|
|
||||||
float dm = 0; /* downmost */
|
|
||||||
float fm = 0; /* frontmost */
|
|
||||||
float bm = 0; /* backmost */
|
|
||||||
|
|
||||||
while(f->read(&c, 1) == 1) {
|
|
||||||
if(c == '\n') {
|
|
||||||
if(l.size() == 0) {
|
|
||||||
} else if(l[0] == '#') {
|
|
||||||
} else {
|
|
||||||
std::vector<std::string> vs;
|
|
||||||
std::string n = "";
|
|
||||||
|
|
||||||
for(int i = 0; i < l.size(); i++) {
|
|
||||||
if(l[i] == ' ') {
|
|
||||||
vs.push_back(n);
|
|
||||||
n = "";
|
|
||||||
} else {
|
|
||||||
n += l[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(n.size() > 0) vs.push_back(n);
|
|
||||||
|
|
||||||
if(vs[0] == "v") {
|
|
||||||
fishbone::Vector3 nv = {std::stof(vs[1]), std::stof(vs[2]), std::stof(vs[3])};
|
|
||||||
|
|
||||||
if(lm > nv.x) lm = nv.x;
|
|
||||||
if(rm < nv.x) rm = nv.x;
|
|
||||||
|
|
||||||
if(dm > nv.y) dm = nv.y;
|
|
||||||
if(um < nv.y) um = nv.y;
|
|
||||||
|
|
||||||
if(fm > nv.z) fm = nv.z;
|
|
||||||
if(bm < nv.z) bm = nv.z;
|
|
||||||
|
|
||||||
v.push_back(nv);
|
|
||||||
} else if(vs[0] == "vt") {
|
|
||||||
fishbone::Vector2 nv = {std::stof(vs[1]), 1 - std::stof(vs[2])};
|
|
||||||
|
|
||||||
vt.push_back(nv);
|
|
||||||
} else if(vs[0] == "vn") {
|
|
||||||
fishbone::Vector3 nv = {std::stof(vs[1]), std::stof(vs[2]), std::stof(vs[3])};
|
|
||||||
|
|
||||||
vn.push_back(nv);
|
|
||||||
} else if(vs[0] == "f") {
|
|
||||||
float sc = 0;
|
|
||||||
float lr = fabs(lm - rm);
|
|
||||||
float ud = fabs(um - dm);
|
|
||||||
float bf = fabs(fm - bm);
|
|
||||||
std::vector<int> ind;
|
|
||||||
struct fishbone::Vector3 v3;
|
|
||||||
|
|
||||||
if(sc < lr) sc = lr;
|
|
||||||
if(sc < ud) sc = ud;
|
|
||||||
if(sc < bf) sc = bf;
|
|
||||||
|
|
||||||
sc /= 2;
|
|
||||||
|
|
||||||
#define PUSH(i) \
|
|
||||||
ind = parseFace(vs[i]); \
|
|
||||||
v3 = v[ind[0] - 1]; \
|
|
||||||
\
|
|
||||||
v3.x /= sc; \
|
|
||||||
v3.y /= sc; \
|
|
||||||
v3.z /= sc; \
|
|
||||||
\
|
|
||||||
this->vertices.push_back(v3); \
|
|
||||||
this->texcoords.push_back(ind.size() >= 2 ? vt[ind[1] - 1] : e2); \
|
|
||||||
this->normals.push_back(ind.size() >= 3 ? vn[ind[2] - 1] : e3);
|
|
||||||
|
|
||||||
for(int i = 1; i < 4; i++) {
|
|
||||||
PUSH(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it's quad...
|
|
||||||
* 1-4
|
|
||||||
* |\|
|
|
||||||
* 2-3
|
|
||||||
*/
|
|
||||||
if(vs.size() == 5) {
|
|
||||||
PUSH(3);
|
|
||||||
PUSH(4);
|
|
||||||
PUSH(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l = "";
|
|
||||||
} else if(c != '\r') {
|
|
||||||
l += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fishbone::MeshData::good() {
|
|
||||||
if(this->vertices.size() == 0) return false;
|
|
||||||
if(this->texcoords.size() == 0) return false;
|
|
||||||
if(this->normals.size() == 0) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
@ -83,7 +83,7 @@ void fishbone::Mixer::read(short* buffer, size_t frames) {
|
||||||
r = req[(j * this->sounds[i]->rate / fishbone::Mixer::rate) * 2 + 1];
|
r = req[(j * this->sounds[i]->rate / fishbone::Mixer::rate) * 2 + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->sounds[i]->is3d) {
|
if(this->sounds[i]->is3d){
|
||||||
l = (l + r) / 2;
|
l = (l + r) / 2;
|
||||||
r = l;
|
r = l;
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ fishbone::Sound* fishbone::Mixer::open(const char* path) {
|
||||||
unsigned char* buffer;
|
unsigned char* buffer;
|
||||||
fishbone::Sound* snd;
|
fishbone::Sound* snd;
|
||||||
|
|
||||||
if(!f.good()) return nullptr;
|
if(!f.good) return nullptr;
|
||||||
|
|
||||||
buffer = new unsigned char[f.size];
|
buffer = new unsigned char[f.size];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
@ -1,5 +1,22 @@
|
||||||
#include <fishbone/foundation.h>
|
#include <fishbone/foundation.h>
|
||||||
|
|
||||||
|
fishbone::SoundLoader::SoundLoader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fishbone::SoundLoader::~SoundLoader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fishbone::Sound* fishbone::SoundLoader::open(fishbone::Mixer* mixer, void* buffer, size_t size) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fishbone::SoundLoader::read(fishbone::Sound* sound, short* buffer, size_t frames) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fishbone::SoundLoader::seek(fishbone::Sound* sound, size_t pos) {
|
||||||
|
}
|
||||||
|
|
||||||
fishbone::Sound::Sound(fishbone::Mixer* mixer, fishbone::SoundLoader* loader, struct fishbone::Sound::Impl* impl) {
|
fishbone::Sound::Sound(fishbone::Mixer* mixer, fishbone::SoundLoader* loader, struct fishbone::Sound::Impl* impl) {
|
||||||
this->mixer = mixer;
|
this->mixer = mixer;
|
||||||
this->loader = loader;
|
this->loader = loader;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
fishbone::TextureData::TextureData(fishbone::File* f) {
|
|
||||||
unsigned char* buf = new unsigned char[f->size];
|
|
||||||
int ch;
|
|
||||||
|
|
||||||
f->read(buf, f->size);
|
|
||||||
|
|
||||||
this->rgba = stbi_load_from_memory(buf, f->size, &this->width, &this->height, &ch, 4);
|
|
||||||
|
|
||||||
delete[] buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::TextureData::~TextureData() {
|
|
||||||
if(this->rgba != nullptr) free(this->rgba);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fishbone::TextureData::good() {
|
|
||||||
if(this->rgba == nullptr) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
#include <fishbone/foundation.h>
|
#include <fishbone/foundation.h>
|
||||||
|
|
||||||
struct call_arg {
|
struct call_arg {
|
||||||
fishbone::Thread::Callable call;
|
fishbone::Thread::Callable call;
|
||||||
fishbone::Thread* thread;
|
fishbone::Thread* thread;
|
||||||
void* arg;
|
void* arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct call_arg2 {
|
struct call_arg2 {
|
||||||
fishbone::Thread::CallableLambda call;
|
fishbone::Thread::CallableFunc call;
|
||||||
fishbone::Thread* thread;
|
fishbone::Thread* thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int SDLCALL thread_call(void* data) {
|
static int SDLCALL thread_call(void* data) {
|
||||||
|
|
@ -48,7 +48,7 @@ fishbone::Thread::Thread(Callable call, void* arg) {
|
||||||
this->impl->thread = SDL_CreateThread(thread_call, "FBThread", data);
|
this->impl->thread = SDL_CreateThread(thread_call, "FBThread", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fishbone::Thread::Thread(CallableLambda call) {
|
fishbone::Thread::Thread(CallableFunc call) {
|
||||||
struct call_arg2* data = new struct call_arg2();
|
struct call_arg2* data = new struct call_arg2();
|
||||||
|
|
||||||
data->call = call;
|
data->call = call;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
fishbone::AccurateClock fishbone::accurateTime() {
|
|
||||||
return std::chrono::high_resolution_clock::now();
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
#include <fishbone/foundation.h>
|
|
||||||
|
|
||||||
struct fishbone::Vector2 fishbone::Vector2::operator+(struct fishbone::Vector2 v) const {
|
|
||||||
return {this->x + v.x, this->y + v.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector2 fishbone::Vector2::operator-(struct fishbone::Vector2 v) const {
|
|
||||||
return {this->x - v.x, this->y - v.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
float fishbone::Vector2::length() {
|
|
||||||
return sqrt(this->x * this->x + this->y * this->y);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector2 fishbone::Vector2::normalize() {
|
|
||||||
float l = this->length();
|
|
||||||
|
|
||||||
if(l > 0) {
|
|
||||||
l = 1 / l;
|
|
||||||
} else {
|
|
||||||
l = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {this->x * l, this->y * l};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector3 fishbone::Vector3::operator+(struct fishbone::Vector3 v) const {
|
|
||||||
return {this->x + v.x, this->y + v.y, this->z + v.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector3 fishbone::Vector3::operator-(struct fishbone::Vector3 v) const {
|
|
||||||
return {this->x - v.x, this->y - v.y, this->z - v.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector3 fishbone::Vector3::operator*(struct fishbone::Vector3 v) const {
|
|
||||||
return {
|
|
||||||
this->y * v.z - this->z * v.y,
|
|
||||||
this->z * v.x - this->x * v.z,
|
|
||||||
this->x * v.y - this->y * v.x};
|
|
||||||
}
|
|
||||||
|
|
||||||
float fishbone::Vector3::length() {
|
|
||||||
return sqrt(this->x * this->x + this->y * this->y + this->z * this->z);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Vector3 fishbone::Vector3::normalize() {
|
|
||||||
float l = this->length();
|
|
||||||
|
|
||||||
if(l > 0) {
|
|
||||||
l = 1 / l;
|
|
||||||
} else {
|
|
||||||
l = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {this->x * l, this->y * l, this->z * l};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Quaternion fishbone::Quaternion::operator+(struct fishbone::Quaternion q) const {
|
|
||||||
return {this->w + q.w, this->x + q.x, this->y + q.y, this->z + q.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fishbone::Quaternion fishbone::Quaternion::operator-(struct fishbone::Quaternion q) const {
|
|
||||||
return {this->w - q.w, this->x - q.x, this->y - q.y, this->z - q.z};
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +1,4 @@
|
||||||
#include <fishbone/config.h>
|
#include <fishbone/config.h>
|
||||||
#ifdef FISHBONE_WINDOW_USE_SDL2
|
#ifdef FISHBONE_WINDOW_USE_SDL2
|
||||||
#include <fishbone/foundation.h>
|
#include <fishbone/foundation.h>
|
||||||
|
|
||||||
static bool sdl_video_init = false;
|
|
||||||
|
|
||||||
struct fishbone::Window::Impl {
|
|
||||||
SDL_Window* window;
|
|
||||||
SDL_GLContext ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
fishbone::Window::Window(std::string title, int width, int height) {
|
|
||||||
if(!sdl_video_init) {
|
|
||||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
|
||||||
sdl_video_init = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->impl = new fishbone::Window::Impl();
|
|
||||||
this->impl->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
|
|
||||||
this->impl->ctx = SDL_GL_CreateContext(this->impl->window);
|
|
||||||
|
|
||||||
gladLoadGL();
|
|
||||||
|
|
||||||
this->width = width;
|
|
||||||
this->height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
fishbone::Window::~Window() {
|
|
||||||
SDL_GL_DeleteContext(this->impl->ctx);
|
|
||||||
SDL_DestroyWindow(this->impl->window);
|
|
||||||
delete this->impl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Window::poll() {
|
|
||||||
SDL_Event ev;
|
|
||||||
|
|
||||||
while(SDL_PollEvent(&ev)) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fishbone::Window::swapBuffer() {
|
|
||||||
SDL_GL_SwapWindow(this->impl->window);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ TEST_CASE("Mutex") {
|
||||||
int a = 0;
|
int a = 0;
|
||||||
fishbone::Mutex m;
|
fishbone::Mutex m;
|
||||||
|
|
||||||
fishbone::Thread::CallableLambda func = [&a, &m](auto) {
|
fishbone::Thread::CallableFunc func = [&a, &m](auto) {
|
||||||
m.lock();
|
m.lock();
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
int b = a;
|
int b = a;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
project(tools)
|
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/util.cmake")
|
|
||||||
|
|
||||||
add_executable(packer packer.cc)
|
|
||||||
|
|
||||||
fb_add_dep(packer lz4)
|
|
||||||
|
|
@ -1,240 +0,0 @@
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include <lz4frame.h>
|
|
||||||
|
|
||||||
#define PATH_PART_LEN 32
|
|
||||||
|
|
||||||
/* Resource file is in simple structure:
|
|
||||||
* 4 bytes: ID
|
|
||||||
* 2 bytes: Data size
|
|
||||||
* n bytes: Data
|
|
||||||
*
|
|
||||||
* Subchunks come after data, so you have to know how chunk is strcutured
|
|
||||||
*
|
|
||||||
* All numbers are in native endian
|
|
||||||
*
|
|
||||||
* DIRE chunk comes with following data:
|
|
||||||
* PATH_PART_LEN bytes name
|
|
||||||
* and nests FILE chunks
|
|
||||||
*
|
|
||||||
* FILE chunk comes with following data:
|
|
||||||
* 2 bytes flag
|
|
||||||
* 4 bytes data location
|
|
||||||
* 4 bytes data size
|
|
||||||
* PATH_PART_LEN bytes name
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct Data {
|
|
||||||
unsigned int size;
|
|
||||||
unsigned char* data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define FILE_FLAG_RAW (1 << 0)
|
|
||||||
|
|
||||||
unsigned int loc = 0;
|
|
||||||
std::vector<struct Data> datalist;
|
|
||||||
|
|
||||||
class Chunk;
|
|
||||||
|
|
||||||
class Chunk {
|
|
||||||
void init(std::string name){
|
|
||||||
this->data = nullptr;
|
|
||||||
memset(this->id, 0, 4);
|
|
||||||
strcpy(this->id, name.c_str());
|
|
||||||
this->name = "";
|
|
||||||
this->fullpath = "";
|
|
||||||
this->keepRaw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
char id[4];
|
|
||||||
unsigned char* data;
|
|
||||||
unsigned int size;
|
|
||||||
Chunk* parent;
|
|
||||||
std::vector<Chunk*> subchunks;
|
|
||||||
std::string name;
|
|
||||||
std::string fullpath;
|
|
||||||
bool keepRaw;
|
|
||||||
|
|
||||||
Chunk(std::string name){
|
|
||||||
this->init(name);
|
|
||||||
|
|
||||||
this->parent = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Chunk(Chunk* parent, std::string name){
|
|
||||||
this->init(name);
|
|
||||||
|
|
||||||
this->parent = parent;
|
|
||||||
this->parent->subchunks.push_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~Chunk(){
|
|
||||||
if(this->data != nullptr) delete[] this->data;
|
|
||||||
|
|
||||||
for(int i = 0; i < this->subchunks.size(); i++){
|
|
||||||
delete this->subchunks[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int totalSize(){
|
|
||||||
unsigned int sz = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < this->subchunks.size(); i++){
|
|
||||||
sz = this->subchunks[i]->totalSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 4 + 4 + this->size + sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write(std::ofstream* ofs){
|
|
||||||
unsigned int sz = 0;
|
|
||||||
|
|
||||||
if(memcmp(this->id, "FILE", 4) == 0){
|
|
||||||
unsigned short* flag;
|
|
||||||
unsigned int* location;
|
|
||||||
unsigned int* size;
|
|
||||||
char* name;
|
|
||||||
std::ifstream ifs(this->fullpath, std::ios::binary);
|
|
||||||
|
|
||||||
unsigned int cbound;
|
|
||||||
unsigned char* fdata;
|
|
||||||
unsigned char* cdata;
|
|
||||||
unsigned int fsize;
|
|
||||||
unsigned int csize;
|
|
||||||
struct Data dc;
|
|
||||||
|
|
||||||
ifs.seekg(0, std::ios_base::end);
|
|
||||||
fsize = ifs.tellg();
|
|
||||||
ifs.seekg(0, std::ios_base::beg);
|
|
||||||
|
|
||||||
fdata = new unsigned char[fsize];
|
|
||||||
ifs.read((char*)fdata, fsize);
|
|
||||||
|
|
||||||
if(this->keepRaw){
|
|
||||||
cdata = fdata;
|
|
||||||
csize = fsize;
|
|
||||||
}else{
|
|
||||||
cbound = LZ4F_compressFrameBound(fsize, nullptr);
|
|
||||||
cdata = new unsigned char[cbound];
|
|
||||||
|
|
||||||
csize = LZ4F_compressFrame(cdata, cbound, fdata, fsize, nullptr);
|
|
||||||
|
|
||||||
delete[] fdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->size = 2 + 4 + 4 + PATH_PART_LEN;
|
|
||||||
this->data = new unsigned char[this->size];
|
|
||||||
|
|
||||||
flag = (unsigned short*)&this->data[0];
|
|
||||||
location = (unsigned int*)&this->data[2];
|
|
||||||
size = (unsigned int*)&this->data[2 + 4];
|
|
||||||
name = (char*)&this->data[2 + 4 + 4];
|
|
||||||
|
|
||||||
*flag = (this->keepRaw ? FILE_FLAG_RAW : 0);
|
|
||||||
*location = loc;
|
|
||||||
*size = csize;
|
|
||||||
|
|
||||||
memset(name, 0, PATH_PART_LEN);
|
|
||||||
memcpy(name, this->name.c_str(), this->name.size());
|
|
||||||
|
|
||||||
dc.data = cdata;
|
|
||||||
dc.size = csize;
|
|
||||||
datalist.push_back(dc);
|
|
||||||
|
|
||||||
loc += csize;
|
|
||||||
}else if(memcmp(this->id, "DIRE", 4) == 0){
|
|
||||||
char* name;
|
|
||||||
|
|
||||||
this->size = PATH_PART_LEN;
|
|
||||||
this->data = new unsigned char[this->size];
|
|
||||||
|
|
||||||
name = (char*)&this->data[0];
|
|
||||||
|
|
||||||
memset(name, 0, PATH_PART_LEN);
|
|
||||||
memcpy(name, this->name.c_str(), this->name.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
sz = this->totalSize() - 4 - 4;
|
|
||||||
|
|
||||||
ofs->write((char*)this->id, 4);
|
|
||||||
ofs->write((char*)&sz, 4);
|
|
||||||
if(this->size > 0) ofs->write((char*)this->data, this->size);
|
|
||||||
for(int i = 0; i < this->subchunks.size(); i++){
|
|
||||||
this->subchunks[i]->write(ofs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void readDir(Chunk* parent, std::string dirname){
|
|
||||||
DIR* dir = opendir(dirname.c_str());
|
|
||||||
struct dirent* d;
|
|
||||||
|
|
||||||
if(dir != nullptr){
|
|
||||||
while((d = readdir(dir)) != nullptr){
|
|
||||||
struct stat s;
|
|
||||||
std::string dn(d->d_name);
|
|
||||||
std::string p = dirname + "/" + dn;
|
|
||||||
Chunk* c;
|
|
||||||
|
|
||||||
if(dn == ".." || dn == ".") continue;
|
|
||||||
|
|
||||||
stat(p.c_str(), &s);
|
|
||||||
|
|
||||||
if(S_ISDIR(s.st_mode)){
|
|
||||||
c = new Chunk(parent, "DIRE");
|
|
||||||
c->name = dn;
|
|
||||||
|
|
||||||
readDir(c, p);
|
|
||||||
}else{
|
|
||||||
int pos = dn.find_last_of('.');
|
|
||||||
std::string ext = (pos == std::string::npos) ? "" : dn.substr(pos, dn.size() - pos);
|
|
||||||
|
|
||||||
c = new Chunk(parent, "FILE");
|
|
||||||
c->name = dn;
|
|
||||||
c->fullpath = p;
|
|
||||||
|
|
||||||
if(ext == ".png"){
|
|
||||||
c->keepRaw = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
|
||||||
Chunk* root;
|
|
||||||
Chunk* rootdir;
|
|
||||||
std::ofstream* ofs;
|
|
||||||
|
|
||||||
if(argc < 3){
|
|
||||||
std::cerr << "Usage: " << argv[0] << " [output] [input...]" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
root = new Chunk("FBPK");
|
|
||||||
|
|
||||||
rootdir = new Chunk(root, "DIRE");
|
|
||||||
rootdir->name = "";
|
|
||||||
|
|
||||||
for(int i = 2; i < argc; i++){
|
|
||||||
readDir(rootdir, argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs = new std::ofstream(argv[1], std::ios::binary);
|
|
||||||
root->write(ofs);
|
|
||||||
for(int i = 0; i < datalist.size(); i++){
|
|
||||||
ofs->write((char*)datalist[i].data, datalist[i].size);
|
|
||||||
}
|
|
||||||
ofs->close();
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue