Added files

This commit is contained in:
Emotion 2023-10-02 23:41:01 +13:00
parent b4120f66fb
commit 91edf15ac5
No known key found for this signature in database
GPG key ID: D7D3E4C27A98C37B
23 changed files with 511 additions and 0 deletions

3
assets/scripts/dummy.gr Normal file
View file

@ -0,0 +1,3 @@
event main() {
}

25
assets/shaders/veil100.fs Normal file
View file

@ -0,0 +1,25 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// NOTE: Add here your custom variables
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
// Convert texel color to grayscale using NTSC conversion weights
float gray = 1.0-dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
// Calculate final fragment color
gl_FragColor = vec4(gray, gray, gray, texelColor.a);
}

23
assets/shaders/veil120.fs Normal file
View file

@ -0,0 +1,23 @@
#version 120
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// NOTE: Add here your custom variables
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
// Convert texel color to grayscale using NTSC conversion weights
float gray = 1.0-dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
// Calculate final fragment color
gl_FragColor = vec4(gray, gray, gray, texelColor.a);
}

26
assets/shaders/veil330.fs Normal file
View file

@ -0,0 +1,26 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor;
// Convert texel color to grayscale using NTSC conversion weights
float gray = 1.0-dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
// Calculate final fragment color
finalColor = vec4(gray, gray, gray, texelColor.a);
}

78
dub.json Normal file
View file

@ -0,0 +1,78 @@
{
"authors": [
"$$$$$$"
],
"buildTypes": {
"debug": {
"buildOptions": [
"debugMode",
"debugInfo"
]
},
"release": {
"buildOptions": [
"releaseMode",
"inline",
"noBoundsCheck",
"optimize"
]
},
"unittest": {
"buildOptions": [
"debugMode",
"debugInfo",
"unittests"
]
}
},
"configurations": [
{
"name": "linux-build",
"platforms": [
"linux"
],
"postBuildCommands": [
"cp ./lib$ARCH/*.dll ../bin"
],
"targetPath": "./bin",
"targetType": "executable"
},
{
"name": "windows-build",
"platforms": [
"windows"
],
"libs" : ["raylib"],
"targetPath": "./bin$ARCH",
"targetType": "executable"
},
{
"lflags": [
"-subsystem:windows",
"-entry:mainCRTStartup"
],
"libs" : ["raylib"],
"name": "windows-release",
"platforms": [
"windows"
],
"targetPath": "./release$ARCH/pzdv",
"targetType": "executable"
}
],
"copyright": "Copyright © 2023, $$$$$$",
"dependencies": {
"grimoire": {
"repository": "git+https://github.com/Enalye/grimoire",
"version": "c4b541f"
},
"raylib-d": "~>4.5.1",
"raylib-d:install": "~>4.5.1"
},
"description": "",
"license": "proprietary",
"name": "$$$$$$",
"targetName": "default_target",
"targetType": "executable",
"workingDirectory": "."
}

10
dub.selections.json Normal file
View file

@ -0,0 +1,10 @@
{
"fileVersion": 1,
"versions": {
"grimoire": {"version":"c4b541f","repository":"git+https://github.com/Enalye/grimoire"},
"io": "0.3.4",
"iopipe": "0.2.4",
"jsoniopipe": "0.1.4",
"raylib-d": "4.5.1"
}
}

BIN
raylib.dll Normal file

Binary file not shown.

BIN
raylib.lib Normal file

Binary file not shown.

73
source/game.d Normal file
View file

