Skip to content

Commit

Permalink
Code refactoring part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Podgajny committed Oct 30, 2022
1 parent 206da3f commit 2a4fc68
Show file tree
Hide file tree
Showing 52 changed files with 443 additions and 414 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.raycaster.Model.Raycasting;

import com.example.raycaster.Model.RaycasterPoint;

public final class Initializing {


static int startcycles = 0;

public static void initizer(){

int posPix = 0;
if(startcycles<255) {
int level = 200;

for (int y = 0; y < 399; y++) {
for (int x = 0; x < 639; x++) {


RenderProcedure.setPixel(posPix, RenderProcedure.shadowPixel(RenderProcedure.getPixel(posPix),level));

posPix+=RenderProcedure.pixelWidth;
}
posPix+=RenderProcedure.pixelWidth;
}

RenderProcedure.angle +=0.1;
if(RenderProcedure.angle>5){
RenderProcedure.angle = 0;
}
startcycles +=5;
RenderProcedure.pos = new RaycasterPoint(61.5f,64.5f);
}else{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.raycaster.Model.Raycasting;

import com.example.raycaster.Model.Game.Moving;
import com.example.raycaster.View.Render;

public final class Quality {


public static final int SCREEN_STEP_STAND =5;
public static final int SCREEN_STEP_WALK = 6;
public final static byte textureResolution = 64;

public static int SCREEN_STEP;
public static int D_SCREEN_STEP;
public final static float raycasterStep = 0.032f;
public final static float lineHeightStep = (float) RenderProcedure.canvasHeight/(float) RenderProcedure.distance * raycasterStep;
public final static float deltaRaycasterStep = raycasterStep * textureResolution;

public static float deltaFi;

public static void adaptationQuality(){
if(Moving.walking()){
SCREEN_STEP =SCREEN_STEP_WALK;
}else{
SCREEN_STEP =SCREEN_STEP_STAND;
}
D_SCREEN_STEP = SCREEN_STEP << 1;
RenderProcedure.realWidth = RenderProcedure.SCREEN_WIDTH << Render.shiftPixelWidth;

deltaFi = RenderProcedure.pi/((float) 1920/(float) SCREEN_STEP);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse;

public class Hit {

protected Hit(){

}

public static void analyse(){

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities;
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.RenderSteps;

import com.example.raycaster.View.Raycasting.Blocks.Blocks;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Uppers.UpperBlocks;
Expand All @@ -18,19 +18,6 @@ public final class InPoint {
public static boolean inPlayerArea(){
return (int)PointOnRay.posX != (int)RenderProcedure.pos.x || (int)PointOnRay.posY != (int)RenderProcedure.pos.y;
}
private static void analyseUpper(){
Ray.lhalfupx = Ray.halfupx;
Ray.halfupx = Map.halfup[(int)PointOnRay.posX][(int)PointOnRay.posY];

if(Ray.halfupx == 1 && Ray.lhalfupx != 1){
final float height = PreColumn.height;

if(PreColumn.mminh < RenderProcedure.cameraY - ((int)height<<1))
PreColumn.minhh = RenderProcedure.cameraY - ((int)height<<1);
}else if(Ray.ceili == 1 && Ray.lceili != 1){
PreColumn.minhh = 0;
}
}

public static void collectInfoAboutActualBlock(){
Ray.luppershape = false;
Expand All @@ -43,8 +30,9 @@ public static void collectInfoAboutActualBlock(){
Ray.ceili = Map.ceiling[(int) PointOnRay.posX][(int) PointOnRay.posY];



analyseUpper();
Ray.lhalfupx = Ray.halfupx;
Ray.halfupx = Map.halfup[(int)PointOnRay.posX][(int)PointOnRay.posY];
UpperBlocks.analyseUpperBlocking();


Ray.lupperbuildingx = Ray.upperbuildingx;
Expand All @@ -68,7 +56,7 @@ public static void analysePoint(float r){

if(inPlayerArea())
if(Sight.lcountPos != countPos) {
WallHit.analysePotentionalHit();
WallHit.analyse();

collectInfoAboutActualBlock();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities;
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.RenderSteps;

import com.example.raycaster.Model.Raycasting.Quality;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.AngleRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
Expand Down Expand Up @@ -122,7 +123,7 @@ public static void analyseRay(float fi){
initRay();
analyseAreaNearPlayer();

float actRaycastStep = RenderProcedure.raycasterStep;
float actRaycastStep = Quality.raycasterStep;


for (float r = 0; r < 12; r += actRaycastStep) {
Expand Down Expand Up @@ -160,7 +161,7 @@ public static void analyseRay(float fi){

}

Sight.posScreenX += RenderProcedure.SCREEN_STEP;
Sight.posScreenX += Quality.SCREEN_STEP;
Sight.renderwall = !Sight.renderwall;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities;
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.RenderSteps;

import com.example.raycaster.Model.Raycasting.Quality;
import com.example.raycaster.Model.Raycasting.RenderProcedure;

public final class Sight {
Expand Down Expand Up @@ -67,8 +68,8 @@ private static float countTan(){

private static void countRelativePos(){

deltaPosXc = ((RenderProcedure.pos.x-((float) (int)RenderProcedure.pos.x))*(float) RenderProcedure.textureResolution);
deltaPosYc = ((RenderProcedure.pos.y-((float) (int)RenderProcedure.pos.y))*(float) RenderProcedure.textureResolution);
deltaPosXc = ((RenderProcedure.pos.x-((float) (int)RenderProcedure.pos.x))*(float) Quality.textureResolution);
deltaPosYc = ((RenderProcedure.pos.y-((float) (int)RenderProcedure.pos.y))*(float) Quality.textureResolution);

}

Expand Down Expand Up @@ -121,7 +122,7 @@ public static void renderSight(){



for(float fi = RenderProcedure.angle - RenderProcedure.pi/6 ;fi<RenderProcedure.angle+RenderProcedure.pi/6; fi+=RenderProcedure.deltaFi) {
for(float fi = RenderProcedure.angle - RenderProcedure.pi/6 ;fi<RenderProcedure.angle+RenderProcedure.pi/6; fi+=Quality.deltaFi) {
Ray.analyseRay(fi);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse;

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeType.Types.Column;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;

public final class ShapeHit {
public final class ShapeHit extends Hit{

public static boolean inX1;
public static boolean inX2;
Expand All @@ -18,17 +19,7 @@ private ShapeHit(){
}

public static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > min && PointOnRay.intdeltaPosX < max;
boolean inY = PointOnRay.intdeltaPosY > min && PointOnRay.intdeltaPosY < max;

int aintX = PointOnRay.intdeltaPosX - 32;
int aintY = PointOnRay.intdeltaPosY - 32;

int fun = aintX * aintX + aintY * aintY;

boolean inZ = fun < 256;

return inX && inY && inZ;
return Column.isInShape();
}

public static void analyse(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeType;

public class ShapeType {

public static final int typeIndex = 0;

private final static int min = 16;
private final static int max = 48;

protected ShapeType(){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeType.Types;

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeType.ShapeType;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;

public final class Column extends ShapeType {

private final static int min = 16;
private final static int max = 48;

public static final int typeIndex = 11;
private Column(){

}

public static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > min && PointOnRay.intdeltaPosX < max;
boolean inY = PointOnRay.intdeltaPosY > min && PointOnRay.intdeltaPosY < max;

int aintX = PointOnRay.intdeltaPosX - 32;
int aintY = PointOnRay.intdeltaPosY - 32;

int fun = aintX * aintX + aintY * aintY;

boolean inZ = fun < 256;

return inX && inY && inZ;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Uppers;

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.RenderSteps.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.BufferUpperColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.RenderProcedure;
import com.example.raycaster.View.Raycasting.UpperBlocks.Full.UpperBlock;
import com.example.raycaster.View.Raycasting.UpperBlocks.Other.UpperBuildingBlocks;
import com.example.raycaster.View.Raycasting.UpperBlocks.Other.UpperHalfBlock;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
import com.example.raycaster.Model.Raycasting.RenderProcedure;

public final class UpperBlocks {

private UpperBlocks(){

}

public static void analyseUpperBlocking(){

if(Ray.halfupx == 1 && Ray.lhalfupx != 1){
final float height = PreColumn.height;

if(PreColumn.mminh < RenderProcedure.cameraY - ((int)height<<1))
PreColumn.minhh = RenderProcedure.cameraY - ((int)height<<1);
}else if(Ray.ceili == 1 && Ray.lceili != 1){
PreColumn.minhh = 0;
}
}


public static void renderUpperBlocks(){
if((Ray.ceili == 1 && Ray.lceili != 1) || (Ray.upperbuildingx&& !Ray.lupperbuildingx)){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;

public final class WallHit {
public final class WallHit extends Hit{

public static boolean pX;
public static boolean pY;
Expand All @@ -14,7 +14,7 @@ public final class WallHit {
private WallHit(){

}
public static void analysePotentionalHit(){
public static void analyse(){
pX = (PointOnRay.lposX == (int) PointOnRay.posX);
pY = (PointOnRay.lposY == (int) PointOnRay.posY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.raycaster.Model.Raycasting.Raycasting.MatrixBuffers;

public class InfoBuffer {

protected final static int neighbourhoodAreaSize = 32 << 5;
protected final static int bufferListSize = 16;

protected InfoBuffer(){

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.raycaster.Model.Raycasting.Raycasting.MatrixBuffers;

public final class RenderInfoBuffer extends InfoBuffer{



public static int[] lfloord =new int[neighbourhoodAreaSize];
public static int[] lupperd =new int[neighbourhoodAreaSize];
public static float[] lheightsh = new float[neighbourhoodAreaSize];
public static int[] lcolumnd =new int[neighbourhoodAreaSize];
public static int[] lcolumnh =new int[neighbourhoodAreaSize];


private RenderInfoBuffer(){

}

public static void clearBuffers(){


SpriteInfoBuffer.clearBuffers();
UpperInfoBuffer.clearBuffers();

lheightsh= new float[neighbourhoodAreaSize];
lcolumnd= new int[neighbourhoodAreaSize];
lcolumnh= new int[neighbourhoodAreaSize];
lfloord= new int[neighbourhoodAreaSize];
lupperd= new int[neighbourhoodAreaSize];

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.raycaster.Model.Raycasting.Raycasting.MatrixBuffers;

import com.example.raycaster.Model.Raycasting.RenderProcedure;

public final class SpriteInfoBuffer extends InfoBuffer{

public static float[] mapsprite = new float[neighbourhoodAreaSize];
public static byte[] mapsprite2 = new byte[neighbourhoodAreaSize];
public static boolean[] mapspritechange = new boolean[neighbourhoodAreaSize];
public static int[] reservedSpritePixels = new int[RenderProcedure.canvasHeight<<6];

public static void clearBuffers(){

mapsprite = new float[neighbourhoodAreaSize];
mapsprite2 = new byte[neighbourhoodAreaSize];
mapspritechange= new boolean[neighbourhoodAreaSize];
}
}
Loading

0 comments on commit 2a4fc68

Please sign in to comment.