Skip to content

Commit

Permalink
See desc
Browse files Browse the repository at this point in the history
* calculate shadow for models (intel, tent and players)
* dont open map while in chat
* repeat minimap at map borders
* bump up version
* command input
  • Loading branch information
xtreme8000 committed Jul 14, 2018
1 parent 29681a6 commit 8dc0aaa
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 47 deletions.
19 changes: 3 additions & 16 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,6 @@ void chunk_draw_shadow_volume(float* data, int max) {
glEnd();*/
}

//see this for details: https://github.com/infogulch/pyspades/blob/protocol075/pyspades/vxl_c.cpp#L380
float sunblock(int x, int y, int z) {
int dec = 18;
int i = 127;

while(dec && y<64) {
if((map_get(x,++y,--z)&0xFFFFFFFF)!=0xFFFFFFFF)
i -= dec;
dec -= 2;
}
return (float)i/127.0F;
}

void* chunk_generate(void* data) {
struct chunk_worker* worker = (struct chunk_worker*)data;

Expand Down Expand Up @@ -1358,7 +1345,7 @@ void chunk_generate_naive(struct chunk_worker* worker) {
unsigned char r = (col&0xFF);
unsigned char g = ((col>>8)&0xFF);
unsigned char b = ((col>>16)&0xFF);
float shade = sunblock(x,y,z);
float shade = map_sunblock(x,y,z);
r *= shade;
g *= shade;
b *= shade;
Expand All @@ -1377,7 +1364,7 @@ void chunk_generate_naive(struct chunk_worker* worker) {
CHECK_ALLOCATION_ERROR(worker->color_data)
}
size++;

#ifdef OPENGL_ES
for(int l=0;l<6;l++) {
#else
Expand Down Expand Up @@ -1531,7 +1518,7 @@ void chunk_generate_naive(struct chunk_worker* worker) {
worker->vertex_data[chunk_vertex_index++] = x;
worker->vertex_data[chunk_vertex_index++] = y;
worker->vertex_data[chunk_vertex_index++] = z;

worker->vertex_data[chunk_vertex_index++] = x;
worker->vertex_data[chunk_vertex_index++] = y+1;
worker->vertex_data[chunk_vertex_index++] = z+1;
Expand Down
4 changes: 2 additions & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#define BETTERSPADES_VERSION "v0.1.2"
#define BETTERSPADES_VERSION "v0.1.3"

#define BETTERSPADES_PATCH 2
#define BETTERSPADES_PATCH 3
#define BETTERSPADES_MINOR 1
#define BETTERSPADES_MAJOR 0

Expand Down
26 changes: 13 additions & 13 deletions src/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,6 @@ static void hud_ingame_render(float scalex, float scalef) {
}
}
glColor3f(1.0F,1.0F,1.0F);

if(window_time()-local_player_last_damage_timer<=0.5F || 1) {
float ang = -camera_rot_x-atan2(camera_z-local_player_last_damage_z,camera_x-local_player_last_damage_x);
texture_draw_rotated(&texture_indicator,settings.window_width/2.0F,settings.window_height/2.0F,200,200,ang);
}
}

if(camera_mode==CAMERAMODE_FPS) {
Expand Down Expand Up @@ -594,7 +589,7 @@ static void hud_ingame_render(float scalex, float scalef) {
if(camera_mode!=CAMERAMODE_SELECTION) {
glColor3f(1.0F,1.0F,1.0F);
//large
if(chat_input_mode==CHAT_NO_INPUT && window_key_down(WINDOW_KEY_MAP)) {
if(window_key_down(WINDOW_KEY_MAP)) {
float minimap_x = (settings.window_width-(map_size_x+1)*scalef)/2.0F;
float minimap_y = ((600-map_size_z-1)/2.0F+map_size_z+1)*scalef;

Expand Down Expand Up @@ -677,17 +672,14 @@ static void hud_ingame_render(float scalex, float scalef) {
glColor3f(1.0F,1.0F,1.0F);
} else {
//minimized, top right
float view_x = min(max(camera_x-64.0F,0.0F),map_size_x+1-128.0F);
float view_z = min(max(camera_z-64.0F,0.0F),map_size_z+1-128.0F);
float view_x = camera_x-64.0F;//min(max(camera_x-64.0F,0.0F),map_size_x+1-128.0F);
float view_z = camera_z-64.0F;//min(max(camera_z-64.0F,0.0F),map_size_z+1-128.0F);

glColor3ub(0,0,0);
texture_draw_empty(settings.window_width-144*scalef,586*scalef,130*scalef,130*scalef);
glColor3f(1.0F,1.0F,1.0F);

glEnable(GL_SCISSOR_TEST);
glScissor(settings.window_width-143*scalef,585*scalef-128*scalef,128*scalef,128*scalef);
texture_draw(&texture_minimap,settings.window_width-(143+(int)view_x)*scalef,(585+(int)view_z)*scalef,512*scalef,512*scalef);
glDisable(GL_SCISSOR_TEST);
texture_draw_sector(&texture_minimap,settings.window_width-143*scalef,585*scalef,128*scalef,128*scalef,(camera_x-64.0F)/512.0F,(camera_z-64.0F)/512.0F,0.25F,0.25F);

for(int k=0;k<TRACER_MAX;k++) {
if(tracers[k].used) {
Expand Down Expand Up @@ -753,7 +745,7 @@ static void hud_ingame_render(float scalex, float scalef) {
}

for(int k=0;k<PLAYERS_MAX;k++) {
if(players[k].connected && players[k].alive && (players[k].team==players[local_player_id].team || (camera_mode==CAMERAMODE_SPECTATOR && k==local_player_id))) {
if(players[k].connected && players[k].alive && (players[k].team==players[local_player_id].team || (camera_mode==CAMERAMODE_SPECTATOR && (k==local_player_id || players[k].team!=TEAM_SPECTATOR)))) {
if(k==local_player_id) {
glColor3ub(0,255,255);
} else {
Expand Down Expand Up @@ -1092,6 +1084,12 @@ static void hud_ingame_keyboard(int key, int action, int mods, int internal) {
chat_add(0,0x0000FF,volstr);
}

if(key==WINDOW_KEY_COMMAND) {
chat_input_mode = CHAT_ALL_INPUT;
text_input_first = 1;
strcpy(chat[0][0],"/");
}

if(key==WINDOW_KEY_CHAT) {
chat_input_mode = CHAT_ALL_INPUT;
text_input_first = 1;
Expand Down Expand Up @@ -1553,6 +1551,8 @@ static void hud_serverlist_render(float scalex, float scaley) {
player_count = 0;
for(int k=1;k<server_count;k++) {
JSON_Object* s = json_array_get_object(servers,k-1);
memset(&serverlist[k],0,sizeof(struct serverlist_entry));

serverlist[k].current = (int)json_object_get_number(s,"players_current");
serverlist[k].max = (int)json_object_get_number(s,"players_max");
serverlist[k].ping = (int)json_object_get_number(s,"latency");
Expand Down
42 changes: 27 additions & 15 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void drawScene(float dt) {
chunk_draw_visible();

glShadeModel(GL_FLAT);
kv6_calclight(-1,-1,-1);
matrix_upload();
particle_render();
tracer_render();
Expand All @@ -111,6 +112,9 @@ void drawScene(float dt) {
matrix_translate(gamestate.gamemode.ctf.team_1_intel_location.dropped.x,
63.0F-gamestate.gamemode.ctf.team_1_intel_location.dropped.z+1.0F,
gamestate.gamemode.ctf.team_1_intel_location.dropped.y);
kv6_calclight(gamestate.gamemode.ctf.team_1_intel_location.dropped.x,
63.0F-gamestate.gamemode.ctf.team_1_intel_location.dropped.z+1.0F,
gamestate.gamemode.ctf.team_1_intel_location.dropped.y);
matrix_upload();
kv6_render(&model_intel,TEAM_1);
matrix_pop();
Expand All @@ -120,6 +124,9 @@ void drawScene(float dt) {
matrix_translate(gamestate.gamemode.ctf.team_2_intel_location.dropped.x,
63.0F-gamestate.gamemode.ctf.team_2_intel_location.dropped.z+1.0F,
gamestate.gamemode.ctf.team_2_intel_location.dropped.y);
kv6_calclight(gamestate.gamemode.ctf.team_2_intel_location.dropped.x,
63.0F-gamestate.gamemode.ctf.team_2_intel_location.dropped.z+1.0F,
gamestate.gamemode.ctf.team_2_intel_location.dropped.y);
matrix_upload();
kv6_render(&model_intel,TEAM_2);
matrix_pop();
Expand All @@ -129,6 +136,9 @@ void drawScene(float dt) {
matrix_translate(gamestate.gamemode.ctf.team_1_base.x,
63.0F-gamestate.gamemode.ctf.team_1_base.z+1.0F,
gamestate.gamemode.ctf.team_1_base.y);
kv6_calclight(gamestate.gamemode.ctf.team_1_base.x,
63.0F-gamestate.gamemode.ctf.team_1_base.z+1.0F,
gamestate.gamemode.ctf.team_1_base.y);
matrix_upload();
kv6_render(&model_tent,TEAM_1);
matrix_pop();
Expand All @@ -138,6 +148,9 @@ void drawScene(float dt) {
matrix_translate(gamestate.gamemode.ctf.team_2_base.x,
63.0F-gamestate.gamemode.ctf.team_2_base.z+1.0F,
gamestate.gamemode.ctf.team_2_base.y);
kv6_calclight(gamestate.gamemode.ctf.team_2_base.x,
63.0F-gamestate.gamemode.ctf.team_2_base.z+1.0F,
gamestate.gamemode.ctf.team_2_base.y);
matrix_upload();
kv6_render(&model_tent,TEAM_2);
matrix_pop();
Expand All @@ -149,6 +162,9 @@ void drawScene(float dt) {
matrix_translate(gamestate.gamemode.tc.territory[k].x,
63.0F-gamestate.gamemode.tc.territory[k].z+1.0F,
gamestate.gamemode.tc.territory[k].y);
kv6_calclight(gamestate.gamemode.tc.territory[k].x,
63.0F-gamestate.gamemode.tc.territory[k].z+1.0F,
gamestate.gamemode.tc.territory[k].y);
matrix_upload();
kv6_render(&model_tent,min(gamestate.gamemode.tc.territory[k].team,2));
matrix_pop();
Expand Down Expand Up @@ -196,13 +212,9 @@ void display(float dt) {
matrix_select(matrix_model);
matrix_identity();

float lpos[4] = {0.0F,-1.0F,1.0F,0.0F};
float lambient[4] = {0.5F,0.5F,0.5F,1.0F};
float ldiffuse[4] = {0.5F,0.5F,0.5F,1.0F};
matrix_upload();
float lpos[4] = {0.0F,-1.0F,1.0F,0.0F};
glLightfv(GL_LIGHT0,GL_POSITION,lpos);
glLightfv(GL_LIGHT0,GL_AMBIENT,lambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse);

map_sun[0] = 1.0F;
map_sun[1] = -3.0F;
Expand All @@ -220,9 +232,6 @@ void display(float dt) {

camera_ExtractFrustum();

float fps = 1.0F/dt;
//printf("FPS: %0.2f\n",fps);

if(!network_map_transfer) {

glx_enable_sphericalfog();
Expand Down Expand Up @@ -484,13 +493,16 @@ void text_input(struct window_instance* window, unsigned int codepoint) {

void keys(struct window_instance* window, int key, int scancode, int action, int mods) {
if(action==WINDOW_PRESS) {
if(config_key(key)->toggle)
window_pressed_keys[key] = !window_pressed_keys[key];
else
window_pressed_keys[key] = 1;
}
if(action==WINDOW_RELEASE && !config_key(key)->toggle)
window_pressed_keys[key] = 0;
if(config_key(key)->toggle) {
if(chat_input_mode==CHAT_NO_INPUT) {
window_pressed_keys[key] = !window_pressed_keys[key];
}
} else {
window_pressed_keys[key] = 1;
}
}
if(action==WINDOW_RELEASE && !config_key(key)->toggle)
window_pressed_keys[key] = 0;

#ifdef USE_GLFW
if(key==WINDOW_KEY_FULLSCREEN && action==GLFW_PRESS) { //switch between fullscreen
Expand Down
13 changes: 13 additions & 0 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,19 @@ void map_update_physics(int x, int y, int z) {
map_update_physics_sub(x,y+1,z);
}

//see this for details: https://github.com/infogulch/pyspades/blob/protocol075/pyspades/vxl_c.cpp#L380
float map_sunblock(int x, int y, int z) {
int dec = 18;
int i = 127;

while(dec && y<64) {
if((map_get(x,++y,--z)&0xFFFFFFFF)!=0xFFFFFFFF)
i -= dec;
dec -= 2;
}
return (float)i/127.0F;
}

unsigned long long map_get(int x, int y, int z) {
if(x<0 || y<0 || z<0 || x>=map_size_x || y>=map_size_y || z>=map_size_z)
return 0xFFFFFFFF;
Expand Down
1 change: 1 addition & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int map_object_visible(float* loc);
int map_damage(int x, int y, int z, int damage);
void map_damaged_voxels_render();
void map_update_physics(int x, int y, int z);
float map_sunblock(int x, int y, int z);
unsigned long long map_get(int x, int y, int z);
unsigned long long map_get_unblocked(int x, int y, int z);
void map_set(int x, int y, int z, unsigned long long color);
Expand Down
12 changes: 11 additions & 1 deletion src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ void kv6_rebuild(struct kv6_t* kv6) {
}
}

void kv6_calclight(int x, int y, int z) {
float f = 1.0F;
if(x>=0 && y>=0 && z>=0)
f = map_sunblock(x,y,z);
float lambient[4] = {0.5F*f,0.5F*f,0.5F*f,1.0F};
float ldiffuse[4] = {0.5F*f,0.5F*f,0.5F*f,1.0F};
glLightfv(GL_LIGHT0,GL_AMBIENT,lambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse);
}

static int kv6_program = -1;
void kv6_render(struct kv6_t* kv6, unsigned char team) {
if(!kv6->has_display_list) {
Expand Down Expand Up @@ -532,7 +542,7 @@ void kv6_render(struct kv6_t* kv6, unsigned char team) {
" float d = clamp(dot(N,L),0.0,1.0)*0.5+0.5;\n" \
" gl_FrontColor = mix(vec4(d,d,d,1.0)*gl_Color,vec4(fog,1.0),min(dist/128.0,1.0));\n" \
" gl_PointSize = size/gl_Position.w;\n" \
"}\n");
"}\n",NULL);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern struct kv6_t model_semi_casing;
extern struct kv6_t model_smg_casing;
extern struct kv6_t model_shotgun_casing;

void kv6_calclight(int x, int y, int z);
char kv6_intersection(struct kv6_t* kv6, Ray* r);
void kv6_rebuild_all(void);
void kv6_rebuild(struct kv6_t* kv6);
Expand Down
3 changes: 3 additions & 0 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ static float foot_function(struct Player* p) {
}

int player_render(struct Player* p, int id, Ray* ray, char render) {
if(render)
kv6_calclight(p->pos.x,p->pos.y,p->pos.z);

if(camera_mode==CAMERAMODE_SPECTATOR && p->team!=TEAM_SPECTATOR) {
int old_state = glx_fog;
if(old_state)
Expand Down

0 comments on commit 8dc0aaa

Please sign in to comment.