@ -0,0 +1,73 @@
import std.stdio: writeln;
import std.exception;
import raylib;
import grimoire;
import utils.log;
import std.string : toStringz;
import std.format;
import std.conv : to;
import core.time;
extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ];
int main(string[] args) {
try {
InitWindow(800,600,"Unnamed project");
log(LogLevel.INFOHIGH, "Window Initialized...");
log(LogLevel.INFOHIGH, "Readying the engine...");
GrEngine engine = new GrEngine();
auto grstd = grLoadStdLibrary();
auto grloglib = getLogLibrary();
engine.addLibrary(grstd);
engine.addLibrary(grloglib);
log(LogLevel.INFOHIGH, "Readying the compiler...");
GrCompiler compiler = new GrCompiler();
compiler.addLibrary(grstd);
compiler.addLibrary(grloglib);
compiler.addFile("./assets/scripts/dummy.gr");
log(LogLevel.INFOHIGH, "Compiling Scripts...");
auto bytecode = compiler.compile(GrOption.symbols);
if(! bytecode) {
throw new Exception(compiler.getError().prettify(GrLocale.en_US));
}
log(LogLevel.INFOHIGH, "Booting Scripts...");
engine.load(bytecode);
log(LogLevel.INFOHIGH, "Go Hot Dog, Go...");
engine.process();
auto reference = MonoTime.currTime();
auto deltaTime = 1f/60f;
while(! WindowShouldClose()) {
if(engine.isPanicking()) {
throw new Exception(engine.panicMessage());
}
log(LogLevel.INFOLOW, format("Frame begin %fs...", deltaTime));
log(LogLevel.INFOLOW, "Processing inputs...");
log(LogLevel.INFOLOW, "Processing coros...");
engine.process();
log(LogLevel.INFOLOW, "Processing changes...");
log(LogLevel.INFOLOW, "Render start...");
BeginDrawing();{
ClearBackground(Colors.WHITE);
DrawFPS(0,0);
auto pos = GetMousePosition();
DrawText(toStringz(format("%f, %f", pos.x, pos.y)), 0, 24, 20, Colors.GREEN);
}EndDrawing();
auto new_reference = MonoTime.currTime();
deltaTime = (new_reference - reference).total!("hnsecs")/10_000_000.0;
reference = new_reference;
}
CloseWindow();
return 0;
}
catch(Exception e) {
log(LogLevel.ERROR, e.msg);
foreach (trace; e.info)
log(LogLevel.ERROR, format("at: %s", trace));
}
return 1;
}

236
source/utils/indexedarray.d Normal file
View file

