Added a dynamic array.
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
#include "display/matrix.h"
|
#include "display/matrix.h"
|
||||||
#include "display/primitive.h"
|
#include "display/primitive.h"
|
||||||
#include "display/render.h"
|
#include "display/render.h"
|
||||||
|
#include "display/scene.h"
|
||||||
#include "display/shader.h"
|
#include "display/shader.h"
|
||||||
#include "display/spritebatch.h"
|
#include "display/spritebatch.h"
|
||||||
#include "display/texture.h"
|
#include "display/texture.h"
|
||||||
@ -75,6 +76,7 @@
|
|||||||
|
|
||||||
// Utility Objects
|
// Utility Objects
|
||||||
#include "util/array.h"
|
#include "util/array.h"
|
||||||
|
#include "util/dynarray.h"
|
||||||
#include "util/flags.h"
|
#include "util/flags.h"
|
||||||
#include "util/list.h"
|
#include "util/list.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
|
46
include/dawn/display/scene.h
Normal file
46
include/dawn/display/scene.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../libs.h"
|
||||||
|
#include "../engine/engine.h"
|
||||||
|
|
||||||
|
/** Maximum number of items a scene can support */
|
||||||
|
#define SCENE_ITEMS_MAX 32
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _scene_t scene_t;
|
||||||
|
typedef struct _sceneitem_t sceneitem_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when scene events occur.
|
||||||
|
*
|
||||||
|
* @param scene The scene that is being evented.
|
||||||
|
* @param i The index of the current scene item.
|
||||||
|
* @param engine The game's engine.
|
||||||
|
*/
|
||||||
|
typedef void sceneitemcallback_t(
|
||||||
|
scene_t *scene, int32_t i, engine_t *engine
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef struct _sceneitem_t {
|
||||||
|
sceneitemcallback_t *onUpdate;
|
||||||
|
sceneitemcallback_t *onRender;
|
||||||
|
sceneitemcallback_t *onDispose;
|
||||||
|
} sceneitem_t;
|
||||||
|
|
||||||
|
typedef struct _scene_t {
|
||||||
|
/** Camera that is used to render the scene */
|
||||||
|
camera_t camera;
|
||||||
|
|
||||||
|
/** Any custom user data pointer */
|
||||||
|
void *user;
|
||||||
|
|
||||||
|
/** Items within the scene */
|
||||||
|
sceneitem_t items[SCENE_ITEMS_MAX];
|
||||||
|
int32_t itemCount;
|
||||||
|
} scene_t;
|
@ -22,6 +22,17 @@
|
|||||||
#define POKER_GAME_SEAT_FOR_PLAYER(p) (p - (POKER_PLAYER_COUNT/2))
|
#define POKER_GAME_SEAT_FOR_PLAYER(p) (p - (POKER_PLAYER_COUNT/2))
|
||||||
#define POKER_GAME_SEAT_DEALER POKER_GAME_SEAT_FOR_PLAYER(POKER_DEALER_INDEX)
|
#define POKER_GAME_SEAT_DEALER POKER_GAME_SEAT_FOR_PLAYER(POKER_DEALER_INDEX)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the seat for a given player index, also works for the dealer index.
|
||||||
|
* @param i The players index.
|
||||||
|
* @return The players seat number.
|
||||||
|
*/
|
||||||
|
#define pokerGameSeatFromIndex(i) (\
|
||||||
|
i == POKER_DEALER_INDEX ? \
|
||||||
|
POKER_GAME_SEAT_DEALER : \
|
||||||
|
POKER_GAME_SEAT_FOR_PLAYER(i) \
|
||||||
|
)
|
||||||
|
|
||||||
#define POKER_GAME_PENNY_BASE_WIDTH 1000
|
#define POKER_GAME_PENNY_BASE_WIDTH 1000
|
||||||
#define POKER_GAME_PENNY_BASE_HEIGHT 1920
|
#define POKER_GAME_PENNY_BASE_HEIGHT 1920
|
||||||
#define POKER_GAME_PENNY_FACE_X 367
|
#define POKER_GAME_PENNY_FACE_X 367
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../../libs.h"
|
#include "../../../libs.h"
|
||||||
#include "../../../ui/label.h"
|
#include "../../../ui/label.h"
|
||||||
|
#include "../../../ui/image.h"
|
||||||
|
#include "../../../display/framebuffer.h"
|
||||||
|
#include "../../../display/camera.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
label_t label;
|
label_t label;
|
||||||
|
@ -14,4 +14,5 @@ typedef struct {
|
|||||||
primitive_t quad;
|
primitive_t quad;
|
||||||
float u0, v0;
|
float u0, v0;
|
||||||
float u1, v1;
|
float u1, v1;
|
||||||
|
float width, height;
|
||||||
} image_t;
|
} image_t;
|
24
include/dawn/util/dynarray.h
Normal file
24
include/dawn/util/dynarray.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../libs.h"
|
||||||
|
|
||||||
|
/** Custom Array Definition */
|
||||||
|
typedef struct {
|
||||||
|
/** The data storage */
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
/** Size of each element within the array */
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
/** The count of elements currently in the array */
|
||||||
|
int32_t length;
|
||||||
|
|
||||||
|
/** Total count of elements the array can hold */
|
||||||
|
int32_t total;
|
||||||
|
} dynarray_t;
|
57
src/display/scene.c
Normal file
57
src/display/scene.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
void sceneInit(scene_t *scene) {
|
||||||
|
scene->itemCount = 0;
|
||||||
|
|
||||||
|
cameraLookAt(&scene->camera, 3,3,3, 0,0,0);
|
||||||
|
cameraPerspective(&scene->camera, 75, 16.0f/9.0f, 0.01f, 100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
sceneitem_t * sceneAdd(scene_t *scene) {
|
||||||
|
sceneitem_t *item = scene->items + scene->itemCount;
|
||||||
|
scene->itemCount++;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneUpdate(scene_t *scene, engine_t *engine) {
|
||||||
|
int32_t i;
|
||||||
|
sceneitem_t *item;
|
||||||
|
|
||||||
|
for(i = 0; i < scene->itemCount; i++) {
|
||||||
|
item = scene->items + i;
|
||||||
|
if(item->onUpdate == NULL) continue;
|
||||||
|
item->onUpdate(scene, i, engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneRender(scene_t *scene, engine_t *engine, shader_t *shader) {
|
||||||
|
int32_t i;
|
||||||
|
sceneitem_t *item;
|
||||||
|
|
||||||
|
shaderUse(shader);
|
||||||
|
shaderUseCamera(shader, &scene->camera);
|
||||||
|
|
||||||
|
for(i = 0; i < scene->itemCount; i++) {
|
||||||
|
item = scene->items + i;
|
||||||
|
if(item->onRender == NULL) continue;
|
||||||
|
item->onRender(scene, i, engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneDispose(scene_t *scene) {
|
||||||
|
int32_t i;
|
||||||
|
sceneitem_t *item;
|
||||||
|
|
||||||
|
for(i = 0; i < scene->itemCount; i++) {
|
||||||
|
item = scene->items + i;
|
||||||
|
if(item->onDispose == NULL) continue;
|
||||||
|
item->onDispose(scene, i, NULL);
|
||||||
|
}
|
||||||
|
}
|
21
src/display/scene.h
Normal file
21
src/display/scene.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <dawn/dawn.h>
|
||||||
|
#include "camera.h"
|
||||||
|
#include "shader.h"
|
||||||
|
|
||||||
|
void sceneInit(scene_t *scene);
|
||||||
|
|
||||||
|
sceneitem_t * sceneAdd(scene_t *scene);
|
||||||
|
|
||||||
|
void sceneUpdate(scene_t *scene, engine_t *engine);
|
||||||
|
|
||||||
|
void sceneRender(scene_t *scene, engine_t *engine, shader_t *shader);
|
||||||
|
|
||||||
|
void sceneDispose(scene_t *scene);
|
@ -29,6 +29,19 @@ bool pokerGameInit(game_t *game) {
|
|||||||
pokerGameActionStartAdd(pokerGame);
|
pokerGameActionStartAdd(pokerGame);
|
||||||
queueNext(&pokerGame->scene.conversation.actionQueue);
|
queueNext(&pokerGame->scene.conversation.actionQueue);
|
||||||
|
|
||||||
|
// Testing
|
||||||
|
dynArrayInit(&dynarr, sizeof(int32_t), 100);
|
||||||
|
int32_t i, count;
|
||||||
|
count = 32;
|
||||||
|
for(i = 0; i < count; i++) {
|
||||||
|
dynArrayPush(&dynarr, &i);
|
||||||
|
printf("Count i is %i\n", *((int32_t *)dynArrayGet(&dynarr, i)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
dynArraySploice(&dynarr, 0, 16);
|
||||||
|
printf("Count 0 is %i\n", *((int32_t *)dynArrayGet(&dynarr, 0)) );
|
||||||
|
printf("Count 8 is %i\n", *((int32_t *)dynArrayGet(&dynarr, 8)) );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +63,7 @@ void pokerGameUpdate(game_t *game) {
|
|||||||
|
|
||||||
// Render the UI
|
// Render the UI
|
||||||
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||||
pokerUiRender(pokerGame);
|
pokerUiRender(pokerGame, &game->engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pokerGameDispose(game_t *game) {
|
void pokerGameDispose(game_t *game) {
|
||||||
|
@ -25,7 +25,9 @@ void pokerPlayerUiRender(
|
|||||||
// Render chips
|
// Render chips
|
||||||
sprintf(buffer, "$%i", player->chips);
|
sprintf(buffer, "$%i", player->chips);
|
||||||
labelSetText(&ui->label, font, buffer);
|
labelSetText(&ui->label, font, buffer);
|
||||||
labelRender(&ui->label, shader, x, y);
|
labelRender(&ui->label, shader, x - ui->label.info.width, y);
|
||||||
|
|
||||||
|
// Render Face
|
||||||
|
|
||||||
// Render state
|
// Render state
|
||||||
if(player->state & POKER_PLAYER_STATE_OUT) {
|
if(player->state & POKER_PLAYER_STATE_OUT) {
|
||||||
@ -40,10 +42,9 @@ void pokerPlayerUiRender(
|
|||||||
sprintf(buffer, "Whatever");
|
sprintf(buffer, "Whatever");
|
||||||
}
|
}
|
||||||
labelSetText(&ui->label, font, buffer);
|
labelSetText(&ui->label, font, buffer);
|
||||||
labelRender(&ui->label, shader, x, y + scale * FONT_LINE_HEIGHT);
|
labelRender(&ui->label, shader,
|
||||||
|
x - ui->label.info.width, y + scale * FONT_LINE_HEIGHT
|
||||||
// Render face?
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pokerPlayerUiDispose(pokerplayerui_t *ui) {
|
void pokerPlayerUiDispose(pokerplayerui_t *ui) {
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../../../ui/label.h"
|
#include "../../../ui/label.h"
|
||||||
|
#include "../../../ui/image.h"
|
||||||
|
#include "../../../display/framebuffer.h"
|
||||||
|
#include "../../../display/camera.h"
|
||||||
|
|
||||||
|
|
||||||
void pokerPlayerUiInit(pokerplayerui_t *ui);
|
void pokerPlayerUiInit(pokerplayerui_t *ui);
|
||||||
|
@ -15,7 +15,7 @@ void pokerUiInit(pokergame_t *pokerGame) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pokerUiRender(pokergame_t *pokerGame) {
|
void pokerUiRender(pokergame_t *pokerGame, engine_t *engine) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
pokerplayerui_t *ui;
|
pokerplayerui_t *ui;
|
||||||
|
|
||||||
@ -23,9 +23,8 @@ void pokerUiRender(pokergame_t *pokerGame) {
|
|||||||
ui = pokerGame->ui.player + i;
|
ui = pokerGame->ui.player + i;
|
||||||
|
|
||||||
pokerPlayerUiRender(ui, pokerGame,
|
pokerPlayerUiRender(ui, pokerGame,
|
||||||
&pokerGame->assets.shader, &pokerGame->assets.font,
|
&pokerGame->assets.shader, &pokerGame->assets.font, i,
|
||||||
i,
|
engine->render.width, i * 75.0f
|
||||||
i * 150.0f, 0
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,9 @@ void pokerUiInit(pokergame_t *pokerGame);
|
|||||||
* Render the Poker Game UI.
|
* Render the Poker Game UI.
|
||||||
*
|
*
|
||||||
* @param pokerGame Game to render the UI for.
|
* @param pokerGame Game to render the UI for.
|
||||||
|
* @param engine Engine to use for the render.
|
||||||
*/
|
*/
|
||||||
void pokerUiRender(pokergame_t *pokerGame);
|
void pokerUiRender(pokergame_t *pokerGame, engine_t *engine);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup only the UI elements for a poker game.
|
* Cleanup only the UI elements for a poker game.
|
||||||
|
@ -7,23 +7,51 @@
|
|||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
void imageInit(image_t *image, texture_t *texture) {
|
void imageInit(image_t *image) {
|
||||||
image->quad.verticeCount = -1;
|
image->quad.verticeCount = -1;
|
||||||
imageSetTexture(image, texture);
|
image->width = 1;
|
||||||
|
image->height = 1;
|
||||||
|
imageSetTexture(image, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void imageSetTexture(image_t *image, texture_t *texture) {
|
void imageSetTexture(image_t *image, texture_t *texture) {
|
||||||
|
imageSetTextureAndCrop(image, texture,
|
||||||
|
0, 0,
|
||||||
|
texture == NULL ? 0 : (float)texture->width,
|
||||||
|
texture == NULL ? 0 : (float)texture->height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void imageSetTextureAndCrop(image_t *image, texture_t *texture,
|
||||||
|
float x, float y, float width, float height
|
||||||
|
) {
|
||||||
|
float u0, u1, v0, v1;
|
||||||
if(image->quad.verticeCount != -1) {
|
if(image->quad.verticeCount != -1) {
|
||||||
primitiveDispose(&image->quad);
|
primitiveDispose(&image->quad);
|
||||||
image->quad.verticeCount = -1;
|
image->quad.verticeCount = -1;
|
||||||
}
|
}
|
||||||
|
if(texture == NULL) return;
|
||||||
|
|
||||||
|
u0 = x / texture->width;
|
||||||
|
u1 = u0 + (width / texture->width);
|
||||||
|
v0 = y / texture->height;
|
||||||
|
v1 = v0 + (height / texture->height);
|
||||||
|
|
||||||
image->texture = texture;
|
image->texture = texture;
|
||||||
quadInit(&image->quad, 0, 0,0,0,0, texture->width,texture->height,1,1);
|
quadInit(&image->quad, 0,
|
||||||
|
0,0,u0,v0,
|
||||||
|
1,1,u1,v1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void imageRender(image_t *image, shader_t *shader, float x, float y) {
|
void imageRender(image_t *image, shader_t *shader, float x, float y) {
|
||||||
shaderUsePosition(shader, x, y, 0, 0, 0, 0);
|
if(image->texture == NULL) return;
|
||||||
|
shaderUsePositionAndScale(shader,
|
||||||
|
x,y,0,
|
||||||
|
0,0,0,
|
||||||
|
image->width, image->height, 1
|
||||||
|
);
|
||||||
|
shaderUseTexture(shader, image->texture);
|
||||||
primitiveDraw(&image->quad, 0, -1);
|
primitiveDraw(&image->quad, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
* Initialize an image.
|
* Initialize an image.
|
||||||
*
|
*
|
||||||
* @param image Image to initialize.
|
* @param image Image to initialize.
|
||||||
* @param texture Texture to use for initialization.
|
|
||||||
*/
|
*/
|
||||||
void imageInit(image_t *image, texture_t *texture);
|
void imageInit(image_t *image);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the texture for an image. This will also initialize the underlying quad.
|
* Set the texture for an image. This will also initialize the underlying quad.
|
||||||
@ -27,6 +26,21 @@ void imageInit(image_t *image, texture_t *texture);
|
|||||||
*/
|
*/
|
||||||
void imageSetTexture(image_t *image, texture_t *texture);
|
void imageSetTexture(image_t *image, texture_t *texture);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the texture for an image. This will also initialize the underlying quad.
|
||||||
|
* Also allows cropping of the texture image.
|
||||||
|
*
|
||||||
|
* @param image Image to set the texture for.
|
||||||
|
* @param texture Texture to use.
|
||||||
|
* @param x X position of the crop.
|
||||||
|
* @param y Y position of the crop.
|
||||||
|
* @param width Width of the crop.
|
||||||
|
* @param height Height of the crop.
|
||||||
|
*/
|
||||||
|
void imageSetTextureAndCrop(image_t *image, texture_t *texture,
|
||||||
|
float x, float y, float width, float height
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an image
|
* Render an image
|
||||||
*
|
*
|
||||||
|
@ -11,6 +11,10 @@ void * arrayGet(size_t size, void *array, int32_t index) {
|
|||||||
return (char *)array + (index * (size/sizeof(char)));
|
return (char *)array + (index * (size/sizeof(char)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void arraySet(size_t size, void *array, int32_t index, void *data) {
|
||||||
|
memcpy(arrayGet(size, array, index), data, size);
|
||||||
|
}
|
||||||
|
|
||||||
void arrayShuffle(size_t size, void *array, int32_t arrayLength) {
|
void arrayShuffle(size_t size, void *array, int32_t arrayLength) {
|
||||||
int32_t x, y;
|
int32_t x, y;
|
||||||
void *itemDest, *itemSource;
|
void *itemDest, *itemSource;
|
||||||
@ -104,4 +108,19 @@ void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
|
|||||||
|
|
||||||
// Cleanup the temporary array.
|
// Cleanup the temporary array.
|
||||||
free(temporary);
|
free(temporary);
|
||||||
|
}
|
||||||
|
|
||||||
|
void arraySplice(
|
||||||
|
size_t size, void *array, int32_t start, int32_t count, int32_t length
|
||||||
|
) {
|
||||||
|
// Take the end of the array...
|
||||||
|
int32_t takeStart = start + count;
|
||||||
|
int32_t takeLength = length - takeStart;
|
||||||
|
|
||||||
|
void *temporary = malloc(size * takeLength);
|
||||||
|
arrayCopy(size, arrayGet(size, array, takeStart), takeLength, temporary);
|
||||||
|
|
||||||
|
// Now copy it back into the original array
|
||||||
|
arrayCopy(size, temporary, takeLength, arrayGet(size, array, start));
|
||||||
|
free(temporary);
|
||||||
}
|
}
|
@ -18,6 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
void * arrayGet(size_t size, void *array, int32_t index);
|
void * arrayGet(size_t size, void *array, int32_t index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an object into the array.
|
||||||
|
*
|
||||||
|
* @param size Size of the element to set.
|
||||||
|
* @param array Array to set in to.
|
||||||
|
* @param index Index to set into.
|
||||||
|
* @param data Data to set into the array.
|
||||||
|
* @return void*
|
||||||
|
*/
|
||||||
|
void arraySet(size_t size, void *array, int32_t index, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomizes the contents of an array.
|
* Randomizes the contents of an array.
|
||||||
*
|
*
|
||||||
@ -114,4 +125,18 @@ int32_t arrayFindString(char **array, int32_t arrayLength, char *value);
|
|||||||
*/
|
*/
|
||||||
void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
|
void arrayRewind(size_t size, void *source, int32_t length, int32_t start,
|
||||||
int32_t count
|
int32_t count
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove some elements from an array. This will cause the elements after the
|
||||||
|
* removed items to be shifted down into their place.
|
||||||
|
*
|
||||||
|
* @param size Size of each element within the array.
|
||||||
|
* @param array Array itself.
|
||||||
|
* @param start The first index you want to remove.
|
||||||
|
* @param count The count of elements to remove.
|
||||||
|
* @param length The length of the total array.
|
||||||
|
*/
|
||||||
|
void arraySplice(
|
||||||
|
size_t size, void *array, int32_t start, int32_t count, int32_t length
|
||||||
);
|
);
|
43
src/util/dynarray.c
Normal file
43
src/util/dynarray.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dynarray.h"
|
||||||
|
|
||||||
|
void dynArrayInit(dynarray_t *array, size_t size, int32_t total) {
|
||||||
|
array->total = total;
|
||||||
|
array->size = size;
|
||||||
|
array->length = 0;
|
||||||
|
array->data = malloc(size * total);
|
||||||
|
}
|
||||||
|
|
||||||
|
void * dynArrayGet(dynarray_t *array, int32_t i) {
|
||||||
|
return arrayGet(array->size, array->data, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynArraySet(dynarray_t *array, int32_t i, void *data) {
|
||||||
|
array->length = mathMax(array->length, i+1);
|
||||||
|
arraySet(array->size, array->data, i, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dynArrayPush(dynarray_t *array, void *data) {
|
||||||
|
int32_t i = array->length;
|
||||||
|
dynArraySet(array, i, data);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynArrayPop(dynarray_t *array) {
|
||||||
|
array->length -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynArraySplice(dynarray_t *array, int32_t start, int32_t count) {
|
||||||
|
arraySplice(array->size, array->data, start, count, array->length);
|
||||||
|
array->length -= count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynArrayDispose(dynarray_t *array) {
|
||||||
|
free(array->data);
|
||||||
|
}
|
75
src/util/dynarray.h
Normal file
75
src/util/dynarray.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <dawn/dawn.h>
|
||||||
|
#include "array.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a dynamic array. Dynamic arrays are a more highlevel array style that
|
||||||
|
* can offer great flexibility and ease-of-use, at the cost of memory, memory
|
||||||
|
* fragmentation and some slight performance. Great for when you need something
|
||||||
|
* like a traditional array, without the hassle of a linked list.
|
||||||
|
*
|
||||||
|
* @param array Array to initialize.
|
||||||
|
* @param size Size of each element within the array.
|
||||||
|
* @param total Total number of elements that the array can hold.
|
||||||
|
*/
|
||||||
|
void dynArrayInit(dynarray_t *array, size_t size, int32_t total);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the pointer to an index within the array.
|
||||||
|
*
|
||||||
|
* @param array Array to get from.
|
||||||
|
* @param i Index to get
|
||||||
|
* @return Pointer to that element.
|
||||||
|
*/
|
||||||
|
void * dynArrayGet(dynarray_t *array, int32_t i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set something into the array.
|
||||||
|
*
|
||||||
|
* @param array Array to set into.
|
||||||
|
* @param i Index to set into.
|
||||||
|
* @param data Pointer to the data to set.
|
||||||
|
*/
|
||||||
|
void dynArraySet(dynarray_t *array, int32_t i, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Push an element into the array.
|
||||||
|
*
|
||||||
|
* @param array Array to push in to.
|
||||||
|
* @param data Pointer to the data to push.
|
||||||
|
* @return The index that the data was pushed in to.
|
||||||
|
*/
|
||||||
|
int32_t dynArrayPush(dynarray_t *array, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Pops" (Removes) the last element from the array.
|
||||||
|
*
|
||||||
|
* @param array Array to pop.
|
||||||
|
*/
|
||||||
|
void dynArrayPop(dynarray_t *array);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes elements from out of the array, and shuffles the remaining items.
|
||||||
|
* This is useful for removing a specific item from an array and keeping the
|
||||||
|
* holes out of the array. This will readjust the indexes of all elements that
|
||||||
|
* appear after the spliced index.
|
||||||
|
*
|
||||||
|
* @param array Array to splice.
|
||||||
|
* @param start First index to splice.
|
||||||
|
* @param count Count of elements to splice
|
||||||
|
*/
|
||||||
|
void dynArraySplice(dynarray_t *array, int32_t start, int32_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispose a previously created dynamic array.
|
||||||
|
*
|
||||||
|
* @param array Dynamic array to dispose.
|
||||||
|
*/
|
||||||
|
void dynArrayDispose(dynarray_t *array);
|
@ -46,14 +46,6 @@ void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
|
|||||||
scene->cameraLookX, scene->cameraLookY, scene->cameraLookZ
|
scene->cameraLookX, scene->cameraLookY, scene->cameraLookZ
|
||||||
);
|
);
|
||||||
|
|
||||||
if(false) {
|
|
||||||
float d = 2;
|
|
||||||
cameraOrbit(&scene->camera,
|
|
||||||
2, engine->time.current / 3.0f, mathDeg2Rad(35),
|
|
||||||
0, 0, 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set Camera Perspective
|
// Set Camera Perspective
|
||||||
cameraPerspective(&scene->camera, 35,
|
cameraPerspective(&scene->camera, 35,
|
||||||
engine->render.width/engine->render.height,
|
engine->render.width/engine->render.height,
|
||||||
|
Reference in New Issue
Block a user