Initial commit
This commit is contained in:
8
source/editor/debug.c
Normal file
8
source/editor/debug.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "debug.h"
|
||||
|
||||
unsigned long long triCount = 0;
|
||||
|
||||
void resetTriangles()
|
||||
{
|
||||
triCount = 0;
|
||||
}
|
||||
9
source/editor/debug.h
Normal file
9
source/editor/debug.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef DEBUG_GUI_H
|
||||
#define DEBUG_GUI_H
|
||||
|
||||
extern unsigned long long triCount;
|
||||
|
||||
void resetTriangles();
|
||||
|
||||
|
||||
#endif
|
||||
154
source/editor/debugdraw.c
Normal file
154
source/editor/debugdraw.c
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "debugdraw.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
static uint32_t circleVBO;
|
||||
static uint32_t circleVAO;
|
||||
static struct mShader *circleShader;
|
||||
|
||||
static uint32_t gridVBO;
|
||||
static uint32_t gridVAO;
|
||||
static struct mShader *gridShader;
|
||||
|
||||
static uint32_t rectVBO;
|
||||
static uint32_t rectVAO;
|
||||
static struct mShader *rectShader;
|
||||
|
||||
void debugdraw_init()
|
||||
{
|
||||
circleShader = MakeShader("circlevert.glsl", "circlefrag.glsl");
|
||||
shader_setUBO(circleShader, "Projection", 0);
|
||||
glGenBuffers(1, &circleVBO);
|
||||
glGenVertexArrays(1, &circleVAO);
|
||||
|
||||
|
||||
float gridverts[] = {
|
||||
-1.f, -1.f,
|
||||
1.f, -1.f,
|
||||
-1.f, 1.f,
|
||||
1.f, 1.f
|
||||
};
|
||||
|
||||
gridShader = MakeShader("gridvert.glsl", "gridfrag.glsl");
|
||||
shader_setUBO(gridShader, "Projection", 0);
|
||||
glGenBuffers(1, &gridVBO);
|
||||
glGenVertexArrays(1, &gridVAO);
|
||||
glBindVertexArray(gridVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, gridVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(gridverts), &gridverts,
|
||||
GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
|
||||
rectShader = MakeShader("linevert.glsl", "linefrag.glsl");
|
||||
shader_setUBO(rectShader, "Projection", 0);
|
||||
glGenBuffers(1, &rectVBO);
|
||||
glGenVertexArrays(1, &rectVAO);
|
||||
}
|
||||
|
||||
void draw_line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
shader_use(rectShader);
|
||||
float verts[] = {
|
||||
x1, y1,
|
||||
x2, y2
|
||||
};
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_DYNAMIC_DRAW);
|
||||
glBindVertexArray(rectVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, 2);
|
||||
}
|
||||
|
||||
void draw_edge(float *points, int n)
|
||||
{
|
||||
shader_use(rectShader);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * n * 2, points,
|
||||
GL_DYNAMIC_DRAW);
|
||||
glBindVertexArray(rectVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, n);
|
||||
}
|
||||
|
||||
void draw_circle(int x, int y, float radius, int pixels)
|
||||
{
|
||||
shader_use(circleShader);
|
||||
|
||||
float verts[] = {
|
||||
x - radius, y - radius, -1.f, -1.f,
|
||||
x + radius, y - radius, 1.f, -1.f,
|
||||
x - radius, y + radius, -1.f, 1.f,
|
||||
x + radius, y + radius, 1.f, 1.f
|
||||
};
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, circleVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_DYNAMIC_DRAW);
|
||||
|
||||
shader_setfloat(circleShader, "radius", radius);
|
||||
shader_setint(circleShader, "thickness", pixels);
|
||||
|
||||
glBindVertexArray(circleVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
void draw_rect(int x, int y, int w, int h)
|
||||
{
|
||||
float hw = w / 2.f;
|
||||
float hh = h / 2.f;
|
||||
|
||||
float verts[] = {
|
||||
x - hw, y - hh,
|
||||
x + hw, y - hh,
|
||||
x + hw, y + hh,
|
||||
x - hw, y + hh
|
||||
};
|
||||
|
||||
shader_use(rectShader);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_DYNAMIC_DRAW);
|
||||
glBindVertexArray(rectVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
}
|
||||
|
||||
void draw_grid(int width, int span)
|
||||
{
|
||||
shader_use(gridShader);
|
||||
shader_setint(gridShader, "thickness", width);
|
||||
shader_setint(gridShader, "span", span);
|
||||
glBindVertexArray(gridVAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void draw_point(int x, int y, float r)
|
||||
{
|
||||
draw_circle(x, y, r, r);
|
||||
}
|
||||
|
||||
void draw_poly(float *points, int n)
|
||||
{
|
||||
shader_use(rectShader);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * n * 2, points,
|
||||
GL_DYNAMIC_DRAW);
|
||||
glBindVertexArray(rectVAO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, n);
|
||||
}
|
||||
|
||||
void debugdraw_flush()
|
||||
{
|
||||
|
||||
}
|
||||
16
source/editor/debugdraw.h
Normal file
16
source/editor/debugdraw.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef DEBUGDRAW_H
|
||||
#define DEBUGDRAW_H
|
||||
|
||||
void debugdraw_init();
|
||||
void draw_line(int x1, int y1, int x2, int y2);
|
||||
void draw_edge(float *points, int n);
|
||||
void draw_circle(int x, int y, float radius, int pixels);
|
||||
void draw_grid(int width, int span);
|
||||
void draw_rect(int x, int y, int w, int h);
|
||||
void draw_point(int x, int y, float r);
|
||||
void draw_poly(float *points, int n);
|
||||
|
||||
void debugdraw_flush(); /* This is called once per frame to draw all queued elements */
|
||||
|
||||
|
||||
#endif
|
||||
1432
source/editor/editor.cpp
Normal file
1432
source/editor/editor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
98
source/editor/editor.h
Normal file
98
source/editor/editor.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include "config.h"
|
||||
#include <SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include "resources.h"
|
||||
|
||||
|
||||
struct mCamera;
|
||||
|
||||
#define ASSET_TYPE_NULL 0
|
||||
#define ASSET_TYPE_IMAGE 1
|
||||
#define ASSET_TYPE_TEXT 2
|
||||
|
||||
struct fileasset {
|
||||
char *filename;
|
||||
short extension_len;
|
||||
short filename_len;
|
||||
bool searched;
|
||||
short type;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct editorVars {
|
||||
bool showStats;
|
||||
bool showHierarchy;
|
||||
bool showLighting;
|
||||
bool showGameSettings;
|
||||
bool showViewmode;
|
||||
bool showDebugMenu;
|
||||
bool showAssetMenu;
|
||||
bool showREPL;
|
||||
bool showExport;
|
||||
bool showLevel;
|
||||
};
|
||||
|
||||
struct gameproject {
|
||||
char name[127];
|
||||
char path[MAXPATH];
|
||||
};
|
||||
|
||||
struct Texture;
|
||||
|
||||
void pickGameObject(int pickID);
|
||||
int is_allowed_extension(const char *ext);
|
||||
|
||||
void editor_init(struct mSDLWindow *mwindow);
|
||||
void editor_input(SDL_Event * e);
|
||||
void editor_render();
|
||||
int editor_wantkeyboard();
|
||||
void editor_save();
|
||||
void editor_makenewobject();
|
||||
|
||||
void editor_project_gui();
|
||||
|
||||
void editor_init_project(struct gameproject *gp);
|
||||
void editor_save_projects();
|
||||
void editor_load_projects();
|
||||
void editor_proj_select_gui();
|
||||
void editor_import_project(char *path);
|
||||
void editor_make_project(char *path);
|
||||
|
||||
void editor_selectasset(struct fileasset *asset);
|
||||
void editor_selectasset_str(char *path);
|
||||
void editor_asset_gui(struct fileasset *asset);
|
||||
void editor_asset_tex_gui(struct Texture *tex);
|
||||
void editor_asset_text_gui(char *text);
|
||||
|
||||
void editor_level_btn(char *level);
|
||||
void editor_prefab_btn(char *prefab);
|
||||
|
||||
void game_start();
|
||||
void game_resume();
|
||||
void game_stop();
|
||||
void game_pause();
|
||||
|
||||
void get_levels();
|
||||
|
||||
///////// Object GUIs
|
||||
void light_gui(struct mLight *light);
|
||||
void pointlight_gui(struct mPointLight *light);
|
||||
void spotlight_gui(struct mSpotLight *spot);
|
||||
void staticactor_gui(struct mStaticActor *sa);
|
||||
void trans_drawgui(struct mTransform *T);
|
||||
void object_gui(struct mGameObject *go);
|
||||
void sprite_gui(struct mSprite *sprite);
|
||||
void circle_gui(struct phys2d_circle *circle);
|
||||
void segment_gui(struct phys2d_segment *seg);
|
||||
void box_gui(struct phys2d_box *box);
|
||||
void poly_gui(struct phys2d_poly *poly);
|
||||
void edge_gui(struct phys2d_edge *edge);
|
||||
void shape_gui(struct phys2d_shape *shape);
|
||||
void pinball_flipper_gui(struct flipper *flip);
|
||||
|
||||
int obj_gui_hierarchy(struct mGameObject *selected);
|
||||
|
||||
#endif
|
||||
19
source/editor/editorstate.c
Normal file
19
source/editor/editorstate.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "editorstate.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
void (*asset_command)(char *asset) = print_file;
|
||||
|
||||
void print_file(char *file)
|
||||
{
|
||||
printf("File path: %s\n", file);
|
||||
}
|
||||
|
||||
void set_new_model(char *modelPath)
|
||||
{
|
||||
printf("Loading new model: %s\n", modelPath);
|
||||
curActor->model = GetExistingModel(modelPath);
|
||||
strcpy(curActor->currentModelPath, modelPath);
|
||||
}
|
||||
|
||||
*/
|
||||
10
source/editor/editorstate.h
Normal file
10
source/editor/editorstate.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef EDITORSTATE_H
|
||||
#define EDITORSTATE_H
|
||||
|
||||
void set_new_model(char *modelPath);
|
||||
|
||||
extern void (*asset_command)(char *asset);
|
||||
|
||||
void print_file(char *file);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user