Only load shader memory location once

This commit is contained in:
Evan Pratten 2021-04-25 18:22:55 -04:00
parent dbc620aa03
commit 5497d8e279
3 changed files with 29 additions and 15 deletions

View File

@ -19,12 +19,17 @@ pub enum InGameState {
pub struct InGameScreen {
current_state: InGameState,
shader_time_var_location: i32,
}
impl InGameScreen {
pub fn new() -> Self {
pub unsafe fn new(game_core: &GameCore) -> Self {
Self {
current_state: InGameState::SWIMMING,
shader_time_var_location: raylib::ffi::GetShaderLocation(
*game_core.resources.pixel_shader,
rstr!("time").as_ptr(),
),
}
}
@ -262,13 +267,10 @@ impl Screen for InGameScreen {
}
// Update the shader's internal time
unsafe {
let time_var_location = raylib::ffi::GetShaderLocation(
*game_core.resources.pixel_shader,
rstr!("time").as_ptr(),
);
game_core.resources.pixel_shader.set_shader_value(time_var_location, draw_handle.get_time() as f32);
}
game_core
.resources
.pixel_shader
.set_shader_value(self.shader_time_var_location, draw_handle.get_time() as f32);
// Render the 2D context via the ripple shader
{
@ -288,7 +290,7 @@ impl Screen for InGameScreen {
x: -10.0,
y: -10.0,
width: win_width as f32 + 20.0,
height: win_height as f32 + 20.0
height: win_height as f32 + 20.0,
},
Vector2::zero(),
0.0,

View File

@ -125,7 +125,7 @@ impl Screen for PauseMenuScreen {
draw_handle.draw_text(
"Credits:\n\t- @ewpratten\n\t- @rsninja722\n\t- @wm-c\n\t- @catarinaburghi",
(win_width / 2) - (SCREEN_PANEL_SIZE.x as i32 / 2) + 10,
(win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 120,
(win_height / 2) - (SCREEN_PANEL_SIZE.y as i32 / 2) + 170,
20,
Color::BLACK,
);

View File

@ -11,7 +11,16 @@ mod world;
use gamecore::{GameCore, GameProgress, GameState};
use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer};
use log::info;
use logic::{gameend::GameEndScreen, ingame::InGameScreen, loadingscreen::LoadingScreen, mainmenu::MainMenuScreen, pausemenu::PauseMenuScreen, screen::Screen, shop::ShopScreen, winscreen::{self, WinScreen}};
use logic::{
gameend::GameEndScreen,
ingame::InGameScreen,
loadingscreen::LoadingScreen,
mainmenu::MainMenuScreen,
pausemenu::PauseMenuScreen,
screen::Screen,
shop::ShopScreen,
winscreen::{self, WinScreen},
};
use raylib::prelude::*;
use world::{load_world_colliders, World};
@ -69,10 +78,13 @@ fn main() {
let mut loading_screen = LoadingScreen::new();
let mut main_menu_screen = MainMenuScreen::new();
let mut pause_menu_screen = PauseMenuScreen::new();
let mut ingame_screen = InGameScreen::new();
let mut ingame_screen;
unsafe {
ingame_screen = InGameScreen::new(&game_core);
}
let mut game_end_screen = GameEndScreen::new();
let mut shop_screen = ShopScreen::new();
let mut win_screen = WinScreen::new();
let mut win_screen = WinScreen::new();
// Main rendering loop
while !raylib.window_should_close() {
@ -117,12 +129,12 @@ fn main() {
&mut audio_system,
&mut game_core,
),
GameState::WinGame => win_screen.render(
GameState::WinGame => win_screen.render(
&mut draw_handle,
&raylib_thread,
&mut audio_system,
&mut game_core,
)
),
};
// If needed, update the global state