Moved some game code into engine code
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
// Workspace: Game
|
// Workspace: Game
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:32.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:34.
|
||||||
//
|
//
|
||||||
GAME_NAME :: "FPS";
|
GAME_NAME :: "OCT24";
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:33.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:35.
|
||||||
//
|
//
|
||||||
#import "Bucket_Array";
|
#import "Bucket_Array";
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:246.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:248.
|
||||||
//
|
//
|
||||||
serialize_entity :: (e: *Entity, path: string) {
|
serialize_entity :: (e: *Entity, path: string) {
|
||||||
builder: String_Builder;
|
builder: String_Builder;
|
||||||
@@ -21,7 +21,6 @@ serialize_entity :: (e: *Entity, path: string) {
|
|||||||
case Block; serialize_entity(cast(*Block)e, *builder);
|
case Block; serialize_entity(cast(*Block)e, *builder);
|
||||||
case Character; serialize_entity(cast(*Character)e, *builder);
|
case Character; serialize_entity(cast(*Character)e, *builder);
|
||||||
case Item; serialize_entity(cast(*Item)e, *builder);
|
case Item; serialize_entity(cast(*Item)e, *builder);
|
||||||
case Pistol; serialize_entity(cast(*Pistol)e, *builder);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ serialize_entity :: (e: *Entity, path: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:257.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:259.
|
||||||
//
|
//
|
||||||
deserialize_entity :: (scene: *Scene, path: string) -> *Entity {
|
deserialize_entity :: (scene: *Scene, path: string) -> *Entity {
|
||||||
content := File.read_entire_file(path);
|
content := File.read_entire_file(path);
|
||||||
@@ -48,7 +47,6 @@ deserialize_entity :: (scene: *Scene, path: string) -> *Entity {
|
|||||||
case "Block"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Block); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Block)e); update_matrix(*e.transform);
|
case "Block"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Block); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Block)e); update_matrix(*e.transform);
|
||||||
case "Character"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Character); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Character)e); update_matrix(*e.transform);
|
case "Character"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Character); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Character)e); update_matrix(*e.transform);
|
||||||
case "Item"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Item); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Item)e); update_matrix(*e.transform);
|
case "Item"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Item); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Item)e); update_matrix(*e.transform);
|
||||||
case "Pistol"; p, locator := find_and_occupy_empty_slot(*scene.by_type._Pistol); p._locator = locator; e = p; register_entity(scene, p); init_entity(p); deserialize_entity(scene, lines, cast(*Pistol)e); update_matrix(*e.transform);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ deserialize_entity :: (scene: *Scene, path: string) -> *Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:266.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:268.
|
||||||
//
|
//
|
||||||
new_block :: (scene: *Scene = null) -> *Block { _scene := scene;
|
new_block :: (scene: *Scene = null) -> *Block { _scene := scene;
|
||||||
if _scene == null {
|
if _scene == null {
|
||||||
@@ -70,178 +68,9 @@ new_item :: (scene: *Scene = null) -> *Item { _scene := scene;
|
|||||||
if _scene == null {
|
if _scene == null {
|
||||||
_scene = current_scene; }
|
_scene = current_scene; }
|
||||||
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
||||||
new_pistol :: (scene: *Scene = null) -> *Pistol { _scene := scene;
|
|
||||||
if _scene == null {
|
|
||||||
_scene = current_scene; }
|
|
||||||
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Pistol); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
//
|
|
||||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
|
||||||
print_to_builder(builder, "type: Item\n");
|
|
||||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
|
||||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
|
||||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
|
||||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
|
||||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
|
||||||
print_to_builder(builder, "entity.grid_position.x: %\n", e.entity.grid_position.x);
|
|
||||||
print_to_builder(builder, "entity.grid_position.y: %\n", e.entity.grid_position.y);
|
|
||||||
print_to_builder(builder, "entity.grid_position.z: %\n", e.entity.grid_position.z);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
|
||||||
//
|
|
||||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
|
||||||
for line: lines {
|
|
||||||
values := split(line, ":");
|
|
||||||
if values.count == 2 {
|
|
||||||
if trim(values[0], " ") == {
|
|
||||||
case "entity.enabled";
|
|
||||||
scan2(values[1], "%", *e.entity.enabled);
|
|
||||||
case "entity.transform.position.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
|
||||||
case "entity.transform.position.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
|
||||||
case "entity.transform.position.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
|
||||||
case "entity.transform.orientation.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
|
||||||
case "entity.transform.orientation.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
|
||||||
case "entity.transform.orientation.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
|
||||||
case "entity.transform.orientation.w";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
|
||||||
case "entity.transform.scale.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
|
||||||
case "entity.transform.scale.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
|
||||||
case "entity.transform.scale.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
|
||||||
case "entity.grid_position.x";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.x);
|
|
||||||
case "entity.grid_position.y";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.y);
|
|
||||||
case "entity.grid_position.z";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.z);
|
|
||||||
case "entity.snap_offset.x";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
|
||||||
case "entity.snap_offset.y";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
|
||||||
case "entity.snap_offset.z";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
|
||||||
//
|
|
||||||
serialize_entity :: (e: *Pistol, builder: *String_Builder) {
|
|
||||||
print_to_builder(builder, "type: Pistol\n");
|
|
||||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
|
||||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
|
||||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
|
||||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
|
||||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
|
||||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
|
||||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
|
||||||
print_to_builder(builder, "entity.grid_position.x: %\n", e.entity.grid_position.x);
|
|
||||||
print_to_builder(builder, "entity.grid_position.y: %\n", e.entity.grid_position.y);
|
|
||||||
print_to_builder(builder, "entity.grid_position.z: %\n", e.entity.grid_position.z);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
|
||||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
|
||||||
print_to_builder(builder, "shooting: %\n", e.shooting);
|
|
||||||
print_to_builder(builder, "reloading: %\n", e.reloading);
|
|
||||||
print_to_builder(builder, "shoot_time: %\n", e.shoot_time);
|
|
||||||
print_to_builder(builder, "reload_time: %\n", e.reload_time);
|
|
||||||
print_to_builder(builder, "shot_cooldown_time: %\n", e.shot_cooldown_time);
|
|
||||||
print_to_builder(builder, "current_mag_ammo: %\n", e.current_mag_ammo);
|
|
||||||
print_to_builder(builder, "ammo_per_mag: %\n", e.ammo_per_mag);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
|
||||||
//
|
|
||||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Pistol) {
|
|
||||||
for line: lines {
|
|
||||||
values := split(line, ":");
|
|
||||||
if values.count == 2 {
|
|
||||||
if trim(values[0], " ") == {
|
|
||||||
case "entity.enabled";
|
|
||||||
scan2(values[1], "%", *e.entity.enabled);
|
|
||||||
case "entity.transform.position.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
|
||||||
case "entity.transform.position.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
|
||||||
case "entity.transform.position.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
|
||||||
case "entity.transform.orientation.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
|
||||||
case "entity.transform.orientation.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
|
||||||
case "entity.transform.orientation.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
|
||||||
case "entity.transform.orientation.w";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
|
||||||
case "entity.transform.scale.x";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
|
||||||
case "entity.transform.scale.y";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
|
||||||
case "entity.transform.scale.z";
|
|
||||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
|
||||||
case "entity.grid_position.x";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.x);
|
|
||||||
case "entity.grid_position.y";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.y);
|
|
||||||
case "entity.grid_position.z";
|
|
||||||
scan2(values[1], "%", *e.entity.grid_position.z);
|
|
||||||
case "entity.snap_offset.x";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
|
||||||
case "entity.snap_offset.y";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
|
||||||
case "entity.snap_offset.z";
|
|
||||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
|
||||||
case "shooting";
|
|
||||||
scan2(values[1], "%", *e.shooting);
|
|
||||||
case "reloading";
|
|
||||||
scan2(values[1], "%", *e.reloading);
|
|
||||||
case "shoot_time";
|
|
||||||
scan2(values[1], "%", *e.shoot_time);
|
|
||||||
case "reload_time";
|
|
||||||
scan2(values[1], "%", *e.reload_time);
|
|
||||||
case "shot_cooldown_time";
|
|
||||||
scan2(values[1], "%", *e.shot_cooldown_time);
|
|
||||||
case "current_mag_ammo";
|
|
||||||
scan2(values[1], "%", *e.current_mag_ammo);
|
|
||||||
case "ammo_per_mag";
|
|
||||||
scan2(values[1], "%", *e.ammo_per_mag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
|
||||||
//
|
//
|
||||||
serialize_entity :: (e: *Block, builder: *String_Builder) {
|
serialize_entity :: (e: *Block, builder: *String_Builder) {
|
||||||
print_to_builder(builder, "type: Block\n");
|
print_to_builder(builder, "type: Block\n");
|
||||||
@@ -268,7 +97,7 @@ serialize_entity :: (e: *Block, builder: *String_Builder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
//
|
//
|
||||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
||||||
for line: lines {
|
for line: lines {
|
||||||
@@ -317,7 +146,79 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
|
//
|
||||||
|
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||||
|
print_to_builder(builder, "type: Item\n");
|
||||||
|
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||||
|
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||||
|
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||||
|
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||||
|
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||||
|
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||||
|
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||||
|
print_to_builder(builder, "entity.grid_position.x: %\n", e.entity.grid_position.x);
|
||||||
|
print_to_builder(builder, "entity.grid_position.y: %\n", e.entity.grid_position.y);
|
||||||
|
print_to_builder(builder, "entity.grid_position.z: %\n", e.entity.grid_position.z);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||||
|
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
|
//
|
||||||
|
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||||
|
for line: lines {
|
||||||
|
values := split(line, ":");
|
||||||
|
if values.count == 2 {
|
||||||
|
if trim(values[0], " ") == {
|
||||||
|
case "entity.enabled";
|
||||||
|
scan2(values[1], "%", *e.entity.enabled);
|
||||||
|
case "entity.transform.position.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||||
|
case "entity.transform.position.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||||
|
case "entity.transform.position.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||||
|
case "entity.transform.orientation.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||||
|
case "entity.transform.orientation.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||||
|
case "entity.transform.orientation.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||||
|
case "entity.transform.orientation.w";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||||
|
case "entity.transform.scale.x";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||||
|
case "entity.transform.scale.y";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||||
|
case "entity.transform.scale.z";
|
||||||
|
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||||
|
case "entity.grid_position.x";
|
||||||
|
scan2(values[1], "%", *e.entity.grid_position.x);
|
||||||
|
case "entity.grid_position.y";
|
||||||
|
scan2(values[1], "%", *e.entity.grid_position.y);
|
||||||
|
case "entity.grid_position.z";
|
||||||
|
scan2(values[1], "%", *e.entity.grid_position.z);
|
||||||
|
case "entity.snap_offset.x";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||||
|
case "entity.snap_offset.y";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||||
|
case "entity.snap_offset.z";
|
||||||
|
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
//
|
//
|
||||||
serialize_entity :: (e: *Character, builder: *String_Builder) {
|
serialize_entity :: (e: *Character, builder: *String_Builder) {
|
||||||
print_to_builder(builder, "type: Character\n");
|
print_to_builder(builder, "type: Character\n");
|
||||||
@@ -343,16 +244,14 @@ serialize_entity :: (e: *Character, builder: *String_Builder) {
|
|||||||
print_to_builder(builder, "look_direction.y: %\n", e.look_direction.y);
|
print_to_builder(builder, "look_direction.y: %\n", e.look_direction.y);
|
||||||
print_to_builder(builder, "look_direction.z: %\n", e.look_direction.z);
|
print_to_builder(builder, "look_direction.z: %\n", e.look_direction.z);
|
||||||
print_to_builder(builder, "yaw: %\n", e.yaw);
|
print_to_builder(builder, "yaw: %\n", e.yaw);
|
||||||
print_to_builder(builder, "pitch: %\n", e.pitch);
|
|
||||||
print_to_builder(builder, "last_footstep_audio: %\n", e.last_footstep_audio);
|
print_to_builder(builder, "last_footstep_audio: %\n", e.last_footstep_audio);
|
||||||
print_to_builder(builder, "animation_time: %\n", e.animation_time);
|
print_to_builder(builder, "animation_time: %\n", e.animation_time);
|
||||||
print_to_builder(builder, "health: %\n", e.health);
|
|
||||||
print_to_builder(builder, "jump_press_time: %\n", e.jump_press_time);
|
print_to_builder(builder, "jump_press_time: %\n", e.jump_press_time);
|
||||||
print_to_builder(builder, "last_grounded_time: %\n", e.last_grounded_time);
|
print_to_builder(builder, "last_grounded_time: %\n", e.last_grounded_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:270.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||||
//
|
//
|
||||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Character) {
|
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Character) {
|
||||||
for line: lines {
|
for line: lines {
|
||||||
@@ -401,14 +300,10 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Character) {
|
|||||||
scan2(values[1], "%", *e.look_direction.z);
|
scan2(values[1], "%", *e.look_direction.z);
|
||||||
case "yaw";
|
case "yaw";
|
||||||
scan2(values[1], "%", *e.yaw);
|
scan2(values[1], "%", *e.yaw);
|
||||||
case "pitch";
|
|
||||||
scan2(values[1], "%", *e.pitch);
|
|
||||||
case "last_footstep_audio";
|
case "last_footstep_audio";
|
||||||
scan2(values[1], "%", *e.last_footstep_audio);
|
scan2(values[1], "%", *e.last_footstep_audio);
|
||||||
case "animation_time";
|
case "animation_time";
|
||||||
scan2(values[1], "%", *e.animation_time);
|
scan2(values[1], "%", *e.animation_time);
|
||||||
case "health";
|
|
||||||
scan2(values[1], "%", *e.health);
|
|
||||||
case "jump_press_time";
|
case "jump_press_time";
|
||||||
scan2(values[1], "%", *e.jump_press_time);
|
scan2(values[1], "%", *e.jump_press_time);
|
||||||
case "last_grounded_time";
|
case "last_grounded_time";
|
||||||
@@ -419,19 +314,18 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Character) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// String added via add_build_string() from c:/Personal/games/FPS/modules/Coven/metaprogram.jai:278.
|
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:280.
|
||||||
//
|
//
|
||||||
|
|
||||||
// NUM_ENTITY_TYPES tells the target program how many entity types there are.
|
// NUM_ENTITY_TYPES tells the target program how many entity types there are.
|
||||||
NUM_ENTITY_TYPES :: 4;
|
NUM_ENTITY_TYPES :: 3;
|
||||||
|
|
||||||
// entity_types is an array containing all the entity types.
|
// entity_types is an array containing all the entity types.
|
||||||
entity_types : [4] Type : .[ Block, Character, Item, Pistol ];
|
entity_types : [3] Type : .[ Block, Character, Item ];
|
||||||
|
|
||||||
Entity_Storage :: struct {
|
Entity_Storage :: struct {
|
||||||
_Block: Bucket_Array(Block, 20, true);
|
_Block: Bucket_Array(Block, 20, true);
|
||||||
_Character: Bucket_Array(Character, 20, true);
|
_Character: Bucket_Array(Character, 20, true);
|
||||||
_Item: Bucket_Array(Item, 20, true);
|
_Item: Bucket_Array(Item, 20, true);
|
||||||
_Pistol: Bucket_Array(Pistol, 20, true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,9 +76,11 @@ Entity :: struct {
|
|||||||
collider : Collider; @DontSerialize
|
collider : Collider; @DontSerialize
|
||||||
// End physics
|
// End physics
|
||||||
|
|
||||||
|
#if NETWORKING {
|
||||||
remote_id: Entity_Id; @DontSerialize
|
remote_id: Entity_Id; @DontSerialize
|
||||||
is_proxy: bool; @DontSerialize
|
is_proxy: bool; @DontSerialize
|
||||||
last_replication_time: float; @DontSerialize
|
last_replication_time: float; @DontSerialize
|
||||||
|
}
|
||||||
|
|
||||||
_locator: Bucket_Locator; @DontSerialize
|
_locator: Bucket_Locator; @DontSerialize
|
||||||
scene: *Scene; @DontSerialize
|
scene: *Scene; @DontSerialize
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ register_entity :: (scene: *Scene, entity: *Entity) {
|
|||||||
array_add(*scene.entities, entity);
|
array_add(*scene.entities, entity);
|
||||||
next_entity_id += 1;
|
next_entity_id += 1;
|
||||||
|
|
||||||
|
#if NETWORKING {
|
||||||
if net_data.net_mode == {
|
if net_data.net_mode == {
|
||||||
case .LISTEN_SERVER; #through;
|
case .LISTEN_SERVER; #through;
|
||||||
case .DEDICATED_SERVER; {
|
case .DEDICATED_SERVER; {
|
||||||
@@ -125,10 +126,67 @@ register_entity :: (scene: *Scene, entity: *Entity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unregister_entity :: (scene: *Scene, entity: *Entity) {
|
unregister_entity :: (scene: *Scene, entity: *Entity) {
|
||||||
array_unordered_remove_by_value(*scene.entities, entity);
|
array_unordered_remove_by_value(*scene.entities, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_animators :: (dt: float) {
|
||||||
|
for e: current_scene.entities {
|
||||||
|
if e.flags & .ANIMATED {
|
||||||
|
update_animator(e, *e.animator, dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update_transforms :: () {
|
||||||
|
for e: current_scene.entities {
|
||||||
|
if e.parent == null {
|
||||||
|
update_entity_transform(e, Matrix4_Identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update_entity_node :: (e: *Entity, model_node: Node, index: s64, parent_matrix: Matrix4) {
|
||||||
|
n := *e.renderable.nodes[index];
|
||||||
|
update_matrix(*n.transform);
|
||||||
|
|
||||||
|
n.transform.world_matrix = parent_matrix * n.transform.model_matrix;
|
||||||
|
|
||||||
|
for children_index: 0..model_node.children.count-1 {
|
||||||
|
index := model_node.children[children_index]-1;
|
||||||
|
mn := e.renderable.model.nodes[index];
|
||||||
|
update_entity_node(e, mn, xx index, n.transform.world_matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update_entity_transform :: (e: *Entity, parent_matrix: Matrix4 = Matrix4_Identity) {
|
||||||
|
if e.transform.dirty {
|
||||||
|
update_matrix(*e.transform);
|
||||||
|
e.transform.dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.transform.world_matrix = parent_matrix * e.transform.model_matrix;
|
||||||
|
|
||||||
|
for model_node, i: e.renderable.model.nodes {
|
||||||
|
if model_node.parent == 0 {
|
||||||
|
update_entity_node(e, model_node, i, e.transform.world_matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i: 0..e.num_children-1 {
|
||||||
|
child := e.children[i];
|
||||||
|
|
||||||
|
matrix := e.transform.world_matrix;
|
||||||
|
if child.attach_node_index != -1 {
|
||||||
|
matrix = e.renderable.nodes[child.attach_node_index].transform.world_matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
update_entity_transform(child, matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#scope_file
|
#scope_file
|
||||||
next_entity_id: Entity_Id;
|
next_entity_id: Entity_Id;
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
#import "Basic";
|
#import "Basic";
|
||||||
#import "String";
|
#import "String";
|
||||||
#import "Sort";
|
#import "Sort";
|
||||||
|
#import "File";
|
||||||
|
|
||||||
build_release := false;
|
build_release := false;
|
||||||
|
|
||||||
build :: (main_path: string, game_name: string, working_dir: string = #filepath) {
|
build :: (main_path: string, game_name: string, working_dir: string = #filepath) {
|
||||||
set_working_directory(working_dir);
|
set_working_directory(working_dir);
|
||||||
|
make_directory_if_it_does_not_exist("../../bin");
|
||||||
|
|
||||||
w := compiler_create_workspace("Game");
|
w := compiler_create_workspace("Game");
|
||||||
opts := get_build_options(w);
|
opts := get_build_options(w);
|
||||||
@@ -22,9 +24,9 @@ build :: (main_path: string, game_name: string, working_dir: string = #filepath)
|
|||||||
array_add(*new_path, "modules");
|
array_add(*new_path, "modules");
|
||||||
opts.import_path = new_path;
|
opts.import_path = new_path;
|
||||||
|
|
||||||
if build_release {
|
//if build_release {
|
||||||
set_optimization(*opts, .VERY_OPTIMIZED);
|
set_optimization(*opts, .VERY_OPTIMIZED);
|
||||||
}
|
//}
|
||||||
|
|
||||||
compiler_begin_intercept(w);
|
compiler_begin_intercept(w);
|
||||||
|
|
||||||
|
|||||||
77
module.jai
77
module.jai
@@ -1,5 +1,8 @@
|
|||||||
EDITOR :: true;
|
#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false);
|
||||||
|
|
||||||
|
EDITOR :: WITH_EDITOR;
|
||||||
DEBUG :: true;
|
DEBUG :: true;
|
||||||
|
NETWORKING :: WITH_NETWORKING;
|
||||||
|
|
||||||
#if EDITOR {
|
#if EDITOR {
|
||||||
//#load "../editor/scene_editor.jai";
|
//#load "../editor/scene_editor.jai";
|
||||||
@@ -21,6 +24,7 @@ input : Input_State;
|
|||||||
current_scene: *Scene;
|
current_scene: *Scene;
|
||||||
|
|
||||||
camera_buffer : Buffer_Handle;
|
camera_buffer : Buffer_Handle;
|
||||||
|
time_buffer : Buffer_Handle;
|
||||||
screen_data_buffer : Buffer_Handle;
|
screen_data_buffer : Buffer_Handle;
|
||||||
directional_light_buffer : Buffer_Handle;
|
directional_light_buffer : Buffer_Handle;
|
||||||
|
|
||||||
@@ -29,6 +33,17 @@ dt: float;
|
|||||||
quit: bool;
|
quit: bool;
|
||||||
frame_index : u64 = 0;
|
frame_index : u64 = 0;
|
||||||
|
|
||||||
|
Camera_Data :: struct {
|
||||||
|
projection_matrix: Matrix4;
|
||||||
|
view_matrix: Matrix4;
|
||||||
|
position: Vector4;
|
||||||
|
}
|
||||||
|
|
||||||
|
Shader_Time :: struct {
|
||||||
|
time: float;
|
||||||
|
padding: Vector3;
|
||||||
|
}
|
||||||
|
|
||||||
coven_init :: (window_title: string, window_width: u32, window_height: u32, fullscreen: bool) {
|
coven_init :: (window_title: string, window_width: u32, window_height: u32, fullscreen: bool) {
|
||||||
window = create_window(window_title, window_width, window_height, fullscreen);
|
window = create_window(window_title, window_width, window_height, fullscreen);
|
||||||
renderer = create_renderer(window);
|
renderer = create_renderer(window);
|
||||||
@@ -41,7 +56,7 @@ coven_init :: (window_title: string, window_width: u32, window_height: u32, full
|
|||||||
ui_init();
|
ui_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
coven_run :: (game_update_proc: (float)) {
|
coven_run :: (game_update_proc: (float), game_update_post_physics_proc: (float)) {
|
||||||
time = xx seconds_since_init();
|
time = xx seconds_since_init();
|
||||||
|
|
||||||
while !quit {
|
while !quit {
|
||||||
@@ -51,7 +66,6 @@ coven_run :: (game_update_proc: (float)) {
|
|||||||
|
|
||||||
update_input();
|
update_input();
|
||||||
|
|
||||||
|
|
||||||
// @Incomplete
|
// @Incomplete
|
||||||
if key_pressed(.SHIFT) && key_down(.ESCAPE) {
|
if key_pressed(.SHIFT) && key_down(.ESCAPE) {
|
||||||
quit = true;
|
quit = true;
|
||||||
@@ -69,6 +83,15 @@ coven_run :: (game_update_proc: (float)) {
|
|||||||
|
|
||||||
game_update_proc(min(0.4, dt));
|
game_update_proc(min(0.4, dt));
|
||||||
|
|
||||||
|
update_animators(dt);
|
||||||
|
|
||||||
|
update_physics(current_scene, dt);
|
||||||
|
update_transforms();
|
||||||
|
game_update_post_physics_proc(dt);
|
||||||
|
sync_engine_buffers();
|
||||||
|
|
||||||
|
update_particle_systems(dt);
|
||||||
|
|
||||||
ui_end();
|
ui_end();
|
||||||
|
|
||||||
update_audio(dt);
|
update_audio(dt);
|
||||||
@@ -81,8 +104,54 @@ coven_run :: (game_update_proc: (float)) {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#load "input/input.jai";
|
sync_engine_buffers :: () {
|
||||||
|
// Camera buffer
|
||||||
|
camera := *current_scene.camera;
|
||||||
|
|
||||||
|
camera_data : Camera_Data;
|
||||||
|
camera_data.projection_matrix = camera.projection_matrix;
|
||||||
|
camera_data.view_matrix = camera.view_matrix;
|
||||||
|
camera_data.position = to_v4(camera.position);
|
||||||
|
upload_data_to_buffer(renderer, camera_buffer, *camera_data, size_of(Camera_Data));
|
||||||
|
|
||||||
|
shader_time : Shader_Time;
|
||||||
|
shader_time.time = time;
|
||||||
|
upload_data_to_buffer(renderer, time_buffer, *shader_time, size_of(Shader_Time));
|
||||||
|
|
||||||
|
// Sync entity transforms
|
||||||
|
for current_scene.entities {
|
||||||
|
if it.flags & .RENDERABLE {
|
||||||
|
if it.renderable.type == {
|
||||||
|
case .MODEL; {
|
||||||
|
for n, i: it.renderable.model.nodes {
|
||||||
|
if n.meshes.count > 0 {
|
||||||
|
node_data := *it.renderable.nodes[i];
|
||||||
|
upload_data_to_buffer(renderer, node_data.transform_buffer, *node_data.transform.world_matrix, size_of(Matrix4));
|
||||||
|
|
||||||
|
if node_data.num_bones > 0 {
|
||||||
|
for handle, mesh_index: n.meshes {
|
||||||
|
m := parray_get(*renderer.meshes, handle);
|
||||||
|
bones : [MAX_BONES] Matrix4;
|
||||||
|
for bone_index: 0..m.num_bones-1 {
|
||||||
|
bone := *it.renderable.nodes[m.bone_indices[bone_index]];
|
||||||
|
bones[bone_index] = bone.transform.world_matrix * m.bone_matrices[bone_index];
|
||||||
|
}
|
||||||
|
upload_data_to_buffer(renderer, node_data.bone_buffers[mesh_index], bones.data, size_of(Matrix4) * m.num_bones);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if NETWORKING {
|
||||||
#load "networking/networking.jai";
|
#load "networking/networking.jai";
|
||||||
|
}
|
||||||
|
|
||||||
|
#load "input/input.jai";
|
||||||
#load "renderer/renderer.jai";
|
#load "renderer/renderer.jai";
|
||||||
#load "windowing/window.jai";
|
#load "windowing/window.jai";
|
||||||
#load "physics/physics.jai";
|
#load "physics/physics.jai";
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ update_gravity :: (scene: *Scene, dt: float) {
|
|||||||
if !e.enabled continue;
|
if !e.enabled continue;
|
||||||
|
|
||||||
if e.flags & .PHYSICS {
|
if e.flags & .PHYSICS {
|
||||||
if e.is_proxy continue;
|
#if NETWORKING { if e.is_proxy continue; }
|
||||||
|
|
||||||
if e.collider.ignore continue;
|
if e.collider.ignore continue;
|
||||||
e.body.velocity.y += GRAVITY * dt;
|
e.body.velocity.y += GRAVITY * dt;
|
||||||
}
|
}
|
||||||
@@ -126,7 +127,9 @@ update_gravity :: (scene: *Scene, dt: float) {
|
|||||||
update_positions :: (scene: *Scene, dt: float) {
|
update_positions :: (scene: *Scene, dt: float) {
|
||||||
for e: scene.entities {
|
for e: scene.entities {
|
||||||
if !e.enabled continue;
|
if !e.enabled continue;
|
||||||
if e.is_proxy continue;
|
|
||||||
|
#if NETWORKING { if e.is_proxy continue; }
|
||||||
|
|
||||||
if e.collider.ignore continue;
|
if e.collider.ignore continue;
|
||||||
|
|
||||||
if e.flags & .PHYSICS {
|
if e.flags & .PHYSICS {
|
||||||
@@ -169,7 +172,7 @@ physics_step :: (scene: *Scene, timestep: float) {
|
|||||||
|
|
||||||
for e: scene.entities {
|
for e: scene.entities {
|
||||||
if !e.enabled continue;
|
if !e.enabled continue;
|
||||||
if e.is_proxy continue;
|
#if NETWORKING { if e.is_proxy continue;}
|
||||||
if e.collider.ignore continue;
|
if e.collider.ignore continue;
|
||||||
|
|
||||||
if e.flags & .PHYSICS {
|
if e.flags & .PHYSICS {
|
||||||
|
|||||||
Reference in New Issue
Block a user