Procházet zdrojové kódy

Restore files, implement 30 FPS cap

The files are retrieved from the older Izanami project.

A basic 30 FPS cap has been implemented for rendering.
master
TheoryOfNekomata před 3 roky
rodič
revize
2a66eb80bf
18 změnil soubory, kde provedl 258 přidání a 13 odebrání
  1. +1
    -1
      CMakeLists.txt
  2. +1
    -0
      src/packages/game/config/IZ_config.c
  3. +49
    -0
      src/packages/game/config/IZ_config.h
  4. +1
    -0
      src/packages/game/config/IZ_config_mapping.c
  5. +20
    -0
      src/packages/game/config/IZ_config_mapping.h
  6. +1
    -0
      src/packages/game/config/IZ_config_pool.c
  7. +14
    -0
      src/packages/game/config/IZ_config_pool.h
  8. +1
    -0
      src/packages/game/config/IZ_config_window.c
  9. +18
    -0
      src/packages/game/config/IZ_config_window.h
  10. +11
    -0
      src/packages/game/core/IZ_constants.h
  11. +1
    -1
      src/packages/game/core/IZ_movable.h
  12. +1
    -1
      src/packages/game/core/IZ_placeable.h
  13. +1
    -1
      src/packages/game/core/IZ_spatial.h
  14. +1
    -0
      src/packages/game/input/IZ_action.c
  15. +102
    -0
      src/packages/game/input/IZ_action.h
  16. +33
    -7
      src/packages/game/main.c
  17. +1
    -1
      src/packages/game/math/IZ_math.h
  18. +1
    -1
      src/packages/game/math/IZ_vector.h

+ 1
- 1
CMakeLists.txt Zobrazit soubor

@@ -7,7 +7,7 @@ set(SDL2PATH "${PROJECT_SOURCE_DIR}/dependencies/SDL2-2.0.16/x86_64-w64-mingw32"
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})

add_executable(izanami src/packages/game/main.c src/packages/game/math/IZ_vector.c src/packages/game/math/IZ_vector.h src/packages/game/math/IZ_math.c src/packages/game/math/IZ_math.h src/packages/game/core/IZ_placeable.c src/packages/game/core/IZ_placeable.h src/packages/game/core/IZ_movable.c src/packages/game/core/IZ_movable.h src/packages/game/core/IZ_spatial.c src/packages/game/core/IZ_spatial.h)
add_executable(izanami src/packages/game/main.c src/packages/game/math/IZ_vector.c src/packages/game/math/IZ_vector.h src/packages/game/math/IZ_math.c src/packages/game/math/IZ_math.h src/packages/game/core/IZ_placeable.c src/packages/game/core/IZ_placeable.h src/packages/game/core/IZ_movable.c src/packages/game/core/IZ_movable.h src/packages/game/core/IZ_spatial.c src/packages/game/core/IZ_spatial.h src/packages/game/input/IZ_action.c src/packages/game/input/IZ_action.h src/packages/game/config/IZ_config.c src/packages/game/config/IZ_config.h src/packages/game/config/IZ_config_window.c src/packages/game/config/IZ_config_window.h src/packages/game/config/IZ_config_mapping.c src/packages/game/config/IZ_config_mapping.h src/packages/game/config/IZ_config_pool.c src/packages/game/config/IZ_config_pool.h src/packages/game/core/IZ_constants.h)

target_link_libraries(izanami ${SDL2_LIBRARY})



+ 1
- 0
src/packages/game/config/IZ_config.c Zobrazit soubor

@@ -0,0 +1 @@
#include "IZ_config.h"

+ 49
- 0
src/packages/game/config/IZ_config.h Zobrazit soubor

@@ -0,0 +1,49 @@
#ifndef IZ_CONFIG_H
#define IZ_CONFIG_H

#include "../core/IZ_constants.h"

#include "IZ_config_mapping.h"
#include "IZ_config_pool.h"
#include "IZ_config_window.h"

/**
* File path of the configuration file.
*/
static const char* IZ_CONFIG_FILE_PATH = "config.ini";

/**
* Structure that defines the application's internal configuration.
*/
typedef struct {
/**
* Window configuration.
*/
IZ_ConfigWindow window;
/**
* Pool configuration.
*/
IZ_ConfigPool pool;
/**
* Keyboard and joystick mappings for each controllable agent.
*/
IZ_ConfigMapping mapping[IZ_MAX_PLAYERS];
} IZ_Config;

