Skip to content

Commit

Permalink
asset manager, release 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
UtoECat committed Sep 24, 2023
1 parent df18341 commit 53e62d6
Show file tree
Hide file tree
Showing 19 changed files with 29,797 additions and 14 deletions.
674 changes: 674 additions & 0 deletions assets/license.txt

Large diffs are not rendered by default.

Binary file added assets/shit_maker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified config.bin
Binary file not shown.
8 changes: 7 additions & 1 deletion makecfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
INCS := -I./src/ -I./src/libs
FLAGS := -Og -fsanitize=address
FLAGS := -O2
LFLAGS := -g

all: pixelbox

# generate asset archive :D
./src/archive-generated.c : ./tools/archiver
./tools/archiver assets/* > ./src/archive-generated.c
6 changes: 5 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include makecfg

SRCS := $(shell find ./src/ -name '*.c')
SRCS := $(shell find ./src/ -name '*.c') ./src/archive-generated.c
OBJS := $(SRCS:./src/%.c=./bin/%.o)
FLAGS +=

Expand All @@ -13,5 +13,9 @@ pixelbox : $(OBJS)
mkdir -p $(dir $@)
$(CC) -c $< -o $@ -Wall -Wextra $(FLAGS) $(INCS)

# archiver building...
./tools/archiver : ./tools/archiver.c
$(CC) $^ -I./tools/ -o ./tools/archiver -lm -lraylib -Wall -O2

clean :
rm ./bin/*.o
6 changes: 4 additions & 2 deletions makefile-win
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: kisspixel.exe clean
.PHONY: pixelbox clean

include makecfg

Expand All @@ -7,7 +7,9 @@ OBJS := $(SRCS:./src/%.c=./wbin/%.o)
FLAGS +=
CC := x86_64-w64-mingw32-gcc

kisspixel.exe : $(OBJS)
pixelbox: pixelbox.exe

pixelbox.exe : $(OBJS)
$(CC) $^ libraylib.a -o $@ $(LFLAGS) -static -static-libgcc -lm -lgdi32 -lwinmm -lpthread $(FLAGS)

./wbin/%.o : ./src/%.c
Expand Down
Binary file modified pixelbox
Binary file not shown.
27 changes: 22 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
# Pixelbox
my last attempt to create pixelbox.
This time it MUST be simple and pretty fast.

*Luajit FFI turns into mess when you trying to use small integers.
Now we are in PURE C, no dynamic languages.*
~~Do you want modification/plugin? Edit source and compile it! Easy!~~
Pixelbox is an unlimited falling-sand sandbox game.
Still in alpha development.

# Controls
- Left Mouse Button - Hold and move to move your camera.
- Right Mouse button - Hold and move to draw pixels
- WASD for precise camera movement

# Special world names
- `:null:` - no database is created, all your changsw will lost when chunks will be unloaded (*used in development, for testing*)
- `:memory:` - In memory database is created, all your changes will lost when you exit the world.
- `any other name` - database file is created, all changes are saved on the disk.

**WARNING:** database is working with `pragma journal_mode=MEMORY`, so it's unsafe to teminate program using task manager or due to system shutdown. Power loss is in effect too. Make sure to properly exit your worlds to minimize risk of the database corruption.
In beta versions it's planned to add automatic world backups, now you may want to do it manually.

Also, since pixelbox is still in alpha, and internal structure may change significantly, **any sort of backwards compatability is not guaranteed!**

# Pages
- See list of [Licenses](LICENSES.md) for code and resources.
- See screenshots (TODO)
- See todo list in Projects tab. (TODO)
- telegram group with news about development [in Russian](https://t.me/pixebox_dev)

# raylib makefile flags for TARGET\_OS=windows, HOST\_OS=linux
```
make RAYLIB_LIBTYPE=STATIC USE_EXTERNAL_GLFW=FALSE PLATFORM_OS=Windows CC=x86_64-w64-mingw32-gcc
```
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
archive-generated.c
60 changes: 60 additions & 0 deletions src/assets.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,70 @@ static Texture errorTexture;

#include "img_error.h"

// DEFLATE'd!
extern const struct archive_node {
const char* name;
const long unsigned int length;
const unsigned char* value;
} __main_arcive[];

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define TRACELOG(...) TraceLog(__VA_ARGS__);

static uint8_t* loadFile(const char* fn, unsigned int *cnt) {
for(const struct archive_node* n = __main_arcive; n->name; n++) {
if (strcmp(fn, n->name) == 0) {
//char* copy = malloc(n->length+1);
//if (!copy) return NULL;
//memcpy(copy, n->value, n->length);
int ressize = 0;
uint8_t* res = DecompressData((uint8_t*)n->value, n->length, &ressize);
*cnt = ressize;
return res;
}
}
// else
// taken form raylib, else i will actually write same stuff...
FILE *file = fopen(fn, "rb");
char* data = NULL;

if (file != NULL) {
fseek(file, 0, SEEK_END);
int size = ftell(file);
fseek(file, 0, SEEK_SET);
if (size > 0) {
data = (unsigned char *)malloc(size+1);
long int count = fread(data, sizeof(unsigned char), size, file);
*cnt = count;
} else TRACELOG(LOG_WARNING, "Failed to read file %s", fn);
fclose(file);
}
else TRACELOG(LOG_WARNING, "Failed to open file %s", fn);
*cnt = 0;
return NULL;
}

static char* loadFileT(const char* fn) {
unsigned int cnt = 0;
uint8_t* dat = loadFile(fn, &cnt);
// check for trailing zero
if (dat && dat[cnt] != 0) {
dat[cnt] = 0;
}
return (char*)dat; // i don't care...
}

void initAssetSystem() {
for (int i = 0; i < HASH_LEN; i++)
ASSET_MAP[i] = NULL;

SetLoadFileDataCallback(loadFile);
SetLoadFileTextCallback(loadFileT);

Image err = (Image) {
.data = img_error_data,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
Expand Down
2 changes: 1 addition & 1 deletion src/pixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool updateChunk(struct chunk* c, const int stage) {

#define TPS 64
#define MIN_TICK (1.0/(double)TPS)
#define MAX_STAGES 7
#define MAX_STAGES 3
static double old_time = 0.0;

void updateWorld(void) {
Expand Down
2 changes: 1 addition & 1 deletion src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void updateRender(Camera2D cam) {
if (!o) {
DrawRectangleRec(
(Rectangle){rx, ry, CHUNK_WIDTH, CHUNK_WIDTH},
getPixelColor(10)//softGenerate(x, y))
getPixelColor(softGenerate(x, y))
);
continue;
}
Expand Down
Binary file added src/scr/config.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion src/scr/scr_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void draw() {

Rectangle item = {rec.x, rec.y, 100, 100};
item.x += rec.width/2 - 50 - 70;
GuiAssetTexture(item, LookupAssetID("icon.png"));
GuiAssetTexture(item, LookupAssetID("assets/icon.png"));
item.x += 105;
item.width = 140;
GuiLabel(item, TextFormat("Pixelbox v.%s\n%s%s",
Expand Down
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/img2header
/archiver
9 changes: 7 additions & 2 deletions tools/ar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <https://www.gnu.org/licenses/>.
--
-- This file needs custom compress() function. It's implemented as
-- raylib's CompressData() wrapper in archiver.c!
--
--]]

local err = io.stderr
Expand All @@ -37,8 +41,9 @@ end

local buff =
[[/* THIS FILE IS AUTOGENERATED!
* SEE ./tools/ar.lua FOR DETAILS!
* SEE ./tools/ar.lua and ./tools/archiver.c FOR DETAILS!
* DO NOT EDIT! */
// Compressed using DEFLATE algo!
]]

