Shuffling things around
This commit is contained in:
parent
2f9e663523
commit
1fc4628cd0
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@
|
||||
/libboids.so
|
||||
/game.fasl
|
||||
/writeimage
|
||||
*.fasl
|
||||
|
||||
@ -5,11 +5,8 @@ CC=gcc
|
||||
|
||||
all: main dod boids_main
|
||||
|
||||
main: main.c lib.h sprites.o sprites.h game_data.h ./lib/libraylib.a
|
||||
$(CC) $(CFLAGS) -Iinclude/ -lm main.c -o main sprites.o ./lib/libraylib.a
|
||||
|
||||
sprites.o: sprites.c sprites.h lib.h
|
||||
$(CC) $(CFLAGS) -c sprites.c -o sprites.o
|
||||
main: main.c lib.h sprites.h game_data.h ./lib/libraylib.a Makefile
|
||||
$(CC) $(CFLAGS) -Iinclude/ -lm main.c -o main ./lib/libraylib.a
|
||||
|
||||
dod: dod.c ./lib/libraylib.a
|
||||
$(CC) $(CFLAGS) -Iinclude/ -lm dod.c -o dod ./lib/libraylib.a
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
#include "include/raylib.h"
|
||||
#include "include/raymath.h"
|
||||
#include <stdio.h>
|
||||
#include "lib.h"
|
||||
|
||||
#define SCREEN_WIDTH 1300
|
||||
#define SCREEN_HEIGHT 1000
|
||||
#define TARGET_FPS 60
|
||||
|
||||
|
||||
int main(void) {
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Boids");
|
||||
|
||||
SetTargetFPS(TARGET_FPS);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
float dt = GetFrameTime();
|
||||
|
||||
// Update
|
||||
|
||||
BeginDrawing();
|
||||
{
|
||||
ClearBackground(RAYWHITE);
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
@ -60,6 +60,34 @@ inline void D_DrawTextureV(Texture2D texture, Vector2 position, Color tint) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Vector2 operations
|
||||
#define v2_add Vector2Add
|
||||
#define v2_sub Vector2Subtract
|
||||
#define v2_mul Vector2Scale
|
||||
#define v2_div Vector2Divide
|
||||
#define v2_dot Vector2DotProduct
|
||||
#define v2_len Vector2Length
|
||||
#define v2_norm Vector2Normalize
|
||||
#define v2_dist Vector2Distance
|
||||
#define v2_lerp Vector2Lerp
|
||||
|
||||
// Vector3 operations
|
||||
#define v3_add Vector3Add
|
||||
#define v3_sub Vector3Subtract
|
||||
#define v3_mul Vector3Scale
|
||||
#define v3_div Vector3Divide
|
||||
#define v3_dot Vector3DotProduct
|
||||
#define v3_cross Vector3CrossProduct
|
||||
#define v3_len Vector3Length
|
||||
#define v3_norm Vector3Normalize
|
||||
#define v3_dist Vector3Distance
|
||||
#define v3_lerp Vector3Lerp
|
||||
|
||||
// Constructor-style macros
|
||||
#define v2(x, y) ((Vector2){x, y})
|
||||
#define v3(x, y, z) ((Vector3){x, y, z})
|
||||
|
||||
|
||||
inline void D_DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint) {
|
||||
DrawTextureRec(texture, source, position, tint);
|
||||
#ifdef DEBUG_MODE_ENABLED
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
#define TEXTURES_BUF_SIZE 16
|
||||
#define TARGET_FPS 60
|
||||
#define MAX_KNIGHTS 10000
|
||||
#define MAX_KNIGHTS 5000
|
||||
#define SCREEN_WIDTH 1300
|
||||
#define SCREEN_HEIGHT 1080
|
||||
|
||||
@ -75,7 +75,7 @@ Assets Init() {
|
||||
|
||||
Assets assets = {0};
|
||||
assets.textures = malloc(sizeof(Texture2D) * TEXTURES_BUF_SIZE);
|
||||
assets.textures[TEX_GROUND] = LoadTexture(../"assets/Terrain/Ground/Tilemap_Flat.png");
|
||||
assets.textures[TEX_GROUND] = LoadTexture("../assets/Terrain/Ground/Tilemap_Flat.png");
|
||||
assets.textures[TEX_KNIGHT] =
|
||||
LoadTexture("../assets/Factions/Knights/Troops/Warrior/Blue/Warrior_Blue.png");
|
||||
assets.textures[TEX_MOUSE_CURSOR] = LoadTexture("../assets/UI/Pointers/01.png");
|
||||
@ -349,6 +349,7 @@ int main(void) {
|
||||
printf("Direction Size: %ld \n", sizeof(Direction));
|
||||
printf("KnightState Size: %ld \n", sizeof(KnightState));
|
||||
|
||||
SetTraceLogLevel(4);
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Tiny Knights");
|
||||
|
||||
int monitor = GetCurrentMonitor();
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
#include "sprites.h"
|
||||
#include "include/raylib.h"
|
||||
|
||||
inline void PlayAnimation(int animation, SpriteAnimation *anims, SpriteAnimationPlayback *playback) {
|
||||
playback->time_elapsed = 0.0f;
|
||||
playback->current_frame = 0;
|
||||
playback->row = animation;
|
||||
playback->total_frames = anims[animation].total_frames;
|
||||
playback->loop = anims[animation].loop;
|
||||
}
|
||||
|
||||
void TickSpriteAnimations(SpriteAnimationPlayback *playbacks, int len) {
|
||||
const f32 anim_speed = 1.0f / 10.0f;
|
||||
for (int i = 0; i < len; i++) {
|
||||
SpriteAnimationPlayback *playback = &playbacks[i];
|
||||
playback->time_elapsed += GetFrameTime();
|
||||
if (playback->time_elapsed >= anim_speed) {
|
||||
playback->time_elapsed = 0.0f;
|
||||
playback->current_frame++;
|
||||
if (playback->current_frame >= playback->total_frames) {
|
||||
if (playback->loop) {
|
||||
playback->current_frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsAnimationFinished(SpriteAnimationPlayback playback) {
|
||||
return playback.current_frame == playback.total_frames;
|
||||
}
|
||||
@ -20,3 +20,32 @@ typedef struct {
|
||||
void PlayAnimation(int animation, SpriteAnimation *anims, SpriteAnimationPlayback *playback);
|
||||
void TickSpriteAnimations(SpriteAnimationPlayback *playbacks, int len);
|
||||
bool IsAnimationFinished(SpriteAnimationPlayback playback);
|
||||
|
||||
inline void PlayAnimation(int animation, SpriteAnimation *anims, SpriteAnimationPlayback *playback) {
|
||||
playback->time_elapsed = 0.0f;
|
||||
playback->current_frame = 0;
|
||||
playback->row = animation;
|
||||
playback->total_frames = anims[animation].total_frames;
|
||||
playback->loop = anims[animation].loop;
|
||||
}
|
||||
|
||||
void TickSpriteAnimations(SpriteAnimationPlayback *playbacks, int len) {
|
||||
const f32 anim_speed = 1.0f / 10.0f;
|
||||
for (int i = 0; i < len; i++) {
|
||||
SpriteAnimationPlayback *playback = &playbacks[i];
|
||||
playback->time_elapsed += GetFrameTime();
|
||||
if (playback->time_elapsed >= anim_speed) {
|
||||
playback->time_elapsed = 0.0f;
|
||||
playback->current_frame++;
|
||||
if (playback->current_frame >= playback->total_frames) {
|
||||
if (playback->loop) {
|
||||
playback->current_frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsAnimationFinished(SpriteAnimationPlayback playback) {
|
||||
return playback.current_frame == playback.total_frames;
|
||||
}
|
||||
|
||||
@ -2,6 +2,104 @@ You will find detailed installation instructions in the ECL manual
|
||||
https://common-lisp.net/project/ecl/static/manual/Building-ECL.html
|
||||
If you do not have access to the online version, follow the following recipies.
|
||||
|
||||
* Cross-compile for the WASM platform (via emscripten)
|
||||
|
||||
Emscripten target is a little fickle so keep in mind that:
|
||||
|
||||
- shared libraries are supported but come with some drawbacks (e.g.
|
||||
increased code size if used together with -sASYNCIFY), therefore the
|
||||
build instructions default to disable-shared
|
||||
|
||||
- disable-tcp is needed, because accept can't be found (lack of
|
||||
-lsockets or something in this spirit?)
|
||||
|
||||
- select for interactive streams does not work, because reading operations are
|
||||
blocking (as they should be!), so there is no EOF returned -- clear-input will
|
||||
hang without a proper file-cnt
|
||||
|
||||
- to build emscripten you need to use their SDK that provides the toolchain, and
|
||||
set the environment variable EMSDK_PATH
|
||||
|
||||
- for the garbage collector to be able to identify roots on the stack,
|
||||
you need to pass the -sBINARYEN_EXTRA_PASSES=--spill-pointers option
|
||||
to the linker for all of your code that might store pointer on the
|
||||
stack (for instance when embedding ECL)
|
||||
|
||||
- the optimization level -O0 is used because higher optimization
|
||||
levels seem to interfere with the binaryen options needed to get the
|
||||
garbage collector to work correctly and tend slow down the program
|
||||
(might be worth experimenting with the optimization options)
|
||||
|
||||
1. Build the host ECL
|
||||
|
||||
#+begin_src shell-script
|
||||
./configure ABI=32 CFLAGS="-m32 -g -O2 -DECL_C_COMPATIBLE_VARIADIC_DISPATCH" LDFLAGS="-m32 -g -O2" \
|
||||
--prefix=`pwd`/ecl-emscripten-host --disable-threads
|
||||
|
||||
make -j16 && make install
|
||||
rm -rf build/
|
||||
#+end_src
|
||||
|
||||
2. Configure the toolchain
|
||||
|
||||
Install the Emscripten SDK using the official instructions:
|
||||
|
||||
https://emscripten.org/docs/getting_started/downloads.html
|
||||
|
||||
These build instructions were tested against ~emsdk 3.1.41~. If things doesn't
|
||||
work try that version instead of ~latest~.
|
||||
|
||||
After that activate the toolchain and configure build flags:
|
||||
|
||||
#+begin_src shell-script
|
||||
source ${EMSDK_PATH}/emsdk_env.sh
|
||||
export ECL_TO_RUN=`pwd`/ecl-emscripten-host/bin/ecl
|
||||
# You may customize various emscripten flags here, i.e:
|
||||
# export LDFLAGS="-sASYNCIFY=1"
|
||||
#+end_src
|
||||
|
||||
3. Build the core environment and install it
|
||||
|
||||
#+begin_src shell-script
|
||||
emconfigure ./configure \
|
||||
--host=wasm32-unknown-emscripten \
|
||||
--build=x86_64-pc-linux-gnu \
|
||||
--with-cross-config=`pwd`/src/util/wasm32-unknown-emscripten.cross_config \
|
||||
--prefix=`pwd`/ecl-emscripten \
|
||||
--disable-shared \
|
||||
--with-tcp=no \
|
||||
--with-cmp=no
|
||||
|
||||
emmake make && emmake make install
|
||||
|
||||
# some files need to be copied manually
|
||||
cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/
|
||||
#+end_src
|
||||
|
||||
4. ECL may be hosted on a web page. Assuming that you have quicklisp installed:
|
||||
|
||||
#+begin_src shell-script
|
||||
export WEBSERVER=`pwd`/src/util/webserver.lisp
|
||||
pushd ecl-emscripten/
|
||||
lisp --load $WEBSERVER
|
||||
# After the server is loaded run:
|
||||
# firefox localhost:8888/ecl.html
|
||||
popd
|
||||
#+end_src
|
||||
|
||||
If the output does not show on the webpage then open the javascript console.
|
||||
This is a default html website produced by emscripten.
|
||||
|
||||
5. Build an external program linked against libecl.a
|
||||
|
||||
The default stack size proposed by emscripten is 64KB. This is too little for
|
||||
ECL, so when you build a program that is linked against libecl.a, then it is
|
||||
imoprtant to specify a different size. For example:
|
||||
|
||||
#+begin_src shell-script
|
||||
emcc program.c -sSTACK_SIZE=1048576 lib/*.a -I./include -o program.o
|
||||
#+end_src
|
||||
|
||||
* Unix and similar platforms.
|
||||
1. Type
|
||||
./configure --help
|
||||
@ -111,104 +209,6 @@ Hint provided by Pascal J. Bourguignon.
|
||||
4. Library and assets in the ecl-iOS directory are ready to run on
|
||||
the iOS system.
|
||||
|
||||
* Cross-compile for the WASM platform (via emscripten)
|
||||
|
||||
Emscripten target is a little fickle so keep in mind that:
|
||||
|
||||
- shared libraries are supported but come with some drawbacks (e.g.
|
||||
increased code size if used together with -sASYNCIFY), therefore the
|
||||
build instructions default to disable-shared
|
||||
|
||||
- disable-tcp is needed, because accept can't be found (lack of
|
||||
-lsockets or something in this spirit?)
|
||||
|
||||
- select for interactive streams does not work, because reading operations are
|
||||
blocking (as they should be!), so there is no EOF returned -- clear-input will
|
||||
hang without a proper file-cnt
|
||||
|
||||
- to build emscripten you need to use their SDK that provides the toolchain, and
|
||||
set the environment variable EMSDK_PATH
|
||||
|
||||
- for the garbage collector to be able to identify roots on the stack,
|
||||
you need to pass the -sBINARYEN_EXTRA_PASSES=--spill-pointers option
|
||||
to the linker for all of your code that might store pointer on the
|
||||
stack (for instance when embedding ECL)
|
||||
|
||||
- the optimization level -O0 is used because higher optimization
|
||||
levels seem to interfere with the binaryen options needed to get the
|
||||
garbage collector to work correctly and tend slow down the program
|
||||
(might be worth experimenting with the optimization options)
|
||||
|
||||
1. Build the host ECL
|
||||
|
||||
#+begin_src shell-script
|
||||
./configure ABI=32 CFLAGS="-m32 -g -O2 -DECL_C_COMPATIBLE_VARIADIC_DISPATCH" LDFLAGS="-m32 -g -O2" \
|
||||
--prefix=`pwd`/ecl-emscripten-host --disable-threads
|
||||
|
||||
make -j16 && make install
|
||||
rm -rf build/
|
||||
#+end_src
|
||||
|
||||
2. Configure the toolchain
|
||||
|
||||
Install the Emscripten SDK using the official instructions:
|
||||
|
||||
https://emscripten.org/docs/getting_started/downloads.html
|
||||
|
||||
These build instructions were tested against ~emsdk 3.1.41~. If things doesn't
|
||||
work try that version instead of ~latest~.
|
||||
|
||||
After that activate the toolchain and configure build flags:
|
||||
|
||||
#+begin_src shell-script
|
||||
source ${EMSDK_PATH}/emsdk_env.sh
|
||||
export ECL_TO_RUN=`pwd`/ecl-emscripten-host/bin/ecl
|
||||
# You may customize various emscripten flags here, i.e:
|
||||
# export LDFLAGS="-sASYNCIFY=1"
|
||||
#+end_src
|
||||
|
||||
3. Build the core environment and install it
|
||||
|
||||
#+begin_src shell-script
|
||||
emconfigure ./configure \
|
||||
--host=wasm32-unknown-emscripten \
|
||||
--build=x86_64-pc-linux-gnu \
|
||||
--with-cross-config=`pwd`/src/util/wasm32-unknown-emscripten.cross_config \
|
||||
--prefix=`pwd`/ecl-emscripten \
|
||||
--disable-shared \
|
||||
--with-tcp=no \
|
||||
--with-cmp=no
|
||||
|
||||
emmake make && emmake make install
|
||||
|
||||
# some files need to be copied manually
|
||||
cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/
|
||||
#+end_src
|
||||
|
||||
4. ECL may be hosted on a web page. Assuming that you have quicklisp installed:
|
||||
|
||||
#+begin_src shell-script
|
||||
export WEBSERVER=`pwd`/src/util/webserver.lisp
|
||||
pushd ecl-emscripten/
|
||||
lisp --load $WEBSERVER
|
||||
# After the server is loaded run:
|
||||
# firefox localhost:8888/ecl.html
|
||||
popd
|
||||
#+end_src
|
||||
|
||||
If the output does not show on the webpage then open the javascript console.
|
||||
This is a default html website produced by emscripten.
|
||||
|
||||
5. Build an external program linked against libecl.a
|
||||
|
||||
The default stack size proposed by emscripten is 64KB. This is too little for
|
||||
ECL, so when you build a program that is linked against libecl.a, then it is
|
||||
imoprtant to specify a different size. For example:
|
||||
|
||||
#+begin_src shell-script
|
||||
emcc program.c -sSTACK_SIZE=1048576 lib/*.a -I./include -o program.o
|
||||
#+end_src
|
||||
|
||||
* Build using Cosmopolitan toolchain (experimental)
|
||||
|
||||
Binaries built with cosmopolitan toolchain can be executed on numerous platforms
|
||||
Loading…
x
Reference in New Issue
Block a user