Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Podgajny committed Oct 30, 2022
1 parent 534700e commit 206da3f
Show file tree
Hide file tree
Showing 48 changed files with 480 additions and 311 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
tools:targetApi="31">
<activity
android:name=".View.Activities.MainActivity"
android:screenOrientation="portrait"
android:screenOrientation="landscape"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/example/raycaster/Model/Game/Moving.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public final class Moving {
public static float dAngle;

public static Point startMousePos = new Point(0,0);

private Moving(){

}
public static boolean walking(){

float step = 1.75f;
Expand Down Expand Up @@ -43,14 +47,13 @@ public static boolean walking(){

char key = 0;

float nposX = RenderProcedure.pos.x + trnsY * step *sinX;
float nposY = RenderProcedure.pos.y + trnsY * step * cosY;
if(trnsX !=0 || trnsY!=0) {
RaycasterPoint npoint1 = new RaycasterPoint(RenderProcedure.pos.x + trnsX, RenderProcedure.pos.y + trnsY);
RaycasterPoint npoint1 = new RaycasterPoint(nposX, nposY);
if (Map.map[(int) npoint1.x][(int) npoint1.y] == 0 || Map.map[(int) npoint1.x][(int) npoint1.y] == 5) {
RenderProcedure.pos.x += trnsY * step *sinX;
RenderProcedure.pos.y += trnsY * step * cosY;
} else {
RenderProcedure.pos.x -= trnsY * step * sinX;
RenderProcedure.pos.y -= trnsY * step* cosY;
RenderProcedure.pos.x = nposX;
RenderProcedure.pos.y = nposY;
}
return true;
}else{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.raycaster.Model.Game;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
Expand All @@ -15,6 +17,10 @@

public final class StartGame {

private StartGame(){

}

public static void initGame(MainActivity app){


Expand All @@ -25,7 +31,10 @@ public static void initGame(MainActivity app){

app.img = app.findViewById(R.id.imageView);
app.img.setWillNotDraw(true);
app.img.setImageBitmap(Render.screen);

BitmapDrawable draw = new BitmapDrawable(Render.screen);
draw.setFilterBitmap(false);
app.img.setImageDrawable(draw);

app.speedCounter = (TextView) app.findViewById(R.id.textView);

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

import com.example.raycaster.View.Raycasting.Blocks.Blocks;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Uppers.UpperBlocks;
import com.example.raycaster.View.Raycasting.UpperBlocks.UpperShapes;
import com.example.raycaster.View.Raycasting.UpperBlocks.Full.UpperShapes;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.WallHit;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PreColumns.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
import com.example.raycaster.Model.Raycasting.RenderProcedure;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Sprites.Sprites;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Floor;
Expand All @@ -15,6 +15,23 @@ public final class InPoint {

public static int countPos;

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 @@ -25,20 +42,17 @@ public static void collectInfoAboutActualBlock(){
Ray.lceili = Ray.ceili;
Ray.ceili = Map.ceiling[(int) PointOnRay.posX][(int) PointOnRay.posY];

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

if(Ray.lhalfupx == 1){
final float height = PreColumn.height;
PreColumn.maxhh = RenderProcedure.cameraY - (int)height;
}

analyseUpper();


Ray.lupperbuildingx = Ray.upperbuildingx;
Ray.upperbuildingx = Map.upperbuilding[(int) PointOnRay.posX][(int) PointOnRay.posY];



if((int)PointOnRay.posX != (int)RenderProcedure.pos.x || (int)PointOnRay.posY != (int)RenderProcedure.pos.y)
if(inPlayerArea())
UpperBlocks.renderUpperBlocks();

if(Ray.halfupx == 0) Ray.lceiling = Ray.ceili;
Expand All @@ -52,7 +66,7 @@ private static int countLocalPos(){
public static void analysePoint(float r){
countPos = countLocalPos();

if((int)PointOnRay.posX != (int)RenderProcedure.pos.x || (int)PointOnRay.posY != (int)RenderProcedure.pos.y)
if(inPlayerArea())
if(Sight.lcountPos != countPos) {
WallHit.analysePotentionalHit();

Expand All @@ -70,7 +84,6 @@ public static void analysePoint(float r){
PreColumn.countHeight();
}
if(Ray.finish) {

if(!Ray.finalrender) {
if (Ray.ceili == 2)

Expand All @@ -88,6 +101,7 @@ public static void analysePoint(float r){
Blocks.renderBlocks(r);
break;


case 3:
case 4:
case 8:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

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.PreColumns.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
import com.example.raycaster.Model.Raycasting.RenderProcedure;
import com.example.raycaster.Model.Resources.Map.Map;
import com.example.raycaster.View.Raycasting.BasicElements.SpriteBufferRender;
import com.example.raycaster.View.Raycasting.Sprites.SpriteBufferRender;
import com.example.raycaster.View.Raycasting.UpperBlocks.Other.UpperBuildingBlocks;

public final class Ray {

Expand Down Expand Up @@ -49,6 +50,10 @@ public final class Ray {

public static boolean outside;

private Ray(){

}

public static int countPosBuffer(int x, int y){
int count = (y << 3) + (x);
if(count>=6400) count = 0;
Expand All @@ -59,6 +64,11 @@ public static int countPosBuffer(int x, int y){

private static void initRay(){

UpperBuildingBlocks.maxh = 0;

PreColumn.minhh = 400;


halfupx = 0;
lhalfupx = 0;

Expand All @@ -76,6 +86,7 @@ private static void initRay(){

ceili = Map.ceiling[(int) PointOnRay.posX][(int) PointOnRay.posY];


lceiling = Map.ceiling[(int) PointOnRay.posX][(int) PointOnRay.posY];

finalrender = false;
Expand Down Expand Up @@ -104,8 +115,8 @@ private static void analyseAreaNearPlayer(){
}
public static void analyseRay(float fi){

new AngleRay(fi);
new PointOnRay();
AngleRay.setNewAngle(fi);
PointOnRay.resetRay();

PreColumn.start();
initRay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public final class Sight {

public static float halflheight = 0;

private Sight(){

}

private static float countTan(){
float tan = (float) Math.tan(RenderProcedure.angle);
Expand Down Expand Up @@ -118,7 +121,7 @@ public static void renderSight(){



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

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public final class ShapeHit {
private final static int min = 16;
private final static int max = 48;

private ShapeHit(){

}

public static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > min && PointOnRay.intdeltaPosX < max;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
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.PreBaking.Ray.PreColumns.UpperPreColumn;
import com.example.raycaster.View.Raycasting.UpperBlocks.UpperBlock;
import com.example.raycaster.View.Raycasting.UpperBlocks.UpperBuildingBlocks;
import com.example.raycaster.View.Raycasting.UpperBlocks.UpperHalfBlock;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.BufferUpperColumn;
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.PreColumns.PreColumn;
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 renderUpperBlocks(){
if((Ray.ceili == 1 && Ray.lceili != 1) || (Ray.upperbuildingx&& !Ray.lupperbuildingx)){

final float height = PreColumn.fakeHeight / PreColumn.z;
final float lha = PreColumn.getLastUpperHeight(height);
final float lhaa = UpperPreColumn.getLastUpperBuildingHeight(height);
final float lhaa = BufferUpperColumn.getLastUpperBuildingHeight(height);

UpperBuildingBlocks.analyse(height,0,lha,lhaa);


int shadow = 0;

if((int)PointOnRay.posX != (int) RenderProcedure.pos.x || (int)PointOnRay.posY != (int)RenderProcedure.pos.y)
if(Ray.ceili == 1 && Ray.lceiling!=1){
if((int)PointOnRay.posX != (int) RenderProcedure.pos.x || (int)PointOnRay.posY != (int)RenderProcedure.pos.y) {

if (Ray.halfupx==0) {
UpperBlock.analyse(height,shadow,lha,lhaa);
}else{
UpperHalfBlock.analyse(height,shadow,lha,lhaa);
}

if(!Ray.halfupper){
PreColumn.minhh = RenderProcedure.cameraY - (int)(2*height);
UpperBuildingBlocks.analyse(height,0,lha,lhaa);

if (Ray.ceili == 1 && Ray.lceiling != 1) {

if (Ray.halfupx == 0) {
UpperBlock.analyse(height, shadow, lha, lhaa);
} else {
UpperHalfBlock.analyse(height, shadow, lha, lhaa);
}

if (!Ray.halfupper) {
Ray.halfupper = true;
}

}

}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public final class WallHit {
public static boolean pY2;
public static boolean pX1;

private WallHit(){

}
public static void analysePotentionalHit(){
pX = (PointOnRay.lposX == (int) PointOnRay.posX);
pY = (PointOnRay.lposY == (int) PointOnRay.posY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.example.raycaster.Model.Raycasting.Raycasting.PreBaking;

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.InPoint;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Sight;
import com.example.raycaster.Model.Resources.Map.Map;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PreColumns.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.Buffers.PreColumn;
import com.example.raycaster.Model.Raycasting.RenderProcedure;
import com.example.raycaster.Model.Raycasting.Raycasting.Textures.TextureContainer;
import com.example.raycaster.View.Raycasting.BasicElements.FloorPixel;
import com.example.raycaster.View.Raycasting.BasicElements.FloorRender;

public final class Floor {

static float heightBuffer = 0;
public static int hei;

private Floor(){

}

private static int getHei(float r){
int hei = (int)(PreColumn.lheightpos - PreColumn.height);
Expand All @@ -37,7 +38,7 @@ public static void renderFloor(int posX, int posY, boolean renderFloor, int posS

if (posScreenX != 0 && renderFloor) {

int hei = getHei(r);
hei = getHei(r);
if(hei != 0) {
final float heightx = PreColumn.height;

Expand All @@ -54,6 +55,7 @@ public static void renderFloor(int posX, int posY, boolean renderFloor, int posS
int posfinish = (int) (RenderProcedure.cameraY + heightx);



if (!oneheight) {
if (ceil != 0 && !(ceil == 2 && Ray.luppershapeR)) {

Expand All @@ -67,12 +69,14 @@ public static void renderFloor(int posX, int posY, boolean renderFloor, int posS
}

if (ceil == 1) {
if (!halfupx || !Ray.outside) {

if(PreColumn.maxh < posstart)
PreColumn.maxh = posstart;
}

}



}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public final class Functions {
final static float[] tan = new float[length];

final static int[] sqrt = new int[32*32*1000];

private Functions(){

}

public static void precount(float deltaRaycasterStep, float raycasterStep) {
for (double fi = -6.283; fi < 6.283; fi+=0.001) {
int n=getValue(fi);
Expand Down
Loading

0 comments on commit 206da3f

Please sign in to comment.