/**
* Writes the configuration to a file.
* @param config The pointer to the configuration data.
* @param filename The filename of the destination file.
* @return Result code of the operation.
*/
unsigned int IZ_ConfigSave(IZ_Config* config, const char* filename);

/**
* Reads the configuration from a file.
* @param config The pointer to the configuration data.
* @param filename The filename of the destination file.
* @return Error message, or NULL if there are no errors.
*/
unsigned int IZ_ConfigLoad(IZ_Config* config, const char* filename);

#endif

+ 1
- 0
src/packages/game/config/IZ_config_mapping.c Zobrazit soubor

@@ -0,0 +1 @@
#include "IZ_config_mapping.h"

+ 20
- 0
src/packages/game/config/IZ_config_mapping.h Zobrazit soubor

@@ -0,0 +1,20 @@
#ifndef IZ_CONFIG_MAPPING_H
#define IZ_CONFIG_MAPPING_H

/**
* Structure that defines the application's input configuration.
*/
typedef struct {
/**
* Mapping of keyboard scan codes to each action.
*/
unsigned int keyboard[16];
/**
* Mapping of joystick buttons to each action.
*
* Note: directional actions are not included here.
*/
unsigned int joystick[12];
} IZ_ConfigMapping;

#endif

+ 1
- 0
src/packages/game/config/IZ_config_pool.c Zobrazit soubor

@@ -0,0 +1 @@
#include "IZ_config_pool.h"

+ 14
- 0
src/packages/game/config/IZ_config_pool.h Zobrazit soubor

@@ -0,0 +1,14 @@
#ifndef IZ_CONFIG_POOL_H
#define IZ_CONFIG_POOL_H

/**
* Structure that defines the application's pools configuration.
*/
typedef struct {
/**
* Capacity of the characters pool.
*/
unsigned int characters;
} IZ_ConfigPool;

#endif

+ 1
- 0
src/packages/game/config/IZ_config_window.c Zobrazit soubor

@@ -0,0 +1 @@
#include "IZ_config_window.h"

+ 18
- 0
src/packages/game/config/IZ_config_window.h Zobrazit soubor

@@ -0,0 +1,18 @@
#ifndef IZ_CONFIG_WINDOW_H
#define IZ_CONFIG_WINDOW_H

/**
* Structure that defines the application's window configuration.
*/
typedef struct {
/**
* Width of the application window
*/
unsigned int width;
/**
* Height of the application window.
*/
unsigned int height;
} IZ_ConfigWindow;

#endif

+ 11
- 0
src/packages/game/core/IZ_constants.h Zobrazit soubor

@@ -0,0 +1,11 @@
#ifndef IZ_CONSTANTS_H
#define IZ_CONSTANTS_H

/**
* How many players can play this application?
*
* Default value: 1u
*/
#define IZ_MAX_PLAYERS ((unsigned short) 1u)

#endif

+ 1
- 1
src/packages/game/core/IZ_movable.h Zobrazit soubor

@@ -7,4 +7,4 @@ typedef struct {
IZ_Vector velocity;
} IZ_Movable;

#endif //IZ_MOVABLE_H
#endif

+ 1
- 1
src/packages/game/core/IZ_placeable.h Zobrazit soubor

@@ -7,4 +7,4 @@ typedef struct {
IZ_Vector location;
} IZ_Placeable;

#endif //IZ_PLACEABLE_H
#endif

+ 1
- 1
src/packages/game/core/IZ_spatial.h Zobrazit soubor

@@ -8,4 +8,4 @@ typedef struct {
IZ_Vector size;
} IZ_Spatial;

#endif //IZ_SPATIAL_H
#endif

+ 1
- 0
src/packages/game/input/IZ_action.c Zobrazit soubor

@@ -0,0 +1 @@
#include "IZ_action.h"

+ 102
- 0
src/packages/game/input/IZ_action.h Zobrazit soubor

@@ -0,0 +1,102 @@
#ifndef IZ_ACTION_H
#define IZ_ACTION_H

/**
* Enumeration for the actions available in the application.
*/
typedef enum {
/**
* Index for the right (eastward) directional action.
*/
IZ_ACTION_INDEX_RIGHT = 0x0u,
/**
* Index for the down (southward) directional action.
*/
IZ_ACTION_INDEX_DOWN = 0x1u,
/**
* Index for the left (westward) directional action.
*/
IZ_ACTION_INDEX_LEFT = 0x2u,
/**
* Index for the up (northward) directional action.
*/
IZ_ACTION_INDEX_UP = 0x3u,
/**
* Index for the affirmative action.
*/
IZ_ACTION_INDEX_YES = 0x4u,
/**
* Index for the negative action.
*/
IZ_ACTION_INDEX_NO = 0x5u,
/**
* Index for the first implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION0 = 0x6u,
/**
* Index for the second implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION1 = 0x7u,
/**
* Index for the third implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION2 = 0x8u,
/**
* Index for the fourth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION3 = 0x9u,
/**
* Index for the fifth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION4 = 0xAu,
/**
* Index for the sixth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION5 = 0xBu,
/**
* Index for the seventh implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION6 = 0xCu,
/**
* Index for the eighth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION7 = 0xDu,
/**
* Index for the ninth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION8 = 0xEu,
/**
* Index for the tenth implementation-defined action.
*/
IZ_ACTION_INDEX_ACTION9 = 0xFu,
} IZ_ActionIndex;

typedef short IZ_ActionFlag;

inline IZ_ActionFlag IZ_ActionFlagValue(IZ_ActionIndex index) {
return (IZ_ActionFlag) (0x1 << index);
}

/**
* Names of the actions.
*/
static const char* IZ_ACTION_NAMES[] = {
"Right",
"Down",
"Left",
"Up",
"Yes",
"No",
"Action0",
"Action1",
"Action2",
"Action3",
"Action4",
"Action5",
"Action6",
"Action7",
"Action8",
"Action9",
};

#endif

+ 33
- 7
src/packages/game/main.c Zobrazit soubor

@@ -3,10 +3,13 @@
#include <stdio.h>

const char* APP_NAME = "SDL2";
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const unsigned int SCREEN_WIDTH = 640;
const unsigned int SCREEN_HEIGHT = 480;
const unsigned int SCREEN_FPS = 30;

int main(int argc, char* args[]) {
#define SDL_GetTicks64 SDL_GetTicks

int main() {
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;

@@ -19,8 +22,8 @@ int main(int argc, char* args[]) {
APP_NAME,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
(int) SCREEN_WIDTH,
(int) SCREEN_HEIGHT,
SDL_WINDOW_SHOWN
);

@@ -32,15 +35,38 @@ int main(int argc, char* args[]) {
bool quit = false;
SDL_Event e;
screenSurface = SDL_GetWindowSurface(window);

uint64_t start = SDL_GetTicks64();
unsigned int seconds_elapsed = 0;
uint64_t last_update = start;
unsigned int frames = 0;
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = true;
}
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);
}

unsigned int current_ticks = SDL_GetTicks64();
unsigned int delta = current_ticks - last_update;
unsigned int new_seconds_elapsed = current_ticks / 1000;

if (new_seconds_elapsed > seconds_elapsed) {
printf("%u\n", frames);
frames = 0;
seconds_elapsed = new_seconds_elapsed;
}

if ((float) delta < 1000.f / (float) (SCREEN_FPS + 1)) {
continue;
}

last_update = current_ticks;
frames += 1;
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);
}

SDL_DestroyWindow(window);
SDL_Quit();



+ 1
- 1
src/packages/game/math/IZ_math.h Zobrazit soubor

@@ -7,4 +7,4 @@ typedef float IZ_Real;

inline IZ_Real IZ_Sqrt(IZ_Real x) { return (IZ_Real) sqrtf(x); }

#endif //IZ_MATH_H
#endif

+ 1
- 1
src/packages/game/math/IZ_vector.h Zobrazit soubor

@@ -49,4 +49,4 @@ inline IZ_Real IZ_VectorDistance(IZ_Vector a, IZ_Vector b) {
return IZ_Sqrt(x * x + y * y);
}

#endif //IZ_VECTOR_H
#endif

Načítá se…
Zrušit
Uložit