Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LARUTAN
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Benjamin REED
LARUTAN
Commits
8b8d5c51
Commit
8b8d5c51
authored
Nov 08, 2024
by
Benjamin REED
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w.i.p. rework of asset system
parent
f7d43721
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
35 deletions
+86
-35
main
main
+0
-0
main.c3
src/main.c3
+79
-28
rendering.c3
src/rendering.c3
+7
-7
No files found.
main
View file @
8b8d5c51
No preview for this file type
src/main.c3
View file @
8b8d5c51
...
...
@@ -5,6 +5,8 @@ import std::core::mem;
import libc;
import std::thread;
import std::collections::list;
import std::collections::map;
import std::core::types;
import raylib;
import rendering;
...
...
@@ -14,6 +16,7 @@ import room_gen;
def SpriteList = List(<Sprite*>);
def EntityList = List(<Entity>);
def IndexList = List(<usz>);
def ImageList = List(<Image>);
const Colour RED = {255, 0, 0, 255};
const Colour WHITE = {255, 255, 255, 255};
...
...
@@ -71,8 +74,6 @@ const double MAP_AABB_RAYCAST_CHECK_RAY_STEP = 0.05;
const uint COLUMN_PIXEL_WIDTH = 1;
const uint PIXEL_HEIGHT = 1;
const uint TEXTURE_COUNT = 1;
// DEBUG
bool draw_minimap = false;
...
...
@@ -80,34 +81,72 @@ bool draw_floor_and_ceiling = true;
//------
const usz WORLD_TEXTURES_COUNT = 1;
const usz SPRITE_TEXTURES_COUNT = 1;
const usz WEAPON_TEXTURES_COUNT = 1;
const usz WORLD_TEXTURES_COUNT = 0;
const usz SPRITE_TEXTURES_COUNT = 0;
const usz WEAPON_TEXTURES_COUNT = 0;
// NOTE: this 'usz' actually means 'AssetCategory', bug(?) in the
// hashmap implementation means i can't use it
def AssetMap = HashMap(<usz, any>); // yucky, can't use
// enum even tho its usz
struct Assets {
Image* world_textures;
Image* sprite_textures;
Image* weapon_textures;
AssetMap assets;
Image missing;
}
macro Assets.@get(&self, category, idx) {
switch (category) {
case "ws":
case "weapons":
enum AssetCategory : usz (typeid type) {
WORLD_TEXTURES = Image.typeid,
SPRITE_TEXTURES = Image.typeid,
WEAPON_TEXTURES = Image.typeid,
}
fn void Assets.init(Assets this) {
this.assets.new_init();
}
fn usz Assets.category_len(Assets self, AssetCategory category) {
any possible_list = self.assets.get((usz)category)!!;
switch (possible_list) {
case ImageList:
return possible_list.len();
default:
return 0;
}
}
fn Image* Assets.missing(Assets* self) {
return &self.missing;
}
// macro so that Asset struct can return more than just an image pointer (not used yet)
macro Assets.@get(&self, $Type, category, idx) {
if (try category_ls = self.assets.get( (usz)category )) {
if ($Type.typeid == category_ls.type.inner) {
io::printfn("Attempt to index into an asset that is not a list.");
return &self.missing;
}
else {
return &anycast(category_ls, $Type)!![idx];
}
}
else {
return &self.missing;
}
/*switch (category) {
case AssetCategory.WEAPON_TEXTURES:
if (idx < 0 || idx >= WEAPON_TEXTURES_COUNT) return &self.missing;
return &self.weapon_textures[idx];
break;
case "w":
case "wrld":
case "world":
case AssetCategory.WORLD_TEXTURES:
if (idx < 0 || idx >= WORLD_TEXTURES_COUNT) return &self.missing;
return &self.world_textures[idx];
break;
case "s":
case "sprite":
case AssetCategory.SPRITE_TEXTURES:
if (idx < 0 || idx >= SPRITE_TEXTURES_COUNT) return &self.missing;
return &self.sprite_textures[idx];
...
...
@@ -115,24 +154,35 @@ macro Assets.@get(&self, category, idx) {
default:
return &self.missing;
}
*/
return &self.missing;
}
fn Image* Assets.load_images(Assets this, String[] paths) {
io::printn("TODO: don't do this, make it similar to the '@get' interface, and make the sizes not be constants because that's a bit schewpid in the year of our lord twenty twenty four");
fn void Assets.load_images(Assets this, AssetCategory category, String[] image_paths) {
if (!this.assets.has_key( (usz) category)) {
ImageList* list = (ImageList*)calloc(ImageList.sizeof);
this.assets.set( (usz)category, list );
}
foreach (path: paths) {
// TODO: don't do this, make it similar to the '@get'
// interface, and make the sizes not be constants because that's a
// bit schewpid in the year of our lord twenty twenty four
foreach (path: image_paths) {
Image img;
img = raylib::load_image(path);
any val = this.assets.get( (usz)category )!!;
switch (val.type) {
case ImageList:
((ImageList*)val).push(img);
break;
default:
io::printfn("WARNING: Type mismatch error pushing images to Assets.");
break;
}
}
return null;
}
fn void Assets.free(Assets this) {
io::printfn("TODO: IMPLEMENT FREEING ASSETS");
this.assets.free();
//for (int i = 0; i < TEXTURE_COUNT; i ++) raylib::unload_image(textures[i]);
}
...
...
@@ -474,10 +524,11 @@ fn int main() {
world.map = (MapCell*)calloc(MAP_WIDTH * MAP_HEIGHT * MapCell.sizeof);
Assets assets;
assets.init();
assets.missing = raylib::load_image("assets/missing.png");
assets.
weapon_textures = assets.load_images(
{"assets/weapons/pistol.png"});
assets.
world_textures = assets.load_images(
{"assets/col_test.png","assets/brick_wall.png"});
assets.
sprite_textures = assets.load_images(
{"assets/sprites/barrel.png","assets/sprites/boy.png"});
assets.
load_images(WEAPON_TEXTURES,
{"assets/weapons/pistol.png"});
assets.
load_images(WORLD_TEXTURES,
{"assets/col_test.png","assets/brick_wall.png"});
assets.
load_images(SPRITE_TEXTURES,
{"assets/sprites/barrel.png","assets/sprites/boy.png"});
/*Image* textures = (Image*)calloc(TEXTURE_COUNT * Image.sizeof);
String[TEXTURE_COUNT] image_paths = {
"assets/col_test.png",
...
...
src/rendering.c3
View file @
8b8d5c51
...
...
@@ -148,10 +148,10 @@ fn void raycast_walls(Player* player, MapCell* map, Assets* assets, Colour* pixe
if (map[map_index] != 0) z_buffer[i] = perp_wall_dist;
int texture_index = map[map_index];
if (texture_index <=
main::TEXTURE_COUNT
) {
if (texture_index <=
assets.category_len(AssetCategory.WORLD_TEXTURES)
) {
texture_index--;
Image *texture = assets.@get(
"w"
, texture_index);
Image *texture = assets.@get(
Image, AssetCategory.WORLD_TEXTURES
, texture_index);
double wall_x = 0.0;
if (side == 0) {
...
...
@@ -242,14 +242,14 @@ fn void raycast_floors(Player* player, MapCell* map, Assets* assets, Colour* pix
for (int x = 0; x < main::RENDER_WINDOW_WIDTH; x ++) {
int[<2>] cell = (int[<2>])math::floor(floor_pos);
int floor_tex_idx =
1
;
int ceiling_tex_idx =
1
;
int floor_tex_idx =
0
;
int ceiling_tex_idx =
0
;
if (cell.x % 2 == 0 && cell.y % 2 == 0) {
floor_tex_idx = 1;
}
Image* floor_texture = assets.
@get("w"
, floor_tex_idx);
Image* ceiling_texture = assets.
@get("w"
, ceiling_tex_idx);
Image* floor_texture = assets.
missing();//assets.@get(ImageList, AssetCategory.WORLD_TEXTURES
, floor_tex_idx);
Image* ceiling_texture = assets.
missing();//assets.@get(ImageList, AssetCategory.WORLD_TEXTURES
, ceiling_tex_idx);
// TODO: calculate separately for different sized floor & ceiling textures
int[<2>] tex_pos = {
...
...
@@ -349,7 +349,7 @@ fn void render_sprites(Player* player, SpriteList* sprites, Assets* assets, Colo
draw_end_x = main::RENDER_WINDOW_WIDTH - 1;
}
Image* tex = assets.
@get("sprite"
, sprite.texture_index);
Image* tex = assets.
missing();//assets.@get(ImageList, AssetCategory.SPRITE_TEXTURES
, sprite.texture_index);
for (int stripe = draw_start_x; stripe < draw_end_x; stripe++) {
int tex_x = (int) (256 * (stripe - (-sprite_width / 2 + sprite_screen_x)) * tex.width / sprite_width) / 256;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment