├── .gitignore
├── .gitmodules
├── CMakeLists.txt
├── Doxyfile
├── ICE.sln
├── LICENSE.md
├── NOTES.md
├── README.md
├── logo
├── logo.png
└── logo_hq.png
├── projects
├── Engine
│ ├── Engine.vcxproj
│ ├── Engine.vcxproj.filters
│ ├── Engine.vcxproj.user
│ └── src
│ │ ├── Audio
│ │ ├── Audio.c
│ │ ├── Audio.h
│ │ ├── Music.c
│ │ ├── Music.h
│ │ ├── Sound.c
│ │ ├── Sound.h
│ │ └── TypesAudio.h
│ │ ├── Core
│ │ ├── Asset.c
│ │ ├── Asset.h
│ │ ├── Asset_private.c
│ │ ├── Asset_private.h
│ │ ├── Config.h
│ │ ├── Config_private.c
│ │ ├── Converter_private.h
│ │ ├── Core.c
│ │ ├── Core.h
│ │ ├── Core_private.c
│ │ ├── Core_private.h
│ │ ├── Data.c
│ │ ├── Data.h
│ │ ├── Debug.c
│ │ ├── Debug.h
│ │ ├── Entity.c
│ │ ├── Entity.h
│ │ ├── Game.c
│ │ ├── Game.h
│ │ ├── Game_private.c
│ │ ├── Game_private.h
│ │ ├── Input.c
│ │ ├── Input.h
│ │ ├── Input_private.c
│ │ ├── Input_private.h
│ │ ├── Label.c
│ │ ├── Label.h
│ │ ├── Label_private.c
│ │ ├── Label_private.h
│ │ ├── MacOS_.c
│ │ ├── MacOS_.h
│ │ ├── SDL2_Includer.h
│ │ ├── State.c
│ │ ├── State.h
│ │ ├── Time_.c
│ │ ├── Time_.h
│ │ ├── Time_private.c
│ │ ├── Time_private.h
│ │ ├── Timer.c
│ │ ├── Timer.h
│ │ ├── TypesCore.h
│ │ ├── Version.c
│ │ ├── Version.h
│ │ ├── Window.c
│ │ ├── Window.h
│ │ ├── Window_private.c
│ │ └── Window_private.h
│ │ ├── External
│ │ ├── SDL2_gfx
│ │ │ ├── SDL2_framerate.c
│ │ │ ├── SDL2_framerate.h
│ │ │ ├── SDL2_gfxPrimitives.c
│ │ │ ├── SDL2_gfxPrimitives.h
│ │ │ ├── SDL2_gfxPrimitives_font.h
│ │ │ ├── SDL2_imageFilter.c
│ │ │ ├── SDL2_imageFilter.h
│ │ │ ├── SDL2_rotozoom.c
│ │ │ └── SDL2_rotozoom.h
│ │ ├── cute
│ │ │ └── cute_files.h
│ │ ├── duktape
│ │ │ ├── duk_config.h
│ │ │ ├── duktape.c
│ │ │ └── duktape.h
│ │ ├── mattiasgustavsson
│ │ │ ├── hashtable.h
│ │ │ └── rnd.h
│ │ ├── physfs
│ │ │ ├── physfs.c
│ │ │ ├── physfs.h
│ │ │ ├── physfs_archiver_7z.c
│ │ │ ├── physfs_archiver_dir.c
│ │ │ ├── physfs_archiver_grp.c
│ │ │ ├── physfs_archiver_hog.c
│ │ │ ├── physfs_archiver_iso9660.c
│ │ │ ├── physfs_archiver_mvl.c
│ │ │ ├── physfs_archiver_qpak.c
│ │ │ ├── physfs_archiver_slb.c
│ │ │ ├── physfs_archiver_unpacked.c
│ │ │ ├── physfs_archiver_vdf.c
│ │ │ ├── physfs_archiver_wad.c
│ │ │ ├── physfs_archiver_zip.c
│ │ │ ├── physfs_byteorder.c
│ │ │ ├── physfs_casefolding.h
│ │ │ ├── physfs_internal.h
│ │ │ ├── physfs_lzmasdk.h
│ │ │ ├── physfs_miniz.h
│ │ │ ├── physfs_platform_apple.m
│ │ │ ├── physfs_platform_haiku.cpp
│ │ │ ├── physfs_platform_os2.c
│ │ │ ├── physfs_platform_posix.c
│ │ │ ├── physfs_platform_qnx.c
│ │ │ ├── physfs_platform_unix.c
│ │ │ ├── physfs_platform_windows.c
│ │ │ ├── physfs_platform_winrt.cpp
│ │ │ ├── physfs_platforms.h
│ │ │ ├── physfs_unicode.c
│ │ │ ├── physfsrwops.c
│ │ │ └── physfsrwops.h
│ │ ├── rlutil
│ │ │ ├── rlutil.c
│ │ │ └── rlutil.h
│ │ └── stb
│ │ │ ├── SDL_stbimage.h
│ │ │ ├── stb_image.h
│ │ │ └── stb_image_write.h
│ │ ├── Framework
│ │ ├── Assert_.c
│ │ ├── Assert_.h
│ │ ├── Crossplatform_.c
│ │ ├── Crossplatform_.h
│ │ ├── File_.c
│ │ ├── File_.h
│ │ ├── Inline.h
│ │ ├── Log.c
│ │ ├── Log.h
│ │ ├── Macrotools.h
│ │ ├── Memory_.c
│ │ ├── Memory_.h
│ │ ├── Random.c
│ │ ├── Random.h
│ │ ├── String_.c
│ │ ├── String_.h
│ │ ├── Terminal.c
│ │ ├── Terminal.h
│ │ ├── Terminal_private.c
│ │ ├── Terminal_private.h
│ │ ├── TypesFramework.h
│ │ ├── UnitTest.c
│ │ └── UnitTest.h
│ │ ├── Graphics
│ │ ├── Animation.c
│ │ ├── Animation.h
│ │ ├── Camera.c
│ │ ├── Camera.h
│ │ ├── Color.h
│ │ ├── Color_private.h
│ │ ├── Draw.c
│ │ ├── Draw.h
│ │ ├── Font.c
│ │ ├── Font.h
│ │ ├── Gui.c
│ │ ├── Gui.h
│ │ ├── Gui_private.c
│ │ ├── Gui_private.h
│ │ ├── Primitive.c
│ │ ├── Primitive.h
│ │ ├── Render.c
│ │ ├── Render.h
│ │ ├── Render_private.c
│ │ ├── Render_private.h
│ │ ├── Screenshot.c
│ │ ├── Screenshot.h
│ │ ├── Sprite.c
│ │ ├── Sprite.h
│ │ ├── Sprite_private.c
│ │ ├── Sprite_private.h
│ │ ├── Texture.c
│ │ ├── Texture.h
│ │ ├── Texture_private.c
│ │ ├── Texture_private.h
│ │ └── TypesGraphics.h
│ │ ├── ICE.h
│ │ ├── Maths
│ │ ├── Box.h
│ │ ├── Interpolate.c
│ │ ├── Interpolate.h
│ │ ├── Maths.h
│ │ ├── TypesMaths.h
│ │ └── Vector.h
│ │ ├── Physics
│ │ ├── Basic_Collision.c
│ │ ├── Basic_Collision.h
│ │ └── TypesPhysics.h
│ │ └── Ressources
│ │ ├── bin
│ │ ├── err1024_png.c
│ │ ├── err512_png.c
│ │ ├── gui27_png.c
│ │ └── logo_png.c
│ │ ├── raw
│ │ ├── Error.c
│ │ └── Icon.c
│ │ └── src
│ │ ├── err1024.png
│ │ ├── err512.png
│ │ ├── gui27.png
│ │ └── logo.png
├── Games
│ ├── 2DWatch
│ │ ├── 2DWatch.vcxproj
│ │ ├── 2DWatch.vcxproj.filters
│ │ ├── 2DWatch.vcxproj.user
│ │ ├── res
│ │ │ ├── img
│ │ │ │ ├── gui.png
│ │ │ │ ├── ice_logo.png
│ │ │ │ ├── pic.png
│ │ │ │ ├── sprite.png
│ │ │ │ └── widow.png
│ │ │ ├── snd
│ │ │ │ ├── explosion.wav
│ │ │ │ ├── hit.wav
│ │ │ │ ├── laser.wav
│ │ │ │ ├── music.ogg
│ │ │ │ └── power.wav
│ │ │ └── ttf
│ │ │ │ ├── FiraSans-Medium.ttf
│ │ │ │ └── LICENSE
│ │ └── src
│ │ │ ├── data.h
│ │ │ ├── inventory.c
│ │ │ ├── inventory.h
│ │ │ ├── main.c
│ │ │ ├── weapon.c
│ │ │ └── weapon.h
│ ├── HelloWorld
│ │ ├── HelloWorld.vcxproj
│ │ ├── HelloWorld.vcxproj.filters
│ │ ├── HelloWorld.vcxproj.user
│ │ ├── res
│ │ │ ├── img
│ │ │ │ ├── gui.png
│ │ │ │ ├── ice_logo.png
│ │ │ │ ├── pic.png
│ │ │ │ ├── sprite.png
│ │ │ │ └── widow.png
│ │ │ ├── snd
│ │ │ │ ├── explosion.wav
│ │ │ │ ├── hit.wav
│ │ │ │ ├── laser.wav
│ │ │ │ ├── music.ogg
│ │ │ │ └── power.wav
│ │ │ └── ttf
│ │ │ │ ├── FiraSans-Medium.ttf
│ │ │ │ ├── LICENSE
│ │ │ │ ├── SoukouMincho.ttf
│ │ │ │ └── code2000.ttf
│ │ └── src
│ │ │ └── main.c
│ ├── ICE_GameTemplate1
│ │ ├── ICE_GameTemplate1.vcxproj
│ │ ├── ICE_GameTemplate1.vcxproj.filters
│ │ ├── ICE_GameTemplate1.vcxproj.user
│ │ ├── res
│ │ │ ├── code2000.ttf
│ │ │ └── woodenui
│ │ │ │ ├── frame_c2_01.png
│ │ │ │ ├── plank_15.png
│ │ │ │ ├── plank_15_hover.png
│ │ │ │ ├── plank_15_hover_pressed.png
│ │ │ │ └── skull_01.png
│ │ └── src
│ │ │ ├── button.c
│ │ │ ├── button.h
│ │ │ ├── config.h
│ │ │ ├── main.c
│ │ │ ├── skull.c
│ │ │ └── skull.h
│ └── Test
│ │ ├── Test.vcxproj
│ │ ├── Test.vcxproj.filters
│ │ ├── Test.vcxproj.user
│ │ ├── res
│ │ ├── img
│ │ │ ├── 000-WINDOW_ICON
│ │ │ ├── 001-SPRITESHEET
│ │ │ ├── 002-ICONS
│ │ │ ├── 003-GUI
│ │ │ ├── 004-ITEMS
│ │ │ └── 005-BACKGROUND
│ │ ├── pak
│ │ │ └── pak1.zip
│ │ ├── snd
│ │ │ ├── 001-MUSIC
│ │ │ └── 001-SOUND
│ │ └── ttf
│ │ │ └── 001-FONT
│ │ └── src
│ │ ├── config.h
│ │ ├── control.c
│ │ ├── control.h
│ │ ├── debug.c
│ │ ├── debug.h
│ │ ├── game.h
│ │ ├── main.c
│ │ ├── player.c
│ │ ├── player.h
│ │ ├── projectile.c
│ │ └── projectile.h
├── Tools
│ └── bin2c
│ │ ├── bin2c.vcxproj
│ │ ├── bin2c.vcxproj.filters
│ │ ├── bin2c.vcxproj.user
│ │ └── src
│ │ └── bin2c.c
└── UT
│ └── String
│ ├── UT_String.vcxproj
│ ├── UT_String.vcxproj.filters
│ ├── UT_String.vcxproj.user
│ └── src
│ └── main.c
└── script
├── cmake
├── FindSDL2.cmake
├── FindSDL2_mixer.cmake
├── FindSDL2_ttf.cmake
└── readme.md
├── sdl2_downloader.ps1
└── sdl2_downloader_apt.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Debug/
3 | SDL2/
4 | ICEngine/CMakeFiles/
5 | \.vs/ICEngine/v15/
6 | \.vs/
7 | ICEngine/Makefile
8 | ICEngine/\.vscode/
9 | ICEngine/CMakeCache\.txt
10 | *.includecache
11 | *.make
12 | ICEngine/CMakeFiles/2inside\.dir/
13 | *.bin
14 | ICEngine/build/
15 | Release/
16 | *.TMP
17 | ICECore/\.vs/
18 | \.idea/
19 | cmake-build-debug/
20 | *.dll
21 | *.DotSettings.user
22 | *.DotSettings.user
23 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "projects\\Engine\\src\\External\\chipmunk"]
2 | path = projects/Engine/src/External/chipmunk
3 | url = https://github.com/slembcke/Chipmunk2D.git
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.9)
2 | project(ICEngine C)
3 | set(CMAKE_C_STANDARD 11)
4 |
5 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
6 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8 |
9 | #### SDL2 #### ########################################################################
10 | #################### ########################################################################
11 |
12 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/script/cmake/")
13 |
14 | IF (WIN32)
15 | add_definitions(-DICE_NO_VLD)
16 | add_definitions(-D_CRT_SECURE_NO_WARNINGS)
17 |
18 | include_directories(
19 | ${CMAKE_SOURCE_DIR}/external/SDL2/include/
20 | )
21 |
22 | ELSE()
23 | find_package(SDL2 REQUIRED)
24 | find_package(SDL2_mixer REQUIRED)
25 | find_package(SDL2_ttf REQUIRED)
26 | include_directories(
27 | ${SDL2_INCLUDE_DIR}
28 | ${SDL2_MIXER_INCLUDE_DIR}
29 | ${SDL2_TTF_INCLUDE_DIR}
30 | )
31 | ENDIF()
32 |
33 |
34 | #### ICE ENGINE #### ########################################################################
35 | #################### ########################################################################
36 |
37 | file(GLOB_RECURSE SOURCES
38 | projects/Engine/src/*.h
39 | projects/Engine/src/*.c
40 | )
41 | string(REGEX REPLACE "CMakeFiles/[^;]+;?" "" SOURCES "${SOURCES}")
42 | add_library(ICE STATIC ${SOURCES})
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 ***REMOVED***
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 | Every code included in "External" / "external" folder or with a special
24 | mention, is not attached to this licence but to it's own licence.
25 |
--------------------------------------------------------------------------------
/NOTES.md:
--------------------------------------------------------------------------------
1 | THAT'S FRENCH
2 |
3 | TODO FIRST :
4 |
5 | - PhysFS pour tous les objets.
6 | - Check error de load
7 | - Font par defaut engine
8 | - Array de font
9 | - Remove des Label et les implémenté sur les Entity et Gui
10 | - GUI REFONTE !
11 | - Anchor !
12 | - Splashscreen custom
13 | - Z order on entity and gui
14 | - Background
15 | Image :
16 | -Taille original centré
17 | -Zoomé mais qui entre dans tous l'écran (cropé)
18 | -Zoomé jusqu'a touché l'écran (non cropé)
19 | -Etiré
20 | -Repeat X, Y ou XY
21 | Couleur
22 | - Zoom ? é_é
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ICE : Indie "C" Engine
2 |
3 |
4 | _A simple Game Engine with basic Camera, Entity, Texture, Audio, Map ..._
5 |
6 | ## Feature :
7 |
8 | **Supported Format :**
9 |
10 | - Image : JPG, PNG, BMP ... ( And everything stb_image support )
11 | - Sound : OGG, WAV ... ( And everything SDL_mixer support )
12 | - Font : TTF ... ( And everything SDL_ttf support )
13 | - Archive : ZIP, 7Z ... ( And everything PhysFS support )
14 |
15 | **Tools** :
16 |
17 | - bin2c : Convert file to static array in C to load them from the binary
18 |
19 | ## Dependancy :
20 |
21 | - SDL2 ( Platform wrapper for Graphics, Window, Input ... )
22 | - SDL2_mixer ( Sound )
23 | - SDL2_ttf ( Text drawing )
24 |
25 | ## Included :
26 |
27 | - stb_image ( Image decode : https://github.com/nothings/stb )
28 | - stb_image_write ( Image save : https://github.com/nothings/stb )
29 | - SDL_stbimage ( stb_image SDL integration : https://github.com/DanielGibson/Snippets/)
30 | - SDL2_gfx ( AA primitives : https://sourceforge.net/projects/sdl2gfx/ )
31 | - PhysFS ( Abstract acces to archives : https://icculus.org/physfs/ )
32 | - cute_files ( Crossplatform folder access : https://github.com/RandyGaul/cute_headers/blob/master/cute_files.h )
33 | - rlutil.h ( Crossplatform terminal color : https://github.com/tapio/rlutil )
34 | - chipmunk2d ( Physics : https://github.com/slembcke/Chipmunk2D )
35 | - duktape ( Embeddable Javascript engine : https://duktape.org/ )
36 |
37 | ## TODO :
38 | See the [Trello](https://trello.com/b/HOWcrZRM/ice/)
39 |
40 | ## Hello World
41 |
42 | ```c
43 | #include
44 |
45 | #define ICE_CONFIG_TITLE "Hello World"
46 |
47 | ICE_Game_Create()
48 | {
49 | ICE_Font_Load("font.ttf");
50 | ICE_LabelID nbr = ICE_Label_Create(
51 | ICE_State_Current,
52 | "Hello World",
53 | ICE_Vect_Zero,
54 | 50,
55 | ICE_LABELTYPE_WORLD
56 | );
57 | }
58 |
59 | ICE_Game_Update()
60 | {
61 | if (ICE_Input_Pressed(ICE_KEY_ESCAPE))
62 | ICE_Input_Quit();
63 | }
64 |
65 | ICE_Game_Destroy() {}
66 | ```
67 |
--------------------------------------------------------------------------------
/logo/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/logo/logo.png
--------------------------------------------------------------------------------
/logo/logo_hq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/logo/logo_hq.png
--------------------------------------------------------------------------------
/projects/Engine/Engine.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Audio.c:
--------------------------------------------------------------------------------
1 | #include "Audio.h"
2 |
3 | #include "../Core/SDL2_Includer.h"
4 | #include "../Framework/Log.h"
5 | #include ICE_INCLUDE_SDL2_MIXER
6 |
7 | void ICE_Audio_Init()
8 | {
9 | int error = 1;
10 |
11 | if (!Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1)
12 | {
13 | ICE_Log(ICE_LOGTYPE_ERROR, "SDL_Mixer -> Mix_OpenAudio : %s", Mix_GetError());
14 | error--;
15 | }
16 |
17 | if (Mix_Init(MIX_INIT_OGG) == 0)
18 | {
19 | ICE_Log(ICE_LOGTYPE_ERROR, "SDL_Mixer -> Mix_Init : %s", Mix_GetError());
20 | error--;
21 | }
22 |
23 | if (error == 1)
24 | ICE_Log(ICE_LOGTYPE_SUCCES, "Init SDL_Mixer : %d audio channels allocated", Mix_AllocateChannels(20));
25 |
26 |
27 | Mix_VolumeMusic(5);
28 | }
29 |
30 | void ICE_Audio_Close()
31 | {
32 | Mix_CloseAudio();
33 | }
34 |
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Audio.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_AUDIO
2 | #define DEF_ICE_AUDIO
3 |
4 | void ICE_Audio_Init();
5 | void ICE_Audio_Close();
6 |
7 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Music.c:
--------------------------------------------------------------------------------
1 | #include "Music.h"
2 |
3 | #include "../Core/TypesCore.h"
4 | #include "../Framework/Memory_.h"
5 | #include "../Framework/Log.h"
6 | #include "../External/physfs/physfs.h"
7 | #include "../External/physfs/physfsrwops.h"
8 | #include "../Core/Asset.h"
9 |
10 | extern ICE_Asset ASSET;
11 |
12 | ICE_ID last_loaded_music = (ICE_ID)-1;
13 |
14 | /* MANAGER */
15 |
16 | void ICE_MusicManager_Init()
17 | {
18 | ICE_MusicManager musicmanager = { 0 };
19 | musicmanager.music_size = ICE_DEFAULT_MUSIC_SIZE;
20 | musicmanager.music = ICE_Calloc(musicmanager.music_size, sizeof(ICE_Music));
21 | ASSET.music_mngr = musicmanager;
22 | ICE_Log(ICE_LOGTYPE_SUCCES, "Init MusicManager");
23 | }
24 |
25 | void ICE_MusicManager_Destroy()
26 | {
27 | for (ICE_ID i = 0; i < ASSET.music_mngr.music_contain; i++)
28 | ICE_Music_Destroy(i);
29 |
30 | ICE_Free(ASSET.music_mngr.music);
31 | ASSET.music_mngr.music = NULL;
32 | ICE_Log(ICE_LOGTYPE_SUCCES, "Free MusicManager");
33 | }
34 |
35 | /* MUSIC */
36 |
37 | ICE_TextureID ICE_Music_GetLastLoaded()
38 | {
39 | return last_loaded_music;
40 | }
41 |
42 | ICE_MusicID ICE_Music_Load(char* path_)
43 | {
44 | SDL_RWops * ops = NULL;
45 |
46 | if(ICE_AssetPak_isPathFromPak(path_))
47 | {
48 | PHYSFS_File * ph_file = PHYSFS_openRead(path_ + 6);
49 | ops = PHYSFSRWOPS_makeRWops(ph_file);
50 | }
51 | else
52 | {
53 | ops = SDL_RWFromFile(path_, "rb");
54 | }
55 |
56 | ICE_ID temp_id = ICE_Music_Load_RW(ops);
57 |
58 | if(temp_id != (ICE_ID)-1)
59 | ICE_Log_Succes("Music loaded from path : ID(%ld), Path(\"%s\")",temp_id, path_);
60 | else
61 | ICE_Log_Error("Music didn't loaded from file : %s", path_);
62 |
63 | return temp_id;
64 | }
65 |
66 |
67 | ICE_Music ICE_Music_Build_RW(SDL_RWops * ops)
68 | {
69 | ICE_Music music = {0};
70 | // Assigne
71 | music.sdl_handle = Mix_LoadMUS_RW(ops, 1);
72 | if(music.sdl_handle == NULL)
73 | ICE_Log(ICE_LOGTYPE_ERROR, "Load Music : %s", Mix_GetError());
74 | return music;
75 | }
76 |
77 | ICE_MusicID ICE_Music_Load_RW(SDL_RWops * ops)
78 | {
79 | ASSET.music_mngr.music[ASSET.music_mngr.music_contain] = ICE_Music_Build_RW(ops);
80 | ASSET.music_mngr.music_contain++;
81 |
82 | if (ASSET.music_mngr.music_size <= ASSET.music_mngr.music_contain) {
83 | ICE_Music* tmp = ICE_Realloc(ASSET.music_mngr.music, sizeof(ICE_Music)*(ASSET.music_mngr.music_size * 2));
84 | ASSET.music_mngr.music = tmp;
85 | ASSET.music_mngr.music_size *= 2;
86 | }
87 | return ASSET.music_mngr.music_contain - 1;
88 | }
89 |
90 |
91 | void ICE_Music_Clear(ICE_ID music_)
92 | {
93 | memset(ASSET.music_mngr.music, 0, sizeof(ICE_Music));
94 | }
95 |
96 | void ICE_Music_Destroy(ICE_ID music_)
97 | {
98 | ICE_String_Free(ASSET.music_mngr.music[music_].filename);
99 | Mix_FreeMusic(ASSET.music_mngr.music[music_].sdl_handle);
100 | }
101 |
102 | // PLAY
103 |
104 | int ICE_Music_Play(ICE_ID music_, ICE_Float volume_)
105 | {
106 | if (ASSET.music_mngr.music[music_].sdl_handle != NULL)
107 | {
108 | Mix_PlayMusic(ASSET.music_mngr.music[music_].sdl_handle, -1);
109 | Mix_VolumeMusic(volume_*128);
110 | return 1;
111 | }
112 | return -1;
113 | }
114 |
115 | void ICE_Music_Pause()
116 | {
117 | Mix_PauseMusic();
118 | }
119 |
120 | void ICE_Music_Resume()
121 | {
122 | Mix_ResumeMusic();
123 | }
124 |
125 | ICE_Music* ICE_Music_Get(ICE_ID music_)
126 | {
127 | return &ASSET.music_mngr.music[music_];
128 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Music.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_MUSIC
2 | #define DEF_ICE_MUSIC
3 |
4 | #define ICE_DEFAULT_MUSIC_SIZE 4
5 |
6 | #include "TypesAudio.h"
7 | #include "../Framework/TypesFramework.h"
8 | #include "../Graphics/Camera.h"
9 | #include "../Framework/Macrotools.h"
10 |
11 | void ICE_MusicManager_Init();
12 | void ICE_MusicManager_Destroy();
13 |
14 | #define ICE_Music_Load_MEM(S) ICE_Music_Load_RW(SDL_RWFromConstMem(S, S##_length));\
15 | if(ICE_Music_GetLastLoaded() != (ICE_ID)-1)\
16 | ICE_Log_Succes(ICE_MACROTOOLS_STRINGIZE(Music loaded from memory ID(%ld)\n Token(##S##)), ICE_Music_GetLastLoaded());\
17 | else\
18 | ICE_Log_printf(ICE_MACROTOOLS_STRINGIZE(Music didn t loaded from token : ##S));\
19 |
20 | // MUSIC
21 | ICE_TextureID ICE_Music_GetLastLoaded();
22 | ICE_MusicID ICE_Music_Load(char* path);
23 | ICE_Music ICE_Music_Build_RW(SDL_RWops * ops);
24 | ICE_MusicID ICE_Music_Load_RW(SDL_RWops * ops);
25 |
26 | void ICE_Music_Clear(ICE_ID music_);
27 | void ICE_Music_Destroy(ICE_ID music_);
28 | ICE_Music* ICE_Music_Get(ICE_ID music_);
29 |
30 | // PLAY
31 |
32 | int ICE_Music_Play(ICE_ID music_, ICE_Float volume_);
33 | void ICE_Music_Pause();
34 | void ICE_Music_Resume();
35 |
36 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Sound.c:
--------------------------------------------------------------------------------
1 | #include "Sound.h"
2 |
3 | #include "../Core/State.h"
4 | #include "../Framework/Memory_.h"
5 | #include "../Framework/Log.h"
6 |
7 | extern ICE_Asset ASSET;
8 |
9 | /* SOUNDMANAGER */
10 |
11 | void ICE_SoundManager_Init()
12 | {
13 | ICE_SoundManager soundmanager = { 0 };
14 | soundmanager.sound_size = ICE_DEFAULT_SOUND_SIZE;
15 | soundmanager.sound = ICE_Calloc(soundmanager.sound_size, sizeof(ICE_Sound));
16 | ASSET.sound_mngr = soundmanager;
17 | ICE_Log(ICE_LOGTYPE_SUCCES, "Init SoundManager");
18 | }
19 |
20 | void ICE_SoundManager_Destroy()
21 | {
22 | for (ICE_ID i = 0; i < ASSET.sound_mngr.sound_contain; i++)
23 | ICE_Sound_Destroy(i);
24 |
25 | ICE_Free(ASSET.sound_mngr.sound);
26 | ASSET.sound_mngr.sound = NULL;
27 | ICE_Log(ICE_LOGTYPE_SUCCES, "Free SoundManager");
28 | }
29 |
30 | /* SOUND */
31 |
32 | ICE_Sound ICE_Sound_Create(char *path)
33 | {
34 | ICE_Sound sound = { 0 };
35 |
36 | sound.filename = ICE_String_Init(path);
37 | sound.sdl_handle = Mix_LoadWAV(path);
38 |
39 | return sound;
40 | }
41 |
42 | ICE_ID ICE_Sound_Load(char *path_)
43 | {
44 | ASSET.sound_mngr.sound[ASSET.sound_mngr.sound_contain] = ICE_Sound_Create(path_);
45 | ASSET.sound_mngr.sound_contain++;
46 | ICE_Log(ICE_LOGTYPE_SUCCES, "Load Sound %d from \"%s\"", ASSET.sound_mngr.sound_contain - 1, path_);
47 |
48 | if (ASSET.sound_mngr.sound_size <= ASSET.sound_mngr.sound_contain) {
49 | ICE_Sound* tmp = ICE_Realloc(ASSET.sound_mngr.sound, sizeof(ICE_Sound)*(ASSET.sound_mngr.sound_size * 2));
50 | ASSET.sound_mngr.sound = tmp;
51 | ASSET.sound_mngr.sound_size *= 2;
52 | }
53 | return ASSET.sound_mngr.sound_contain - 1;
54 | }
55 |
56 | void ICE_Sound_Clear(ICE_ID sound_)
57 | {
58 | memset(ASSET.sound_mngr.sound[sound_].sdl_handle, 0, sizeof(ICE_Sound));
59 | }
60 |
61 | void ICE_Sound_Destroy(ICE_ID sound_)
62 | {
63 | ICE_String_Free(ASSET.sound_mngr.sound[sound_].filename);
64 | Mix_FreeChunk(ASSET.sound_mngr.sound[sound_].sdl_handle);
65 | }
66 |
67 | // PLAY
68 |
69 | int ICE_Sound_Play(ICE_ID sound_, ICE_Float volume_)
70 | {
71 | if (ASSET.sound_mngr.sound[sound_].sdl_handle != NULL)
72 | {
73 | Mix_Volume(Mix_PlayChannel(-1, ASSET.sound_mngr.sound[sound_].sdl_handle, 0), volume_*128);
74 | return 1;
75 | }
76 | return -1;
77 | }
78 |
79 | ICE_Sound* ICE_Sound_Get(ICE_ID sound_)
80 | {
81 | return &ASSET.sound_mngr.sound[sound_];
82 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/Sound.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_SOUND
2 | #define DEF_ICE_SOUND
3 |
4 | #define ICE_DEFAULT_SOUND_SIZE 4
5 | #include "TypesAudio.h"
6 | #include "../Framework/TypesFramework.h"
7 |
8 | // MANAGER
9 |
10 | void ICE_SoundManager_Init();
11 | void ICE_SoundManager_Destroy();
12 |
13 | // SOUND
14 |
15 | ICE_Sound ICE_Sound_Create(char *path);
16 | ICE_ID ICE_Sound_Load(char *path);
17 | void ICE_Sound_Clear(ICE_ID sound_);
18 | void ICE_Sound_Destroy(ICE_ID sound_);
19 | ICE_Sound* ICE_Sound_Get(ICE_ID sound_);
20 |
21 | // PLAY
22 |
23 | int ICE_Sound_Play(ICE_ID sound_, ICE_Float volume_);
24 |
25 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Audio/TypesAudio.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TYPESAUDIO
2 | #define DEF_ICE_TYPESAUDIO
3 |
4 | #include "../Core/SDL2_Includer.h"
5 | #include ICE_INCLUDE_SDL2_MIXER
6 |
7 | #include "../Framework/String_.h"
8 |
9 | #ifndef ICE_BOOL_DEFINED
10 | #define ICE_BOOL_DEFINED
11 | typedef _Bool ICE_Bool;
12 | #define ICE_True 1
13 | #define ICE_TRUE 1
14 | #define ICE_true 1
15 | #define ICE_False 0
16 | #define ICE_FALSE 0
17 | #define ICE_false 0
18 | #define ICE_BOOL_BITFIELD(S) ICE_Bool S : 1
19 | #endif
20 |
21 | #ifndef ICE_FLOAT_DEFINED
22 | #define ICE_FLOAT_DEFINED
23 | typedef double ICE_Float;
24 | #endif
25 |
26 | typedef struct {
27 |
28 | Mix_Music* sdl_handle;
29 | ICE_String filename;
30 |
31 | } ICE_Music;
32 |
33 | typedef struct
34 | {
35 | ICE_Bool isFree;
36 | unsigned short music_size;
37 | unsigned short music_contain;
38 | ICE_Music* music;
39 |
40 | } ICE_MusicManager;
41 |
42 | typedef struct {
43 |
44 | Mix_Chunk* sdl_handle;
45 | ICE_String filename;
46 |
47 | } ICE_Sound;
48 |
49 | typedef struct {
50 |
51 | ICE_Bool isFree;
52 | unsigned short sound_size;
53 | unsigned short sound_contain;
54 | ICE_Sound *sound;
55 |
56 | } ICE_SoundManager;
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Asset.c:
--------------------------------------------------------------------------------
1 | #include "Asset.h"
2 | #include "../Framework/String_.h"
3 | #include "../External/physfs/physfs.h"
4 |
5 |
6 | void ICE_AssetPak_Load(ICE_StringStd path_)
7 | {
8 | PHYSFS_mount(path_, NULL, 1);
9 | }
10 |
11 | void ICE_AssetPak_Load_MEM__(const void * buffer, ICE_Uint64 lenght, ICE_StringStd dir_name)
12 | {
13 | PHYSFS_mountMemory(buffer, lenght, NULL, dir_name, NULL, 1);
14 | }
15 |
16 | void ICE_AssetPak_Unload(ICE_StringStd path_)
17 | {
18 | PHYSFS_unmount(path_);
19 | }
20 |
21 | ICE_Bool ICE_AssetPak_FileExist(ICE_StringStd path_)
22 | {
23 | return PHYSFS_exists(path_);
24 | }
25 |
26 | ICE_Bool ICE_AssetPak_isPathFromPak(ICE_StringStd path_)
27 | {
28 | if(ICE_String_STDSize(path_) > 7)
29 | {
30 | if(path_[0] == 'r')
31 | if(path_[1] == 'e')
32 | if(path_[2] == 's')
33 | if(path_[3] == ':')
34 | if(path_[4] == '/')
35 | if(path_[5] == '/')
36 | return ICE_True;
37 | }
38 | return ICE_False;
39 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Asset.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_ASSET
2 | #define DEF_ICE_ASSET
3 | #include "../Framework/String_.h"
4 | #include "../Framework/TypesFramework.h"
5 | #include "../Framework/Macrotools.h"
6 |
7 | // AssetPak Loader/Unloader
8 | #define ICE_AssetPak_Load_MEM(S) ICE_AssetPak_Load_MEM__(S, S##_length, ICE_MACROTOOLS_STRINGIZE(FROMMEMORY_##S));
9 | #define ICE_AssetPak_Unload_MEM(S) ICE_AssetPak_Load_MEM__(S, S##_length, ICE_MACROTOOLS_STRINGIZE(FROMMEMORY_##S));
10 | void ICE_AssetPak_Load(ICE_StringStd path_);
11 | void ICE_AssetPak_Load_MEM__(const void * buffer, ICE_Uint64 lenght, ICE_StringStd dir_name);
12 | void ICE_AssetPak_Unload(ICE_StringStd path_);
13 |
14 | // AssetPak Tools
15 |
16 | /**
17 | * \brief Return ICE_True if the file exist in loaded pak. ICE_False if not.
18 | * \param path_ path and filename to the file.
19 | * \return
20 | */
21 | ICE_Bool ICE_AssetPak_FileExist(ICE_StringStd path_);
22 |
23 | /**
24 | * \brief Return ICE_True if the path contain res:// and point something in pak. ICE_False if not
25 | * \param path_ string to check
26 | * \return
27 | */
28 | ICE_Bool ICE_AssetPak_isPathFromPak(ICE_StringStd path_);
29 |
30 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Asset_private.c:
--------------------------------------------------------------------------------
1 | #include "Asset_private.h"
2 |
3 | #include "TypesCore.h"
4 |
5 | ICE_Asset ASSET = { 0 };
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Asset_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_ASSET_PRIVATE
2 | #define DEF_ICE_ASSET_PRIVATE
3 |
4 |
5 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Config.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CONFIG
2 | #define DEF_ICE_CONFIG
3 |
4 | #define ICE_CONFIG_WINDOW_W 640
5 | #define ICE_CONFIG_WINDOW_H 480
6 | #define ICE_CONFIG_TITLE "ICE"
7 | // 0 = nope, 1 = fullscreen, 2 = windowed fullscreen
8 | #define ICE_CONFIG_FULLSCREEN 0
9 | #define ICE_CONFIG_RESIZABLE 0
10 | #define ICE_CONFIG_EDITORNAME "ice"
11 | #define ICE_CONFIG_PRODUCTNAME "engine"
12 | #define ICE_CONFIG_VSYNC 1
13 | #define ICE_CONFIG_REFRESHRATE 144
14 | #define ICE_CONFIG_WINDOW_ICON 0
15 | #define ICE_CONFIG_GAME_VERSION "Prototype"
16 |
17 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Config_private.c:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CONFIG
2 | #define DEF_ICE_CONFIG
3 |
4 | #include "TypesCore.h"
5 |
6 | ICE_Config CONFIG = { 0 };
7 |
8 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Converter_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CONVERTER_PRIVATE
2 | #define DEF_ICE_CONVERTER_PRIVATE
3 | #include "SDL2_Includer.h"
4 |
5 | ////////////////////////////////////
6 | // Converter ice<->sdl //
7 | ////////////////////////////////////
8 |
9 | #include ICE_INCLUDE_SDL2
10 |
11 | #include "../Maths/TypesMaths.h"
12 | #include "../Framework/Inline.h"
13 |
14 | /**
15 | * \brief Convert a SDL_Rect to a ICE_Box
16 | * \param rect The SDL_Rect to convert
17 | * \return The converted ICE_Box
18 | */
19 | ICE_INLINE ICE_Box ICE_Convert_SDLtoBox(SDL_Rect *rect)
20 | {
21 | ICE_Box ice = { 0 };
22 | if (rect)
23 | {
24 | ice.x = rect->x;
25 | ice.y = rect->y;
26 | ice.w = rect->w;
27 | ice.h = rect->h;
28 | }
29 | return ice;
30 | }
31 |
32 | /**
33 | * \brief Convert a ICE_Box to a SDL_Rect
34 | * \param box The ICE_Box to convert
35 | * \return The converted SDL_Rect
36 | */
37 | ICE_INLINE SDL_Rect ICE_Convert_BoxToSDL(ICE_Box *box)
38 | {
39 | SDL_Rect sdl = { 0 };
40 | if (box)
41 | {
42 | sdl.x = (int)box->x;
43 | sdl.y = (int)box->y;
44 | sdl.w = (int)box->w;
45 | sdl.h = (int)box->h;
46 | }
47 |
48 | return sdl;
49 | }
50 | ////////////////////////////////////
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Core.c:
--------------------------------------------------------------------------------
1 | #include "Core.h"
2 | #include "TypesCore.h"
3 | #include "Core_private.h"
4 | #include "Game_private.h"
5 | #include "../Graphics/Draw.h"
6 | #include "../Graphics/Render_private.h"
7 | #include "Time_private.h"
8 | #include "Input_private.h"
9 | #include "../Framework/Log.h"
10 | #include "Entity.h"
11 |
12 | extern ICE_Game GAME;
13 | extern ICE_Core CORE;
14 |
15 | void ICE_Core_Main(void(*call_create)(void), void(*call_update)(void), void(*call_destroy)(void))
16 | {
17 | ICE_Core_Init();
18 | ICE_Render_Init();
19 | ICE_Game_Init();
20 |
21 | ICE_Log_Line();
22 | ICE_Log(ICE_LOGTYPE_RUNNING, "Main Create ...");
23 | call_create();
24 | ICE_Log(ICE_LOGTYPE_FINISH, "Main Create");
25 | ICE_Log_Line();
26 |
27 | ICE_Log_Line();
28 | ICE_Log(ICE_LOGTYPE_RUNNING, "Main Update ...");
29 | while (!CORE.window.input.quit)
30 | {
31 | // LOGIC HERE
32 | ICE_Time_Start();
33 | ICE_Input_Return();
34 |
35 | ICE_Entity_FunctionUpdate(NULL);
36 | call_update();
37 |
38 | // RENDER HERE
39 | ICE_Render_SetColor(GAME.current->background);
40 | ICE_Render_Clear();
41 |
42 | ICE_Draw_AllEntity();
43 | ICE_Draw_LabelWorld();
44 | ICE_Draw_AllGui();
45 | ICE_Draw_LabelScreen();
46 |
47 | #if defined(_DEBUG)
48 | if (CORE.lateDrawDebug)
49 | CORE.lateDrawDebug();
50 | #endif
51 |
52 | ICE_Render_Now();
53 | ICE_Time_End();
54 | }
55 | ICE_Log(ICE_LOGTYPE_FINISH, "Main Update");
56 | ICE_Log_Line();
57 |
58 | ICE_Log_Line();
59 | ICE_Log(ICE_LOGTYPE_RUNNING, "Main Destroy ...");
60 | call_destroy();
61 | ICE_Log(ICE_LOGTYPE_FINISH, "Main Destroy");
62 | ICE_Log_Line();
63 |
64 | ICE_Game_Quit();
65 | ICE_Render_Quit();
66 | ICE_Core_Quit();
67 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Core.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CORE
2 | #define DEF_ICE_CORE
3 |
4 | #define ICE_Game_Update() ICE_User_Update(void)
5 | #define ICE_Game_Destroy() ICE_User_Destroy(void)
6 | #define ICE_Game_Create() ICE_User_Create(void);\
7 | void ICE_Game_Update();\
8 | void ICE_Game_Destroy();\
9 | extern ICE_Config CONFIG;\
10 | int main(int argc, char ** argv)\
11 | {\
12 | CONFIG.argc = argc;\
13 | CONFIG.argv = argv;\
14 | CONFIG.title = ICE_CONFIG_TITLE;\
15 | CONFIG.editor_name = ICE_CONFIG_EDITORNAME;\
16 | CONFIG.product_name = ICE_CONFIG_PRODUCTNAME;\
17 | CONFIG.window_w = ICE_CONFIG_WINDOW_W;\
18 | CONFIG.window_h = ICE_CONFIG_WINDOW_H;\
19 | CONFIG.window_icon = ICE_CONFIG_WINDOW_ICON;\
20 | CONFIG.refresh_rate = ICE_CONFIG_REFRESHRATE;\
21 | CONFIG.fullscreen = ICE_CONFIG_FULLSCREEN;\
22 | CONFIG.resizable = ICE_CONFIG_RESIZABLE;\
23 | CONFIG.vsync = ICE_CONFIG_VSYNC;\
24 | CONFIG.game_version = ICE_CONFIG_GAME_VERSION;\
25 | ICE_Core_Main(ICE_User_Create, ICE_User_Update, ICE_User_Destroy);\
26 | return 0;\
27 | }\
28 | void ICE_User_Create(void)
29 |
30 | void ICE_Core_Main(void(*call_create)(void), void(*call_update)(void), void(*call_destroy)(void));
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Core_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CORE_PRIVATE
2 | #define DEF_ICE_CORE_PRIVATE
3 |
4 | /**
5 | * \brief Init everything for the engine
6 | * \return 0
7 | */
8 | int ICE_Core_Init();
9 |
10 | /**
11 | * \brief Close everything for the engine
12 | * \return 0
13 | */
14 | int ICE_Core_Quit();
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Data.c:
--------------------------------------------------------------------------------
1 | #include "Data.h"
2 | #include
3 | #include "Game.h"
4 | #include "../Framework/Assert_.h"
5 | #include "../Framework/Memory_.h"
6 |
7 | extern ICE_Game GAME;
8 |
9 | // Make a Data and create a pointer in the GAME->data array (return the pointer created)
10 | void* ICE_Data_Insert_(ICE_State * state, ICE_ID _size)
11 | {
12 | if (!state)
13 | state = GAME.current;
14 |
15 | state->object.data_nb++;
16 | state->object.data = ICE_Realloc(state->object.data, sizeof(void*)*(state->object.data_nb));
17 | state->object.data[state->object.data_nb - 1] = ICE_Calloc(1, _size);
18 | void * _pointer = state->object.data[state->object.data_nb - 1];
19 | return _pointer;
20 | }
21 |
22 | /// Return pointer to a Data
23 | void* ICE_Data_Get(ICE_State * state, ICE_ID nb_data)
24 | {
25 | if (!state)
26 | state = GAME.current;
27 |
28 | void * _pointer;
29 |
30 | if (nb_data <= state->object.data_nb)
31 | _pointer = state->object.data[nb_data];
32 |
33 | ////////////////////////////////////////////
34 | // //
35 | // If you see this assert, you choosed //
36 | // a data that doesn't exist //
37 | // //
38 | ////////////////////////////////////////////
39 |
40 | else
41 | {
42 | _pointer = NULL;
43 | //assert(("Pointer is null so there is no data at this number", _pointer));
44 | ICE_Assert(_pointer != NULL, "Pointer is null so there is no data at this number");
45 | }
46 |
47 | return _pointer;
48 | }
49 |
50 | /// Destroy a Data
51 | void ICE_Data_Destroy(ICE_State * state, ICE_ID nb_data)
52 | {
53 | if (!state)
54 | state = GAME.current;
55 |
56 | void * _pointer;
57 |
58 | if (nb_data <= state->object.data_nb)
59 | _pointer = state->object.data[nb_data];
60 |
61 | ////////////////////////////////////////////
62 | // //
63 | // If you see this assert, you choosed //
64 | // a data that doesn't exist //
65 | // //
66 | ////////////////////////////////////////////
67 |
68 | else
69 | {
70 | _pointer = NULL;
71 | //assert("Pointer is null so there is no data at this number", _pointer);
72 | ICE_Assert(_pointer != NULL, "Pointer is null so there is no data at this number");
73 | }
74 |
75 | ICE_Free(_pointer);
76 | }
77 |
78 | void ICE_Data_DestroyAll(ICE_State * state)
79 | {
80 | if (!state)
81 | state = GAME.current;
82 |
83 | for(ICE_ID i = 0; i < state->object.data_nb; i++)
84 | {
85 | ICE_Free(state->object.data[i]);
86 | }
87 | ICE_Free(state->object.data);
88 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Data.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_DATA
2 | #define DEF_ICE_DATA
3 | #include "State.h"
4 |
5 | #define ICE_Data_Insert(STATE, DATATYPE) ICE_Data_Insert_(STATE, sizeof(DATATYPE))
6 |
7 | // Make a Data and create a pointer in the GAME->data array (return the pointer created)
8 | void* ICE_Data_Insert_(ICE_State * state, ICE_ID _size);
9 |
10 | /// Return pointer to a Data
11 | void* ICE_Data_Get(ICE_State * state, ICE_ID nb_data);
12 |
13 | /// Destroy a Data
14 | void ICE_Data_Destroy(ICE_State * state, ICE_ID nb_data);
15 |
16 | void ICE_Data_DestroyAll(ICE_State * state);
17 |
18 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Debug.c:
--------------------------------------------------------------------------------
1 | #include "Debug.h"
2 |
3 | ICE_Bool ICE_Debug_Get_Linked()
4 | {
5 | #if defined(_DEBUG)
6 | return ICE_True;
7 | #else
8 | return ICE_False;
9 | #endif
10 | }
11 |
12 | #if defined(_DEBUG)
13 |
14 | #include "TypesCore.h"
15 | #include "Window.h"
16 | #include "Input.h"
17 | #include "Game.h"
18 |
19 | #include "../Graphics/Font.h"
20 | #include "../Graphics/Camera.h"
21 | #include "../Graphics/Color.h"
22 | #include "../Graphics/Color_private.h"
23 | #include "../Maths/Vector.h"
24 |
25 | #include
26 |
27 | extern ICE_Core CORE;
28 | extern ICE_Game GAME;
29 | extern ICE_Asset ASSET;
30 |
31 | void ICE_Debug_DrawCoordinate()
32 | {
33 | if (SDL_GetMouseFocus())
34 | {
35 | char coo[20];
36 | ICE_Box coordinate = { CORE.window.input.mousex, CORE.window.input.mousey };
37 | if (CORE.window.input.leftclic_pressed)
38 | coordinate = ICE_Camera_ScreenWorld(coordinate);
39 | sprintf(coo, "%0.0f, %0.0f", coordinate.x, coordinate.y);
40 |
41 | const ICE_Vect vect = { CORE.window.input.mousex + 10, CORE.window.input.mousey + 10 };
42 | ICE_Font_Draw(coo, vect, ICE_Color_New(255,255,255), ICE_Color_New(0,0,0));
43 | }
44 | }
45 |
46 | void ICE_Debug_DrawFps(int y_pos)
47 | {
48 | char gh[20];
49 | sprintf(gh, " FPS : [%.0f] ", CORE.time.fps);
50 | ICE_Debug_FontDraw(y_pos, gh);
51 | }
52 |
53 | void ICE_Debug_TitleFps()
54 | {
55 | char buffer[20];
56 | sprintf(buffer, "FPS : [%.0f]", CORE.time.fps);
57 | ICE_Window_SetTitle(buffer);
58 | }
59 |
60 | ICE_Color font_color_background_set = 0xFF0000FF;
61 | ICE_Color font_color_foreground_set = 0xFFFFFFFF;
62 |
63 | void ICE_Debug_FontSetColorBg(int r, int g, int b)
64 | {
65 | font_color_background_set = ICE_Color_New(r,g,b);
66 | }
67 |
68 | void ICE_Debug_FontSetColorFg(int r, int g, int b)
69 | {
70 | font_color_foreground_set = ICE_Color_New(r, g, b);
71 | }
72 |
73 | void ICE_Debug_FontDraw(int y, const char* format, ...)
74 | {
75 | char buffer[512];
76 | va_list args;
77 | va_start(args, format);
78 | vsprintf(buffer, format, args);
79 | int size = (int)((ICE_Float)ICE_Window_GetH() / 50.0);
80 | if (size < 12)
81 | size = 12;
82 | SDL_Surface *surf = TTF_RenderText_Shaded(ASSET.font.size[size], buffer, ICE_Color_ToSdl(font_color_foreground_set), ICE_Color_ToSdl(font_color_background_set));
83 | SDL_Rect rect; rect.x = 0; rect.y = surf->h * y;
84 | rect.w = surf->w; rect.h = surf->h;
85 | SDL_Texture *texture = SDL_CreateTextureFromSurface(CORE.window.render, surf);
86 | SDL_RenderCopy(CORE.window.render, texture, NULL, &rect);
87 | SDL_FreeSurface(surf);
88 | SDL_DestroyTexture(texture);
89 | va_end(args);
90 | }
91 |
92 | void ICE_Debug_CameraControl()
93 | {
94 | if (ICE_Input_Pressed(ICE_KEY_W))
95 | ICE_Camera_ShiftPos(ICE_Vect_New(0, -1000 * ICE_Game_GetDelta()));
96 | if (ICE_Input_Pressed(ICE_KEY_S))
97 | ICE_Camera_ShiftPos(ICE_Vect_New(0, 1000 * ICE_Game_GetDelta()));
98 | if (ICE_Input_Pressed(ICE_KEY_A))
99 | ICE_Camera_ShiftPos(ICE_Vect_New(-1000 * ICE_Game_GetDelta(), 0));
100 | if (ICE_Input_Pressed(ICE_KEY_D))
101 | ICE_Camera_ShiftPos(ICE_Vect_New(1000 * ICE_Game_GetDelta(), 0));
102 | if (ICE_Input_Pressed(ICE_KEY_SPACE))
103 | ICE_Camera_MovePos(ICE_Vect_Zero, 1000 * ICE_Game_GetDelta());
104 | }
105 |
106 | void ICE_Debug_CallbackDraw(void(*callback)())
107 | {
108 | CORE.lateDrawDebug = callback;
109 | }
110 |
111 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Debug.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_DEBUG
2 | #define DEF_ICE_DEBUG
3 |
4 | #include "TypesCore.h"
5 | #include "../Framework/Inline.h"
6 |
7 |
8 | #define ICE_DEBUG_COMMENT ICE_DEBUG_SLASH(/)
9 | #define ICE_DEBUG_SLASH(s) /##s
10 | #if defined(_DEBUG)
11 | #define ICE_DEBUG_ONLY
12 | #define ICE_DEBUG_START
13 | #define ICE_DEBUG_END
14 | #else
15 | #define ICE_DEBUG_ONLY ICE_DEBUG_COMMENT
16 | #define ICE_DEBUG_START ICE_DEBUG_SLASH(*)
17 | #define ICE_DEBUG_END *ICE_DEBUG_SLASH()
18 | #endif
19 |
20 |
21 |
22 | // Get the Header and User debug mode
23 | ICE_INLINE ICE_Bool ICE_Debug_Get_Compiled()
24 | {
25 | #if defined(_DEBUG)
26 | return ICE_True;
27 | #else
28 | return ICE_False;
29 | #endif
30 | }
31 |
32 | // Get the Library Debug
33 | ICE_Bool ICE_Debug_Get_Linked();
34 |
35 | #if defined(_DEBUG)
36 |
37 | /**
38 | * \brief Draw the mouse coordinate
39 | */
40 | void ICE_Debug_DrawCoordinate();
41 |
42 | /**
43 | * \brief Draw the fps on screen using debug font
44 | * \param y_pos Position of the font on screen line
45 | */
46 | void ICE_Debug_DrawFps(int y_pos);
47 |
48 | /**
49 | * \brief Show FPS in the title
50 | */
51 | void ICE_Debug_TitleFps();
52 |
53 | /**
54 | * \brief The background color of the debug font
55 | * \param r Red value
56 | * \param g Green value
57 | * \param b Blue value
58 | */
59 | void ICE_Debug_FontSetColorBg(int r, int g, int b);
60 |
61 | /**
62 | * \brief The color of the debug font
63 | * \param r Red value
64 | * \param g Green value
65 | * \param b Blue value
66 | */
67 | void ICE_Debug_FontSetColorFg(int r, int g, int b);
68 |
69 | /**
70 | * \brief Draw text on screen
71 | * \param y The position in the Y axis, 0 = First line, 1 = Second line etc ...
72 | * \param format char array formated
73 | * \param ... value for formating
74 | */
75 | void ICE_Debug_FontDraw(int y, const char* format, ...);
76 |
77 | /**
78 | * \brief Basic control for camera (WQSD, ARROW)
79 | */
80 | void ICE_Debug_CameraControl();
81 |
82 |
83 | /**
84 | * \brief
85 | * \param callback Callback to the function to debug draw
86 | */
87 | void ICE_Debug_CallbackDraw(void(*callback)());
88 |
89 | #else
90 | #define ICE_Debug_DrawCoordinate();
91 | #define ICE_Debug_DrawFps(...);
92 | #define ICE_Debug_TitleFps();
93 | #define ICE_Debug_FontSetColorBg(...);
94 | #define ICE_Debug_FontSetColorFg(...);
95 | #define ICE_Debug_FontDraw(...);
96 | #define ICE_Debug_CameraControl();
97 | #define ICE_Debug_CallbackDraw(...);
98 | #endif
99 |
100 | #endif
101 |
102 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Entity.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_ENTITY
2 | #define DEF_ICE_ENTITY
3 |
4 | #define ICE_DEFAULT_ENTITY_MNGR_SIZE 4
5 |
6 | #include "TypesCore.h"
7 |
8 | /////////
9 |
10 | /* ENTITY MANAGER */
11 |
12 | void ICE_EntityManager_Init(ICE_State* state);
13 | void ICE_EntityManager_Destroy(ICE_State* state);
14 |
15 | /* ENTITY */
16 |
17 | ICE_Entity ICE_Entity_Build(ICE_Box pos);
18 | ICE_ID ICE_Entity_Create(ICE_State* state, ICE_Box pos);
19 | void ICE_Entity_Clear(ICE_Entity* entity);
20 | void ICE_Entity_Destroy(ICE_Entity* ptr);
21 |
22 | /////////
23 |
24 | /* ENTITY INFO */
25 |
26 | //Simple
27 | ICE_Entity* ICE_Entity_Get(ICE_State* state, ICE_EntityID entity_id);
28 | ICE_ID ICE_Entity_GetQuantity(ICE_State* state, ICE_ID manager);
29 | ICE_ID ICE_EntityManager_GetQuantity(ICE_State* state);
30 |
31 | ICE_Vect ICE_Entity_GetPosition(ICE_Entity* entity);
32 | ICE_Box ICE_Entity_GetBox(ICE_Entity* entity);
33 |
34 | /* ENTITY MODIFIER */
35 |
36 | //Texture
37 | void ICE_Entity_SetTexture(ICE_Entity* entity_ptr, ICE_TextureID texture_id);
38 | void ICE_Entity_RemoveTexture(ICE_Entity* entity);
39 |
40 | //Position
41 | void ICE_Entity_SetPos(ICE_Entity* entity, ICE_Float x, ICE_Float y);
42 | void ICE_Entity_ShiftPos(ICE_Entity* entity, ICE_Float x, ICE_Float y);
43 | void ICE_Entity_MovePos(ICE_Entity* entity, ICE_Vect pos, ICE_Float r);
44 |
45 | //Size
46 | void ICE_Entity_SetSize(ICE_Entity* entity, ICE_Vect size);
47 | void ICE_Entity_Scale(ICE_Entity* entity, ICE_Float scale);
48 |
49 | //Rotation
50 | void ICE_Entity_SetAngle(ICE_Entity* entity, ICE_Float angle);
51 | void ICE_Entity_AddAngle(ICE_Entity* entity, ICE_Float angle);
52 | void ICE_Entity_LookAt(ICE_Entity* entity, ICE_Vect pos);
53 |
54 | //Sprite
55 | void ICE_Entity_SetSprite(ICE_Entity* entity_, ICE_ID sprite_);
56 | void ICE_Entity_SetSpriteFrame(ICE_Entity* entity, ICE_ID frame);
57 |
58 | ICE_Sprite* ICE_Entity_GetSprite(ICE_Entity* _entity);
59 |
60 |
61 | void ICE_Entity_SetFunction(ICE_Entity* entity, void (*call_create)(ICE_Entity*), void (*call_update)(ICE_Entity*),
62 | void (*call_destroy)(ICE_Entity*));
63 | void ICE_Entity_FunctionUpdate(ICE_State* state);
64 | ICE_ID ICE_Entity_GetSpriteFrame(ICE_Entity * entity);
65 |
66 | /* ENTITY DATA */
67 |
68 | #define ICE_Entity_DataAdd(ENTITY, DATATYPE) ICE_Entity_DataAdd_(ENTITY, sizeof(DATATYPE))
69 | void * ICE_Entity_DataAdd_(ICE_Entity * entity_, ICE_ID size_);
70 | void * ICE_Entity_DataGet(ICE_Entity * entity_, ICE_DataID id_data_);
71 | void ICE_Entity_DataDestroy(ICE_Entity * entity_, ICE_DataID id_data_);
72 | void ICE_Entity_DataDestroyAll(ICE_Entity * entity_);
73 | ICE_EntityID ICE_Entity_GetID(ICE_Entity * entity_);
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Game.c:
--------------------------------------------------------------------------------
1 | #include "Game.h"
2 |
3 | #include "TypesCore.h"
4 |
5 | extern ICE_Core CORE;
6 | extern ICE_Config CONFIG;
7 |
8 | ICE_Float ICE_Game_GetDelta()
9 | {
10 | return CORE.time.delta;
11 | }
12 |
13 | ICE_Float ICE_Game_GetFps()
14 | {
15 | return CORE.time.fps;
16 | }
17 |
18 | ICE_StringStd ICE_Game_GetVersion()
19 | {
20 | return CONFIG.game_version;
21 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Game.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_GAME
2 | #define DEF_ICE_GAME
3 |
4 | #include "TypesCore.h"
5 |
6 | /**
7 | * \brief Get the value of time between last frame
8 | * \return The elapsed time between last frame
9 | */
10 | ICE_Float ICE_Game_GetDelta();
11 |
12 | /**
13 | * \brief Get the fps value
14 | * \return The fps value
15 | */
16 | ICE_Float ICE_Game_GetFps();
17 |
18 | ICE_StringStd ICE_Game_GetVersion();
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Game_private.c:
--------------------------------------------------------------------------------
1 | #include "Game_private.h"
2 |
3 | #include "TypesCore.h"
4 |
5 | #include "../Core/Label.h"
6 | #include "../Core/Entity.h"
7 | #include "../Core/Data.h"
8 |
9 | #include "../Graphics/Gui.h"
10 |
11 | #include "../Graphics/Texture.h"
12 | #include "../Graphics/Sprite.h"
13 |
14 | #include "../Audio/Music.h"
15 | #include "../Audio/Sound.h"
16 | #include "../Graphics/Gui_private.h"
17 | #include "../Graphics/Texture_private.h"
18 |
19 | ICE_Game GAME = { 0 };
20 | extern ICE_Core CORE;
21 | extern ICE_Asset ASSET;
22 |
23 | void ICE_Game_Init()
24 | {
25 | GAME.current = &GAME.state_main;
26 | GAME.state_main.name = ICE_String_Init("Main_State");
27 |
28 | // Asset
29 | ICE_TextureManager_Init();
30 | ICE_SpriteManager_Init();
31 | ICE_SoundManager_Init();
32 | ICE_MusicManager_Init();
33 |
34 | // Items
35 | ICE_EntityManager_Init(NULL);
36 | ICE_GuiManager_Init(NULL);
37 | ICE_LabelManager_Init(NULL);
38 |
39 | //Default Engine Ressource
40 | ICE_Texture_ErrorInit();
41 | ICE_Texture_DefaultGuiInit();
42 |
43 | }
44 |
45 | void ICE_Game_Quit()
46 | {
47 | ICE_String_Free(GAME.state_main.name);
48 |
49 | ICE_Texture_DefaultAllFree();
50 |
51 | ICE_TextureManager_Destroy();
52 | ICE_SpriteManager_Destroy();
53 | ICE_SoundManager_Destroy();
54 | ICE_MusicManager_Destroy();
55 |
56 | ICE_LabelManager_Destroy(NULL);
57 | ICE_GuiManager_Destroy(NULL);
58 | ICE_EntityManager_Destroy(NULL);
59 |
60 | ICE_Data_DestroyAll(NULL);
61 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Game_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_GAME_PRIVATE
2 | #define DEF_ICE_GAME_PRIVATE
3 |
4 | void ICE_Game_Init();
5 | void ICE_Game_Quit();
6 |
7 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Input.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "Input.h"
4 |
5 | #include "../Framework/Log.h"
6 | #include "../Graphics/Camera.h"
7 | #include "../Maths/Box.h"
8 | #include "../Maths/Vector.h"
9 |
10 | extern ICE_Game GAME;
11 | extern ICE_Core CORE;
12 |
13 | ICE_Bool ICE_Input_Pressed(enum ICE_Key button)
14 | {
15 | if (button < 512)
16 | {
17 | return CORE.window.input.Pressed[button];
18 | }
19 | if (button > 600 && button < ICE_KEY_MAX)
20 | {
21 | if (button == ICE_KEY_LEFTCLICK)
22 | {
23 | return CORE.window.input.leftclic_pressed;
24 | }
25 | if (button == ICE_KEY_RIGHTCLICK)
26 | {
27 | return CORE.window.input.rightclic_pressed;
28 | }
29 | if (button == ICE_KEY_WHEELUP)
30 | {
31 | return CORE.window.input.wheelup;
32 | }
33 | if (button == ICE_KEY_WHEELDOWN)
34 | {
35 | return CORE.window.input.wheeldown;
36 | }
37 | }
38 | else
39 | {
40 | ICE_Log(ICE_LOGTYPE_WARNING, "No key corresponding : %d", button);
41 | return ICE_False;
42 | }
43 |
44 | return ICE_False;
45 | }
46 |
47 | ICE_Bool ICE_Input_OnPress(enum ICE_Key button)
48 | {
49 | if (button < 512)
50 | {
51 | return CORE.window.input.OnPress[button];
52 | }
53 | if (button > 600 && button < ICE_KEY_MAX)
54 | {
55 | if (button == ICE_KEY_LEFTCLICK)
56 | {
57 | return CORE.window.input.leftclic_OnPress;
58 | }
59 | if (button == ICE_KEY_RIGHTCLICK)
60 | {
61 | return CORE.window.input.rightclic_OnPress;
62 | }
63 | }
64 | ICE_Log(ICE_LOGTYPE_WARNING, "No key corresponding : %d", button);
65 | return ICE_False;
66 | }
67 |
68 | ICE_Bool ICE_Input_OnRelease(enum ICE_Key button)
69 | {
70 | if (button < 512)
71 | {
72 | return CORE.window.input.OnRelease[button];
73 | }
74 | if (button > 600 && button < ICE_KEY_MAX)
75 | {
76 | if (button == ICE_KEY_LEFTCLICK)
77 | {
78 | return CORE.window.input.leftclic_OnRelease;
79 | }
80 | if (button == ICE_KEY_RIGHTCLICK)
81 | {
82 | return CORE.window.input.rightclic_OnRelease;
83 | }
84 | }
85 | ICE_Log(ICE_LOGTYPE_WARNING, "No key corresponding : %d", button);
86 | return ICE_False;
87 | }
88 |
89 | int ICE_Input_MouseX()
90 | {
91 | return CORE.window.input.mousex;
92 | }
93 |
94 | int ICE_Input_MouseY()
95 | {
96 | return CORE.window.input.mousey;
97 | }
98 |
99 | ICE_Vect ICE_Input_MouseVector()
100 | {
101 | return ICE_Vect_New(CORE.window.input.mousex, CORE.window.input.mousey);
102 | }
103 |
104 | int ICE_Input_MouseX_World()
105 | {
106 | ICE_Box translating = ICE_Camera_ScreenWorld(ICE_Box_New(CORE.window.input.mousex, CORE.window.input.mousey,1, 1));
107 | return (int)translating.x;
108 | }
109 |
110 | int ICE_Input_MouseY_World()
111 | {
112 | ICE_Box translating = ICE_Camera_ScreenWorld(ICE_Box_New(CORE.window.input.mousex, CORE.window.input.mousey, 1, 1));
113 | return (int)translating.y;
114 | }
115 |
116 | ICE_Vect ICE_Input_MouseVector_World()
117 | {
118 | ICE_Box translating = ICE_Camera_ScreenWorld(ICE_Box_New(CORE.window.input.mousex, CORE.window.input.mousey,1, 1));
119 | return ICE_Vect_New(translating.x, translating.y);
120 | }
121 |
122 | void ICE_Input_Quit()
123 | {
124 | SDL_HideWindow(CORE.window.handle);
125 | CORE.window.input.quit = ICE_True;
126 | }
127 |
128 | void ICE_Input_Reset()
129 | {
130 | int temp = CORE.window.input.focus;
131 | int temp2 = CORE.window.input.quit;
132 | int mousex = CORE.window.input.mousex;
133 | int mousey = CORE.window.input.mousey;
134 | memset(&CORE.window.input, 0, sizeof(ICE_Input));
135 | CORE.window.input.focus = temp;
136 | CORE.window.input.quit = temp2;
137 | CORE.window.input.mousex = mousex;
138 | CORE.window.input.mousey = mousey;
139 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Input_private.c:
--------------------------------------------------------------------------------
1 | #include "Input_private.h"
2 |
3 | #include "TypesCore.h"
4 |
5 | extern ICE_Game GAME;
6 | extern ICE_Core CORE;
7 |
8 | void ICE_Input_Return()
9 | {
10 | static SDL_Event event;
11 |
12 | // Reset one time event
13 | for(int i = 0; i < 512; i++)
14 | {
15 | CORE.window.input.OnPress[i] = 0;
16 | CORE.window.input.OnRelease[i] = 0;
17 | }
18 |
19 | CORE.window.input.leftclic_OnPress = 0;
20 | CORE.window.input.leftclic_OnRelease = 0;
21 | CORE.window.input.rightclic_OnPress = 0;
22 | CORE.window.input.rightclic_OnRelease = 0;
23 |
24 | while (SDL_PollEvent(&event))
25 | {
26 | switch (event.type)
27 | {
28 | case SDL_QUIT:
29 | CORE.window.input.quit = 1;
30 | break;
31 | case SDL_KEYDOWN:
32 |
33 | if (CORE.window.input.Pressed[event.key.keysym.scancode] == 0)
34 | {
35 | CORE.window.input.Pressed[event.key.keysym.scancode] = 1;
36 | CORE.window.input.OnPress[event.key.keysym.scancode] = 1;
37 | }
38 | break;
39 | case SDL_KEYUP:
40 | if (CORE.window.input.Pressed[event.key.keysym.scancode] == 1)
41 | {
42 | CORE.window.input.Pressed[event.key.keysym.scancode] = 0;
43 | CORE.window.input.OnRelease[event.key.keysym.scancode] = 1;
44 | }
45 | break;
46 | case SDL_MOUSEWHEEL:
47 | if (event.wheel.y > 0)
48 | CORE.window.input.wheelup = 1;
49 | if (event.wheel.y < 0)
50 | CORE.window.input.wheeldown = 1;
51 | break;
52 | case SDL_MOUSEBUTTONDOWN:
53 | if (event.button.button == SDL_BUTTON_LEFT)
54 | {
55 | if (CORE.window.input.leftclic_pressed == 0)
56 | {
57 | CORE.window.input.leftclic_pressed = 1;
58 | CORE.window.input.leftclic_OnPress = 1;
59 | }
60 | }
61 | if (event.button.button == SDL_BUTTON_RIGHT)
62 | {
63 | if (CORE.window.input.rightclic_pressed == 0)
64 | {
65 | CORE.window.input.rightclic_pressed = 1;
66 | CORE.window.input.rightclic_OnPress = 1;
67 | }
68 | }
69 | break;
70 | case SDL_MOUSEBUTTONUP:
71 | if (event.button.button == SDL_BUTTON_LEFT)
72 | {
73 | if (CORE.window.input.leftclic_pressed == 1)
74 | {
75 | CORE.window.input.leftclic_pressed = 0;
76 | CORE.window.input.leftclic_OnRelease = 1;
77 | }
78 | }
79 | if (event.button.button == SDL_BUTTON_RIGHT)
80 | {
81 | if (CORE.window.input.rightclic_pressed == 1)
82 | {
83 | CORE.window.input.rightclic_pressed = 0;
84 | CORE.window.input.rightclic_OnRelease = 1;
85 | }
86 | }
87 | break;
88 | case SDL_MOUSEMOTION:
89 | CORE.window.input.mousex = event.motion.x;
90 | CORE.window.input.mousey = event.motion.y;
91 | break;
92 | case SDL_DROPFILE:
93 | CORE.window.input.filedrop = event.drop.file;
94 | break;
95 | case SDL_WINDOWEVENT:
96 | switch (event.window.event)
97 | {
98 | case SDL_WINDOWEVENT_FOCUS_GAINED:
99 | CORE.window.input.focus = 1;
100 | break;
101 | case SDL_WINDOWEVENT_FOCUS_LOST:
102 | CORE.window.input.focus = 0;
103 | break;
104 | case SDL_WINDOWEVENT_RESIZED:
105 | CORE.window.w = event.window.data1;
106 | CORE.window.h = event.window.data2;
107 | break;
108 | default:
109 | break;
110 | }
111 | default:
112 | break;
113 | }
114 | if (event.wheel.y == 0)
115 | {
116 | CORE.window.input.wheelup = 0;
117 | CORE.window.input.wheeldown = 0;
118 | }
119 | }
120 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Input_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_INPUT_PRIVATE
2 | #define DEF_ICE_INPUT_PRIVATE
3 |
4 | /**
5 | * \brief Where SDL_Event are made and update the input structure of the engine
6 | */
7 | void ICE_Input_Return();
8 |
9 | #endif
10 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Label.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_LABEL
2 | #define DEF_ICE_LABEL
3 |
4 |
5 | #include "TypesCore.h"
6 | #include "../Framework/String_.h"
7 | #include "../Framework/TypesFramework.h"
8 | #include "../Maths/TypesMaths.h"
9 |
10 | #define ICE_DEFAULT_LABEL_MNGR_SIZE 4
11 |
12 | /////////////////////// * LABEL MANAGER * //////////////////////////
13 |
14 | /**
15 | * \brief Insert a new LabelManager in the Game
16 | */
17 | void ICE_LabelManager_Init(ICE_State* state);
18 |
19 | /**
20 | * \brief Destroy a manager
21 | * \param state The state to destroy manager
22 | */
23 | void ICE_LabelManager_Destroy(ICE_State * state);
24 |
25 | /////////////////////// * LABEL * //////////////////////////
26 |
27 | /**
28 | * \brief Create a New Label
29 | * \param text The text of the Label
30 | * \param pos The position of the Label
31 | * \return The new Label
32 | */
33 | ICE_Label ICE_Label_Build(ICE_StringStd text, ICE_Vect pos, int size, enum ICE_LabelType type);
34 |
35 | /**
36 | * \brief Insert a new Label in a manager
37 | * \param state The state where the manager is
38 | * \param text The text of the Label
39 | * \param pos The position of the Label
40 | */
41 | ICE_ID ICE_Label_Create(ICE_State * state, ICE_StringStd text, const ICE_Vect pos, int size, enum ICE_LabelType type);
42 |
43 | /**
44 | * \brief Clear a Label and put everything to 0
45 | * \param label ptr to clear
46 | */
47 | void ICE_Label_Clear(ICE_Label * label);
48 |
49 | /**
50 | * \brief Destroy a label with it's pointer
51 | * \param ptr The pointer of the Label
52 | */
53 | void ICE_Label_Destroy(ICE_Label * ptr);
54 |
55 | /////////////////////// * LABEL GET * //////////////////////////
56 |
57 | ICE_String ICE_Label_GetString(ICE_Label* ptr);
58 | ICE_Label * ICE_Label_Get(ICE_State * state, const ICE_ID nb);
59 | unsigned ICE_Label_GetWidth(ICE_Label* label);
60 | unsigned ICE_Label_GetHeight(ICE_Label* label);
61 | ICE_Float ICE_Label_GetX(ICE_Label * label);
62 | ICE_Float ICE_Label_GetY(ICE_Label * label);
63 |
64 | /////////////////////// * LABEL SET * //////////////////////////
65 |
66 | void ICE_Label_SetSize(ICE_Label *label, int size);
67 | void ICE_Label_SetString(ICE_Label * label, ICE_StringStd format, ...);
68 | void ICE_Label_SetPos(ICE_Label * label, ICE_Vect vect);
69 | void ICE_Label_SetColor(ICE_Label * label, ICE_Color color);
70 | void ICE_Label_SetWrapWidth(ICE_Label * label, int wrap_width);
71 | void ICE_Label_SetAngle(ICE_Label * label, ICE_Float angle);
72 | void ICE_Label_FixToWorld(ICE_Label * label, ICE_Bool yn);
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Label_private.c:
--------------------------------------------------------------------------------
1 | #include "SDL2_Includer.h"
2 |
3 | #include ICE_INCLUDE_SDL2
4 | #include ICE_INCLUDE_SDL2_TTF
5 |
6 | #include "TypesCore.h"
7 | #include "../Graphics/Color_private.h"
8 | #include "../Framework/Assert_.h"
9 |
10 | extern ICE_Asset ASSET;
11 | extern ICE_Core CORE;
12 |
13 | void ICE_Label_UpdateTexture(ICE_Label * label)
14 | {
15 | ICE_Assert(ASSET.font.size[100] != 0, "Font is probably not loaded or with an error");
16 | SDL_Surface *surf;
17 | if(label->wrap_width == 0)
18 | {
19 | surf = TTF_RenderText_Blended(
20 | ASSET.font.size[label->size],
21 | label->text,
22 | ICE_Color_ToSdl(label->color)
23 | );
24 | }
25 | else
26 | {
27 | surf = TTF_RenderText_Blended_Wrapped(
28 | ASSET.font.size[label->size],
29 | label->text,
30 | ICE_Color_ToSdl(label->color),
31 | label->wrap_width
32 | );
33 | }
34 |
35 | ICE_Texture texture = { 0 };
36 |
37 | texture.handle = SDL_CreateTextureFromSurface(CORE.window.render, surf);
38 | if (texture.handle)
39 | {
40 | texture.w = surf->w; texture.h = surf->h;
41 | if (label->texture.exist)
42 | {
43 | SDL_DestroyTexture(label->texture.handle);
44 | }
45 | label->texture = texture;
46 | label->texture.exist = ICE_True;
47 | SDL_FreeSurface(surf);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Label_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_LABEL_PRIVATE
2 | #define DEF_ICE_LABEL_PRIVATE
3 |
4 | #include "Label.h"
5 | void ICE_Label_UpdateTexture(ICE_Label * label);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/MacOS_.c:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ***REMOVED*** on 30/07/2018.
3 | //
4 |
5 | #include "MacOS_.h"
6 |
7 | #if defined(__APPLE__)
8 | #include
9 | #include
10 | ICE_StringStd ICE_MacOS_GetResourcesDirectory()
11 | {
12 | CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
13 | char * returner = (char*)malloc(sizeof(char)*PATH_MAX);
14 | CFURLGetFileSystemRepresentation(url, true, (UInt8*)returner, sizeof(sizeof(char)*PATH_MAX));
15 | //chdir(path) != 0)
16 | CFRelease(url);
17 | return returner;
18 | }
19 | ICE_Bool ICE_MacOS_SetWorkingDirectory(ICE_StringStd path)
20 | {
21 | return chdir(path);
22 | }
23 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/MacOS_.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ***REMOVED*** on 30/07/2018.
3 | //
4 |
5 | #ifndef ICE_MACOS_H
6 | #define ICE_MACOS_H
7 |
8 | #include "../Framework/TypesFramework.h"
9 | #include "../Framework/String_.h"
10 |
11 | #if defined(__APPLE__)
12 | #include
13 | #include //
14 | ICE_StringStd ICE_MacOS_GetResourcesDirectory();
15 | ICE_Bool ICE_MacOS_SetWorkingDirectory(ICE_StringStd path);
16 | #else
17 | #define ICE_MacOS_GetResourcesDirectory() (ICE_StringStd) "NOT MACOS"
18 | #define ICE_MacOS_SetWorkingDirectory(...) ICE_False
19 | #endif
20 |
21 | #endif //ICENGINE_MACOS_H
22 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/SDL2_Includer.h:
--------------------------------------------------------------------------------
1 | #ifndef ICE_SDL2_INCLUDER
2 | #define ICE_SDL2_INCLUDER
3 |
4 | // If I need to edit SDL path location easly with include
5 |
6 | #define ICE_INCLUDE_SDL2
7 | #define ICE_INCLUDE_SDL2_TTF
8 | #define ICE_INCLUDE_SDL2_MIXER
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/State.c:
--------------------------------------------------------------------------------
1 | #include "State.h"
2 |
3 | #include "TypesCore.h"
4 | #include "Time_private.h"
5 | #include "Input_private.h"
6 | #include "Input.h"
7 |
8 | #include "../Graphics/Render_private.h"
9 | #include "../Framework/Log.h"
10 | #include "../Core/Label.h"
11 | #include "../Graphics/Draw.h"
12 | #include "../Graphics/Gui.h"
13 |
14 | #include "Data.h"
15 | #include "../Graphics/Gui_private.h"
16 | #include "../ICE.h"
17 |
18 | extern ICE_Game GAME;
19 | extern ICE_Core CORE;
20 |
21 | ICE_State ICE_State_Create(void (*func_create)(void), void (* func_update)(void), void (* func_destroy)(void))
22 | {
23 | ICE_State state = {0};
24 |
25 | state.func_create = func_create;
26 | state.func_update = func_update;
27 | state.func_destroy = func_destroy;
28 |
29 | return state;
30 | }
31 |
32 | void ICE_State_Change(ICE_State * state)
33 | {
34 | GAME.current = state;
35 | }
36 |
37 | void ICE_State_Quit()
38 | {
39 | GAME.current->quit = ICE_True;
40 | }
41 |
42 | void ICE_State_Pause()
43 | {
44 | GAME.current->quit = ICE_True;
45 | GAME.current->isPaused = ICE_True;
46 | }
47 |
48 | void ICE_State_ResumeCallback(ICE_State * state, void(*func_resume)(void))
49 | {
50 | if (!state)
51 | state = GAME.current;
52 |
53 | state->func_OnResume = func_resume;
54 | }
55 |
56 | void ICE_State_PauseCallback(ICE_State * state, void(*func_pause)(void))
57 | {
58 | if (!state)
59 | state = GAME.current;
60 |
61 | state->func_OnPause = func_pause;
62 | }
63 |
64 | ICE_Bool ICE_State_WasPaused()
65 | {
66 | return GAME.current->isPaused;
67 | }
68 |
69 | void ICE_Substate_Start(ICE_State *state)
70 | {
71 | state->parent = GAME.current;
72 | GAME.current = state;
73 |
74 | if(GAME.current->isPaused)
75 | {
76 | GAME.current->quit = ICE_False;
77 | }
78 |
79 | ICE_Substate_Loop();
80 |
81 | GAME.current = state->parent;
82 |
83 |
84 | }
85 |
86 | ICE_State * ICE_State_Main()
87 | {
88 | return &GAME.state_main;
89 | }
90 |
91 | void ICE_State_Destroy(ICE_State * state)
92 | {
93 | if(!state->isFree)
94 | {
95 | ICE_LabelManager_Destroy(state);
96 | ICE_GuiManager_Destroy(state);
97 | ICE_Data_DestroyAll(state);
98 | }
99 | }
100 |
101 | void ICE_Substate_Loop()
102 | {
103 | ICE_Input_Reset();
104 | ICE_State * current = GAME.current;
105 |
106 |
107 |
108 | ICE_Log(ICE_LOGTYPE_RUNNING, "Entering substate");
109 |
110 | if (!current->isPaused)
111 | {
112 | ICE_LabelManager_Init(NULL);
113 | ICE_GuiManager_Init(NULL);
114 | ICE_EntityManager_Init(NULL);
115 | current->func_create();
116 | }
117 | else
118 | if (current->func_OnResume != NULL)
119 | current->func_OnResume();
120 |
121 | while (!CORE.window.input.quit && !GAME.current->quit)
122 | {
123 | ICE_Time_Start();
124 | ICE_Input_Return();
125 | ICE_Render_SetColor(current->background);
126 | ICE_Render_Clear();
127 |
128 | current->func_update();
129 |
130 | // RENDER HERE
131 | ICE_Draw_AllEntity();
132 | ICE_Draw_LabelWorld();
133 | ICE_Draw_AllGui();
134 | ICE_Draw_LabelScreen();
135 | ICE_Render_Now();
136 | ICE_Time_End();
137 | }
138 |
139 | if (!current->isPaused)
140 | {
141 | current->func_destroy();
142 | current->isFree = ICE_True;
143 | ICE_LabelManager_Destroy(NULL);
144 | ICE_GuiManager_Destroy(NULL);
145 | ICE_EntityManager_Destroy(NULL);
146 | ICE_Data_DestroyAll(NULL);
147 | ICE_ObjectManager obj = { 0 };
148 | current->object = obj;
149 | }
150 | else
151 | if(current->func_OnPause != NULL)
152 | current->func_OnPause();
153 |
154 | ICE_Log(ICE_LOGTYPE_RUNNING, "Leaving substate");
155 |
156 | ICE_Input_Reset();
157 | }
158 |
159 | ICE_State * ICE_State_GetParent(ICE_State * state)
160 | {
161 | if (!state)
162 | state = GAME.current;
163 |
164 |
165 | if(state->parent)
166 | return state->parent;
167 | ICE_Log(ICE_LOGTYPE_CRITICAL, "No Parent State");
168 | return state;
169 | }
170 |
171 | ICE_String ICE_State_CurrentName()
172 | {
173 | return GAME.current->name;
174 | }
175 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/State.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_STATE
2 | #define DEF_ICE_STATE
3 |
4 | #define ICE_DEFAULT_STATE_MNGR_SIZE 4
5 |
6 | #include "TypesCore.h"
7 |
8 | /// Current State
9 | #define ICE_State_Current NULL
10 |
11 | ICE_State ICE_State_Create(void(*func_create)(void), void(*func_update)(void), void(*func_destroy)(void));
12 | void ICE_State_Change(ICE_State * state);
13 | void ICE_State_Quit();
14 | void ICE_State_Pause();
15 | void ICE_State_ResumeCallback(ICE_State * state, void(*func_resume)(void));
16 | void ICE_State_PauseCallback(ICE_State * state, void(*func_pause)(void));
17 | ICE_Bool ICE_State_WasPaused();
18 | ICE_State * ICE_State_Main();
19 | void ICE_Substate_Start(ICE_State * state);
20 | void ICE_State_Destroy(ICE_State * state);
21 | void ICE_Substate_Loop();
22 | ICE_State * ICE_State_GetParent(ICE_State * state);
23 | ICE_String ICE_State_CurrentName();
24 |
25 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Time_.c:
--------------------------------------------------------------------------------
1 | #include "Time_.h"
2 | #include
3 |
4 | ICE_Uint64 ICE_Time_GetMS()
5 | {
6 | return (ICE_Float)clock();
7 | }
8 |
9 | ICE_Float ICE_Time_GetS()
10 | {
11 | return (ICE_Float)clock() / 1000.0;
12 | }
13 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Time_.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TIME
2 | #define DEF_ICE_TIME
3 |
4 | #include "../Framework/TypesFramework.h"
5 |
6 | ICE_Uint64 ICE_Time_GetMS();
7 | ICE_Float ICE_Time_GetS();
8 |
9 | #endif
10 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Time_private.c:
--------------------------------------------------------------------------------
1 | #include "Time_private.h"
2 | #include "TypesCore.h"
3 |
4 | #include "../External/SDL2_gfx/SDL2_framerate.h"
5 | #include "../Framework/Log.h"
6 |
7 | extern ICE_Game GAME;
8 | extern ICE_Core CORE;
9 | extern ICE_Config CONFIG;
10 |
11 | FPSmanager fps_manager_global;
12 |
13 | void ICE_Time_Init()
14 | {
15 | SDL_initFramerate(&fps_manager_global);
16 | if(SDL_setFramerate(&fps_manager_global, CONFIG.refresh_rate) == -1)
17 | ICE_Log(ICE_LOGTYPE_ERROR, "SDL_Gfx -> SDL_setFramerate");
18 | }
19 |
20 | void ICE_Time_Start()
21 | {
22 | /*
23 | GAME.time.actual = SDL_GetTicks(); // ticks since start of software at the start of loop
24 | GAME.time.ticksEllapsed = GAME.time.actual - GAME.time.last; // calculate nb of ticks ellapsed
25 | GAME.time.delta = (double)GAME.time.ticksEllapsed / 1000.0; // update the time.delta
26 | //if (GAME.time.ticksEllapsed > GAME.time.ticks) {// if the ticks ellapsed is superiore to the ticks for a frame it run the loop
27 | if (GAME.time.ticksEllapsed)
28 | GAME.time.fps = (double)(1000.0 / GAME.time.ticksEllapsed); // calculate fps
29 | */
30 | }
31 |
32 | void ICE_Time_End()
33 | {
34 |
35 | #define NB_COUNT_FPS 25
36 | #define TIME_BETWEEN_UPDATE 6.9444444444444
37 |
38 | static double fps_count[NB_COUNT_FPS];
39 | static int fps_actual_to_fill = 0;
40 | static ICE_Bool trigger_fpsblock = ICE_False;
41 | Uint32 elapsedMS = SDL_framerateDelay(&fps_manager_global);
42 | CORE.time.delta = (ICE_Float) elapsedMS / 1000.0;
43 |
44 | fps_count[fps_actual_to_fill] = 1000.0 / (ICE_Float)elapsedMS;
45 | fps_actual_to_fill++;
46 | if (fps_actual_to_fill >= NB_COUNT_FPS || fps_actual_to_fill < 0)
47 | {
48 | fps_actual_to_fill = 0;
49 | trigger_fpsblock = ICE_True;
50 | }
51 |
52 | static int time_to_refresh = 0;
53 | time_to_refresh += elapsedMS;
54 |
55 | if(time_to_refresh > 1000 || !trigger_fpsblock)
56 | {
57 | ICE_Float somme = 0;
58 | for (int i = 0; i < NB_COUNT_FPS; i++)
59 | somme += fps_count[i];
60 | CORE.time.fps = (ICE_Float)somme / NB_COUNT_FPS;
61 | time_to_refresh = 0;
62 | }
63 |
64 | /*
65 | GAME.time.last = GAME.time.actual;
66 | */
67 | }
68 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Time_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TIME_PRIVATE
2 | #define DEF_ICE_TIME_PRIVATE
3 |
4 | /**
5 | * \brief Init everything related to time
6 | */
7 | void ICE_Time_Init();
8 |
9 | /**
10 | * \brief Save everything before the main loop to measure time
11 | */
12 | void ICE_Time_Start();
13 |
14 | /**
15 | * \brief Return and calcul everything in need for time in GAME
16 | */
17 | void ICE_Time_End();
18 |
19 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Timer.c:
--------------------------------------------------------------------------------
1 | #include "Timer.h"
2 |
3 | #include
4 |
5 | void ICE_Timer_Start(ICE_Timer * timer_)
6 | {
7 | timer_->started = ICE_True;
8 | timer_->paused = ICE_False;
9 | timer_->start_ticks = SDL_GetTicks();
10 | timer_->pause_ticks = 0;
11 | }
12 |
13 | void ICE_Timer_Stop(ICE_Timer * timer_)
14 | {
15 | timer_->started = ICE_False;
16 | timer_->paused = ICE_False;
17 | timer_->start_ticks = 0;
18 | timer_->pause_ticks = 0;
19 | }
20 |
21 | void ICE_Timer_Pause(ICE_Timer * timer_)
22 | {
23 | if (timer_->started && !timer_->paused)
24 | {
25 | timer_->paused = ICE_True;
26 | timer_->pause_ticks = SDL_GetTicks() - timer_->start_ticks;
27 | timer_->start_ticks = 0;
28 | }
29 | }
30 |
31 | void ICE_Timer_Unpause(ICE_Timer * timer_)
32 | {
33 | if (timer_->started && timer_->paused)
34 | {
35 | timer_->paused = ICE_False;
36 | timer_->start_ticks = SDL_GetTicks() - timer_->pause_ticks;
37 | timer_->pause_ticks = 0;
38 | }
39 | }
40 |
41 | ICE_Uint32 ICE_Timer_GetTicks(ICE_Timer * timer_)
42 | {
43 | ICE_Uint32 time = 0;
44 | if (timer_->started)
45 | {
46 | if (timer_->paused)
47 | time = timer_->pause_ticks;
48 | else
49 | time = SDL_GetTicks() - timer_->start_ticks;
50 | }
51 | return time;
52 | }
53 |
54 | ICE_Bool ICE_Timer_isStarted(ICE_Timer * timer_)
55 | {
56 | return timer_->started;
57 | }
58 |
59 | ICE_Bool ICE_Timer_isPaused(ICE_Timer * timer_)
60 | {
61 | return timer_->paused;
62 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Timer.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TIMER_PRIVATE
2 | #define DEF_ICE_TIMER_PRIVATE
3 |
4 | #include "../Framework/TypesFramework.h"
5 |
6 | struct ICE_Timer
7 | {
8 | ICE_Uint32 start_ticks;
9 | ICE_Uint32 pause_ticks;
10 | ICE_Bool paused;
11 | ICE_Bool started;
12 |
13 | };
14 | typedef struct ICE_Timer ICE_Timer;
15 |
16 | void ICE_Timer_Start(ICE_Timer * timer_);
17 | void ICE_Timer_Stop(ICE_Timer * timer_);
18 | void ICE_Timer_Pause(ICE_Timer * timer_);
19 | void ICE_Timer_Unpause(ICE_Timer * timer_);
20 | ICE_Uint32 ICE_Timer_GetTicks(ICE_Timer * timer_);
21 | ICE_Bool ICE_Timer_isStarted(ICE_Timer * timer_);
22 | ICE_Bool ICE_Timer_isPaused(ICE_Timer * timer_);
23 |
24 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Version.c:
--------------------------------------------------------------------------------
1 | #include "Version.h"
2 |
3 | ICE_StringStd ICE_Core_GetLinkedVersion()
4 | {
5 | return ICE_VERSION;
6 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Version.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_VERSION_H
2 | #define DEF_ICE_VERSION_H
3 |
4 | #include "../Framework/Inline.h"
5 | #include "../Framework/String_.h"
6 |
7 | #define ICE_VERSION "DEV.1902.1"
8 |
9 | ICE_StringStd ICE_Core_GetLinkedVersion();
10 | ICE_INLINE ICE_StringStd ICE_Core_GetCompiledVersion()
11 | {
12 | return ICE_VERSION;
13 | }
14 |
15 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Window.c:
--------------------------------------------------------------------------------
1 | #include "Window.h"
2 | #include "TypesCore.h"
3 | #include ICE_INCLUDE_SDL2
4 | #include "../External/stb/SDL_stbimage.h"
5 | #define STB_IMAGE_WRITE_IMPLEMENTATION
6 | #include "../External/stb/stb_image_write.h"
7 | #include "../Framework/Log.h"
8 | #include "../Framework/Memory_.h"
9 |
10 | extern ICE_Game GAME;
11 | extern ICE_Core CORE;
12 |
13 | void ICE_Window_SetSize(int w, int h)
14 | {
15 | SDL_SetWindowSize(CORE.window.handle, w, h);
16 | CORE.window.w = w; CORE.window.h = h;
17 | }
18 |
19 | void ICE_Window_SetResizable(ICE_Bool yn)
20 | {
21 | SDL_SetWindowResizable(CORE.window.handle, yn);
22 | }
23 |
24 | void ICE_Window_SetFullscreen(int yn)
25 | {
26 | SDL_SetWindowFullscreen(CORE.window.handle, yn);
27 | }
28 |
29 | void ICE_Window_SetTitle(const char *title)
30 | {
31 | SDL_SetWindowTitle(CORE.window.handle, title);
32 | }
33 |
34 | void ICE_Window_SetIcon(char * path)
35 | {
36 | if (!path)
37 | {
38 | #include "../Ressources/raw/Icon.c"
39 |
40 | #if SDL_BYTEORDER == SDL_BIG_ENDIAN
41 | int shift = (ice_raw_img_icon.bytes_per_pixel == 3) ? 8 : 0;
42 | Uint32 rmask = 0xff000000 >> shift;
43 | Uint32 gmask = 0x00ff0000 >> shift;
44 | Uint32 bmask = 0x0000ff00 >> shift;
45 | Uint32 amask = 0x000000ff >> shift;
46 | #else // little endian, like x86
47 | Uint32 rmask = 0x000000ff;
48 | Uint32 gmask = 0x0000ff00;
49 | Uint32 bmask = 0x00ff0000;
50 | Uint32 amask = (ice_raw_img_icon.bytes_per_pixel == 3) ? 0 : 0xff000000;
51 | #endif
52 |
53 | SDL_Surface* icon = SDL_CreateRGBSurfaceFrom((void*)ice_raw_img_icon.pixel_data, ice_raw_img_icon.width,
54 | ice_raw_img_icon.height, ice_raw_img_icon.bytes_per_pixel * 8, ice_raw_img_icon.bytes_per_pixel*ice_raw_img_icon.width,
55 | rmask, gmask, bmask, amask);
56 |
57 | SDL_SetWindowIcon(CORE.window.handle, icon);
58 |
59 | SDL_FreeSurface(icon);
60 | }
61 | else
62 | {
63 |
64 | SDL_Surface *icon = STBIMG_Load(path);
65 |
66 | if (icon == NULL)
67 | ICE_Log(ICE_LOGTYPE_ERROR, "ICE_Window_SetIcon : %s", SDL_GetError);
68 |
69 | SDL_SetWindowIcon(CORE.window.handle, icon);
70 | SDL_FreeSurface(icon);
71 | }
72 | }
73 |
74 | int ICE_Window_GetW()
75 | {
76 | return (int)CORE.window.w;
77 | }
78 | int ICE_Window_GetH()
79 | {
80 | return (int)CORE.window.h;
81 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Window.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_WINDOW
2 | #define DEF_ICE_WINDOW
3 |
4 | #include "TypesCore.h"
5 |
6 | /**
7 | * \brief Set size of the window
8 | * \param w Width
9 | * \param h Height
10 | */
11 | void ICE_Window_SetSize(int w, int h);
12 |
13 | /**
14 | * \brief Set the window resizable or not
15 | * \param yn A Bool with the answer
16 | */
17 | void ICE_Window_SetResizable(ICE_Bool yn);
18 |
19 | /**
20 | * \brief Set the window fullscreen or not
21 | * \param yn A Bool with the answer
22 | */
23 | void ICE_Window_SetFullscreen(int yn);
24 |
25 | /**
26 | * \brief Set the window title
27 | * \param title The title of the window
28 | */
29 | void ICE_Window_SetTitle(const char *title);
30 |
31 | /**
32 | * \brief Set icon of the window from a file
33 | * \param path Path to the file
34 | */
35 | void ICE_Window_SetIcon(char * path);
36 |
37 | /**
38 | * \brief Get the width of the window
39 | * \return Width of the window
40 | */
41 | int ICE_Window_GetW();
42 |
43 | /**
44 | * \brief Get the height of the window
45 | * \return Height of the window
46 | */
47 | int ICE_Window_GetH();
48 |
49 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Window_private.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "TypesCore.h"
3 | #include "Window.h"
4 | #include "Window_private.h"
5 | #include "../Framework/Log.h"
6 |
7 | extern ICE_Config CONFIG;
8 | extern ICE_Core CORE;
9 |
10 | void ICE_Window_Config()
11 | {
12 | if (CONFIG.resizable)
13 | ICE_Window_SetResizable(1);
14 |
15 | if (CONFIG.fullscreen == 1)
16 | ICE_Window_SetFullscreen(SDL_WINDOW_FULLSCREEN);
17 |
18 | if (CONFIG.fullscreen == 2)
19 | {
20 | int display_index = SDL_GetWindowDisplayIndex(CORE.window.handle);
21 | SDL_Rect screen_size;
22 | SDL_GetDisplayBounds(display_index, &screen_size);
23 | ICE_Window_SetSize(screen_size.w, screen_size.h);
24 | ICE_Window_SetFullscreen(SDL_WINDOW_FULLSCREEN_DESKTOP);
25 | }
26 | ICE_Window_SetIcon(CONFIG.window_icon);
27 | SDL_ShowWindow(CORE.window.handle);
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/projects/Engine/src/Core/Window_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_WINDOW_PRIVATE
2 | #define DEF_ICE_WINDOW_PRIVATE
3 |
4 | void ICE_Window_Config();
5 |
6 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/External/SDL2_gfx/SDL2_framerate.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | SDL2_framerate.h: framerate manager
4 |
5 | Copyright (C) 2012-2014 Andreas Schiffler
6 |
7 | This software is provided 'as-is', without any express or implied
8 | warranty. In no event will the authors be held liable for any damages
9 | arising from the use of this software.
10 |
11 | Permission is granted to anyone to use this software for any purpose,
12 | including commercial applications, and to alter it and redistribute it
13 | freely, subject to the following restrictions:
14 |
15 | 1. The origin of this software must not be misrepresented; you must not
16 | claim that you wrote the original software. If you use this software
17 | in a product, an acknowledgment in the product documentation would be
18 | appreciated but is not required.
19 |
20 | 2. Altered source versions must be plainly marked as such, and must not be
21 | misrepresented as being the original software.
22 |
23 | 3. This notice may not be removed or altered from any source
24 | distribution.
25 |
26 | Andreas Schiffler -- aschiffler at ferzkopp dot net
27 |
28 | */
29 |
30 | #ifndef _SDL2_framerate_h
31 | #define _SDL2_framerate_h
32 |
33 | /* Set up for C function definitions, even when using C++ */
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | /* --- */
39 |
40 | #include "../../Core/SDL2_Includer.h"
41 | #include ICE_INCLUDE_SDL2
42 |
43 | /* --------- Definitions */
44 |
45 | /*!
46 | \brief Highest possible rate supported by framerate controller in Hz (1/s).
47 | */
48 | #define FPS_UPPER_LIMIT 200
49 |
50 | /*!
51 | \brief Lowest possible rate supported by framerate controller in Hz (1/s).
52 | */
53 | #define FPS_LOWER_LIMIT 1
54 |
55 | /*!
56 | \brief Default rate of framerate controller in Hz (1/s).
57 | */
58 | #define FPS_DEFAULT 30
59 |
60 | /*!
61 | \brief Structure holding the state and timing information of the framerate controller.
62 | */
63 | typedef struct {
64 | Uint32 framecount;
65 | float rateticks;
66 | Uint32 baseticks;
67 | Uint32 lastticks;
68 | Uint32 rate;
69 | } FPSmanager;
70 |
71 | /* ---- Function Prototypes */
72 |
73 | #ifdef _MSC_VER
74 | # if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
75 | # define SDL2_FRAMERATE_SCOPE __declspec(dllexport)
76 | # else
77 | # ifdef LIBSDL2_GFX_DLL_IMPORT
78 | # define SDL2_FRAMERATE_SCOPE __declspec(dllimport)
79 | # endif
80 | # endif
81 | #endif
82 | #ifndef SDL2_FRAMERATE_SCOPE
83 | # define SDL2_FRAMERATE_SCOPE extern
84 | #endif
85 |
86 | /* Functions return 0 or value for sucess and -1 for error */
87 |
88 | SDL2_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager);
89 | SDL2_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate);
90 | SDL2_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager);
91 | SDL2_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager);
92 | SDL2_FRAMERATE_SCOPE Uint32 SDL_framerateDelay(FPSmanager * manager);
93 |
94 | /* --- */
95 |
96 | /* Ends C function definitions when using C++ */
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /* _SDL2_framerate_h */
102 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/SDL2_gfx/SDL2_gfxPrimitives_font.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/External/SDL2_gfx/SDL2_gfxPrimitives_font.h
--------------------------------------------------------------------------------
/projects/Engine/src/External/SDL2_gfx/SDL2_rotozoom.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
4 |
5 | Copyright (C) 2012-2014 Andreas Schiffler
6 |
7 | This software is provided 'as-is', without any express or implied
8 | warranty. In no event will the authors be held liable for any damages
9 | arising from the use of this software.
10 |
11 | Permission is granted to anyone to use this software for any purpose,
12 | including commercial applications, and to alter it and redistribute it
13 | freely, subject to the following restrictions:
14 |
15 | 1. The origin of this software must not be misrepresented; you must not
16 | claim that you wrote the original software. If you use this software
17 | in a product, an acknowledgment in the product documentation would be
18 | appreciated but is not required.
19 |
20 | 2. Altered source versions must be plainly marked as such, and must not be
21 | misrepresented as being the original software.
22 |
23 | 3. This notice may not be removed or altered from any source
24 | distribution.
25 |
26 | Andreas Schiffler -- aschiffler at ferzkopp dot net
27 |
28 | */
29 |
30 | #ifndef _SDL2_rotozoom_h
31 | #define _SDL2_rotozoom_h
32 |
33 | #include
34 |
35 | /* Set up for C function definitions, even when using C++ */
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | #ifndef M_PI
41 | #define M_PI 3.1415926535897932384626433832795
42 | #endif
43 |
44 | #include "../../Core/SDL2_Includer.h"
45 | #include ICE_INCLUDE_SDL2
46 |
47 | /* ---- Defines */
48 |
49 | /*!
50 | \brief Disable anti-aliasing (no smoothing).
51 | */
52 | #define SMOOTHING_OFF 0
53 |
54 | /*!
55 | \brief Enable anti-aliasing (smoothing).
56 | */
57 | #define SMOOTHING_ON 1
58 |
59 | /* ---- Function Prototypes */
60 |
61 | #ifdef _MSC_VER
62 | # if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
63 | # define SDL2_ROTOZOOM_SCOPE __declspec(dllexport)
64 | # else
65 | # ifdef LIBSDL2_GFX_DLL_IMPORT
66 | # define SDL2_ROTOZOOM_SCOPE __declspec(dllimport)
67 | # endif
68 | # endif
69 | #endif
70 | #ifndef SDL2_ROTOZOOM_SCOPE
71 | # define SDL2_ROTOZOOM_SCOPE extern
72 | #endif
73 |
74 | /*
75 |
76 | Rotozoom functions
77 |
78 | */
79 |
80 | SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
81 |
82 | SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
83 | (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
84 |
85 |
86 | SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
87 | int *dstheight);
88 |
89 | SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
90 | (int width, int height, double angle, double zoomx, double zoomy,
91 | int *dstwidth, int *dstheight);
92 |
93 | /*
94 |
95 | Zooming functions
96 |
97 | */
98 |
99 | SDL2_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
100 |
101 | SDL2_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
102 |
103 | /*
104 |
105 | Shrinking functions
106 |
107 | */
108 |
109 | SDL2_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
110 |
111 | /*
112 |
113 | Specialized rotation functions
114 |
115 | */
116 |
117 | SDL2_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
118 |
119 | /* Ends C function definitions when using C++ */
120 | #ifdef __cplusplus
121 | }
122 | #endif
123 |
124 | #endif /* _SDL2_rotozoom_h */
125 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_archiver_grp.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRP support routines for PhysicsFS.
3 | *
4 | * This driver handles BUILD engine archives ("groupfiles"). This format
5 | * (but not this driver) was put together by Ken Silverman.
6 | *
7 | * The format is simple enough. In Ken's words:
8 | *
9 | * What's the .GRP file format?
10 | *
11 | * The ".grp" file format is just a collection of a lot of files stored
12 | * into 1 big one. I tried to make the format as simple as possible: The
13 | * first 12 bytes contains my name, "KenSilverman". The next 4 bytes is
14 | * the number of files that were compacted into the group file. Then for
15 | * each file, there is a 16 byte structure, where the first 12 bytes are
16 | * the filename, and the last 4 bytes are the file's size. The rest of
17 | * the group file is just the raw data packed one after the other in the
18 | * same order as the list of files.
19 | *
20 | * (That info is from http://www.advsys.net/ken/build.htm ...)
21 | *
22 | * Please see the file LICENSE.txt in the source's root directory.
23 | *
24 | * This file written by Ryan C. Gordon.
25 | */
26 |
27 | #define __PHYSICSFS_INTERNAL__
28 | #include "physfs_internal.h"
29 |
30 | #if PHYSFS_SUPPORTS_GRP
31 |
32 | static int grpLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
33 | {
34 | PHYSFS_uint32 pos = 16 + (16 * count); /* past sig+metadata. */
35 | PHYSFS_uint32 i;
36 |
37 | for (i = 0; i < count; i++)
38 | {
39 | char *ptr;
40 | char name[13];
41 | PHYSFS_uint32 size;
42 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 12), 0);
43 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
44 |
45 | name[12] = '\0'; /* name isn't null-terminated in file. */
46 | if ((ptr = strchr(name, ' ')) != NULL)
47 | *ptr = '\0'; /* trim extra spaces. */
48 |
49 | size = PHYSFS_swapULE32(size);
50 | BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
51 |
52 | pos += size;
53 | } /* for */
54 |
55 | return 1;
56 | } /* grpLoadEntries */
57 |
58 |
59 | static void *GRP_openArchive(PHYSFS_Io *io, const char *name,
60 | int forWriting, int *claimed)
61 | {
62 | PHYSFS_uint8 buf[12];
63 | PHYSFS_uint32 count = 0;
64 | void *unpkarc = NULL;
65 |
66 | assert(io != NULL); /* shouldn't ever happen. */
67 |
68 | BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
69 |
70 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
71 | if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0)
72 | BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
73 |
74 | *claimed = 1;
75 |
76 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
77 | count = PHYSFS_swapULE32(count);
78 |
79 | unpkarc = UNPK_openArchive(io);
80 | BAIL_IF_ERRPASS(!unpkarc, NULL);
81 |
82 | if (!grpLoadEntries(io, count, unpkarc))
83 | {
84 | UNPK_abandonArchive(unpkarc);
85 | return NULL;
86 | } /* if */
87 |
88 | return unpkarc;
89 | } /* GRP_openArchive */
90 |
91 |
92 | const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
93 | {
94 | CURRENT_PHYSFS_ARCHIVER_API_VERSION,
95 | {
96 | "GRP",
97 | "Build engine Groupfile format",
98 | "Ryan C. Gordon ",
99 | "https://icculus.org/physfs/",
100 | 0, /* supportsSymlinks */
101 | },
102 | GRP_openArchive,
103 | UNPK_enumerate,
104 | UNPK_openRead,
105 | UNPK_openWrite,
106 | UNPK_openAppend,
107 | UNPK_remove,
108 | UNPK_mkdir,
109 | UNPK_stat,
110 | UNPK_closeArchive
111 | };
112 |
113 | #endif /* defined PHYSFS_SUPPORTS_GRP */
114 |
115 | /* end of physfs_archiver_grp.c ... */
116 |
117 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_archiver_hog.c:
--------------------------------------------------------------------------------
1 | /*
2 | * HOG support routines for PhysicsFS.
3 | *
4 | * This driver handles Descent I/II HOG archives.
5 | *
6 | * The format is very simple:
7 | *
8 | * The file always starts with the 3-byte signature "DHF" (Descent
9 | * HOG file). After that the files of a HOG are just attached after
10 | * another, divided by a 17 bytes header, which specifies the name
11 | * and length (in bytes) of the forthcoming file! So you just read
12 | * the header with its information of how big the following file is,
13 | * and then skip exact that number of bytes to get to the next file
14 | * in that HOG.
15 | *
16 | * char sig[3] = {'D', 'H', 'F'}; // "DHF"=Descent HOG File
17 | *
18 | * struct {
19 | * char file_name[13]; // Filename, padded to 13 bytes with 0s
20 | * int file_size; // filesize in bytes
21 | * char data[file_size]; // The file data
22 | * } FILE_STRUCT; // Repeated until the end of the file.
23 | *
24 | * (That info is from http://www.descent2.com/ddn/specs/hog/)
25 | *
26 | * Please see the file LICENSE.txt in the source's root directory.
27 | *
28 | * This file written by Bradley Bell.
29 | * Based on grp.c by Ryan C. Gordon.
30 | */
31 |
32 | #define __PHYSICSFS_INTERNAL__
33 | #include "physfs_internal.h"
34 |
35 | #if PHYSFS_SUPPORTS_HOG
36 |
37 | static int hogLoadEntries(PHYSFS_Io *io, void *arc)
38 | {
39 | const PHYSFS_uint64 iolen = io->length(io);
40 | PHYSFS_uint32 pos = 3;
41 |
42 | while (pos < iolen)
43 | {
44 | PHYSFS_uint32 size;
45 | char name[13];
46 |
47 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
48 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
49 | name[12] = '\0'; /* just in case. */
50 | pos += 13 + 4;
51 |
52 | size = PHYSFS_swapULE32(size);
53 | BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
54 | pos += size;
55 |
56 | /* skip over entry */
57 | BAIL_IF_ERRPASS(!io->seek(io, pos), 0);
58 | } /* while */
59 |
60 | return 1;
61 | } /* hogLoadEntries */
62 |
63 |
64 | static void *HOG_openArchive(PHYSFS_Io *io, const char *name,
65 | int forWriting, int *claimed)
66 | {
67 | PHYSFS_uint8 buf[3];
68 | void *unpkarc = NULL;
69 |
70 | assert(io != NULL); /* shouldn't ever happen. */
71 | BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
72 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
73 | BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
74 |
75 | *claimed = 1;
76 |
77 | unpkarc = UNPK_openArchive(io);
78 | BAIL_IF_ERRPASS(!unpkarc, NULL);
79 |
80 | if (!hogLoadEntries(io, unpkarc))
81 | {
82 | UNPK_abandonArchive(unpkarc);
83 | return NULL;
84 | } /* if */
85 |
86 | return unpkarc;
87 | } /* HOG_openArchive */
88 |
89 |
90 | const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
91 | {
92 | CURRENT_PHYSFS_ARCHIVER_API_VERSION,
93 | {
94 | "HOG",
95 | "Descent I/II HOG file format",
96 | "Bradley Bell ",
97 | "https://icculus.org/physfs/",
98 | 0, /* supportsSymlinks */
99 | },
100 | HOG_openArchive,
101 | UNPK_enumerate,
102 | UNPK_openRead,
103 | UNPK_openWrite,
104 | UNPK_openAppend,
105 | UNPK_remove,
106 | UNPK_mkdir,
107 | UNPK_stat,
108 | UNPK_closeArchive
109 | };
110 |
111 | #endif /* defined PHYSFS_SUPPORTS_HOG */
112 |
113 | /* end of physfs_archiver_hog.c ... */
114 |
115 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_archiver_mvl.c:
--------------------------------------------------------------------------------
1 | /*
2 | * MVL support routines for PhysicsFS.
3 | *
4 | * This driver handles Descent II Movielib archives.
5 | *
6 | * The file format of MVL is quite easy...
7 | *
8 | * //MVL File format - Written by Heiko Herrmann
9 | * char sig[4] = {'D','M', 'V', 'L'}; // "DMVL"=Descent MoVie Library
10 | *
11 | * int num_files; // the number of files in this MVL
12 | *
13 | * struct {
14 | * char file_name[13]; // Filename, padded to 13 bytes with 0s
15 | * int file_size; // filesize in bytes
16 | * }DIR_STRUCT[num_files];
17 | *
18 | * struct {
19 | * char data[file_size]; // The file data
20 | * }FILE_STRUCT[num_files];
21 | *
22 | * (That info is from http://www.descent2.com/ddn/specs/mvl/)
23 | *
24 | * Please see the file LICENSE.txt in the source's root directory.
25 | *
26 | * This file written by Bradley Bell.
27 | * Based on grp.c by Ryan C. Gordon.
28 | */
29 |
30 | #define __PHYSICSFS_INTERNAL__
31 | #include "physfs_internal.h"
32 |
33 | #if PHYSFS_SUPPORTS_MVL
34 |
35 | static int mvlLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
36 | {
37 | PHYSFS_uint32 pos = 8 + (17 * count); /* past sig+metadata. */
38 | PHYSFS_uint32 i;
39 |
40 | for (i = 0; i < count; i++)
41 | {
42 | PHYSFS_uint32 size;
43 | char name[13];
44 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 13), 0);
45 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
46 | name[12] = '\0'; /* just in case. */
47 | size = PHYSFS_swapULE32(size);
48 | BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
49 | pos += size;
50 | } /* for */
51 |
52 | return 1;
53 | } /* mvlLoadEntries */
54 |
55 |
56 | static void *MVL_openArchive(PHYSFS_Io *io, const char *name,
57 | int forWriting, int *claimed)
58 | {
59 | PHYSFS_uint8 buf[4];
60 | PHYSFS_uint32 count = 0;
61 | void *unpkarc;
62 |
63 | assert(io != NULL); /* shouldn't ever happen. */
64 | BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
65 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 4), NULL);
66 | BAIL_IF(memcmp(buf, "DMVL", 4) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
67 |
68 | *claimed = 1;
69 |
70 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
71 | count = PHYSFS_swapULE32(count);
72 |
73 | unpkarc = UNPK_openArchive(io);
74 | BAIL_IF_ERRPASS(!unpkarc, NULL);
75 |
76 | if (!mvlLoadEntries(io, count, unpkarc))
77 | {
78 | UNPK_abandonArchive(unpkarc);
79 | return NULL;
80 | } /* if */
81 |
82 | return unpkarc;
83 | } /* MVL_openArchive */
84 |
85 |
86 | const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
87 | {
88 | CURRENT_PHYSFS_ARCHIVER_API_VERSION,
89 | {
90 | "MVL",
91 | "Descent II Movielib format",
92 | "Bradley Bell ",
93 | "https://icculus.org/physfs/",
94 | 0, /* supportsSymlinks */
95 | },
96 | MVL_openArchive,
97 | UNPK_enumerate,
98 | UNPK_openRead,
99 | UNPK_openWrite,
100 | UNPK_openAppend,
101 | UNPK_remove,
102 | UNPK_mkdir,
103 | UNPK_stat,
104 | UNPK_closeArchive
105 | };
106 |
107 | #endif /* defined PHYSFS_SUPPORTS_MVL */
108 |
109 | /* end of physfs_archiver_mvl.c ... */
110 |
111 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_archiver_qpak.c:
--------------------------------------------------------------------------------
1 | /*
2 | * QPAK support routines for PhysicsFS.
3 | *
4 | * This archiver handles the archive format utilized by Quake 1 and 2.
5 | * Quake3-based games use the PkZip/Info-Zip format (which our
6 | * physfs_archiver_zip.c handles).
7 | *
8 | * ========================================================================
9 | *
10 | * This format info (in more detail) comes from:
11 | * https://web.archive.org/web/20040209101748/http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt
12 | *
13 | * Quake PAK Format
14 | *
15 | * Header
16 | * (4 bytes) signature = 'PACK'
17 | * (4 bytes) directory offset
18 | * (4 bytes) directory length
19 | *
20 | * Directory
21 | * (56 bytes) file name
22 | * (4 bytes) file position
23 | * (4 bytes) file length
24 | *
25 | * ========================================================================
26 | *
27 | * Please see the file LICENSE.txt in the source's root directory.
28 | *
29 | * This file written by Ryan C. Gordon.
30 | */
31 |
32 | #define __PHYSICSFS_INTERNAL__
33 | #include "physfs_internal.h"
34 |
35 | #if PHYSFS_SUPPORTS_QPAK
36 |
37 | #define QPAK_SIG 0x4B434150 /* "PACK" in ASCII. */
38 |
39 | static int qpakLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 count, void *arc)
40 | {
41 | PHYSFS_uint32 i;
42 | for (i = 0; i < count; i++)
43 | {
44 | PHYSFS_uint32 size;
45 | PHYSFS_uint32 pos;
46 | char name[56];
47 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, name, 56), 0);
48 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &pos, 4), 0);
49 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &size, 4), 0);
50 | size = PHYSFS_swapULE32(size);
51 | pos = PHYSFS_swapULE32(pos);
52 | BAIL_IF_ERRPASS(!UNPK_addEntry(arc, name, 0, -1, -1, pos, size), 0);
53 | } /* for */
54 |
55 | return 1;
56 | } /* qpakLoadEntries */
57 |
58 |
59 | static void *QPAK_openArchive(PHYSFS_Io *io, const char *name,
60 | int forWriting, int *claimed)
61 | {
62 | PHYSFS_uint32 val = 0;
63 | PHYSFS_uint32 pos = 0;
64 | PHYSFS_uint32 count = 0;
65 | void *unpkarc;
66 |
67 | assert(io != NULL); /* shouldn't ever happen. */
68 |
69 | BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
70 |
71 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
72 | if (PHYSFS_swapULE32(val) != QPAK_SIG)
73 | BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
74 |
75 | *claimed = 1;
76 |
77 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
78 | pos = PHYSFS_swapULE32(val); /* directory table offset. */
79 |
80 | BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &val, 4), NULL);
81 | count = PHYSFS_swapULE32(val);
82 |
83 | /* corrupted archive? */
84 | BAIL_IF((count % 64) != 0, PHYSFS_ERR_CORRUPT, NULL);
85 | count /= 64;
86 |
87 | BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
88 |
89 | unpkarc = UNPK_openArchive(io);
90 | BAIL_IF_ERRPASS(!unpkarc, NULL);
91 |
92 | if (!qpakLoadEntries(io, count, unpkarc))
93 | {
94 | UNPK_abandonArchive(unpkarc);
95 | return NULL;
96 | } /* if */
97 |
98 | return unpkarc;
99 | } /* QPAK_openArchive */
100 |
101 |
102 | const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
103 | {
104 | CURRENT_PHYSFS_ARCHIVER_API_VERSION,
105 | {
106 | "PAK",
107 | "Quake I/II format",
108 | "Ryan C. Gordon ",
109 | "https://icculus.org/physfs/",
110 | 0, /* supportsSymlinks */
111 | },
112 | QPAK_openArchive,
113 | UNPK_enumerate,
114 | UNPK_openRead,
115 | UNPK_openWrite,
116 | UNPK_openAppend,
117 | UNPK_remove,
118 | UNPK_mkdir,
119 | UNPK_stat,
120 | UNPK_closeArchive
121 | };
122 |
123 | #endif /* defined PHYSFS_SUPPORTS_QPAK */
124 |
125 | /* end of physfs_archiver_qpak.c ... */
126 |
127 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_platform_winrt.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Windows Runtime (WinRT) support routines for PhysicsFS.
3 | *
4 | * Please see the file LICENSE.txt in the source's root directory.
5 | *
6 | * This file originally written by Martin "T-Bone" Ahrnbom, but was mostly
7 | * merged into physfs_platform_windows.c by Ryan C. Gordon (so please harass
8 | * Ryan about bugs and not Martin).
9 | */
10 |
11 | /* (There used to be instructions on how to make a WinRT project, but at
12 | this point, either CMake will do it for you or you should just drop
13 | PhysicsFS's sources into your existing project. --ryan.) */
14 |
15 | #define __PHYSICSFS_INTERNAL__
16 | #include "physfs_platforms.h"
17 |
18 | #ifdef PHYSFS_PLATFORM_WINRT
19 |
20 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
21 | #define _CRT_SECURE_NO_WARNINGS 1
22 | #endif
23 | #include
24 |
25 | #include "physfs_internal.h"
26 |
27 | const void *__PHYSFS_winrtCalcBaseDir(void)
28 | {
29 | return Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
30 | } /* __PHYSFS_winrtCalcBaseDir */
31 |
32 | const void *__PHYSFS_winrtCalcPrefDir(void)
33 | {
34 | return Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data();
35 | } /* __PHYSFS_winrtCalcBaseDir */
36 |
37 |
38 | #endif /* PHYSFS_PLATFORM_WINRT */
39 |
40 | /* end of physfs_platform_winrt.cpp ... */
41 |
42 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfs_platforms.h:
--------------------------------------------------------------------------------
1 | #ifndef _INCL_PHYSFS_PLATFORMS
2 | #define _INCL_PHYSFS_PLATFORMS
3 |
4 | #ifndef __PHYSICSFS_INTERNAL__
5 | #error Do not include this header from your applications.
6 | #endif
7 |
8 | /*
9 | * These only define the platforms to determine which files in the platforms
10 | * directory should be compiled. For example, technically BeOS can be called
11 | * a "unix" system, but since it doesn't use unix.c, we don't define
12 | * PHYSFS_PLATFORM_UNIX on that system.
13 | */
14 |
15 | #if (defined __HAIKU__)
16 | # define PHYSFS_PLATFORM_HAIKU 1
17 | # define PHYSFS_PLATFORM_POSIX 1
18 | #elif ((defined __BEOS__) || (defined __beos__))
19 | # error BeOS support was dropped since PhysicsFS 2.1. Sorry. Try Haiku!
20 | #elif (defined _WIN32_WCE) || (defined _WIN64_WCE)
21 | # error PocketPC support was dropped since PhysicsFS 2.1. Sorry. Try WinRT!
22 | #elif (defined(_MSC_VER) && (_MSC_VER >= 1700) && !_USING_V110_SDK71_) /* _MSC_VER==1700 for MSVC 2012 */
23 | # include
24 | # define PHYSFS_PLATFORM_WINDOWS 1
25 | # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
26 | # define PHYSFS_NO_CDROM_SUPPORT 1
27 | # define PHYSFS_PLATFORM_WINRT 1
28 | # endif
29 | #elif (((defined _WIN32) || (defined _WIN64)) && (!defined __CYGWIN__))
30 | # define PHYSFS_PLATFORM_WINDOWS 1
31 | #elif defined(__OS2__) || defined(OS2)
32 | # define PHYSFS_PLATFORM_OS2 1
33 | #elif ((defined __MACH__) && (defined __APPLE__))
34 | /* To check if iOS or not, we need to include this file */
35 | # include
36 | # if ((TARGET_IPHONE_SIMULATOR) || (TARGET_OS_IPHONE))
37 | # define PHYSFS_NO_CDROM_SUPPORT 1
38 | # endif
39 | # define PHYSFS_PLATFORM_APPLE 1
40 | # define PHYSFS_PLATFORM_POSIX 1
41 | #elif defined(macintosh)
42 | # error Classic Mac OS support was dropped from PhysicsFS 2.0. Move to OS X.
43 | #elif defined(ANDROID)
44 | # define PHYSFS_PLATFORM_LINUX 1
45 | # define PHYSFS_PLATFORM_UNIX 1
46 | # define PHYSFS_PLATFORM_POSIX 1
47 | # define PHYSFS_NO_CDROM_SUPPORT 1
48 | #elif defined(__linux)
49 | # define PHYSFS_PLATFORM_LINUX 1
50 | # define PHYSFS_PLATFORM_UNIX 1
51 | # define PHYSFS_PLATFORM_POSIX 1
52 | #elif defined(__sun) || defined(sun)
53 | # define PHYSFS_PLATFORM_SOLARIS 1
54 | # define PHYSFS_PLATFORM_UNIX 1
55 | # define PHYSFS_PLATFORM_POSIX 1
56 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
57 | # define PHYSFS_PLATFORM_FREEBSD 1
58 | # define PHYSFS_PLATFORM_BSD 1
59 | # define PHYSFS_PLATFORM_UNIX 1
60 | # define PHYSFS_PLATFORM_POSIX 1
61 | #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
62 | # define PHYSFS_PLATFORM_BSD 1
63 | # define PHYSFS_PLATFORM_UNIX 1
64 | # define PHYSFS_PLATFORM_POSIX 1
65 | #elif defined(__EMSCRIPTEN__)
66 | # define PHYSFS_NO_CDROM_SUPPORT 1
67 | # define PHYSFS_PLATFORM_UNIX 1
68 | # define PHYSFS_PLATFORM_POSIX 1
69 | #elif defined(__QNX__)
70 | # define PHYSFS_PLATFORM_QNX 1
71 | # define PHYSFS_PLATFORM_POSIX 1
72 | #elif defined(unix) || defined(__unix__)
73 | # define PHYSFS_PLATFORM_UNIX 1
74 | # define PHYSFS_PLATFORM_POSIX 1
75 | #else
76 | # error Unknown platform.
77 | #endif
78 |
79 | #endif /* include-once blocker. */
80 |
81 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/physfs/physfsrwops.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This code provides a glue layer between PhysicsFS and Simple Directmedia
3 | * Layer's (SDL) RWops i/o abstraction.
4 | *
5 | * License: this code is public domain. I make no warranty that it is useful,
6 | * correct, harmless, or environmentally safe.
7 | *
8 | * This particular file may be used however you like, including copying it
9 | * verbatim into a closed-source project, exploiting it commercially, and
10 | * removing any trace of my name from the source (although I hope you won't
11 | * do that). I welcome enhancements and corrections to this file, but I do
12 | * not require you to send me patches if you make changes. This code has
13 | * NO WARRANTY.
14 | *
15 | * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
16 | * Please see LICENSE.txt in the root of the source tree.
17 | *
18 | * SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS.
19 | * You can get SDL at https://www.libsdl.org/
20 | *
21 | * This file was written by Ryan C. Gordon. (icculus@icculus.org).
22 | */
23 |
24 | #ifndef _INCLUDE_PHYSFSRWOPS_H_
25 | #define _INCLUDE_PHYSFSRWOPS_H_
26 |
27 | #include "physfs.h"
28 | #include "../../Core/SDL2_Includer.h"
29 | #include ICE_INCLUDE_SDL2
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | /**
36 | * Open a platform-independent filename for reading, and make it accessible
37 | * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
38 | * RWops is closed. PhysicsFS should be configured to your liking before
39 | * opening files through this method.
40 | *
41 | * @param filename File to open in platform-independent notation.
42 | * @return A valid SDL_RWops structure on success, NULL on error. Specifics
43 | * of the error can be gleaned from PHYSFS_getLastError().
44 | */
45 | PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
46 |
47 | /**
48 | * Open a platform-independent filename for writing, and make it accessible
49 | * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
50 | * RWops is closed. PhysicsFS should be configured to your liking before
51 | * opening files through this method.
52 | *
53 | * @param filename File to open in platform-independent notation.
54 | * @return A valid SDL_RWops structure on success, NULL on error. Specifics
55 | * of the error can be gleaned from PHYSFS_getLastError().
56 | */
57 | PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
58 |
59 | /**
60 | * Open a platform-independent filename for appending, and make it accessible
61 | * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
62 | * RWops is closed. PhysicsFS should be configured to your liking before
63 | * opening files through this method.
64 | *
65 | * @param filename File to open in platform-independent notation.
66 | * @return A valid SDL_RWops structure on success, NULL on error. Specifics
67 | * of the error can be gleaned from PHYSFS_getLastError().
68 | */
69 | PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
70 |
71 | /**
72 | * Make a SDL_RWops from an existing PhysicsFS file handle. You should
73 | * dispose of any references to the handle after successful creation of
74 | * the RWops. The actual PhysicsFS handle will be destroyed when the
75 | * RWops is closed.
76 | *
77 | * @param handle a valid PhysicsFS file handle.
78 | * @return A valid SDL_RWops structure on success, NULL on error. Specifics
79 | * of the error can be gleaned from PHYSFS_getLastError().
80 | */
81 | PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle);
82 |
83 | #ifdef __cplusplus
84 | }
85 | #endif
86 |
87 | #endif /* include-once blocker */
88 |
89 | /* end of physfsrwops.h ... */
90 |
91 |
--------------------------------------------------------------------------------
/projects/Engine/src/External/rlutil/rlutil.c:
--------------------------------------------------------------------------------
1 | #include "rlutil.h"
2 |
3 | const RLUTIL_STRING_T ANSI_CLS = "\033[2J\033[3J";
4 | const RLUTIL_STRING_T ANSI_CONSOLE_TITLE_PRE = "\033]0;";
5 | const RLUTIL_STRING_T ANSI_CONSOLE_TITLE_POST = "\007";
6 | const RLUTIL_STRING_T ANSI_ATTRIBUTE_RESET = "\033[0m";
7 | const RLUTIL_STRING_T ANSI_CURSOR_HIDE = "\033[?25l";
8 | const RLUTIL_STRING_T ANSI_CURSOR_SHOW = "\033[?25h";
9 | const RLUTIL_STRING_T ANSI_CURSOR_HOME = "\033[H";
10 | const RLUTIL_STRING_T ANSI_BLACK = "\033[22;30m";
11 | const RLUTIL_STRING_T ANSI_RED = "\033[22;31m";
12 | const RLUTIL_STRING_T ANSI_GREEN = "\033[22;32m";
13 | const RLUTIL_STRING_T ANSI_BROWN = "\033[22;33m";
14 | const RLUTIL_STRING_T ANSI_BLUE = "\033[22;34m";
15 | const RLUTIL_STRING_T ANSI_MAGENTA = "\033[22;35m";
16 | const RLUTIL_STRING_T ANSI_CYAN = "\033[22;36m";
17 | const RLUTIL_STRING_T ANSI_GREY = "\033[22;37m";
18 | const RLUTIL_STRING_T ANSI_DARKGREY = "\033[01;30m";
19 | const RLUTIL_STRING_T ANSI_LIGHTRED = "\033[01;31m";
20 | const RLUTIL_STRING_T ANSI_LIGHTGREEN = "\033[01;32m";
21 | const RLUTIL_STRING_T ANSI_YELLOW = "\033[01;33m";
22 | const RLUTIL_STRING_T ANSI_LIGHTBLUE = "\033[01;34m";
23 | const RLUTIL_STRING_T ANSI_LIGHTMAGENTA = "\033[01;35m";
24 | const RLUTIL_STRING_T ANSI_LIGHTCYAN = "\033[01;36m";
25 | const RLUTIL_STRING_T ANSI_WHITE = "\033[01;37m";
26 | const RLUTIL_STRING_T ANSI_BACKGROUND_BLACK = "\033[40m";
27 | const RLUTIL_STRING_T ANSI_BACKGROUND_RED = "\033[41m";
28 | const RLUTIL_STRING_T ANSI_BACKGROUND_GREEN = "\033[42m";
29 | const RLUTIL_STRING_T ANSI_BACKGROUND_YELLOW = "\033[43m";
30 | const RLUTIL_STRING_T ANSI_BACKGROUND_BLUE = "\033[44m";
31 | const RLUTIL_STRING_T ANSI_BACKGROUND_MAGENTA = "\033[45m";
32 | const RLUTIL_STRING_T ANSI_BACKGROUND_CYAN = "\033[46m";
33 | const RLUTIL_STRING_T ANSI_BACKGROUND_WHITE = "\033[47m";
--------------------------------------------------------------------------------
/projects/Engine/src/External/rlutil/rlutil.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/External/rlutil/rlutil.h
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Assert_.c:
--------------------------------------------------------------------------------
1 | #include "Assert_.h"
2 |
3 | #include
4 | #include
5 |
6 | #include "Log.h"
7 | #include "Terminal.h"
8 |
9 | #if defined(_DEBUG)
10 |
11 | void ICE_Assert_(const char* expr_str, int expr, const char* file, int line, const char* msg)
12 | {
13 | if (!expr)
14 | {
15 | ICE_Log_Line();
16 | puts("");
17 | ICE_Log(ICE_LOGTYPE_CRITICAL, "ASSERT");
18 | printf("\n Assert Msg\t:\t");
19 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTGREEN);
20 | printf("%s\n", msg);
21 | ICE_Term_ResetColor();
22 | printf(" Expected\t:\t");
23 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTMAGENTA);
24 | printf("%s\n", expr_str);
25 | ICE_Term_ResetColor();
26 | printf(" Source File\t:\t");
27 | ICE_Term_SetColor(ICE_TERMCOLOR_YELLOW);
28 | printf("%s\n", file);
29 | ICE_Term_ResetColor();
30 | printf(" At the Line\t:\t");
31 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTCYAN);
32 | printf("%d\n\n", line);
33 | ICE_Term_ResetColor();
34 | ICE_Log_Line();
35 | abort();
36 | }
37 | }
38 |
39 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Assert_.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_ASSERT
2 | #define DEF_ICE_ASSERT
3 |
4 | #define ICE_DEBUG_GET_GAME_OBJECT extern ICE_Game game;
5 |
6 | #if defined(_DEBUG)
7 | #define ICE_Assert(Expr, Msg) ICE_Assert_(#Expr, Expr, __FILE__, __LINE__, Msg)
8 | #else
9 | #define ICE_Assert(Expr, Msg) ;
10 | #endif
11 |
12 | #if defined(_DEBUG)
13 | void ICE_Assert_(const char* expr_str, int expr, const char* file, int line, const char* msg);
14 | #endif
15 |
16 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Crossplatform_.c:
--------------------------------------------------------------------------------
1 | #include "Crossplatform_.h"
2 | #include
3 | #include "Memory_.h"
4 | #include
5 |
6 | #ifdef _MSC_VER
7 | #define vscprintf _vscprintf
8 | #endif
9 |
10 | #ifdef __GNUC__
11 | int vscprintf(const char *format, va_list ap)
12 | {
13 | va_list ap_copy;
14 | va_copy(ap_copy, ap);
15 | int retval = vsnprintf(NULL, 0, format, ap_copy);
16 | va_end(ap_copy);
17 | return retval;
18 | }
19 | #endif
20 |
21 | #ifdef _MSC_VER
22 |
23 | int ICE_Crossplat_vasprintf(char **strp, const char *format, va_list ap)
24 | {
25 | int len = vscprintf(format, ap);
26 | if (len == -1)
27 | return -1;
28 | char *str = (char*)ICE_Malloc((size_t) len + 1);
29 | if (!str)
30 | return -1;
31 | int retval = vsnprintf(str, len + 1, format, ap);
32 | if (retval == -1) {
33 | ICE_Free(str);
34 | return -1;
35 | }
36 | *strp = str;
37 | return retval;
38 | }
39 |
40 | int ICE_Crossplat_asprintf(char **strp, const char *format, ...)
41 | {
42 | va_list ap;
43 | va_start(ap, format);
44 | int retval = ICE_Crossplat_vasprintf(strp, format, ap);
45 | va_end(ap);
46 | return retval;
47 | }
48 |
49 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Crossplatform_.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_CROSSPLATFORM_H
2 | #define DEF_ICE_CROSSPLATFORM_H
3 |
4 | #include
5 |
6 | #ifdef _MSC_VER
7 | int ICE_Crossplat_vasprintf(char **strp, const char *format, va_list ap);
8 | int ICE_Crossplat_asprintf(char **strp, const char *format, ...);
9 | #elif
10 | #define ICE_Crossplat_vasprintf vasprintf
11 | #define ICE_Crossplat_asprintf asrpintf
12 | #endif
13 |
14 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/File_.c:
--------------------------------------------------------------------------------
1 | #include "File_.h"
2 |
3 | /// Move cursor to the next character
4 | void ICE_File_ToNextCharacter(FILE* fichier, ICE_Char character)
5 | {
6 | int charactuel;
7 | do {
8 | charactuel = fgetc(fichier);
9 | } while (charactuel != character);
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/File_.h:
--------------------------------------------------------------------------------
1 | #ifndef ICE_DEF_FILE_
2 | #define ICE_DEF_FILE_
3 |
4 | #include "String_.h"
5 | #include
6 |
7 | void ICE_File_ToNextCharacter(FILE* fichier, ICE_Char character);
8 |
9 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Inline.h:
--------------------------------------------------------------------------------
1 | #ifndef ICE_GUARD_INLINE
2 | #define ICE_GUARD_INLINE
3 |
4 | #if defined(__APPLE__)
5 | #define ICE_INLINE static inline
6 | #elif defined(_MSC_VER)
7 | #define ICE_INLINE __forceinline
8 | #else
9 | #define ICE_INLINE inline
10 | #endif
11 |
12 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Log.c:
--------------------------------------------------------------------------------
1 | #include "Log.h"
2 |
3 | #if defined(_DEBUG)
4 |
5 | #include "Terminal.h"
6 | #include "TypesFramework.h"
7 | #include "../External/rlutil/rlutil.h"
8 |
9 | #include
10 | #include
11 |
12 | void ICE_Log_Line()
13 | {
14 | int nb = tcols();
15 | for(int i = 0; i < nb-1; i++)
16 | putchar('_');
17 | printf("\n");
18 | }
19 |
20 | void ICE_Log_printf(const char* format, ...)
21 | {
22 | va_list args;
23 | va_start(args, format);
24 | vprintf(format, args);
25 | va_end(args);
26 | }
27 |
28 | void ICE_Log_(int nb_tab, const char* file, int line, ICE_LogTypes type, const char * format, ...)
29 | {
30 | va_list args;
31 | va_start(args, format);
32 |
33 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
34 |
35 | char * type_in_string;
36 | switch (type)
37 | {
38 | case ICE_LOGTYPE_INFO:
39 | ICE_Term_SetColor(ICE_TERMCOLOR_GREY);
40 | type_in_string = "";
41 | break;
42 | case ICE_LOGTYPE_SUCCES:
43 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTGREEN);
44 | type_in_string = "";
45 | break;
46 | case ICE_LOGTYPE_WARNING:
47 | ICE_Term_SetColor(ICE_TERMCOLOR_YELLOW);
48 | type_in_string = "";
49 | break;
50 | case ICE_LOGTYPE_ERROR:
51 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTRED);
52 | type_in_string = "";
53 | break;
54 | case ICE_LOGTYPE_CRITICAL:
55 | ICE_Term_SetColor(ICE_TERMCOLOR_RED);
56 | type_in_string = "";
57 | break;
58 | case ICE_LOGTYPE_RUNNING:
59 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTMAGENTA);
60 | type_in_string = "";
61 | break;
62 | case ICE_LOGTYPE_FINISH:
63 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTBLUE);
64 | type_in_string = "";
65 | break;
66 | default:
67 | ICE_Term_ResetColor();
68 | type_in_string = "";
69 | break;
70 | }
71 | printf(" %s ", type_in_string);
72 | ICE_Term_ResetColor();
73 |
74 | vprintf(format, args);
75 | printf("\n");
76 | ICE_Term_ResetColor();
77 |
78 | va_end(args);
79 | }
80 |
81 | void ICE_Log_NoReturn_(const char* file, int line, ICE_LogTypes type, const char * format, ...)
82 | {
83 | va_list args;
84 | va_start(args, format);
85 |
86 | switch (type)
87 | {
88 | case ICE_LOGTYPE_SUCCES:
89 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
90 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTGREEN);
91 | printf("[SUCCES]");
92 | break;
93 | case ICE_LOGTYPE_INFO:
94 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
95 | printf("[LOG]");
96 | break;
97 | case ICE_LOGTYPE_WARNING:
98 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
99 | ICE_Term_SetColor(ICE_TERMCOLOR_YELLOW);
100 | printf("[WARNING]");
101 | break;
102 | case ICE_LOGTYPE_ERROR:
103 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
104 | ICE_Term_SetColor(ICE_TERMCOLOR_LIGHTRED);
105 |
106 | printf("[ERROR]");
107 | break;
108 | case ICE_LOGTYPE_CRITICAL:
109 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
110 | ICE_Term_SetColor(ICE_TERMCOLOR_RED);
111 | printf("[CRITICAL]");
112 | break;
113 | default:
114 | ICE_Term_Clock(ICE_TERMCOLOR_LIGHTCYAN);
115 | printf("[NOLOGTYPE]");
116 | break;
117 | }
118 | ICE_Term_ResetColor();
119 | printf("::[");
120 | vprintf(format, args);
121 | printf("]");
122 | va_end(args);
123 | }
124 |
125 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Log.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_LOG
2 | #define DEF_ICE_LOG
3 | #include "Macrotools.h"
4 |
5 | /**
6 | * \brief Different log types and how they are showed
7 | */
8 | enum ICE_LogTypes
9 | {
10 | ICE_LOGTYPE_CRITICAL = -3,
11 | ICE_LOGTYPE_ERROR = -2,
12 | ICE_LOGTYPE_WARNING = -1,
13 |
14 | ICE_LOGTYPE_INFO = 0,
15 |
16 | ICE_LOGTYPE_SUCCES = 1,
17 | ICE_LOGTYPE_RUNNING = 2,
18 | ICE_LOGTYPE_FINISH = 3
19 |
20 | }; typedef enum ICE_LogTypes ICE_LogTypes;
21 |
22 | #if defined(_DEBUG)
23 | /// Use in log or other va_args thing : ICE_Log("Is that true ? : %s", ICE_LOG_TRUEFALSE(myBool))
24 | #define ICE_LOG_TRUEFALSE(X) X?ICE_MACROTOOLS_STRINGIZE(True):ICE_MACROTOOLS_STRINGIZE(False)
25 |
26 | #define ICE_Log_Error(FORMAT, ...) ICE_Log(ICE_LOGTYPE_ERROR, FORMAT, __VA_ARGS__ )
27 | #define ICE_Log_Critical(FORMAT, ...) ICE_Log(ICE_LOGTYPE_CRITICAL, FORMAT, __VA_ARGS__ )
28 | #define ICE_Log_Warning(FORMAT, ...) ICE_Log(ICE_LOGTYPE_WARNING, FORMAT, __VA_ARGS__ )
29 | #define ICE_Log_Info(FORMAT, ...) ICE_Log(ICE_LOGTYPE_INFO, FORMAT, __VA_ARGS__)
30 | #define ICE_Log_Succes(FORMAT, ...) ICE_Log(ICE_LOGTYPE_SUCCES, FORMAT, __VA_ARGS__)
31 | #define ICE_Log_Running(FORMAT, ...) ICE_Log(ICE_LOGTYPE_RUNNING, FORMAT, __VA_ARGS__)
32 | #define ICE_Log_Finish(FORMAT, ...) ICE_Log(ICE_LOGTYPE_FINISH, FORMAT, __VA_ARGS__)
33 | #define ICE_Log(TYPE, FORMAT, ...) ICE_Log_(0, __FILE__, __LINE__, TYPE, FORMAT, __VA_ARGS__)
34 | void ICE_Log_(int nb_tab, const char* file, int line, ICE_LogTypes type, const char * format, ...);
35 |
36 | #define ICE_Log_NoReturn(TYPE, FORMAT, ...) ICE_Log_NoReturn_(__FILE__, __LINE__, TYPE, FORMAT, __VA_ARGS__)
37 | void ICE_Log_NoReturn_(const char* file, int line, ICE_LogTypes type, const char * format, ...);
38 |
39 | void ICE_Log_Line();
40 |
41 |
42 | void ICE_Log_printf(const char * format, ...);
43 | #else
44 | #define ICE_Log_Error(FORMAT, ...)
45 | #define ICE_Log_Critical(FORMAT, ...)
46 | #define ICE_Log_Warning(FORMAT, ...)
47 | #define ICE_Log_Info(FORMAT, ...)
48 | #define ICE_Log_Succes(FORMAT, ...)
49 | #define ICE_Log_Running(FORMAT, ...)
50 | #define ICE_Log_Finish(FORMAT, ...)
51 | #define ICE_Log(...)
52 | #define ICE_Log_NoReturn(...)
53 | #define ICE_Log_Line()
54 | #define ICE_Log_printf(...)
55 | #endif
56 |
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Macrotools.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_MACROTOOLS_H
2 | #define DEF_ICE_MACROTOOLS_H
3 |
4 | #define ICE_MACROTOOLS_STRINGIZE2(s) #s
5 | #define ICE_MACROTOOLS_STRINGIZE(s) ICE_MACROTOOLS_STRINGIZE2(s)
6 | #define ICE_MACROTOOLS_CONCATENATE(A, B) A##B
7 |
8 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Memory_.c:
--------------------------------------------------------------------------------
1 | #include "Memory_.h"
2 |
3 | #include
4 | #include "Log.h"
5 | #include "Assert_.h"
6 | #include "../Core/Debug.h"
7 |
8 | ICE_DEBUG_ONLY size_t _thing_to_free_ = 0;
9 |
10 | void* ICE_Malloc(size_t _Size)
11 | {
12 | void* ptr = malloc(_Size);
13 | if (ptr == NULL)
14 | {
15 | ICE_Log(ICE_LOGTYPE_CRITICAL, "Memory]::[Malloc]::[Failed");
16 | ICE_Assert(ptr != NULL, "(Malloc) Failed to allocate memory");
17 | }
18 |
19 | ICE_DEBUG_ONLY _thing_to_free_++;
20 |
21 | return ptr;
22 | }
23 |
24 | void* ICE_Calloc(size_t _Nb_Elem, size_t _Size)
25 | {
26 | void* ptr = calloc(_Nb_Elem, _Size);
27 | if (ptr == NULL)
28 | {
29 | ICE_Log(ICE_LOGTYPE_CRITICAL, "Memory]::[Calloc]::[Failed");
30 | ICE_Assert(ptr != NULL, "(Calloc) Failed to allocate memory");
31 | }
32 | #if defined(_DEBUG)
33 | _thing_to_free_++;
34 | #endif
35 | return ptr;
36 | }
37 |
38 | void* ICE_Realloc(void* _Block, size_t _Size)
39 | {
40 | void* ptr = realloc(_Block, _Size);
41 | if (ptr == NULL)
42 | {
43 | ICE_Log(ICE_LOGTYPE_CRITICAL, "Memory]::[Realloc]::[Failed");
44 | ICE_Assert(ptr != NULL, "(Realloc) Failed to reallocate memory");
45 | }
46 | return ptr;
47 | }
48 |
49 | void ICE_Free(void* _Block)
50 | {
51 | free(_Block);
52 | ICE_DEBUG_ONLY _thing_to_free_--;
53 | }
54 |
55 | #if defined(_DEBUG)
56 | size_t ICE_Memory_NbFreeToDo()
57 | {
58 | if(_thing_to_free_ > 0)
59 | {
60 | ICE_Log(ICE_LOGTYPE_ERROR, "There is %d heap(s) to free", _thing_to_free_);
61 | }
62 | else
63 | {
64 | ICE_Log(ICE_LOGTYPE_SUCCES, "No heaps to free");
65 | }
66 | return _thing_to_free_;
67 | }
68 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Memory_.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_MEMORY
2 | #define DEF_ICE_MEMORY
3 |
4 | #include
5 |
6 | void* ICE_Malloc(size_t _Size);
7 | void* ICE_Calloc(size_t _Nb_Elem, size_t _Size);
8 | void* ICE_Realloc(void* _Block, size_t _Size);
9 | void ICE_Free(void* _Block);
10 | #if defined(_DEBUG)
11 | size_t ICE_Memory_NbFreeToDo();
12 | #else
13 | #define ICE_Memory_NbFreeToDo()
14 | #endif
15 |
16 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Random.c:
--------------------------------------------------------------------------------
1 | #include "Random.h"
2 |
3 | #include
4 | #include
5 |
6 | #include "TypesFramework.h"
7 | #include "Log.h"
8 |
9 | #if defined(__linux__) || defined(_POSIX_VERSION)
10 | #include
11 | #define GET_PID_ getpid
12 | #elif defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
13 | #include
14 | #define GETPID_ _getpid
15 | #endif
16 |
17 | unsigned long mix(unsigned long a, unsigned long b, unsigned long c)
18 | {
19 | a=a-b; a=a-c; a=a^(c >> 13);
20 | b=b-c; b=b-a; b=b^(a << 8);
21 | c=c-a; c=c-b; c=c^(b >> 13);
22 | a=a-b; a=a-c; a=a^(c >> 12);
23 | b=b-c; b=b-a; b=b^(a << 16);
24 | c=c-a; c=c-b; c=c^(b >> 5);
25 | a=a-b; a=a-c; a=a^(c >> 3);
26 | b=b-c; b=b-a; b=b^(a << 10);
27 | c=c-a; c=c-b; c=c^(b >> 15);
28 | return c;
29 | }
30 |
31 | void ICE_Random_Init()
32 | {
33 | static ICE_Bool triggered = ICE_False;
34 | if (!triggered)
35 | {
36 | const unsigned int seed = mix(clock(), time(NULL), GETPID_());
37 | srand(seed);
38 | ICE_Log(ICE_LOGTYPE_SUCCES, "Init ICE_Random");
39 | triggered = ICE_True;
40 | }
41 | }
42 |
43 | int ICE_Random_Int(int min, int max)
44 | {
45 | int lowest, highest;
46 | if (min < max)
47 | {
48 | lowest = min;
49 | highest = max + 1;
50 | }
51 | else {
52 | lowest = max + 1;
53 | highest = min;
54 | }
55 | return (rand() % (highest - lowest)) + lowest;
56 | }
57 |
58 | // Return a random float between 0 and 1;
59 | ICE_Float ICE_Random_Float()
60 | {
61 | return (ICE_Float)rand() / (ICE_Float)RAND_MAX;
62 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Random.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_RANDOM
2 | #define DEF_ICE_RANDOM
3 |
4 | #include "TypesFramework.h"
5 |
6 | /**
7 | * \brief Init the random system
8 | */
9 | void ICE_Random_Init();
10 |
11 | /**
12 | * \brief Get a random int between min and max value
13 | * \param min Minimal random value
14 | * \param max Maximal random value
15 | * \return Random Int
16 | */
17 | int ICE_Random_Int(int min, int max);
18 |
19 | /**
20 | * \brief Get a random float between 0 and 1
21 | * \return
22 | */
23 | ICE_Float ICE_Random_Float();
24 |
25 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Terminal.c:
--------------------------------------------------------------------------------
1 | #include "Terminal.h"
2 |
3 | #include "../External/rlutil/rlutil.h"
4 |
5 | #include "TypesFramework.h"
6 | #include "Log.h"
7 | #include
8 |
9 | #if defined(_DEBUG)
10 |
11 | void ICE_Term_ResetColor(){
12 | resetColor();
13 | }
14 | void ICE_Term_SetColor(const int c){
15 | setColor(c);
16 | }
17 | void ICE_Term_SetBgColor(const int c){
18 | setBackgroundColor(c);
19 | }
20 |
21 | void ICE_Term_Clear(){
22 | cls();
23 | }
24 |
25 | void ICE_Term_Clock(int color){
26 | ICE_Term_SetColor(color);
27 | printf("%08.3fs", (ICE_Float)clock()/1000.0f);
28 | ICE_Term_ResetColor();
29 | printf("");
30 | }
31 |
32 | void ICE_Term_Hour()
33 | {
34 | ICE_Term_SetColor(ICE_TERMCOLOR_CYAN);
35 | time_t t = time(NULL);
36 | struct tm tm = *localtime(&t);
37 | printf("%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
38 | }
39 |
40 | void ICE_Term_Wait(){
41 | ICE_Log_NoReturn(ICE_LOGTYPE_INFO, "TERMINAL]::[PRESSRETURNTOCONTINUE");
42 | #ifdef getch
43 | getch();
44 | puts("");
45 | #else
46 | getchar();
47 | #endif
48 | }
49 |
50 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Terminal.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TERMINALCOLOR
2 | #define DEF_ICE_TERMINALCOLOR
3 |
4 | /**
5 | * \brief Color usable in the terminal with ICE_Term_ function
6 | */
7 | enum ICE_TermColor {
8 | ICE_TERMCOLOR_BLACK,
9 | ICE_TERMCOLOR_BLUE,
10 | ICE_TERMCOLOR_GREEN,
11 | ICE_TERMCOLOR_CYAN,
12 | ICE_TERMCOLOR_RED,
13 | ICE_TERMCOLOR_MAGENTA,
14 | ICE_TERMCOLOR_BROWN,
15 | ICE_TERMCOLOR_GREY,
16 | ICE_TERMCOLOR_DARKGREY,
17 | ICE_TERMCOLOR_LIGHTBLUE,
18 | ICE_TERMCOLOR_LIGHTGREEN,
19 | ICE_TERMCOLOR_LIGHTCYAN,
20 | ICE_TERMCOLOR_LIGHTRED,
21 | ICE_TERMCOLOR_LIGHTMAGENTA,
22 | ICE_TERMCOLOR_YELLOW,
23 | ICE_TERMCOLOR_WHITE
24 | };
25 |
26 | #if defined(_DEBUG)
27 | /**
28 | * \brief Reset color to default terminal color
29 | */
30 | void ICE_Term_ResetColor();
31 |
32 | /**
33 | * \brief Set color of text in terminal
34 | * \param c Color to set
35 | */
36 | void ICE_Term_SetColor(const int c);
37 |
38 | /**
39 | * \brief Set background color of text in terminal
40 | * \param c Color to set
41 | */
42 | void ICE_Term_SetBgColor(const int c);
43 |
44 | /**
45 | * \brief Clear everything in terminal
46 | */
47 | void ICE_Term_Clear();
48 |
49 | /**
50 | * \brief Draw time since game start on terminal without line return
51 | */
52 | void ICE_Term_Clock(int color);
53 |
54 | void ICE_Term_Hour();
55 |
56 | /**
57 | * \brief Wait a key to continue with message
58 | */
59 | void ICE_Term_Wait();
60 | #else
61 | #define ICE_Term_ResetColor()
62 | #define ICE_Term_SetColor(INT)
63 | #define ICE_Term_SetBgColor(INT)
64 | #define ICE_Term_Clear()
65 | #define ICE_Term_Clock()
66 | #define ICE_Term_Wait()
67 | #endif
68 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Terminal_private.c:
--------------------------------------------------------------------------------
1 | #include "Terminal_private.h"
2 |
3 | #if defined(_DEBUG)
4 |
5 | #include "../External/rlutil/rlutil.h"
6 |
7 | void ICE_Term_SaveColor()
8 | {
9 | saveDefaultColor();
10 | }
11 |
12 | void ICE_Term_HideCursor()
13 | {
14 | hidecursor();
15 | }
16 |
17 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/Terminal_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TERMINAL_PRIVATE
2 | #define DEF_ICE_TERMINAL_PRIVATE
3 |
4 | #if defined(_DEBUG)
5 |
6 | /**
7 | * \brief Save default terminal color
8 | */
9 | void ICE_Term_SaveColor();
10 |
11 | /**
12 | * \brief Hide cursor
13 | */
14 | void ICE_Term_HideCursor();
15 |
16 | #else
17 | #define ICE_Term_SaveColor()
18 | #define ICE_Term_HideCursor()
19 | #endif
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/TypesFramework.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TYPESFRAMEWORK
2 | #define DEF_ICE_TYPESFRAMEWORK
3 |
4 | #include
5 | #include
6 |
7 | #ifndef ICE_BOOL_DEFINED
8 | #define ICE_BOOL_DEFINED
9 |
10 | typedef _Bool ICE_Bool;
11 | #define ICE_True 1
12 | #define ICE_TRUE 1
13 | #define ICE_true 1
14 | #define ICE_False 0
15 | #define ICE_FALSE 0
16 | #define ICE_false 0
17 | #define ICE_BOOL_BITFIELD(S) ICE_Bool S : 1
18 | #endif
19 |
20 | #ifndef ICE_FLOAT_DEFINED
21 | #define ICE_FLOAT_DEFINED
22 | typedef double ICE_Float;
23 | #endif
24 |
25 | #ifndef ICE_INDEX_DEFINED
26 | #define ICE_INDEX_DEFINED
27 | typedef size_t ICE_ID;
28 | typedef size_t ICE_Index;
29 | #endif
30 |
31 | #ifndef ICE_SIZED_INT_DEFINED
32 | #define ICE_SIZED_INT_DEFINED
33 | typedef int8_t ICE_Int8;
34 | typedef int16_t ICE_Int16;
35 | typedef int32_t ICE_Int32;
36 | typedef int64_t ICE_Int64;
37 |
38 | typedef uint8_t ICE_Uint8;
39 | typedef uint16_t ICE_Uint16;
40 | typedef uint32_t ICE_Uint32;
41 | typedef uint64_t ICE_Uint64;
42 | #endif
43 |
44 | #endif
45 |
46 |
47 |
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/UnitTest.c:
--------------------------------------------------------------------------------
1 | #include "UnitTest.h"
2 |
3 |
--------------------------------------------------------------------------------
/projects/Engine/src/Framework/UnitTest.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_UNITTEST_H
2 | #define DEF_ICE_UNITTEST_H
3 |
4 | #include "Terminal_private.h"
5 | #include "Macrotools.h"
6 |
7 | #define ICE_UT_EQUAL(X, Z) if(X != Z)\
8 | { ICE_Log_Error("Error at line %d in file %s", __LINE__, __FILE__); ICE_Log_printf(ICE_MACROTOOLS_STRINGIZE(X## != ##Z##\n)); global_status_ut = ICE_True; global_number_error_happened++;}\
9 |
10 | #define ICE_UT_COMPARE(X, Y, Z) if(!(X Y Z))\
11 | { ICE_Log_Error("Error at line %d in file %s", __LINE__, __FILE__); ICE_Log_printf(ICE_MACROTOOLS_STRINGIZE(X##Y##Z##\n)); global_status_ut = ICE_True; global_number_error_happened++;}\
12 |
13 | #define ICE_UT_MAIN() global_status_ut = ICE_False;\
14 | int global_number_error_happened = 0;\
15 | int ICE_UT_MAIN___(int argc, char ** argv);\
16 | int main(int argc, char ** argv)\
17 | {\
18 | ICE_Term_SaveColor();\
19 | ICE_Log_Line();\
20 | ICE_UT_MAIN___(argc, argv);\
21 | ICE_Log_printf("\n");\
22 | if(ICE_Memory_NbFreeToDo() != 0)\
23 | {global_status_ut = ICE_True; global_number_error_happened++;}\
24 | if(!global_status_ut)\
25 | {ICE_Log_Succes("No error happened");}\
26 | else\
27 | ICE_Log_Error("There are %d error in that UT", global_number_error_happened);\
28 | ICE_Log_Line();\
29 | ICE_Log_printf("\n");\
30 | return global_number_error_happened;\
31 | }\
32 | int ICE_UT_MAIN___(int argc, char ** argv)
33 |
34 |
35 | #define ICE_UT_LOOP_STEP STEP
36 | #define ICE_UT_LOOP(X) for(int ICE_UT_LOOP_STEP = 0; ICE_UT_LOOP_STEP < X; ICE_UT_LOOP_STEP++)\
37 |
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Animation.c:
--------------------------------------------------------------------------------
1 | #include "Animation.h"
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Animation.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_ANIMATION
2 | #define DEF_ICE_ANIMATION
3 |
4 |
5 |
6 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Camera.c:
--------------------------------------------------------------------------------
1 | #include "Camera.h"
2 | #include "../Core/TypesCore.h"
3 | #include "../Maths/Vector.h"
4 |
5 |
6 | extern ICE_Game GAME;
7 | extern ICE_Core CORE;
8 |
9 | // Camera edit
10 | // ----------------------------------------------------
11 |
12 | void ICE_Camera_SetPos(ICE_Vect vect)
13 | {
14 |
15 | GAME.current->object.camera.x = vect.x;
16 | GAME.current->object.camera.y = vect.y;
17 | }
18 |
19 | void ICE_Camera_MovePos(ICE_Vect vect, ICE_Float r)
20 | {
21 | const ICE_Float xdif = vect.x - GAME.current->object.camera.x;
22 | const ICE_Float ydif = vect.y - GAME.current->object.camera.y;
23 |
24 | const ICE_Float angle = atan2(ydif, xdif);
25 | const ICE_Float distance_r_r = xdif * xdif + ydif * ydif;
26 |
27 | GAME.current->object.camera.x += r * cos(angle);
28 | GAME.current->object.camera.y += r * sin(angle);
29 |
30 | if (distance_r_r < r)
31 | {
32 | GAME.current->object.camera.x = vect.x;
33 | GAME.current->object.camera.y = vect.y;
34 | }
35 | }
36 |
37 | void ICE_Camera_ShiftPos(ICE_Vect delta_)
38 | {
39 | GAME.current->object.camera.x += delta_.x;
40 | GAME.current->object.camera.y += delta_.y;
41 | }
42 |
43 | // Camera return
44 | // ----------------------------------------------------
45 |
46 | ICE_Vect ICE_Camera_GetPos(ICE_State* state_)
47 | {
48 | if (state_ == NULL)
49 | state_ = GAME.current;
50 |
51 | return ICE_Vect_New(state_->object.camera.x, state_->object.camera.y);
52 | }
53 |
54 | // Converter
55 | // ----------------------------------
56 |
57 | ICE_Box ICE_Camera_WorldScreen(ICE_Box rect)
58 | {
59 | ICE_Box rect2 = {
60 | (CORE.window.w / 2) + rect.x - GAME.current->object.camera.x,
61 | (CORE.window.h / 2) + rect.y - GAME.current->object.camera.y,
62 | rect.w,
63 | rect.h
64 | };
65 | return rect2;
66 | }
67 |
68 | ICE_Box ICE_Camera_ScreenWorld(ICE_Box rect)
69 | {
70 | ICE_Box rect2 = {
71 | -CORE.window.w / 2 + GAME.current->object.camera.x + rect.x,
72 | -CORE.window.h / 2 + GAME.current->object.camera.y + rect.y,
73 | rect.w,
74 | rect.h
75 | };
76 | return rect2;
77 | }
78 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Camera.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE__CAMERA
2 | #define DEF_ICE__CAMERA
3 |
4 | #include "../Maths/TypesMaths.h"
5 | #include "../Core/TypesCore.h"
6 |
7 | /**
8 | * \brief Set Camera position to a Vector
9 | * \param vect New Camera position
10 | */
11 | void ICE_Camera_SetPos(ICE_Vect vect);
12 |
13 | /**
14 | * \brief Move Camera to a coordinate and move it by a value R
15 | * \param vect Coordinate where Camera go
16 | * \param r Value/Distance to move the camera
17 | */
18 | void ICE_Camera_MovePos(ICE_Vect vect, ICE_Float r);
19 |
20 | /**
21 | * \brief Shift Camera position by a vector
22 | * \param Dvect Vector to add
23 | */
24 | void ICE_Camera_ShiftPos(ICE_Vect Dvect);
25 |
26 |
27 | /**
28 | * \brief Convert a ICE_Box in World Coordinate to Screen Coordinate
29 | * \param rect Box in World Coordinate to convert
30 | * \return Box in Screen Coordinate
31 | */
32 | ICE_Box ICE_Camera_WorldScreen(ICE_Box rect);
33 |
34 | /**
35 | * \brief Convert a ICE_Box in Screen Coordinate to World Coordinate
36 | * \param rect Box in Screen Coordinate to convert
37 | * \return Box in World Coordinate
38 | */
39 | ICE_Box ICE_Camera_ScreenWorld(ICE_Box rect);
40 |
41 | /**
42 | * \brief Return a Vector with Camera Coordinate
43 | * \return
44 | */
45 | ICE_Vect ICE_Camera_GetPos(ICE_State* state_);
46 |
47 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Color.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_COLOR
2 | #define DEF_ICE_COLOR
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Framework/Inline.h"
6 |
7 | #define ICE_Color_Red ICE_Color_New(255,0,0)
8 | #define ICE_Color_Blue ICE_Color_New(0,0,255)
9 | #define ICE_Color_Green ICE_Color_New(0,255,0)
10 | #define ICE_Color_Black ICE_Color_New(0,0,0)
11 | #define ICE_Color_White ICE_Color_New(255,255,255)
12 | #define ICE_Color_Grey ICE_Color_New(127,127,127)
13 |
14 | /**
15 | * \brief Create a new Color
16 | * \param r The red value
17 | * \param g The green value
18 | * \param b The blue value
19 | * \return The new created Color
20 | */
21 | ICE_INLINE ICE_Color ICE_Color_New(const ICE_Uint8 r, const ICE_Uint8 g, const ICE_Uint8 b)
22 | {
23 | return (ICE_Color)(r << 24) + (g << 16) + (b << 8) + 255;
24 | }
25 |
26 | /**
27 | * \brief Create a new Color
28 | * \param r The red value
29 | * \param g The green value
30 | * \param b The blue value
31 | * \param a the alpha value
32 | * \return The new created Color
33 | */
34 | ICE_INLINE ICE_Color ICE_Color_New_Rgba(const ICE_Uint8 r, const ICE_Uint8 g, const ICE_Uint8 b,
35 | const ICE_Uint8 a)
36 | {
37 | return (ICE_Color)((r << 24) + (g << 16) + (b << 8) + a);
38 | }
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Color_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_COLOR_PRIVATE
2 | #define DEF_ICE_COLOR_PRIVATE
3 |
4 | #include ICE_INCLUDE_SDL2
5 |
6 | #include "TypesGraphics.h"
7 | #include "../Framework/Inline.h"
8 |
9 | /**
10 | * \brief Convert a ICE_Color to a SDL one
11 | * \param ice_color The ICE_Color to convert
12 | * \return A SDL_Color converted from a ICE one
13 | */
14 | ICE_INLINE SDL_Color ICE_Color_ToSdl(const ICE_Color ice_color) {
15 | SDL_Color sdl_color;
16 | sdl_color.r = ice_color >> 24 & 255;
17 | sdl_color.g = ice_color >> 16 & 255;
18 | sdl_color.b = ice_color >> 8 & 255;
19 | sdl_color.a = ice_color & 255;
20 | return sdl_color;
21 | }
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Draw.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_DRAW
2 | #define DEF_ICE_DRAW
3 |
4 | void ICE_Draw_LabelWorld();
5 | void ICE_Draw_LabelScreen();
6 | void ICE_Draw_AllGui();
7 | void ICE_Draw_AllEntity();
8 |
9 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Font.c:
--------------------------------------------------------------------------------
1 | #include "Font.h"
2 |
3 | #include "../Core/SDL2_Includer.h"
4 | #include ICE_INCLUDE_SDL2_TTF
5 |
6 | #include "TypesGraphics.h"
7 | #include "Color_private.h"
8 |
9 | #include "../Core/Window.h"
10 | #include "../Framework/Log.h"
11 | #include "../Maths/TypesMaths.h"
12 |
13 | extern ICE_Game GAME;
14 | extern ICE_Core CORE;
15 | extern ICE_Asset ASSET;
16 |
17 | ICE_FontID ICE_Font_Load(char *path)
18 | {
19 | for (int i = 0; i < 256; i++) {
20 | ASSET.font.size[i] = TTF_OpenFont(path, i);
21 | if (!ASSET.font.size[i])
22 | ICE_Log(ICE_LOGTYPE_CRITICAL, "%s\n", TTF_GetError());
23 | }
24 |
25 | return 0;
26 | }
27 |
28 | #if defined(_DEBUG)
29 | void ICE_Font_Draw(char* text, ICE_Vect vect, ICE_Color fg, ICE_Color bg)
30 | {
31 | int size = (int)((ICE_Float)ICE_Window_GetH() / 50.0);
32 | if (size < 12)
33 | size = 12;
34 | SDL_Surface *surf = TTF_RenderText_Shaded(ASSET.font.size[size], text, ICE_Color_ToSdl(fg), ICE_Color_ToSdl(bg));
35 | SDL_Rect rect; rect.x = (int)vect.x; rect.y = (int)vect.y;
36 | rect.w = surf->w; rect.h = surf->h;
37 | SDL_Texture *texture = SDL_CreateTextureFromSurface(CORE.window.render, surf);
38 | SDL_RenderCopy(CORE.window.render, texture, NULL, &rect);
39 | SDL_FreeSurface(surf);
40 | SDL_DestroyTexture(texture);
41 | }
42 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Font.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_FONT
2 | #define DEF_ICE_FONT
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Maths/TypesMaths.h"
6 |
7 | /**
8 | * \brief Load the font
9 | * \param path Path to the font file
10 | */
11 | ICE_FontID ICE_Font_Load(char *path);
12 |
13 |
14 | #if defined(_DEBUG)
15 | /**
16 | * \brief Unoptimized font drawing
17 | * \param text Text to draw
18 | * \param vect Position of the text
19 | * \param fg Color of the text
20 | * \param bg Color of the background
21 | */
22 | void ICE_Font_Draw(char* text, ICE_Vect vect, ICE_Color fg, ICE_Color bg);
23 | #else
24 | #define ICE_Font_Draw(...)
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Gui.c:
--------------------------------------------------------------------------------
1 | #include "Gui.h"
2 |
3 | #include "Gui_private.h"
4 |
5 | #include "../Maths/TypesMaths.h"
6 | #include "Texture_private.h"
7 | #include "../Core/TypesCore.h"
8 | #include "../Framework/Memory_.h"
9 | #include "../Framework/Log.h"
10 | #include "Texture.h"
11 |
12 | extern ICE_Game GAME;
13 |
14 | /* GUI */
15 |
16 | ICE_ID ICE_Gui_Create(ICE_State * state_, const ICE_Box box_, ICE_GuiType types_)
17 | {
18 | if (!state_)
19 | state_ = GAME.current;
20 |
21 | // Insert label in array
22 | state_->object.gui_mngr.gui[state_->object.gui_mngr.gui_contain] = ICE_Gui_Build(box_, types_);
23 | state_->object.gui_mngr.gui_contain++;
24 |
25 | ICE_Log(ICE_LOGTYPE_SUCCES, "Create Gui %d ", state_->object.gui_mngr.gui_contain-1);
26 |
27 | // Test size to realloc more space
28 | if (state_->object.gui_mngr.gui_size <= state_->object.gui_mngr.gui_contain)
29 | {
30 | ICE_Gui* tmp = ICE_Realloc(state_->object.gui_mngr.gui, sizeof(ICE_Gui)*(state_->object.gui_mngr.gui_size * 2));
31 | state_->object.gui_mngr.gui = tmp;
32 | state_->object.gui_mngr.gui_size *= 2;
33 | }
34 |
35 | ICE_Gui_UpdateTexture(state_, state_->object.gui_mngr.gui_contain - 1);
36 | return state_->object.gui_mngr.gui_contain - 1;
37 | }
38 |
39 | void ICE_Gui_Clear(ICE_Gui * label_)
40 | {
41 | ICE_Texture temp = label_->texture_cache;
42 | memset(label_, 0, sizeof(ICE_Gui));
43 | label_->texture_cache = temp;
44 | }
45 | void ICE_Gui_Destroy(ICE_Gui * ptr)
46 | {
47 | ICE_Texture_Free(&ptr->texture_cache);
48 | }
49 |
50 | /* GUI GET */
51 |
52 | ICE_Gui * ICE_Gui_Get(ICE_State *state, ICE_GuiID gui)
53 | {
54 | if (!state)
55 | state = GAME.current;
56 |
57 | return &state->object.gui_mngr.gui[gui];
58 | }
59 |
60 | ICE_Box ICE_Gui_GetBox(ICE_Gui * gui)
61 | {
62 | return gui->box;
63 | }
64 |
65 | /* GUI SET */
66 |
67 | void ICE_Gui_SetTexture(ICE_Gui * gui_ptr_, int texture_id_)
68 | {
69 | gui_ptr_->texture_index = texture_id_;
70 | gui_ptr_->have_texture_defined = ICE_True;
71 | }
72 |
73 | void ICE_Gui_SetBox(ICE_Gui * gui, ICE_Box box)
74 | {
75 | gui->box = box;
76 | }
77 |
78 | void ICE_Gui_SetPos(ICE_Gui * gui, ICE_Vect pos)
79 | {
80 | gui->box.x = pos.x;
81 | gui->box.y = pos.y;
82 | }
83 |
84 | void ICE_Gui_SetSize(ICE_Gui * gui, ICE_Vect vect)
85 | {
86 | gui->box.w = vect.x;
87 | gui->box.h = vect.y;
88 | }
89 |
90 | void ICE_Gui_SetType(ICE_Gui * gui, ICE_GuiType type)
91 | {
92 | gui->type = type;
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Gui.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_GUI
2 | #define DEF_ICE_GUI
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Maths/TypesMaths.h"
6 | #include "../Core/State.h"
7 |
8 | #define ICE_DEFAULT_GUI_MNGR_SIZE 4
9 |
10 | /* GUI */
11 |
12 | ICE_ID ICE_Gui_Create(ICE_State * state_, const ICE_Box box_, ICE_GuiType types_);
13 | void ICE_Gui_Clear(ICE_Gui * label_);
14 | void ICE_Gui_Destroy(ICE_Gui * ptr);
15 |
16 | /* GUI GET */
17 |
18 | ICE_Gui * ICE_Gui_Get(ICE_State *state, ICE_GuiID gui);
19 | ICE_Box ICE_Gui_GetBox(ICE_Gui * gui);
20 |
21 | /* GUI SET */
22 |
23 | void ICE_Gui_SetTexture(ICE_Gui * gui_ptr_, int texture_id_);
24 | void ICE_Gui_SetBox(ICE_Gui * gui, ICE_Box box);
25 | void ICE_Gui_SetPos(ICE_Gui * gui, ICE_Vect pos);
26 | void ICE_Gui_SetSize(ICE_Gui * gui, ICE_Vect vect);
27 | void ICE_Gui_SetType(ICE_Gui * gui, ICE_GuiType type);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Gui_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_GUI_PRIVATE
2 | #define DEF_ICE_GUI_PRIVATE
3 |
4 | #include "../Core/TypesCore.h"
5 |
6 | void ICE_GuiManager_Init(ICE_State* state);
7 | void ICE_GuiManager_Destroy(ICE_State * state);
8 | ICE_Gui ICE_Gui_Build(ICE_Box box_, ICE_GuiType types_);
9 | void ICE_Gui_UpdateTexture(ICE_State* state_, ICE_ID gui);
10 | void ICE_Gui_Rect(ICE_Texture * texture, struct ICE_Box rect);
11 |
12 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Primitive.c:
--------------------------------------------------------------------------------
1 | #include "Primitive.h"
2 |
3 | #include "Render_private.h"
4 |
5 | #include "../Core/Converter_private.h"
6 | #include "../Core/TypesCore.h"
7 | #include "../Maths/TypesMaths.h"
8 |
9 | extern ICE_Game GAME;
10 | extern ICE_Core CORE;
11 |
12 | // ClassicShit
13 |
14 | int ICE_Draw_Point(const ICE_Vect vect, const ICE_Color color) {
15 | ICE_Render_SetColor(color);
16 | return SDL_RenderDrawPoint(CORE.window.render, (int)vect.x, (int)vect.y);
17 | }
18 |
19 | int ICE_Draw_Line(const ICE_Vect vect1, const ICE_Vect vect2, const ICE_Color color) {
20 | ICE_Render_SetColor(color);
21 | return SDL_RenderDrawLine(CORE.window.render, (int)vect1.x, (int)vect1.y, (int)vect2.x, (int)vect2.y);
22 | }
23 |
24 | int ICE_Draw_Rectangle(ICE_Box box, const ICE_Color color) {
25 | ICE_Render_SetColor(color);
26 | return SDL_RenderDrawRect(CORE.window.render, (SDL_Rect[]){ICE_Convert_BoxToSDL(&box)});
27 | }
28 |
29 | int ICE_Draw_RectangleFill(ICE_Box box, const ICE_Color color) {
30 | ICE_Render_SetColor(color);
31 | return SDL_RenderFillRect(CORE.window.render, (SDL_Rect[]) {ICE_Convert_BoxToSDL(&box) });
32 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Primitive.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_PRIMITIVE
2 | #define DEF_ICE_PRIMITIVE
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Maths/TypesMaths.h"
6 |
7 |
8 | /**
9 | * \brief Draw a pixel on the screen with a defined color
10 | * \param vect Vector that is the Coordinate of the pixel
11 | * \param color Color of the pixel
12 | * \return 1
13 | */
14 | int ICE_Draw_Point(const ICE_Vect vect, const ICE_Color color);
15 |
16 |
17 | /**
18 | * \brief Draw a line of pixel on the screen with a defined color
19 | * \param vect1 Vector that is the first point of the line
20 | * \param vect2 Vector that is the second point of the line
21 | * \param color Color of the line
22 | * \return 0
23 | */
24 | int ICE_Draw_Line(const ICE_Vect vect1, const ICE_Vect vect2, const ICE_Color color);
25 |
26 | /**
27 | * \brief Draw a rectangle of pixel on the screen with a defined color
28 | * \param box Box that is the position and size of the rectangle drawed
29 | * \param color Color of the rectangle
30 | * \return 0
31 | */
32 | int ICE_Draw_Rectangle(ICE_Box box, const ICE_Color color);
33 |
34 | /**
35 | * \brief Draw a filled rectangle of pixel on the screen with a defined color
36 | * \param box Box that is the position and size of the rectangle drawed
37 | * \param color Color of the rectangle
38 | * \return 0
39 | */
40 | int ICE_Draw_RectangleFill(ICE_Box box, const ICE_Color color);
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Render.c:
--------------------------------------------------------------------------------
1 | #include "Render.h"
2 |
3 | #include "../Core/TypesCore.h"
4 |
5 | extern ICE_Game GAME;
6 |
7 | void ICE_Render_Color(const ICE_Color rgba_hex) {
8 | GAME.current->background = rgba_hex;
9 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Render.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_INPUT_RENDER
2 | #define DEF_ICE_INPUT_RENDER
3 |
4 | #include "TypesGraphics.h"
5 |
6 | /**
7 | * \brief Set a color to be the background color of the renderer
8 | * \param rgba_hex Color to set
9 | */
10 | void ICE_Render_Color(const ICE_Color rgba_hex);
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Render_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_RENDER_PRIVATE
2 | #define DEF_ICE_RENDER_PRIVATE
3 |
4 | #include "TypesGraphics.h"
5 |
6 | /**
7 | * \brief Change the rendering color in SDL
8 | * \param rgba_hex color to change
9 | * \return 0
10 | */
11 | int ICE_Render_SetColor(const ICE_Color rgba_hex);
12 |
13 | /**
14 | * \brief Clear screen
15 | * \return 0
16 | */
17 | int ICE_Render_Clear();
18 |
19 | /**
20 | * \brief Flip the buffer to draw everything on screen
21 | */
22 | void ICE_Render_Now();
23 |
24 | void ICE_Render_SplashScreen();
25 |
26 | #if defined(_DEBUG)
27 | void ICE_Render_Info();
28 | #else
29 | #define ICE_Render_Info(...)
30 | #endif
31 |
32 | void ICE_Render_Init();
33 | void ICE_Render_Quit();
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Screenshot.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_SCREENSHOT
2 | #define DEF_ICE_SCREENSHOT
3 |
4 | #include "../Framework/String_.h"
5 |
6 | void ICE_Screenshot(ICE_StringStd path_to_save_, ICE_StringStd filetype);
7 | void ICE_Screenshot_Custom(ICE_StringStd path_);
8 |
9 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Sprite.c:
--------------------------------------------------------------------------------
1 | #include "Sprite.h"
2 | #include "../Core/State.h"
3 | #include "../Framework/Memory_.h"
4 | #include "../Framework/Log.h"
5 |
6 | extern ICE_Game GAME;
7 | extern ICE_Asset ASSET;
8 |
9 | /* SPRITEMANAGER */
10 |
11 | void ICE_SpriteManager_Init()
12 | {
13 | ICE_SpriteManager sprite_manager = { 0 };
14 | sprite_manager.sprite_size = ICE_DEFAULT_SPRITEMNGR_SIZE;
15 | sprite_manager.sprite = ICE_Calloc(ICE_DEFAULT_SPRITEMNGR_SIZE, sizeof(ICE_Sprite));
16 | ASSET.sprite_mngr = sprite_manager;
17 | ICE_Log(ICE_LOGTYPE_SUCCES, "Init SpriteManager");
18 | }
19 |
20 | void ICE_SpriteManager_Destroy()
21 | {
22 | for (ICE_ID i = 0; i < ASSET.sprite_mngr.sprite_contain; i++)
23 | ICE_Sprite_Destroy(i);
24 |
25 | ICE_Free(ASSET.sprite_mngr.sprite);
26 | ASSET.sprite_mngr.sprite = NULL;
27 | ICE_Log(ICE_LOGTYPE_SUCCES, "Free SpriteManager");
28 | }
29 |
30 | /* SPRITE */
31 |
32 | ICE_Sprite ICE_Sprite_Build(ICE_TextureID texture_, ICE_Vect size_frame_sprite_)
33 | {
34 | ICE_Sprite sprite = { 0 };
35 | ICE_Texture * texture_get = NULL;
36 | if(texture_ != (ICE_TextureID)-1)
37 | texture_get = &ASSET.texture_mngr.texture[texture_];
38 | else
39 | texture_get = &ASSET.texture_error;
40 |
41 | sprite.exist = ICE_True;
42 | sprite.have_texture_defined = ICE_True;
43 | sprite.texture_index = texture_;
44 | sprite.size_w = (unsigned int)size_frame_sprite_.x;
45 | sprite.size_h = (unsigned int)size_frame_sprite_.y;
46 | sprite.number_frame_w = (ICE_Index)texture_get->w / size_frame_sprite_.x;
47 | sprite.number_frame_h = (ICE_Index)texture_get->h / size_frame_sprite_.y;
48 |
49 | return sprite;
50 | }
51 |
52 | ICE_ID ICE_Sprite_Load(ICE_TextureID texture_, ICE_Vect size_frame_sprite_)
53 | {
54 | if(texture_ != (ICE_TextureID)-1)
55 | {
56 | ASSET.sprite_mngr.sprite[ASSET.sprite_mngr.sprite_contain] = ICE_Sprite_Build(texture_, size_frame_sprite_);;
57 | ASSET.sprite_mngr.sprite_contain++;
58 |
59 | ASSET.sprite_mngr.sprite[ASSET.sprite_mngr.sprite_contain].index = ASSET.sprite_mngr.sprite_contain - 1;
60 |
61 | ICE_Log(ICE_LOGTYPE_SUCCES, "Create Sprite %d from Texture %d <%d*%d>", ASSET.sprite_mngr.sprite_contain - 1, texture_, ASSET.sprite_mngr.sprite[ASSET.sprite_mngr.sprite_contain-1].size_w, ASSET.sprite_mngr.sprite[ASSET.sprite_mngr.sprite_contain-1].size_h);
62 |
63 | if (ASSET.sprite_mngr.sprite_size <= ASSET.sprite_mngr.sprite_contain)
64 | {
65 | ASSET.sprite_mngr.sprite = ICE_Realloc(ASSET.sprite_mngr.sprite, sizeof(ICE_Sprite)*(ASSET.sprite_mngr.sprite_size * 2));;
66 | ASSET.sprite_mngr.sprite_size *= 2;
67 | }
68 |
69 | return ASSET.sprite_mngr.sprite_contain - 1;
70 | }
71 | return (ICE_SpriteID)-1;
72 | }
73 |
74 | void ICE_Sprite_Clear(ICE_SpriteID sprite_)
75 | {
76 | memset(&ASSET.sprite_mngr.sprite[sprite_], 0, sizeof(ICE_Sprite));
77 | }
78 |
79 | ICE_Sprite * ICE_Sprite_Get(ICE_SpriteID sprite_)
80 | {
81 | return &ASSET.sprite_mngr.sprite[sprite_];
82 | }
83 |
84 | void ICE_Sprite_Destroy(ICE_SpriteID sprite_)
85 | {
86 |
87 | }
88 |
89 | ICE_Uint64 ICE_Sprite_GetFrameQuantity(ICE_SpriteID _sprite)
90 | {
91 | return ASSET.sprite_mngr.sprite[_sprite].number_frame_h * ASSET.sprite_mngr.sprite[_sprite].number_frame_w;
92 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Sprite.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_SPRITE
2 | #define DEF_ICE_SPRITE
3 |
4 | #include "TypesGraphics.h"
5 |
6 | #define ICE_DEFAULT_SPRITEMNGR_SIZE 4
7 |
8 | void ICE_SpriteManager_Init();
9 | void ICE_SpriteManager_Destroy();
10 |
11 | ICE_Sprite ICE_Sprite_Build(ICE_TextureID texture_, ICE_Vect size_frame_sprite_);
12 | ICE_ID ICE_Sprite_Load(ICE_TextureID texture_, ICE_Vect size_frame_sprite_);
13 | void ICE_Sprite_Clear(ICE_SpriteID sprite_);
14 | void ICE_Sprite_Destroy(ICE_SpriteID sprite_);
15 | ICE_Sprite * ICE_Sprite_Get(ICE_SpriteID sprite_);
16 | ICE_Uint64 ICE_Sprite_GetFrameQuantity(ICE_SpriteID sprite_);
17 |
18 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Sprite_private.c:
--------------------------------------------------------------------------------
1 | #include "Sprite_private.h"
2 |
3 |
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Sprite_private.h:
--------------------------------------------------------------------------------
1 | #ifndef ICE_GUARD_SPRITE_PRIVATE
2 | #define ICE_GUARD_SPRITE_PRIVATE
3 |
4 |
5 |
6 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Texture.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TEXTURE
2 | #define DEF_ICE_TEXTURE
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Framework/String_.h"
6 | #include "../Framework/Macrotools.h"
7 |
8 | #define ICE_DEFAULT_TEXTUREMNGR_SIZE 4
9 |
10 | void ICE_TextureManager_Init();
11 | void ICE_TextureManager_Destroy();
12 |
13 | #define ICE_Texture_Load_MEM(S) ICE_Texture_Load_RW(SDL_RWFromConstMem(S, S##_length));\
14 | if(ICE_Texture_GetLastLoaded() != (ICE_ID)-1)\
15 | ICE_Log_Succes(ICE_MACROTOOLS_STRINGIZE(Texture loaded from memory : ID(%ld) Token(##S##)), ICE_Texture_GetLastLoaded());\
16 | else\
17 | ICE_Log_printf(ICE_MACROTOOLS_STRINGIZE(Texture didn t loaded from token : ##S));\
18 |
19 | ICE_TextureID ICE_Texture_GetLastLoaded();
20 | ICE_ID ICE_Texture_Load(ICE_StringStd path_);
21 | ICE_Texture ICE_Texture_Build_RW(SDL_RWops * rwops);
22 | ICE_ID ICE_Texture_Load_RW(SDL_RWops * rwops_);
23 | void ICE_Texture_Destroy(ICE_ID texture_);
24 | void ICE_Texture_Free(ICE_Texture * texture_);
25 |
26 | // Texture Tools
27 | unsigned int ICE_Texture_GetW(ICE_ID texture_);
28 | unsigned int ICE_Texture_GetH(ICE_ID texture_);
29 | ICE_Texture * ICE_Texture_Get(ICE_ID texture_);
30 |
31 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/Texture_private.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TEXTURE_PRIVATE
2 | #define DEF_ICE_TEXTURE_PRIVATE
3 |
4 | #include "TypesGraphics.h"
5 | #include "../Maths/TypesMaths.h"
6 |
7 | int ICE_Texture_RenderEx(const ICE_Texture *texture, ICE_Box* src, ICE_Box* dst, const ICE_Float angle);
8 | int ICE_Texture_RenderEx2(const ICE_Texture* tex, ICE_Box* src, ICE_Box* dst, const ICE_Float angle);
9 | ICE_Texture ICE_Texture_LoadFromFile(char *path);
10 | ICE_Texture ICE_Texture_LoadFromFile_RW(SDL_RWops * rwops_);
11 | void ICE_Texture_ErrorInit();
12 | void ICE_Texture_LogoInit();
13 | void ICE_Texture_DefaultGuiInit();
14 |
15 | void ICE_Texture_LogoFree();
16 | void ICE_Texture_DefaultGuiFree();
17 | void ICE_Texture_ErrorFree();
18 | void ICE_Texture_DefaultAllFree();
19 |
20 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Graphics/TypesGraphics.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TYPESGRAPHICS
2 | #define DEF_ICE_TYPESGRAPHICS
3 |
4 | #include "../Maths/TypesMaths.h"
5 | #include "../Framework/TypesFramework.h"
6 | #include "../Core/SDL2_Includer.h"
7 |
8 | #include ICE_INCLUDE_SDL2_TTF
9 |
10 | #ifndef ICE_INDEX_CORETYPE_DEFINED
11 | #define ICE_INDEX_CORETYPE_DEFINED
12 |
13 | typedef ICE_ID ICE_EntityID;
14 | typedef ICE_ID ICE_LabelID;
15 | typedef ICE_ID ICE_GuiID;
16 |
17 | typedef ICE_ID ICE_SpriteID;
18 | typedef ICE_ID ICE_TextureID;
19 | typedef ICE_ID ICE_FontID;
20 | typedef ICE_ID ICE_SoundID;
21 | typedef ICE_ID ICE_MusicID;
22 | typedef ICE_ID ICE_DataID;
23 |
24 | #endif
25 |
26 | #ifndef ICE_BOOL_DEFINED
27 | #define ICE_BOOL_DEFINED
28 | typedef _Bool ICE_Bool;
29 | #define ICE_True 1
30 | #define ICE_TRUE 1
31 | #define ICE_true 1
32 | #define ICE_False 0
33 | #define ICE_FALSE 0
34 | #define ICE_false 0
35 | #define ICE_BOOL_BITFIELD(S) ICE_Bool S : 1
36 | #endif
37 |
38 | /**
39 | * \brief Color in the Engine, it's a uint32_t for 8 bits per value (R, G, B, A)
40 | */
41 | typedef uint32_t ICE_Color;
42 |
43 | /**
44 | * \brief Texture struct handling sdl texture
45 | */
46 | struct ICE_Texture
47 | {
48 | ICE_ID id;
49 | ICE_Bool exist;
50 | unsigned int w, h;
51 | SDL_Texture* handle;
52 | };
53 |
54 | typedef struct ICE_Texture ICE_Texture;
55 |
56 | /**
57 | * \brief Texture Manager
58 | */
59 | struct ICE_TextureManager
60 | {
61 | ICE_Bool isFree;
62 |
63 | ICE_ID texture_size;
64 | ICE_ID texture_contain;
65 | ICE_Texture* texture;
66 | };
67 | typedef struct ICE_TextureManager ICE_TextureManager;
68 |
69 | typedef struct
70 | {
71 | unsigned int sprite_index;
72 | ICE_Float duration;
73 | ICE_Float actual_time;
74 |
75 | } ICE_AnimationStep;
76 |
77 | typedef struct
78 | {
79 | unsigned int actual_step;
80 | ICE_ID step_size;
81 | ICE_ID step_contain;
82 | ICE_AnimationStep * step;
83 |
84 | } ICE_Animation;
85 |
86 | typedef struct
87 | {
88 | ICE_ID index;
89 | ICE_Bool exist;
90 |
91 | ICE_Bool have_texture_defined;
92 | ICE_ID texture_index;
93 |
94 | unsigned int size_w, size_h;
95 | ICE_Index number_frame_w, number_frame_h;
96 |
97 | ICE_ID animation_size;
98 | ICE_ID animation_contain;
99 | ICE_Animation * animation;
100 |
101 | } ICE_Sprite;
102 |
103 | typedef struct
104 | {
105 | ICE_Bool isFree;
106 |
107 | ICE_ID sprite_size;
108 | ICE_ID sprite_contain;
109 | ICE_Sprite * sprite;
110 |
111 | } ICE_SpriteManager;
112 |
113 | typedef enum
114 | {
115 | ICE_GUITYPE_9PATCH,
116 | ICE_GUITYPE_IMAGE,
117 | ICE_GUITYPE_LABEL
118 |
119 | } ICE_GuiType;
120 |
121 | typedef struct
122 | {
123 | ICE_BOOL_BITFIELD(exist);
124 | ICE_BOOL_BITFIELD(active);
125 |
126 | ICE_BOOL_BITFIELD(have_texture_defined);
127 | ICE_ID texture_index;
128 | ICE_ID old_texture_index;
129 | ICE_Box box;
130 | ICE_Box old_box;
131 |
132 | ICE_GuiType type;
133 | ICE_Texture texture_cache;
134 |
135 | } ICE_Gui;
136 |
137 | typedef struct
138 | {
139 | ICE_Bool isFree;
140 |
141 | ICE_ID gui_size;
142 | ICE_ID gui_contain;
143 | ICE_Gui* gui;
144 |
145 | } ICE_GuiManager;
146 |
147 | #endif
148 |
--------------------------------------------------------------------------------
/projects/Engine/src/ICE.h:
--------------------------------------------------------------------------------
1 | /*
2 | , \ / ,
3 | / \ )\__/( / \
4 | / \ (_\ /_) / \
5 | ____/_____\__\@ @/___/_____\____
6 | | |\../| |
7 | | \VV/ |
8 | | COLDRAGON |
9 | |_________________________________|
10 | | /\ / \\ \ /\ |
11 | | / V )) V \ |
12 | |/ ` // ' \|
13 | ` V '
14 |
15 | */
16 |
17 | #ifndef DEF_ICE_INCLUDER_0X505050
18 | #define DEF_ICE_INCLUDER_0X505050
19 |
20 | #if defined(_DEBUG) && defined (_MSC_VER) && !defined(ICE_NO_VLD)
21 | //#include
22 | #endif
23 |
24 | // Framework
25 |
26 | #include "Framework/TypesFramework.h"
27 |
28 | #include "Framework/Assert_.h"
29 | #include "Framework/Log.h"
30 | #include "Framework/Memory_.h"
31 | #include "Framework/Random.h"
32 | #include "Framework/String_.h"
33 | #include "Framework/Terminal.h"
34 |
35 | // Core
36 |
37 | #include "Core/TypesCore.h"
38 |
39 | #include "Core/Asset.h"
40 | #include "Core/Config.h"
41 | #include "Core/Core.h"
42 | #include "Core/Debug.h"
43 | #include "Core/Game.h"
44 | #include "Core/Input.h"
45 | #include "Core/Label.h"
46 | #include "Core/State.h"
47 | #include "Core/Time_.h"
48 | #include "Core/Window.h"
49 | #include "Core/Data.h"
50 | #include "Core/Entity.h"
51 | #include "Core/MacOS_.h"
52 | #include "Core/Version.h"
53 |
54 | // Graphics
55 |
56 | #include "Graphics/TypesGraphics.h"
57 |
58 | #include "Graphics/Camera.h"
59 | #include "Graphics/Color.h"
60 | #include "Graphics/Font.h"
61 | #include "Graphics/Primitive.h"
62 | #include "Graphics/Render.h"
63 | #include "Graphics/Texture.h"
64 | #include "Graphics/Sprite.h"
65 | #include "Graphics/Gui.h"
66 | #include "Graphics/Screenshot.h"
67 |
68 | // Audio
69 |
70 | #include "Audio/TypesAudio.h"
71 | #include "Audio/Audio.h"
72 | #include "Audio/Sound.h"
73 | #include "Audio/Music.h"
74 |
75 | // Maths
76 |
77 | #include "Maths/TypesMaths.h"
78 |
79 | #include "Maths/Box.h"
80 | #include "Maths/Interpolate.h"
81 | #include "Maths/Vector.h"
82 |
83 | // Physics
84 |
85 | #include "Physics/TypesPhysics.h"
86 | #include "Physics/Basic_Collision.h"
87 |
88 | //
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/projects/Engine/src/Maths/Box.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_BOX
2 | #define DEF_ICE_BOX
3 |
4 | #include "TypesMaths.h"
5 | #include "../Framework/Inline.h"
6 |
7 | /**
8 | * \brief Create a new Box
9 | * \param x Position X
10 | * \param y Position Y
11 | * \param w Width
12 | * \param h Height
13 | * \return The new Box
14 | */
15 | ICE_INLINE ICE_Box ICE_Box_New(const ICE_Float x, const ICE_Float y, const ICE_Float w, const ICE_Float h) {
16 | ICE_Box box = { x,y,w,h };
17 | return box;
18 | }
19 |
20 | /**
21 | * \brief
22 | * \param rect Rectangle to scale
23 | * \param scale Value to scale (<1 reduce size, >1 enlarge size)
24 | * \return The scaled box
25 | */
26 | ICE_INLINE ICE_Box ICE_Box_Scale(ICE_Box rect, ICE_Float scale)
27 | {
28 | return ICE_Box_New(rect.x, rect.y, rect.w * scale, rect.h * scale);
29 | }
30 |
31 | /**
32 | * \brief Compare two Box if they are exactly the same
33 | * \param box1 First Box
34 | * \param box2 Second Box
35 | * \return ICE_True or ICE_False
36 | */
37 | ICE_INLINE ICE_Bool ICE_Box_Compare(ICE_Box box1, ICE_Box box2)
38 | {
39 | if (box1.x != box2.x ||
40 | box1.y != box2.y ||
41 | box1.w != box2.w ||
42 | box1.h != box2.h)
43 | return ICE_False;
44 | return ICE_True;
45 | }
46 |
47 | /**
48 | * \brief Compare two Box if they have the same size
49 | * \param box1 First Box
50 | * \param box2 Second Box
51 | * \return ICE_True or ICE_False
52 | */
53 | ICE_INLINE ICE_Bool ICE_Box_CompareSize(ICE_Box box1, ICE_Box box2)
54 | {
55 | if (box1.w != box2.w ||
56 | box1.h != box2.h)
57 | return ICE_False;
58 | return ICE_True;
59 | }
60 |
61 | /**
62 | * \brief Compare two Box if they are at the same position
63 | * \param box1 First Box
64 | * \param box2 Second Box
65 | * \return ICE_True or ICE_False
66 | */
67 | ICE_INLINE ICE_Bool ICE_Box_ComparePos(ICE_Box box1, ICE_Box box2)
68 | {
69 | if (box1.x != box2.x ||
70 | box1.y != box2.y)
71 | return ICE_False;
72 | return ICE_True;
73 | }
74 |
75 | /**
76 | * \brief Set the Box position to a new position with a Vector
77 | * \param box The Box to change position
78 | * \param vect The Vector that is the new position
79 | */
80 | ICE_INLINE void ICE_Box_SetPos(ICE_Box *box, ICE_Vect vect)
81 | {
82 | box->x = vect.x; box->y = vect.y;
83 |
84 | }
85 |
86 | /**
87 | * \brief Set the Box size to a new size
88 | * \param box The Box to change size
89 | * \param w The width value
90 | * \param h The height value
91 | */
92 | ICE_INLINE void ICE_Box_SetSize(ICE_Box *box, ICE_Float w, ICE_Float h)
93 | {
94 | box->w = w; box->h = h;
95 | }
96 |
97 | /**
98 | * \brief Shift the box position by a value
99 | * \param box The box to move
100 | * \param x The X value added to position
101 | * \param y The Y value added to position
102 | */
103 | ICE_INLINE void ICE_Box_Shift(ICE_Box *box, ICE_Float x, ICE_Float y)
104 | {
105 | box->x += x; box->y += y;
106 | }
107 | #endif
108 |
--------------------------------------------------------------------------------
/projects/Engine/src/Maths/Maths.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_MATHS
2 | #define DEF_ICE_MATHS
3 |
4 | #include
5 | #include "TypesMaths.h"
6 | #include "../Framework/Inline.h"
7 |
8 | /// Move point to an other point from a r distance in float
9 | ICE_INLINE void ICE_Maths_MoveFromAngle(ICE_Float *x, ICE_Float *y, const ICE_Float angle, const ICE_Float r) {
10 | *x += r * cos(angle); *y += r * sin(angle);
11 | }
12 |
13 | /// Calculate the angle for two point in degree
14 | ICE_INLINE ICE_Float ICE_Maths_AngleCalculatDegree(const ICE_Float x1, const ICE_Float y1, const ICE_Float x2, const ICE_Float y2) {
15 | ICE_Float xdif = x2 - x1; ICE_Float ydif = y2 - y1;
16 | return 57.29*atan2(ydif, xdif);
17 | }
18 |
19 | /// Calculate the angle for two point in radiant
20 | ICE_INLINE ICE_Float ICE_Maths_AngleCalculatRadiant(const ICE_Float x1, const ICE_Float y1, const ICE_Float x2, const ICE_Float y2) {
21 | ICE_Float xdif = x2 - x1; ICE_Float ydif = y2 - y1;
22 | return atan2(ydif, xdif);
23 | }
24 |
25 | ICE_INLINE void ICE_Maths_MoveToPosition(ICE_Float *x1, ICE_Float *y1, ICE_Float x2, ICE_Float y2, ICE_Float r) {
26 | ICE_Float xdif = x2 - *x1; ICE_Float ydif = y2 - *y1;
27 | ICE_Float angle = atan2(ydif, xdif);
28 | ICE_Float distance_r_r = xdif * xdif + ydif * ydif;
29 | *x1 += r * cos(angle); *y1 += r * sin(angle);
30 | if (distance_r_r < r*r) {
31 | *x1 = x2;
32 | *y1 = y2;
33 | }
34 | }
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/projects/Engine/src/Maths/TypesMaths.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TYPESMATHS
2 | #define DEF_ICE_TYPESMATHS
3 |
4 | #ifndef ICE_BOOL_DEFINED
5 | #define ICE_BOOL_DEFINED
6 | typedef _Bool ICE_Bool;
7 | #define ICE_True 1
8 | #define ICE_TRUE 1
9 | #define ICE_true 1
10 | #define ICE_False 0
11 | #define ICE_FALSE 0
12 | #define ICE_false 0
13 | #define ICE_BOOL_BITFIELD(S) ICE_Bool S : 1
14 | #endif
15 |
16 | #ifndef ICE_FLOAT_DEFINED
17 | #define ICE_FLOAT_DEFINED
18 | typedef double ICE_Float;
19 | #endif
20 |
21 | /**
22 | * \brief Vector2D
23 | */
24 | struct ICE_Vect
25 | {
26 | ICE_Float x;
27 | ICE_Float y;
28 |
29 | }; typedef struct ICE_Vect ICE_Vect;
30 |
31 | /**
32 | * \brief Box (or Rectangle)
33 | */
34 | struct ICE_Box
35 | {
36 | ICE_Float x;
37 | ICE_Float y;
38 | ICE_Float w;
39 | ICE_Float h;
40 |
41 | }; typedef struct ICE_Box ICE_Box;
42 |
43 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Maths/Vector.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_VECTOR
2 | #define DEF_ICE_VECTOR
3 |
4 | #include "TypesMaths.h"
5 | #include
6 | #include "../Framework/Inline.h"
7 |
8 | /**
9 | * \brief Create a new Vector
10 | * \param x X value
11 | * \param y Y value
12 | * \return The created Vector
13 | */
14 | ICE_INLINE ICE_Vect ICE_Vect_New(ICE_Float x, ICE_Float y) {
15 | ICE_Vect vect = { x,y };
16 | return vect;
17 | }
18 |
19 | /**
20 | * \brief Sum two vector
21 | * \param vect1 Vector 1
22 | * \param vect2 Vector 2
23 | * \return Sum of the two Vector
24 | */
25 | ICE_INLINE ICE_Vect ICE_Vect_Sum(ICE_Vect vect1, ICE_Vect vect2) {
26 | return ICE_Vect_New(vect1.x + vect2.x, vect1.y + vect2.y);
27 | }
28 |
29 | /**
30 | * \brief Sub vector 2 from vector 1
31 | * \param vect1 Vector 1
32 | * \param vect2 Vector 2
33 | * \return Vect1-Vect2
34 | */
35 | ICE_INLINE ICE_Vect ICE_Vect_Sub(ICE_Vect vect1, ICE_Vect vect2) {
36 | return ICE_Vect_New(vect1.x - vect2.x, vect1.y - vect2.y);
37 | }
38 |
39 | /**
40 | * \brief Scale a Vector by a value
41 | * \param vect1 Vector to scale
42 | * \param value Scaling value
43 | * \return Vector scaled
44 | */
45 | ICE_INLINE ICE_Vect ICE_Vect_Scale(ICE_Vect vect1, ICE_Float value) {
46 | return ICE_Vect_New(vect1.x * value, vect1.y * value);
47 | }
48 |
49 | /**
50 | * \brief Multiply a Vector by another
51 | * \param vect1 Vector1
52 | * \param vect2 Vector2
53 | * \return Vector1 * Vector2
54 | */
55 | ICE_INLINE ICE_Vect ICE_Vect_Multi(ICE_Vect vect1, ICE_Vect vect2) {
56 | return ICE_Vect_New(vect1.x * vect2.x, vect1.y * vect2.y);
57 | }
58 |
59 | /**
60 | * \brief Magnitude of a vector
61 | * \param vect Vector1
62 | * \return Magnitude of Vector1
63 | */
64 | ICE_INLINE ICE_Float ICE_Vect_Magn(ICE_Vect vect) {
65 | return sqrt((vect.x*vect.x) + (vect.y*vect.y));
66 | }
67 |
68 | /**
69 | * \brief Vector Null (0, 0)
70 | */
71 | #define ICE_Vect_Zero ICE_Vect_New(0,0)
72 |
73 | /**
74 | * \brief Vector that is the size of the screen
75 | */
76 | #define ICE_Vect_Screen ICE_Vect_New(ICE_Window_GetW(), ICE_Window_GetH())
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/projects/Engine/src/Physics/Basic_Collision.c:
--------------------------------------------------------------------------------
1 | #include "Basic_Collision.h"
2 |
3 |
4 | ICE_Bool ICE_Collision_Box_Point(ICE_Box box, ICE_Vect point)
5 | {
6 | return point.x > box.x && point.x < box.x+box.w && point.y > box.y && point.y < box.y+box.h;
7 | }
--------------------------------------------------------------------------------
/projects/Engine/src/Physics/Basic_Collision.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_BASIC_COLLISION
2 | #define DEF_ICE_BASIC_COLLISION
3 |
4 | #include "../Maths/Vector.h"
5 |
6 | ICE_Bool ICE_Collision_Box_Point(ICE_Box box, ICE_Vect point);
7 |
8 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Physics/TypesPhysics.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_ICE_TYPESPHYSICS
2 | #define DEF_ICE_TYPESPHYSICS
3 |
4 | #ifndef ICE_BOOL_DEFINED
5 | #define ICE_BOOL_DEFINED
6 | typedef _Bool ICE_Bool;
7 | #define ICE_True 1
8 | #define ICE_TRUE 1
9 | #define ICE_true 1
10 | #define ICE_False 0
11 | #define ICE_FALSE 0
12 | #define ICE_false 0
13 | #define ICE_BOOL_BITFIELD(S) ICE_Bool S : 1
14 | #endif
15 |
16 | #endif
--------------------------------------------------------------------------------
/projects/Engine/src/Ressources/bin/gui27_png.c:
--------------------------------------------------------------------------------
1 | const char ICE_Ressource_gui27_png[362] = {
2 | 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
3 | 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00,
4 | 0x00, 0x1b, 0x08, 0x06, 0x00, 0x00, 0x00, 0x8d, 0xd4, 0xf4, 0x55,
5 | 0x00, 0x00, 0x00, 0x06, 0x62, 0x4b, 0x47, 0x44, 0x00, 0xff, 0x00,
6 | 0xff, 0x00, 0xff, 0xa0, 0xbd, 0xa7, 0x93, 0x00, 0x00, 0x00, 0x09,
7 | 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b,
8 | 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74,
9 | 0x49, 0x4d, 0x45, 0x07, 0xe1, 0x0b, 0x03, 0x07, 0x1f, 0x29, 0xfe,
10 | 0x0e, 0x7c, 0x0f, 0x00, 0x00, 0x00, 0x1d, 0x69, 0x54, 0x58, 0x74,
11 | 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00,
12 | 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69,
13 | 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x64, 0x2e, 0x65, 0x07,
14 | 0x00, 0x00, 0x00, 0xce, 0x49, 0x44, 0x41, 0x54, 0x48, 0xc7, 0xed,
15 | 0xd6, 0x31, 0x8a, 0x83, 0x40, 0x14, 0x87, 0xf1, 0x2f, 0x33, 0xa0,
16 | 0x04, 0x64, 0xd9, 0x3e, 0x48, 0x9a, 0x01, 0x49, 0x33, 0x88, 0x57,
17 | 0x49, 0xeb, 0x31, 0x52, 0xe4, 0x20, 0x39, 0x44, 0x4e, 0x62, 0xfd,
18 | 0x10, 0x61, 0xeb, 0x85, 0x0d, 0xf6, 0x83, 0x9d, 0xc8, 0x4b, 0x63,
19 | 0xca, 0xed, 0x1c, 0xab, 0xf9, 0x60, 0xda, 0xff, 0xaf, 0x98, 0xe6,
20 | 0xa1, 0xaa, 0x00, 0x47, 0xe0, 0x0e, 0xfc, 0x01, 0xba, 0xf1, 0xbb,
21 | 0x03, 0x47, 0x55, 0xe5, 0xb0, 0x42, 0x3f, 0xd6, 0xda, 0x73, 0x5d,
22 | 0xd7, 0x78, 0xef, 0x29, 0x8a, 0x82, 0x2d, 0xea, 0xba, 0x0e, 0x11,
23 | 0x61, 0x59, 0x96, 0x5f, 0xe0, 0x62, 0x81, 0x9b, 0xb5, 0xf6, 0xda,
24 | 0xb6, 0x2d, 0xce, 0x39, 0xb2, 0x2c, 0x63, 0xab, 0xca, 0xb2, 0xa4,
25 | 0xaa, 0x2a, 0x86, 0x61, 0xf8, 0x56, 0xd5, 0xc9, 0x02, 0xcf, 0xa6,
26 | 0x69, 0xbe, 0x9c, 0x73, 0xc4, 0x28, 0xcf, 0x73, 0xe6, 0x79, 0x66,
27 | 0x1c, 0xc7, 0x8b, 0x01, 0x4e, 0xde, 0x7b, 0x62, 0xb6, 0xee, 0x9f,
28 | 0x0c, 0xb0, 0xd9, 0x1f, 0xfd, 0xd7, 0x67, 0xdf, 0xb0, 0x63, 0x09,
29 | 0x4b, 0x58, 0xc2, 0x12, 0x96, 0xb0, 0x84, 0xc5, 0xc4, 0xa6, 0x69,
30 | 0x8a, 0x8a, 0x7c, 0xf6, 0x0d, 0xf0, 0xea, 0xfb, 0x3e, 0x2a, 0xb6,
31 | 0xee, 0xbf, 0x0c, 0xf0, 0x10, 0x11, 0x42, 0x08, 0x51, 0xa0, 0x10,
32 | 0x02, 0x22, 0x02, 0xf0, 0xd8, 0xf5, 0x6e, 0x64, 0xcf, 0x8b, 0xf8,
33 | 0x0d, 0xcb, 0x1b, 0x78, 0xd8, 0xb9, 0xe9, 0xf9, 0xf9, 0x00, 0x00,
34 | 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
35 | };
36 |
37 | const int ICE_Ressource_gui27_png_length = 362;
38 |
--------------------------------------------------------------------------------
/projects/Engine/src/Ressources/src/err1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/Ressources/src/err1024.png
--------------------------------------------------------------------------------
/projects/Engine/src/Ressources/src/err512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/Ressources/src/err512.png
--------------------------------------------------------------------------------
/projects/Engine/src/Ressources/src/gui27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/Ressources/src/gui27.png
--------------------------------------------------------------------------------
/projects/Engine/src/Ressources/src/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Engine/src/Ressources/src/logo.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/2DWatch.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 | src
15 |
16 |
17 | src
18 |
19 |
20 |
21 |
22 | src
23 |
24 |
25 | src
26 |
27 |
28 | src
29 |
30 |
31 |
--------------------------------------------------------------------------------
/projects/Games/2DWatch/2DWatch.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/img/gui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/img/gui.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/img/ice_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/img/ice_logo.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/img/pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/img/pic.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/img/sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/img/sprite.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/img/widow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/img/widow.png
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/snd/explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/snd/explosion.wav
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/snd/hit.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/snd/hit.wav
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/snd/laser.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/snd/laser.wav
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/snd/music.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/snd/music.ogg
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/snd/power.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/snd/power.wav
--------------------------------------------------------------------------------
/projects/Games/2DWatch/res/ttf/FiraSans-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/2DWatch/res/ttf/FiraSans-Medium.ttf
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/data.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_GAME_DATA
2 | #define DEF_GAME_DATA
3 |
4 | #include "weapon.h"
5 |
6 | struct DATA1
7 | {
8 | int life, speed;
9 | ICE_State inventory;
10 | Game_Weapon current_weapon;
11 |
12 | }; typedef struct DATA1 DATA1;
13 |
14 | #endif
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/inventory.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "inventory.h"
3 | #include "data.h"
4 |
5 | void inventory_create()
6 | {
7 | ICE_Render_Color(ICE_Color_New(50, 50, 50));
8 | DATA1 * data = ICE_Data_Get(ICE_State_GetParent(NULL), 0);
9 | ICE_ID nb = ICE_Label_Create
10 | (
11 | NULL,
12 | "",
13 | ICE_Vect_New(50, 20),
14 | 12,
15 | ICE_LABELTYPE_SCREEN
16 | );
17 | ICE_Label_SetString
18 | (
19 | ICE_Label_Get(NULL, nb),
20 | "Name : %s Damage : %.1f Speed : %.1f",
21 | data->current_weapon.name,
22 | data->current_weapon.damage,
23 | data->current_weapon.speed
24 | );
25 | ICE_Label_SetWrapWidth(ICE_Label_Get(NULL, nb), 100);
26 | ICE_Gui_Create
27 | (
28 | NULL,
29 | ICE_Box_New
30 | (
31 | ICE_Label_GetX(ICE_Label_Get(NULL, nb)) - 5,
32 | ICE_Label_GetY(ICE_Label_Get(NULL, nb)),
33 | ICE_Label_GetWidth(ICE_Label_Get(NULL, nb)) + 10,
34 | ICE_Label_GetHeight(ICE_Label_Get(NULL, nb) + 2)
35 | ),
36 | ICE_GUITYPE_9PATCH
37 | );
38 | }
39 |
40 | void inventory_update()
41 | {
42 | ICE_Debug_DrawFps(5);
43 |
44 | ICE_Label_SetPos(ICE_Label_Get(NULL, 0), ICE_Vect_New(ICE_Input_MouseX() + 15, ICE_Input_MouseY() - 10));
45 | DATA1 * data = ICE_Data_Get(ICE_State_GetParent(NULL), 0);
46 | ICE_Gui_SetSize
47 | (
48 | ICE_Gui_Get(NULL, 0),
49 | ICE_Vect_New
50 | (
51 | ICE_Label_GetWidth(ICE_Label_Get(NULL, 0)) + 10,
52 | ICE_Label_GetHeight(ICE_Label_Get(NULL, 0)) + 2
53 | )
54 | );
55 |
56 | ICE_Gui_SetPos
57 | (
58 | ICE_Gui_Get(NULL, 0),
59 | ICE_Vect_New
60 | (
61 | ICE_Label_GetX(ICE_Label_Get(NULL, 0)) - 5,
62 | ICE_Label_GetY(ICE_Label_Get(NULL, 0))
63 | )
64 | );
65 | ICE_Debug_CameraControl();
66 |
67 | if (ICE_Input_Pressed(ICE_KEY_ESCAPE))
68 | ICE_State_Pause();
69 | }
70 |
71 | void inventory_destroy()
72 | {
73 |
74 | }
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/inventory.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_GAME_INVENTORY
2 | #define DEF_GAME_INVENTORY
3 |
4 | void inventory_create();
5 | void inventory_update();
6 | void inventory_destroy();
7 |
8 | #endif
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/main.c:
--------------------------------------------------------------------------------
1 | // Engine
2 | #include
3 |
4 | // Game
5 | #include "weapon.h"
6 | #include "data.h"
7 | #include "inventory.h"
8 |
9 | enum
10 | {
11 | texture_Pic = 0,
12 | texture_Gui = 1,
13 | texture_Widow = 2,
14 | texture_Sprite = 3,
15 | texture_Logo = 4
16 | };
17 |
18 | #define ICE_CONFIG_TITLE "2DWatch"
19 | #define ICE_CONFIG_WINDOW_W 800
20 | #define ICE_CONFIG_WINDOW_H 480
21 |
22 | void ICE_Game_Create()
23 | {
24 | // Texture
25 | ICE_Texture_Load("res//img//pic.png");
26 | ICE_Texture_Load("res//img//gui.png");
27 | ICE_Texture_Load("res//img//widow.png");
28 | ICE_Texture_Load("res//img//sprite.png");
29 | ICE_Texture_Load("res//img//ice_logo.png");
30 |
31 | // Sound
32 | ICE_Sound_Load("res//snd//explosion.wav");
33 |
34 | // Music
35 | ICE_Music_Load("res//snd//music.ogg");
36 |
37 | // FNT
38 | ICE_Font_Load("res//ttf//FiraSans-Medium.ttf");
39 |
40 | // Debug
41 |
42 | ICE_Debug_FontSetColorBg(100, 100, 100);
43 | ICE_Debug_FontSetColorFg(255, 255, 255);
44 |
45 | // Entity
46 |
47 | // Entity
48 | ICE_ID nb = ICE_Entity_Create(ICE_State_Current, ICE_Box_New(0, 0, 375, 250));
49 | ICE_Entity_SetTexture
50 | (
51 | ICE_Entity_Get(ICE_State_Current, 0),
52 | 0
53 | );
54 |
55 | // Gui
56 | nb = ICE_Gui_Create(ICE_State_Current, ICE_Box_New(0, 0, ICE_Window_GetW(), 50), ICE_GUITYPE_9PATCH);
57 | nb = ICE_Gui_Create(ICE_State_Current, ICE_Box_New(0, 0, 50, 70), ICE_GUITYPE_9PATCH);
58 | ICE_Gui_SetType(ICE_Gui_Get(ICE_State_Current, nb), ICE_GUITYPE_IMAGE);
59 |
60 | // 1
61 | nb = ICE_Label_Create(ICE_State_Current, "It is a me", ICE_Vect_New(0, 0), 30, ICE_LABELTYPE_WORLD);
62 | ICE_Label_SetAngle(ICE_Label_Get(ICE_State_Current, nb), 30);
63 | // 2
64 | nb = ICE_Label_Create(ICE_State_Current, "Russian Pawa", ICE_Vect_New(5, 5), 30, ICE_LABELTYPE_SCREEN);
65 |
66 | // Data
67 | DATA1 * data = ICE_Data_Insert_(ICE_State_Current, sizeof(DATA1));
68 | data->inventory = ICE_State_Create(inventory_create, inventory_update, inventory_destroy);
69 | data->current_weapon = Game_Weapon_Init("Big Sword", 100, 1.2, 50);
70 |
71 | // Music
72 | ICE_Music_Play(0, 16);
73 | }
74 |
75 | void Screen_Update()
76 | {
77 | // Update background color
78 | static float amount = 0; float result;
79 | if (amount <= 5.0f)
80 | result = ICE_Interpolate(0, 255, amount / 5.0f, ICE_Interpolate_CubicIn);
81 | else
82 | result = ICE_Interpolate(0, 255, 1.0f - ((amount - 5) / 5.0f), ICE_Interpolate_CubicOut);
83 | ICE_Render_Color(ICE_Color_New(result / 5, result / 2.5f + 20, result / 1.5f + 20));
84 | amount += ICE_Game_GetDelta();
85 | if (amount >= 10.0f)
86 | amount = 0;
87 |
88 | ICE_Entity_AddAngle(ICE_Entity_Get(NULL, 0), 50 * ICE_Game_GetDelta());
89 | }
90 |
91 | void ICE_Game_Update()
92 | {
93 | Screen_Update();
94 |
95 | ICE_Debug_DrawFps(5);
96 |
97 | // Gui Resize
98 | ICE_Gui * gui_main = ICE_Gui_Get(NULL, 0);
99 | ICE_Gui_SetSize(gui_main, ICE_Vect_New(ICE_Window_GetW(), 50));
100 |
101 | DATA1 * data = ICE_Data_Get(NULL, 0);
102 | ICE_Debug_CameraControl();
103 |
104 | if (ICE_Input_Pressed(ICE_KEY_ESCAPE))
105 | {
106 | ICE_Sound_Play(0, 16);
107 | ICE_Substate_Start(&data->inventory);
108 | }
109 | if (ICE_Input_Pressed(ICE_KEY_SPACE))
110 | {
111 | ICE_Label_SetString(ICE_Label_Get(NULL, 0), "IT IS THE END OF THE WORLD");
112 | ICE_Label_SetSize(ICE_Label_Get(NULL, 0), 50);
113 | ICE_Label_SetColor(ICE_Label_Get(NULL, 0), ICE_Color_Red);
114 | ICE_Label_SetPos(ICE_Label_Get(NULL, 0), ICE_Vect_New(0, 0));
115 | }
116 | if (ICE_Input_Pressed(ICE_KEY_RETURN))
117 | ICE_Camera_SetPos(ICE_Vect_New(0, 0));
118 | }
119 |
120 | void ICE_Game_Destroy()
121 | {
122 | DATA1 * data = ICE_Data_Get(NULL, 0);
123 | ICE_State_Destroy(&data->inventory);
124 | Game_Weapon_Destroy(&data->current_weapon);
125 | }
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/weapon.c:
--------------------------------------------------------------------------------
1 | #include "weapon.h"
2 |
3 | Game_Weapon Game_Weapon_Init(ICE_String name, ICE_Float damage, ICE_Float speed, ICE_Float weight)
4 | {
5 | Game_Weapon weapon = {
6 | ICE_String_Init(name),
7 | damage,
8 | speed,
9 | weight };
10 |
11 | return weapon;
12 | }
13 |
14 | void Game_Weapon_Destroy(Game_Weapon *weapon)
15 | {
16 | ICE_String_Free(weapon->name);
17 | }
--------------------------------------------------------------------------------
/projects/Games/2DWatch/src/weapon.h:
--------------------------------------------------------------------------------
1 | #ifndef DEF_GAME_WEAPON
2 | #define DEF_GAME_WEAPON
3 |
4 | #include
5 |
6 | struct Game_Weapon
7 | {
8 |
9 | ICE_String name;
10 | ICE_Float damage;
11 | ICE_Float speed;
12 | ICE_Float weight;
13 |
14 | }; typedef struct Game_Weapon Game_Weapon;
15 |
16 |
17 | Game_Weapon Game_Weapon_Init(ICE_String name, ICE_Float damage, ICE_Float speed, ICE_Float weight);
18 | void Game_Weapon_Destroy(Game_Weapon *weapon);
19 |
20 | #endif
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/HelloWorld.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 |
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/HelloWorld.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/img/gui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/img/gui.png
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/img/ice_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/img/ice_logo.png
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/img/pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/img/pic.png
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/img/sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/img/sprite.png
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/img/widow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/img/widow.png
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/snd/explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/snd/explosion.wav
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/snd/hit.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/snd/hit.wav
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/snd/laser.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/snd/laser.wav
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/snd/music.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/snd/music.ogg
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/snd/power.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/snd/power.wav
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/ttf/FiraSans-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/ttf/FiraSans-Medium.ttf
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/ttf/SoukouMincho.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/ttf/SoukouMincho.ttf
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/res/ttf/code2000.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/HelloWorld/res/ttf/code2000.ttf
--------------------------------------------------------------------------------
/projects/Games/HelloWorld/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define ICE_CONFIG_TITLE "Hello World"
4 |
5 | void ICE_Game_Create()
6 | {
7 | ICE_Font_Load("res\\ttf\\FiraSans-Medium.ttf");
8 | ICE_LabelID nbr = ICE_Label_Create
9 | (
10 | ICE_State_Current,
11 | "Hello World",
12 | ICE_Vect_Zero,
13 | 50,
14 | ICE_LABELTYPE_WORLD
15 | );
16 | }
17 |
18 | void ICE_Game_Update()
19 | {
20 | if (ICE_Input_Pressed(ICE_KEY_ESCAPE))
21 | ICE_Input_Quit();
22 | }
23 |
24 | void ICE_Game_Destroy() {}
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/ICE_GameTemplate1.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 | src
15 |
16 |
17 | src
18 |
19 |
20 |
21 |
22 | src
23 |
24 |
25 | src
26 |
27 |
28 | src
29 |
30 |
31 |
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/ICE_GameTemplate1.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/code2000.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/code2000.ttf
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/woodenui/frame_c2_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/woodenui/frame_c2_01.png
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15.png
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15_hover.png
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15_hover_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/woodenui/plank_15_hover_pressed.png
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/res/woodenui/skull_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/ICE_GameTemplate1/res/woodenui/skull_01.png
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/button.c:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include "button.h"
4 |
5 | struct GG_Button GG_Button_Create(ICE_TextureID texture, ICE_TextureID text_hover, ICE_TextureID text_hover_clicked, ICE_Box box, ICE_StringStd string_, int size, void(*callback)(struct GG_Button*))
6 | {
7 | struct GG_Button temp = { texture, text_hover, text_hover_clicked, (ICE_GuiID)-1, (ICE_LabelID)-1, size, callback };
8 |
9 | temp.gui_object = ICE_Gui_Create(ICE_State_Current, box, ICE_GUITYPE_IMAGE);
10 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, temp.gui_object), temp.texture);
11 |
12 | temp.text = ICE_Label_Create(ICE_State_Current, string_, ICE_Vect_New(box.x + box.w / 2, box.y + box.h / 2), size, ICE_LABELTYPE_SCREEN);
13 | int heigh = ICE_Label_GetHeight(ICE_Label_Get(ICE_State_Current, temp.text));
14 | int width = ICE_Label_GetWidth(ICE_Label_Get(ICE_State_Current, temp.text));
15 | ICE_Vect pos_temp = { ICE_Label_GetX(ICE_Label_Get(ICE_State_Current, temp.text)), ICE_Label_GetY(ICE_Label_Get(ICE_State_Current, temp.text)) };
16 | ICE_Label_SetPos(ICE_Label_Get(ICE_State_Current, temp.text), ICE_Vect_New(pos_temp.x - width / 2, pos_temp.y - heigh / 2));
17 |
18 | return temp;
19 | }
20 |
21 | void GG_Button_Update(struct GG_Button * button)
22 | {
23 | if (ICE_Collision_Box_Point(ICE_Gui_GetBox(ICE_Gui_Get(ICE_State_Current, button->gui_object)), ICE_Input_MouseVector()))
24 | {
25 | if (ICE_Input_Pressed(ICE_KEY_LEFTCLICK))
26 | {
27 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, button->gui_object), button->texture_hover_clicked);
28 | button->callback(button);
29 | }
30 | else
31 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, button->gui_object), button->texture_hover);
32 | }
33 | else
34 | {
35 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, button->gui_object), button->texture);
36 | }
37 | }
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/button.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct GG_Button
4 | {
5 | ICE_TextureID texture;
6 | ICE_TextureID texture_hover;
7 | ICE_TextureID texture_hover_clicked;
8 | ICE_GuiID gui_object;
9 | ICE_LabelID text;
10 | int size;
11 | void(*callback)(struct GG_Button*);
12 | };
13 |
14 | struct GG_Button GG_Button_Create(ICE_TextureID texture, ICE_TextureID text_hover, ICE_TextureID text_hover_clicked, ICE_Box box, ICE_StringStd string_, int size, void(*callback)(struct GG_Button*));
15 | void GG_Button_Update(struct GG_Button* button);
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/config.h:
--------------------------------------------------------------------------------
1 | #ifndef $safeprojectname$_GAME_CONFIG_H
2 | #define $safeprojectname$_GAME_CONFIG_H
3 |
4 | #define ICE_CONFIG_TITLE "Skulltest"
5 | #define ICE_CONFIG_WINDOW_W 1280
6 | #define ICE_CONFIG_WINDOW_H 720
7 | #define ICE_CONFIG_FULLSCREEN 0
8 | #define ICE_CONFIG_RESIZABLE 0
9 | #define ICE_CONFIG_EDITORNAME "coldragon"
10 | #define ICE_CONFIG_PRODUCTNAME "skulltest"
11 | #define ICE_CONFIG_VSYNC 1
12 | #define ICE_CONFIG_REFRESHRATE 144
13 | #define ICE_CONFIG_WINDOW_ICON 0
14 | #define ICE_CONFIG_GAME_VERSION "0.0.1"
15 |
16 |
17 | #endif // $safeprojectname$_GAME_CONFIG_H
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "config.h"
3 | #include "button.h"
4 | #include "skull.h"
5 |
6 | ICE_TextureID texture_frame_main;
7 | ICE_GuiID gui_frame_main;
8 |
9 | ICE_TextureID texture_button;
10 | ICE_TextureID texture_button_hover;
11 | ICE_TextureID texture_button_hover_pressed;
12 |
13 | ICE_TextureID texture_skull;
14 | ICE_GuiID gui_button_skull;
15 |
16 | struct GG_Button button1;
17 | struct GG_Button button2;
18 |
19 | void GG_Button1_Action(struct GG_Button* _this)
20 | {
21 | ICE_EntityID entity_temp = ICE_Entity_Create(ICE_State_Current, ICE_Box_New(ICE_Random_Int(-ICE_Window_GetW() / 2, ICE_Window_GetW() / 2), ICE_Random_Int(-ICE_Window_GetH() / 2, ICE_Window_GetH() / 2), 64, 64));
22 | ICE_Entity_SetTexture(ICE_Entity_Get(ICE_State_Current, entity_temp), texture_skull); // Set Sprite to Entity
23 | ICE_Entity_SetFunction(ICE_Entity_Get(ICE_State_Current, entity_temp), GG_Skull_Create, GG_Skull_Update, NULL);
24 | }
25 |
26 | void GG_Button2_Action(struct GG_Button* _this)
27 | {
28 | ICE_Log_Info("Button 2");
29 | }
30 |
31 | void GG_Debug_Draw()
32 | {
33 | ICE_Debug_DrawFps(4);
34 | ICE_Debug_CameraControl();
35 | }
36 |
37 | void ICE_Game_Create()
38 | {
39 | ICE_Render_Color(ICE_Color_New(0, 64, 128));
40 | texture_frame_main = ICE_Texture_Load("res\\woodenui\\frame_c2_01.png");
41 | gui_frame_main = ICE_Gui_Create(ICE_State_Current, ICE_Box_New(0,ICE_Window_GetH()-128, ICE_Window_GetW(), 128), ICE_GUITYPE_9PATCH);
42 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, gui_frame_main), texture_frame_main);
43 |
44 | texture_button = ICE_Texture_Load("res\\woodenui\\plank_15.png");
45 | texture_button_hover = ICE_Texture_Load("res\\woodenui\\plank_15_hover.png");
46 | texture_button_hover_pressed = ICE_Texture_Load("res\\woodenui\\plank_15_hover_pressed.png");
47 |
48 | texture_skull = ICE_Texture_Load("res\\woodenui\\skull_01.png");
49 | gui_button_skull = ICE_Gui_Create(ICE_State_Current, ICE_Box_New(32, ICE_Window_GetH()-90, 50, 55), ICE_GUITYPE_IMAGE);
50 | ICE_Gui_SetTexture(ICE_Gui_Get(ICE_State_Current, gui_button_skull), texture_skull);
51 |
52 | ICE_Font_Load("res\\code2000.ttf");
53 |
54 | button1 = GG_Button_Create
55 | (
56 | texture_button,
57 | texture_button_hover,
58 | texture_button_hover_pressed,
59 | ICE_Box_New(0,0, 342, 135),
60 | "Skull",
61 | 70,
62 | GG_Button1_Action
63 | );
64 |
65 | button2 = GG_Button_Create
66 | (
67 | texture_button,
68 | texture_button_hover,
69 | texture_button_hover_pressed,
70 | ICE_Box_New(500, 190, 342, 135),
71 | "Not Skull",
72 | 70,
73 | GG_Button2_Action
74 | );
75 |
76 | ICE_Debug_CallbackDraw(GG_Debug_Draw);
77 | }
78 |
79 | void ICE_Game_Update()
80 | {
81 | if (ICE_Input_Pressed(ICE_KEY_ESCAPE))
82 | ICE_Input_Quit();
83 |
84 | GG_Button_Update(&button1);
85 | GG_Button_Update(&button2);
86 | }
87 |
88 | void ICE_Game_Destroy()
89 | {
90 |
91 | }
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/skull.c:
--------------------------------------------------------------------------------
1 | #include "skull.h"
2 |
3 | void GG_Skull_Create(ICE_Entity* this_)
4 | {
5 | struct GG_Skull_Data* D = ICE_Entity_DataAdd(this_, struct GG_Skull_Data);
6 | D->timer = 3.0f;
7 | ICE_Entity_SetAngle(this_, ICE_Random_Int(0, 360));
8 | D->speed_rotation = ICE_Random_Int(5, 15);
9 | D->direction_rotation = ICE_Random_Int(0, 1);
10 | }
11 |
12 | void GG_Skull_Update(ICE_Entity* this_)
13 | {
14 | struct GG_Skull_Data* D = ICE_Entity_DataGet(this_, 0);
15 | D->timer -= ICE_Game_GetDelta();
16 | ICE_Entity_AddAngle(this_, D->direction_rotation ? ICE_Game_GetDelta() * D->speed_rotation : -(ICE_Game_GetDelta() * D->speed_rotation));
17 | if (D->timer <= 0.0f)
18 | ICE_Entity_Destroy(this_);
19 | }
--------------------------------------------------------------------------------
/projects/Games/ICE_GameTemplate1/src/skull.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | ///////////// SKULL ENTITY ////////////////
5 |
6 | struct GG_Skull_Data
7 | {
8 | ICE_Float timer;
9 | ICE_Float speed_rotation;
10 | ICE_Bool direction_rotation;
11 | };
12 |
13 | void GG_Skull_Create(ICE_Entity* this_);
14 | void GG_Skull_Update(ICE_Entity* this_);
--------------------------------------------------------------------------------
/projects/Games/Test/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 | src
15 |
16 |
17 | src
18 |
19 |
20 | src
21 |
22 |
23 | src
24 |
25 |
26 |
27 |
28 | src
29 |
30 |
31 | src
32 |
33 |
34 | src
35 |
36 |
37 | src
38 |
39 |
40 | src
41 |
42 |
43 | src
44 |
45 |
46 |
--------------------------------------------------------------------------------
/projects/Games/Test/Test.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/000-WINDOW_ICON:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/000-WINDOW_ICON
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/001-SPRITESHEET:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/001-SPRITESHEET
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/002-ICONS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/002-ICONS
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/003-GUI:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/003-GUI
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/004-ITEMS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/004-ITEMS
--------------------------------------------------------------------------------
/projects/Games/Test/res/img/005-BACKGROUND:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/img/005-BACKGROUND
--------------------------------------------------------------------------------
/projects/Games/Test/res/pak/pak1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/pak/pak1.zip
--------------------------------------------------------------------------------
/projects/Games/Test/res/snd/001-MUSIC:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/snd/001-MUSIC
--------------------------------------------------------------------------------
/projects/Games/Test/res/snd/001-SOUND:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/snd/001-SOUND
--------------------------------------------------------------------------------
/projects/Games/Test/res/ttf/001-FONT:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitsycore/c-ice/d4bdc782129c4b7aafa5e722d7d1022a837a9d09/projects/Games/Test/res/ttf/001-FONT
--------------------------------------------------------------------------------
/projects/Games/Test/src/config.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_CONFIG_H
2 | #define GAME_CONFIG_H
3 |
4 | #define ICE_CONFIG_EDITORNAME "coldragon"
5 | #define ICE_CONFIG_PRODUCTNAME "test"
6 | #define ICE_CONFIG_TITLE "Test"
7 | #define ICE_CONFIG_WINDOW_W 1280
8 | #define ICE_CONFIG_WINDOW_H 720
9 | //#define ICE_CONFIG_WINDOW_ICON "res//img//000-WINDOW_ICON"
10 | #define ICE_CONFIG_RESIZABLE 1
11 | #define ICE_CONFIG_VSYNC 1
12 | #define ICE_CONFIG_GAME_VERSION "0.1a"
13 |
14 | #endif
--------------------------------------------------------------------------------
/projects/Games/Test/src/control.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "game.h"
3 | #include "projectile.h"
4 | #include "player.h"
5 |
6 | void GAME_Control()
7 | {
8 | GAME_DATA * D = ICE_Data_Get(NULL, 0);
9 | ICE_Entity * player = ICE_Entity_Get(NULL, D->player);
10 | GAME_DATA_PLAYER * D_player = ICE_Entity_DataGet(player, 0);
11 | ICE_Gui_SetSize(ICE_Gui_Get(NULL, D->rectangle), ICE_Vect_New(ICE_Window_GetW(), 64));
12 | if (ICE_Entity_GetSpriteFrame(player) == D_player->frame_down)
13 | {
14 | D_player->dx = 0;
15 | D_player->dy = 1;
16 | }
17 | if (ICE_Entity_GetSpriteFrame(player) == D_player->frame_up)
18 | {
19 | D_player->dx = 0;
20 | D_player->dy = -1;
21 | }
22 | if (ICE_Entity_GetSpriteFrame(player) == D_player->frame_left)
23 | {
24 | D_player->dx = -1;
25 | D_player->dy = 0;
26 | }
27 | if (ICE_Entity_GetSpriteFrame(player) == D_player->frame_right)
28 | {
29 | D_player->dx = 1;
30 | D_player->dy = 0;
31 | }
32 | if (ICE_Input_Pressed(ICE_KEY_D))
33 | {
34 | ICE_Entity_ShiftPos(player, D_player->speed * ICE_Game_GetDelta(), 0);
35 | ICE_Entity_SetSpriteFrame(player, D_player->frame_right);
36 | D_player->dx = 1;
37 | }
38 | if (ICE_Input_Pressed(ICE_KEY_A))
39 | {
40 | ICE_Entity_ShiftPos(player, -D_player->speed * ICE_Game_GetDelta(), 0);
41 | ICE_Entity_SetSpriteFrame(player, D_player->frame_left);
42 | D_player->dx = -1;
43 | }
44 | if (ICE_Input_Pressed(ICE_KEY_W))
45 | {
46 | ICE_Entity_ShiftPos(player, 0, -D_player->speed * ICE_Game_GetDelta());
47 | ICE_Entity_SetSpriteFrame(player, D_player->frame_up);
48 | D_player->dy = -1;
49 | }
50 | if (ICE_Input_Pressed(ICE_KEY_S))
51 | {
52 | ICE_Entity_ShiftPos(player, 0, D_player->speed * ICE_Game_GetDelta());
53 | ICE_Entity_SetSpriteFrame(player, D_player->frame_down);
54 | D_player->dy = 1;
55 | }
56 |
57 | if (ICE_Input_OnPress(ICE_KEY_RETURN))
58 | {
59 | ICE_Vect vect = ICE_Entity_GetPosition(player);
60 | const ICE_Box box = { vect.x, vect.y, 32, 32 };
61 | ICE_Entity * fireball = ICE_Entity_Get(NULL, ICE_Entity_Create(NULL, box));
62 | ICE_Entity_SetFunction(fireball, GAME_Projectile_Create, GAME_Projectile_Update, GAME_Projectile_Destroy);
63 | }
64 |
65 | if (ICE_Input_Pressed(ICE_KEY_KP_PLUS))
66 | {
67 | D_player->size_text++;
68 |
69 | if (D_player->size_text > 255)
70 | D_player->size_text = 255;
71 |
72 | ICE_Label_SetSize(ICE_Label_Get(NULL, D->hello_world), D_player->size_text);
73 | }
74 |
75 | if (ICE_Input_Pressed(ICE_KEY_KP_MINUS))
76 | {
77 | D_player->size_text--;
78 |
79 | if (D_player->size_text < 1)
80 | D_player->size_text = 1;
81 |
82 | ICE_Label_SetSize(ICE_Label_Get(NULL, D->hello_world), D_player->size_text);
83 | }
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/projects/Games/Test/src/control.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_CONTROL_H
2 | #define GAME_CONTROL_H
3 |
4 | void GAME_Control();
5 |
6 | #endif
--------------------------------------------------------------------------------
/projects/Games/Test/src/debug.c:
--------------------------------------------------------------------------------
1 | #include "debug.h"
2 | #include "ICE.h"
3 | #include "game.h"
4 |
5 | void GAME_Debug_LateDraw()
6 | {
7 | GAME_DATA * D = ICE_Data_Get(ICE_State_Current, 0);
8 |
9 | ICE_Debug_FontDraw(4, "%s Test", ICE_VERSION);
10 | ICE_Debug_DrawFps(5);
11 |
12 | if(D->screenShotDraw)
13 | #
14 | ICE_Debug_FontDraw(3, "Screenshot %s saved", D->screenshot_name);
15 | }
16 |
--------------------------------------------------------------------------------
/projects/Games/Test/src/debug.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_DEBUG_H
2 | #define GAME_DEBUG_H
3 |
4 | void GAME_Debug_LateDraw();
5 |
6 | #endif
--------------------------------------------------------------------------------
/projects/Games/Test/src/game.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_H
2 | #define GAME_H
3 |
4 | typedef struct
5 | {
6 | //Assets
7 | ICE_TextureID texture_tileset, texture_gui, texture_background, texture_items_spritesheet, texture_gui_icons;
8 | ICE_FontID font;
9 | ICE_SpriteID sprite_player;
10 | ICE_SpriteID items_sprite;
11 | ICE_MusicID main_theme;
12 | ICE_SoundID explosion;
13 |
14 | //GameObject
15 |
16 | ICE_GuiID rectangle;
17 | ICE_LabelID hello_world;
18 | ICE_EntityID player;
19 |
20 |
21 | ICE_Bool screenShotDraw : 1;
22 | ICE_String screenshot_name;
23 |
24 | } GAME_DATA;
25 |
26 | #endif
--------------------------------------------------------------------------------
/projects/Games/Test/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "config.h"
4 | #include "game.h"
5 | #include "player.h"
6 | #include "debug.h"
7 |
8 | void ICE_Game_Create()
9 | {
10 | // Data
11 | GAME_DATA * D = ICE_Data_Insert(ICE_State_Current, GAME_DATA);
12 |
13 | // Pack Load
14 | ICE_AssetPak_Load("res\\pak\\pak1.zip");
15 |
16 | // Texture Load
17 | D->texture_tileset = ICE_Texture_Load("res://001-SPRITESHEET$CoLdRaGoN");
18 | D->texture_gui_icons = ICE_Texture_Load("res://002-ICONS$CoLdRaGoN");
19 | D->texture_gui = ICE_Texture_Load("res://003-GUI$CoLdRaGoN");
20 | D->texture_items_spritesheet = ICE_Texture_Load("res://004-ITEMS");
21 | D->texture_background = ICE_Texture_Load("res://005-BACKGROUND$CoLdRaGoN");
22 |
23 | // Sprite Load
24 | D->sprite_player = ICE_Sprite_Load(D->texture_tileset, ICE_Vect_New(64, 64));
25 |
26 | // Sound & Music Load
27 | D->main_theme = ICE_Music_Load("res//snd//001-MUSIC");
28 | D->explosion = ICE_Sound_Load("res//snd//001-SOUND");
29 |
30 | // Font Load
31 | D->font = ICE_Font_Load("res//ttf//001-FONT");
32 |
33 | // GUI Create
34 | D->rectangle = ICE_Gui_Create(NULL, ICE_Box_New(0, 0, 0, 64), ICE_GUITYPE_9PATCH);
35 | ICE_Gui_SetTexture(ICE_Gui_Get(NULL, D->rectangle), D->texture_gui);
36 |
37 | // Background create
38 | ICE_Entity_SetTexture(ICE_Entity_Get(NULL, ICE_Entity_Create(NULL, ICE_Box_New(0, 0, 1920, 1920))), D->texture_background);
39 |
40 | // Music Start
41 | ICE_Music_Play(0, 0.05);
42 |
43 | // Player Init
44 | GAME_Player_Init();
45 |
46 | // Debug Init
47 | ICE_Debug_CallbackDraw(GAME_Debug_LateDraw);
48 | }
49 |
50 | void ICE_Game_Update()
51 | {
52 | GAME_DATA * D = ICE_Data_Get(ICE_State_Current, 0);
53 |
54 | ICE_String temp = ICE_String_Init("");
55 | static ICE_Float timer_screenshot_value = 0.0;
56 |
57 | if(ICE_Input_OnPress(ICE_KEY_L))
58 | {
59 | ICE_EntityID entity_temp = ICE_Entity_Create(ICE_State_Current, ICE_Box_New(ICE_Random_Int(-500, 500), ICE_Random_Int(-500, 500), 64, 64));
60 | ICE_Entity_SetSprite(ICE_Entity_Get(NULL, entity_temp), D->sprite_player); // Set Sprite to Entity
61 | ICE_Entity_SetSpriteFrame(ICE_Entity_Get(NULL, entity_temp), 10); // Select Frame
62 | }
63 |
64 | if(ICE_Input_OnPress(ICE_KEY_K))
65 | {
66 | ICE_Screenshot(NULL, "png");
67 |
68 | timer_screenshot_value = 3.0;
69 | D->screenShotDraw = ICE_True;
70 |
71 | if(D->screenshot_name == 0)
72 | D->screenshot_name = ICE_String_Init("Screenshot taken ! %ld", ICE_Time_GetMS());
73 | }
74 | if(D->screenShotDraw == ICE_True)
75 | {
76 | if(timer_screenshot_value > 0)
77 | {
78 | timer_screenshot_value -= ICE_Game_GetDelta();
79 | }
80 | else
81 | {
82 | D->screenShotDraw = ICE_False;
83 | ICE_String_Destroy(&D->screenshot_name);
84 | }
85 | }
86 |
87 | ICE_String_Free(temp);
88 | }
89 |
90 | void ICE_Game_Destroy()
91 | {
92 | ICE_AssetPak_Unload("res//pak//pak1.zip");
93 | GAME_DATA * D = ICE_Data_Get(ICE_State_Current, 0);
94 | ICE_String_Destroy(&D->screenshot_name);
95 | }
--------------------------------------------------------------------------------
/projects/Games/Test/src/player.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "player.h"
3 | #include "game.h"
4 | #include "control.h"
5 |
6 | void GAME_Player_Create(ICE_Entity* this_)
7 | {
8 | GAME_DATA * D = ICE_Data_Get(NULL, 0);
9 | GAME_DATA_PLAYER * D_player = ICE_Entity_DataAdd(ICE_Entity_Get(NULL, D->player), GAME_DATA_PLAYER);
10 |
11 | D_player->speed = 190;
12 | D_player->frame_down = 53;
13 | D_player->frame_up = 56;
14 | D_player->frame_left = 82;
15 | D_player->frame_right = 79;
16 | D_player->size_text = 25;
17 | D_player->name = ICE_String_Init("***REMOVED***");
18 |
19 | ICE_Entity_SetSprite(ICE_Entity_Get(NULL, D->player), D->sprite_player); // Set Sprite to Entity
20 | ICE_Entity_SetSpriteFrame(ICE_Entity_Get(NULL, D->player), D_player->frame_down); // Select Frame
21 |
22 | D->hello_world = ICE_Label_Create(NULL, D_player->name, ICE_Vect_New(0, 0), D_player->size_text, ICE_LABELTYPE_WORLD);
23 | ICE_Label_SetString(ICE_Label_Get(NULL, D->hello_world), D_player->name);
24 | }
25 |
26 | void GAME_Player_Update(ICE_Entity* this_)
27 | {
28 | GAME_DATA * D = ICE_Data_Get(NULL, 0);
29 | ICE_Vect vect = ICE_Entity_GetPosition(ICE_Entity_Get(NULL, D->player));
30 | vect.y -= 50;
31 | ICE_Label_SetPos(ICE_Label_Get(NULL, D->hello_world), vect);
32 |
33 | GAME_Control();
34 | }
35 |
36 | void GAME_Player_Destroy(ICE_Entity* this_)
37 | {
38 | GAME_DATA_PLAYER * D_player = ICE_Entity_DataGet(this_, 0);
39 | ICE_String_Free(D_player->name);
40 | }
41 |
42 | void GAME_Player_Init()
43 | {
44 | GAME_DATA * D = ICE_Data_Get(NULL, 0);
45 | D->player = ICE_Entity_Create(NULL, ICE_Box_New(0, 0, 64, 64));
46 | ICE_Entity_SetFunction(ICE_Entity_Get(NULL, D->player), GAME_Player_Create, GAME_Player_Update, GAME_Player_Destroy);
47 | }
48 |
--------------------------------------------------------------------------------
/projects/Games/Test/src/player.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_PLAYER_H
2 | #define GAME_PLAYER_H
3 | #include
4 |
5 | typedef struct
6 | {
7 | ICE_EntityID id;
8 | ICE_Float speed;
9 | int dx, dy;
10 |
11 | ICE_ID frame_up, frame_down,
12 | frame_left, frame_right;
13 |
14 | int size_text;
15 | ICE_String name;
16 |
17 | } GAME_DATA_PLAYER;
18 |
19 | void GAME_Player_Init();
20 |
21 | #endif
--------------------------------------------------------------------------------
/projects/Games/Test/src/projectile.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "projectile.h"
4 | #include "game.h"
5 | #include "player.h"
6 |
7 | void GAME_Projectile_Create(ICE_Entity * this_)
8 | {
9 | GAME_DATA * D = ICE_Data_Get(NULL, 0);
10 | GAME_DATA_PROJECTILE * D_entity = ICE_Entity_DataAdd(this_, GAME_DATA_PROJECTILE);
11 | ICE_Entity * player = ICE_Entity_Get(NULL, D->player);
12 | GAME_DATA_PLAYER * D_player = ICE_Entity_DataGet(player, 0);
13 |
14 | ICE_Entity_SetSprite(this_, D->sprite_player);
15 | ICE_Entity_SetSpriteFrame(this_, 39);
16 | ICE_Sound_Play(D->explosion, 0.105);
17 | D_entity->speed = 600;
18 | D_entity->speedDiag = sqrt((D_entity->speed*D_entity->speed) / 2);
19 | D_entity->dx = D_player->dx;
20 | D_entity->dy = D_player->dy;
21 | D_entity->timer = 1.500;
22 | }
23 |
24 | void GAME_Projectile_Update(ICE_Entity * this_)
25 | {
26 | GAME_DATA_PROJECTILE * D_entity = ICE_Entity_DataGet(this_, 0);
27 |
28 | if(D_entity->dx != 0 && D_entity->dy != 0)
29 | ICE_Entity_ShiftPos(
30 | this_,
31 | D_entity->dx * D_entity->speedDiag * ICE_Game_GetDelta(),
32 | D_entity->dy * D_entity->speedDiag * ICE_Game_GetDelta()
33 | );
34 | else
35 | ICE_Entity_ShiftPos(
36 | this_,
37 | D_entity->dx * D_entity->speed * ICE_Game_GetDelta(),
38 | D_entity->dy * D_entity->speed * ICE_Game_GetDelta()
39 | );
40 |
41 | D_entity->timer -= ICE_Game_GetDelta();
42 |
43 | if (D_entity->timer < 0)
44 | ICE_Entity_Destroy(this_);
45 | }
46 |
47 | void GAME_Projectile_Destroy(ICE_Entity * this_)
48 | {
49 | ICE_Log(ICE_LOGTYPE_SUCCES, "Destroy Entity %d (Projectile)", ICE_Entity_GetID(this_), ICE_State_CurrentName());
50 | }
--------------------------------------------------------------------------------
/projects/Games/Test/src/projectile.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_PROJECTILE_H
2 | #define GAME_PROJECTILE_H
3 |
4 | typedef struct
5 | {
6 | int dx, dy;
7 | ICE_Float speed;
8 | ICE_Float speedDiag;
9 | ICE_Float timer;
10 |
11 | } GAME_DATA_PROJECTILE;
12 |
13 |
14 | void GAME_Projectile_Create(ICE_Entity * this_);
15 | void GAME_Projectile_Update(ICE_Entity * this_);
16 | void GAME_Projectile_Destroy(ICE_Entity * this_);
17 |
18 | #endif
--------------------------------------------------------------------------------
/projects/Tools/bin2c/bin2c.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 |
--------------------------------------------------------------------------------
/projects/Tools/bin2c/bin2c.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/projects/Tools/bin2c/src/bin2c.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This is bin2c program, which allows you to convert binary file to
3 | * C language array, for use as embedded resource, for instance you can
4 | * embed graphics or audio file directly into your program.
5 | * This is public domain software, use it on your own risk.
6 | * Contact Serge Fukanchik at fuxx@mail.ru if you have any questions.
7 | *
8 | * Some modifications were made by Gwilym Kuiper (kuiper.gwilym@gmail.com)
9 | * I have decided not to change the licence.
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #ifdef USE_BZ2
18 | #include "bzlib.h"
19 | #endif
20 |
21 | int
22 | main(int argc, char *argv[])
23 | {
24 | char *buf;
25 | char *ident;
26 | unsigned int i, file_size, need_comma;
27 |
28 | FILE *f_input, *f_output;
29 |
30 | #ifdef USE_BZ2
31 | char *bz2_buf;
32 | unsigned int uncompressed_size, bz2_size;
33 | #endif
34 |
35 | if (argc < 4) {
36 | fprintf(stderr, "Usage: %s binary_file output_file array_name\n",
37 | argv[0]);
38 | return -1;
39 | }
40 |
41 | f_input = fopen(argv[1], "rb");
42 | if (f_input == NULL) {
43 | fprintf(stderr, "%s: can't open %s for reading\n", argv[0], argv[1]);
44 | return -1;
45 | }
46 |
47 | // Get the file length
48 | fseek(f_input, 0, SEEK_END);
49 | file_size = ftell(f_input);
50 | fseek(f_input, 0, SEEK_SET);
51 |
52 | buf = (char *) malloc(file_size);
53 | assert(buf);
54 |
55 | fread(buf, file_size, 1, f_input);
56 | fclose(f_input);
57 |
58 | #ifdef USE_BZ2
59 | // allocate for bz2.
60 | bz2_size =
61 | (file_size + file_size / 100 + 1) + 600; // as per the documentation
62 |
63 | bz2_buf = (char *) malloc(bz2_size);
64 | assert(bz2_buf);
65 |
66 | // compress the data
67 | int status =
68 | BZ2_bzBuffToBuffCompress(bz2_buf, &bz2_size, buf, file_size, 9, 1, 0);
69 |
70 | if (status != BZ_OK) {
71 | fprintf(stderr, "Failed to compress data: error %i\n", status);
72 | return -1;
73 | }
74 |
75 | // and be very lazy
76 | free(buf);
77 | uncompressed_size = file_size;
78 | file_size = bz2_size;
79 | buf = bz2_buf;
80 | #endif
81 |
82 | f_output = fopen(argv[2], "w");
83 | if (f_output == NULL) {
84 | fprintf(stderr, "%s: can't open %s for writing\n", argv[0], argv[1]);
85 | return -1;
86 | }
87 |
88 | ident = argv[3];
89 |
90 | need_comma = 0;
91 |
92 | fprintf(f_output, "const char %s[%i] = {", ident, file_size);
93 | for (i = 0; i < file_size; ++i) {
94 | if (need_comma)
95 | fprintf(f_output, ", ");
96 | else
97 | need_comma = 1;
98 | if ((i % 11) == 0)
99 | fprintf(f_output, "\n\t");
100 | fprintf(f_output, "0x%.2x", buf[i] & 0xff);
101 | }
102 | fprintf(f_output, "\n};\n\n");
103 |
104 | fprintf(f_output, "const int %s_length = %i;\n", ident, file_size);
105 |
106 | #ifdef USE_BZ2
107 | fprintf(f_output, "const int %s_length_uncompressed = %i;\n", ident,
108 | uncompressed_size);
109 | #endif
110 |
111 | fclose(f_output);
112 |
113 | return 0;
114 | }
115 |
--------------------------------------------------------------------------------
/projects/UT/String/UT_String.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
14 |
--------------------------------------------------------------------------------
/projects/UT/String/UT_String.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/script/cmake/readme.md:
--------------------------------------------------------------------------------
1 |
2 | This repository contains CMake scripts for finding the `SDL2`, `SDL2_image` and
3 | `SDL2_ttf` libraries and headers.
4 |
5 | CMake itself comes with corresponding scripts for SDL 1.2, which hopefully in
6 | time will be updated for SDL2 and make this repo redundant. In the mean
7 | time, I'm putting them up here in case anyone else finds them useful.
8 |
9 | I've tested them on Linux and Mac OS using the Makefile and XCode targets.
10 | On Linux, you'll need the SDL2 development packages installed from your distro
11 | package manager. On Mac OS you can install the development frameworks
12 | from the SDL website or alternatively, if you use Homebrew you can run
13 | `brew install sdl2` to install the development packages.
14 |
15 | ## Usage
16 |
17 | ### General
18 |
19 | In order to use these scripts, you first need to tell CMake where to find them, via
20 | the `CMAKE_MODULE_PATH` variable. For example, if you put them in a
21 | subdirectory called `cmake`, then in your root `CMakeLists.txt` add the line
22 |
23 | ```cmake
24 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${project_SOURCE_DIR}/cmake")
25 | ```
26 |
27 | where `project` is the name of your project. You can then use the packages
28 | themselves by adding
29 |
30 | ```cmake
31 | find_package(SDL2 REQUIRED)
32 | find_package(SDL2_image REQUIRED)
33 | find_package(SDL2_ttf REQUIRED)
34 |
35 | include_directories(${SDL2_INCLUDE_DIR}
36 | ${SDL2_IMAGE_INCLUDE_DIR}
37 | ${SDL2_TTF_INCLUDE_DIR})
38 | target_link_libraries(target ${SDL2_LIBRARY}
39 | ${SDL2_IMAGE_LIBRARIES}
40 | ${SDL2_TTF_LIBRARIES})
41 |
42 | ```
43 |
44 | or whatever is appropriate for your project.
45 |
46 | ### mingw32 / msys
47 |
48 | This section supplements ```Usage -> General``` section. You still are required
49 | to incorporate ```General``` configuration settings in you CMakeLists.txt.
50 |
51 | Because cmake binaries for windows aren't aware of *nix/win paths conversion,
52 | default paths FindSDL2 will look in won't do any good. For that you should set SDL2_PATH variable.
53 | For example:
54 | ```cmake
55 | set(SDL2_PATH "D:\\apps\\SDL2\\i686-w64-mingw32")
56 | ```
57 |
58 | ```bash
59 | mkdir build
60 | cd build
61 | cmake .. -G"MSYS Makefiles"
62 | make
63 | ```
64 |
65 |
66 | ## Licence
67 |
68 | I am not the original author of these scripts. I found `FindSDL2.cmake`
69 | after some Googling, and hacked up the `image` and `ttf` scripts from the
70 | SDL1 versions that come with CMake. The original scripts, and my changes,
71 | are released under the two-clause BSD licence.
72 |
73 | ## Bugs
74 |
75 | These scripts are provided in the hope that you might find them useful. They
76 | work for me and hopefully they'll work for you too. If you fix any
77 | issues with them then I'd appreciate a pull request so other
78 | users can get your fixes too, but that's up to you :-).
79 |
80 |
81 |
--------------------------------------------------------------------------------
/script/sdl2_downloader_apt.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | sudo apt-get update
4 | sudo -E apt-get -yq --no-install-suggests --no-install-recommends install libsdl2-dev libsdl2-mixer-dev libsdl2-ttf-dev
--------------------------------------------------------------------------------