Skip to content

Commit

Permalink
Home support, faster copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Gameblabla committed Oct 28, 2016
1 parent b38f634 commit cd75fb4
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -9,6 +9,10 @@ screenshots
src/*.o
*.elf
*.exe
*.zip
*.deb
*.res
*.cfg
src/err.txt
nkaruga-debian/opt/nkaruga/sfx
nkaruga-debian/opt/nkaruga/*.elf
2 changes: 1 addition & 1 deletion Makefile
@@ -1,7 +1,7 @@
CC = gcc
CXX = g++
LD = g++
CFLAGS = -Ofast -fdata-sections -ffunction-sections $(shell sdl2-config --cflags)
CFLAGS = -Ofast -fdata-sections -ffunction-sections $(shell sdl2-config --cflags) -DHOMEDIR
CXXFLAGS = $(CFLAGS) -std=c++11 -fno-exceptions -fno-rtti
LDFLAGS = $(shell sdl2-config --libs) -lSDL2_mixer -lm -Wl,--as-needed,--gc-sections -flto -s
LDFLAGS += -static-libgcc -Wl,-Bdynamic
Expand Down
File renamed without changes.
Binary file added assets/nkaruga-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions build_deb.sh
@@ -0,0 +1,3 @@
cp -r ./sfx ./nkaruga-debian/opt/nkaruga
cp ./nKaruga.elf ./nkaruga-debian/opt/nkaruga/nKaruga.elf
dpkg-deb --build nkaruga-debian
2 changes: 1 addition & 1 deletion icon.rc
@@ -1 +1 @@
id ICON "./icon.ico"
id ICON "./assets/icon.ico"
9 changes: 9 additions & 0 deletions nkaruga-debian/DEBIAN/control
@@ -0,0 +1,9 @@
Package: nkaruga
Architecture: amd64
Maintainer: Gameblabla
Depends: libsdl2-2.0-0, libsdl2-mixer-2.0-0
Priority: optional
Version: 0.2.5
Description: Shoot-them up clone
Shoot-them up clone inspired by Ikagura.
.
2 changes: 2 additions & 0 deletions nkaruga-debian/usr/bin/start_nkaruga.sh
@@ -0,0 +1,2 @@
cd /opt/nkaruga
exec ./nKaruga.elf
11 changes: 11 additions & 0 deletions nkaruga-debian/usr/share/applications/nkaruga.desktop
@@ -0,0 +1,11 @@
[Desktop Entry]
Version=0.2.5
Name=nKaruga
Comment=Shoot-them up clone
Exec=sh /usr/bin/start_nkaruga.sh
Icon=nkaruga-icon
Terminal=false
Type=Application
Categories=GTK;Game;ArcadeGame;
Keywords=game;games;
StartupNotify=true
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 30 additions & 5 deletions src/main.cpp
Expand Up @@ -4,6 +4,12 @@
#include "gfx/kanji.h"
#include "misc_data.h"

#ifdef HOMEDIR
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <stack>

#define ENEMY_W(i) Level::enemiesArray->data[i].img[0]
Expand Down Expand Up @@ -85,6 +91,25 @@ inline void readFromConfig(FILE* in)
G_displayBg = !!fgetc(in);
}

static FILE* open_configfile(const char* mode)
{
#ifdef HOMEDIR
char finalpath[128], finalpath2[128];

snprintf(finalpath, sizeof(finalpath), "%s/.nkaruga", getenv("XDG_CONFIG_HOME"));
/* Check if home folder exists */
if(access( finalpath, F_OK ) == -1)
{
mkdir(finalpath, 0755);
}

snprintf(finalpath2, sizeof(finalpath2), "%s/%s", finalpath, string_nKaruga_config);
return fopen(finalpath2, mode);
#else
return fopen(string_nKaruga_config, mode);
#endif
}

int main(int argc, char **argv)
{
UNUSED(argc);
Expand All @@ -97,8 +122,8 @@ int main(int argc, char **argv)
// Custom keys vars
t_key* customKeys[KEYS_TO_BIND] = { &G_fireKey, &G_polarityKey, &G_fragmentKey, &G_pauseKey };
int choice = 0;
configFile = fopen(string_nKaruga_config, "rb");

configFile = open_configfile("rb");
if(configFile)
{
readFromConfig(configFile);
Expand All @@ -109,7 +134,7 @@ int main(int argc, char **argv)
G_fireKey = SDL_SCANCODE_LCTRL;
G_polarityKey = SDL_SCANCODE_LALT;
G_fragmentKey = SDL_SCANCODE_LSHIFT;
G_pauseKey = SDL_SCANCODE_RETURN;
G_pauseKey = SDL_SCANCODE_SPACE;
G_downKey = SDL_SCANCODE_DOWN;
G_leftKey = SDL_SCANCODE_LEFT;
G_rightKey = SDL_SCANCODE_RIGHT;
Expand Down Expand Up @@ -197,7 +222,7 @@ int main(int argc, char **argv)
while (!get_key_pressed(customKeys[i])) updateKeys();
wait_no_key_pressed(*(customKeys[i]));
}
configFile = fopen(string_nKaruga_config, "wb");
configFile = open_configfile("wb");
if (configFile)
{
writeToConfig(configFile);
Expand All @@ -206,7 +231,7 @@ int main(int argc, char **argv)
}
else if (!choice)
{
configFile = fopen(string_nKaruga_config, "w+");
configFile = open_configfile("w+");
if (configFile)
{
writeToConfig(configFile);
Expand Down
5 changes: 1 addition & 4 deletions src/n2DLib.c
Expand Up @@ -78,10 +78,7 @@ void updateScreen()
int pitch;

SDL_LockTexture(MAIN_SCREEN, NULL, &pixels, &pitch);
for (i = 0; i < 76800; i++)
{
*(unsigned short*)(pixels + i * 2) = BUFF_BASE_ADDRESS[i];
}
memcpy(pixels,BUFF_BASE_ADDRESS,153600);
SDL_UnlockTexture(MAIN_SCREEN);
SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
SDL_RenderClear(sdlRenderer);
Expand Down

0 comments on commit cd75fb4

Please sign in to comment.