Skip to content

Commit

Permalink
Console demo start
Browse files Browse the repository at this point in the history
  • Loading branch information
goudreinette committed Feb 29, 2024
1 parent 196a9e6 commit ddbf4fc
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ARM9"
],
"cStandard": "c11",
"cppStandard": "c++11",
"cppStandard": "c++17",
"compilerPath": "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc",
"configurationProvider": "ms-vscode.makefile-tools"
},
Expand All @@ -34,7 +34,7 @@
"ARM9"
],
"cStandard": "c11",
"cppStandard": "c++11",
"cppStandard": "c++17",
"compilerPath": "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc",
"configurationProvider": "ms-vscode.makefile-tools"
},
Expand Down
126 changes: 126 additions & 0 deletions nds_framebuffer_bitmaps/perlin/perlin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "math.h"


static double rawnoise(int n) {
n = (n << 13) ^ n;
return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}

static double noise1d(int x, int octave, int seed) {
return rawnoise(x * 1619 + octave * 3463 + seed * 13397);
}

static double noise2d(int x, int y, int octave, int seed) {
return rawnoise(x * 1619 + y * 31337 + octave * 3463 + seed * 13397);
}

static double noise3d(int x, int y, int z, int octave, int seed) {
return rawnoise(x * 1919 + y * 31337 + z * 7669 + octave * 3463 + seed * 13397);
}

static double interpolate(double a, double b, double x) {
double f = (1 - cos(x * 3.141593)) * 0.5;

return a * (1 - f) + b * f;
}

static double smooth1d(double x, int octave, int seed) {
int intx = (int)x;
double fracx = x - intx;

double v1 = noise1d(intx, octave, seed);
double v2 = noise1d(intx + 1, octave, seed);

return interpolate(v1, v2, fracx);
}

static double smooth2d(double x, double y, int octave, int seed) {
int intx = (int)x;
double fracx = x - intx;
int inty = (int)y;
double fracy = y - inty;

double v1 = noise2d(intx, inty, octave, seed);
double v2 = noise2d(intx + 1, inty, octave, seed);
double v3 = noise2d(intx, inty + 1, octave, seed);
double v4 = noise2d(intx + 1, inty + 1, octave, seed);

double i1 = interpolate(v1, v2, fracx);
double i2 = interpolate(v3, v4, fracx);

return interpolate(i1, i2, fracy);
}

static double smooth3d(double x, double y, double z, int octave, int seed) {
int intx = (int)x;
double fracx = x - intx;
int inty = (int)y;
double fracy = y - inty;
int intz = (int)z;
double fracz = z - intz;


double v1 = noise3d(intx, inty, intz, octave, seed);
double v2 = noise3d(intx + 1, inty, intz, octave, seed);
double v3 = noise3d(intx, inty + 1, intz, octave, seed);
double v4 = noise3d(intx + 1, inty + 1, intz, octave, seed);
double v5 = noise3d(intx, inty, intz + 1, octave, seed);
double v6 = noise3d(intx + 1, inty, intz + 1, octave, seed);
double v7 = noise3d(intx, inty + 1, intz + 1, octave, seed);
double v8 = noise3d(intx + 1, inty + 1, intz + 1, octave, seed);

double i1 = interpolate(v1, v2, fracx);
double i2 = interpolate(v3, v4, fracx);
double i3 = interpolate(v5, v6, fracx);
double i4 = interpolate(v7, v8, fracx);

double j1 = interpolate(i1, i2, fracy);
double j2 = interpolate(i3, i4, fracy);

return interpolate(j1, j2, fracz);
}

static double pnoise1d(double x, double persistence, int octaves, int seed) {
double total = 0.0;
double frequency = 1.0;
double amplitude = 1.0;
int i = 0;

for(i = 0; i < octaves; i++) {
total += smooth1d(x * frequency, i, seed) * amplitude;
frequency /= 2;
amplitude *= persistence;
}

return total;
}

static double pnoise2d(double x, double y, double persistence, int octaves, int seed) {
double total = 0.0;
double frequency = 1.0;
double amplitude = 1.0;
int i = 0;

for(i = 0; i < octaves; i++) {
total += smooth2d(x * frequency, y * frequency, i, seed) * amplitude;
frequency /= 2;
amplitude *= persistence;
}

return total;
}

static double pnoise3d(double x, double y, double z, double persistence, int octaves, int seed) {
double total = 0.0;
double frequency = 1.0;
double amplitude = 1.0;
int i = 0;

for(i = 0; i < octaves; i++) {
total += smooth3d(x * frequency, y * frequency, z * frequency, i, seed) * amplitude;
frequency /= 2;
amplitude *= persistence;
}

return total;
}
8 changes: 7 additions & 1 deletion nds_framebuffer_bitmaps/source/1_color.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <nds.h>
#include "screen_utils.h"
#include "scene.h"
#include "math.h"
#include "../../effolkronium/random.hpp"