@ -0,0 +1,236 @@
module utils.indexedarray;
/**
IndexedArray
Copyright: (c) Enalye 2017
License: Zlib
Authors: Enalye
Repo: https://github.com/Enalye/atelier
*/
import std.parallelism;
import std.range;
import std.typecons;
/**
Special Array that remove fragmentation while keeping indexes valid.
*/
class IndexedArray(T, uint _capacity, bool _useParallelism = false) {
private uint _dataTop = 0u;
private uint _availableIndexesTop = 0u;
private uint _removeTop = 0u;
private T[_capacity] _dataTable;
private uint[_capacity] _availableIndexes;
private uint[_capacity] _translationTable;
private uint[_capacity] _reverseTranslationTable;
private uint[_capacity] _removeTable;
@property {
uint length() const {
return _dataTop;
}
uint capacity() const {
return _capacity;
}
ref T[_capacity] data() {
return _dataTable;
}
}
uint push(T value) {
uint index;
if ((_dataTop + 1u) == _capacity) {
throw new Exception("IndexedArray overload");
}
if (_availableIndexesTop) {
//Take out the last available index on the list.
_availableIndexesTop--;
index = _availableIndexes[_availableIndexesTop];
}
else {
//Or use a new id.
index = _dataTop;
}
//Add the value to the data stack.
_dataTable[_dataTop] = value;
_translationTable[index] = _dataTop;
_reverseTranslationTable[_dataTop] = index;
++_dataTop;
return index;
}
void pop(uint index) {
uint valueIndex = _translationTable[index];
//Push the index on the available indexes stack.
_availableIndexes[_availableIndexesTop] = index;
_availableIndexesTop++;
//Invalidate the index.
_translationTable[index] = -1;
//Take the top value on the stack and fill the gap.
_dataTop--;
if (valueIndex < _dataTop) {
uint userIndex = _reverseTranslationTable[_dataTop];
_dataTable[valueIndex] = _dataTable[_dataTop];
_translationTable[userIndex] = valueIndex;
_reverseTranslationTable[valueIndex] = userIndex;
}
}
void reset() {
_dataTop = 0u;
_availableIndexesTop = 0u;
_removeTop = 0u;
}
void markInternalForRemoval(uint index) {
synchronized {
_removeTable[_removeTop] = _reverseTranslationTable[index];
_removeTop++;
}
}
void markForRemoval(uint index) {
_removeTable[_removeTop] = index;
_removeTop++;
}
void sweepMarkedData() {
for (uint i = 0u; i < _removeTop; i++) {
pop(_removeTable[i]);
}
_removeTop = 0u;
}
static if (_useParallelism) {
int opApply(int delegate(ref T) dlg) {
int result;
foreach (i; parallel(iota(_dataTop))) {
result = dlg(_dataTable[i]);
if (result)
break;
}
return result;
}
}
else {
int opApply(int delegate(ref T) dlg) {
int result;
foreach (i; 0u .. _dataTop) {
result = dlg(_dataTable[i]);
if (result)
break;
}
return result;
}
}
int opApply(int delegate(const ref T) dlg) const {
int result;
foreach (i; 0u .. _dataTop) {
result = dlg(_dataTable[i]);
if (result)
break;
}
return result;
}
static if (_useParallelism) {
int opApply(int delegate(ref T, uint) dlg) {
int result;
foreach (i; parallel(iota(_dataTop))) {
result = dlg(_dataTable[i], i);
if (result)
break;
}
return result;
}
}
else {
int opApply(int delegate(ref T, uint) dlg) {
int result;
foreach (i; 0u .. _dataTop) {
result = dlg(_dataTable[i], i);
if (result)
break;
}
return result;
}
}
int opApply(int delegate(const ref T, uint) dlg) const {
int result;
foreach (i; 0u .. _dataTop) {
result = dlg(_dataTable[i], i);
if (result)
break;
}
return result;
}
int opApply(int delegate(const Tuple!(const uint, const T)) dlg) const {
int result;
foreach (i; 0u .. _dataTop) {
result = dlg(tuple!(const uint, const T)(_reverseTranslationTable[i], _dataTable[i]));
if (result)
break;
}
return result;
}
T opIndex(uint index) {
return _dataTable[_translationTable[index]];
}
bool has(uint index) {
if (index > _dataTop)
return false;
if (_translationTable[index] == -1)
return false;
return true;
}
/// Returns the first element in the list
T first() {
assert(_dataTop > 0);
return _dataTable[0];
}
/// Returns the last element in the list
T last() {
assert(_dataTop > 0);
return _dataTable[_dataTop - 1];
}
}

37
source/utils/log.d Normal file
View file

@ -0,0 +1,37 @@
module utils.log;
import std.stdio;
import std.format;
import std.conv;
import core.time;
import std.typecons;
import grimoire;
enum LogLevel {
INFOLOW, // Reserved for hot loop logging
INFOMED, // Reserved for loop repeated events
INFOHIGH, // Reserved for non loop rare events
DEBUG, // Reserved for sensitive events that may be bugs
WARN, // Reserved for pending bugs
ERROR // Reserved for bugs that may cause a crash in hot loop, should be guarded
}
enum CurrentLogLevel = LogLevel.INFOLOW;
public void log(LogLevel lvl, string data) {
static Nullable!MonoTime start;
if(start.isNull) start = MonoTime.currTime;
if(lvl >= CurrentLogLevel) writeln(format("%7.6f : %s : %s",(MonoTime.currTime - start.get).total!("hnsecs")/10_000_000.0, std.conv.to!string(lvl), data));
}
public void grLog(GrCall call) {
log(call.getEnum!LogLevel(0), "Gr> " ~ call.getString(1));
}
public GrLibrary getLogLibrary() {
auto lib = new GrLibrary();
auto loglvl_t = lib.addEnum("LogLevel", ["INFOLOW", "INFOMED", "INFOHIGH", "DEBUG", "WARN", "ERROR"]);
lib.addFunction(&grLog, "log", [loglvl_t, grString]);
return lib;
}