From 477ea4d6606aa4659549f786935096942f187b37 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 12 Mar 2019 16:00:26 +0100 Subject: Support external config flags --- src/utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index b31ce6ae..6b174354 100644 --- a/src/utils.c +++ b/src/utils.c @@ -30,9 +30,13 @@ * **********************************************************************************************/ -#include "config.h" - #include "raylib.h" // WARNING: Required for: LogType enum + +// Check if config flags have been externally provided on compilation line +#if !defined(EXTERNAL_CONFIG_FLAGS) + #include "config.h" // Defines module configuration flags +#endif + #include "utils.h" #if defined(PLATFORM_ANDROID) -- cgit v1.2.3 From f21761fbbb02f0b58b5b54342f0c3ad3abc0003e Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 7 Apr 2019 17:49:12 +0200 Subject: Happy new year 2019 --- examples/Makefile | 2 +- examples/audio/audio_raw_stream.c | 2 +- examples/models/models_obj_viewer.c | 2 +- examples/others/rlgl_standalone.c | 2 +- games/Makefile | 2 +- games/cat_vs_roomba/Makefile | 2 +- games/cat_vs_roomba/roomba.c | 2 +- games/cat_vs_roomba/screens/screen_ending.c | 2 +- games/cat_vs_roomba/screens/screen_gameplay.c | 2 +- games/cat_vs_roomba/screens/screen_logo.c | 2 +- games/cat_vs_roomba/screens/screen_title.c | 2 +- games/cat_vs_roomba/screens/screens.h | 2 +- games/drturtle/Makefile | 2 +- games/just_do/Makefile | 2 +- games/koala_seasons/Makefile | 2 +- games/light_my_ritual/Makefile | 2 +- games/skully_escape/Makefile | 2 +- games/transmission/Makefile | 2 +- games/transmission/screens/screen_ending.c | 2 +- games/transmission/screens/screen_gameplay.c | 2 +- games/transmission/screens/screen_logo.c | 2 +- games/transmission/screens/screen_mission.c | 2 +- games/transmission/screens/screen_title.c | 2 +- games/transmission/screens/screens.h | 2 +- games/transmission/transmission.c | 2 +- games/wave_collector/Makefile | 2 +- projects/VSCode/Makefile | 2 +- src/Makefile | 2 +- src/core.c | 2 +- src/gestures.h | 2 +- src/models.c | 2 +- src/raylib.h | 2 +- src/rglfw.c | 2 +- src/rlgl.h | 2 +- src/shapes.c | 2 +- src/text.c | 2 +- src/textures.c | 2 +- src/utils.c | 2 +- src/utils.h | 2 +- templates/advance_game/Makefile | 2 +- templates/advance_game/advance_game.c | 2 +- templates/advance_game/screens/screen_ending.c | 2 +- templates/advance_game/screens/screen_gameplay.c | 2 +- templates/advance_game/screens/screen_logo.c | 2 +- templates/advance_game/screens/screen_options.c | 2 +- templates/advance_game/screens/screen_title.c | 2 +- templates/advance_game/screens/screens.h | 2 +- templates/simple_game/Makefile | 2 +- templates/simple_game/simple_game.c | 2 +- templates/standard_game/Makefile | 2 +- templates/standard_game/screens/screen_ending.c | 2 +- templates/standard_game/screens/screen_gameplay.c | 2 +- templates/standard_game/screens/screen_logo.c | 2 +- templates/standard_game/screens/screen_options.c | 2 +- templates/standard_game/screens/screen_title.c | 2 +- templates/standard_game/screens/screens.h | 2 +- templates/standard_game/standard_game.c | 2 +- 57 files changed, 57 insertions(+), 57 deletions(-) (limited to 'src/utils.c') diff --git a/examples/Makefile b/examples/Makefile index e14762b3..b35e39f9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/examples/audio/audio_raw_stream.c b/examples/audio/audio_raw_stream.c index 7eee46f6..d7fa5d79 100644 --- a/examples/audio/audio_raw_stream.c +++ b/examples/audio/audio_raw_stream.c @@ -7,7 +7,7 @@ * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2015-2018 Ramon Santamaria (@raysan5) and James Hofmann (@triplefox) +* Copyright (c) 2015-2019 Ramon Santamaria (@raysan5) and James Hofmann (@triplefox) * ********************************************************************************************/ diff --git a/examples/models/models_obj_viewer.c b/examples/models/models_obj_viewer.c index 0581df34..7d387441 100644 --- a/examples/models/models_obj_viewer.c +++ b/examples/models/models_obj_viewer.c @@ -5,7 +5,7 @@ * This example has been created using raylib 2.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/others/rlgl_standalone.c b/examples/others/rlgl_standalone.c index 4b262bbd..42aec2e2 100644 --- a/examples/others/rlgl_standalone.c +++ b/examples/others/rlgl_standalone.c @@ -24,7 +24,7 @@ * This example is licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software: * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/Makefile b/games/Makefile index 5d60f15d..44e053c6 100644 --- a/games/Makefile +++ b/games/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/Makefile b/games/cat_vs_roomba/Makefile index 6662a6be..b1304656 100644 --- a/games/cat_vs_roomba/Makefile +++ b/games/cat_vs_roomba/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/roomba.c b/games/cat_vs_roomba/roomba.c index 0d236775..eeee7a71 100644 --- a/games/cat_vs_roomba/roomba.c +++ b/games/cat_vs_roomba/roomba.c @@ -8,7 +8,7 @@ * This game has been created using raylib (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/games/cat_vs_roomba/screens/screen_ending.c b/games/cat_vs_roomba/screens/screen_ending.c index ef2a5f74..466d9b91 100644 --- a/games/cat_vs_roomba/screens/screen_ending.c +++ b/games/cat_vs_roomba/screens/screen_ending.c @@ -4,7 +4,7 @@ * * Ending Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/screens/screen_gameplay.c b/games/cat_vs_roomba/screens/screen_gameplay.c index 49a0bb6b..4dd13856 100644 --- a/games/cat_vs_roomba/screens/screen_gameplay.c +++ b/games/cat_vs_roomba/screens/screen_gameplay.c @@ -4,7 +4,7 @@ * * Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/screens/screen_logo.c b/games/cat_vs_roomba/screens/screen_logo.c index 9fc704c7..a697013e 100644 --- a/games/cat_vs_roomba/screens/screen_logo.c +++ b/games/cat_vs_roomba/screens/screen_logo.c @@ -4,7 +4,7 @@ * * Logo Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/screens/screen_title.c b/games/cat_vs_roomba/screens/screen_title.c index 009fbd0a..6acadce5 100644 --- a/games/cat_vs_roomba/screens/screen_title.c +++ b/games/cat_vs_roomba/screens/screen_title.c @@ -4,7 +4,7 @@ * * Title Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/cat_vs_roomba/screens/screens.h b/games/cat_vs_roomba/screens/screens.h index 9cc07eab..0ad4f9af 100644 --- a/games/cat_vs_roomba/screens/screens.h +++ b/games/cat_vs_roomba/screens/screens.h @@ -4,7 +4,7 @@ * * Screens Functions Declarations (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/drturtle/Makefile b/games/drturtle/Makefile index 8f1934b5..4cd5033e 100644 --- a/games/drturtle/Makefile +++ b/games/drturtle/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/just_do/Makefile b/games/just_do/Makefile index b6c935f6..af9b31c1 100644 --- a/games/just_do/Makefile +++ b/games/just_do/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/koala_seasons/Makefile b/games/koala_seasons/Makefile index 8482bf2d..25dbe696 100644 --- a/games/koala_seasons/Makefile +++ b/games/koala_seasons/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/light_my_ritual/Makefile b/games/light_my_ritual/Makefile index fbc34aac..3291bb3e 100644 --- a/games/light_my_ritual/Makefile +++ b/games/light_my_ritual/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/skully_escape/Makefile b/games/skully_escape/Makefile index 8875ad52..4673a549 100644 --- a/games/skully_escape/Makefile +++ b/games/skully_escape/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/Makefile b/games/transmission/Makefile index a1b7e764..f62fe080 100644 --- a/games/transmission/Makefile +++ b/games/transmission/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screen_ending.c b/games/transmission/screens/screen_ending.c index bb355b8b..0492a0cc 100644 --- a/games/transmission/screens/screen_ending.c +++ b/games/transmission/screens/screen_ending.c @@ -4,7 +4,7 @@ * * Ending Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screen_gameplay.c b/games/transmission/screens/screen_gameplay.c index ee70632a..3dfce714 100644 --- a/games/transmission/screens/screen_gameplay.c +++ b/games/transmission/screens/screen_gameplay.c @@ -4,7 +4,7 @@ * * Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screen_logo.c b/games/transmission/screens/screen_logo.c index 37543302..dc016423 100644 --- a/games/transmission/screens/screen_logo.c +++ b/games/transmission/screens/screen_logo.c @@ -4,7 +4,7 @@ * * Logo Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screen_mission.c b/games/transmission/screens/screen_mission.c index 1cd2563b..77777c73 100644 --- a/games/transmission/screens/screen_mission.c +++ b/games/transmission/screens/screen_mission.c @@ -3,7 +3,7 @@ * raylib - transmission mission * * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screen_title.c b/games/transmission/screens/screen_title.c index 2a30a6ba..e9023b08 100644 --- a/games/transmission/screens/screen_title.c +++ b/games/transmission/screens/screen_title.c @@ -3,7 +3,7 @@ * raylib - transmission mission * * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/screens/screens.h b/games/transmission/screens/screens.h index be5e31d9..49698f0d 100644 --- a/games/transmission/screens/screens.h +++ b/games/transmission/screens/screens.h @@ -4,7 +4,7 @@ * * Screens Functions Declarations (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/games/transmission/transmission.c b/games/transmission/transmission.c index 91ca28c1..9fc3d802 100644 --- a/games/transmission/transmission.c +++ b/games/transmission/transmission.c @@ -7,7 +7,7 @@ * This game has been created using raylib (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/games/wave_collector/Makefile b/games/wave_collector/Makefile index 06e74799..703383b8 100644 --- a/games/wave_collector/Makefile +++ b/games/wave_collector/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/projects/VSCode/Makefile b/projects/VSCode/Makefile index 747718fc..3cffaaba 100644 --- a/projects/VSCode/Makefile +++ b/projects/VSCode/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/src/Makefile b/src/Makefile index e2fe6c5d..0217c198 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,7 +14,7 @@ # Many thanks to Milan Nikolic (@gen2brain) for implementing Android platform pipeline. # Many thanks to Emanuele Petriglia for his contribution on GNU/Linux pipeline. # -# Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. # In no event will the authors be held liable for any damages arising from diff --git a/src/core.c b/src/core.c index b0c0658d..42db214f 100644 --- a/src/core.c +++ b/src/core.c @@ -68,7 +68,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/gestures.h b/src/gestures.h index a4546eb1..36775333 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -24,7 +24,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/models.c b/src/models.c index 7a9acdf7..07f8203b 100644 --- a/src/models.c +++ b/src/models.c @@ -17,7 +17,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/raylib.h b/src/raylib.h index dc864b8d..dade7aba 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -49,7 +49,7 @@ * raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software: * -* Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/rglfw.c b/src/rglfw.c index 853c5200..3463bb96 100644 --- a/src/rglfw.c +++ b/src/rglfw.c @@ -7,7 +7,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2017-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2017-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/rlgl.h b/src/rlgl.h index 81f39d68..3e428241 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -42,7 +42,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/shapes.c b/src/shapes.c index b7f7e3df..fbc70fc4 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -14,7 +14,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/text.c b/src/text.c index d44cdd11..cd7a6802 100644 --- a/src/text.c +++ b/src/text.c @@ -17,7 +17,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/textures.c b/src/textures.c index cd0bd208..5189b635 100644 --- a/src/textures.c +++ b/src/textures.c @@ -38,7 +38,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/utils.c b/src/utils.c index 6b174354..10cce9b9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -11,7 +11,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/src/utils.h b/src/utils.h index 08b33962..d7ab8829 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,7 +5,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/Makefile b/templates/advance_game/Makefile index 2e5d6e26..e475f72c 100644 --- a/templates/advance_game/Makefile +++ b/templates/advance_game/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/advance_game.c b/templates/advance_game/advance_game.c index 48a34f6d..3fb5d657 100644 --- a/templates/advance_game/advance_game.c +++ b/templates/advance_game/advance_game.c @@ -8,7 +8,7 @@ * This game has been created using raylib (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/templates/advance_game/screens/screen_ending.c b/templates/advance_game/screens/screen_ending.c index 66b5ddf9..62d1267a 100644 --- a/templates/advance_game/screens/screen_ending.c +++ b/templates/advance_game/screens/screen_ending.c @@ -4,7 +4,7 @@ * * Ending Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/screens/screen_gameplay.c b/templates/advance_game/screens/screen_gameplay.c index 8943adb5..8ea61491 100644 --- a/templates/advance_game/screens/screen_gameplay.c +++ b/templates/advance_game/screens/screen_gameplay.c @@ -4,7 +4,7 @@ * * Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/screens/screen_logo.c b/templates/advance_game/screens/screen_logo.c index 6282e83e..8badbf52 100644 --- a/templates/advance_game/screens/screen_logo.c +++ b/templates/advance_game/screens/screen_logo.c @@ -4,7 +4,7 @@ * * Logo Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/screens/screen_options.c b/templates/advance_game/screens/screen_options.c index dc8d74fa..4b58da13 100644 --- a/templates/advance_game/screens/screen_options.c +++ b/templates/advance_game/screens/screen_options.c @@ -4,7 +4,7 @@ * * Options Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/screens/screen_title.c b/templates/advance_game/screens/screen_title.c index 5727546a..8e74a027 100644 --- a/templates/advance_game/screens/screen_title.c +++ b/templates/advance_game/screens/screen_title.c @@ -4,7 +4,7 @@ * * Title Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/advance_game/screens/screens.h b/templates/advance_game/screens/screens.h index 4d7f9b53..7c2dfb48 100644 --- a/templates/advance_game/screens/screens.h +++ b/templates/advance_game/screens/screens.h @@ -4,7 +4,7 @@ * * Screens Functions Declarations (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/simple_game/Makefile b/templates/simple_game/Makefile index 86e0dbde..9f27a429 100644 --- a/templates/simple_game/Makefile +++ b/templates/simple_game/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/simple_game/simple_game.c b/templates/simple_game/simple_game.c index 028b1da8..8f2dc36a 100644 --- a/templates/simple_game/simple_game.c +++ b/templates/simple_game/simple_game.c @@ -8,7 +8,7 @@ * This game has been created using raylib (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/templates/standard_game/Makefile b/templates/standard_game/Makefile index b9c6c188..4333c8b8 100644 --- a/templates/standard_game/Makefile +++ b/templates/standard_game/Makefile @@ -2,7 +2,7 @@ # # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 # -# Copyright (c) 2013-2018 Ramon Santamaria (@raysan5) +# Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) # # This software is provided "as-is", without any express or implied warranty. In no event # will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screen_ending.c b/templates/standard_game/screens/screen_ending.c index 87196977..1bd5ce98 100644 --- a/templates/standard_game/screens/screen_ending.c +++ b/templates/standard_game/screens/screen_ending.c @@ -4,7 +4,7 @@ * * Ending Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screen_gameplay.c b/templates/standard_game/screens/screen_gameplay.c index 7f108265..427e5ba7 100644 --- a/templates/standard_game/screens/screen_gameplay.c +++ b/templates/standard_game/screens/screen_gameplay.c @@ -4,7 +4,7 @@ * * Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screen_logo.c b/templates/standard_game/screens/screen_logo.c index c0b60571..435ea241 100644 --- a/templates/standard_game/screens/screen_logo.c +++ b/templates/standard_game/screens/screen_logo.c @@ -4,7 +4,7 @@ * * Logo Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screen_options.c b/templates/standard_game/screens/screen_options.c index 9f6690d1..df68dd26 100644 --- a/templates/standard_game/screens/screen_options.c +++ b/templates/standard_game/screens/screen_options.c @@ -4,7 +4,7 @@ * * Options Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screen_title.c b/templates/standard_game/screens/screen_title.c index 328448ba..5bd33825 100644 --- a/templates/standard_game/screens/screen_title.c +++ b/templates/standard_game/screens/screen_title.c @@ -4,7 +4,7 @@ * * Title Screen Functions Definitions (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/screens/screens.h b/templates/standard_game/screens/screens.h index e961b533..9450c29f 100644 --- a/templates/standard_game/screens/screens.h +++ b/templates/standard_game/screens/screens.h @@ -4,7 +4,7 @@ * * Screens Functions Declarations (Init, Update, Draw, Unload) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. diff --git a/templates/standard_game/standard_game.c b/templates/standard_game/standard_game.c index 8871484e..7918562c 100644 --- a/templates/standard_game/standard_game.c +++ b/templates/standard_game/standard_game.c @@ -8,7 +8,7 @@ * This game has been created using raylib (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ -- cgit v1.2.3 From e67ebabb02c1068d6e7f5107dcff5388ede3faa5 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 23 Apr 2019 14:55:35 +0200 Subject: Support custom memory management macros Users can define their custom memory management macros. NOTE: Most external libraries support custom macros in the same way, raylib should redefine those macros to raylib ones, to unify custom memory loading. That redefinition is only implemented as example for stb_image.h in [textures] module. --- src/core.c | 24 ++--- src/models.c | 291 +++++++++++++++++++++++++++++---------------------------- src/raudio.c | 38 ++++---- src/raudio.h | 11 ++- src/raylib.h | 11 +++ src/rlgl.h | 88 ++++++++--------- src/text.c | 54 +++++------ src/textures.c | 181 ++++++++++++++++++----------------- src/utils.c | 6 +- 9 files changed, 365 insertions(+), 339 deletions(-) (limited to 'src/utils.c') diff --git a/src/core.c b/src/core.c index 6bb54c51..844994d0 100644 --- a/src/core.c +++ b/src/core.c @@ -1113,7 +1113,7 @@ void EndDrawing(void) unsigned char *screenData = rlReadScreenPixels(screenWidth, screenHeight); GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false); - free(screenData); // Free image data + RL_FREE(screenData); // Free image data } if (((gifFramesCounter/15)%2) == 1) @@ -1595,7 +1595,7 @@ void TakeScreenshot(const char *fileName) #endif ExportImage(image, path); - free(imgData); + RL_FREE(imgData); #if defined(PLATFORM_WEB) // Download file from MEMFS (emscripten memory filesystem) @@ -1742,8 +1742,8 @@ char **GetDirectoryFiles(const char *dirPath, int *fileCount) ClearDirectoryFiles(); // Memory allocation for MAX_DIRECTORY_FILES - dirFilesPath = (char **)malloc(sizeof(char *)*MAX_DIRECTORY_FILES); - for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH); + dirFilesPath = (char **)RL_MALLOC(sizeof(char *)*MAX_DIRECTORY_FILES); + for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)RL_MALLOC(sizeof(char)*MAX_FILEPATH_LENGTH); int counter = 0; struct dirent *ent; @@ -1776,9 +1776,9 @@ void ClearDirectoryFiles(void) { if (dirFilesCount > 0) { - for (int i = 0; i < dirFilesCount; i++) free(dirFilesPath[i]); + for (int i = 0; i < dirFilesCount; i++) RL_FREE(dirFilesPath[i]); - free(dirFilesPath); + RL_FREE(dirFilesPath); dirFilesCount = 0; } } @@ -1808,9 +1808,9 @@ void ClearDroppedFiles(void) { if (dropFilesCount > 0) { - for (int i = 0; i < dropFilesCount; i++) free(dropFilesPath[i]); + for (int i = 0; i < dropFilesCount; i++) RL_FREE(dropFilesPath[i]); - free(dropFilesPath); + RL_FREE(dropFilesPath); dropFilesCount = 0; } @@ -1925,7 +1925,7 @@ void OpenURL(const char *url) } else { - char *cmd = (char *)calloc(strlen(url) + 10, sizeof(char)); + char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char)); #if defined(_WIN32) sprintf(cmd, "explorer %s", url); @@ -1935,7 +1935,7 @@ void OpenURL(const char *url) sprintf(cmd, "open '%s'", url); #endif system(cmd); - free(cmd); + RL_FREE(cmd); } } @@ -3455,11 +3455,11 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths { ClearDroppedFiles(); - dropFilesPath = (char **)malloc(sizeof(char *)*count); + dropFilesPath = (char **)RL_MALLOC(sizeof(char *)*count); for (int i = 0; i < count; i++) { - dropFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH); + dropFilesPath[i] = (char *)RL_MALLOC(sizeof(char)*MAX_FILEPATH_LENGTH); strcpy(dropFilesPath[i], paths[i]); } diff --git a/src/models.c b/src/models.c index 631c4942..c81dfe19 100644 --- a/src/models.c +++ b/src/models.c @@ -651,7 +651,7 @@ Model LoadModel(const char *fileName) TraceLog(LOG_WARNING, "[%s] No meshes can be loaded, default to cube mesh", fileName); model.meshCount = 1; - model.meshes = (Mesh *)calloc(model.meshCount, sizeof(Mesh)); + model.meshes = (Mesh *)RL_CALLOC(model.meshCount, sizeof(Mesh)); model.meshes[0] = GenMeshCube(1.0f, 1.0f, 1.0f); } else @@ -665,10 +665,10 @@ Model LoadModel(const char *fileName) TraceLog(LOG_WARNING, "[%s] No materials can be loaded, default to white material", fileName); model.materialCount = 1; - model.materials = (Material *)calloc(model.materialCount, sizeof(Material)); + model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material)); model.materials[0] = LoadMaterialDefault(); - model.meshMaterial = (int *)calloc(model.meshCount, sizeof(int)); + model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); } return model; @@ -685,14 +685,14 @@ Model LoadModelFromMesh(Mesh mesh) model.transform = MatrixIdentity(); model.meshCount = 1; - model.meshes = (Mesh *)malloc(model.meshCount*sizeof(Mesh)); + model.meshes = (Mesh *)RL_MALLOC(model.meshCount*sizeof(Mesh)); model.meshes[0] = mesh; model.materialCount = 1; - model.materials = (Material *)malloc(model.materialCount*sizeof(Material)); + model.materials = (Material *)RL_MALLOC(model.materialCount*sizeof(Material)); model.materials[0] = LoadMaterialDefault(); - model.meshMaterial = (int *)malloc(model.meshCount*sizeof(int)); + model.meshMaterial = (int *)RL_MALLOC(model.meshCount*sizeof(int)); model.meshMaterial[0] = 0; // First material index return model; @@ -704,13 +704,13 @@ void UnloadModel(Model model) for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]); for (int i = 0; i < model.materialCount; i++) UnloadMaterial(model.materials[i]); - free(model.meshes); - free(model.materials); - free(model.meshMaterial); + RL_FREE(model.meshes); + RL_FREE(model.materials); + RL_FREE(model.meshMaterial); // Unload animation data - free(model.bones); - free(model.bindPose); + RL_FREE(model.bones); + RL_FREE(model.bindPose); TraceLog(LOG_INFO, "Unloaded model data from RAM and VRAM"); } @@ -866,7 +866,7 @@ void SetModelMeshMaterial(Model *model, int meshId, int materialId) // Load model animations from file ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) { - ModelAnimation *animations = (ModelAnimation *)malloc(1*sizeof(ModelAnimation)); + ModelAnimation *animations = (ModelAnimation *)RL_MALLOC(1*sizeof(ModelAnimation)); int count = 1; #define IQM_MAGIC "INTERQUAKEMODEL" // IQM file magic number @@ -935,12 +935,12 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) // bones IQMPose *poses; - poses = malloc(sizeof(IQMPose)*iqm.num_poses); + poses = RL_MALLOC(sizeof(IQMPose)*iqm.num_poses); fseek(iqmFile, iqm.ofs_poses, SEEK_SET); fread(poses, sizeof(IQMPose)*iqm.num_poses, 1, iqmFile); animation.boneCount = iqm.num_poses; - animation.bones = malloc(sizeof(BoneInfo)*iqm.num_poses); + animation.bones = RL_MALLOC(sizeof(BoneInfo)*iqm.num_poses); for (int j = 0; j < iqm.num_poses; j++) { @@ -957,12 +957,12 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) //animation.framerate = anim.framerate; // frameposes - unsigned short *framedata = malloc(sizeof(unsigned short)*iqm.num_frames*iqm.num_framechannels); + unsigned short *framedata = RL_MALLOC(sizeof(unsigned short)*iqm.num_frames*iqm.num_framechannels); fseek(iqmFile, iqm.ofs_frames, SEEK_SET); fread(framedata, sizeof(unsigned short)*iqm.num_frames*iqm.num_framechannels, 1, iqmFile); - animation.framePoses = malloc(sizeof(Transform*)*anim.num_frames); - for (int j = 0; j < anim.num_frames; j++) animation.framePoses[j] = malloc(sizeof(Transform)*iqm.num_poses); + animation.framePoses = RL_MALLOC(sizeof(Transform*)*anim.num_frames); + for (int j = 0; j < anim.num_frames; j++) animation.framePoses[j] = RL_MALLOC(sizeof(Transform)*iqm.num_poses); int dcounter = anim.first_frame*iqm.num_framechannels; @@ -1069,8 +1069,8 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) } } - free(framedata); - free(poses); + RL_FREE(framedata); + RL_FREE(poses); fclose(iqmFile); @@ -1145,10 +1145,10 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) // Unload animation data void UnloadModelAnimation(ModelAnimation anim) { - for (int i = 0; i < anim.frameCount; i++) free(anim.framePoses[i]); + for (int i = 0; i < anim.frameCount; i++) RL_FREE(anim.framePoses[i]); - free(anim.bones); - free(anim.framePoses); + RL_FREE(anim.bones); + RL_FREE(anim.framePoses); } // Check model animation skeleton match @@ -1177,7 +1177,7 @@ Mesh GenMeshPoly(int sides, float radius) int vertexCount = sides*3; // Vertices definition - Vector3 *vertices = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); + Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3)); for (int i = 0, v = 0; i < 360; i += 360/sides, v += 3) { vertices[v] = (Vector3){ 0.0f, 0.0f, 0.0f }; @@ -1186,18 +1186,18 @@ Mesh GenMeshPoly(int sides, float radius) } // Normals definition - Vector3 *normals = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); + Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3)); for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up; // TexCoords definition - Vector2 *texcoords = (Vector2 *)malloc(vertexCount*sizeof(Vector2)); + Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2)); for (int n = 0; n < vertexCount; n++) texcoords[n] = (Vector2){ 0.0f, 0.0f }; mesh.vertexCount = vertexCount; mesh.triangleCount = sides; - mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); - mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); // Mesh vertices position array for (int i = 0; i < mesh.vertexCount; i++) @@ -1222,9 +1222,9 @@ Mesh GenMeshPoly(int sides, float radius) mesh.normals[3*i + 2] = normals[i].z; } - free(vertices); - free(normals); - free(texcoords); + RL_FREE(vertices); + RL_FREE(normals); + RL_FREE(texcoords); // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); @@ -1245,7 +1245,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) // Vertices definition int vertexCount = resX*resZ; // vertices get reused for the faces - Vector3 *vertices = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); + Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3)); for (int z = 0; z < resZ; z++) { // [-length/2, length/2] @@ -1259,11 +1259,11 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) } // Normals definition - Vector3 *normals = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); + Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3)); for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up; // TexCoords definition - Vector2 *texcoords = (Vector2 *)malloc(vertexCount*sizeof(Vector2)); + Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2)); for (int v = 0; v < resZ; v++) { for (int u = 0; u < resX; u++) @@ -1274,7 +1274,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) // Triangles definition (indices) int numFaces = (resX - 1)*(resZ - 1); - int *triangles = (int *)malloc(numFaces*6*sizeof(int)); + int *triangles = (int *)RL_MALLOC(numFaces*6*sizeof(int)); int t = 0; for (int face = 0; face < numFaces; face++) { @@ -1292,10 +1292,10 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) mesh.vertexCount = vertexCount; mesh.triangleCount = numFaces*2; - mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); - mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.indices = (unsigned short *)malloc(mesh.triangleCount*3*sizeof(unsigned short)); + mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.indices = (unsigned short *)RL_MALLOC(mesh.triangleCount*3*sizeof(unsigned short)); // Mesh vertices position array for (int i = 0; i < mesh.vertexCount; i++) @@ -1323,10 +1323,10 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) // Mesh indices array initialization for (int i = 0; i < mesh.triangleCount*3; i++) mesh.indices[i] = triangles[i]; - free(vertices); - free(normals); - free(texcoords); - free(triangles); + RL_FREE(vertices); + RL_FREE(normals); + RL_FREE(texcoords); + RL_FREE(triangles); #else // Use par_shapes library to generate plane mesh @@ -1335,9 +1335,9 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) par_shapes_rotate(plane, -PI/2.0f, (float[]){ 1, 0, 0 }); par_shapes_translate(plane, -width/2, 0.0f, length/2); - mesh.vertices = (float *)malloc(plane->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(plane->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(plane->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float)); mesh.vertexCount = plane->ntriangles*3; mesh.triangleCount = plane->ntriangles; @@ -1453,16 +1453,16 @@ Mesh GenMeshCube(float width, float height, float length) -1.0f, 0.0f, 0.0f }; - mesh.vertices = (float *)malloc(24*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(24*3*sizeof(float)); memcpy(mesh.vertices, vertices, 24*3*sizeof(float)); - mesh.texcoords = (float *)malloc(24*2*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(24*2*sizeof(float)); memcpy(mesh.texcoords, texcoords, 24*2*sizeof(float)); - mesh.normals = (float *)malloc(24*3*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(24*3*sizeof(float)); memcpy(mesh.normals, normals, 24*3*sizeof(float)); - mesh.indices = (unsigned short *)malloc(36*sizeof(unsigned short)); + mesh.indices = (unsigned short *)RL_MALLOC(36*sizeof(unsigned short)); int k = 0; @@ -1500,9 +1500,9 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron par_shapes_translate(cube, -width/2, 0.0f, -length/2); par_shapes_compute_normals(cube); - mesh.vertices = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(cube->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(cube->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float)); mesh.vertexCount = cube->ntriangles*3; mesh.triangleCount = cube->ntriangles; @@ -1539,9 +1539,9 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) par_shapes_scale(sphere, radius, radius, radius); // NOTE: Soft normals are computed internally - mesh.vertices = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(sphere->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float)); mesh.vertexCount = sphere->ntriangles*3; mesh.triangleCount = sphere->ntriangles; @@ -1577,9 +1577,9 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices) par_shapes_scale(sphere, radius, radius, radius); // NOTE: Soft normals are computed internally - mesh.vertices = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(sphere->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float)); mesh.vertexCount = sphere->ntriangles*3; mesh.triangleCount = sphere->ntriangles; @@ -1635,9 +1635,9 @@ Mesh GenMeshCylinder(float radius, float height, int slices) par_shapes_merge_and_free(cylinder, capTop); par_shapes_merge_and_free(cylinder, capBottom); - mesh.vertices = (float *)malloc(cylinder->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(cylinder->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(cylinder->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(cylinder->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float)); mesh.vertexCount = cylinder->ntriangles*3; mesh.triangleCount = cylinder->ntriangles; @@ -1677,9 +1677,9 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides) par_shapes_mesh *torus = par_shapes_create_torus(radSeg, sides, radius); par_shapes_scale(torus, size/2, size/2, size/2); - mesh.vertices = (float *)malloc(torus->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(torus->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(torus->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(torus->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float)); mesh.vertexCount = torus->ntriangles*3; mesh.triangleCount = torus->ntriangles; @@ -1717,9 +1717,9 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides) par_shapes_mesh *knot = par_shapes_create_trefoil_knot(radSeg, sides, radius); par_shapes_scale(knot, size, size, size); - mesh.vertices = (float *)malloc(knot->ntriangles*3*3*sizeof(float)); - mesh.texcoords = (float *)malloc(knot->ntriangles*3*2*sizeof(float)); - mesh.normals = (float *)malloc(knot->ntriangles*3*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(knot->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float)); mesh.vertexCount = knot->ntriangles*3; mesh.triangleCount = knot->ntriangles; @@ -1764,9 +1764,9 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size) mesh.vertexCount = mesh.triangleCount*3; - mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float)); mesh.colors = NULL; int vCounter = 0; // Used to count vertices float by float @@ -1848,7 +1848,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size) } } - free(pixels); + RL_FREE(pixels); // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); @@ -1878,9 +1878,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) float h = cubeSize.z; float h2 = cubeSize.y; - Vector3 *mapVertices = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3)); - Vector2 *mapTexcoords = (Vector2 *)malloc(maxTriangles*3*sizeof(Vector2)); - Vector3 *mapNormals = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3)); + Vector3 *mapVertices = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3)); + Vector2 *mapTexcoords = (Vector2 *)RL_MALLOC(maxTriangles*3*sizeof(Vector2)); + Vector3 *mapNormals = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3)); // Define the 6 normals of the cube, we will combine them accordingly later... Vector3 n1 = { 1.0f, 0.0f, 0.0f }; @@ -2167,9 +2167,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) mesh.vertexCount = vCounter; mesh.triangleCount = vCounter/3; - mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float)); mesh.colors = NULL; int fCounter = 0; @@ -2204,11 +2204,11 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) fCounter += 2; } - free(mapVertices); - free(mapNormals); - free(mapTexcoords); + RL_FREE(mapVertices); + RL_FREE(mapNormals); + RL_FREE(mapTexcoords); - free(cubicmapPixels); // Free image pixel data + RL_FREE(cubicmapPixels); // Free image pixel data // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); @@ -2250,11 +2250,11 @@ BoundingBox MeshBoundingBox(Mesh mesh) // Implementation base don: https://answers.unity.com/questions/7789/calculating-tangents-vector4.html void MeshTangents(Mesh *mesh) { - if (mesh->tangents == NULL) mesh->tangents = (float *)malloc(mesh->vertexCount*4*sizeof(float)); + if (mesh->tangents == NULL) mesh->tangents = (float *)RL_MALLOC(mesh->vertexCount*4*sizeof(float)); else TraceLog(LOG_WARNING, "Mesh tangents already exist"); - Vector3 *tan1 = (Vector3 *)malloc(mesh->vertexCount*sizeof(Vector3)); - Vector3 *tan2 = (Vector3 *)malloc(mesh->vertexCount*sizeof(Vector3)); + Vector3 *tan1 = (Vector3 *)RL_MALLOC(mesh->vertexCount*sizeof(Vector3)); + Vector3 *tan2 = (Vector3 *)RL_MALLOC(mesh->vertexCount*sizeof(Vector3)); for (int i = 0; i < mesh->vertexCount; i += 3) { @@ -2318,8 +2318,8 @@ void MeshTangents(Mesh *mesh) #endif } - free(tan1); - free(tan2); + RL_FREE(tan1); + RL_FREE(tan2); // Load a new tangent attributes buffer mesh->vboId[LOC_VERTEX_TANGENT] = rlLoadAttribBuffer(mesh->vaoId, LOC_VERTEX_TANGENT, mesh->tangents, mesh->vertexCount*4*sizeof(float), false); @@ -2746,7 +2746,7 @@ static Model LoadOBJ(const char *fileName) long length = ftell(objFile); // Get file size fseek(objFile, 0, SEEK_SET); // Reset file pointer - data = (char *)malloc(length); + data = (char *)RL_MALLOC(length); fread(data, length, 1, objFile); dataLength = length; @@ -2763,12 +2763,12 @@ static Model LoadOBJ(const char *fileName) // Init model meshes array model.meshCount = meshCount; - model.meshes = (Mesh *)malloc(model.meshCount*sizeof(Mesh)); + model.meshes = (Mesh *)RL_MALLOC(model.meshCount*sizeof(Mesh)); // Init model materials array model.materialCount = materialCount; - model.materials = (Material *)malloc(model.materialCount*sizeof(Material)); - model.meshMaterial = (int *)calloc(model.meshCount, sizeof(int)); + model.materials = (Material *)RL_MALLOC(model.materialCount*sizeof(Material)); + model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); /* // Multiple meshes data reference @@ -2787,9 +2787,9 @@ static Model LoadOBJ(const char *fileName) memset(&mesh, 0, sizeof(Mesh)); mesh.vertexCount = attrib.num_faces*3; mesh.triangleCount = attrib.num_faces; - mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); - mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); + mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); + mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float)); + mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float)); int vCount = 0; int vtCount = 0; @@ -2934,17 +2934,26 @@ static Model LoadIQM(const char *fileName) typedef struct IQMTriangle { unsigned int vertex[3]; } IQMTriangle; - - // NOTE: Adjacency unused by default - typedef struct IQMAdjacency { - unsigned int triangle[3]; - } IQMAdjacency; - + typedef struct IQMJoint { unsigned int name; int parent; float translate[3], rotate[4], scale[3]; } IQMJoint; + + typedef struct IQMVertexArray { + unsigned int type; + unsigned int flags; + unsigned int format; + unsigned int size; + unsigned int offset; + } IQMVertexArray; + + // NOTE: Below IQM structures are not used but listed for reference + /* + typedef struct IQMAdjacency { + unsigned int triangle[3]; + } IQMAdjacency; typedef struct IQMPose { int parent; @@ -2960,19 +2969,11 @@ static Model LoadIQM(const char *fileName) unsigned int flags; } IQMAnim; - typedef struct IQMVertexArray { - unsigned int type; - unsigned int flags; - unsigned int format; - unsigned int size; - unsigned int offset; - } IQMVertexArray; - - // NOTE: Bounds unused by default typedef struct IQMBounds { float bbmin[3], bbmax[3]; float xyradius, radius; } IQMBounds; + */ //----------------------------------------------------------------------------------- // IQM vertex data types @@ -3028,12 +3029,12 @@ static Model LoadIQM(const char *fileName) } // Meshes data processing - imesh = malloc(sizeof(IQMMesh)*iqm.num_meshes); + imesh = RL_MALLOC(sizeof(IQMMesh)*iqm.num_meshes); fseek(iqmFile, iqm.ofs_meshes, SEEK_SET); fread(imesh, sizeof(IQMMesh)*iqm.num_meshes, 1, iqmFile); model.meshCount = iqm.num_meshes; - model.meshes = malloc(model.meshCount*sizeof(Mesh)); + model.meshes = RL_MALLOC(model.meshCount*sizeof(Mesh)); char name[MESH_NAME_LENGTH]; @@ -3043,24 +3044,24 @@ static Model LoadIQM(const char *fileName) fread(name, sizeof(char)*MESH_NAME_LENGTH, 1, iqmFile); // Mesh name not used... model.meshes[i].vertexCount = imesh[i].num_vertexes; - model.meshes[i].vertices = malloc(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex positions - model.meshes[i].normals = malloc(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex normals - model.meshes[i].texcoords = malloc(sizeof(float)*model.meshes[i].vertexCount*2); // Default vertex texcoords + model.meshes[i].vertices = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex positions + model.meshes[i].normals = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex normals + model.meshes[i].texcoords = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*2); // Default vertex texcoords - model.meshes[i].boneIds = malloc(sizeof(int)*model.meshes[i].vertexCount*4); // Up-to 4 bones supported! - model.meshes[i].boneWeights = malloc(sizeof(float)*model.meshes[i].vertexCount*4); // Up-to 4 bones supported! + model.meshes[i].boneIds = RL_MALLOC(sizeof(int)*model.meshes[i].vertexCount*4); // Up-to 4 bones supported! + model.meshes[i].boneWeights = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*4); // Up-to 4 bones supported! model.meshes[i].triangleCount = imesh[i].num_triangles; - model.meshes[i].indices = malloc(sizeof(unsigned short)*model.meshes[i].triangleCount*3); + model.meshes[i].indices = RL_MALLOC(sizeof(unsigned short)*model.meshes[i].triangleCount*3); // Animated verted data, what we actually process for rendering // NOTE: Animated vertex should be re-uploaded to GPU (if not using GPU skinning) - model.meshes[i].animVertices = malloc(sizeof(float)*model.meshes[i].vertexCount*3); - model.meshes[i].animNormals = malloc(sizeof(float)*model.meshes[i].vertexCount*3); + model.meshes[i].animVertices = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); + model.meshes[i].animNormals = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); } // Triangles data processing - tri = malloc(sizeof(IQMTriangle)*iqm.num_triangles); + tri = RL_MALLOC(sizeof(IQMTriangle)*iqm.num_triangles); fseek(iqmFile, iqm.ofs_triangles, SEEK_SET); fread(tri, sizeof(IQMTriangle)*iqm.num_triangles, 1, iqmFile); @@ -3079,7 +3080,7 @@ static Model LoadIQM(const char *fileName) } // Vertex arrays data processing - va = malloc(sizeof(IQMVertexArray)*iqm.num_vertexarrays); + va = RL_MALLOC(sizeof(IQMVertexArray)*iqm.num_vertexarrays); fseek(iqmFile, iqm.ofs_vertexarrays, SEEK_SET); fread(va, sizeof(IQMVertexArray)*iqm.num_vertexarrays, 1, iqmFile); @@ -3089,7 +3090,7 @@ static Model LoadIQM(const char *fileName) { case IQM_POSITION: { - vertex = malloc(sizeof(float)*iqm.num_vertexes*3); + vertex = RL_MALLOC(sizeof(float)*iqm.num_vertexes*3); fseek(iqmFile, va[i].offset, SEEK_SET); fread(vertex, sizeof(float)*iqm.num_vertexes*3, 1, iqmFile); @@ -3106,7 +3107,7 @@ static Model LoadIQM(const char *fileName) } break; case IQM_NORMAL: { - normal = malloc(sizeof(float)*iqm.num_vertexes*3); + normal = RL_MALLOC(sizeof(float)*iqm.num_vertexes*3); fseek(iqmFile, va[i].offset, SEEK_SET); fread(normal, sizeof(float)*iqm.num_vertexes*3, 1, iqmFile); @@ -3123,7 +3124,7 @@ static Model LoadIQM(const char *fileName) } break; case IQM_TEXCOORD: { - text = malloc(sizeof(float)*iqm.num_vertexes*2); + text = RL_MALLOC(sizeof(float)*iqm.num_vertexes*2); fseek(iqmFile, va[i].offset, SEEK_SET); fread(text, sizeof(float)*iqm.num_vertexes*2, 1, iqmFile); @@ -3139,7 +3140,7 @@ static Model LoadIQM(const char *fileName) } break; case IQM_BLENDINDEXES: { - blendi = malloc(sizeof(char)*iqm.num_vertexes*4); + blendi = RL_MALLOC(sizeof(char)*iqm.num_vertexes*4); fseek(iqmFile, va[i].offset, SEEK_SET); fread(blendi, sizeof(char)*iqm.num_vertexes*4, 1, iqmFile); @@ -3155,7 +3156,7 @@ static Model LoadIQM(const char *fileName) } break; case IQM_BLENDWEIGHTS: { - blendw = malloc(sizeof(unsigned char)*iqm.num_vertexes*4); + blendw = RL_MALLOC(sizeof(unsigned char)*iqm.num_vertexes*4); fseek(iqmFile,va[i].offset,SEEK_SET); fread(blendw,sizeof(unsigned char)*iqm.num_vertexes*4,1,iqmFile); @@ -3173,13 +3174,13 @@ static Model LoadIQM(const char *fileName) } // Bones (joints) data processing - ijoint = malloc(sizeof(IQMJoint)*iqm.num_joints); + ijoint = RL_MALLOC(sizeof(IQMJoint)*iqm.num_joints); fseek(iqmFile, iqm.ofs_joints, SEEK_SET); fread(ijoint, sizeof(IQMJoint)*iqm.num_joints, 1, iqmFile); model.boneCount = iqm.num_joints; - model.bones = malloc(sizeof(BoneInfo)*iqm.num_joints); - model.bindPose = malloc(sizeof(Transform)*iqm.num_joints); + model.bones = RL_MALLOC(sizeof(BoneInfo)*iqm.num_joints); + model.bindPose = RL_MALLOC(sizeof(Transform)*iqm.num_joints); for (int i = 0; i < iqm.num_joints; i++) { @@ -3216,15 +3217,15 @@ static Model LoadIQM(const char *fileName) } fclose(iqmFile); - free(imesh); - free(tri); - free(va); - free(vertex); - free(normal); - free(text); - free(blendi); - free(blendw); - free(ijoint); + RL_FREE(imesh); + RL_FREE(tri); + RL_FREE(va); + RL_FREE(vertex); + RL_FREE(normal); + RL_FREE(text); + RL_FREE(blendi); + RL_FREE(blendw); + RL_FREE(ijoint); return model; } @@ -3249,7 +3250,7 @@ static Model LoadGLTF(const char *fileName) int size = ftell(gltfFile); fseek(gltfFile, 0, SEEK_SET); - void *buffer = malloc(size); + void *buffer = RL_MALLOC(size); fread(buffer, size, 1, gltfFile); fclose(gltfFile); @@ -3259,7 +3260,7 @@ static Model LoadGLTF(const char *fileName) cgltf_data *data; cgltf_result result = cgltf_parse(&options, buffer, size, &data); - free(buffer); + RL_FREE(buffer); if (result == cgltf_result_success) { @@ -3270,7 +3271,7 @@ static Model LoadGLTF(const char *fileName) // Process glTF data and map to model model.meshCount = data->meshes_count; - model.meshes = malloc(model.meshCount*sizeof(Mesh)); + model.meshes = RL_MALLOC(model.meshCount*sizeof(Mesh)); for (int i = 0; i < model.meshCount; i++) { @@ -3282,11 +3283,11 @@ static Model LoadGLTF(const char *fileName) model.meshes[i].triangleCount = data->meshes[i].primitives_count; // data.meshes[i].weights not used (array of weights to be applied to the Morph Targets) - model.meshes[i].vertices = malloc(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex positions - model.meshes[i].normals = malloc(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex normals - model.meshes[i].texcoords = malloc(sizeof(float)*model.meshes[i].vertexCount*2); // Default vertex texcoords + model.meshes[i].vertices = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex positions + model.meshes[i].normals = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*3); // Default vertex normals + model.meshes[i].texcoords = RL_MALLOC(sizeof(float)*model.meshes[i].vertexCount*2); // Default vertex texcoords - model.meshes[i].indices = malloc(sizeof(unsigned short)*model.meshes[i].triangleCount*3); + model.meshes[i].indices = RL_MALLOC(sizeof(unsigned short)*model.meshes[i].triangleCount*3); } } diff --git a/src/raudio.c b/src/raudio.c index 636d15b8..9108a903 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -567,7 +567,7 @@ void SetMasterVolume(float volume) // Create a new audio buffer. Initially filled with silence AudioBuffer *CreateAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 bufferSizeInFrames, AudioBufferUsage usage) { - AudioBuffer *audioBuffer = (AudioBuffer *)calloc(sizeof(*audioBuffer) + (bufferSizeInFrames*channels*ma_get_bytes_per_sample(format)), 1); + AudioBuffer *audioBuffer = (AudioBuffer *)RL_CALLOC(sizeof(*audioBuffer) + (bufferSizeInFrames*channels*ma_get_bytes_per_sample(format)), 1); if (audioBuffer == NULL) { TraceLog(LOG_ERROR, "CreateAudioBuffer() : Failed to allocate memory for audio buffer"); @@ -591,7 +591,7 @@ AudioBuffer *CreateAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 s if (result != MA_SUCCESS) { TraceLog(LOG_ERROR, "CreateAudioBuffer() : Failed to create data conversion pipeline"); - free(audioBuffer); + RL_FREE(audioBuffer); return NULL; } @@ -623,7 +623,7 @@ void DeleteAudioBuffer(AudioBuffer *audioBuffer) } UntrackAudioBuffer(audioBuffer); - free(audioBuffer); + RL_FREE(audioBuffer); } // Check if an audio buffer is playing @@ -863,7 +863,7 @@ Sound LoadSoundFromWave(Wave wave) // Unload wave data void UnloadWave(Wave wave) { - if (wave.data != NULL) free(wave.data); + if (wave.data != NULL) RL_FREE(wave.data); TraceLog(LOG_INFO, "Unloaded wave data from RAM"); } @@ -1017,7 +1017,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels) return; } - void *data = malloc(frameCount*channels*(sampleSize/8)); + void *data = RL_MALLOC(frameCount*channels*(sampleSize/8)); frameCount = (ma_uint32)ma_convert_frames(data, formatOut, channels, sampleRate, wave->data, formatIn, wave->channels, wave->sampleRate, frameCountIn); if (frameCount == 0) @@ -1030,7 +1030,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels) wave->sampleSize = sampleSize; wave->sampleRate = sampleRate; wave->channels = channels; - free(wave->data); + RL_FREE(wave->data); wave->data = data; } @@ -1039,7 +1039,7 @@ Wave WaveCopy(Wave wave) { Wave newWave = { 0 }; - newWave.data = malloc(wave.sampleCount*wave.sampleSize/8*wave.channels); + newWave.data = RL_MALLOC(wave.sampleCount*wave.sampleSize/8*wave.channels); if (newWave.data != NULL) { @@ -1064,11 +1064,11 @@ void WaveCrop(Wave *wave, int initSample, int finalSample) { int sampleCount = finalSample - initSample; - void *data = malloc(sampleCount*wave->sampleSize/8*wave->channels); + void *data = RL_MALLOC(sampleCount*wave->sampleSize/8*wave->channels); memcpy(data, (unsigned char *)wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->channels*wave->sampleSize/8); - free(wave->data); + RL_FREE(wave->data); wave->data = data; } else TraceLog(LOG_WARNING, "Wave crop range out of bounds"); @@ -1078,7 +1078,7 @@ void WaveCrop(Wave *wave, int initSample, int finalSample) // NOTE: Returned sample values are normalized to range [-1..1] float *GetWaveData(Wave wave) { - float *samples = (float *)malloc(wave.sampleCount*wave.channels*sizeof(float)); + float *samples = (float *)RL_MALLOC(wave.sampleCount*wave.channels*sizeof(float)); for (unsigned int i = 0; i < wave.sampleCount; i++) { @@ -1100,7 +1100,7 @@ float *GetWaveData(Wave wave) // Load music stream from file Music LoadMusicStream(const char *fileName) { - Music music = (MusicData *)malloc(sizeof(MusicData)); + Music music = (MusicData *)RL_MALLOC(sizeof(MusicData)); bool musicLoaded = true; #if defined(SUPPORT_FILEFORMAT_OGG) @@ -1228,7 +1228,7 @@ Music LoadMusicStream(const char *fileName) if (false) {} #endif #if defined(SUPPORT_FILEFORMAT_FLAC) - else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac); + else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_RL_FREE(music->ctxFlac); #endif #if defined(SUPPORT_FILEFORMAT_MP3) else if (music->ctxType == MUSIC_AUDIO_MP3) drmp3_uninit(&music->ctxMp3); @@ -1240,7 +1240,7 @@ Music LoadMusicStream(const char *fileName) else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod); #endif - free(music); + RL_FREE(music); music = NULL; TraceLog(LOG_WARNING, "[%s] Music file could not be opened", fileName); @@ -1262,7 +1262,7 @@ void UnloadMusicStream(Music music) if (false) {} #endif #if defined(SUPPORT_FILEFORMAT_FLAC) - else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac); + else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_RL_FREE(music->ctxFlac); #endif #if defined(SUPPORT_FILEFORMAT_MP3) else if (music->ctxType == MUSIC_AUDIO_MP3) drmp3_uninit(&music->ctxMp3); @@ -1274,7 +1274,7 @@ void UnloadMusicStream(Music music) else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod); #endif - free(music); + RL_FREE(music); } // Start music playing (open stream) @@ -1357,7 +1357,7 @@ void UpdateMusicStream(Music music) unsigned int subBufferSizeInFrames = ((AudioBuffer *)music->stream.audioBuffer)->bufferSizeInFrames/2; // NOTE: Using dynamic allocation because it could require more than 16KB - void *pcm = calloc(subBufferSizeInFrames*music->stream.channels*music->stream.sampleSize/8, 1); + void *pcm = RL_CALLOC(subBufferSizeInFrames*music->stream.channels*music->stream.sampleSize/8, 1); int samplesCount = 0; // Total size of data steamed in L+R samples for xm floats, individual L or R for ogg shorts @@ -1427,7 +1427,7 @@ void UpdateMusicStream(Music music) } // Free allocated pcm data - free(pcm); + RL_FREE(pcm); // Reset audio stream for looping if (streamEnding) @@ -1750,7 +1750,7 @@ static Wave LoadWAV(const char *fileName) else { // Allocate memory for data - wave.data = malloc(wavData.subChunkSize); + wave.data = RL_MALLOC(wavData.subChunkSize); // Read in the sound data into the soundData variable fread(wave.data, wavData.subChunkSize, 1, wavFile); @@ -1891,7 +1891,7 @@ static Wave LoadOGG(const char *fileName) float totalSeconds = stb_vorbis_stream_length_in_seconds(oggFile); if (totalSeconds > 10) TraceLog(LOG_WARNING, "[%s] Ogg audio length is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds); - wave.data = (short *)malloc(wave.sampleCount*wave.channels*sizeof(short)); + wave.data = (short *)RL_MALLOC(wave.sampleCount*wave.channels*sizeof(short)); // NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!) int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels); diff --git a/src/raudio.h b/src/raudio.h index e8701814..f71a3083 100644 --- a/src/raudio.h +++ b/src/raudio.h @@ -56,7 +56,16 @@ //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -//... +// Allow custom memory allocators +#ifndef RL_MALLOC + #define RL_MALLOC(sz) malloc(sz) +#endif +#ifndef RL_CALLOC + #define RL_CALLOC(n,sz) calloc(n,sz) +#endif +#ifndef RL_FREE + #define RL_FREE(p) free(p) +#endif //---------------------------------------------------------------------------------- // Types and Structures Definition diff --git a/src/raylib.h b/src/raylib.h index 424a9dd7..43260e06 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -99,6 +99,17 @@ // Shader and material limits #define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct #define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct + +// Allow custom memory allocators +#ifndef RL_MALLOC + #define RL_MALLOC(sz) malloc(sz) +#endif +#ifndef RL_CALLOC + #define RL_CALLOC(n,sz) calloc(n,sz) +#endif +#ifndef RL_FREE + #define RL_FREE(p) free(p) +#endif // NOTE: MSC C++ compiler does not support compound literals (C99 feature) // Plain structures in C++ (without constructors) can be initialized from { } initializers. diff --git a/src/rlgl.h b/src/rlgl.h index 0356858a..c2ddd028 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1492,7 +1492,7 @@ void rlglInit(int width, int height) glGetIntegerv(GL_NUM_EXTENSIONS, &numExt); #if defined(_MSC_VER) - const char **extList = malloc(sizeof(const char *)*numExt); + const char **extList = RL_MALLOC(sizeof(const char *)*numExt); #else const char *extList[numExt]; #endif @@ -1504,7 +1504,7 @@ void rlglInit(int width, int height) // NOTE: We have to duplicate string because glGetString() returns a const string int len = strlen(extensions) + 1; - char *extensionsDup = (char *)malloc(len); + char *extensionsDup = (char *)RL_MALLOC(len); strcpy(extensionsDup, extensions); // NOTE: String could be splitted using strtok() function (string.h) @@ -1520,7 +1520,7 @@ void rlglInit(int width, int height) extList[numExt] = strtok(NULL, " "); } - free(extensionsDup); // Duplicated string must be deallocated + RL_FREE(extensionsDup); // Duplicated string must be deallocated numExt -= 1; #endif @@ -1595,7 +1595,7 @@ void rlglInit(int width, int height) } #if defined(_WIN32) && defined(_MSC_VER) - free(extList); + RL_FREE(extList); #endif #if defined(GRAPHICS_API_OPENGL_ES2) @@ -1640,7 +1640,7 @@ void rlglInit(int width, int height) transformMatrix = MatrixIdentity(); // Init draw calls tracking system - draws = (DrawCall *)malloc(sizeof(DrawCall)*MAX_DRAWCALL_REGISTERED); + draws = (DrawCall *)RL_MALLOC(sizeof(DrawCall)*MAX_DRAWCALL_REGISTERED); for (int i = 0; i < MAX_DRAWCALL_REGISTERED; i++) { @@ -1710,7 +1710,7 @@ void rlglClose(void) TraceLog(LOG_INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", defaultTextureId); - free(draws); + RL_FREE(draws); #endif } @@ -2300,7 +2300,7 @@ void rlGenerateMipmaps(Texture2D *texture) } texture->mipmaps = mipmapCount + 1; - free(data); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data + RL_FREE(data); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data TraceLog(LOG_WARNING, "[TEX ID %i] Mipmaps [%i] generated manually on CPU side", texture->id, texture->mipmaps); } @@ -2735,18 +2735,18 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform) // Unload mesh data from CPU and GPU void rlUnloadMesh(Mesh *mesh) { - free(mesh->vertices); - free(mesh->texcoords); - free(mesh->normals); - free(mesh->colors); - free(mesh->tangents); - free(mesh->texcoords2); - free(mesh->indices); - - free(mesh->animVertices); - free(mesh->animNormals); - free(mesh->boneWeights); - free(mesh->boneIds); + RL_FREE(mesh->vertices); + RL_FREE(mesh->texcoords); + RL_FREE(mesh->normals); + RL_FREE(mesh->colors); + RL_FREE(mesh->tangents); + RL_FREE(mesh->texcoords2); + RL_FREE(mesh->indices); + + RL_FREE(mesh->animVertices); + RL_FREE(mesh->animNormals); + RL_FREE(mesh->boneWeights); + RL_FREE(mesh->boneIds); rlDeleteBuffers(mesh->vboId[0]); // vertex rlDeleteBuffers(mesh->vboId[1]); // texcoords @@ -2762,14 +2762,14 @@ void rlUnloadMesh(Mesh *mesh) // Read screen pixel data (color buffer) unsigned char *rlReadScreenPixels(int width, int height) { - unsigned char *screenData = (unsigned char *)calloc(width*height*4, sizeof(unsigned char)); + unsigned char *screenData = (unsigned char *)RL_CALLOC(width*height*4, sizeof(unsigned char)); // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly! glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, screenData); // Flip image vertically! - unsigned char *imgData = (unsigned char *)malloc(width*height*sizeof(unsigned char)*4); + unsigned char *imgData = (unsigned char *)RL_MALLOC(width*height*sizeof(unsigned char)*4); for (int y = height - 1; y >= 0; y--) { @@ -2783,7 +2783,7 @@ unsigned char *rlReadScreenPixels(int width, int height) } } - free(screenData); + RL_FREE(screenData); return imgData; // NOTE: image data should be freed } @@ -2815,7 +2815,7 @@ void *rlReadTexturePixels(Texture2D texture) if ((glInternalFormat != -1) && (texture.format < COMPRESSED_DXT1_RGB)) { - pixels = (unsigned char *)malloc(size); + pixels = (unsigned char *)RL_MALLOC(size); glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels); } else TraceLog(LOG_WARNING, "Texture data retrieval not suported for pixel format"); @@ -2841,7 +2841,7 @@ void *rlReadTexturePixels(Texture2D texture) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id, 0); // Allocate enough memory to read back our texture data - pixels = (unsigned char *)malloc(GetPixelDataSize(texture.width, texture.height, texture.format)); + pixels = (unsigned char *)RL_MALLOC(GetPixelDataSize(texture.width, texture.height, texture.format)); // Get OpenGL internal formats and data type from our texture format unsigned int glInternalFormat, glFormat, glType; @@ -2911,7 +2911,7 @@ char *LoadText(const char *fileName) if (size > 0) { - text = (char *)malloc(sizeof(char)*(size + 1)); + text = (char *)RL_MALLOC(sizeof(char)*(size + 1)); int count = fread(text, sizeof(char), size, textFile); text[count] = '\0'; } @@ -2938,8 +2938,8 @@ Shader LoadShader(const char *vsFileName, const char *fsFileName) shader = LoadShaderCode(vShaderStr, fShaderStr); - if (vShaderStr != NULL) free(vShaderStr); - if (fShaderStr != NULL) free(fShaderStr); + if (vShaderStr != NULL) RL_FREE(vShaderStr); + if (fShaderStr != NULL) RL_FREE(fShaderStr); return shader; } @@ -3758,7 +3758,7 @@ static unsigned int CompileShader(const char *shaderStr, int type) glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); #if defined(_MSC_VER) - char *log = malloc(maxLength); + char *log = RL_MALLOC(maxLength); #else char log[maxLength]; #endif @@ -3767,7 +3767,7 @@ static unsigned int CompileShader(const char *shaderStr, int type) TraceLog(LOG_INFO, "%s", log); #if defined(_MSC_VER) - free(log); + RL_FREE(log); #endif } else TraceLog(LOG_INFO, "[SHDR ID %i] Shader compiled successfully", shader); @@ -3814,7 +3814,7 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength); #if defined(_MSC_VER) - char *log = malloc(maxLength); + char *log = RL_MALLOC(maxLength); #else char log[maxLength]; #endif @@ -3823,7 +3823,7 @@ static unsigned int LoadShaderProgram(unsigned int vShaderId, unsigned int fShad TraceLog(LOG_INFO, "%s", log); #if defined(_MSC_VER) - free(log); + RL_FREE(log); #endif glDeleteProgram(program); @@ -3984,13 +3984,13 @@ static void LoadBuffersDefault(void) //-------------------------------------------------------------------------------------------- for (int i = 0; i < MAX_BATCH_BUFFERING; i++) { - vertexData[i].vertices = (float *)malloc(sizeof(float)*3*4*MAX_BATCH_ELEMENTS); // 3 float by vertex, 4 vertex by quad - vertexData[i].texcoords = (float *)malloc(sizeof(float)*2*4*MAX_BATCH_ELEMENTS); // 2 float by texcoord, 4 texcoord by quad - vertexData[i].colors = (unsigned char *)malloc(sizeof(unsigned char)*4*4*MAX_BATCH_ELEMENTS); // 4 float by color, 4 colors by quad + vertexData[i].vertices = (float *)RL_MALLOC(sizeof(float)*3*4*MAX_BATCH_ELEMENTS); // 3 float by vertex, 4 vertex by quad + vertexData[i].texcoords = (float *)RL_MALLOC(sizeof(float)*2*4*MAX_BATCH_ELEMENTS); // 2 float by texcoord, 4 texcoord by quad + vertexData[i].colors = (unsigned char *)RL_MALLOC(sizeof(unsigned char)*4*4*MAX_BATCH_ELEMENTS); // 4 float by color, 4 colors by quad #if defined(GRAPHICS_API_OPENGL_33) - vertexData[i].indices = (unsigned int *)malloc(sizeof(unsigned int)*6*MAX_BATCH_ELEMENTS); // 6 int by quad (indices) + vertexData[i].indices = (unsigned int *)RL_MALLOC(sizeof(unsigned int)*6*MAX_BATCH_ELEMENTS); // 6 int by quad (indices) #elif defined(GRAPHICS_API_OPENGL_ES2) - vertexData[i].indices = (unsigned short *)malloc(sizeof(unsigned short)*6*MAX_BATCH_ELEMENTS); // 6 int by quad (indices) + vertexData[i].indices = (unsigned short *)RL_MALLOC(sizeof(unsigned short)*6*MAX_BATCH_ELEMENTS); // 6 int by quad (indices) #endif for (int j = 0; j < (3*4*MAX_BATCH_ELEMENTS); j++) vertexData[i].vertices[j] = 0.0f; @@ -4266,10 +4266,10 @@ static void UnloadBuffersDefault(void) if (vaoSupported) glDeleteVertexArrays(1, &vertexData[i].vaoId); // Free vertex arrays memory from CPU (RAM) - free(vertexData[i].vertices); - free(vertexData[i].texcoords); - free(vertexData[i].colors); - free(vertexData[i].indices); + RL_FREE(vertexData[i].vertices); + RL_FREE(vertexData[i].texcoords); + RL_FREE(vertexData[i].colors); + RL_FREE(vertexData[i].indices); } } @@ -4444,7 +4444,7 @@ static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight) // Generate mipmaps // NOTE: Every mipmap data is stored after data - Color *image = (Color *)malloc(width*height*sizeof(Color)); + Color *image = (Color *)RL_MALLOC(width*height*sizeof(Color)); Color *mipmap = NULL; int offset = 0; int j = 0; @@ -4481,13 +4481,13 @@ static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight) j++; } - free(image); + RL_FREE(image); image = mipmap; mipmap = NULL; } - free(mipmap); // free mipmap data + RL_FREE(mipmap); // free mipmap data return mipmapCount; } @@ -4501,7 +4501,7 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight) int width = srcWidth/2; int height = srcHeight/2; - Color *mipmap = (Color *)malloc(width*height*sizeof(Color)); + Color *mipmap = (Color *)RL_MALLOC(width*height*sizeof(Color)); // Scaling algorithm works perfectly (box-filter) for (int y = 0; y < height; y++) diff --git a/src/text.c b/src/text.c index bd9e09f0..22bd7659 100644 --- a/src/text.c +++ b/src/text.c @@ -174,7 +174,7 @@ extern void LoadDefaultFont(void) int imWidth = 128; int imHeight = 128; - Color *imagePixels = (Color *)malloc(imWidth*imHeight*sizeof(Color)); + Color *imagePixels = (Color *)RL_MALLOC(imWidth*imHeight*sizeof(Color)); for (int i = 0; i < imWidth*imHeight; i++) imagePixels[i] = BLANK; // Initialize array @@ -196,7 +196,7 @@ extern void LoadDefaultFont(void) Image image = LoadImageEx(imagePixels, imWidth, imHeight); ImageFormat(&image, UNCOMPRESSED_GRAY_ALPHA); - free(imagePixels); + RL_FREE(imagePixels); defaultFont.texture = LoadTextureFromImage(image); UnloadImage(image); @@ -206,7 +206,7 @@ extern void LoadDefaultFont(void) // Allocate space for our characters info data // NOTE: This memory should be freed at end! --> CloseWindow() - defaultFont.chars = (CharInfo *)malloc(defaultFont.charsCount*sizeof(CharInfo)); + defaultFont.chars = (CharInfo *)RL_MALLOC(defaultFont.charsCount*sizeof(CharInfo)); int currentLine = 0; int currentPosX = charsDivisor; @@ -249,7 +249,7 @@ extern void LoadDefaultFont(void) extern void UnloadDefaultFont(void) { UnloadTexture(defaultFont.texture); - free(defaultFont.chars); + RL_FREE(defaultFont.chars); } #endif // SUPPORT_DEFAULT_FONT @@ -407,7 +407,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) // Create a new image with the processed color data (key color replaced by BLANK) Image fontClear = LoadImageEx(pixels, image.width, image.height); - free(pixels); // Free pixels array memory + RL_FREE(pixels); // Free pixels array memory // Create spritefont with all data parsed from image Font spriteFont = { 0 }; @@ -419,7 +419,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) // We got tempCharValues and tempCharsRecs populated with chars data // Now we move temp data to sized charValues and charRecs arrays - spriteFont.chars = (CharInfo *)malloc(spriteFont.charsCount*sizeof(CharInfo)); + spriteFont.chars = (CharInfo *)RL_MALLOC(spriteFont.charsCount*sizeof(CharInfo)); for (int i = 0; i < spriteFont.charsCount; i++) { @@ -466,7 +466,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c long size = ftell(fontFile); // Get file size fseek(fontFile, 0, SEEK_SET); // Reset file pointer - unsigned char *fontBuffer = (unsigned char *)malloc(size); + unsigned char *fontBuffer = (unsigned char *)RL_MALLOC(size); fread(fontBuffer, size, 1, fontFile); fclose(fontFile); @@ -491,12 +491,12 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c int genFontChars = false; if (fontChars == NULL) { - fontChars = (int *)malloc(charsCount*sizeof(int)); + fontChars = (int *)RL_MALLOC(charsCount*sizeof(int)); for (int i = 0; i < charsCount; i++) fontChars[i] = i + 32; genFontChars = true; } - chars = (CharInfo *)malloc(charsCount*sizeof(CharInfo)); + chars = (CharInfo *)RL_MALLOC(charsCount*sizeof(CharInfo)); // NOTE: Using simple packaging, one char after another for (int i = 0; i < charsCount; i++) @@ -540,8 +540,8 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c chars[i].advanceX *= scaleFactor; } - free(fontBuffer); - if (genFontChars) free(fontChars); + RL_FREE(fontBuffer); + if (genFontChars) RL_FREE(fontChars); } else TraceLog(LOG_WARNING, "[%s] TTF file could not be opened", fileName); #else @@ -572,7 +572,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int paddi atlas.width = imageSize; // Atlas bitmap width atlas.height = imageSize; // Atlas bitmap height - atlas.data = (unsigned char *)calloc(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp) + atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp) atlas.format = UNCOMPRESSED_GRAYSCALE; atlas.mipmaps = 1; @@ -619,11 +619,11 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int paddi { TraceLog(LOG_DEBUG, "Using Skyline packing algorythm!"); - stbrp_context *context = (stbrp_context *)malloc(sizeof(*context)); - stbrp_node *nodes = (stbrp_node *)malloc(charsCount*sizeof(*nodes)); + stbrp_context *context = (stbrp_context *)RL_MALLOC(sizeof(*context)); + stbrp_node *nodes = (stbrp_node *)RL_MALLOC(charsCount*sizeof(*nodes)); stbrp_init_target(context, atlas.width, atlas.height, nodes, charsCount); - stbrp_rect *rects = (stbrp_rect *)malloc(charsCount*sizeof(stbrp_rect)); + stbrp_rect *rects = (stbrp_rect *)RL_MALLOC(charsCount*sizeof(stbrp_rect)); // Fill rectangles for packaging for (int i = 0; i < charsCount; i++) @@ -655,16 +655,16 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int paddi else TraceLog(LOG_WARNING, "Character could not be packed: %i", i); } - free(rects); - free(nodes); - free(context); + RL_FREE(rects); + RL_FREE(nodes); + RL_FREE(context); } // TODO: Crop image if required for smaller size // Convert image data from GRAYSCALE to GRAY_ALPHA // WARNING: ImageAlphaMask(&atlas, atlas) does not work in this case, requires manual operation - unsigned char *dataGrayAlpha = (unsigned char *)malloc(imageSize*imageSize*sizeof(unsigned char)*2); // Two channels + unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(imageSize*imageSize*sizeof(unsigned char)*2); // Two channels for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2) { @@ -672,7 +672,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int paddi dataGrayAlpha[k + 1] = ((unsigned char *)atlas.data)[i]; } - free(atlas.data); + RL_FREE(atlas.data); atlas.data = dataGrayAlpha; atlas.format = UNCOMPRESSED_GRAY_ALPHA; @@ -688,10 +688,10 @@ void UnloadFont(Font font) { for (int i = 0; i < font.charsCount; i++) { - free(font.chars[i].data); + RL_FREE(font.chars[i].data); } UnloadTexture(font.texture); - free(font.chars); + RL_FREE(font.chars); TraceLog(LOG_DEBUG, "Unloaded sprite font data"); } @@ -1214,7 +1214,7 @@ const char *TextReplace(char *text, const char *replace, const char *by) for (count = 0; (temp = strstr(insertPoint, replace)); count++) insertPoint = temp + replaceLen; // Allocate returning string and point temp to it - temp = result = malloc(strlen(text) + (byLen - replaceLen)*count + 1); + temp = result = RL_MALLOC(strlen(text) + (byLen - replaceLen)*count + 1); if (!result) return NULL; // Memory could not be allocated @@ -1245,7 +1245,7 @@ const char *TextInsert(const char *text, const char *insert, int position) int textLen = strlen(text); int insertLen = strlen(insert); - char *result = (char *)malloc(textLen + insertLen + 1); + char *result = (char *)RL_MALLOC(textLen + insertLen + 1); for (int i = 0; i < position; i++) result[i] = text[i]; for (int i = position; i < insertLen + position; i++) result[i] = insert[i]; @@ -1477,7 +1477,7 @@ static Font LoadBMFont(const char *fileName) } // NOTE: We need some extra space to avoid memory corruption on next allocations! - texPath = malloc(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4); + texPath = RL_MALLOC(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4); // NOTE: strcat() and strncat() required a '\0' terminated string to work! *texPath = '\0'; @@ -1501,13 +1501,13 @@ static Font LoadBMFont(const char *fileName) else font.texture = LoadTextureFromImage(imFont); UnloadImage(imFont); - free(texPath); + RL_FREE(texPath); // Fill font characters info data font.baseSize = fontSize; font.charsCount = charsCount; - font.chars = (CharInfo *)malloc(charsCount*sizeof(CharInfo)); + font.chars = (CharInfo *)RL_MALLOC(charsCount*sizeof(CharInfo)); int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX; diff --git a/src/textures.c b/src/textures.c index 7059fabb..eb743026 100644 --- a/src/textures.c +++ b/src/textures.c @@ -112,9 +112,14 @@ defined(SUPPORT_FILEFORMAT_GIF) || \ defined(SUPPORT_FILEFORMAT_PIC) || \ defined(SUPPORT_FILEFORMAT_HDR)) + + #define STBI_MALLOC RL_MALLOC + #define STBI_FREE RL_FREE + #define STBI_REALLOC(p,newsz) realloc(p,newsz) + #define STB_IMAGE_IMPLEMENTATION - #include "external/stb_image.h" // Required for: stbi_load_from_file() - // NOTE: Used to read image data (multiple formats support) + #include "external/stb_image.h" // Required for: stbi_load_from_file() + // NOTE: Used to read image data (multiple formats support) #endif #if defined(SUPPORT_IMAGE_EXPORT) @@ -305,7 +310,7 @@ Image LoadImageEx(Color *pixels, int width, int height) int k = 0; - image.data = (unsigned char *)malloc(image.width*image.height*4*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(image.width*image.height*4*sizeof(unsigned char)); for (int i = 0; i < image.width*image.height*4; i += 4) { @@ -353,7 +358,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int unsigned int size = GetPixelDataSize(width, height, format); - image.data = malloc(size); // Allocate required memory in bytes + image.data = RL_MALLOC(size); // Allocate required memory in bytes // NOTE: fread() returns num read elements instead of bytes, // to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element) @@ -364,7 +369,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int { TraceLog(LOG_WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName); - free(image.data); + RL_FREE(image.data); } else { @@ -425,7 +430,7 @@ RenderTexture2D LoadRenderTexture(int width, int height) // Unload image from CPU memory (RAM) void UnloadImage(Image image) { - free(image.data); + RL_FREE(image.data); } // Unload texture from GPU memory (VRAM) @@ -448,7 +453,7 @@ void UnloadRenderTexture(RenderTexture2D target) // Get pixel data from image in the form of Color struct array Color *GetImageData(Image image) { - Color *pixels = (Color *)malloc(image.width*image.height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(image.width*image.height*sizeof(Color)); if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats"); else @@ -563,7 +568,7 @@ Color *GetImageData(Image image) // Get pixel data from image as Vector4 array (float normalized) Vector4 *GetImageDataNormalized(Image image) { - Vector4 *pixels = (Vector4 *)malloc(image.width*image.height*sizeof(Vector4)); + Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4)); if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats"); else @@ -797,7 +802,7 @@ void ExportImage(Image image, const char *fileName) fclose(rawFile); } - free(imgData); + RL_FREE(imgData); #endif if (success != 0) TraceLog(LOG_INFO, "Image exported successfully: %s", fileName); @@ -863,7 +868,7 @@ Image ImageCopy(Image image) if (height < 1) height = 1; } - newImage.data = malloc(size); + newImage.data = RL_MALLOC(size); if (newImage.data != NULL) { @@ -896,7 +901,7 @@ void ImageToPOT(Image *image, Color fillColor) Color *pixelsPOT = NULL; // Generate POT array from NPOT data - pixelsPOT = (Color *)malloc(potWidth*potHeight*sizeof(Color)); + pixelsPOT = (Color *)RL_MALLOC(potWidth*potHeight*sizeof(Color)); for (int j = 0; j < potHeight; j++) { @@ -909,15 +914,15 @@ void ImageToPOT(Image *image, Color fillColor) TraceLog(LOG_WARNING, "Image converted to POT: (%ix%i) -> (%ix%i)", image->width, image->height, potWidth, potHeight); - free(pixels); // Free pixels data - free(image->data); // Free old image data + RL_FREE(pixels); // Free pixels data + RL_FREE(image->data); // Free old image data int format = image->format; // Store image data format to reconvert later // NOTE: Image size changes, new width and height *image = LoadImageEx(pixelsPOT, potWidth, potHeight); - free(pixelsPOT); // Free POT pixels data + RL_FREE(pixelsPOT); // Free POT pixels data ImageFormat(image, format); // Reconvert image to previous format } @@ -932,7 +937,7 @@ void ImageFormat(Image *image, int newFormat) { Vector4 *pixels = GetImageDataNormalized(*image); // Supports 8 to 32 bit per channel - free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end... + RL_FREE(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end... image->data = NULL; image->format = newFormat; @@ -942,7 +947,7 @@ void ImageFormat(Image *image, int newFormat) { case UNCOMPRESSED_GRAYSCALE: { - image->data = (unsigned char *)malloc(image->width*image->height*sizeof(unsigned char)); + image->data = (unsigned char *)RL_MALLOC(image->width*image->height*sizeof(unsigned char)); for (int i = 0; i < image->width*image->height; i++) { @@ -952,7 +957,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_GRAY_ALPHA: { - image->data = (unsigned char *)malloc(image->width*image->height*2*sizeof(unsigned char)); + image->data = (unsigned char *)RL_MALLOC(image->width*image->height*2*sizeof(unsigned char)); for (int i = 0; i < image->width*image->height*2; i += 2, k++) { @@ -963,7 +968,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R5G6B5: { - image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short)); + image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short)); unsigned char r = 0; unsigned char g = 0; @@ -981,7 +986,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R8G8B8: { - image->data = (unsigned char *)malloc(image->width*image->height*3*sizeof(unsigned char)); + image->data = (unsigned char *)RL_MALLOC(image->width*image->height*3*sizeof(unsigned char)); for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) { @@ -994,7 +999,7 @@ void ImageFormat(Image *image, int newFormat) { #define ALPHA_THRESHOLD 50 - image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short)); + image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short)); unsigned char r = 0; unsigned char g = 0; @@ -1014,7 +1019,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R4G4B4A4: { - image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short)); + image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short)); unsigned char r = 0; unsigned char g = 0; @@ -1034,7 +1039,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R8G8B8A8: { - image->data = (unsigned char *)malloc(image->width*image->height*4*sizeof(unsigned char)); + image->data = (unsigned char *)RL_MALLOC(image->width*image->height*4*sizeof(unsigned char)); for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) { @@ -1048,7 +1053,7 @@ void ImageFormat(Image *image, int newFormat) { // WARNING: Image is converted to GRAYSCALE eqeuivalent 32bit - image->data = (float *)malloc(image->width*image->height*sizeof(float)); + image->data = (float *)RL_MALLOC(image->width*image->height*sizeof(float)); for (int i = 0; i < image->width*image->height; i++) { @@ -1057,7 +1062,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R32G32B32: { - image->data = (float *)malloc(image->width*image->height*3*sizeof(float)); + image->data = (float *)RL_MALLOC(image->width*image->height*3*sizeof(float)); for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) { @@ -1068,7 +1073,7 @@ void ImageFormat(Image *image, int newFormat) } break; case UNCOMPRESSED_R32G32B32A32: { - image->data = (float *)malloc(image->width*image->height*4*sizeof(float)); + image->data = (float *)RL_MALLOC(image->width*image->height*4*sizeof(float)); for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) { @@ -1081,7 +1086,7 @@ void ImageFormat(Image *image, int newFormat) default: break; } - free(pixels); + RL_FREE(pixels); pixels = NULL; // In case original image had mipmaps, generate mipmaps for formated image @@ -1286,7 +1291,7 @@ void ImageCrop(Image *image, Rectangle crop) { // Start the cropping process Color *pixels = GetImageData(*image); // Get data as Color pixels array - Color *cropPixels = (Color *)malloc((int)crop.width*(int)crop.height*sizeof(Color)); + Color *cropPixels = (Color *)RL_MALLOC((int)crop.width*(int)crop.height*sizeof(Color)); for (int j = (int)crop.y; j < (int)(crop.y + crop.height); j++) { @@ -1296,7 +1301,7 @@ void ImageCrop(Image *image, Rectangle crop) } } - free(pixels); + RL_FREE(pixels); int format = image->format; @@ -1304,7 +1309,7 @@ void ImageCrop(Image *image, Rectangle crop) *image = LoadImageEx(cropPixels, (int)crop.width, (int)crop.height); - free(cropPixels); + RL_FREE(cropPixels); // Reformat 32bit RGBA image to original format ImageFormat(image, format); @@ -1341,7 +1346,7 @@ void ImageAlphaCrop(Image *image, float threshold) Rectangle crop = { xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin }; - free(pixels); + RL_FREE(pixels); // Check for not empty image brefore cropping if (!((xMax < xMin) || (yMax < yMin))) ImageCrop(image, crop); @@ -1355,7 +1360,7 @@ void ImageResize(Image *image, int newWidth, int newHeight) { // Get data as Color pixels array to work with it Color *pixels = GetImageData(*image); - Color *output = (Color *)malloc(newWidth*newHeight*sizeof(Color)); + Color *output = (Color *)RL_MALLOC(newWidth*newHeight*sizeof(Color)); // NOTE: Color data is casted to (unsigned char *), there shouldn't been any problem... stbir_resize_uint8((unsigned char *)pixels, image->width, image->height, 0, (unsigned char *)output, newWidth, newHeight, 0, 4); @@ -1367,15 +1372,15 @@ void ImageResize(Image *image, int newWidth, int newHeight) *image = LoadImageEx(output, newWidth, newHeight); ImageFormat(image, format); // Reformat 32bit RGBA image to original format - free(output); - free(pixels); + RL_FREE(output); + RL_FREE(pixels); } // Resize and image to new size using Nearest-Neighbor scaling algorithm void ImageResizeNN(Image *image,int newWidth,int newHeight) { Color *pixels = GetImageData(*image); - Color *output = (Color *)malloc(newWidth*newHeight*sizeof(Color)); + Color *output = (Color *)RL_MALLOC(newWidth*newHeight*sizeof(Color)); // EDIT: added +1 to account for an early rounding problem int xRatio = (int)((image->width << 16)/newWidth) + 1; @@ -1400,8 +1405,8 @@ void ImageResizeNN(Image *image,int newWidth,int newHeight) *image = LoadImageEx(output, newWidth, newHeight); ImageFormat(image, format); // Reformat 32bit RGBA image to original format - free(output); - free(pixels); + RL_FREE(output); + RL_FREE(pixels); } // Resize canvas and fill with color @@ -1555,7 +1560,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp) { Color *pixels = GetImageData(*image); - free(image->data); // free old image data + RL_FREE(image->data); // free old image data if ((image->format != UNCOMPRESSED_R8G8B8) && (image->format != UNCOMPRESSED_R8G8B8A8)) { @@ -1573,7 +1578,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp) } // NOTE: We will store the dithered data as unsigned short (16bpp) - image->data = (unsigned short *)malloc(image->width*image->height*sizeof(unsigned short)); + image->data = (unsigned short *)RL_MALLOC(image->width*image->height*sizeof(unsigned short)); Color oldPixel = WHITE; Color newPixel = WHITE; @@ -1641,7 +1646,7 @@ void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp) } } - free(pixels); + RL_FREE(pixels); } } @@ -1652,7 +1657,7 @@ Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount) #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a)) Color *pixels = GetImageData(image); - Color *palette = (Color *)malloc(maxPaletteSize*sizeof(Color)); + Color *palette = (Color *)RL_MALLOC(maxPaletteSize*sizeof(Color)); int palCount = 0; for (int i = 0; i < maxPaletteSize; i++) palette[i] = BLANK; // Set all colors to BLANK @@ -1689,7 +1694,7 @@ Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount) } } - free(pixels); + RL_FREE(pixels); *extractCount = palCount; @@ -1799,8 +1804,8 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec) *dst = LoadImageEx(dstPixels, (int)dst->width, (int)dst->height); ImageFormat(dst, dst->format); - free(srcPixels); - free(dstPixels); + RL_FREE(srcPixels); + RL_FREE(dstPixels); } // Create an image from text (default font) @@ -1933,7 +1938,7 @@ void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, void ImageFlipVertical(Image *image) { Color *srcPixels = GetImageData(*image); - Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + Color *dstPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -1947,8 +1952,8 @@ void ImageFlipVertical(Image *image) ImageFormat(&processed, image->format); UnloadImage(*image); - free(srcPixels); - free(dstPixels); + RL_FREE(srcPixels); + RL_FREE(dstPixels); image->data = processed.data; } @@ -1957,7 +1962,7 @@ void ImageFlipVertical(Image *image) void ImageFlipHorizontal(Image *image) { Color *srcPixels = GetImageData(*image); - Color *dstPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + Color *dstPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -1971,8 +1976,8 @@ void ImageFlipHorizontal(Image *image) ImageFormat(&processed, image->format); UnloadImage(*image); - free(srcPixels); - free(dstPixels); + RL_FREE(srcPixels); + RL_FREE(dstPixels); image->data = processed.data; } @@ -1981,7 +1986,7 @@ void ImageFlipHorizontal(Image *image) void ImageRotateCW(Image *image) { Color *srcPixels = GetImageData(*image); - Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + Color *rotPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -1995,8 +2000,8 @@ void ImageRotateCW(Image *image) ImageFormat(&processed, image->format); UnloadImage(*image); - free(srcPixels); - free(rotPixels); + RL_FREE(srcPixels); + RL_FREE(rotPixels); image->data = processed.data; image->width = processed.width; @@ -2007,7 +2012,7 @@ void ImageRotateCW(Image *image) void ImageRotateCCW(Image *image) { Color *srcPixels = GetImageData(*image); - Color *rotPixels = (Color *)malloc(image->width*image->height*sizeof(Color)); + Color *rotPixels = (Color *)RL_MALLOC(image->width*image->height*sizeof(Color)); for (int y = 0; y < image->height; y++) { @@ -2021,8 +2026,8 @@ void ImageRotateCCW(Image *image) ImageFormat(&processed, image->format); UnloadImage(*image); - free(srcPixels); - free(rotPixels); + RL_FREE(srcPixels); + RL_FREE(rotPixels); image->data = processed.data; image->width = processed.width; @@ -2059,7 +2064,7 @@ void ImageColorTint(Image *image, Color color) Image processed = LoadImageEx(pixels, image->width, image->height); ImageFormat(&processed, image->format); UnloadImage(*image); - free(pixels); + RL_FREE(pixels); image->data = processed.data; } @@ -2082,7 +2087,7 @@ void ImageColorInvert(Image *image) Image processed = LoadImageEx(pixels, image->width, image->height); ImageFormat(&processed, image->format); UnloadImage(*image); - free(pixels); + RL_FREE(pixels); image->data = processed.data; } @@ -2142,7 +2147,7 @@ void ImageColorContrast(Image *image, float contrast) Image processed = LoadImageEx(pixels, image->width, image->height); ImageFormat(&processed, image->format); UnloadImage(*image); - free(pixels); + RL_FREE(pixels); image->data = processed.data; } @@ -2182,7 +2187,7 @@ void ImageColorBrightness(Image *image, int brightness) Image processed = LoadImageEx(pixels, image->width, image->height); ImageFormat(&processed, image->format); UnloadImage(*image); - free(pixels); + RL_FREE(pixels); image->data = processed.data; } @@ -2212,7 +2217,7 @@ void ImageColorReplace(Image *image, Color color, Color replace) Image processed = LoadImageEx(pixels, image->width, image->height); ImageFormat(&processed, image->format); UnloadImage(*image); - free(pixels); + RL_FREE(pixels); image->data = processed.data; } @@ -2221,13 +2226,13 @@ void ImageColorReplace(Image *image, Color color, Color replace) // Generate image: plain color Image GenImageColor(int width, int height, Color color) { - Color *pixels = (Color *)calloc(width*height, sizeof(Color)); + Color *pixels = (Color *)RL_CALLOC(width*height, sizeof(Color)); for (int i = 0; i < width*height; i++) pixels[i] = color; Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2236,7 +2241,7 @@ Image GenImageColor(int width, int height, Color color) // Generate image: vertical gradient Image GenImageGradientV(int width, int height, Color top, Color bottom) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); for (int j = 0; j < height; j++) { @@ -2251,7 +2256,7 @@ Image GenImageGradientV(int width, int height, Color top, Color bottom) } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2259,7 +2264,7 @@ Image GenImageGradientV(int width, int height, Color top, Color bottom) // Generate image: horizontal gradient Image GenImageGradientH(int width, int height, Color left, Color right) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); for (int i = 0; i < width; i++) { @@ -2274,7 +2279,7 @@ Image GenImageGradientH(int width, int height, Color left, Color right) } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2282,7 +2287,7 @@ Image GenImageGradientH(int width, int height, Color left, Color right) // Generate image: radial gradient Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); float radius = (width < height)? (float)width/2.0f : (float)height/2.0f; float centerX = (float)width/2.0f; @@ -2306,7 +2311,7 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner, } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2314,7 +2319,7 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner, // Generate image: checked Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); for (int y = 0; y < height; y++) { @@ -2326,7 +2331,7 @@ Image GenImageChecked(int width, int height, int checksX, int checksY, Color col } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2334,7 +2339,7 @@ Image GenImageChecked(int width, int height, int checksX, int checksY, Color col // Generate image: white noise Image GenImageWhiteNoise(int width, int height, float factor) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); for (int i = 0; i < width*height; i++) { @@ -2343,7 +2348,7 @@ Image GenImageWhiteNoise(int width, int height, float factor) } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2351,7 +2356,7 @@ Image GenImageWhiteNoise(int width, int height, float factor) // Generate image: perlin noise Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); for (int y = 0; y < height; y++) { @@ -2374,7 +2379,7 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float } Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2382,13 +2387,13 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float // Generate image: cellular algorithm. Bigger tileSize means bigger cells Image GenImageCellular(int width, int height, int tileSize) { - Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color)); int seedsPerRow = width/tileSize; int seedsPerCol = height/tileSize; int seedsCount = seedsPerRow * seedsPerCol; - Vector2 *seeds = (Vector2 *)malloc(seedsCount*sizeof(Vector2)); + Vector2 *seeds = (Vector2 *)RL_MALLOC(seedsCount*sizeof(Vector2)); for (int i = 0; i < seedsCount; i++) { @@ -2431,10 +2436,10 @@ Image GenImageCellular(int width, int height, int tileSize) } } - free(seeds); + RL_FREE(seeds); Image image = LoadImageEx(pixels, width, height); - free(pixels); + RL_FREE(pixels); return image; } @@ -2921,7 +2926,7 @@ static Image LoadDDS(const char *fileName) { if (ddsHeader.ddspf.flags == 0x40) // no alpha channel { - image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short)); + image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short)); fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile); image.format = UNCOMPRESSED_R5G6B5; @@ -2930,7 +2935,7 @@ static Image LoadDDS(const char *fileName) { if (ddsHeader.ddspf.aBitMask == 0x8000) // 1bit alpha { - image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short)); + image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short)); fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile); unsigned char alpha = 0; @@ -2947,7 +2952,7 @@ static Image LoadDDS(const char *fileName) } else if (ddsHeader.ddspf.aBitMask == 0xf000) // 4bit alpha { - image.data = (unsigned short *)malloc(image.width*image.height*sizeof(unsigned short)); + image.data = (unsigned short *)RL_MALLOC(image.width*image.height*sizeof(unsigned short)); fread(image.data, image.width*image.height*sizeof(unsigned short), 1, ddsFile); unsigned char alpha = 0; @@ -2967,14 +2972,14 @@ static Image LoadDDS(const char *fileName) if (ddsHeader.ddspf.flags == 0x40 && ddsHeader.ddspf.rgbBitCount == 24) // DDS_RGB, no compressed { // NOTE: not sure if this case exists... - image.data = (unsigned char *)malloc(image.width*image.height*3*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(image.width*image.height*3*sizeof(unsigned char)); fread(image.data, image.width*image.height*3, 1, ddsFile); image.format = UNCOMPRESSED_R8G8B8; } else if (ddsHeader.ddspf.flags == 0x41 && ddsHeader.ddspf.rgbBitCount == 32) // DDS_RGBA, no compressed { - image.data = (unsigned char *)malloc(image.width*image.height*4*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(image.width*image.height*4*sizeof(unsigned char)); fread(image.data, image.width*image.height*4, 1, ddsFile); unsigned char blue = 0; @@ -3001,7 +3006,7 @@ static Image LoadDDS(const char *fileName) TraceLog(LOG_DEBUG, "Pitch or linear size: %i", ddsHeader.pitchOrLinearSize); - image.data = (unsigned char *)malloc(size*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char)); fread(image.data, size, 1, ddsFile); @@ -3098,7 +3103,7 @@ static Image LoadPKM(const char *fileName) int size = image.width*image.height*bpp/8; // Total data size in bytes - image.data = (unsigned char *)malloc(size*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char)); fread(image.data, size, 1, pkmFile); @@ -3192,7 +3197,7 @@ static Image LoadKTX(const char *fileName) int dataSize; fread(&dataSize, sizeof(unsigned int), 1, ktxFile); - image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char)); fread(image.data, dataSize, 1, ktxFile); @@ -3441,7 +3446,7 @@ static Image LoadPVR(const char *fileName) } int dataSize = image.width*image.height*bpp/8; // Total data size in bytes - image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char)); // Read data from file fread(image.data, dataSize, 1, pvrFile); @@ -3518,7 +3523,7 @@ static Image LoadASTC(const char *fileName) { int dataSize = image.width*image.height*bpp/8; // Data size in bytes - image.data = (unsigned char *)malloc(dataSize*sizeof(unsigned char)); + image.data = (unsigned char *)RL_MALLOC(dataSize*sizeof(unsigned char)); fread(image.data, dataSize, 1, astcFile); if (bpp == 8) image.format = COMPRESSED_ASTC_4x4_RGBA; diff --git a/src/utils.c b/src/utils.c index 10cce9b9..3cff472b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -45,10 +45,10 @@ #include // Required for: Android assets manager: AAsset, AAssetManager_open(), ... #endif -#include // Required for: malloc(), free() -#include // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen() +#include // Required for: exit() +#include // Required for: printf(), sprintf() #include // Required for: va_list, va_start(), vfprintf(), va_end() -#include // Required for: strlen(), strrchr(), strcmp() +#include // Required for: strcpy(), strcat() #define MAX_TRACELOG_BUFFER_SIZE 128 // Max length of one trace-log message -- cgit v1.2.3 From 2de1f318212dbceb71db6be053be995208748f2a Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Sat, 27 Apr 2019 19:33:51 +0100 Subject: UWP Support Overhaul (#819) * Working build * Fix build again, stop deleting files * Hotfix crash, needs investigating * Remove VS2015.UWP, I cannot update the project * Lots of UWP work, added keyboard and mouse press support. Still need to finish scroll wheel, mouse position and cursor hiding, plus other stuff that I haven't seen yet. * Implemented a ton more things, added BaseApp.h to provide common code to UWP apps. * Remove constant window dimensions * Enable and Disable cursor support. * Actually use mouse delta * Gamepad Support * Cleaning and small tweaks * Restore original example. * Update comment * Use 'Messages' to handle the cursor functions so code is more portable. * Comment * Comment unused message fields and use vector for mouse pos instead. * Move messages to utils.h and use messages for everything. No more plat-specific code in raylib.h * Working build * Fix build again, stop deleting files * Hotfix crash, needs investigating * Remove VS2015.UWP, I cannot update the project * Lots of UWP work, added keyboard and mouse press support. Still need to finish scroll wheel, mouse position and cursor hiding, plus other stuff that I haven't seen yet. * Implemented a ton more things, added BaseApp.h to provide common code to UWP apps. * Remove constant window dimensions * Enable and Disable cursor support. * Actually use mouse delta * Gamepad Support * Cleaning and small tweaks * Restore original example. * Update comment * Use 'Messages' to handle the cursor functions so code is more portable. * Comment * Comment unused message fields and use vector for mouse pos instead. * Move messages to utils.h and use messages for everything. No more plat-specific code in raylib.h * Tested some desktop stuff and added projection matrix updates for window resizing. * Fixed big bad mouse bug * Fix alt buttons and add hack to combat flickery key presses (far from perfect) * Remove debug code * Final commit * Well, so I thought * Wow, i am bad * Remove packages folder * Remove useless include * Apply requested changes and fix linux build * Try to stop packages folder * Have we fixed the formatting properly? * Third time's the charm? * Where did this come from? * Re-fix * Autoformat is gonna kill * Fixed XBOX ONE Support * Fix tabs --- .gitignore | 1 + projects/VS2015.UWP/raylib.App.UWP/App.cpp | 558 -------------------- projects/VS2015.UWP/raylib.App.UWP/App.h | 49 -- .../raylib.App.UWP/Assets/Logo.scale-100.png | Bin 801 -> 0 bytes .../raylib.App.UWP/Assets/SmallLogo.scale-100.png | Bin 329 -> 0 bytes .../Assets/SplashScreen.scale-100.png | Bin 2146 -> 0 bytes .../raylib.App.UWP/Assets/StoreLogo.scale-100.png | Bin 429 -> 0 bytes .../raylib.App.UWP/Assets/WideLogo.scale-100.png | Bin 2150 -> 0 bytes .../VS2015.UWP/raylib.App.UWP/Package.appxmanifest | 26 - projects/VS2015.UWP/raylib.App.UWP/packages.config | 4 - projects/VS2015.UWP/raylib.App.UWP/pch.cpp | 1 - projects/VS2015.UWP/raylib.App.UWP/pch.h | 16 - .../raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx | Bin 2512 -> 0 bytes .../raylib.App.UWP/raylib.App.UWP.filters | 42 -- .../VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user | 4 - .../raylib.App.UWP/raylib.App.UWP.vcxproj | 145 ------ projects/VS2015.UWP/raylib.UWP.sln | 51 -- projects/VS2015.UWP/raylib/raylib.vcxproj | 182 ------- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 78 +++ projects/VS2017.UWP/raylib.App.UWP/App.h | 25 + .../raylib.App.UWP/Assets/Logo.scale-100.png | Bin 0 -> 801 bytes .../raylib.App.UWP/Assets/SmallLogo.scale-100.png | Bin 0 -> 329 bytes .../Assets/SplashScreen.scale-100.png | Bin 0 -> 2146 bytes .../raylib.App.UWP/Assets/StoreLogo.scale-100.png | Bin 0 -> 429 bytes .../raylib.App.UWP/Assets/WideLogo.scale-100.png | Bin 0 -> 2150 bytes projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 567 +++++++++++++++++++++ .../VS2017.UWP/raylib.App.UWP/Package.appxmanifest | 26 + projects/VS2017.UWP/raylib.App.UWP/packages.config | 4 + projects/VS2017.UWP/raylib.App.UWP/pch.cpp | 1 + projects/VS2017.UWP/raylib.App.UWP/pch.h | 16 + .../raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx | Bin 0 -> 2512 bytes .../raylib.App.UWP/raylib.App.UWP.filters | 42 ++ .../raylib.App.UWP/raylib.App.UWP.vcxproj | 151 ++++++ projects/VS2017.UWP/raylib.UWP.sln | 57 +++ projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj | 231 +++++++++ .../raylib.UWP/raylib.UWP.vcxproj.filters | 29 ++ src/camera.h | 2 +- src/core.c | 260 +++++++++- src/external/ANGLE/EGL/eglplatform.h | 5 + src/rlgl.h | 10 +- src/utils.c | 92 +++- src/utils.h | 75 +++ 42 files changed, 1647 insertions(+), 1103 deletions(-) delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/App.cpp delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/App.h delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/packages.config delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/pch.cpp delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/pch.h delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user delete mode 100644 projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj delete mode 100644 projects/VS2015.UWP/raylib.UWP.sln delete mode 100644 projects/VS2015.UWP/raylib/raylib.vcxproj create mode 100644 projects/VS2017.UWP/raylib.App.UWP/App.cpp create mode 100644 projects/VS2017.UWP/raylib.App.UWP/App.h create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png create mode 100644 projects/VS2017.UWP/raylib.App.UWP/BaseApp.h create mode 100644 projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest create mode 100644 projects/VS2017.UWP/raylib.App.UWP/packages.config create mode 100644 projects/VS2017.UWP/raylib.App.UWP/pch.cpp create mode 100644 projects/VS2017.UWP/raylib.App.UWP/pch.h create mode 100644 projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx create mode 100644 projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters create mode 100644 projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj create mode 100644 projects/VS2017.UWP/raylib.UWP.sln create mode 100644 projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj create mode 100644 projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters (limited to 'src/utils.c') diff --git a/.gitignore b/.gitignore index 08e661af..df96338a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ ipch/ *.opensdf *.db *.opendb +packages/ # Ignore compiled binaries *.o diff --git a/projects/VS2015.UWP/raylib.App.UWP/App.cpp b/projects/VS2015.UWP/raylib.App.UWP/App.cpp deleted file mode 100644 index 6ce6915c..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/App.cpp +++ /dev/null @@ -1,558 +0,0 @@ -#include "pch.h" -#include "app.h" - -#include "raylib.h" - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::UI::Core; -using namespace Windows::UI::Input; -using namespace Windows::Devices::Input; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::Gaming::Input; -using namespace Windows::Graphics::Display; -using namespace Microsoft::WRL; -using namespace Platform; - -using namespace raylibUWP; - -/* -TODO list: - - Cache reference to our CoreWindow? - - Implement gestures support -*/ - -// Declare uwpWindow as exter to be used by raylib internals -// NOTE: It should be properly assigned before calling InitWindow() -extern "C" { EGLNativeWindowType uwpWindow; }; - -/* INPUT CODE */ -// Stand-ins for "core.c" variables -#define MAX_GAMEPADS 4 // Max number of gamepads supported -#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) -#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) - -static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready -static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state -static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state -static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state - -static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state -static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state - -static char previousMouseState[3] = { 0 }; // Registers previous mouse button state -static char currentMouseState[3] = { 0 }; // Registers current mouse button state -static int previousMouseWheelY = 0; // Registers previous mouse wheel variation -static int currentMouseWheelY = 0; // Registers current mouse wheel variation - -static bool cursorOnScreen = false; // Tracks if cursor is inside client area -static bool cursorHidden = false; // Track if cursor is hidden - -static Vector2 mousePosition; -static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c" -static bool toggleCursorLock; - -CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type - -// Helper to process key events -void ProcessKeyEvent(Windows::System::VirtualKey key, int action) -{ - using Windows::System::VirtualKey; - switch (key) - { - case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break; - case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break; - case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break; - case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break; - case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break; - case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break; - case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break; - case VirtualKey::Up: currentKeyState[KEY_UP] = action; break; - case VirtualKey::F1: currentKeyState[KEY_F1] = action; break; - case VirtualKey::F2: currentKeyState[KEY_F2] = action; break; - case VirtualKey::F3: currentKeyState[KEY_F4] = action; break; - case VirtualKey::F4: currentKeyState[KEY_F5] = action; break; - case VirtualKey::F5: currentKeyState[KEY_F6] = action; break; - case VirtualKey::F6: currentKeyState[KEY_F7] = action; break; - case VirtualKey::F7: currentKeyState[KEY_F8] = action; break; - case VirtualKey::F8: currentKeyState[KEY_F9] = action; break; - case VirtualKey::F9: currentKeyState[KEY_F10] = action; break; - case VirtualKey::F10: currentKeyState[KEY_F11] = action; break; - case VirtualKey::F11: currentKeyState[KEY_F12] = action; break; - case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break; - case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break; - case VirtualKey::LeftMenu: currentKeyState[KEY_LEFT_ALT] = action; break; // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown - case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break; - case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break; - case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break; - case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break; - case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break; - case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break; - case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break; - case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break; - case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break; - case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break; - case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break; - case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break; - case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break; - case VirtualKey::A: currentKeyState[KEY_A] = action; break; - case VirtualKey::B: currentKeyState[KEY_B] = action; break; - case VirtualKey::C: currentKeyState[KEY_C] = action; break; - case VirtualKey::D: currentKeyState[KEY_D] = action; break; - case VirtualKey::E: currentKeyState[KEY_E] = action; break; - case VirtualKey::F: currentKeyState[KEY_F] = action; break; - case VirtualKey::G: currentKeyState[KEY_G] = action; break; - case VirtualKey::H: currentKeyState[KEY_H] = action; break; - case VirtualKey::I: currentKeyState[KEY_I] = action; break; - case VirtualKey::J: currentKeyState[KEY_J] = action; break; - case VirtualKey::K: currentKeyState[KEY_K] = action; break; - case VirtualKey::L: currentKeyState[KEY_L] = action; break; - case VirtualKey::M: currentKeyState[KEY_M] = action; break; - case VirtualKey::N: currentKeyState[KEY_N] = action; break; - case VirtualKey::O: currentKeyState[KEY_O] = action; break; - case VirtualKey::P: currentKeyState[KEY_P] = action; break; - case VirtualKey::Q: currentKeyState[KEY_Q] = action; break; - case VirtualKey::R: currentKeyState[KEY_R] = action; break; - case VirtualKey::S: currentKeyState[KEY_S] = action; break; - case VirtualKey::T: currentKeyState[KEY_T] = action; break; - case VirtualKey::U: currentKeyState[KEY_U] = action; break; - case VirtualKey::V: currentKeyState[KEY_V] = action; break; - case VirtualKey::W: currentKeyState[KEY_W] = action; break; - case VirtualKey::X: currentKeyState[KEY_X] = action; break; - case VirtualKey::Y: currentKeyState[KEY_Y] = action; break; - case VirtualKey::Z: currentKeyState[KEY_Z] = action; break; - - } -} - -// Callbacks -void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args) -{ - if (args->CurrentPoint->Properties->IsLeftButtonPressed) - { - currentMouseState[MOUSE_LEFT_BUTTON] = 1; - } - if (args->CurrentPoint->Properties->IsRightButtonPressed) - { - currentMouseState[MOUSE_RIGHT_BUTTON] = 1; - } - if (args->CurrentPoint->Properties->IsMiddleButtonPressed) - { - currentMouseState[MOUSE_MIDDLE_BUTTON] = 1; - } -} - -void App::PointerReleased(CoreWindow ^window, PointerEventArgs^ args) -{ - if (!(args->CurrentPoint->Properties->IsLeftButtonPressed)) - { - currentMouseState[MOUSE_LEFT_BUTTON] = 0; - } - if (!(args->CurrentPoint->Properties->IsRightButtonPressed)) - { - currentMouseState[MOUSE_RIGHT_BUTTON] = 0; - } - if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed)) - { - currentMouseState[MOUSE_MIDDLE_BUTTON] = 0; - } -} - -void App::PointerWheelChanged(CoreWindow ^window, PointerEventArgs^ args) -{ - // TODO: Scale the MouseWheelDelta to match GLFW's mouse wheel sensitivity. - currentMouseWheelY += args->CurrentPoint->Properties->MouseWheelDelta; -} - -void App::MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) -{ - mouseDelta.x += args->MouseDelta.X; - mouseDelta.y += args->MouseDelta.Y; -} - -void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 1); -} - -void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 0); -} - -/* REIMPLEMENTED FROM CORE.C */ -// Get one key state -static bool GetKeyStatus(int key) -{ - return currentKeyState[key]; -} - -// Show mouse cursor -void UWPShowCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - cursorHidden = false; -} - -// Hides mouse cursor -void UWPHideCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - cursorHidden = true; -} - -// Set mouse position XY -void UWPSetMousePosition(Vector2 position) -{ - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - Point mousePosScreen = Point(position.x + window->Bounds.X, position.y + window->Bounds.Y); - window->PointerPosition = mousePosScreen; - mousePosition = position; -} - -// Enables cursor (unlock cursor) -void UWPEnableCursor() -{ - UWPShowCursor(); - UWPSetMousePosition(mousePosition); // The mouse is hidden in the center of the screen - move it to where it should appear - toggleCursorLock = false; -} - -// Disables cursor (lock cursor) -void UWPDisableCursor() -{ - UWPHideCursor(); - toggleCursorLock = true; -} - -// Get one mouse button state -static bool UWPGetMouseButtonStatus(int button) -{ - return currentMouseState[button]; -} - -// Poll (store) all input events -void UWP_PollInput() -{ - // Register previous keyboard state - for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; - - // Process Mouse - { - // Register previous mouse states - for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i]; - previousMouseWheelY = currentMouseWheelY; - currentMouseWheelY = 0; - - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - if (toggleCursorLock) - { - // Track cursor movement delta, recenter it on the client - mousePosition.x += mouseDelta.x; - mousePosition.y += mouseDelta.y; - - // Why we're not using UWPSetMousePosition here... - // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. - // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition" - Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; - window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); - } - else - { - // Record the cursor's position relative to the client - mousePosition.x = window->PointerPosition.X - window->Bounds.X; - mousePosition.y = window->PointerPosition.Y - window->Bounds.Y; - } - - mouseDelta = { 0 ,0 }; - } - - // Process Gamepads - { - // Check if gamepads are ready - for (int i = 0; i < MAX_GAMEPADS; i++) - { - // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of - // connected gamepads with their spot in the list, but this has serious robustness problems - // e.g. player 1, 2, and 3 are playing a game - if player2 disconnects, p3's controller would now be mapped to p2's character since p3 is now second in the list. - - gamepadReady[i] = (i < Gamepad::Gamepads->Size); - } - - // Get current gamepad state - for (int i = 0; i < MAX_GAMEPADS; i++) - { - if (gamepadReady[i]) - { - // Register previous gamepad states - for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; - - // Get current gamepad state - auto gamepad = Gamepad::Gamepads->GetAt(i); - GamepadReading reading = gamepad->GetCurrentReading(); - - // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP - - // Get current axis state - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; - } - } - } - -} - -// The following functions were ripped from core.c and have *no additional work done on them* -// Detect if a key has been pressed once -bool UWPIsKeyPressed(int key) -{ - bool pressed = false; - - if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true; - else pressed = false; - - return pressed; -} - -// Detect if a key is being pressed (key held down) -bool UWPIsKeyDown(int key) -{ - if (GetKeyStatus(key) == 1) return true; - else return false; -} - -// Detect if a key has been released once -bool UWPIsKeyReleased(int key) -{ - bool released = false; - - if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true; - else released = false; - - return released; -} - -// Detect if a key is NOT being pressed (key not held down) -bool UWPIsKeyUp(int key) -{ - if (GetKeyStatus(key) == 0) return true; - else return false; -} - -/* OTHER CODE */ - -// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. -inline float ConvertDipsToPixels(float dips, float dpi) -{ - static const float dipsPerInch = 96.0f; - return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. -} - -// Implementation of the IFrameworkViewSource interface, necessary to run our app. -ref class SimpleApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource -{ -public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() - { - return ref new App(); - } -}; - -// The main function creates an IFrameworkViewSource for our app, and runs the app. -[Platform::MTAThread] -int main(Platform::Array^) -{ - auto simpleApplicationSource = ref new SimpleApplicationSource(); - CoreApplication::Run(simpleApplicationSource); - - return 0; -} - -App::App() : - mWindowClosed(false), - mWindowVisible(true) -{ -} - -// The first method called when the IFrameworkView is being created. -void App::Initialize(CoreApplicationView^ applicationView) -{ - // Register event handlers for app lifecycle. This example includes Activated, so that we - // can make the CoreWindow active and start rendering on the window. - applicationView->Activated += ref new TypedEventHandler(this, &App::OnActivated); - - // Logic for other event handlers could go here. - // Information about the Suspending and Resuming event handlers can be found here: - // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx - - CoreApplication::Resuming += ref new EventHandler(this, &App::OnResuming); -} - -// Called when the CoreWindow object is created (or re-created). -void App::SetWindow(CoreWindow^ window) -{ - window->SizeChanged += ref new TypedEventHandler(this, &App::OnWindowSizeChanged); - window->VisibilityChanged += ref new TypedEventHandler(this, &App::OnVisibilityChanged); - window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); - - window->PointerPressed += ref new TypedEventHandler(this, &App::PointerPressed); - window->PointerReleased += ref new TypedEventHandler(this, &App::PointerReleased); - window->PointerWheelChanged += ref new TypedEventHandler(this, &App::PointerWheelChanged); - window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); - window->KeyUp += ref new TypedEventHandler(this, &App::OnKeyUp); - - Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &App::MouseMoved); - - DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); - currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); - currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); - - // The CoreWindow has been created, so EGL can be initialized. - - uwpWindow = (EGLNativeWindowType)window; - - InitWindow(800, 450, NULL); -} - -// Initializes scene resources -void App::Load(Platform::String^ entryPoint) -{ - // InitWindow() --> rlglInit() -} - -static int posX = 100; -static int posY = 100; -static int time = 0; -// This method is called after the window becomes active. -void App::Run() -{ - while (!mWindowClosed) - { - if (mWindowVisible) - { - // Draw - BeginDrawing(); - - ClearBackground(RAYWHITE); - - posX += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_X] * 5; - posY += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_Y] * -5; - DrawRectangle(posX, posY, 400, 100, RED); - - DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); - - DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE); - - if (UWPIsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); - - if (UWPIsKeyPressed(KEY_A)) - { - posX -= 50; - UWPEnableCursor(); - } - - if (UWPIsKeyPressed(KEY_D)) - { - posX += 50; - UWPDisableCursor(); - } - - if (currentKeyState[KEY_LEFT_ALT]) DrawRectangle(250, 250, 20, 20, BLACK); - if (currentKeyState[KEY_BACKSPACE]) DrawRectangle(280, 250, 20, 20, BLACK); - if (currentMouseState[MOUSE_LEFT_BUTTON]) DrawRectangle(280, 250, 20, 20, BLACK); - - static int pos = 0; - pos -= currentMouseWheelY; - - DrawRectangle(280, pos + 50, 20, 20, BLACK); - DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); - - EndDrawing(); - - UWP_PollInput(); - - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - } - else - { - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); - } - } - - CloseWindow(); -} - -// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView -// class is torn down while the app is in the foreground. -void App::Uninitialize() -{ - // CloseWindow(); -} - -// Application lifecycle event handler. -void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) -{ - // Run() won't start until the CoreWindow is activated. - CoreWindow::GetForCurrentThread()->Activate(); -} - -void App::OnResuming(Object^ sender, Object^ args) -{ - // Restore any data or state that was unloaded on suspend. By default, data - // and state are persisted when resuming from suspend. Note that this event - // does not occur if the app was previously terminated. -} - -void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) -{ - // TODO: Update window and render area size - //m_deviceResources->SetLogicalSize(Size(sender->Bounds.Width, sender->Bounds.Height)); - //m_main->UpdateForWindowSizeChange(); -} - -// Window event handlers. -void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) -{ - mWindowVisible = args->Visible; - - // raylib core has the variable windowMinimized to register state, - // it should be modifyed by this event... -} - -void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) -{ - mWindowClosed = true; - - // raylib core has the variable windowShouldClose to register state, - // it should be modifyed by this event... -} - -void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) -{ - //m_deviceResources->SetDpi(sender->LogicalDpi); - //m_main->UpdateForWindowSizeChange(); -} - -void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) -{ - //m_deviceResources->SetCurrentOrientation(sender->CurrentOrientation); - //m_main->UpdateForWindowSizeChange(); -} diff --git a/projects/VS2015.UWP/raylib.App.UWP/App.h b/projects/VS2015.UWP/raylib.App.UWP/App.h deleted file mode 100644 index 5b58528b..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/App.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include "pch.h" - -namespace raylibUWP -{ - ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView - { - public: - App(); - - // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); - virtual void Load(Platform::String^ entryPoint); - virtual void Run(); - virtual void Uninitialize(); - - protected: - - // Application lifecycle event handlers. - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); - void OnResuming(Platform::Object^ sender, Platform::Object^ args); - - // Window event handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); - - // DisplayInformation event handlers. - void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); - void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); - - // Input event handlers - void PointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void PointerReleased(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); - void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); - void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args); - void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - - private: - - bool mWindowClosed; - bool mWindowVisible; - }; -} diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png b/projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png deleted file mode 100644 index e26771cb..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png b/projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png deleted file mode 100644 index 1eb0d9d5..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png b/projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png deleted file mode 100644 index c951e031..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png b/projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png deleted file mode 100644 index dcb67271..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png b/projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png deleted file mode 100644 index 9dd94b62..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest b/projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest deleted file mode 100644 index 56020a50..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - raylibUWP - raysan5 - Assets\StoreLogo.png - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/packages.config b/projects/VS2015.UWP/raylib.App.UWP/packages.config deleted file mode 100644 index 70c3dea0..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/pch.cpp b/projects/VS2015.UWP/raylib.App.UWP/pch.cpp deleted file mode 100644 index bcb5590b..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/pch.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pch.h" diff --git a/projects/VS2015.UWP/raylib.App.UWP/pch.h b/projects/VS2015.UWP/raylib.App.UWP/pch.h deleted file mode 100644 index dcbd2378..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/pch.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include - -// OpenGL ES includes -#include -#include - -// EGL includes -#include -#include -#include - -// ANGLE include for Windows Store -#include \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx b/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx deleted file mode 100644 index 0ada3be0..00000000 Binary files a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx and /dev/null differ diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters b/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters deleted file mode 100644 index 4e83c979..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - Assets - - - Assets - - - Assets - - - Assets - - - Assets - - - - - - - - - - - - - - {d16954bb-de54-472b-ac10-ecab10d3fdc8} - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user b/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user deleted file mode 100644 index abe8dd89..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj deleted file mode 100644 index f20a276e..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj +++ /dev/null @@ -1,145 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - Debug - ARM - - - Release - ARM - - - - {b842558c-c034-4e4b-9457-a286f26e83cc} - raylibUWP - en-US - 14.0 - true - Windows Store - 10.0.14393.0 - 10.0.14393.0 - 10.0 - raylib.App.UWP - - - - Application - true - v140 - - - Application - false - true - v140 - - - - - - - - raylib.App.UWP.TemporaryKey.pfx - - - $(IncludePath) - $(LibraryPath) - - - - mincore.lib;raylib.lib;%(AdditionalDependencies) - %(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\arm;$(VCInstallDir)\lib\arm;$(SolutionDir)\raylib\Debug - - - - - mincore.lib;raylib.lib;%(AdditionalDependencies) - $(SolutionDir)raylib\Debug;%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store; $(VCInstallDir)\lib - - - - - mincore.lib;raylib.lib;%(AdditionalDependencies) - C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\x64\Debug;C:\Users\Alumno\Downloads\angle\UWP_OpenGLES2\raylib;%(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\amd64;$(VCInstallDir)\lib\amd64 - - - - - pch.h - $(IntDir)pch.pch - $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) - /bigobj %(AdditionalOptions) - 4453;28204 - _DEBUG;%(PreprocessorDefinitions) - - - true - - - - - pch.h - $(IntDir)pch.pch - $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) - /bigobj %(AdditionalOptions) - 4453;28204 - NDEBUG;%(PreprocessorDefinitions) - Default - false - - - /NODEFAULTLIB %(AdditionalOptions) - - - - - - - - - - - - - - - - - Create - - - - - Designer - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.UWP.sln b/projects/VS2015.UWP/raylib.UWP.sln deleted file mode 100644 index 087e84f4..00000000 --- a/projects/VS2015.UWP/raylib.UWP.sln +++ /dev/null @@ -1,51 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib.App.UWP", "raylib.App.UWP\raylib.App.UWP.vcxproj", "{B842558C-C034-4E4B-9457-A286F26E83CC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib", "raylib\raylib.vcxproj", "{E89D61AC-55DE-4482-AFD4-DF7242EBC859}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM = Debug|ARM - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|ARM = Release|ARM - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.ActiveCfg = Debug|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.Build.0 = Debug|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.Deploy.0 = Debug|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.ActiveCfg = Debug|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.Build.0 = Debug|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.Deploy.0 = Debug|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.ActiveCfg = Debug|Win32 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.Build.0 = Debug|Win32 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.Deploy.0 = Debug|Win32 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.ActiveCfg = Release|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.Build.0 = Release|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.Deploy.0 = Release|ARM - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.ActiveCfg = Release|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.Build.0 = Release|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.Deploy.0 = Release|x64 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.ActiveCfg = Release|Win32 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Build.0 = Release|Win32 - {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Deploy.0 = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|ARM.ActiveCfg = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|ARM.Build.0 = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x64.ActiveCfg = Debug|x64 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.ActiveCfg = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.Build.0 = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|ARM.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x64.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x86.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/projects/VS2015.UWP/raylib/raylib.vcxproj b/projects/VS2015.UWP/raylib/raylib.vcxproj deleted file mode 100644 index ed8eb80b..00000000 --- a/projects/VS2015.UWP/raylib/raylib.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {E89D61AC-55DE-4482-AFD4-DF7242EBC859} - Win32Proj - raylib - 10.0.16299.0 - - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)$(ProjectName)\$(Configuration)\ - - - - $(SolutionDir)$(ProjectName)\$(Configuration)\ - $(SolutionDir)$(ProjectName)\$(Configuration)\temp - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - CompileAsC - $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE - - - Windows - - - %(AdditionalLibraryDirectories) - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - CompileAsC - $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\include\ANGLE - - - Windows - - - %(AdditionalLibraryDirectories) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - $(SolutionDir)..\..\src\external\ANGLE;$(SolutionDir)..\..\release\include - CompileAsC - - - Windows - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - $(SolutionDir)..\..\src\external\include\ANGLE;$(SolutionDir)..\..\release\include - CompileAsC - - - Windows - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp new file mode 100644 index 00000000..ae137ed2 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -0,0 +1,78 @@ +#include "pch.h" +#include "app.h" + +#include "raylib.h" + +using namespace raylibUWP; + +// The main function creates an IFrameworkViewSource for our app, and runs the app. +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto appSource = ref new ApplicationSource(); + CoreApplication::Run(appSource); + + return 0; +} + +App::App() +{ + //This does not work... need to fix this. + SetConfigFlags(0); + + Setup(640, 480); +} + +static int posX = 100; +static int posY = 100; +static int gTime = 0; + +// This method is called every frame +void App::Update() +{ + //return; + // Draw + BeginDrawing(); + + ClearBackground(RAYWHITE); + + posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X) * 5; + posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y) * -5; + + DrawRectangle(posX, posY, 400, 100, RED); + + DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + + auto mPos = GetMousePosition(); + + DrawCircle(mPos.x, mPos.y, 40, BLUE); + + if (IsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); + + if (IsKeyPressed(KEY_A)) + { + posX -= 50; + EnableCursor(); + } + + if (IsKeyPressed(KEY_D)) + { + posX += 50; + DisableCursor(); + } + + if (IsKeyDown(KEY_LEFT_ALT)) + DrawRectangle(250, 250, 20, 20, BLACK); + if (IsKeyDown(KEY_BACKSPACE)) + DrawRectangle(280, 250, 20, 20, BLACK); + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + DrawRectangle(280, 250, 20, 20, BLACK); + + static int pos = 0; + pos -= GetMouseWheelMove(); + + DrawRectangle(280, pos + 50, 20, 20, BLACK); + DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE); + + EndDrawing(); +} \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.h b/projects/VS2017.UWP/raylib.App.UWP/App.h new file mode 100644 index 00000000..26c1d400 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/App.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "pch.h" + +//Define what header we use for BaseApp.h +#define PCH "pch.h" + +//Enable hold hack +#define HOLDHACK + +#include "BaseApp.h" + +namespace raylibUWP +{ + ref class App sealed : public BaseApp + { + public: + App(); + + // IFrameworkView Methods. + void Update() override; + }; +} diff --git a/projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png new file mode 100644 index 00000000..e26771cb Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png new file mode 100644 index 00000000..1eb0d9d5 Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png new file mode 100644 index 00000000..c951e031 Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png new file mode 100644 index 00000000..dcb67271 Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png new file mode 100644 index 00000000..9dd94b62 Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h new file mode 100644 index 00000000..e27909e2 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -0,0 +1,567 @@ +/********************************************************************************************** +* +* raylib.BaseApp - UWP App generic code for managing interface between C and C++ +* +* LICENSE: zlib/libpng +* +* CONFIGURATION: +* +* #define PCH +* This defines what header is the PCH and needs to be included +* +* #define HOLDHACK +* This enables a hack to fix flickering key presses (Temporary) +* +* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) +* +* This software is provided "as-is", without any express or implied warranty. In no event +* will the authors be held liable for any damages arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, including commercial +* applications, and to alter it and redistribute it freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not claim that you +* wrote the original software. If you use this software in a product, an acknowledgment +* in the product documentation would be appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be misrepresented +* as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +* +**********************************************************************************************/ + +#pragma once + +#if defined(PCH) +#include PCH +#endif + +#include +#include +#include + +//EGL +#include + +#include "raylib.h" +#include "utils.h" + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::Devices::Input; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Gaming::Input; +using namespace Windows::Graphics::Display; +using namespace Microsoft::WRL; +using namespace Platform; + +extern "C" { EGLNativeWindowType uwpWindow; }; + +/* +TODO list: + - Cache reference to our CoreWindow? + - Implement gestures support +*/ + +// Stand-ins for "core.c" variables +#define MAX_GAMEPADS 4 // Max number of gamepads supported +#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) +#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) + +//Mouse cursor locking +bool cursorLocked = false; +Vector2 mouseDelta = {0, 0}; + +//Our mouse cursor +CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type + +//Base app implementation +ref class BaseApp : public Windows::ApplicationModel::Core::IFrameworkView +{ +public: + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView) + { + // Register event handlers for app lifecycle. This example includes Activated, so that we + // can make the CoreWindow active and start rendering on the window. + applicationView->Activated += ref new TypedEventHandler(this, &BaseApp::OnActivated); + + // Logic for other event handlers could go here. + // Information about the Suspending and Resuming event handlers can be found here: + // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx + + CoreApplication::Resuming += ref new EventHandler(this, &BaseApp::OnResuming); + } + + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window) + { + window->SizeChanged += ref new TypedEventHandler(this, &BaseApp::OnWindowSizeChanged); + window->VisibilityChanged += ref new TypedEventHandler(this, &BaseApp::OnVisibilityChanged); + window->Closed += ref new TypedEventHandler(this, &BaseApp::OnWindowClosed); + + window->PointerPressed += ref new TypedEventHandler(this, &BaseApp::PointerPressed); + window->PointerWheelChanged += ref new TypedEventHandler(this, &BaseApp::PointerWheelChanged); + window->KeyDown += ref new TypedEventHandler(this, &BaseApp::OnKeyDown); + window->KeyUp += ref new TypedEventHandler(this, &BaseApp::OnKeyUp); + + Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &BaseApp::MouseMoved); + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &BaseApp::OnDpiChanged); + currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &BaseApp::OnOrientationChanged); + + // The CoreWindow has been created, so EGL can be initialized. + + uwpWindow = (EGLNativeWindowType)window; + + InitWindow(width, height, NULL); + } + + virtual void Load(Platform::String^ entryPoint) {} + + void Setup(int width, int height) + { + //Set dimensions + this->width = width; + this->height = height; + } + + virtual void Run() + { + //Get display dimensions + DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); + Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels }; + + //Send display dimensions + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetDisplayDims; + msg->Vector0 = screenSize; + UWPSendMessage(msg); + + //Send the time to the core + using clock = std::chrono::high_resolution_clock; + auto timeStart = clock::now(); + + //Set fps if 0 + if (GetFPS() <= 0) + SetTargetFPS(60); + + while (!mWindowClosed) + { + if (mWindowVisible) + { + //Send time + auto delta = clock::now() - timeStart; + + UWPMessage* timeMsg = CreateUWPMessage(); + timeMsg->Type = SetGameTime; + timeMsg->Double0 = std::chrono::duration_cast(delta).count(); + UWPSendMessage(timeMsg); + + //Call update function + Update(); + + PollInput(); + + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + } + else + { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + } + + CloseWindow(); + } + + //Called every frame (Maybe add draw) + virtual void Update() {} + + virtual void Uninitialize() {} + +protected: + + // Input polling + void PollInput() + { + // Process Messages + { + //Loop over pending messages + while (UWPHasMessages()) + { + //Get the message + auto msg = UWPGetMessage(); + + //Carry out the command + switch(msg->Type) + { + case ShowMouse: //Do the same thing because of how UWP works... + case UnlockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + cursorLocked = false; + MoveMouse(GetMousePosition()); + break; + } + case HideMouse: //Do the same thing because of how UWP works... + case LockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorLocked = true; + break; + } + case SetMouseLocation: + { + MoveMouse(msg->Vector0); + break; + } + } + + //Delete the message + DeleteUWPMessage(msg); + } + } + + // Process Keyboard + { + for (int k = 0x08; k < 0xA6; k++) { + auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k); + +#ifdef HOLDHACK + //Super hacky way of waiting three frames to see if we are ready to register the key as deregistered + //This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering + if (KeyboardStateHack[k] == 2) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + KeyboardStateHack[k] = 3; + } + } + else if (KeyboardStateHack[k] == 3) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + KeyboardStateHack[k] = 4; + } + } + else if (KeyboardStateHack[k] == 4) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + //Reset key... + KeyboardStateHack[k] = 0; + + //Tell core + RegisterKey(k, 0); + } + } +#endif + //Left and right alt, KeyUp and KeyDown are not called for it + //No need to hack because this is not a character + + //TODO: Maybe do all other key registrations like this, no more key events? + + if (k == 0xA4 || k == 0xA5) + { + if ((state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) + { + RegisterKey(k, 1); + } + else + { + RegisterKey(k, 0); + } + } + } + } + + // Process Mouse + { + + if (CurrentPointerID > -1) { + auto point = PointerPoint::GetCurrentPoint(CurrentPointerID); + auto props = point->Properties; + + if (props->IsLeftButtonPressed) + { + RegisterClick(MOUSE_LEFT_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_LEFT_BUTTON, 0); + } + + if (props->IsRightButtonPressed) + { + RegisterClick(MOUSE_RIGHT_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_RIGHT_BUTTON, 0); + } + + if (props->IsMiddleButtonPressed) + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 0); + } + } + + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + + if (cursorLocked) + { + // Track cursor movement delta, recenter it on the client + auto curMousePos = GetMousePosition(); + + auto x = curMousePos.x + mouseDelta.x; + auto y = curMousePos.y + mouseDelta.y; + + UpdateMousePosition({ x, y }); + + // Why we're not using UWPSetMousePosition here... + // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. + // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition" + Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; + window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); + } + else + { + // Record the cursor's position relative to the client + auto x = window->PointerPosition.X - window->Bounds.X; + auto y = window->PointerPosition.Y - window->Bounds.Y; + + UpdateMousePosition({ x, y }); + } + + mouseDelta = { 0 ,0 }; + } + + // Process Gamepads + { + // Check if gamepads are ready + for (int i = 0; i < MAX_GAMEPADS; i++) + { + // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of + // connected gamepads with their spot in the list, but this has serious robustness problems + // e.g. player 1, 2, and 3 are playing a game - if player2 disconnects, p3's controller would now be mapped to p2's character since p3 is now second in the list. + + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadActive; + msg->Int0 = i; + msg->Bool0 = i < Gamepad::Gamepads->Size; + UWPSendMessage(msg); + } + + // Get current gamepad state + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (IsGamepadAvailable(i)) + { + // Get current gamepad state + auto gamepad = Gamepad::Gamepads->GetAt(i); + GamepadReading reading = gamepad->GetCurrentReading(); + + // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP + + // Get current axis state + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger); + } + } + } + } + + // Application lifecycle event handlers. + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args) + { + // Run() won't start until the CoreWindow is activated. + CoreWindow::GetForCurrentThread()->Activate(); + } + + void OnResuming(Platform::Object^ sender, Platform::Object^ args) {} + + // Window event handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HandleResize; + UWPSendMessage(msg); + } + + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) + { + mWindowVisible = args->Visible; + } + + void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args) + { + mWindowClosed = true; + } + + // DisplayInformation event handlers. + void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args) {} + void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args) {} + + // Input event handlers + void PointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) + { + //Get the current active pointer ID for our loop + CurrentPointerID = args->CurrentPoint->PointerId; + args->Handled = true; + } + + void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ScrollWheelUpdate; + msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta; + UWPSendMessage(msg); + } + + void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) + { + mouseDelta.x += args->MouseDelta.X; + mouseDelta.y += args->MouseDelta.Y; + } + + void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) + { +#ifdef HOLDHACK + //Start the hack + KeyboardStateHack[(int)args->VirtualKey] = 1; +#endif + + RegisterKey((int)args->VirtualKey, 1); + } + + void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) + { +#ifdef HOLDHACK + //The same hack + if (KeyboardStateHack[(int)args->VirtualKey] == 1) + { + KeyboardStateHack[(int)args->VirtualKey] = 2; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 2) + { + KeyboardStateHack[(int)args->VirtualKey] = 3; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 3) + { + KeyboardStateHack[(int)args->VirtualKey] = 4; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 4) + { + RegisterKey((int)args->VirtualKey, 0); + KeyboardStateHack[(int)args->VirtualKey] = 0; + } +#else + //No hack, allow flickers + RegisterKey((int)args->VirtualKey, 0); +#endif + } + +private: + + void RegisterKey(int key, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterKey; + msg->Int0 = key; + msg->Char0 = status; + UWPSendMessage(msg); + } + + void MoveMouse(Vector2 pos) + { + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(pos.x + window->Bounds.X, pos.y + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + } + + void RegisterGamepadButton(int gamepad, int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadButton; + msg->Int0 = gamepad; + msg->Int1 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } + + void RegisterGamepadAxis(int gamepad, int axis, float value) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadAxis; + msg->Int0 = gamepad; + msg->Int1 = axis; + msg->Float0 = value; + UWPSendMessage(msg); + } + + void UpdateMousePosition(Vector2 pos) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UpdateMouseLocation; + msg->Vector0 = pos; + UWPSendMessage(msg); + } + + void RegisterClick(int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterClick; + msg->Int0 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } + + bool mWindowClosed = false; + bool mWindowVisible = true; + + int width = 640; + int height = 480; + + int CurrentPointerID = -1; + +#ifdef HOLDHACK + char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5 +#endif +}; + +//Application source for creating the program +template +ref class ApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() + { + return ref new AppType(); + } +}; \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest b/projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest new file mode 100644 index 00000000..56020a50 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest @@ -0,0 +1,26 @@ + + + + + + raylibUWP + raysan5 + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/packages.config b/projects/VS2017.UWP/raylib.App.UWP/packages.config new file mode 100644 index 00000000..70c3dea0 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/pch.cpp b/projects/VS2017.UWP/raylib.App.UWP/pch.cpp new file mode 100644 index 00000000..bcb5590b --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/projects/VS2017.UWP/raylib.App.UWP/pch.h b/projects/VS2017.UWP/raylib.App.UWP/pch.h new file mode 100644 index 00000000..dcbd2378 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/pch.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +// OpenGL ES includes +#include +#include + +// EGL includes +#include +#include +#include + +// ANGLE include for Windows Store +#include \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx new file mode 100644 index 00000000..0ada3be0 Binary files /dev/null and b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx differ diff --git a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters new file mode 100644 index 00000000..4e83c979 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters @@ -0,0 +1,42 @@ + + + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + + + + + + + + + {d16954bb-de54-472b-ac10-ecab10d3fdc8} + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj new file mode 100644 index 00000000..421d7209 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM + + + Release + ARM + + + + {b842558c-c034-4e4b-9457-a286f26e83cc} + raylibUWP + en-US + 14.0 + true + Windows Store + 10.0.17763.0 + 10.0.17763.0 + 10.0 + raylib.App.UWP + + + + Application + true + v141 + + + Application + false + true + v140 + + + + + + + + raylib.App.UWP.TemporaryKey.pfx + + + $(IncludePath) + $(LibraryPath) + + + + mincore.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\arm;$(VCInstallDir)\lib\arm;$(SolutionDir)\raylib\Debug + + + + + mincore.lib;%(AdditionalDependencies) + $(SolutionDir)raylib\Debug;%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store; $(VCInstallDir)\lib + + + + + mincore.lib;%(AdditionalDependencies) + C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\x64\Debug;C:\Users\Alumno\Downloads\angle\UWP_OpenGLES2\raylib;%(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\amd64;$(VCInstallDir)\lib\amd64 + + + + + pch.h + $(IntDir)pch.pch + $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) + 4453;28204 + PLATFORM_UWP;_DEBUG;%(PreprocessorDefinitions) + + + true + + + + + pch.h + $(IntDir)pch.pch + $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) + 4453;28204 + PLATFORM_UWP;NDEBUG;%(PreprocessorDefinitions) + Default + false + + + /NODEFAULTLIB %(AdditionalOptions) + + + + + + + + + + + + + + + + + + Create + + + + + Designer + + + + + + + {ea91e088-7c71-4f32-b761-e054305cd519} + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP.sln b/projects/VS2017.UWP/raylib.UWP.sln new file mode 100644 index 00000000..fb528655 --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP.sln @@ -0,0 +1,57 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.438 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib.App.UWP", "raylib.App.UWP\raylib.App.UWP.vcxproj", "{B842558C-C034-4E4B-9457-A286F26E83CC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib.UWP", "raylib.UWP\raylib.UWP.vcxproj", "{EA91E088-7C71-4F32-B761-E054305CD519}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.ActiveCfg = Debug|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.Build.0 = Debug|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|ARM.Deploy.0 = Debug|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.ActiveCfg = Debug|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.Build.0 = Debug|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x64.Deploy.0 = Debug|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.ActiveCfg = Debug|Win32 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.Build.0 = Debug|Win32 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Debug|x86.Deploy.0 = Debug|Win32 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.ActiveCfg = Release|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.Build.0 = Release|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|ARM.Deploy.0 = Release|ARM + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.ActiveCfg = Release|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.Build.0 = Release|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x64.Deploy.0 = Release|x64 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.ActiveCfg = Release|Win32 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Build.0 = Release|Win32 + {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Deploy.0 = Release|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|ARM.ActiveCfg = Debug|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|ARM.Build.0 = Debug|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x64.ActiveCfg = Debug|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x64.Build.0 = Debug|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x86.ActiveCfg = Debug|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x86.Build.0 = Debug|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|ARM.ActiveCfg = Release|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|ARM.Build.0 = Release|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x64.ActiveCfg = Release|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x64.Build.0 = Release|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x86.ActiveCfg = Release|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E32C7998-071A-419B-8869-E957374307CA} + EndGlobalSection +EndGlobal diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj new file mode 100644 index 00000000..f05f829c --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj @@ -0,0 +1,231 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {ea91e088-7c71-4f32-b761-e054305cd519} + StaticLibrary + raylib_UWP + en-US + 14.0 + true + Windows Store + 10.0.17763.0 + 10.0.15063.0 + 10.0 + + + + StaticLibrary + true + v141 + + + StaticLibrary + true + v141 + + + StaticLibrary + true + v141 + + + StaticLibrary + false + true + v141 + + + StaticLibrary + false + true + v141 + + + StaticLibrary + false + true + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters new file mode 100644 index 00000000..cbad7c9b --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/camera.h b/src/camera.h index e103b293..d80f8346 100644 --- a/src/camera.h +++ b/src/camera.h @@ -256,7 +256,7 @@ void SetCameraMode(Camera camera, int mode) //cameraAngle.y = -60.0f*DEG2RAD; // Camera angle in plane XY (0 aligned with X, move positive CW) playerEyesPosition = camera.position.y; - + // Lock cursor for first person and third person cameras if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor(); else EnableCursor(); diff --git a/src/core.c b/src/core.c index 0d17fdad..db75979a 100644 --- a/src/core.c +++ b/src/core.c @@ -134,7 +134,7 @@ #include // Required for: tolower() [Used in IsFileExtension()] #include // Required for stat() [Used in GetLastWriteTime()] -#if defined(PLATFORM_DESKTOP) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__)) +#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__)) #include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()] #else #include // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()] @@ -391,6 +391,7 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto static pthread_t gamepadThreadId; // Gamepad reading thread id static char gamepadName[64]; // Gamepad name holder #endif + //----------------------------------------------------------------------------------- // Timming system variables @@ -401,6 +402,7 @@ static double updateTime = 0.0; // Time measure for frame update static double drawTime = 0.0; // Time measure for frame draw static double frameTime = 0.0; // Time measure for one frame static double targetTime = 0.0; // Desired time for one frame, if 0 not applied + //----------------------------------------------------------------------------------- // Config internal variables @@ -486,10 +488,6 @@ static void InitGamepad(void); // Init raw gamepad inpu static void *GamepadThread(void *arg); // Mouse reading thread #endif -#if defined(PLATFORM_UWP) -// TODO: Define functions required to manage inputs -#endif - #if defined(_WIN32) // NOTE: We include Sleep() function signature here to avoid windows.h inclusion void __stdcall Sleep(unsigned long msTimeout); // Required for Wait() @@ -810,6 +808,7 @@ void SetWindowIcon(Image image) // Set title for window (only PLATFORM_DESKTOP) void SetWindowTitle(const char *title) { + windowTitle = title; #if defined(PLATFORM_DESKTOP) glfwSetWindowTitle(window, title); #endif @@ -887,7 +886,7 @@ int GetScreenHeight(void) // Get native window handle void *GetWindowHandle(void) { -#if defined(_WIN32) +#if defined(PLATFORM_DESKTOP) && defined(_WIN32) // NOTE: Returned handle is: void *HWND (windows.h) return glfwGetWin32Window(window); #elif defined(__linux__) @@ -1026,6 +1025,11 @@ void ShowCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ShowMouse; + SendMessageToUWP(msg); #endif cursorHidden = false; } @@ -1035,6 +1039,11 @@ void HideCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HideMouse; + SendMessageToUWP(msg); #endif cursorHidden = true; } @@ -1053,6 +1062,11 @@ void EnableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = LockMouse; + SendMessageToUWP(msg); #endif cursorHidden = false; } @@ -1065,6 +1079,11 @@ void DisableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UnlockMouse; + SendMessageToUWP(msg); #endif cursorHidden = true; } @@ -1145,6 +1164,8 @@ void EndDrawing(void) frameTime += extraTime; } + + return; } // Initialize 2D mode with custom camera (2D) @@ -1421,6 +1442,11 @@ double GetTime(void) return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer() #endif + +#if defined(PLATFORM_UWP) + //Updated through messages + return currentTime; +#endif } // Returns hexadecimal value for a Color @@ -2209,6 +2235,13 @@ void SetMousePosition(int x, int y) // NOTE: emscripten not implemented glfwSetCursorPos(window, mousePosition.x, mousePosition.y); #endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetMouseLocation; + msg->Vector0.x = mousePosition.x; + msg->Vector0.y = mousePosition.y; + SendMessageToUWP(msg); +#endif } // Set mouse offset @@ -2736,6 +2769,8 @@ static bool InitGraphicsDevice(int width, int height) eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); + //SetupFramebuffer(displayWidth, displayHeight); //Borked + #else // PLATFORM_ANDROID, PLATFORM_RPI EGLint numConfigs; @@ -2906,8 +2941,8 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_WARNING, "DOWNSCALING: Required screen size (%ix%i) is bigger than display size (%ix%i)", screenWidth, screenHeight, displayWidth, displayHeight); // Downscaling to fit display with border-bars - float widthRatio = (float)displayWidth/(float)screenWidth; - float heightRatio = (float)displayHeight/(float)screenHeight; + float widthRatio = (float)displayWidth / (float)screenWidth; + float heightRatio = (float)displayHeight / (float)screenHeight; if (widthRatio <= heightRatio) { @@ -2925,7 +2960,7 @@ static void SetupFramebuffer(int width, int height) } // Screen scaling required - float scaleRatio = (float)renderWidth/(float)screenWidth; + float scaleRatio = (float)renderWidth / (float)screenWidth; screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio); // NOTE: We render to full display resolution! @@ -2941,13 +2976,13 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_INFO, "UPSCALING: Required screen size: %i x %i -> Display size: %i x %i", screenWidth, screenHeight, displayWidth, displayHeight); // Upscaling to fit display with border-bars - float displayRatio = (float)displayWidth/(float)displayHeight; - float screenRatio = (float)screenWidth/(float)screenHeight; + float displayRatio = (float)displayWidth / (float)displayHeight; + float screenRatio = (float)screenWidth / (float)screenHeight; if (displayRatio <= screenRatio) { renderWidth = screenWidth; - renderHeight = (int)round((float)screenWidth/displayRatio); + renderHeight = (int)round((float)screenWidth / displayRatio); renderOffsetX = 0; renderOffsetY = (renderHeight - screenHeight); } @@ -2996,7 +3031,7 @@ static void InitTimer(void) // http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected static void Wait(float ms) { -#if defined(SUPPORT_BUSY_WAIT_LOOP) +#if defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_UWP) double prevTime = GetTime(); double nextTime = 0.0; @@ -3029,7 +3064,7 @@ static bool GetKeyStatus(int key) // NOTE: Android supports up to 260 keys if (key < 0 || key > 260) return false; else return currentKeyState[key]; -#elif defined(PLATFORM_RPI) +#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP) // NOTE: Keys states are filled in PollInputEvents() if (key < 0 || key > 511) return false; else return currentKeyState[key]; @@ -3044,7 +3079,7 @@ static bool GetMouseButtonStatus(int button) #elif defined(PLATFORM_ANDROID) // TODO: Check for virtual mouse? return false; -#elif defined(PLATFORM_RPI) +#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP) // NOTE: Mouse buttons states are filled in PollInputEvents() return currentMouseState[button]; #endif @@ -3090,6 +3125,197 @@ static void PollInputEvents(void) } #endif +#if defined(PLATFORM_UWP) + + // Register previous keys states + for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i]; + + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (gamepadReady[i]) + { + for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; + } + } + + // Register previous mouse states + previousMouseWheelY = currentMouseWheelY; + currentMouseWheelY = 0; + for (int i = 0; i < 3; i++) + { + previousMouseState[i] = currentMouseState[i]; + + } + + // Loop over pending messages + while (HasMessageFromUWP()) + { + UWPMessage* msg = GetMessageFromUWP(); + + switch (msg->Type) + { + case RegisterKey: + { + //Convert from virtualKey + int actualKey = -1; + + switch (msg->Int0) + { + case 0x08: actualKey = KEY_BACKSPACE; break; + case 0x20: actualKey = KEY_SPACE; break; + case 0x1B: actualKey = KEY_ESCAPE; break; + case 0x0D: actualKey = KEY_ENTER; break; + case 0x2E: actualKey = KEY_DELETE; break; + case 0x27: actualKey = KEY_RIGHT; break; + case 0x25: actualKey = KEY_LEFT; break; + case 0x28: actualKey = KEY_DOWN; break; + case 0x26: actualKey = KEY_UP; break; + case 0x70: actualKey = KEY_F1; break; + case 0x71: actualKey = KEY_F2; break; + case 0x72: actualKey = KEY_F3; break; + case 0x73: actualKey = KEY_F4; break; + case 0x74: actualKey = KEY_F5; break; + case 0x75: actualKey = KEY_F6; break; + case 0x76: actualKey = KEY_F7; break; + case 0x77: actualKey = KEY_F8; break; + case 0x78: actualKey = KEY_F9; break; + case 0x79: actualKey = KEY_F10; break; + case 0x7A: actualKey = KEY_F11; break; + case 0x7B: actualKey = KEY_F12; break; + case 0xA0: actualKey = KEY_LEFT_SHIFT; break; + case 0xA2: actualKey = KEY_LEFT_CONTROL; break; + case 0xA4: actualKey = KEY_LEFT_ALT; break; + case 0xA1: actualKey = KEY_RIGHT_SHIFT; break; + case 0xA3: actualKey = KEY_RIGHT_CONTROL; break; + case 0xA5: actualKey = KEY_RIGHT_ALT; break; + case 0x30: actualKey = KEY_ZERO; break; + case 0x31: actualKey = KEY_ONE; break; + case 0x32: actualKey = KEY_TWO; break; + case 0x33: actualKey = KEY_THREE; break; + case 0x34: actualKey = KEY_FOUR; break; + case 0x35: actualKey = KEY_FIVE; break; + case 0x36: actualKey = KEY_SIX; break; + case 0x37: actualKey = KEY_SEVEN; break; + case 0x38: actualKey = KEY_EIGHT; break; + case 0x39: actualKey = KEY_NINE; break; + case 0x41: actualKey = KEY_A; break; + case 0x42: actualKey = KEY_B; break; + case 0x43: actualKey = KEY_C; break; + case 0x44: actualKey = KEY_D; break; + case 0x45: actualKey = KEY_E; break; + case 0x46: actualKey = KEY_F; break; + case 0x47: actualKey = KEY_G; break; + case 0x48: actualKey = KEY_H; break; + case 0x49: actualKey = KEY_I; break; + case 0x4A: actualKey = KEY_J; break; + case 0x4B: actualKey = KEY_K; break; + case 0x4C: actualKey = KEY_L; break; + case 0x4D: actualKey = KEY_M; break; + case 0x4E: actualKey = KEY_N; break; + case 0x4F: actualKey = KEY_O; break; + case 0x50: actualKey = KEY_P; break; + case 0x51: actualKey = KEY_Q; break; + case 0x52: actualKey = KEY_R; break; + case 0x53: actualKey = KEY_S; break; + case 0x54: actualKey = KEY_T; break; + case 0x55: actualKey = KEY_U; break; + case 0x56: actualKey = KEY_V; break; + case 0x57: actualKey = KEY_W; break; + case 0x58: actualKey = KEY_X; break; + case 0x59: actualKey = KEY_Y; break; + case 0x5A: actualKey = KEY_Z; break; + } + + if (actualKey > -1) + currentKeyState[actualKey] = msg->Char0; + break; + } + + case RegisterClick: + { + currentMouseState[msg->Int0] = msg->Char0; + break; + } + + case ScrollWheelUpdate: + { + currentMouseWheelY += msg->Int0; + break; + } + + case UpdateMouseLocation: + { + mousePosition = msg->Vector0; + break; + } + + case MarkGamepadActive: + { + if (msg->Int0 < MAX_GAMEPADS) + gamepadReady[msg->Int0] = msg->Bool0; + break; + } + + case MarkGamepadButton: + { + if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_BUTTONS) + currentGamepadState[msg->Int0][msg->Int1] = msg->Char0; + break; + } + + case MarkGamepadAxis: + { + if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_AXIS) + gamepadAxisState[msg->Int0][msg->Int1] = msg->Float0; + break; + } + + case SetDisplayDims: + { + displayWidth = msg->Vector0.x; + displayHeight = msg->Vector0.y; + break; + } + + case HandleResize: + { + eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); + eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); + + // If window is resized, viewport and projection matrix needs to be re-calculated + rlViewport(0, 0, screenWidth, screenHeight); // Set viewport width and height + rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix + rlLoadIdentity(); // Reset current matrix (PROJECTION) + rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0) + rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix + rlLoadIdentity(); // Reset current matrix (MODELVIEW) + rlClearScreenBuffers(); // Clear screen buffers (color and depth) + + // Window size must be updated to be used on 3D mode to get new aspect ratio (BeginMode3D()) + // NOTE: Be careful! GLFW3 will choose the closest fullscreen resolution supported by current monitor, + // for example, if reescaling back to 800x450 (desired), it could set 720x480 (closest fullscreen supported) + currentWidth = screenWidth; + currentHeight = screenHeight; + + // NOTE: Postprocessing texture is not scaled to new size + + windowResized = true; + break; + } + + case SetGameTime: + { + currentTime = msg->Double0; + break; + } + + } + + DeleteUWPMessage(msg); //Delete, we are done + } + +#endif + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling double mouseX; @@ -4577,7 +4803,7 @@ static void *GamepadThread(void *arg) // Plays raylib logo appearing animation static void LogoAnimation(void) { -#if !defined(PLATFORM_WEB) +#if !defined(PLATFORM_WEB) && !defined(PLATFORM_UWP) int logoPositionX = screenWidth/2 - 128; int logoPositionY = screenHeight/2 - 128; @@ -4686,4 +4912,4 @@ static void LogoAnimation(void) #endif showLogo = false; // Prevent for repeating when reloading window (Android) -} +} \ No newline at end of file diff --git a/src/external/ANGLE/EGL/eglplatform.h b/src/external/ANGLE/EGL/eglplatform.h index eb3ea70c..7e542ff7 100644 --- a/src/external/ANGLE/EGL/eglplatform.h +++ b/src/external/ANGLE/EGL/eglplatform.h @@ -74,11 +74,16 @@ //#include // raylib edit!!! +#ifndef PLATFORM_UWP typedef void *PVOID; // PVOID is a pointer to any type. This type is declared in WinNT.h typedef PVOID HANDLE; // HANDLE is handle to an object. This type is declared in WinNT.h typedef HANDLE HWND; // HWND is a handle to a window. This type is declared in WinDef.h typedef HANDLE HDC; // HDC is a handle to a device context (DC). This type is declared in WinDef.h typedef HANDLE HBITMAP; // HBITMAP is a handle to a bitmap. This type is declared in WinDef.h +#else +//UWP Fix +#include "Windows.h" +#endif // HDC, HBITMAP and HWND are actually pointers to void. You can cast a long to a HWND like this: HWND h = (HWND)my_long_var; // but very careful of what information is stored in my_long_var. You have to make sure that you have a pointer in there. diff --git a/src/rlgl.h b/src/rlgl.h index 71a1dc4b..ae92f149 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -999,17 +999,17 @@ void rlMultMatrixf(float *matf) } // Multiply the current matrix by a perspective matrix generated by parameters -void rlFrustum(double left, double right, double bottom, double top, double near, double far) +void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar) { - Matrix matPerps = MatrixFrustum(left, right, bottom, top, near, far); + Matrix matPerps = MatrixFrustum(left, right, bottom, top, znear, zfar); *currentMatrix = MatrixMultiply(*currentMatrix, matPerps); } // Multiply the current matrix by an orthographic matrix generated by parameters -void rlOrtho(double left, double right, double bottom, double top, double near, double far) +void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar) { - Matrix matOrtho = MatrixOrtho(left, right, bottom, top, near, far); + Matrix matOrtho = MatrixOrtho(left, right, bottom, top, znear, zfar); *currentMatrix = MatrixMultiply(*currentMatrix, matOrtho); } @@ -1619,7 +1619,7 @@ void rlglInit(int width, int height) if (strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; } -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_WIN32) && defined(_MSC_VER) && !defined(PLATFORM_UWP) //is this a hotfix? I may need to find out why this is broken RL_FREE(extList); #endif diff --git a/src/utils.c b/src/utils.c index 3cff472b..c886d2a7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -132,7 +132,7 @@ void TraceLog(int logType, const char *text, ...) #else char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 }; - switch(logType) + switch (logType) { case LOG_TRACE: strcpy(buffer, "TRACE: "); break; case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break; @@ -150,7 +150,7 @@ void TraceLog(int logType, const char *text, ...) va_end(args); - if (logType >= logTypeExit) exit(1); // If exit message, exit program + if (logType >= logTypeExit) exit(1); // If exit message, exit program #endif // SUPPORT_TRACELOG } @@ -202,3 +202,91 @@ static int android_close(void *cookie) return 0; } #endif + +#if defined(PLATFORM_UWP) + +#define MAX_MESSAGES 512 //If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512 + +static int UWPOutMessageId = -1; //Stores the last index for the message +static UWPMessage* UWPOutMessages[MAX_MESSAGES]; //Messages out to UWP + +static int UWPInMessageId = -1; //Stores the last index for the message +static UWPMessage* UWPInMessages[MAX_MESSAGES]; //Messages in from UWP + +UWPMessage* CreateUWPMessage(void) +{ + UWPMessage* msg = (UWPMessage*)RL_MALLOC(sizeof(UWPMessage)); + msg->Type = None; + Vector2 v0 = {0, 0}; + msg->Vector0 = v0; + msg->Int0 = 0; + msg->Int1 = 0; + msg->Char0 = 0; + msg->Float0 = 0; + msg->Double0 = 0; + msg->Bool0 = false; + return msg; +} + +void DeleteUWPMessage(UWPMessage* msg) +{ + RL_FREE(msg); +} + +bool UWPHasMessages(void) +{ + return UWPOutMessageId > -1; +} + +UWPMessage* UWPGetMessage(void) +{ + if (UWPHasMessages()) + { + return UWPOutMessages[UWPOutMessageId--]; + } + + return NULL; +} + +void UWPSendMessage(UWPMessage* msg) +{ + if (UWPInMessageId + 1 < MAX_MESSAGES) + { + UWPInMessageId++; + UWPInMessages[UWPInMessageId] = msg; + } + else + { + TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message."); + } +} + +void SendMessageToUWP(UWPMessage* msg) +{ + if (UWPOutMessageId + 1 < MAX_MESSAGES) + { + UWPOutMessageId++; + UWPOutMessages[UWPOutMessageId] = msg; + } + else + { + TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message."); + } +} + +bool HasMessageFromUWP(void) +{ + return UWPInMessageId > -1; +} + +UWPMessage* GetMessageFromUWP(void) +{ + if (HasMessageFromUWP()) + { + return UWPInMessages[UWPInMessageId--]; + } + + return NULL; +} + +#endif diff --git a/src/utils.h b/src/utils.h index d7ab8829..14e6bf70 100644 --- a/src/utils.h +++ b/src/utils.h @@ -59,6 +59,81 @@ void InitAssetManager(AAssetManager *manager); // Initialize asset manager from FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() #endif +#if defined(PLATFORM_UWP) + +// UWP Messages System + +typedef enum +{ + None = 0, + + //Send + ShowMouse, + HideMouse, + LockMouse, + UnlockMouse, + SetMouseLocation, //Vector0 (pos) + + //Recieve (Into C) + RegisterKey, //Int0 (key), Char0 (status) + RegisterClick, //Int0 (button), Char0 (status) + ScrollWheelUpdate, //Int0 (delta) + UpdateMouseLocation, //Vector0 (pos) + MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not) + MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status) + MarkGamepadAxis,//Int0 (gamepad), int1 (axis), Float0 (value) + SetDisplayDims, //Vector0 (display dimensions) + HandleResize, //Vector0 (new dimensions) - Onresized event + SetGameTime, //Int0 +} UWPMessageType; + +typedef struct UWPMessage +{ + //The message type + UWPMessageType Type; + + //Vector parameters + Vector2 Vector0; + + //Int parameters + int Int0; + int Int1; + + //Char parameters + char Char0; + + //Float parameters + float Float0; + + //Double parameters + double Double0; + + //Bool parameters + bool Bool0; + + //More parameters can be added and fed to functions +} UWPMessage; + +//Allocate UWP Message +RLAPI UWPMessage* CreateUWPMessage(void); + +//Free UWP Message +RLAPI void DeleteUWPMessage(UWPMessage* msg); + +//Get messages into C++ +RLAPI bool UWPHasMessages(void); +RLAPI UWPMessage* UWPGetMessage(void); +RLAPI void UWPSendMessage(UWPMessage* msg); + +//For C to call +#ifndef _cplusplus //Hide from C++ code +void SendMessageToUWP(UWPMessage* msg); +bool HasMessageFromUWP(void); +UWPMessage* GetMessageFromUWP(void); +#endif + +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.3 From e8c413b7cd1696c207d015bc3e4a00edf71300d2 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 27 Apr 2019 22:47:03 +0200 Subject: Review UWP implementation Basically, formating review and some variables naming to follow raylib conventions. --- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 61 ++--- projects/VS2017.UWP/raylib.App.UWP/App.h | 4 +- projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 118 +++++----- src/core.c | 329 ++++++++++++--------------- src/rlgl.h | 31 +-- src/utils.c | 63 ++--- src/utils.h | 94 ++++---- 7 files changed, 307 insertions(+), 393 deletions(-) (limited to 'src/utils.c') diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index ae137ed2..82e5b12e 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -17,7 +17,7 @@ int main(Platform::Array^) App::App() { - //This does not work... need to fix this. + // This does not work... need to fix this. SetConfigFlags(0); Setup(640, 480); @@ -30,49 +30,50 @@ static int gTime = 0; // This method is called every frame void App::Update() { - //return; - // Draw + // Update + //---------------------------------------------------------------------------------- + posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X) * 5; + posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y) * -5; + + auto mPos = GetMousePosition(); + + if (IsKeyPressed(KEY_A)) + { + posX -= 50; + EnableCursor(); + } + + if (IsKeyPressed(KEY_D)) + { + posX += 50; + DisableCursor(); + } + + static int pos = 0; + pos -= GetMouseWheelMove(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); - - posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X) * 5; - posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y) * -5; DrawRectangle(posX, posY, 400, 100, RED); DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); - auto mPos = GetMousePosition(); - DrawCircle(mPos.x, mPos.y, 40, BLUE); if (IsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); - if (IsKeyPressed(KEY_A)) - { - posX -= 50; - EnableCursor(); - } - - if (IsKeyPressed(KEY_D)) - { - posX += 50; - DisableCursor(); - } - - if (IsKeyDown(KEY_LEFT_ALT)) - DrawRectangle(250, 250, 20, 20, BLACK); - if (IsKeyDown(KEY_BACKSPACE)) - DrawRectangle(280, 250, 20, 20, BLACK); - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - DrawRectangle(280, 250, 20, 20, BLACK); - - static int pos = 0; - pos -= GetMouseWheelMove(); - + if (IsKeyDown(KEY_LEFT_ALT)) DrawRectangle(250, 250, 20, 20, BLACK); + if (IsKeyDown(KEY_BACKSPACE)) DrawRectangle(280, 250, 20, 20, BLACK); + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) DrawRectangle(280, 250, 20, 20, BLACK); + DrawRectangle(280, pos + 50, 20, 20, BLACK); DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE); EndDrawing(); + //---------------------------------------------------------------------------------- } \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.h b/projects/VS2017.UWP/raylib.App.UWP/App.h index 26c1d400..fa33237d 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.h +++ b/projects/VS2017.UWP/raylib.App.UWP/App.h @@ -4,10 +4,10 @@ #include "pch.h" -//Define what header we use for BaseApp.h +// Define what header we use for BaseApp.h #define PCH "pch.h" -//Enable hold hack +// Enable hold hack #define HOLDHACK #include "BaseApp.h" diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index e27909e2..74434a75 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -126,44 +126,43 @@ public: void Setup(int width, int height) { - //Set dimensions + // Set dimensions this->width = width; this->height = height; } virtual void Run() { - //Get display dimensions + // Get display dimensions DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels }; - //Send display dimensions - UWPMessage* msg = CreateUWPMessage(); - msg->Type = SetDisplayDims; - msg->Vector0 = screenSize; + // Send display dimensions + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_SET_DISPLAY_DIMS; + msg->paramVector0 = screenSize; UWPSendMessage(msg); - //Send the time to the core + // Send the time to the core using clock = std::chrono::high_resolution_clock; auto timeStart = clock::now(); - //Set fps if 0 - if (GetFPS() <= 0) - SetTargetFPS(60); + // Set fps if 0 + if (GetFPS() <= 0) SetTargetFPS(60); while (!mWindowClosed) { if (mWindowVisible) { - //Send time + // Send time auto delta = clock::now() - timeStart; - UWPMessage* timeMsg = CreateUWPMessage(); - timeMsg->Type = SetGameTime; - timeMsg->Double0 = std::chrono::duration_cast(delta).count(); + UWPMessage *timeMsg = CreateUWPMessage(); + timeMsg->type = UWP_MSG_SET_GAME_TIME; + timeMsg->paramDouble0 = std::chrono::duration_cast(delta).count(); UWPSendMessage(timeMsg); - //Call update function + // Call update function Update(); PollInput(); @@ -191,38 +190,38 @@ protected: { // Process Messages { - //Loop over pending messages + // Loop over pending messages while (UWPHasMessages()) { - //Get the message + // Get the message auto msg = UWPGetMessage(); - //Carry out the command - switch(msg->Type) + // Carry out the command + switch(msg->type) { - case ShowMouse: //Do the same thing because of how UWP works... - case UnlockMouse: + case UWP_MSG_SHOW_MOUSE: // Do the same thing because of how UWP works... + case UWP_MSG_UNLOCK_MOUSE: { CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; cursorLocked = false; MoveMouse(GetMousePosition()); break; } - case HideMouse: //Do the same thing because of how UWP works... - case LockMouse: + case UWP_MSG_HIDE_MOUSE: // Do the same thing because of how UWP works... + case UWP_MSG_LOCK_MOUSE: { CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; cursorLocked = true; break; } - case SetMouseLocation: + case UWP_MSG_SET_MOUSE_LOCATION: { - MoveMouse(msg->Vector0); + MoveMouse(msg->paramVector0); break; } } - //Delete the message + // Delete the message DeleteUWPMessage(msg); } } @@ -233,8 +232,8 @@ protected: auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k); #ifdef HOLDHACK - //Super hacky way of waiting three frames to see if we are ready to register the key as deregistered - //This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering + // Super hacky way of waiting three frames to see if we are ready to register the key as deregistered + // This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering if (KeyboardStateHack[k] == 2) { if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) @@ -261,10 +260,10 @@ protected: } } #endif - //Left and right alt, KeyUp and KeyDown are not called for it - //No need to hack because this is not a character + // Left and right alt, KeyUp and KeyDown are not called for it + // No need to hack because this is not a character - //TODO: Maybe do all other key registrations like this, no more key events? + // TODO: Maybe do all other key registrations like this, no more key events? if (k == 0xA4 || k == 0xA5) { @@ -283,7 +282,8 @@ protected: // Process Mouse { - if (CurrentPointerID > -1) { + if (CurrentPointerID > -1) + { auto point = PointerPoint::GetCurrentPoint(CurrentPointerID); auto props = point->Properties; @@ -355,9 +355,9 @@ protected: // e.g. player 1, 2, and 3 are playing a game - if player2 disconnects, p3's controller would now be mapped to p2's character since p3 is now second in the list. UWPMessage* msg = CreateUWPMessage(); - msg->Type = MarkGamepadActive; - msg->Int0 = i; - msg->Bool0 = i < Gamepad::Gamepads->Size; + msg->type = UWP_MSG_SET_GAMEPAD_ACTIVE; + msg->paramInt0 = i; + msg->paramBool0 = i < Gamepad::Gamepads->Size; UWPSendMessage(msg); } @@ -410,7 +410,7 @@ protected: void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = HandleResize; + msg->type = UWP_MSG_HANDLE_RESIZE; UWPSendMessage(msg); } @@ -439,8 +439,8 @@ protected: void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = ScrollWheelUpdate; - msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta; + msg->type = UWP_MSG_SCROLL_WHEEL_UPDATE; + msg->paramFloat0 = args->CurrentPoint->Properties->MouseWheelDelta; UWPSendMessage(msg); } @@ -453,7 +453,7 @@ protected: void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) { #ifdef HOLDHACK - //Start the hack + // Start the hack KeyboardStateHack[(int)args->VirtualKey] = 1; #endif @@ -463,7 +463,7 @@ protected: void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) { #ifdef HOLDHACK - //The same hack + // The same hack if (KeyboardStateHack[(int)args->VirtualKey] == 1) { KeyboardStateHack[(int)args->VirtualKey] = 2; @@ -482,7 +482,7 @@ protected: KeyboardStateHack[(int)args->VirtualKey] = 0; } #else - //No hack, allow flickers + // No hack, allow flickers RegisterKey((int)args->VirtualKey, 0); #endif } @@ -492,9 +492,9 @@ private: void RegisterKey(int key, char status) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = UWPMessageType::RegisterKey; - msg->Int0 = key; - msg->Char0 = status; + msg->type = UWPMessageType::UWP_MSG_REGISTER_KEY; + msg->paramInt0 = key; + msg->paramChar0 = status; UWPSendMessage(msg); } @@ -508,37 +508,37 @@ private: void RegisterGamepadButton(int gamepad, int button, char status) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = MarkGamepadButton; - msg->Int0 = gamepad; - msg->Int1 = button; - msg->Char0 = status; + msg->type = UWP_MSG_SET_GAMEPAD_BUTTON; + msg->paramInt0 = gamepad; + msg->paramInt1 = button; + msg->paramChar0 = status; UWPSendMessage(msg); } void RegisterGamepadAxis(int gamepad, int axis, float value) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = MarkGamepadAxis; - msg->Int0 = gamepad; - msg->Int1 = axis; - msg->Float0 = value; + msg->type = UWP_MSG_SET_GAMEPAD_AXIS; + msg->paramInt0 = gamepad; + msg->paramInt1 = axis; + msg->paramFloat0 = value; UWPSendMessage(msg); } void UpdateMousePosition(Vector2 pos) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = UpdateMouseLocation; - msg->Vector0 = pos; + msg->type = UWP_MSG_UPDATE_MOUSE_LOCATION; + msg->paramVector0 = pos; UWPSendMessage(msg); } void RegisterClick(int button, char status) { UWPMessage* msg = CreateUWPMessage(); - msg->Type = UWPMessageType::RegisterClick; - msg->Int0 = button; - msg->Char0 = status; + msg->type = UWPMessageType::UWP_MSG_REGISTER_CLICK; + msg->paramInt0 = button; + msg->paramChar0 = status; UWPSendMessage(msg); } @@ -551,11 +551,11 @@ private: int CurrentPointerID = -1; #ifdef HOLDHACK - char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5 + char KeyboardStateHack[0xA6]; // 0xA6 because the highest key we compare against is 0xA5 #endif }; -//Application source for creating the program +// Application source for creating the program template ref class ApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource { diff --git a/src/core.c b/src/core.c index db75979a..2a8f2e3a 100644 --- a/src/core.c +++ b/src/core.c @@ -391,7 +391,6 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto static pthread_t gamepadThreadId; // Gamepad reading thread id static char gamepadName[64]; // Gamepad name holder #endif - //----------------------------------------------------------------------------------- // Timming system variables @@ -402,7 +401,6 @@ static double updateTime = 0.0; // Time measure for frame update static double drawTime = 0.0; // Time measure for frame draw static double frameTime = 0.0; // Time measure for one frame static double targetTime = 0.0; // Desired time for one frame, if 0 not applied - //----------------------------------------------------------------------------------- // Config internal variables @@ -1027,8 +1025,8 @@ void ShowCursor(void) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); #endif #if defined(PLATFORM_UWP) - UWPMessage* msg = CreateUWPMessage(); - msg->Type = ShowMouse; + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_SHOW_MOUSE; SendMessageToUWP(msg); #endif cursorHidden = false; @@ -1041,8 +1039,8 @@ void HideCursor(void) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); #endif #if defined(PLATFORM_UWP) - UWPMessage* msg = CreateUWPMessage(); - msg->Type = HideMouse; + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_HIDE_MOUSE; SendMessageToUWP(msg); #endif cursorHidden = true; @@ -1064,8 +1062,8 @@ void EnableCursor(void) toggleCursorLock = true; #endif #if defined(PLATFORM_UWP) - UWPMessage* msg = CreateUWPMessage(); - msg->Type = LockMouse; + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_LOCK_MOUSE; SendMessageToUWP(msg); #endif cursorHidden = false; @@ -1081,8 +1079,8 @@ void DisableCursor(void) toggleCursorLock = true; #endif #if defined(PLATFORM_UWP) - UWPMessage* msg = CreateUWPMessage(); - msg->Type = UnlockMouse; + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_UNLOCK_MOUSE; SendMessageToUWP(msg); #endif cursorHidden = true; @@ -1165,7 +1163,7 @@ void EndDrawing(void) frameTime += extraTime; } - return; + return; } // Initialize 2D mode with custom camera (2D) @@ -1444,8 +1442,8 @@ double GetTime(void) #endif #if defined(PLATFORM_UWP) - //Updated through messages - return currentTime; + // Updated through messages + return currentTime; #endif } @@ -2236,10 +2234,10 @@ void SetMousePosition(int x, int y) glfwSetCursorPos(window, mousePosition.x, mousePosition.y); #endif #if defined(PLATFORM_UWP) - UWPMessage* msg = CreateUWPMessage(); - msg->Type = SetMouseLocation; - msg->Vector0.x = mousePosition.x; - msg->Vector0.y = mousePosition.y; + UWPMessage *msg = CreateUWPMessage(); + msg->type = UWP_MSG_SET_MOUSE_LOCATION; + msg->paramVector0.x = mousePosition.x; + msg->paramVector0.y = mousePosition.y; SendMessageToUWP(msg); #endif } @@ -2711,8 +2709,6 @@ static bool InitGraphicsDevice(int width, int height) } } - //SetupFramebuffer(displayWidth, displayHeight); - EGLint numConfigs = 0; if ((eglChooseConfig(display, framebufferAttribs, &config, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0)) { @@ -2769,8 +2765,6 @@ static bool InitGraphicsDevice(int width, int height) eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); - //SetupFramebuffer(displayWidth, displayHeight); //Borked - #else // PLATFORM_ANDROID, PLATFORM_RPI EGLint numConfigs; @@ -2941,8 +2935,8 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_WARNING, "DOWNSCALING: Required screen size (%ix%i) is bigger than display size (%ix%i)", screenWidth, screenHeight, displayWidth, displayHeight); // Downscaling to fit display with border-bars - float widthRatio = (float)displayWidth / (float)screenWidth; - float heightRatio = (float)displayHeight / (float)screenHeight; + float widthRatio = (float)displayWidth/(float)screenWidth; + float heightRatio = (float)displayHeight/(float)screenHeight; if (widthRatio <= heightRatio) { @@ -2960,7 +2954,7 @@ static void SetupFramebuffer(int width, int height) } // Screen scaling required - float scaleRatio = (float)renderWidth / (float)screenWidth; + float scaleRatio = (float)renderWidth/(float)screenWidth; screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio); // NOTE: We render to full display resolution! @@ -2976,13 +2970,13 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_INFO, "UPSCALING: Required screen size: %i x %i -> Display size: %i x %i", screenWidth, screenHeight, displayWidth, displayHeight); // Upscaling to fit display with border-bars - float displayRatio = (float)displayWidth / (float)displayHeight; - float screenRatio = (float)screenWidth / (float)screenHeight; + float displayRatio = (float)displayWidth/(float)displayHeight; + float screenRatio = (float)screenWidth/(float)screenHeight; if (displayRatio <= screenRatio) { renderWidth = screenWidth; - renderHeight = (int)round((float)screenWidth / displayRatio); + renderHeight = (int)round((float)screenWidth/displayRatio); renderOffsetX = 0; renderOffsetY = (renderHeight - screenHeight); } @@ -3126,7 +3120,6 @@ static void PollInputEvents(void) #endif #if defined(PLATFORM_UWP) - // Register previous keys states for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i]; @@ -3141,180 +3134,140 @@ static void PollInputEvents(void) // Register previous mouse states previousMouseWheelY = currentMouseWheelY; currentMouseWheelY = 0; - for (int i = 0; i < 3; i++) - { - previousMouseState[i] = currentMouseState[i]; - - } + for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i]; // Loop over pending messages while (HasMessageFromUWP()) { - UWPMessage* msg = GetMessageFromUWP(); + UWPMessage *msg = GetMessageFromUWP(); - switch (msg->Type) - { - case RegisterKey: + switch (msg->type) { - //Convert from virtualKey - int actualKey = -1; - - switch (msg->Int0) + case UWP_MSG_REGISTER_KEY: { - case 0x08: actualKey = KEY_BACKSPACE; break; - case 0x20: actualKey = KEY_SPACE; break; - case 0x1B: actualKey = KEY_ESCAPE; break; - case 0x0D: actualKey = KEY_ENTER; break; - case 0x2E: actualKey = KEY_DELETE; break; - case 0x27: actualKey = KEY_RIGHT; break; - case 0x25: actualKey = KEY_LEFT; break; - case 0x28: actualKey = KEY_DOWN; break; - case 0x26: actualKey = KEY_UP; break; - case 0x70: actualKey = KEY_F1; break; - case 0x71: actualKey = KEY_F2; break; - case 0x72: actualKey = KEY_F3; break; - case 0x73: actualKey = KEY_F4; break; - case 0x74: actualKey = KEY_F5; break; - case 0x75: actualKey = KEY_F6; break; - case 0x76: actualKey = KEY_F7; break; - case 0x77: actualKey = KEY_F8; break; - case 0x78: actualKey = KEY_F9; break; - case 0x79: actualKey = KEY_F10; break; - case 0x7A: actualKey = KEY_F11; break; - case 0x7B: actualKey = KEY_F12; break; - case 0xA0: actualKey = KEY_LEFT_SHIFT; break; - case 0xA2: actualKey = KEY_LEFT_CONTROL; break; - case 0xA4: actualKey = KEY_LEFT_ALT; break; - case 0xA1: actualKey = KEY_RIGHT_SHIFT; break; - case 0xA3: actualKey = KEY_RIGHT_CONTROL; break; - case 0xA5: actualKey = KEY_RIGHT_ALT; break; - case 0x30: actualKey = KEY_ZERO; break; - case 0x31: actualKey = KEY_ONE; break; - case 0x32: actualKey = KEY_TWO; break; - case 0x33: actualKey = KEY_THREE; break; - case 0x34: actualKey = KEY_FOUR; break; - case 0x35: actualKey = KEY_FIVE; break; - case 0x36: actualKey = KEY_SIX; break; - case 0x37: actualKey = KEY_SEVEN; break; - case 0x38: actualKey = KEY_EIGHT; break; - case 0x39: actualKey = KEY_NINE; break; - case 0x41: actualKey = KEY_A; break; - case 0x42: actualKey = KEY_B; break; - case 0x43: actualKey = KEY_C; break; - case 0x44: actualKey = KEY_D; break; - case 0x45: actualKey = KEY_E; break; - case 0x46: actualKey = KEY_F; break; - case 0x47: actualKey = KEY_G; break; - case 0x48: actualKey = KEY_H; break; - case 0x49: actualKey = KEY_I; break; - case 0x4A: actualKey = KEY_J; break; - case 0x4B: actualKey = KEY_K; break; - case 0x4C: actualKey = KEY_L; break; - case 0x4D: actualKey = KEY_M; break; - case 0x4E: actualKey = KEY_N; break; - case 0x4F: actualKey = KEY_O; break; - case 0x50: actualKey = KEY_P; break; - case 0x51: actualKey = KEY_Q; break; - case 0x52: actualKey = KEY_R; break; - case 0x53: actualKey = KEY_S; break; - case 0x54: actualKey = KEY_T; break; - case 0x55: actualKey = KEY_U; break; - case 0x56: actualKey = KEY_V; break; - case 0x57: actualKey = KEY_W; break; - case 0x58: actualKey = KEY_X; break; - case 0x59: actualKey = KEY_Y; break; - case 0x5A: actualKey = KEY_Z; break; - } - - if (actualKey > -1) - currentKeyState[actualKey] = msg->Char0; - break; - } - - case RegisterClick: - { - currentMouseState[msg->Int0] = msg->Char0; - break; - } - - case ScrollWheelUpdate: - { - currentMouseWheelY += msg->Int0; - break; - } - - case UpdateMouseLocation: - { - mousePosition = msg->Vector0; - break; - } + // Convert from virtualKey + int actualKey = -1; - case MarkGamepadActive: - { - if (msg->Int0 < MAX_GAMEPADS) - gamepadReady[msg->Int0] = msg->Bool0; - break; - } - - case MarkGamepadButton: - { - if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_BUTTONS) - currentGamepadState[msg->Int0][msg->Int1] = msg->Char0; - break; - } - - case MarkGamepadAxis: - { - if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_AXIS) - gamepadAxisState[msg->Int0][msg->Int1] = msg->Float0; - break; - } - - case SetDisplayDims: - { - displayWidth = msg->Vector0.x; - displayHeight = msg->Vector0.y; - break; - } - - case HandleResize: - { - eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); - eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); - - // If window is resized, viewport and projection matrix needs to be re-calculated - rlViewport(0, 0, screenWidth, screenHeight); // Set viewport width and height - rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix - rlLoadIdentity(); // Reset current matrix (PROJECTION) - rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0) - rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix - rlLoadIdentity(); // Reset current matrix (MODELVIEW) - rlClearScreenBuffers(); // Clear screen buffers (color and depth) - - // Window size must be updated to be used on 3D mode to get new aspect ratio (BeginMode3D()) - // NOTE: Be careful! GLFW3 will choose the closest fullscreen resolution supported by current monitor, - // for example, if reescaling back to 800x450 (desired), it could set 720x480 (closest fullscreen supported) - currentWidth = screenWidth; - currentHeight = screenHeight; - - // NOTE: Postprocessing texture is not scaled to new size - - windowResized = true; - break; - } + switch (msg->paramInt0) + { + case 0x08: actualKey = KEY_BACKSPACE; break; + case 0x20: actualKey = KEY_SPACE; break; + case 0x1B: actualKey = KEY_ESCAPE; break; + case 0x0D: actualKey = KEY_ENTER; break; + case 0x2E: actualKey = KEY_DELETE; break; + case 0x27: actualKey = KEY_RIGHT; break; + case 0x25: actualKey = KEY_LEFT; break; + case 0x28: actualKey = KEY_DOWN; break; + case 0x26: actualKey = KEY_UP; break; + case 0x70: actualKey = KEY_F1; break; + case 0x71: actualKey = KEY_F2; break; + case 0x72: actualKey = KEY_F3; break; + case 0x73: actualKey = KEY_F4; break; + case 0x74: actualKey = KEY_F5; break; + case 0x75: actualKey = KEY_F6; break; + case 0x76: actualKey = KEY_F7; break; + case 0x77: actualKey = KEY_F8; break; + case 0x78: actualKey = KEY_F9; break; + case 0x79: actualKey = KEY_F10; break; + case 0x7A: actualKey = KEY_F11; break; + case 0x7B: actualKey = KEY_F12; break; + case 0xA0: actualKey = KEY_LEFT_SHIFT; break; + case 0xA2: actualKey = KEY_LEFT_CONTROL; break; + case 0xA4: actualKey = KEY_LEFT_ALT; break; + case 0xA1: actualKey = KEY_RIGHT_SHIFT; break; + case 0xA3: actualKey = KEY_RIGHT_CONTROL; break; + case 0xA5: actualKey = KEY_RIGHT_ALT; break; + case 0x30: actualKey = KEY_ZERO; break; + case 0x31: actualKey = KEY_ONE; break; + case 0x32: actualKey = KEY_TWO; break; + case 0x33: actualKey = KEY_THREE; break; + case 0x34: actualKey = KEY_FOUR; break; + case 0x35: actualKey = KEY_FIVE; break; + case 0x36: actualKey = KEY_SIX; break; + case 0x37: actualKey = KEY_SEVEN; break; + case 0x38: actualKey = KEY_EIGHT; break; + case 0x39: actualKey = KEY_NINE; break; + case 0x41: actualKey = KEY_A; break; + case 0x42: actualKey = KEY_B; break; + case 0x43: actualKey = KEY_C; break; + case 0x44: actualKey = KEY_D; break; + case 0x45: actualKey = KEY_E; break; + case 0x46: actualKey = KEY_F; break; + case 0x47: actualKey = KEY_G; break; + case 0x48: actualKey = KEY_H; break; + case 0x49: actualKey = KEY_I; break; + case 0x4A: actualKey = KEY_J; break; + case 0x4B: actualKey = KEY_K; break; + case 0x4C: actualKey = KEY_L; break; + case 0x4D: actualKey = KEY_M; break; + case 0x4E: actualKey = KEY_N; break; + case 0x4F: actualKey = KEY_O; break; + case 0x50: actualKey = KEY_P; break; + case 0x51: actualKey = KEY_Q; break; + case 0x52: actualKey = KEY_R; break; + case 0x53: actualKey = KEY_S; break; + case 0x54: actualKey = KEY_T; break; + case 0x55: actualKey = KEY_U; break; + case 0x56: actualKey = KEY_V; break; + case 0x57: actualKey = KEY_W; break; + case 0x58: actualKey = KEY_X; break; + case 0x59: actualKey = KEY_Y; break; + case 0x5A: actualKey = KEY_Z; break; + default: break; + } - case SetGameTime: - { - currentTime = msg->Double0; - break; - } + if (actualKey > -1) currentKeyState[actualKey] = msg->paramChar0; + } break; + case UWP_MSG_REGISTER_CLICK: currentMouseState[msg->paramInt0] = msg->paramChar0; break; + case UWP_MSG_SCROLL_WHEEL_UPDATE: currentMouseWheelY += msg->paramInt0; break; + case UWP_MSG_UPDATE_MOUSE_LOCATION: mousePosition = msg->paramVector0; break; + case UWP_MSG_SET_GAMEPAD_ACTIVE: if (msg->paramInt0 < MAX_GAMEPADS) gamepadReady[msg->paramInt0] = msg->paramBool0; break; + case UWP_MSG_SET_GAMEPAD_BUTTON: + { + if ((msg->paramInt0 < MAX_GAMEPADS) && (msg->paramInt1 < MAX_GAMEPAD_BUTTONS)) currentGamepadState[msg->paramInt0][msg->paramInt1] = msg->paramChar0; + } break; + case UWP_MSG_SET_GAMEPAD_AXIS: + { + if ((msg->paramInt0 < MAX_GAMEPADS) && (msg->paramInt1 < MAX_GAMEPAD_AXIS)) gamepadAxisState[msg->paramInt0][msg->paramInt1] = msg->paramFloat0; + } break; + case UWP_MSG_SET_DISPLAY_DIMS: + { + displayWidth = msg->paramVector0.x; + displayHeight = msg->paramVector0.y; + } break; + case UWP_MSG_HANDLE_RESIZE: + { + eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); + eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); + + // If window is resized, viewport and projection matrix needs to be re-calculated + rlViewport(0, 0, screenWidth, screenHeight); // Set viewport width and height + rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix + rlLoadIdentity(); // Reset current matrix (PROJECTION) + rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0) + rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix + rlLoadIdentity(); // Reset current matrix (MODELVIEW) + rlClearScreenBuffers(); // Clear screen buffers (color and depth) + + // Window size must be updated to be used on 3D mode to get new aspect ratio (BeginMode3D()) + // NOTE: Be careful! GLFW3 will choose the closest fullscreen resolution supported by current monitor, + // for example, if reescaling back to 800x450 (desired), it could set 720x480 (closest fullscreen supported) + currentWidth = screenWidth; + currentHeight = screenHeight; + + // NOTE: Postprocessing texture is not scaled to new size + + windowResized = true; + + } break; + case UWP_MSG_SET_GAME_TIME: currentTime = msg->paramDouble0; break; + default: break; } DeleteUWPMessage(msg); //Delete, we are done } - -#endif +#endif // defined(PLATFORM_UWP) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling diff --git a/src/rlgl.h b/src/rlgl.h index ae92f149..1091f0d1 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -422,8 +422,8 @@ RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current ma RLAPI void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix RLAPI void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix -RLAPI void rlFrustum(double left, double right, double bottom, double top, double near, double far); -RLAPI void rlOrtho(double left, double right, double bottom, double top, double near, double far); +RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar); +RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar); RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area //------------------------------------------------------------------------------------ @@ -888,14 +888,14 @@ void rlMatrixMode(int mode) } } -void rlFrustum(double left, double right, double bottom, double top, double zNear, double zFar) +void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar) { - glFrustum(left, right, bottom, top, zNear, zFar); + glFrustum(left, right, bottom, top, znear, zfar); } -void rlOrtho(double left, double right, double bottom, double top, double zNear, double zFar) +void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar) { - glOrtho(left, right, bottom, top, zNear, zFar); + glOrtho(left, right, bottom, top, znear, zfar); } void rlPushMatrix(void) { glPushMatrix(); } @@ -1491,7 +1491,6 @@ void rlglInit(int width, int height) GLint numExt = 0; #if defined(GRAPHICS_API_OPENGL_33) - // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default vaoSupported = true; @@ -1504,12 +1503,7 @@ void rlglInit(int width, int height) // NOTE: We don't need to check again supported extensions but we do (GLAD already dealt with that) glGetIntegerv(GL_NUM_EXTENSIONS, &numExt); -#if defined(_MSC_VER) const char **extList = RL_MALLOC(sizeof(const char *)*numExt); -#else - const char *extList[numExt]; -#endif - for (int i = 0; i < numExt; i++) extList[i] = (char *)glGetStringi(GL_EXTENSIONS, i); #elif defined(GRAPHICS_API_OPENGL_ES2) @@ -1523,10 +1517,10 @@ void rlglInit(int width, int height) // NOTE: String could be splitted using strtok() function (string.h) // NOTE: strtok() modifies the passed string, it can not be const - char *extList[512]; // Allocate 512 strings pointers (2 KB) + // Allocate 512 strings pointers (2 KB) + const char **extList = RL_MALLOC(sizeof(const char *)*512); extList[numExt] = strtok(extensionsDup, " "); - while (extList[numExt] != NULL) { numExt++; @@ -1619,9 +1613,7 @@ void rlglInit(int width, int height) if (strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; } -#if defined(_WIN32) && defined(_MSC_VER) && !defined(PLATFORM_UWP) //is this a hotfix? I may need to find out why this is broken RL_FREE(extList); -#endif #if defined(GRAPHICS_API_OPENGL_ES2) if (vaoSupported) TraceLog(LOG_INFO, "[EXTENSION] VAO extension detected, VAO functions initialized successfully"); @@ -1642,11 +1634,8 @@ void rlglInit(int width, int height) if (debugMarkerSupported) TraceLog(LOG_INFO, "[EXTENSION] Debug Marker supported"); - - // Initialize buffers, default shaders and default textures //---------------------------------------------------------- - // Init default white texture unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes) defaultTextureId = rlLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1); @@ -4623,6 +4612,6 @@ int GetPixelDataSize(int width, int height, int format) return dataSize; } -#endif +#endif // RLGL_STANDALONE -#endif // RLGL_IMPLEMENTATION \ No newline at end of file +#endif // RLGL_IMPLEMENTATION \ No newline at end of file diff --git a/src/utils.c b/src/utils.c index c886d2a7..52fd0b45 100644 --- a/src/utils.c +++ b/src/utils.c @@ -205,73 +205,64 @@ static int android_close(void *cookie) #if defined(PLATFORM_UWP) -#define MAX_MESSAGES 512 //If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512 +#define MAX_MESSAGES 512 // If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512 -static int UWPOutMessageId = -1; //Stores the last index for the message -static UWPMessage* UWPOutMessages[MAX_MESSAGES]; //Messages out to UWP +static int UWPOutMessageId = -1; // Stores the last index for the message +static UWPMessage* UWPOutMessages[MAX_MESSAGES]; // Messages out to UWP -static int UWPInMessageId = -1; //Stores the last index for the message -static UWPMessage* UWPInMessages[MAX_MESSAGES]; //Messages in from UWP +static int UWPInMessageId = -1; // Stores the last index for the message +static UWPMessage* UWPInMessages[MAX_MESSAGES]; // Messages in from UWP UWPMessage* CreateUWPMessage(void) { - UWPMessage* msg = (UWPMessage*)RL_MALLOC(sizeof(UWPMessage)); - msg->Type = None; - Vector2 v0 = {0, 0}; - msg->Vector0 = v0; - msg->Int0 = 0; - msg->Int1 = 0; - msg->Char0 = 0; - msg->Float0 = 0; - msg->Double0 = 0; - msg->Bool0 = false; + UWPMessage *msg = (UWPMessage *)RL_MALLOC(sizeof(UWPMessage)); + msg->type = UWP_MSG_NONE; + Vector2 v0 = { 0, 0 }; + msg->paramVector0 = v0; + msg->paramInt0 = 0; + msg->paramInt1 = 0; + msg->paramChar0 = 0; + msg->paramFloat0 = 0; + msg->paramDouble0 = 0; + msg->paramBool0 = false; return msg; } -void DeleteUWPMessage(UWPMessage* msg) +void DeleteUWPMessage(UWPMessage *msg) { RL_FREE(msg); } bool UWPHasMessages(void) { - return UWPOutMessageId > -1; + return (UWPOutMessageId > -1); } -UWPMessage* UWPGetMessage(void) +UWPMessage *UWPGetMessage(void) { - if (UWPHasMessages()) - { - return UWPOutMessages[UWPOutMessageId--]; - } + if (UWPHasMessages()) return UWPOutMessages[UWPOutMessageId--]; return NULL; } -void UWPSendMessage(UWPMessage* msg) +void UWPSendMessage(UWPMessage *msg) { if (UWPInMessageId + 1 < MAX_MESSAGES) { UWPInMessageId++; UWPInMessages[UWPInMessageId] = msg; } - else - { - TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message."); - } + else TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message."); } -void SendMessageToUWP(UWPMessage* msg) +void SendMessageToUWP(UWPMessage *msg) { if (UWPOutMessageId + 1 < MAX_MESSAGES) { UWPOutMessageId++; UWPOutMessages[UWPOutMessageId] = msg; } - else - { - TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message."); - } + else TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message."); } bool HasMessageFromUWP(void) @@ -281,12 +272,8 @@ bool HasMessageFromUWP(void) UWPMessage* GetMessageFromUWP(void) { - if (HasMessageFromUWP()) - { - return UWPInMessages[UWPInMessageId--]; - } + if (HasMessageFromUWP()) return UWPInMessages[UWPInMessageId--]; return NULL; } - -#endif +#endif // defined(PLATFORM_UWP) diff --git a/src/utils.h b/src/utils.h index 14e6bf70..1611b02c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -60,79 +60,63 @@ FILE *android_fopen(const char *fileName, const char *mode); // Replacement f #endif #if defined(PLATFORM_UWP) - // UWP Messages System - -typedef enum -{ - None = 0, - - //Send - ShowMouse, - HideMouse, - LockMouse, - UnlockMouse, - SetMouseLocation, //Vector0 (pos) - - //Recieve (Into C) - RegisterKey, //Int0 (key), Char0 (status) - RegisterClick, //Int0 (button), Char0 (status) - ScrollWheelUpdate, //Int0 (delta) - UpdateMouseLocation, //Vector0 (pos) - MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not) - MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status) - MarkGamepadAxis,//Int0 (gamepad), int1 (axis), Float0 (value) - SetDisplayDims, //Vector0 (display dimensions) - HandleResize, //Vector0 (new dimensions) - Onresized event - SetGameTime, //Int0 +typedef enum { + UWP_MSG_NONE = 0, + + // Send + UWP_MSG_SHOW_MOUSE, + UWP_MSG_HIDE_MOUSE, + UWP_MSG_LOCK_MOUSE, + UWP_MSG_UNLOCK_MOUSE, + UWP_MSG_SET_MOUSE_LOCATION, // paramVector0 (pos) + + // Receive (Into C) + UWP_MSG_REGISTER_KEY, // paramInt0 (key), paramChar0 (status) + UWP_MSG_REGISTER_CLICK, // paramInt0 (button), paramChar0 (status) + UWP_MSG_SCROLL_WHEEL_UPDATE, // paramInt0 (delta) + UWP_MSG_UPDATE_MOUSE_LOCATION, // paramVector0 (pos) + UWP_MSG_SET_GAMEPAD_ACTIVE, // paramInt0 (gamepad), paramBool0 (active or not) + UWP_MSG_SET_GAMEPAD_BUTTON, // paramInt0 (gamepad), paramInt1 (button), paramChar0 (status) + UWP_MSG_SET_GAMEPAD_AXIS, // paramInt0 (gamepad), int1 (axis), paramFloat0 (value) + UWP_MSG_SET_DISPLAY_DIMS, // paramVector0 (display dimensions) + UWP_MSG_HANDLE_RESIZE, // paramVector0 (new dimensions) - Onresized event + UWP_MSG_SET_GAME_TIME, // paramInt0 } UWPMessageType; -typedef struct UWPMessage -{ - //The message type - UWPMessageType Type; - - //Vector parameters - Vector2 Vector0; - - //Int parameters - int Int0; - int Int1; - - //Char parameters - char Char0; - - //Float parameters - float Float0; - - //Double parameters - double Double0; - - //Bool parameters - bool Bool0; - - //More parameters can be added and fed to functions +typedef struct UWPMessage { + UWPMessageType type; // Message type + + Vector2 paramVector0; // Vector parameters + int paramInt0; // Int parameter + int paramInt1; // Int parameter + char paramChar0; // Char parameters + float paramFloat0; // Float parameters + double paramDouble0; // Double parameters + bool paramBool0; // Bool parameters + + // More parameters can be added and fed to functions } UWPMessage; -//Allocate UWP Message +// Allocate UWP Message RLAPI UWPMessage* CreateUWPMessage(void); -//Free UWP Message +// Free UWP Message RLAPI void DeleteUWPMessage(UWPMessage* msg); -//Get messages into C++ +// Get messages into C++ RLAPI bool UWPHasMessages(void); RLAPI UWPMessage* UWPGetMessage(void); RLAPI void UWPSendMessage(UWPMessage* msg); -//For C to call -#ifndef _cplusplus //Hide from C++ code +// For C to call +#ifndef __cplusplus // Hide from C++ code void SendMessageToUWP(UWPMessage* msg); bool HasMessageFromUWP(void); UWPMessage* GetMessageFromUWP(void); #endif -#endif +#endif //defined(PLATFORM_UWP) #ifdef __cplusplus } -- cgit v1.2.3 From 40940f439860b3345198dc44cd493f0c0dc12f7c Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 28 Apr 2019 16:45:23 +0200 Subject: Some formatting review --- src/core.c | 67 ++++++++++++++++++++++++++++--------------------------------- src/rlgl.h | 16 +++++++-------- src/utils.c | 10 ++++----- 3 files changed, 44 insertions(+), 49 deletions(-) (limited to 'src/utils.c') diff --git a/src/core.c b/src/core.c index 2a8f2e3a..1273a057 100644 --- a/src/core.c +++ b/src/core.c @@ -476,12 +476,13 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE #endif #if defined(PLATFORM_RPI) +static void InitEvdevInput(void); // Evdev inputs initialization +static void EventThreadSpawn(char *device); // Identifies a input device and spawns a thread to handle it if needed +static void *EventThread(void *arg); // Input device events reading thread + static void InitKeyboard(void); // Init raw keyboard system (standard input reading) static void ProcessKeyboard(void); // Process keyboard events static void RestoreKeyboard(void); // Restore keyboard system -static void InitEvdevInput(void); // Mouse initialization (including mouse thread) -static void EventThreadSpawn(char *device); // Identifies a input device and spawns a thread to handle it if needed -static void *EventThread(void *arg); // Input device events reading thread static void InitGamepad(void); // Init raw gamepad input static void *GamepadThread(void *arg); // Mouse reading thread #endif @@ -595,7 +596,7 @@ void InitWindow(int width, int height, const char *title) #if defined(PLATFORM_RPI) // Init raw input system - InitEvdevInput(); // Mouse init + InitEvdevInput(); // Evdev inputs initialization InitKeyboard(); // Keyboard init InitGamepad(); // Gamepad init #endif @@ -629,7 +630,7 @@ void InitWindow(int width, int height, const char *title) SetTargetFPS(60); LogoAnimation(); } -#endif // defined(PLATFORM_ANDROID) +#endif // PLATFORM_ANDROID } // Close window and unload OpenGL context @@ -2369,12 +2370,12 @@ static bool InitGraphicsDevice(int width, int height) // Screen size security check if (screenWidth <= 0) screenWidth = displayWidth; if (screenHeight <= 0) screenHeight = displayHeight; -#endif // defined(PLATFORM_DESKTOP) +#endif // PLATFORM_DESKTOP #if defined(PLATFORM_WEB) displayWidth = screenWidth; displayHeight = screenHeight; -#endif // defined(PLATFORM_WEB) +#endif // PLATFORM_WEB glfwDefaultWindowHints(); // Set default windows hints: //glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits @@ -2552,7 +2553,7 @@ static bool InitGraphicsDevice(int width, int height) glfwSwapInterval(1); TraceLog(LOG_INFO, "Trying to enable VSYNC"); } -#endif // defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) +#endif // PLATFORM_DESKTOP || PLATFORM_WEB #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP) fullscreen = true; @@ -2819,7 +2820,7 @@ static bool InitGraphicsDevice(int width, int height) //ANativeWindow_setBuffersGeometry(androidApp->window, 0, 0, displayFormat); // Force use of native display size surface = eglCreateWindowSurface(display, config, androidApp->window, NULL); -#endif // defined(PLATFORM_ANDROID) +#endif // PLATFORM_ANDROID #if defined(PLATFORM_RPI) graphics_get_display_size(0, &displayWidth, &displayHeight); @@ -2859,7 +2860,8 @@ static bool InitGraphicsDevice(int width, int height) surface = eglCreateWindowSurface(display, config, &nativeWindow, NULL); //--------------------------------------------------------------------------------- -#endif // defined(PLATFORM_RPI) +#endif // PLATFORM_RPI + // There must be at least one frame displayed before the buffers are swapped //eglSwapInterval(display, 1); @@ -2880,7 +2882,7 @@ static bool InitGraphicsDevice(int width, int height) TraceLog(LOG_INFO, "Screen size: %i x %i", screenWidth, screenHeight); TraceLog(LOG_INFO, "Viewport offsets: %i, %i", renderOffsetX, renderOffsetY); } -#endif // defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) +#endif // PLATFORM_ANDROID || PLATFORM_RPI renderWidth = screenWidth; renderHeight = screenHeight; @@ -3103,7 +3105,7 @@ static void PollInputEvents(void) for (int i = 0; i < 512; i++)previousKeyState[i] = currentKeyState[i]; // Grab a keypress from the evdev fifo if avalable - if(lastKeyPressedEvdev.Head != lastKeyPressedEvdev.Tail) + if (lastKeyPressedEvdev.Head != lastKeyPressedEvdev.Tail) { lastKeyPressed = lastKeyPressedEvdev.Contents[lastKeyPressedEvdev.Tail]; // Read the key from the buffer lastKeyPressedEvdev.Tail = (lastKeyPressedEvdev.Tail + 1) & 0x07; // Increment the tail pointer forwards and binary wraparound after 7 (fifo is 8 elements long) @@ -3267,7 +3269,7 @@ static void PollInputEvents(void) DeleteUWPMessage(msg); //Delete, we are done } -#endif // defined(PLATFORM_UWP) +#endif // PLATFORM_UWP #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling @@ -3414,12 +3416,11 @@ static void PollInputEvents(void) #endif #if defined(PLATFORM_RPI) - // NOTE: Mouse input events polling is done asynchonously in another pthread - EventThread() - // NOTE: Keyboard reading could be done using input_event(s) reading or just read from stdin, // we now use both methods inside here. 2nd method is still used for legacy purposes (Allows for input trough SSH console) ProcessKeyboard(); + // NOTE: Mouse input events polling is done asynchronously in another pthread - EventThread() // NOTE: Gamepad (Joystick) input events polling is done asynchonously in another pthread - GamepadThread() #endif } @@ -4244,6 +4245,7 @@ static void InitEvdevInput(void) // Open the linux directory of "/dev/input" directory = opendir(DEFAULT_EVDEV_PATH); + if (directory) { while ((entity = readdir(directory)) != NULL) @@ -4460,9 +4462,10 @@ static void EventThreadSpawn(char *device) static void *EventThread(void *arg) { // Scancode to keycode mapping for US keyboards - // TODO: Proabobly replace this with a keymap from the X11 to get the correct regional map for the keyboard (Currently non US keyboards will have the wrong mapping for some keys) + // TODO: Probably replace this with a keymap from the X11 to get the correct regional map for the keyboard: + // Currently non US keyboards will have the wrong mapping for some keys static const int keymap_US[] = - {0,256,49,50,51,52,53,54,55,56,57,48,45,61,259,258,81,87,69,82,84, + { 0,256,49,50,51,52,53,54,55,56,57,48,45,61,259,258,81,87,69,82,84, 89,85,73,79,80,91,93,257,341,65,83,68,70,71,72,74,75,76,59,39,96, 340,92,90,88,67,86,66,78,77,44,46,47,344,332,342,32,280,290,291, 292,293,294,295,296,297,298,299,282,281,327,328,329,333,324,325, @@ -4476,7 +4479,7 @@ static void *EventThread(void *arg) 192,193,194,0,0,0,0,0,200,201,202,203,204,205,206,207,208,209,210, 211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226, 227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242, - 243,244,245,246,247,248,0,0,0,0,0,0,0,}; + 243,244,245,246,247,248,0,0,0,0,0,0,0, }; struct input_event event; InputEventWorker *worker = (InputEventWorker *)arg; @@ -4515,10 +4518,7 @@ static void *EventThread(void *arg) #endif } - if (event.code == REL_WHEEL) - { - currentMouseWheelY += event.value; - } + if (event.code == REL_WHEEL) currentMouseWheelY += event.value; } // Absolute movement parsing @@ -4546,26 +4546,21 @@ static void *EventThread(void *arg) } // Multitouch movement - if (event.code == ABS_MT_SLOT) - { - worker->touchSlot = event.value; // Remeber the slot number for the folowing events - } + if (event.code == ABS_MT_SLOT) worker->touchSlot = event.value; // Remeber the slot number for the folowing events if (event.code == ABS_MT_POSITION_X) { - if (worker->touchSlot < MAX_TOUCH_POINTS) - touchPosition[worker->touchSlot].x = (event.value - worker->absRange.x)*screenWidth/worker->absRange.width; // Scale acording to absRange + if (worker->touchSlot < MAX_TOUCH_POINTS) touchPosition[worker->touchSlot].x = (event.value - worker->absRange.x)*screenWidth/worker->absRange.width; // Scale acording to absRange } if (event.code == ABS_MT_POSITION_Y) { - if (worker->touchSlot < MAX_TOUCH_POINTS) - touchPosition[worker->touchSlot].y = (event.value - worker->absRange.y)*screenHeight/worker->absRange.height; // Scale acording to absRange + if (worker->touchSlot < MAX_TOUCH_POINTS) touchPosition[worker->touchSlot].y = (event.value - worker->absRange.y)*screenHeight/worker->absRange.height; // Scale acording to absRange } if (event.code == ABS_MT_TRACKING_ID) { - if ( (event.value < 0) && (worker->touchSlot < MAX_TOUCH_POINTS) ) + if ((event.value < 0) && (worker->touchSlot < MAX_TOUCH_POINTS)) { // Touch has ended for this point touchPosition[worker->touchSlot].x = -1; @@ -4577,7 +4572,6 @@ static void *EventThread(void *arg) // Button parsing if (event.type == EV_KEY) { - // Mouse button parsing if ((event.code == BTN_TOUCH) || (event.code == BTN_LEFT)) { @@ -4595,25 +4589,26 @@ static void *EventThread(void *arg) if (event.code == BTN_MIDDLE) currentMouseStateEvdev[MOUSE_MIDDLE_BUTTON] = event.value; // Keyboard button parsing - if((event.code >= 1) && (event.code <= 255)) //Keyboard keys appear for codes 1 to 255 + if ((event.code >= 1) && (event.code <= 255)) //Keyboard keys appear for codes 1 to 255 { keycode = keymap_US[event.code & 0xFF]; // The code we get is a scancode so we look up the apropriate keycode + // Make sure we got a valid keycode - if((keycode > 0) && (keycode < sizeof(currentKeyState))) + if ((keycode > 0) && (keycode < sizeof(currentKeyState))) { // Store the key information for raylib to later use currentKeyStateEvdev[keycode] = event.value; - if(event.value > 0) + if (event.value > 0) { // Add the key int the fifo lastKeyPressedEvdev.Contents[lastKeyPressedEvdev.Head] = keycode; // Put the data at the front of the fifo snake lastKeyPressedEvdev.Head = (lastKeyPressedEvdev.Head + 1) & 0x07; // Increment the head pointer forwards and binary wraparound after 7 (fifo is 8 elements long) // TODO: This fifo is not fully threadsafe with multiple writers, so multiple keyboards hitting a key at the exact same time could miss a key (double write to head before it was incremented) } + TraceLog(LOG_DEBUG, "KEY%s ScanCode: %4i KeyCode: %4i",event.value == 0 ? "UP":"DOWN", event.code, keycode); } } - } // Screen confinement diff --git a/src/rlgl.h b/src/rlgl.h index b067e5c7..e98c6dc3 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -831,9 +831,9 @@ static RenderTexture2D stereoFbo; // VR stereo rendering framebuffer static bool vrSimulatorReady = false; // VR simulator ready flag static bool vrStereoRender = false; // VR stereo rendering enabled/disabled flag // NOTE: This flag is useful to render data over stereo image (i.e. FPS) -#endif // defined(SUPPORT_VR_SIMULATOR) +#endif // SUPPORT_VR_SIMULATOR -#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 static int blendMode = 0; // Track current blending mode @@ -864,7 +864,7 @@ static void GenDrawQuad(void); // Generate and draw quad static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView); // Set internal projection and modelview matrix depending on eye #endif -#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 #if defined(GRAPHICS_API_OPENGL_11) static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight); @@ -1691,7 +1691,7 @@ void rlglInit(int width, int height) projection = MatrixIdentity(); modelview = MatrixIdentity(); currentMatrix = &modelview; -#endif // defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 // Initialize OpenGL default states //---------------------------------------------------------- @@ -1883,11 +1883,11 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi return id; } #endif -#endif // defined(GRAPHICS_API_OPENGL_11) +#endif // GRAPHICS_API_OPENGL_11 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glGenTextures(1, &id); // Generate Pointer to the texture + glGenTextures(1, &id); // Generate texture id #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) //glActiveTexture(GL_TEXTURE0); // If not defined, using GL_TEXTURE0 by default (shader texture) @@ -4428,9 +4428,9 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView) SetMatrixModelview(eyeModelView); SetMatrixProjection(eyeProjection); } -#endif // defined(SUPPORT_VR_SIMULATOR) +#endif // SUPPORT_VR_SIMULATOR -#endif //defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2 #if defined(GRAPHICS_API_OPENGL_11) // Mipmaps data is generated after image data diff --git a/src/utils.c b/src/utils.c index 52fd0b45..ee4be46d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -34,7 +34,7 @@ // Check if config flags have been externally provided on compilation line #if !defined(EXTERNAL_CONFIG_FLAGS) - #include "config.h" // Defines module configuration flags + #include "config.h" // Defines module configuration flags #endif #include "utils.h" @@ -69,7 +69,7 @@ AAssetManager *assetManager; // Module specific Functions Declaration //---------------------------------------------------------------------------------- #if defined(PLATFORM_ANDROID) -/* This should be in , but Travis doesn't find it... */ +// This should be in , but Travis does not find it... FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int), fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *)); @@ -173,7 +173,7 @@ FILE *android_fopen(const char *fileName, const char *mode) return funopen(asset, android_read, android_write, android_seek, android_close); } -#endif +#endif // PLATFORM_ANDROID //---------------------------------------------------------------------------------- // Module specific Functions Definition @@ -201,7 +201,7 @@ static int android_close(void *cookie) AAsset_close((AAsset *)cookie); return 0; } -#endif +#endif // PLATFORM_ANDROID #if defined(PLATFORM_UWP) @@ -276,4 +276,4 @@ UWPMessage* GetMessageFromUWP(void) return NULL; } -#endif // defined(PLATFORM_UWP) +#endif // PLATFORM_UWP -- cgit v1.2.3