class FirstSketch : public Scene
{
int t = 0;
Expand Down Expand Up @@ -86,15 +88,19 @@ class FirstSketch : public Scene
ball.col = 0;
ball.cdel *= -1;
}


}


void draw() {

// slightly erase everything
int countOfPalette = std::size(palette);

for (int i=0; i<100; i++) {
int randomPixel = Random::get(0, SCREENHEIGHT*SCREENWIDTH);
int randomColor = Random::get(0, 9);
int randomColor = Random::get(0, countOfPalette);
VRAM_A[randomPixel] = palette[randomColor];
// VRAM_A[randomPixel] = COLOR(0,0,0);
// VRAM_A[randomPixel] = i % 2 == 0 ? COLOR(0,0,0) : COLOR(31,31,31)
Expand Down
62 changes: 62 additions & 0 deletions nds_framebuffer_bitmaps/source/5_perlin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <nds.h>
#include <nf_lib.h>
#include <filesystem.h>
#include "screen_utils.h"
#include "scene.h"
#include "../../effolkronium/random.hpp"
#include "../perlin/perlin.cpp"





class PerlinScene : public Scene
{
int t = 0;

using Random = effolkronium::random_static;


public:
void setup() {

// Set the main diplay to frame buffer mode 0 (FB0).
// In FB0 VRAM A is drawn to the screen.
// REG_DISPCNT_MAIN = MODE_FB0;
// // Enable VRAM A
// VRAM_A_CR = VRAM_ENABLE;

// Initialize 2D engine in both screens and use mode 0
// NF_Set2D(0, 5);
// NF_Set2D(1, 5);

// // Initialize NitroFS and set it as the root folder of the filesystem
// nitroFSInit(NULL);
// NF_SetRootFolder("NITROFS");

// initBGSys();

// NF_Load16bitsBg("clear", 1);
// NF_Load16bitsImage("circlesmall", CIRCLE_IMG, 16, 16);
}


void update() {

}


void draw() {
t++;

for (int i=0; i<100; i++) {
int x = Random::get(0, SCREENWIDTH);
int y = Random::get(0, SCREENHEIGHT);

int randomPixel = Random::get(0, SCREENHEIGHT*SCREENWIDTH);
int color = noise3d(x, y, t, 1, 1) * 31;
// VRAM_A[randomPixel] = RGB15(50, 50, 50);
VRAM_A[randomPixel] = noise3d(x, y, t, 1, 1) * 31;
}
}
};
45 changes: 45 additions & 0 deletions nds_framebuffer_bitmaps/source/6_chars.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <nds.h>
#include <stdio.h>

#include "scene.h"
#include "../../effolkronium/random.hpp"





class CharsScene : public Scene
{
int t = 0;

using Random = effolkronium::random_static;


public:
void setup() {
consoleDemoInit();

// PrintConsole* console = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 8, 0, true, true);
// consoleSelect(console);
// consoleInit(NULL, 3, BgType_Text4bpp, BgSize_T_256x256, 8, 0, true, true);
}


void update() {

}


void draw() {
t++;

if (t % 10000 == 0) {
printf("PARRALLEL PROBLEMSPARRALLEL PROB");
}

if (t % 300000 == 1000) {
consoleClear();
}

}
};
26 changes: 20 additions & 6 deletions nds_framebuffer_bitmaps/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,52 @@
#include "2_bw.cpp"
#include "3_with_sprites.cpp"
#include "4_pico_palette.cpp"

#include "5_perlin.cpp"
#include "6_chars.cpp"

FirstSketch first_sketch;
SecondSketch second_sketch;
WithSprites with_sprites;
PicoPalette pico_palette;

PerlinScene perlin_scene;
CharsScene chars_scene;

Scene* scenes[] = {
&first_sketch,
&second_sketch,
&with_sprites,
&pico_palette
&pico_palette,
&perlin_scene,
&chars_scene
};

int currentSceneIndex = 3;
int currentSceneIndex = 5;
int numScenes = 6;


void setupBottomScreen() {

}


int main(void) {
// Top screen
Scene* currentScene = scenes[currentSceneIndex];
currentScene->setup();

// Bottom screen
setupBottomScreen();

// main loop
while(1) {
scanKeys();
int keys = keysDown();
if (keys & KEY_UP) {
currentSceneIndex = (currentSceneIndex + 1) % 4;
currentSceneIndex = (currentSceneIndex + 1) % numScenes;
currentScene = scenes[currentSceneIndex];
currentScene->setup();
} else if (keys & KEY_DOWN) {
currentSceneIndex = (currentSceneIndex - 1 + 4) % 4;
currentSceneIndex = (currentSceneIndex - 1 + numScenes) % numScenes;
currentScene = scenes[currentSceneIndex];
currentScene->setup();
}
Expand Down
Loading

0 comments on commit ddbf4fc

Please sign in to comment.