Expand Down Expand Up @@ -93,7 +98,7 @@ end
local function readdata(name)
local ext = name:sub(-3, -1)
local fun = extensions[ext] and extensions[ext] or pass
local data = fun(readfile(name))
local data = compress(fun(readfile(name)))
return data
end

Expand Down
39 changes: 39 additions & 0 deletions tools/archiver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#define LUA_IMPL
#include "minilua.h"
#include <stdio.h>
#include <raylib.h>

static int lua_deflate(lua_State* L) {
int outsize = 0;
size_t insize = 0;
const char* str = luaL_checklstring(L, 1, &insize);
char* res = CompressData(str, insize, &outsize);
if (!res) return 0;
lua_pushlstring(L, res, outsize);
MemFree(res);
return 1;
}

int main(int argc, const char** argv) {
lua_State* L = luaL_newstate();
luaL_openlibs(L);

SetTraceLogLevel(LOG_NONE);
lua_pushcfunction(L, lua_deflate);
lua_setglobal(L, "compress");

lua_newtable(L);
for(int i = 1; i < argc; i++) {
lua_pushstring(L, argv[i]);
lua_seti(L, -2, i);
}
lua_setglobal(L, "arg");

if (luaL_dofile(L, "tools/ar.lua") != LUA_OK) {
fprintf(stderr, "%s", lua_tostring(L, -1));
return -1;
}

lua_close(L);
return 0;
}
File renamed without changes
Loading

0 comments on commit 53e62d6

Please sign in to comment.