diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-11 22:00:15 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-11 22:03:54 +0700 |
commit | 521320a29e168396e8812b3acf1cf9d3e287537c (patch) | |
tree | f9a59adc680061bc30623d150c9b86565f96512e | |
parent | f4076dc5d99a4f6d590c27d7089492ff40a7abcd (diff) | |
download | blackshades-2.4.6.tar.gz |
Covert misc Game methods to C 2.4.6
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | src/Game.h | 52 | ||||
-rw-r--r-- | src/GameDraw.cpp | 18 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 9 | ||||
-rw-r--r-- | src/GameTick.cpp | 115 |
5 files changed, 90 insertions, 111 deletions
diff --git a/CHANGES b/CHANGES index d5d9862..7697dc6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +Tag: 2.4.6 +Date: 2021-12-11 + + Fix stuck VIP + + Internally, a transition to C ABI has been started. + Tag: 2.4.5 Date: 2021-11-29 diff --git a/src/Game.h b/src/Game.h index 4835f42..5933e3a 100644 --- a/src/Game.h +++ b/src/Game.h @@ -22,22 +22,22 @@ #ifndef BLACKSHADES_GAME_H #define BLACKSHADES_GAME_H -#include <GLFW/glfw3.h> - -#include "config.h" -#include "misc.h" +#define num_blocks 100 +#define block_spacing 360 +#define max_people 90 +#define max_people_block 20 -#ifdef __cplusplus -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <cstdarg> +#include <stdbool.h> #include <AL/al.h> #include <GL/gl.h> +#include <GLFW/glfw3.h> #include "Quaternions.h" +#include "config.h" +#include "misc.h" + +#ifdef __cplusplus #include "Camera.h" #include "Skeleton.h" #include "Models.h" @@ -48,19 +48,7 @@ #include "Person.h" #include "Decals.h" -#define num_blocks 100 -#define block_spacing 360 -#define max_people 90 -#define max_people_block 20 - -class Game { - void handleMenu(); - void handleToggles(); - void mouseLook(); - XYZ aimPlayer(); - XYZ aimBot(int); - void setListener(XYZ&); -public: +struct Game { // Graphics int screenwidth, screenheight; float viewdistance; @@ -86,7 +74,7 @@ public: int cycle; bool whacked; float losedelay; - XYZ bodycoords; + struct XYZ bodycoords; FRUSTUM frustum; Model blocks[4]; @@ -100,7 +88,7 @@ public: Model Bigstreet; Model path; Model blocksimple; - XYZ boundingpoints[8]; + struct XYZ boundingpoints[8]; Text text; int goodkills; int badkills; @@ -113,12 +101,12 @@ public: bool paused; bool menu; - XYZ aimer[2]; + struct XYZ aimer[2]; double eqn[4]; float oldrot, oldrot2; - XYZ lastshot[2]; + struct XYZ lastshot[2]; bool zoom; int numpeople; @@ -153,19 +141,11 @@ public: int evilprobability; float difficulty; - // GL functions - GLvoid ReSizeGLScene(float fov, float near); - void DrawGLScene(); - - void updateSong(); - // Game functions + void DrawGLScene(); void Tick(); - void Splat(int k); }; #else // __cplusplus -#include <stdbool.h> - typedef struct Game Game; #endif // __cplusplus diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp index 54fddc1..f2d5695 100644 --- a/src/GameDraw.cpp +++ b/src/GameDraw.cpp @@ -19,6 +19,8 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. +#include <stdio.h> + #include "Game.h" #include "misc.h" @@ -39,6 +41,16 @@ extern float sinefluctprog; extern int environment; extern Decals decals; +GLvoid ReSizeGLScene(Game* game, float fov, float near) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(fov, game->screenwidth / (GLfloat) game->screenheight, + near, game->viewdistance); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + void Game::DrawGLScene(void) { //Main menu @@ -571,9 +583,9 @@ void Game::DrawGLScene(void) glEnable(GL_LIGHT0); // Change fov if zooming with scope if (zoom) - ReSizeGLScene(10.0f, 0.6f); + ReSizeGLScene(this, 10.0f, 0.6f); else - ReSizeGLScene(90.0f, 0.1f); + ReSizeGLScene(this, 90.0f, 0.1f); nocolors=0; } else { glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat[]) { 0.0f, 0.0f, 0.0f, 1.0f }); @@ -586,7 +598,7 @@ void Game::DrawGLScene(void) fog.SetFog(fogcolorr,fogcolorg,fogcolorb,0,viewdistance*.8*.5*(sinefluct/4+.3),sinefluct/3+.7); glClearColor(fogcolorr,fogcolorg,fogcolorb,1); - ReSizeGLScene(120-sinefluct*20,.3); + ReSizeGLScene(this, 120.0f - sinefluct * 20.0f, 0.3f); glRotatef(sinefluct*10,0,0,.1); nocolors=1; diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 6d99c4c..83435fb 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -1047,15 +1047,6 @@ void initGl(Game* game) decals.bloodtextureptr[10] = loadTexture("blood/10.png"); } -GLvoid Game::ReSizeGLScene(float fov, float near) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,near,viewdistance); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - struct Scores getScores(Game* game) { return { diff --git a/src/GameTick.cpp b/src/GameTick.cpp index c4fff12..cd206ae 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -46,28 +46,34 @@ extern Decals decals; #define maxfallvel 40 -void Game::Splat(int k) +void Splat(Game* game, int k) { if (k && visions) return; - auto& skeleton = person[k].skeleton; + auto& person = game->person[k]; + if (person.velocity.y > -maxfallvel) { + person.velocity.y = 0; + return; + } + + auto& skeleton = person.skeleton; skeleton.free = 1; skeleton.offset = 0; - person[k].health = 0; - person[k].longdead = person[k].bleeding = person[k].bleeddelay = 1; - person[k].DoAnimations(k); + person.health = 0; + person.longdead = person.bleeding = person.bleeddelay = 1; + person.DoAnimations(k); auto& joints = skeleton.joints; auto& head_joint = joints[head]; - person[k].bjoint1 = &head_joint; - person[k].bjoint2 = joints + neck; + person.bjoint1 = &head_joint; + person.bjoint2 = joints + neck; for (auto& joint : joints) { joint.position = DoRotation(joint.position + joint.offset, 0, - person[k].playerrotation, 0) + person[k].playercoords; + person.playerrotation, 0) + person.playercoords; joint.realoldposition = joint.position; - joint.velocity = {0, person[k].velocity.y, 0}; + joint.velocity = {0, person.velocity.y, 0}; } auto soundpos = head_joint.position - camera.position; @@ -80,28 +86,28 @@ void Game::Splat(int k) alSourcePlay(gSourceID[headwhacksound]); } -void Game::updateSong() +void updateSong(Game* game) { if (environment == rainy_environment) alSourcePlay(gSourceID[rainsound]); else alSourcePause(gSourceID[rainsound]); - alSourceStop(gSourceID[whichsong]); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0); + alSourceStop(gSourceID[game->whichsong]); + alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 0); + alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 0); - if (type == zombie_type) - whichsong = zombiesong; - else if (person[0].whichgun == knife) - whichsong = knifesong; + if (game->type == zombie_type) + game->whichsong = zombiesong; + else if (game->person[0].whichgun == knife) + game->whichsong = knifesong; else - whichsong = shootsong; + game->whichsong = shootsong; - alSourcef(gSourceID[whichsong], AL_PITCH, 1); - alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1); - alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1); - alSourcePlay(gSourceID[whichsong]); + alSourcef(gSourceID[game->whichsong], AL_PITCH, 1); + alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1); + alSourcef(gSourceID[game->whichsong], AL_MAX_GAIN, 1); + alSourcePlay(gSourceID[game->whichsong]); } void click(Game* game, int button, int action, int mods) @@ -131,7 +137,7 @@ void click(Game* game, int button, int action, int mods) switch (game->mouseoverbutton) { case 1: - game->updateSong(); + updateSong(game); game->flashr = game->flashg = game->flashb = 1.0f; game->flashamount = 1.0f; alSourcePlay(gSourceID[soulinsound]); @@ -346,7 +352,7 @@ void look(Game* game, double xpos, double ypos) } } -void Game::setListener(XYZ& facing) +void setListener(Game* game, XYZ facing) { XYZ upvector {0, 0, -1}; upvector = DoRotation(upvector, -camera.rotation2 + 90, 0, 0); @@ -359,13 +365,13 @@ void Game::setListener(XYZ& facing) alListenerfv(AL_ORIENTATION, ori); } -XYZ Game::aimPlayer() +XYZ aimPlayer(Game* game) { - auto& joints = person[0].skeleton.joints; + auto& joints = game->person[0].skeleton.joints; auto point = joints[lefthand].position - joints[righthand].position; float aimrot = 0.0f, aimrot2 = 0.0f; - switch (person[0].whichgun) { + switch (game->person[0].whichgun) { case assaultrifle: aimrot = -2.5f; break; @@ -387,13 +393,14 @@ XYZ Game::aimPlayer() } return DoRotation(point, aimrot2, - person[0].playerrotation + aimrot, 0); + game->person[0].playerrotation + aimrot, 0); } -XYZ Game::aimBot(int j) +XYZ aimBot(Game* game, int j) { + auto& bot = game->person[j]; float inaccuracy = 0.0f; - switch (person[j].whichgun) { + switch (bot.whichgun) { case handgun1: case handgun2: inaccuracy = 8.0f; @@ -406,10 +413,11 @@ XYZ Game::aimBot(int j) inaccuracy = 2.0f; break; } - if (person[person[j].killtarget].skeleton.free) + + auto& target = game->person[bot.killtarget]; + if (target.skeleton.free) inaccuracy *= 3; - auto& target = person[person[j].killtarget]; auto& joints = target.skeleton.joints; XYZ aim = joints[abdomen].position; if (target.skeleton.free) @@ -419,12 +427,12 @@ XYZ Game::aimBot(int j) + target.playercoords; auto& lefthandpos = joints[lefthand].position; - aim -= person[j].playercoords - + DoRotation(lefthandpos, 0, person[j].playerrotation, 0); + aim -= bot.playercoords + + DoRotation(lefthandpos, 0, bot.playerrotation, 0); return DoRotation( - DoRotation(DoRotation(aim, 0, -person[j].playerrotation, 0), + DoRotation(DoRotation(aim, 0, -bot.playerrotation, 0), randFloat() * inaccuracy, randFloat() * inaccuracy, 0), - 0, person[j].playerrotation, 0); + 0, bot.playerrotation, 0); } void Game::Tick() @@ -458,7 +466,7 @@ void Game::Tick() setMenu(this, beatgame = true); gameinprogress = 0; } else { - updateSong(); + updateSong(this); initGame(this); } } @@ -470,7 +478,7 @@ void Game::Tick() flashr = flashg = flashb = 0; alSourcePlay(gSourceID[soulinsound]); - updateSong(); + updateSong(this); initGame(this); } @@ -570,15 +578,9 @@ void Game::Tick() whichtri=sidewalkcollide.LineCheck2(overpoint,underpoint,&collpoint,move,cityrotation[i][j]*90); if(whichtri!=-1&&person[k].playercoords.y<=collpoint.y&&person[k].velocity.y<=0){ - person[k].playercoords.y=collpoint.y; - person[k].onground=1; - - if(person[k].velocity.y<-maxfallvel)Splat(k); - - else person[k].velocity.y=0; - + Splat(this, k); } if(whichtri!=-1){ @@ -638,34 +640,21 @@ void Game::Tick() whichtri=blockroofs[citytype[i][j]].LineCheck2(overpoint,underpoint,&collpoint,move,cityrotation[i][j]*90); if(whichtri!=-1&&person[k].playercoords.y<=collpoint.y&&person[k].velocity.y<=0){ - person[k].playercoords.y=collpoint.y; - person[k].onground=1; - - if(person[k].velocity.y<-maxfallvel)Splat(k); - - else person[k].velocity.y=0; - + Splat(this, k); } if(whichtri!=-1)inblock=1; - } - } - } - } if (person[k].playercoords.y <= 0) { person[k].onground = 1; person[k].playercoords.y = 0; - if (person[k].velocity.y<-maxfallvel) - Splat(k); - else - person[k].velocity.y = 0; + Splat(this, k); if (k == 0) onblockx = onblocky = -1; } @@ -1768,9 +1757,9 @@ void Game::Tick() for (int p = 0; p < numshots; p++) { XYZ aim; if (j) - aim = aimBot(j); + aim = aimBot(this, j); else if (!zoom) - aim = aimPlayer(); + aim = aimPlayer(this); else aim = facing; Normalise(&aim); @@ -2902,7 +2891,7 @@ void Game::Tick() psychicpower+=multiplier*5; if(psychicpower>10)psychicpower=10; - setListener(facing); + setListener(this, facing); if (score < 0) score = 0; } |